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

Consider the following translation scheme. 

S→ER

R→∗E{print(′∗′);}R∣ε

E→F+E{print(′+′);}∣F

F→S∣id{print(id.value);}

Here id is a token that represents an integer and id.value represents the corresponding integer value. For an input '2 * 3 + 4',  this translation scheme prints 

(A) 2 * 3 + 4  
(B) 2 * +3 4  
(C) 2 3 * 4 + 
(D) 2 3 4+*

My try: I figured out the following tree and found the answer to be (C) i.e. 23*4+. But the given answer in (D). 
Am I missing something?

asked in Compiler Design by Active (1.5k points)   | 120 views

i think D. is ans since + having higher precedency over * ...In ur tree * having higher precedence than + ...

The precedence is enforced by grammar, so if I am able to draw the tree using the grammar shouldn't that be correct?
My understanding is that if + has higher precedence than * then using that using no tree should give higher precedence to *. Is that wrong to assume?
Yes we should not assume that

2 Answers

0 votes
answered by Loyal (4.5k points)  
0 votes
Yes , Answer is D
answered by (499 points)  
Top Users Jan 2017
  1. Debashish Deka

    8126 Points

  2. sudsho

    5042 Points

  3. Habibkhan

    4706 Points

  4. Vijay Thakur

    4458 Points

  5. Bikram

    4348 Points

  6. saurabh rai

    4212 Points

  7. Arjun

    4010 Points

  8. santhoshdevulapally

    3722 Points

  9. GateSet

    3292 Points

  10. Sushant Gokhale

    3286 Points

Monthly Topper: Rs. 500 gift card

19,122 questions
24,033 answers
52,725 comments
20,276 users