


































Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
Prepare for your exams
Study with the several resources on Docsity
Earn points to download
Earn points by helping other students or get them with a premium plan
A detailed lecture on abstract syntax trees (ast) in the context of compilers. It covers ast design, decoration, and construction, including type inference, scope analysis, and symbol table. The lecture also discusses the difference between derivation trees and ast, and the advantages and disadvantages of ast generation on-the-fly versus parser tree reduction. The document also includes a discussion on ll(1) parsing, first/follow sets, and parsing table, as well as ast data structure design and generation on-the-fly. The lecture is part of a university course on programming languages and compilers.
Typology: Lecture notes
1 / 42
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