]> granicus.if.org Git - flex/commitdiff
millaway simplified the reentrant api; here's the result
authorWill Estes <wlestes@users.sourceforge.net>
Fri, 26 Oct 2001 12:59:35 +0000 (12:59 +0000)
committerWill Estes <wlestes@users.sourceforge.net>
Fri, 26 Oct 2001 12:59:35 +0000 (12:59 +0000)
flex.skl
flex.texi
gen.c
main.c
tests/test-bison-yylloc/scanner.l
tests/test-bison-yylval/scanner.l
tests/test-include-by-reentrant/scanner.l
tests/test-prefix-nr/scanner.l
tests/test-pthread/scanner.l
tests/test-string-r/scanner.l
tests/test-yyextra/scanner.l

index 4ed8ff2171a712cb6d4ff8b4bbca4956d7665af4..1b46d840b9f3b9b0e473ca0aab59908834d9c47b 100644 (file)
--- a/flex.skl
+++ b/flex.skl
 #define YY_CALL_LAST_ARG  , yy_globals
 #define YY_CALL_ONLY_ARG   yy_globals
 
-/* For convenience. */
-#define yyin_r YY_G(yyin)
-#define yyout_r YY_G(yyout)
-#define yyextra_r YY_G(yyextra)
-#define yyleng_r YY_G(yyleng)
-#define yytext_r YY_G(yytext)
-#define yylineno_r YY_G(yylineno)
+/* For convenience, these vars (plus the bison vars far below)
+   are macros in the reentrant scanner. */
+#define yyin YY_G(yyin_r)
+#define yyout YY_G(yyout_r)
+#define yyextra YY_G(yyextra_r)
+#define yyleng YY_G(yyleng_r)
+#define yytext YY_G(yytext_r)
+#define yylineno YY_G(yylineno_r)
 
 int yylex_init YY_PROTO((void** scanner));
 int yylex_destroy YY_PROTO((void* scanner));
@@ -153,7 +154,7 @@ int yylex_destroy YY_PROTO((void* scanner));
 #define YY_STATE_EOF(state) (YY_END_OF_BUFFER + state + 1)
 
 /* Special action meaning "start processing a new file". */
-#define YY_NEW_FILE yyrestart( YY_G(yyin) YY_CALL_LAST_ARG )
+#define YY_NEW_FILE yyrestart( yyin YY_CALL_LAST_ARG )
 
 #define YY_END_OF_BUFFER_CHAR 0
 
@@ -339,7 +340,7 @@ static void yy_flex_free YY_PROTO(( void * YY_LAST_ARG ));
        { \
        if ( ! YY_G(yy_current_buffer) ) \
                YY_G(yy_current_buffer) =    \
-            yy_create_buffer( YY_G(yyin), YY_BUF_SIZE YY_CALL_LAST_ARG); \
+            yy_create_buffer( yyin, YY_BUF_SIZE YY_CALL_LAST_ARG); \
        YY_G(yy_current_buffer)->yy_is_interactive = is_interactive; \
        }
 
@@ -347,7 +348,7 @@ static void yy_flex_free YY_PROTO(( void * YY_LAST_ARG ));
        { \
        if ( ! YY_G(yy_current_buffer) ) \
                YY_G(yy_current_buffer) =    \
-            yy_create_buffer( YY_G(yyin), YY_BUF_SIZE YY_CALL_LAST_ARG); \
+            yy_create_buffer( yyin, YY_BUF_SIZE YY_CALL_LAST_ARG); \
        YY_G(yy_current_buffer)->yy_at_bol = at_bol; \
        }
 
@@ -392,14 +393,14 @@ struct yy_globals_t
     {
 
     /* User-defined. Not touched by flex. */
-    YY_EXTRA_TYPE yyextra;
+    YY_EXTRA_TYPE yyextra_r;
 
     /* The rest are the same as the globals declared in the non-reentrant scanner. */
-    FILE *yyin, *yyout;
+    FILE *yyin_r, *yyout_r;
     YY_BUFFER_STATE yy_current_buffer;
     char yy_hold_char;
     int yy_n_chars;
-    int yyleng;
+    int yyleng_r;
     char *yy_c_buf_p;
     int yy_init;
     int yy_start;
@@ -410,23 +411,23 @@ struct yy_globals_t
     yy_state_type yy_last_accepting_state;
     char* yy_last_accepting_cpos;
 
-    int yylineno;
+    int yylineno_r;
 
 #ifdef YY_TEXT_IS_ARRAY
-    char yytext[YYLMAX];
+    char yytext_r[YYLMAX];
     char *yytext_ptr;
     int yy_more_offset;
     int yy_prev_more_offset;
 #else
-    char *yytext;
+    char *yytext_r;
     int yy_more_flag;
     int yy_more_len;
 #endif
 
 #ifdef YY_REENTRANT_BISON_PURE
-    YYSTYPE * yylval;
+    YYSTYPE * yylval_r;
 #ifdef YYLTYPE
-    YYLTYPE * yylloc;
+    YYLTYPE * yylloc_r;
 #endif
 #endif
 
@@ -439,9 +440,9 @@ static int yy_init_globals YY_PROTO(( void * ));
 /* This must go here because YYSTYPE and YYLSTYPE are included
  * from bison output in section 1.*/
 #ifdef YY_REENTRANT_BISON_PURE
-#    define yylval_r YY_G(yylval)
+#    define yylval YY_G(yylval_r)
 #  ifdef YYLTYPE
-#    define yylloc_r YY_G(yylloc)
+#    define yylloc YY_G(yylloc_r)
 #  endif
 #endif
 
@@ -595,7 +596,7 @@ YY_MALLOC_DECL
 /* This used to be an fputs(), but since the string might contain NUL's,
  * we now use fwrite().
  */
-#define ECHO (void) fwrite( YY_G(yytext), YY_G(yyleng), 1, YY_G(yyout) )
+#define ECHO (void) fwrite( yytext, yyleng, 1, yyout )
 %+ C++ definition
 #define ECHO LexerOutput( yytext, yyleng )
 %*
@@ -701,9 +702,9 @@ YY_DECL
 %% [7.0] user's declarations go here
 
 #ifdef YY_REENTRANT_BISON_PURE
-    YY_G(yylval) = yylvalp;
+    yylval = yylvalp;
 #ifdef YYLTYPE
-    YY_G(yylloc) = yyllocp;
+    yylloc = yyllocp;
 #endif
 #endif
 
@@ -718,23 +719,23 @@ YY_DECL
                if ( ! YY_G(yy_start) )
                        YY_G(yy_start) = 1;     /* first start state */
 
-               if ( ! YY_G(yyin) )
+               if ( ! yyin )
 %-
-                       YY_G(yyin) = stdin;
+                       yyin = stdin;
 %+
                        yyin = & FLEX_STD cin;
 %*
 
-               if ( ! YY_G(yyout) )
+               if ( ! yyout )
 %-
-                       YY_G(yyout) = stdout;
+                       yyout = stdout;
 %+
                        yyout = & FLEX_STD cout;
 %*
 
                if ( ! YY_G(yy_current_buffer) )
                        YY_G(yy_current_buffer) =
-                               yy_create_buffer( YY_G(yyin), YY_BUF_SIZE YY_CALL_LAST_ARG);
+                               yy_create_buffer( yyin, YY_BUF_SIZE YY_CALL_LAST_ARG);
 
                yy_load_buffer_state( YY_CALL_ONLY_ARG );
                }
@@ -790,7 +791,7 @@ do_action:  /* This label is used only to access EOF actions. */
                         * back-up) that will match for the new input source.
                         */
                        YY_G(yy_n_chars) = YY_G(yy_current_buffer)->yy_n_chars;
-                       YY_G(yy_current_buffer)->yy_input_file = YY_G(yyin);
+                       YY_G(yy_current_buffer)->yy_input_file = yyin;
                        YY_G(yy_current_buffer)->yy_buffer_status = YY_BUFFER_NORMAL;
                        }
 
@@ -1109,7 +1110,7 @@ int yyFlexLexer::yy_get_next_buffer()
                if ( number_to_move == YY_MORE_ADJ )
                        {
                        ret_val = EOB_ACT_END_OF_FILE;
-                       yyrestart( YY_G(yyin)  YY_CALL_LAST_ARG);
+                       yyrestart( yyin  YY_CALL_LAST_ARG);
                        }
 
                else
@@ -1288,7 +1289,7 @@ int yyFlexLexer::yyinput()
                                         */
 
                                        /* Reset buffer status. */
-                                       yyrestart( YY_G(yyin) YY_CALL_LAST_ARG);
+                                       yyrestart( yyin YY_CALL_LAST_ARG);
 
                                        /* fall through */
 
@@ -1339,7 +1340,7 @@ void yyFlexLexer::yyrestart( FLEX_STD istream* input_file )
        {
        if ( ! YY_G(yy_current_buffer) )
                YY_G(yy_current_buffer) =
-            yy_create_buffer( YY_G(yyin), YY_BUF_SIZE YY_CALL_LAST_ARG);
+            yy_create_buffer( yyin, YY_BUF_SIZE YY_CALL_LAST_ARG);
 
        yy_init_buffer( YY_G(yy_current_buffer), input_file YY_CALL_LAST_ARG);
        yy_load_buffer_state( YY_CALL_ONLY_ARG );
@@ -1394,7 +1395,7 @@ void yyFlexLexer::yy_load_buffer_state()
        {
        YY_G(yy_n_chars) = YY_G(yy_current_buffer)->yy_n_chars;
        yytext_ptr = YY_G(yy_c_buf_p) = YY_G(yy_current_buffer)->yy_buf_pos;
-       YY_G(yyin) = YY_G(yy_current_buffer)->yy_input_file;
+       yyin = YY_G(yy_current_buffer)->yy_input_file;
        YY_G(yy_hold_char) = *YY_G(yy_c_buf_p);
        }
 
@@ -1753,11 +1754,11 @@ void yyFlexLexer::LexerError( yyconst char msg[] )
        do \
                { \
                /* Undo effects of setting up yytext. */ \
-               YY_G(yytext)[YY_G(yyleng)] = YY_G(yy_hold_char); \
-               YY_G(yy_c_buf_p) = YY_G(yytext) + n; \
+               yytext[yyleng] = YY_G(yy_hold_char); \
+               YY_G(yy_c_buf_p) = yytext + n; \
                YY_G(yy_hold_char) = *YY_G(yy_c_buf_p); \
                *YY_G(yy_c_buf_p) = '\0'; \
-               YY_G(yyleng) = n; \
+               yyleng = n; \
                } \
        while ( 0 )
 
@@ -1775,7 +1776,7 @@ YY_EXTRA_TYPE yyget_extra( YY_ONLY_ARG )
     YY_DECL_LAST_ARG
 #endif
 {
-    return YY_G(yyextra);
+    return yyextra;
 }
 #endif /* !YY_NO_GET_EXTRA */
 
@@ -1787,7 +1788,7 @@ int yyget_lineno( YY_ONLY_ARG )
     YY_DECL_LAST_ARG
 #  endif
 {
-    return YY_G(yylineno);
+    return yylineno;
 }
 #endif /* !YY_NO_GET_LINENO */
 
@@ -1799,7 +1800,7 @@ FILE *yyget_in( YY_ONLY_ARG )
     YY_DECL_LAST_ARG
 #endif
 {
-    return YY_G(yyin);
+    return yyin;
 }
 #endif /* !YY_NO_GET_IN */
 
@@ -1811,7 +1812,7 @@ FILE *yyget_out( YY_ONLY_ARG )
     YY_DECL_LAST_ARG
 #endif
 {
-    return YY_G(yyout);
+    return yyout;
 }
 #endif /* !YY_NO_GET_OUT */
 
@@ -1823,7 +1824,7 @@ int yyget_leng( YY_ONLY_ARG )
     YY_DECL_LAST_ARG
 #endif
 {
-    return YY_G(yyleng);
+    return yyleng;
 }
 #endif /* !YY_NO_GET_LENG */
 
@@ -1835,7 +1836,7 @@ char *yyget_text( YY_ONLY_ARG )
     YY_DECL_LAST_ARG
 #endif
 {
-    return YY_G(yytext);
+    return yytext;
 }
 #endif /* !YY_NO_GET_TEXT */
 
@@ -1848,7 +1849,7 @@ void yyset_extra( user_defined YY_LAST_ARG )
     YY_DECL_LAST_ARG
 #endif
 {
-    YY_G(yyextra) = user_defined ;
+    yyextra = user_defined ;
 }
 #endif /* !YY_NO_SET_EXTRA */
 
@@ -1861,7 +1862,7 @@ void yyset_lineno( line_number YY_LAST_ARG )
     YY_DECL_LAST_ARG
 #  endif
 {
-    YY_G(yylineno) = line_number;
+    yylineno = line_number;
 }
 #endif /* !YY_NO_SET_LINENO */
 
@@ -1875,7 +1876,7 @@ void yyset_in( in_str YY_LAST_ARG )
     YY_DECL_LAST_ARG
 #endif
 {
-    YY_G(yyin) = in_str ;
+    yyin = in_str ;
 }
 #endif /* !YY_NO_SET_IN */
 
@@ -1888,7 +1889,7 @@ void yyset_out( out_str YY_LAST_ARG )
     YY_DECL_LAST_ARG
 #endif
 {
-    YY_G(yyout) = out_str ;
+    yyout = out_str ;
 }
 #endif /* !YY_NO_SET_OUT */
 
@@ -1903,7 +1904,7 @@ YYSTYPE * yyget_lval( YY_ONLY_ARG )
     YY_DECL_LAST_ARG
 #endif
 {
-    return YY_G(yylval);
+    return yylval;
 }
 #endif /* !YY_NO_GET_LVAL */
 
@@ -1916,7 +1917,7 @@ void yyset_lval( yylvalp YY_LAST_ARG )
     YY_DECL_LAST_ARG
 #endif
 {
-    YY_G(yylval) = yylvalp;
+    yylval = yylvalp;
 }
 #endif /* !YY_NO_SET_LVAL */
 
@@ -1929,7 +1930,7 @@ YYLTYPE *yyget_lloc( YY_ONLY_ARG )
     YY_DECL_LAST_ARG
 #endif
 {
-    return YY_G(yylloc);
+    return yylloc;
 }
 #endif /* !YY_NO_GET_LLOC */
 
@@ -1942,7 +1943,7 @@ void yyset_lloc( yyllocp YY_LAST_ARG )
     YY_DECL_LAST_ARG
 #endif
 {
-    YY_G(yylloc) = yyllocp;
+    yylloc = yyllocp;
 }
 #endif /* !YY_NO_SET_LLOC */
 
@@ -1962,7 +1963,7 @@ static int yy_init_globals( yy_globals )
 
   /* We do not touch yylineno unless the option is enabled. */
 #ifdef YY_USE_LINENO
-    YY_G(yylineno) =  1;
+    yylineno =  1;
 #endif
     YY_G(yy_current_buffer) = 0;
     YY_G(yy_c_buf_p) = (char *) 0;
@@ -1974,11 +1975,11 @@ static int yy_init_globals( yy_globals )
 
 /* Defined in main.c */
 #ifdef YY_STDINIT
-    YY_G(yyin) = stdin;
-    YY_G(yyout) = stdout;
+    yyin = stdin;
+    yyout = stdout;
 #else
-    YY_G(yyin) = (FILE *) 0;
-    YY_G(yyout) = (FILE *) 0;
+    yyin = (FILE *) 0;
+    yyout = (FILE *) 0;
 #endif
     return 0;
     }
index 6712ba103cef9318fca700f968b2c38c5b04fabb..c7328ecaa45e8ee56d2e724ffa7305a0cd43c121 100644 (file)
--- a/flex.texi
+++ b/flex.texi
@@ -2105,9 +2105,9 @@ option, but with minor API changes for
 compatibility. In particular, the declaration of
 @code{yylex}
 is modified, and support for
-@code{yylval_r}
+@code{yylval}
 and
-@code{yylloc_r}
+@code{yylloc}
 is incorporated. @xref{bison pure}.
 
 The options @samp{--reentrant} and @samp{--reentrant-bison} do not affect the performance of
@@ -2348,7 +2348,7 @@ is performed in @code{yylex_init} at runtime.
 directs @code{flex} to generate a scanner
 that maintains the number of the current line read from its input in the
 global variable @code{yylineno}.  This option is implied by @code{%option
-lex-compat}.  In a reentrant C scanner, the macro @code{yylineno_r} is
+lex-compat}.  In a reentrant C scanner, the macro @code{yylineno} is
 accessible regardless of the value of @code{%option yylineno}, however, its
 value is not modified by @code{flex} unless @code{%option yylineno} is enabled.
 
@@ -3048,9 +3048,9 @@ another instance of itself.
     "eval(".+")"  {  
                       void * scanner;
                       yylex_init( &scanner );
-                      yytext_r[yyleng_r-1] = ' '; 
+                      yytext[yyleng-1] = ' '; 
 
-                      yyscan_string( yytext_r + 5, scanner );
+                      yyscan_string( yytext + 5, scanner );
                       yylex( scanner );
 
                       yylex_destroy( scanner );
@@ -3073,7 +3073,7 @@ scanners. Here is a quick overview of the API:
 All functions take one additional argument: @code{yy_globals}
 
 @item
-All global variables are replaced by their @samp{_r} equivalents.
+All global variables are replaced by their macro equivalents.
 
 @item
 @code{yylex_init} and @code{yylex_destroy} must be called before and
@@ -3084,7 +3084,7 @@ Accessor methods (get/set functions) provide access to common
 @code{flex} variables.
 
 @item 
-User-specific data can be stored in @code{yyextra_r}.
+User-specific data can be stored in @code{yyextra}.
 @end itemize
 
 @node reentrant example, reentrant detail, reentrant overview, reentrant
@@ -3101,7 +3101,7 @@ First, an example of a reentrant scanner:
     "//"                 yy_push_state( COMMENT, yy_globals);
     .|\n
     <COMMENT>\n          yy_pop_state( yy_globals );
-    <COMMENT>[^\n]+      fprintf( yyout_r, "%s\n", yytext_r);
+    <COMMENT>[^\n]+      fprintf( yyout, "%s\n", yytext);
     %%
     int main ( int argc, char * argv[] ) 
     {
@@ -3133,8 +3133,7 @@ Here are the things you need to do or know to use the reentrant C API of
 @node specify reentrant, extra reentrant argument, reentrant detail, reentrant detail
 @subsection Declaring a Scanner as Reentrant
 
- %option reentrant
-must be specified.
+ %option reentrant (--reentrant) must be specified.
 
 Notice that @code{%option reentrant} is specified in the above example
 (@pxref{reentrant example}. Had this option not been specified,
@@ -3172,39 +3171,33 @@ see @ref{reentrant functions}. Note that preprocessor macros, such as
 additional argument.
 
 @node global replacement, init and destroy and destroy, extra reentrant argument, reentrant detail
-@subsection Global Variables Replaced
+@subsection Global Variables Replaced by Macros
 
-All global variables are replaced by their @code{_r} equivalents.
+All global variables are replaced by macro equivalents.
 
-Notice in the above example that @code{yyout} and @code{yytext} are
-replaced by @code{yyout_r} and @code{yytext_r}.  These are macros that
-will expand to their equivalent lvalue.  All of the familiar @code{flex}
-globals have been replaced by their @code{_r} equivalents. Wherever you
-would normally use @code{yytext} in actions, you must use @code{yytext_r}
-instead. This rule applies to all @code{flex} variables. The following
-is an example that uses the @code{_r} macros:
+Note that in the above example, @code{yyout} and @code{yytext} are
+not plain variables. These are macros that will expand to their equivalent lvalue.
+All of the familiar @code{flex} globals have been replaced by their macro
+equivalents. In particular, @code{yytext}, @code{yyleng}, @code{yylineno},
+@code{yyin}, @code{yyout}, @code{yyextra}, @code{yylval}, and @code{yylloc}
+are macros. You may safely use these macros in actions as if they were plain
+variables. We only tell you this so you don't expect to link to these variables
+externally. Currently, each macro expands to a member of an internal struct, e.g.,
 
 @example
 @verbatim
-    %%
-        #define SWAP(a,b) do{int t=a; a=b; b=t;}while(0)
-    "reverse me"  {
-            int i;
-            for( i =0; i  yyleng_r/2 ; i++ )
-                SWAP( yytext_r[i], yytext_r[yyleng_r-i-1] );
-            fprintf( yyout_r, "%s", yytext_r );
-           }
+#define yytext (((struct yy_globals_t*)yy_globals)->yytext_r)
 @end verbatim
 @end example
 
 One important thing to remember about
-@code{yytext_r}
+@code{yytext}
 and friends is that
-@code{yytext_r}
+@code{yytext}
 is not a global variable in a reentrant
 scanner, you can not access it directly from outside an action or from
-other functions. You must use the accessor method 
-@code{yyget_text}
+other functions. You must use an accessor method, e.g., 
+@code{yyget_text}
 to accomplish this. (See below).
 
 @node init and destroy and destroy, accessor methods, global replacement, reentrant detail
@@ -3248,7 +3241,7 @@ Accessor methods (get/set functions) provide access to common
 Many scanners that you build will be part of a larger project. Portions
 of your project will need access to @code{flex} values, such as
 @code{yytext}.  In a non-reentrant scanner, these values are global, so
-there is no problem. However, in a reentrant scanner, there are no
+there is no problem accessing them. However, in a reentrant scanner, there are no
 global @code{flex} values. You can not access them directly.  Instead,
 you must access @code{flex} values using accessor methods (get/set
 functions). Each accessor method is named @code{yyget_NAME} or
@@ -3278,7 +3271,7 @@ The above code may be called from within an action like this:
 @node extra data,  , accessor methods, reentrant detail
 @subsection Extra Data
 
-User-specific data can be stored in @code{yyextra_r}.
+User-specific data can be stored in @code{yyextra}.
 
 In a reentrant scanner, it is unwise to use global variables to
 communicate with or maintain state between different pieces of your program.
@@ -3294,7 +3287,7 @@ This data is accessible through the accessor methods
 and
 @code{yyset_extra}
 from outside the scanner, and through the shortcut macro
-@code{yyextra_r}
+@code{yyextra}
 from within the scanner itself. They are defined as follows:
 
 @example
@@ -3306,7 +3299,7 @@ from within the scanner itself. They are defined as follows:
 @end example
 
 By default, @code{YY_EXTRA_TYPE} is defined as type @code{void *}.  You
-will have to cast @code{yyextra_r} and the return value from
+will have to cast @code{yyextra} and the return value from
 @code{yyget_extra} to the appropriate value each time you access the
 extra data.  To avoid casting, you may override the default type by
 defining @code{YY_EXTRA_TYPE} in section 1 of your scanner:
@@ -3322,8 +3315,8 @@ defining @code{YY_EXTRA_TYPE} in section 1 of your scanner:
     %option reentrant
     %%
           
-    __filesize__     printf( "%ld", yyextra_r->st_size  );
-    __lastmod__      printf( "%ld", yyextra_r->st_mtime );
+    __filesize__     printf( "%ld", yyextra->st_size  );
+    __lastmod__      printf( "%ld", yyextra->st_mtime );
     %%
     void scan_file( char* filename )
     {
@@ -3351,17 +3344,17 @@ half of the @code{flex} and @code{bison} pair.  We do not discuss
 @code{bison} in any detail.  For more information about generating pure
 @code{bison} parsers, see @ref{Top, , , bison, The GNU Bison Manual} A
 @code{bison}-compatible scanner is generated by declaring @samp{%option
-reentrant-bison} or by supplying @samp{-Rb} when invoking @code{flex}
+reentrant-bison} or by supplying @samp{--reentran-bison} when invoking @code{flex}
 from the command line.  This instructs @code{flex} that the macros
-@code{yylval_r} and @code{yylloc_r} may be used. The data types for
-@code{yylval_r} and @code{yylloc_r}, (@code{YYSTYPE} and @code{YYLTYPE},
+@code{yylval} and @code{yylloc} may be used. The data types for
+@code{yylval} and @code{yylloc}, (@code{YYSTYPE} and @code{YYLTYPE},
 are typically defined in a header file, included in section 1 of the
 @code{flex} input file.  @code{%option reentrant-bison} implies
 @code{%option reentrant}.  If @code{%option reentrant-bison} is
 specified, @code{flex} provides support for the functions
 @code{yyget_lval}, @code{yyset_lval}, @code{yyget_lloc}, and
 @code{yyset_lloc}, defined below, and the corresponding macros
-@code{yylval_r} and @code{yylloc_r}, for use within actions.
+@code{yylval} and @code{yylloc}, for use within actions.
 
 @example
 @verbatim
@@ -3381,7 +3374,7 @@ Accordingly, the declaration of yylex becomes one of the following:
 @end verbatim
 @end example
 
-Note that the macros @code{yylval_r} and @code{yylloc_r} evaluate to
+Note that the macros @code{yylval} and @code{yylloc} evaluate to
 pointers.  Support for @code{yylloc} is optional in @code{bison}, so it
 is optional in @code{flex} as well. This support is automatically
 handled by @code{flex}.  Specifically, support for @code{yyloc} is only
@@ -3399,17 +3392,17 @@ scanner that is @code{bison}-compatible.
     %option reentrant-bison
     %
    
-    [[:digit:]]+  { yylval_r->num = atoi(yytext_r);   return NUMBER;}
-    [[:alnum:]]+  { yylval_r->str = strdup(yytext_r); return STRING;}
-    "="|";"       { return yytext_r[0];}
+    [[:digit:]]+  { yylval->num = atoi(yytext);   return NUMBER;}
+    [[:alnum:]]+  { yylval->str = strdup(yytext); return STRING;}
+    "="|";"       { return yytext[0];}
     .  {}
     %
-@end vernbatim
+@end verbatim
 @end example
 
 As you can see, there really is no magic here. We just use
-@code{yylval_r} as we would any other variable. The data type of
-@code{yylval_r} is generated by @code{bison}, and included in the file
+@code{yylval} as we would any other variable. The data type of
+@code{yylval} is generated by @code{bison}, and included in the file
 @file{y.tab.h}.  Here is the corresponding @code{bison} parser:
 
 @example
@@ -3424,7 +3417,7 @@ As you can see, there really is no magic here. We just use
     %union {
         int num;
         char* str;
-   }
+    }
     %token <str> STRING
     %token <num> NUMBER 
     %%
@@ -3439,7 +3432,7 @@ As you can see, there really is no magic here. We just use
 @node reentrant functions,  , bison pure, reentrant
 @section FUNCTIONS AND MACROS AVAILABLE IN REENTRANT C SCANNERS
 
-The ffollowing Functions are available in a reentrant scanner:
+The following Functions are available in a reentrant scanner:
 
 @example
 @verbatim
@@ -3456,29 +3449,29 @@ The ffollowing Functions are available in a reentrant scanner:
 @end verbatim
 @end example
 
-There are no ``set'' functions for yytext_r and yyleng_r. This is intentional.
+There are no ``set'' functions for yytext and yyleng. This is intentional.
 
 The following Macro shortcuts are available in actions in a reentrant
 scanner:
 
 @example
 @verbatim
-    yytext_r
-    yyleng_r
-    yyin_r
-    yyout_r
-    yylineno_r
-    yyextra_r
+    yytext
+    yyleng
+    yyin
+    yyout
+    yylineno
+    yyextra
 @end verbatim
 @end example
 
-In a reentrant C scanner, support for yylineno_r is always present
-(i.e., you may access yylineno_r), but the value is never modified by
+In a reentrant C scanner, support for yylineno is always present
+(i.e., you may access yylineno), but the value is never modified by
 @code{flex} unless @code{%option yylineno} is enabled. This is to allow
 the user to maintain the line count independently of @code{flex}.
 
 The following functions and macros are made available when @code{%option
-reentrant-bison} (@samp{-Rb}) is specified:
+reentrant-bison} (@samp{--reentrant-bison}) is specified:
 
 @example
 @verbatim
@@ -3486,8 +3479,8 @@ reentrant-bison} (@samp{-Rb}) is specified:
     YYLTYPE *yyget_lloc ( void * scanner );
     void yyset_lval ( YYSTYPE * yylvalp , void * scanner );
     void yyset_lloc ( YYLTYPE * yyllocp , void * scanner );
-    yylval_r
-    yylloc_r
+    yylval
+    yylloc
 @end verbatim
 @end example
 
diff --git a/gen.c b/gen.c
index 22db43d315d0a59de19822272aaf45b47363ddfb..1878500ad95f4154d82969651bad1d59c620aa67 100644 (file)
--- a/gen.c
+++ b/gen.c
@@ -1074,11 +1074,11 @@ void make_tables()
        if ( yymore_used && ! yytext_is_array )
                {
                indent_puts( "YY_G(yytext_ptr) -= YY_G(yy_more_len); \\" );
-               indent_puts( "YY_G(yyleng) = (size_t) (yy_cp - YY_G(yytext_ptr)); \\" );
+               indent_puts( "yyleng = (size_t) (yy_cp - YY_G(yytext_ptr)); \\" );
                }
 
        else
-               indent_puts( "YY_G(yyleng) = (size_t) (yy_cp - yy_bp); \\" );
+               indent_puts( "yyleng = (size_t) (yy_cp - yy_bp); \\" );
 
        /* Now also deal with copying yytext_ptr to yytext if needed. */
        skelout(); /* %% [3.0] - break point in skel */
@@ -1086,9 +1086,9 @@ void make_tables()
                {
                if ( yymore_used )
                        indent_puts(
-                               "if ( YY_G(yyleng) + YY_G(yy_more_offset) >= YYLMAX ) \\" );
+                               "if ( yyleng + YY_G(yy_more_offset) >= YYLMAX ) \\" );
                else
-                       indent_puts( "if ( YY_G(yyleng) >= YYLMAX ) \\" );
+                       indent_puts( "if ( yyleng >= YYLMAX ) \\" );
 
                indent_up();
                indent_puts(
@@ -1098,8 +1098,8 @@ void make_tables()
                if ( yymore_used )
                        {
                        indent_puts(
-"yy_flex_strncpy( &YY_G(yytext)[YY_G(yy_more_offset)], YY_G(yytext_ptr), YY_G(yyleng) + 1 YY_CALL_LAST_ARG); \\" );
-                       indent_puts( "YY_G(yyleng) += YY_G(yy_more_offset); \\" );
+"yy_flex_strncpy( &yytext[YY_G(yy_more_offset)], YY_G(yytext_ptr), yyleng + 1 YY_CALL_LAST_ARG); \\" );
+                       indent_puts( "yyleng += YY_G(yy_more_offset); \\" );
                        indent_puts(
                                "YY_G(yy_prev_more_offset) = YY_G(yy_more_offset); \\" );
                        indent_puts( "YY_G(yy_more_offset) = 0; \\" );
@@ -1107,7 +1107,7 @@ void make_tables()
                else
                        {
                        indent_puts(
-               "yy_flex_strncpy( YY_G(yytext), YY_G(yytext_ptr), YY_G(yyleng) + 1 YY_CALL_LAST_ARG); \\" );
+               "yy_flex_strncpy( yytext, YY_G(yytext_ptr), yyleng + 1 YY_CALL_LAST_ARG); \\" );
                        }
                }
 
@@ -1287,14 +1287,14 @@ void make_tables()
                if ( yytext_is_array )
                        {
                        indent_puts(
-       "#define yymore() (YY_G(yy_more_offset) = yy_flex_strlen( YY_G(yytext) YY_CALL_LAST_ARG))" );
+       "#define yymore() (YY_G(yy_more_offset) = yy_flex_strlen( yytext YY_CALL_LAST_ARG))" );
                        indent_puts( "#define YY_NEED_STRLEN" );
                        indent_puts( "#define YY_MORE_ADJ 0" );
                        indent_puts( "#define YY_RESTORE_YY_MORE_OFFSET \\" );
                        indent_up();
                        indent_puts( "{ \\" );
                        indent_puts( "YY_G(yy_more_offset) = YY_G(yy_prev_more_offset); \\" );
-                       indent_puts( "YY_G(yyleng) -= YY_G(yy_more_offset); \\" );
+                       indent_puts( "yyleng -= YY_G(yy_more_offset); \\" );
                        indent_puts( "}" );
                        indent_down();
                        }
@@ -1345,7 +1345,7 @@ void make_tables()
                if ( use_read )
                        {
                        outn(
-"\tif ( (result = read( fileno(YY_G(yyin)), (char *) buf, max_size )) < 0 ) \\" );
+"\tif ( (result = read( fileno(yyin), (char *) buf, max_size )) < 0 ) \\" );
                        outn(
                "\t\tYY_FATAL_ERROR( \"input in flex scanner failed\" );" );
                        }
@@ -1358,18 +1358,18 @@ void make_tables()
                        outn( "\t\tint c = '*'; \\");
                        outn( "\t\tsize_t n; \\" );
                        outn( "\t\tfor ( n = 0; n < max_size && \\" );
-       outn( "\t\t\t     (c = getc( YY_G(yyin) )) != EOF && c != '\\n'; ++n ) \\" );
+       outn( "\t\t\t     (c = getc( yyin )) != EOF && c != '\\n'; ++n ) \\" );
                        outn( "\t\t\tbuf[n] = (char) c; \\" );
                        outn( "\t\tif ( c == '\\n' ) \\" );
                        outn( "\t\t\tbuf[n++] = (char) c; \\" );
-                       outn( "\t\tif ( c == EOF && ferror( YY_G(yyin) ) ) \\" );
+                       outn( "\t\tif ( c == EOF && ferror( yyin ) ) \\" );
                        outn(
        "\t\t\tYY_FATAL_ERROR( \"input in flex scanner failed\" ); \\" );
                        outn( "\t\tresult = n; \\" );
                        outn( "\t\t} \\" );
                        outn(
-       "\telse if ( ((result = fread( buf, 1, max_size, YY_G(yyin) )) == 0) \\" );
-                       outn( "\t\t  && ferror( YY_G(yyin) ) ) \\" );
+       "\telse if ( ((result = fread( buf, 1, max_size, yyin )) == 0) \\" );
+                       outn( "\t\t  && ferror( yyin ) ) \\" );
                        outn(
                "\t\tYY_FATAL_ERROR( \"input in flex scanner failed\" );" );
                        }
@@ -1381,10 +1381,10 @@ void make_tables()
        indent_up();
        if ( bol_needed )
                {
-               indent_puts( "if ( YY_G(yyleng) > 0 ) \\" );
+               indent_puts( "if ( yyleng > 0 ) \\" );
                indent_up();
                indent_puts( "YY_G(yy_current_buffer)->yy_at_bol = \\" );
-               indent_puts( "\t\t(YY_G(yytext)[YY_G(yyleng) - 1] == '\\n'); \\" );
+               indent_puts( "\t\t(yytext[yyleng - 1] == '\\n'); \\" );
                indent_down();
                }
        indent_puts( "YY_USER_ACTION" );
@@ -1433,13 +1433,13 @@ void make_tables()
                indent_puts( "{" );
                indent_puts( "int yyl;" );
                do_indent();
-               out_str( "for ( yyl = %s; yyl < YY_G(yyleng); ++yyl )\n",
+               out_str( "for ( yyl = %s; yyl < yyleng; ++yyl )\n",
                        yymore_used ? (yytext_is_array ? "yy_prev_more_offset" :
                                                         "yy_more_len") : "0");
                indent_up();
-               indent_puts( "if ( YY_G(yytext)[yyl] == '\\n' )" );
+               indent_puts( "if ( yytext[yyl] == '\\n' )" );
                indent_up();
-               indent_puts( "++YY_G(yylineno);" );
+               indent_puts( "++yylineno;" );
                indent_down();
                indent_down();
                indent_puts( "}" );
@@ -1477,7 +1477,7 @@ void make_tables()
        "fprintf( stderr, \"--accepting rule at line %d (\\\"%s\\\")\\n\"," );
 
                        indent_puts(
-                               "         yy_rule_linenum[yy_act], YY_G(yytext) );" );
+                               "         yy_rule_linenum[yy_act], yytext );" );
                        }
 
                indent_down();
@@ -1495,7 +1495,7 @@ void make_tables()
                        {
                        indent_puts(
        "fprintf( stderr, \"--accepting default rule (\\\"%s\\\")\\n\"," );
-                       indent_puts( "         YY_G(yytext) );" );
+                       indent_puts( "         yytext );" );
                        }
 
                indent_down();
@@ -1607,7 +1607,7 @@ void make_tables()
                { /* update yylineno inside of unput() */
                indent_puts( "if ( c == '\\n' )" );
                indent_up();
-               indent_puts( "--YY_G(yylineno);" );
+               indent_puts( "--yylineno;" );
                indent_down();
                }
 
@@ -1620,7 +1620,7 @@ void make_tables()
                        {
                        indent_puts( "if ( YY_G(yy_current_buffer)->yy_at_bol )" );
                        indent_up();
-                       indent_puts( "++YY_G(yylineno);" );
+                       indent_puts( "++yylineno;" );
                        indent_down();
                        }
                }
@@ -1629,7 +1629,7 @@ void make_tables()
                {
                indent_puts( "if ( c == '\\n' )" );
                indent_up();
-               indent_puts( "++YY_G(yylineno);" );
+               indent_puts( "++yylineno;" );
                indent_down();
                }
 
diff --git a/main.c b/main.c
index 4b5517ce25addc9365ab84e4ca63755ed1fefc19..b76e7ad5f292597067253ae053f680440463df36 100644 (file)
--- a/main.c
+++ b/main.c
@@ -336,12 +336,8 @@ void check_options()
                        GEN_PREFIX( "_flush_buffer" );
                        GEN_PREFIX( "_load_buffer_state" );
                        GEN_PREFIX( "_switch_to_buffer" );
-                       GEN_PREFIX( "in" );
-                       GEN_PREFIX( "leng" );
                        GEN_PREFIX( "lex" );
-                       GEN_PREFIX( "out" );
                        GEN_PREFIX( "restart" );
-                       GEN_PREFIX( "text" );
             GEN_PREFIX( "lex_init" );
             GEN_PREFIX( "lex_destroy" );
             GEN_PREFIX( "get_extra" );
@@ -364,9 +360,6 @@ void check_options()
             outn( "#endif" );
             outn( "#endif" );
 
-                       if ( do_yylineno )
-                               GEN_PREFIX( "lineno" );
-
             if ( do_yylineno && reentrant)
                 outn ( "#define YY_USE_LINENO 1");
                        }
@@ -1334,12 +1327,10 @@ _( "Variable trailing context rules entail a large performance penalty\n" ) );
 
                else
                        {
-            outn( "#ifdef YY_REENTRANT" );
-                       outn( "#define yytext_ptr YY_G(yytext)" );
-            outn( "#else" );
+            outn( "#ifndef YY_REENTRANT" );
                        outn( "extern char *yytext;" );
-                       outn( "#define yytext_ptr yytext" );
             outn( "#endif" );
+                       outn( "#define yytext_ptr yytext" );
                        }
 
                if ( yyclass )
index 4f059765a2ac4ce931890c22e6aeb864c44817d1..0c5ef001ca0549b3fac5e4fc8af78dca87696e27 100644 (file)
@@ -16,18 +16,18 @@ static char* STRDUP(char* s1);
 
 %%
 
-    if ( !yyextra_r)
-        yyextra_r = 1;
+    if ( !yyextra)
+        yyextra = 1;
 
 ^[[:digit:]]+  { 
-        yylval_r->lineno = yyextra_r++;
-        yylloc_r->first_line = (int)strtol(yytext_r,NULL,10);
+        yylval->lineno = yyextra++;
+        yylloc->first_line = (int)strtol(yytext,NULL,10);
         return LINENO;
     }
 ":"  { return COLON; }
 " "  { return SPACE; }
 "="  { return EQUAL; }
-[[:alnum:]_]+ {  yylval_r->str = STRDUP(yytext_r); return IDENT;}
+[[:alnum:]_]+ {  yylval->str = STRDUP(yytext); return IDENT;}
 
 \r|\n { }
 .     { yyterminate();}
index 521fcf432ce54ab33587a9864288dc030ffa1ce6..d2c7981238be4f849201ffb3b2304653cfd3ba00 100644 (file)
@@ -21,22 +21,22 @@ enum yesno_t { no=0, yes=1 };
 %x DISCARD_THRU_GT
 %%
 
-    #define YY_USER_INIT yyextra_r = no;
-    #define NEED_TAG_NAME yyextra_r
+    #define YY_USER_INIT yyextra = no;
+    #define NEED_TAG_NAME yyextra
         
 
 <INITIAL>{
 "</"       { NEED_TAG_NAME= yes; yy_push_state( IN_TAG, yy_globals); return LTSLASH;}
 "<"[^[:alpha:]]  { yy_push_state(DISCARD_THRU_GT,yy_globals); }
 "<"        { NEED_TAG_NAME= yes; yy_push_state( IN_TAG, yy_globals); return  LT; }
-[^<]{1,512} { yyget_lval(yy_globals)->str = STRDUP(yytext_r); return TEXT;}
+[^<]{1,512} { yyget_lval(yy_globals)->str = STRDUP(yytext); return TEXT;}
 }
 <IN_TAG>{
 ">"  { yy_pop_state( yy_globals ); return GT; }
 [[:alpha:]][[:alnum:]]* {
         if( NEED_TAG_NAME == yes){
             NEED_TAG_NAME=no;
-            yylval_r->str = STRDUP(yytext_r);
+            yylval->str = STRDUP(yytext);
             return TAGNAME;
         }
     }
index 6079a2ee1ed8dad793b18cd9dabed3863217aafb..80aceff78949245e137f618996b987a53644ae85 100644 (file)
      /* recurse */
     void * scanner;
     FILE * fp;
-    yytext_r[yyleng_r-1]='\0';
-    if((fp=fopen(yytext_r,"r"))==NULL) {
+    yytext[yyleng-1]='\0';
+    if((fp=fopen(yytext,"r"))==NULL) {
         fprintf(stderr,"*** Error: Could not open include file \"%s\".\n",
-            yytext_r);
+            yytext);
         yyterminate();
     }
     yylex_init(&scanner);
     BEGIN(0);
     }
 .|\n  {
-    fprintf(stderr,"Invalid input \"%s\".\n", yytext_r);
+    fprintf(stderr,"Invalid input \"%s\".\n", yytext);
     yyterminate();
    }
 }
 
-<<EOF>> { fclose(yyin_r); yyterminate();}
+<<EOF>> { fclose(yyin); yyterminate();}
 
 %%
 
index 24369c04835acd72ec1b74c1a816de0810cc1846..7df5629a2a2fe6f964131c999bb9a56df67b8feb 100644 (file)
         FOO_scan_bytes((yyconst char*)0, 0);
         FOO_scan_string((yyconst char*)0);
         FOO_switch_to_buffer((YY_BUFFER_STATE)0);
-        FOOin   = (FILE*)0;
-        FOOout  = (FILE*)0;
-        FOOleng = 0;
-        FOOlex();
-        FOOrestart((FILE*)0);
-        FOOtext = (char*)0;
+        yyin   = (FILE*)0;
+        yyout  = (FILE*)0;
+        yyleng = 0;
+        yylex();
+        yyrestart((FILE*)0);
+        yytext = (char*)0;
     }
  }
 %%
@@ -41,8 +41,8 @@
 int
 main ( int argc, char** argv )
 {
-    FOOin = stdin;
-    FOOout = stdout;
+    yyin = stdin;
+    yyout = stdout;
     FOOlex();
     printf("TEST RETURNING OK.\n");
     return 0;
index d5f8f75907f4a2ccedcd8d9ae3fd6d8003a54fc6..55d92745e2f4f9fd74e78ab828b7e5e5303cfebd 100644 (file)
@@ -38,18 +38,18 @@ static int process_text(char* s, void* scanner);
     #define NUMBER 200
     #define WORD   201
 
-<INITIAL>[[:digit:]]+ { BEGIN(STATE_1); process_text(yytext_r,yy_globals); return NUMBER; }
-<INITIAL>[[:alpha:]]+ { BEGIN(STATE_2); process_text(yytext_r,yy_globals); return WORD; }
+<INITIAL>[[:digit:]]+ { BEGIN(STATE_1); process_text(yytext,yy_globals); return NUMBER; }
+<INITIAL>[[:alpha:]]+ { BEGIN(STATE_2); process_text(yytext,yy_globals); return WORD; }
 
-<STATE_1>[[:alpha:]]+ { BEGIN(0); process_text(yytext_r,yy_globals); return WORD; }
-<STATE_1>[[:digit:]]+ { BEGIN(0); process_text(yytext_r,yy_globals); return NUMBER; }
+<STATE_1>[[:alpha:]]+ { BEGIN(0); process_text(yytext,yy_globals); return WORD; }
+<STATE_1>[[:digit:]]+ { BEGIN(0); process_text(yytext,yy_globals); return NUMBER; }
 
-<STATE_2>[[:alpha:]]+ { BEGIN(0); process_text(yytext_r,yy_globals); return WORD; }
-<STATE_2>[[:digit:]]+ { BEGIN(0); process_text(yytext_r,yy_globals); return NUMBER; }
+<STATE_2>[[:alpha:]]+ { BEGIN(0); process_text(yytext,yy_globals); return WORD; }
+<STATE_2>[[:digit:]]+ { BEGIN(0); process_text(yytext,yy_globals); return NUMBER; }
 
-<INITIAL,STATE_1,STATE_2>" "|\t|\r|\n { process_text(yytext_r,yy_globals); }
+<INITIAL,STATE_1,STATE_2>" "|\t|\r|\n { process_text(yytext,yy_globals); }
 <INITIAL,STATE_1,STATE_2>[^[:alnum:][:space:]\t\r\n] {
-        /*fprintf(stderr,"*** Error: bad input char '%c'.\n", yytext_r[0]); */
+        /*fprintf(stderr,"*** Error: bad input char '%c'.\n", yytext[0]); */
         yyterminate();
     }
 <INITIAL,STATE_1,STATE_2>[[:space:]\r\n]+  { }
index 5f23105d6f139b43dc434d7c2f1b0c7bb7b49fd7..eb02e769023b2b20407feb50986a0ef2424b4aa6 100644 (file)
@@ -21,7 +21,7 @@
 [[:alpha:]]+   { printf("WORD "); fflush(stdout);}
 .              {
     fprintf(stderr,"*** Error: Unrecognized character '%c' while scanning.\n",
-         yytext_r[0]);
+         yytext[0]);
     yyterminate();
     }
 
index eff4855a85d0a263834e3237337b14e21f5dc5c4..b112c21388133cbdc0cc4ac1c12680562b7df5d3 100644 (file)
@@ -32,7 +32,7 @@ static void append_char (char c,  void* scanner );
 
 %%
 
-.|\r|\n  { append_char (yytext_r[0],yy_globals); }
+.|\r|\n  { append_char (yytext[0],yy_globals); }
 
 %%