The Gateway to Computer Science Excellence
First time here? Checkout the FAQ!
+1 vote

Consider the following translation scheme. 





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.9k points) | 266 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

3 Answers

0 votes
answered by Loyal (4.8k points)
0 votes
Yes , Answer is D
answered by Active (1.1k points)
0 votes
This grammer is actually left recursive removed grammer of S-->E*E|E  E-->F+E|F and so on. So + have highest precedence than * . So although the grammer give two parse tree for the given i/p string.. The correct ans should be which allow + have higher precedence than * .. i.e Option D.
answered by Active (2.3k points)

Quick search syntax
tags tag:apple
author user:martin
title title:apple
content content:apple
exclude -tag:apple
force match +apple
views views:100
score score:10
answers answers:2
is accepted isaccepted:true
is closed isclosed:true

28,834 questions
36,688 answers
34,641 users