0 votes
114 views

some one pls tell why it is wrong?

asked
retagged | 114 views

## 2 Answers

+4 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.

answered by Loyal (4.5k points)
Thank you @ankur.
+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. :)

answered by (87 points)
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.

+1 vote
1 answer
1
0 votes
1 answer
2
+1 vote
0 answers
3