Copyright © 2006 Gradiance Corporation.
FIRST AND FOLLOW
Construction of FIRST and FOLLOW sets for grammars.
1.
Compute the FOLLOW set for each variable of this grammar:
S → ABCDE
A → a
B → b | ε
C → c
D → d | ε
E → e | ε
Then, identify the correct value for one of these variables from the list below.
a)
FOLLOW(A) = {b}
b)
FOLLOW(A) = {a, b, c}
c)
FOLLOW(C) = {d, e, $}
d)
FOLLOW(D) = {d, e, $}
2.
Consider the grammar:
S → AaAb | BbBa
A → ε
B → ε
Compute FIRST for all grammar symbols and FOLLOW for all nonterminals. Identify the statement below that is not true.
a is in FIRST(S)
a is in FIRST(a)
B is in FIRST(S)
ε is in FIRST(A)
3.
Here is an LL(1) grammar that generates all and only the strings with an equal number of a's and b's:
Find the FIRST and FOLLOW sets for each of the variables. Then, construct the LL(1) parsing table for the grammar. Finally, indicate which of the following statements is true. Note: we use the notation T(X,c) to represent (by its number) the production used to expand variable X when c is the lookahead. $ is the lookahead that represents the end of the input. T(X,c) = error means there is no correct choice of expansion.
T(S,$) = error
FOLLOW(B) = {a,b}
FIRST(B) = {a,b,ε}
T(A,a) = 5
4.
C → c | ε
D → d
FOLLOW(C) = {d}
FOLLOW(A) = {B, b, c, d}
FOLLOW(A) = {a, b, c, d}
5.
Here is an ambiguous grammar for strings with two kinds of balanced parentheses, round and square:
S → (S) | [S] | SS | ε
Which of the following is not in FOLLOW(S)?
)
$
(
ε