The Gateway to Computer Science Excellence
First time here? Checkout the FAQ!
x
+2 votes
148 views

 

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.1k points)
edited by | 148 views
0
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
0

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

+1

 check this out

0
this is s attribute B is the answer
0

S1 and S2 both are true actually. @akshat sharma

0

@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?

0
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

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

what will be the answer to this question?

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

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.4k 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,092 questions
55,276 answers
190,804 comments
86,089 users