]> granicus.if.org Git - flex/commitdiff
phew, millaway's latest batch
authorWill Estes <wlestes@users.sourceforge.net>
Mon, 22 Oct 2001 13:42:24 +0000 (13:42 +0000)
committerWill Estes <wlestes@users.sourceforge.net>
Mon, 22 Oct 2001 13:42:24 +0000 (13:42 +0000)
flex.skl
flex.texi
gen.c
main.c
misc.c
options.h
scan.l
scanopt.c
tests/README
tests/configure.in

index ae965142358866ca8517a5b119d4ea16314ca8ec..4ed8ff2171a712cb6d4ff8b4bbca4956d7665af4 100644 (file)
--- a/flex.skl
+++ b/flex.skl
@@ -1,6 +1,23 @@
 /* -*-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
@@ -336,7 +353,7 @@ static void yy_flex_free YY_PROTO(( void * YY_LAST_ARG ));
 
 #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
@@ -352,16 +369,16 @@ static void yy_fatal_error YY_PROTO(( yyconst char msg[] ));
  */
 #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
@@ -589,7 +606,7 @@ YY_MALLOC_DECL
  */
 #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" );
@@ -672,7 +689,7 @@ extern int yylex YY_PROTO( YY_LEX_ARGS );
 #define YY_BREAK break;
 #endif
 
-%% YY_RULE_SETUP definition goes here
+%% [6.0] YY_RULE_SETUP definition goes here
 
 %c
 YY_DECL
@@ -681,7 +698,7 @@ 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;
@@ -724,7 +741,7 @@ YY_DECL
 
        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. */
@@ -735,22 +752,22 @@ YY_DECL
                 */
                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:
                {
@@ -815,7 +832,7 @@ do_action:  /* This label is used only to access EOF actions. */
 
                        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;
                                }
                        }
@@ -1133,11 +1150,11 @@ yy_state_type yyFlexLexer::yy_get_previous_state()
        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;
@@ -1163,7 +1180,7 @@ yy_state_type yyFlexLexer::yy_try_NUL_trans( yy_state_type 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;
        }
@@ -1211,7 +1228,7 @@ void yyFlexLexer::yyunput( int c, register char* yy_bp YY_LAST_ARG)
 
        *--yy_cp = (char) c;
 
-%% update yylineno here
+%% [18.0] update yylineno here
 
        yytext_ptr = yy_bp;
        YY_G(yy_hold_char) = *yy_cp;
@@ -1300,7 +1317,7 @@ int yyFlexLexer::yyinput()
        *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;
        }
index 2984cf32260111d28338a10dd67a69983bf9e176..6712ba103cef9318fca700f968b2c38c5b04fabb 100644 (file)
--- a/flex.texi
+++ b/flex.texi
@@ -1900,22 +1900,22 @@ is @code{TOK_NUMBER}, part of the scanner might look like:
 @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
@@ -1934,30 +1934,36 @@ the end of its input buffer (or encounters a NUL; at this point, the two
 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.
@@ -1966,7 +1972,7 @@ cannot be used with the @samp{-+}, @samp{-f}, @samp{-F}, @samp{-Cf}, or
 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
@@ -1976,43 +1982,43 @@ lead to minor performance losses.
 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:
@@ -2030,12 +2036,12 @@ 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
@@ -2052,16 +2058,16 @@ newline, it is not recognized as a newline token until they enter
 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
@@ -2079,21 +2085,21 @@ input file (if the errors are due to code in the input file), or
 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
@@ -2104,28 +2110,27 @@ and
 @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},
@@ -2133,25 +2138,25 @@ in which case @code{flex} defaults to generating 7-bit scanners unless
 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.
@@ -2160,7 +2165,7 @@ 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
@@ -2168,7 +2173,7 @@ RISC architectures, fetching and manipulating longwords is more efficient
 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
@@ -2185,10 +2190,10 @@ similar transition functions for different states.
 
 @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
@@ -2199,7 +2204,7 @@ classes are often a big win when using compressed tables, but they
 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,
@@ -2248,17 +2253,17 @@ use the default, maximal compression.
 @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:
@@ -2303,89 +2308,34 @@ as linking with
 @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,
@@ -2394,7 +2344,7 @@ even though it is not compliant with ANSI C, which does not require
 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
@@ -2402,47 +2352,78 @@ lex-compat}.  In a reentrant C scanner, the macro @code{yylineno_r} is
 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
diff --git a/gen.c b/gen.c
index 4048d38dc14c8532c62059daddc2407bbd7acfe6..22db43d315d0a59de19822272aaf45b47363ddfb 100644 (file)
--- a/gen.c
+++ b/gen.c
@@ -1064,7 +1064,7 @@ void make_tables()
        register int i;
        int did_eof_rule = false;
 
-       skelout();
+       skelout(); /* %% [2.0] - break point in skel */
 
        /* First, take care of YY_DO_BEFORE_ACTION depending on yymore
         * being used.
@@ -1081,7 +1081,7 @@ void make_tables()
                indent_puts( "YY_G(yyleng) = (size_t) (yy_cp - yy_bp); \\" );
 
        /* Now also deal with copying yytext_ptr to yytext if needed. */
-       skelout();
+       skelout(); /* %% [3.0] - break point in skel */
        if ( yytext_is_array )
                {
                if ( yymore_used )
@@ -1113,7 +1113,7 @@ void make_tables()
 
        set_indent( 0 );
 
-       skelout();
+       skelout(); /* %% [4.0] - break point in skel */
 
 
        out_dec( "#define YY_NUM_RULES %d\n", num_rules );
@@ -1338,7 +1338,7 @@ void make_tables()
 
        line_directive_out( stdout, 0 );
 
-       skelout();
+       skelout(); /* %% [5.0] - break point in skel */
 
        if ( ! C_plus_plus )
                {
@@ -1375,7 +1375,7 @@ void make_tables()
                        }
                }
 
-       skelout();
+       skelout(); /* %% [6.0] - break point in skel */
 
        indent_puts( "#define YY_RULE_SETUP \\" );
        indent_up();
@@ -1390,14 +1390,14 @@ void make_tables()
        indent_puts( "YY_USER_ACTION" );
        indent_down();
 
-       skelout();
+       skelout(); /* %% [7.0] - break point in skel */
 
        /* Copy prolog to output file. */
        out( &action_array[prolog_offset] );
 
        line_directive_out( stdout, 0 );
 
-       skelout();
+       skelout(); /* %% [8.0] - break point in skel */
 
        set_indent( 2 );
 
@@ -1413,7 +1413,7 @@ void make_tables()
                indent_down();
                }
 
-       skelout();
+       skelout(); /* %% [9.0] - break point in skel */
 
        gen_start_state();
 
@@ -1421,11 +1421,11 @@ void make_tables()
        outn( "yy_match:" );
        gen_next_match();
 
-       skelout();
+       skelout(); /* %% [10.0] - break point in skel */
        set_indent( 2 );
        gen_find_action();
 
-       skelout();
+       skelout(); /* %% [11.0] - break point in skel */
        if ( do_yylineno )
                {
                indent_puts( "if ( yy_act != YY_END_OF_BUFFER )" );
@@ -1446,7 +1446,7 @@ void make_tables()
                indent_down();
                }
 
-       skelout();
+       skelout(); /* %% [12.0] - break point in skel */
        if ( ddebug )
                {
                indent_puts( "if ( yy_flex_debug )" );
@@ -1532,7 +1532,7 @@ void make_tables()
                }
 
        /* Copy actions to output file. */
-       skelout();
+       skelout(); /* %% [13.0] - break point in skel */
        indent_up();
        gen_bu_action();
        out( &action_array[action_offset] );
@@ -1561,7 +1561,7 @@ void make_tables()
        /* First, deal with backing up and setting up yy_cp if the scanner
         * finds that it should JAM on the NUL.
         */
-       skelout();
+       skelout(); /* %% [14.0] - break point in skel */
        set_indent( 4 );
 
        if ( fullspd || fulltbl )
@@ -1590,19 +1590,19 @@ void make_tables()
 
        /* Generate code for yy_get_previous_state(). */
        set_indent( 1 );
-       skelout();
+       skelout(); /* %% [15.0] - break point in skel */
 
        gen_start_state();
 
        set_indent( 2 );
-       skelout();
+       skelout(); /* %% [16.0] - break point in skel */
        gen_next_state( true );
 
        set_indent( 1 );
-       skelout();
+       skelout(); /* %% [17.0] - break point in skel */
        gen_NUL_trans();
 
-       skelout();
+       skelout(); /* %% [18.0] - break point in skel */
        if ( do_yylineno )
                { /* update yylineno inside of unput() */
                indent_puts( "if ( c == '\\n' )" );
@@ -1611,7 +1611,7 @@ void make_tables()
                indent_down();
                }
 
-       skelout();
+       skelout(); /* %% [19.0] - break point in skel */
        /* Update BOL and yylineno inside of input(). */
        if ( bol_needed )
                {
@@ -1640,5 +1640,7 @@ void make_tables()
        line_directive_out( stdout, 1 );
 
        if ( sectnum == 3 )
+               OUT_BEGIN_CODE();
                (void) flexscan(); /* copy remainder of input to output */
+               OUT_END_CODE();
        }
diff --git a/main.c b/main.c
index bf7a1718f5bf42fcf7981164cf3532506092e88c..0f5ea28af7ee9fbe87cdecb40e24ab9d9cf47f25 100644 (file)
--- a/main.c
+++ b/main.c
@@ -51,6 +51,7 @@ void readin PROTO((void));
 void set_up_initial_allocations PROTO((void));
 static char * basename2 PROTO((char* path, int should_strip_ext));
 
+
 /* these globals are all defined and commented in flexdef.h */
 int printstats, syntaxerror, eofseen, ddebug, trace, nowarn, spprdflt;
 int interactive, caseins, lex_compat, do_yylineno, useecs, fulltbl, usemecs;
@@ -194,6 +195,9 @@ void check_options()
                use_read = false;
                }
 
+       if ( use_stdout && headerfilename )
+           flexerror( _( "Can't specify header option if writing to stdout.") );
+
        if ( do_yylineno )
                /* This should really be "maintain_backup_tables = true" */
                reject_really_used = true;
@@ -381,6 +385,7 @@ void check_options()
             outn( (char*)(userdef_buf.elts) );
 
        skelout();
+    /* %% [1.0] */
        }
 
 
@@ -431,7 +436,7 @@ int exit_status;
                        fprintf(header_out,
                                        "#ifndef %sHEADER_H\n"
                                        "#define %sHEADER_H 1\n"
-                                       "#define %sIN_HEADER 1\n",
+                                       "#define %sIN_HEADER 1\n\n",
                                        prefix,prefix,prefix);
                        fflush(header_out);
 
@@ -856,7 +861,7 @@ char **argv;
                         if (strcmp(arg,"b")==0)
                             reentrant_bison_pure = true;
                         else
-                            lerrif(_( "unknown -R option '%c'" ),(int)arg[i]);
+                            lerrif(_( "unknown -R option '%c'" ),(int)arg[0]);
                     }
                     break;
 
@@ -1350,6 +1355,7 @@ _(
 "  -S, --skel=FILE         specify skeleton file\n"
 "  -t, --stdout            write scanner on stdout instead of %s\n"
 "      --yyclass=NAME      name of C++ class\n"
+"      --header=FILE       create a C header file in addition to the scanner\n"
     
 "\n"
 "Scanner behavior:\n"
diff --git a/misc.c b/misc.c
index dc5b6ef64a690da49c7fc5ef4e839c02868cbe8b..3c37e3374e453f6913c39fc6e74bf9bf3dd64a97 100644 (file)
--- a/misc.c
+++ b/misc.c
@@ -795,10 +795,13 @@ void skelout()
                if ( buf[0] == '%' )
                        { /* control line */
                        /* print the control line as a comment. */
-                       if (buf[strlen(buf)-1]=='\\')
-                               out_str("/* %s */\\\n", buf);
-                       else
-                               out_str("/* %s */\n", buf);
+                       if (buf[1] != '#')
+                               {
+                               if (buf[strlen(buf)-1]=='\\')
+                                       out_str("/* %s */\\\n", buf);
+                               else
+                                       out_str("/* %s */\n", buf);
+                               }
                                
                        switch ( buf[1] )
                                {
@@ -817,14 +820,18 @@ void skelout()
                                        do_copy = 1;
                                        break;
 
-                               case 'c':
+                               case 'c': /* begin linkage-only (non-header) code. */
                                        OUT_BEGIN_CODE();
                                        break;
 
-                               case 'e':
+                               case 'e': /* end linkage-only code. */
                                        OUT_END_CODE();
                                        break;
-
+                                       
+                               case '#':
+                                       /* a comment in the skel. ignore. */
+                                       break;
+                                       
                                default:
                                        flexfatal(
                                        _( "bad line in skeleton file" ) );
index 5ee1dc693643b44f40ee0ea5812d87618f1a9db2..39ae1f5d8dbe58affee9df886bd61d0f24c18e92 100644 (file)
--- a/options.h
+++ b/options.h
@@ -9,7 +9,7 @@ enum flexopt_flag_t {
      * Order is not important. */
     OPT_7BIT=1,
     OPT_8BIT,
-    OPT_ALIGN,
+    OPT_ALIGN,  OPT_NO_ALIGN,
     OPT_ALWAYS_INTERACTIVE,
     OPT_ARRAY,
     OPT_BACKUP,
@@ -17,40 +17,63 @@ enum flexopt_flag_t {
     OPT_CASE_INSENSITIVE,
     OPT_COMPRESSION,
     OPT_CPLUSPLUS,
-    OPT_DEBUG,
-    OPT_DEFAULT,
+    OPT_DEBUG,     OPT_NO_DEBUG,
+    OPT_DEFAULT,   OPT_NO_DEFAULT,
     OPT_DONOTHING,
-    OPT_ECS,
+    OPT_ECS,       OPT_NO_ECS,
     OPT_FAST,
     OPT_FULL,
     OPT_HEADER,
     OPT_HELP,
     OPT_INTERACTIVE,
     OPT_LEX_COMPAT,
-    OPT_MAIN,
-    OPT_META_ECS,
+    OPT_MAIN,      OPT_NO_MAIN,
+    OPT_META_ECS,  OPT_NO_META_ECS
     OPT_NEVER_INTERACTIVE,
-    OPT_NODEFAULT,
-    OPT_NOLINE,
-    OPT_NOWARN,
+    OPT_NO_LINE,
     OPT_OUTFILE,
     OPT_PERF_REPORT,
     OPT_POINTER,
     OPT_PREFIX,
     OPT_PREPROCDEFINE,
     OPT_READ,
-    OPT_REENTRANT,
+    OPT_REENTRANT,  OPT_NO_REENTRANT,
     OPT_REENTRANT_BISON,
+    OPT_REJECT,  OPT_NO_REJECT,
     OPT_SKEL,
     OPT_STACK,
     OPT_STDINIT,
     OPT_STDOUT,
     OPT_TRACE,
+    OPT_UNPUT,    OPT_NOUNPUT,
     OPT_VERBOSE,
     OPT_VERSION,
+    OPT_WARN,     OPT_NOWARN,
     OPT_YYCLASS,
-    OPT_YYLINENO,
-    OPT_YYWRAP
+    OPT_YYLINENO, OPT_NO_YYLINEO,
+    OPT_YYMORE,   OPT_NO_YYMORE,
+    OPT_YYWRAP,   OPT_NO_YYWRAP,
+
+    OPT_YY_PUSH_STATE, OPT_NO_YY_PUSH_STATE,
+    OPT_YY_POP_STATE,  OPT_NO_YY_POP_STATE,
+    OPT_YY_TOP_STATE,  OPT_NO_YY_TOP_STATE,
+    OPT_YY_SCAN_BUFFER,OPT_NO_YY_SCAN_BUFFER,
+    OPT_YY_SCAN_BYTES, OPT_NO_YY_SCAN_BYTES,
+    OPT_YY_SCAN_STRING,OPT_NO_YY_SCAN_STRING,
+    OPT_YYGET_EXTRA,   OPT_NO_YYGET_EXTRA,
+    OPT_YYSET_EXTRA,   OPT_NO_YYSET_EXTRA,
+    OPT_YYGET_LENG,    OPT_NO_YYGET_LENG,
+    OPT_YYGET_TEXT,    OPT_NO_YYGET_TEXT,
+    OPT_YYGET_LINENO,  OPT_NO_YYGET_LINENO,
+    OPT_YYSET_LINENO,  OPT_NO_YYSET_LINENO,
+    OPT_YYGET_IN,      OPT_NO_YYGET_IN,
+    OPT_YYSET_IN,      OPT_NO_YYSET_IN,
+    OPT_YYGET_OUT,     OPT_NO_YYGET_OUT,
+    OPT_YYSET_OUT,     OPT_NO_YYSET_OUT,
+    OPT_YYGET_LVAL,    OPT_NO_YYGET_LVAL,
+    OPT_YYSET_LVAL,    OPT_NO_YYSET_LVAL,
+    OPT_YYGET_LLOC,    OPT_NO_YYGET_LLOC,
+    OPT_YYSET_LLOC,    OPT_NO_YYSET_LLOC
 };
 
 #endif
diff --git a/scan.l b/scan.l
index ac58aaff09238aa613b2956dfcb7cfaeee70c9d9..392948bcdc90badf62f920074008926f62c05978 100644 (file)
--- a/scan.l
+++ b/scan.l
@@ -422,6 +422,7 @@ LEXOPT              [aceknopr]
        ^"%%".*         {
                        sectnum = 3;
                        BEGIN(SECT3);
+                       outn("/* Begin user sect3 */");
                        yyterminate(); /* to stop the parser */
                        }
 
index 0adf5120da6d6d9c5506b8e67b46dab083c5b9f7..9702dedd82dc2bf8bbc295a74a42b6e48a4cad1f 100644 (file)
--- a/scanopt.c
+++ b/scanopt.c
@@ -718,6 +718,7 @@ scanopt (svoid, arg, optindex)
 
         optname = pstart;
         namelen = 1;
+        is_short = 1;
 
         if(!find_opt(s, 0, pstart, namelen, &errcode,&opt_offset)) {
             return scanopt_err(s,opt_offset,1,errcode);
index 28b51d50adca396b6f39d805bc3812d68e7b9a69..6b55ca0f10fbfa91bbd6c2f43a06eb154564fe17 100644 (file)
@@ -62,6 +62,8 @@ DESCRIPTION OF TESTS
   basic-r       -  Simple scanner, reentrant.
   bison-yylval  -  Reentrant scanner + pure parser. Requires bison.
   bison-yylloc  -  Reentrant scanner + pure parser. Requires bison.
+  header-nr     -  Test generated header file, non-reentrant.
+  header-r      -  Test generated header file, reentrant.
   include-by-buffer     - YY_BUFFER_STATE, yy_push_state, etc.
   include-by-reentrant  - Nested scanners.
   prefix-nr     - verify prefixes are working, nonreentrant.
index 26fcb2373a99fca5bfdc5c5fac91fd2a8cfbf041..83373c5d4fa7dd8737242a4d91dd803bd4dd69e4 100644 (file)
@@ -42,12 +42,13 @@ TESTDIRS="test-string-r test-pthread \
           TEMPLATE test-basic-nr test-basic-r \
           test-include-by-buffer test-string-nr \
           test-bison-yylloc test-yyextra test-prefix-nr \
-          test-prefix-r"
+          test-prefix-r test-header-nr test-header-r"
 
 AC_OUTPUT( Makefile test-string-r/Makefile test-pthread/Makefile
            test-bison-yylval/Makefile test-include-by-reentrant/Makefile
            TEMPLATE/Makefile test-basic-nr/Makefile test-basic-r/Makefile
            test-include-by-buffer/Makefile test-string-nr/Makefile
            test-bison-yylloc/Makefile test-yyextra/Makefile
-           test-prefix-nr/Makefile test-prefix-r/Makefile)
+           test-prefix-nr/Makefile test-prefix-r/Makefile
+           test-header-nr/Makefile test-header-r/Makefile)