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.
29 /* $Header: /home/daffy/u0/vern/flex/RCS/gen.c,v 2.56 96/05/25 20:43:38 vern Exp $ */
30 /* $FreeBSD: src/usr.bin/lex/gen.c,v 1.5 1999/10/27 07:56:44 obrien Exp $ */
35 /* declare functions that have forward references */
37 void gen_next_state PROTO((int));
38 void genecs PROTO((void));
39 void indent_put2s PROTO((char [], char []));
40 void indent_puts PROTO((char []));
43 static int indent_level = 0; /* each level is 8 spaces */
45 #define indent_up() (++indent_level)
46 #define indent_down() (--indent_level)
47 #define set_indent(indent_val) indent_level = indent_val
49 /* Almost everything is done in terms of arrays starting at 1, so provide
50 * a null entry for the zero element of all C arrays. (The exception
51 * to this is that the fast table representation generally uses the
52 * 0 elements of its arrays, too.)
54 static char C_int_decl[] = "static yyconst int %s[%d] =\n { 0,\n";
55 static char C_short_decl[] = "static yyconst short int %s[%d] =\n { 0,\n";
56 static char C_long_decl[] = "static yyconst long int %s[%d] =\n { 0,\n";
57 static char C_state_decl[] =
58 "static yyconst yy_state_type %s[%d] =\n { 0,\n";
61 /* Indent to the current level. */
65 register int i = indent_level * 8;
81 /* Generate the code to keep backing-up information. */
85 if ( reject || num_backing_up == 0 )
89 indent_puts( "if ( yy_current_state[-1].yy_nxt )" );
91 indent_puts( "if ( yy_accept[yy_current_state] )" );
95 indent_puts( "yy_last_accepting_state = yy_current_state;" );
96 indent_puts( "yy_last_accepting_cpos = yy_cp;" );
102 /* Generate the code to perform the backing up. */
106 if ( reject || num_backing_up == 0 )
111 indent_puts( "case 0: /* must back up */" );
112 indent_puts( "/* undo the effects of YY_DO_BEFORE_ACTION */" );
113 indent_puts( "*yy_cp = yy_hold_char;" );
115 if ( fullspd || fulltbl )
116 indent_puts( "yy_cp = yy_last_accepting_cpos + 1;" );
118 /* Backing-up info for compressed tables is taken \after/
119 * yy_cp has been incremented for the next state.
121 indent_puts( "yy_cp = yy_last_accepting_cpos;" );
123 indent_puts( "yy_current_state = yy_last_accepting_state;" );
124 indent_puts( "goto yy_find_action;" );
131 /* genctbl - generates full speed compressed transition table */
136 int end_of_buffer_action = num_rules + 1;
138 /* Table of verify for transition and offset to next state. */
139 out_dec( "static yyconst struct yy_trans_info yy_transition[%d] =\n",
140 tblend + numecs + 1 );
143 /* We want the transition to be represented as the offset to the
144 * next state, not the actual state number, which is what it currently
145 * is. The offset is base[nxt[i]] - (base of current state)]. That's
146 * just the difference between the starting points of the two involved
147 * states (to - from).
149 * First, though, we need to find some way to put in our end-of-buffer
150 * flags and states. We do this by making a state with absolutely no
151 * transitions. We put it at the end of the table.
154 /* We need to have room in nxt/chk for two more slots: One for the
155 * action and one for the end-of-buffer transition. We now *assume*
156 * that we're guaranteed the only character we'll try to index this
157 * nxt/chk pair with is EOB, i.e., 0, so we don't have to make sure
158 * there's room for jam entries for other characters.
161 while ( tblend + 2 >= current_max_xpairs )
164 while ( lastdfa + 1 >= current_max_dfas )
167 base[lastdfa + 1] = tblend + 2;
168 nxt[tblend + 1] = end_of_buffer_action;
169 chk[tblend + 1] = numecs + 1;
170 chk[tblend + 2] = 1; /* anything but EOB */
172 /* So that "make test" won't show arb. differences. */
175 /* Make sure every state has an end-of-buffer transition and an
178 for ( i = 0; i <= lastdfa; ++i )
180 int anum = dfaacc[i].dfaacc_state;
181 int offset = base[i];
183 chk[offset] = EOB_POSITION;
184 chk[offset - 1] = ACTION_POSITION;
185 nxt[offset - 1] = anum; /* action number */
188 for ( i = 0; i <= tblend; ++i )
190 if ( chk[i] == EOB_POSITION )
191 transition_struct_out( 0, base[lastdfa + 1] - i );
193 else if ( chk[i] == ACTION_POSITION )
194 transition_struct_out( 0, nxt[i] );
196 else if ( chk[i] > numecs || chk[i] == 0 )
197 transition_struct_out( 0, 0 ); /* unused slot */
199 else /* verify, transition */
200 transition_struct_out( chk[i],
201 base[nxt[i]] - (i - chk[i]) );
205 /* Here's the final, end-of-buffer state. */
206 transition_struct_out( chk[tblend + 1], nxt[tblend + 1] );
207 transition_struct_out( chk[tblend + 2], nxt[tblend + 2] );
211 /* Table of pointers to start states. */
213 "static yyconst struct yy_trans_info *yy_start_state_list[%d] =\n",
215 outn( " {" ); /* } so vi doesn't get confused */
217 for ( i = 0; i <= lastsc * 2; ++i )
218 out_dec( " &yy_transition[%d],\n", base[i] );
227 /* Generate equivalence-class tables. */
234 out_str_dec( C_int_decl, "yy_ec", csize );
236 for ( i = 1; i < csize; ++i )
238 if ( caseins && (i >= 'A') && (i <= 'Z') )
239 ecgroup[i] = ecgroup[clower( i )];
241 ecgroup[i] = ABS( ecgroup[i] );
242 mkdata( ecgroup[i] );
249 fputs( _( "\n\nEquivalence Classes:\n\n" ), stderr );
253 for ( j = 0; j < numrows; ++j )
255 for ( i = j; i < csize; i = i + numrows )
257 fprintf( stderr, "%4s = %-2d",
258 readable_form( i ), ecgroup[i] );
263 putc( '\n', stderr );
269 /* Generate the code to find the action number. */
271 void gen_find_action()
274 indent_puts( "yy_act = yy_current_state[-1].yy_nxt;" );
277 indent_puts( "yy_act = yy_accept[yy_current_state];" );
281 indent_puts( "yy_current_state = *--yy_state_ptr;" );
282 indent_puts( "yy_lp = yy_accept[yy_current_state];" );
285 "find_rule: /* we branch to this label when backing up */" );
288 "for ( ; ; ) /* until we find what rule we matched */" );
295 "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 )" );
308 "if ( yy_act == yy_looking_for_trail_begin )" );
311 indent_puts( "yy_looking_for_trail_begin = 0;" );
312 indent_puts( "yy_act &= ~YY_TRAILING_HEAD_MASK;" );
313 indent_puts( "break;" );
320 indent_puts( "else if ( yy_act & YY_TRAILING_MASK )" );
324 "yy_looking_for_trail_begin = yy_act & ~YY_TRAILING_MASK;" );
326 "yy_looking_for_trail_begin |= YY_TRAILING_HEAD_MASK;" );
330 /* Remember matched text in case we back up
333 indent_puts( "yy_full_match = yy_cp;" );
334 indent_puts( "yy_full_state = yy_state_ptr;" );
335 indent_puts( "yy_full_lp = yy_lp;" );
341 indent_puts( "else" );
344 indent_puts( "yy_full_match = yy_cp;" );
345 indent_puts( "yy_full_state = yy_state_ptr;" );
346 indent_puts( "yy_full_lp = yy_lp;" );
347 indent_puts( "break;" );
351 indent_puts( "++yy_lp;" );
352 indent_puts( "goto find_rule;" );
357 /* Remember matched text in case we back up due to
358 * trailing context plus REJECT.
362 indent_puts( "yy_full_match = yy_cp;" );
363 indent_puts( "break;" );
371 indent_puts( "--yy_cp;" );
373 /* We could consolidate the following two lines with those at
374 * the beginning, but at the cost of complaints that we're
375 * branching inside a loop.
377 indent_puts( "yy_current_state = *--yy_state_ptr;" );
378 indent_puts( "yy_lp = yy_accept[yy_current_state];" );
387 indent_puts( "yy_act = yy_accept[yy_current_state];" );
389 if ( interactive && ! reject )
391 /* Do the guaranteed-needed backing up to figure out
394 indent_puts( "if ( yy_act == 0 )" );
396 indent_puts( "{ /* have to back up */" );
397 indent_puts( "yy_cp = yy_last_accepting_cpos;" );
399 "yy_current_state = yy_last_accepting_state;" );
400 indent_puts( "yy_act = yy_accept[yy_current_state];" );
408 /* genftbl - generate full transition table */
413 int end_of_buffer_action = num_rules + 1;
415 out_str_dec( long_align ? C_long_decl : C_short_decl,
416 "yy_accept", lastdfa + 1 );
418 dfaacc[end_of_buffer_state].dfaacc_state = end_of_buffer_action;
420 for ( i = 1; i <= lastdfa; ++i )
422 register int anum = dfaacc[i].dfaacc_state;
427 fprintf( stderr, _( "state # %d accepts: [%d]\n" ),
436 /* Don't have to dump the actual full table entries - they were
437 * created on-the-fly.
442 /* Generate the code to find the next compressed-table state. */
444 void gen_next_compressed_state( char_map )
447 indent_put2s( "register YY_CHAR yy_c = %s;", char_map );
449 /* Save the backing-up info \before/ computing the next state
450 * because we always compute one more state than needed - we
451 * always proceed until we reach a jam state
456 "while ( yy_chk[yy_base[yy_current_state] + yy_c] != yy_current_state )" );
459 indent_puts( "yy_current_state = (int) yy_def[yy_current_state];" );
463 /* We've arrange it so that templates are never chained
464 * to one another. This means we can afford to make a
465 * very simple test to see if we need to convert to
466 * yy_c's meta-equivalence class without worrying
467 * about erroneously looking up the meta-equivalence
472 /* lastdfa + 2 is the beginning of the templates */
473 out_dec( "if ( yy_current_state >= %d )\n", lastdfa + 2 );
476 indent_puts( "yy_c = yy_meta[(unsigned int) yy_c];" );
484 "yy_current_state = yy_nxt[yy_base[yy_current_state] + (unsigned int) yy_c];" );
488 /* Generate the code to find the next match. */
490 void gen_next_match()
492 /* NOTE - changes in here should be reflected in gen_next_state() and
495 char *char_map = useecs ?
496 "yy_ec[YY_SC_TO_UI(*yy_cp)]" :
497 "YY_SC_TO_UI(*yy_cp)";
499 char *char_map_2 = useecs ?
500 "yy_ec[YY_SC_TO_UI(*++yy_cp)]" :
501 "YY_SC_TO_UI(*++yy_cp)";
506 "while ( (yy_current_state = yy_nxt[yy_current_state][%s]) > 0 )",
511 if ( num_backing_up > 0 )
513 indent_puts( "{" ); /* } for vi */
518 indent_puts( "++yy_cp;" );
520 if ( num_backing_up > 0 )
527 indent_puts( "yy_current_state = -yy_current_state;" );
532 indent_puts( "{" ); /* } for vi */
534 "register yyconst struct yy_trans_info *yy_trans_info;\n" );
535 indent_puts( "register YY_CHAR yy_c;\n" );
536 indent_put2s( "for ( yy_c = %s;", char_map );
538 " (yy_trans_info = &yy_current_state[(unsigned int) yy_c])->" );
539 indent_puts( "yy_verify == yy_c;" );
540 indent_put2s( " yy_c = %s )", char_map_2 );
544 if ( num_backing_up > 0 )
545 indent_puts( "{" ); /* } for vi */
547 indent_puts( "yy_current_state += yy_trans_info->yy_nxt;" );
549 if ( num_backing_up > 0 )
552 gen_backing_up(); /* { for vi */
556 indent_down(); /* { for vi */
565 indent_puts( "{" ); /* } for vi */
567 gen_next_state( false );
569 indent_puts( "++yy_cp;" );
578 out_dec( "while ( yy_base[yy_current_state] != %d );\n",
581 out_dec( "while ( yy_current_state != %d );\n",
584 if ( ! reject && ! interactive )
586 /* Do the guaranteed-needed backing up to figure out
589 indent_puts( "yy_cp = yy_last_accepting_cpos;" );
591 "yy_current_state = yy_last_accepting_state;" );
597 /* Generate the code to find the next state. */
599 void gen_next_state( worry_about_NULs )
600 int worry_about_NULs;
601 { /* NOTE - changes in here should be reflected in gen_next_match() */
604 if ( worry_about_NULs && ! nultrans )
607 (void) sprintf( char_map,
608 "(*yy_cp ? yy_ec[YY_SC_TO_UI(*yy_cp)] : %d)",
611 (void) sprintf( char_map,
612 "(*yy_cp ? YY_SC_TO_UI(*yy_cp) : %d)", NUL_ec );
616 strcpy( char_map, useecs ?
617 "yy_ec[YY_SC_TO_UI(*yy_cp)]" : "YY_SC_TO_UI(*yy_cp)" );
619 if ( worry_about_NULs && nultrans )
621 if ( ! fulltbl && ! fullspd )
622 /* Compressed tables back up *before* they match. */
625 indent_puts( "if ( *yy_cp )" );
627 indent_puts( "{" ); /* } for vi */
632 "yy_current_state = yy_nxt[yy_current_state][%s];",
637 "yy_current_state += yy_current_state[%s].yy_nxt;",
641 gen_next_compressed_state( char_map );
643 if ( worry_about_NULs && nultrans )
648 indent_puts( "else" );
651 "yy_current_state = yy_NUL_trans[yy_current_state];" );
655 if ( fullspd || fulltbl )
659 indent_puts( "*yy_state_ptr++ = yy_current_state;" );
663 /* Generate the code to make a NUL transition. */
666 { /* NOTE - changes in here should be reflected in gen_next_match() */
667 /* Only generate a definition for "yy_cp" if we'll generate code
668 * that uses it. Otherwise lint and the like complain.
670 int need_backing_up = (num_backing_up > 0 && ! reject);
672 if ( need_backing_up && (! nultrans || fullspd || fulltbl) )
673 /* We're going to need yy_cp lying around for the call
674 * below to gen_backing_up().
676 indent_puts( "register char *yy_cp = yy_c_buf_p;" );
683 "yy_current_state = yy_NUL_trans[yy_current_state];" );
684 indent_puts( "yy_is_jam = (yy_current_state == 0);" );
690 out_dec( "yy_current_state = yy_nxt[yy_current_state][%d];\n",
692 indent_puts( "yy_is_jam = (yy_current_state <= 0);" );
698 out_dec( "register int yy_c = %d;\n", NUL_ec );
701 "register yyconst struct yy_trans_info *yy_trans_info;\n" );
703 "yy_trans_info = &yy_current_state[(unsigned int) yy_c];" );
704 indent_puts( "yy_current_state += yy_trans_info->yy_nxt;" );
707 "yy_is_jam = (yy_trans_info->yy_verify != yy_c);" );
714 (void) sprintf( NUL_ec_str, "%d", NUL_ec );
715 gen_next_compressed_state( NUL_ec_str );
718 out_dec( "yy_is_jam = (yy_current_state == %d);\n", jamstate );
722 /* Only stack this state if it's a transition we
723 * actually make. If we stack it on a jam, then
724 * the state stack and yy_c_buf_p get out of sync.
726 indent_puts( "if ( ! yy_is_jam )" );
728 indent_puts( "*yy_state_ptr++ = yy_current_state;" );
733 /* If we've entered an accepting state, back up; note that
734 * compressed tables have *already* done such backing up, so
735 * we needn't bother with it again.
737 if ( need_backing_up && (fullspd || fulltbl) )
740 indent_puts( "if ( ! yy_is_jam )" );
750 /* Generate the code to find the start state. */
752 void gen_start_state()
759 "yy_current_state = yy_start_state_list[yy_start + YY_AT_BOL()];" );
763 "yy_current_state = yy_start_state_list[yy_start];" );
768 indent_puts( "yy_current_state = yy_start;" );
771 indent_puts( "yy_current_state += YY_AT_BOL();" );
775 /* Set up for storing up states. */
776 indent_puts( "yy_state_ptr = yy_state_buf;" );
777 indent_puts( "*yy_state_ptr++ = yy_current_state;" );
783 /* gentabs - generate data statements for the transition tables */
787 int i, j, k, *accset, nacc, *acc_array, total_states;
788 int end_of_buffer_action = num_rules + 1;
790 acc_array = allocate_integer_array( current_max_dfas );
793 /* The compressed table format jams by entering the "jam state",
794 * losing information about the previous state in the process.
795 * In order to recover the previous state, we effectively need
796 * to keep backing-up information.
802 /* Write out accepting list and pointer list.
804 * First we generate the "yy_acclist" array. In the process,
805 * we compute the indices that will go into the "yy_accept"
806 * array, and save the indices in the dfaacc array.
808 int EOB_accepting_list[2];
810 /* Set up accepting structures for the End Of Buffer state. */
811 EOB_accepting_list[0] = 0;
812 EOB_accepting_list[1] = end_of_buffer_action;
813 accsiz[end_of_buffer_state] = 1;
814 dfaacc[end_of_buffer_state].dfaacc_set = EOB_accepting_list;
816 out_str_dec( long_align ? C_long_decl : C_short_decl,
817 "yy_acclist", MAX( numas, 1 ) + 1 );
819 j = 1; /* index into "yy_acclist" array */
821 for ( i = 1; i <= lastdfa; ++i )
825 if ( accsiz[i] != 0 )
827 accset = dfaacc[i].dfaacc_set;
832 _( "state # %d accepts: " ),
835 for ( k = 1; k <= nacc; ++k )
837 int accnum = accset[k];
841 if ( variable_trailing_context_rules &&
842 ! (accnum & YY_TRAILING_HEAD_MASK) &&
843 accnum > 0 && accnum <= num_rules &&
844 rule_type[accnum] == RULE_VARIABLE )
846 /* Special hack to flag
847 * accepting number as part
848 * of trailing context rule.
850 accnum |= YY_TRAILING_MASK;
857 fprintf( stderr, "[%d]",
861 fputs( ", ", stderr );
863 putc( '\n', stderr );
869 /* add accepting number for the "jam" state */
877 dfaacc[end_of_buffer_state].dfaacc_state = end_of_buffer_action;
879 for ( i = 1; i <= lastdfa; ++i )
880 acc_array[i] = dfaacc[i].dfaacc_state;
882 /* add accepting number for jam state */
886 /* Spit out "yy_accept" array. If we're doing "reject", it'll be
887 * pointers into the "yy_acclist" array. Otherwise it's actual
888 * accepting numbers. In either case, we just dump the numbers.
891 /* "lastdfa + 2" is the size of "yy_accept"; includes room for C arrays
892 * beginning at 0 and for "jam" state.
897 /* We put a "cap" on the table associating lists of accepting
898 * numbers with state numbers. This is needed because we tell
899 * where the end of an accepting list is by looking at where
900 * the list for the next state starts.
904 out_str_dec( long_align ? C_long_decl : C_short_decl, "yy_accept", k );
906 for ( i = 1; i <= lastdfa; ++i )
908 mkdata( acc_array[i] );
910 if ( ! reject && trace && acc_array[i] )
911 fprintf( stderr, _( "state # %d accepts: [%d]\n" ),
915 /* Add entry for "jam" state. */
916 mkdata( acc_array[i] );
919 /* Add "cap" for the list. */
920 mkdata( acc_array[i] );
929 /* Write out meta-equivalence classes (used to index
934 fputs( _( "\n\nMeta-Equivalence Classes:\n" ),
937 out_str_dec( C_int_decl, "yy_meta", numecs + 1 );
939 for ( i = 1; i <= numecs; ++i )
942 fprintf( stderr, "%d = %d\n",
943 i, ABS( tecbck[i] ) );
945 mkdata( ABS( tecbck[i] ) );
951 total_states = lastdfa + numtemps;
953 out_str_dec( (tblend >= MAX_SHORT || long_align) ?
954 C_long_decl : C_short_decl,
955 "yy_base", total_states + 1 );
957 for ( i = 1; i <= lastdfa; ++i )
959 register int d = def[i];
961 if ( base[i] == JAMSTATE )
969 /* Template reference. */
971 def[i] = lastdfa - d + 1;
977 /* Generate jam state's base index. */
980 for ( ++i /* skip jam state */; i <= total_states; ++i )
988 out_str_dec( (total_states >= MAX_SHORT || long_align) ?
989 C_long_decl : C_short_decl,
990 "yy_def", total_states + 1 );
992 for ( i = 1; i <= total_states; ++i )
997 out_str_dec( (total_states >= MAX_SHORT || long_align) ?
998 C_long_decl : C_short_decl,
999 "yy_nxt", tblend + 1 );
1001 for ( i = 1; i <= tblend; ++i )
1003 /* Note, the order of the following test is important.
1004 * If chk[i] is 0, then nxt[i] is undefined.
1006 if ( chk[i] == 0 || nxt[i] == 0 )
1007 nxt[i] = jamstate; /* new state is the JAM state */
1014 out_str_dec( (total_states >= MAX_SHORT || long_align) ?
1015 C_long_decl : C_short_decl,
1016 "yy_chk", tblend + 1 );
1018 for ( i = 1; i <= tblend; ++i )
1030 /* Write out a formatted string (with a secondary string argument) at the
1031 * current indentation level, adding a final newline.
1034 void indent_put2s( fmt, arg )
1038 out_str( fmt, arg );
1043 /* Write out a string at the current indentation level, adding a final
1047 void indent_puts( str )
1055 /* make_tables - generate transition tables and finishes generating output file
1061 int did_eof_rule = false;
1065 /* First, take care of YY_DO_BEFORE_ACTION depending on yymore
1070 if ( yymore_used && ! yytext_is_array )
1072 indent_puts( "yytext_ptr -= yy_more_len; \\" );
1073 indent_puts( "yyleng = (int) (yy_cp - yytext_ptr); \\" );
1077 indent_puts( "yyleng = (int) (yy_cp - yy_bp); \\" );
1079 /* Now also deal with copying yytext_ptr to yytext if needed. */
1081 if ( yytext_is_array )
1085 "if ( yyleng + yy_more_offset >= YYLMAX ) \\" );
1087 indent_puts( "if ( yyleng >= YYLMAX ) \\" );
1091 "YY_FATAL_ERROR( \"token too large, exceeds YYLMAX\" ); \\" );
1097 "yy_flex_strncpy( &yytext[yy_more_offset], yytext_ptr, yyleng + 1 ); \\" );
1098 indent_puts( "yyleng += yy_more_offset; \\" );
1100 "yy_prev_more_offset = yy_more_offset; \\" );
1101 indent_puts( "yy_more_offset = 0; \\" );
1106 "yy_flex_strncpy( yytext, yytext_ptr, yyleng + 1 ); \\" );
1115 out_dec( "#define YY_NUM_RULES %d\n", num_rules );
1116 out_dec( "#define YY_END_OF_BUFFER %d\n", num_rules + 1 );
1120 /* Need to define the transet type as a size large
1121 * enough to hold the biggest offset.
1123 int total_table_size = tblend + numecs + 1;
1124 char *trans_offset_type =
1125 (total_table_size >= MAX_SHORT || long_align) ?
1129 indent_puts( "struct yy_trans_info" );
1131 indent_puts( "{" ); /* } for vi */
1134 indent_puts( "long yy_verify;" );
1136 indent_puts( "short yy_verify;" );
1138 /* In cases where its sister yy_verify *is* a "yes, there is
1139 * a transition", yy_nxt is the offset (in records) to the
1140 * next state. In most cases where there is no transition,
1141 * the value of yy_nxt is irrelevant. If yy_nxt is the -1th
1142 * record of a state, though, then yy_nxt is the action number
1146 indent_put2s( "%s yy_nxt;", trans_offset_type );
1147 indent_puts( "};" );
1158 /* Definitions for backing up. We don't need them if REJECT
1159 * is being used because then we use an alternative backin-up
1160 * technique instead.
1162 if ( num_backing_up > 0 && ! reject )
1164 if ( ! C_plus_plus )
1167 "static yy_state_type yy_last_accepting_state;" );
1169 "static char *yy_last_accepting_cpos;\n" );
1175 out_str_dec( C_state_decl, "yy_NUL_trans", lastdfa + 1 );
1177 for ( i = 1; i <= lastdfa; ++i )
1180 out_dec( " &yy_transition[%d],\n", base[i] );
1182 mkdata( nultrans[i] );
1189 { /* Spit out table mapping rules to line numbers. */
1190 if ( ! C_plus_plus )
1192 indent_puts( "extern int yy_flex_debug;" );
1193 indent_puts( "int yy_flex_debug = 1;\n" );
1196 out_str_dec( long_align ? C_long_decl : C_short_decl,
1197 "yy_rule_linenum", num_rules );
1198 for ( i = 1; i < num_rules; ++i )
1199 mkdata( rule_linenum[i] );
1205 /* Declare state buffer variables. */
1206 if ( ! C_plus_plus )
1209 "static yy_state_type yy_state_buf[YY_BUF_SIZE + 2], *yy_state_ptr;" );
1210 outn( "static char *yy_full_match;" );
1211 outn( "static int yy_lp;" );
1214 if ( variable_trailing_context_rules )
1216 if ( ! C_plus_plus )
1219 "static int yy_looking_for_trail_begin = 0;" );
1220 outn( "static int yy_full_lp;" );
1221 outn( "static int *yy_full_state;" );
1224 out_hex( "#define YY_TRAILING_MASK 0x%x\n",
1225 (unsigned int) YY_TRAILING_MASK );
1226 out_hex( "#define YY_TRAILING_HEAD_MASK 0x%x\n",
1227 (unsigned int) YY_TRAILING_HEAD_MASK );
1230 outn( "#define REJECT \\" );
1231 outn( "{ \\" ); /* } for vi */
1233 "*yy_cp = yy_hold_char; /* undo effects of setting up yytext */ \\" );
1235 "yy_cp = yy_full_match; /* restore poss. backed-over text */ \\" );
1237 if ( variable_trailing_context_rules )
1240 "yy_lp = yy_full_lp; /* restore orig. accepting pos. */ \\" );
1242 "yy_state_ptr = yy_full_state; /* restore orig. state */ \\" );
1244 "yy_current_state = *yy_state_ptr; /* restore curr. state */ \\" );
1247 outn( "++yy_lp; \\" );
1248 outn( "goto find_rule; \\" );
1256 "/* The intent behind this definition is that it'll catch" );
1257 outn( " * any uses of REJECT which flex missed." );
1259 outn( "#define REJECT reject_used_but_not_detected" );
1264 if ( ! C_plus_plus )
1266 if ( yytext_is_array )
1268 indent_puts( "static int yy_more_offset = 0;" );
1270 "static int yy_prev_more_offset = 0;" );
1274 indent_puts( "static int yy_more_flag = 0;" );
1275 indent_puts( "static int yy_more_len = 0;" );
1279 if ( yytext_is_array )
1282 "#define yymore() (yy_more_offset = yy_flex_strlen( yytext ))" );
1283 indent_puts( "#define YY_NEED_STRLEN" );
1284 indent_puts( "#define YY_MORE_ADJ 0" );
1285 indent_puts( "#define YY_RESTORE_YY_MORE_OFFSET \\" );
1287 indent_puts( "{ \\" );
1288 indent_puts( "yy_more_offset = yy_prev_more_offset; \\" );
1289 indent_puts( "yyleng -= yy_more_offset; \\" );
1295 indent_puts( "#define yymore() (yy_more_flag = 1)" );
1296 indent_puts( "#define YY_MORE_ADJ yy_more_len" );
1297 indent_puts( "#define YY_RESTORE_YY_MORE_OFFSET" );
1303 indent_puts( "#define yymore() yymore_used_but_not_detected" );
1304 indent_puts( "#define YY_MORE_ADJ 0" );
1305 indent_puts( "#define YY_RESTORE_YY_MORE_OFFSET" );
1308 if ( ! C_plus_plus )
1310 if ( yytext_is_array )
1312 outn( "#ifndef YYLMAX" );
1313 outn( "#define YYLMAX 8192" );
1315 outn( "char yytext[YYLMAX];" );
1316 outn( "char *yytext_ptr;" );
1320 outn( "char *yytext;" );
1323 out( &action_array[defs1_offset] );
1325 line_directive_out( stdout, 0 );
1329 if ( ! C_plus_plus )
1334 "\tif ( (result = read( fileno(yyin), (char *) buf, max_size )) < 0 ) \\" );
1336 "\t\tYY_FATAL_ERROR( \"input in flex scanner failed\" );" );
1342 "\tif ( yy_current_buffer->yy_is_interactive ) \\" );
1344 outn( "\t\tint c = '*', n; \\" );
1345 outn( "\t\tfor ( n = 0; n < max_size && \\" );
1346 outn( "\t\t\t (c = getc( yyin )) != EOF && c != '\\n'; ++n ) \\" );
1347 outn( "\t\t\tbuf[n] = (char) c; \\" );
1348 outn( "\t\tif ( c == '\\n' ) \\" );
1349 outn( "\t\t\tbuf[n++] = (char) c; \\" );
1350 outn( "\t\tif ( c == EOF && ferror( yyin ) ) \\" );
1352 "\t\t\tYY_FATAL_ERROR( \"input in flex scanner failed\" ); \\" );
1353 outn( "\t\tresult = n; \\" );
1356 "\telse if ( ((result = fread( buf, 1, max_size, yyin )) == 0) \\" );
1357 outn( "\t\t && ferror( yyin ) ) \\" );
1359 "\t\tYY_FATAL_ERROR( \"input in flex scanner failed\" );" );
1365 indent_puts( "#define YY_RULE_SETUP \\" );
1369 indent_puts( "if ( yyleng > 0 ) \\" );
1371 indent_puts( "yy_current_buffer->yy_at_bol = \\" );
1372 indent_puts( "\t\t(yytext[yyleng - 1] == '\\n'); \\" );
1375 indent_puts( "YY_USER_ACTION" );
1380 /* Copy prolog to output file. */
1381 out( &action_array[prolog_offset] );
1383 line_directive_out( stdout, 0 );
1389 if ( yymore_used && ! yytext_is_array )
1391 indent_puts( "yy_more_len = 0;" );
1392 indent_puts( "if ( yy_more_flag )" );
1395 indent_puts( "yy_more_len = yy_c_buf_p - yytext_ptr;" );
1396 indent_puts( "yy_more_flag = 0;" );
1405 /* Note, don't use any indentation. */
1406 outn( "yy_match:" );
1416 indent_puts( "if ( yy_act != YY_END_OF_BUFFER )" );
1419 indent_puts( "int yyl;" );
1420 indent_puts( "for ( yyl = 0; yyl < yyleng; ++yyl )" );
1422 indent_puts( "if ( yytext[yyl] == '\\n' )" );
1424 indent_puts( "++yylineno;" );
1434 indent_puts( "if ( yy_flex_debug )" );
1438 indent_puts( "if ( yy_act == 0 )" );
1440 indent_puts( C_plus_plus ?
1441 "cerr << \"--scanner backing up\\n\";" :
1442 "fprintf( stderr, \"--scanner backing up\\n\" );" );
1446 out_dec( "else if ( yy_act < %d )\n", num_rules );
1452 "cerr << \"--accepting rule at line \" << yy_rule_linenum[yy_act] <<" );
1454 " \"(\\\"\" << yytext << \"\\\")\\n\";" );
1459 "fprintf( stderr, \"--accepting rule at line %d (\\\"%s\\\")\\n\"," );
1462 " yy_rule_linenum[yy_act], yytext );" );
1468 out_dec( "else if ( yy_act == %d )\n", num_rules );
1474 "cerr << \"--accepting default rule (\\\"\" << yytext << \"\\\")\\n\";" );
1479 "fprintf( stderr, \"--accepting default rule (\\\"%s\\\")\\n\"," );
1480 indent_puts( " yytext );" );
1486 out_dec( "else if ( yy_act == %d )\n", num_rules + 1 );
1489 indent_puts( C_plus_plus ?
1490 "cerr << \"--(end of buffer or a NUL)\\n\";" :
1491 "fprintf( stderr, \"--(end of buffer or a NUL)\\n\" );" );
1502 "cerr << \"--EOF (start condition \" << YY_START << \")\\n\";" );
1507 "fprintf( stderr, \"--EOF (start condition %d)\\n\", YY_START );" );
1516 /* Copy actions to output file. */
1520 out( &action_array[action_offset] );
1522 line_directive_out( stdout, 0 );
1524 /* generate cases for any missing EOF rules */
1525 for ( i = 1; i <= lastsc; ++i )
1529 out_str( "case YY_STATE_EOF(%s):\n", scname[i] );
1530 did_eof_rule = true;
1536 indent_puts( "yyterminate();" );
1541 /* Generate code for handling NUL's, if needed. */
1543 /* First, deal with backing up and setting up yy_cp if the scanner
1544 * finds that it should JAM on the NUL.
1549 if ( fullspd || fulltbl )
1550 indent_puts( "yy_cp = yy_c_buf_p;" );
1553 { /* compressed table */
1554 if ( ! reject && ! interactive )
1556 /* Do the guaranteed-needed backing up to figure
1559 indent_puts( "yy_cp = yy_last_accepting_cpos;" );
1561 "yy_current_state = yy_last_accepting_state;" );
1565 /* Still need to initialize yy_cp, though
1566 * yy_current_state was set up by
1567 * yy_get_previous_state().
1569 indent_puts( "yy_cp = yy_c_buf_p;" );
1573 /* Generate code for yy_get_previous_state(). */
1581 gen_next_state( true );
1589 { /* update yylineno inside of unput() */
1590 indent_puts( "if ( c == '\\n' )" );
1592 indent_puts( "--yylineno;" );
1597 /* Update BOL and yylineno inside of input(). */
1600 indent_puts( "yy_current_buffer->yy_at_bol = (c == '\\n');" );
1603 indent_puts( "if ( yy_current_buffer->yy_at_bol )" );
1605 indent_puts( "++yylineno;" );
1610 else if ( do_yylineno )
1612 indent_puts( "if ( c == '\\n' )" );
1614 indent_puts( "++yylineno;" );
1620 /* Copy remainder of input to output. */
1622 line_directive_out( stdout, 1 );
1625 (void) flexscan(); /* copy remainder of input to output */