Predictive parsers
. A non recursive top down parsing method
. Parser "predicts" which production to use
. It removes backtracking by fixing one production for every non-terminal and input token(s)
. Predictive parsers accept LL(k) languages
- First L stands for left to right scan of input
- Second L stands for leftmost derivation
- k stands for number of lookahead token
. In practice LL(1) is used
In general, the selection of a production for a non-terminal may involve trial-and-error; that is, we may have to try a production and backtrack to try another production if the first is found to be unsuitable. A production is unsuitable if, after using the production, we cannot complete the tree to match the input string. Predictive parsing is a special form of recursive-descent parsing, in which the current input token unambiguously determines the production to be applied at each step. After eliminating left recursion and left factoring, we can obtain a grammar that can be parsed by a recursive-descent parser that needs no backtracking . Basically, it removes the need of backtracking by fixing one production for every non-terminal and input tokens.
Predictive parsers accept LL(k) languages where:
. First L : The input is scanned from left to right.
. Second L : Leftmost derivations are derived for the strings.
. k : The number of lookahead tokens is k.
However, in practice, LL(1) grammars are used i.e., one lookahead token is used.