Skip to content
Official PYQ · 2010

GATE CS 2010 Q38 — Parsing (LL, LR)

Explain with AI

The grammar S→aSa∣bS∣cS \to aSa \mid bS \mid c is 

Choose one option
View worked solution

Answer: C

To determine the classification of the grammar S→aSa∣bS∣cS \to aSa \mid bS \mid c, we can analyze its LL(1) and LR(1) properties.

1. Checking for LL(1)

A grammar is LL(1) if, for every non-terminal AA with multiple productions A→α1∣α2∣⋯∣αnA \to \alpha_1 \mid \alpha_2 \mid \dots \mid \alpha_n:

  1. The FIRST\text{FIRST} sets of all alternatives are pairwise disjoint.
  2. If any production can derive the empty string ϵ\epsilon, its FIRST\text{FIRST} set must be disjoint from the FOLLOW\text{FOLLOW} set of AA.

Let's find the FIRST\text{FIRST} sets for the three alternatives of SS:

  • FIRST(aSa)={a}\text{FIRST}(aSa) = \{a\}
  • FIRST(bS)={b}\text{FIRST}(bS) = \{b\}
  • FIRST(c)={c}\text{FIRST}(c) = \{c\}

Since the sets {a}\{a\}, {b}\{b\}, and {c}\{c\} are pairwise disjoint, and there are no ϵ\epsilon-productions, there are no FIRST/FIRST or FIRST/FOLLOW conflicts. Therefore, the grammar is LL(1).

2. Checking for LR(1)

A fundamental theorem in compiler design states that every LL(1) grammar is also an LR(1) grammar (i.e., LL(1)⊂LR(1)\text{LL}(1) \subset \text{LR}(1)). Since the grammar is LL(1), it is guaranteed to be LR(1).

Thus, the grammar is both LL(1) and LR(1).

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

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