1 /* gen - actual generation (writing) of flex scanners */
4 * Copyright (c) 1990 The Regents of the University of California.
7 * This code is derived from software contributed to Berkeley by
10 * The United States Government has rights in this work pursuant
11 * to contract no. DE-AC03-76SF00098 between the United States
12 * Department of Energy and the University of California.
14 * Redistribution and use in source and binary forms are permitted provided
15 * that: (1) source distributions retain this entire copyright notice and
16 * comment, and (2) distributions including binaries display the following
17 * acknowledgement: ``This product includes software developed by the
18 * University of California, Berkeley and its contributors'' in the
19 * documentation or other materials provided with the distribution and in
20 * all advertising materials mentioning features or use of this software.
21 * Neither the name of the University nor the names of its contributors may
22 * be used to endorse or promote products derived from this software without
23 * specific prior written permission.
24 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR IMPLIED
25 * WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF
26 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
31 "@(#) $Id: gen.c,v 1.3 1994/06/24 10:56:56 ceriel Exp $ (LBL)";
37 /* declare functions that have forward references */
39 void gen_next_state PROTO((int));
40 void genecs PROTO(());
41 void indent_put2s PROTO((char [], char []));
42 void indent_puts PROTO((char []));
45 static int indent_level = 0; /* each level is 4 spaces */
47 #define indent_up() (++indent_level)
48 #define indent_down() (--indent_level)
49 #define set_indent(indent_val) indent_level = indent_val
51 /* *everything* is done in terms of arrays starting at 1, so provide
52 * a null entry for the zero element of all C arrays
54 static char C_short_decl[] = "static const short int %s[%d] =\n { 0,\n";
55 static char C_long_decl[] = "static const long int %s[%d] =\n { 0,\n";
56 static char C_state_decl[] =
57 "static const yy_state_type %s[%d] =\n { 0,\n";
60 /* indent to the current level */
65 register int i = indent_level * 4;
81 /* generate the code to keep backtracking information */
83 void gen_backtracking()
86 if ( reject || num_backtracking == 0 )
90 indent_puts( "if ( yy_current_state[-1].yy_nxt )" );
92 indent_puts( "if ( yy_accept[yy_current_state] )" );
96 indent_puts( "yy_last_accepting_state = yy_current_state;" );
97 indent_puts( "yy_last_accepting_cpos = yy_cp;" );
103 /* generate the code to perform the backtrack */
108 if ( reject || num_backtracking == 0 )
113 indent_puts( "case 0: /* must backtrack */" );
114 indent_puts( "/* undo the effects of YY_DO_BEFORE_ACTION */" );
115 indent_puts( "*yy_cp = yy_hold_char;" );
117 if ( fullspd || fulltbl )
118 indent_puts( "yy_cp = yy_last_accepting_cpos + 1;" );
120 /* backtracking info for compressed tables is taken \after/
121 * yy_cp has been incremented for the next state
123 indent_puts( "yy_cp = yy_last_accepting_cpos;" );
125 indent_puts( "yy_current_state = yy_last_accepting_state;" );
126 indent_puts( "goto yy_find_action;" );
133 /* genctbl - generates full speed compressed transition table
143 int end_of_buffer_action = num_rules + 1;
145 /* table of verify for transition and offset to next state */
146 printf( "static const struct yy_trans_info yy_transition[%d] =\n",
147 tblend + numecs + 1 );
150 /* We want the transition to be represented as the offset to the
151 * next state, not the actual state number, which is what it currently is.
152 * The offset is base[nxt[i]] - base[chk[i]]. That's just the
153 * difference between the starting points of the two involved states
156 * first, though, we need to find some way to put in our end-of-buffer
157 * flags and states. We do this by making a state with absolutely no
158 * transitions. We put it at the end of the table.
160 /* at this point, we're guaranteed that there's enough room in nxt[]
161 * and chk[] to hold tblend + numecs entries. We need just two slots.
162 * One for the action and one for the end-of-buffer transition. We
163 * now *assume* that we're guaranteed the only character we'll try to
164 * index this nxt/chk pair with is EOB, i.e., 0, so we don't have to
165 * make sure there's room for jam entries for other characters.
168 base[lastdfa + 1] = tblend + 2;
169 nxt[tblend + 1] = end_of_buffer_action;
170 chk[tblend + 1] = numecs + 1;
171 chk[tblend + 2] = 1; /* anything but EOB */
172 nxt[tblend + 2] = 0; /* so that "make test" won't show arb. differences */
174 /* make sure every state has a end-of-buffer transition and an action # */
175 for ( i = 0; i <= lastdfa; ++i )
177 register int anum = dfaacc[i].dfaacc_state;
179 chk[base[i]] = EOB_POSITION;
180 chk[base[i] - 1] = ACTION_POSITION;
181 nxt[base[i] - 1] = anum; /* action number */
184 for ( i = 0; i <= tblend; ++i )
186 if ( chk[i] == EOB_POSITION )
187 transition_struct_out( 0, base[lastdfa + 1] - i );
189 else if ( chk[i] == ACTION_POSITION )
190 transition_struct_out( 0, nxt[i] );
192 else if ( chk[i] > numecs || chk[i] == 0 )
193 transition_struct_out( 0, 0 ); /* unused slot */
195 else /* verify, transition */
196 transition_struct_out( chk[i], base[nxt[i]] - (i - chk[i]) );
200 /* here's the final, end-of-buffer state */
201 transition_struct_out( chk[tblend + 1], nxt[tblend + 1] );
202 transition_struct_out( chk[tblend + 2], nxt[tblend + 2] );
207 /* table of pointers to start states */
208 printf( "static const struct yy_trans_info *yy_start_state_list[%d] =\n",
212 for ( i = 0; i <= lastsc * 2; ++i )
213 printf( " &yy_transition[%d],\n", base[i] );
222 /* generate equivalence-class tables */
228 static char C_char_decl[] = "static const %s %s[%d] =\n { 0,\n";
232 if ( numecs < csize )
233 printf( C_char_decl, "YY_CHAR", "yy_ec", csize );
235 printf( C_char_decl, "short", "yy_ec", csize );
237 for ( i = 1; i < csize; ++i )
239 if ( caseins && (i >= 'A') && (i <= 'Z') )
240 ecgroup[i] = ecgroup[clower( i )];
242 ecgroup[i] = abs( ecgroup[i] );
243 mkdata( ecgroup[i] );
250 char *readable_form();
252 fputs( "\n\nEquivalence Classes:\n\n", stderr );
256 for ( j = 0; j < numrows; ++j )
258 for ( i = j; i < csize; i = i + numrows )
260 fprintf( stderr, "%4s = %-2d", readable_form( i ), ecgroup[i] );
265 putc( '\n', stderr );
271 /* generate the code to find the action number */
273 void gen_find_action()
277 indent_puts( "yy_act = yy_current_state[-1].yy_nxt;" );
280 indent_puts( "yy_act = yy_accept[yy_current_state];" );
284 indent_puts( "yy_current_state = *--yy_state_ptr;" );
285 indent_puts( "yy_lp = yy_accept[yy_current_state];" );
287 puts( "find_rule: /* we branch to this label when backtracking */" );
289 indent_puts( "for ( ; ; ) /* until we find what rule we matched */" );
295 indent_puts( "if ( yy_lp && yy_lp < yy_accept[yy_current_state + 1] )" );
298 indent_puts( "yy_act = yy_acclist[yy_lp];" );
300 if ( variable_trailing_context_rules )
302 indent_puts( "if ( yy_act & YY_TRAILING_HEAD_MASK ||" );
303 indent_puts( " yy_looking_for_trail_begin )" );
307 indent_puts( "if ( yy_act == yy_looking_for_trail_begin )" );
310 indent_puts( "yy_looking_for_trail_begin = 0;" );
311 indent_puts( "yy_act &= ~YY_TRAILING_HEAD_MASK;" );
312 indent_puts( "break;" );
319 indent_puts( "else if ( yy_act & YY_TRAILING_MASK )" );
323 "yy_looking_for_trail_begin = yy_act & ~YY_TRAILING_MASK;" );
325 "yy_looking_for_trail_begin |= YY_TRAILING_HEAD_MASK;" );
329 /* remember matched text in case we back up due to REJECT */
330 indent_puts( "yy_full_match = yy_cp;" );
331 indent_puts( "yy_full_state = yy_state_ptr;" );
332 indent_puts( "yy_full_lp = yy_lp;" );
338 indent_puts( "else" );
341 indent_puts( "yy_full_match = yy_cp;" );
342 indent_puts( "yy_full_state = yy_state_ptr;" );
343 indent_puts( "yy_full_lp = yy_lp;" );
344 indent_puts( "break;" );
348 indent_puts( "++yy_lp;" );
349 indent_puts( "goto find_rule;" );
354 /* remember matched text in case we back up due to trailing context
359 indent_puts( "yy_full_match = yy_cp;" );
360 indent_puts( "break;" );
368 indent_puts( "--yy_cp;" );
370 /* we could consolidate the following two lines with those at
371 * the beginning, but at the cost of complaints that we're
372 * branching inside a loop
374 indent_puts( "yy_current_state = *--yy_state_ptr;" );
375 indent_puts( "yy_lp = yy_accept[yy_current_state];" );
384 indent_puts( "yy_act = yy_accept[yy_current_state];" );
388 /* genftbl - generates full transition table
398 int end_of_buffer_action = num_rules + 1;
400 printf( C_short_decl, "yy_accept", lastdfa + 1 );
403 dfaacc[end_of_buffer_state].dfaacc_state = end_of_buffer_action;
405 for ( i = 1; i <= lastdfa; ++i )
407 register int anum = dfaacc[i].dfaacc_state;
412 fprintf( stderr, "state # %d accepts: [%d]\n", i, anum );
420 /* don't have to dump the actual full table entries - they were created
426 /* generate the code to find the next compressed-table state */
428 void gen_next_compressed_state( char_map )
432 indent_put2s( "register YY_CHAR yy_c = %s;", char_map );
434 /* save the backtracking info \before/ computing the next state
435 * because we always compute one more state than needed - we
436 * always proceed until we reach a jam state
441 "while ( yy_chk[yy_base[yy_current_state] + yy_c] != yy_current_state )" );
444 indent_puts( "yy_current_state = yy_def[yy_current_state];" );
448 /* we've arrange it so that templates are never chained
449 * to one another. This means we can afford make a
450 * very simple test to see if we need to convert to
451 * yy_c's meta-equivalence class without worrying
452 * about erroneously looking up the meta-equivalence
456 /* lastdfa + 2 is the beginning of the templates */
457 printf( "if ( yy_current_state >= %d )\n", lastdfa + 2 );
460 indent_puts( "yy_c = yy_meta[yy_c];" );
468 "yy_current_state = yy_nxt[yy_base[yy_current_state] + yy_c];" );
472 /* generate the code to find the next match */
474 void gen_next_match()
477 /* NOTE - changes in here should be reflected in gen_next_state() and
480 char *char_map = useecs ? "yy_ec[*yy_cp]" : "*yy_cp";
481 char *char_map_2 = useecs ? "yy_ec[*++yy_cp]" : "*++yy_cp";
486 "while ( (yy_current_state = yy_nxt[yy_current_state][%s]) > 0 )",
491 if ( num_backtracking > 0 )
498 indent_puts( "++yy_cp;" );
500 if ( num_backtracking > 0 )
506 indent_puts( "yy_current_state = -yy_current_state;" );
512 indent_puts( "register const struct yy_trans_info *yy_trans_info;\n" );
513 indent_puts( "register YY_CHAR yy_c;\n" );
514 indent_put2s( "for ( yy_c = %s;", char_map );
516 " (yy_trans_info = &yy_current_state[yy_c])->yy_verify == yy_c;" );
517 indent_put2s( " yy_c = %s )", char_map_2 );
521 if ( num_backtracking > 0 )
524 indent_puts( "yy_current_state += yy_trans_info->yy_nxt;" );
526 if ( num_backtracking > 0 )
544 gen_next_state( false );
546 indent_puts( "++yy_cp;" );
554 printf( "while ( yy_base[yy_current_state] != %d );\n", jambase );
556 printf( "while ( yy_current_state != %d );\n", jamstate );
558 if ( ! reject && ! interactive )
560 /* do the guaranteed-needed backtrack to figure out the match */
561 indent_puts( "yy_cp = yy_last_accepting_cpos;" );
562 indent_puts( "yy_current_state = yy_last_accepting_state;" );
568 /* generate the code to find the next state */
570 void gen_next_state( worry_about_NULs )
571 int worry_about_NULs;
573 { /* NOTE - changes in here should be reflected in get_next_match() */
576 if ( worry_about_NULs && ! nultrans )
579 (void) sprintf( char_map, "(*yy_cp ? yy_ec[*yy_cp] : %d)", NUL_ec );
581 (void) sprintf( char_map, "(*yy_cp ? *yy_cp : %d)", NUL_ec );
585 (void) strcpy( char_map, useecs ? "yy_ec[*yy_cp]" : "*yy_cp" );
587 if ( worry_about_NULs && nultrans )
589 if ( ! fulltbl && ! fullspd )
590 /* compressed tables backtrack *before* they match */
593 indent_puts( "if ( *yy_cp )" );
599 indent_put2s( "yy_current_state = yy_nxt[yy_current_state][%s];",
603 indent_put2s( "yy_current_state += yy_current_state[%s].yy_nxt;",
607 gen_next_compressed_state( char_map );
609 if ( worry_about_NULs && nultrans )
613 indent_puts( "else" );
615 indent_puts( "yy_current_state = yy_NUL_trans[yy_current_state];" );
619 if ( fullspd || fulltbl )
623 indent_puts( "*yy_state_ptr++ = yy_current_state;" );
627 /* generate the code to make a NUL transition */
631 { /* NOTE - changes in here should be reflected in get_next_match() */
632 int need_backtracking = (num_backtracking > 0 && ! reject);
634 if ( need_backtracking )
635 /* we'll need yy_cp lying around for the gen_backtracking() */
636 indent_puts( "register YY_CHAR *yy_cp = yy_c_buf_p;" );
642 indent_puts( "yy_current_state = yy_NUL_trans[yy_current_state];" );
643 indent_puts( "yy_is_jam = (yy_current_state == 0);" );
649 printf( "yy_current_state = yy_nxt[yy_current_state][%d];\n",
651 indent_puts( "yy_is_jam = (yy_current_state <= 0);" );
657 printf( "register int yy_c = %d;\n", NUL_ec );
660 "register const struct yy_trans_info *yy_trans_info;\n" );
661 indent_puts( "yy_trans_info = &yy_current_state[yy_c];" );
662 indent_puts( "yy_current_state += yy_trans_info->yy_nxt;" );
664 indent_puts( "yy_is_jam = (yy_trans_info->yy_verify != yy_c);" );
671 (void) sprintf( NUL_ec_str, "%d", NUL_ec );
672 gen_next_compressed_state( NUL_ec_str );
675 indent_puts( "*yy_state_ptr++ = yy_current_state;" );
680 printf( "yy_is_jam = (yy_base[yy_current_state] == %d);\n",
683 printf( "yy_is_jam = (yy_current_state == %d);\n", jamstate );
686 /* if we've entered an accepting state, backtrack; note that
687 * compressed tables have *already* done such backtracking, so
688 * we needn't bother with it again
690 if ( need_backtracking && (fullspd || fulltbl) )
693 indent_puts( "if ( ! yy_is_jam )" );
703 /* generate the code to find the start state */
705 void gen_start_state()
709 indent_put2s( "yy_current_state = yy_start_state_list[yy_start%s];",
710 bol_needed ? " + (yy_bp[-1] == '\\n' ? 1 : 0)" : "" );
714 indent_puts( "yy_current_state = yy_start;" );
718 indent_puts( "if ( yy_bp[-1] == '\\n' )" );
720 indent_puts( "++yy_current_state;" );
726 /* set up for storing up states */
727 indent_puts( "yy_state_ptr = yy_state_buf;" );
728 indent_puts( "*yy_state_ptr++ = yy_current_state;" );
734 /* gentabs - generate data statements for the transition tables
743 int i, j, k, *accset, nacc, *acc_array, total_states;
744 int end_of_buffer_action = num_rules + 1;
746 /* *everything* is done in terms of arrays starting at 1, so provide
747 * a null entry for the zero element of all C arrays
749 static char C_char_decl[] =
750 "static const YY_CHAR %s[%d] =\n { 0,\n";
752 acc_array = allocate_integer_array( current_max_dfas );
755 /* the compressed table format jams by entering the "jam state",
756 * losing information about the previous state in the process.
757 * In order to recover the previous state, we effectively need
758 * to keep backtracking information.
764 /* write out accepting list and pointer list
766 * first we generate the "yy_acclist" array. In the process, we compute
767 * the indices that will go into the "yy_accept" array, and save the
768 * indices in the dfaacc array
770 int EOB_accepting_list[2];
772 /* set up accepting structures for the End Of Buffer state */
773 EOB_accepting_list[0] = 0;
774 EOB_accepting_list[1] = end_of_buffer_action;
775 accsiz[end_of_buffer_state] = 1;
776 dfaacc[end_of_buffer_state].dfaacc_set = EOB_accepting_list;
778 printf( C_short_decl, "yy_acclist", max( numas, 1 ) + 1 );
780 j = 1; /* index into "yy_acclist" array */
782 for ( i = 1; i <= lastdfa; ++i )
786 if ( accsiz[i] != 0 )
788 accset = dfaacc[i].dfaacc_set;
792 fprintf( stderr, "state # %d accepts: ", i );
794 for ( k = 1; k <= nacc; ++k )
796 int accnum = accset[k];
800 if ( variable_trailing_context_rules &&
801 ! (accnum & YY_TRAILING_HEAD_MASK) &&
802 accnum > 0 && accnum <= num_rules &&
803 rule_type[accnum] == RULE_VARIABLE )
805 /* special hack to flag accepting number as part
806 * of trailing context rule
808 accnum |= YY_TRAILING_MASK;
815 fprintf( stderr, "[%d]", accset[k] );
818 fputs( ", ", stderr );
820 putc( '\n', stderr );
826 /* add accepting number for the "jam" state */
834 dfaacc[end_of_buffer_state].dfaacc_state = end_of_buffer_action;
836 for ( i = 1; i <= lastdfa; ++i )
837 acc_array[i] = dfaacc[i].dfaacc_state;
839 /* add accepting number for jam state */
843 /* spit out "yy_accept" array. If we're doing "reject", it'll be pointers
844 * into the "yy_acclist" array. Otherwise it's actual accepting numbers.
845 * In either case, we just dump the numbers.
848 /* "lastdfa + 2" is the size of "yy_accept"; includes room for C arrays
849 * beginning at 0 and for "jam" state
854 /* we put a "cap" on the table associating lists of accepting
855 * numbers with state numbers. This is needed because we tell
856 * where the end of an accepting list is by looking at where
857 * the list for the next state starts.
861 printf( C_short_decl, "yy_accept", k );
863 for ( i = 1; i <= lastdfa; ++i )
865 mkdata( acc_array[i] );
867 if ( ! reject && trace && acc_array[i] )
868 fprintf( stderr, "state # %d accepts: [%d]\n", i, acc_array[i] );
871 /* add entry for "jam" state */
872 mkdata( acc_array[i] );
875 /* add "cap" for the list */
876 mkdata( acc_array[i] );
885 /* write out meta-equivalence classes (used to index templates with) */
888 fputs( "\n\nMeta-Equivalence Classes:\n", stderr );
890 printf( C_char_decl, "yy_meta", numecs + 1 );
892 for ( i = 1; i <= numecs; ++i )
895 fprintf( stderr, "%d = %d\n", i, abs( tecbck[i] ) );
897 mkdata( abs( tecbck[i] ) );
903 total_states = lastdfa + numtemps;
905 printf( tblend > MAX_SHORT ? C_long_decl : C_short_decl,
906 "yy_base", total_states + 1 );
908 for ( i = 1; i <= lastdfa; ++i )
910 register int d = def[i];
912 if ( base[i] == JAMSTATE )
920 /* template reference */
922 def[i] = lastdfa - d + 1;
928 /* generate jam state's base index */
931 for ( ++i /* skip jam state */; i <= total_states; ++i )
939 printf( tblend > MAX_SHORT ? C_long_decl : C_short_decl,
940 "yy_def", total_states + 1 );
942 for ( i = 1; i <= total_states; ++i )
947 printf( lastdfa > MAX_SHORT ? C_long_decl : C_short_decl,
948 "yy_nxt", tblend + 1 );
950 for ( i = 1; i <= tblend; ++i )
952 if ( nxt[i] == 0 || chk[i] == 0 )
953 nxt[i] = jamstate; /* new state is the JAM state */
960 printf( lastdfa > MAX_SHORT ? C_long_decl : C_short_decl,
961 "yy_chk", tblend + 1 );
963 for ( i = 1; i <= tblend; ++i )
975 /* write out a formatted string (with a secondary string argument) at the
976 * current indentation level, adding a final newline
979 void indent_put2s( fmt, arg )
989 /* write out a string at the current indentation level, adding a final
993 void indent_puts( str )
1002 /* make_tables - generate transition tables
1007 * Generates transition tables and finishes generating output file
1014 int did_eof_rule = false;
1018 /* first, take care of YY_DO_BEFORE_ACTION depending on yymore being used */
1023 indent_puts( "yytext -= yy_more_len; \\" );
1024 indent_puts( "yyleng = yy_cp - yytext; \\" );
1028 indent_puts( "yyleng = yy_cp - yy_bp; \\" );
1035 printf( "#define YY_END_OF_BUFFER %d\n", num_rules + 1 );
1038 { /* need to define the transet type as a size large
1039 * enough to hold the biggest offset
1041 int total_table_size = tblend + numecs + 1;
1042 char *trans_offset_type =
1043 total_table_size > MAX_SHORT ? "long" : "short";
1046 indent_puts( "struct yy_trans_info" );
1049 indent_puts( "short yy_verify;" );
1051 /* in cases where its sister yy_verify *is* a "yes, there is a
1052 * transition", yy_nxt is the offset (in records) to the next state.
1053 * In most cases where there is no transition, the value of yy_nxt
1054 * is irrelevant. If yy_nxt is the -1th record of a state, though,
1055 * then yy_nxt is the action number for that state
1058 indent_put2s( "%s yy_nxt;", trans_offset_type );
1059 indent_puts( "};" );
1062 indent_puts( "typedef const struct yy_trans_info *yy_state_type;" );
1066 indent_puts( "typedef int yy_state_type;" );
1077 if ( num_backtracking > 0 )
1079 indent_puts( "static yy_state_type yy_last_accepting_state;" );
1080 indent_puts( "static YY_CHAR *yy_last_accepting_cpos;\n" );
1085 printf( C_state_decl, "yy_NUL_trans", lastdfa + 1 );
1087 for ( i = 1; i <= lastdfa; ++i )
1092 printf( " &yy_transition[%d],\n", base[i] );
1098 mkdata( nultrans[i] );
1105 { /* spit out table mapping rules to line numbers */
1106 indent_puts( "extern int yy_flex_debug;" );
1107 indent_puts( "int yy_flex_debug = 1;\n" );
1109 printf( C_short_decl, "yy_rule_linenum", num_rules );
1110 for ( i = 1; i < num_rules; ++i )
1111 mkdata( rule_linenum[i] );
1117 /* declare state buffer variables */
1119 "static yy_state_type yy_state_buf[YY_BUF_SIZE + 2], *yy_state_ptr;" );
1120 puts( "static YY_CHAR *yy_full_match;" );
1121 puts( "static int yy_lp;" );
1123 if ( variable_trailing_context_rules )
1125 puts( "static int yy_looking_for_trail_begin = 0;" );
1126 puts( "static int yy_full_lp;" );
1127 puts( "static int *yy_full_state;" );
1128 printf( "#define YY_TRAILING_MASK 0x%x\n", YY_TRAILING_MASK );
1129 printf( "#define YY_TRAILING_HEAD_MASK 0x%x\n",
1130 YY_TRAILING_HEAD_MASK );
1133 puts( "#define REJECT \\" );
1136 "*yy_cp = yy_hold_char; /* undo effects of setting up yytext */ \\" );
1138 "yy_cp = yy_full_match; /* restore poss. backed-over text */ \\" );
1140 if ( variable_trailing_context_rules )
1142 puts( "yy_lp = yy_full_lp; /* restore orig. accepting pos. */ \\" );
1144 "yy_state_ptr = yy_full_state; /* restore orig. state */ \\" );
1146 "yy_current_state = *yy_state_ptr; /* restore curr. state */ \\" );
1149 puts( "++yy_lp; \\" );
1150 puts( "goto find_rule; \\" );
1156 puts( "/* the intent behind this definition is that it'll catch" );
1157 puts( " * any uses of REJECT which flex missed" );
1159 puts( "#define REJECT reject_used_but_not_detected" );
1164 indent_puts( "static int yy_more_flag = 0;" );
1165 indent_puts( "static int yy_doing_yy_more = 0;" );
1166 indent_puts( "static int yy_more_len = 0;" );
1168 "#define yymore() { yy_more_flag = 1; }" );
1170 "#define YY_MORE_ADJ (yy_doing_yy_more ? yy_more_len : 0)" );
1175 indent_puts( "#define yymore() yymore_used_but_not_detected" );
1176 indent_puts( "#define YY_MORE_ADJ 0" );
1181 if ( ferror( temp_action_file ) )
1182 flexfatal( "error occurred when writing temporary action file" );
1184 else if ( fclose( temp_action_file ) )
1185 flexfatal( "error occurred when closing temporary action file" );
1187 temp_action_file = fopen( action_file_name, "r" );
1189 if ( temp_action_file == NULL )
1190 flexfatal( "could not re-open temporary action file" );
1192 /* copy prolog from action_file to output file */
1201 indent_puts( "yy_more_len = 0;" );
1202 indent_puts( "yy_doing_yy_more = yy_more_flag;" );
1203 indent_puts( "if ( yy_doing_yy_more )" );
1206 indent_puts( "yy_more_len = yyleng;" );
1207 indent_puts( "yy_more_flag = 0;" );
1216 /* note, don't use any indentation */
1217 puts( "yy_match:" );
1227 indent_puts( "if ( yy_flex_debug )" );
1231 indent_puts( "if ( yy_act == 0 )" );
1233 indent_puts( "fprintf( stderr, \"--scanner backtracking\\n\" );" );
1237 printf( "else if ( yy_act < %d )\n", num_rules );
1240 "fprintf( stderr, \"--accepting rule at line %d (\\\"%s\\\")\\n\"," );
1241 indent_puts( " yy_rule_linenum[yy_act], yytext );" );
1245 printf( "else if ( yy_act == %d )\n", num_rules );
1248 "fprintf( stderr, \"--accepting default rule (\\\"%s\\\")\\n\"," );
1249 indent_puts( " yytext );" );
1253 printf( "else if ( yy_act == %d )\n", num_rules + 1 );
1255 indent_puts( "fprintf( stderr, \"--(end of buffer or a NUL)\\n\" );" );
1261 indent_puts( "fprintf( stderr, \"--EOF\\n\" );" );
1268 /* copy actions from action_file to output file */
1274 /* generate cases for any missing EOF rules */
1275 for ( i = 1; i <= lastsc; ++i )
1279 printf( "case YY_STATE_EOF(%s):\n", scname[i] );
1280 did_eof_rule = true;
1286 indent_puts( "yyterminate();" );
1291 /* generate code for handling NUL's, if needed */
1293 /* first, deal with backtracking and setting up yy_cp if the scanner
1294 * finds that it should JAM on the NUL
1299 if ( fullspd || fulltbl )
1300 indent_puts( "yy_cp = yy_c_buf_p;" );
1303 { /* compressed table */
1304 if ( ! reject && ! interactive )
1306 /* do the guaranteed-needed backtrack to figure out the match */
1307 indent_puts( "yy_cp = yy_last_accepting_cpos;" );
1308 indent_puts( "yy_current_state = yy_last_accepting_state;" );
1313 /* generate code for yy_get_previous_state() */
1318 indent_puts( "register YY_CHAR *yy_bp = yytext;\n" );
1324 gen_next_state( true );
1332 /* copy remainder of input to output */
1334 line_directive_out( stdout );
1335 (void) flexscan(); /* copy remainder of input to output */