Noeud:Flex Regular Expressions, Noeud « Next »:Flex Actions, Noeud « Previous »:Flex Directives, Noeud « Up »:Using Flex
The characters and literals may be described by:
x
.
[xyz]
x
, y
or z
. You may use a
dash for character intervals: [a-z]
denotes any letter from
a
through z
. You may use a leading hat to negate the
class: [0-9]
stands for any character which is not a decimal
digit, including new-line.
\
x
a
, b
, f
, n
, r
,
t
, or v
, then the ANSI-C interpretation of
\
x
. Otherwise, a literal
x
(used to escape
operators such as *
).
\0
\
num
\x
num
"
string"
"/*"
denotes the
character /
and then the character *
, as opposed to
/*
denoting any number of slashes.
<<EOF>>
The basic operators to make more complex regular expressions are, with r and s being two regular expressions:
(
r)
r
s
r|
s
{
abbreviation}
%% [a-zA-Z_][a-zA-Z0-9_]* return IDENTIFIER; %%
you may write
id [a-zA-Z_][a-zA-Z0-9_]* %% {id} return IDENTIFIER; %%
The quantifiers allow to specify the number of times a pattern must be repeated:
r*
r+
r?
r{
[
num
]}
r{
min,
[
max
]}
For instance -?([0-9]+|[0-9]*\.[0-9]+([eE][-+]?[0-9]+)?)
matches
C integer and floating point numbers.
One may also depend upon the context:
r/
s
do
, one needs:
DO/[A-Z0-9]*=[A-Z0-9]*,
to distinguish DO1I=1,5
, a for loop where I
runs from 1 to
5, from DO1I=1.5
, a definition/assignment of the floating
variable DO1I
to 1.5. Voir Fortran and Satellites, for more on
Fortran loops and traps.
^
r
r$
r/\n
, and therefore suffers the same problems, see
Simple Uses of Flex.