in Compiler Design retagged by
406 views
0 votes
0 votes

some one pls tell why it is wrong?

in Compiler Design retagged by
406 views

2 Answers

5 votes
5 votes

to derive a^b*c

first we use E->E^E

then        E->E*E

then        E->id

so it print first all id , then * after this ^ will be print.

1 comment

Thank you @ankur.
0
0
3 votes
3 votes

To derive a^b*c, one can use either of the following two derivations:-

Derivation 1:

E ==> E ^ E

   ==> E ^ E * E

   ==> a ^ b * c

Derivation 2:

E ==> E * E

   ==> E ^ E * E

   ==> a ^ b * c

Draw a parse tree for both the derivations and do a postorder traversal of the same. The outputs would be a b ^ c* and a b c * ^. Only one of these is mentioned in the option and so that would be the answer. :)

1 comment

ohk, i got my mistake. what i did was i drew first parse tree and then thought that we could interchange. because of the same precedence, just because of my little laziness. I should had taken into account that that i need to drew it for the above string. very silly mistake.. seriously. Thank you buddy @rahul.
0
0

Related questions