Question

Consider two binary operators '↑\uparrow' and '↓\downarrow' with the precedence of operator ↓\downarrow being lower than that of 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↓3↑4↑3↓2)(7 \downarrow 3 \uparrow 4 \uparrow 3 \downarrow 2)?

Choose one option
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.

  1. The expression to parse is 7↓3↑4↑3↓27 \downarrow 3 \uparrow 4 \uparrow 3 \downarrow 2.
  1. Precedence rule: ↑\uparrow has higher precedence than ↓\downarrow, so subexpressions involving ↑\uparrow bind tighter.
  1. Associativity rule for ↑\uparrow: Right-associative. The subexpression 3↑4↑33 \uparrow 4 \uparrow 3 parenthesizes as (3↑(4↑3))(3 \uparrow (4 \uparrow 3)).
  1. Associativity rule for ↓\downarrow: Left-associative with lower precedence. The full expression parenthesizes as:
((7↓(3↑(4↑3)))↓2)((7 \downarrow (3 \uparrow (4 \uparrow 3))) \downarrow 2)
  1. In the parse tree:
  • The root is the lowest-precedence leftmost operator ↓\downarrow with left subtree (7↓(3↑(4↑3)))(7 \downarrow (3 \uparrow (4 \uparrow 3))) and right child 22.
  • The left subtree has root ↓\downarrow with left child 77 and right child (3↑(4↑3))(3 \uparrow (4 \uparrow 3)).
  • 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.