In general, every production can be written as N ::= alpha M beta,
where alpha and beta are sequences of tokens and nonterminals.

Note that there are a variety of ways to write a production in that
form. Consider N ::= a B b C D

We might have M is B, alpha is a, and
beta is b C D

We might have M is C, alpha is a B b, and
beta is C D

We might have M is D, alpha is a B b C, and
beta is epsilon

How do we use this information to build the Follow
table? We know that M can be followed by anything that can begin
a string derivable from beta.

What if beta can derive epsilon (that is, beta is nullable)? Then
anything that can follow N can follow M.

S =>* aardvark N baboon -- Derivation of a string with N

=> aardvark alpha M beta baboon -- N ::= alpha M beta

=> aardvark alpha M baboon -- beta derives epsilon

Putting it all together

for each nonterminal, N
Follow(N) = {};
for each production P
for each form of P, N ::= alpha M beta
Follow(M) = Follow(M) union first(beta)
end for
end for
repeat
for each production P
for each form of P, N :: = alpha M beta
if nullable(beta)
Follow(M) = Follow(M) union Follow(N)
end if
end for
end for
until no changes are made
end for

We can now use these tables to build recursive descent parsers for selected
languages.

for each nonterminal N, build the method parseN as follows
for each production, N ::= Stuff
for each symbol in first(Stuff)
add a case for that symbol, using the steps to parse Stuff
end for
if nullable(Stuff) then
for each symbol in Follow(N)
add a case for that symbol, using the steps to parse Stuff
-- Note that we still parse Stuff, even thoush we
-- ``know'' it nullifies
end for
end if
end for each production
end for each nonterminal