Question

Consider the following augmented grammar, which is to be parsed with a SLR parser. The set of terminals is {a,b,c,d,#,@}\{a,b,c,d,\#,@\}

S′→SS' \rightarrow S
S→SS∣Aa∣bAc∣Bc∣bBaS \rightarrow SS \mid Aa \mid bAc \mid Bc \mid bBa
A→d#A \rightarrow d\#
B→@B \rightarrow @

Let I0=CLOSURE({S′→∙S})I_0 = \text{CLOSURE}(\{S' \rightarrow \bullet S\}). The number of items in the set GOTO(I0,S)\text{GOTO}(I_0, S) is ___________

Official answer and solution
Official answer
9
From
Official GATE 2024 answer key

Solution

Find the kernel items of GOTO(I0,S)\text{GOTO}(I_0, S) by advancing the dot past SS in I0I_0, then compute CLOSURE\text{CLOSURE} by expanding nonterminals immediately following the dot.

  1. In I0=CLOSURE({S′→∙S})I_0 = \text{CLOSURE}(\{S' \rightarrow \bullet S\}), the items having the dot (∙\bullet) immediately before SS are:
    • S′→∙SS' \rightarrow \bullet S
    • S→∙SSS \rightarrow \bullet SS
  2. Advancing the dot past SS gives the kernel items of GOTO(I0,S)\text{GOTO}(I_0, S) (2 items):
    1. S′→S∙S' \rightarrow S\bullet
    2. S→S∙SS \rightarrow S\bullet S
  3. Since the dot in S→S∙SS \rightarrow S\bullet S immediately precedes nonterminal SS, CLOSURE\text{CLOSURE} adds all 55 productions of SS with a leading dot (5 items):
    3. S→∙SSS \rightarrow \bullet SS
    4. S→∙AaS \rightarrow \bullet Aa
    5. S→∙bAcS \rightarrow \bullet bAc
    6. S→∙BcS \rightarrow \bullet Bc
    7. S→∙bBaS \rightarrow \bullet bBa
  4. Because S→∙AaS \rightarrow \bullet Aa has the dot before AA and S→∙BcS \rightarrow \bullet Bc has the dot before BB, CLOSURE\text{CLOSURE} also adds the productions of AA and BB (2 items):
    8. A→∙d#A \rightarrow \bullet d\#
    9. B→∙@B \rightarrow \bullet @

Total number of LR(0) items in GOTO(I0,S)\text{GOTO}(I_0, S) is 2+5+2=92 + 5 + 2 = 9.

Final answer

9

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

Source

Paper
GATE 2024 Computer Science and Information Technology - Set 2 (CS2)
Question
65 of 65
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.