The GATE Grind

GATE 2014 CS (CS2) – Question 27

Compiler Design · Parsing and Syntax Analysis · 1 mark · Multiple choice

Grammar: S → T * P; T → U | T * U; P → Q + P | Q; Q → Id; U → Id. Which is TRUE?

  1. + is left associative; * is right associative
  2. + is right associative; * is left associative
  3. Both + and * are right associative
  4. Both + and * are left associative

Practise this question in The GATE Grind →

Show answer and explanation

Correct answer: (B) + is right associative; * is left associative

Explanation

T→T*U is left-recursive, grouping repeated multiplication to the left. P→Q+P is right-recursive, grouping repeated addition to the right. Hence **+right-associative,*left-associative,B**. The outer S production does not reverse these repeated-operator groupings.