The Gateway to Computer Science Excellence
First time here? Checkout the FAQ!
x
+1 vote
182 views
Either L attribute or S attributed .

What kind of SDT it is  ?

S --->E#   Out('#')

E ---> E+E   Out('+')

E --->T

T ---> T#F   Out('*)

T ---> F

F ---> (E)

F ---> a   Out ('a')

For the sentence a+a+a

What will be the final Output of it ?
asked in Compiler Design by Veteran (43.4k points)
retagged | 182 views

1 Answer

0 votes

It is S attributed as the attributes are depending on their child

Let me know if anything is wrong

answered by Veteran (14.4k points)
How do you know it is s attributed . I mean how did you figure out .Given a SDT how can i find out which one is what .its seems almost same to me.

it is said that S attributed is evaluated Bottom up manner and in L attributed we use Depth First .Right to Left but i dont find any difference we do the same procedure for evaluation.

how do you distinguish the parse tree of L attributed from this one ?

And one more thing in this production E ---->E+E  we can choose any side fro further evaluation why did you choose right side . if we use left side answer will be different .

Please clear the confusion b/w Procedure of evaluation .and figuring out what is what .
Yeah ur right if we use that to left sided we get result as aa+a+#

Since S couldn't be finished untill E gets finished it means here S is depending on its Child E so it is S attributed
Are we going to see this dependency in every production or in just one is enough.
No if we find that all are s attributed we say it is s attributed
If some are S attributed and other are L attributed then we say it as L attribute
I have one more Question as you said it is s attributed but L attributed definition itself contains both definition synthesized as  well as inherited definition then if a SDT is s attributed then we can apply both S attributed as well as L attributed  definition for solving the question and there will be ambiguity in Answer.

What do you think ?
every s attrbuted could be L -attributed but not vice versa

in this question their is not dependency on siblings i think what do u say ?
where u get this question ??
Actually just by lookig at the SDT I dont know how to check whether it is L attributed or S attributed..Unless we have some Semantic rules with it .and i think it should be very imp to know what kind of SDT it is .otherwise we will make some mistake in evatuation process.mainly in case og ambiguous grammar like

E ---> E+ E

E --->E*E

E ---> id

if someone says evaluate it for like 1+1*1 then which way to do it . I don't know
we need to consider unambiguous grammar for sdt if not we need to change it to unambiguous I think
@sekhar parse tree as per order of presedence....
@shekhar yes as the tree is evaluated from all it's children , so it is a S attributed ,

+ is left associative, So, if the parse tree is evaluate from left to right it will be more accurate
if the string is in the form of a+a+a then we have to evaluate by using left associativity but u made this as right associativity i think thats why u got a diff ans

i got ans as    aa+a+#


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

28,834 questions
36,688 answers
90,626 comments
34,641 users