Consider a context-free grammar with the following production rules, where
denotes an empty string.
Terminals symbols are
,
,
and parentheses.
Then, we build fonction FOLLOW for every non-terminal.
First, since
is the axiom, we had $ to FOLLOW
.
Then, we look at all the production
, and we add the contents of FIRST
(except
) to FOLLOW
.
Since
, FOLLOW
.
Since
, FOLLOW
.
Since
, FOLLOW
.
Finally, we look at all the productions
(or
with
) and we add FOLLOW
to FOLLOW
.
Since
, FOLLOW
and FOLLOW
.
Since
, FOLLOW
.
Since
, FOLLOW
and FOLLOW
.
As these sets are closed, we conclude:
FOLLOW
FOLLOW
FOLLOW
FOLLOW
FOLLOW
Now, we build the predictive parse table. For each production
, we do the following. For each terminal
in FIRST
, we add
to
. If
is in FIRST
, we add
to
for all the terminals in FOLLOW
. If
is in FIRST
and $ is in FOLLOW(A), we had
to
.
We add
to
.
We add
to
.
We add
to
and
.
We add
to
,
and
.
No productions involving
as a left-hand yields an entry to
.
The
locates errors in the parse table.