/* -*-C-*- */
/* A lexical scanner generated by flex */
+%# Lines in this skeleton starting with a '%' character are "control lines"
+%# and affect the generation of the scanner. The possible control codes are:
+%#
+%# %# - A comment. The current line is ommited from the generated scanner.
+%# %+ - The following lines are printed for C++ scanners ONLY.
+%# %- - The following lines are NOT printed for C++ scanners.
+%# %* - The following lines are printed in BOTH C and C++ scanners.
+%# %% - A stop-point, where code is inserted by flex.
+%# Each stop-point is numbered here and also in the code generator.
+%# (See gen.c, etc. for details.)
+%# %c - Begin linkage code that should NOT appear in a ".h" file.
+%# %e - End linkage code. %c and %e are used
+%#
+%# All control-lines EXCEPT comment lines ("%#") will be inserted into
+%# the generated scanner as a C-style comment. This is to aid those who
+%# edit the skeleton.
+%#
#define FLEX_SCANNER
#define YY_FLEX_MAJOR_VERSION 2
#define YY_FLEX_MINOR_VERSION 5
#define YY_AT_BOL() (YY_G(yy_current_buffer)->yy_at_bol)
-%% yytext/yyin/yyout/yy_state_type/yylineno etc. def's & init go here
+%% [1.0] yytext/yyin/yyout/yy_state_type/yylineno etc. def's & init go here
%- Standard (non-C++) definition
%c
*/
#define YY_DO_BEFORE_ACTION \
yytext_ptr = yy_bp; \
-%% code to fiddle yytext and yyleng for yymore() goes here \
+%% [2.0] code to fiddle yytext and yyleng for yymore() goes here \
YY_G(yy_hold_char) = *yy_cp; \
*yy_cp = '\0'; \
-%% code to copy yytext_ptr to yytext[] goes here, if %array \
+%% [3.0] code to copy yytext_ptr to yytext[] goes here, if %array \
YY_G(yy_c_buf_p) = yy_cp;
%*
%c
-%% data tables for the DFA and the user's section 1 definitions go here
+%% [4.0] data tables for the DFA and the user's section 1 definitions go here
%e
#ifndef YY_EXTRA_TYPE
*/
#ifndef YY_INPUT
#define YY_INPUT(buf,result,max_size) \
-%% fread()/read() definition of YY_INPUT goes here unless we're doing C++ \
+%% [5.0] fread()/read() definition of YY_INPUT goes here unless we're doing C++ \
%+ C++ definition \
if ( (result = LexerInput( (char *) buf, max_size )) < 0 ) \
YY_FATAL_ERROR( "input in flex scanner failed" );
#define YY_BREAK break;
#endif
-%% YY_RULE_SETUP definition goes here
+%% [6.0] YY_RULE_SETUP definition goes here
%c
YY_DECL
register char *yy_cp, *yy_bp;
register int yy_act;
-%% user's declarations go here
+%% [7.0] user's declarations go here
#ifdef YY_REENTRANT_BISON_PURE
YY_G(yylval) = yylvalp;
while ( 1 ) /* loops until end-of-file is reached */
{
-%% yymore()-related code goes here
+%% [8.0] yymore()-related code goes here
yy_cp = YY_G(yy_c_buf_p);
/* Support of yytext. */
*/
yy_bp = yy_cp;
-%% code to set up and find next match goes here
+%% [9.0] code to set up and find next match goes here
yy_find_action:
-%% code to find the action number goes here
+%% [10.0] code to find the action number goes here
YY_DO_BEFORE_ACTION;
-%% code for yylineno update goes here
+%% [11.0] code for yylineno update goes here
do_action: /* This label is used only to access EOF actions. */
-%% debug code goes here
+%% [12.0] debug code goes here
switch ( yy_act )
{ /* beginning of action switch */
-%% actions go here
+%% [13.0] actions go here
case YY_END_OF_BUFFER:
{
else
{
-%% code to do back-up for compressed tables and set up yy_cp goes here
+%% [14.0] code to do back-up for compressed tables and set up yy_cp goes here
goto yy_find_action;
}
}
register yy_state_type yy_current_state;
register char *yy_cp;
-%% code to get the start state into yy_current_state goes here
+%% [15.0] code to get the start state into yy_current_state goes here
for ( yy_cp = yytext_ptr + YY_MORE_ADJ; yy_cp < YY_G(yy_c_buf_p); ++yy_cp )
{
-%% code to find the next state goes here
+%% [16.0] code to find the next state goes here
}
return yy_current_state;
%*
{
register int yy_is_jam;
-%% code to find the next state, and perhaps do backing up, goes here
+%% [17.0] code to find the next state, and perhaps do backing up, goes here
return yy_is_jam ? 0 : yy_current_state;
}
*--yy_cp = (char) c;
-%% update yylineno here
+%% [18.0] update yylineno here
yytext_ptr = yy_bp;
YY_G(yy_hold_char) = *yy_cp;
*YY_G(yy_c_buf_p) = '\0'; /* preserve yytext */
YY_G(yy_hold_char) = *++YY_G(yy_c_buf_p);
-%% update BOL and yylineno
+%% [19.0] update BOL and yylineno
return c;
}
@chapter Invoking flex
@code{flex}
-has the following options:
+has the following options.
@table @samp
-@item -b
+@item -b, --backup
Generate backing-up information to @file{lex.backup}. This is a list of
scanner states which require backing up and the input characters on
which they do so. By adding rules one can remove backing-up states. If
@emph{all} backing-up states are eliminated and @samp{-Cf} or @code{-CF}
-is used, the generated scanner will run faster (see the @samp{-p} flag).
+is used, the generated scanner will run faster (see the @samp{--perf-report} flag).
Only users who wish to squeeze every last cycle out of their scanners
need worry about this option. (@pxref{performance}).
@item -c
is a do-nothing option included for POSIX compliance.
-@item -d
+@item -d, --debug
makes the generated scanner run in @dfn{debug} mode. Whenever a pattern
is recognized and the global variable @code{yy_flex_debug} is non-zero
(which is the default), the scanner will write to @file{stderr} a line
look the same as far as the scanner's concerned), or reaches an
end-of-file.
-@item -f
+@item -f, --full
specifies
@dfn{fast scanner}.
No table compression is done and @code{stdio} is bypassed.
The result is large but fast. This option is equivalent to
@samp{--Cfr}
-@item -h
+@item -h, -?, --help
generates a ``help'' summary of @code{flex}'s options to @file{stdout}
-and then exits. @samp{-?} and @samp{--help} are synonyms for
-@samp{-h}.
+and then exits.
-@item -i
+@item --header=FILE
+instructs flex to write a C header to @file{FILE}. This file contains
+function prototypes, extern variables, and macros used by the scanner.
+It is meant to be included in other C files to avoid compiler warnings.
+The @samp{--header} option is not compatible with the @samp{--c++} option,
+since the C++ scanner provides its own header in @file{yyFlexLexer.h}.
+
+@item -i, --case-insensitive
instructs @code{flex} to generate a @dfn{case-insensitive} scanner. The
case of letters given in the @code{flex} input patterns will be ignored,
and tokens in the input will be matched regardless of case. The matched
text given in @code{yytext} will have the preserved case (i.e., it will
not be folded).
-@item -l
+@item -l, --lex-compat
turns on maximum compatibility with the original AT&T @code{lex}
implementation. Note that this does not mean @emph{full} compatibility.
Use of this option costs a considerable amount of performance, and it
-cannot be used with the @samp{-+}, @samp{-f}, @samp{-F}, @samp{-Cf}, or
+cannot be used with the @samp{--c++}, @samp{--full}, @samp{--fast}, @samp{-Cf}, or
@samp{-CF} options. For details on the compatibilities it provides, see
@ref{lex and posix}. This option also results in the name
@code{YY_FLEX_LEX_COMPAT} being @code{#define}'d in the generated scanner.
is another do-nothing option included only for
POSIX compliance.
-@item -p
+@item -p, --perf-report
generates a performance report to @file{stderr}. The report consists of
comments regarding features of the @code{flex} input file which will
cause a serious loss of performance in the resulting scanner. If you
Note that the use of @code{REJECT}, @code{%option yylineno}, and
variable trailing context (@pxref{limitations}) entails a substantial
performance penalty; use of @code{yymore()}, the @samp{^} operator, and
-the @samp{-I} flag entail minor performance penalties.
+the @samp{--interactive} flag entail minor performance penalties.
-@item -s
+@item -s, --nodefault
causes the @emph{default rule} (that unmatched scanner input is echoed
to @file{stdout)} to be suppressed. If the scanner encounters input
that does not match any of its rules, it aborts with an error. This
option is useful for finding holes in a scanner's rule set.
-@item -t
+@item -t, --stdout
instructs @code{flex} to write the scanner it generates to standard
output instead of @file{lex.yy.c}.
-@item -v
+@item -v, --verbose
specifies that @code{flex} should write to @file{stderr} a summary of
statistics regarding the scanner it generates. Most of the statistics
are meaningless to the casual @code{flex} user, but the first line
-identifies the version of @code{flex} (same as reported by @samp{-V}),
+identifies the version of @code{flex} (same as reported by @samp{--version}),
and the next line the flags used when generating the scanner, including
those that are on by default.
-@item -w
+@item -w, --nowarn
suppresses warning messages.
-@item -B
+@item -B, --batch
instructs @code{flex} to generate a @dfn{batch} scanner, the opposite of
-@emph{interactive} scanners generated by @samp{-I} (see below). In
+@emph{interactive} scanners generated by @samp{--interactive} (see below). In
general, you use @samp{-B} when you are @emph{certain} that your scanner
will never be used interactively, and you want to squeeze a
@emph{little} more performance out of it. If your goal is instead to
squeeze out a @emph{lot} more performance, you should be using the
-@samp{-Cf} or @samp{-CF} options, which turn on @samp{-B} automatically
+@samp{-Cf} or @samp{-CF} options, which turn on @samp{--batch} automatically
anyway.
-@item -F
+@item -F, --fast
specifies that the @emph{fast} scanner table representation should be
used (and @code{stdio} bypassed). This representation is about as fast
-as the full table representation @samp{-f}, and for some sets of
+as the full table representation @samp{--full}, and for some sets of
patterns will be considerably smaller (and for others, larger). In
general, if the pattern set contains both @emph{keywords} and a
catch-all, @emph{identifier} rule, such as in the set:
then you're better off using the full table representation. If only
the @emph{identifier} rule is present and you then use a hash table or some such
to detect the keywords, you're better off using
-@samp{-F}.
+@samp{--fast}.
This option is equivalent to @samp{-CFr} (see below). It cannot be used
-with @samp{-+}.
+with @samp{--c++}.
-@item -I
+@item -I, --interactive
instructs @code{flex} to generate an @i{interactive} scanner. An
interactive scanner is one that only looks ahead to decide what token
has been matched if it absolutely must. It turns out that always
high-performance you should be using one of these options, so if you
didn't, @code{flex} assumes you'd rather trade off a bit of run-time
performance for intuitive interactive behavior. Note also that you
-@emph{cannot} use @samp{-I} in conjunction with @samp{-Cf} or
+@emph{cannot} use @samp{--interactive} in conjunction with @samp{-Cf} or
@samp{-CF}. Thus, this option is not really needed; it is on by default
for all those cases in which it is allowed.
You can force a scanner to
@emph{not}
be interactive by using
-@samp{-B}
+@samp{--batch}
-@item -L
+@item -L, --noline
instructs
@code{flex}
not to generate
fault -- you should report these sorts of errors to the email address
given in @ref{reporting bugs}).
-@item -R
+@item -R, --reentrant
instructs flex to generate a reentrant C scanner. The generated scanner
may safely be used in a multi-threaded environment. The API for a
reentrant scanner is different than for a non-reentrant scanner
@pxref{reentrant}). Because of the API difference between
reentrant and non-reentrant @code{flex} scanners, non-reentrant flex
code must be modified before it is suitable for use with this option.
-This option is not compatible with the @samp{-+} option.
+This option is not compatible with the @samp{--c++} option.
-@item -Rb
+@item -Rb, --reentrant-bison
instructs flex to generate a reentrant C scanner that is
meant to be called by a
@code{GNU bison}
pure parser. The scanner is the same as the scanner generated by the
-@samp{-R}
+@samp{--reentrant}
option, but with minor API changes for
@code{bison}
compatibility. In particular, the declaration of
@code{yylloc_r}
is incorporated. @xref{bison pure}.
-The options @samp{-R} and @samp{-Rb} do not affect the performance of
+The options @samp{--reentrant} and @samp{--reentrant-bison} do not affect the performance of
the scanner.
-@item -T
+@item -T, --trace
makes @code{flex} run in @dfn{trace} mode. It will generate a lot of
messages to @file{stderr} concerning the form of the input and the
resultant non-deterministic and deterministic finite automata. This
option is mostly for use in maintaining @code{flex}.
-@item -V
-prints the version number to @file{stdout} and exits. @samp{--version}
-is a synonym for @samp{-V}.
+@item -V, --version
+prints the version number to @file{stdout} and exits.
-@item -7
+@item -7, --7bit
instructs @code{flex} to generate a 7-bit scanner, i.e., one which can
only recognize 7-bit characters in its input. The advantage of using
-@samp{-7} is that the scanner's tables can be up to half the size of
-those generated using the @samp{-8}. The disadvantage is that such
+@samp{--7bit} is that the scanner's tables can be up to half the size of
+those generated using the @samp{--8bit}. The disadvantage is that such
scanners often hang or crash if their input contains an 8-bit character.
Note, however, that unless you generate your scanner using the
-@samp{-Cf} or @samp{-CF} table compression options, use of @samp{-7}
+@samp{-Cf} or @samp{-CF} table compression options, use of @samp{--7bit}
will save only a small amount of table space, and make your scanner
considerably less portable. @code{Flex}'s default behavior is to
generate an 8-bit scanner unless you use the @samp{-Cf} or @samp{-CF},
your site was always configured to generate 8-bit scanners (as will
often be the case with non-USA sites). You can tell whether flex
generated a 7-bit or an 8-bit scanner by inspecting the flag summary in
-the @samp{-v} output as described above.
+the @samp{--verbose} output as described above.
Note that if you use @samp{-Cfe} or @samp{-CFe} @code{flex} still
defaults to generating an 8-bit scanner, since usually with these
compression options full 8-bit tables are not much more expensive than
7-bit tables.
-@item -8
+@item -8, --8bit
instructs @code{flex} to generate an 8-bit scanner, i.e., one which can
recognize 8-bit characters. This flag is only needed for scanners
generated using @samp{-Cf} or @samp{-CF}, as otherwise flex defaults to
generating an 8-bit scanner anyway.
See the discussion of
-@samp{-7}
+@samp{--7bit}
above for @code{flex}'s default behavior and the tradeoffs between 7-bit
and 8-bit scanners.
-@item -+
+@item -+, --c++
specifies that you want flex to generate a C++
scanner class. @xref{cxx}, for
details.
controls the degree of table compression and, more generally, trade-offs
between small scanners and fast scanners.
-@item -Ca
+@item -Ca, --align
(``align'') instructs flex to trade off larger tables in the
generated scanner for faster performance because the elements of
the tables are better aligned for memory access and computation. On some
than with smaller-sized units such as shortwords. This option can
double the size of the tables used by your scanner.
-@item -Ce
+@item -Ce, --ecs
directs @code{flex} to construct @dfn{equivalence classes}, i.e., sets
of characters which have identical lexical properties (for example, if
the only appearance of digits in the @code{flex} input is in the
@item -CF
specifies that the alternate fast scanner representation (described
-above under the @samp{-F} flag) should be used. This option cannot be
-used with @samp{-+}.
+above under the @samp{--fast} flag) should be used. This option cannot be
+used with @samp{--c++}.
-@item -Cm
+@item -Cm, --meta-ecs
directs
@code{flex}
to construct
have a moderate performance impact (one or two @code{if} tests and one
array look-up per character scanned).
-@item -Cr
+@item -Cr, --read
causes the generated scanner to @emph{bypass} use of the standard I/O
library (@code{stdio}) for input. Instead of calling @code{fread()} or
@code{getc()}, the scanner will use the @code{read()} system call,
@samp{-Cfe} is often a good compromise between speed and size for
production scanners.
-@item -ooutput
-directs flex to write the scanner to the file @file{output} instead of
-@file{lex.yy.c}. If you combine @samp{-o} with the @samp{-t} option,
+@item -oFILE, --outfile=FILE
+directs flex to write the scanner to the file @file{FILE} instead of
+@file{lex.yy.c}. If you combine @samp{--outfile} with the @samp{--stdout} option,
then the scanner is written to @file{stdout} but its @code{#line}
directives (see the @samp{-l} option above) refer to the file
-@file{output}.
+@file{FILE}.
-@item -Pprefix
+@item -PPREFIX, --prefix=PREFIX
changes the default @samp{yy} prefix used by @code{flex} for all
globally-visible variable and function names to instead be
-@samp{prefix}. For example, @samp{-Pfoo} changes the name of
+@samp{PREFIX}. For example, @samp{--prefix=foo} changes the name of
@code{yytext} to @code{footext}. It also changes the name of the default
output file from @file{lex.yy.c} to @file{lex.foo.c}. Here are all of
the names affected:
@samp{-lfl}
no longer provides one for you by default.
-@item -Sskeleton_file
+@item -SFILE, --skel=FILE
overrides the default skeleton file from which
@code{flex}
constructs its scanners. You'll never need this option unless you are doing
@code{flex}
maintenance or development.
-@end table
-
-@node scanner options, performance, invoking flex, Top
-@chapter option Directives within Scanners
-
-@code{flex} also provides a mechanism for controlling options within the
-scanner specification itself, rather than from the flex command-line.
-This is done by including @code{%option} directives in the first section
-of the scanner specification. You can specify multiple options with a
-single @code{%option} directive, and multiple directives in the first
-section of your flex input file.
-
-Most options are given simply as names, optionally preceded by the
-word @samp{no} (with no intervening whitespace) to negate their meaning.
-A number are equivalent to flex flags or their negation:
-
-@example
-@verbatim
- 7bit -7 option
- 8bit -8 option
- align -Ca option
- backup -b option
- batch -B option
- c++ -+ option
-
- caseful or
- case-sensitive opposite of -i (default)
-
- case-insensitive or
- caseless -i option
-
- debug -d option
- default opposite of -s option
- ecs -Ce option
- fast -F option
- full -f option
- interactive -I option
- lex-compat -l option
- meta-ecs -Cm option
- perf-report -p option
- read -Cr option
- reentrant -R option
- rentrant-bison -Rb option
- stdout -t option
- verbose -v option
- warn opposite of -w option
- (use "%option nowarn" for -w)
-
- array equivalent to "%array"
- pointer equivalent to "%pointer" (default)
-@end verbatim
-@end example
-Some @code{%option}'s provide features otherwise not available:
-
-@table @code
-@item always-interactive
+@item --always-interactive
instructs flex to generate a scanner which always considers its input
@emph{interactive}. Normally, on each new input file the scanner calls
@code{isatty()} in an attempt to determine whether the scanner's input
source is interactive and thus should be read a character at a time.
When this option is used, however, then no such call is made.
-@item main
+@item --main
directs flex to provide a default @code{main()} program for the
scanner, which simply calls @code{yylex()}. This option implies
@code{noyywrap} (see below).
-@item never-interactive
+@item --never-interactive
instructs flex to generate a scanner which never considers its input
interactive. This is the opposite of @code{always-interactive}.
-@item stack
+@item --stack
enables the use of
start condition stacks (@pxref{start conditions}).
-@item stdinit
+@item --stdinit
if set (i.e., @b{%option stdinit)} initializes @code{yyin} and
@code{yyout} to @file{stdin} and @file{stdout}, instead of the default of
@file{nil}. Some existing @code{lex} programs depend on this behavior,
reentrant scanner, however, this is not a problem since initialization
is performed in @code{yylex_init} at runtime.
-@item yylineno
+@item --yylineno
directs @code{flex} to generate a scanner
that maintains the number of the current line read from its input in the
global variable @code{yylineno}. This option is implied by @code{%option
accessible regardless of the value of @code{%option yylineno}, however, its
value is not modified by @code{flex} unless @code{%option yylineno} is enabled.
-@item yywrap
-if unset (i.e., @code{%option noyywrap)}, makes the scanner not call
+@item --yywrap
+if unset (i.e., @code{--noyywrap)}, makes the scanner not call
@code{yywrap()} upon an end-of-file, but simply assume that there are no
more files to scan (until the user points @file{yyin} at a new file and
calls @code{yylex()} again).
@end table
-@code{flex} scans your rule actions to determine whether you use the
-@code{REJECT} or @code{yymore()} features. The @code{REJECT} and
-@code{yymore} options are available to override its decision as to
-whether you use the options, either by setting them (e.g., @code{%option
-reject)} to indicate the feature is indeed used, or unsetting them to
-indicate it actually is not used (e.g., @code{%option noyymore)}.
-
-These options take string-delimited values, offset with '=':
+@node scanner options, performance, invoking flex, Top
+@chapter option Directives within Scanners
-@example
-@verbatim
- %option outfile="ABC"
-@end verbatim
-@end example
+@code{flex} also provides a mechanism for controlling options within the
+scanner specification itself, rather than from the flex command-line.
+This is done by including @code{%option} directives in the first section
+of the scanner specification. You can specify multiple options with a
+single @code{%option} directive, and multiple directives in the first
+section of your flex input file.
-is equivalent to @samp{-oABC}, and
+Most options are given simply as names, optionally preceded by the
+word @samp{no} (with no intervening whitespace) to negate their meaning.
+The names are the same as their long-option equivalents (but without the
+leading @samp{--} ).
@example
@verbatim
- %option prefix="XYZ"
-@end verbatim
-@end example
+ 7bit -7 --7bit
+ 8bit -8 --8bit
+ align -Ca --align
+ array --array equivalent to "%array"
+ backup -b --backup
+ batch -B --batch
+ c++ -+ --c++
-is equivalent to @samp{-PXYZ}.
+ caseful or
+ case-sensitive (default)
-Finally,
+ case-insensitive or
+ caseless -i --case-insensitive
+
+ debug -d --debug
+ default --default
+ ecs -Ce --ecs
+ fast -F --fast
+ full -f --full
+ header="FILE" --header=FILE
+ interactive -I --interactive
+ lex-compat -l --lex-compat
+ meta-ecs -Cm --meta-ecs
+ perf-report -p --perf-report
+ pointer --pointer equivalent to "%pointer" (default)
+ prefix="PREFIX" -P --prefix
+ outfile="FILE" -o --outfile=FILE
+ read -Cr --read
+ reentrant -R --reentrant
+ reentrant-bison -Rb --reentrant-bison
+ stdout -t --stdout
+ verbose -v --verbose
+ warn --warn (use "%option nowarn" for -w)
+ yyclass="NAME" --yyclass=NAME
-@example
-@verbatim
- %option yyclass="foo"
@end verbatim
@end example
-only applies when generating a C++ scanner (the @samp{-+} option). It
+@code{flex} scans your rule actions to determine whether you use the
+@code{REJECT} or @code{yymore()} features. The @code{REJECT} and
+@code{yymore} options are available to override its decision as to
+whether you use the options, either by setting them (e.g., @code{%option
+reject)} to indicate the feature is indeed used, or unsetting them to
+indicate it actually is not used (e.g., @code{%option noyymore)}.
+
+
+@code{%option yyclass}
+only applies when generating a C++ scanner (the @samp{--c++} option). It
informs @code{flex} that you have derived @code{foo} as a subclass of
@code{yyFlexLexer}, so @code{flex} will place your actions in the member
function @code{foo::yylex()} instead of @code{yyFlexLexer::yylex()}. It