GateAI
Parsing

GATE CSE 2024 Set 2 · Q65

NAT2 marksMedium

Time

Consider the following augmented grammar, which is to be parsed with a SLR parser. The set of terminals is {a,b,c,d,#,@}\{a,b,c,d,\#,@\} S′→SS→SS∣Aa∣bAc∣Bc∣bBaA→d#B→@\begin{aligned} S^{\prime} &\rightarrow S S &\rightarrow SS \mid Aa \mid bAc \mid Bc \mid bBa A &\rightarrow d\# B &\rightarrow @ \end{aligned} Let I0=CLOSURE({S′→∙S})I_0 = CLOSURE(\{S^{\prime} \rightarrow \bullet S\}). The number of items in the set GOTO(I0,S)GOTO(I_0, S) is _______

Your answerNumerical answer

Enter a value to check

Solution

Step-by-step verified solution

Official answer: 9

Parsing

### Step 1: Find the initial state I0=CLOSURE({S′→∙S})I_0 = \text{CLOSURE}(\{S^{\prime} \rightarrow \bullet S\}) Starting with S′→∙SS^{\prime} \rightarrow \bullet S:

  • Add all SS-productions with the dot at the beginning:

    • S→∙SSS \rightarrow \bullet SS

    • S→∙AaS \rightarrow \bullet Aa

    • S→∙bAcS \rightarrow \bullet bAc

    • S→∙BcS \rightarrow \bullet Bc

    • S→∙bBaS \rightarrow \bullet bBa

  • From S→∙AaS \rightarrow \bullet Aa, add AA-productions:

    • A→∙d#A \rightarrow \bullet d\#

  • From S→∙BcS \rightarrow \bullet Bc, add BB-productions:

    • B→∙@B \rightarrow \bullet @

### Step 2: Compute GOTO(I0,S)\text{GOTO}(I_0, S) Find all items in I0I_0 where the dot is immediately before SS, and advance the dot past SS:

  1. From S′→∙SS^{\prime} \rightarrow \bullet S, we get the kernel item: S′→S∙S^{\prime} \rightarrow S \bullet

  2. From S→∙SSS \rightarrow \bullet SS, we get the kernel item: S→S∙SS \rightarrow S \bullet S

### Step 3: Compute the closure of this kernel set Kernel items:

  1. S′→S∙S^{\prime} \rightarrow S \bullet

  2. S→S∙SS \rightarrow S \bullet S

Since item 2 has the dot before non-terminal SS, add all SS-productions with the dot at the beginning:

  1. S→∙SSS \rightarrow \bullet SS

  2. S→∙AaS \rightarrow \bullet Aa

  3. S→∙bAcS \rightarrow \bullet bAc

  4. S→∙BcS \rightarrow \bullet Bc

  5. S→∙bBaS \rightarrow \bullet bBa

From item 4 (S→∙AaS \rightarrow \bullet Aa), the dot is before AA, so add AA-productions:

  1. A→∙d#A \rightarrow \bullet d\#

From item 6 (S→∙BcS \rightarrow \bullet Bc), the dot is before BB, so add BB-productions:

  1. B→∙@B \rightarrow \bullet @

No other non-terminals have a dot immediately before them in newly added items.

### Step 4: Count the items The total number of items in the set GOTO(I0,S)\text{GOTO}(I_0, S) is 9.

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 Q65 of the GATE CSE 2024 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. 3 of them are 2-mark NAT questions like this one, and GATE CSE 2024 Set 2 has 2.

How GATE tests Parsing

More from GATE CSE 2024 Set 2

Share this solution

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

GateAI solution cardGATE CSE 2024 Set 2 · Q65 · NAT

Consider the following augmented grammar, which is to be parsed with a SLR parser. The set of terminals is {a,b,c,d,\#,@} S' &→ S S &→ SS Aa bAc Bc bBa A &→ d\# B &→ @ Let I0 = CLOSURE({S' → S}). The number of items in the set GOTO(I0, S) is …

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.