Consider the augmented grammar with {+, *, (, ), id} as the set of terminals.…
2022
Consider the augmented grammar with {+, *, (, ), id} as the set of terminals.
S′ → S
S → S + R⏐R
R → R * P⏐P
P → (S)⏐id
If I0 is the set of two LR(0) items {[S′ → S.], [S → S. + R]}, then goto(closure(I0), +) contains exactly ________ items.
Attempted by 104 students.
Show answer & explanation
Correct answer: 5
Key insight: move the dot past the '+' and then take the closure of the resulting item.
Start from the item that has '+' after the dot: S → S . + R.
Applying goto on '+': advance the dot to get S → S + . R.
Take the closure: add items for R (dot at start) and for P (since R → . P), and then for P's productions.
Therefore goto(closure(I0), +) contains exactly 5 items:
S → S + . R
R → . R * P
R → . P
P → . ( S )
P → . id