Consider the Grammar : S → A A → \(\$\)B\(\$\) | id B → B, A | A If I0 = CLOSURE ({[S → .A]}) then, how many items be in the set for GOTO(I0, \(\$\))
5
In LR(0) parsing, GOTO(I, X) is formed by moving the dot past the symbol X in every item of I that has X right after the dot, and then taking the CLOSURE of those kernel items. CLOSURE adds an item B → .γ for every production of a non-terminal B that appears immediately after a dot.
Step 1 — Build I0 = CLOSURE({[S → .A]}). The dot is before A, so both A-productions are added: S → .A, A → .\(\$\)B\(\$\), A → .id. Thus I0 has 3 items.
Step 2 — Kernel of GOTO(I0, \(\$\)): only A → .\(\$\)B\(\$\) has \(\$\) after the dot, giving the kernel item A → \(\$\).B\(\$\).
Step 3 — Closure: the dot is before B, so add B → .B, A and B → .A. The item B → .B, A again has B after the dot (already added). The item B → .A has A after the dot, so add A → .\(\$\)B\(\$\) and A → .id.
Step 4 — The final set is {A → \(\$\).B\(\$\), B → .B, A, B → .A, A → .\(\$\)B\(\$\), A → .id}, which contains 5 items.
Counting only 3 or 4 items misses the A-productions pulled in through B → .A, and 6 would double-count the recursive item B → .B, A, which appears only once in the set.
5 option is correct.