diff options
-rw-r--r-- | usr.bin/lex/FlexLexer.h | 96 | ||||
-rw-r--r-- | usr.bin/lex/NEWS | 527 | ||||
-rw-r--r-- | usr.bin/lex/README | 27 | ||||
-rw-r--r-- | usr.bin/lex/config.h | 26 | ||||
-rw-r--r-- | usr.bin/lex/flex.skl | 520 | ||||
-rw-r--r-- | usr.bin/lex/lib/libmain.c | 7 | ||||
-rwxr-xr-x | usr.bin/lex/mkskel.sh | 4 | ||||
-rw-r--r-- | usr.bin/lex/parse.y | 320 | ||||
-rw-r--r-- | usr.bin/lex/scan.l | 548 | ||||
-rw-r--r-- | usr.bin/lex/skel.c | 524 | ||||
-rw-r--r-- | usr.bin/lex/version.h | 2 |
11 files changed, 1999 insertions, 602 deletions
diff --git a/usr.bin/lex/FlexLexer.h b/usr.bin/lex/FlexLexer.h index feb40b6..6c9a950 100644 --- a/usr.bin/lex/FlexLexer.h +++ b/usr.bin/lex/FlexLexer.h @@ -1,6 +1,7 @@ -// $Header: FlexLexer.h,v 1.2 94/01/04 14:57:26 vern Exp $ +// $Header: /home/daffy/u0/vern/flex/RCS/FlexLexer.h,v 1.19 96/05/25 20:43:02 vern Exp $ -// FlexLexer.h -- define classes for lexical analyzers generated by flex +// FlexLexer.h -- define interfaces for lexical analyzer classes generated +// by flex // Copyright (c) 1993 The Regents of the University of California. // All rights reserved. @@ -22,19 +23,26 @@ // WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF // MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. -#ifndef __FLEX_LEXER_H -#define __FLEX_LEXER_H - - -// This file defines two classes. The first, FlexLexer, is an abstract -// class which specifies the external interface provided to flex C++ -// lexer objects. The second, yyFlexLexer, fills out most of the meat -// of the lexer class; its internals may vary from lexer to lexer -// depending on things like whether REJECT is used. +// This file defines FlexLexer, an abstract class which specifies the +// external interface provided to flex C++ lexer objects, and yyFlexLexer, +// which defines a particular lexer class. // // If you want to create multiple lexer classes, you use the -P flag -// to rename each yyFlexLexer to some other xxFlexLexer. +// to rename each yyFlexLexer to some other xxFlexLexer. You then +// include <FlexLexer.h> in your other sources once per lexer class: +// +// #undef yyFlexLexer +// #define yyFlexLexer xxFlexLexer +// #include <FlexLexer.h> +// +// #undef yyFlexLexer +// #define yyFlexLexer zzFlexLexer +// #include <FlexLexer.h> +// ... +#ifndef __FLEX_LEXER_H +// Never included before - need to define base class. +#define __FLEX_LEXER_H #include <iostream.h> extern "C++" { @@ -58,46 +66,46 @@ public: virtual int yylex() = 0; + // Call yylex with new input/output sources. + int yylex( istream* new_in, ostream* new_out = 0 ) + { + switch_streams( new_in, new_out ); + return yylex(); + } + + // Switch to new input/output streams. A nil stream pointer + // indicates "keep the current one". + virtual void switch_streams( istream* new_in = 0, + ostream* new_out = 0 ) = 0; + + int lineno() const { return yylineno; } + + int debug() const { return yy_flex_debug; } + void set_debug( int flag ) { yy_flex_debug = flag; } + protected: char* yytext; int yyleng; + int yylineno; // only maintained if you use %option yylineno + int yy_flex_debug; // only has effect with -d or "%option debug" }; +} +#endif + +#if defined(yyFlexLexer) || ! defined(yyFlexLexerOnce) +// Either this is the first time through (yyFlexLexerOnce not defined), +// or this is a repeated include to define a different flavor of +// yyFlexLexer, as discussed in the flex man page. +#define yyFlexLexerOnce class yyFlexLexer : public FlexLexer { public: // arg_yyin and arg_yyout default to the cin and cout, but we // only make that assignment when initializing in yylex(). - yyFlexLexer( istream* arg_yyin = 0, ostream* arg_yyout = 0 ) - { - yyin = arg_yyin; - yyout = arg_yyout; - yy_c_buf_p = 0; - yy_init = 1; - yy_start = 0; - - yy_did_buffer_switch_on_eof = 0; - - yy_looking_for_trail_begin = 0; - yy_more_flag = 0; - yy_more_len = 0; - - yy_start_stack_ptr = yy_start_stack_depth = 0; - yy_start_stack = 0; - - yy_current_buffer = 0; + yyFlexLexer( istream* arg_yyin = 0, ostream* arg_yyout = 0 ); -#ifdef YY_USES_REJECT - yy_state_buf = new yy_state_type[YY_BUF_SIZE + 2]; -#else - yy_state_buf = 0; -#endif - } - - virtual ~yyFlexLexer() - { - delete yy_state_buf; - } + virtual ~yyFlexLexer(); void yy_switch_to_buffer( struct yy_buffer_state* new_buffer ); struct yy_buffer_state* yy_create_buffer( istream* s, int size ); @@ -105,6 +113,7 @@ public: void yyrestart( istream* s ); virtual int yylex(); + virtual void switch_streams( istream* new_in, ostream* new_out ); protected: virtual int LexerInput( char* buf, int max_size ); @@ -116,6 +125,7 @@ protected: void yy_load_buffer_state(); void yy_init_buffer( struct yy_buffer_state* b, istream* s ); + void yy_flush_buffer( struct yy_buffer_state* b ); int yy_start_stack_ptr; int yy_start_stack_depth; @@ -168,8 +178,8 @@ protected: int yy_more_flag; int yy_more_len; + int yy_more_offset; + int yy_prev_more_offset; }; -} - #endif diff --git a/usr.bin/lex/NEWS b/usr.bin/lex/NEWS index aff90a3..e4ba93f 100644 --- a/usr.bin/lex/NEWS +++ b/usr.bin/lex/NEWS @@ -1,3 +1,525 @@ +Changes between release 2.5.3 (29May96) and release 2.5.2: + + - Some serious bugs in yymore() have been fixed. In particular, + when using AT&T-lex-compatibility or %array, you can intermix + calls to input(), unput(), and yymore(). (This still doesn't + work for %pointer, and isn't likely to in the future.) + + - A bug in handling NUL's in the input stream of scanners using + REJECT has been fixed. + + - The default main() in libfl.a now repeatedly calls yylex() until + it returns 0, rather than just calling it once. + + - Minor tweak for Windows NT Makefile, MISC/NT/Makefile. + + +Changes between release 2.5.2 (25Apr95) and release 2.5.1: + + - The --prefix configuration option now works. + + - A bug that completely broke the "-Cf" table compression + option has been fixed. + + - A major headache involving "const" declarators and Solaris + systems has been fixed. + + - An octal escape sequence in a flex regular expression must + now contain only the digits 0-7. + + - You can now use "--" on the flex command line to mark the + end of flex options. + + - You can now specify the filename '-' as a synonym for stdin. + + - By default, the scanners generated by flex no longer + statically initialize yyin and yyout to stdin and stdout. + This change is necessary because in some ANSI environments, + stdin and stdout are not compile-time constant. You can + force the initialization using "%option stdinit" in the first + section of your flex input. + + - "%option nounput" now correctly omits the unput() routine + from the output. + + - "make clean" now removes config.log, config.cache, and the + flex binary. The fact that it removes the flex binary means + you should take care if making changes to scan.l, to make + sure you don't wind up in a bootstrap problem. + + - In general, the Makefile has been reworked somewhat (thanks + to Francois Pinard) for added flexibility - more changes will + follow in subsequent releases. + + - The .texi and .info files in MISC/texinfo/ have been updated, + thanks also to Francois Pinard. + + - The FlexLexer::yylex(istream* new_in, ostream* new_out) method + now does not have a default for the first argument, to disambiguate + it from FlexLexer::yylex(). + + - A bug in destructing a FlexLexer object before doing any scanning + with it has been fixed. + + - A problem with including FlexLexer.h multiple times has been fixed. + + - The alloca() chud necessary to accommodate bison has grown + even uglier, but hopefully more correct. + + - A portability tweak has been added to accommodate compilers that + use char* generic pointers. + + - EBCDIC contact information in the file MISC/EBCDIC has been updated. + + - An OS/2 Makefile and config.h for flex 2.5 is now available in + MISC/OS2/, contributed by Kai Uwe Rommel. + + - The descrip.mms file for building flex under VMS has been updated, + thanks to Pat Rankin. + + - The notes on building flex for the Amiga have been updated for + flex 2.5, contributed by Andreas Scherer. + + +Changes between release 2.5.1 (28Mar95) and release 2.4.7: + + - A new concept of "start condition" scope has been introduced. + A start condition scope is begun with: + + <SCs>{ + + where SCs is a list of one or more start conditions. Inside + the start condition scope, every rule automatically has the + prefix <SCs> applied to it, until a '}' which matches the + initial '{'. So, for example: + + <ESC>{ + "\\n" return '\n'; + "\\r" return '\r'; + "\\f" return '\f'; + "\\0" return '\0'; + } + + is equivalent to: + + <ESC>"\\n" return '\n'; + <ESC>"\\r" return '\r'; + <ESC>"\\f" return '\f'; + <ESC>"\\0" return '\0'; + + As indicated in this example, rules inside start condition scopes + (and any rule, actually, other than the first) can be indented, + to better show the extent of the scope. + + Start condition scopes may be nested. + + - The new %option directive can be used in the first section of + a flex scanner to control scanner-generation options. Most + options are given simply as names, optionally preceded by the + word "no" (with no intervening whitespace) to negate their + meaning. Some are equivalent to flex flags, so putting them + in your scanner source is equivalent to always specifying + the flag (%option's take precedence over flags): + + 7bit -7 option + 8bit -8 option + align -Ca option + backup -b option + batch -B option + c++ -+ option + caseful opposite of -i option (caseful is the default); + case-sensitive same as above + caseless -i option; + case-insensitive same as above + 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 + stdout -t option + verbose -v option + warn opposite of -w option (so use "%option nowarn" for -w) + + array equivalent to "%array" + pointer equivalent to "%pointer" (default) + + Some provide new features: + + always-interactive generate a scanner which always + considers its input "interactive" (no call to isatty() + will be made when the scanner runs) + main supply a main program for the scanner, which + simply calls yylex(). Implies %option noyywrap. + never-interactive generate a scanner which never + considers its input "interactive" (no call to isatty() + will be made when the scanner runs) + stack if set, enable start condition stacks (see below) + stdinit if unset ("%option nostdinit"), initialize yyin + and yyout statically to nil FILE* pointers, instead + of stdin and stdout + yylineno if set, keep track of the current line + number in global yylineno (this option is expensive + in terms of performance). The line number is available + to C++ scanning objects via the new member function + lineno(). + yywrap if unset ("%option noyywrap"), scanner does not + call yywrap() upon EOF but simply assumes there + are no more files to scan + + Flex scans your rule actions to determine whether you use the + REJECT or yymore features (this is not new). Two %options can be + used to override its decision, either by setting them to indicate + the feature is indeed used, or unsetting them to indicate it + actually is not used: + + reject + yymore + + Three %option's take string-delimited values, offset with '=': + + outfile="<name>" equivalent to -o<name> + prefix="<name>" equivalent to -P<name> + yyclass="<name>" set the name of the C++ scanning class + (see below) + + A number of %option's are available for lint purists who + want to suppress the appearance of unneeded routines in + the generated scanner. Each of the following, if unset, + results in the corresponding routine not appearing in the + generated scanner: + + input, unput + yy_push_state, yy_pop_state, yy_top_state + yy_scan_buffer, yy_scan_bytes, yy_scan_string + + You can specify multiple options with a single %option directive, + and multiple directives in the first section of your flex input file. + + - The new function: + + YY_BUFFER_STATE yy_scan_string( const char *str ) + + returns a YY_BUFFER_STATE (which also becomes the current input + buffer) for scanning the given string, which occurs starting + with the next call to yylex(). The string must be NUL-terminated. + A related function: + + YY_BUFFER_STATE yy_scan_bytes( const char *bytes, int len ) + + creates a buffer for scanning "len" bytes (including possibly NUL's) + starting at location "bytes". + + Note that both of these functions create and scan a *copy* of + the string/bytes. (This may be desirable, since yylex() modifies + the contents of the buffer it is scanning.) You can avoid the + copy by using: + + YY_BUFFER_STATE yy_scan_buffer( char *base, yy_size_t size ) + + which scans in place the buffer starting at "base", consisting + of "size" bytes, the last two bytes of which *must* be + YY_END_OF_BUFFER_CHAR (these bytes are not scanned; thus, scanning + consists of base[0] through base[size-2], inclusive). If you + fail to set up "base" in this manner, yy_scan_buffer returns a + nil pointer instead of creating a new input buffer. + + The type yy_size_t is an integral type to which you can cast + an integer expression reflecting the size of the buffer. + + - Three new routines are available for manipulating stacks of + start conditions: + + void yy_push_state( int new_state ) + + pushes the current start condition onto the top of the stack + and BEGIN's "new_state" (recall that start condition names are + also integers). + + void yy_pop_state() + + pops the top of the stack and BEGIN's to it, and + + int yy_top_state() + + returns the top of the stack without altering the stack's + contents. + + The start condition stack grows dynamically and so has no built-in + size limitation. If memory is exhausted, program execution + is aborted. + + To use start condition stacks, your scanner must include + a "%option stack" directive. + + - flex now supports POSIX character class expressions. These + are expressions enclosed inside "[:" and ":]" delimiters (which + themselves must appear between the '[' and ']' of a character + class; other elements may occur inside the character class, too). + The expressions flex recognizes are: + + [:alnum:] [:alpha:] [:blank:] [:cntrl:] [:digit:] [:graph:] + [:lower:] [:print:] [:punct:] [:space:] [:upper:] [:xdigit:] + + These expressions all designate a set of characters equivalent to + the corresponding isXXX function (for example, [:alnum:] designates + those characters for which isalnum() returns true - i.e., any + alphabetic or numeric). Some systems don't provide isblank(), + so flex defines [:blank:] as a blank or a tab. + + For example, the following character classes are all equivalent: + + [[:alnum:]] + [[:alpha:][:digit:] + [[:alpha:]0-9] + [a-zA-Z0-9] + + If your scanner is case-insensitive (-i flag), then [:upper:] + and [:lower:] are equivalent to [:alpha:]. + + - The promised rewrite of the C++ FlexLexer class has not yet + been done. Support for FlexLexer is limited at the moment to + fixing show-stopper bugs, so, for example, the new functions + yy_scan_string() & friends are not available to FlexLexer + objects. + + - The new macro + + yy_set_interactive(is_interactive) + + can be used to control whether the current buffer is considered + "interactive". An interactive buffer is processed more slowly, + but must be used when the scanner's input source is indeed + interactive to avoid problems due to waiting to fill buffers + (see the discussion of the -I flag in flex.1). A non-zero value + in the macro invocation marks the buffer as interactive, a zero + value as non-interactive. Note that use of this macro overrides + "%option always-interactive" or "%option never-interactive". + + yy_set_interactive() must be invoked prior to beginning to + scan the buffer. + + - The new macro + + yy_set_bol(at_bol) + + can be used to control whether the current buffer's scanning + context for the next token match is done as though at the + beginning of a line (non-zero macro argument; makes '^' anchored + rules active) or not at the beginning of a line (zero argument, + '^' rules inactive). + + - Related to this change, the mechanism for determining when a scan is + starting at the beginning of a line has changed. It used to be + that '^' was active iff the character prior to that at which the + scan started was a newline. The mechanism now is that '^' is + active iff the last token ended in a newline (or the last call to + input() returned a newline). For most users, the difference in + mechanisms is negligible. Where it will make a difference, + however, is if unput() or yyless() is used to alter the input + stream. When in doubt, use yy_set_bol(). + + - The new beginning-of-line mechanism involved changing some fairly + twisted code, so it may have introduced bugs - beware ... + + - The macro YY_AT_BOL() returns true if the next token scanned from + the current buffer will have '^' rules active, false otherwise. + + - The new function + + void yy_flush_buffer( struct yy_buffer_state* b ) + + flushes the contents of the current buffer (i.e., next time + the scanner attempts to match a token using b as the current + buffer, it will begin by invoking YY_INPUT to fill the buffer). + This routine is also available to C++ scanners (unlike some + of the other new routines). + + The related macro + + YY_FLUSH_BUFFER + + flushes the contents of the current buffer. + + - A new "-ooutput" option writes the generated scanner to "output". + If used with -t, the scanner is still written to stdout, but + its internal #line directives (see previous item) use "output". + + - Flex now generates #line directives relating the code it + produces to the output file; this means that error messages + in the flex-generated code should be correctly pinpointed. + + - When generating #line directives, filenames with embedded '\'s + have those characters escaped (i.e., turned into '\\'). This + feature helps with reporting filenames for some MS-DOS and OS/2 + systems. + + - The FlexLexer class includes two new public member functions: + + virtual void switch_streams( istream* new_in = 0, + ostream* new_out = 0 ) + + reassigns yyin to new_in (if non-nil) and yyout to new_out + (ditto), deleting the previous input buffer if yyin is + reassigned. It is used by: + + int yylex( istream* new_in = 0, ostream* new_out = 0 ) + + which first calls switch_streams() and then returns the value + of calling yylex(). + + - C++ scanners now have yy_flex_debug as a member variable of + FlexLexer rather than a global, and member functions for testing + and setting it. + + - When generating a C++ scanning class, you can now use + + %option yyclass="foo" + + to inform flex that you have derived "foo" as a subclass of + yyFlexLexer, so flex will place your actions in the member + function foo::yylex() instead of yyFlexLexer::yylex(). It also + generates a yyFlexLexer::yylex() member function that generates a + run-time error if called (by invoking yyFlexLexer::LexerError()). + This feature is necessary if your subclass "foo" introduces some + additional member functions or variables that you need to access + from yylex(). + + - Current texinfo files in MISC/texinfo, contributed by Francois + Pinard. + + - You can now change the name "flex" to something else (e.g., "lex") + by redefining $(FLEX) in the Makefile. + + - Two bugs (one serious) that could cause "bigcheck" to fail have + been fixed. + + - A number of portability/configuration changes have been made + for easier portability. + + - You can use "YYSTATE" in your scanner as an alias for YY_START + (for AT&T lex compatibility). + + - input() now maintains yylineno. + + - input() no longer trashes yytext. + + - interactive scanners now read characters in YY_INPUT up to a + newline, a large performance gain. + + - C++ scanner objects now work with the -P option. You include + <FlexLexer.h> once per scanner - see comments in <FlexLexer.h> + (or flex.1) for details. + + - C++ FlexLexer objects now use the "cerr" stream to report -d output + instead of stdio. + + - The -c flag now has its full glorious POSIX interpretation (do + nothing), rather than being interpreted as an old-style -C flag. + + - Scanners generated by flex now include two #define's giving + the major and minor version numbers (YY_FLEX_MAJOR_VERSION, + YY_FLEX_MINOR_VERSION). These can then be tested to see + whether certain flex features are available. + + - Scanners generated using -l lex compatibility now have the symbol + YY_FLEX_LEX_COMPAT #define'd. + + - When initializing (i.e., yy_init is non-zero on entry to yylex()), + generated scanners now set yy_init to zero before executing + YY_USER_INIT. This means that you can set yy_init back to a + non-zero value in YY_USER_INIT if you need the scanner to be + reinitialized on the next call. + + - You can now use "#line" directives in the first section of your + scanner specification. + + - When generating full-table scanners (-Cf), flex now puts braces + around each row of the 2-d array initialization, to silence warnings + on over-zealous compilers. + + - Improved support for MS-DOS. The flex sources have been successfully + built, unmodified, for Borland 4.02 (all that's required is a + Borland Makefile and config.h file, which are supplied in + MISC/Borland - contributed by Terrence O Kane). + + - Improved support for Macintosh using Think C - the sources should + build for this platform "out of the box". Contributed by Scott + Hofmann. + + - Improved support for VMS, in MISC/VMS/, contributed by Pat Rankin. + + - Support for the Amiga, in MISC/Amiga/, contributed by Andreas + Scherer. Note that the contributed files were developed for + flex 2.4 and have not been tested with flex 2.5. + + - Some notes on support for the NeXT, in MISC/NeXT, contributed + by Raf Schietekat. + + - The MISC/ directory now includes a preformatted version of flex.1 + in flex.man, and pre-yacc'd versions of parse.y in parse.{c,h}. + + - The flex.1 and flexdoc.1 manual pages have been merged. There + is now just one document, flex.1, which includes an overview + at the beginning to help you find the section you need. + + - Documentation now clarifies that start conditions persist across + switches to new input files or different input buffers. If you + want to e.g., return to INITIAL, you must explicitly do so. + + - The "Performance Considerations" section of the manual has been + updated. + + - Documented the "yy_act" variable, which when YY_USER_ACTION is + invoked holds the number of the matched rule, and added an + example of using yy_act to profile how often each rule is matched. + + - Added YY_NUM_RULES, a definition that gives the total number + of rules in the file, including the default rule (even if you + use -s). + + - Documentation now clarifies that you can pass a nil FILE* pointer + to yy_create_buffer() or yyrestart() if you've arrange YY_INPUT + to not need yyin. + + - Documentation now clarifies that YY_BUFFER_STATE is a pointer to + an opaque "struct yy_buffer_state". + + - Documentation now stresses that you gain the benefits of removing + backing-up states only if you remove *all* of them. + + - Documentation now points out that traditional lex allows you + to put the action on a separate line from the rule pattern if + the pattern has trailing whitespace (ugh!), but flex doesn't + support this. + + - A broken example in documentation of the difference between + inclusive and exclusive start conditions is now fixed. + + - Usage (-h) report now goes to stdout. + + - Version (-V) info now goes to stdout. + + - More #ifdef chud has been added to the parser in attempt to + deal with bison's use of alloca(). + + - "make clean" no longer deletes emacs backup files (*~). + + - Some memory leaks have been fixed. + + - A bug was fixed in which dynamically-expanded buffers were + reallocated a couple of bytes too small. + + - A bug was fixed which could cause flex to read and write beyond + the end of the input buffer. + + - -S will not be going away. + + Changes between release 2.4.7 (03Aug94) and release 2.4.6: - Fixed serious bug in reading multiple files. @@ -24,7 +546,6 @@ Changes between release 2.4.6 (04Jan94) and release 2.4.5: - The use of 'extern "C++"' in FlexLexer.h has been modified to get around an incompatibility with g++'s header files. - Changes between release 2.4.5 (11Dec93) and release 2.4.4: - Fixed bug breaking C++ scanners that use REJECT or variable @@ -296,9 +817,7 @@ Changes between release 2.4.1 (30Nov93) and release 2.3.8: - The skeleton file is no longer opened at run-time, but instead compiled into a large string array (thanks to John Gilmore and friends at Cygnus). You can still use the -S flag to point flex - at a different skeleton file, though if you use this option let - me know, as I plan to otherwise do away with -S in the near - future. + at a different skeleton file. - flex no longer uses a temporary file to store the scanner's actions. diff --git a/usr.bin/lex/README b/usr.bin/lex/README index 339e9bb..7a4224d 100644 --- a/usr.bin/lex/README +++ b/usr.bin/lex/README @@ -1,4 +1,4 @@ -This is release 2.4 of flex. See "version.h" for the exact patch-level. +This is release 2.5 of flex. See "version.h" for the exact patch-level. See the file "NEWS" to find out what is new in this Flex release. @@ -15,19 +15,12 @@ Note that flex is distributed under a copyright very similar to that of BSD Unix, and not under the GNU General Public License (GPL), except for the "configure" script, which is covered by the GPL. -Many thanks to the 2.4 pre-testers for finding a bunch of bugs and helping -increase/test portability: Francois Pinard, Nathan Zelle, Gavin Nicol, -Chris Thewalt, and Matthew Jacob. +Many thanks to the 2.5 beta-testers for finding bugs and helping test and +increase portability: Stan Adermann, Scott David Daniels, Charles Elliott, +Joe Gayda, Chris Meier, James Nordby, Terrence O'Kane, Karsten Pahnke, +Francois Pinard, Pat Rankin, Andreas Scherer, Marc Wiese, Nathan Zelle. -Please send bug reports and feedback to: - - Vern Paxson - ICSD, 46A/1123 - Lawrence Berkeley Laboratory - 1 Cyclotron Rd. - Berkeley, CA 94720 - - vern@ee.lbl.gov +Please send bug reports and feedback to: Vern Paxson (vern@ee.lbl.gov). The flex distribution consists of the following files: @@ -40,7 +33,8 @@ The flex distribution consists of the following files: COPYING flex's copyright - configure.in, configure, Makefile.in, install.sh, mkinstalldirs + conf.in, configure.in, configure, Makefile.in, install.sh, + mkinstalldirs elements of the "autoconf" auto-configuration process flexdef.h, parse.y, scan.l, ccl.c, dfa.c, ecs.c, gen.c, main.c, @@ -51,8 +45,8 @@ The flex distribution consists of the following files: flex.skl flex scanner skeleton mkskel.sh script for converting flex.skl to C source file skel.c + skel.c pre-converted C version of flex.skl - liballoc.c libmain.c flex library (-lfl) sources libyywrap.c @@ -60,8 +54,7 @@ The flex distribution consists of the following files: FlexLexer.h header file for C++ lexer class - flexdoc.1 full user documentation - flex.1 reference documentation + flex.1 user documentation MISC/ a directory containing miscellaneous contributions. See MISC/README for details. diff --git a/usr.bin/lex/config.h b/usr.bin/lex/config.h new file mode 100644 index 0000000..dc4481c --- /dev/null +++ b/usr.bin/lex/config.h @@ -0,0 +1,26 @@ +/* config.h. Generated automatically by configure. */ +/* $Header: /home/daffy/u0/vern/flex/RCS/conf.in,v 1.2 95/01/09 12:11:51 vern Exp $ */ + +/* Define to empty if the keyword does not work. */ +/* #undef const */ + +/* Define to `unsigned' if <sys/types.h> doesn't define. */ +/* #undef size_t */ + +/* Define if you have the ANSI C header files. */ +#define STDC_HEADERS 1 + +/* Define if you have the <malloc.h> header file. */ +/* #undef HAVE_MALLOC_H */ + +/* Define if you have the <string.h> header file. */ +#define HAVE_STRING_H 1 + +/* Define if you have the <sys/types.h> header file. */ +#define HAVE_SYS_TYPES_H 1 + +/* Define if you have <alloca.h> and it should be used (not on Ultrix). */ +/* #undef HAVE_ALLOCA_H */ + +/* Define if platform-specific command line handling is necessary. */ +/* #undef NEED_ARGV_FIXUP */ diff --git a/usr.bin/lex/flex.skl b/usr.bin/lex/flex.skl index 01ff7a1..67ebe57 100644 --- a/usr.bin/lex/flex.skl +++ b/usr.bin/lex/flex.skl @@ -1,10 +1,12 @@ /* A lexical scanner generated by flex */ /* Scanner skeleton version: - * $Header: /home/daffy/u0/vern/flex/flex-2.4.7/RCS/flex.skl,v 1.2 94/08/03 11:13:24 vern Exp $ + * $Header: /home/daffy/u0/vern/flex/RCS/flex.skl,v 2.89 96/05/25 21:02:21 vern Exp $ */ #define FLEX_SCANNER +#define YY_FLEX_MAJOR_VERSION 2 +#define YY_FLEX_MINOR_VERSION 5 %- #include <stdio.h> @@ -35,7 +37,7 @@ class istream; #else /* ! __cplusplus */ -#ifdef __STDC__ +#if __STDC__ #define YY_USE_PROTOS #define YY_USE_CONST @@ -43,16 +45,19 @@ class istream; #endif /* __STDC__ */ #endif /* ! __cplusplus */ - #ifdef __TURBOC__ + #pragma warn -rch + #pragma warn -use +#include <io.h> +#include <stdlib.h> #define YY_USE_CONST +#define YY_USE_PROTOS #endif - -#ifndef YY_USE_CONST -#ifndef const -#define const -#endif +#ifdef YY_USE_CONST +#define yyconst const +#else +#define yyconst #endif @@ -79,16 +84,16 @@ class istream; #define BEGIN yy_start = 1 + 2 * /* Translate the current start state into a value that can be later handed - * to BEGIN to return to the state. + * to BEGIN to return to the state. The YYSTATE alias is for lex + * compatibility. */ #define YY_START ((yy_start - 1) / 2) +#define YYSTATE YY_START /* Action number for EOF rule of a given start state. */ #define YY_STATE_EOF(state) (YY_END_OF_BUFFER + state + 1) -/* Special action meaning "start processing a new file". Now included - * only for backward compatibility with previous versions of flex. - */ +/* Special action meaning "start processing a new file". */ #define YY_NEW_FILE yyrestart( yyin ) #define YY_END_OF_BUFFER_CHAR 0 @@ -103,14 +108,6 @@ extern int yyleng; extern FILE *yyin, *yyout; %* -#ifdef __cplusplus -extern "C" { -#endif - extern int yywrap YY_PROTO(( void )); -#ifdef __cplusplus - } -#endif - #define EOB_ACT_CONTINUE_SCAN 0 #define EOB_ACT_END_OF_FILE 1 #define EOB_ACT_LAST_MATCH 2 @@ -136,6 +133,7 @@ extern "C" { { \ /* Undo effects of setting up yytext. */ \ *yy_cp = yy_hold_char; \ + YY_RESTORE_YY_MORE_OFFSET \ yy_c_buf_p = yy_cp = yy_bp + n - YY_MORE_ADJ; \ YY_DO_BEFORE_ACTION; /* set up yytext again */ \ } \ @@ -143,6 +141,12 @@ extern "C" { #define unput(c) yyunput( c, yytext_ptr ) +/* The following is because we cannot portably get our hands on size_t + * (without autoconf's help, which isn't available because we want + * flex-generated scanners to compile on their own). + */ +typedef unsigned int yy_size_t; + struct yy_buffer_state { @@ -158,13 +162,19 @@ struct yy_buffer_state /* Size of input buffer in bytes, not including room for EOB * characters. */ - int yy_buf_size; + yy_size_t yy_buf_size; /* Number of characters read into yy_ch_buf, not including EOB * characters. */ int yy_n_chars; + /* Whether we "own" the buffer - i.e., we know we created it, + * and can realloc() it to grow it, and should free() it to + * delete it. + */ + int yy_is_our_buffer; + /* Whether this is an "interactive" input source; if so, and * if we're using stdio for input, then we want to use getc() * instead of fread(), to make sure we stop fetching input after @@ -172,6 +182,12 @@ struct yy_buffer_state */ int yy_is_interactive; + /* Whether we're considered to be at the beginning of a line. + * If so, '^' rules will be active on the next match, otherwise + * not. + */ + int yy_at_bol; + /* Whether to try to fill the input buffer when we reach the * end of it. */ @@ -223,47 +239,50 @@ static int yy_start = 0; /* start state number */ */ static int yy_did_buffer_switch_on_eof; -static void yyunput YY_PROTO(( int c, char *buf_ptr )); void yyrestart YY_PROTO(( FILE *input_file )); + void yy_switch_to_buffer YY_PROTO(( YY_BUFFER_STATE new_buffer )); void yy_load_buffer_state YY_PROTO(( void )); YY_BUFFER_STATE yy_create_buffer YY_PROTO(( FILE *file, int size )); void yy_delete_buffer YY_PROTO(( YY_BUFFER_STATE b )); void yy_init_buffer YY_PROTO(( YY_BUFFER_STATE b, FILE *file )); +void yy_flush_buffer YY_PROTO(( YY_BUFFER_STATE b )); +#define YY_FLUSH_BUFFER yy_flush_buffer( yy_current_buffer ) -static int yy_start_stack_ptr = 0; -static int yy_start_stack_depth = 0; -static int *yy_start_stack = 0; -static void yy_push_state YY_PROTO(( int new_state )); -static void yy_pop_state YY_PROTO(( void )); -static int yy_top_state YY_PROTO(( void )); +YY_BUFFER_STATE yy_scan_buffer YY_PROTO(( char *base, yy_size_t size )); +YY_BUFFER_STATE yy_scan_string YY_PROTO(( yyconst char *str )); +YY_BUFFER_STATE yy_scan_bytes YY_PROTO(( yyconst char *bytes, int len )); %* -static void *yy_flex_alloc YY_PROTO(( unsigned int )); -static void *yy_flex_realloc YY_PROTO(( void *, unsigned int )); +static void *yy_flex_alloc YY_PROTO(( yy_size_t )); +static void *yy_flex_realloc YY_PROTO(( void *, yy_size_t )); static void yy_flex_free YY_PROTO(( void * )); #define yy_new_buffer yy_create_buffer -%% yytext/yyin/yyout/yy_state_type/yylineno etc. def's & init go here +#define yy_set_interactive(is_interactive) \ + { \ + if ( ! yy_current_buffer ) \ + yy_current_buffer = yy_create_buffer( yyin, YY_BUF_SIZE ); \ + yy_current_buffer->yy_is_interactive = is_interactive; \ + } -#ifndef yytext_ptr -static void yy_flex_strncpy YY_PROTO(( char *, const char *, int )); -#endif +#define yy_set_bol(at_bol) \ + { \ + if ( ! yy_current_buffer ) \ + yy_current_buffer = yy_create_buffer( yyin, YY_BUF_SIZE ); \ + yy_current_buffer->yy_at_bol = at_bol; \ + } -%- Standard (non-C++) definition -#ifdef __cplusplus -static int yyinput YY_PROTO(( void )); -#else -static int input YY_PROTO(( void )); -#endif -%* +#define YY_AT_BOL() (yy_current_buffer->yy_at_bol) + +%% yytext/yyin/yyout/yy_state_type/yylineno etc. def's & init go here %- Standard (non-C++) definition static yy_state_type yy_get_previous_state YY_PROTO(( void )); static yy_state_type yy_try_NUL_trans YY_PROTO(( yy_state_type current_state )); static int yy_get_next_buffer YY_PROTO(( void )); -static void yy_fatal_error YY_PROTO(( const char msg[] )); +static void yy_fatal_error YY_PROTO(( yyconst char msg[] )); %* /* Done after the current pattern has been matched and before the @@ -283,6 +302,58 @@ static void yy_fatal_error YY_PROTO(( const char msg[] )); * section 1. */ +#ifndef YY_SKIP_YYWRAP +#ifdef __cplusplus +extern "C" int yywrap YY_PROTO(( void )); +#else +extern int yywrap YY_PROTO(( void )); +#endif +#endif + +%- +#ifndef YY_NO_UNPUT +static void yyunput YY_PROTO(( int c, char *buf_ptr )); +#endif +%* + +#ifndef yytext_ptr +static void yy_flex_strncpy YY_PROTO(( char *, yyconst char *, int )); +#endif + +#ifdef YY_NEED_STRLEN +static int yy_flex_strlen YY_PROTO(( yyconst char * )); +#endif + +#ifndef YY_NO_INPUT +%- Standard (non-C++) definition +#ifdef __cplusplus +static int yyinput YY_PROTO(( void )); +#else +static int input YY_PROTO(( void )); +#endif +%* +#endif + +#if YY_STACK_USED +static int yy_start_stack_ptr = 0; +static int yy_start_stack_depth = 0; +static int *yy_start_stack = 0; +#ifndef YY_NO_PUSH_STATE +static void yy_push_state YY_PROTO(( int new_state )); +#endif +#ifndef YY_NO_POP_STATE +static void yy_pop_state YY_PROTO(( void )); +#endif +#ifndef YY_NO_TOP_STATE +static int yy_top_state YY_PROTO(( void )); +#endif + +#else +#define YY_NO_PUSH_STATE 1 +#define YY_NO_POP_STATE 1 +#define YY_NO_TOP_STATE 1 +#endif + #ifdef YY_MALLOC_DECL YY_MALLOC_DECL #else @@ -373,6 +444,8 @@ YY_MALLOC_DECL #define YY_BREAK break; #endif +%% YY_RULE_SETUP definition goes here + YY_DECL { register yy_state_type yy_current_state; @@ -383,6 +456,8 @@ YY_DECL if ( yy_init ) { + yy_init = 0; + #ifdef YY_USER_INIT YY_USER_INIT; #endif @@ -404,15 +479,11 @@ YY_DECL yyout = &cout; %* - if ( yy_current_buffer ) - yy_init_buffer( yy_current_buffer, yyin ); - else + if ( ! yy_current_buffer ) yy_current_buffer = yy_create_buffer( yyin, YY_BUF_SIZE ); yy_load_buffer_state(); - - yy_init = 0; } while ( 1 ) /* loops until end-of-file is reached */ @@ -435,7 +506,7 @@ yy_find_action: YY_DO_BEFORE_ACTION; -%% code for yylineno update goes here, if -l option +%% code for yylineno update goes here do_action: /* This label is used only to access EOF actions. */ @@ -448,10 +519,11 @@ do_action: /* This label is used only to access EOF actions. */ case YY_END_OF_BUFFER: { /* Amount of text matched not including the EOB char. */ - int yy_amount_of_matched_text = yy_cp - yytext_ptr - 1; + int yy_amount_of_matched_text = (int) (yy_cp - yytext_ptr) - 1; /* Undo the effects of YY_DO_BEFORE_ACTION. */ *yy_cp = yy_hold_char; + YY_RESTORE_YY_MORE_OFFSET if ( yy_current_buffer->yy_buffer_status == YY_BUFFER_NEW ) { @@ -574,6 +646,53 @@ do_action: /* This label is used only to access EOF actions. */ } /* end of yylex */ %+ +yyFlexLexer::yyFlexLexer( istream* arg_yyin, ostream* arg_yyout ) + { + yyin = arg_yyin; + yyout = arg_yyout; + yy_c_buf_p = 0; + yy_init = 1; + yy_start = 0; + yy_flex_debug = 0; + yylineno = 1; // this will only get updated if %option yylineno + + yy_did_buffer_switch_on_eof = 0; + + yy_looking_for_trail_begin = 0; + yy_more_flag = 0; + yy_more_len = 0; + yy_more_offset = yy_prev_more_offset = 0; + + yy_start_stack_ptr = yy_start_stack_depth = 0; + yy_start_stack = 0; + + yy_current_buffer = 0; + +#ifdef YY_USES_REJECT + yy_state_buf = new yy_state_type[YY_BUF_SIZE + 2]; +#else + yy_state_buf = 0; +#endif + } + +yyFlexLexer::~yyFlexLexer() + { + delete yy_state_buf; + yy_delete_buffer( yy_current_buffer ); + } + +void yyFlexLexer::switch_streams( istream* new_in, ostream* new_out ) + { + if ( new_in ) + { + yy_delete_buffer( yy_current_buffer ); + yy_switch_to_buffer( yy_create_buffer( new_in, YY_BUF_SIZE ) ); + } + + if ( new_out ) + yyout = new_out; + } + #ifdef YY_INTERACTIVE int yyFlexLexer::LexerInput( char* buf, int /* max_size */ ) #else @@ -625,7 +744,7 @@ int yyFlexLexer::yy_get_next_buffer() %* { register char *dest = yy_current_buffer->yy_ch_buf; - register char *source = yytext_ptr - 1; /* copy prev. char, too */ + register char *source = yytext_ptr; register int number_to_move, i; int ret_val; @@ -637,7 +756,7 @@ int yyFlexLexer::yy_get_next_buffer() { /* Don't try to fill the buffer, so this is an EOF. */ if ( yy_c_buf_p - yytext_ptr - YY_MORE_ADJ == 1 ) { - /* We matched a singled characater, the EOB, so + /* We matched a single character, the EOB, so * treat this as a final EOF. */ return EOB_ACT_END_OF_FILE; @@ -655,7 +774,7 @@ int yyFlexLexer::yy_get_next_buffer() /* Try to read more data. */ /* First move last chars to start of buffer. */ - number_to_move = yy_c_buf_p - yytext_ptr; + number_to_move = (int) (yy_c_buf_p - yytext_ptr) - 1; for ( i = 0; i < number_to_move; ++i ) *(dest++) = *(source++); @@ -681,12 +800,26 @@ int yyFlexLexer::yy_get_next_buffer() /* just a shorter name for the current buffer */ YY_BUFFER_STATE b = yy_current_buffer; - int yy_c_buf_p_offset = yy_c_buf_p - b->yy_ch_buf; + int yy_c_buf_p_offset = + (int) (yy_c_buf_p - b->yy_ch_buf); + + if ( b->yy_is_our_buffer ) + { + int new_size = b->yy_buf_size * 2; + + if ( new_size <= 0 ) + b->yy_buf_size += b->yy_buf_size / 8; + else + b->yy_buf_size *= 2; - b->yy_buf_size *= 2; - b->yy_ch_buf = (char *) - yy_flex_realloc( (void *) b->yy_ch_buf, - b->yy_buf_size ); + b->yy_ch_buf = (char *) + /* Include room in for 2 EOB chars. */ + yy_flex_realloc( (void *) b->yy_ch_buf, + b->yy_buf_size + 2 ); + } + else + /* Can't grow it, we don't own it. */ + b->yy_ch_buf = 0; if ( ! b->yy_ch_buf ) YY_FATAL_ERROR( @@ -709,7 +842,7 @@ int yyFlexLexer::yy_get_next_buffer() if ( yy_n_chars == 0 ) { - if ( number_to_move - YY_MORE_ADJ == 1 ) + if ( number_to_move == YY_MORE_ADJ ) { ret_val = EOB_ACT_END_OF_FILE; yyrestart( yyin ); @@ -730,13 +863,7 @@ int yyFlexLexer::yy_get_next_buffer() yy_current_buffer->yy_ch_buf[yy_n_chars] = YY_END_OF_BUFFER_CHAR; yy_current_buffer->yy_ch_buf[yy_n_chars + 1] = YY_END_OF_BUFFER_CHAR; - /* yytext begins at the second character in yy_ch_buf; the first - * character is the one which preceded it before reading in the latest - * buffer; it needs to be kept around in case it's a newline, so - * yy_get_previous_state() will have with '^' rules active. - */ - - yytext_ptr = &yy_current_buffer->yy_ch_buf[1]; + yytext_ptr = &yy_current_buffer->yy_ch_buf[0]; return ret_val; } @@ -789,6 +916,7 @@ yy_state_type yyFlexLexer::yy_try_NUL_trans( yy_state_type yy_current_state ) %- +#ifndef YY_NO_UNPUT #ifdef YY_USE_PROTOS static void yyunput( int c, register char *yy_bp ) #else @@ -817,26 +945,25 @@ void yyFlexLexer::yyunput( int c, register char* yy_bp ) while ( source > yy_current_buffer->yy_ch_buf ) *--dest = *--source; - yy_cp += dest - source; - yy_bp += dest - source; + yy_cp += (int) (dest - source); + yy_bp += (int) (dest - source); yy_n_chars = yy_current_buffer->yy_buf_size; if ( yy_cp < yy_current_buffer->yy_ch_buf + 2 ) YY_FATAL_ERROR( "flex scanner push-back overflow" ); } - if ( yy_cp > yy_bp && yy_cp[-1] == '\n' ) - yy_cp[-2] = '\n'; - *--yy_cp = (char) c; -%% update yylineno here, if doing -l +%% update yylineno here - /* Note: the formal parameter *must* be called "yy_bp" for this - * macro to now work correctly. - */ - YY_DO_BEFORE_ACTION; /* set up yytext again */ + yytext_ptr = yy_bp; + yy_hold_char = *yy_cp; + yy_c_buf_p = yy_cp; } +%- +#endif /* ifndef YY_NO_UNPUT */ +%* %- @@ -865,7 +992,7 @@ int yyFlexLexer::yyinput() else { /* need more input */ - yytext_ptr = yy_c_buf_p; + int offset = yy_c_buf_p - yytext_ptr; ++yy_c_buf_p; switch ( yy_get_next_buffer() ) @@ -874,12 +1001,12 @@ int yyFlexLexer::yyinput() { if ( yywrap() ) { - yy_c_buf_p = - yytext_ptr + YY_MORE_ADJ; + yy_c_buf_p = yytext_ptr + offset; return EOF; } - YY_NEW_FILE; + if ( ! yy_did_buffer_switch_on_eof ) + YY_NEW_FILE; #ifdef __cplusplus return yyinput(); #else @@ -888,7 +1015,7 @@ int yyFlexLexer::yyinput() } case EOB_ACT_CONTINUE_SCAN: - yy_c_buf_p = yytext_ptr + YY_MORE_ADJ; + yy_c_buf_p = yytext_ptr + offset; break; case EOB_ACT_LAST_MATCH: @@ -907,6 +1034,8 @@ int yyFlexLexer::yyinput() *yy_c_buf_p = '\0'; /* preserve yytext */ yy_hold_char = *++yy_c_buf_p; +%% update BOL and yylineno + return c; } @@ -996,7 +1125,6 @@ YY_BUFFER_STATE yyFlexLexer::yy_create_buffer( istream* file, int size ) YY_BUFFER_STATE b; b = (YY_BUFFER_STATE) yy_flex_alloc( sizeof( struct yy_buffer_state ) ); - if ( ! b ) YY_FATAL_ERROR( "out of dynamic memory in yy_create_buffer()" ); @@ -1006,10 +1134,11 @@ YY_BUFFER_STATE yyFlexLexer::yy_create_buffer( istream* file, int size ) * we need to put in 2 end-of-buffer characters. */ b->yy_ch_buf = (char *) yy_flex_alloc( b->yy_buf_size + 2 ); - if ( ! b->yy_ch_buf ) YY_FATAL_ERROR( "out of dynamic memory in yy_create_buffer()" ); + b->yy_is_our_buffer = 1; + yy_init_buffer( b, file ); return b; @@ -1027,15 +1156,26 @@ YY_BUFFER_STATE b; void yyFlexLexer::yy_delete_buffer( YY_BUFFER_STATE b ) %* { + if ( ! b ) + return; + if ( b == yy_current_buffer ) yy_current_buffer = (YY_BUFFER_STATE) 0; - yy_flex_free( (void *) b->yy_ch_buf ); + if ( b->yy_is_our_buffer ) + yy_flex_free( (void *) b->yy_ch_buf ); + yy_flex_free( (void *) b ); } %- +#ifndef YY_ALWAYS_INTERACTIVE +#ifndef YY_NEVER_INTERACTIVE +extern int isatty YY_PROTO(( int )); +#endif +#endif + #ifdef YY_USE_PROTOS void yy_init_buffer( YY_BUFFER_STATE b, FILE *file ) #else @@ -1043,40 +1183,167 @@ void yy_init_buffer( b, file ) YY_BUFFER_STATE b; FILE *file; #endif + %+ +extern "C" int isatty YY_PROTO(( int )); void yyFlexLexer::yy_init_buffer( YY_BUFFER_STATE b, istream* file ) %* + { + yy_flush_buffer( b ); + b->yy_input_file = file; + b->yy_fill_buffer = 1; - /* We put in the '\n' and start reading from [1] so that an - * initial match-at-newline will be true. - */ +%- +#if YY_ALWAYS_INTERACTIVE + b->yy_is_interactive = 1; +#else +#if YY_NEVER_INTERACTIVE + b->yy_is_interactive = 0; +#else + b->yy_is_interactive = file ? (isatty( fileno(file) ) > 0) : 0; +#endif +#endif +%+ + b->yy_is_interactive = 0; +%* + } - b->yy_ch_buf[0] = '\n'; - b->yy_n_chars = 1; + +%- +#ifdef YY_USE_PROTOS +void yy_flush_buffer( YY_BUFFER_STATE b ) +#else +void yy_flush_buffer( b ) +YY_BUFFER_STATE b; +#endif + +%+ +void yyFlexLexer::yy_flush_buffer( YY_BUFFER_STATE b ) +%* + { + b->yy_n_chars = 0; /* We always need two end-of-buffer characters. The first causes * a transition to the end-of-buffer state. The second causes * a jam in that state. */ + b->yy_ch_buf[0] = YY_END_OF_BUFFER_CHAR; b->yy_ch_buf[1] = YY_END_OF_BUFFER_CHAR; - b->yy_ch_buf[2] = YY_END_OF_BUFFER_CHAR; - b->yy_buf_pos = &b->yy_ch_buf[1]; + b->yy_buf_pos = &b->yy_ch_buf[0]; + + b->yy_at_bol = 1; + b->yy_buffer_status = YY_BUFFER_NEW; + if ( b == yy_current_buffer ) + yy_load_buffer_state(); + } +%* + + +#ifndef YY_NO_SCAN_BUFFER %- - b->yy_is_interactive = file ? isatty( fileno(file) ) : 0; -%+ +#ifdef YY_USE_PROTOS +YY_BUFFER_STATE yy_scan_buffer( char *base, yy_size_t size ) +#else +YY_BUFFER_STATE yy_scan_buffer( base, size ) +char *base; +yy_size_t size; +#endif + { + YY_BUFFER_STATE b; + + if ( size < 2 || + base[size-2] != YY_END_OF_BUFFER_CHAR || + base[size-1] != YY_END_OF_BUFFER_CHAR ) + /* They forgot to leave room for the EOB's. */ + return 0; + + b = (YY_BUFFER_STATE) yy_flex_alloc( sizeof( struct yy_buffer_state ) ); + if ( ! b ) + YY_FATAL_ERROR( "out of dynamic memory in yy_scan_buffer()" ); + + b->yy_buf_size = size - 2; /* "- 2" to take care of EOB's */ + b->yy_buf_pos = b->yy_ch_buf = base; + b->yy_is_our_buffer = 0; + b->yy_input_file = 0; + b->yy_n_chars = b->yy_buf_size; b->yy_is_interactive = 0; + b->yy_at_bol = 1; + b->yy_fill_buffer = 0; + b->yy_buffer_status = YY_BUFFER_NEW; + + yy_switch_to_buffer( b ); + + return b; + } %* +#endif - b->yy_fill_buffer = 1; - b->yy_buffer_status = YY_BUFFER_NEW; +#ifndef YY_NO_SCAN_STRING +%- +#ifdef YY_USE_PROTOS +YY_BUFFER_STATE yy_scan_string( yyconst char *str ) +#else +YY_BUFFER_STATE yy_scan_string( str ) +yyconst char *str; +#endif + { + int len; + for ( len = 0; str[len]; ++len ) + ; + + return yy_scan_bytes( str, len ); } +%* +#endif +#ifndef YY_NO_SCAN_BYTES +%- +#ifdef YY_USE_PROTOS +YY_BUFFER_STATE yy_scan_bytes( yyconst char *bytes, int len ) +#else +YY_BUFFER_STATE yy_scan_bytes( bytes, len ) +yyconst char *bytes; +int len; +#endif + { + YY_BUFFER_STATE b; + char *buf; + yy_size_t n; + int i; + + /* Get memory for full buffer, including space for trailing EOB's. */ + n = len + 2; + buf = (char *) yy_flex_alloc( n ); + if ( ! buf ) + YY_FATAL_ERROR( "out of dynamic memory in yy_scan_bytes()" ); + + for ( i = 0; i < len; ++i ) + buf[i] = bytes[i]; + + buf[len] = buf[len+1] = YY_END_OF_BUFFER_CHAR; + + b = yy_scan_buffer( buf, n ); + if ( ! b ) + YY_FATAL_ERROR( "bad buffer in yy_scan_bytes()" ); + + /* It's okay to grow etc. this buffer, and we should throw it + * away when we're done. + */ + b->yy_is_our_buffer = 1; + + return b; + } +%* +#endif + + +#ifndef YY_NO_PUSH_STATE %- #ifdef YY_USE_PROTOS static void yy_push_state( int new_state ) @@ -1090,7 +1357,7 @@ void yyFlexLexer::yy_push_state( int new_state ) { if ( yy_start_stack_ptr >= yy_start_stack_depth ) { - int new_size; + yy_size_t new_size; yy_start_stack_depth += YY_START_STACK_INCR; new_size = yy_start_stack_depth * sizeof( int ); @@ -1111,8 +1378,10 @@ void yyFlexLexer::yy_push_state( int new_state ) BEGIN(new_state); } +#endif +#ifndef YY_NO_POP_STATE %- static void yy_pop_state() %+ @@ -1124,8 +1393,10 @@ void yyFlexLexer::yy_pop_state() BEGIN(yy_start_stack[yy_start_stack_ptr]); } +#endif +#ifndef YY_NO_TOP_STATE %- static int yy_top_state() %+ @@ -1134,26 +1405,30 @@ int yyFlexLexer::yy_top_state() { return yy_start_stack[yy_start_stack_ptr - 1]; } +#endif +#ifndef YY_EXIT_FAILURE +#define YY_EXIT_FAILURE 2 +#endif %- #ifdef YY_USE_PROTOS -static void yy_fatal_error( const char msg[] ) +static void yy_fatal_error( yyconst char msg[] ) #else static void yy_fatal_error( msg ) char msg[]; #endif { (void) fprintf( stderr, "%s\n", msg ); - exit( 1 ); + exit( YY_EXIT_FAILURE ); } %+ -void yyFlexLexer::LexerError( const char msg[] ) +void yyFlexLexer::LexerError( yyconst char msg[] ) { cerr << msg << '\n'; - exit( 1 ); + exit( YY_EXIT_FAILURE ); } %* @@ -1166,7 +1441,7 @@ void yyFlexLexer::LexerError( const char msg[] ) { \ /* Undo effects of setting up yytext. */ \ yytext[yyleng] = yy_hold_char; \ - yy_c_buf_p = yytext + n - YY_MORE_ADJ; \ + yy_c_buf_p = yytext + n; \ yy_hold_char = *yy_c_buf_p; \ *yy_c_buf_p = '\0'; \ yyleng = n; \ @@ -1178,11 +1453,11 @@ void yyFlexLexer::LexerError( const char msg[] ) #ifndef yytext_ptr #ifdef YY_USE_PROTOS -static void yy_flex_strncpy( char *s1, const char *s2, int n ) +static void yy_flex_strncpy( char *s1, yyconst char *s2, int n ) #else static void yy_flex_strncpy( s1, s2, n ) char *s1; -const char *s2; +yyconst char *s2; int n; #endif { @@ -1192,26 +1467,49 @@ int n; } #endif +#ifdef YY_NEED_STRLEN +#ifdef YY_USE_PROTOS +static int yy_flex_strlen( yyconst char *s ) +#else +static int yy_flex_strlen( s ) +yyconst char *s; +#endif + { + register int n; + for ( n = 0; s[n]; ++n ) + ; + + return n; + } +#endif + #ifdef YY_USE_PROTOS -static void *yy_flex_alloc( unsigned int size ) +static void *yy_flex_alloc( yy_size_t size ) #else static void *yy_flex_alloc( size ) -unsigned int size; +yy_size_t size; #endif { return (void *) malloc( size ); } #ifdef YY_USE_PROTOS -static void *yy_flex_realloc( void *ptr, unsigned int size ) +static void *yy_flex_realloc( void *ptr, yy_size_t size ) #else static void *yy_flex_realloc( ptr, size ) void *ptr; -unsigned int size; +yy_size_t size; #endif { - return (void *) realloc( ptr, size ); + /* The cast to (char *) in the following accommodates both + * implementations that use char* generic pointers, and those + * that use void* generic pointers. It works with the latter + * because both ANSI C and C++ allow castless assignment from + * any pointer type to void*, and deal with argument conversions + * as though doing an assignment. + */ + return (void *) realloc( (char *) ptr, size ); } #ifdef YY_USE_PROTOS @@ -1223,3 +1521,11 @@ void *ptr; { free( ptr ); } + +#if YY_MAIN +int main() + { + yylex(); + return 0; + } +#endif diff --git a/usr.bin/lex/lib/libmain.c b/usr.bin/lex/lib/libmain.c index a893c7a..6c43b08 100644 --- a/usr.bin/lex/lib/libmain.c +++ b/usr.bin/lex/lib/libmain.c @@ -1,6 +1,6 @@ /* libmain - flex run-time support library "main" function */ -/* $Header: /home/daffy/u0/vern/flex/RCS/libmain.c,v 1.3 93/04/14 22:41:55 vern Exp $ */ +/* $Header: /home/daffy/u0/vern/flex/RCS/libmain.c,v 1.4 95/09/27 12:47:55 vern Exp $ */ extern int yylex(); @@ -8,5 +8,8 @@ int main( argc, argv ) int argc; char *argv[]; { - return yylex(); + while ( yylex() != 0 ) + ; + + return 0; } diff --git a/usr.bin/lex/mkskel.sh b/usr.bin/lex/mkskel.sh index ffc7c7f..a03a11a 100755 --- a/usr.bin/lex/mkskel.sh +++ b/usr.bin/lex/mkskel.sh @@ -1,11 +1,11 @@ #! /bin/sh cat <<! -/* File created from flex.skel via mkskel.sh */ +/* File created from flex.skl via mkskel.sh */ #include "flexdef.h" -char *skel[] = { +const char *skel[] = { ! sed 's/\\/&&/g' $* | sed 's/"/\\"/g' | sed 's/.*/ "&",/' diff --git a/usr.bin/lex/parse.y b/usr.bin/lex/parse.y index c14f245..8dbd125 100644 --- a/usr.bin/lex/parse.y +++ b/usr.bin/lex/parse.y @@ -1,6 +1,10 @@ /* parse.y - parser for flex input */ -%token CHAR NUMBER SECTEND SCDECL XSCDECL WHITESPACE NAME PREVCCL EOF_OP +%token CHAR NUMBER SECTEND SCDECL XSCDECL NAME PREVCCL EOF_OP +%token OPTION_OP OPT_OUTFILE OPT_PREFIX OPT_YYCLASS + +%token CCE_ALNUM CCE_ALPHA CCE_BLANK CCE_CNTRL CCE_DIGIT CCE_GRAPH +%token CCE_LOWER CCE_PRINT CCE_PUNCT CCE_SPACE CCE_UPPER CCE_XDIGIT %{ /*- @@ -29,7 +33,7 @@ * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. */ -/* $Header: /home/daffy/u0/vern/flex/RCS/parse.y,v 2.15 93/12/09 13:57:23 vern Exp $ */ +/* $Header: /home/daffy/u0/vern/flex/RCS/parse.y,v 2.28 95/04/21 11:51:51 vern Exp $ */ /* Some versions of bison are broken in that they use alloca() but don't @@ -37,37 +41,63 @@ * #ifdef chud to fix the problem, courtesy of Francois Pinard. */ #ifdef YYBISON -/* AIX requires this to be the first thing in the file. */ -#ifdef __GNUC__ -#define alloca __builtin_alloca -#else /* not __GNUC__ */ -#if HAVE_ALLOCA_H -#include <alloca.h> -#else /* not HAVE_ALLOCA_H */ -#ifdef _AIX +/* AIX requires this to be the first thing in the file. What a piece. */ +# ifdef _AIX #pragma alloca -#else /* not _AIX */ +# endif +#endif + +#include "flexdef.h" + +/* The remainder of the alloca() cruft has to come after including flexdef.h, + * so HAVE_ALLOCA_H is (possibly) defined. + */ +#ifdef YYBISON +# ifdef __GNUC__ +# ifndef alloca +# define alloca __builtin_alloca +# endif +# else +# if HAVE_ALLOCA_H +# include <alloca.h> +# else +# ifdef __hpux +void *alloca (); +# else +# ifdef __TURBOC__ +# include <malloc.h> +# else char *alloca (); -#endif /* not _AIX */ -#endif /* not HAVE_ALLOCA_H */ -#endif /* not __GNUC__ */ -#endif /* YYBISON */ +# endif +# endif +# endif +# endif +#endif /* Bletch, ^^^^ that was ugly! */ -#include "flexdef.h" +int pat, scnum, eps, headcnt, trailcnt, anyccl, lastchar, i, rulelen; +int trlcontxt, xcluflg, currccl, cclsorted, varlength, variable_trail_rule; -int pat, scnum, eps, headcnt, trailcnt, anyccl, lastchar, i, actvp, rulelen; -int trlcontxt, xcluflg, cclsorted, varlength, variable_trail_rule; -int *active_ss; -Char clower(); -void build_eof_action(); -void yyerror(); +int *scon_stk; +int scon_stk_ptr; static int madeany = false; /* whether we've made the '.' character class */ int previous_continued_action; /* whether the previous rule's action was '|' */ +/* Expand a POSIX character class expression. */ +#define CCL_EXPR(func) \ + { \ + int c; \ + for ( c = 0; c < csize; ++c ) \ + if ( isascii(c) && func(c) ) \ + ccladd( currccl, c ); \ + } + +/* While POSIX defines isblank(), it's not ANSI C. */ +#define IS_BLANK(c) ((c) == ' ' || (c) == '\t') + /* On some over-ambitious machines, such as DEC Alpha's, the default * token type is "long" instead of "int"; this leads to problems with * declaring yylval in flexdef.h. But so far, all the yacc's I've seen @@ -113,30 +143,21 @@ initlex : /* Create default DFA start condition. */ scinstal( "INITIAL", false ); - - /* Initially, the start condition scoping is - * "no start conditions active". - */ - actvp = 0; } ; -sect1 : sect1 startconddecl WHITESPACE namelist1 '\n' +sect1 : sect1 startconddecl namelist1 + | sect1 options | - | error '\n' + | error { synerr( "unknown error processing section 1" ); } ; sect1end : SECTEND { - /* We now know how many start conditions there - * are, so create the "activity" map indicating - * which conditions are active. - */ - active_ss = allocate_integer_array( lastsc + 1 ); - - for ( i = 1; i <= lastsc; ++i ) - active_ss[i] = 0; + check_options(); + scon_stk = allocate_integer_array( lastsc + 1 ); + scon_stk_ptr = 0; } ; @@ -147,7 +168,7 @@ startconddecl : SCDECL { xcluflg = true; } ; -namelist1 : namelist1 WHITESPACE NAME +namelist1 : namelist1 NAME { scinstal( nmstr, xcluflg ); } | NAME @@ -157,7 +178,28 @@ namelist1 : namelist1 WHITESPACE NAME { synerr( "bad start condition list" ); } ; -sect2 : sect2 initforrule flexrule '\n' +options : OPTION_OP optionlist + ; + +optionlist : optionlist option + | + ; + +option : OPT_OUTFILE '=' NAME + { + outfilename = copy_string( nmstr ); + did_outfilename = 1; + } + | OPT_PREFIX '=' NAME + { prefix = copy_string( nmstr ); } + | OPT_YYCLASS '=' NAME + { yyclass = copy_string( nmstr ); } + ; + +sect2 : sect2 scon initforrule flexrule '\n' + { scon_stk_ptr = $2; } + | sect2 scon '{' sect2 '}' + { scon_stk_ptr = $2; } | ; @@ -168,54 +210,37 @@ initforrule : trailcnt = headcnt = rulelen = 0; current_state_type = STATE_NORMAL; previous_continued_action = continued_action; + in_rule = true; + new_rule(); } ; -flexrule : scon '^' rule +flexrule : '^' rule { - pat = $3; + pat = $2; finish_rule( pat, variable_trail_rule, headcnt, trailcnt ); - for ( i = 1; i <= actvp; ++i ) - scbol[actvsc[i]] = - mkbranch( scbol[actvsc[i]], pat ); - - if ( ! bol_needed ) + if ( scon_stk_ptr > 0 ) { - bol_needed = true; - - if ( performance_report > 1 ) - pinpoint_message( - "'^' operator results in sub-optimal performance" ); + for ( i = 1; i <= scon_stk_ptr; ++i ) + scbol[scon_stk[i]] = + mkbranch( scbol[scon_stk[i]], + pat ); } - } - - | scon rule - { - pat = $2; - finish_rule( pat, variable_trail_rule, - headcnt, trailcnt ); - for ( i = 1; i <= actvp; ++i ) - scset[actvsc[i]] = - mkbranch( scset[actvsc[i]], pat ); - } - - | '^' rule - { - pat = $2; - finish_rule( pat, variable_trail_rule, - headcnt, trailcnt ); - - /* Add to all non-exclusive start conditions, - * including the default (0) start condition. - */ + else + { + /* Add to all non-exclusive start conditions, + * including the default (0) start condition. + */ - for ( i = 1; i <= lastsc; ++i ) - if ( ! scxclu[i] ) - scbol[i] = mkbranch( scbol[i], pat ); + for ( i = 1; i <= lastsc; ++i ) + if ( ! scxclu[i] ) + scbol[i] = mkbranch( scbol[i], + pat ); + } if ( ! bol_needed ) { @@ -233,51 +258,82 @@ flexrule : scon '^' rule finish_rule( pat, variable_trail_rule, headcnt, trailcnt ); - for ( i = 1; i <= lastsc; ++i ) - if ( ! scxclu[i] ) - scset[i] = mkbranch( scset[i], pat ); - } + if ( scon_stk_ptr > 0 ) + { + for ( i = 1; i <= scon_stk_ptr; ++i ) + scset[scon_stk[i]] = + mkbranch( scset[scon_stk[i]], + pat ); + } - | scon EOF_OP - { build_eof_action(); } + else + { + for ( i = 1; i <= lastsc; ++i ) + if ( ! scxclu[i] ) + scset[i] = + mkbranch( scset[i], + pat ); + } + } | EOF_OP { - /* This EOF applies to all start conditions - * which don't already have EOF actions. - */ - actvp = 0; - - for ( i = 1; i <= lastsc; ++i ) - if ( ! sceof[i] ) - actvsc[++actvp] = i; + if ( scon_stk_ptr > 0 ) + build_eof_action(); + + else + { + /* This EOF applies to all start conditions + * which don't already have EOF actions. + */ + for ( i = 1; i <= lastsc; ++i ) + if ( ! sceof[i] ) + scon_stk[++scon_stk_ptr] = i; - if ( actvp == 0 ) - warn( + if ( scon_stk_ptr == 0 ) + warn( "all start conditions already have <<EOF>> rules" ); - else - build_eof_action(); + else + build_eof_action(); + } } | error { synerr( "unrecognized rule" ); } ; -scon : '<' namelist2 '>' +scon_stk_ptr : + { $$ = scon_stk_ptr; } + ; + +scon : '<' scon_stk_ptr namelist2 '>' + { $$ = $2; } | '<' '*' '>' { - actvp = 0; + $$ = scon_stk_ptr; for ( i = 1; i <= lastsc; ++i ) - actvsc[++actvp] = i; + { + int j; + + for ( j = 1; j <= scon_stk_ptr; ++j ) + if ( scon_stk[j] == i ) + break; + + if ( j > scon_stk_ptr ) + scon_stk[++scon_stk_ptr] = i; + } } + + | + { $$ = scon_stk_ptr; } ; namelist2 : namelist2 ',' sconname - | { actvp = 0; } sconname + | sconname | error { synerr( "bad start condition list" ); } @@ -291,15 +347,17 @@ sconname : NAME nmstr ); else { - if ( ++actvp >= current_max_scs ) - /* Some bozo has included multiple - * instances of start condition names. - */ - pinpoint_message( - "too many start conditions in <> construct!" ); + for ( i = 1; i <= scon_stk_ptr; ++i ) + if ( scon_stk[i] == scnum ) + { + format_warn( + "<%s> specified twice", + scname[scnum] ); + break; + } - else - actvsc[actvp] = scnum; + if ( i > scon_stk_ptr ) + scon_stk[++scon_stk_ptr] = scnum; } } ; @@ -666,14 +724,40 @@ ccl : ccl CHAR '-' CHAR $$ = $1; } + | ccl ccl_expr + { + /* Too hard to properly maintain cclsorted. */ + cclsorted = false; + $$ = $1; + } + | { cclsorted = true; lastchar = 0; - $$ = cclinit(); + currccl = $$ = cclinit(); } ; +ccl_expr: CCE_ALNUM { CCL_EXPR(isalnum) } + | CCE_ALPHA { CCL_EXPR(isalpha) } + | CCE_BLANK { CCL_EXPR(IS_BLANK) } + | CCE_CNTRL { CCL_EXPR(iscntrl) } + | CCE_DIGIT { CCL_EXPR(isdigit) } + | CCE_GRAPH { CCL_EXPR(isgraph) } + | CCE_LOWER { CCL_EXPR(islower) } + | CCE_PRINT { CCL_EXPR(isprint) } + | CCE_PUNCT { CCL_EXPR(ispunct) } + | CCE_SPACE { CCL_EXPR(isspace) } + | CCE_UPPER { + if ( caseins ) + CCL_EXPR(islower) + else + CCL_EXPR(isupper) + } + | CCE_XDIGIT { CCL_EXPR(isxdigit) } + ; + string : string CHAR { if ( caseins && $2 >= 'A' && $2 <= 'Z' ) @@ -700,23 +784,23 @@ void build_eof_action() register int i; char action_text[MAXLINE]; - for ( i = 1; i <= actvp; ++i ) + for ( i = 1; i <= scon_stk_ptr; ++i ) { - if ( sceof[actvsc[i]] ) + if ( sceof[scon_stk[i]] ) format_pinpoint_message( "multiple <<EOF>> rules for start condition %s", - scname[actvsc[i]] ); + scname[scon_stk[i]] ); else { - sceof[actvsc[i]] = true; + sceof[scon_stk[i]] = true; sprintf( action_text, "case YY_STATE_EOF(%s):\n", - scname[actvsc[i]] ); + scname[scon_stk[i]] ); add_action( action_text ); } } - line_directive_out( (FILE *) 0 ); + line_directive_out( (FILE *) 0, 1 ); /* This isn't a normal rule after all - don't count it as * such, so we don't have any holes in the rule numbering @@ -750,6 +834,18 @@ char str[]; } +/* format_warn - write out formatted warning */ + +void format_warn( msg, arg ) +char msg[], arg[]; + { + char warn_msg[MAXLINE]; + + (void) sprintf( warn_msg, msg, arg ); + warn( warn_msg ); + } + + /* warn - report a warning, unless -w was given */ void warn( str ) diff --git a/usr.bin/lex/scan.l b/usr.bin/lex/scan.l index 74b589c..73caab4 100644 --- a/usr.bin/lex/scan.l +++ b/usr.bin/lex/scan.l @@ -27,12 +27,18 @@ * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. */ -/* $Header: scan.l,v 1.2 94/01/04 14:33:09 vern Exp $ */ +/* $Header: /home/daffy/u0/vern/flex/RCS/scan.l,v 2.56 95/04/24 12:17:19 vern Exp $ */ #include "flexdef.h" #include "parse.h" #define ACTION_ECHO add_action( yytext ) +#define ACTION_IFDEF(def, should_define) \ + { \ + if ( should_define ) \ + action_define( def, 1 ); \ + } + #define MARK_END_OF_PROLOG mark_prolog(); #define YY_DECL \ @@ -59,118 +65,125 @@ yymore_used = true; %} +%option caseless nodefault outfile="scan.c" stack noyy_top_state +%option nostdinit + %x SECT2 SECT2PROLOG SECT3 CODEBLOCK PICKUPDEF SC CARETISBOL NUM QUOTE -%x FIRSTCCL CCL ACTION RECOVER BRACEERROR C_COMMENT ACTION_COMMENT -%x ACTION_STRING PERCENT_BRACE_ACTION USED_LIST CODEBLOCK_2 +%x FIRSTCCL CCL ACTION RECOVER COMMENT ACTION_STRING PERCENT_BRACE_ACTION +%x OPTION LINEDIR -WS [ \t]+ -OPTWS [ \t]* -NOT_WS [^ \t\n] +WS [[:blank:]]+ +OPTWS [[:blank:]]* +NOT_WS [^[:blank:]\n] -NL (\n|\r\n|\n\r) +NL \r?\n -NAME ([a-z_][a-z_0-9-]*) -NOT_NAME [^a-z_*\n]+ +NAME ([[:alpha:]_][[:alnum:]_-]*) +NOT_NAME [^[:alpha:]_*\n]+ SCNAME {NAME} -ESCSEQ (\\([^\n]|[0-9]{1,3}|x[0-9a-f]{1,2})) +ESCSEQ (\\([^\n]|[0-7]{1,3}|x[[:xdigit:]]{1,2})) FIRST_CCL_CHAR ([^\\\n]|{ESCSEQ}) CCL_CHAR ([^\\\n\]]|{ESCSEQ}) +CCL_EXPR ("[:"[[:alpha:]]+":]") + +LEXOPT [aceknopr] %% - static int bracelevel, didadef, indented_code, checking_used; + static int bracelevel, didadef, indented_code; + static int doing_rule_action = false; + static int option_sense; int doing_codeblock = false; int i; Char nmdef[MAXLINE], myesc(); -^{WS} indented_code = true; BEGIN(CODEBLOCK); -^"/*" ACTION_ECHO; BEGIN(C_COMMENT); -^"%s"{NAME}? return SCDECL; -^"%x"{NAME}? return XSCDECL; -^"%{".*{NL} { +<INITIAL>{ + ^{WS} indented_code = true; BEGIN(CODEBLOCK); + ^"/*" ACTION_ECHO; yy_push_state( COMMENT ); + ^#{OPTWS}line{WS} yy_push_state( LINEDIR ); + ^"%s"{NAME}? return SCDECL; + ^"%x"{NAME}? return XSCDECL; + ^"%{".*{NL} { ++linenum; - line_directive_out( (FILE *) 0 ); + line_directive_out( (FILE *) 0, 1 ); indented_code = false; BEGIN(CODEBLOCK); } -{WS} return WHITESPACE; + {WS} /* discard */ -^"%%".* { + ^"%%".* { sectnum = 2; bracelevel = 0; mark_defs1(); - line_directive_out( (FILE *) 0 ); + line_directive_out( (FILE *) 0, 1 ); BEGIN(SECT2PROLOG); return SECTEND; } -^"%pointer".*{NL} { - if ( lex_compat ) - warn( "%pointer incompatible with -l option" ); - else - yytext_is_array = false; - ++linenum; - } -^"%array".*{NL} { - if ( C_plus_plus ) - warn( "%array incompatible with -+ option" ); - else - yytext_is_array = true; - ++linenum; - } - -^"%used" { - warn( "%used/%unused have been deprecated" ); - checking_used = REALLY_USED; BEGIN(USED_LIST); - } -^"%unused" { - warn( "%used/%unused have been deprecated" ); - checking_used = REALLY_NOT_USED; BEGIN(USED_LIST); - } + ^"%pointer".*{NL} yytext_is_array = false; ++linenum; + ^"%array".*{NL} yytext_is_array = true; ++linenum; + ^"%option" BEGIN(OPTION); return OPTION_OP; -^"%"[aceknopr]{OPTWS}[0-9]*{OPTWS}{NL} ++linenum; /* ignore */ + ^"%"{LEXOPT}{OPTWS}[[:digit:]]*{OPTWS}{NL} ++linenum; /* ignore */ + ^"%"{LEXOPT}{WS}.*{NL} ++linenum; /* ignore */ -^"%"[^sxanpekotcru{}].* synerr( "unrecognized '%' directive" ); + ^"%"[^sxaceknopr{}].* synerr( _( "unrecognized '%' directive" ) ); -^{NAME} { + ^{NAME} { strcpy( nmstr, yytext ); didadef = false; BEGIN(PICKUPDEF); } -{SCNAME} RETURNNAME; -^{OPTWS}{NL} ++linenum; /* allows blank lines in section 1 */ -{OPTWS}{NL} ++linenum; return '\n'; + {SCNAME} RETURNNAME; + ^{OPTWS}{NL} ++linenum; /* allows blank lines in section 1 */ + {OPTWS}{NL} ACTION_ECHO; ++linenum; /* maybe end of comment line */ +} + + +<COMMENT>{ + "*/" ACTION_ECHO; yy_pop_state(); + "*" ACTION_ECHO; + [^*\n]+ ACTION_ECHO; + [^*\n]*{NL} ++linenum; ACTION_ECHO; +} + +<LINEDIR>{ + \n yy_pop_state(); + [[:digit:]]+ linenum = myctoi( yytext ); + \"[^"\n]*\" { + flex_free( (void *) infilename ); + infilename = copy_string( yytext + 1 ); + infilename[strlen( infilename ) - 1] = '\0'; + } + . /* ignore spurious characters */ +} -<C_COMMENT>"*/" ACTION_ECHO; BEGIN(INITIAL); -<C_COMMENT>"*/".*{NL} ++linenum; ACTION_ECHO; BEGIN(INITIAL); -<C_COMMENT>[^*\n]+ ACTION_ECHO; -<C_COMMENT>"*" ACTION_ECHO; -<C_COMMENT>{NL} ++linenum; ACTION_ECHO; +<CODEBLOCK>{ + ^"%}".*{NL} ++linenum; BEGIN(INITIAL); + {NAME}|{NOT_NAME}|. ACTION_ECHO; -<CODEBLOCK>^"%}".*{NL} ++linenum; BEGIN(INITIAL); -<CODEBLOCK>"reject" ACTION_ECHO; CHECK_REJECT(yytext); -<CODEBLOCK>"yymore" ACTION_ECHO; CHECK_YYMORE(yytext); -<CODEBLOCK>{NAME}|{NOT_NAME}|. ACTION_ECHO; -<CODEBLOCK>{NL} { + {NL} { ++linenum; ACTION_ECHO; if ( indented_code ) BEGIN(INITIAL); } +} -<PICKUPDEF>{WS} /* separates name and definition */ +<PICKUPDEF>{ + {WS} /* separates name and definition */ -<PICKUPDEF>{NOT_WS}.* { + {NOT_WS}.* { strcpy( (char *) nmdef, yytext ); /* Skip trailing whitespace. */ @@ -185,44 +198,111 @@ CCL_CHAR ([^\\\n\]]|{ESCSEQ}) didadef = true; } -<PICKUPDEF>{NL} { + {NL} { if ( ! didadef ) - synerr( "incomplete name definition" ); + synerr( _( "incomplete name definition" ) ); BEGIN(INITIAL); ++linenum; } - -<RECOVER>.*{NL} ++linenum; BEGIN(INITIAL); RETURNNAME; - - -<USED_LIST>{NL} ++linenum; BEGIN(INITIAL); -<USED_LIST>{WS} -<USED_LIST>"reject" { - if ( all_upper( yytext ) ) - reject_really_used = checking_used; - else - synerr( - "unrecognized %used/%unused construct" ); +} + + +<OPTION>{ + {NL} ++linenum; BEGIN(INITIAL); + {WS} option_sense = true; + + "=" return '='; + + no option_sense = ! option_sense; + + 7bit csize = option_sense ? 128 : 256; + 8bit csize = option_sense ? 256 : 128; + + align long_align = option_sense; + always-interactive { + action_define( "YY_ALWAYS_INTERACTIVE", option_sense ); + } + array yytext_is_array = option_sense; + backup backing_up_report = option_sense; + batch interactive = ! option_sense; + "c++" C_plus_plus = option_sense; + caseful|case-sensitive caseins = ! option_sense; + caseless|case-insensitive caseins = option_sense; + debug ddebug = option_sense; + default spprdflt = ! option_sense; + ecs useecs = option_sense; + fast { + useecs = usemecs = false; + use_read = fullspd = true; + } + full { + useecs = usemecs = false; + use_read = fulltbl = true; + } + input ACTION_IFDEF("YY_NO_INPUT", ! option_sense); + interactive interactive = option_sense; + lex-compat lex_compat = option_sense; + main { + action_define( "YY_MAIN", option_sense ); + do_yywrap = ! option_sense; + } + meta-ecs usemecs = option_sense; + never-interactive { + action_define( "YY_NEVER_INTERACTIVE", option_sense ); + } + perf-report performance_report += option_sense ? 1 : -1; + pointer yytext_is_array = ! option_sense; + read use_read = option_sense; + reject reject_really_used = option_sense; + stack action_define( "YY_STACK_USED", option_sense ); + stdinit do_stdinit = option_sense; + stdout use_stdout = option_sense; + unput ACTION_IFDEF("YY_NO_UNPUT", ! option_sense); + verbose printstats = option_sense; + warn nowarn = ! option_sense; + yylineno do_yylineno = option_sense; + yymore yymore_really_used = option_sense; + yywrap do_yywrap = option_sense; + + yy_push_state ACTION_IFDEF("YY_NO_PUSH_STATE", ! option_sense); + yy_pop_state ACTION_IFDEF("YY_NO_POP_STATE", ! option_sense); + yy_top_state ACTION_IFDEF("YY_NO_TOP_STATE", ! option_sense); + + yy_scan_buffer ACTION_IFDEF("YY_NO_SCAN_BUFFER", ! option_sense); + yy_scan_bytes ACTION_IFDEF("YY_NO_SCAN_BYTES", ! option_sense); + yy_scan_string ACTION_IFDEF("YY_NO_SCAN_STRING", ! option_sense); + + outfile return OPT_OUTFILE; + prefix return OPT_PREFIX; + yyclass return OPT_YYCLASS; + + \"[^"\n]*\" { + strcpy( nmstr, yytext + 1 ); + nmstr[strlen( nmstr ) - 1] = '\0'; + return NAME; } -<USED_LIST>"yymore" { - if ( all_lower( yytext ) ) - yymore_really_used = checking_used; - else - synerr( - "unrecognized %used/%unused construct" ); + + (([a-mo-z]|n[a-np-z])[[:alpha:]\-+]*)|. { + format_synerr( _( "unrecognized %%option: %s" ), + yytext ); + BEGIN(RECOVER); } -<USED_LIST>{NOT_WS}+ synerr( "unrecognized %used/%unused construct" ); +} +<RECOVER>.*{NL} ++linenum; BEGIN(INITIAL); -<SECT2PROLOG>^"%{".* ++bracelevel; yyless( 2 ); /* eat only %{ */ -<SECT2PROLOG>^"%}".* --bracelevel; yyless( 2 ); /* eat only %} */ -<SECT2PROLOG>^{WS}.* ACTION_ECHO; /* indented code in prolog */ +<SECT2PROLOG>{ + ^"%{".* ++bracelevel; yyless( 2 ); /* eat only %{ */ + ^"%}".* --bracelevel; yyless( 2 ); /* eat only %} */ -<SECT2PROLOG>^{NOT_WS}.* { /* non-indented code */ + ^{WS}.* ACTION_ECHO; /* indented code in prolog */ + + ^{NOT_WS}.* { /* non-indented code */ if ( bracelevel <= 0 ) { /* not in %{ ... %} */ yyless( 0 ); /* put it all back */ + yy_set_bol( 1 ); mark_prolog(); BEGIN(SECT2); } @@ -230,43 +310,55 @@ CCL_CHAR ([^\\\n\]]|{ESCSEQ}) ACTION_ECHO; } -<SECT2PROLOG>.* ACTION_ECHO; -<SECT2PROLOG>{NL} ++linenum; ACTION_ECHO; + .* ACTION_ECHO; + {NL} ++linenum; ACTION_ECHO; -<SECT2PROLOG><<EOF>> { + <<EOF>> { mark_prolog(); sectnum = 0; yyterminate(); /* to stop the parser */ } +} -<SECT2>^{OPTWS}{NL} ++linenum; /* allow blank lines in section 2 */ +<SECT2>{ + ^{OPTWS}{NL} ++linenum; /* allow blank lines in section 2 */ -<SECT2>^({WS}|"%{") { - indented_code = (yytext[0] != '%'); + ^{OPTWS}"%{" { + indented_code = false; doing_codeblock = true; bracelevel = 1; - - if ( indented_code ) - ACTION_ECHO; - - BEGIN(CODEBLOCK_2); + BEGIN(PERCENT_BRACE_ACTION); } -<SECT2>^"<" BEGIN(SC); return '<'; -<SECT2>^"^" return '^'; -<SECT2>\" BEGIN(QUOTE); return '"'; -<SECT2>"{"/[0-9] BEGIN(NUM); return '{'; -<SECT2>"{"[^0-9\n][^}\n]* BEGIN(BRACEERROR); -<SECT2>"$"/([ \t]|{NL}) return '$'; + ^{OPTWS}"<" BEGIN(SC); return '<'; + ^{OPTWS}"^" return '^'; + \" BEGIN(QUOTE); return '"'; + "{"/[[:digit:]] BEGIN(NUM); return '{'; + "$"/([[:blank:]]|{NL}) return '$'; -<SECT2>{WS}"%{" { + {WS}"%{" { bracelevel = 1; BEGIN(PERCENT_BRACE_ACTION); - return '\n'; + + if ( in_rule ) + { + doing_rule_action = true; + in_rule = false; + return '\n'; + } + } + {WS}"|".*{NL} continued_action = true; ++linenum; return '\n'; + + ^{WS}"/*" { + yyless( yyleng - 2 ); /* put back '/', '*' */ + bracelevel = 0; + continued_action = false; + BEGIN(ACTION); } -<SECT2>{WS}"|".*{NL} continued_action = true; ++linenum; return '\n'; -<SECT2>{WS} { + ^{WS} /* allow indented rules */ + + {WS} { /* This rule is separate from the one below because * otherwise we get variable trailing context, so * we can't build the scanner using -{f,F}. @@ -274,26 +366,39 @@ CCL_CHAR ([^\\\n\]]|{ESCSEQ}) bracelevel = 0; continued_action = false; BEGIN(ACTION); - return '\n'; + + if ( in_rule ) + { + doing_rule_action = true; + in_rule = false; + return '\n'; + } } -<SECT2>{OPTWS}{NL} { + {OPTWS}{NL} { bracelevel = 0; continued_action = false; BEGIN(ACTION); unput( '\n' ); /* so <ACTION> sees it */ - return '\n'; + + if ( in_rule ) + { + doing_rule_action = true; + in_rule = false; + return '\n'; + } } -<SECT2>"<<EOF>>" return EOF_OP; + ^{OPTWS}"<<EOF>>" | + "<<EOF>>" return EOF_OP; -<SECT2>^"%%".* { + ^"%%".* { sectnum = 3; BEGIN(SECT3); yyterminate(); /* to stop the parser */ } -<SECT2>"["{FIRST_CCL_CHAR}{CCL_CHAR}* { + "["({FIRST_CCL_CHAR}|{CCL_EXPR})({CCL_CHAR}|{CCL_EXPR})* { int cclval; strcpy( nmstr, yytext ); @@ -301,10 +406,10 @@ CCL_CHAR ([^\\\n\]]|{ESCSEQ}) /* Check to see if we've already encountered this * ccl. */ - if ( (cclval = ccllookup( (Char *) nmstr )) ) + if ( (cclval = ccllookup( (Char *) nmstr )) != 0 ) { if ( input() != ']' ) - synerr( "bad character class" ); + synerr( _( "bad character class" ) ); yylval = cclval; ++cclreuse; @@ -327,15 +432,16 @@ CCL_CHAR ([^\\\n\]]|{ESCSEQ}) } } -<SECT2>"{"{NAME}"}" { + "{"{NAME}"}" { register Char *nmdefptr; Char *ndlookup(); strcpy( nmstr, yytext + 1 ); nmstr[yyleng - 2] = '\0'; /* chop trailing brace */ - if ( ! (nmdefptr = ndlookup( nmstr )) ) - format_synerr( "undefined definition {%s}", + if ( (nmdefptr = ndlookup( nmstr )) == 0 ) + format_synerr( + _( "undefined definition {%s}" ), nmstr ); else @@ -360,157 +466,186 @@ CCL_CHAR ([^\\\n\]]|{ESCSEQ}) } } -<SECT2>[/|*+?.()] return (unsigned char) yytext[0]; -<SECT2>. RETURNCHAR; + [/|*+?.(){}] return (unsigned char) yytext[0]; + . RETURNCHAR; +} -<SC>[,*] return (unsigned char) yytext[0]; -<SC>">" BEGIN(SECT2); return '>'; -<SC>">"/^ BEGIN(CARETISBOL); return '>'; -<SC>{SCNAME} RETURNNAME; -<SC>. { - format_synerr( "bad <start condition>: %s", yytext ); +<SC>{ + [,*] return (unsigned char) yytext[0]; + ">" BEGIN(SECT2); return '>'; + ">"/^ BEGIN(CARETISBOL); return '>'; + {SCNAME} RETURNNAME; + . { + format_synerr( _( "bad <start condition>: %s" ), + yytext ); } +} <CARETISBOL>"^" BEGIN(SECT2); return '^'; -<QUOTE>[^"\n] RETURNCHAR; -<QUOTE>\" BEGIN(SECT2); return '"'; +<QUOTE>{ + [^"\n] RETURNCHAR; + \" BEGIN(SECT2); return '"'; -<QUOTE>{NL} { - synerr( "missing quote" ); + {NL} { + synerr( _( "missing quote" ) ); BEGIN(SECT2); ++linenum; return '"'; } +} -<FIRSTCCL>"^"/[^-\]\n] BEGIN(CCL); return '^'; -<FIRSTCCL>"^"/("-"|"]") return '^'; -<FIRSTCCL>. BEGIN(CCL); RETURNCHAR; +<FIRSTCCL>{ + "^"/[^-\]\n] BEGIN(CCL); return '^'; + "^"/("-"|"]") return '^'; + . BEGIN(CCL); RETURNCHAR; +} -<CCL>-/[^\]\n] return '-'; -<CCL>[^\]\n] RETURNCHAR; -<CCL>"]" BEGIN(SECT2); return ']'; -<CCL>.|{NL} { - synerr( "bad character class" ); +<CCL>{ + -/[^\]\n] return '-'; + [^\]\n] RETURNCHAR; + "]" BEGIN(SECT2); return ']'; + .|{NL} { + synerr( _( "bad character class" ) ); BEGIN(SECT2); return ']'; } - - -<NUM>[0-9]+ { +} + +<FIRSTCCL,CCL>{ + "[:alnum:]" BEGIN(CCL); return CCE_ALNUM; + "[:alpha:]" BEGIN(CCL); return CCE_ALPHA; + "[:blank:]" BEGIN(CCL); return CCE_BLANK; + "[:cntrl:]" BEGIN(CCL); return CCE_CNTRL; + "[:digit:]" BEGIN(CCL); return CCE_DIGIT; + "[:graph:]" BEGIN(CCL); return CCE_GRAPH; + "[:lower:]" BEGIN(CCL); return CCE_LOWER; + "[:print:]" BEGIN(CCL); return CCE_PRINT; + "[:punct:]" BEGIN(CCL); return CCE_PUNCT; + "[:space:]" BEGIN(CCL); return CCE_SPACE; + "[:upper:]" BEGIN(CCL); return CCE_UPPER; + "[:xdigit:]" BEGIN(CCL); return CCE_XDIGIT; + {CCL_EXPR} { + format_synerr( + _( "bad character class expression: %s" ), + yytext ); + BEGIN(CCL); return CCE_ALNUM; + } +} + +<NUM>{ + [[:digit:]]+ { yylval = myctoi( yytext ); return NUMBER; } -<NUM>"," return ','; -<NUM>"}" BEGIN(SECT2); return '}'; + "," return ','; + "}" BEGIN(SECT2); return '}'; -<NUM>. { - synerr( "bad character inside {}'s" ); + . { + synerr( _( "bad character inside {}'s" ) ); BEGIN(SECT2); return '}'; } -<NUM>{NL} { - synerr( "missing }" ); + {NL} { + synerr( _( "missing }" ) ); BEGIN(SECT2); ++linenum; return '}'; } +} -<BRACEERROR>"}" synerr( "bad name in {}'s" ); BEGIN(SECT2); -<BRACEERROR>{NL} synerr( "missing }" ); ++linenum; BEGIN(SECT2); +<PERCENT_BRACE_ACTION>{ + {OPTWS}"%}".* bracelevel = 0; + <ACTION>"/*" ACTION_ECHO; yy_push_state( COMMENT ); -<CODEBLOCK_2>"/*" ACTION_ECHO; BEGIN(ACTION_COMMENT); -<PERCENT_BRACE_ACTION,CODEBLOCK_2>{OPTWS}"%}".* bracelevel = 0; -<PERCENT_BRACE_ACTION,CODEBLOCK_2,ACTION>"reject" { + <CODEBLOCK,ACTION>{ + "reject" { ACTION_ECHO; CHECK_REJECT(yytext); } -<PERCENT_BRACE_ACTION,CODEBLOCK_2,ACTION>"yymore" { + "yymore" { ACTION_ECHO; CHECK_YYMORE(yytext); } -<PERCENT_BRACE_ACTION,CODEBLOCK_2>{NAME}|{NOT_NAME}|. ACTION_ECHO; -<PERCENT_BRACE_ACTION,CODEBLOCK_2>{NL} { + } + + {NAME}|{NOT_NAME}|. ACTION_ECHO; + {NL} { ++linenum; ACTION_ECHO; if ( bracelevel == 0 || (doing_codeblock && indented_code) ) { - if ( ! doing_codeblock ) + if ( doing_rule_action ) add_action( "\tYY_BREAK\n" ); - - doing_codeblock = false; + + doing_rule_action = doing_codeblock = false; BEGIN(SECT2); } } +} /* Reject and YYmore() are checked for above, in PERCENT_BRACE_ACTION */ -<ACTION>"{" ACTION_ECHO; ++bracelevel; -<ACTION>"}" ACTION_ECHO; --bracelevel; -<ACTION>[^a-z_{}"'/\n]+ ACTION_ECHO; -<ACTION>{NAME} ACTION_ECHO; -<ACTION>"/*" ACTION_ECHO; BEGIN(ACTION_COMMENT); -<ACTION>"'"([^'\\\n]|\\.)*"'" ACTION_ECHO; /* character constant */ -<ACTION>\" ACTION_ECHO; BEGIN(ACTION_STRING); -<ACTION>{NL} { +<ACTION>{ + "{" ACTION_ECHO; ++bracelevel; + "}" ACTION_ECHO; --bracelevel; + [^[:alpha:]_{}"'/\n]+ ACTION_ECHO; + {NAME} ACTION_ECHO; + "'"([^'\\\n]|\\.)*"'" ACTION_ECHO; /* character constant */ + \" ACTION_ECHO; BEGIN(ACTION_STRING); + {NL} { ++linenum; ACTION_ECHO; if ( bracelevel == 0 ) { - add_action( "\tYY_BREAK\n" ); + if ( doing_rule_action ) + add_action( "\tYY_BREAK\n" ); + + doing_rule_action = false; BEGIN(SECT2); } } -<ACTION>. ACTION_ECHO; + . ACTION_ECHO; +} -<ACTION_COMMENT>"*/" { - ACTION_ECHO; - if ( doing_codeblock ) - BEGIN(CODEBLOCK_2); - else - BEGIN(ACTION); - } +<ACTION_STRING>{ + [^"\\\n]+ ACTION_ECHO; + \\. ACTION_ECHO; + {NL} ++linenum; ACTION_ECHO; + \" ACTION_ECHO; BEGIN(ACTION); + . ACTION_ECHO; +} -<ACTION_COMMENT>"*" ACTION_ECHO; -<ACTION_COMMENT>[^*\n]+ ACTION_ECHO; -<ACTION_COMMENT>[^*\n]*{NL} ++linenum; ACTION_ECHO; - -<ACTION_STRING>[^"\\\n]+ ACTION_ECHO; -<ACTION_STRING>\\. ACTION_ECHO; -<ACTION_STRING>{NL} ++linenum; ACTION_ECHO; -<ACTION_STRING>\" ACTION_ECHO; BEGIN(ACTION); -<ACTION_STRING>. ACTION_ECHO; - -<ACTION,ACTION_COMMENT,ACTION_STRING><<EOF>> { - synerr( "EOF encountered inside an action" ); +<COMMENT,ACTION,ACTION_STRING><<EOF>> { + synerr( _( "EOF encountered inside an action" ) ); yyterminate(); } -<SECT2,QUOTE,CCL>{ESCSEQ} { +<SECT2,QUOTE,FIRSTCCL,CCL>{ESCSEQ} { yylval = myesc( (Char *) yytext ); - return CHAR; - } -<FIRSTCCL>{ESCSEQ} { - yylval = myesc( (Char *) yytext ); - BEGIN(CCL); + if ( YY_START == FIRSTCCL ) + BEGIN(CCL); + return CHAR; } -<SECT3>.*(\n?) ECHO; -<SECT3><<EOF>> sectnum = 0; yyterminate(); +<SECT3>{ + .*(\n?) ECHO; + <<EOF>> sectnum = 0; yyterminate(); +} -<*>.|\n format_synerr( "bad character: %s", yytext ); +<*>.|\n format_synerr( _( "bad character: %s" ), yytext ); %% @@ -533,40 +668,43 @@ int yywrap() void set_input_file( file ) char *file; { - if ( file ) + if ( file && strcmp( file, "-" ) ) { - infilename = file; + infilename = copy_string( file ); yyin = fopen( infilename, "r" ); if ( yyin == NULL ) - lerrsf( "can't open %s", file ); + lerrsf( _( "can't open %s" ), file ); } else { yyin = stdin; - infilename = "<stdin>"; + infilename = copy_string( "<stdin>" ); } + + linenum = 1; } /* Wrapper routines for accessing the scanner's malloc routines. */ void *flex_alloc( size ) -unsigned int size; +size_t size; { - return yy_flex_alloc( size ); + return (void *) malloc( size ); } void *flex_realloc( ptr, size ) void *ptr; -unsigned int size; +size_t size; { - return yy_flex_realloc( ptr, size ); + return (void *) realloc( ptr, size ); } void flex_free( ptr ) void *ptr; { - yy_flex_free( ptr ); + if ( ptr ) + free( ptr ); } diff --git a/usr.bin/lex/skel.c b/usr.bin/lex/skel.c index 4ab49d1..adf710f 100644 --- a/usr.bin/lex/skel.c +++ b/usr.bin/lex/skel.c @@ -1,15 +1,17 @@ -/* File created from flex.skel via mkskel.sh */ +/* File created from flex.skl via mkskel.sh */ #include "flexdef.h" -char *skel[] = { +const char *skel[] = { "/* A lexical scanner generated by flex */", "", "/* Scanner skeleton version:", - " * $Header: /home/daffy/u0/vern/flex/flex-2.4.7/RCS/flex.skl,v 1.2 94/08/03 11:13:24 vern Exp $", + " * $Header: /home/daffy/u0/vern/flex/RCS/flex.skl,v 2.89 96/05/25 21:02:21 vern Exp $", " */", "", "#define FLEX_SCANNER", + "#define YY_FLEX_MAJOR_VERSION 2", + "#define YY_FLEX_MINOR_VERSION 5", "", "%-", "#include <stdio.h>", @@ -40,7 +42,7 @@ char *skel[] = { "", "#else /* ! __cplusplus */", "", - "#ifdef __STDC__", + "#if __STDC__", "", "#define YY_USE_PROTOS", "#define YY_USE_CONST", @@ -48,16 +50,19 @@ char *skel[] = { "#endif /* __STDC__ */", "#endif /* ! __cplusplus */", "", - "", "#ifdef __TURBOC__", + " #pragma warn -rch", + " #pragma warn -use", + "#include <io.h>", + "#include <stdlib.h>", "#define YY_USE_CONST", + "#define YY_USE_PROTOS", "#endif", "", - "", - "#ifndef YY_USE_CONST", - "#ifndef const", - "#define const", - "#endif", + "#ifdef YY_USE_CONST", + "#define yyconst const", + "#else", + "#define yyconst", "#endif", "", "", @@ -84,16 +89,16 @@ char *skel[] = { "#define BEGIN yy_start = 1 + 2 *", "", "/* Translate the current start state into a value that can be later handed", - " * to BEGIN to return to the state.", + " * to BEGIN to return to the state. The YYSTATE alias is for lex", + " * compatibility.", " */", "#define YY_START ((yy_start - 1) / 2)", + "#define YYSTATE YY_START", "", "/* Action number for EOF rule of a given start state. */", "#define YY_STATE_EOF(state) (YY_END_OF_BUFFER + state + 1)", "", - "/* Special action meaning \"start processing a new file\". Now included", - " * only for backward compatibility with previous versions of flex.", - " */", + "/* Special action meaning \"start processing a new file\". */", "#define YY_NEW_FILE yyrestart( yyin )", "", "#define YY_END_OF_BUFFER_CHAR 0", @@ -108,14 +113,6 @@ char *skel[] = { "extern FILE *yyin, *yyout;", "%*", "", - "#ifdef __cplusplus", - "extern \"C\" {", - "#endif", - " extern int yywrap YY_PROTO(( void ));", - "#ifdef __cplusplus", - " }", - "#endif", - "", "#define EOB_ACT_CONTINUE_SCAN 0", "#define EOB_ACT_END_OF_FILE 1", "#define EOB_ACT_LAST_MATCH 2", @@ -141,6 +138,7 @@ char *skel[] = { " { \\", " /* Undo effects of setting up yytext. */ \\", " *yy_cp = yy_hold_char; \\", + " YY_RESTORE_YY_MORE_OFFSET \\", " yy_c_buf_p = yy_cp = yy_bp + n - YY_MORE_ADJ; \\", " YY_DO_BEFORE_ACTION; /* set up yytext again */ \\", " } \\", @@ -148,6 +146,12 @@ char *skel[] = { "", "#define unput(c) yyunput( c, yytext_ptr )", "", + "/* The following is because we cannot portably get our hands on size_t", + " * (without autoconf's help, which isn't available because we want", + " * flex-generated scanners to compile on their own).", + " */", + "typedef unsigned int yy_size_t;", + "", "", "struct yy_buffer_state", " {", @@ -163,13 +167,19 @@ char *skel[] = { " /* Size of input buffer in bytes, not including room for EOB", " * characters.", " */", - " int yy_buf_size;", + " yy_size_t yy_buf_size;", "", " /* Number of characters read into yy_ch_buf, not including EOB", " * characters.", " */", " int yy_n_chars;", "", + " /* Whether we \"own\" the buffer - i.e., we know we created it,", + " * and can realloc() it to grow it, and should free() it to", + " * delete it.", + " */", + " int yy_is_our_buffer;", + "", " /* Whether this is an \"interactive\" input source; if so, and", " * if we're using stdio for input, then we want to use getc()", " * instead of fread(), to make sure we stop fetching input after", @@ -177,6 +187,12 @@ char *skel[] = { " */", " int yy_is_interactive;", "", + " /* Whether we're considered to be at the beginning of a line.", + " * If so, '^' rules will be active on the next match, otherwise", + " * not.", + " */", + " int yy_at_bol;", + "", " /* Whether to try to fill the input buffer when we reach the", " * end of it.", " */", @@ -228,47 +244,50 @@ char *skel[] = { " */", "static int yy_did_buffer_switch_on_eof;", "", - "static void yyunput YY_PROTO(( int c, char *buf_ptr ));", "void yyrestart YY_PROTO(( FILE *input_file ));", + "", "void yy_switch_to_buffer YY_PROTO(( YY_BUFFER_STATE new_buffer ));", "void yy_load_buffer_state YY_PROTO(( void ));", "YY_BUFFER_STATE yy_create_buffer YY_PROTO(( FILE *file, int size ));", "void yy_delete_buffer YY_PROTO(( YY_BUFFER_STATE b ));", "void yy_init_buffer YY_PROTO(( YY_BUFFER_STATE b, FILE *file ));", + "void yy_flush_buffer YY_PROTO(( YY_BUFFER_STATE b ));", + "#define YY_FLUSH_BUFFER yy_flush_buffer( yy_current_buffer )", "", - "static int yy_start_stack_ptr = 0;", - "static int yy_start_stack_depth = 0;", - "static int *yy_start_stack = 0;", - "static void yy_push_state YY_PROTO(( int new_state ));", - "static void yy_pop_state YY_PROTO(( void ));", - "static int yy_top_state YY_PROTO(( void ));", + "YY_BUFFER_STATE yy_scan_buffer YY_PROTO(( char *base, yy_size_t size ));", + "YY_BUFFER_STATE yy_scan_string YY_PROTO(( yyconst char *str ));", + "YY_BUFFER_STATE yy_scan_bytes YY_PROTO(( yyconst char *bytes, int len ));", "%*", "", - "static void *yy_flex_alloc YY_PROTO(( unsigned int ));", - "static void *yy_flex_realloc YY_PROTO(( void *, unsigned int ));", + "static void *yy_flex_alloc YY_PROTO(( yy_size_t ));", + "static void *yy_flex_realloc YY_PROTO(( void *, yy_size_t ));", "static void yy_flex_free YY_PROTO(( void * ));", "", "#define yy_new_buffer yy_create_buffer", "", - "%% yytext/yyin/yyout/yy_state_type/yylineno etc. def's & init go here", + "#define yy_set_interactive(is_interactive) \\", + " { \\", + " if ( ! yy_current_buffer ) \\", + " yy_current_buffer = yy_create_buffer( yyin, YY_BUF_SIZE ); \\", + " yy_current_buffer->yy_is_interactive = is_interactive; \\", + " }", "", - "#ifndef yytext_ptr", - "static void yy_flex_strncpy YY_PROTO(( char *, const char *, int ));", - "#endif", + "#define yy_set_bol(at_bol) \\", + " { \\", + " if ( ! yy_current_buffer ) \\", + " yy_current_buffer = yy_create_buffer( yyin, YY_BUF_SIZE ); \\", + " yy_current_buffer->yy_at_bol = at_bol; \\", + " }", "", - "%- Standard (non-C++) definition", - "#ifdef __cplusplus", - "static int yyinput YY_PROTO(( void ));", - "#else", - "static int input YY_PROTO(( void ));", - "#endif", - "%*", + "#define YY_AT_BOL() (yy_current_buffer->yy_at_bol)", + "", + "%% yytext/yyin/yyout/yy_state_type/yylineno etc. def's & init go here", "", "%- Standard (non-C++) definition", "static yy_state_type yy_get_previous_state YY_PROTO(( void ));", "static yy_state_type yy_try_NUL_trans YY_PROTO(( yy_state_type current_state ));", "static int yy_get_next_buffer YY_PROTO(( void ));", - "static void yy_fatal_error YY_PROTO(( const char msg[] ));", + "static void yy_fatal_error YY_PROTO(( yyconst char msg[] ));", "%*", "", "/* Done after the current pattern has been matched and before the", @@ -288,6 +307,58 @@ char *skel[] = { " * section 1.", " */", "", + "#ifndef YY_SKIP_YYWRAP", + "#ifdef __cplusplus", + "extern \"C\" int yywrap YY_PROTO(( void ));", + "#else", + "extern int yywrap YY_PROTO(( void ));", + "#endif", + "#endif", + "", + "%-", + "#ifndef YY_NO_UNPUT", + "static void yyunput YY_PROTO(( int c, char *buf_ptr ));", + "#endif", + "%*", + "", + "#ifndef yytext_ptr", + "static void yy_flex_strncpy YY_PROTO(( char *, yyconst char *, int ));", + "#endif", + "", + "#ifdef YY_NEED_STRLEN", + "static int yy_flex_strlen YY_PROTO(( yyconst char * ));", + "#endif", + "", + "#ifndef YY_NO_INPUT", + "%- Standard (non-C++) definition", + "#ifdef __cplusplus", + "static int yyinput YY_PROTO(( void ));", + "#else", + "static int input YY_PROTO(( void ));", + "#endif", + "%*", + "#endif", + "", + "#if YY_STACK_USED", + "static int yy_start_stack_ptr = 0;", + "static int yy_start_stack_depth = 0;", + "static int *yy_start_stack = 0;", + "#ifndef YY_NO_PUSH_STATE", + "static void yy_push_state YY_PROTO(( int new_state ));", + "#endif", + "#ifndef YY_NO_POP_STATE", + "static void yy_pop_state YY_PROTO(( void ));", + "#endif", + "#ifndef YY_NO_TOP_STATE", + "static int yy_top_state YY_PROTO(( void ));", + "#endif", + "", + "#else", + "#define YY_NO_PUSH_STATE 1", + "#define YY_NO_POP_STATE 1", + "#define YY_NO_TOP_STATE 1", + "#endif", + "", "#ifdef YY_MALLOC_DECL", "YY_MALLOC_DECL", "#else", @@ -378,6 +449,8 @@ char *skel[] = { "#define YY_BREAK break;", "#endif", "", + "%% YY_RULE_SETUP definition goes here", + "", "YY_DECL", " {", " register yy_state_type yy_current_state;", @@ -388,6 +461,8 @@ char *skel[] = { "", " if ( yy_init )", " {", + " yy_init = 0;", + "", "#ifdef YY_USER_INIT", " YY_USER_INIT;", "#endif", @@ -409,15 +484,11 @@ char *skel[] = { " yyout = &cout;", "%*", "", - " if ( yy_current_buffer )", - " yy_init_buffer( yy_current_buffer, yyin );", - " else", + " if ( ! yy_current_buffer )", " yy_current_buffer =", " yy_create_buffer( yyin, YY_BUF_SIZE );", "", " yy_load_buffer_state();", - "", - " yy_init = 0;", " }", "", " while ( 1 ) /* loops until end-of-file is reached */", @@ -440,7 +511,7 @@ char *skel[] = { "", " YY_DO_BEFORE_ACTION;", "", - "%% code for yylineno update goes here, if -l option", + "%% code for yylineno update goes here", "", "do_action: /* This label is used only to access EOF actions. */", "", @@ -453,10 +524,11 @@ char *skel[] = { " case YY_END_OF_BUFFER:", " {", " /* Amount of text matched not including the EOB char. */", - " int yy_amount_of_matched_text = yy_cp - yytext_ptr - 1;", + " int yy_amount_of_matched_text = (int) (yy_cp - yytext_ptr) - 1;", "", " /* Undo the effects of YY_DO_BEFORE_ACTION. */", " *yy_cp = yy_hold_char;", + " YY_RESTORE_YY_MORE_OFFSET", "", " if ( yy_current_buffer->yy_buffer_status == YY_BUFFER_NEW )", " {", @@ -579,6 +651,53 @@ char *skel[] = { " } /* end of yylex */", "", "%+", + "yyFlexLexer::yyFlexLexer( istream* arg_yyin, ostream* arg_yyout )", + " {", + " yyin = arg_yyin;", + " yyout = arg_yyout;", + " yy_c_buf_p = 0;", + " yy_init = 1;", + " yy_start = 0;", + " yy_flex_debug = 0;", + " yylineno = 1; // this will only get updated if %option yylineno", + "", + " yy_did_buffer_switch_on_eof = 0;", + "", + " yy_looking_for_trail_begin = 0;", + " yy_more_flag = 0;", + " yy_more_len = 0;", + " yy_more_offset = yy_prev_more_offset = 0;", + "", + " yy_start_stack_ptr = yy_start_stack_depth = 0;", + " yy_start_stack = 0;", + "", + " yy_current_buffer = 0;", + "", + "#ifdef YY_USES_REJECT", + " yy_state_buf = new yy_state_type[YY_BUF_SIZE + 2];", + "#else", + " yy_state_buf = 0;", + "#endif", + " }", + "", + "yyFlexLexer::~yyFlexLexer()", + " {", + " delete yy_state_buf;", + " yy_delete_buffer( yy_current_buffer );", + " }", + "", + "void yyFlexLexer::switch_streams( istream* new_in, ostream* new_out )", + " {", + " if ( new_in )", + " {", + " yy_delete_buffer( yy_current_buffer );", + " yy_switch_to_buffer( yy_create_buffer( new_in, YY_BUF_SIZE ) );", + " }", + "", + " if ( new_out )", + " yyout = new_out;", + " }", + "", "#ifdef YY_INTERACTIVE", "int yyFlexLexer::LexerInput( char* buf, int /* max_size */ )", "#else", @@ -630,7 +749,7 @@ char *skel[] = { "%*", " {", " register char *dest = yy_current_buffer->yy_ch_buf;", - " register char *source = yytext_ptr - 1; /* copy prev. char, too */", + " register char *source = yytext_ptr;", " register int number_to_move, i;", " int ret_val;", "", @@ -642,7 +761,7 @@ char *skel[] = { " { /* Don't try to fill the buffer, so this is an EOF. */", " if ( yy_c_buf_p - yytext_ptr - YY_MORE_ADJ == 1 )", " {", - " /* We matched a singled characater, the EOB, so", + " /* We matched a single character, the EOB, so", " * treat this as a final EOF.", " */", " return EOB_ACT_END_OF_FILE;", @@ -660,7 +779,7 @@ char *skel[] = { " /* Try to read more data. */", "", " /* First move last chars to start of buffer. */", - " number_to_move = yy_c_buf_p - yytext_ptr;", + " number_to_move = (int) (yy_c_buf_p - yytext_ptr) - 1;", "", " for ( i = 0; i < number_to_move; ++i )", " *(dest++) = *(source++);", @@ -686,12 +805,26 @@ char *skel[] = { " /* just a shorter name for the current buffer */", " YY_BUFFER_STATE b = yy_current_buffer;", "", - " int yy_c_buf_p_offset = yy_c_buf_p - b->yy_ch_buf;", + " int yy_c_buf_p_offset =", + " (int) (yy_c_buf_p - b->yy_ch_buf);", + "", + " if ( b->yy_is_our_buffer )", + " {", + " int new_size = b->yy_buf_size * 2;", + "", + " if ( new_size <= 0 )", + " b->yy_buf_size += b->yy_buf_size / 8;", + " else", + " b->yy_buf_size *= 2;", "", - " b->yy_buf_size *= 2;", - " b->yy_ch_buf = (char *)", - " yy_flex_realloc( (void *) b->yy_ch_buf,", - " b->yy_buf_size );", + " b->yy_ch_buf = (char *)", + " /* Include room in for 2 EOB chars. */", + " yy_flex_realloc( (void *) b->yy_ch_buf,", + " b->yy_buf_size + 2 );", + " }", + " else", + " /* Can't grow it, we don't own it. */", + " b->yy_ch_buf = 0;", "", " if ( ! b->yy_ch_buf )", " YY_FATAL_ERROR(", @@ -714,7 +847,7 @@ char *skel[] = { "", " if ( yy_n_chars == 0 )", " {", - " if ( number_to_move - YY_MORE_ADJ == 1 )", + " if ( number_to_move == YY_MORE_ADJ )", " {", " ret_val = EOB_ACT_END_OF_FILE;", " yyrestart( yyin );", @@ -735,13 +868,7 @@ char *skel[] = { " yy_current_buffer->yy_ch_buf[yy_n_chars] = YY_END_OF_BUFFER_CHAR;", " yy_current_buffer->yy_ch_buf[yy_n_chars + 1] = YY_END_OF_BUFFER_CHAR;", "", - " /* yytext begins at the second character in yy_ch_buf; the first", - " * character is the one which preceded it before reading in the latest", - " * buffer; it needs to be kept around in case it's a newline, so", - " * yy_get_previous_state() will have with '^' rules active.", - " */", - "", - " yytext_ptr = &yy_current_buffer->yy_ch_buf[1];", + " yytext_ptr = &yy_current_buffer->yy_ch_buf[0];", "", " return ret_val;", " }", @@ -794,6 +921,7 @@ char *skel[] = { "", "", "%-", + "#ifndef YY_NO_UNPUT", "#ifdef YY_USE_PROTOS", "static void yyunput( int c, register char *yy_bp )", "#else", @@ -822,26 +950,25 @@ char *skel[] = { " while ( source > yy_current_buffer->yy_ch_buf )", " *--dest = *--source;", "", - " yy_cp += dest - source;", - " yy_bp += dest - source;", + " yy_cp += (int) (dest - source);", + " yy_bp += (int) (dest - source);", " yy_n_chars = yy_current_buffer->yy_buf_size;", "", " if ( yy_cp < yy_current_buffer->yy_ch_buf + 2 )", " YY_FATAL_ERROR( \"flex scanner push-back overflow\" );", " }", "", - " if ( yy_cp > yy_bp && yy_cp[-1] == '\\n' )", - " yy_cp[-2] = '\\n';", - "", " *--yy_cp = (char) c;", "", - "%% update yylineno here, if doing -l", + "%% update yylineno here", "", - " /* Note: the formal parameter *must* be called \"yy_bp\" for this", - " * macro to now work correctly.", - " */", - " YY_DO_BEFORE_ACTION; /* set up yytext again */", + " yytext_ptr = yy_bp;", + " yy_hold_char = *yy_cp;", + " yy_c_buf_p = yy_cp;", " }", + "%-", + "#endif /* ifndef YY_NO_UNPUT */", + "%*", "", "", "%-", @@ -870,7 +997,7 @@ char *skel[] = { "", " else", " { /* need more input */", - " yytext_ptr = yy_c_buf_p;", + " int offset = yy_c_buf_p - yytext_ptr;", " ++yy_c_buf_p;", "", " switch ( yy_get_next_buffer() )", @@ -879,12 +1006,12 @@ char *skel[] = { " {", " if ( yywrap() )", " {", - " yy_c_buf_p =", - " yytext_ptr + YY_MORE_ADJ;", + " yy_c_buf_p = yytext_ptr + offset;", " return EOF;", " }", "", - " YY_NEW_FILE;", + " if ( ! yy_did_buffer_switch_on_eof )", + " YY_NEW_FILE;", "#ifdef __cplusplus", " return yyinput();", "#else", @@ -893,7 +1020,7 @@ char *skel[] = { " }", "", " case EOB_ACT_CONTINUE_SCAN:", - " yy_c_buf_p = yytext_ptr + YY_MORE_ADJ;", + " yy_c_buf_p = yytext_ptr + offset;", " break;", "", " case EOB_ACT_LAST_MATCH:", @@ -912,6 +1039,8 @@ char *skel[] = { " *yy_c_buf_p = '\\0'; /* preserve yytext */", " yy_hold_char = *++yy_c_buf_p;", "", + "%% update BOL and yylineno", + "", " return c;", " }", "", @@ -1001,7 +1130,6 @@ char *skel[] = { " YY_BUFFER_STATE b;", "", " b = (YY_BUFFER_STATE) yy_flex_alloc( sizeof( struct yy_buffer_state ) );", - "", " if ( ! b )", " YY_FATAL_ERROR( \"out of dynamic memory in yy_create_buffer()\" );", "", @@ -1011,10 +1139,11 @@ char *skel[] = { " * we need to put in 2 end-of-buffer characters.", " */", " b->yy_ch_buf = (char *) yy_flex_alloc( b->yy_buf_size + 2 );", - "", " if ( ! b->yy_ch_buf )", " YY_FATAL_ERROR( \"out of dynamic memory in yy_create_buffer()\" );", "", + " b->yy_is_our_buffer = 1;", + "", " yy_init_buffer( b, file );", "", " return b;", @@ -1032,15 +1161,26 @@ char *skel[] = { "void yyFlexLexer::yy_delete_buffer( YY_BUFFER_STATE b )", "%*", " {", + " if ( ! b )", + " return;", + "", " if ( b == yy_current_buffer )", " yy_current_buffer = (YY_BUFFER_STATE) 0;", "", - " yy_flex_free( (void *) b->yy_ch_buf );", + " if ( b->yy_is_our_buffer )", + " yy_flex_free( (void *) b->yy_ch_buf );", + "", " yy_flex_free( (void *) b );", " }", "", "", "%-", + "#ifndef YY_ALWAYS_INTERACTIVE", + "#ifndef YY_NEVER_INTERACTIVE", + "extern int isatty YY_PROTO(( int ));", + "#endif", + "#endif", + "", "#ifdef YY_USE_PROTOS", "void yy_init_buffer( YY_BUFFER_STATE b, FILE *file )", "#else", @@ -1048,40 +1188,167 @@ char *skel[] = { "YY_BUFFER_STATE b;", "FILE *file;", "#endif", + "", "%+", + "extern \"C\" int isatty YY_PROTO(( int ));", "void yyFlexLexer::yy_init_buffer( YY_BUFFER_STATE b, istream* file )", "%*", + "", " {", + " yy_flush_buffer( b );", + "", " b->yy_input_file = file;", + " b->yy_fill_buffer = 1;", "", - " /* We put in the '\\n' and start reading from [1] so that an", - " * initial match-at-newline will be true.", - " */", + "%-", + "#if YY_ALWAYS_INTERACTIVE", + " b->yy_is_interactive = 1;", + "#else", + "#if YY_NEVER_INTERACTIVE", + " b->yy_is_interactive = 0;", + "#else", + " b->yy_is_interactive = file ? (isatty( fileno(file) ) > 0) : 0;", + "#endif", + "#endif", + "%+", + " b->yy_is_interactive = 0;", + "%*", + " }", "", - " b->yy_ch_buf[0] = '\\n';", - " b->yy_n_chars = 1;", + "", + "%-", + "#ifdef YY_USE_PROTOS", + "void yy_flush_buffer( YY_BUFFER_STATE b )", + "#else", + "void yy_flush_buffer( b )", + "YY_BUFFER_STATE b;", + "#endif", + "", + "%+", + "void yyFlexLexer::yy_flush_buffer( YY_BUFFER_STATE b )", + "%*", + " {", + " b->yy_n_chars = 0;", "", " /* We always need two end-of-buffer characters. The first causes", " * a transition to the end-of-buffer state. The second causes", " * a jam in that state.", " */", + " b->yy_ch_buf[0] = YY_END_OF_BUFFER_CHAR;", " b->yy_ch_buf[1] = YY_END_OF_BUFFER_CHAR;", - " b->yy_ch_buf[2] = YY_END_OF_BUFFER_CHAR;", "", - " b->yy_buf_pos = &b->yy_ch_buf[1];", + " b->yy_buf_pos = &b->yy_ch_buf[0];", + "", + " b->yy_at_bol = 1;", + " b->yy_buffer_status = YY_BUFFER_NEW;", "", + " if ( b == yy_current_buffer )", + " yy_load_buffer_state();", + " }", + "%*", + "", + "", + "#ifndef YY_NO_SCAN_BUFFER", "%-", - " b->yy_is_interactive = file ? isatty( fileno(file) ) : 0;", - "%+", + "#ifdef YY_USE_PROTOS", + "YY_BUFFER_STATE yy_scan_buffer( char *base, yy_size_t size )", + "#else", + "YY_BUFFER_STATE yy_scan_buffer( base, size )", + "char *base;", + "yy_size_t size;", + "#endif", + " {", + " YY_BUFFER_STATE b;", + "", + " if ( size < 2 ||", + " base[size-2] != YY_END_OF_BUFFER_CHAR ||", + " base[size-1] != YY_END_OF_BUFFER_CHAR )", + " /* They forgot to leave room for the EOB's. */", + " return 0;", + "", + " b = (YY_BUFFER_STATE) yy_flex_alloc( sizeof( struct yy_buffer_state ) );", + " if ( ! b )", + " YY_FATAL_ERROR( \"out of dynamic memory in yy_scan_buffer()\" );", + "", + " b->yy_buf_size = size - 2; /* \"- 2\" to take care of EOB's */", + " b->yy_buf_pos = b->yy_ch_buf = base;", + " b->yy_is_our_buffer = 0;", + " b->yy_input_file = 0;", + " b->yy_n_chars = b->yy_buf_size;", " b->yy_is_interactive = 0;", + " b->yy_at_bol = 1;", + " b->yy_fill_buffer = 0;", + " b->yy_buffer_status = YY_BUFFER_NEW;", + "", + " yy_switch_to_buffer( b );", + "", + " return b;", + " }", "%*", + "#endif", "", - " b->yy_fill_buffer = 1;", "", - " b->yy_buffer_status = YY_BUFFER_NEW;", + "#ifndef YY_NO_SCAN_STRING", + "%-", + "#ifdef YY_USE_PROTOS", + "YY_BUFFER_STATE yy_scan_string( yyconst char *str )", + "#else", + "YY_BUFFER_STATE yy_scan_string( str )", + "yyconst char *str;", + "#endif", + " {", + " int len;", + " for ( len = 0; str[len]; ++len )", + " ;", + "", + " return yy_scan_bytes( str, len );", " }", + "%*", + "#endif", "", "", + "#ifndef YY_NO_SCAN_BYTES", + "%-", + "#ifdef YY_USE_PROTOS", + "YY_BUFFER_STATE yy_scan_bytes( yyconst char *bytes, int len )", + "#else", + "YY_BUFFER_STATE yy_scan_bytes( bytes, len )", + "yyconst char *bytes;", + "int len;", + "#endif", + " {", + " YY_BUFFER_STATE b;", + " char *buf;", + " yy_size_t n;", + " int i;", + "", + " /* Get memory for full buffer, including space for trailing EOB's. */", + " n = len + 2;", + " buf = (char *) yy_flex_alloc( n );", + " if ( ! buf )", + " YY_FATAL_ERROR( \"out of dynamic memory in yy_scan_bytes()\" );", + "", + " for ( i = 0; i < len; ++i )", + " buf[i] = bytes[i];", + "", + " buf[len] = buf[len+1] = YY_END_OF_BUFFER_CHAR;", + "", + " b = yy_scan_buffer( buf, n );", + " if ( ! b )", + " YY_FATAL_ERROR( \"bad buffer in yy_scan_bytes()\" );", + "", + " /* It's okay to grow etc. this buffer, and we should throw it", + " * away when we're done.", + " */", + " b->yy_is_our_buffer = 1;", + "", + " return b;", + " }", + "%*", + "#endif", + "", + "", + "#ifndef YY_NO_PUSH_STATE", "%-", "#ifdef YY_USE_PROTOS", "static void yy_push_state( int new_state )", @@ -1095,7 +1362,7 @@ char *skel[] = { " {", " if ( yy_start_stack_ptr >= yy_start_stack_depth )", " {", - " int new_size;", + " yy_size_t new_size;", "", " yy_start_stack_depth += YY_START_STACK_INCR;", " new_size = yy_start_stack_depth * sizeof( int );", @@ -1116,8 +1383,10 @@ char *skel[] = { "", " BEGIN(new_state);", " }", + "#endif", "", "", + "#ifndef YY_NO_POP_STATE", "%-", "static void yy_pop_state()", "%+", @@ -1129,8 +1398,10 @@ char *skel[] = { "", " BEGIN(yy_start_stack[yy_start_stack_ptr]);", " }", + "#endif", "", "", + "#ifndef YY_NO_TOP_STATE", "%-", "static int yy_top_state()", "%+", @@ -1139,26 +1410,30 @@ char *skel[] = { " {", " return yy_start_stack[yy_start_stack_ptr - 1];", " }", + "#endif", "", + "#ifndef YY_EXIT_FAILURE", + "#define YY_EXIT_FAILURE 2", + "#endif", "", "%-", "#ifdef YY_USE_PROTOS", - "static void yy_fatal_error( const char msg[] )", + "static void yy_fatal_error( yyconst char msg[] )", "#else", "static void yy_fatal_error( msg )", "char msg[];", "#endif", " {", " (void) fprintf( stderr, \"%s\\n\", msg );", - " exit( 1 );", + " exit( YY_EXIT_FAILURE );", " }", "", "%+", "", - "void yyFlexLexer::LexerError( const char msg[] )", + "void yyFlexLexer::LexerError( yyconst char msg[] )", " {", " cerr << msg << '\\n';", - " exit( 1 );", + " exit( YY_EXIT_FAILURE );", " }", "%*", "", @@ -1171,7 +1446,7 @@ char *skel[] = { " { \\", " /* Undo effects of setting up yytext. */ \\", " yytext[yyleng] = yy_hold_char; \\", - " yy_c_buf_p = yytext + n - YY_MORE_ADJ; \\", + " yy_c_buf_p = yytext + n; \\", " yy_hold_char = *yy_c_buf_p; \\", " *yy_c_buf_p = '\\0'; \\", " yyleng = n; \\", @@ -1183,11 +1458,11 @@ char *skel[] = { "", "#ifndef yytext_ptr", "#ifdef YY_USE_PROTOS", - "static void yy_flex_strncpy( char *s1, const char *s2, int n )", + "static void yy_flex_strncpy( char *s1, yyconst char *s2, int n )", "#else", "static void yy_flex_strncpy( s1, s2, n )", "char *s1;", - "const char *s2;", + "yyconst char *s2;", "int n;", "#endif", " {", @@ -1197,26 +1472,49 @@ char *skel[] = { " }", "#endif", "", + "#ifdef YY_NEED_STRLEN", + "#ifdef YY_USE_PROTOS", + "static int yy_flex_strlen( yyconst char *s )", + "#else", + "static int yy_flex_strlen( s )", + "yyconst char *s;", + "#endif", + " {", + " register int n;", + " for ( n = 0; s[n]; ++n )", + " ;", + "", + " return n;", + " }", + "#endif", + "", "", "#ifdef YY_USE_PROTOS", - "static void *yy_flex_alloc( unsigned int size )", + "static void *yy_flex_alloc( yy_size_t size )", "#else", "static void *yy_flex_alloc( size )", - "unsigned int size;", + "yy_size_t size;", "#endif", " {", " return (void *) malloc( size );", " }", "", "#ifdef YY_USE_PROTOS", - "static void *yy_flex_realloc( void *ptr, unsigned int size )", + "static void *yy_flex_realloc( void *ptr, yy_size_t size )", "#else", "static void *yy_flex_realloc( ptr, size )", "void *ptr;", - "unsigned int size;", + "yy_size_t size;", "#endif", " {", - " return (void *) realloc( ptr, size );", + " /* The cast to (char *) in the following accommodates both", + " * implementations that use char* generic pointers, and those", + " * that use void* generic pointers. It works with the latter", + " * because both ANSI C and C++ allow castless assignment from", + " * any pointer type to void*, and deal with argument conversions", + " * as though doing an assignment.", + " */", + " return (void *) realloc( (char *) ptr, size );", " }", "", "#ifdef YY_USE_PROTOS", @@ -1228,5 +1526,13 @@ char *skel[] = { " {", " free( ptr );", " }", + "", + "#if YY_MAIN", + "int main()", + " {", + " yylex();", + " return 0;", + " }", + "#endif", 0 }; diff --git a/usr.bin/lex/version.h b/usr.bin/lex/version.h index 633a31e..a7c072c 100644 --- a/usr.bin/lex/version.h +++ b/usr.bin/lex/version.h @@ -1 +1 @@ -#define FLEX_VERSION "2.4.7" +#define FLEX_VERSION "2.5.3" |