<s>
In	O
computer	B-General_Concept
science	I-General_Concept
,	O
a	O
recursive	B-Application
descent	I-Application
parser	I-Application
is	O
a	O
kind	O
of	O
top-down	B-Application
parser	I-Application
built	O
from	O
a	O
set	O
of	O
mutually	B-Algorithm
recursive	I-Algorithm
procedures	O
(	O
or	O
a	O
non-recursive	O
equivalent	O
)	O
where	O
each	O
such	O
procedure	O
implements	O
one	O
of	O
the	O
nonterminals	B-Algorithm
of	O
the	O
grammar	O
.	O
</s>
<s>
A	O
predictive	B-Application
parser	I-Application
is	O
a	O
recursive	B-Application
descent	I-Application
parser	I-Application
that	O
does	O
not	O
require	O
backtracking	B-Algorithm
.	O
</s>
<s>
Predictive	B-Application
parsing	I-Application
is	O
possible	O
only	O
for	O
the	O
class	O
of	O
LL(k )	O
grammars	O
,	O
which	O
are	O
the	O
context-free	O
grammars	O
for	O
which	O
there	O
exists	O
some	O
positive	O
integer	O
k	O
that	O
allows	O
a	O
recursive	B-Application
descent	I-Application
parser	I-Application
to	O
decide	O
which	O
production	O
to	O
use	O
by	O
examining	O
only	O
the	O
next	O
k	O
tokens	O
of	O
input	O
.	O
</s>
<s>
The	O
LL(k )	O
grammars	O
therefore	O
exclude	O
all	O
ambiguous	O
grammars	O
,	O
as	O
well	O
as	O
all	O
grammars	O
that	O
contain	O
left	B-Application
recursion	I-Application
.	O
</s>
<s>
Any	O
context-free	O
grammar	O
can	O
be	O
transformed	O
into	O
an	O
equivalent	O
grammar	O
that	O
has	O
no	O
left	B-Application
recursion	I-Application
,	O
but	O
removal	O
of	O
left	B-Application
recursion	I-Application
does	O
not	O
always	O
yield	O
an	O
LL(k )	O
grammar	O
.	O
</s>
<s>
A	O
predictive	B-Application
parser	I-Application
runs	O
in	O
linear	O
time	O
.	O
</s>
<s>
Recursive	B-Application
descent	I-Application
with	O
backtracking	B-Algorithm
is	O
a	O
technique	O
that	O
determines	O
which	O
production	O
to	O
use	O
by	O
trying	O
each	O
production	O
in	O
turn	O
.	O
</s>
<s>
Recursive	B-Application
descent	I-Application
with	O
backtracking	B-Algorithm
is	O
not	O
limited	O
to	O
LL(k )	O
grammars	O
,	O
but	O
is	O
not	O
guaranteed	O
to	O
terminate	O
unless	O
the	O
grammar	O
is	O
LL(k )	O
.	O
</s>
<s>
Even	O
when	O
they	O
terminate	O
,	O
parsers	O
that	O
use	O
recursive	B-Application
descent	I-Application
with	O
backtracking	B-Algorithm
may	O
require	O
exponential	O
time	O
.	O
</s>
<s>
Although	O
predictive	B-Application
parsers	I-Application
are	O
widely	O
used	O
,	O
and	O
are	O
frequently	O
chosen	O
if	O
writing	O
a	O
parser	O
by	O
hand	O
,	O
programmers	O
often	O
prefer	O
to	O
use	O
a	O
table-based	O
parser	O
produced	O
by	O
a	O
parser	B-Language
generator	I-Language
,	O
either	O
for	O
an	O
LL(k )	O
language	O
or	O
using	O
an	O
alternative	O
parser	O
,	O
such	O
as	O
LALR	B-Application
or	O
LR	B-Application
.	O
</s>
<s>
This	O
is	O
particularly	O
the	O
case	O
if	O
a	O
grammar	O
is	O
not	O
in	O
LL(k )	O
form	O
,	O
as	O
transforming	O
the	O
grammar	O
to	O
LL	O
to	O
make	O
it	O
suitable	O
for	O
predictive	B-Application
parsing	I-Application
is	O
involved	O
.	O
</s>
<s>
Predictive	B-Application
parsers	I-Application
can	O
also	O
be	O
automatically	O
generated	O
,	O
using	O
tools	O
like	O
ANTLR	B-Application
.	O
</s>
<s>
Predictive	B-Application
parsers	I-Application
can	O
be	O
depicted	O
using	O
transition	O
diagrams	O
for	O
each	O
non-terminal	B-Algorithm
symbol	I-Algorithm
where	O
the	O
edges	O
between	O
the	O
initial	O
and	O
the	O
final	O
states	O
are	O
labelled	O
by	O
the	O
symbols	O
(	O
terminals	O
and	O
non-terminals	B-Algorithm
)	O
of	O
the	O
right	O
side	O
of	O
the	O
production	O
rule	O
.	O
</s>
<s>
The	O
following	O
EBNF-like	O
grammar	O
(	O
for	O
Niklaus	O
Wirth	O
's	O
PL/0	B-Language
programming	I-Language
language	I-Language
,	O
from	O
Algorithms	O
+	O
Data	O
Structures	O
=	O
Programs	O
)	O
is	O
in	O
LL(1 )	O
form	O
:	O
</s>
<s>
Each	O
nonterminal	B-Algorithm
is	O
defined	O
by	O
a	O
rule	O
in	O
the	O
grammar	O
,	O
except	O
for	O
ident	O
and	O
number	O
,	O
which	O
are	O
assumed	O
to	O
be	O
implicitly	O
defined	O
.	O
</s>
<s>
What	O
follows	O
is	O
an	O
implementation	O
of	O
a	O
recursive	B-Application
descent	I-Application
parser	I-Application
for	O
the	O
above	O
language	O
in	O
C	B-Language
.	O
The	O
parser	O
reads	O
in	O
source	O
code	O
,	O
and	O
exits	O
with	O
an	O
error	O
message	O
if	O
the	O
code	O
fails	O
to	O
parse	O
,	O
exiting	O
silently	O
if	O
the	O
code	O
parses	O
correctly	O
.	O
</s>
<s>
Notice	O
how	O
closely	O
the	O
predictive	B-Application
parser	I-Application
below	O
mirrors	O
the	O
grammar	O
above	O
.	O
</s>
<s>
There	O
is	O
a	O
procedure	O
for	O
each	O
nonterminal	B-Algorithm
in	O
the	O
grammar	O
.	O
</s>
<s>
Parsing	O
descends	O
in	O
a	O
top-down	O
manner	O
until	O
the	O
final	O
nonterminal	B-Algorithm
has	O
been	O
processed	O
.	O
</s>
<s>
Some	O
recursive	B-Application
descent	I-Application
parser	I-Application
generators	O
:	O
</s>
