Question

Consider the augmented grammar given below:

S′→SS→⟨L⟩∣idL→L,S∣S\begin{aligned} S' &\to S \\ S &\to \langle L \rangle \mid \text{id} \\ L &\to L, S \mid S \end{aligned}

Let I0=CLOSURE({[S′→∙S]})I_0 = \text{CLOSURE}(\{[S' \to \bullet S]\}). The number of items in the set GOTO(I0,⟨)\text{GOTO}(I_0, \langle) is: ________.

Official answer and solution
Official answer
5
From
Official GATE 2019 answer key

Solution

Compute the LR(0) kernel items and perform closure to find the number of items in GOTO(I0, '<').

The augmented grammar is:

S′→SS' \to S
S→⟨L⟩∣idS \to \langle L \rangle \mid \text{id}
L→L,S∣SL \to L, S \mid S

The initial state I0=CLOSURE({[S′→∙S]})I_0 = \text{CLOSURE}(\{[S' \to \bullet S]\}) consists of:

  • [S′→∙S][S' \to \bullet S]
  • [S→∙⟨L⟩][S \to \bullet \langle L \rangle]
  • [S→∙id][S \to \bullet \text{id}]

To find GOTO(I0,⟨)\text{GOTO}(I_0, \langle), we take all items in I0I_0 where the dot precedes ⟨\langle and advance the dot past ⟨\langle:

Kernel(GOTO(I0,⟨))={[S→⟨∙L⟩]}\text{Kernel}(\text{GOTO}(I_0, \langle)) = \{[S \to \langle \bullet L \rangle]\}

Now compute CLOSURE({[S→⟨∙L⟩]})\text{CLOSURE}(\{[S \to \langle \bullet L \rangle]\}):

  1. [S→⟨∙L⟩][S \to \langle \bullet L \rangle] (initial kernel item)
  2. Since the dot is before non-terminal LL, add all LL-productions with the dot at the start:
    • [L→∙L,S][L \to \bullet L, S]
    • [L→∙S][L \to \bullet S]
  3. Since the dot in [L→∙S][L \to \bullet S] is before non-terminal SS, add all SS-productions with the dot at the start:
    • [S→∙⟨L⟩][S \to \bullet \langle L \rangle]
    • [S→∙id][S \to \bullet \text{id}]

Listing all distinct items in GOTO(I0,⟨)\text{GOTO}(I_0, \langle):

  1. S→⟨∙L⟩S \to \langle \bullet L \rangle
  2. L→∙L,SL \to \bullet L, S
  3. L→∙SL \to \bullet S
  4. S→∙⟨L⟩S \to \bullet \langle L \rangle
  5. S→∙idS \to \bullet \text{id}

There are exactly 55 items in the set.

Final answer

5

Common trap

Omitting the closure for S after expanding L -> .S.

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

Source

Paper
GATE 2019 Computer Science and Information Technology (CS)
Question
53 of 65, printed as CS Q.43
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.