Question

Consider the following augmented grammar with {#,@,<,>,a,b,c}\{\#, @, <, >, a, b, c\} as the set of terminals.

S′→SS→S#cSS→SSS→S@S→<S>S→aS→bS→c\begin{aligned} S' &\to S \\ S &\to S \# c S \\ S &\to S S \\ S &\to S @ \\ S &\to {<} S {>} \\ S &\to a \\ S &\to b \\ S &\to c \end{aligned}

Let I0=CLOSURE({S′→⋅S})I_0 = \text{CLOSURE}(\{S' \to \cdot S\}). The number of items in the set GOTO(GOTO(I0,<),<)\text{GOTO}(\text{GOTO}(I_0, <), <) is ______.

Official answer and solution
Official answer
8
From
Official GATE 2021 answer key

Solution

Trace the LR(0) item set closures and GOTO transitions starting from state I0I_0.

The augmented grammar has start symbol S′S' and non-terminal SS with productions:

  1. S′→SS' \to S
  2. S→S#cSS \to S \# c S
  3. S→SSS \to S S
  4. S→S@S \to S @
  5. S→<S>S \to {<} S {>}
  6. S→aS \to a
  7. S→bS \to b
  8. S→cS \to c

State I0=CLOSURE({S′→⋅S})I_0 = \text{CLOSURE}(\{S' \to \cdot S\}).
Taking the transition on terminal '<':

I1=GOTO(I0,<)I_1 = \text{GOTO}(I_0, <)

Among the items in I0I_0, only S→⋅<S>S \to \cdot {<} S {>} has the dot immediately before '<'. Moving the dot gives the kernel item:

Kernel(I1)={S→<⋅S>}\text{Kernel}(I_1) = \{S \to {<} \cdot S {>}\}

Since the dot is before non-terminal SS, the closure adds all productions of SS with the dot at the beginning:

  • S→⋅S#cSS \to \cdot S \# c S
  • S→⋅SSS \to \cdot S S
  • S→⋅S@S \to \cdot S @
  • S→⋅<S>S \to \cdot {<} S {>}
  • S→⋅aS \to \cdot a
  • S→⋅bS \to \cdot b
  • S→⋅cS \to \cdot c

Next, compute I2=GOTO(I1,<)I_2 = \text{GOTO}(I_1, <):
Among all items in I1I_1, the only item with the dot before '<' is again S→⋅<S>S \to \cdot {<} S {>}.
Moving the dot past '<' gives the kernel item:

Kernel(I2)={S→<⋅S>}\text{Kernel}(I_2) = \{S \to {<} \cdot S {>}\}

Taking the closure of I2I_2 adds the same 7 initial items for SS with the dot at the front:

  1. S→<⋅S>S \to {<} \cdot S {>} (kernel item)
  2. S→⋅S#cSS \to \cdot S \# c S
  3. S→⋅SSS \to \cdot S S
  4. S→⋅S@S \to \cdot S @
  5. S→⋅<S>S \to \cdot {<} S {>}
  6. S→⋅aS \to \cdot a
  7. S→⋅bS \to \cdot b
  8. S→⋅cS \to \cdot c

Counting all distinct items in I2I_2, we have 1+7=81 + 7 = 8 items.

Final answer

8

The answer is the one in the official GATE answer key. The solution is this site's own explanation.

Source

Paper
GATE 2021 Computer Science and Information Technology - Session 2 (CS2)
Question
61 of 65, printed as CS Q.51
Section
Computer Science and Information Technology

Report an error in this question

GATE questions are the work of the organising institutes. This site is independent and is not affiliated with them.