IAE Academy

GATE 2024 CS2 Q.65: solution and answer

GATE 2024 · CS2Q.65 · 2 marks · NAT

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 ______

See the question in the paper

Answer and solution

ANSWER

contains 9 items.

Official answer: 9Source: Official answer key, GATE 2024 CS2 (IISc Bengaluru)

  1. contains , then (dot before ) all -productions , , , , , and (dot before and ) , .

  2. 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.

  3. Moving the dot gives the kernel: and .

  4. In the dot is before the nonterminal , so add every -production with the dot at the start: , , , , (5 items).

  5. The items and have the dot before and , so add and (2 items).

  6. 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.

  7. 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

More Parsing questions