97 views

some one pls tell why it is wrong?

asked | 97 views

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 Active (1.3k points)
Thank you @ankur.

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 (57 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