语句的类型检查 很多语言中语句没有值,我们给它们赋予一个基本类型void,错误类型是type_error。 P→D;S S→id:=E {if id.type = E.type then S.type := void else S.type := type_error} S→if E then S1 {E.type := boolean then S.type := S1.type else S.type := type_error} S→while E do S1 {if E.type = boolean then S.type:= S1.type else S.type:= type_error} S→S1;S2 {if S1.tpye = void and S2.type = void then S.type := void else S.type := type_error} 函数的类型检查 带有参数的函数引用可由下面产生式描述: E→E(E) 对函数类型的说明 T→T1 ‘→’ T2 {T.type := T1.type → T2.type} 对函数引用的类型检查规则 E→E1(E2) {if E2.type =s and E1.type = s→t then E.ty
原创力文档

文档评论(0)