Skip to main content

GATE CSE 2025Compiler Design › Grammars & ParsingVerified

GATE CSE 2025 PYQ: ​​Given a Context-Free Grammar G \text{G} G as follows: S → A a ∣ b A c ∣ d c ∣ b d a A → d \begin{array}{l}…

​​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?

  1. A
    G\text{G} is neither LALR⁡(1)\operatorname{LALR}(1) nor SLR⁡(1)\operatorname{SLR}(1)
  2. B
    G\text{G} is CLR(1)\text{CLR(1)}, not LALR(1)\text{LALR(1)}
  3. C
    G\text{G} is LALR⁡(1),not⁡SLR⁡(1)\operatorname{LALR}(1), \operatorname{not} \operatorname{SLR}(1)
    Correct answer
  4. D
    G\text{G} is LALR⁡(1)\operatorname{LALR}(1), also SLR⁡(1)\operatorname{SLR}(1)

Answer

(C) G \text{G} G is LALR ⁡ ( 1 ) , not ⁡ SLR ⁡ ( 1 ) \operatorname{LALR}(1), \operatorname{not} \operatorname{SLR}(1) LALR ( 1 ) , not SLR ( 1 )

Approach

Build the LR(0) automaton and compute FOLLOW(A). The only possible conflict arises from the item A -> d. in the state reached after shifting d from the initial state, because SLR(1) uses FOLLOW(A) = {a, c}. Then compare with the more precise LR(1)/LALR(1) lookaheads to see whether that conflict survives.

The SLR(1) table contains a shift-reduce conflict at the state reached after shifting d from the start state: on symbol c it must both shift for S -> d . c and reduce A -> d because c ∈ FOLLOW(A). Canonical LR(1) uses the exact lookahead a in that state, and LALR(1) does not merge this state with any other state having the same core, so the conflict disappears. Thus G is LALR(1), not SLR(1).

Reviewed by GateIQ Editorial Team: IIT & IISc Alumni.