edited by
7,052 views
38 votes
38 votes

Consider two binary operators $\text{‘} \uparrow \text{’}$  and $\text{‘} \downarrow \text{’}$ with the precedence of operator $\downarrow$ being lower than that of the operator $\uparrow$. Operator $\uparrow$ is right associative while operator $\downarrow$ is left associative. Which one of the following represents the parse tree for expression $(7 \downarrow 3 \uparrow 4 \uparrow 3 \downarrow 2)$



  1.  


  2.  


edited by

4 Answers

Best answer
51 votes
51 votes

Answer is B.

To make the parse tree start compiling the identifiers into blocks based on associativity and precedence.

Grouping: $(7 \downarrow (3 \uparrow(4 \uparrow 3)))  \downarrow2 $

Tree can be made by opening inner braces and move towards braces.

edited by
12 votes
12 votes
Higher precedence operator comes at lowest level in the tree.And and if there is left recursion on operator then it is left assosiative ,same if right recursive then it is right associative. Scince tree is given it can be easily seen.As B) is correct.
1 votes
1 votes

Higher precedence operators comes at the bottom

↑ has higher precedence so  $3↑4↑3$ will be evaluated first.As ↑ is left associative so $4↑3$ will be evaluated so $4↑3$ should be at last level then 

$3↑(4↑3)$

↓ i this is left associative so left operand i.e & will be evaluated 

$(7↓(3↑(4↑3))$

and then 2 

$((7↓(3↑(4↑3))↓2)$

which gives option (B)

 

0 votes
0 votes
answer - B
Answer:

Related questions

37 votes
37 votes
2 answers
2
44 votes
44 votes
3 answers
3
go_editor asked Sep 29, 2014
17,148 views
In a compiler, keywords of a language are recognized duringparsing of the programthe code generationthe lexical analysis of the programdataflow analysis