```latex
program \rightarrow stmt\_list \$\$
stmt\_list \rightarrow stmt stmt\_list | \epsilon
stmt \rightarrow id := expr | read id | write expr
expr \rightarrow term term\_tail
term\_tail \rightarrow add\_op term term\_tail | \epsilon
term \rightarrow factor factor\_tail
factor\_tail \rightarrow mult\_op factor factor\_tail | \epsilon
factor \rightarrow ( expr ) | id | number
add\_op \rightarrow + | -
mult\_op \rightarrow * | /
```
Figure 2.16 LL(1) grammar for a simple calculator language.
| Top-of-stack nonterminal | id | number | read | write | := | ( | ) | + | - | * | / | $$ |
|---|---|---|---|---|---|---|---|---|---|---|---|---|
| program | 1 | - | - | - | - | - | - | - | - | - | - | 1 |
| stmt\_list | 2 | - | - | - | - | - | - | - | - | - | - | 3 |
| stmt | 4 | 7 | - | 1 | 2 | 6 | - | - | - | - | - | - |
| expr | 7 | - | 9 | - | - | - | - | - | - | - | - | - | - |
| term\_tail | 9 | 10 | - | - | - | - | - | 8 | - | - | - | - | - |
| term | 10 | - | - | - | - | - | - | - | - | - | - | - | - |
| factor\_tail | 12 | 15 | - | - | - | - | - | - | - | - | - | - | - |
| factor | 14 | - | - | - | - | - | - | - | - | - | - | - | - |
| add\_op | - | - | - | - | - | - | - | - | - | - | - | - | - |
| mult\_op | - | - | - | - | - | - | - | - | - | - | - | - | - |
Figure 2.20 LL(1) parse table for the calculator language. Table entries indicate the production to predict (as numbered in Figure 2.23). A dash indicates an error. When the top-of-stack symbol is a terminal, the appropriate action is always to match it against an incoming token from the scanner. An auxiliary table, not shown here, gives the right-hand-side symbols for each production.