Consider the augmented grammar with {+, *, (, ), id} as the set of terminals.
S' -> S
S -> S + R | R
R -> R * P | P
P -> ( S ) | idIf is the set of two LR(0) items , then contains exactly ______ items.
Consider the augmented grammar with {+, *, (, ), id} as the set of terminals.
S' -> S
S -> S + R | R
R -> R * P | P
P -> ( S ) | idIf is the set of two LR(0) items , then contains exactly ______ items.
ANSWER
contains exactly 5 items.
Official answer: 5Source: Official answer key, GATE 2022 CS (IIT Kharagpur)
Only a non-terminal immediately after the dot makes the closure add items. In the dot is at the end. In the symbol after the dot is the terminal . So .
moves the dot over in every item that has right after the dot. Only qualifies, so the kernel is the single item .
Take the closure of the kernel. The dot is before , so add every -production with the dot at the start: and .
In the dot is before , so add every -production with the dot at the start: and .
In the dot is before , and both -items are already present. In and the next symbols are terminals, so nothing more is added and the closure is complete.
The resulting set is . It has exactly 5 items.
KEY IDEA
moves the dot over in the items of that have after the dot. You then take the closure of that kernel, adding productions for each non-terminal that now follows a dot.
WATCH OUT FOR
Stopping at the kernel item and forgetting the closure. Another slip is counting in the result, although it has no after its dot and so does not carry over.
From the GATE 2022 CS paper. Every question of this paper · Download the full paper · All 13 Parsing questions, with notes