search
Log In
0 votes
326 views
E->TE'

E'->*T { printf('*') ;}  E' | epsilon

T-> id {printf (id.name) ;}

A) E->E*T | T {printf('*');}

T->id {printf(id.name);}

B) E->TE'

E'->*TME' | epsilon

M->epsilon { printf('*');}

T->id {printf(id.name) ; }

 

C) E->T*E {printf('*');}

E->T

T->id {printf (id.name) ;}

D) None of these  

 

Please explain precisely .
in Compiler Design 326 views
0

Refer this

0

And this

1 Answer

0 votes

In case of L attributed definition the semantic action is embedded to the immediate left of the non-terminal in a production. In case of S attributed definition the semantic action is embedded at the end of a production

As bottom up parsers cannot handle L attributed definitions so we convert L attributed definitions to S attribute definitions

How we do it?

By introducing a redundant non-terminal

Given grammar

E->TE'

E'->*T { printf('*') ;}  E' | epsilon

T-> id {printf (id.name) ;}

the highlighted semantic action is not placed in the end of the production. so it is not S attributed. Remaining are S attributed

E->TE'

E'->*T M  E' | epsilon

M->epsilon { printf('*') ;}

T-> id {printf (id.name) ;}

Both the grammars are equivalent

Option B is correct

Related questions

4 votes
0 answers
1
1.4k views
I read from Dragon Book that Syntax directed translation is used for type checking for instance where performing some reductions and other operation on the string or symbol we perform some additional operations. https://en.wikipedia.org/wiki/L-attributed_grammar Here for ... L attributes definition I understand that but it could be Both because L attribute definition is both. Resolve my doubt !
asked Nov 12, 2017 in Compiler Design saxena0612 1.4k views
0 votes
1 answer
2
1 vote
2 answers
3
157 views asked Feb 2, 2016 in Compiler Design Sourabh Kumar 157 views
3 votes
2 answers
4
1.5k views
How to solve this question? Attributes calculated from children are synthesized, while attributes calculated from parents and/or siblings is inherited. And S-attributed are purely synthesized, while L-attributed are synthesized+inherited, is this right?
asked Jan 27, 2016 in Compiler Design Purple 1.5k views
...