GateAI
Parsing

GATE CSE 2025 Set 2 · Q40

MCQ2 marksMedium

Time

Given a Context-Free Grammar GG as follows: S→Aa∣bAc∣dc∣bdaS \rightarrow Aa \mid bAc \mid dc \mid bda A→dA \rightarrow d Which ONE of the following statements is TRUE?

Select one answerSingle correct

Pick an option to check

Solution

Step-by-step verified solution

Official answer: C) G is LALR(1), not SLR(1)

Parsing

Let us analyze the grammar GG by constructing the LR(0) and LR(1) items:

  1. Augmented Grammar:

    1. S′→SS^{\prime} \rightarrow S

    2. S→AaS \rightarrow Aa

    3. S→bAcS \rightarrow bAc

    4. S→dcS \rightarrow dc

    5. S→bdaS \rightarrow bda

    6. A→dA \rightarrow d

  2. SLR(1) Analysis:

    • FOLLOW(A)\text{FOLLOW}(A): From S→AaS \rightarrow Aa, a∈FOLLOW(A)a \in \text{FOLLOW}(A). From S→bAcS \rightarrow bAc, c∈FOLLOW(A)c \in \text{FOLLOW}(A). Hence, FOLLOW(A)={a,c}\text{FOLLOW}(A) = \{a, c\}.

    • In the initial canonical collection state I0=CLOSURE(S′→⋅S)I_0 = \text{CLOSURE}(S^{\prime} \rightarrow \cdot S): S′→⋅SS→⋅AaS→⋅bAcS→⋅dcS→⋅bdaA→⋅d\begin{aligned} S^{\prime} &\rightarrow \cdot S \\ S &\rightarrow \cdot Aa \\ S &\rightarrow \cdot bAc \\ S &\rightarrow \cdot dc \\ S &\rightarrow \cdot bda \\ A &\rightarrow \cdot d \end{aligned}

    • On input symbol dd from I0I_0, we transition to state I1I_1:

      I1=GOTO(I0,d)={S→d⋅c,  A→d⋅}I_1 = \text{GOTO}(I_0, d) = \{ S \rightarrow d \cdot c, \; A \rightarrow d \cdot \}
    • In state I1I_1, on terminal cc:

      • There is a shift action due to S→d⋅cS \rightarrow d \cdot c.

      • There is a reduce action due to A→d⋅A \rightarrow d \cdot since c∈FOLLOW(A)c \in \text{FOLLOW}(A).

    • This causes a Shift-Reduce (SR) conflict on symbol cc. Therefore, the grammar GG is not SLR(1).

  3. CLR(1) and LALR(1) Analysis:

    • In the LR(1) collection, the lookaheads are computed explicitly:

      • In I0I_0, the item [A→⋅d,a][A \rightarrow \cdot d, a] has lookahead aa because it is generated from [S \rightarrow \cdot Aa, \]$.

      • The item [S \rightarrow \cdot dc, \]yields yields [S \rightarrow d \cdot c, \$]withashifton with a shift on c$.

    • Thus, in the state for GOTO(I0,d)\text{GOTO}(I_0, d):

      • Shift on cc for [S \rightarrow d \cdot c, \]$.

      • Reduce by A→dA \rightarrow d on lookahead aa for [A→d⋅,a][A \rightarrow d \cdot, a].

    • Since the lookaheads for shift and reduce are disjoint ({c}∩{a}=∅\{c\} \cap \{a\} = \emptyset), there is no conflict.

    • Similarly, after transitioning on bb, the state containing [A→⋅d,c][A \rightarrow \cdot d, c] has lookahead cc and [S \rightarrow bd \cdot a, \]hasshifton has shift on a$, which are also conflict-free.

    • No merge conflicts arise when converting to LALR(1).

Hence, GG is LALR(1), not SLR(1), which matches option (C).

Try the question first, then check your work.

Think the official key or this write-up is wrong?

Report error or challenge

Examiner trap

The misconception this question tests

This Parsing previous year question is Q40 of the GATE CSE 2025 Set 2 paper. Find more GATE CSE PYQs on Parsing in Compiler Design, or browse all GATE CSE PYQs.

Free diagnostic

Where do you stand for GATE?

Take the 20-minute diagnostic: the 3 topics that cost you the most marks, and a rank range. Or sit 5 related Parsing PYQs now with no account.

One GATE CSE PYQ every morning

An official question by email at 7 AM IST, with a link to its verified solution. Unsubscribe in one click.

Parsing in GATE CSE

Parsing has 23 GATE CSE PYQs across 16 papers from 2012 to 2026. 11 of them are 2-mark MCQs like this one, and GATE CSE 2025 Set 2 has 2.

How GATE tests Parsing

More from GATE CSE 2025 Set 2

Share this solution

A plain-text card for WhatsApp or Telegram study groups.

GateAI solution cardGATE CSE 2025 Set 2 · Q40 · MCQ

Given a Context-Free Grammar G as follows: S → Aa bAc dc bda A → d Which ONE of the following statements is TRUE?

Topic-wise GATE CS PYQs with verified steps

Independent practice explanation verified by the GateAI team. GATE is conducted by the IITs; question text follows the official paper.