LL(1) Table-Driven Parsing Overview
First, compute nullable, first, follow
Then, make parsing table which stores the alternative, given
- non-terminal being parsed (in which procedure we are)
- current token
Given (X ::= | … | ) we insert alternative j into table iff
- t first(p_j), or
- nullable() and t follow(X)
If in parsing table we have two or more alternatives for same token and non-terminal:
- we have conflict
- we cannot parse grammar using recursive descent
Otherwise, we say that the grammar is LL(1)
- Left-to-right parse (the way input is examined)
- Leftmost derivation (expand leftmost non-terminal first–recursion in descent does this)
- (1) token lookahead (current token)
What about empty entries?
- they indicate errors
- report that we expect one of tokens in
- first(X), if X nullable
- first(X) follow(X), if X nullable