Generation of AST
6/69
Gist: A parser simulates the construction of PT and, simultaneously, calls some semantic actions to create AST.
Example:
Rule: Semantic Action:
S  ® i := Ek { S.a   := MakeTree(‘=’, i.a, Ek.a) }
Ei ® Ej + Ek { Ei.a := MakeTree(‘+’, Ej .a, Ek .a) }
Ei ® Ej * Ek { Ei.a := MakeTree(‘*’, Ej .a, Ek .a) }
Ei ® (Ej) { Ei.a := Ej.a }
Ei ®  i { Ei.a  := MakeLeaf(i.a) }
Notes:
• MakeTree(o, a, b) creates a new node o, attaches sons a (left) and b, and returns a pointer to node o
• MakeLeaf(i.a) creates a new node i.a
(i.a is a symbol-table address) and returns a pointer to this new node