SYNTAX DIRECTED
TRANSLATIONCOMPILERS
29TH OCTOBER 2013
SDDA X1X2X3
Semantic RuleA.x = f ( X1.a, X2.b, X3.c )
SDTA X1X2{A.x = f( X1.a, X2.b) }X3
Embedded
S – attributed SDD SDTA X1X2X3 {a}
When we perform reduction, we evaluate the attribute to get the result
We have the stack
X1X2X3 symbols and states
X1.a, X2.b, X3.c values
After Reduction
A replaces X1X2X3
A.x evaluated by the functionf( X1.a, X2.b, X3.c )
L E { Print (E.val) }E E + T { E.val = E.val +
T.val }E T {E.val = T.val}
T T * F { T.val = T.val * F.val }T F { T.val = F.val }F id { F.val = id }
Stack Symbol
Stack Value
Input String
Syntax Action
Semantic Action
$ $ 3*4$ 3 $3 *4 F id F.val = id$ F $ 3 *4 T F T.Val = F.val$ T $ 3 *4 Shift$ T * $ 3* 4 Shift$ T*4 $ 3*4 $ F id F.val = id$ T*F $ 3*4 $ T T * F T.Val = T.val * F.val
$ T $ 12 $
To evaluate T.val = T.val * F.val , we need the two values; which we
get form the value stack.
L – attributed SDD is suitable for top-down parsing LL (1)
synthesized attributes inherited attributes
A non-terminal can have multiple inherited attributes ; for each will
have some defined action
In case of synthesize attribute, we append it to the end of the rule
For predictive parsers, for each non-terminal, we have a function
E.G : Recursive Descent ParserA X1X2X3
A(){
if ( a == X1 )move to next symbolif ( X1 is a NT)
X1()}
This function invokes the functions of the body of the production
To implement predictive parsing, we need to implement those functions
Made By :
Mohit Bhura11CS30019