Skip to content
Official PYQ · 2014

GATE CS 2014 Set 2 Q17 — Parsing (LL, LR)

Explain with AI

Consider the grammar defined by the following production rules, with two operators ∗∗ and ++

  • S → T∗PS\:\to\:T∗P
  • T → U∣T∗UT\:\to\:U\mid T∗U
  • P → Q+P∣QP\:\to\:Q+P\mid Q
  • Q →IdQ\:\to Id
  • U →IdU\:\to Id

Which one of the following is TRUE?

Choose one option
View worked solution

Answer: B

To determine the associativity of the operators ++ and ∗*, we analyze the recursive structure of the production rules defining them:

  1. Associativity of ∗* (defined by TT):

    The production rule is:

    T→T∗U∣UT \to T * U \mid U

    This is a left-recursive production because the non-terminal on the left-hand side (TT) appears as the leftmost symbol on the right-hand side of the recursive alternative (T∗UT * U). Left-recursion groups operands from left to right, meaning the operator ∗* is left-associative.

  2. Associativity of ++ (defined by PP):

    The production rule is:

    P→Q+P∣QP \to Q + P \mid Q

    This is a right-recursive production because the non-terminal on the left-hand side (PP) appears as the rightmost symbol on the right-hand side of the recursive alternative (Q+PQ + P). Right-recursion groups operands from right to left, meaning the operator ++ is right-associative.

Thus, ++ is right-associative, while ∗* is left-associative.

Free practice · Your answers on this page are not saved.

Published
Report a correction
Keep exploringMore Parsing (LL, LR) questions