<s>
In	O
the	O
formal	O
language	O
theory	O
of	O
computer	B-General_Concept
science	I-General_Concept
,	O
left	B-Application
recursion	I-Application
is	O
a	O
special	O
case	O
of	O
recursion	O
where	O
a	O
string	O
is	O
recognized	O
as	O
part	O
of	O
a	O
language	O
by	O
the	O
fact	O
that	O
it	O
decomposes	O
into	O
a	O
string	O
from	O
that	O
same	O
language	O
(	O
on	O
the	O
left	O
)	O
and	O
a	O
suffix	O
(	O
on	O
the	O
right	O
)	O
.	O
</s>
<s>
In	O
terms	O
of	O
context-free	O
grammar	O
,	O
a	O
nonterminal	O
is	O
left-recursive	O
if	O
the	O
leftmost	O
symbol	O
in	O
one	O
of	O
its	O
productions	O
is	O
itself	O
(	O
in	O
the	O
case	O
of	O
direct	O
left	B-Application
recursion	I-Application
)	O
or	O
can	O
be	O
made	O
itself	O
by	O
some	O
sequence	O
of	O
substitutions	O
(	O
in	O
the	O
case	O
of	O
indirect	O
left	B-Application
recursion	I-Application
)	O
.	O
</s>
<s>
Direct	O
left	B-Application
recursion	I-Application
occurs	O
when	O
the	O
definition	O
can	O
be	O
satisfied	O
with	O
only	O
one	O
substitution	O
.	O
</s>
<s>
Indirect	O
left	B-Application
recursion	I-Application
occurs	O
when	O
the	O
definition	O
of	O
left	B-Application
recursion	I-Application
is	O
satisfied	O
via	O
several	O
substitutions	O
.	O
</s>
<s>
Left	B-Application
recursion	I-Application
often	O
poses	O
problems	O
for	O
parsers	B-Language
,	O
either	O
because	O
it	O
leads	O
them	O
into	O
infinite	O
recursion	O
(	O
as	O
in	O
the	O
case	O
of	O
most	O
top-down	B-Application
parsers	I-Application
)	O
or	O
because	O
they	O
expect	O
rules	O
in	O
a	O
normal	O
form	O
that	O
forbids	O
it	O
(	O
as	O
in	O
the	O
case	O
of	O
many	O
bottom-up	B-Application
parsers	I-Application
,	O
including	O
the	O
CYK	B-Application
algorithm	I-Application
)	O
.	O
</s>
<s>
Therefore	O
,	O
a	O
grammar	O
is	O
often	O
preprocessed	O
to	O
eliminate	O
the	O
left	B-Application
recursion	I-Application
.	O
</s>
<s>
The	O
general	O
algorithm	O
to	O
remove	O
direct	O
left	B-Application
recursion	I-Application
follows	O
.	O
</s>
<s>
Repeat	O
this	O
process	O
until	O
no	O
direct	O
left	B-Application
recursion	I-Application
remains	O
.	O
</s>
<s>
By	O
establishing	O
a	O
topological	B-Algorithm
ordering	I-Algorithm
on	O
nonterminals	O
,	O
the	O
above	O
process	O
can	O
be	O
extended	O
to	O
also	O
eliminate	O
indirect	O
left	B-Application
recursion	I-Application
:	O
</s>
<s>
Remove	O
direct	O
left	B-Application
recursion	I-Application
for	O
as	O
described	O
above	O
.	O
</s>
<s>
Although	O
the	O
above	O
transformations	O
preserve	O
the	O
language	O
generated	O
by	O
a	O
grammar	O
,	O
they	O
may	O
change	O
the	O
parse	B-Language
trees	O
that	O
witness	O
strings	O
 '	O
recognition	O
.	O
</s>
<s>
With	O
suitable	O
bookkeeping	O
,	O
tree	O
rewriting	O
can	O
recover	O
the	O
originals	O
,	O
but	O
if	O
this	O
step	O
is	O
omitted	O
,	O
the	O
differences	O
may	O
change	O
the	O
semantics	O
of	O
a	O
parse	B-Language
.	O
</s>
<s>
the	O
standard	O
transformations	O
to	O
remove	O
left	B-Application
recursion	I-Application
yield	O
the	O
following	O
:	O
</s>
<s>
Parsing	B-Language
the	O
string	O
"	O
1	O
-	O
2	O
-	O
3	O
"	O
with	O
the	O
first	O
grammar	O
in	O
an	O
LALR	B-Application
parser	I-Application
(	O
which	O
can	O
handle	O
left-recursive	O
grammars	O
)	O
would	O
have	O
resulted	O
in	O
the	O
parse	B-Language
tree	O
:	O
</s>
<s>
This	O
parse	B-Language
tree	O
groups	O
the	O
terms	O
on	O
the	O
left	O
,	O
giving	O
the	O
correct	O
semantics	O
(	O
1	O
-	O
2	O
)	O
-	O
3	O
.	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
LL(k )	O
-parser	O
or	O
other	O
naive	O
recursive	B-Application
descent	I-Application
parser	I-Application
unless	O
it	O
is	O
converted	O
to	O
a	O
weakly	O
equivalent	O
right-recursive	O
form	O
.	O
</s>
<s>
In	O
contrast	O
,	O
left	B-Application
recursion	I-Application
is	O
preferred	O
for	O
LALR	B-Application
parsers	I-Application
because	O
it	O
results	O
in	O
lower	O
stack	O
usage	O
than	O
right	O
recursion	O
.	O
</s>
<s>
However	O
,	O
more	O
sophisticated	O
top-down	B-Application
parsers	I-Application
can	O
implement	O
general	O
context-free	O
grammars	O
by	O
use	O
of	O
curtailment	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
as	O
well	O
as	O
direct	O
left	B-Application
recursion	I-Application
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
authors	O
then	O
implemented	O
the	O
algorithm	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>
