Skip to content
Official PYQ · 2019

GATE CS 2019 Q43 — Parsing (LL, LR)

Explain with AI

Consider the augmented grammar given below:

  • S’→SS’ \rightarrow S
  • S→⟨L⟩∣idS \rightarrow \langle L \rangle \mid id
  • L→L,S∣SL \rightarrow L, S \mid S

Let I0=CLOSURE({[S’→⋅S]}).I_0 = \text{CLOSURE} (\{[S’ \rightarrow \cdot S ]\}). The number of items in the set GOTO(I0,⟨ )\text{GOTO} (I_0, \langle \: ) is______

View worked solution

Answer: 5

To find the number of items in the set GOTO(I0,⟨)\text{GOTO}(I_0, \langle), we first construct the initial state I0I_0 and then compute the transition on the terminal symbol ⟨\langle.

Step 1: Compute the initial state I0I_0

The state I0I_0 is defined as CLOSURE({[S’→⋅S]})\text{CLOSURE}(\{[S’ \rightarrow \cdot S ]\}).

I0={S′→⋅S,S→⋅⟨L⟩,S→⋅id}\begin{align*} I_0 = \{& S' \rightarrow \cdot S, \\ & S \rightarrow \cdot \langle L \rangle, \\ & S \rightarrow \cdot id \} \end{align*}

Step 2: Compute GOTO(I0,⟨)\text{GOTO}(I_0, \langle)

The GOTO\text{GOTO} operation is defined as the closure of the set of items obtained by shifting the dot past the symbol ⟨\langle in I0I_0:

GOTO(I0,⟨)=CLOSURE({[S→⟨⋅L⟩]})\text{GOTO}(I_0, \langle) = \text{CLOSURE}(\{[S \rightarrow \langle \cdot L \rangle]\})

Now, we compute the closure of this kernel item:

  1. Add the kernel item: S→⟨⋅L⟩S \rightarrow \langle \cdot L \rangle
  2. Since the dot is before the non-terminal LL, we add the productions of LL with the dot at the beginning: L→⋅L,SL \rightarrow \cdot L, S L→⋅SL \rightarrow \cdot S
  3. Since the dot is before the non-terminal SS in the item L→⋅SL \rightarrow \cdot S, we add the productions of SS with the dot at the beginning: S→⋅⟨L⟩S \rightarrow \cdot \langle L \rangle S→⋅idS \rightarrow \cdot id

Combining all these, the set of items in GOTO(I0,⟨)\text{GOTO}(I_0, \langle) is:

1.S→⟨⋅L⟩2.L→⋅L,S3.L→⋅S4.S→⋅⟨L⟩5.S→⋅id\begin{align*} 1. & \quad S \rightarrow \langle \cdot L \rangle \\ 2. & \quad L \rightarrow \cdot L, S \\ 3. & \quad L \rightarrow \cdot S \\ 4. & \quad S \rightarrow \cdot \langle L \rangle \\ 5. & \quad S \rightarrow \cdot id \end{align*}

Thus, the total number of items in the set GOTO(I0,⟨)\text{GOTO}(I_0, \langle) is 5.

Free practice · Your answers on this page are not saved.

Published
Report a correction
Keep exploringMore Parsing (LL, LR) questions