Question
Consider two binary operators '' and '' with the precedence of operator being lower than that of operator . Operator is right associative while operator is left associative. Which one of the following represents the parse tree for expression ?
Official answer and solution
- Official answer
- B
- From
- Official GATE 2011 answer key
Solution
Apply operator precedence and associativity to construct the unique parse tree for the expression.
- The expression to parse is .
- Precedence rule: has higher precedence than , so subexpressions involving bind tighter.
- Associativity rule for : Right-associative. The subexpression parenthesizes as .
- Associativity rule for : Left-associative with lower precedence. The full expression parenthesizes as:
- In the parse tree:
- The root is the lowest-precedence leftmost operator with left subtree and right child .
- The left subtree has root with left child and right child .
- This matches parse tree B exactly.
Final answer
B
The answer is the one in the official GATE answer key. The solution is this site's own explanation.
Source
- Paper
- GATE 2011 Computer Science and Information Technology (CS)
- Question
- 27 of 65, printed as CS Q.27
- Section
- Computer Science and Information Technology
Report an error in this question
GATE questions are the work of the organising institutes. This site is independent and is not affiliated with them.