<s>
re2c	B-Application
is	O
a	O
free	B-License
and	I-License
open-source	I-License
lexer	B-Application
generator	I-Application
for	O
C	B-Language
,	O
C++	B-Language
,	O
Go	B-Application
,	O
and	O
Rust	B-Application
.	O
</s>
<s>
It	O
compiles	O
declarative	O
regular	O
expression	O
specifications	O
to	O
deterministic	B-General_Concept
finite	I-General_Concept
automata	I-General_Concept
.	O
</s>
<s>
Originally	O
written	O
by	O
Peter	O
Bumbulis	O
and	O
described	O
in	O
his	O
paper	O
,	O
re2c	B-Application
was	O
put	O
in	O
public	O
domain	O
and	O
has	O
been	O
since	O
maintained	O
by	O
volunteers	O
.	O
</s>
<s>
It	O
is	O
the	O
lexer	B-Application
generator	I-Application
adopted	O
by	O
projects	O
such	O
as	O
PHP	B-Application
,	O
SpamAssassin	B-Language
,	O
Ninja	B-Application
build	I-Application
system	I-Application
and	O
others	O
.	O
</s>
<s>
Together	O
with	O
the	O
Lemon	B-Application
parser	I-Application
generator	I-Application
,	O
re2c	B-Application
is	O
used	O
in	O
BRL-CAD	B-Language
.	O
</s>
<s>
The	O
main	O
goal	O
of	O
re2c	B-Application
is	O
generating	O
fast	O
lexers	B-Application
:	O
</s>
<s>
at	O
least	O
as	O
fast	O
as	O
reasonably	O
optimized	O
C	B-Language
lexers	B-Application
coded	O
by	O
hand	O
.	O
</s>
<s>
encodes	O
the	O
generated	O
finite	B-Architecture
state	I-Architecture
machine	I-Architecture
directly	O
in	O
the	O
form	O
of	O
conditional	O
jumps	O
and	O
comparisons	O
.	O
</s>
<s>
Moreover	O
,	O
this	O
approach	O
often	O
results	O
in	O
smaller	O
lexers	B-Application
,	O
</s>
<s>
as	O
re2c	B-Application
applies	O
a	O
number	O
of	O
optimizations	O
such	O
as	O
DFA	B-General_Concept
minimization	I-General_Concept
and	O
the	O
construction	O
of	O
tunnel	O
automaton	O
.	O
</s>
<s>
Another	O
distinctive	O
feature	O
of	O
re2c	B-Application
is	O
its	O
flexible	O
interface	O
:	O
</s>
<s>
re2c	B-Application
lets	O
the	O
programmer	O
write	O
most	O
of	O
the	O
interface	O
code	O
and	O
adapt	O
the	O
generated	O
lexer	B-Application
to	O
any	O
particular	O
environment	O
.	O
</s>
<s>
The	O
main	O
idea	O
is	O
that	O
re2c	B-Application
should	O
be	O
a	O
zero-cost	O
abstraction	O
for	O
the	O
programmer	O
:	O
</s>
<s>
Submatch	O
extraction	O
:	O
re2c	B-Application
supports	O
both	O
POSIX-compliant	O
capturing	O
groups	O
and	O
standalone	O
tags	O
(	O
with	O
leftmost	O
greedy	O
disambiguation	O
and	O
optional	O
handling	O
of	O
repeated	O
submatch	O
)	O
.	O
</s>
<s>
Encoding	O
support	O
:	O
re2c	B-Application
supports	O
ASCII	O
,	O
UTF-8	O
,	O
UTF-16	O
,	O
UTF-32	O
,	O
UCS-2	O
and	O
EBCDIC	O
.	O
</s>
<s>
Storable	O
state	O
:	O
re2c	B-Application
supports	O
both	O
pull-model	O
lexers	B-Application
(	O
when	O
lexer	B-Application
runs	O
without	O
interrupts	O
and	O
pulls	O
more	O
input	O
as	O
necessary	O
)	O
and	O
push-model	O
lexers	B-Application
(	O
when	O
lexer	B-Application
is	O
periodically	O
stopped	O
and	O
resumed	O
to	O
parse	O
new	O
chunks	O
of	O
input	O
)	O
.	O
</s>
<s>
Start	O
conditions	O
:	O
re2c	B-Application
can	O
generate	O
multiple	O
interrelated	O
lexers	B-Application
,	O
where	O
each	O
lexer	B-Application
is	O
triggered	O
by	O
a	O
certain	O
condition	O
in	O
program	O
.	O
</s>
<s>
Self-validation	O
:	O
re2c	B-Application
has	O
a	O
special	O
mode	O
in	O
which	O
it	O
ignores	O
all	O
used-defined	O
interface	O
code	O
and	O
generates	O
a	O
self-contained	O
skeleton	O
program	O
.	O
</s>
<s>
Additionally	O
,	O
re2c	B-Application
generates	O
two	O
files	O
:	O
one	O
with	O
the	O
input	O
strings	O
derived	O
from	O
the	O
regular	O
grammar	O
,	O
and	O
one	O
with	O
compressed	O
match	O
results	O
that	O
are	O
used	O
to	O
verify	O
lexer	B-Application
behavior	O
on	O
all	O
inputs	O
.	O
</s>
<s>
Input	O
strings	O
are	O
generated	O
so	O
that	O
they	O
extensively	O
cover	O
DFA	B-General_Concept
transitions	O
and	O
paths	O
.	O
</s>
<s>
Data	O
generation	O
happens	O
right	O
after	O
DFA	B-General_Concept
construction	O
and	O
prior	O
to	O
any	O
optimizations	O
,	O
but	O
the	O
lexer	B-Application
itself	O
is	O
fully	O
optimized	O
,	O
so	O
skeleton	O
programs	O
are	O
capable	O
of	O
revealing	O
any	O
errors	O
in	O
optimizations	O
and	O
code	O
generation	O
.	O
</s>
<s>
Warnings	O
:	O
re2c	B-Application
performs	O
static	O
analysis	O
of	O
the	O
program	O
and	O
warns	O
its	O
users	O
about	O
possible	O
deficiencies	O
or	O
bugs	O
,	O
such	O
as	O
undefined	O
control	O
flow	O
,	O
unreachable	O
code	O
,	O
ill-formed	O
escape	O
symbols	O
and	O
potential	O
misuse	O
of	O
the	O
interface	O
primitives	O
.	O
</s>
<s>
Besides	O
generating	O
human-readable	O
lexers	B-Application
,	O
re2c	B-Application
has	O
a	O
number	O
of	O
options	O
that	O
dump	O
various	O
intermediate	O
representations	O
of	O
the	O
generated	O
lexer	B-Application
,	O
such	O
as	O
NFA	B-General_Concept
,	O
multiple	O
stages	O
of	O
DFA	B-General_Concept
and	O
the	O
resulting	O
program	O
graph	O
in	O
DOT	B-Application
format	I-Application
.	O
</s>
<s>
re2c	B-Application
program	O
can	O
contain	O
any	O
number	O
of	O
/	O
*	O
!	O
re2c	B-Application
...	O
*	O
/	O
blocks	O
.	O
</s>
<s>
Rules	O
have	O
the	O
form	O
REGEXP	O
{	O
CODE	O
}	O
or	O
REGEXP	O
:=	O
CODE	O
;	O
where	O
REGEXP	O
is	O
a	O
regular	O
expression	O
and	O
CODE	O
is	O
a	O
block	O
of	O
C	B-Language
code	O
.	O
</s>
<s>
re2c	B-Application
has	O
greedy	O
matching	O
semantics	O
:	O
if	O
multiple	O
rules	O
match	O
,	O
the	O
rule	O
that	O
matches	O
longer	O
prefix	O
is	O
preferred	O
;	O
if	O
the	O
conflicting	O
rules	O
match	O
the	O
same	O
prefix	O
,	O
the	O
earlier	O
rule	O
has	O
priority	O
.	O
</s>
<s>
Definitions	O
have	O
the	O
form	O
NAME	O
=	O
REGEXP	O
;	O
(	O
and	O
also	O
NAME	O
{	O
REGEXP	O
}	O
in	O
Flex	B-General_Concept
compatibility	O
mode	O
)	O
.	O
</s>
<s>
Configurations	O
have	O
the	O
form	O
re2c:CONFIG	O
=	O
VALUE	O
;	O
where	O
CONFIG	O
is	O
the	O
name	O
of	O
the	O
particular	O
configuration	O
and	O
VALUE	O
is	O
a	O
number	O
or	O
a	O
string	O
.	O
</s>
<s>
For	O
more	O
advanced	O
usage	O
see	O
the	O
official	O
re2c	B-Application
manual	O
.	O
</s>
<s>
re2c	B-Application
uses	O
the	O
following	O
syntax	O
for	O
regular	O
expressions	O
:	O
</s>
<s>
Here	O
is	O
a	O
very	O
simple	O
program	O
in	O
re2c	B-Application
(	O
example.re	O
)	O
.	O
</s>
<s>
The	O
code	O
for	O
re2c	B-Application
is	O
enclosed	O
in	O
comments	O
/	O
*	O
!	O
re2c	B-Application
...	O
*	O
/	O
,	O
all	O
the	O
rest	O
is	O
plain	O
C	B-Language
code	O
.	O
</s>
<s>
See	O
the	O
official	O
re2c	B-Application
website	O
for	O
more	O
complex	O
examples	O
.	O
</s>
<s>
Given	O
that	O
,	O
re2c	B-Application
-is	O
-o	O
example.c	O
example.re	O
generates	O
the	O
code	O
below	O
(	O
example.c	O
)	O
.	O
</s>
<s>
There	O
are	O
several	O
code	O
generation	O
options	O
;	O
normally	O
re2c	B-Application
uses	O
switch	O
statements	O
,	O
</s>
<s>
Which	O
option	O
is	O
better	O
depends	O
on	O
the	O
C	B-Language
compiler	O
;	O
</s>
<s>
re2c	B-Application
users	O
are	O
encouraged	O
to	O
experiment	O
.	O
</s>
