+ All Categories
Home > Documents > SYNTAX DIRECTED TRANSLATION

SYNTAX DIRECTED TRANSLATION

Date post: 22-Feb-2016
Category:
Upload: gracie
View: 52 times
Download: 0 times
Share this document with a friend
Description:
SYNTAX DIRECTED TRANSLATION. COMPILERS 29 TH OCTOBER 2013. SDD. Semantic Rule. A.x = f ( X 1 .a, X 2 .b, X 3 .c ). A  X 1 X 2 X 3. SDT. Embedded. A  X 1 X 2 { A.x = f( X 1 .a, X 2 .b) } X 3. S – attributed SDD SDT A  X 1 X 2 X 3 {a} - PowerPoint PPT Presentation
14
SYNTAX DIRECTED TRANSLATION COMPILERS 29 TH OCTOBER 2013
Transcript
Page 1: SYNTAX DIRECTED TRANSLATION

SYNTAX DIRECTED

TRANSLATIONCOMPILERS

29TH OCTOBER 2013

Page 2: SYNTAX DIRECTED TRANSLATION

SDDA X1X2X3

Semantic RuleA.x = f ( X1.a, X2.b, X3.c )

Page 3: SYNTAX DIRECTED TRANSLATION

SDTA X1X2{A.x = f( X1.a, X2.b) }X3

Embedded

Page 4: SYNTAX DIRECTED TRANSLATION

S – attributed SDD SDTA X1X2X3 {a}

When we perform reduction, we evaluate the attribute to get the result

Page 5: SYNTAX DIRECTED TRANSLATION

We have the stack

X1X2X3 symbols and states

X1.a, X2.b, X3.c values

Page 6: SYNTAX DIRECTED TRANSLATION

After Reduction

A replaces X1X2X3

A.x evaluated by the functionf( X1.a, X2.b, X3.c )

Page 7: SYNTAX DIRECTED TRANSLATION

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 }

Page 8: SYNTAX DIRECTED TRANSLATION

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 $

Page 9: SYNTAX DIRECTED TRANSLATION

To evaluate T.val = T.val * F.val , we need the two values; which we

get form the value stack.

Page 10: SYNTAX DIRECTED TRANSLATION

L – attributed SDD is suitable for top-down parsing LL (1)

synthesized attributes inherited attributes

Page 11: SYNTAX DIRECTED TRANSLATION

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

Page 12: SYNTAX DIRECTED TRANSLATION

E.G : Recursive Descent ParserA X1X2X3

A(){

if ( a == X1 )move to next symbolif ( X1 is a NT)

X1()}

Page 13: SYNTAX DIRECTED TRANSLATION

This function invokes the functions of the body of the production

To implement predictive parsing, we need to implement those functions

Page 14: SYNTAX DIRECTED TRANSLATION

Made By :

Mohit Bhura11CS30019


Recommended