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

some one pls tell why it is wrong?

asked in Compiler Design by Active (1.7k points)   | 97 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.3k 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 May 2017
  1. akash.dinkar12

    3302 Points

  2. pawan kumarln

    1776 Points

  3. Bikram

    1646 Points

  4. sh!va

    1640 Points

  5. Arjun

    1396 Points

  6. Devshree Dubey

    1272 Points

  7. Debashish Deka

    1142 Points

  8. Angkit

    1044 Points

  9. LeenSharma

    1000 Points

  10. Arunav Khare

    754 Points

Monthly Topper: Rs. 500 gift card
Top Users 2017 May 22 - 28
  1. Bikram

    732 Points

  2. Arnab Bhadra

    402 Points

  3. pawan kumarln

    402 Points

  4. bharti

    304 Points

  5. LeenSharma

    238 Points


22,823 questions
29,142 answers
65,209 comments
27,666 users