Compiler Design and Construction - Old Questions
3. Differentiate between recursive descent and non-recursive predictive parsing method. Find first and follow of all the non-terminals in the following grammar.
Difference between recursive descent and non-recursive predictive parsing
Recursive predictive descent parsing |
Non-recursive predictive descent parsing |
It
is a technique which may or may not require backtracking process. |
It
is a technique that does not require any kind of back tracking. |
It
uses procedures for every non terminal entity to parse strings. |
It
finds out productions to use by replacing input string. |
It
is a type of top-down parsing built from a set of mutually recursive
procedures where each procedure implements one of non-terminal s of grammar. |
It
is a type of top-down approach, which is also a type of recursive parsing
that does not uses technique of backtracking. |
It
contains several small functions one for each non- terminals in grammar. |
The
predictive parser uses a look ahead pointer which points to next input
symbols to make it parser back tracking free, predictive parser puts some
constraints on grammar. |
It
accepts all kinds of grammars. |
It
accepts only a class of grammar known as LL(k) grammar. |
Now,
Given grammar;
Now, the FIRST and FOLLOW for the non-terminals are:
Non-terminals |
FIRST() |
FOLLOW() |
E |
{(, id} |
{), $} |
A |
{+, ∈} |
{), $} |
T |
{(, id} |
{), +, $} |
B |
{*, ∈} |
{), +, $} |
F |
{(, id} |
{*, +, ), $} |