Which of the following statements is TRUE for the grammar given below? S ->…
2017
Which of the following statements is TRUE for the grammar given below?
S -> (L) | a
L -> L,S | S
- A.
The grammar can be parsed by LR(0) parser only
- B.
The grammar can't be parsed by LR(0) but it can be parsed by SLR(1)
- C.
The grammar can be parsed by LL(1) and LR(0) parsers
- D.
The grammar can be parsed by LL(1) parser only
Attempted by 39 students.
Show answer & explanation
Correct answer: A
Concept
Parser-class hierarchy: For the LR family, LR(0) ⊆ SLR(1) ⊆ LALR(1) ⊆ LR(1). A grammar is LR(0) when its LR(0) item-set (canonical collection) has no shift–reduce or reduce–reduce conflict in any state — i.e. no state holds a completed item [A → α·] together with a shift item, and no state holds two completed items. Separately, a grammar with left recursion (e.g. L → L , S) can never be LL(1).
Application to this grammar
LL(1) check: The production L → L , S is immediately left-recursive, so the grammar is not LL(1). Any statement asserting LL(1) is therefore false.
Build the LR(0) item sets. Augment the grammar with S′ → S and walk CLOSURE/GOTO state by state (dot · marks how far each item has been matched):
I0 = {S′ → ·S, S → ·(L), S → ·a} — no completed item; pure shift/goto state.
On '(' from I0: I2 = {S → (·L), L → ·L,S, L → ·S, S → ·(L), S → ·a} — no completed item; pure shift/goto state.
On S from I2: I5 = {L → S·} — the only item in this state, so it is reduce-only; no shift item shares the state, hence no shift–reduce conflict.
On L from I2: I4 = {S → (L·), L → L·,S} — both items have the dot immediately before a terminal (either ')' or ','), so this is a pure shift state with no completed item.
On ')' from I4: I6 = {S → (L)·} — single completed item, reduce-only.
On ',' from I4: I7 = {L → L,·S, S → ·(L), S → ·a} — no completed item; pure shift/goto state.
On S from I7: I8 = {L → L,S·} — single completed item, reduce-only.
On 'a' (from I0, I2, or I7): I3 = {S → a·} — single completed item, reduce-only.
On S from I0: I1 = {S′ → S·} — the accept state.
Across all nine states, every state is either a pure shift/goto state (no completed item) or holds exactly one completed item (reduce-only) — no state ever mixes a completed item with a shift, and no state holds two completed items. So there is no LR(0) conflict anywhere: the grammar is LR(0).
Cross-check
Because LR(0) ⊆ SLR(1) ⊆ LR(1), an LR(0) grammar is automatically SLR(1) and LR(1) too — FOLLOW(L) = { ) , , } and FOLLOW(S) = { $ , ) , , } are never even needed to resolve a conflict, since none exists. Among the four statements, the only one consistent with “LR(0) = yes, LL(1) = no” is “The grammar can be parsed by LR(0) parser”. The word “only” is loose — every LR(0) grammar is trivially also SLR/LALR/LR(1) — but it is the intended reading, since it is the lone option that does not contradict the automaton just built.