Download presentation
Presentation is loading. Please wait.
1
SYNTAX DIRECTED TRANSLATION
COMPILERS 29TH OCTOBER 2013
2
SDD Semantic Rule A X1X2X3 A.x = f ( X1.a, X2.b, X3.c )
3
SDT A X1X2{A.x = f( X1.a, X2.b) }X3 Embedded
4
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
5
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
6
After Reduction A replaces X1X2X3 A
After Reduction A replaces X1X2X3 A.x evaluated by the function f( X1.a, X2.b, X3.c )
7
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 }
8
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
9
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.
10
L – attributed SDD is suitable for top-down parsing LL (1) synthesized attributes inherited attributes
11
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
12
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() }
13
This function invokes the functions of the body of the production To implement predictive parsing, we need to implement those functions
14
Made By : Mohit Bhura 11CS30019
Similar presentations
© 2024 SlidePlayer.com. Inc.
All rights reserved.