Skip to content
Official PYQ · 2025

GATE CS 2025 Set 2 Q30 — Parsing (LL, LR)

Explain with AI

​​Given a Context-Free Grammar G\text{G} as follows:
S→Aa∣bAc∣dc∣bdaA→d\begin{array}{l} S \rightarrow A a|b A c| d c \mid b d a \\ A \rightarrow d \end{array}

Which ONE of the following statements is TRUE?

Choose one option
View worked solution

Answer: C

To determine the parsing class of the grammar GG, we analyze the LR(0)\text{LR}(0) and LR(1)\text{LR}(1) states.

1. SLR(1) Analysis:
First, let's compute the Follow\text{Follow} set of the non-terminal AA: Follow(A)={a,c}\text{Follow}(A) = \{a, c\} Consider the LR(0)\text{LR}(0) state II reached after scanning the terminal dd from the start state: I={S→d.c,  A→d.}I = \{S \rightarrow d.c, \; A \rightarrow d.\} In this state:

  • There is a shift action on terminal cc (from S→d.cS \rightarrow d.c).
  • There is a reduce action for A→dA \rightarrow d on any terminal in Follow(A)={a,c}\text{Follow}(A) = \{a, c\}.
Since c∈Follow(A)c \in \text{Follow}(A), we have a Shift-Reduce conflict on terminal cc. Thus, the grammar is not SLR(1)\text{SLR}(1).

2. LR(1) and LALR(1) Analysis:
Let's construct the corresponding LR(1)\text{LR}(1) states to see if lookaheads resolve the conflict:

  • From the path S→dcS \rightarrow d c, we get the state: I1={S→d.c,  [$],A→d.,  [a]}I_1 = \{S \rightarrow d.c, \; [\$], \quad A \rightarrow d., \; [a]\} Here, the shift is on cc and the reduce is on aa. There is no conflict.
  • From the path S→bdaS \rightarrow b d a, we get the state: I2={S→bd.a,  [$],A→d.,  [c]}I_2 = \{S \rightarrow b d.a, \; [\$], \quad A \rightarrow d., \; [c]\} Here, the shift is on aa and the reduce is on cc. There is no conflict.
Since these two states have different cores (core(I1)={S→d.c,A→d.}\text{core}(I_1) = \{S \rightarrow d.c, A \rightarrow d.\} and core(I2)={S→bd.a,A→d.}\text{core}(I_2) = \{S \rightarrow b d.a, A \rightarrow d.\}), they are not merged during LALR(1)\text{LALR}(1) construction. Thus, the grammar is LALR(1)\text{LALR}(1).

Therefore, GG is LALR(1)\text{LALR}(1) but not SLR(1)\text{SLR}(1).

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

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