1. Gandhinagar Institute of Technology
SUBJECT – CD (2170701)
Non-predictive Parser
Prepared By-
Tarj Mehta (170120107074)
Guided By – Prof. Archana Singh
2. Non-predictive parser
•It is a top-down parser, so it builds the parse tree
from top to bottom starting from non-terminal.
•It is also known as recursive-descent parser as it
uses a set of recursive procedures to scan its input.
•This parsing technique may involve backtracking:
that is making repeated scan of its input.
4. Example
• Consider the grammar given below:
S cAd
A ab | a
• Consider the input string: w = c a d
input pointer
Step-1: S cAd
S if (input pointer == descent pointer)
increment descent pointer by 1
c A d increment input pointer by 1
Descent pointer
5. • Step-2: w = c a d
input pointer
S A is non-terminal so expand it
c A d
descent pointer
• A ab | a Now,
S input pointer == descent pointer
incrementing both pointers in next
c A d step
a b
descent pointer
6. • Step-3: w = c a d
input pointer
S
c A d
a b
descent pointer
Here, input pointer != descent pointer
Now backtracking to the immediate non-terminal
7. • Step – 4: w = c a d
input pointer
S input pointer == descent pointer
incrementing both the pointers
c A d
a
descent pointer
Now, S
w = c a d
c A d
input pointer
Here, a
input pointer == descent pointer
descent pointer
8. • As both the pointers are equal and all the elements of input string
have been parsed, we can say that the string has been successfully
parsed.
• The final parse tree can be given as follows:
S
c A d
a
• The given grammar was small to solve, but in case of big grammar
the non-predictive parser technique becomes very long.
• Hence to over come this, predictive parser was introduced.