GateAI
Parsing

GATE CSE 2021 Set 2 · Q51

NAT2 marksMedium

Time

Consider the following augmented grammar with {#,@,<,>,a,b,c}\{\#, @, \lt, \gt, a, b, c\} as the set of terminals. S′→SS^{\prime} \to S S→S#cSS \to S\#cS S→SSS \to SS S→S@S \to S@ S→<S>S \to \lt S \gt S→aS \to a S→bS \to b S→cS \to c Let I0=CLOSURE({S′→∙S})I_0 = \text{CLOSURE}(\{S^{\prime} \to \bullet S\}). The number of items in the set GOTO(GOTO(I0,<),<)\text{GOTO}(\text{GOTO}(I_0, \lt), \lt) is __________.

Your answerNumerical answer

Enter a value to check

Solution

Step-by-step verified solution

Official answer: 8

Parsing
  1. Find set I0=CLOSURE({S′→∙S})I_0 = \text{CLOSURE}(\{S^{\prime} \to \bullet S\}):

Since the dot is before non-terminal SS, we add all SS-productions with the dot at the beginning:

  • S′→∙SS^{\prime} \to \bullet S

  • S→∙S#cSS \to \bullet S\#cS

  • S→∙SSS \to \bullet SS

  • S→∙S@S \to \bullet S@

  • S→∙<S>S \to \bullet \lt S \gt

  • S→∙aS \to \bullet a

  • S→∙bS \to \bullet b

  • S→∙cS \to \bullet c

  1. Find set I1=GOTO(I0,<)I_1 = \text{GOTO}(I_0, \lt):

In I0I_0, the only item with the dot immediately preceding <\lt is S→∙<S>S \to \bullet \lt S \gt. Advancing the dot gives the kernel item:

S→<∙S>S \to \lt \bullet S \gt

Taking the closure of this kernel item requires adding all productions of SS with the dot at the beginning:

  • S→<∙S>S \to \lt \bullet S \gt (kernel item)

  • S→∙S#cSS \to \bullet S\#cS

  • S→∙SSS \to \bullet SS

  • S→∙S@S \to \bullet S@

  • S→∙<S>S \to \bullet \lt S \gt

  • S→∙aS \to \bullet a

  • S→∙bS \to \bullet b

  • S→∙cS \to \bullet c

  1. Find set I2=GOTO(I1,<)I_2 = \text{GOTO}(I_1, \lt):

In I1I_1, the only item with the dot immediately preceding <\lt is again S→∙<S>S \to \bullet \lt S \gt. Advancing the dot yields the exact same kernel item:

S→<∙S>S \to \lt \bullet S \gt

Taking the closure results in the same 8 items as in I1I_1:

  1. S→<∙S>S \to \lt \bullet S \gt

  2. S→∙S#cSS \to \bullet S\#cS

  3. S→∙SSS \to \bullet SS

  4. S→∙S@S \to \bullet S@

  5. S→∙<S>S \to \bullet \lt S \gt

  6. S→∙aS \to \bullet a

  7. S→∙bS \to \bullet b

  8. S→∙cS \to \bullet c

Thus, the total number of items in GOTO(GOTO(I0,<),<)\text{GOTO}(\text{GOTO}(I_0, \lt), \lt) is 8.

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

How GATE tests Parsing

More from GATE CSE 2021 Set 2

Share this solution

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

GateAI solution cardGATE CSE 2021 Set 2 · Q51 · NAT

Consider the following augmented grammar with {\#, @, , , a, b, c} as the set of terminals. S' → S S → S\#cS S → SS S → S@ S → S S → a S → b S → c Let I0 = CLOSURE({S' → S}). The number of items in the set GOTO(GOTO(I0, ), ) 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.