


































Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!



































AST Design
class AST_node {
int node_type;
AST_node[ ] children;
String name; int value; …etc…
Use Class Hierarchy
of nonterminals (e.g., expressions)
abstract class Expr { … }
class Add extends Expr { Expr left, right; … }
class Mult extends Expr { Expr left, right; … }
// or: class BinExpr extends Expr { Oper o; Expr l,
r; }
class Minus extends Expr { Expr e; …}
a - b - c Valid
a > b > c invalid
AST Construction
checking phase
checks (or other actions) only after tree has
been built and its structure is stable
7
abstract syntax tree)
Left-factored Grammar for
Illustration
→ if then ) = {$}Left-factored Grammar for
Illustration
→ if then begin
int
bool
ε
if
then
x
x ε
y
ε
y
x