diff --git a/src/FlexLexer.h b/src/FlexLexer.h index c4dad2b14..d7603c8ec 100644 --- a/src/FlexLexer.h +++ b/src/FlexLexer.h @@ -132,6 +132,7 @@ class yyFlexLexer : public FlexLexer { void yy_switch_to_buffer( yy_buffer_state* new_buffer ); yy_buffer_state* yy_create_buffer( std::istream* s, int size ); yy_buffer_state* yy_create_buffer( std::istream& s, int size ); + yy_buffer_state* yy_append_bytes( const char * yybytes, int _yybytes_len ); void yy_delete_buffer( yy_buffer_state* b ); void yyrestart( std::istream* s ); void yyrestart( std::istream& s ); @@ -213,6 +214,8 @@ class yyFlexLexer : public FlexLexer { int yy_more_len; int yy_more_offset; int yy_prev_more_offset; + + int yy_resume; // whether we should resume scanning after a stall }; } diff --git a/src/flex.skl b/src/flex.skl index 9a6952075..6e95132b2 100644 --- a/src/flex.skl +++ b/src/flex.skl @@ -65,6 +65,7 @@ m4_ifelse(M4_YY_PREFIX,yy,, #define yy_scan_buffer M4_YY_PREFIX[[_scan_buffer]] #define yy_scan_string M4_YY_PREFIX[[_scan_string]] #define yy_scan_bytes M4_YY_PREFIX[[_scan_bytes]] +#define yy_append_bytes M4_YY_PREFIX[[_append_bytes]] #define yy_init_buffer M4_YY_PREFIX[[_init_buffer]] #define yy_flush_buffer M4_YY_PREFIX[[_flush_buffer]] #define yy_load_buffer_state M4_YY_PREFIX[[_load_buffer_state]] @@ -140,6 +141,7 @@ m4_ifelse(M4_YY_PREFIX,yy,, M4_GEN_PREFIX(`_scan_buffer') M4_GEN_PREFIX(`_scan_string') M4_GEN_PREFIX(`_scan_bytes') + M4_GEN_PREFIX(`_append_bytes') M4_GEN_PREFIX(`_init_buffer') M4_GEN_PREFIX(`_flush_buffer') M4_GEN_PREFIX(`_load_buffer_state') @@ -432,6 +434,9 @@ m4_ifdef( [[M4_YY_NOT_IN_HEADER]], #define EOB_ACT_CONTINUE_SCAN 0 #define EOB_ACT_END_OF_FILE 1 #define EOB_ACT_LAST_MATCH 2 +/*#if defined(YY_STALLED)*/ +#define EOB_ACT_STALLED 3 +/*#endif*/ /* defined(YY_STALLED) */ m4_ifdef( [[M4_YY_USE_LINENO]], [[ /* Note: We specifically omit the test for yy_rule_can_match_eol because it requires @@ -451,7 +456,7 @@ m4_ifdef( [[M4_YY_NOT_IN_HEADER]], #define YY_LINENO_REWIND_TO(dst) \ do {\ const char *p;\ - for ( p = yy_cp-1; p >= (dst); --p)\ + for ( p = YY_G(yy_cp)-1; p >= (dst); --p)\ if ( *p == '\n' )\ --yylineno;\ }while(0) @@ -467,9 +472,9 @@ m4_ifdef( [[M4_YY_NOT_IN_HEADER]], /* Undo effects of setting up yytext. */ \ int yyless_macro_arg = (n); \ YY_LESS_LINENO(yyless_macro_arg);\ - *yy_cp = YY_G(yy_hold_char); \ + *YY_G(yy_cp) = YY_G(yy_hold_char); \ YY_RESTORE_YY_MORE_OFFSET \ - YY_G(yy_c_buf_p) = yy_cp = yy_bp + yyless_macro_arg - YY_MORE_ADJ; \ + YY_G(yy_c_buf_p) = YY_G(yy_cp) = YY_G(yy_bp) + yyless_macro_arg - YY_MORE_ADJ; \ YY_DO_BEFORE_ACTION; /* set up yytext again */ \ } \ while ( 0 ) @@ -590,6 +595,7 @@ int yyleng; /* Points to current character in buffer. */ static char *yy_c_buf_p = NULL; +static int yy_resume = 0; /**< resume after YY_STALLED */ static int yy_init = 0; /* whether we need to initialize */ static int yy_start = 0; /* start state number */ @@ -619,6 +625,7 @@ static void yy_init_buffer ( YY_BUFFER_STATE b, FILE *file M4_YY_PROTO_LAST_ARG YY_BUFFER_STATE yy_scan_buffer ( char *base, yy_size_t size M4_YY_PROTO_LAST_ARG ); YY_BUFFER_STATE yy_scan_string ( const char *yy_str M4_YY_PROTO_LAST_ARG ); YY_BUFFER_STATE yy_scan_bytes ( const char *bytes, int len M4_YY_PROTO_LAST_ARG ); +YY_BUFFER_STATE yy_append_bytes ( const char *bytes, int len M4_YY_PROTO_LAST_ARG ); %endif @@ -671,16 +678,22 @@ static void yynoreturn yy_fatal_error ( const char* msg M4_YY_PROTO_LAST_ARG ); m4_ifdef( [[M4_YY_NOT_IN_HEADER]], [[ +%if-not-reentrant +static char *yy_cp = NULL; /* */ +static char *yy_bp = NULL; /* */ +static yy_state_type yy_current_state = 0; +%endif + /* Done after the current pattern has been matched and before the * corresponding action - sets up yytext. */ #define YY_DO_BEFORE_ACTION \ - YY_G(yytext_ptr) = yy_bp; \ + YY_G(yytext_ptr) = YY_G(yy_bp); \ %% [2.0] code to fiddle yytext and yyleng for yymore() goes here \ - YY_G(yy_hold_char) = *yy_cp; \ - *yy_cp = '\0'; \ + YY_G(yy_hold_char) = *YY_G(yy_cp); \ + *YY_G(yy_cp) = '\0'; \ %% [3.0] code to copy yytext_ptr to yytext[] goes here, if %array \ - YY_G(yy_c_buf_p) = yy_cp; + YY_G(yy_c_buf_p) = YY_G(yy_cp); %% [4.0] data tables for the DFA and the user's section 1 definitions go here ]]) @@ -732,12 +745,15 @@ struct yyguts_t size_t yy_buffer_stack_top; /**< index of top of stack. */ size_t yy_buffer_stack_max; /**< capacity of stack. */ YY_BUFFER_STATE * yy_buffer_stack; /**< Stack as an array. */ - char yy_hold_char; - int yy_n_chars; - int yyleng_r; - char *yy_c_buf_p; - int yy_init; - int yy_start; + char yy_hold_char; /**< This variable holds the character that is replace by '\0' in order to terminate yytext (in-place in the buffer). */ + int yy_n_chars; /**< Number of characters read into yy_ch_buf. */ + int yyleng_r; /**< yyleng for current scanner */ + char *yy_c_buf_p; /**< Points to current character in buffer. */ + int yy_init; /**< whether we need to initialize */ + int yy_start; /**< start state number */ +#if defined(YY_STALLED) + int yy_resume; /**< resume after YY_STALLED */ +#endif /* defined(YY_STALLED) */ int yy_did_buffer_switch_on_eof; int yy_start_stack_ptr; int yy_start_stack_depth; @@ -746,7 +762,7 @@ struct yyguts_t char* yy_last_accepting_cpos; int yylineno_r; - int yy_flex_debug_r; + int yy_flex_debug_r; /**< yy_flex_debug for current scanner */ m4_ifdef( [[M4_YY_USES_REJECT]], [[ @@ -770,20 +786,23 @@ m4_ifdef( [[M4_YY_TEXT_IS_ARRAY]], int yy_prev_more_offset; ]], [[ - char *yytext_r; + char *yytext_r; /**< yytext for current scanner */ int yy_more_flag; int yy_more_len; ]]) m4_ifdef( [[M4_YY_BISON_LVAL]], [[ - YYSTYPE * yylval_r; + YYSTYPE * yylval_r; /**< yylval for current scanner */ ]]) m4_ifdef( [[]], [[ YYLTYPE * yylloc_r; ]]) + yy_state_type yy_current_state; + char *yy_cp; /**< */ + char *yy_bp; /**< */ }; /* end struct yyguts_t */ ]]) @@ -1188,8 +1207,6 @@ m4_ifdef( [[M4_YY_NOT_IN_HEADER]], */ YY_DECL { - yy_state_type yy_current_state; - char *yy_cp, *yy_bp; int yy_act; M4_YY_DECL_GUTS_VAR(); @@ -1218,6 +1235,9 @@ m4_ifdef( [[]], if ( !YY_G(yy_init) ) { YY_G(yy_init) = 1; +#if defined(YY_STALLED) + YY_G(yy_resume) = 0; +#endif /* defined(YY_STALLED) */ #ifdef YY_USER_INIT YY_USER_INIT; @@ -1263,18 +1283,25 @@ m4_ifdef( [[M4_YY_USES_REJECT]], { %% [7.0] user's declarations go here +#if defined(YY_STALLED) + if(YY_G(yy_resume)){ + YY_G(yy_resume)=0; + goto yy_match; + } +#endif /* defined(YY_STALLED) */ + while ( /*CONSTCOND*/1 ) /* loops until end-of-file is reached */ { %% [8.0] yymore()-related code goes here - yy_cp = YY_G(yy_c_buf_p); + YY_G(yy_cp) = YY_G(yy_c_buf_p); /* Support of yytext. */ - *yy_cp = YY_G(yy_hold_char); + *YY_G(yy_cp) = YY_G(yy_hold_char); /* yy_bp points to the position in yy_ch_buf of the start of * the current run. */ - yy_bp = yy_cp; + YY_G(yy_bp) = YY_G(yy_cp); %% [9.0] code to set up and find next match goes here @@ -1296,10 +1323,10 @@ 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 = (int) (yy_cp - YY_G(yytext_ptr)) - 1; + int yy_amount_of_matched_text = (int) (YY_G(yy_cp) - YY_G(yytext_ptr)) - 1; /* Undo the effects of YY_DO_BEFORE_ACTION. */ - *yy_cp = YY_G(yy_hold_char); + *YY_G(yy_cp) = YY_G(yy_hold_char); YY_RESTORE_YY_MORE_OFFSET if ( YY_CURRENT_BUFFER_LVALUE->yy_buffer_status == YY_BUFFER_NEW ) @@ -1336,7 +1363,7 @@ do_action: /* This label is used only to access EOF actions. */ YY_G(yy_c_buf_p) = YY_G(yytext_ptr) + yy_amount_of_matched_text; - yy_current_state = yy_get_previous_state( M4_YY_CALL_ONLY_ARG ); + YY_G(yy_current_state) = yy_get_previous_state( M4_YY_CALL_ONLY_ARG ); /* Okay, we're now positioned to make the NUL * transition. We couldn't have @@ -1347,15 +1374,15 @@ do_action: /* This label is used only to access EOF actions. */ * will run more slowly). */ - yy_next_state = yy_try_NUL_trans( yy_current_state M4_YY_CALL_LAST_ARG); + yy_next_state = yy_try_NUL_trans( YY_G(yy_current_state) M4_YY_CALL_LAST_ARG); - yy_bp = YY_G(yytext_ptr) + YY_MORE_ADJ; + YY_G(yy_bp) = YY_G(yytext_ptr) + YY_MORE_ADJ; if ( yy_next_state ) { /* Consume the NUL. */ - yy_cp = ++YY_G(yy_c_buf_p); - yy_current_state = yy_next_state; + YY_G(yy_cp) = ++YY_G(yy_c_buf_p); + YY_G(yy_current_state) = yy_next_state; goto yy_match; } @@ -1401,21 +1428,41 @@ do_action: /* This label is used only to access EOF actions. */ YY_G(yy_c_buf_p) = YY_G(yytext_ptr) + yy_amount_of_matched_text; - yy_current_state = yy_get_previous_state( M4_YY_CALL_ONLY_ARG ); + YY_G(yy_current_state) = yy_get_previous_state( M4_YY_CALL_ONLY_ARG ); - yy_cp = YY_G(yy_c_buf_p); - yy_bp = YY_G(yytext_ptr) + YY_MORE_ADJ; + YY_G(yy_cp) = YY_G(yy_c_buf_p); + YY_G(yy_bp) = YY_G(yytext_ptr) + YY_MORE_ADJ; goto yy_match; case EOB_ACT_LAST_MATCH: YY_G(yy_c_buf_p) = &YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[YY_G(yy_n_chars)]; - yy_current_state = yy_get_previous_state( M4_YY_CALL_ONLY_ARG ); + YY_G(yy_current_state) = yy_get_previous_state( M4_YY_CALL_ONLY_ARG ); - yy_cp = YY_G(yy_c_buf_p); - yy_bp = YY_G(yytext_ptr) + YY_MORE_ADJ; + YY_G(yy_cp) = YY_G(yy_c_buf_p); + YY_G(yy_bp) = YY_G(yytext_ptr) + YY_MORE_ADJ; goto yy_find_action; +#if defined(YY_STALLED) + case EOB_ACT_STALLED: + YY_G(yy_c_buf_p) = + YY_G(yytext_ptr) + yy_amount_of_matched_text; + + YY_G(yy_current_state) = yy_get_previous_state( M4_YY_CALL_ONLY_ARG ); + + YY_G(yy_cp) = YY_G(yy_c_buf_p); + YY_G(yy_bp) = YY_G(yytext_ptr) + YY_MORE_ADJ; + YY_G(yy_resume)=1; + + printf("yytext_ptr='%s'\n", YY_G(yytext_ptr)); + YY_BUFFER_STATE b = YY_CURRENT_BUFFER; +/* printf("yy_ch_buf[%d]=\n", b->yy_buf_size); + dump_buffer(b->yy_ch_buf, b->yy_buf_size);*/ + + printf("yy_current_state=%d\n", YY_G(yy_current_state)); + + return YY_STALLED; +#endif /* defined(YY_STALLED) */ } break; } @@ -1431,6 +1478,11 @@ do_action: /* This label is used only to access EOF actions. */ %if-c++-only %not-for-header +m4_ifdef( [[M4_YY_NO_YYWRAP]],, +[[ +int yyFlexLexer::yywrap() { return 1; } +]]) + /* The contents of this function are C++ specific, so the YY_G macro is not used. * This constructor simply maintains backward compatibility. * DEPRECATED @@ -1567,6 +1619,7 @@ m4_ifdef( [[M4_YY_NOT_IN_HEADER]], * EOB_ACT_LAST_MATCH - * EOB_ACT_CONTINUE_SCAN - continue scanning from current position * EOB_ACT_END_OF_FILE - end of file + * EOB_ACT_STALLED - push lexer stalled, needs more data to resume */ %if-c-only static int yy_get_next_buffer (M4_YY_DEF_ONLY_ARG) @@ -1581,6 +1634,12 @@ int yyFlexLexer::yy_get_next_buffer() int number_to_move, i; int ret_val; +#if defined(YY_STALLED) + if ( YY_CURRENT_BUFFER_LVALUE->yy_fill_buffer == 2 ){ + return EOB_ACT_STALLED; + } +#endif /* defined(YY_STALLED) */ + if ( YY_G(yy_c_buf_p) > &YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[YY_G(yy_n_chars) + 1] ) YY_FATAL_ERROR( "fatal flex scanner internal error--end of buffer missed" ); @@ -1726,18 +1785,16 @@ m4_ifdef( [[M4_YY_USES_REJECT]], yy_state_type yyFlexLexer::yy_get_previous_state() %endif { - yy_state_type yy_current_state; - char *yy_cp; M4_YY_DECL_GUTS_VAR(); %% [15.0] code to get the start state into yy_current_state goes here - for ( yy_cp = YY_G(yytext_ptr) + YY_MORE_ADJ; yy_cp < YY_G(yy_c_buf_p); ++yy_cp ) + for ( YY_G(yy_cp) = YY_G(yytext_ptr) + YY_MORE_ADJ; YY_G(yy_cp) < YY_G(yy_c_buf_p); ++YY_G(yy_cp) ) { %% [16.0] code to find the next state goes here } - return yy_current_state; + return YY_G(yy_current_state); } @@ -1747,18 +1804,19 @@ m4_ifdef( [[M4_YY_USES_REJECT]], * next_state = yy_try_NUL_trans( current_state ); */ %if-c-only - static yy_state_type yy_try_NUL_trans YYFARGS1( yy_state_type, yy_current_state) + static yy_state_type yy_try_NUL_trans YYFARGS1( yy_state_type, yy_cur_state) %endif %if-c++-only - yy_state_type yyFlexLexer::yy_try_NUL_trans( yy_state_type yy_current_state ) + yy_state_type yyFlexLexer::yy_try_NUL_trans( yy_state_type yy_cur_state ) %endif { int yy_is_jam; M4_YY_DECL_GUTS_VAR(); /* This var may be unused depending upon options. */ + YY_G(yy_current_state) = yy_cur_state; %% [17.0] code to find the next state, and perhaps do backing up, goes here M4_YY_NOOP_GUTS_VAR(); -return yy_is_jam ? 0 : yy_current_state; +return yy_is_jam ? 0 : YY_G(yy_current_state); } @@ -2402,6 +2460,101 @@ YY_BUFFER_STATE yy_scan_bytes YYFARGS2( const char *,yybytes, int ,_yybytes_len ]]) +m4_ifdef( [[M4_YY_NO_APPEND_BYTES]],, +[[ +%if-c-only +YY_BUFFER_STATE yy_append_bytes YYFARGS2( const char *,yybytes, int ,_yybytes_len) +%endif +%if-c++-only + YY_BUFFER_STATE yyFlexLexer::yy_append_bytes( const char * yybytes, int _yybytes_len ) +%endif +{ + M4_YY_DECL_GUTS_VAR(); + YY_BUFFER_STATE b = YY_CURRENT_BUFFER; + char *buf; + int bNeedSwitchBuffer = 0; + + if(!b){ + b = (YY_BUFFER_STATE) yyalloc( sizeof( struct yy_buffer_state ) M4_YY_CALL_LAST_ARG ); + if ( ! b ) + YY_FATAL_ERROR( "out of dynamic memory in yy_scan_buffer()" ); + + b->yy_buf_size = 0; + b->yy_buf_pos = b->yy_ch_buf = NULL; + b->yy_is_our_buffer = 1; + b->yy_input_file = NULL; + b->yy_n_chars = 0; + b->yy_is_interactive = 0; + b->yy_at_bol = 1; + b->yy_fill_buffer = 2; + b->yy_buffer_status = YY_BUFFER_NEW; + + bNeedSwitchBuffer = 1; + }else{ + printf("Entering yy_append_bytes buf@%p:%d:%d\n", b->yy_ch_buf, b->yy_buf_size, b->yy_n_chars); +/* dump_buffer(b->yy_ch_buf, b->yy_n_chars+2);*/ + } + +// Do we need more room? + if(b->yy_n_chars+_yybytes_len>b->yy_buf_size){ // First try some clean up + // Chars before yytext_ptr aren't acutally needed any more. + int cbp_offs = YY_G(yy_c_buf_p) - YY_G(yytext_ptr); + int cp_offs = YY_G(yy_cp) - YY_G(yytext_ptr); + int bp_offs = YY_G(yy_bp) - YY_G(yytext_ptr); + int nbActive = b->yy_n_chars - (YY_G(yytext_ptr) - b->yy_ch_buf); + int cnt; + printf("Moving %d character(s) back %d places.\n", nbActive, (int)(YY_G(yytext_ptr) - b->yy_ch_buf)); + for(cnt=0;cntyy_ch_buf[cnt] = YY_G(yytext_ptr)[cnt]; + } + + YY_G(yytext_ptr) = b->yy_ch_buf; + YY_G(yy_c_buf_p) = YY_G(yytext_ptr) + cbp_offs; + YY_G(yy_cp) = YY_G(yytext_ptr) + cp_offs; + YY_G(yy_bp) = YY_G(yytext_ptr) + bp_offs; + b->yy_n_chars = nbActive; + } + + if(b->yy_n_chars+_yybytes_len>b->yy_buf_size){ // If clean up wasn't enough, let's allocate more memory +// printf("~~~ yy_append_bytes MUST realloc\n"); + printf("~~~ yy_append_bytes reallocating\n"); + int cbp_offs = YY_G(yy_c_buf_p) - b->yy_ch_buf; + int cp_offs = YY_G(yy_cp) - b->yy_ch_buf; + int bp_offs = YY_G(yy_bp) - b->yy_ch_buf; + int text_offs = YY_G(yytext_ptr) - b->yy_ch_buf; + int new_size = b->yy_buf_size*2; + if(new_sizeyy_n_chars+_yybytes_len){new_size = b->yy_n_chars+_yybytes_len;} + if(new_size<256){new_size=256;} + buf = (char *) yyrealloc( b->yy_ch_buf, new_size+2 M4_YY_CALL_LAST_ARG ); + if ( ! buf ) + YY_FATAL_ERROR( "out of dynamic memory in yy_scan_bytes()" ); + b->yy_ch_buf = buf; + b->yy_buf_size = new_size; + YY_G(yy_c_buf_p) = b->yy_ch_buf + cbp_offs; + YY_G(yy_cp) = b->yy_ch_buf + cp_offs; + YY_G(yy_bp) = b->yy_ch_buf + bp_offs; + YY_G(yytext_ptr) = b->yy_ch_buf + text_offs; + } + + for(int cnt=0; cnt<_yybytes_len; cnt++){ + b->yy_ch_buf[b->yy_n_chars+cnt] = yybytes[cnt]; + } + b->yy_n_chars += _yybytes_len; + b->yy_ch_buf[b->yy_n_chars] = b->yy_ch_buf[b->yy_n_chars+1] = YY_END_OF_BUFFER_CHAR; + + if(bNeedSwitchBuffer){ + b->yy_buf_pos = b->yy_ch_buf; + yy_switch_to_buffer( b M4_YY_CALL_LAST_ARG ); + } + + printf("Leaving yy_append_bytes buf@%p:%d:%d\n", b->yy_ch_buf, b->yy_buf_size, b->yy_n_chars); +/* dump_buffer(b->yy_ch_buf, b->yy_n_chars+2);*/ + + return b; +} +]]) + + m4_ifdef( [[M4_YY_NO_PUSH_STATE]],, [[ %if-c-only diff --git a/src/flexdef.h b/src/flexdef.h index a48c64d1e..1759f9784 100644 --- a/src/flexdef.h +++ b/src/flexdef.h @@ -385,6 +385,7 @@ extern int trace_hex; * did_outfilename - whether outfilename was explicitly set * prefix - the prefix used for externally visible names ("yy" by default) * yyclass - yyFlexLexer subclass to use for YY_DECL + * yystall - value to return when push lexer is stalled * do_stdinit - whether to initialize yyin/yyout to stdin/stdout * use_stdout - the -t flag * input_files - array holding names of input files @@ -408,6 +409,7 @@ extern int skel_ind; extern char *infilename, *outfilename, *headerfilename; extern int did_outfilename; extern char *prefix, *yyclass, *extra_type; +extern char *yystall; extern int do_stdinit, use_stdout; extern char **input_files; extern int num_input_files; diff --git a/src/gen.c b/src/gen.c index c959f75bc..5d23100f5 100644 --- a/src/gen.c +++ b/src/gen.c @@ -153,14 +153,14 @@ void gen_backing_up (void) return; if (fullspd) - indent_puts ("if ( yy_current_state[-1].yy_nxt )"); + indent_puts ("if ( YY_G(yy_current_state)[-1].yy_nxt )"); else - indent_puts ("if ( yy_accept[yy_current_state] )"); + indent_puts ("if ( yy_accept[YY_G(yy_current_state)] )"); ++indent_level; indent_puts ("{"); - indent_puts ("YY_G(yy_last_accepting_state) = yy_current_state;"); - indent_puts ("YY_G(yy_last_accepting_cpos) = yy_cp;"); + indent_puts ("YY_G(yy_last_accepting_state) = YY_G(yy_current_state);"); + indent_puts ("YY_G(yy_last_accepting_cpos) = YY_G(yy_cp);"); indent_puts ("}"); --indent_level; } @@ -177,17 +177,17 @@ void gen_bu_action (void) indent_puts ("case 0: /* must back up */"); indent_puts ("/* undo the effects of YY_DO_BEFORE_ACTION */"); - indent_puts ("*yy_cp = YY_G(yy_hold_char);"); + indent_puts ("*YY_G(yy_cp) = YY_G(yy_hold_char);"); if (fullspd || fulltbl) - indent_puts ("yy_cp = YY_G(yy_last_accepting_cpos) + 1;"); + indent_puts ("YY_G(yy_cp) = YY_G(yy_last_accepting_cpos) + 1;"); else /* Backing-up info for compressed tables is taken \after/ * yy_cp has been incremented for the next state. */ - indent_puts ("yy_cp = YY_G(yy_last_accepting_cpos);"); + indent_puts ("YY_G(yy_cp) = YY_G(yy_last_accepting_cpos);"); - indent_puts ("yy_current_state = YY_G(yy_last_accepting_state);"); + indent_puts ("YY_G(yy_current_state) = YY_G(yy_last_accepting_state);"); indent_puts ("goto yy_find_action;"); outc ('\n'); @@ -501,14 +501,14 @@ void genecs (void) void gen_find_action (void) { if (fullspd) - indent_puts ("yy_act = yy_current_state[-1].yy_nxt;"); + indent_puts ("yy_act = YY_G(yy_current_state)[-1].yy_nxt;"); else if (fulltbl) - indent_puts ("yy_act = yy_accept[yy_current_state];"); + indent_puts ("yy_act = yy_accept[YY_G(yy_current_state)];"); else if (reject) { - indent_puts ("yy_current_state = *--YY_G(yy_state_ptr);"); - indent_puts ("YY_G(yy_lp) = yy_accept[yy_current_state];"); + indent_puts ("YY_G(yy_current_state) = *--YY_G(yy_state_ptr);"); + indent_puts ("YY_G(yy_lp) = yy_accept[YY_G(yy_current_state)];"); if (!variable_trailing_context_rules) outn ("m4_ifdef( [[M4_YY_USES_REJECT]],\n[["); @@ -525,7 +525,7 @@ void gen_find_action (void) indent_puts ("{"); indent_puts - ("if ( YY_G(yy_lp) && YY_G(yy_lp) < yy_accept[yy_current_state + 1] )"); + ("if ( YY_G(yy_lp) && YY_G(yy_lp) < yy_accept[YY_G(yy_current_state) + 1] )"); ++indent_level; indent_puts ("{"); indent_puts ("yy_act = yy_acclist[YY_G(yy_lp)];"); @@ -564,7 +564,7 @@ void gen_find_action (void) * due to REJECT. */ indent_puts - ("YY_G(yy_full_match) = yy_cp;"); + ("YY_G(yy_full_match) = YY_G(yy_cp);"); indent_puts ("YY_G(yy_full_state) = YY_G(yy_state_ptr);"); indent_puts ("YY_G(yy_full_lp) = YY_G(yy_lp);"); @@ -576,7 +576,7 @@ void gen_find_action (void) indent_puts ("else"); ++indent_level; indent_puts ("{"); - indent_puts ("YY_G(yy_full_match) = yy_cp;"); + indent_puts ("YY_G(yy_full_match) = YY_G(yy_cp);"); indent_puts ("YY_G(yy_full_state) = YY_G(yy_state_ptr);"); indent_puts ("YY_G(yy_full_lp) = YY_G(yy_lp);"); @@ -594,7 +594,7 @@ void gen_find_action (void) */ ++indent_level; indent_puts ("{"); - indent_puts ("YY_G(yy_full_match) = yy_cp;"); + indent_puts ("YY_G(yy_full_match) = YY_G(yy_cp);"); indent_puts ("break;"); indent_puts ("}"); --indent_level; @@ -603,14 +603,14 @@ void gen_find_action (void) indent_puts ("}"); --indent_level; - indent_puts ("--yy_cp;"); + indent_puts ("--YY_G(yy_cp);"); /* We could consolidate the following two lines with those at * the beginning, but at the cost of complaints that we're * branching inside a loop. */ - indent_puts ("yy_current_state = *--YY_G(yy_state_ptr);"); - indent_puts ("YY_G(yy_lp) = yy_accept[yy_current_state];"); + indent_puts ("YY_G(yy_current_state) = *--YY_G(yy_state_ptr);"); + indent_puts ("YY_G(yy_lp) = yy_accept[YY_G(yy_current_state)];"); indent_puts ("}"); @@ -618,7 +618,7 @@ void gen_find_action (void) } else { /* compressed */ - indent_puts ("yy_act = yy_accept[yy_current_state];"); + indent_puts ("yy_act = yy_accept[YY_G(yy_current_state)];"); if (interactive && !reject) { /* Do the guaranteed-needed backing up to figure out @@ -628,11 +628,11 @@ void gen_find_action (void) ++indent_level; indent_puts ("{ /* have to back up */"); indent_puts - ("yy_cp = YY_G(yy_last_accepting_cpos);"); + ("YY_G(yy_cp) = YY_G(yy_last_accepting_cpos);"); indent_puts - ("yy_current_state = YY_G(yy_last_accepting_state);"); + ("YY_G(yy_current_state) = YY_G(yy_last_accepting_state);"); indent_puts - ("yy_act = yy_accept[yy_current_state];"); + ("yy_act = yy_accept[YY_G(yy_current_state)];"); indent_puts ("}"); --indent_level; } @@ -724,10 +724,10 @@ void gen_next_compressed_state (char *char_map) gen_backing_up (); indent_puts - ("while ( yy_chk[yy_base[yy_current_state] + yy_c] != yy_current_state )"); + ("while ( yy_chk[yy_base[YY_G(yy_current_state)] + yy_c] != YY_G(yy_current_state) )"); ++indent_level; indent_puts ("{"); - indent_puts ("yy_current_state = (int) yy_def[yy_current_state];"); + indent_puts ("YY_G(yy_current_state) = (int) yy_def[YY_G(yy_current_state)];"); if (usemecs) { /* We've arrange it so that templates are never chained @@ -740,7 +740,7 @@ void gen_next_compressed_state (char *char_map) do_indent (); /* lastdfa + 2 is the beginning of the templates */ - out_dec ("if ( yy_current_state >= %d )\n", lastdfa + 2); + out_dec ("if ( YY_G(yy_current_state) >= %d )\n", lastdfa + 2); ++indent_level; indent_puts ("yy_c = yy_meta[yy_c];"); @@ -751,7 +751,7 @@ void gen_next_compressed_state (char *char_map) --indent_level; indent_puts - ("yy_current_state = yy_nxt[yy_base[yy_current_state] + yy_c];"); + ("YY_G(yy_current_state) = yy_nxt[yy_base[YY_G(yy_current_state)] + yy_c];"); } @@ -763,19 +763,19 @@ void gen_next_match (void) * gen_NUL_trans(). */ char *char_map = useecs ? - "yy_ec[YY_SC_TO_UI(*yy_cp)] " : "YY_SC_TO_UI(*yy_cp)"; + "yy_ec[YY_SC_TO_UI(*YY_G(yy_cp))] " : "YY_SC_TO_UI(*YY_G(yy_cp))"; char *char_map_2 = useecs ? - "yy_ec[YY_SC_TO_UI(*++yy_cp)] " : "YY_SC_TO_UI(*++yy_cp)"; + "yy_ec[YY_SC_TO_UI(*++YY_G(yy_cp))] " : "YY_SC_TO_UI(*++YY_G(yy_cp))"; if (fulltbl) { if (gentables) indent_put2s - ("while ( (yy_current_state = yy_nxt[yy_current_state][ %s ]) > 0 )", + ("while ( (YY_G(yy_current_state) = yy_nxt[YY_G(yy_current_state)][ %s ]) > 0 )", char_map); else indent_put2s - ("while ( (yy_current_state = yy_nxt[yy_current_state*YY_NXT_LOLEN + %s ]) > 0 )", + ("while ( (YY_G(yy_current_state) = yy_nxt[YY_G(yy_current_state)*YY_NXT_LOLEN + %s ]) > 0 )", char_map); ++indent_level; @@ -786,7 +786,7 @@ void gen_next_match (void) outc ('\n'); } - indent_puts ("++yy_cp;"); + indent_puts ("++YY_G(yy_cp);"); if (num_backing_up > 0) @@ -795,7 +795,7 @@ void gen_next_match (void) --indent_level; outc ('\n'); - indent_puts ("yy_current_state = -yy_current_state;"); + indent_puts ("YY_G(yy_current_state) = -YY_G(yy_current_state);"); } else if (fullspd) { @@ -805,7 +805,7 @@ void gen_next_match (void) indent_puts ("YY_CHAR yy_c;\n"); indent_put2s ("for ( yy_c = %s;", char_map); indent_puts - (" (yy_trans_info = &yy_current_state[yy_c])->"); + (" (yy_trans_info = &YY_G(yy_current_state)[yy_c])->"); indent_puts ("yy_verify == yy_c;"); indent_put2s (" yy_c = %s )", char_map_2); @@ -814,7 +814,7 @@ void gen_next_match (void) if (num_backing_up > 0) indent_puts ("{"); - indent_puts ("yy_current_state += yy_trans_info->yy_nxt;"); + indent_puts ("YY_G(yy_current_state) += yy_trans_info->yy_nxt;"); if (num_backing_up > 0) { outc ('\n'); @@ -834,7 +834,7 @@ void gen_next_match (void) gen_next_state (false); - indent_puts ("++yy_cp;"); + indent_puts ("++YY_G(yy_cp);"); indent_puts ("}"); @@ -843,9 +843,9 @@ void gen_next_match (void) do_indent (); if (interactive) - out_dec ("while ( yy_base[yy_current_state] != %d );\n", jambase); + out_dec ("while ( yy_base[YY_G(yy_current_state)] != %d );\n", jambase); else - out_dec ("while ( yy_current_state != %d );\n", + out_dec ("while ( YY_G(yy_current_state) != %d );\n", jamstate); if (!reject && !interactive) { @@ -853,9 +853,9 @@ void gen_next_match (void) * the match. */ indent_puts - ("yy_cp = YY_G(yy_last_accepting_cpos);"); + ("YY_G(yy_cp) = YY_G(yy_last_accepting_cpos);"); indent_puts - ("yy_current_state = YY_G(yy_last_accepting_state);"); + ("YY_G(yy_current_state) = YY_G(yy_last_accepting_state);"); } } } @@ -870,25 +870,25 @@ void gen_next_state (int worry_about_NULs) if (worry_about_NULs && !nultrans) { if (useecs) snprintf (char_map, sizeof(char_map), - "(*yy_cp ? yy_ec[YY_SC_TO_UI(*yy_cp)] : %d)", + "(*YY_G(yy_cp) ? yy_ec[YY_SC_TO_UI(*YY_G(yy_cp))] : %d)", NUL_ec); else snprintf (char_map, sizeof(char_map), - "(*yy_cp ? YY_SC_TO_UI(*yy_cp) : %d)", + "(*YY_G(yy_cp) ? YY_SC_TO_UI(*YY_G(yy_cp)) : %d)", NUL_ec); } else strcpy (char_map, useecs ? - "yy_ec[YY_SC_TO_UI(*yy_cp)] " : - "YY_SC_TO_UI(*yy_cp)"); + "yy_ec[YY_SC_TO_UI(*YY_G(yy_cp))] " : + "YY_SC_TO_UI(*YY_G(yy_cp))"); if (worry_about_NULs && nultrans) { if (!fulltbl && !fullspd) /* Compressed tables back up *before* they match. */ gen_backing_up (); - indent_puts ("if ( *yy_cp )"); + indent_puts ("if ( *YY_G(yy_cp) )"); ++indent_level; indent_puts ("{"); } @@ -896,17 +896,17 @@ void gen_next_state (int worry_about_NULs) if (fulltbl) { if (gentables) indent_put2s - ("yy_current_state = yy_nxt[yy_current_state][%s];", + ("YY_G(yy_current_state) = yy_nxt[YY_G(yy_current_state)][%s];", char_map); else indent_put2s - ("yy_current_state = yy_nxt[yy_current_state*YY_NXT_LOLEN + %s];", + ("YY_G(yy_current_state) = yy_nxt[YY_G(yy_current_state)*YY_NXT_LOLEN + %s];", char_map); } else if (fullspd) indent_put2s - ("yy_current_state += yy_current_state[%s].yy_nxt;", + ("YY_G(yy_current_state) += YY_G(yy_current_state)[%s].yy_nxt;", char_map); else @@ -919,7 +919,7 @@ void gen_next_state (int worry_about_NULs) indent_puts ("else"); ++indent_level; indent_puts - ("yy_current_state = yy_NUL_trans[yy_current_state];"); + ("YY_G(yy_current_state) = yy_NUL_trans[YY_G(yy_current_state)];"); --indent_level; } @@ -927,7 +927,7 @@ void gen_next_state (int worry_about_NULs) gen_backing_up (); if (reject) - indent_puts ("*YY_G(yy_state_ptr)++ = yy_current_state;"); + indent_puts ("*YY_G(yy_state_ptr)++ = YY_G(yy_current_state);"); } @@ -944,23 +944,23 @@ void gen_NUL_trans (void) /* We're going to need yy_cp lying around for the call * below to gen_backing_up(). */ - indent_puts ("char *yy_cp = YY_G(yy_c_buf_p);"); + indent_puts ("YY_G(yy_cp) = YY_G(yy_c_buf_p);"); outc ('\n'); if (nultrans) { indent_puts - ("yy_current_state = yy_NUL_trans[yy_current_state];"); - indent_puts ("yy_is_jam = (yy_current_state == 0);"); + ("YY_G(yy_current_state) = yy_NUL_trans[YY_G(yy_current_state)];"); + indent_puts ("yy_is_jam = (YY_G(yy_current_state) == 0);"); } else if (fulltbl) { do_indent (); if (gentables) - out_dec ("yy_current_state = yy_nxt[yy_current_state][%d];\n", NUL_ec); + out_dec ("YY_G(yy_current_state) = yy_nxt[YY_G(yy_current_state)][%d];\n", NUL_ec); else - out_dec ("yy_current_state = yy_nxt[yy_current_state*YY_NXT_LOLEN + %d];\n", NUL_ec); - indent_puts ("yy_is_jam = (yy_current_state <= 0);"); + out_dec ("YY_G(yy_current_state) = yy_nxt[YY_G(yy_current_state)*YY_NXT_LOLEN + %d];\n", NUL_ec); + indent_puts ("yy_is_jam = (YY_G(yy_current_state) <= 0);"); } else if (fullspd) { @@ -970,8 +970,8 @@ void gen_NUL_trans (void) indent_puts ("const struct yy_trans_info *yy_trans_info;\n"); indent_puts - ("yy_trans_info = &yy_current_state[(unsigned int) yy_c];"); - indent_puts ("yy_current_state += yy_trans_info->yy_nxt;"); + ("yy_trans_info = &YY_G(yy_current_state)[(unsigned int) yy_c];"); + indent_puts ("YY_G(yy_current_state) += yy_trans_info->yy_nxt;"); indent_puts ("yy_is_jam = (yy_trans_info->yy_verify != yy_c);"); @@ -984,7 +984,7 @@ void gen_NUL_trans (void) gen_next_compressed_state (NUL_ec_str); do_indent (); - out_dec ("yy_is_jam = (yy_current_state == %d);\n", + out_dec ("yy_is_jam = (YY_G(yy_current_state) == %d);\n", jamstate); if (reject) { @@ -995,7 +995,7 @@ void gen_NUL_trans (void) indent_puts ("if ( ! yy_is_jam )"); ++indent_level; indent_puts - ("*YY_G(yy_state_ptr)++ = yy_current_state;"); + ("*YY_G(yy_state_ptr)++ = YY_G(yy_current_state);"); --indent_level; } } @@ -1023,18 +1023,18 @@ void gen_start_state (void) if (fullspd) { if (bol_needed) { indent_puts - ("yy_current_state = yy_start_state_list[YY_G(yy_start) + YY_AT_BOL()];"); + ("YY_G(yy_current_state) = yy_start_state_list[YY_G(yy_start) + YY_AT_BOL()];"); } else indent_puts - ("yy_current_state = yy_start_state_list[YY_G(yy_start)];"); + ("YY_G(yy_current_state) = yy_start_state_list[YY_G(yy_start)];"); } else { - indent_puts ("yy_current_state = YY_G(yy_start);"); + indent_puts ("YY_G(yy_current_state) = YY_G(yy_start);"); if (bol_needed) - indent_puts ("yy_current_state += YY_AT_BOL();"); + indent_puts ("YY_G(yy_current_state) += YY_AT_BOL();"); if (reject) { /* Set up for storing up states. */ @@ -1042,7 +1042,7 @@ void gen_start_state (void) indent_puts ("YY_G(yy_state_ptr) = YY_G(yy_state_buf);"); indent_puts - ("*YY_G(yy_state_ptr)++ = yy_current_state;"); + ("*YY_G(yy_state_ptr)++ = YY_G(yy_current_state);"); outn ("]])"); } } @@ -1506,11 +1506,11 @@ void make_tables (void) if (yymore_used && !yytext_is_array) { indent_puts ("YY_G(yytext_ptr) -= YY_G(yy_more_len); \\"); indent_puts - ("yyleng = (int) (yy_cp - YY_G(yytext_ptr)); \\"); + ("yyleng = (int) (YY_G(yy_cp) - YY_G(yytext_ptr)); \\"); } else - indent_puts ("yyleng = (int) (yy_cp - yy_bp); \\"); + indent_puts ("yyleng = (int) (YY_G(yy_cp) - YY_G(yy_bp)); \\"); /* Now also deal with copying yytext_ptr to yytext if needed. */ skelout (); /* %% [3.0] - break point in skel */ @@ -1769,13 +1769,13 @@ void make_tables (void) outn ("#define REJECT \\"); outn ("{ \\"); - outn ("*yy_cp = YY_G(yy_hold_char); /* undo effects of setting up yytext */ \\"); - outn ("yy_cp = YY_G(yy_full_match); /* restore poss. backed-over text */ \\"); + outn ("*YY_G(yy_cp) = YY_G(yy_hold_char); /* undo effects of setting up yytext */ \\"); + outn ("YY_G(yy_cp) = YY_G(yy_full_match); /* restore poss. backed-over text */ \\"); if (variable_trailing_context_rules) { outn ("YY_G(yy_lp) = YY_G(yy_full_lp); /* restore orig. accepting pos. */ \\"); outn ("YY_G(yy_state_ptr) = YY_G(yy_full_state); /* restore orig. state */ \\"); - outn ("yy_current_state = *YY_G(yy_state_ptr); /* restore curr. state */ \\"); + outn ("YY_G(yy_current_state) = *YY_G(yy_state_ptr); /* restore curr. state */ \\"); } outn ("++YY_G(yy_lp); \\"); @@ -2088,7 +2088,7 @@ void make_tables (void) set_indent (4); if (fullspd || fulltbl) - indent_puts ("yy_cp = YY_G(yy_c_buf_p);"); + indent_puts ("YY_G(yy_cp) = YY_G(yy_c_buf_p);"); else { /* compressed table */ if (!reject && !interactive) { @@ -2096,9 +2096,9 @@ void make_tables (void) * out the match. */ indent_puts - ("yy_cp = YY_G(yy_last_accepting_cpos);"); + ("YY_G(yy_cp) = YY_G(yy_last_accepting_cpos);"); indent_puts - ("yy_current_state = YY_G(yy_last_accepting_state);"); + ("YY_G(yy_current_state) = YY_G(yy_last_accepting_state);"); } else @@ -2106,7 +2106,7 @@ void make_tables (void) * yy_current_state was set up by * yy_get_previous_state(). */ - indent_puts ("yy_cp = YY_G(yy_c_buf_p);"); + indent_puts ("YY_G(yy_cp) = YY_G(yy_c_buf_p);"); } diff --git a/src/main.c b/src/main.c index a4047d7be..2eb0c2d89 100644 --- a/src/main.c +++ b/src/main.c @@ -67,6 +67,7 @@ int action_size, defs1_offset, prolog_offset, action_offset, char *infilename = NULL, *outfilename = NULL, *headerfilename = NULL; int did_outfilename; char *prefix, *yyclass, *extra_type = NULL; +char *yystall = NULL; int do_stdinit, use_stdout; int onestate[ONE_STACK_SIZE], onesym[ONE_STACK_SIZE]; int onenext[ONE_STACK_SIZE], onedef[ONE_STACK_SIZE], onesp; @@ -964,6 +965,7 @@ void flexinit (int argc, char **argv) did_outfilename = 0; prefix = "yy"; yyclass = 0; + yystall = NULL; use_read = use_stdout = false; tablesext = tablesverify = false; gentables = true; @@ -1317,6 +1319,10 @@ void flexinit (int argc, char **argv) yyclass = arg; break; + case OPT_YYSTALL: + yystall = arg; + break; + case OPT_YYLINENO: do_yylineno = true; break; @@ -1450,6 +1456,12 @@ void flexinit (int argc, char **argv) } /* switch */ } /* while scanopt() */ +// if(do_yywrap){ +// buf_m4_define( &m4defs_buf, "M4_YY_NO_YYWRAP",NULL); +// } + fprintf(stderr, ">>> do_yywrap = %d\n", do_yywrap); + buf_m4_define( &m4defs_buf, "M4_YY_NO_YYWRAP",do_yywrap?"1":NULL); + scanopt_destroy (sopt); num_input_files = argc - optind; @@ -1612,6 +1624,9 @@ void readin (void) if (ddebug) outn ("\n#define FLEX_DEBUG"); + if(yystall) + out_str ("\n#define YY_STALLED %s\n", yystall); // XYZ + OUT_BEGIN_CODE (); outn ("typedef flex_uint8_t YY_CHAR;"); OUT_END_CODE (); @@ -1675,9 +1690,10 @@ void readin (void) if (C_plus_plus) { outn ("\n#include "); - if (!do_yywrap) { - outn("\nint yyFlexLexer::yywrap() { return 1; }"); - } +// if(do_yywrap){ +// buf_m4_define( &m4defs_buf, "M4_YY_NO_YYWRAP",NULL); +// } +// fprintf(stderr, ">>> do_yywrap = %d\n", do_yywrap); if (yyclass) { outn ("int yyFlexLexer::yylex()"); @@ -1831,6 +1847,7 @@ void usage (void) " -S, --skel=FILE specify skeleton file\n" " -t, --stdout write scanner on stdout instead of %s\n" " --yyclass=NAME name of C++ class\n" + " --yystall=VALUE value to return when the push lexer is stalled\n" " --header-file=FILE create a C header file in addition to the scanner\n" " --tables-file[=FILE] write tables to FILE\n" " --backup-file=FILE write backing-up information to FILE\n" "\n" diff --git a/src/options.c b/src/options.c index e98159c4c..e967b03ff 100644 --- a/src/options.c +++ b/src/options.c @@ -226,6 +226,8 @@ optspec_t flexopts[] = { , {"--noyymore", OPT_NO_YYMORE, 0} , + {"--yystall=VALUE", OPT_YYSTALL, 0} + , {"--noyywrap", OPT_NO_YYWRAP, 0} , {"--yywrap", OPT_YYWRAP, 0} diff --git a/src/options.h b/src/options.h index acee2753a..96fd8018b 100644 --- a/src/options.h +++ b/src/options.h @@ -128,6 +128,7 @@ enum flexopt_flag_t { OPT_YYCLASS, OPT_YYLINENO, OPT_YYMORE, + OPT_YYSTALL, OPT_YYWRAP, OPT_NO_SECT3_ESCAPE, }; diff --git a/src/parse.y b/src/parse.y index 5a0732066..1295ad777 100644 --- a/src/parse.y +++ b/src/parse.y @@ -1,7 +1,7 @@ /* parse.y - parser for flex input */ %token CHAR NUMBER SECTEND SCDECL XSCDECL NAME PREVCCL EOF_OP -%token TOK_OPTION TOK_OUTFILE TOK_PREFIX TOK_YYCLASS TOK_HEADER_FILE TOK_EXTRA_TYPE +%token TOK_OPTION TOK_OUTFILE TOK_PREFIX TOK_YYCLASS TOK_YYSTALL TOK_HEADER_FILE TOK_EXTRA_TYPE %token TOK_TABLES_FILE %token CCE_ALNUM CCE_ALPHA CCE_BLANK CCE_CNTRL CCE_DIGIT CCE_GRAPH @@ -204,6 +204,8 @@ option : TOK_OUTFILE '=' NAME flexerror(_("Prefix must not contain [ or ]")); } | TOK_YYCLASS '=' NAME { yyclass = xstrdup(nmstr); } + | TOK_YYSTALL '=' NAME + { yystall = xstrdup(nmstr); } | TOK_HEADER_FILE '=' NAME { headerfilename = xstrdup(nmstr); } | TOK_TABLES_FILE '=' NAME diff --git a/src/scan.l b/src/scan.l index f4b44b825..c2737fc5a 100644 --- a/src/scan.l +++ b/src/scan.l @@ -396,8 +396,10 @@ M4QEND "]""]" main { ACTION_M4_IFDEF( "M4""_YY_MAIN", option_sense); /* Override yywrap */ - if( option_sense == true ) + if( option_sense == true ){ do_yywrap = false; + ACTION_M4_IFDEF("M4""_YY_NO_YYWRAP", NULL); + } } meta-ecs usemecs = option_sense; never-interactive { @@ -418,7 +420,7 @@ M4QEND "]""]" warn nowarn = ! option_sense; yylineno do_yylineno = option_sense; ACTION_M4_IFDEF("M4""_YY_USE_LINENO", option_sense); yymore yymore_really_used = option_sense; - yywrap do_yywrap = option_sense; + yywrap {do_yywrap = option_sense; ACTION_M4_IFDEF("M4""_YY_NO_YYWRAP", option_sense);} yy_push_state ACTION_M4_IFDEF("M4""_YY_NO_PUSH_STATE", ! option_sense); yy_pop_state ACTION_M4_IFDEF("M4""_YY_NO_POP_STATE", ! option_sense); @@ -455,6 +457,7 @@ M4QEND "]""]" outfile return TOK_OUTFILE; prefix return TOK_PREFIX; yyclass return TOK_YYCLASS; + yystall return TOK_YYSTALL; header(-file)? return TOK_HEADER_FILE; tables-file return TOK_TABLES_FILE; tables-verify { diff --git a/tests/Makefile.am b/tests/Makefile.am index 65f9d65a8..f2c5aa3b7 100644 --- a/tests/Makefile.am +++ b/tests/Makefile.am @@ -62,18 +62,26 @@ check_PROGRAMS = $(simple_tests) $(reject_tests) $(TABLE_TESTS) $(DIRECT_TESTS) simple_tests = \ alloc_extra \ + alloc_extra_p \ array_nr \ + array_nrp \ array_r \ + array_rp \ basic_nr \ basic_r \ + basic_rp \ bison_nr \ + bison_nrp \ bison_yylloc \ + bison_yylloc_p \ bison_yylval \ + bison_yylval_p \ c_cxx_nr \ c_cxx_r \ ccl \ cxx_basic \ cxx_multiple_scanners \ + cxx_multiple_scanners_p \ cxx_restart \ debug_nr \ debug_r \ @@ -123,21 +131,34 @@ ONE_TESTS = \ quote_in_comment_SOURCES = quote_in_comment.l alloc_extra_SOURCES = alloc_extra.l +alloc_extra_p_SOURCES = alloc_extra_p.l array_nr_SOURCES = array_nr.l +array_nrp_SOURCES = array_nrp.l array_r_SOURCES = array_r.l +array_rp_SOURCES = array_rp.l basic_nr_SOURCES = basic_nr.l basic_r_SOURCES = basic_r.l +basic_rp_SOURCES = basic_rp.l if HAVE_BISON bison_nr_SOURCES = bison_nr_scanner.l bison_nr_parser.y bison_nr_main.c nodist_bison_nr_SOURCES = bison_nr_parser.h bison_nr_scanner.h +bison_nrp_SOURCES = bison_nrp_scanner.l bison_nrp_parser.y bison_nrp_main.c +nodist_bison_nrp_SOURCES = bison_nrp_parser.h bison_nrp_scanner.h bison_yylloc_SOURCES = bison_yylloc_scanner.l bison_yylloc_parser.y bison_yylloc_main.c nodist_bison_yylloc_SOURCES = bison_yylloc_parser.h bison_yylloc_scanner.h +bison_yylloc_p_SOURCES = bison_yylloc_scanner_p.l bison_yylloc_parser_p.y bison_yylloc_main_p.c +nodist_bison_yylloc_p_SOURCES = bison_yylloc_parser_p.h bison_yylloc_scanner_p.h bison_yylval_SOURCES = bison_yylval_scanner.l bison_yylval_parser.y bison_yylval_main.c nodist_bison_yylval_SOURCES = bison_yylval_parser.h bison_yylval_scanner.h +bison_yylval_p_SOURCES = bison_yylval_scanner_p.l bison_yylval_parser_p.y bison_yylval_main_p.c +nodist_bison_p_yylval_SOURCES = bison_yylval_parser_p.h bison_yylval_scanner_p.h else bison_nr_SOURCES = no_bison_stub.c +bison_nrp_SOURCES = no_bison_stub.c bison_yylloc_SOURCES = no_bison_stub.c +bison_yylloc_p_SOURCES = no_bison_stub.c bison_yylval_SOURCES = no_bison_stub.c +bison_yylval_p_SOURCES = no_bison_stub.c endif c_cxx_nr_SOURCES = c_cxx_nr.lll c_cxx_r_SOURCES = c_cxx_r.lll @@ -145,6 +166,7 @@ ccl_SOURCES = ccl.l cxx_basic_SOURCES = cxx_basic.ll cxx_restart_SOURCES = cxx_restart.ll cxx_multiple_scanners_SOURCES = cxx_multiple_scanners_main.cc cxx_multiple_scanners_1.ll cxx_multiple_scanners_2.ll +cxx_multiple_scanners_p_SOURCES = cxx_multiple_scanners_1_p.ll cxx_multiple_scanners_2_p.ll cxx_multiple_scanners_main_p.cc cxx_yywrap_i3_SOURCES = cxx_yywrap.ll debug_nr_SOURCES = debug_nr.l debug_r_SOURCES = debug_r.l @@ -194,28 +216,48 @@ yyextra_SOURCES = yyextra.l CLEANFILES = \ alloc_extra.c \ + alloc_extra_p.c \ array_nr.c \ + array_nrp.c \ array_r.c \ + array_rp.c \ basic_nr.c \ basic_r.c \ + basic_rp.c \ bison_nr_parser.c \ bison_nr_parser.h \ bison_nr_scanner.c \ bison_nr_scanner.h \ + bison_nrp_parser.c \ + bison_nrp_parser.h \ + bison_nrp_scanner.c \ + bison_nrp_scanner.h \ bison_yylloc_parser.c \ bison_yylloc_parser.h \ bison_yylloc_scanner.c \ bison_yylloc_scanner.h \ + bison_yylloc_parser_p.c \ + bison_yylloc_parser_p.h \ + bison_yylloc_scanner_p.c \ + bison_yylloc_scanner_p.h \ bison_yylval_parser.c \ bison_yylval_parser.h \ bison_yylval_scanner.c \ bison_yylval_scanner.h \ + bison_yylval_parser_p.c \ + bison_yylval_parser_p.h \ + bison_yylval_scanner_p.c \ + bison_yylval_scanner_p.h \ c_cxx_nr.cc \ c_cxx_r.cc \ ccl.c \ cxx_basic.cc \ cxx_multiple_scanners_1.cc \ cxx_multiple_scanners_2.cc \ + cxx_multiple_scanners_1_p.cc \ + cxx_multiple_scanners_1_p.h \ + cxx_multiple_scanners_2_p.cc \ + cxx_multiple_scanners_2_p.h \ cxx_restart.cc \ cxx_yywrap.cc \ debug_nr.c \ @@ -273,18 +315,26 @@ dist-hook: EXTRA_DIST = \ README \ alloc_extra.txt \ + alloc_extra_p.txt \ array_nr.txt \ + array_nrp.txt \ array_r.txt \ + array_rp.txt \ basic_nr.txt \ basic_r.txt \ + basic_rp.txt \ bison_nr.txt \ + bison_nrp.txt \ bison_yylloc.txt \ + bison_yylloc_p.txt \ bison_yylval.txt \ + bison_yylval_p.txt \ c_cxx_nr.txt \ c_cxx_r.txt \ ccl.txt \ cxx_basic.txt \ cxx_multiple_scanners.txt \ + cxx_multiple_scanners_p.txt \ cxx_restart.txt \ cxx_yywrap.txt \ debug_nr.txt \ @@ -349,6 +399,13 @@ bison_nr_scanner.h: bison_nr_scanner.c @if test ! -f $@; then rm -f $<; else :; fi @if test ! -f $@; then $(MAKE) $(AM_MAKEFLAGS) $<; else :; fi +bison_nrp_main.$(OBJEXT): bison_nrp_parser.h bison_nrp_scanner.h +bison_nrp_scanner.$(OBJEXT): bison_nrp_parser.h + +bison_nrp_scanner.h: bison_nrp_scanner.c + @if test ! -f $@; then rm -f $<; else :; fi + @if test ! -f $@; then $(MAKE) $(AM_MAKEFLAGS) $<; else :; fi + bison_yylloc_main.$(OBJEXT): bison_yylloc_parser.h bison_yylloc_scanner.h bison_yylloc_scanner.$(OBJEXT): bison_yylloc_parser.h @@ -356,6 +413,13 @@ bison_yylloc_scanner.h: bison_yylloc_scanner.c @if test ! -f $@; then rm -f $<; else :; fi @if test ! -f $@; then $(MAKE) $(AM_MAKEFLAGS) $<; else :; fi +bison_yylloc_main_p.$(OBJEXT): bison_yylloc_parser_p.h bison_yylloc_scanner_p.h +bison_yylloc_scanner_p.$(OBJEXT): bison_yylloc_parser_p.h + +bison_yylloc_scanner_p.h: bison_yylloc_scanner_p.c + @if test ! -f $@; then rm -f $<; else :; fi + @if test ! -f $@; then $(MAKE) $(AM_MAKEFLAGS) $<; else :; fi + bison_yylval_main.$(OBJEXT): bison_yylval_parser.h bison_yylval_scanner.h bison_yylval_scanner.$(OBJEXT): bison_yylval_parser.h @@ -363,6 +427,13 @@ bison_yylval_scanner.h: bison_yylval_scanner.c @if test ! -f $@; then rm -f $<; else :; fi @if test ! -f $@; then $(MAKE) $(AM_MAKEFLAGS) $<; else :; fi +bison_yylval_main_p.$(OBJEXT): bison_yylval_parser_p.h bison_yylval_scanner_p.h +bison_yylval_scanner_p.$(OBJEXT): bison_yylval_parser_p.h + +bison_yylval_scanner_p.h: bison_yylval_scanner_p.c + @if test ! -f $@; then rm -f $<; else :; fi + @if test ! -f $@; then $(MAKE) $(AM_MAKEFLAGS) $<; else :; fi + # automake does not support compiling flex scanners output in C as C++ # so we explicitly sayhow, using the .lll suffix for the lex input file diff --git a/tests/alloc_extra_p.l b/tests/alloc_extra_p.l new file mode 100644 index 000000000..d0f978659 --- /dev/null +++ b/tests/alloc_extra_p.l @@ -0,0 +1,123 @@ +/* + * This file is part of flex. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * Neither the name of the University nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE. + */ + +%{ +/* A file to build "scanner.c". */ +/* This tests that we can use "yyextra". + We buffer all input into a growable array, then print it. + We run diff on the input and output. +*/ + +#include +#include +#include "config.h" + + +/* We'll store the entire input in this buffer, growing as necessary. */ +struct Check { + char foo; + char *bar; + char qux; +}; + +/* Save char into junk array at next position. */ +static void check_extra ( yyscan_t scanner ); + +%} + +%option 8bit prefix="test" +%option nounput nomain noyywrap nodefault noinput +%option warn +%option extra-type="struct Check *" +%option reentrant +%option noyyalloc yystall="0xBADF00D" + + +%% + +.|\r|\n { check_extra (yyscanner); } + +%% + +int main(void); + +int +main (void) +{ + yyscan_t scanner; + struct Check check; + + check.foo = 'a'; + check.bar = NULL; + check.qux = 'z'; + + testlex_init_extra(&check, &scanner); + testset_out(stdout, scanner); + + /* Test to confirm that testalloc was called from + * testlex_init_extra with the testextra argument. + */ + check_extra(scanner); + + while(!feof(stdin)){ + char car = fgetc(stdin); + test_append_bytes(&car, 1, scanner); + testlex(scanner); + } + + testlex_destroy(scanner); + return 0; +} + +void *testalloc(size_t size, yyscan_t scanner) +{ + struct Check *check; + check = testget_extra(scanner); + + if (!check->bar) + check->bar = "Hello World"; + + check_extra(scanner); + + return malloc(size); +} + +/* Save char into junk array at next position. */ +static void check_extra(yyscan_t scanner) +{ + struct Check *check; + check = testget_extra(scanner); + + if (check->foo != 'a') { + fprintf(stderr, "foo is not 'a'\n"); + exit(1); + } + if (strcmp(check->bar, "Hello World") != 0) { + fprintf(stderr, "bar is not Hello World\n"); + exit(1); + } + if (check->qux != 'z') { + fprintf(stderr, "qux is not 'z'\n"); + exit(1); + } +} diff --git a/tests/alloc_extra_p.txt b/tests/alloc_extra_p.txt new file mode 100644 index 000000000..243df295f --- /dev/null +++ b/tests/alloc_extra_p.txt @@ -0,0 +1,795 @@ + + THE UNITED STATES CONSTITUTION + _________________________________________________________________ + + (See Note 1) + + We the People of the United States, in Order to form a more perfect + Union, establish Justice, insure domestic Tranquility, provide for the + common defence, promote the general Welfare, and secure the Blessings + of Liberty to ourselves and our Posterity, do ordain and establish + this Constitution for the United States of America. + +Article. I. + + Section 1. + + All legislative Powers herein granted shall be vested in a Congress of + the United States, which shall consist of a Senate and House of + Representatives. + + Section. 2. + + Clause 1: The House of Representatives shall be composed of Members + chosen every second Year by the People of the several States, and the + Electors in each State shall have the Qualifications requisite for + Electors of the most numerous Branch of the State Legislature. + + Clause 2: No Person shall be a Representative who shall not have + attained to the Age of twenty five Years, and been seven Years a + Citizen of the United States, and who shall not, when elected, be an + Inhabitant of that State in which he shall be chosen. + + Clause 3: Representatives and direct Taxes shall be apportioned among + the several States which may be included within this Union, according + to their respective Numbers, which shall be determined by adding to + the whole Number of free Persons, including those bound to Service for + a Term of Years, and excluding Indians not taxed, three fifths of all + other Persons. (See Note 2) The actual Enumeration shall be made + within three Years after the first Meeting of the Congress of the + United States, and within every subsequent Term of ten Years, in such + Manner as they shall by Law direct. The Number of Representatives + shall not exceed one for every thirty Thousand, but each State shall + have at Least one Representative; and until such enumeration shall be + made, the State of New Hampshire shall be entitled to chuse three, + Massachusetts eight, Rhode-Island and Providence Plantations one, + Connecticut five, New-York six, New Jersey four, Pennsylvania eight, + Delaware one, Maryland six, Virginia ten, North Carolina five, South + Carolina five, and Georgia three. + + Clause 4: When vacancies happen in the Representation from any State, + the Executive Authority thereof shall issue Writs of Election to fill + such Vacancies. + + Clause 5: The House of Representatives shall chuse their Speaker and + other Officers; and shall have the sole Power of Impeachment. + + Section. 3. + + Clause 1: The Senate of the United States shall be composed of two + Senators from each State, chosen by the Legislature thereof, (See Note + 3) for six Years; and each Senator shall have one Vote. + + Clause 2: Immediately after they shall be assembled in Consequence of + the first Election, they shall be divided as equally as may be into + three Classes. The Seats of the Senators of the first Class shall be + vacated at the Expiration of the second Year, of the second Class at + the Expiration of the fourth Year, and of the third Class at the + Expiration of the sixth Year, so that one third may be chosen every + second Year; and if Vacancies happen by Resignation, or otherwise, + during the Recess of the Legislature of any State, the Executive + thereof may make temporary Appointments until the next Meeting of the + Legislature, which shall then fill such Vacancies. (See Note 4) + + Clause 3: No Person shall be a Senator who shall not have attained to + the Age of thirty Years, and been nine Years a Citizen of the United + States, and who shall not, when elected, be an Inhabitant of that + State for which he shall be chosen. + + Clause 4: The Vice President of the United States shall be President + of the Senate, but shall have no Vote, unless they be equally divided. + + Clause 5: The Senate shall chuse their other Officers, and also a + President pro tempore, in the Absence of the Vice President, or when + he shall exercise the Office of President of the United States. + + Clause 6: The Senate shall have the sole Power to try all + Impeachments. When sitting for that Purpose, they shall be on Oath or + Affirmation. When the President of the United States is tried, the + Chief Justice shall preside: And no Person shall be convicted without + the Concurrence of two thirds of the Members present. + + Clause 7: Judgment in Cases of Impeachment shall not extend further + than to removal from Office, and disqualification to hold and enjoy + any Office of honor, Trust or Profit under the United States: but the + Party convicted shall nevertheless be liable and subject to + Indictment, Trial, Judgment and Punishment, according to Law. + + Section. 4. + + Clause 1: The Times, Places and Manner of holding Elections for + Senators and Representatives, shall be prescribed in each State by the + Legislature thereof; but the Congress may at any time by Law make or + alter such Regulations, except as to the Places of chusing Senators. + + Clause 2: The Congress shall assemble at least once in every Year, and + such Meeting shall be on the first Monday in December, (See Note 5) + unless they shall by Law appoint a different Day. + + Section. 5. + + Clause 1: Each House shall be the Judge of the Elections, Returns and + Qualifications of its own Members, and a Majority of each shall + constitute a Quorum to do Business; but a smaller Number may adjourn + from day to day, and may be authorized to compel the Attendance of + absent Members, in such Manner, and under such Penalties as each House + may provide. + + Clause 2: Each House may determine the Rules of its Proceedings, + punish its Members for disorderly Behaviour, and, with the Concurrence + of two thirds, expel a Member. + + Clause 3: Each House shall keep a Journal of its Proceedings, and from + time to time publish the same, excepting such Parts as may in their + Judgment require Secrecy; and the Yeas and Nays of the Members of + either House on any question shall, at the Desire of one fifth of + those Present, be entered on the Journal. + + Clause 4: Neither House, during the Session of Congress, shall, + without the Consent of the other, adjourn for more than three days, + nor to any other Place than that in which the two Houses shall be + sitting. + + Section. 6. + + Clause 1: The Senators and Representatives shall receive a + Compensation for their Services, to be ascertained by Law, and paid + out of the Treasury of the United States. (See Note 6) They shall in + all Cases, except Treason, Felony and Breach of the Peace, + beprivileged from Arrest during their Attendance at the Session of + their respective Houses, and in going to and returning from the same; + and for any Speech or Debate in either House, they shall not be + questioned in any other Place. + + Clause 2: No Senator or Representative shall, during the Time for + which he was elected, be appointed to any civil Office under the + Authority of the United States, which shall have been created, or the + Emoluments whereof shall have been encreased during such time; and no + Person holding any Office under the United States, shall be a Member + of either House during his Continuance in Office. + + Section. 7. + + Clause 1: All Bills for raising Revenue shall originate in the House + of Representatives; but the Senate may propose or concur with + Amendments as on other Bills. + + Clause 2: Every Bill which shall have passed the House of + Representatives and the Senate, shall, before it become a Law, be + presented to the President of the United States; If he approve he + shall sign it, but if not he shall return it, with his Objections to + that House in which it shall have originated, who shall enter the + Objections at large on their Journal, and proceed to reconsider it. If + after such Reconsideration two thirds of that House shall agree to + pass the Bill, it shall be sent, together with the Objections, to the + other House, by which it shall likewise be reconsidered, and if + approved by two thirds of that House, it shall become a Law. But in + all such Cases the Votes of both Houses shall be determined by yeas + and Nays, and the Names of the Persons voting for and against the Bill + shall be entered on the Journal of each House respectively. If any + Bill shall not be returned by the President within ten Days (Sundays + excepted) after it shall have been presented to him, the Same shall be + a Law, in like Manner as if he had signed it, unless the Congress by + their Adjournment prevent its Return, in which Case it shall not be a + Law. + + Clause 3: Every Order, Resolution, or Vote to which the Concurrence of + the Senate and House of Representatives may be necessary (except on a + question of Adjournment) shall be presented to the President of the + United States; and before the Same shall take Effect, shall be + approved by him, or being disapproved by him, shall be repassed by two + thirds of the Senate and House of Representatives, according to the + Rules and Limitations prescribed in the Case of a Bill. + + Section. 8. + + Clause 1: The Congress shall have Power To lay and collect Taxes, + Duties, Imposts and Excises, to pay the Debts and provide for the + common Defence and general Welfare of the United States; but all + Duties, Imposts and Excises shall be uniform throughout the United + States; + + Clause 2: To borrow Money on the credit of the United States; + + Clause 3: To regulate Commerce with foreign Nations, and among the + several States, and with the Indian Tribes; + + Clause 4: To establish an uniform Rule of Naturalization, and uniform + Laws on the subject of Bankruptcies throughout the United States; + + Clause 5: To coin Money, regulate the Value thereof, and of foreign + Coin, and fix the Standard of Weights and Measures; + + Clause 6: To provide for the Punishment of counterfeiting the + Securities and current Coin of the United States; + + Clause 7: To establish Post Offices and post Roads; + + Clause 8: To promote the Progress of Science and useful Arts, by + securing for limited Times to Authors and Inventors the exclusive + Right to their respective Writings and Discoveries; + + Clause 9: To constitute Tribunals inferior to the supreme Court; + + Clause 10: To define and punish Piracies and Felonies committed on the + high Seas, and Offences against the Law of Nations; + + Clause 11: To declare War, grant Letters of Marque and Reprisal, and + make Rules concerning Captures on Land and Water; + + Clause 12: To raise and support Armies, but no Appropriation of Money + to that Use shall be for a longer Term than two Years; + + Clause 13: To provide and maintain a Navy; + + Clause 14: To make Rules for the Government and Regulation of the land + and naval Forces; + + Clause 15: To provide for calling forth the Militia to execute the + Laws of the Union, suppress Insurrections and repel Invasions; + + Clause 16: To provide for organizing, arming, and disciplining, the + Militia, and for governing such Part of them as may be employed in the + Service of the United States, reserving to the States respectively, + the Appointment of the Officers, and the Authority of training the + Militia according to the discipline prescribed by Congress; + + Clause 17: To exercise exclusive Legislation in all Cases whatsoever, + over such District (not exceeding ten Miles square) as may, byCession + of particular States, and the Acceptance of Congress, become the Seat + of the Government of the United States, and to exercise like Authority + over all Places purchased by the Consent of the Legislature of the + State in which the Same shall be, for the Erection of Forts, + Magazines, Arsenals, dock-Yards, and other needful Buildings;--And + + Clause 18: To make all Laws which shall be necessary and proper for + carrying into Execution the foregoing Powers, and all other Powers + vested by this Constitution in the Government of the United States, or + in any Department or Officer thereof. + + Section. 9. + + Clause 1: The Migration or Importation of such Persons as any of the + States now existing shall think proper to admit, shall not be + prohibited by the Congress prior to the Year one thousand eight + hundred and eight, but a Tax or duty may be imposed on such + Importation, not exceeding ten dollars for each Person. + + Clause 2: The Privilege of the Writ of Habeas Corpus shall not be + suspended, unless when in Cases of Rebellion or Invasion the public + Safety may require it. + + Clause 3: No Bill of Attainder or ex post facto Law shall be passed. + + Clause 4: No Capitation, or other direct, Tax shall be laid, unless in + Proportion to the Census or Enumeration herein before directed to be + taken. (See Note 7) + + Clause 5: No Tax or Duty shall be laid on Articles exported from any + State. + + Clause 6: No Preference shall be given by any Regulation of Commerce + or Revenue to the Ports of one State over those of another: nor shall + Vessels bound to, or from, one State, be obliged to enter, clear, or + pay Duties in another. + + Clause 7: No Money shall be drawn from the Treasury, but in + Consequence of Appropriations made by Law; and a regular Statement and + Account of the Receipts and Expenditures of all public Money shall be + published from time to time. + + Clause 8: No Title of Nobility shall be granted by the United States: + And no Person holding any Office of Profit or Trust under them, shall, + without the Consent of the Congress, accept of any present, Emolument, + Office, or Title, of any kind whatever, from any King, Prince, or + foreign State. + + Section. 10. + + Clause 1: No State shall enter into any Treaty, Alliance, or + Confederation; grant Letters of Marque and Reprisal; coin Money; emit + Bills of Credit; make any Thing but gold and silver Coin a Tender in + Payment of Debts; pass any Bill of Attainder, ex post facto Law, or + Law impairing the Obligation of Contracts, or grant any Title of + Nobility. + + Clause 2: No State shall, without the Consent of the Congress, lay any + Imposts or Duties on Imports or Exports, except what may be absolutely + necessary for executing it's inspection Laws: and the net Produce of + all Duties and Imposts, laid by any State on Imports or Exports, shall + be for the Use of the Treasury of the United States; and all such Laws + shall be subject to the Revision and Controul of the Congress. + + Clause 3: No State shall, without the Consent of Congress, lay any + Duty of Tonnage, keep Troops, or Ships of War in time of Peace, enter + into any Agreement or Compact with another State, or with a foreign + Power, or engage in War, unless actually invaded, or in such imminent + Danger as will not admit of delay. + +Article. II. + + Section. 1. + + Clause 1: The executive Power shall be vested in a President of the + United States of America. He shall hold his Office during the Term of + four Years, and, together with the Vice President, chosen for the same + Term, be elected, as follows + + Clause 2: Each State shall appoint, in such Manner as the Legislature + thereof may direct, a Number of Electors, equal to the whole Number of + Senators and Representatives to which the State may be entitled in the + Congress: but no Senator or Representative, or Person holding an + Office of Trust or Profit under the United States, shall be appointed + an Elector. + + Clause 3: The Electors shall meet in their respective States, and vote + by Ballot for two Persons, of whom one at least shall not be an + Inhabitant of the same State with themselves. And they shall make a + List of all the Persons voted for, and of the Number of Votes for + each; which List they shall sign and certify, and transmit sealed to + the Seat of the Government of the United States, directed to the + President of the Senate. The President of the Senate shall, in the + Presence of the Senate and House of Representatives, open all the + Certificates, and the Votes shall then be counted. The Person having + the greatest Number of Votes shall be the President, if such Number be + a Majority of the whole Number of Electors appointed; and if there be + more than one who have such Majority, and have an equal Number of + Votes, then the House of Representatives shall immediately chuse by + Ballot one of them for President; and if no Person have a Majority, + then from the five highest on the List the said House shall in like + Manner chuse the President. But in chusing the President, the Votes + shall be taken by States, the Representation from each State having + one Vote; A quorum for this Purpose shall consist of a Member or + Members from two thirds of the States, and a Majority of all the + States shall be necessary to a Choice. In every Case, after the Choice + of the President, the Person having the greatest Number of Votes of + the Electors shall be the Vice President. But if there should remain + two or more who have equal Votes, the Senate shall chuse from them by + Ballot the Vice President. (See Note 8) + + Clause 4: The Congress may determine the Time of chusing the Electors, + and the Day on which they shall give their Votes; which Day shall be + the same throughout the United States. + + Clause 5: No Person except a natural born Citizen, or a Citizen of the + United States, at the time of the Adoption of this Constitution, shall + be eligible to the Office of President; neither shall any Person be + eligible to that Office who shall not have attained to the Age of + thirty five Years, and been fourteen Years a Resident within the + United States. + + Clause 6: In Case of the Removal of the President from Office, or of + his Death, Resignation, or Inability to discharge the Powers and + Duties of the said Office, (See Note 9) the Same shall devolve on the + VicePresident, and the Congress may by Law provide for the Case of + Removal, Death, Resignation or Inability, both of the President and + Vice President, declaring what Officer shall then act as President, + and such Officer shall act accordingly, until the Disability be + removed, or a President shall be elected. + + Clause 7: The President shall, at stated Times, receive for his + Services, a Compensation, which shall neither be encreased nor + diminished during the Period for which he shall have been elected, and + he shall not receive within that Period any other Emolument from the + United States, or any of them. + + Clause 8: Before he enter on the Execution of his Office, he shall + take the following Oath or Affirmation:--"I do solemnly swear (or + affirm) that I will faithfully execute the Office of President of the + United States, and will to the best of my Ability, preserve, protect + and defend the Constitution of the United States." + + Section. 2. + + Clause 1: The President shall be Commander in Chief of the Army and + Navy of the United States, and of the Militia of the several States, + when called into the actual Service of the United States; he may + require the Opinion, in writing, of the principal Officer in each of + the executive Departments, upon any Subject relating to the Duties of + their respective Offices, and he shall have Power to grant Reprieves + and Pardons for Offences against the United States, except in Cases of + Impeachment. + + Clause 2: He shall have Power, by and with the Advice and Consent of + the Senate, to make Treaties, provided two thirds of the Senators + present concur; and he shall nominate, and by and with the Advice and + Consent of the Senate, shall appoint Ambassadors, other public + Ministers and Consuls, Judges of the supreme Court, and all other + Officers of the United States, whose Appointments are not herein + otherwise provided for, and which shall be established by Law: but the + Congress may by Law vest the Appointment of such inferior Officers, as + they think proper, in the President alone, in the Courts of Law, or in + the Heads of Departments. + + Clause 3: The President shall have Power to fill up all Vacancies that + may happen during the Recess of the Senate, by granting Commissions + which shall expire at the End of their next Session. + + Section. 3. + + He shall from time to time give to the Congress Information of the + State of the Union, and recommend to their Consideration such Measures + as he shall judge necessary and expedient; he may, on extraordinary + Occasions, convene both Houses, or either of them, and in Case of + Disagreement between them, with Respect to the Time of Adjournment, he + may adjourn them to such Time as he shall think proper; he shall + receive Ambassadors and other public Ministers; he shall take Care + that the Laws be faithfully executed, and shall Commission all the + Officers of the United States. + + Section. 4. + + The President, Vice President and all civil Officers of the United + States, shall be removed from Office on Impeachment for, and + Conviction of, Treason, Bribery, or other high Crimes and + Misdemeanors. + +Article. III. + + Section. 1. + + The judicial Power of the United States, shall be vested in one + supreme Court, and in such inferior Courts as the Congress may from + time to time ordain and establish. The Judges, both of the supreme and + inferior Courts, shall hold their Offices during good Behaviour, and + shall, at stated Times, receive for their Services, a Compensation, + which shall not be diminished during their Continuance in Office. + + Section. 2. + + Clause 1: The judicial Power shall extend to all Cases, in Law and + Equity, arising under this Constitution, the Laws of the United + States, and Treaties made, or which shall be made, under their + Authority;--to all Cases affecting Ambassadors, other public Ministers + and Consuls;--to all Cases of admiralty and maritime Jurisdiction;--to + Controversies to which the United States shall be a Party;--to + Controversies between two or more States;--between a State and + Citizens of another State; (See Note 10)--between Citizens of + different States, --between Citizens of the same State claiming Lands + under Grants of different States, and between a State, or the Citizens + thereof, and foreign States, Citizens or Subjects. + + Clause 2: In all Cases affecting Ambassadors, other public Ministers + and Consuls, and those in which a State shall be Party, the supreme + Court shall have original Jurisdiction. In all the other Cases before + mentioned, the supreme Court shall have appellate Jurisdiction, both + as to Law and Fact, with such Exceptions, and under such Regulations + as the Congress shall make. + + Clause 3: The Trial of all Crimes, except in Cases of Impeachment, + shall be by Jury; and such Trial shall be held in the State where the + said Crimes shall have been committed; but when not committed within + any State, the Trial shall be at such Place or Places as the Congress + may by Law have directed. + + Section. 3. + + Clause 1: Treason against the United States, shall consist only in + levying War against them, or in adhering to their Enemies, giving them + Aid and Comfort. No Person shall be convicted of Treason unless on the + Testimony of two Witnesses to the same overt Act, or on Confession in + open Court. + + Clause 2: The Congress shall have Power to declare the Punishment of + Treason, but no Attainder of Treason shall work Corruption of Blood, + or Forfeiture except during the Life of the Person attainted. + +Article. IV. + + Section. 1. + + Full Faith and Credit shall be given in each State to the public Acts, + Records, and judicial Proceedings of every other State. And the + Congress may by general Laws prescribe the Manner in which such Acts, + Records and Proceedings shall be proved, and the Effect thereof. + + Section. 2. + + Clause 1: The Citizens of each State shall be entitled to all + Privileges and Immunities of Citizens in the several States. + + Clause 2: A Person charged in any State with Treason, Felony, or other + Crime, who shall flee from Justice, and be found in another State, + shall on Demand of the executive Authority of the State from which he + fled, be delivered up, to be removed to the State having Jurisdiction + of the Crime. + + Clause 3: No Person held to Service or Labour in one State, under the + Laws thereof, escaping into another, shall, in Consequence of any Law + or Regulation therein, be discharged from such Service or Labour, but + shall be delivered up on Claim of the Party to whom such Service or + Labour may be due. (See Note 11) + + Section. 3. + + Clause 1: New States may be admitted by the Congress into this Union; + but no new State shall be formed or erected within the Jurisdiction of + any other State; nor any State be formed by the Junction of two or + more States, or Parts of States, without the Consent of the + Legislatures of the States concerned as well as of the Congress. + + Clause 2: The Congress shall have Power to dispose of and make all + needful Rules and Regulations respecting the Territory or other + Property belonging to the United States; and nothing in this + Constitution shall be so construed as to Prejudice any Claims of the + United States, or of any particular State. + + Section. 4. + + The United States shall guarantee to every State in this Union a + Republican Form of Government, and shall protect each of them against + Invasion; and on Application of the Legislature, or of the Executive + (when the Legislature cannot be convened) against domestic Violence. + +Article. V. + + The Congress, whenever two thirds of both Houses shall deem it + necessary, shall propose [1]Amendments to this Constitution, or, on + the Application of the Legislatures of two thirds of the several + States, shall call a Convention for proposing Amendments, which, in + either Case, shall be valid to all Intents and Purposes, as Part of + this Constitution, when ratified by the Legislatures of three fourths + of the several States, or by Conventions in three fourths thereof, as + the one or the other Mode of Ratification may be proposed by the + Congress; Provided that no Amendment which may be made prior to the + Year One thousand eight hundred and eight shall in any Manner affect + the first and fourth Clauses in the Ninth Section of the first + Article; and that no State, without its Consent, shall be deprived of + its equal Suffrage in the Senate. + +Article. VI. + + Clause 1: All Debts contracted and Engagements entered into, before + the Adoption of this Constitution, shall be as valid against the + United States under this Constitution, as under the Confederation. + + Clause 2: This Constitution, and the Laws of the United States which + shall be made in Pursuance thereof; and all Treaties made, or which + shall be made, under the Authority of the United States, shall be the + supreme Law of the Land; and the Judges in every State shall be bound + thereby, any Thing in the Constitution or Laws of any State to the + Contrary notwithstanding. + + Clause 3: The Senators and Representatives before mentioned, and the + Members of the several State Legislatures, and all executive and + judicial Officers, both of the United States and of the several + States, shall be bound by Oath or Affirmation, to support this + Constitution; but no religious Test shall ever be required as a + Qualification to any Office or public Trust under the United States. + +Article. VII. + + The Ratification of the Conventions of nine States, shall be + sufficient for the Establishment of this Constitution between the + States so ratifying the Same. + + done in Convention by the Unanimous Consent of the States present the + Seventeenth Day of September in the Year of our Lord one thousand + seven hundred and Eighty seven and of the Independence of the United + States of America the Twelfth In witness whereof We have hereunto + subscribed our Names, + + GO WASHINGTON--Presidt. and deputy from Virginia + + [Signed also by the deputies of twelve States.] + + Delaware + + Geo: Read + Gunning Bedford jun + John Dickinson + Richard Bassett + Jaco: Broom + + Maryland + + James MCHenry + Dan of ST ThoS. Jenifer + DanL Carroll. + + Virginia + + John Blair-- + James Madison Jr. + + North Carolina + + WM Blount + RichD. Dobbs Spaight. + Hu Williamson + + South Carolina + + J. Rutledge + Charles 1ACotesworth Pinckney + Charles Pinckney + Pierce Butler. + + Georgia + + William Few + Abr Baldwin + + New Hampshire + + John Langdon + Nicholas Gilman + + Massachusetts + + Nathaniel Gorham + Rufus King + + Connecticut + WM. SamL. Johnson + Roger Sherman + + New York + + Alexander Hamilton + + New Jersey + + Wil: Livingston + David Brearley. + WM. Paterson. + Jona: Dayton + + Pennsylvania + + B Franklin + Thomas Mifflin + RobT Morris + Geo. Clymer + ThoS. FitzSimons + Jared Ingersoll + James Wilson. + Gouv Morris + + Attest William Jackson Secretary + + NOTES + + Note 1: This text of the Constitution follows the engrossed copy + signed by Gen. Washington and the deputies from 12 States. The small + superior figures preceding the paragraphs designate Clauses, and were + not in the original and have no reference to footnotes. + + The Constitution was adopted by a convention of the States on + September 17, 1787, and was subsequently ratified by the several + States, on the following dates: Delaware, December 7, 1787; + Pennsylvania, December 12, 1787; New Jersey, December 18, 1787; + Georgia, January 2, 1788; Connecticut, January 9, 1788; Massachusetts, + February 6, 1788; Maryland, April 28, 1788; South Carolina, May 23, + 1788; New Hampshire, June 21, 1788. + + Ratification was completed on June 21, 1788. + + The Constitution was subsequently ratified by Virginia, June 25, 1788; + New York, July 26, 1788; North Carolina, November 21, 1789; Rhode + Island, May 29, 1790; and Vermont, January 10, 1791. + + In May 1785, a committee of Congress made a report recommending an + alteration in the Articles of Confederation, but no action was taken + on it, and it was left to the State Legislatures to proceed in the + matter. In January 1786, the Legislature of Virginia passed a + resolution providing for the appointment of five commissioners, who, + or any three of them, should meet such commissioners as might be + appointed in the other States of the Union, at a time and place to be + agreed upon, to take into consideration the trade of the United + States; to consider how far a uniform system in their commercial + regulations may be necessary to their common interest and their + permanent harmony; and to report to the several States such an act, + relative to this great object, as, when ratified by them, will enable + the United States in Congress effectually to provide for the same. The + Virginia commissioners, after some correspondence, fixed the first + Monday in September as the time, and the city of Annapolis as the + place for the meeting, but only four other States were represented, + viz: Delaware, New York, New Jersey, and Pennsylvania; the + commissioners appointed by Massachusetts, New Hampshire, North + Carolina, and Rhode Island failed to attend. Under the circumstances + of so partial a representation, the commissioners present agreed upon + a report, (drawn by Mr. Hamilton, of New York,) expressing their + unanimous conviction that it might essentially tend to advance the + interests of the Union if the States by which they were respectively + delegated would concur, and use their endeavors to procure the + concurrence of the other States, in the appointment of commissioners + to meet at Philadelphia on the Second Monday of May following, to take + into consideration the situation of the United States; to devise such + further provisions as should appear to them necessary to render the + Constitution of the Federal Government adequate to the exigencies of + the Union; and to report such an act for that purpose to the United + States in Congress assembled as, when agreed to by them and afterwards + confirmed by the Legislatures of every State, would effectually + provide for the same. + + Congress, on the 21st of February, 1787, adopted a resolution in favor + of a convention, and the Legislatures of those States which had not + already done so (with the exception of Rhode Island) promptly + appointed delegates. On the 25th of May, seven States having convened, + George Washington, of Virginia, was unanimously elected President, and + the consideration of the proposed constitution was commenced. On the + 17th of September, 1787, the Constitution as engrossed and agreed upon + was signed by all the members present, except Mr. Gerry of + Massachusetts, and Messrs. Mason and Randolph, of Virginia. The + president of the convention transmitted it to Congress, with a + resolution stating how the proposed Federal Government should be put + in operation, and an explanatory letter. Congress, on the 28th of + September, 1787, directed the Constitution so framed, with the + resolutions and letter concerning the same, to "be transmitted to the + several Legislatures in order to be submitted to a convention of + delegates chosen in each State by the people thereof, in conformity to + the resolves of the convention." + + On the 4th of March, 1789, the day which had been fixed for commencing + the operations of Government under the new Constitution, it had been + ratified by the conventions chosen in each State to consider it, as + follows: Delaware, December 7, 1787; Pennsylvania, December 12, 1787; + New Jersey, December 18, 1787; Georgia, January 2, 1788; Connecticut, + January 9, 1788; Massachusetts, February 6, 1788; Maryland, April 28, + 1788; South Carolina, May 23, 1788; New Hampshire, June 21, 1788; + Virginia, June 25, 1788; and New York, July 26, 1788. + + The President informed Congress, on the 28th of January, 1790, that + North Carolina had ratified the Constitution November 21, 1789; and he + informed Congress on the 1st of June, 1790, that Rhode Island had + ratified the Constitution May 29, 1790. Vermont, in convention, + ratified the Constitution January 10, 1791, and was, by an act of + Congress approved February 18, 1791, "received and admitted into this + Union as a new and entire member of the United States." + + Note 2: The part of this Clause relating to the mode of apportionment + of representatives among the several States has been affected by + Section 2 of amendment XIV, and as to taxes on incomes without + apportionment by amendment XVI. + + Note 3: This Clause has been affected by Clause 1 of amendment XVII. + + Note 4: This Clause has been affected by Clause 2 of amendment XVIII. + + Note 5: This Clause has been affected by amendment XX. + + Note 6: This Clause has been affected by amendment XXVII. + + Note 7: This Clause has been affected by amendment XVI. + + Note 8: This Clause has been superseded by amendment XII. + + Note 9: This Clause has been affected by amendment XXV. + + Note 10: This Clause has been affected by amendment XI. + + Note 11: This Clause has been affected by amendment XIII. + + Note 12: The first ten amendments to the Constitution of the United + States (and two others, one of which failed of ratification and the + other which later became the 27th amendment) were proposed to the + legislatures of the several States by the First Congress on September + 25, 1789. The first ten amendments were ratified by the following + States, and the notifications of ratification by the Governors thereof + were successively communicated by the President to Congress: New + Jersey, November 20, 1789; Maryland, December 19, 1789; North + Carolina, December 22, 1789; South Carolina, January 19, 1790; New + Hampshire, January 25, 1790; Delaware, January 28, 1790; New York, + February 24, 1790; Pennsylvania, March 10, 1790; Rhode Island, June 7, + 1790; Vermont, November 3, 1791; and Virginia, December 15, 1791. + + Ratification was completed on December 15, 1791. + + The amendments were subsequently ratified by the legislatures of + Massachusetts, March 2, 1939; Georgia, March 18, 1939; and + Connecticut, April 19, 1939. + + Note 13: Only the 13th, 14th, 15th, and 16th articles of amendment had + numbers assigned to them at the time of ratification. + + Note 14: This sentence has been superseded by section 3 of amendment + XX. + + Note 15: See amendment XIX and section 1 of amendment XXVI. + + Note 16: Repealed by section 1 of amendment XXI. + +References + + 1. http://www.house.gov/Constitution/Amend.html diff --git a/tests/array_nrp.l b/tests/array_nrp.l new file mode 100644 index 000000000..d63de9277 --- /dev/null +++ b/tests/array_nrp.l @@ -0,0 +1,60 @@ +/* + * This file is part of flex. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * Neither the name of the University nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE. + */ + +%{ +/* A template scanner file to build "scanner.c". */ +#include +#include +#include "config.h" +/*#include "parser.h" */ + +%} + +%option 8bit prefix="test" +%option nounput nomain noyywrap noinput +%option warn array yystall="0xBADF00D" + + +%% + +.|\n { } + + +%% + +int main (void); + +int +main (void) +{ + yyout = stdout; + + while(!feof(stdin)){ + char car = fgetc(stdin); + yy_append_bytes(&car, 1); + yylex( ); + } + + printf("TEST RETURNING OK.\n"); + return 0; +} diff --git a/tests/array_nrp.txt b/tests/array_nrp.txt new file mode 100644 index 000000000..7288a4075 --- /dev/null +++ b/tests/array_nrp.txt @@ -0,0 +1,2 @@ +0000 foo 1111 foo 0000 bar +0000 foo 1111 foo 0000 bar diff --git a/tests/array_rp.l b/tests/array_rp.l new file mode 100644 index 000000000..11b419e35 --- /dev/null +++ b/tests/array_rp.l @@ -0,0 +1,64 @@ +/* + * This file is part of flex. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * Neither the name of the University nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE. + */ + +%{ +/* A template scanner file to build "scanner.c". */ +#include +#include +#include "config.h" +/*#include "parser.h" */ +%} + +%option 8bit prefix="test" +%option nounput nomain noyywrap noinput +%option warn array reentrant yystall="0xBADF00D" + + +%% + +.|\n { } + + +%% + +int main(void); + +int +main (void) +{ + yyscan_t lexer; + + yylex_init(&lexer); + yyset_out(stdout, lexer); + + while(!feof(stdin)){ + char car = fgetc(stdin); + yy_append_bytes(&car, 1, lexer); + yylex( lexer ); + } + + yylex_destroy( lexer); + printf("TEST RETURNING OK.\n"); + + return 0; +} diff --git a/tests/array_rp.txt b/tests/array_rp.txt new file mode 100644 index 000000000..7288a4075 --- /dev/null +++ b/tests/array_rp.txt @@ -0,0 +1,2 @@ +0000 foo 1111 foo 0000 bar +0000 foo 1111 foo 0000 bar diff --git a/tests/basic_nrp.l b/tests/basic_nrp.l new file mode 100644 index 000000000..74896b89e --- /dev/null +++ b/tests/basic_nrp.l @@ -0,0 +1,65 @@ +/* + * This file is part of flex. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * Neither the name of the University nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE. + */ + +/* TEST scanner. + Basic non-reentrant scanner. + + Sample Input: + # this is a comment + foo = true + bar = "string value" + integer = 43 +*/ +%{ +#include "config.h" +#define YY_STALLED 1 +%} + +%option prefix="test" +%option nounput noyywrap noyylineno warn nodefault noinput + +IDENT [[:alnum:]_-] +WS [[:blank:]] +%% + +^{IDENT}+{WS}*={WS}*(true|false){WS}*\r?\n { return 100;} +^{IDENT}+{WS}*={WS}*\"[^\"\n\r]*\"{WS}*\r?\n { return 101;} +^{IDENT}+{WS}*={WS}*[[:digit:]]+{WS}*\r?\n { return 102;} +^{WS}*#.*\r?\n { } +^{WS}*\r?\n { } +.|\n { fprintf(stderr,"Invalid line.\n"); exit(-1);} + +%% + +int main(void); + +int main (void) +{ + yyin = stdin; + yyout = stdout; + while( yylex() ) + { + } + printf("TEST RETURNING OK.\n"); + return 0; +} diff --git a/tests/basic_nrp.txt b/tests/basic_nrp.txt new file mode 100644 index 000000000..642e0fb7a --- /dev/null +++ b/tests/basic_nrp.txt @@ -0,0 +1,5 @@ +# this is a comment +foo = "bar" +num = 43 +setting = false + diff --git a/tests/basic_rp.l b/tests/basic_rp.l new file mode 100644 index 000000000..aabdb62a0 --- /dev/null +++ b/tests/basic_rp.l @@ -0,0 +1,71 @@ +/* + * This file is part of flex. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * Neither the name of the University nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE. + */ + +/* A reentrant scanner. + This file will not compile under flex version <= 2.5.4. + Sample Input: + # this is a comment + foo = true + bar = "string value" + integer = 43 +*/ +%{ +#include "config.h" +%} + +%option prefix="test" +%option nounput noyywrap noyylineno warn nodefault noinput +%option reentrant yystall="0xBADF00D" + +IDENT [[:alnum:]_-] +WS [[:blank:]] +%% + +^{IDENT}+{WS}*={WS}*(true|false){WS}*\r?\n { return 100;} +^{IDENT}+{WS}*={WS}*\"[^\"\n\r]*\"{WS}*\r?\n { return 101;} +^{IDENT}+{WS}*={WS}*[[:digit:]]+{WS}*\r?\n { return 102;} +^{WS}*#.*\r?\n { } +^{WS}*\r?\n { } +.|\n { fprintf(stderr,"Invalid line.\n"); exit(-1);} + +%% + +int main(void); + +int main (void) +{ + yyscan_t lexer; + testlex_init( &lexer ); + testset_out ( stdout,lexer); + + while(!feof(stdin)){ + char car = fgetc(stdin); + test_append_bytes(&car, 1, lexer); + testlex( lexer ); + } + + testlex_destroy( lexer ); + printf("TEST RETURNING OK.\n"); + return 0; +} + diff --git a/tests/basic_rp.txt b/tests/basic_rp.txt new file mode 100644 index 000000000..216062852 --- /dev/null +++ b/tests/basic_rp.txt @@ -0,0 +1,4 @@ +# this is a comment +foo = "bar" +num = 43 +setting = false diff --git a/tests/bison_nrp.txt b/tests/bison_nrp.txt new file mode 100644 index 000000000..94adcb2f2 --- /dev/null +++ b/tests/bison_nrp.txt @@ -0,0 +1,4 @@ +0001: FIRSTNAME=firstname +0002: MIDDLENAME=middle +0003: LASTNAME=lastname +0004: ADDRESS=address diff --git a/tests/bison_nrp_main.c b/tests/bison_nrp_main.c new file mode 100644 index 000000000..9169a812f --- /dev/null +++ b/tests/bison_nrp_main.c @@ -0,0 +1,63 @@ +/* + * This file is part of flex. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * Neither the name of the University nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE. + */ + +#include "bison_nrp_parser.h" +#include "bison_nrp_scanner.h" + + +int main ( int argc, char** argv ) +{ + YYSTYPE pushed_value; + YYLTYPE pushed_location; + testpstate * ps; + + (void)argc; + (void)argv; + + /*yydebug =1;*/ + ps = testpstate_new(); + + while(!feof(stdin)){ + char car = fgetc(stdin); + test_append_bytes(&car, 1); + int statusYacc; + do{ + statusYacc = 0; + int statusLex = testlex(&pushed_value, &pushed_location); + if(!statusLex){break;} + if(statusLex == YY_STALLED){ + printf("Not invoking parser because we are STALLED\n"); + }else{ + statusYacc = testpush_parse(ps, statusLex, &pushed_value, &pushed_location); + printf("[%d:%d]", statusLex, statusYacc); + } + }while(statusYacc==YYPUSH_MORE); + } + + + return 0; +} + + + +/* vim:set tabstop=8 softtabstop=4 shiftwidth=4: */ diff --git a/tests/bison_nrp_parser.y b/tests/bison_nrp_parser.y new file mode 100644 index 000000000..047cdd09b --- /dev/null +++ b/tests/bison_nrp_parser.y @@ -0,0 +1,101 @@ +/* + * This file is part of flex. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * Neither the name of the University nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE. + */ + +/* + How to compile: + bison --defines --output-file="parser.c" --name-prefix="test" parser.y + */ +%{ +#include +#include +#include +#include "config.h" +#include "bison_nrp_parser.h" +#include "bison_nrp_scanner.h" + +#define YYERROR_VERBOSE 1 +/* #define YYPARSE_PARAM scanner */ +/* #define YYLEX_PARAM scanner */ + +int yyerror(YYLTYPE *location, const char* msg); + + +/* A dummy function. A check against seg-faults in yylval->str. */ +static int process_text(char* s) { + int total =0; + while(*s) { + total += (int) *s; + ++s; + } + return total; +} + + +%} + +%define api.pure full +%define api.push-pull push + +%union { + int lineno; + char * str; +} +%token IDENT +%token LINENO +%token EQUAL "=" +%token COLON ":" +%token SPACE " " + +%token YY_STALLED +%% + +file: + line + | file line + ; + +line: + LINENO COLON SPACE IDENT EQUAL IDENT + { + process_text($4); + process_text($6); + /* Check lineno. */ + if( $1 != @1.first_line || $1 != testget_lineno()) + { + yyerror(NULL, "Parse failed: Line numbers do not match."); + YYABORT; + } + + /* Recreate the line to stdout. */ + printf ( "%04d: %s=%s\n", @1.first_line, $4, $6); + } + ; + +%% + +int yyerror(YYLTYPE *location, const char* msg) { + (void)location; + fprintf(stderr,"%s\n",msg); + return 0; +} + diff --git a/tests/bison_nrp_scanner.l b/tests/bison_nrp_scanner.l new file mode 100644 index 000000000..571949a0b --- /dev/null +++ b/tests/bison_nrp_scanner.l @@ -0,0 +1,62 @@ +/* + * This file is part of flex. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * Neither the name of the University nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE. + */ + +%{ +/* The scanner expects to link to bison yylval . */ +#include +#include +#include "bison_nrp_parser.h" +#include "config.h" +static char* STRDUP(char* s1); +#define YY_EXTRA_TYPE int +%} + +%option 8bit prefix="test" +%option bison-locations yylineno +%option header="bison_nrp_scanner.h" yylineno +%option nomain nounput noyy_top_state noyywrap nodefault noinput warn +%option yystall="YY_STALLED" + +%% + +^[[:digit:]]+ { + yylval->lineno = yylineno; + yylloc->first_line = (int)strtol(yytext,NULL,10); + return LINENO; + } +":" { return COLON; } +" " { return SPACE; } +"=" { return EQUAL; } +[[:alnum:]_]+ { yylval->str = STRDUP(yytext); return IDENT;} + +\r|\n { } +. { yyterminate();} +%% + + +static char* STRDUP(char* s1) +{ + char* s2 = malloc(strlen(s1)+1); + sprintf(s2,"%s",s1); + return s2; +} diff --git a/tests/bison_yylloc_main_p.c b/tests/bison_yylloc_main_p.c new file mode 100644 index 000000000..b600cecd8 --- /dev/null +++ b/tests/bison_yylloc_main_p.c @@ -0,0 +1,63 @@ +/* + * This file is part of flex. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * Neither the name of the University nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE. + */ + +#include "bison_yylloc_parser_p.h" +#include "bison_yylloc_scanner_p.h" + +int main ( int argc, char** argv ) +{ + yyscan_t scanner; + YYSTYPE pushed_value; + YYLTYPE pushed_location; + testpstate * ps; + + (void)argc; + (void)argv; + + /*yydebug =1;*/ + testlex_init ( &scanner ); + ps = testpstate_new(); + + while(!feof(stdin)){ + char car = fgetc(stdin); + test_append_bytes(&car, 1, scanner); + int statusYacc; + do{ + statusYacc = 0; + int statusLex = testlex(&pushed_value, &pushed_location, scanner); + if(!statusLex){break;} + if(statusLex == YY_STALLED){ + printf("Not invoking parser because we are STALLED\n"); + }else{ + statusYacc = testpush_parse(ps, statusLex, &pushed_value, &pushed_location, scanner); + printf("[%d:%d]", statusLex, statusYacc); + } + }while(statusYacc==YYPUSH_MORE); + } + + testlex_destroy ( scanner ); + return 0; +} + + +/* vim:set tabstop=8 softtabstop=4 shiftwidth=4: */ diff --git a/tests/bison_yylloc_p.txt b/tests/bison_yylloc_p.txt new file mode 100644 index 000000000..94adcb2f2 --- /dev/null +++ b/tests/bison_yylloc_p.txt @@ -0,0 +1,4 @@ +0001: FIRSTNAME=firstname +0002: MIDDLENAME=middle +0003: LASTNAME=lastname +0004: ADDRESS=address diff --git a/tests/bison_yylloc_parser.y b/tests/bison_yylloc_parser.y index 93c63c025..7adeb40e6 100644 --- a/tests/bison_yylloc_parser.y +++ b/tests/bison_yylloc_parser.y @@ -54,7 +54,7 @@ static int process_text(char* s) { %} -%pure-parser +%define api.pure %union { int lineno; diff --git a/tests/bison_yylloc_parser_p.y b/tests/bison_yylloc_parser_p.y new file mode 100644 index 000000000..37c8df791 --- /dev/null +++ b/tests/bison_yylloc_parser_p.y @@ -0,0 +1,103 @@ +/* + * This file is part of flex. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * Neither the name of the University nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE. + */ + +%parse-param { void* scanner } +%lex-param { void* scanner } + +/* + How to compile: + bison --defines --output-file="bison_yylloc_parser.c" --name-prefix="test" parser.y + */ +%{ +#include +#include +#include +#include "config.h" +#include "bison_yylloc_parser_p.h" +#include "bison_yylloc_scanner_p.h" + +int yyerror(YYLTYPE *location, void* scanner, const char* msg); + +#define YYERROR_VERBOSE 1 + + +/* A dummy function. A check against seg-faults in yylval->str. */ +static int process_text(char* s) { + int total =0; + while(*s) { + total += (int) *s; + ++s; + } + return total; +} + + +%} + +%define api.pure full +%define api.push-pull push + +%union { + int lineno; + char * str; +} +%token IDENT +%token LINENO +%token EQUAL "=" +%token COLON ":" +%token SPACE " " + +%token YY_STALLED +%% + +file: + line + | file line + ; + +line: + LINENO COLON SPACE IDENT EQUAL IDENT + { + process_text($4); + process_text($6); + /* Check lineno. */ + if( $1 != @1.first_line || $1 != testget_lineno(scanner)) + { + yyerror(0, 0, "Parse failed: Line numbers do not match."); + YYABORT; + } + + /* Recreate the line to stdout. */ + printf ( "%04d: %s=%s\n", @1.first_line, $4, $6); + } + ; + +%% + +int yyerror(YYLTYPE *location, void* scanner, const char* msg) { + (void)location; + (void)scanner; + fprintf(stderr,"%s\n",msg); + return 0; +} + diff --git a/tests/bison_yylloc_scanner_p.l b/tests/bison_yylloc_scanner_p.l new file mode 100644 index 000000000..170fbf3ae --- /dev/null +++ b/tests/bison_yylloc_scanner_p.l @@ -0,0 +1,66 @@ +/* + * This file is part of flex. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * Neither the name of the University nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE. + */ + +%{ +/* The scanner expects to link to bison yylval . */ +#include +#include +#include "bison_yylloc_parser_p.h" +#include "config.h" +static char* STRDUP(char* s1); +#define YY_EXTRA_TYPE int +%} + +%option 8bit prefix="test" +%option reentrant bison-bridge bison-locations yylineno +%option header="bison_yylloc_scanner_p.h" +%option nomain nounput noyy_top_state noyywrap nodefault noinput warn +%option yystall="YY_STALLED" + + +%% + + if ( !yyextra) + yyextra = 1; + +^[[:digit:]]+ { + yylval->lineno = yyextra++; + yylloc->first_line = (int)strtol(yytext,NULL,10); + return LINENO; + } +":" { return COLON; } +" " { return SPACE; } +"=" { return EQUAL; } +[[:alnum:]_]+ { yylval->str = STRDUP(yytext); return IDENT;} + +\r|\n { } +. { yyterminate();} +%% + + +static char* STRDUP(char* s1) +{ + char* s2 = malloc(strlen(s1)+1); + sprintf(s2,"%s",s1); + return s2; +} diff --git a/tests/bison_yylval_main_p.c b/tests/bison_yylval_main_p.c new file mode 100644 index 000000000..3d7e1cfbe --- /dev/null +++ b/tests/bison_yylval_main_p.c @@ -0,0 +1,63 @@ +/* + * This file is part of flex. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * Neither the name of the University nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE. + */ + +#include "bison_yylval_parser_p.h" +#include "bison_yylval_scanner_p.h" + +int main ( int argc, char** argv ) +{ + yyscan_t scanner; + YYSTYPE pushed_value; + testpstate * ps; + + (void)argc; + (void)argv; + + /*yydebug =1;*/ + testlex_init ( &scanner ); + testset_in(stdin,scanner); + ps = testpstate_new(); + + while(!feof(stdin)){ + char car = fgetc(stdin); + test_append_bytes(&car, 1, scanner); + int statusYacc; + do{ + statusYacc = 0; + int statusLex = testlex(&pushed_value, scanner); + if(!statusLex){break;} + if(statusLex == YY_STALLED){ + printf("Not invoking parser because we are STALLED\n"); + }else{ + statusYacc = testpush_parse(ps, statusLex, &pushed_value, scanner); + printf("[%d:%d]", statusLex, statusYacc); + } + }while(statusYacc==YYPUSH_MORE); + } + + testlex_destroy ( scanner ); + return 0; +} + + +/* vim:set tabstop=8 softtabstop=4 shiftwidth=4: */ diff --git a/tests/bison_yylval_p.txt b/tests/bison_yylval_p.txt new file mode 100644 index 000000000..846f206df --- /dev/null +++ b/tests/bison_yylval_p.txt @@ -0,0 +1,5 @@ + + + This is a test + + diff --git a/tests/bison_yylval_parser_p.y b/tests/bison_yylval_parser_p.y new file mode 100644 index 000000000..0e6c0bb0c --- /dev/null +++ b/tests/bison_yylval_parser_p.y @@ -0,0 +1,87 @@ +/* + * This file is part of flex. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * Neither the name of the University nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE. + */ + +/* Accepts html-like input. + How to compile: + bison --defines --output-file="parser.c" --name-prefix="test" parser.y + */ +%parse-param { void* scanner } +%lex-param { void* scanner } +%{ +#include +#include +#include +#include "config.h" +#include "bison_yylval_parser_p.h" +#include "bison_yylval_scanner_p.h" + +#define YYERROR_VERBOSE 1 + +int yyerror(void* scanner, const char* msg); + +/* A dummy function. A check against seg-faults in yylval->str. */ +static int process_text(char* s) { + int total =0; + while(*s) { + total += (int) *s; + ++s; + } + return total; +} + + +%} + +%define api.pure full +%define api.push-pull push + +%union { + long unused; + char * str; +} + +%token TAGNAME TEXT +%token LT +%token GT +%token LTSLASH " +#include +#include "bison_yylval_parser_p.h" +#include "config.h" +static char* STRDUP(char* s1); + +enum yesno_t { no=0, yes=1 }; +#define YY_EXTRA_TYPE enum yesno_t +%} + +%option 8bit prefix="test" +%option reentrant bison-bridge +%option header="bison_yylval_scanner_p.h" +%option noyywrap nomain nounput noyy_top_state noyywrap nodefault noinput warn +%option stack yystall="YY_STALLED" + + +%x IN_TAG +%x DISCARD_THRU_GT +%% + + #define YY_USER_INIT yyextra = no; + #define NEED_TAG_NAME yyextra + + +{ +"str = STRDUP(yytext); return TEXT;} +} +{ +">" { yy_pop_state( yyscanner ); return GT; } +[[:alpha:]][[:alnum:]]* { + if( NEED_TAG_NAME == yes){ + NEED_TAG_NAME=no; + yylval->str = STRDUP(yytext); + return TAGNAME; + } + } + +.|\r|\n { } +} +{ +[^>]{1,512} { } +">" { yy_pop_state(yyscanner);} +} +%% + + +static char* STRDUP(char* s1) +{ + char* s2 = malloc(strlen(s1)+1); + sprintf(s2,"%s",s1); + return s2; +} diff --git a/tests/cxx_multiple_scanners_1_p.ll b/tests/cxx_multiple_scanners_1_p.ll new file mode 100644 index 000000000..cfbb10a80 --- /dev/null +++ b/tests/cxx_multiple_scanners_1_p.ll @@ -0,0 +1,46 @@ + // This file is part of flex. + // + // Redistribution and use in source and binary forms, with or without + // modification, are permitted provided that the following conditions + // are met: + // + // 1. Redistributions of source code must retain the above copyright + // notice, this list of conditions and the following disclaimer. + // 2. Redistributions in binary form must reproduce the above copyright + // notice, this list of conditions and the following disclaimer in the + // documentation and/or other materials provided with the distribution. + // + // Neither the name of the University nor the names of its contributors + // may be used to endorse or promote products derived from this software + // without specific prior written permission. + // + // THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR + // IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED + // WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + // PURPOSE. + +%{ +#include "config.h" + +%} + +%option 8bit prefix="S1_" +%option nounput nomain noyywrap +%option warn stack noyy_top_state +%option yystall="0xBADC0DE1" +%option header="cxx_multiple_scanners_1_p.h" + +%x ON +%x OFF +%% +{ +on yy_push_state(ON); return 10; +off yy_push_state(OFF); return 11; +.|\n return 12; +} +.|\n yy_pop_state(); return 13; + +.|\n yy_pop_state(); return 14; + +%% + diff --git a/tests/cxx_multiple_scanners_2_p.ll b/tests/cxx_multiple_scanners_2_p.ll new file mode 100644 index 000000000..f10d0708c --- /dev/null +++ b/tests/cxx_multiple_scanners_2_p.ll @@ -0,0 +1,50 @@ + // This file is part of flex. + // + // Redistribution and use in source and binary forms, with or without + // modification, are permitted provided that the following conditions + // are met: + // + // 1. Redistributions of source code must retain the above copyright + // notice, this list of conditions and the following disclaimer. + // 2. Redistributions in binary form must reproduce the above copyright + // notice, this list of conditions and the following disclaimer in the + // documentation and/or other materials provided with the distribution. + // + // Neither the name of the University nor the names of its contributors + // may be used to endorse or promote products derived from this software + // without specific prior written permission. + // + // THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR + // IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED + // WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + // PURPOSE. + +%{ +#include "config.h" + +%} + +%option 8bit prefix="S2_" +%option nounput nomain +%option warn stack noyy_top_state +%option yystall="0xBADC0DE2" +%option header="cxx_multiple_scanners_2_p.h" + +%x OFF +%x ON +%% +{ +on yy_push_state(ON); return 3; +off yy_push_state(OFF); return 4; +.|\n return 5; +} +.|\n yy_pop_state(); return 6; + +.|\n yy_pop_state(); return 7; +%% + +int S2_FlexLexer::yywrap() +{ + std::cout << "NOW WRAPPING." << std::endl; + return 1; +} diff --git a/tests/cxx_multiple_scanners_main_p.cc b/tests/cxx_multiple_scanners_main_p.cc new file mode 100644 index 000000000..7c79defa8 --- /dev/null +++ b/tests/cxx_multiple_scanners_main_p.cc @@ -0,0 +1,65 @@ +/* + * This file is part of flex. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * Neither the name of the University nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE. + */ + +#include + +/*#undef yyFlexLexer +#define yyFlexLexer S1_FlexLexer +#include */ +#include "cxx_multiple_scanners_1_p.h" + +/*#undef yyFlexLexer +#define yyFlexLexer S2_FlexLexer +#include */ +#include "cxx_multiple_scanners_2_p.h" + +int +main ( int argc, char** argv ) +{ + int S1_ok=1, S2_ok=1; + S1_FlexLexer* S1 = new S1_FlexLexer; + S2_FlexLexer* S2 = new S2_FlexLexer; + + // scan simultaneously. + while((S1_ok || S2_ok) && !std::cin.eof()) + { + char ch; + std::cin.get(ch); + if (S1_ok){ + do{ + std::cin.get(ch); + S1->yy_append_bytes(&ch, 1); + S1_ok = S1->yylex(); + }while(S1_ok == YY_STALLED); + } + if (S2_ok) + S2_ok = S2->yylex(); + } + printf("TEST RETURNING OK.\n"); + delete S1; + delete S2; + return 0; +} + + +/* vim:set tabstop=8 softtabstop=4 shiftwidth=4: */ diff --git a/tests/cxx_multiple_scanners_p.txt b/tests/cxx_multiple_scanners_p.txt new file mode 100644 index 000000000..08498fa17 --- /dev/null +++ b/tests/cxx_multiple_scanners_p.txt @@ -0,0 +1 @@ +foo on bar off