GateAI
Parsing

GATE CSE 2022 · Q29

NAT1 markEasy

Time

Consider the augmented grammar with {+,∗,(,),id}\{+, *, (, ), id\} as the set of terminals. S′→SS^{\prime} \rightarrow S S→S+R∣RS \rightarrow S + R \mid R R→R∗P∣PR \rightarrow R * P \mid P P→(S)∣idP \rightarrow (S) \mid id If I0I_0 is the set of two LR(0)LR(0) items {[S′→S.],[S→S.+R]}\{[S^{\prime} \rightarrow S.], [S \rightarrow S. + R]\}, then goto(closure(I0),+)goto(closure(I_0), +) contains exactly ________ items.

Your answerNumerical answer

Enter a value to check

Solution

Step-by-step verified solution

Official answer: 5

Parsing

Given the item set I0={[S′→S.],[S→S.+R]}I_0 = \{[S^{\prime} \rightarrow S.], [S \rightarrow S. + R]\}.

Since no item in I0I_0 has the dot immediately preceding a non-terminal, closure(I0)=I0closure(I_0) = I_0.

To compute $goto(closure(I_0), +)$:

  1. Shift the dot over ++ in the item [S→S.+R][S \rightarrow S. + R]:

    {[S→S+.R]}\{[S \rightarrow S + . R]\}
  2. Find the closure of this item:

    • Since the dot is before RR, add all productions of RR with the dot at the beginning:

      [R→.R∗P][R \rightarrow . R * P]
      [R→.P][R \rightarrow . P]
    • Since the dot in [R→.P][R \rightarrow . P] is before non-terminal PP, add all productions of PP with the dot at the beginning:

      [P→.(S)][P \rightarrow . (S)]
      [P→.id][P \rightarrow . id]

Collecting all items, goto(closure(I0),+)goto(closure(I_0), +) consists of the following 55 items:

  1. [S→S+.R][S \rightarrow S + . R]

  2. [R→.R∗P][R \rightarrow . R * P]

  3. [R→.P][R \rightarrow . P]

  4. [P→.(S)][P \rightarrow . (S)]

  5. [P→.id][P \rightarrow . id]

Hence, the set contains exactly 5 items.

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 Q29 of the GATE CSE 2022 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. This is the only 1-mark NAT question among them, and GATE CSE 2022 has 2.

How GATE tests Parsing

More from GATE CSE 2022

Share this solution

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

GateAI solution cardGATE CSE 2022 · Q29 · NAT

Consider the augmented grammar with {+, *, (, ), id} as the set of terminals. S' → S S → S + R R R → R * P P P → (S) id If I0 is the set of two LR(0) items {[S' → S.], [S → S. + R]}, then goto(closure(I0), +) contains exactly … items.

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.