diff options
-rw-r--r-- | flex.skl | 27 | ||||
-rw-r--r-- | flex.texi | 44 | ||||
-rw-r--r-- | tests/test-bison-yylval/scanner.l | 12 | ||||
-rw-r--r-- | tests/test-mem-r/scanner.l | 12 | ||||
-rw-r--r-- | tests/test-multiple-scanners-r/scanner-1.l | 8 | ||||
-rw-r--r-- | tests/test-multiple-scanners-r/scanner-2.l | 8 | ||||
-rw-r--r-- | tests/test-prefix-r/scanner.l | 18 | ||||
-rw-r--r-- | tests/test-pthread/scanner.l | 14 | ||||
-rw-r--r-- | tests/test-yyextra/scanner.l | 2 |
9 files changed, 73 insertions, 72 deletions
@@ -97,20 +97,20 @@ typedef void* yyscan_t; #endif /* For use wherever a Global is accessed or assigned. */ -#define YY_G(var) (((struct yy_globals_t*)yy_globals)->var) +#define YY_G(var) (((struct yyguts_t*)yyscanner)->var) /* For use in function prototypes to append the additional argument. */ -#define YY_PROTO_LAST_ARG , yyscan_t yy_globals -#define YY_PROTO_ONLY_ARG yyscan_t yy_globals +#define YY_PROTO_LAST_ARG , yyscan_t yyscanner +#define YY_PROTO_ONLY_ARG yyscan_t yyscanner /* For use in function definitions to append the additional argument. */ -#define YY_DEF_LAST_ARG , yy_globals -#define YY_DEF_ONLY_ARG yy_globals -#define YY_DECL_LAST_ARG yyscan_t yy_globals; +#define YY_DEF_LAST_ARG , yyscanner +#define YY_DEF_ONLY_ARG yyscanner +#define YY_DECL_LAST_ARG yyscan_t yyscanner; /* For use in function calls to pass the additional argument. */ -#define YY_CALL_LAST_ARG , yy_globals -#define YY_CALL_ONLY_ARG yy_globals +#define YY_CALL_LAST_ARG , yyscanner +#define YY_CALL_ONLY_ARG yyscanner /* For convenience, these vars (plus the bison vars far below) are macros in the reentrant scanner. */ @@ -419,7 +419,8 @@ static void yy_fatal_error YY_PARAMS(( yyconst char msg[] )); #ifdef YY_REENTRANT %c -struct yy_globals_t +/* Holds the entire state of the reentrant scanner. */ +struct yyguts_t { /* User-defined. Not touched by flex. */ @@ -1865,8 +1866,8 @@ void yyset_lloc ( yyllocp YY_DEF_LAST_ARG ) #endif /* YY_REENTRANT_BISON_PURE */ -static int yy_init_globals( yy_globals ) - yyscan_t yy_globals; +static int yy_init_globals( yyscanner ) + yyscan_t yyscanner; { /* Initialization is the same as for the non-reentrant scanner. This function is called once per scanner lifetime. */ @@ -1898,7 +1899,7 @@ static int yy_init_globals( yy_globals ) int yylex_init( ptr_yy_globals ) yyscan_t* ptr_yy_globals; { - *ptr_yy_globals = (yyscan_t) yyalloc ( sizeof( struct yy_globals_t ), NULL ); + *ptr_yy_globals = (yyscan_t) yyalloc ( sizeof( struct yyguts_t ), NULL ); yy_init_globals ( *ptr_yy_globals ); return 0; } @@ -1924,7 +1925,7 @@ int yylex_destroy ( YY_DEF_ONLY_ARG ) #ifdef YY_REENTRANT /* Destroy the main struct (reentrant only). */ - yyfree ( yy_globals YY_CALL_LAST_ARG ); + yyfree ( yyscanner YY_CALL_LAST_ARG ); #endif return 0; } @@ -3414,7 +3414,7 @@ scanners. Here is a quick overview of the API: @code{%option reentrant} must be specified. @item -All functions take one additional argument: @code{yy_globals} +All functions take one additional argument: @code{yyscanner} @item All global variables are replaced by their macro equivalents. @@ -3443,9 +3443,9 @@ First, an example of a reentrant scanner: %option reentrant stack %x COMMENT %% - "//" yy_push_state( COMMENT, yy_globals); + "//" yy_push_state( COMMENT, yyscanner); .|\n - <COMMENT>\n yy_pop_state( yy_globals ); + <COMMENT>\n yy_pop_state( yyscanner ); <COMMENT>[^\n]+ fprintf( yyout, "%s\n", yytext); %% int main ( int argc, char * argv[] ) @@ -3492,28 +3492,28 @@ necessary. The default is to generate a non-reentrant scanner. @subsection The Extra Argument @cindex reentrant, calling functions -@vindex yy_globals (reentrant only) -All functions take one additional argument: @code{yy_globals}. +@vindex yyscanner (reentrant only) +All functions take one additional argument: @code{yyscanner}. Notice that the calls to @code{yy_push_state} and @code{yy_pop_state} -both have an argument, @code{yy_globals} , that is not present in a +both have an argument, @code{yyscanner} , that is not present in a non-reentrant scanner. Here are the declarations of @code{yy_push_state} and @code{yy_pop_state} in the generated scanner: @example @verbatim - static void yy_push_state ( int new_state , yyscan_t yy_globals ) ; - static void yy_pop_state ( yyscan_t yy_globals ) ; + static void yy_push_state ( int new_state , yyscan_t yyscanner ) ; + static void yy_pop_state ( yyscan_t yyscanner ) ; @end verbatim @end example -Notice that the argument @code{yy_globals} appears in the declaration of +Notice that the argument @code{yyscanner} appears in the declaration of both functions. In fact, all @code{flex} functions in a reentrant scanner have this additional argument. It is always the last argument in the argument list, it is always of type @code{yyscan_t} (which is typedef'd to @code{void *}) and it is -always named @code{yy_globals}. As you may have guessed, -@code{yy_globals} is a pointer to an opaque data structure encapsulating +always named @code{yyscanner}. As you may have guessed, +@code{yyscanner} is a pointer to an opaque data structure encapsulating the current state of the scanner. For a list of function declarations, see @ref{Reentrant Functions}. Note that preprocessor macros, such as @code{BEGIN}, @code{ECHO}, and @code{REJECT}, do not take this @@ -3536,7 +3536,7 @@ externally. Currently, each macro expands to a member of an internal struct, e.g @example @verbatim -#define yytext (((struct yy_globals_t*)yy_globals)->yytext_r) +#define yytext (((struct yyguts_t*)yyscanner)->yytext_r) @end verbatim @end example @@ -3564,8 +3564,8 @@ after @code{yylex}, respectively. @example @verbatim int yylex_init ( yyscan_t * ptr_yy_globals ) ; - int yylex ( yyscan_t yy_globals ) ; - int yylex_destroy ( yyscan_t yy_globals ) ; + int yylex ( yyscan_t yyscanner ) ; + int yylex_destroy ( yyscan_t yyscanner ) ; @end verbatim @end example @@ -3584,7 +3584,7 @@ version of @code{yylex}. The function @code{yylex_destroy} should be called to free resources used by the scanner. After @code{yylex_destroy} -is called, the contents of @code{yy_globals} should not be used. Of +is called, the contents of @code{yyscanner} should not be used. Of course, there is no need to destroy a scanner if you plan to reuse it. A @code{flex} scanner (both reentrant and non-reentrant) may be restarted by calling @code{yyrestart}. @@ -3644,7 +3644,7 @@ The above code may be called from within an action like this: @example @verbatim %% - .+\n { chop( yy_globals );} + .+\n { chop( yyscanner );} @end verbatim @end example @@ -4273,9 +4273,9 @@ void * yyrealloc (void * ptr, size_t bytes); void yyfree (void * ptr); // For a reentrant scanner -void * yyalloc (size_t bytes, void * yy_globals); -void * yyrealloc (void * ptr, size_t bytes, void * yy_globals); -void yyfree (void * ptr, void * yy_globals); +void * yyalloc (size_t bytes, void * yyscanner); +void * yyrealloc (void * ptr, size_t bytes, void * yyscanner); +void yyfree (void * ptr, void * yyscanner); @end verbatim @end example @@ -4306,15 +4306,15 @@ custom allocator through @code{yyextra}. %% /* Provide our own implementations. */ -void * yyalloc (size_t bytes, void* yy_globals) { +void * yyalloc (size_t bytes, void* yyscanner) { return allocator_alloc (yyextra, bytes); } -void * yyrealloc (void * ptr, size_t bytes, void* yy_globals) { +void * yyrealloc (void * ptr, size_t bytes, void* yyscanner) { return allocator_realloc (yyextra, bytes); } -void yyfree (void * ptr, void * yy_globals) { +void yyfree (void * ptr, void * yyscanner) { /* Do nothing -- we leave it to the garbage collector. */ } diff --git a/tests/test-bison-yylval/scanner.l b/tests/test-bison-yylval/scanner.l index 1035c1a..1af8db3 100644 --- a/tests/test-bison-yylval/scanner.l +++ b/tests/test-bison-yylval/scanner.l @@ -49,13 +49,13 @@ enum yesno_t { no=0, yes=1 }; <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); return TEXT;} +"</" { NEED_TAG_NAME= yes; yy_push_state( IN_TAG, yyscanner); return LTSLASH;} +"<"[^[:alpha:]] { yy_push_state(DISCARD_THRU_GT,yyscanner); } +"<" { NEED_TAG_NAME= yes; yy_push_state( IN_TAG, yyscanner); return LT; } +[^<]{1,512} { yyget_lval(yyscanner)->str = STRDUP(yytext); return TEXT;} } <IN_TAG>{ -">" { yy_pop_state( yy_globals ); return GT; } +">" { yy_pop_state( yyscanner ); return GT; } [[:alpha:]][[:alnum:]]* { if( NEED_TAG_NAME == yes){ NEED_TAG_NAME=no; @@ -68,7 +68,7 @@ enum yesno_t { no=0, yes=1 }; } <DISCARD_THRU_GT>{ [^>]{1,512} { } -">" { yy_pop_state(yy_globals);} +">" { yy_pop_state(yyscanner);} } %% diff --git a/tests/test-mem-r/scanner.l b/tests/test-mem-r/scanner.l index 01ac9de..69eae6d 100644 --- a/tests/test-mem-r/scanner.l +++ b/tests/test-mem-r/scanner.l @@ -46,15 +46,15 @@ %% <INITIAL>{ -"(" { printf("yy_push_state(parens)\n"); yy_push_state(parens,yy_globals); } +"(" { printf("yy_push_state(parens)\n"); yy_push_state(parens,yyscanner); } len=[0-9]+ { printf("About read token where %s\n",yytext); } 0+ { } .|\n { } } <parens>{ -"(" { printf("yy_push_state(parens)\n"); yy_push_state(parens,yy_globals); } -")" { printf("yy_pop_state()\n");yy_pop_state(yy_globals);} +"(" { printf("yy_push_state(parens)\n"); yy_push_state(parens,yyscanner); } +")" { printf("yy_pop_state()\n");yy_pop_state(yyscanner);} [^()\n]+ { } .|\n { } } @@ -82,7 +82,7 @@ static void dump_mem(FILE* fp){ fprintf(fp,"}\n"); } -void * yyalloc(size_t n , void* yy_globals) +void * yyalloc(size_t n , void* yyscanner) { void * p; struct memsz * old; @@ -112,7 +112,7 @@ void * yyalloc(size_t n , void* yy_globals) return p; } -void * yyrealloc(void* p, size_t n , void* yy_globals) +void * yyrealloc(void* p, size_t n , void* yyscanner) { int i; for (i=0; i < arrsz; i++) @@ -133,7 +133,7 @@ void * yyrealloc(void* p, size_t n , void* yy_globals) exit(1); } -void yyfree(void* p , void* yy_globals) +void yyfree(void* p , void* yyscanner) { int i; for (i=0; i < arrsz; i++) diff --git a/tests/test-multiple-scanners-r/scanner-1.l b/tests/test-multiple-scanners-r/scanner-1.l index 647e4de..9fa1bc0 100644 --- a/tests/test-multiple-scanners-r/scanner-1.l +++ b/tests/test-multiple-scanners-r/scanner-1.l @@ -38,13 +38,13 @@ %x OFF %% <INITIAL>{ -on yy_push_state(ON, yy_globals); return 10; -off yy_push_state(OFF, yy_globals); return 11; +on yy_push_state(ON, yyscanner); return 10; +off yy_push_state(OFF, yyscanner); return 11; .|\n return 12; } -<ON>.|\n yy_pop_state(yy_globals); return 13; +<ON>.|\n yy_pop_state(yyscanner); return 13; -<OFF>.|\n yy_pop_state(yy_globals); return 14; +<OFF>.|\n yy_pop_state(yyscanner); return 14; %% diff --git a/tests/test-multiple-scanners-r/scanner-2.l b/tests/test-multiple-scanners-r/scanner-2.l index a604288..209ceca 100644 --- a/tests/test-multiple-scanners-r/scanner-2.l +++ b/tests/test-multiple-scanners-r/scanner-2.l @@ -38,12 +38,12 @@ %x ON %% <INITIAL>{ -on yy_push_state(ON, yy_globals); return 3; -off yy_push_state(OFF, yy_globals); return 4; +on yy_push_state(ON, yyscanner); return 3; +off yy_push_state(OFF, yyscanner); return 4; .|\n return 5; } -<ON>.|\n yy_pop_state(yy_globals); return 6; +<ON>.|\n yy_pop_state(yyscanner); return 6; -<OFF>.|\n yy_pop_state(yy_globals); return 7; +<OFF>.|\n yy_pop_state(yyscanner); return 7; %% diff --git a/tests/test-prefix-r/scanner.l b/tests/test-prefix-r/scanner.l index d6cb6b4..4accbe3 100644 --- a/tests/test-prefix-r/scanner.l +++ b/tests/test-prefix-r/scanner.l @@ -42,15 +42,15 @@ /* Compile, but do not execute the following code. */ if( 0 ) { - FOO_create_buffer( (FILE*)0, 0, yy_globals); - FOO_delete_buffer( (YY_BUFFER_STATE)0, yy_globals); - FOO_flush_buffer( (YY_BUFFER_STATE)0, yy_globals); - FOO_init_buffer( (YY_BUFFER_STATE)0, (FILE*)0, yy_globals); - FOO_load_buffer_state( yy_globals); - FOO_scan_buffer( (char*)0, (yy_size_t)0, yy_globals); - FOO_scan_bytes( (yyconst char*)0, 0, yy_globals); - FOO_scan_string( (yyconst char*)0, yy_globals); - FOO_switch_to_buffer( (YY_BUFFER_STATE)0, yy_globals); + FOO_create_buffer( (FILE*)0, 0, yyscanner); + FOO_delete_buffer( (YY_BUFFER_STATE)0, yyscanner); + FOO_flush_buffer( (YY_BUFFER_STATE)0, yyscanner); + FOO_init_buffer( (YY_BUFFER_STATE)0, (FILE*)0, yyscanner); + FOO_load_buffer_state( yyscanner); + FOO_scan_buffer( (char*)0, (yy_size_t)0, yyscanner); + FOO_scan_bytes( (yyconst char*)0, 0, yyscanner); + FOO_scan_string( (yyconst char*)0, yyscanner); + FOO_switch_to_buffer( (YY_BUFFER_STATE)0, yyscanner); FOOrestart( (FILE*)0, (yyscan_t )0); FOOget_extra( (yyscan_t )0 ); diff --git a/tests/test-pthread/scanner.l b/tests/test-pthread/scanner.l index 77c7528..d4e6bca 100644 --- a/tests/test-pthread/scanner.l +++ b/tests/test-pthread/scanner.l @@ -61,16 +61,16 @@ static int process_text(char* s, yyscan_t scanner); #define NUMBER 200 #define WORD 201 -<INITIAL>[[:digit:]]+ { BEGIN(STATE_1); process_text(yytext,yy_globals); return NUMBER; } -<INITIAL>[[:alpha:]]+ { BEGIN(STATE_2); process_text(yytext,yy_globals); return WORD; } +<INITIAL>[[:digit:]]+ { BEGIN(STATE_1); process_text(yytext,yyscanner); return NUMBER; } +<INITIAL>[[:alpha:]]+ { BEGIN(STATE_2); process_text(yytext,yyscanner); return WORD; } -<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_1>[[:alpha:]]+ { BEGIN(0); process_text(yytext,yyscanner); return WORD; } +<STATE_1>[[:digit:]]+ { BEGIN(0); process_text(yytext,yyscanner); 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; } +<STATE_2>[[:alpha:]]+ { BEGIN(0); process_text(yytext,yyscanner); return WORD; } +<STATE_2>[[:digit:]]+ { BEGIN(0); process_text(yytext,yyscanner); return NUMBER; } -<INITIAL,STATE_1,STATE_2>" "|\t|\r|\n { process_text(yytext,yy_globals); } +<INITIAL,STATE_1,STATE_2>" "|\t|\r|\n { process_text(yytext,yyscanner); } <INITIAL,STATE_1,STATE_2>[^[:alnum:][:space:]\t\r\n] { /*fprintf(stderr,"*** Error: bad input char '%c'.\n", yytext[0]); */ yyterminate(); diff --git a/tests/test-yyextra/scanner.l b/tests/test-yyextra/scanner.l index 025f409..375a77b 100644 --- a/tests/test-yyextra/scanner.l +++ b/tests/test-yyextra/scanner.l @@ -55,7 +55,7 @@ static void append_char (char c, yyscan_t scanner ); %% -.|\r|\n { append_char (yytext[0],yy_globals); } +.|\r|\n { append_char (yytext[0],yyscanner); } %% |