GateAI
Parsing

GATE CSE 2026 Set 2 · Q41

MCQ2 marksMedium

Time

Consider the canonical LR(0)LR(0) parsing of the grammar below using terminals {a,b,c}\{a, b, c\} and non-terminals {A,B,C,S}\{A, B, C, S\} with SS as the start symbol. S→ACBS \rightarrow ACB A→aA∣ϵA \rightarrow aA \mid \epsilon C→cC∣ϵC \rightarrow cC \mid \epsilon B→bB∣bB \rightarrow bB \mid b Which one of the following options gives the number of shift-reduce conflicts that will occur in the LR(0)LR(0) ACTION table?

Select one answerSingle correct

Pick an option to check

Solution

Step-by-step verified solution

Official answer: D) 5

Parsing

To find the number of shift-reduce (S-R) conflicts in the canonical LR(0)LR(0) ACTION table, we first construct the augmented grammar and its canonical collection of LR(0)LR(0) items:

Augmented Grammar:

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

  2. S→ACBS \rightarrow ACB

  3. A→aAA \rightarrow aA

  4. A→ϵA \rightarrow \epsilon

  5. C→cCC \rightarrow cC

  6. C→ϵC \rightarrow \epsilon

  7. B→bBB \rightarrow bB

  8. B→bB \rightarrow b

Canonical Collection of LR(0)LR(0) Sets of Items:

  • State I0I_0:

    CLOSURE({S′→.S})={S′→.S, S→.ACB, A→.aA, A→.}\text{CLOSURE}(\{S^{\prime} \rightarrow .S\}) = \{S^{\prime} \rightarrow .S,\ S \rightarrow .ACB,\ A \rightarrow .aA,\ A \rightarrow .\}
    • Shift on terminal aa (from A→.aAA \rightarrow .aA).

    • Reduce on all terminals including aa (from A→.A \rightarrow .).

    • S-R conflict #1:(I0,a)(I_0, a)

  • State I1=GOTO(I0,S)I_1 = \text{GOTO}(I_0, S): {S′→S.}\{S^{\prime} \rightarrow S.\} (Accept state, no conflict)

  • State I2=GOTO(I0,A)I_2 = \text{GOTO}(I_0, A):

    {S→A.CB, C→.cC, C→.}\{S \rightarrow A.CB,\ C \rightarrow .cC,\ C \rightarrow .\}
    • Shift on terminal cc (from C→.cCC \rightarrow .cC).

    • Reduce on all terminals including cc (from C→.C \rightarrow .).

    • S-R conflict #2:(I2,c)(I_2, c)

  • State I3=GOTO(I2,C)I_3 = \text{GOTO}(I_2, C):

    {S→AC.B, B→.bB, B→.b}\{S \rightarrow AC.B,\ B \rightarrow .bB,\ B \rightarrow .b\}

    (No reduce items, so no S-R conflict)

  • State I4=GOTO(I2,c)I_4 = \text{GOTO}(I_2, c):

    {C→c.C, C→.cC, C→.}\{C \rightarrow c.C,\ C \rightarrow .cC,\ C \rightarrow .\}
    • Shift on terminal cc (from C→.cCC \rightarrow .cC).

    • Reduce on all terminals including cc (from C→.C \rightarrow .).

    • S-R conflict #3:(I4,c)(I_4, c)

  • State I5=GOTO(I0,a)I_5 = \text{GOTO}(I_0, a):

    {A→a.A, A→.aA, A→.}\{A \rightarrow a.A,\ A \rightarrow .aA,\ A \rightarrow .\}
    • Shift on terminal aa (from A→.aAA \rightarrow .aA).

    • Reduce on all terminals including aa (from A→.A \rightarrow .).

    • S-R conflict #4:(I5,a)(I_5, a)

  • State I6=GOTO(I3,B)I_6 = \text{GOTO}(I_3, B): {S→ACB.}\{S \rightarrow ACB.\} (Reduce item only, no conflict)

  • State I7=GOTO(I3,b)I_7 = \text{GOTO}(I_3, b):

    {B→b.B, B→b., B→.bB, B→.b}\{B \rightarrow b.B,\ B \rightarrow b.,\ B \rightarrow .bB,\ B \rightarrow .b\}
    • Shift on terminal bb (from B→.bB, B→.bB \rightarrow .bB,\ B \rightarrow .b).

    • Reduce on all terminals including bb (from B→b.B \rightarrow b.).

    • S-R conflict #5:(I7,b)(I_7, b)

  • State I8=GOTO(I4,C)I_8 = \text{GOTO}(I_4, C):{C→cC.}\{C \rightarrow cC.\}

  • State I9=GOTO(I5,A)I_9 = \text{GOTO}(I_5, A):{A→aA.}\{A \rightarrow aA.\}

  • State I10=GOTO(I7,B)I_{10} = \text{GOTO}(I_7, B):{B→bB.}\{B \rightarrow bB.\}

Thus, there are a total of 5 shift-reduce conflicts in the LR(0)LR(0) ACTION table:

  1. In state I0I_0 on terminal aa

  2. In state I2I_2 on terminal cc

  3. In state I4I_4 on terminal cc

  4. In state I5I_5 on terminal aa

  5. In state I7I_7 on terminal bb

Hence, the correct option is (D).

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 Q41 of the GATE CSE 2026 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 it is the only one in GATE CSE 2026 Set 2.

How GATE tests Parsing

More from GATE CSE 2026 Set 2

Share this solution

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

GateAI solution cardGATE CSE 2026 Set 2 · Q41 · MCQ

Consider the canonical LR(0) parsing of the grammar below using terminals {a, b, c} and non-terminals {A, B, C, S} with S as the start symbol. S → ACB A → aA C → cC B → bB b Which one of the following options gives the number of shift-reduce conflicts that will occur in the LR(0) ACTION table?

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.