Skip to content
Official PYQ · 2021

GATE CS 2021 Set 2 Q51 — Parsing (LL, LR)

Explain with AI
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{array}{l} S’ \rightarrow S \\ S \rightarrow S \# cS \\ S \rightarrow SS \\ S \rightarrow S @ \\ S \rightarrow < S > \\ S \rightarrow a \\ S \rightarrow b \\ S \rightarrow c \end{array}Let I0=CLOSURE({S’→∙S})I_0 = \text{CLOSURE}(\{S’ \rightarrow \bullet S\}). The number of items in the set GOTO(GOTO(I0<),<)\text{GOTO(GOTO}(I_0<), <) is ___________
View worked solution

Answer: 8 : 8

To find the number of items in the set GOTO(GOTO(I0,<),<)\text{GOTO}(\text{GOTO}(I_0, <), <), we compute the sets step-by-step.

Step 1: Find I0=CLOSURE({S’→∙S})I_0 = \text{CLOSURE}(\{S’ \rightarrow \bullet S\})

Expanding the closure of the start item, we get:

I0={S’→∙S,S→∙S#cS,S→∙SS,S→∙S@,S→∙<S>,S→∙a,S→∙b,S→∙c}\begin{aligned}I_0 = \{ & S’ \rightarrow \bullet S, \\ & S \rightarrow \bullet S \# cS, \\ & S \rightarrow \bullet SS, \\ & S \rightarrow \bullet S @, \\ & S \rightarrow \bullet < S >, \\ & S \rightarrow \bullet a, \\ & S \rightarrow \bullet b, \\ & S \rightarrow \bullet c \}\end{aligned}

Step 2: Find I1=GOTO(I0,<)I_1 = \text{GOTO}(I_0, <)

The only item in I0I_0 with the dot before the terminal << is S→∙<S>S \rightarrow \bullet < S >. Moving the dot over << gives the kernel of I1I_1:

Kernel(I1)={S→<∙S>}\text{Kernel}(I_1) = \{ S \rightarrow < \bullet S > \}

Taking the closure of this kernel (since the dot is before the non-terminal SS):

I1={S→<∙S>,S→∙S#cS,S→∙SS,S→∙S@,S→∙<S>,S→∙a,S→∙b,S→∙c}\begin{aligned}I_1 = \{ & S \rightarrow < \bullet S >, \\ & S \rightarrow \bullet S \# cS, \\ & S \rightarrow \bullet SS, \\ & S \rightarrow \bullet S @, \\ & S \rightarrow \bullet < S >, \\ & S \rightarrow \bullet a, \\ & S \rightarrow \bullet b, \\ & S \rightarrow \bullet c \}\end{aligned}

Step 3: Find I2=GOTO(I1,<)I_2 = \text{GOTO}(I_1, <)

In I1I_1, the only item with the dot before << is S→∙<S>S \rightarrow \bullet < S >. Moving the dot over << gives the kernel of I2I_2:

Kernel(I2)={S→<∙S>}\text{Kernel}(I_2) = \{ S \rightarrow < \bullet S > \}

Since the kernel of I2I_2 is identical to the kernel of I1I_1, their closures are identical, meaning I2=I1I_2 = I_1.

Counting the items in I2I_2, we have exactly 8 items.

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

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