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 /* $NetBSD: gen.c,v 1.17 2003/11/18 21:37:39 christos Exp $ */
34 /* declare functions that have forward references */
36 void genecs
PROTO((void));
39 static int indent_level
= 0; /* each level is 8 spaces */
41 #define indent_up() (++indent_level)
42 #define indent_down() (--indent_level)
43 #define set_indent(indent_val) indent_level = indent_val
45 /* Almost everything is done in terms of arrays starting at 1, so provide
46 * a null entry for the zero element of all C arrays. (The exception
47 * to this is that the fast table representation generally uses the
48 * 0 elements of its arrays, too.)
50 static char C_int_decl
[] = "static yyconst int %s[%d] =\n { 0,\n";
51 static char C_short_decl
[] = "static yyconst short int %s[%d] =\n { 0,\n";
52 static char C_long_decl
[] = "static yyconst long int %s[%d] =\n { 0,\n";
53 static char C_state_decl
[] =
54 "static yyconst yy_state_type %s[%d] =\n { 0,\n";
57 /* Indent to the current level. */
61 register int i
= indent_level
* 8;
77 /* Generate the code to keep backing-up information. */
81 if ( reject
|| num_backing_up
== 0 )
85 indent_puts( "if ( yy_current_state[-1].yy_nxt )" );
87 indent_puts( "if ( yy_accept[yy_current_state] )" );
91 indent_puts( "yy_last_accepting_state = yy_current_state;" );
92 indent_puts( "yy_last_accepting_cpos = yy_cp;" );
98 /* Generate the code to perform the backing up. */
102 if ( reject
|| num_backing_up
== 0 )
107 indent_puts( "case 0: /* must back up */" );
108 indent_puts( "/* undo the effects of YY_DO_BEFORE_ACTION */" );
109 indent_puts( "*yy_cp = yy_hold_char;" );
111 if ( fullspd
|| fulltbl
)
112 indent_puts( "yy_cp = yy_last_accepting_cpos + 1;" );
114 /* Backing-up info for compressed tables is taken \after/
115 * yy_cp has been incremented for the next state.
117 indent_puts( "yy_cp = yy_last_accepting_cpos;" );
119 indent_puts( "yy_current_state = yy_last_accepting_state;" );
120 indent_puts( "goto yy_find_action;" );
127 /* genctbl - generates full speed compressed transition table */
132 int end_of_buffer_action
= num_rules
+ 1;
134 /* Table of verify for transition and offset to next state. */
135 out_dec( "static yyconst struct yy_trans_info yy_transition[%d] =\n",
136 tblend
+ numecs
+ 1 );
139 /* We want the transition to be represented as the offset to the
140 * next state, not the actual state number, which is what it currently
141 * is. The offset is base[nxt[i]] - (base of current state)]. That's
142 * just the difference between the starting points of the two involved
143 * states (to - from).
145 * First, though, we need to find some way to put in our end-of-buffer
146 * flags and states. We do this by making a state with absolutely no
147 * transitions. We put it at the end of the table.
150 /* We need to have room in nxt/chk for two more slots: One for the
151 * action and one for the end-of-buffer transition. We now *assume*
152 * that we're guaranteed the only character we'll try to index this
153 * nxt/chk pair with is EOB, i.e., 0, so we don't have to make sure
154 * there's room for jam entries for other characters.
157 while ( tblend
+ 2 >= current_max_xpairs
)
160 while ( lastdfa
+ 1 >= current_max_dfas
)
163 base
[lastdfa
+ 1] = tblend
+ 2;
164 nxt
[tblend
+ 1] = end_of_buffer_action
;
165 chk
[tblend
+ 1] = numecs
+ 1;
166 chk
[tblend
+ 2] = 1; /* anything but EOB */
168 /* So that "make test" won't show arb. differences. */
171 /* Make sure every state has an end-of-buffer transition and an
174 for ( i
= 0; i
<= lastdfa
; ++i
)
176 int anum
= dfaacc
[i
].dfaacc_state
;
177 int offset
= base
[i
];
179 chk
[offset
] = EOB_POSITION
;
180 chk
[offset
- 1] = ACTION_POSITION
;
181 nxt
[offset
- 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
],
197 base
[nxt
[i
]] - (i
- chk
[i
]) );
201 /* Here's the final, end-of-buffer state. */
202 transition_struct_out( chk
[tblend
+ 1], nxt
[tblend
+ 1] );
203 transition_struct_out( chk
[tblend
+ 2], nxt
[tblend
+ 2] );
207 /* Table of pointers to start states. */
209 "static yyconst struct yy_trans_info *yy_start_state_list[%d] =\n",
211 outn( " {" ); /* } so vi doesn't get confused */
213 for ( i
= 0; i
<= lastsc
* 2; ++i
)
214 out_dec( " &yy_transition[%d],\n", base
[i
] );
223 /* Generate equivalence-class tables. */
230 out_str_dec( C_int_decl
, "yy_ec", csize
);
232 for ( i
= 1; i
< csize
; ++i
)
234 if ( caseins
&& (i
>= 'A') && (i
<= 'Z') )
235 ecgroup
[i
] = ecgroup
[clower( i
)];
237 ecgroup
[i
] = ABS( ecgroup
[i
] );
238 mkdata( ecgroup
[i
] );
245 fputs( _( "\n\nEquivalence Classes:\n\n" ), stderr
);
249 for ( j
= 0; j
< numrows
; ++j
)
251 for ( i
= j
; i
< csize
; i
= i
+ numrows
)
253 fprintf( stderr
, "%4s = %-2d",
254 readable_form( i
), ecgroup
[i
] );
259 putc( '\n', stderr
);
265 /* Generate the code to find the action number. */
267 void gen_find_action()
270 indent_puts( "yy_act = yy_current_state[-1].yy_nxt;" );
273 indent_puts( "yy_act = yy_accept[yy_current_state];" );
277 indent_puts( "yy_current_state = *--yy_state_ptr;" );
278 indent_puts( "yy_lp = yy_accept[yy_current_state];" );
281 "find_rule: /* we branch to this label when backing up */" );
284 "for ( ; ; ) /* until we find what rule we matched */" );
291 "if ( yy_lp && yy_lp < yy_accept[yy_current_state + 1] )" );
294 indent_puts( "yy_act = yy_acclist[yy_lp];" );
296 if ( variable_trailing_context_rules
)
298 indent_puts( "if ( yy_act & YY_TRAILING_HEAD_MASK ||" );
299 indent_puts( " yy_looking_for_trail_begin )" );
304 "if ( yy_act == yy_looking_for_trail_begin )" );
307 indent_puts( "yy_looking_for_trail_begin = 0;" );
308 indent_puts( "yy_act &= ~YY_TRAILING_HEAD_MASK;" );
309 indent_puts( "break;" );
316 indent_puts( "else if ( yy_act & YY_TRAILING_MASK )" );
320 "yy_looking_for_trail_begin = yy_act & ~YY_TRAILING_MASK;" );
322 "yy_looking_for_trail_begin |= YY_TRAILING_HEAD_MASK;" );
326 /* Remember matched text in case we back up
329 indent_puts( "yy_full_match = yy_cp;" );
330 indent_puts( "yy_full_state = yy_state_ptr;" );
331 indent_puts( "yy_full_lp = yy_lp;" );
337 indent_puts( "else" );
340 indent_puts( "yy_full_match = yy_cp;" );
341 indent_puts( "yy_full_state = yy_state_ptr;" );
342 indent_puts( "yy_full_lp = yy_lp;" );
343 indent_puts( "break;" );
347 indent_puts( "++yy_lp;" );
348 indent_puts( "goto find_rule;" );
353 /* Remember matched text in case we back up due to
354 * trailing context plus REJECT.
358 indent_puts( "yy_full_match = yy_cp;" );
359 indent_puts( "break;" );
367 indent_puts( "--yy_cp;" );
369 /* We could consolidate the following two lines with those at
370 * the beginning, but at the cost of complaints that we're
371 * branching inside a loop.
373 indent_puts( "yy_current_state = *--yy_state_ptr;" );
374 indent_puts( "yy_lp = yy_accept[yy_current_state];" );
383 indent_puts( "yy_act = yy_accept[yy_current_state];" );
385 if ( interactive
&& ! reject
)
387 /* Do the guaranteed-needed backing up to figure out
390 indent_puts( "if ( yy_act == 0 )" );
392 indent_puts( "{ /* have to back up */" );
393 indent_puts( "yy_cp = yy_last_accepting_cpos;" );
395 "yy_current_state = yy_last_accepting_state;" );
396 indent_puts( "yy_act = yy_accept[yy_current_state];" );
404 /* genftbl - generate full transition table */
409 int end_of_buffer_action
= num_rules
+ 1;
411 out_str_dec( long_align
? C_long_decl
: C_short_decl
,
412 "yy_accept", lastdfa
+ 1 );
414 dfaacc
[end_of_buffer_state
].dfaacc_state
= end_of_buffer_action
;
416 for ( i
= 1; i
<= lastdfa
; ++i
)
418 register int anum
= dfaacc
[i
].dfaacc_state
;
423 fprintf( stderr
, _( "state # %d accepts: [%d]\n" ),
432 /* Don't have to dump the actual full table entries - they were
433 * created on-the-fly.
438 /* Generate the code to find the next compressed-table state. */
440 void gen_next_compressed_state( char_map
)
443 indent_put2s( "register YY_CHAR yy_c = %s;", char_map
);
445 /* Save the backing-up info \before/ computing the next state
446 * because we always compute one more state than needed - we
447 * always proceed until we reach a jam state
452 "while ( yy_chk[yy_base[yy_current_state] + yy_c] != yy_current_state )" );
455 indent_puts( "yy_current_state = (int) yy_def[yy_current_state];" );
459 /* We've arrange it so that templates are never chained
460 * to one another. This means we can afford to make a
461 * very simple test to see if we need to convert to
462 * yy_c's meta-equivalence class without worrying
463 * about erroneously looking up the meta-equivalence
468 /* lastdfa + 2 is the beginning of the templates */
469 out_dec( "if ( yy_current_state >= %d )\n", lastdfa
+ 2 );
472 indent_puts( "yy_c = yy_meta[(unsigned int) yy_c];" );
480 "yy_current_state = yy_nxt[yy_base[yy_current_state] + (unsigned int) yy_c];" );
484 /* Generate the code to find the next match. */
486 void gen_next_match()
488 /* NOTE - changes in here should be reflected in gen_next_state() and
491 char *char_map
= useecs
?
492 "yy_ec[YY_SC_TO_UI(*yy_cp)]" :
493 "YY_SC_TO_UI(*yy_cp)";
495 char *char_map_2
= useecs
?
496 "yy_ec[YY_SC_TO_UI(*++yy_cp)]" :
497 "YY_SC_TO_UI(*++yy_cp)";
502 "while ( (yy_current_state = yy_nxt[yy_current_state][%s]) > 0 )",
507 if ( num_backing_up
> 0 )
509 indent_puts( "{" ); /* } for vi */
514 indent_puts( "++yy_cp;" );
516 if ( num_backing_up
> 0 )
523 indent_puts( "yy_current_state = -yy_current_state;" );
528 indent_puts( "{" ); /* } for vi */
530 "register yyconst struct yy_trans_info *yy_trans_info;\n" );
531 indent_puts( "register YY_CHAR yy_c;\n" );
532 indent_put2s( "for ( yy_c = %s;", char_map
);
534 " (yy_trans_info = &yy_current_state[(unsigned int) yy_c])->" );
535 indent_puts( "yy_verify == yy_c;" );
536 indent_put2s( " yy_c = %s )", char_map_2
);
540 if ( num_backing_up
> 0 )
541 indent_puts( "{" ); /* } for vi */
543 indent_puts( "yy_current_state += yy_trans_info->yy_nxt;" );
545 if ( num_backing_up
> 0 )
548 gen_backing_up(); /* { for vi */
552 indent_down(); /* { for vi */
561 indent_puts( "{" ); /* } for vi */
563 gen_next_state( false );
565 indent_puts( "++yy_cp;" );
574 out_dec( "while ( yy_base[yy_current_state] != %d );\n",
577 out_dec( "while ( yy_current_state != %d );\n",
580 if ( ! reject
&& ! interactive
)
582 /* Do the guaranteed-needed backing up to figure out
585 indent_puts( "yy_cp = yy_last_accepting_cpos;" );
587 "yy_current_state = yy_last_accepting_state;" );
593 /* Generate the code to find the next state. */
595 void gen_next_state( worry_about_NULs
)
596 int worry_about_NULs
;
597 { /* NOTE - changes in here should be reflected in gen_next_match() */
600 if ( worry_about_NULs
&& ! nultrans
)
603 (void) snprintf(char_map
, sizeof(char_map
),
604 "(*yy_cp ? yy_ec[YY_SC_TO_UI(*yy_cp)] : %d)",
607 (void) snprintf(char_map
, sizeof(char_map
),
608 "(*yy_cp ? YY_SC_TO_UI(*yy_cp) : %d)", NUL_ec
);
612 strlcpy(char_map
, useecs
?
613 "yy_ec[YY_SC_TO_UI(*yy_cp)]" : "YY_SC_TO_UI(*yy_cp)",
616 if ( worry_about_NULs
&& nultrans
)
618 if ( ! fulltbl
&& ! fullspd
)
619 /* Compressed tables back up *before* they match. */
622 indent_puts( "if ( *yy_cp )" );
624 indent_puts( "{" ); /* } for vi */
629 "yy_current_state = yy_nxt[yy_current_state][%s];",
634 "yy_current_state += yy_current_state[%s].yy_nxt;",
638 gen_next_compressed_state( char_map
);
640 if ( worry_about_NULs
&& nultrans
)
645 indent_puts( "else" );
648 "yy_current_state = yy_NUL_trans[yy_current_state];" );
652 if ( fullspd
|| fulltbl
)
656 indent_puts( "*yy_state_ptr++ = yy_current_state;" );
660 /* Generate the code to make a NUL transition. */
663 { /* NOTE - changes in here should be reflected in gen_next_match() */
664 /* Only generate a definition for "yy_cp" if we'll generate code
665 * that uses it. Otherwise lint and the like complain.
667 int need_backing_up
= (num_backing_up
> 0 && ! reject
);
669 if ( need_backing_up
&& (! nultrans
|| fullspd
|| fulltbl
) )
670 /* We're going to need yy_cp lying around for the call
671 * below to gen_backing_up().
673 indent_puts( "register char *yy_cp = yy_c_buf_p;" );
680 "yy_current_state = yy_NUL_trans[yy_current_state];" );
681 indent_puts( "yy_is_jam = (yy_current_state == 0);" );
687 out_dec( "yy_current_state = yy_nxt[yy_current_state][%d];\n",
689 indent_puts( "yy_is_jam = (yy_current_state <= 0);" );
695 out_dec( "register int yy_c = %d;\n", NUL_ec
);
698 "register yyconst struct yy_trans_info *yy_trans_info;\n" );
700 "yy_trans_info = &yy_current_state[(unsigned int) yy_c];" );
701 indent_puts( "yy_current_state += yy_trans_info->yy_nxt;" );
704 "yy_is_jam = (yy_trans_info->yy_verify != yy_c);" );
711 (void) snprintf(NUL_ec_str
, sizeof(NUL_ec_str
), "%d", NUL_ec
);
712 gen_next_compressed_state( NUL_ec_str
);
715 out_dec( "yy_is_jam = (yy_current_state == %d);\n", jamstate
);
719 /* Only stack this state if it's a transition we
720 * actually make. If we stack it on a jam, then
721 * the state stack and yy_c_buf_p get out of sync.
723 indent_puts( "if ( ! yy_is_jam )" );
725 indent_puts( "*yy_state_ptr++ = yy_current_state;" );
730 /* If we've entered an accepting state, back up; note that
731 * compressed tables have *already* done such backing up, so
732 * we needn't bother with it again.
734 if ( need_backing_up
&& (fullspd
|| fulltbl
) )
737 indent_puts( "if ( ! yy_is_jam )" );
747 /* Generate the code to find the start state. */
749 void gen_start_state()
756 "yy_current_state = yy_start_state_list[yy_start + YY_AT_BOL()];" );
760 "yy_current_state = yy_start_state_list[yy_start];" );
765 indent_puts( "yy_current_state = yy_start;" );
768 indent_puts( "yy_current_state += YY_AT_BOL();" );
772 /* Set up for storing up states. */
773 indent_puts( "yy_state_ptr = yy_state_buf;" );
774 indent_puts( "*yy_state_ptr++ = yy_current_state;" );
780 /* gentabs - generate data statements for the transition tables */
784 int i
, j
, k
, *accset
, nacc
, *acc_array
, total_states
;
785 int end_of_buffer_action
= num_rules
+ 1;
787 acc_array
= allocate_integer_array( current_max_dfas
);
790 /* The compressed table format jams by entering the "jam state",
791 * losing information about the previous state in the process.
792 * In order to recover the previous state, we effectively need
793 * to keep backing-up information.
799 /* Write out accepting list and pointer list.
801 * First we generate the "yy_acclist" array. In the process,
802 * we compute the indices that will go into the "yy_accept"
803 * array, and save the indices in the dfaacc array.
805 int EOB_accepting_list
[2];
807 /* Set up accepting structures for the End Of Buffer state. */
808 EOB_accepting_list
[0] = 0;
809 EOB_accepting_list
[1] = end_of_buffer_action
;
810 accsiz
[end_of_buffer_state
] = 1;
811 dfaacc
[end_of_buffer_state
].dfaacc_set
= EOB_accepting_list
;
813 out_str_dec( long_align
? C_long_decl
: C_short_decl
,
814 "yy_acclist", MAX( numas
, 1 ) + 1 );
816 j
= 1; /* index into "yy_acclist" array */
818 for ( i
= 1; i
<= lastdfa
; ++i
)
822 if ( accsiz
[i
] != 0 )
824 accset
= dfaacc
[i
].dfaacc_set
;
829 _( "state # %d accepts: " ),
832 for ( k
= 1; k
<= nacc
; ++k
)
834 int accnum
= accset
[k
];
838 if ( variable_trailing_context_rules
&&
839 ! (accnum
& YY_TRAILING_HEAD_MASK
) &&
840 accnum
> 0 && accnum
<= num_rules
&&
841 rule_type
[accnum
] == RULE_VARIABLE
)
843 /* Special hack to flag
844 * accepting number as part
845 * of trailing context rule.
847 accnum
|= YY_TRAILING_MASK
;
854 fprintf( stderr
, "[%d]",
858 fputs( ", ", stderr
);
860 putc( '\n', stderr
);
866 /* add accepting number for the "jam" state */
874 dfaacc
[end_of_buffer_state
].dfaacc_state
= end_of_buffer_action
;
876 for ( i
= 1; i
<= lastdfa
; ++i
)
877 acc_array
[i
] = dfaacc
[i
].dfaacc_state
;
879 /* add accepting number for jam state */
883 /* Spit out "yy_accept" array. If we're doing "reject", it'll be
884 * pointers into the "yy_acclist" array. Otherwise it's actual
885 * accepting numbers. In either case, we just dump the numbers.
888 /* "lastdfa + 2" is the size of "yy_accept"; includes room for C arrays
889 * beginning at 0 and for "jam" state.
894 /* We put a "cap" on the table associating lists of accepting
895 * numbers with state numbers. This is needed because we tell
896 * where the end of an accepting list is by looking at where
897 * the list for the next state starts.
901 out_str_dec( long_align
? C_long_decl
: C_short_decl
, "yy_accept", k
);
903 for ( i
= 1; i
<= lastdfa
; ++i
)
905 mkdata( acc_array
[i
] );
907 if ( ! reject
&& trace
&& acc_array
[i
] )
908 fprintf( stderr
, _( "state # %d accepts: [%d]\n" ),
912 /* Add entry for "jam" state. */
913 mkdata( acc_array
[i
] );
916 /* Add "cap" for the list. */
917 mkdata( acc_array
[i
] );
926 /* Write out meta-equivalence classes (used to index
931 fputs( _( "\n\nMeta-Equivalence Classes:\n" ),
934 out_str_dec( C_int_decl
, "yy_meta", numecs
+ 1 );
936 for ( i
= 1; i
<= numecs
; ++i
)
939 fprintf( stderr
, "%d = %d\n",
940 i
, ABS( tecbck
[i
] ) );
942 mkdata( ABS( tecbck
[i
] ) );
948 total_states
= lastdfa
+ numtemps
;
950 out_str_dec( (tblend
>= MAX_SHORT
|| long_align
) ?
951 C_long_decl
: C_short_decl
,
952 "yy_base", total_states
+ 1 );
954 for ( i
= 1; i
<= lastdfa
; ++i
)
956 register int d
= def
[i
];
958 if ( base
[i
] == JAMSTATE
)
966 /* Template reference. */
968 def
[i
] = lastdfa
- d
+ 1;
974 /* Generate jam state's base index. */
977 for ( ++i
/* skip jam state */; i
<= total_states
; ++i
)
985 out_str_dec( (total_states
>= MAX_SHORT
|| long_align
) ?
986 C_long_decl
: C_short_decl
,
987 "yy_def", total_states
+ 1 );
989 for ( i
= 1; i
<= total_states
; ++i
)
994 out_str_dec( (total_states
>= MAX_SHORT
|| long_align
) ?
995 C_long_decl
: C_short_decl
,
996 "yy_nxt", tblend
+ 1 );
998 for ( i
= 1; i
<= tblend
; ++i
)
1000 /* Note, the order of the following test is important.
1001 * If chk[i] is 0, then nxt[i] is undefined.
1003 if ( chk
[i
] == 0 || nxt
[i
] == 0 )
1004 nxt
[i
] = jamstate
; /* new state is the JAM state */
1011 out_str_dec( (total_states
>= MAX_SHORT
|| long_align
) ?
1012 C_long_decl
: C_short_decl
,
1013 "yy_chk", tblend
+ 1 );
1015 for ( i
= 1; i
<= tblend
; ++i
)
1028 /* Write out a formatted string (with a secondary string argument) at the
1029 * current indentation level, adding a final newline.
1032 void indent_put2s( fmt
, arg
)
1036 out_str( fmt
, arg
);
1041 /* Write out a string at the current indentation level, adding a final
1045 void indent_puts( str
)
1053 /* make_tables - generate transition tables and finishes generating output file
1059 int did_eof_rule
= false;
1063 /* First, take care of YY_DO_BEFORE_ACTION depending on yymore
1068 if ( yymore_used
&& ! yytext_is_array
)
1070 indent_puts( "yytext_ptr -= yy_more_len; \\" );
1071 indent_puts( "yyleng = (int) (yy_cp - yytext_ptr); \\" );
1075 indent_puts( "yyleng = (int) (yy_cp - yy_bp); \\" );
1077 /* Now also deal with copying yytext_ptr to yytext if needed. */
1079 if ( yytext_is_array
)
1083 "if ( yyleng + yy_more_offset >= YYLMAX ) \\" );
1085 indent_puts( "if ( yyleng >= YYLMAX ) \\" );
1089 "YY_FATAL_ERROR( \"token too large, exceeds YYLMAX\" ); \\" );
1095 "yy_flex_strncpy( &yytext[yy_more_offset], yytext_ptr, yyleng + 1 ); \\" );
1096 indent_puts( "yyleng += yy_more_offset; \\" );
1098 "yy_prev_more_offset = yy_more_offset; \\" );
1099 indent_puts( "yy_more_offset = 0; \\" );
1104 "yy_flex_strncpy( yytext, yytext_ptr, yyleng + 1 ); \\" );
1113 out_dec( "#define YY_NUM_RULES %d\n", num_rules
);
1114 out_dec( "#define YY_END_OF_BUFFER %d\n", num_rules
+ 1 );
1118 /* Need to define the transet type as a size large
1119 * enough to hold the biggest offset.
1121 int total_table_size
= tblend
+ numecs
+ 1;
1122 char *trans_offset_type
=
1123 (total_table_size
>= MAX_SHORT
|| long_align
) ?
1127 indent_puts( "struct yy_trans_info" );
1129 indent_puts( "{" ); /* } for vi */
1132 indent_puts( "long yy_verify;" );
1134 indent_puts( "short yy_verify;" );
1136 /* In cases where its sister yy_verify *is* a "yes, there is
1137 * a transition", yy_nxt is the offset (in records) to the
1138 * next state. In most cases where there is no transition,
1139 * the value of yy_nxt is irrelevant. If yy_nxt is the -1th
1140 * record of a state, though, then yy_nxt is the action number
1144 indent_put2s( "%s yy_nxt;", trans_offset_type
);
1145 indent_puts( "};" );
1156 /* Definitions for backing up. We don't need them if REJECT
1157 * is being used because then we use an alternative backin-up
1158 * technique instead.
1160 if ( num_backing_up
> 0 && ! reject
)
1162 if ( ! C_plus_plus
)
1165 "static yy_state_type yy_last_accepting_state;" );
1167 "static char *yy_last_accepting_cpos;\n" );
1173 out_str_dec( C_state_decl
, "yy_NUL_trans", lastdfa
+ 1 );
1175 for ( i
= 1; i
<= lastdfa
; ++i
)
1178 out_dec( " &yy_transition[%d],\n", base
[i
] );
1180 mkdata( nultrans
[i
] );
1187 { /* Spit out table mapping rules to line numbers. */
1188 if ( ! C_plus_plus
)
1190 indent_puts( "extern int yy_flex_debug;" );
1191 indent_puts( "int yy_flex_debug = 1;\n" );
1194 out_str_dec( long_align
? C_long_decl
: C_short_decl
,
1195 "yy_rule_linenum", num_rules
);
1196 for ( i
= 1; i
< num_rules
; ++i
)
1197 mkdata( rule_linenum
[i
] );
1203 /* Declare state buffer variables. */
1204 if ( ! C_plus_plus
)
1207 "static yy_state_type yy_state_buf[YY_BUF_SIZE + 2], *yy_state_ptr;" );
1208 outn( "static char *yy_full_match;" );
1209 outn( "static int yy_lp;" );
1212 if ( variable_trailing_context_rules
)
1214 if ( ! C_plus_plus
)
1217 "static int yy_looking_for_trail_begin = 0;" );
1218 outn( "static int yy_full_lp;" );
1219 outn( "static int *yy_full_state;" );
1222 out_hex( "#define YY_TRAILING_MASK 0x%x\n",
1223 (unsigned int) YY_TRAILING_MASK
);
1224 out_hex( "#define YY_TRAILING_HEAD_MASK 0x%x\n",
1225 (unsigned int) YY_TRAILING_HEAD_MASK
);
1228 outn( "#define REJECT \\" );
1229 outn( "{ \\" ); /* } for vi */
1231 "*yy_cp = yy_hold_char; /* undo effects of setting up yytext */ \\" );
1233 "yy_cp = yy_full_match; /* restore poss. backed-over text */ \\" );
1235 if ( variable_trailing_context_rules
)
1238 "yy_lp = yy_full_lp; /* restore orig. accepting pos. */ \\" );
1240 "yy_state_ptr = yy_full_state; /* restore orig. state */ \\" );
1242 "yy_current_state = *yy_state_ptr; /* restore curr. state */ \\" );
1245 outn( "++yy_lp; \\" );
1246 outn( "goto find_rule; \\" );
1254 "/* The intent behind this definition is that it'll catch" );
1255 outn( " * any uses of REJECT which flex missed." );
1257 outn( "#define REJECT reject_used_but_not_detected" );
1262 if ( ! C_plus_plus
)
1264 if ( yytext_is_array
)
1266 indent_puts( "static int yy_more_offset = 0;" );
1268 "static int yy_prev_more_offset = 0;" );
1272 indent_puts( "static int yy_more_flag = 0;" );
1273 indent_puts( "static int yy_more_len = 0;" );
1277 if ( yytext_is_array
)
1280 "#define yymore() (yy_more_offset = yy_flex_strlen( yytext ))" );
1281 indent_puts( "#define YY_NEED_STRLEN" );
1282 indent_puts( "#define YY_MORE_ADJ 0" );
1283 indent_puts( "#define YY_RESTORE_YY_MORE_OFFSET \\" );
1285 indent_puts( "{ \\" );
1286 indent_puts( "yy_more_offset = yy_prev_more_offset; \\" );
1287 indent_puts( "yyleng -= yy_more_offset; \\" );
1293 indent_puts( "#define yymore() (yy_more_flag = 1)" );
1294 indent_puts( "#define YY_MORE_ADJ yy_more_len" );
1295 indent_puts( "#define YY_RESTORE_YY_MORE_OFFSET" );
1301 indent_puts( "#define yymore() yymore_used_but_not_detected" );
1302 indent_puts( "#define YY_MORE_ADJ 0" );
1303 indent_puts( "#define YY_RESTORE_YY_MORE_OFFSET" );
1306 if ( ! C_plus_plus
)
1308 if ( yytext_is_array
)
1310 outn( "#ifndef YYLMAX" );
1311 outn( "#define YYLMAX 8192" );
1313 outn( "char yytext[YYLMAX];" );
1314 outn( "char *yytext_ptr;" );
1318 outn( "char *yytext;" );
1321 out( &action_array
[defs1_offset
] );
1323 line_directive_out( stdout
, 0 );
1327 if ( ! C_plus_plus
)
1332 "\tif ( (result = read( fileno(yyin), (char *) buf, max_size )) < 0 ) \\" );
1334 "\t\tYY_FATAL_ERROR( \"input in flex scanner failed\" );" );
1340 "\tif ( yy_current_buffer->yy_is_interactive ) \\" );
1342 outn( "\t\tint c = '*', n; \\" );
1343 outn( "\t\tfor ( n = 0; n < max_size && \\" );
1344 outn( "\t\t\t (c = getc( yyin )) != EOF && c != '\\n'; ++n ) \\" );
1345 outn( "\t\t\tbuf[n] = (char) c; \\" );
1346 outn( "\t\tif ( c == '\\n' ) \\" );
1347 outn( "\t\t\tbuf[n++] = (char) c; \\" );
1348 outn( "\t\tif ( c == EOF && ferror( yyin ) ) \\" );
1350 "\t\t\tYY_FATAL_ERROR( \"input in flex scanner failed\" ); \\" );
1351 outn( "\t\tresult = n; \\" );
1354 "\telse if ( ((result = fread( buf, 1, (size_t)max_size, yyin )) == 0) \\" );
1355 outn( "\t\t && ferror( yyin ) ) \\" );
1357 "\t\tYY_FATAL_ERROR( \"input in flex scanner failed\" );" );
1363 indent_puts( "#define YY_RULE_SETUP \\" );
1367 indent_puts( "if ( yyleng > 0 ) \\" );
1369 indent_puts( "yy_current_buffer->yy_at_bol = \\" );
1370 indent_puts( "\t\t(yytext[yyleng - 1] == '\\n'); \\" );
1373 indent_puts( "YY_USER_ACTION" );
1378 /* Copy prolog to output file. */
1379 out( &action_array
[prolog_offset
] );
1381 line_directive_out( stdout
, 0 );
1387 if ( yymore_used
&& ! yytext_is_array
)
1389 indent_puts( "yy_more_len = 0;" );
1390 indent_puts( "if ( yy_more_flag )" );
1393 indent_puts( "yy_more_len = yy_c_buf_p - yytext_ptr;" );
1394 indent_puts( "yy_more_flag = 0;" );
1403 /* Note, don't use any indentation. */
1404 outn( "yy_match:" );
1414 indent_puts( "if ( yy_act != YY_END_OF_BUFFER )" );
1417 indent_puts( "int yyl;" );
1418 indent_puts( "for ( yyl = 0; yyl < yyleng; ++yyl )" );
1420 indent_puts( "if ( yytext[yyl] == '\\n' )" );
1422 indent_puts( "++yylineno;" );
1432 indent_puts( "if ( yy_flex_debug )" );
1436 indent_puts( "if ( yy_act == 0 )" );
1438 indent_puts( C_plus_plus
?
1439 "std::cerr << \"--scanner backing up\" << std::endl;" :
1440 "fprintf( stderr, \"--scanner backing up\\n\" );" );
1444 out_dec( "else if ( yy_act < %d )\n", num_rules
);
1450 "std::cerr << \"--accepting rule at line \" << yy_rule_linenum[yy_act] <<" );
1452 " \"(\\\"\" << yytext << \"\\\")\" << std::endl;" );
1457 "fprintf( stderr, \"--accepting rule at line %d (\\\"%s\\\")\\n\"," );
1460 " yy_rule_linenum[yy_act], yytext );" );
1466 out_dec( "else if ( yy_act == %d )\n", num_rules
);
1472 "std::cerr << \"--accepting default rule (\\\"\" << yytext << \"\\\")\" << std::endl;" );
1477 "fprintf( stderr, \"--accepting default rule (\\\"%s\\\")\\n\"," );
1478 indent_puts( " yytext );" );
1484 out_dec( "else if ( yy_act == %d )\n", num_rules
+ 1 );
1487 indent_puts( C_plus_plus
?
1488 "std::cerr << \"--(end of buffer or a NUL)\" << std::endl;" :
1489 "fprintf( stderr, \"--(end of buffer or a NUL)\\n\" );" );
1500 "std::cerr << \"--EOF (start condition \" << YY_START << \")\" << std::endl;" );
1505 "fprintf( stderr, \"--EOF (start condition %d)\\n\", YY_START );" );
1514 /* Copy actions to output file. */
1518 out( &action_array
[action_offset
] );
1520 line_directive_out( stdout
, 0 );
1522 /* generate cases for any missing EOF rules */
1523 for ( i
= 1; i
<= lastsc
; ++i
)
1527 out_str( "case YY_STATE_EOF(%s):\n", scname
[i
] );
1528 did_eof_rule
= true;
1534 indent_puts( "yyterminate();" );
1539 /* Generate code for handling NUL's, if needed. */
1541 /* First, deal with backing up and setting up yy_cp if the scanner
1542 * finds that it should JAM on the NUL.
1547 if ( fullspd
|| fulltbl
)
1548 indent_puts( "yy_cp = yy_c_buf_p;" );
1551 { /* compressed table */
1552 if ( ! reject
&& ! interactive
)
1554 /* Do the guaranteed-needed backing up to figure
1557 indent_puts( "yy_cp = yy_last_accepting_cpos;" );
1559 "yy_current_state = yy_last_accepting_state;" );
1563 /* Still need to initialize yy_cp, though
1564 * yy_current_state was set up by
1565 * yy_get_previous_state().
1567 indent_puts( "yy_cp = yy_c_buf_p;" );
1571 /* Generate code for yy_get_previous_state(). */
1579 gen_next_state( true );
1587 { /* update yylineno inside of unput() */
1588 indent_puts( "if ( c == '\\n' )" );
1590 indent_puts( "--yylineno;" );
1595 /* Update BOL and yylineno inside of input(). */
1598 indent_puts( "yy_current_buffer->yy_at_bol = (c == '\\n');" );
1601 indent_puts( "if ( yy_current_buffer->yy_at_bol )" );
1603 indent_puts( "++yylineno;" );
1608 else if ( do_yylineno
)
1610 indent_puts( "if ( c == '\\n' )" );
1612 indent_puts( "++yylineno;" );
1618 /* Copy remainder of input to output. */
1620 line_directive_out( stdout
, 1 );
1623 (void) flexscan(); /* copy remainder of input to output */