Lecture # 17. Syntax Directed Definition. Translation Schemes. A translation scheme is a CF grammar embedded with semantic actions. rest + term { print(“+”) } rest. Embedded semantic action. rest. +. term. { print(“+”) }. rest. Example Translation Scheme.
Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author.While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server.
Lecture # 17
Syntax Directed Definition
rest +term { print(“+”) } rest
Embeddedsemantic action
rest
+
term
{ print(“+”) }
rest
expr expr+termexpr exprtermexpr termterm 0term 1…term 9
{ print(“+”) }{ print(“”) }{ print(“0”) }{ print(“1”) }…{ print(“9”) }
expr
{ print(“+”) }
+
expr
term
{ print(“2”) }
{ print(“”) }

2
expr
term
{ print(“5”) }
5
term
{ print(“9”) }
9
Translates 95+2 into postfix 952+
inherited
Production
Semantic Rule
D T LT int…L id
L.in:= T.typeT.type:=‘integer’…… := L.in
synthesized
Production
Semantic Rule
L.in:= T.typeT.type:= ‘integer’T.type:= ‘real’ L1.in:= L.in; addtype(id.entry, L.in)addtype(id.entry, L.in)
D T LT intT realL L1,idL id
Synthesized:T.type, id.entryInherited:L.in
Productions
Semantic Rules
S.pos = 0
S.pos=S.pos+1
S.decval= A.decval+S.decval
A.val=0 A.pos=S.pos
A.decval= A.val *2pos
A.val=1 A.pos=S.pos
A.decval= A.val *2pos
S.pos =S.pos