Unit 4 - Syntax Directed Translation
Unit 4 - Syntax Directed Translation
CHAPTER TWO
•Strings
•Regular expressions
•Tokens
•Transition diagrams
•Finite Automata
CHAPTER THREE
• Grammars
• Derivations
• Parse-trees
• Top-down parsing (LL)
• Bottom-up paring (LR, SLR,LALR)
L → En Print (E.val)
F.val=3 digit.lexval=5
parse tree showing the value
digit.lexval=3 of the attributes at each node
is called Annotated parse tree
Annotated parse tree for 3*5+4n
D
Production Semantic rules
D→TL L.in = T.type LL.in=real
T
T.type=real
T → int T.type = integer
real ,
T → real T.type = real id
id3
L1
L.in=real
L → L1 , id L1.in = L.in,
addtype(id.entry,L.in)
,
L → id addtype(id.entry,L.in) L.in=real
L1 id2
id
id
id1
D→TL
L → Lid
1 , id
E1 E2
val + val
The edges to E.val from E1.val and E2.val shows that E.val is depends on E1.val and E2.val
1 T.type=real L.in=real 2
real 3 ,
L.in=real id3 4
,
5 L.in=real id2 6
7 id1
• Above syntax directed definition is not L-attributed because the inherited attribute Q.i of
the grammar symbol Q depends on the attribute R.s of the grammar symbol to its right.
T R
- R
9 {Print(9)} T {Print(-)}
5 {Print(5)} + R
T {Print(+)}
2 {Print(2)} 𝜖