in Compiler Design edited by
3,303 views
4 votes
4 votes

 

Consider the following grammar and their Syntax Directed Translation (SDT) rules.

 

(Here id represent a integer and id.val is value of that integer)

S1: Given SDT is L-attributed and using L-attributed evaluation the value of the expression 4 * 6 + 3 * 7 is 84.

S2: Given SDT is S-attributed and using S-attributed evaluation value of the expression 4 * 6 + 3 * 7 is 84.

 

Which of the above statements are true with respect to the above SDT.?

My doubt here: Is there any difference in the way of evaluation of L-attributed SDT and S-attributed SDT ?

in Compiler Design edited by
3.3k views

4 Comments

S-attributed SDT will have semantic actions at postfix while L-attributed SDT can have sematic actions at pre,in or postfix and since they both are have only synthesized attribute there order of execution will be bottom-up order.
0
0

@adarsh_1997 https://gateoverflow.in/294863/gradeup

what will be the answer to this question?

0
0
even i got only S2 correct!!

 grammar is S attributed

am not sure

because L attributed grammar consists of both inherited and synthesized attributes.so may be both are true.

pls someone confirm
0
0

1 Answer

0 votes
0 votes

As we can clearly see that S is taking value from its children and even A is doing the same so there is no doubt that the grammar is Synthesized i.e. S-attributed grammar. Now all S attributed grammars are L attributed Grammars as L attributed grammar= synthesized+inherited grammar.

So BOTH S1 and S2 are True

and the evaluation of expression is like-->4*(6+3)*7 =4*3*7 = 84


PS--> If in S1 we were given inherited instead of L attributed then it would have been only S2

by

1 comment

To make things more clear:

If in S1 we were given inherited instead of L attributed then it would have been only S2

He is talking about the underlined ‘L-attributed’. And it would have been false because the given SDD does not have inherited attributes.

S1: Given SDT is L-attributed and using L-attributed evaluation the value of the expression 4 * 6 + 3 * 7 is 84.

 

0
0

Related questions