SYNTAX DIRECTED TRANSLATION COMPILERS 29TH OCTOBER 2013
SDD Semantic Rule A X1X2X3 A.x = f ( X1.a, X2.b, X3.c )
SDT A X1X2{A.x = f( X1.a, X2.b) }X3 Embedded
When we perform reduction, we evaluate the attribute to get the result S – attributed SDD SDT A 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 We have the stack X1X2X3 symbols and states X1.a, X2.b, X3.c values
After Reduction A replaces X1X2X3 A After Reduction A replaces X1X2X3 A.x evaluated by the function f( X1.a, X2.b, X3.c )
L E { Print (E. val) } E E + T { E. val = E. val + T 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 $ 3*4 $ 3 $3 *4 Semantic Action $ 3*4 $ 3 $3 *4 F id F.val = id $ F T F T.Val = F.val $ T Shift $ T * $ 3* 4 $ T*4 $ 3*4 $ T*F T T * F T.Val = T.val * F.val $ 12
To evaluate T. val = T. val. F 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 Parser A X1X2X3 A(). {. if ( a == X1 ) E.G : Recursive Descent Parser A X1X2X3 A() { if ( a == X1 ) move to next symbol if ( 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 Bhura 11CS30019