The GATE Grind

GATE 2011 CS (CS1) – Question 37

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

Binary operator ↓ has lower precedence than ↑. Operator ↑ is right-associative and ↓ left-associative. Which displayed parse tree represents 7↓3↑4↑3↓2?

Diagram for GATE 2011 CS (CS1) question 37
  1. Tree A
  2. Tree B
  3. Tree C
  4. Tree D

Practise this question in The GATE Grind →

Show answer and explanation

Correct answer: (B) Tree B

Explanation

First group the higher-precedence right-associative portion as 3↑(4↑3). Then left-associate the lower-precedence operators: (7↓(3↑(4↑3)))↓2. Its root is ↓ with right leaf two; the left child is ↓ joining seven to that nested ↑ tree. This is B.

More Parsing and Syntax Analysis questions

All Parsing and Syntax Analysis questions →