![]() |
VOOZH | about |
In this, we will cover the overview of Predictive Parser and mainly focus on the role of Predictive Parser. And will also cover the algorithm for the implementation of the Predictive parser algorithm and finally will discuss an example by implementing the algorithm for precedence parsing. Letβs discuss it one by one.
π ImagePredictive Parser :
A predictive parser is a recursive descent parser with no backtracking or backup. It is a top-down parser that does not require backtracking. At each step, the choice of the rule to be expanded is made upon the next terminal symbol.
Consider
A -> A1 | A2 | ... | AnIf the non-terminal is to be further expanded to 'A', the rule is selected based on the current input symbol 'a' only.
Predictive Parser Algorithm :
Consider the following grammar -
E->E+T|T
T->T*F|F
F->(E)|id
After removing left recursion, left factoring
E->TT'
T'->+TT'|Ξ΅
T->FT''
T''->*FT''|Ξ΅
F->(E)|id
STEP 1:
Make a transition diagram(DFA/NFA) for every rule of grammar.
STEP 2:
Optimize the DFA by decreases the number of states, yielding the final transition diagram.
It can be optimized ahead by combining it with DFA for E'->TE'
π ImageAccordingly, we optimize the other structures to produce the following DFA
π ImageSTEP 3:
Simulation on the input string.
Steps involved in the simulation procedure are: