The Gateway to Computer Science Excellence
+3 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 by Active (3.2k points)
edited by | 253 views
in evaluation phase in L attr -> attribute are evaluated by traversing parse tree depth ,left to right

in case of S attri-> it is from bottom to up

can you please share source where I can read the example? @adarsh_1997


 check this out

this is s attribute B is the answer

S1 and S2 both are true actually. @akshat sharma


@Shivam Kasat yes  only evaluation will differ otherwise result must be same .isnt? 

i think result wud have been different as in case L attributed we may have semantic action in other order(pre,in) but in case of S att semantic action must be postfix.

i need to be confirmed. isnt true?

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.


what will be the answer to this question?

even i got only S2 correct!!

 grammar is S attributed

am not sure

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

pls someone confirm

1 Answer

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 Active (3.6k points)

Related questions

Quick search syntax
tags tag:apple
author user:martin
title title:apple
content content:apple
exclude -tag:apple
force match +apple
views views:100
score score:10
answers answers:2
is accepted isaccepted:true
is closed isclosed:true
50,833 questions
57,689 answers
107,252 users