Let's build the top-down parsing table for a slightly different grammar.
1. L | → | ε |
2. L | → | N |
3. N | → | E |
4. N | → | E, N |
5. E | → | n |
The FIRST and FOLLOW sets for that grammar are:
X | L | N | E |
---|---|---|---|
FIRST(X) | {n, ε} | {n} | {n} |
FOLLOW(X) | {$} | {$} | {,, $} |
The parsing table is as follows.
Table D | |||
---|---|---|---|
n | , | $ | |
L | 2 | 1 | |
N | 3,4 | ||
E | 6 |
The algorithm adds two productions to one of the cells in the table. When that happens, it is called a parsing conflict
The problem is that the parser cannot know whether to use production N → E or N → E , N, based on a single-token lookahead. That decision depends on whether the E is followed by a comma, and that would require a longer lookahead.