BKS Unit II-S and L-Attributed SDDs
BKS Unit II-S and L-Attributed SDDs
Unit II
– Predictive Parsing
– Bottom Up Parsing
– Operator Precedence Parsing
– LR Parsers
• SLR,
• LALR
• LR
• Parser Generator
Learn Compiler Design: From B. K. Sharma
Unit II: Syllabus
L-Attributed
L for Left-to-right:
Dependency graph edges go from left-to-right.
Learn CD: From B K Sharma
L-Attributed Definitions
Evaluation Order
Attributes in L-attributed SDDs are evaluated by
depth-first and left-to-right parsing manner.
L-Attributed Definitions
A.a
X1.x X2.x
L-Attributed Definitions
L-attributed definitions allow for a natural order of
evaluating attributes: depth-first and left to right
Y.i:=X.s
Evaluation Order:
Once a parse tree is constructed, attributes can be
computed (evaluated) according to the defined semantic
rules.
The question is: in what order?
Learn CD: From B K Sharma
Dependency Graph
Dependency Graph
A.a
A X Y A.a := f(X.x, Y.y)
X.x Y.y
A.a
X.x := f(A.a, Y.y)
X.x Y.y
Direction of A.a
Y.y := f(A.a, X.x)
value dependence X.x Y.y
Learn CD: From B K Sharma
X Y
X.i :=g(A.a,Y.y)
X Y
Learn CD: From B K Sharma
D
T.type = ‘real’ L.in = ‘real’
id1.entry
Learn CD: From B K Sharma
D
T.type = ‘real’ L.in = ‘real’
id1.entry
Learn CD: From B K Sharma
Dependency Graph
Evaluation Order
The evaluation order of semantic rules depends from a
Topological Sort derived from the dependency graph.
1 id1.entry 7. L2.in=L1.in
8. addtype(id2.entry, L2.in)
9. L3.in=L2.in
10. addtype(id1.entry, L3.in)