A predictive parser is a recursive descent parser without backtracking. It relies on the concept of a lookahead symbol to determine which production rule to use. It does not support left recursion, and requires any left-recursive grammars to be converted to right recursive grammars. A predictive parser is called LL(k) where k denotes the number of lookahead symbols used. This is LL(1) because we're only using one 1 look ahead symbol equivalent to 1 character terminal in the input string. There is no lexer required, thus in this case the tokens and terminals are the exact same thing.
Strings to be parsed:
1+2-4
Left Recursive Grammar:
expr = expr + term
| expr - term
| e
term = 0
| 1
| 2
| 3
| 4
| 5
| 6
| 7
| 8
| 9
Left Recursion Eliminated Grammar:
expr = term rest
rest = + term rest
| - term rest
| e
term = 0
| 1
| 2
| 3
| 4
| 5
| 6
| 7
| 8
| 9
Some goals:
- Turn the above into post-fix notation.
- Failing that, just print out whatever you're doing.