Assignment 3
Assignment 3
example of CFG:
For an input string: read, a top-down parser, will behave like
this:
It will start with S from the production rules and will match its
yield to the left-most letter of the input, i.e. ‘r’. The very
production of S (S → rXd) matches with it. So the top-down
parser advances to the next input letter (i.e. ‘e’). The parser tries
to expand non-terminal ‘X’ and checks its production from the
left (X → oa). It does not match with the next input symbol. So
the top-down parser backtracks to obtain the next production
rule of X, (X → ea).
Now the parser matches all the input letters in an ordered
manner. The string is accepted.
• Predictive Parser
Predictive parser is a recursive descent parser, which has the
capability to predict which production is to be used to replace
the input string. The predictive parser does not suffer from
backtracking.
To accomplish its tasks, the predictive parser uses a look-ahead
pointer, which points to the next input symbols. To make the
parser back-tracking free, the predictive parser puts some
constraints on the grammar and accepts only a class of grammar
• LL Parser
An LL Parser accepts LL grammar. LL grammar is a subset of
context-free grammar but with some restrictions to get the
simplified version, in order to achieve easy implementation. LL
grammar can be implemented by means of both algorithms
namely, recursive-descent or table-driven.
LL parser is denoted as LL(k). The first L in LL(k) is parsing the
input from left to right, the second L in LL(k) stands for left-
most derivation and k itself represents the number of look ahead.
Generally k = 1, so LL(k) may also be written as LL(1).