GATE CSE
First time here? Checkout the FAQ!
x
0 votes
107 views

some one pls tell why it is wrong?

asked in Compiler Design by Active (1.7k points)  
retagged by | 107 views

2 Answers

+3 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 Active (1.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 (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.


Top Users Sep 2017
  1. Habibkhan

    6826 Points

  2. Arjun

    2310 Points

  3. Warrior

    2302 Points

  4. nikunj

    1980 Points

  5. A_i_$_h

    1842 Points

  6. manu00x

    1750 Points

  7. Bikram

    1744 Points

  8. SiddharthMahapatra

    1718 Points

  9. makhdoom ghaya

    1690 Points

  10. rishu_darkshadow

    1672 Points


26,033 questions
33,610 answers
79,659 comments
31,066 users