<s>
In	O
computer	B-General_Concept
programming	I-General_Concept
and	O
computer	B-General_Concept
science	I-General_Concept
,	O
"	O
maximal	B-Application
munch	I-Application
"	O
or	O
"	O
longest	O
match	O
"	O
is	O
the	O
principle	O
that	O
when	O
creating	O
some	O
construct	O
,	O
as	O
much	O
of	O
the	O
available	O
input	O
as	O
possible	O
should	O
be	O
consumed	O
.	O
</s>
<s>
Cattell	O
in	O
his	O
PhD	O
thesis	O
on	O
automatic	O
derivation	O
of	O
code	O
generators	O
for	O
compilers	B-Language
.	O
</s>
<s>
For	O
instance	O
,	O
the	O
lexical	B-Application
syntax	I-Application
of	O
many	O
programming	O
languages	O
requires	O
that	O
tokens	O
be	O
built	O
from	O
the	O
maximum	O
possible	O
number	O
of	O
characters	O
from	O
the	O
input	O
stream	O
.	O
</s>
<s>
This	O
is	O
done	O
to	O
resolve	O
the	O
problem	O
of	O
inherent	O
ambiguity	O
in	O
commonly	O
used	O
regular	B-Language
expressions	I-Language
such	O
as	O
[a-z]+	O
(	O
one	O
or	O
more	O
lower-case	O
letters	O
)	O
.	O
</s>
<s>
The	O
term	O
is	O
also	O
used	O
in	O
compilers	B-Language
in	O
the	O
instruction	O
selection	O
stage	O
to	O
describe	O
a	O
method	O
of	O
"	O
tiling	O
"	O
—	O
determining	O
how	O
a	O
structured	O
tree	O
representing	O
a	O
program	O
in	O
an	O
intermediate	O
language	O
should	O
be	O
converted	O
into	O
linear	O
machine	B-Language
code	I-Language
.	O
</s>
<s>
An	O
entire	O
subtree	O
might	O
be	O
converted	O
into	O
just	O
one	O
machine	B-Language
instruction	I-Language
,	O
and	O
the	O
problem	O
is	O
how	O
to	O
split	O
the	O
tree	O
into	O
non-overlapping	O
"	O
tiles	O
"	O
,	O
each	O
representing	O
one	O
machine	B-Language
instruction	I-Language
.	O
</s>
<s>
An	O
effective	O
strategy	O
is	O
simply	O
to	O
make	O
a	O
tile	O
of	O
the	O
largest	O
subtree	O
possible	O
at	O
any	O
given	O
point	O
,	O
which	O
is	O
called	O
"	O
maximal	B-Application
munch	I-Application
"	O
.	O
</s>
<s>
In	O
some	O
situations	O
,	O
"	O
maximal	B-Application
munch	I-Application
"	O
leads	O
to	O
undesirable	O
or	O
unintuitive	O
outcomes	O
.	O
</s>
<s>
For	O
instance	O
,	O
in	O
the	O
C	B-Language
programming	I-Language
language	I-Language
,	O
the	O
statement	O
x	O
=	O
y/	O
*z	O
;	O
(	O
without	O
any	O
whitespace	O
)	O
will	O
probably	O
lead	O
to	O
a	O
syntax	O
error	O
,	O
since	O
the	O
/	O
*	O
character	O
sequence	O
initiates	O
a	O
(	O
unintended	O
)	O
comment	O
that	O
is	O
either	O
unterminated	O
or	O
terminated	O
by	O
the	O
end	O
token	O
*	O
/	O
of	O
some	O
later	O
,	O
unrelated	O
actual	O
comment	O
(	O
comments	O
in	O
C	B-Language
do	O
not	O
nest	O
)	O
.	O
</s>
<s>
Another	O
example	O
,	O
in	O
C++	B-Language
,	O
uses	O
the	O
"	O
angle	O
bracket	O
"	O
characters	O
< and > in the syntax for template specialization, but two consecutive > characters are interpreted as the right-shift operator >>	O
.	O
</s>
<s>
Prior	O
to	O
C++11	B-Language
,	O
the	O
following	O
code	O
would	O
produce	O
a	O
parse	O
error	O
,	O
because	O
the	O
right-shift	O
operator	O
token	O
is	O
encountered	O
instead	O
of	O
two	O
right-angle-bracket	O
tokens	O
:	O
</s>
<s>
The	O
C++11	B-Language
standard	O
adopted	O
in	O
August	O
2011	O
amended	O
the	O
grammar	O
so	O
that	O
a	O
right-shift	O
token	O
is	O
accepted	O
as	O
synonymous	O
with	O
a	O
pair	O
of	O
right	O
angle	O
brackets	O
(	O
as	O
in	O
Java	B-Language
)	O
,	O
which	O
complicates	O
the	O
grammar	O
but	O
allows	O
the	O
continued	O
use	O
of	O
the	O
maximal	B-Application
munch	I-Application
principle	O
.	O
</s>
<s>
An	O
exception	O
to	O
the	O
maximal	B-Application
munch	I-Application
rule	O
had	O
to	O
be	O
added	O
anyway	O
to	O
deal	O
with	O
the	O
sequence	O
<	O
::	O
which	O
can	O
appear	O
in	O
templates	B-Application
.	O
</s>
<s>
Programming	O
languages	O
researchers	O
have	O
also	O
responded	O
by	O
replacing	O
or	O
supplementing	O
the	O
principle	O
of	O
maximal	B-Application
munch	I-Application
with	O
other	O
lexical	O
disambiguation	O
tactics	O
.	O
</s>
<s>
For	O
example	O
,	O
stipulating	O
that	O
strings	O
matching	O
[a-z]+	O
cannot	O
be	O
followed	O
by	O
an	O
alphabetic	O
character	O
achieves	O
the	O
same	O
effect	O
as	O
maximal	B-Application
munch	I-Application
with	O
that	O
regular	B-Language
expression	I-Language
.	O
</s>
<s>
(	O
In	O
the	O
context	O
of	O
regular	B-Language
expressions	I-Language
,	O
the	O
maximal	B-Application
munch	I-Application
principle	O
is	O
referred	O
to	O
as	O
greediness	O
and	O
contrasted	O
with	O
laziness	O
.	O
)	O
</s>
<s>
Another	O
approach	O
is	O
to	O
keep	O
the	O
principle	O
of	O
maximal	B-Application
munch	I-Application
but	O
make	O
it	O
subordinate	O
to	O
some	O
other	O
principle	O
,	O
such	O
as	O
context	O
(	O
e.g.	O
,	O
the	O
right-shift	O
token	O
in	O
Java	B-Language
would	O
not	O
be	O
matched	O
in	O
the	O
context	O
of	O
a	O
generics	B-Language
expression	O
,	O
where	O
it	O
is	O
syntactically	O
invalid	O
)	O
.	O
</s>
