Consider the following augmented grammar, which is to be parsed with a SLR parser. The set of terminals is {a, b, c, d, #, @}
Let . The number of items in the set is ______
Consider the following augmented grammar, which is to be parsed with a SLR parser. The set of terminals is {a, b, c, d, #, @}
Let . The number of items in the set is ______
ANSWER
contains 9 items.
Official answer: 9Source: Official answer key, GATE 2024 CS2 (IISc Bengaluru)
contains , then (dot before ) all -productions , , , , , and (dot before and ) , .
is the closure of the set obtained by moving the dot over in every item of that has the dot immediately before . Only and qualify.
Moving the dot gives the kernel: and .
In the dot is before the nonterminal , so add every -production with the dot at the start: , , , , (5 items).
The items and have the dot before and , so add and (2 items).
The items and have the dot before the terminal , so they add nothing. No other nonterminal appears after a dot, so the closure is complete.
Count: . The set is .
KEY IDEA
GOTO(I, X) moves the dot over X in every item that has the dot just before X, then takes the closure. Closure adds productions only for a nonterminal that sits immediately after a dot.
WATCH OUT FOR
Leaving out the kernel item , or adding items for and from and . There the dot is before the terminal , so they add nothing. Another slip is counting the old items instead of recomputing the closure.
From the GATE 2024 CS2 paper. Every question of this paper · Download the full paper · All 13 Parsing questions, with notes