Professional Documents
Culture Documents
a b A a b A a b A a b A
c d c ε
(a) (b) (c) (d)
PARSE TREE
Predictive Parsing
Predictive parsing are special case of recursive descent
parsing where no backtracking is required. Predictive
parsing chooses the correct A production by looking ahead
at the input a fixed number of symbols, usually the next input
symbol.
The class of grammars for which predictive parsers
can be constructed by looking k symbols ahead in the input is
called the LL (k) class. A non-recursive predictive parsers
can be built by maintaining a stack explicitly. The table
driven parser has an input buffer, a stack containing a
sequence of grammar symbols and a parsing table.
Example of Predictive Parsing
E E->TE' E->TE'
E′-> ε
E' E′->+TE′ E′-> ε
T->FT T->FT
T ′ ′
T′->ε T'->*FT
T' ′ T′->ε T′->ε
F F->id F->(E)
Moves made by a predictive parser on input id+id*id
+id*id$
T'E'$ Match id
Output T'->ε
E'$ +id*id$
T'E'$ Match id
*id$
*id$
*FT'E'$ Output T‘->*FT'
id$ Match *
FT'E'$
Output F->id
idT'E'$ id$
Match id
T'E'$ $
E'$
$ Output T'->ε
$ $ Output E'->ε
Bottom Up Parsers
id F
id
T*F T E
F id T * F T
id F id T * F
F
id
id
Shift Reduce Parsing
$T *id2 Shift
$T* id2$ Shift
Reduce by F->id
$T*id2 $
Reduce by T->T*F
$T*F $
Reduce by E->T
$T $
$E $ Accept
Actions of a Shift-Reduce Parser