Consider the following augmented grammar, which is to be parsed with a SLR…
2024
Consider the following augmented grammar, which is to be parsed with a SLR parser. The set of terminals is {𝑎,𝑏,𝑐,𝑑,#,@}
𝑆 ′ → 𝑆
𝑆 → 𝑆𝑆 | 𝐴𝑎 | 𝑏𝐴𝑐 | 𝐵𝑐 | 𝑏𝐵𝑎
𝐴 → 𝑑#
𝐵 → @
Let 𝐼0 = 𝐶𝐿𝑂𝑆𝑈𝑅𝐸({𝑆 ′ → • 𝑆}). The number of items in the set 𝐺𝑂𝑇𝑂(𝐼0, 𝑆) is ___________
Attempted by 97 students.
Show answer & explanation
Correct answer: 9
Key idea: compute GOTO(I0, S) by advancing the dot over S in all items of I0 that have • before S, then take the closure of the resulting items.
Start: I0 contains all items with the dot at the beginning for S and for any nonterminal immediately after a dot. Concretely I0 includes:
S' → • S
S → • S S
S → • A a
S → • b A c
S → • B c
S → • b B a
A → • d #
B → • @
Advance the dot for symbols with • before S in I0 (those are S' → • S and S → • S S). The kernel of GOTO(I0, S) is:
S' → S •
S → S • S
Take the closure: because S → S • S has • before S, include all S-productions with • at start, and then include A and B productions reached from those. The closure adds:
S → • S S
S → • A a
S → • b A c
S → • B c
S → • b B a
A → • d #
B → • @
Counting all distinct items (the two kernel items plus the seven closure items) gives a total of 9 items in GOTO(I0, S).
A video solution is available for this question — log in and enroll to watch it.