<s>
Top-down	B-Application
parsing	I-Application
in	O
computer	B-General_Concept
science	I-General_Concept
is	O
a	O
parsing	B-Language
strategy	O
where	O
one	O
first	O
looks	O
at	O
the	O
highest	O
level	O
of	O
the	O
parse	B-Language
tree	O
and	O
works	O
down	O
the	O
parse	B-Language
tree	O
by	O
using	O
the	O
rewriting	O
rules	O
of	O
a	O
formal	O
grammar	O
.	O
</s>
<s>
LL	B-Language
parsers	I-Language
are	O
a	O
type	O
of	O
parser	O
that	O
uses	O
a	O
top-down	B-Application
parsing	I-Application
strategy	O
.	O
</s>
<s>
Top-down	B-Application
parsing	I-Application
is	O
a	O
strategy	O
of	O
analyzing	O
unknown	O
data	O
relationships	O
by	O
hypothesizing	O
general	O
parse	B-Language
tree	O
structures	O
and	O
then	O
considering	O
whether	O
the	O
known	O
fundamental	O
structures	O
are	O
compatible	O
with	O
the	O
hypothesis	O
.	O
</s>
<s>
It	O
occurs	O
in	O
the	O
analysis	O
of	O
both	O
natural	O
languages	O
and	O
computer	B-Language
languages	I-Language
.	O
</s>
<s>
Top-down	B-Application
parsing	I-Application
can	O
be	O
viewed	O
as	O
an	O
attempt	O
to	O
find	O
left-most	O
derivations	O
of	O
an	O
input-stream	O
by	O
searching	O
for	O
parse-trees	O
using	O
a	O
top-down	O
expansion	O
of	O
the	O
given	O
formal	O
grammar	O
rules	O
.	O
</s>
<s>
Simple	O
implementations	O
of	O
top-down	B-Application
parsing	I-Application
do	O
not	O
terminate	O
for	O
left-recursive	B-Application
grammars	O
,	O
and	O
top-down	B-Application
parsing	I-Application
with	O
backtracking	O
may	O
have	O
exponential	O
time	O
complexity	O
with	O
respect	O
to	O
the	O
length	O
of	O
the	O
input	O
for	O
ambiguous	O
CFGs	O
.	O
</s>
<s>
However	O
,	O
more	O
sophisticated	O
top-down	B-Application
parsers	I-Application
have	O
been	O
created	O
by	O
Frost	O
,	O
Hafiz	O
,	O
and	O
Callaghan	O
,	O
which	O
do	O
accommodate	O
ambiguity	O
and	O
left	B-Application
recursion	I-Application
in	O
polynomial	O
time	O
and	O
which	O
generate	O
polynomial-sized	O
representations	O
of	O
the	O
potentially	O
exponential	O
number	O
of	O
parse	B-Language
trees	O
.	O
</s>
<s>
A	O
compiler	B-Language
parses	B-Language
input	O
from	O
a	O
programming	O
language	O
to	O
an	O
internal	O
representation	O
by	O
matching	O
the	O
incoming	O
symbols	O
to	O
production	O
rules	O
.	O
</s>
<s>
An	O
LL	B-Language
parser	I-Language
is	O
a	O
type	O
of	O
parser	O
that	O
does	O
top-down	B-Application
parsing	I-Application
by	O
applying	O
each	O
production	O
rule	O
to	O
the	O
incoming	O
symbols	O
,	O
working	O
from	O
the	O
left-most	O
symbol	O
yielded	O
on	O
a	O
production	O
rule	O
and	O
then	O
proceeding	O
to	O
the	O
next	O
production	O
rule	O
for	O
each	O
non-terminal	O
symbol	O
encountered	O
.	O
</s>
<s>
In	O
this	O
way	O
the	O
parsing	B-Language
starts	O
on	O
the	O
Left	O
of	O
the	O
result	O
side	O
(	O
right	O
side	O
)	O
of	O
the	O
production	O
rule	O
and	O
evaluates	O
non-terminals	O
from	O
the	O
Left	O
first	O
and	O
,	O
thus	O
,	O
proceeds	O
down	O
the	O
parse	B-Language
tree	O
for	O
each	O
new	O
non-terminal	O
before	O
continuing	O
to	O
the	O
next	O
symbol	O
for	O
a	O
production	O
rule	O
.	O
</s>
<s>
A	O
non-ambiguous	O
language	O
may	O
be	O
parsed	B-Language
by	O
an	O
LL(1 )	O
grammar	O
where	O
the	O
(	O
1	O
)	O
signifies	O
the	O
parser	O
reads	O
ahead	O
one	O
token	O
at	O
a	O
time	O
.	O
</s>
<s>
For	O
an	O
ambiguous	O
language	O
to	O
be	O
parsed	B-Language
by	O
an	O
LL	B-Language
parser	I-Language
,	O
the	O
parser	O
must	O
lookahead	O
more	O
than	O
1	O
symbol	O
,	O
e.g.	O
</s>
<s>
The	O
common	O
solution	O
to	O
this	O
problem	O
is	O
to	O
use	O
an	O
LR	B-Application
parser	I-Application
,	O
which	O
is	O
a	O
type	O
of	O
shift-reduce	B-Application
parser	I-Application
,	O
and	O
does	O
bottom-up	B-Application
parsing	I-Application
.	O
</s>
<s>
A	O
formal	O
grammar	O
that	O
contains	O
left	B-Application
recursion	I-Application
cannot	O
be	O
parsed	B-Language
by	O
a	O
naive	O
recursive	B-Application
descent	I-Application
parser	I-Application
unless	O
they	O
are	O
converted	O
to	O
a	O
weakly	O
equivalent	O
right-recursive	O
form	O
.	O
</s>
<s>
However	O
,	O
recent	O
research	O
demonstrates	O
that	O
it	O
is	O
possible	O
to	O
accommodate	O
left-recursive	B-Application
grammars	O
(	O
along	O
with	O
all	O
other	O
forms	O
of	O
general	O
CFGs	O
)	O
in	O
a	O
more	O
sophisticated	O
top-down	B-Application
parser	I-Application
by	O
use	O
of	O
curtailment	O
.	O
</s>
<s>
A	O
recognition	O
algorithm	O
that	O
accommodates	O
ambiguous	O
grammars	O
and	O
curtails	O
an	O
ever-growing	O
direct	O
left-recursive	B-Application
parse	B-Language
by	O
imposing	O
depth	O
restrictions	O
with	O
respect	O
to	O
input	O
length	O
and	O
current	O
input	O
position	O
,	O
is	O
described	O
by	O
Frost	O
and	O
Hafiz	O
in	O
2006	O
.	O
</s>
<s>
That	O
algorithm	O
was	O
extended	O
to	O
a	O
complete	O
parsing	B-Language
algorithm	O
to	O
accommodate	O
indirect	O
(	O
by	O
comparing	O
previously	O
computed	O
context	O
with	O
current	O
context	O
)	O
as	O
well	O
as	O
direct	O
left-recursion	O
in	O
polynomial	O
time	O
,	O
and	O
to	O
generate	O
compact	O
polynomial-size	O
representations	O
of	O
the	O
potentially	O
exponential	O
number	O
of	O
parse	B-Language
trees	O
for	O
highly	O
ambiguous	O
grammars	O
by	O
Frost	O
,	O
Hafiz	O
and	O
Callaghan	O
in	O
2007	O
.	O
</s>
<s>
The	O
algorithm	O
has	O
since	O
been	O
implemented	O
as	O
a	O
set	O
of	O
parser	B-Application
combinators	I-Application
written	O
in	O
the	O
Haskell	B-Language
programming	I-Language
language	I-Language
.	O
</s>
<s>
Additionally	O
,	O
one	O
may	O
use	O
a	O
Graph-structured	O
stack	O
(	O
GSS	O
)	O
in	O
addition	O
to	O
the	O
aforementioned	O
curtailment	O
in	O
order	O
to	O
accommodate	O
left	B-Application
recursion	I-Application
by	O
'	O
merging	O
 '	O
stacks	O
with	O
common	O
prefixes	O
and	O
by	O
preventing	O
infinite	O
recursion	O
,	O
thereby	O
reducing	O
the	O
number	O
and	O
contents	O
of	O
each	O
stack	O
,	O
thereby	O
reducing	O
the	O
time	O
and	O
space	O
complexity	O
of	O
the	O
parser	O
.	O
</s>
<s>
This	O
leads	O
to	O
a	O
algorithm	O
known	O
as	O
Generalized	O
LL	B-Language
parsing	I-Language
,	O
in	O
which	O
you	O
use	O
a	O
GSS	O
,	O
left-recursion	O
curtailment	O
,	O
and	O
an	O
LL(k )	O
parser	O
to	O
parse	B-Language
input	O
strings	O
relative	O
to	O
a	O
given	O
CFG	O
.	O
</s>
<s>
When	O
top-down	B-Application
parser	I-Application
tries	O
to	O
parse	B-Language
an	O
ambiguous	O
input	O
with	O
respect	O
to	O
an	O
ambiguous	O
CFG	O
,	O
it	O
may	O
need	O
exponential	O
number	O
of	O
steps	O
(	O
with	O
respect	O
to	O
the	O
length	O
of	O
the	O
input	O
)	O
to	O
try	O
all	O
alternatives	O
of	O
the	O
CFG	O
in	O
order	O
to	O
produce	O
all	O
possible	O
parse	B-Language
trees	O
,	O
which	O
eventually	O
would	O
require	O
exponential	O
memory	O
space	O
.	O
</s>
<s>
The	O
problem	O
of	O
exponential	O
time	O
complexity	O
in	O
top-down	B-Application
parsers	I-Application
constructed	O
as	O
sets	O
of	O
mutually	O
recursive	O
functions	O
has	O
been	O
solved	O
by	O
Norvig	O
in	O
1991	O
.	O
</s>
<s>
His	O
technique	O
is	O
similar	O
to	O
the	O
use	O
of	O
dynamic	O
programming	O
and	O
state-sets	O
in	O
Earley	B-Algorithm
's	I-Algorithm
algorithm	I-Algorithm
(	O
1970	O
)	O
,	O
and	O
tables	O
in	O
the	O
CYK	B-Application
algorithm	I-Application
of	O
Cocke	O
,	O
Younger	O
and	O
Kasami	O
.	O
</s>
<s>
Frost	O
,	O
Hafiz	O
and	O
Callaghan	O
also	O
use	O
memoization	O
for	O
refraining	O
redundant	O
computations	O
to	O
accommodate	O
any	O
form	O
of	O
CFG	O
in	O
polynomial	O
time	O
(Θ(n4 )	O
for	O
left-recursive	B-Application
grammars	O
and	O
Θ(n3 )	O
for	O
non	O
left-recursive	B-Application
grammars	O
)	O
.	O
</s>
<s>
Their	O
top-down	B-Application
parsing	I-Application
algorithm	O
also	O
requires	O
polynomial	O
space	O
for	O
potentially	O
exponential	O
ambiguous	O
parse	B-Language
trees	O
by	O
'	O
compact	O
representation	O
 '	O
and	O
'	O
local	O
ambiguities	O
grouping	O
 '	O
.	O
</s>
<s>
Their	O
compact	O
representation	O
is	O
comparable	O
with	O
Tomita	O
's	O
compact	O
representation	O
of	O
bottom-up	B-Application
parsing	I-Application
.	O
</s>
<s>
Using	O
PEG	O
's	O
,	O
another	O
representation	O
of	O
grammars	O
,	O
packrat	O
parsers	B-Language
provide	O
an	O
elegant	O
and	O
powerful	O
parsing	B-Language
algorithm	O
.	O
</s>
<s>
See	O
Parsing	B-Language
expression	O
grammar	O
.	O
</s>
<s>
Some	O
of	O
the	O
parsers	B-Language
that	O
use	O
top-down	B-Application
parsing	I-Application
include	O
:	O
</s>
