Top-Down Parsing


Consider the CFG with productions:

expr term rest
rest  → + term rest | - term rest
term 0 | 1 | . . . | 9

Step 0:
Initialization: Root must be starting symbol
Step 1:
expr term rest
Step 2:
term 9
Step 3
rest term rest
Step 4:
term 5
Step 5:
rest term rest
Step 6:
term 2
Step 7:
rest E

In the example above, the grammar made it easy for the top-down parser to pick the correct production in each step.
This is not true in general, see example of dangling 'else'.