CSC 530 Lecture Notes Week 4
Introduction to the Formal Semantics of Programming Languages
Introduction to Attribute Grammars
E ::= E1 + T E.type = (if E1.type = T.type then E1.type else "ERROR") E ::= T E.type = T.type T ::= T1 * F T.type = (if T1.type = F.type then T1.type else "ERROR") T ::= F T.type = F.type F ::= ident F.type = Lookup(env, ident).type F ::= real F.type = "real" F ::= integer F.type = "integer"
E ::= E1 + T E.val = E1.val + T.val E ::= T E.val = T.val T ::= T1 * F T.val = T1.val * F.val T ::= F T.val = F.val F ::= ident F.val = GetVal(store, ident) F ::= real F.val = read(val) F ::= integer F.val = read(val)
and the corresponding attribute dependency diagramX ::= Y Z Y.a1 = X.a1 Z.a1 = Y.a2 X.a2 = Z.a2