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 with or without
15 * modification are permitted provided that: (1) source distributions retain
16 * this entire copyright notice and comment, and (2) distributions including
17 * binaries display the following acknowledgement: ``This product includes
18 * software developed by the University of California, Berkeley and its
19 * contributors'' in the documentation or other materials provided with the
20 * distribution and in all advertising materials mentioning features or use
21 * of this software. Neither the name of the University nor the names of
22 * its contributors may be used to endorse or promote products derived from
23 * this software without 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.
34 /* declare functions that have forward references */
36 void gen_next_state
PROTO((int));
37 void genecs
PROTO((void));
38 void indent_put2s
PROTO((char [], char []));
39 void indent_puts
PROTO((char []));
42 static int indent_level
= 0; /* each level is 8 spaces */
44 #define indent_up() (++indent_level)
45 #define indent_down() (--indent_level)
46 #define set_indent(indent_val) indent_level = indent_val
48 /* Almost everything is done in terms of arrays starting at 1, so provide
49 * a null entry for the zero element of all C arrays. (The exception
50 * to this is that the fast table representation generally uses the
51 * 0 elements of its arrays, too.)
53 static char C_int_decl
[] = "static yyconst int %s[%d] =\n { 0,\n";
54 static char C_short_decl
[] = "static yyconst short int %s[%d] =\n { 0,\n";
55 static char C_long_decl
[] = "static yyconst long int %s[%d] =\n { 0,\n";
56 static char C_state_decl
[] =
57 "static yyconst yy_state_type %s[%d] =\n { 0,\n";
60 /* Indent to the current level. */
64 register int i
= indent_level
* 8;
80 /* Generate the code to keep backing-up information. */
84 if ( reject
|| num_backing_up
== 0 )
88 indent_puts( "if ( yy_current_state[-1].yy_nxt )" );
90 indent_puts( "if ( yy_accept[yy_current_state] )" );
94 indent_puts( "yy_last_accepting_state = yy_current_state;" );
95 indent_puts( "yy_last_accepting_cpos = yy_cp;" );
101 /* Generate the code to perform the backing up. */
105 if ( reject
|| num_backing_up
== 0 )
110 indent_puts( "case 0: /* must back up */" );
111 indent_puts( "/* undo the effects of YY_DO_BEFORE_ACTION */" );
112 indent_puts( "*yy_cp = yy_hold_char;" );
114 if ( fullspd
|| fulltbl
)
115 indent_puts( "yy_cp = yy_last_accepting_cpos + 1;" );
117 /* Backing-up info for compressed tables is taken \after/
118 * yy_cp has been incremented for the next state.
120 indent_puts( "yy_cp = yy_last_accepting_cpos;" );
122 indent_puts( "yy_current_state = yy_last_accepting_state;" );
123 indent_puts( "goto yy_find_action;" );
130 /* genctbl - generates full speed compressed transition table */
135 int end_of_buffer_action
= num_rules
+ 1;
137 /* Table of verify for transition and offset to next state. */
138 out_dec( "static yyconst struct yy_trans_info yy_transition[%d] =\n",
139 tblend
+ numecs
+ 1 );
142 /* We want the transition to be represented as the offset to the
143 * next state, not the actual state number, which is what it currently
144 * is. The offset is base[nxt[i]] - (base of current state)]. That's
145 * just the difference between the starting points of the two involved
146 * states (to - from).
148 * First, though, we need to find some way to put in our end-of-buffer
149 * flags and states. We do this by making a state with absolutely no
150 * transitions. We put it at the end of the table.
153 /* We need to have room in nxt/chk for two more slots: One for the
154 * action and one for the end-of-buffer transition. We now *assume*
155 * that we're guaranteed the only character we'll try to index this
156 * nxt/chk pair with is EOB, i.e., 0, so we don't have to make sure
157 * there's room for jam entries for other characters.
160 while ( tblend
+ 2 >= current_max_xpairs
)
163 while ( lastdfa
+ 1 >= current_max_dfas
)
166 base
[lastdfa
+ 1] = tblend
+ 2;
167 nxt
[tblend
+ 1] = end_of_buffer_action
;
168 chk
[tblend
+ 1] = numecs
+ 1;
169 chk
[tblend
+ 2] = 1; /* anything but EOB */
171 /* So that "make test" won't show arb. differences. */
174 /* Make sure every state has an end-of-buffer transition and an
177 for ( i
= 0; i
<= lastdfa
; ++i
)
179 int anum
= dfaacc
[i
].dfaacc_state
;
180 int offset
= base
[i
];
182 chk
[offset
] = EOB_POSITION
;
183 chk
[offset
- 1] = ACTION_POSITION
;
184 nxt
[offset
- 1] = anum
; /* action number */
187 for ( i
= 0; i
<= tblend
; ++i
)
189 if ( chk
[i
] == EOB_POSITION
)
190 transition_struct_out( 0, base
[lastdfa
+ 1] - i
);
192 else if ( chk
[i
] == ACTION_POSITION
)
193 transition_struct_out( 0, nxt
[i
] );
195 else if ( chk
[i
] > numecs
|| chk
[i
] == 0 )
196 transition_struct_out( 0, 0 ); /* unused slot */
198 else /* verify, transition */
199 transition_struct_out( chk
[i
],
200 base
[nxt
[i
]] - (i
- chk
[i
]) );
204 /* Here's the final, end-of-buffer state. */
205 transition_struct_out( chk
[tblend
+ 1], nxt
[tblend
+ 1] );
206 transition_struct_out( chk
[tblend
+ 2], nxt
[tblend
+ 2] );
210 /* Table of pointers to start states. */
212 "static yyconst struct yy_trans_info *yy_start_state_list[%d] =\n",
214 outn( " {" ); /* } so vi doesn't get confused */
216 for ( i
= 0; i
<= lastsc
* 2; ++i
)
217 out_dec( " &yy_transition[%d],\n", base
[i
] );
226 /* Generate equivalence-class tables. */
233 out_str_dec( C_int_decl
, "yy_ec", csize
);
235 for ( i
= 1; i
< csize
; ++i
)
237 if ( caseins
&& (i
>= 'A') && (i
<= 'Z') )
238 ecgroup
[i
] = ecgroup
[clower( i
)];
240 ecgroup
[i
] = ABS( ecgroup
[i
] );
241 mkdata( ecgroup
[i
] );
248 fputs( _( "\n\nEquivalence Classes:\n\n" ), stderr
);
252 for ( j
= 0; j
< numrows
; ++j
)
254 for ( i
= j
; i
< csize
; i
= i
+ numrows
)
256 fprintf( stderr
, "%4s = %-2d",
257 readable_form( i
), ecgroup
[i
] );
262 putc( '\n', stderr
);
268 /* Generate the code to find the action number. */
270 void gen_find_action()
273 indent_puts( "yy_act = yy_current_state[-1].yy_nxt;" );
276 indent_puts( "yy_act = yy_accept[yy_current_state];" );
280 indent_puts( "yy_current_state = *--yy_state_ptr;" );
281 indent_puts( "yy_lp = yy_accept[yy_current_state];" );
284 "find_rule: /* we branch to this label when backing up */" );
287 "for ( ; ; ) /* until we find what rule we matched */" );
294 "if ( yy_lp && yy_lp < yy_accept[yy_current_state + 1] )" );
297 indent_puts( "yy_act = yy_acclist[yy_lp];" );
299 if ( variable_trailing_context_rules
)
301 indent_puts( "if ( yy_act & YY_TRAILING_HEAD_MASK ||" );
302 indent_puts( " yy_looking_for_trail_begin )" );
307 "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
332 indent_puts( "yy_full_match = yy_cp;" );
333 indent_puts( "yy_full_state = yy_state_ptr;" );
334 indent_puts( "yy_full_lp = yy_lp;" );
340 indent_puts( "else" );
343 indent_puts( "yy_full_match = yy_cp;" );
344 indent_puts( "yy_full_state = yy_state_ptr;" );
345 indent_puts( "yy_full_lp = yy_lp;" );
346 indent_puts( "break;" );
350 indent_puts( "++yy_lp;" );
351 indent_puts( "goto find_rule;" );
356 /* Remember matched text in case we back up due to
357 * trailing context plus REJECT.
361 indent_puts( "yy_full_match = yy_cp;" );
362 indent_puts( "break;" );
370 indent_puts( "--yy_cp;" );
372 /* We could consolidate the following two lines with those at
373 * the beginning, but at the cost of complaints that we're
374 * branching inside a loop.
376 indent_puts( "yy_current_state = *--yy_state_ptr;" );
377 indent_puts( "yy_lp = yy_accept[yy_current_state];" );
386 indent_puts( "yy_act = yy_accept[yy_current_state];" );
388 if ( interactive
&& ! reject
)
390 /* Do the guaranteed-needed backing up to figure out
393 indent_puts( "if ( yy_act == 0 )" );
395 indent_puts( "{ /* have to back up */" );
396 indent_puts( "yy_cp = yy_last_accepting_cpos;" );
398 "yy_current_state = yy_last_accepting_state;" );
399 indent_puts( "yy_act = yy_accept[yy_current_state];" );
407 /* genftbl - generate full transition table */
412 int end_of_buffer_action
= num_rules
+ 1;
414 out_str_dec( long_align
? C_long_decl
: C_short_decl
,
415 "yy_accept", lastdfa
+ 1 );
417 dfaacc
[end_of_buffer_state
].dfaacc_state
= end_of_buffer_action
;
419 for ( i
= 1; i
<= lastdfa
; ++i
)
421 register int anum
= dfaacc
[i
].dfaacc_state
;
426 fprintf( stderr
, _( "state # %d accepts: [%d]\n" ),
435 /* Don't have to dump the actual full table entries - they were
436 * created on-the-fly.
441 /* Generate the code to find the next compressed-table state. */
443 void gen_next_compressed_state( char_map
)
446 indent_put2s( "register YY_CHAR yy_c = %s;", char_map
);
448 /* Save the backing-up info \before/ computing the next state
449 * because we always compute one more state than needed - we
450 * always proceed until we reach a jam state
455 "while ( yy_chk[yy_base[yy_current_state] + yy_c] != yy_current_state )" );
458 indent_puts( "yy_current_state = (int) yy_def[yy_current_state];" );
462 /* We've arrange it so that templates are never chained
463 * to one another. This means we can afford to make a
464 * very simple test to see if we need to convert to
465 * yy_c's meta-equivalence class without worrying
466 * about erroneously looking up the meta-equivalence
471 /* lastdfa + 2 is the beginning of the templates */
472 out_dec( "if ( yy_current_state >= %d )\n", lastdfa
+ 2 );
475 indent_puts( "yy_c = yy_meta[(unsigned int) yy_c];" );
483 "yy_current_state = yy_nxt[yy_base[yy_current_state] + (unsigned int) yy_c];" );
487 /* Generate the code to find the next match. */
489 void gen_next_match()
491 /* NOTE - changes in here should be reflected in gen_next_state() and
494 char *char_map
= useecs
?
495 "yy_ec[YY_SC_TO_UI(*yy_cp)]" :
496 "YY_SC_TO_UI(*yy_cp)";
498 char *char_map_2
= useecs
?
499 "yy_ec[YY_SC_TO_UI(*++yy_cp)]" :
500 "YY_SC_TO_UI(*++yy_cp)";
505 "while ( (yy_current_state = yy_nxt[yy_current_state][%s]) > 0 )",
510 if ( num_backing_up
> 0 )
512 indent_puts( "{" ); /* } for vi */
517 indent_puts( "++yy_cp;" );
519 if ( num_backing_up
> 0 )
526 indent_puts( "yy_current_state = -yy_current_state;" );
531 indent_puts( "{" ); /* } for vi */
533 "register yyconst struct yy_trans_info *yy_trans_info;\n" );
534 indent_puts( "register YY_CHAR yy_c;\n" );
535 indent_put2s( "for ( yy_c = %s;", char_map
);
537 " (yy_trans_info = &yy_current_state[(unsigned int) yy_c])->" );
538 indent_puts( "yy_verify == yy_c;" );
539 indent_put2s( " yy_c = %s )", char_map_2
);
543 if ( num_backing_up
> 0 )
544 indent_puts( "{" ); /* } for vi */
546 indent_puts( "yy_current_state += yy_trans_info->yy_nxt;" );
548 if ( num_backing_up
> 0 )
551 gen_backing_up(); /* { for vi */
555 indent_down(); /* { for vi */
564 indent_puts( "{" ); /* } for vi */
566 gen_next_state( false );
568 indent_puts( "++yy_cp;" );
577 out_dec( "while ( yy_base[yy_current_state] != %d );\n",
580 out_dec( "while ( yy_current_state != %d );\n",
583 if ( ! reject
&& ! interactive
)
585 /* Do the guaranteed-needed backing up to figure out
588 indent_puts( "yy_cp = yy_last_accepting_cpos;" );
590 "yy_current_state = yy_last_accepting_state;" );
596 /* Generate the code to find the next state. */
598 void gen_next_state( worry_about_NULs
)
599 int worry_about_NULs
;
600 { /* NOTE - changes in here should be reflected in gen_next_match() */
603 if ( worry_about_NULs
&& ! nultrans
)
606 (void) sprintf( char_map
,
607 "(*yy_cp ? yy_ec[YY_SC_TO_UI(*yy_cp)] : %d)",
610 (void) sprintf( char_map
,
611 "(*yy_cp ? YY_SC_TO_UI(*yy_cp) : %d)", NUL_ec
);
615 strcpy( char_map
, useecs
?
616 "yy_ec[YY_SC_TO_UI(*yy_cp)]" : "YY_SC_TO_UI(*yy_cp)" );
618 if ( worry_about_NULs
&& nultrans
)
620 if ( ! fulltbl
&& ! fullspd
)
621 /* Compressed tables back up *before* they match. */
624 indent_puts( "if ( *yy_cp )" );
626 indent_puts( "{" ); /* } for vi */
631 "yy_current_state = yy_nxt[yy_current_state][%s];",
636 "yy_current_state += yy_current_state[%s].yy_nxt;",
640 gen_next_compressed_state( char_map
);
642 if ( worry_about_NULs
&& nultrans
)
647 indent_puts( "else" );
650 "yy_current_state = yy_NUL_trans[yy_current_state];" );
654 if ( fullspd
|| fulltbl
)
658 indent_puts( "*yy_state_ptr++ = yy_current_state;" );
662 /* Generate the code to make a NUL transition. */
665 { /* NOTE - changes in here should be reflected in gen_next_match() */
666 /* Only generate a definition for "yy_cp" if we'll generate code
667 * that uses it. Otherwise lint and the like complain.
669 int need_backing_up
= (num_backing_up
> 0 && ! reject
);
671 if ( need_backing_up
&& (! nultrans
|| fullspd
|| fulltbl
) )
672 /* We're going to need yy_cp lying around for the call
673 * below to gen_backing_up().
675 indent_puts( "register char *yy_cp = yy_c_buf_p;" );
682 "yy_current_state = yy_NUL_trans[yy_current_state];" );
683 indent_puts( "yy_is_jam = (yy_current_state == 0);" );
689 out_dec( "yy_current_state = yy_nxt[yy_current_state][%d];\n",
691 indent_puts( "yy_is_jam = (yy_current_state <= 0);" );
697 out_dec( "register int yy_c = %d;\n", NUL_ec
);
700 "register yyconst struct yy_trans_info *yy_trans_info;\n" );
702 "yy_trans_info = &yy_current_state[(unsigned int) yy_c];" );
703 indent_puts( "yy_current_state += yy_trans_info->yy_nxt;" );
706 "yy_is_jam = (yy_trans_info->yy_verify != yy_c);" );
713 (void) sprintf( NUL_ec_str
, "%d", NUL_ec
);
714 gen_next_compressed_state( NUL_ec_str
);
717 out_dec( "yy_is_jam = (yy_current_state == %d);\n", jamstate
);
721 /* Only stack this state if it's a transition we
722 * actually make. If we stack it on a jam, then
723 * the state stack and yy_c_buf_p get out of sync.
725 indent_puts( "if ( ! yy_is_jam )" );
727 indent_puts( "*yy_state_ptr++ = yy_current_state;" );
732 /* If we've entered an accepting state, back up; note that
733 * compressed tables have *already* done such backing up, so
734 * we needn't bother with it again.
736 if ( need_backing_up
&& (fullspd
|| fulltbl
) )
739 indent_puts( "if ( ! yy_is_jam )" );
749 /* Generate the code to find the start state. */
751 void gen_start_state()
758 "yy_current_state = yy_start_state_list[yy_start + YY_AT_BOL()];" );
762 "yy_current_state = yy_start_state_list[yy_start];" );
767 indent_puts( "yy_current_state = yy_start;" );
770 indent_puts( "yy_current_state += YY_AT_BOL();" );
774 /* Set up for storing up states. */
775 indent_puts( "yy_state_ptr = yy_state_buf;" );
776 indent_puts( "*yy_state_ptr++ = yy_current_state;" );
782 /* gentabs - generate data statements for the transition tables */
786 int i
, j
, k
, *accset
, nacc
, *acc_array
, total_states
;
787 int end_of_buffer_action
= num_rules
+ 1;
789 acc_array
= allocate_integer_array( current_max_dfas
);
792 /* The compressed table format jams by entering the "jam state",
793 * losing information about the previous state in the process.
794 * In order to recover the previous state, we effectively need
795 * to keep backing-up information.
801 /* Write out accepting list and pointer list.
803 * First we generate the "yy_acclist" array. In the process,
804 * we compute the indices that will go into the "yy_accept"
805 * array, and save the indices in the dfaacc array.
807 int EOB_accepting_list
[2];
809 /* Set up accepting structures for the End Of Buffer state. */
810 EOB_accepting_list
[0] = 0;
811 EOB_accepting_list
[1] = end_of_buffer_action
;
812 accsiz
[end_of_buffer_state
] = 1;
813 dfaacc
[end_of_buffer_state
].dfaacc_set
= EOB_accepting_list
;
815 out_str_dec( long_align
? C_long_decl
: C_short_decl
,
816 "yy_acclist", MAX( numas
, 1 ) + 1 );
818 j
= 1; /* index into "yy_acclist" array */
820 for ( i
= 1; i
<= lastdfa
; ++i
)
824 if ( accsiz
[i
] != 0 )
826 accset
= dfaacc
[i
].dfaacc_set
;
831 _( "state # %d accepts: " ),
834 for ( k
= 1; k
<= nacc
; ++k
)
836 int accnum
= accset
[k
];
840 if ( variable_trailing_context_rules
&&
841 ! (accnum
& YY_TRAILING_HEAD_MASK
) &&
842 accnum
> 0 && accnum
<= num_rules
&&
843 rule_type
[accnum
] == RULE_VARIABLE
)
845 /* Special hack to flag
846 * accepting number as part
847 * of trailing context rule.
849 accnum
|= YY_TRAILING_MASK
;
856 fprintf( stderr
, "[%d]",
860 fputs( ", ", stderr
);
862 putc( '\n', stderr
);
868 /* add accepting number for the "jam" state */
876 dfaacc
[end_of_buffer_state
].dfaacc_state
= end_of_buffer_action
;
878 for ( i
= 1; i
<= lastdfa
; ++i
)
879 acc_array
[i
] = dfaacc
[i
].dfaacc_state
;
881 /* add accepting number for jam state */
885 /* Spit out "yy_accept" array. If we're doing "reject", it'll be
886 * pointers into the "yy_acclist" array. Otherwise it's actual
887 * accepting numbers. In either case, we just dump the numbers.
890 /* "lastdfa + 2" is the size of "yy_accept"; includes room for C arrays
891 * beginning at 0 and for "jam" state.
896 /* We put a "cap" on the table associating lists of accepting
897 * numbers with state numbers. This is needed because we tell
898 * where the end of an accepting list is by looking at where
899 * the list for the next state starts.
903 out_str_dec( long_align
? C_long_decl
: C_short_decl
, "yy_accept", k
);
905 for ( i
= 1; i
<= lastdfa
; ++i
)
907 mkdata( acc_array
[i
] );
909 if ( ! reject
&& trace
&& acc_array
[i
] )
910 fprintf( stderr
, _( "state # %d accepts: [%d]\n" ),
914 /* Add entry for "jam" state. */
915 mkdata( acc_array
[i
] );
918 /* Add "cap" for the list. */
919 mkdata( acc_array
[i
] );
928 /* Write out meta-equivalence classes (used to index
933 fputs( _( "\n\nMeta-Equivalence Classes:\n" ),
936 out_str_dec( C_int_decl
, "yy_meta", numecs
+ 1 );
938 for ( i
= 1; i
<= numecs
; ++i
)
941 fprintf( stderr
, "%d = %d\n",
942 i
, ABS( tecbck
[i
] ) );
944 mkdata( ABS( tecbck
[i
] ) );
950 total_states
= lastdfa
+ numtemps
;
952 out_str_dec( (tblend
>= MAX_SHORT
|| long_align
) ?
953 C_long_decl
: C_short_decl
,
954 "yy_base", total_states
+ 1 );
956 for ( i
= 1; i
<= lastdfa
; ++i
)
958 register int d
= def
[i
];
960 if ( base
[i
] == JAMSTATE
)
968 /* Template reference. */
970 def
[i
] = lastdfa
- d
+ 1;
976 /* Generate jam state's base index. */
979 for ( ++i
/* skip jam state */; i
<= total_states
; ++i
)
987 out_str_dec( (total_states
>= MAX_SHORT
|| long_align
) ?
988 C_long_decl
: C_short_decl
,
989 "yy_def", total_states
+ 1 );
991 for ( i
= 1; i
<= total_states
; ++i
)
996 out_str_dec( (total_states
>= MAX_SHORT
|| long_align
) ?
997 C_long_decl
: C_short_decl
,
998 "yy_nxt", tblend
+ 1 );
1000 for ( i
= 1; i
<= tblend
; ++i
)
1002 /* Note, the order of the following test is important.
1003 * If chk[i] is 0, then nxt[i] is undefined.
1005 if ( chk
[i
] == 0 || nxt
[i
] == 0 )
1006 nxt
[i
] = jamstate
; /* new state is the JAM state */
1013 out_str_dec( (total_states
>= MAX_SHORT
|| long_align
) ?
1014 C_long_decl
: C_short_decl
,
1015 "yy_chk", tblend
+ 1 );
1017 for ( i
= 1; i
<= tblend
; ++i
)
1029 /* Write out a formatted string (with a secondary string argument) at the
1030 * current indentation level, adding a final newline.
1033 void indent_put2s( fmt
, arg
)
1037 out_str( fmt
, arg
);
1042 /* Write out a string at the current indentation level, adding a final
1046 void indent_puts( str
)
1054 /* make_tables - generate transition tables and finishes generating output file
1060 int did_eof_rule
= false;
1064 /* First, take care of YY_DO_BEFORE_ACTION depending on yymore
1069 if ( yymore_used
&& ! yytext_is_array
)
1071 indent_puts( "yytext_ptr -= yy_more_len; \\" );
1072 indent_puts( "yyleng = (int) (yy_cp - yytext_ptr); \\" );
1076 indent_puts( "yyleng = (int) (yy_cp - yy_bp); \\" );
1078 /* Now also deal with copying yytext_ptr to yytext if needed. */
1080 if ( yytext_is_array
)
1084 "if ( yyleng + yy_more_offset >= YYLMAX ) \\" );
1086 indent_puts( "if ( yyleng >= YYLMAX ) \\" );
1090 "YY_FATAL_ERROR( \"token too large, exceeds YYLMAX\" ); \\" );
1096 "yy_flex_strncpy( &yytext[yy_more_offset], yytext_ptr, yyleng + 1 ); \\" );
1097 indent_puts( "yyleng += yy_more_offset; \\" );
1099 "yy_prev_more_offset = yy_more_offset; \\" );
1100 indent_puts( "yy_more_offset = 0; \\" );
1105 "yy_flex_strncpy( yytext, yytext_ptr, yyleng + 1 ); \\" );
1114 out_dec( "#define YY_NUM_RULES %d\n", num_rules
);
1115 out_dec( "#define YY_END_OF_BUFFER %d\n", num_rules
+ 1 );
1119 /* Need to define the transet type as a size large
1120 * enough to hold the biggest offset.
1122 int total_table_size
= tblend
+ numecs
+ 1;
1123 char *trans_offset_type
=
1124 (total_table_size
>= MAX_SHORT
|| long_align
) ?
1128 indent_puts( "struct yy_trans_info" );
1130 indent_puts( "{" ); /* } for vi */
1133 indent_puts( "long yy_verify;" );
1135 indent_puts( "short yy_verify;" );
1137 /* In cases where its sister yy_verify *is* a "yes, there is
1138 * a transition", yy_nxt is the offset (in records) to the
1139 * next state. In most cases where there is no transition,
1140 * the value of yy_nxt is irrelevant. If yy_nxt is the -1th
1141 * record of a state, though, then yy_nxt is the action number
1145 indent_put2s( "%s yy_nxt;", trans_offset_type
);
1146 indent_puts( "};" );
1157 /* Definitions for backing up. We don't need them if REJECT
1158 * is being used because then we use an alternative backin-up
1159 * technique instead.
1161 if ( num_backing_up
> 0 && ! reject
)
1163 if ( ! C_plus_plus
)
1166 "static yy_state_type yy_last_accepting_state;" );
1168 "static char *yy_last_accepting_cpos;\n" );
1174 out_str_dec( C_state_decl
, "yy_NUL_trans", lastdfa
+ 1 );
1176 for ( i
= 1; i
<= lastdfa
; ++i
)
1179 out_dec( " &yy_transition[%d],\n", base
[i
] );
1181 mkdata( nultrans
[i
] );
1188 { /* Spit out table mapping rules to line numbers. */
1189 if ( ! C_plus_plus
)
1191 indent_puts( "extern int yy_flex_debug;" );
1192 indent_puts( "int yy_flex_debug = 1;\n" );
1195 out_str_dec( long_align
? C_long_decl
: C_short_decl
,
1196 "yy_rule_linenum", num_rules
);
1197 for ( i
= 1; i
< num_rules
; ++i
)
1198 mkdata( rule_linenum
[i
] );
1204 /* Declare state buffer variables. */
1205 if ( ! C_plus_plus
)
1208 "static yy_state_type yy_state_buf[YY_BUF_SIZE + 2], *yy_state_ptr;" );
1209 outn( "static char *yy_full_match;" );
1210 outn( "static int yy_lp;" );
1213 if ( variable_trailing_context_rules
)
1215 if ( ! C_plus_plus
)
1218 "static int yy_looking_for_trail_begin = 0;" );
1219 outn( "static int yy_full_lp;" );
1220 outn( "static int *yy_full_state;" );
1223 out_hex( "#define YY_TRAILING_MASK 0x%x\n",
1224 (unsigned int) YY_TRAILING_MASK
);
1225 out_hex( "#define YY_TRAILING_HEAD_MASK 0x%x\n",
1226 (unsigned int) YY_TRAILING_HEAD_MASK
);
1229 outn( "#define REJECT \\" );
1230 outn( "{ \\" ); /* } for vi */
1232 "*yy_cp = yy_hold_char; /* undo effects of setting up yytext */ \\" );
1234 "yy_cp = yy_full_match; /* restore poss. backed-over text */ \\" );
1236 if ( variable_trailing_context_rules
)
1239 "yy_lp = yy_full_lp; /* restore orig. accepting pos. */ \\" );
1241 "yy_state_ptr = yy_full_state; /* restore orig. state */ \\" );
1243 "yy_current_state = *yy_state_ptr; /* restore curr. state */ \\" );
1246 outn( "++yy_lp; \\" );
1247 outn( "goto find_rule; \\" );
1255 "/* The intent behind this definition is that it'll catch" );
1256 outn( " * any uses of REJECT which flex missed." );
1258 outn( "#define REJECT reject_used_but_not_detected" );
1263 if ( ! C_plus_plus
)
1265 if ( yytext_is_array
)
1267 indent_puts( "static int yy_more_offset = 0;" );
1269 "static int yy_prev_more_offset = 0;" );
1273 indent_puts( "static int yy_more_flag = 0;" );
1274 indent_puts( "static int yy_more_len = 0;" );
1278 if ( yytext_is_array
)
1281 "#define yymore() (yy_more_offset = yy_flex_strlen( yytext ))" );
1282 indent_puts( "#define YY_NEED_STRLEN" );
1283 indent_puts( "#define YY_MORE_ADJ 0" );
1284 indent_puts( "#define YY_RESTORE_YY_MORE_OFFSET \\" );
1286 indent_puts( "{ \\" );
1287 indent_puts( "yy_more_offset = yy_prev_more_offset; \\" );
1288 indent_puts( "yyleng -= yy_more_offset; \\" );
1294 indent_puts( "#define yymore() (yy_more_flag = 1)" );
1295 indent_puts( "#define YY_MORE_ADJ yy_more_len" );
1296 indent_puts( "#define YY_RESTORE_YY_MORE_OFFSET" );
1302 indent_puts( "#define yymore() yymore_used_but_not_detected" );
1303 indent_puts( "#define YY_MORE_ADJ 0" );
1304 indent_puts( "#define YY_RESTORE_YY_MORE_OFFSET" );
1307 if ( ! C_plus_plus
)
1309 if ( yytext_is_array
)
1311 outn( "#ifndef YYLMAX" );
1312 outn( "#define YYLMAX 8192" );
1314 outn( "char yytext[YYLMAX];" );
1315 outn( "char *yytext_ptr;" );
1319 outn( "char *yytext;" );
1322 out( &action_array
[defs1_offset
] );
1324 line_directive_out( stdout
, 0 );
1328 if ( ! C_plus_plus
)
1333 "\tif ( (result = read( fileno(yyin), (char *) buf, max_size )) < 0 ) \\" );
1335 "\t\tYY_FATAL_ERROR( \"input in flex scanner failed\" );" );
1341 "\tif ( yy_current_buffer->yy_is_interactive ) \\" );
1343 outn( "\t\tint c = '*', n; \\" );
1344 outn( "\t\tfor ( n = 0; n < max_size && \\" );
1345 outn( "\t\t\t (c = getc( yyin )) != EOF && c != '\\n'; ++n ) \\" );
1346 outn( "\t\t\tbuf[n] = (char) c; \\" );
1347 outn( "\t\tif ( c == '\\n' ) \\" );
1348 outn( "\t\t\tbuf[n++] = (char) c; \\" );
1349 outn( "\t\tif ( c == EOF && ferror( yyin ) ) \\" );
1351 "\t\t\tYY_FATAL_ERROR( \"input in flex scanner failed\" ); \\" );
1352 outn( "\t\tresult = n; \\" );
1355 "\telse if ( ((result = fread( buf, 1, max_size, yyin )) == 0) \\" );
1356 outn( "\t\t && ferror( yyin ) ) \\" );
1358 "\t\tYY_FATAL_ERROR( \"input in flex scanner failed\" );" );
1364 indent_puts( "#define YY_RULE_SETUP \\" );
1368 indent_puts( "if ( yyleng > 0 ) \\" );
1370 indent_puts( "yy_current_buffer->yy_at_bol = \\" );
1371 indent_puts( "\t\t(yytext[yyleng - 1] == '\\n'); \\" );
1374 indent_puts( "YY_USER_ACTION" );
1379 /* Copy prolog to output file. */
1380 out( &action_array
[prolog_offset
] );
1382 line_directive_out( stdout
, 0 );
1388 if ( yymore_used
&& ! yytext_is_array
)
1390 indent_puts( "yy_more_len = 0;" );
1391 indent_puts( "if ( yy_more_flag )" );
1394 indent_puts( "yy_more_len = yy_c_buf_p - yytext_ptr;" );
1395 indent_puts( "yy_more_flag = 0;" );
1404 /* Note, don't use any indentation. */
1405 outn( "yy_match:" );
1415 indent_puts( "if ( yy_act != YY_END_OF_BUFFER )" );
1418 indent_puts( "int yyl;" );
1419 indent_puts( "for ( yyl = 0; yyl < yyleng; ++yyl )" );
1421 indent_puts( "if ( yytext[yyl] == '\\n' )" );
1423 indent_puts( "++yylineno;" );
1433 indent_puts( "if ( yy_flex_debug )" );
1437 indent_puts( "if ( yy_act == 0 )" );
1439 indent_puts( C_plus_plus
?
1440 "cerr << \"--scanner backing up\\n\";" :
1441 "fprintf( stderr, \"--scanner backing up\\n\" );" );
1445 out_dec( "else if ( yy_act < %d )\n", num_rules
);
1451 "cerr << \"--accepting rule at line \" << yy_rule_linenum[yy_act] <<" );
1453 " \"(\\\"\" << yytext << \"\\\")\\n\";" );
1458 "fprintf( stderr, \"--accepting rule at line %d (\\\"%s\\\")\\n\"," );
1461 " yy_rule_linenum[yy_act], yytext );" );
1467 out_dec( "else if ( yy_act == %d )\n", num_rules
);
1473 "cerr << \"--accepting default rule (\\\"\" << yytext << \"\\\")\\n\";" );
1478 "fprintf( stderr, \"--accepting default rule (\\\"%s\\\")\\n\"," );
1479 indent_puts( " yytext );" );
1485 out_dec( "else if ( yy_act == %d )\n", num_rules
+ 1 );
1488 indent_puts( C_plus_plus
?
1489 "cerr << \"--(end of buffer or a NUL)\\n\";" :
1490 "fprintf( stderr, \"--(end of buffer or a NUL)\\n\" );" );
1501 "cerr << \"--EOF (start condition \" << YY_START << \")\\n\";" );
1506 "fprintf( stderr, \"--EOF (start condition %d)\\n\", YY_START );" );
1515 /* Copy actions to output file. */
1519 out( &action_array
[action_offset
] );
1521 line_directive_out( stdout
, 0 );
1523 /* generate cases for any missing EOF rules */
1524 for ( i
= 1; i
<= lastsc
; ++i
)
1528 out_str( "case YY_STATE_EOF(%s):\n", scname
[i
] );
1529 did_eof_rule
= true;
1535 indent_puts( "yyterminate();" );
1540 /* Generate code for handling NUL's, if needed. */
1542 /* First, deal with backing up and setting up yy_cp if the scanner
1543 * finds that it should JAM on the NUL.
1548 if ( fullspd
|| fulltbl
)
1549 indent_puts( "yy_cp = yy_c_buf_p;" );
1552 { /* compressed table */
1553 if ( ! reject
&& ! interactive
)
1555 /* Do the guaranteed-needed backing up to figure
1558 indent_puts( "yy_cp = yy_last_accepting_cpos;" );
1560 "yy_current_state = yy_last_accepting_state;" );
1564 /* Still need to initialize yy_cp, though
1565 * yy_current_state was set up by
1566 * yy_get_previous_state().
1568 indent_puts( "yy_cp = yy_c_buf_p;" );
1572 /* Generate code for yy_get_previous_state(). */
1580 gen_next_state( true );
1588 { /* update yylineno inside of unput() */
1589 indent_puts( "if ( c == '\\n' )" );
1591 indent_puts( "--yylineno;" );
1596 /* Update BOL and yylineno inside of input(). */
1599 indent_puts( "yy_current_buffer->yy_at_bol = (c == '\\n');" );
1602 indent_puts( "if ( yy_current_buffer->yy_at_bol )" );
1604 indent_puts( "++yylineno;" );
1609 else if ( do_yylineno
)
1611 indent_puts( "if ( c == '\\n' )" );
1613 indent_puts( "++yylineno;" );
1619 /* Copy remainder of input to output. */
1621 line_directive_out( stdout
, 1 );
1624 (void) flexscan(); /* copy remainder of input to output */