Skip to content
Official PYQ · 2024

GATE CS 2024 Set 2 Q55 — Parsing (LL, LR)

Explain with AI
Consider the following augmented grammar, which is to be parsed with a SLR\text{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{array}{l} S^{\prime} \rightarrow S \\ S \rightarrow S S|A a| b A c|B c| b B a \\ A \rightarrow d \# \\ B \rightarrow @ \end{array}

Let I0=CLOSURE⁡({S′→∙S})I_{0}=\operatorname{CLOSURE}\left(\left\{S^{\prime} \rightarrow \bullet S\right\}\right). The number of items in the set GOTO⁡(I0,S)\operatorname{GOTO}\left(I_{0}, S\right) is __________.
View worked solution

Answer: 9

To find the number of items in the set GOTO⁡(I0,S)\operatorname{GOTO}(I_0, S), we first determine the items in I0I_0 that have the dot immediately preceding the non-terminal SS.

The initial state I0=CLOSURE⁡({S′→∙S})I_0 = \operatorname{CLOSURE}(\{S' \rightarrow \bullet S\}) contains the following items with ∙S\bullet S:

  • S′→∙SS' \rightarrow \bullet S
  • S→∙SSS \rightarrow \bullet S S

The kernel of GOTO⁡(I0,S)\operatorname{GOTO}(I_0, S) is obtained by shifting the dot over SS in these items:

Kernel={S′→S∙,  S→S∙S}\text{Kernel} = \{S' \rightarrow S \bullet, \; S \rightarrow S \bullet S\}

To find the complete set GOTO⁡(I0,S)\operatorname{GOTO}(I_0, S), we compute the closure of this kernel. Since the item S→S∙SS \rightarrow S \bullet S has the dot before SS, we must add all productions of SS with the dot at the beginning:

  • S→∙SSS \rightarrow \bullet S S
  • S→∙AaS \rightarrow \bullet A a
  • S→∙bAcS \rightarrow \bullet b A c
  • S→∙BcS \rightarrow \bullet B c
  • S→∙bBaS \rightarrow \bullet b B a

Since we added items with ∙A\bullet A and ∙B\bullet B, we must also include the productions of AA and BB with the dot at the beginning:

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

Combining the kernel and closure items, the complete set GOTO⁡(I0,S)\operatorname{GOTO}(I_0, S) consists of the following 99 items:

  1. S′→S∙S' \rightarrow S \bullet
  2. S→S∙SS \rightarrow S \bullet S
  3. S→∙SSS \rightarrow \bullet S S
  4. S→∙AaS \rightarrow \bullet A a
  5. S→∙bAcS \rightarrow \bullet b A c
  6. S→∙BcS \rightarrow \bullet B c
  7. S→∙bBaS \rightarrow \bullet b B a
  8. A→∙d#A \rightarrow \bullet d \#
  9. B→∙@B \rightarrow \bullet @

Thus, the number of items in GOTO⁡(I0,S)\operatorname{GOTO}(I_0, S) is 9.

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

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