edited by
1,682 views
0 votes
0 votes
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 .
edited by

1 Answer

1 votes
1 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

1 votes
1 votes
2 answers
2
4 votes
4 votes
2 answers
3
0 votes
0 votes
2 answers
4
jaswanth431 asked Nov 16, 2021
792 views
If the grammar has only S-attributed semantic definitions, in a top down parser we will add the semantic action at the end of production and it will we executed when we...