Consider the grammar with non-terminals N = {S,C,S1 },terminals T={a,b,i,t,e},…
2007
Consider the grammar with non-terminals N = {S,C,S1 },terminals T={a,b,i,t,e}, with S as the start symbol, and the following set of rules:
S --> iCtSS1|a
S1 --> eS|ϵ
C --> bThe grammar is NOT LL(1) because:
- A.
it is left recursive
- B.
it is right recursive
- C.
it is ambiguous
- D.
It is not context-free.
Attempted by 147 students.
Show answer & explanation
Correct answer: C
Correct reason: there is a FIRST/FOLLOW conflict for the nonterminal S1, so a single-token lookahead cannot always choose the right production.
Productions:
S → i C t S S1
S → a
S1 → e S
S1 → ε
C → b
Compute FIRST sets:
FIRST(S) = {i, a}
FIRST(S1) = {e, ε}
FIRST(C) = {b}
Compute FOLLOW sets (key points):
S is the start symbol, so $ ∈ FOLLOW(S).
In the production S → i C t S S1, the S that appears before S1 has FIRST(S1) − {ε} = {e} in its FOLLOW. Because S1 can be ε, FOLLOW(S) (which contains $) is also in FOLLOW of that S. Hence FOLLOW(S) = {e, $}.
S1 appears at the end of the S production, so FOLLOW(S1) = FOLLOW(S) = {e, $}.
Why this causes a conflict:
For nonterminal S1 we have two alternatives: one starts with terminal e (FIRST = {e}) and the other is ε (FIRST contains ε).
Because ε is an alternative, the parser must consult FOLLOW(S1) to decide when to use the ε-production. But FOLLOW(S1) contains e, and e is also in FIRST of the other alternative.
Therefore FIRST(e S) ∩ FOLLOW(S1) contains e, creating a predictive parsing table conflict. This makes the grammar not LL(1).
Additional clarifications:
This is a FIRST/FOLLOW conflict, not necessarily ambiguity. Ambiguity is a different property (multiple parse trees for the same string).
The grammar is context-free and not left-recursive, so the listed reasons claiming non-context-freeness or left recursion are incorrect.
A video solution is available for this question — log in and enroll to watch it.