The GATE Grind

GATE 2018 CS – Question 48

Compiler Design · Parsing and Syntax Analysis · 2 marks · Multiple choice

Consider the following parse tree for the expression $a\#b\mathbin{\char36}c\mathbin{\char36}d\#e\#f$, involving two binary operators $\char36$ and `#`.

Which one of the following is correct for the given parse tree?

Diagram for GATE 2018 CS question 48
  1. $\char36$ has higher precedence and is left associative; `#` is right associative
  2. `#` has higher precedence and is left associative; $\char36$ is right associative
  3. $\char36$ has higher precedence and is left associative; `#` is left associative
  4. `#` has higher precedence and is right associative; $\char36$ is left associative

Practise this question in The GATE Grind →

Show answer and explanation

Correct answer: (A) $\char36$ has higher precedence and is left associative; `#` is right associative

Explanation

In the tree, the chain of dollar operators is grouped left to right, so the dollar operator binds tighter than `#` and is left associative. The `#` operators nest to the right, so `#` is right associative.

More Parsing and Syntax Analysis questions

All Parsing and Syntax Analysis questions →