NetBSD/usr.bin/lex/lex.1

782 lines
20 KiB
Groff
Raw Normal View History

1993-05-04 11:44:39 +04:00
.TH FLEX 1 "26 May 1990" "Version 2.3"
.SH NAME
flex - fast lexical analyzer generator
.SH SYNOPSIS
.B flex
.B [-bcdfinpstvFILT8 -C[efmF] -Sskeleton]
.I [filename ...]
.SH DESCRIPTION
.I flex
1993-03-21 12:45:37 +03:00
is a tool for generating
1993-05-04 11:44:39 +04:00
.I scanners:
1993-03-21 12:45:37 +03:00
programs which recognized lexical patterns in text.
1993-05-04 11:44:39 +04:00
.I flex
1993-03-21 12:45:37 +03:00
reads
the given input files, or its standard input if no file names are given,
for a description of a scanner to generate. The description is in
the form of pairs
of regular expressions and C code, called
1993-05-04 11:44:39 +04:00
.I rules. flex
1993-03-21 12:45:37 +03:00
generates as output a C source file,
1993-05-04 11:44:39 +04:00
.B lex.yy.c,
1993-03-21 12:45:37 +03:00
which defines a routine
1993-05-04 11:44:39 +04:00
.B yylex().
1993-03-21 12:45:37 +03:00
This file is compiled and linked with the
1993-05-04 11:44:39 +04:00
.B -lfl
1993-03-21 12:45:37 +03:00
library to produce an executable. When the executable is run,
it analyzes its input for occurrences
of the regular expressions. Whenever it finds one, it executes
the corresponding C code.
1993-05-04 11:44:39 +04:00
.LP
1993-03-21 12:45:37 +03:00
For full documentation, see
1993-05-04 11:44:39 +04:00
.B flexdoc(1).
1993-03-21 12:45:37 +03:00
This manual entry is intended for use as a quick reference.
1993-05-04 11:44:39 +04:00
.SH OPTIONS
.I flex
1993-03-21 12:45:37 +03:00
has the following options:
1993-05-04 11:44:39 +04:00
.TP
.B -b
1993-03-21 12:45:37 +03:00
Generate backtracking information to
1993-05-04 11:44:39 +04:00
.I lex.backtrack.
1993-03-21 12:45:37 +03:00
This is a list of scanner states which require backtracking
and the input characters on which they do so. By adding rules one
can remove backtracking states. If all backtracking states
are eliminated and
1993-05-04 11:44:39 +04:00
.B -f
1993-03-21 12:45:37 +03:00
or
1993-05-04 11:44:39 +04:00
.B -F
1993-03-21 12:45:37 +03:00
is used, the generated scanner will run faster.
1993-05-04 11:44:39 +04:00
.TP
.B -c
is a do-nothing, deprecated option included for POSIX compliance.
.IP
.B NOTE:
1993-03-21 12:45:37 +03:00
in previous releases of
1993-05-04 11:44:39 +04:00
.I flex
.B -c
1993-03-21 12:45:37 +03:00
specified table-compression options. This functionality is
now given by the
1993-05-04 11:44:39 +04:00
.B -C
1993-03-21 12:45:37 +03:00
flag. To ease the the impact of this change, when
1993-05-04 11:44:39 +04:00
.I flex
1993-03-21 12:45:37 +03:00
encounters
1993-05-04 11:44:39 +04:00
.B -c,
1993-03-21 12:45:37 +03:00
it currently issues a warning message and assumes that
1993-05-04 11:44:39 +04:00
.B -C
1993-03-21 12:45:37 +03:00
was desired instead. In the future this "promotion" of
1993-05-04 11:44:39 +04:00
.B -c
1993-03-21 12:45:37 +03:00
to
1993-05-04 11:44:39 +04:00
.B -C
will go away in the name of full POSIX compliance (unless
the POSIX meaning is removed first).
.TP
.B -d
makes the generated scanner run in
.I debug
1993-03-21 12:45:37 +03:00
mode. Whenever a pattern is recognized and the global
1993-05-04 11:44:39 +04:00
.B yy_flex_debug
1993-03-21 12:45:37 +03:00
is non-zero (which is the default), the scanner will
write to
1993-05-04 11:44:39 +04:00
.I stderr
1993-03-21 12:45:37 +03:00
a line of the form:
1993-05-04 11:44:39 +04:00
.nf
--accepting rule at line 53 ("the matched text")
.fi
1993-03-21 12:45:37 +03:00
The line number refers to the location of the rule in the file
1993-05-04 11:44:39 +04:00
defining the scanner (i.e., the file that was fed to flex). Messages
1993-03-21 12:45:37 +03:00
are also generated when the scanner backtracks, accepts the
default rule, reaches the end of its input buffer (or encounters
1993-05-04 11:44:39 +04:00
a NUL; the two look the same as far as the scanner's concerned),
1993-03-21 12:45:37 +03:00
or reaches an end-of-file.
1993-05-04 11:44:39 +04:00
.TP
.B -f
specifies (take your pick)
.I full table
1993-03-21 12:45:37 +03:00
or
1993-05-04 11:44:39 +04:00
.I fast scanner.
1993-03-21 12:45:37 +03:00
No table compression is done. The result is large but fast.
This option is equivalent to
1993-05-04 11:44:39 +04:00
.B -Cf
1993-03-21 12:45:37 +03:00
(see below).
1993-05-04 11:44:39 +04:00
.TP
.B -i
instructs
.I flex
1993-03-21 12:45:37 +03:00
to generate a
1993-05-04 11:44:39 +04:00
.I case-insensitive
1993-03-21 12:45:37 +03:00
scanner. The case of letters given in the
1993-05-04 11:44:39 +04:00
.I flex
1993-03-21 12:45:37 +03:00
input patterns will
be ignored, and tokens in the input will be matched regardless of case. The
matched text given in
1993-05-04 11:44:39 +04:00
.I yytext
1993-03-21 12:45:37 +03:00
will have the preserved case (i.e., it will not be folded).
1993-05-04 11:44:39 +04:00
.TP
.B -n
is another do-nothing, deprecated option included only for
POSIX compliance.
.TP
.B -p
generates a performance report to stderr. The report
1993-03-21 12:45:37 +03:00
consists of comments regarding features of the
1993-05-04 11:44:39 +04:00
.I flex
1993-03-21 12:45:37 +03:00
input file which will cause a loss of performance in the resulting scanner.
1993-05-04 11:44:39 +04:00
.TP
.B -s
causes the
.I default rule
1993-03-21 12:45:37 +03:00
(that unmatched scanner input is echoed to
1993-05-04 11:44:39 +04:00
.I stdout)
1993-03-21 12:45:37 +03:00
to be suppressed. If the scanner encounters input that does not
match any of its rules, it aborts with an error.
1993-05-04 11:44:39 +04:00
.TP
.B -t
instructs
.I flex
1993-03-21 12:45:37 +03:00
to write the scanner it generates to standard output instead
of
1993-05-04 11:44:39 +04:00
.B lex.yy.c.
.TP
.B -v
specifies that
.I flex
1993-03-21 12:45:37 +03:00
should write to
1993-05-04 11:44:39 +04:00
.I stderr
1993-03-21 12:45:37 +03:00
a summary of statistics regarding the scanner it generates.
1993-05-04 11:44:39 +04:00
.TP
.B -F
specifies that the
.ul
fast
1993-03-21 12:45:37 +03:00
scanner table representation should be used. This representation is
about as fast as the full table representation
1993-05-04 11:44:39 +04:00
.ul
(-f),
1993-03-21 12:45:37 +03:00
and for some sets of patterns will be considerably smaller (and for
others, larger). See
1993-05-04 11:44:39 +04:00
.B flexdoc(1)
1993-03-21 12:45:37 +03:00
for details.
1993-05-04 11:44:39 +04:00
.IP
1993-03-21 12:45:37 +03:00
This option is equivalent to
1993-05-04 11:44:39 +04:00
.B -CF
1993-03-21 12:45:37 +03:00
(see below).
1993-05-04 11:44:39 +04:00
.TP
.B -I
instructs
.I flex
1993-03-21 12:45:37 +03:00
to generate an
1993-05-04 11:44:39 +04:00
.I interactive
1993-03-21 12:45:37 +03:00
scanner, that is, a scanner which stops immediately rather than
looking ahead if it knows
that the currently scanned text cannot be part of a longer rule's match.
Again, see
1993-05-04 11:44:39 +04:00
.B flexdoc(1)
1993-03-21 12:45:37 +03:00
for details.
1993-05-04 11:44:39 +04:00
.IP
1993-03-21 12:45:37 +03:00
Note,
1993-05-04 11:44:39 +04:00
.B -I
1993-03-21 12:45:37 +03:00
cannot be used in conjunction with
1993-05-04 11:44:39 +04:00
.I full
1993-03-21 12:45:37 +03:00
or
1993-05-04 11:44:39 +04:00
.I fast tables,
1993-03-21 12:45:37 +03:00
i.e., the
1993-05-04 11:44:39 +04:00
.B -f, -F, -Cf,
1993-03-21 12:45:37 +03:00
or
1993-05-04 11:44:39 +04:00
.B -CF
1993-03-21 12:45:37 +03:00
flags.
1993-05-04 11:44:39 +04:00
.TP
.B -L
instructs
.I flex
1993-03-21 12:45:37 +03:00
not to generate
1993-05-04 11:44:39 +04:00
.B #line
1993-03-21 12:45:37 +03:00
directives in
1993-05-04 11:44:39 +04:00
.B lex.yy.c.
1993-03-21 12:45:37 +03:00
The default is to generate such directives so error
messages in the actions will be correctly
located with respect to the original
1993-05-04 11:44:39 +04:00
.I flex
1993-03-21 12:45:37 +03:00
input file, and not to
the fairly meaningless line numbers of
1993-05-04 11:44:39 +04:00
.B lex.yy.c.
.TP
.B -T
makes
.I flex
1993-03-21 12:45:37 +03:00
run in
1993-05-04 11:44:39 +04:00
.I trace
1993-03-21 12:45:37 +03:00
mode. It will generate a lot of messages to
1993-05-04 11:44:39 +04:00
.I stdout
1993-03-21 12:45:37 +03:00
concerning
the form of the input and the resultant non-deterministic and deterministic
finite automata. This option is mostly for use in maintaining
1993-05-04 11:44:39 +04:00
.I flex.
.TP
.B -8
instructs
.I flex
1993-03-21 12:45:37 +03:00
to generate an 8-bit scanner.
On some sites, this is the default. On others, the default
is 7-bit characters. To see which is the case, check the verbose
1993-05-04 11:44:39 +04:00
.B (-v)
1993-03-21 12:45:37 +03:00
output for "equivalence classes created". If the denominator of
the number shown is 128, then by default
1993-05-04 11:44:39 +04:00
.I flex
1993-03-21 12:45:37 +03:00
is generating 7-bit characters. If it is 256, then the default is
8-bit characters.
1993-05-04 11:44:39 +04:00
.TP
.B -C[efmF]
controls the degree of table compression.
.IP
.B -Ce
directs
.I flex
1993-03-21 12:45:37 +03:00
to construct
1993-05-04 11:44:39 +04:00
.I equivalence classes,
1993-03-21 12:45:37 +03:00
i.e., sets of characters
which have identical lexical properties.
Equivalence classes usually give
dramatic reductions in the final table/object file sizes (typically
a factor of 2-5) and are pretty cheap performance-wise (one array
look-up per character scanned).
1993-05-04 11:44:39 +04:00
.IP
.B -Cf
specifies that the
.I full
1993-03-21 12:45:37 +03:00
scanner tables should be generated -
1993-05-04 11:44:39 +04:00
.I flex
1993-03-21 12:45:37 +03:00
should not compress the
tables by taking advantages of similar transition functions for
different states.
1993-05-04 11:44:39 +04:00
.IP
.B -CF
specifies that the alternate fast scanner representation (described in
.B flexdoc(1))
1993-03-21 12:45:37 +03:00
should be used.
1993-05-04 11:44:39 +04:00
.IP
.B -Cm
directs
.I flex
1993-03-21 12:45:37 +03:00
to construct
1993-05-04 11:44:39 +04:00
.I meta-equivalence classes,
1993-03-21 12:45:37 +03:00
which are sets of equivalence classes (or characters, if equivalence
classes are not being used) that are commonly used together. Meta-equivalence
classes are often a big win when using compressed tables, but they
have a moderate performance impact (one or two "if" tests and one
array look-up per character scanned).
1993-05-04 11:44:39 +04:00
.IP
A lone
.B -C
specifies that the scanner tables should be compressed but neither
equivalence classes nor meta-equivalence classes should be used.
.IP
1993-03-21 12:45:37 +03:00
The options
1993-05-04 11:44:39 +04:00
.B -Cf
1993-03-21 12:45:37 +03:00
or
1993-05-04 11:44:39 +04:00
.B -CF
1993-03-21 12:45:37 +03:00
and
1993-05-04 11:44:39 +04:00
.B -Cm
1993-03-21 12:45:37 +03:00
do not make sense together - there is no opportunity for meta-equivalence
classes if the table is not being compressed. Otherwise the options
may be freely mixed.
1993-05-04 11:44:39 +04:00
.IP
The default setting is
.B -Cem,
which specifies that
.I flex
should generate equivalence classes
and meta-equivalence classes. This setting provides the highest
degree of table compression. You can trade off
faster-executing scanners at the cost of larger tables with
the following generally being true:
.nf
slowest & smallest
-Cem
-Cm
-Ce
-C
-C{f,F}e
-C{f,F}
fastest & largest
.fi
.IP
.B -C
options are not cumulative; whenever the flag is encountered, the
previous -C settings are forgotten.
.TP
.B -Sskeleton_file
overrides the default skeleton file from which
.I flex
constructs its scanners. You'll never need this option unless you are doing
.I flex
1993-03-21 12:45:37 +03:00
maintenance or development.
1993-05-04 11:44:39 +04:00
.SH SUMMARY OF FLEX REGULAR EXPRESSIONS
1993-03-21 12:45:37 +03:00
The patterns in the input are written using an extended set of regular
expressions. These are:
1993-05-04 11:44:39 +04:00
.nf
x match the character 'x'
. any character except newline
[xyz] a "character class"; in this case, the pattern
matches either an 'x', a 'y', or a 'z'
[abj-oZ] a "character class" with a range in it; matches
an 'a', a 'b', any letter from 'j' through 'o',
or a 'Z'
[^A-Z] a "negated character class", i.e., any character
but those in the class. In this case, any
character EXCEPT an uppercase letter.
[^A-Z\\n] any character EXCEPT an uppercase letter or
a newline
r* zero or more r's, where r is any regular expression
r+ one or more r's
r? zero or one r's (that is, "an optional r")
r{2,5} anywhere from two to five r's
r{2,} two or more r's
r{4} exactly 4 r's
{name} the expansion of the "name" definition
(see above)
"[xyz]\\"foo"
the literal string: [xyz]"foo
\\X if X is an '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 '*')
\\123 the character with octal value 123
\\x2a the character with hexadecimal value 2a
(r) match an r; parentheses are used to override
precedence (see below)
rs the regular expression r followed by the
regular expression s; called "concatenation"
r|s either an r or an s
r/s an r but only if it is followed by an s. The
s is not part of the matched text. This type
of pattern is called as "trailing context".
^r an r, but only at the beginning of a line
r$ an r, but only at the end of a line. Equivalent
to "r/\\n".
<s>r an r, but only in start condition s (see
below for discussion of start conditions)
<s1,s2,s3>r
same, but in any of start conditions s1,
s2, or s3
<<EOF>> an end-of-file
<s1,s2><<EOF>>
an end-of-file when in start condition s1 or s2
.fi
1993-03-21 12:45:37 +03:00
The regular expressions listed above are grouped according to
precedence, from highest precedence at the top to lowest at the bottom.
Those grouped together have equal precedence.
1993-05-04 11:44:39 +04:00
.LP
1993-03-21 12:45:37 +03:00
Some notes on patterns:
1993-05-04 11:44:39 +04:00
.IP -
1993-03-21 12:45:37 +03:00
Negated character classes
1993-05-04 11:44:39 +04:00
.I match newlines
unless "\\n" (or an equivalent escape sequence) is one of the
1993-03-21 12:45:37 +03:00
characters explicitly present in the negated character class
1993-05-04 11:44:39 +04:00
(e.g., "[^A-Z\\n]").
.IP -
1993-03-21 12:45:37 +03:00
A rule can have at most one instance of trailing context (the '/' operator
or the '$' operator). The start condition, '^', and "<<EOF>>" patterns
can only occur at the beginning of a pattern, and, as well as with '/' and '$',
cannot be grouped inside parentheses. The following are all illegal:
1993-05-04 11:44:39 +04:00
.nf
foo/bar$
foo|(bar$)
foo|^bar
<sc1>foo<sc2>bar
.fi
.SH SUMMARY OF SPECIAL ACTIONS
1993-03-21 12:45:37 +03:00
In addition to arbitrary C code, the following can appear in actions:
1993-05-04 11:44:39 +04:00
.IP -
.B ECHO
copies yytext to the scanner's output.
.IP -
.B BEGIN
followed by the name of a start condition places the scanner in the
1993-03-21 12:45:37 +03:00
corresponding start condition.
1993-05-04 11:44:39 +04:00
.IP -
.B REJECT
directs the scanner to proceed on to the "second best" rule which matched the
1993-03-21 12:45:37 +03:00
input (or a prefix of the input).
1993-05-04 11:44:39 +04:00
.B yytext
1993-03-21 12:45:37 +03:00
and
1993-05-04 11:44:39 +04:00
.B yyleng
1993-03-21 12:45:37 +03:00
are set up appropriately. Note that
1993-05-04 11:44:39 +04:00
.B REJECT
1993-03-21 12:45:37 +03:00
is a particularly expensive feature in terms scanner performance;
if it is used in
1993-05-04 11:44:39 +04:00
.I any
1993-03-21 12:45:37 +03:00
of the scanner's actions it will slow down
1993-05-04 11:44:39 +04:00
.I all
1993-03-21 12:45:37 +03:00
of the scanner's matching. Furthermore,
1993-05-04 11:44:39 +04:00
.B REJECT
1993-03-21 12:45:37 +03:00
cannot be used with the
1993-05-04 11:44:39 +04:00
.I -f
1993-03-21 12:45:37 +03:00
or
1993-05-04 11:44:39 +04:00
.I -F
1993-03-21 12:45:37 +03:00
options.
1993-05-04 11:44:39 +04:00
.IP
1993-03-21 12:45:37 +03:00
Note also that unlike the other special actions,
1993-05-04 11:44:39 +04:00
.B REJECT
1993-03-21 12:45:37 +03:00
is a
1993-05-04 11:44:39 +04:00
.I branch;
1993-03-21 12:45:37 +03:00
code immediately following it in the action will
1993-05-04 11:44:39 +04:00
.I not
1993-03-21 12:45:37 +03:00
be executed.
1993-05-04 11:44:39 +04:00
.IP -
.B yymore()
1993-03-21 12:45:37 +03:00
tells the scanner that the next time it matches a rule, the corresponding
token should be
1993-05-04 11:44:39 +04:00
.I appended
1993-03-21 12:45:37 +03:00
onto the current value of
1993-05-04 11:44:39 +04:00
.B yytext
1993-03-21 12:45:37 +03:00
rather than replacing it.
1993-05-04 11:44:39 +04:00
.IP -
.B yyless(n)
1993-03-21 12:45:37 +03:00
returns all but the first
1993-05-04 11:44:39 +04:00
.I n
1993-03-21 12:45:37 +03:00
characters of the current token back to the input stream, where they
will be rescanned when the scanner looks for the next match.
1993-05-04 11:44:39 +04:00
.B yytext
1993-03-21 12:45:37 +03:00
and
1993-05-04 11:44:39 +04:00
.B yyleng
1993-03-21 12:45:37 +03:00
are adjusted appropriately (e.g.,
1993-05-04 11:44:39 +04:00
.B yyleng
1993-03-21 12:45:37 +03:00
will now be equal to
1993-05-04 11:44:39 +04:00
.I n
).
.IP -
.B unput(c)
1993-03-21 12:45:37 +03:00
puts the character
1993-05-04 11:44:39 +04:00
.I c
1993-03-21 12:45:37 +03:00
back onto the input stream. It will be the next character scanned.
1993-05-04 11:44:39 +04:00
.IP -
.B input()
1993-03-21 12:45:37 +03:00
reads the next character from the input stream (this routine is called
1993-05-04 11:44:39 +04:00
.B yyinput()
1993-03-21 12:45:37 +03:00
if the scanner is compiled using
1993-05-04 11:44:39 +04:00
.B C++).
.IP -
.B yyterminate()
1993-03-21 12:45:37 +03:00
can be used in lieu of a return statement in an action. It terminates
the scanner and returns a 0 to the scanner's caller, indicating "all done".
1993-05-04 11:44:39 +04:00
.IP
1993-03-21 12:45:37 +03:00
By default,
1993-05-04 11:44:39 +04:00
.B yyterminate()
1993-03-21 12:45:37 +03:00
is also called when an end-of-file is encountered. It is a macro and
may be redefined.
1993-05-04 11:44:39 +04:00
.IP -
.B YY_NEW_FILE
1993-03-21 12:45:37 +03:00
is an action available only in <<EOF>> rules. It means "Okay, I've
set up a new input file, continue scanning".
1993-05-04 11:44:39 +04:00
.IP -
.B yy_create_buffer( file, size )
1993-03-21 12:45:37 +03:00
takes a
1993-05-04 11:44:39 +04:00
.I FILE
1993-03-21 12:45:37 +03:00
pointer and an integer
1993-05-04 11:44:39 +04:00
.I size.
1993-03-21 12:45:37 +03:00
It returns a YY_BUFFER_STATE
handle to a new input buffer large enough to accomodate
1993-05-04 11:44:39 +04:00
.I size
1993-03-21 12:45:37 +03:00
characters and associated with the given file. When in doubt, use
1993-05-04 11:44:39 +04:00
.B YY_BUF_SIZE
1993-03-21 12:45:37 +03:00
for the size.
1993-05-04 11:44:39 +04:00
.IP -
.B yy_switch_to_buffer( new_buffer )
1993-03-21 12:45:37 +03:00
switches the scanner's processing to scan for tokens from
the given buffer, which must be a YY_BUFFER_STATE.
1993-05-04 11:44:39 +04:00
.IP -
.B yy_delete_buffer( buffer )
1993-03-21 12:45:37 +03:00
deletes the given buffer.
1993-05-04 11:44:39 +04:00
.SH VALUES AVAILABLE TO THE USER
.IP -
.B char *yytext
1993-03-21 12:45:37 +03:00
holds the text of the current token. It may not be modified.
1993-05-04 11:44:39 +04:00
.IP -
.B int yyleng
1993-03-21 12:45:37 +03:00
holds the length of the current token. It may not be modified.
1993-05-04 11:44:39 +04:00
.IP -
.B FILE *yyin
1993-03-21 12:45:37 +03:00
is the file which by default
1993-05-04 11:44:39 +04:00
.I flex
1993-03-21 12:45:37 +03:00
reads from. It may be redefined but doing so only makes sense before
scanning begins. Changing it in the middle of scanning will have
unexpected results since
1993-05-04 11:44:39 +04:00
.I flex
1993-03-21 12:45:37 +03:00
buffers its input. Once scanning terminates because an end-of-file
has been seen,
1993-05-04 11:44:39 +04:00
.B
void yyrestart( FILE *new_file )
1993-03-21 12:45:37 +03:00
may be called to point
1993-05-04 11:44:39 +04:00
.I yyin
1993-03-21 12:45:37 +03:00
at the new input file.
1993-05-04 11:44:39 +04:00
.IP -
.B FILE *yyout
1993-03-21 12:45:37 +03:00
is the file to which
1993-05-04 11:44:39 +04:00
.B ECHO
1993-03-21 12:45:37 +03:00
actions are done. It can be reassigned by the user.
1993-05-04 11:44:39 +04:00
.IP -
.B YY_CURRENT_BUFFER
1993-03-21 12:45:37 +03:00
returns a
1993-05-04 11:44:39 +04:00
.B YY_BUFFER_STATE
1993-03-21 12:45:37 +03:00
handle to the current buffer.
1993-05-04 11:44:39 +04:00
.SH MACROS THE USER CAN REDEFINE
.IP -
.B YY_DECL
1993-03-21 12:45:37 +03:00
controls how the scanning routine is declared.
By default, it is "int yylex()", or, if prototypes are being
used, "int yylex(void)". This definition may be changed by redefining
the "YY_DECL" macro. Note that
if you give arguments to the scanning routine using a
K&R-style/non-prototyped function declaration, you must terminate
the definition with a semi-colon (;).
1993-05-04 11:44:39 +04:00
.IP -
1993-03-21 12:45:37 +03:00
The nature of how the scanner
gets its input can be controlled by redefining the
1993-05-04 11:44:39 +04:00
.B YY_INPUT
1993-03-21 12:45:37 +03:00
macro.
YY_INPUT's calling sequence is "YY_INPUT(buf,result,max_size)". Its
action is to place up to
1993-05-04 11:44:39 +04:00
.I max_size
1993-03-21 12:45:37 +03:00
characters in the character array
1993-05-04 11:44:39 +04:00
.I buf
1993-03-21 12:45:37 +03:00
and return in the integer variable
1993-05-04 11:44:39 +04:00
.I result
1993-03-21 12:45:37 +03:00
either the
number of characters read or the constant YY_NULL (0 on Unix systems)
to indicate EOF. The default YY_INPUT reads from the
global file-pointer "yyin".
A sample redefinition of YY_INPUT (in the definitions
section of the input file):
1993-05-04 11:44:39 +04:00
.nf
%{
#undef YY_INPUT
#define YY_INPUT(buf,result,max_size) \\
{ \\
int c = getchar(); \\
result = (c == EOF) ? YY_NULL : (buf[0] = c, 1); \\
}
%}
.fi
.IP -
1993-03-21 12:45:37 +03:00
When the scanner receives an end-of-file indication from YY_INPUT,
it then checks the
1993-05-04 11:44:39 +04:00
.B yywrap()
1993-03-21 12:45:37 +03:00
function. If
1993-05-04 11:44:39 +04:00
.B yywrap()
1993-03-21 12:45:37 +03:00
returns false (zero), then it is assumed that the
function has gone ahead and set up
1993-05-04 11:44:39 +04:00
.I yyin
1993-03-21 12:45:37 +03:00
to point to another input file, and scanning continues. If it returns
true (non-zero), then the scanner terminates, returning 0 to its
caller.
1993-05-04 11:44:39 +04:00
.IP
1993-03-21 12:45:37 +03:00
The default
1993-05-04 11:44:39 +04:00
.B yywrap()
1993-03-21 12:45:37 +03:00
always returns 1. Presently, to redefine it you must first
"#undef yywrap", as it is currently implemented as a macro. It is
likely that
1993-05-04 11:44:39 +04:00
.B yywrap()
1993-03-21 12:45:37 +03:00
will soon be defined to be a function rather than a macro.
1993-05-04 11:44:39 +04:00
.IP -
YY_USER_ACTION
1993-03-21 12:45:37 +03:00
can be redefined to provide an action
which is always executed prior to the matched rule's action.
1993-05-04 11:44:39 +04:00
.IP -
1993-03-21 12:45:37 +03:00
The macro
1993-05-04 11:44:39 +04:00
.B YY_USER_INIT
1993-03-21 12:45:37 +03:00
may be redefined to provide an action which is always executed before
the first scan.
1993-05-04 11:44:39 +04:00
.IP -
1993-03-21 12:45:37 +03:00
In the generated scanner, the actions are all gathered in one large
switch statement and separated using
1993-05-04 11:44:39 +04:00
.B YY_BREAK,
1993-03-21 12:45:37 +03:00
which may be redefined. By default, it is simply a "break", to separate
each rule's action from the following rule's.
1993-05-04 11:44:39 +04:00
.SH FILES
.TP
.I flex.skel
1993-03-21 12:45:37 +03:00
skeleton scanner.
1993-05-04 11:44:39 +04:00
.TP
.I lex.yy.c
generated scanner (called
.I lexyy.c
1993-03-21 12:45:37 +03:00
on some systems).
1993-05-04 11:44:39 +04:00
.TP
.I lex.backtrack
1993-03-21 12:45:37 +03:00
backtracking information for
1993-05-04 11:44:39 +04:00
.B -b
flag (called
.I lex.bck
1993-03-21 12:45:37 +03:00
on some systems).
1993-05-04 11:44:39 +04:00
.TP
.B -lfl
library with which to link the scanners.
.SH "SEE ALSO"
.LP
flexdoc(1), lex(1), yacc(1), sed(1), awk(1).
.LP
M. E. Lesk and E. Schmidt,
.I LEX - Lexical Analyzer Generator
.SH DIAGNOSTICS
.I reject_used_but_not_detected undefined
1993-03-21 12:45:37 +03:00
or
1993-05-04 11:44:39 +04:00
.LP
.I yymore_used_but_not_detected undefined -
These errors can occur at compile time. They indicate that the
1993-03-21 12:45:37 +03:00
scanner uses
1993-05-04 11:44:39 +04:00
.B REJECT
1993-03-21 12:45:37 +03:00
or
1993-05-04 11:44:39 +04:00
.B yymore()
1993-03-21 12:45:37 +03:00
but that
1993-05-04 11:44:39 +04:00
.I flex
failed to notice the fact, meaning that
.I flex
1993-03-21 12:45:37 +03:00
scanned the first two sections looking for occurrences of these actions
1993-05-04 11:44:39 +04:00
and failed to find any, but somehow you snuck some in (via a #include
file, for example). Make an explicit reference to the action in your
.I flex
input file. (Note that previously
.I flex
1993-03-21 12:45:37 +03:00
supported a
1993-05-04 11:44:39 +04:00
.B %used/%unused
mechanism for dealing with this problem; this feature is still supported
but now deprecated, and will go away soon unless the author hears from
people who can argue compellingly that they need it.)
.LP
.I flex scanner jammed -
1993-03-21 12:45:37 +03:00
a scanner compiled with
1993-05-04 11:44:39 +04:00
.B -s
1993-03-21 12:45:37 +03:00
has encountered an input string which wasn't matched by
any of its rules.
1993-05-04 11:44:39 +04:00
.LP
.I flex input buffer overflowed -
1993-03-21 12:45:37 +03:00
a scanner rule matched a string long enough to overflow the
1993-05-04 11:44:39 +04:00
scanner's internal input buffer (16K bytes - controlled by
.B YY_BUF_MAX
in "flex.skel").
.LP
.I scanner requires -8 flag -
1993-03-21 12:45:37 +03:00
Your scanner specification includes recognizing 8-bit characters and
1993-05-04 11:44:39 +04:00
you did not specify the -8 flag (and your site has not installed flex
with -8 as the default).
.LP
.I
fatal flex scanner internal error--end of buffer missed -
This can occur in an scanner which is reentered after a long-jump
has jumped out (or over) the scanner's activation frame. Before
reentering the scanner, use:
.nf
yyrestart( yyin );
.fi
.LP
.I too many %t classes! -
1993-03-21 12:45:37 +03:00
You managed to put every single character into its own %t class.
1993-05-04 11:44:39 +04:00
.I flex
1993-03-21 12:45:37 +03:00
requires that at least one of the classes share characters.
1993-05-04 11:44:39 +04:00
.SH AUTHOR
1993-03-21 12:45:37 +03:00
Vern Paxson, with the help of many ideas and much inspiration from
Van Jacobson. Original version by Jef Poskanzer.
1993-05-04 11:44:39 +04:00
.LP
See flexdoc(1) for additional credits and the address to send comments to.
.SH DEFICIENCIES / BUGS
.LP
1993-03-21 12:45:37 +03:00
Some trailing context
patterns cannot be properly matched and generate
warning messages ("Dangerous trailing context"). These are
patterns where the ending of the
first part of the rule matches the beginning of the second
part, such as "zx*/xy*", where the 'x*' matches the 'x' at
1993-05-04 11:44:39 +04:00
the beginning of the trailing context. (Note that the POSIX draft
1993-03-21 12:45:37 +03:00
states that the text matched by such patterns is undefined.)
1993-05-04 11:44:39 +04:00
.LP
1993-03-21 12:45:37 +03:00
For some trailing context rules, parts which are actually fixed-length are
not recognized as such, leading to the abovementioned performance loss.
1993-05-04 11:44:39 +04:00
In particular, parts using '|' or {n} (such as "foo{3}") are always
1993-03-21 12:45:37 +03:00
considered variable-length.
1993-05-04 11:44:39 +04:00
.LP
Combining trailing context with the special '|' action can result in
.I fixed
1993-03-21 12:45:37 +03:00
trailing context being turned into the more expensive
1993-05-04 11:44:39 +04:00
.I variable
trailing context. For example, this happens in the following example:
.nf
%%
abc |
xyz/def
.fi
.LP
Use of unput() invalidates yytext and yyleng.
.LP
Use of unput() to push back more text than was matched can
1993-03-21 12:45:37 +03:00
result in the pushed-back text matching a beginning-of-line ('^')
rule even though it didn't come at the beginning of the line
(though this is rare!).
1993-05-04 11:44:39 +04:00
.LP
Pattern-matching of NUL's is substantially slower than matching other
1993-03-21 12:45:37 +03:00
characters.
1993-05-04 11:44:39 +04:00
.LP
.I flex
1993-03-21 12:45:37 +03:00
does not generate correct #line directives for code internal
to the scanner; thus, bugs in
1993-05-04 11:44:39 +04:00
.I flex.skel
1993-03-21 12:45:37 +03:00
yield bogus line numbers.
1993-05-04 11:44:39 +04:00
.LP
1993-03-21 12:45:37 +03:00
Due to both buffering of input and read-ahead, you cannot intermix
1993-05-04 11:44:39 +04:00
calls to <stdio.h> routines, such as, for example,
.B getchar(),
1993-03-21 12:45:37 +03:00
with
1993-05-04 11:44:39 +04:00
.I flex
1993-03-21 12:45:37 +03:00
rules and expect it to work. Call
1993-05-04 11:44:39 +04:00
.B input()
1993-03-21 12:45:37 +03:00
instead.
1993-05-04 11:44:39 +04:00
.LP
1993-03-21 12:45:37 +03:00
The total table entries listed by the
1993-05-04 11:44:39 +04:00
.B -v
1993-03-21 12:45:37 +03:00
flag excludes the number of table entries needed to determine
what rule has been matched. The number of entries is equal
1993-05-04 11:44:39 +04:00
to the number of DFA states if the scanner does not use
.B REJECT,
1993-03-21 12:45:37 +03:00
and somewhat greater than the number of states if it does.
1993-05-04 11:44:39 +04:00
.LP
.B REJECT
1993-03-21 12:45:37 +03:00
cannot be used with the
1993-05-04 11:44:39 +04:00
.I -f
1993-03-21 12:45:37 +03:00
or
1993-05-04 11:44:39 +04:00
.I -F
1993-03-21 12:45:37 +03:00
options.
1993-05-04 11:44:39 +04:00
.LP
1993-03-21 12:45:37 +03:00
Some of the macros, such as
1993-05-04 11:44:39 +04:00
.B yywrap(),
1993-03-21 12:45:37 +03:00
may in the future become functions which live in the
1993-05-04 11:44:39 +04:00
.B -lfl
1993-03-21 12:45:37 +03:00
library. This will doubtless break a lot of code, but may be
1993-05-04 11:44:39 +04:00
required for POSIX-compliance.
.LP
1993-03-21 12:45:37 +03:00
The
1993-05-04 11:44:39 +04:00
.I flex
1993-03-21 12:45:37 +03:00
internal algorithms need documentation.