For the grammar below, a partial LL(1) parsing table is also presented along…
2012
For the grammar below, a partial LL(1) parsing table is also presented along with the grammar. Entries that need to be filled are indicated as E1, E2, and E3. \(\varepsilon\) is the empty string, $ indicates end of input, and, | separates alternate right hand sides of productions.
S \(\to\) a A b B | b A a B | \(\varepsilon\)
A \(\to\) S
B \(\to\) S

The FIRST and FOLLOW sets for the non-terminals A and B are
- A.
FIRST(A) = {a, b,
\(\varepsilon\)} = FIRST(B)FOLLOW(A) = {a, b}
FOLLOW(B) = {a, b, $}
- B.
FIRST(A) = {a, b, $}
FIRST(B) = {a, b,
\(\varepsilon\)} FOLLOW(A) = {a, b}
FOLLOW(B) = {$}
- C.
FIRST(A) = {a, b,
\(\varepsilon\)} = FIRST(B)FOLLOW(A) = {a, b}
FOLLOW(B) =
\(\phi\) - D.
FIRST(A) = {a, b} = FIRST(B)
FOLLOW(A) = {a, b}
FOLLOW(B) = {a, b}
Attempted by 118 students.
Show answer & explanation
Correct answer: A
Solution:
Compute FIRST sets.
FIRST(S) = {a, b, ε} because S → a A b B, S → b A a B, and S → ε.
FIRST(B) = FIRST(S) = {a, b, ε} because B → S.
FIRST(A): from A → S B include FIRST(S) \{ε} = {a, b}. Since S can produce ε, also include FIRST(B) which contains ε, so FIRST(A) = {a, b, ε}.
Compute FOLLOW sets.
Start: FOLLOW(S) contains $ because S is the start symbol.
From S → a A b B and S → b A a B, A is followed by b or a, so add {a, b} to FOLLOW(A). Thus FOLLOW(A) ⊇ {a, b}.
From A → S B: for S before B, add FIRST(B) \{ε} = {a, b} to FOLLOW(S). Because FIRST(B) contains ε, also add FOLLOW(A) to FOLLOW(S).
From B → S: S is at the end, so add FOLLOW(B) to FOLLOW(S).
From S → ... B (B at the end of S-productions), add FOLLOW(S) to FOLLOW(B).
Solve these inclusions:
FOLLOW(A) = {a, b} (no other symbols follow A in the grammar).
FOLLOW(S) must include $ and {a, b} (from the relations), so FOLLOW(S) = {a, b, $}.
FOLLOW(B) includes FOLLOW(S) and FOLLOW(A), giving FOLLOW(B) = {a, b, $}.
Final answer:
FIRST(A) = {a, b, ε} = FIRST(B)
FOLLOW(A) = {a, b}
FOLLOW(B) = {a, b, $}
A video solution is available for this question — log in and enroll to watch it.