<s>
RE/flex	B-General_Concept
(	O
regex-centric	O
,	O
fast	B-General_Concept
lexical	I-General_Concept
analyzer	I-General_Concept
)	O
is	O
a	O
free	O
and	O
open	O
source	O
computer	B-Application
program	I-Application
written	O
in	O
C++	B-Language
that	O
generates	O
fast	B-General_Concept
lexical	I-General_Concept
analyzers	I-General_Concept
(	O
also	O
known	O
as	O
"	O
scanners	B-Application
"	O
or	O
"	O
lexers	B-Application
"	O
)	O
in	O
C++	B-Language
.	O
</s>
<s>
RE/flex	B-General_Concept
offers	O
full	O
Unicode	O
support	O
,	O
indentation	O
anchors	O
,	O
word	O
boundaries	O
,	O
lazy	O
quantifiers	O
(	O
non-greedy	O
,	O
lazy	O
repeats	O
)	O
,	O
and	O
performance	O
tuning	O
options	O
.	O
</s>
<s>
RE/flex	B-General_Concept
accepts	O
Flex	B-General_Concept
lexer	I-General_Concept
specifications	O
and	O
offers	O
options	O
to	O
generate	O
scanners	B-Application
for	O
Bison	B-Application
parsers	O
.	O
</s>
<s>
RE/flex	B-General_Concept
includes	O
a	O
fast	O
C++	B-Language
regular	B-Language
expression	I-Language
library	O
.	O
</s>
<s>
The	O
RE/flex	B-General_Concept
project	O
was	O
designed	O
and	O
implemented	O
by	O
professor	O
Robert	O
van	O
Engelen	O
in	O
2016	O
and	O
released	O
in	O
2017	O
as	O
free	O
open	O
source	O
.	O
</s>
<s>
The	O
RE/flex	B-General_Concept
tool	O
generates	O
lexical	B-Application
analyzers	I-Application
based	O
on	O
regular	B-Language
expression	I-Language
(	O
"	O
regex	B-Language
"	O
)	O
libraries	O
,	O
instead	O
of	O
fixed	O
DFA	B-General_Concept
tables	O
generated	O
by	O
traditional	O
lexical	B-Application
analyzer	I-Application
generators	O
.	O
</s>
<s>
The	O
RE/flex	B-General_Concept
lexical	B-Application
analyzer	I-Application
generator	O
accepts	O
an	O
extended	O
syntax	O
of	O
Flex	B-General_Concept
lexer	I-General_Concept
specifications	O
as	O
input	O
.	O
</s>
<s>
The	O
RE/flex	B-General_Concept
specification	O
syntax	O
is	O
more	O
expressive	O
than	O
the	O
traditional	O
Flex	B-General_Concept
lexer	I-General_Concept
specification	O
syntax	O
and	O
may	O
include	O
indentation	O
anchors	O
,	O
word	O
boundaries	O
,	O
lazy	O
quantifiers	O
(	O
non-greedy	O
,	O
lazy	O
repeats	O
)	O
,	O
and	O
new	O
actions	O
such	O
as	O
wstr( )	O
to	O
retrieve	O
Unicode	O
wide-string	O
matches	O
.	O
</s>
<s>
A	O
lexer	B-Application
specification	O
is	O
of	O
the	O
form	O
:	O
</s>
<s>
The	O
Definitions	O
section	O
includes	O
declarations	O
and	O
customization	O
options	O
,	O
followed	O
by	O
name-pattern	O
pairs	O
to	O
define	O
names	O
for	O
regular	B-Language
expression	I-Language
patterns	O
.	O
</s>
<s>
The	O
following	O
example	O
defines	O
a	O
rule	O
to	O
translate	O
a	O
number	O
to	O
the	O
lexer	B-Application
class	O
integer	O
value	O
member	O
:	O
</s>
<s>
The	O
User	O
Code	O
section	O
typically	O
defines	O
C/C	O
++	O
functions	O
,	O
for	O
example	O
a	O
main	O
program	O
:	O
</s>
<s>
The	O
yyFlexLexer	O
class	O
is	O
generated	O
by	O
RE/flex	B-General_Concept
as	O
instructed	O
by	O
the	O
%option	O
flex	B-General_Concept
directive	O
in	O
the	O
lexer	B-Application
specification	O
.	O
</s>
<s>
The	O
generated	O
lex.yy.cpp	O
source	O
code	O
contains	O
the	O
algorithm	O
for	O
lexical	B-Application
analysis	I-Application
,	O
which	O
is	O
linked	O
with	O
the	O
libreflex	O
library	O
.	O
</s>
<s>
The	O
generated	O
algorithm	O
for	O
lexical	B-Application
analysis	I-Application
is	O
based	O
on	O
the	O
concept	O
that	O
any	O
regular	B-Language
expression	I-Language
engine	O
can	O
in	O
principle	O
be	O
used	O
to	O
tokenize	O
input	O
into	O
tokens	O
:	O
given	O
a	O
set	O
of	O
regular	B-Language
expression	I-Language
patterns	O
for	O
,	O
a	O
regular	B-Language
expression	I-Language
of	O
the	O
form	O
"	O
(	O
)	O
|( 	O
)	O
|	O
...	O
|( 	O
)	O
"	O
with	O
alternations	O
may	O
be	O
specified	O
to	O
match	O
and	O
tokenize	O
the	O
input	O
.	O
</s>
<s>
In	O
this	O
way	O
,	O
the	O
group	O
capture	O
index	O
of	O
a	O
matching	O
pattern	O
that	O
is	O
returned	O
by	O
the	O
regular	B-Language
expression	I-Language
matcher	O
identifies	O
the	O
pattern	O
that	O
matched	O
the	O
input	O
text	O
partially	O
and	O
continuously	O
after	O
the	O
previous	O
match	O
.	O
</s>
<s>
This	O
approach	O
makes	O
it	O
possible	O
for	O
any	O
regex	B-Language
library	O
that	O
supports	O
group	O
captures	O
to	O
be	O
utilized	O
as	O
a	O
matcher	O
.	O
</s>
<s>
The	O
following	O
RE/flex	B-General_Concept
-generated	O
yyFlexLexer	O
class	O
yylex	O
method	O
repeatedly	O
invokes	O
the	O
matcher	O
's	O
scan	O
(	O
continuous	O
partial	O
matching	O
)	O
operation	O
to	O
tokenize	O
input	O
:	O
</s>
<s>
The	O
default	O
rule	O
echo	O
's	O
the	O
current	O
input	O
character	O
and	O
advances	O
the	O
scanner	B-Application
to	O
the	O
next	O
character	O
in	O
the	O
input	O
.	O
</s>
<s>
The	O
regular	B-Language
expression	I-Language
pattern	O
"	O
(	O
)	O
|( 	O
)	O
|	O
...	O
|( 	O
)	O
"	O
is	O
produced	O
by	O
RE/flex	B-General_Concept
from	O
a	O
lexer	B-Application
specification	O
with	O
rules	O
of	O
pattern-action	O
pairs	O
:	O
</s>
<s>
From	O
this	O
specification	O
,	O
RE/flex	B-General_Concept
generates	O
the	O
aforementioned	O
yyFlexLexer	O
class	O
with	O
the	O
yylex( )	O
method	O
that	O
executes	O
actions	O
corresponding	O
to	O
the	O
patterns	O
matched	O
in	O
the	O
input	O
.	O
</s>
<s>
The	O
generated	O
yyFlexLexer	O
class	O
is	O
used	O
in	O
a	O
C++	B-Language
application	O
,	O
such	O
as	O
a	O
parser	O
,	O
to	O
tokenize	O
the	O
input	O
into	O
the	O
integer-valued	O
tokens	O
returned	O
by	O
the	O
actions	O
in	O
the	O
lexer	B-Application
specification	O
.	O
</s>
<s>
A	O
lexical	B-Application
analyzer	I-Application
often	O
serves	O
as	O
a	O
tokenizer	O
for	O
a	O
parser	O
generated	O
by	O
a	O
parser	O
generator	O
such	O
as	O
Bison	B-Application
.	O
</s>
<s>
RE/flex	B-General_Concept
is	O
compatible	O
with	O
Flex	B-General_Concept
specifications	O
when	O
%option	O
flex	B-General_Concept
is	O
used	O
.	O
</s>
<s>
RE/flex	B-General_Concept
is	O
also	O
compatible	O
with	O
Bison	B-Application
using	O
a	O
range	O
of	O
RE/flex	B-General_Concept
options	O
for	O
complete	O
coverage	O
of	O
Bison	B-Application
options	O
and	O
features	O
.	O
</s>
<s>
By	O
contrast	O
to	O
Flex	B-General_Concept
,	O
RE/flex	B-General_Concept
scanners	B-Application
are	O
thread-safe	B-Operating_System
by	O
default	O
on	O
work	O
with	O
reentrant	O
Bison	B-Application
parsers	O
.	O
</s>
<s>
RE/flex	B-General_Concept
supports	O
Unicode	O
regular	B-Language
expression	I-Language
patterns	O
in	O
lexer	B-Application
specifications	O
and	O
automatically	O
tokenizes	O
UTF-8	O
,	O
UTF-16	O
,	O
and	O
UTF-32	O
input	O
files	O
.	O
</s>
<s>
Code	O
pages	O
may	O
be	O
specified	O
to	O
tokenize	O
input	O
files	O
encoded	O
in	O
ISO/IEC	O
8859	O
1	O
to	O
16	O
,	O
Windows-1250	O
to	O
Windows-1258	O
,	O
CP-437	O
,	O
CP-850	O
,	O
CP-858	O
,	O
MacRoman	O
,	O
KOI-8	O
,	O
EBCDIC	B-Language
,	O
and	O
so	O
on	O
.	O
</s>
<s>
Normalization	O
to	O
UTF-8	O
is	O
automatically	O
performed	O
by	O
internal	O
incremental	O
buffering	O
for	O
(	O
partial	O
)	O
pattern	O
matching	O
with	O
Unicode	O
regular	B-Language
expression	I-Language
patterns	O
.	O
</s>
<s>
RE/flex	B-General_Concept
integrates	O
indent	O
and	O
dedent	O
matching	O
directly	O
in	O
the	O
regular	B-Language
expression	I-Language
syntax	O
with	O
new	O
\i	O
and	O
\j	O
anchors	O
.	O
</s>
<s>
For	O
example	O
,	O
the	O
following	O
lexer	B-Application
specification	O
detects	O
and	O
reports	O
indentation	O
changes	O
:	O
</s>
<s>
Lazy	O
quantifiers	O
may	O
be	O
associated	O
with	O
repeats	O
in	O
RE/flex	B-General_Concept
regular	B-Language
expression	I-Language
patterns	O
to	O
simplify	O
the	O
expressions	O
using	O
non-greedy	O
repeats	O
,	O
when	O
applicable	O
.	O
</s>
<s>
As	O
a	O
practical	O
application	O
of	O
lazy	O
quantifiers	O
,	O
consider	O
matching	O
C/C	O
++	O
multiline	O
comments	O
of	O
the	O
form	O
/	O
*...*/	O
.	O
</s>
<s>
The	O
lexer	B-Application
specification	O
pattern	O
with	O
lazy	O
repeat	O
*	O
?	O
</s>
<s>
Without	O
lazy	O
repeats	O
the	O
pattern	O
should	O
be	O
used	O
(	O
note	O
that	O
quotation	O
of	O
the	O
form	O
"	O
...	O
"	O
is	O
allowed	O
in	O
lexer	B-Application
specifications	O
only	O
,	O
this	O
construct	O
is	O
comparable	O
to	O
the	O
Q	O
...	O
quotations	O
supported	O
by	O
most	O
regex	B-Language
libraries	O
.	O
)	O
</s>
<s>
RE/flex	B-General_Concept
offers	O
a	O
choice	O
of	O
regular	B-Language
expression	I-Language
pattern	O
matchers	O
:	O
RE/flex	B-General_Concept
regex	B-Language
and	O
Boost.Regex	O
.	O
</s>
<s>
The	O
RE/flex	B-General_Concept
regex	B-Language
engine	O
is	O
based	O
on	O
a	O
DFA	B-General_Concept
and	O
usually	O
has	O
a	O
time	O
complexity	O
of	O
in	O
the	O
length	O
of	O
the	O
input	O
.	O
</s>
<s>
Boost.Regex	O
offers	O
a	O
richer	O
regular	B-Language
expression	I-Language
pattern	O
syntax	O
,	O
but	O
is	O
slower	O
due	O
to	O
its	O
NFA-based	O
matching	O
algorithm	O
.	O
</s>
<s>
By	O
default	O
RE/flex	B-General_Concept
generates	O
DFA	B-General_Concept
tables	O
to	O
speed	O
up	O
the	O
matcher	O
's	O
scan	O
operation	O
.	O
</s>
<s>
A	O
faster	O
DFA	B-General_Concept
for	O
pattern	O
matching	O
is	O
generated	O
with	O
the	O
--fast	O
option	O
.	O
</s>
<s>
This	O
DFA	B-General_Concept
is	O
expressed	O
in	O
direct	O
code	O
instead	O
of	O
in	O
tables	O
.	O
</s>
<s>
For	O
example	O
,	O
the	O
following	O
coded	O
DFA	B-General_Concept
for	O
pattern	O
\w+	O
runs	O
very	O
efficiently	O
to	O
match	O
words	O
:	O
</s>
<s>
Performance	O
can	O
be	O
analyzed	O
for	O
optimization	O
using	O
the	O
RE/flex	B-General_Concept
built-in	O
profiler	O
.	O
</s>
<s>
When	O
the	O
scanner	B-Application
terminates	O
,	O
the	O
profiler	O
reports	O
the	O
number	O
of	O
times	O
a	O
rule	O
is	O
matched	O
and	O
the	O
cumulative	O
time	O
consumed	O
by	O
the	O
matching	O
rule	O
.	O
</s>
<s>
This	O
allows	O
fine-tuning	O
the	O
performance	O
of	O
the	O
generated	O
scanners	B-Application
and	O
parsers	O
.	O
</s>
<s>
First	O
,	O
the	O
lexer	B-Application
rules	O
that	O
are	O
hot	O
spots	O
,	O
i.e.	O
</s>
