LL(1) Check for the Grammar (S \rightarrow iEtSA \mid a,; A \rightarrow eS \mid \epsilon,; E \rightarrow b)
LL(1) Check for the Grammar (S \rightarrow iEtSA \mid a,; A \rightarrow eS \mid \epsilon,; E \rightarrow b)
To check whether a context-free grammar is LL(1), we verify that for every nonterminal (X), the parser has at most one production to choose based on the next input token. Concretely, we use the LL(1) condition based on FIRST and FOLLOW sets and the behavior of (\epsilon)-productions:
- For any nonterminal (X), productions (X \rightarrow \alpha) and (X \rightarrow \beta) must satisfy
(\text{FIRST}(\alpha) \cap \text{FIRST}(\beta) = \varnothing). - If (\epsilon \in \text{FIRST}(\alpha)), then (\text{FIRST}(\beta)) must not intersect (\text{FOLLOW}(X)), equivalently the LL(1) parsing-table row for (X) must have no conflicts.
Key terms used below:
- LL(1) grammar
- FIRST set
- FOLLOW set
- Parsing table
- Epsilon production
LL(1) FIRST/FOLLOW check (overview)
We are given the grammar: [ S \rightarrow iEtSA \mid a ] [ A \rightarrow eS \mid \epsilon ] [ E \rightarrow b ] Terminals are ({i,e,b,a}). The start symbol is (S).
We will compute (\text{FIRST}) and (\text{FOLLOW}) sets, then show whether the LL(1) parsing table for (S) and (A) has conflicts.
Important: The grammar is LL(1) iff, for each nonterminal, the productions chosen by a given lookahead token are unique (no multiple entries per table cell).
Step-by-step LL(1) check using FIRST/FOLLOW
- 1Step 1
Determine FIRST(S), FIRST(A), FIRST(E) using productions and epsilon propagation.
- 2Step 2
Propagate FOLLOW sets using occurrences of nonterminals in right-hand sides and epsilon rules.
- 3Step 3
Verify FIRST/FIRST disjointness and FIRST/FOLLOW compatibility for epsilon-producing nonterminals.
- 4Step 4
If any conflict exists in the implied parsing-table row, the grammar is not LL(1); otherwise it is LL(1).
1) FIRST sets
We compute:
FIRST((E))
Since (E \rightarrow b), [ \text{FIRST}(E)={b}. ]
FIRST((S))
(S) has two productions: (S \rightarrow iEtSA) and (S \rightarrow a).
- From (S \rightarrow iEtSA), the first terminal is (i), so (i \in \text{FIRST}(S)).
- From (S \rightarrow a), (a \in \text{FIRST}(S)).
Also, neither right-hand side can derive (\epsilon). Therefore: [ \text{FIRST}(S)={i,a}. ]
FIRST((A))
(A \rightarrow eS \mid \epsilon).
- From (A \rightarrow eS): (e \in \text{FIRST}(A)).
- From (A \rightarrow \epsilon): (\epsilon \in \text{FIRST}(A)).
So: [ \text{FIRST}(A)={e,\epsilon}. ]
2) FOLLOW sets
Let ($) denote end-of-input marker. Since (S) is the start symbol: [ $ \in \text{FOLLOW}(S). ]
Now scan productions:
From (S \rightarrow iEtSA)
Right-hand side: (i; E; t; S; A)
-
(E) is followed by terminal (t), but note: there is no terminal (t) listed in the grammar statement. In the given production it appears as (t). For LL(1) analysis we must treat every symbol on the RHS that is not a nonterminal as a terminal. So (t) is a terminal symbol here. Hence: [ t \in \text{FOLLOW}(E). ]
-
(S) is followed by (A) (since the RHS has (S A)). Therefore: [ \text{FIRST}(A)\setminus{\epsilon} \subseteq \text{FOLLOW}(S). ] Since (\text{FIRST}(A)={e,\epsilon}), we get: [ e \in \text{FOLLOW}(S). ] Also, because (A\Rightarrow^* \epsilon), we must add: [ \text{FOLLOW}(S) \subseteq \text{FOLLOW}(S) ] (which is tautological for this self-recursive position). Concretely, after (S) comes a symbol that may vanish, so whatever can follow the left-hand side (S) can also follow that inner (S). That is already captured by ($ \in \text{FOLLOW}(S)) and propagated consistently; no contradiction arises.
From (A \rightarrow eS)
RHS: (e; S). Since (S) is at the end of the production, we add: [ \text{FOLLOW}(A)\subseteq \text{FOLLOW}(S)\quad\text{does not directly apply here;} ] rather, it means: [ \text{FOLLOW}(S) \text{ gets } \text{FOLLOW}(A) \text{ when } A \text{ is the LHS. } ] So we should determine (\text{FOLLOW}(A)).
Determine FOLLOW((A))
(A) occurs in (S \rightarrow iEtSA) at the end. Therefore: [ \text{FOLLOW}(A) \subseteq \text{FOLLOW}(S). ] So: [ $\in \text{FOLLOW}(A) \quad \text{(since } $\in \text{FOLLOW}(S)\text{)}. ]
Summary of FOLLOW sets
- (\text{FOLLOW}(S)) contains at least ({$, e}).
- (\text{FOLLOW}(A)) contains at least ({$}).
- (\text{FOLLOW}(E)) contains ({t}) (where (t) is the terminal appearing after (E) in the production (S \rightarrow iEtSA)).
So we can take: [ \text{FOLLOW}(S)={$, e},\quad \text{FOLLOW}(A)={$},\quad \text{FOLLOW}(E)={t}. ]
3) LL(1) conflict checks
Nonterminal (S)
Productions:
- (S \rightarrow iEtSA)
- (S \rightarrow a)
We check FIRST/FIRST disjointness: [ \text{FIRST}(iEtSA)={i},\quad \text{FIRST}(a)={a}. ] Since ({i}\cap{a}=\varnothing), there is no LL(1) conflict in the (S) row.
Nonterminal (A)
Productions:
- (A \rightarrow eS)
- (A \rightarrow \epsilon)
We check FIRST/FIRST: [ \text{FIRST}(eS)={e},\quad \text{FIRST}(\epsilon)={\epsilon}. ] Their intersection is empty (terminals only), so FIRST/FIRST is fine.
Now apply epsilon rule: because (A \rightarrow \epsilon), we must ensure: [ \text{FIRST}(eS)\cap \text{FOLLOW}(A) = \varnothing. ] We have: [ \text{FIRST}(eS)={e},\quad \text{FOLLOW}(A)={$}. ] Thus: [ {e}\cap{$}=\varnothing. ] So the (A) row is also conflict-free.
How to spot LL(1) conflicts quickly
If two productions for the same nonterminal can start with terminals that overlap in FIRST sets (or one can be ε), then the lookahead cannot select uniquely. Compute FIRST sets first; only then use FOLLOW sets for ε-productions.
Treat every non-nonterminal symbol as a terminal
In (S \rightarrow iEtSA), the symbol (t) is not declared as a nonterminal, so it must be treated as a terminal when computing FOLLOW(E). If (t) was meant to be something else, the LL(1) check could change.
LL(1) decision workflow
Compute FIRST sets
1Find which terminals can begin derivations from each nonterminal."
Compute FOLLOW sets
2Find which terminals can appear right after each nonterminal in sentential forms."
Check ε-production constraints
3For X → ε, ensure FIRST(other alternatives) does not intersect FOLLOW(X)."
Final verdict
4No parsing-table conflicts ⇒ LL(1); otherwise not LL(1)."
FIRST sets size and contents (terminals only)
Quick view of starting terminals for each nonterminal
Conclusion
All LL(1) conditions for the grammar are satisfied:
- For (S), the FIRST sets of alternatives are disjoint: ({i}) vs ({a}).
- For (A), the ε-production does not cause a conflict: (\text{FIRST}(eS)={e}) is disjoint from (\text{FOLLOW}(A)={$}).
Therefore, the given grammar is LL(1).
Common edge cases
Knowledge Check
For (S \rightarrow iEtSA \mid a), what is (\text{FIRST}(S))?
Explore Related Topics
LR(0) / SLR Parsing for \(S \rightarrow 0S0 \mid 1S1 \mid 10\)
Ambiguity in the Grammar \(S \rightarrow ABA,\; A \rightarrow aA \mid \epsilon,\; B \rightarrow bB \mid \epsilon\)
The grammar (S\rightarrow ABA,;A\rightarrow aA\mid\epsilon,;B\rightarrow bB\mid\epsilon) is ambiguous because the two (A) nonterminals can distribute the same (a)-string in multiple ways, especially when (B) derives (\epsilon).
- It generates the language (L(S)={a^i b^j a^k\mid i,j,k\ge0}=a^*b^a^).
- The shortest string (a) has two distinct left‑most derivations (or parse trees), proving ambiguity.
- Every string (a^n) with (n\ge1) can be split between the two (A) symbols in (n+1) ways, yielding multiple parse trees.
- The ambiguity stems from both (A) producing (a^*) and (B) being able to vanish via (\epsilon).
- An equivalent unambiguous grammar can be constructed, showing the ambiguity is a property of this grammar, not necessarily of the language.
FIRST, FOLLOW, and LL(1) Parsing Table for a Grammar with ε-Productions