<s>
In	O
computer	B-General_Concept
programming	I-General_Concept
,	O
the	B-Language
lexer	I-Language
hack	I-Language
is	O
a	O
common	O
solution	O
to	O
the	O
problems	O
in	O
parsing	B-Language
ANSI	O
C	O
,	O
due	O
to	O
the	O
reference	O
grammar	O
being	O
context-sensitive	O
.	O
</s>
<s>
In	O
C	O
,	O
classifying	O
a	O
sequence	O
of	O
characters	O
as	O
a	O
variable	O
name	O
or	O
a	O
type	O
name	O
requires	O
contextual	O
information	O
of	O
the	O
phrase	O
structure	O
,	O
which	O
prevents	O
one	O
from	O
having	O
a	O
context-free	O
lexer	B-Application
.	O
</s>
<s>
Alternatively	O
,	O
it	O
could	O
be	O
casting	O
the	O
dereferenced	O
value	O
of	O
B	O
to	O
the	O
type	O
A	O
,	O
in	O
which	O
case	O
A	O
is	O
a	O
typedef	B-Language
name	O
;	O
written	O
unambiguously	O
:	O
</s>
<s>
In	O
more	O
detail	O
,	O
in	O
a	O
compiler	B-Language
,	O
the	O
lexer	B-Application
performs	O
one	O
of	O
the	O
earliest	O
stages	O
of	O
converting	O
the	O
source	O
code	O
to	O
a	O
program	O
.	O
</s>
<s>
This	O
ambiguity	O
can	O
happen	O
in	O
C	O
if	O
the	O
lexer	B-Application
does	O
not	O
distinguish	O
between	O
variable	O
and	O
typedef	B-Language
identifiers	O
.	O
</s>
<s>
the	O
lexer	B-Application
may	O
find	O
these	O
tokens	O
:	O
</s>
<s>
This	O
is	O
known	O
as	O
the	O
"	O
typedef-name	O
:	O
identifier	O
"	O
problem	O
,	O
due	O
to	O
the	O
name	O
of	O
the	O
problematic	O
production	O
rule	O
.	O
</s>
<s>
The	O
solution	O
generally	O
consists	O
of	O
feeding	O
information	O
from	O
the	O
semantic	O
symbol	B-Application
table	I-Application
back	O
into	O
the	O
lexer	B-Application
.	O
</s>
<s>
That	O
is	O
,	O
rather	O
than	O
functioning	O
as	O
a	O
pure	O
one-way	O
pipeline	B-Operating_System
from	O
the	O
lexer	B-Application
to	O
the	O
parser	O
,	O
there	O
is	O
a	O
backchannel	O
from	O
semantic	O
analysis	O
back	O
to	O
the	O
lexer	B-Application
.	O
</s>
<s>
This	O
mixing	O
of	O
parsing	B-Language
and	O
semantic	O
analysis	O
is	O
generally	O
regarded	O
as	O
inelegant	O
,	O
which	O
is	O
why	O
it	O
is	O
called	O
a	O
"	O
hack	O
"	O
.	O
</s>
<s>
Without	O
added	O
context	O
,	O
the	O
lexer	B-Application
cannot	O
distinguish	O
type	O
identifiers	O
from	O
other	O
identifiers	O
because	O
all	O
identifiers	O
have	O
the	O
same	O
format	O
.	O
</s>
<s>
With	O
the	O
hack	O
in	O
the	O
above	O
example	O
,	O
when	O
the	O
lexer	B-Application
finds	O
the	O
identifier	O
A	O
it	O
should	O
be	O
able	O
to	O
classify	O
the	O
token	O
as	O
a	O
type	O
identifier	O
.	O
</s>
<s>
The	O
problem	O
also	O
exists	O
in	O
C++	B-Language
and	O
parsers	B-Language
can	O
use	O
the	O
same	O
hack	O
.	O
</s>
<s>
This	O
problem	O
does	O
not	O
arise	O
(	O
and	O
hence	O
needs	O
no	O
"	O
hack	O
"	O
in	O
order	O
to	O
solve	O
)	O
when	O
using	O
lexerless	B-Application
parsing	I-Application
techniques	O
,	O
as	O
these	O
are	O
intrinsically	O
contextual	O
.	O
</s>
<s>
These	O
are	O
generally	O
seen	O
as	O
less	O
elegant	O
designs	O
,	O
however	O
,	O
because	O
they	O
lack	O
the	O
modularity	O
of	O
having	O
a	O
concurrent	B-Architecture
lexer	B-Application
and	O
parser	O
in	O
a	O
pipeline	B-Operating_System
.	O
</s>
<s>
Some	O
parser	O
generators	O
,	O
such	O
as	O
the	O
byacc-derived	O
BtYacc	O
(	O
"	O
Backtracking	O
Yacc	O
"	O
)	O
,	O
give	O
the	O
generated	O
parser	O
the	O
ability	O
to	O
try	O
multiple	O
attempts	O
to	O
parse	B-Language
the	O
tokens	O
.	O
</s>
<s>
The	O
Clang	B-Application
parser	O
handles	O
the	O
situation	O
in	O
a	O
completely	O
different	O
way	O
,	O
namely	O
by	O
using	O
a	O
non-reference	O
lexical	O
grammar	O
.	O
</s>
<s>
Clang	B-Application
's	O
lexer	B-Application
does	O
not	O
attempt	O
to	O
differentiate	O
between	O
type	O
names	O
and	O
variable	O
names	O
:	O
it	O
simply	O
reports	O
the	O
current	O
token	O
as	O
an	O
identifier	O
.	O
</s>
<s>
The	O
parser	O
then	O
uses	O
Clang	B-Application
's	O
semantic	O
analysis	O
library	O
to	O
determine	O
the	O
nature	O
of	O
the	O
identifier	O
.	O
</s>
<s>
This	O
allows	O
a	O
much	O
cleaner	O
separation	O
of	O
concerns	O
and	O
encapsulation	B-Application
of	O
the	O
lexer	B-Application
and	O
parser	O
,	O
and	O
is	O
therefore	O
considered	O
by	O
some	O
compiler	B-Language
developers	O
to	O
be	O
a	O
much	O
more	O
elegant	O
solution	O
than	O
The	B-Language
Lexer	I-Language
Hack	I-Language
.	O
</s>
<s>
This	O
is	O
also	O
the	O
approach	O
used	O
in	O
most	O
other	O
modern	O
languages	O
,	O
which	O
do	O
not	O
distinguish	O
different	O
classes	O
of	O
identifiers	O
in	O
the	O
lexical	O
grammar	O
,	O
but	O
instead	O
defer	O
them	O
to	O
the	O
parsing	B-Language
or	O
semantic	O
analysis	O
phase	O
,	O
when	O
sufficient	O
information	O
is	O
available	O
.	O
</s>
