1 /* gen - actual generation (writing) of flex scanners */
3 /* Copyright (c) 1990 The Regents of the University of California. */
4 /* All rights reserved. */
6 /* This code is derived from software contributed to Berkeley by */
9 /* The United States Government has rights in this work pursuant */
10 /* to contract no. DE-AC03-76SF00098 between the United States */
11 /* Department of Energy and the University of California. */
13 /* This file is part of flex. */
15 /* Redistribution and use in source and binary forms, with or without */
16 /* modification, are permitted provided that the following conditions */
19 /* 1. Redistributions of source code must retain the above copyright */
20 /* notice, this list of conditions and the following disclaimer. */
21 /* 2. Redistributions in binary form must reproduce the above copyright */
22 /* notice, this list of conditions and the following disclaimer in the */
23 /* documentation and/or other materials provided with the distribution. */
25 /* Neither the name of the University nor the names of its contributors */
26 /* may be used to endorse or promote products derived from this software */
27 /* without specific prior written permission. */
29 /* THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR */
30 /* IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED */
31 /* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR */
38 /* declare functions that have forward references */
40 void gen_next_state
PROTO ((int));
41 void genecs
PROTO ((void));
42 void indent_put2s
PROTO ((const char *, const char *));
43 void indent_puts
PROTO ((const char *));
46 static int indent_level
= 0; /* each level is 8 spaces */
48 #define indent_up() (++indent_level)
49 #define indent_down() (--indent_level)
50 #define set_indent(indent_val) indent_level = indent_val
52 /* Almost everything is done in terms of arrays starting at 1, so provide
53 * a null entry for the zero element of all C arrays. (The exception
54 * to this is that the fast table representation generally uses the
55 * 0 elements of its arrays, too.)
58 static const char *get_int16_decl (void)
61 ? "static yyconst flex_int16_t %s[%d] =\n { 0,\n"
62 : "static yyconst flex_int16_t * %s = 0;\n";
66 static const char *get_int32_decl (void)
69 ? "static yyconst flex_int32_t %s[%d] =\n { 0,\n"
70 : "static yyconst flex_int32_t * %s = 0;\n";
73 static const char *get_state_decl (void)
76 ? "static yyconst yy_state_type %s[%d] =\n { 0,\n"
77 : "static yyconst yy_state_type * %s = 0;\n";
80 /* Indent to the current level. */
84 register int i
= indent_level
* 8;
98 /** Make the table for possible eol matches.
99 * @return the newly allocated rule_can_match_eol table
101 static struct yytbl_data
*mkeoltbl (void)
104 flex_int8_t
*tdata
= 0;
105 struct yytbl_data
*tbl
;
107 tbl
= (struct yytbl_data
*) calloc (1, sizeof (struct yytbl_data
));
108 yytbl_data_init (tbl
, YYTD_ID_RULE_CAN_MATCH_EOL
);
109 tbl
->td_flags
= YYTD_DATA8
;
110 tbl
->td_lolen
= num_rules
+ 1;
111 tbl
->td_data
= tdata
=
112 (flex_int8_t
*) calloc (tbl
->td_lolen
, sizeof (flex_int8_t
));
114 for (i
= 1; i
<= num_rules
; i
++)
115 tdata
[i
] = rule_has_nl
[i
] ? 1 : 0;
117 buf_prints (&yydmap_buf
,
118 "\t{YYTD_ID_RULE_CAN_MATCH_EOL, (void**)&yy_rule_can_match_eol, sizeof(%s)},\n",
123 /* Generate the table for possible eol matches. */
124 static void geneoltbl ()
128 outn ("m4_ifdef( [[M4_YY_USE_LINENO]],[[");
129 outn ("/* Table of booleans, true if rule could match eol. */");
130 out_str_dec (get_int32_decl (), "yy_rule_can_match_eol",
134 for (i
= 1; i
<= num_rules
; i
++) {
135 out_dec ("%d, ", rule_has_nl
[i
] ? 1 : 0);
136 /* format nicely, 20 numbers per line. */
146 /* Generate the code to keep backing-up information. */
148 void gen_backing_up ()
150 if (reject
|| num_backing_up
== 0)
154 indent_puts ("if ( yy_current_state[-1].yy_nxt )");
156 indent_puts ("if ( yy_accept[yy_current_state] )");
160 indent_puts ("YY_G(yy_last_accepting_state) = yy_current_state;");
161 indent_puts ("YY_G(yy_last_accepting_cpos) = yy_cp;");
167 /* Generate the code to perform the backing up. */
169 void gen_bu_action ()
171 if (reject
|| num_backing_up
== 0)
176 indent_puts ("case 0: /* must back up */");
177 indent_puts ("/* undo the effects of YY_DO_BEFORE_ACTION */");
178 indent_puts ("*yy_cp = YY_G(yy_hold_char);");
180 if (fullspd
|| fulltbl
)
181 indent_puts ("yy_cp = YY_G(yy_last_accepting_cpos) + 1;");
183 /* Backing-up info for compressed tables is taken \after/
184 * yy_cp has been incremented for the next state.
186 indent_puts ("yy_cp = YY_G(yy_last_accepting_cpos);");
188 indent_puts ("yy_current_state = YY_G(yy_last_accepting_state);");
189 indent_puts ("goto yy_find_action;");
195 /** mkctbl - make full speed compressed transition table
196 * This is an array of structs; each struct a pair of integers.
197 * You should call mkssltbl() immediately after this.
198 * Then, I think, mkecstbl(). Arrrg.
199 * @return the newly allocated trans table
202 static struct yytbl_data
*mkctbl (void)
205 struct yytbl_data
*tbl
= 0;
206 flex_int32_t
*tdata
= 0, curr
= 0;
207 int end_of_buffer_action
= num_rules
+ 1;
209 buf_prints (&yydmap_buf
,
210 "\t{YYTD_ID_TRANSITION, (void**)&yy_transition, sizeof(%s)},\n",
211 ((tblend
+ numecs
+ 1) >= INT16_MAX
212 || long_align
) ? "flex_int32_t" : "flex_int16_t");
214 tbl
= (struct yytbl_data
*) calloc (1, sizeof (struct yytbl_data
));
215 yytbl_data_init (tbl
, YYTD_ID_TRANSITION
);
216 tbl
->td_flags
= YYTD_DATA32
| YYTD_STRUCT
;
218 tbl
->td_lolen
= tblend
+ numecs
+ 1; /* number of structs */
220 tbl
->td_data
= tdata
=
221 (flex_int32_t
*) calloc (tbl
->td_lolen
* 2, sizeof (flex_int32_t
));
223 /* We want the transition to be represented as the offset to the
224 * next state, not the actual state number, which is what it currently
225 * is. The offset is base[nxt[i]] - (base of current state)]. That's
226 * just the difference between the starting points of the two involved
227 * states (to - from).
229 * First, though, we need to find some way to put in our end-of-buffer
230 * flags and states. We do this by making a state with absolutely no
231 * transitions. We put it at the end of the table.
234 /* We need to have room in nxt/chk for two more slots: One for the
235 * action and one for the end-of-buffer transition. We now *assume*
236 * that we're guaranteed the only character we'll try to index this
237 * nxt/chk pair with is EOB, i.e., 0, so we don't have to make sure
238 * there's room for jam entries for other characters.
241 while (tblend
+ 2 >= current_max_xpairs
)
244 while (lastdfa
+ 1 >= current_max_dfas
)
245 increase_max_dfas ();
247 base
[lastdfa
+ 1] = tblend
+ 2;
248 nxt
[tblend
+ 1] = end_of_buffer_action
;
249 chk
[tblend
+ 1] = numecs
+ 1;
250 chk
[tblend
+ 2] = 1; /* anything but EOB */
252 /* So that "make test" won't show arb. differences. */
255 /* Make sure every state has an end-of-buffer transition and an
258 for (i
= 0; i
<= lastdfa
; ++i
) {
259 int anum
= dfaacc
[i
].dfaacc_state
;
260 int offset
= base
[i
];
262 chk
[offset
] = EOB_POSITION
;
263 chk
[offset
- 1] = ACTION_POSITION
;
264 nxt
[offset
- 1] = anum
; /* action number */
267 for (i
= 0; i
<= tblend
; ++i
) {
268 if (chk
[i
] == EOB_POSITION
) {
270 tdata
[curr
++] = base
[lastdfa
+ 1] - i
;
273 else if (chk
[i
] == ACTION_POSITION
) {
275 tdata
[curr
++] = nxt
[i
];
278 else if (chk
[i
] > numecs
|| chk
[i
] == 0) {
282 else { /* verify, transition */
284 tdata
[curr
++] = chk
[i
];
285 tdata
[curr
++] = base
[nxt
[i
]] - (i
- chk
[i
]);
290 /* Here's the final, end-of-buffer state. */
291 tdata
[curr
++] = chk
[tblend
+ 1];
292 tdata
[curr
++] = nxt
[tblend
+ 1];
294 tdata
[curr
++] = chk
[tblend
+ 2];
295 tdata
[curr
++] = nxt
[tblend
+ 2];
301 /** Make start_state_list table.
302 * @return the newly allocated start_state_list table
304 static struct yytbl_data
*mkssltbl (void)
306 struct yytbl_data
*tbl
= 0;
307 flex_int32_t
*tdata
= 0;
310 tbl
= (struct yytbl_data
*) calloc (1, sizeof (struct yytbl_data
));
311 yytbl_data_init (tbl
, YYTD_ID_START_STATE_LIST
);
312 tbl
->td_flags
= YYTD_DATA32
| YYTD_PTRANS
;
314 tbl
->td_lolen
= lastsc
* 2 + 1;
316 tbl
->td_data
= tdata
=
317 (flex_int32_t
*) calloc (tbl
->td_lolen
, sizeof (flex_int32_t
));
319 for (i
= 0; i
<= lastsc
* 2; ++i
)
322 buf_prints (&yydmap_buf
,
323 "\t{YYTD_ID_START_STATE_LIST, (void**)&yy_start_state_list, sizeof(%s)},\n",
324 "struct yy_trans_info*");
331 /* genctbl - generates full speed compressed transition table */
336 int end_of_buffer_action
= num_rules
+ 1;
338 /* Table of verify for transition and offset to next state. */
340 out_dec ("static yyconst struct yy_trans_info yy_transition[%d] =\n {\n", tblend
+ numecs
+ 1);
342 outn ("static yyconst struct yy_trans_info *yy_transition = 0;");
344 /* We want the transition to be represented as the offset to the
345 * next state, not the actual state number, which is what it currently
346 * is. The offset is base[nxt[i]] - (base of current state)]. That's
347 * just the difference between the starting points of the two involved
348 * states (to - from).
350 * First, though, we need to find some way to put in our end-of-buffer
351 * flags and states. We do this by making a state with absolutely no
352 * transitions. We put it at the end of the table.
355 /* We need to have room in nxt/chk for two more slots: One for the
356 * action and one for the end-of-buffer transition. We now *assume*
357 * that we're guaranteed the only character we'll try to index this
358 * nxt/chk pair with is EOB, i.e., 0, so we don't have to make sure
359 * there's room for jam entries for other characters.
362 while (tblend
+ 2 >= current_max_xpairs
)
365 while (lastdfa
+ 1 >= current_max_dfas
)
366 increase_max_dfas ();
368 base
[lastdfa
+ 1] = tblend
+ 2;
369 nxt
[tblend
+ 1] = end_of_buffer_action
;
370 chk
[tblend
+ 1] = numecs
+ 1;
371 chk
[tblend
+ 2] = 1; /* anything but EOB */
373 /* So that "make test" won't show arb. differences. */
376 /* Make sure every state has an end-of-buffer transition and an
379 for (i
= 0; i
<= lastdfa
; ++i
) {
380 int anum
= dfaacc
[i
].dfaacc_state
;
381 int offset
= base
[i
];
383 chk
[offset
] = EOB_POSITION
;
384 chk
[offset
- 1] = ACTION_POSITION
;
385 nxt
[offset
- 1] = anum
; /* action number */
388 for (i
= 0; i
<= tblend
; ++i
) {
389 if (chk
[i
] == EOB_POSITION
)
390 transition_struct_out (0, base
[lastdfa
+ 1] - i
);
392 else if (chk
[i
] == ACTION_POSITION
)
393 transition_struct_out (0, nxt
[i
]);
395 else if (chk
[i
] > numecs
|| chk
[i
] == 0)
396 transition_struct_out (0, 0); /* unused slot */
398 else /* verify, transition */
399 transition_struct_out (chk
[i
],
405 /* Here's the final, end-of-buffer state. */
406 transition_struct_out (chk
[tblend
+ 1], nxt
[tblend
+ 1]);
407 transition_struct_out (chk
[tblend
+ 2], nxt
[tblend
+ 2]);
412 /* Table of pointers to start states. */
414 out_dec ("static yyconst struct yy_trans_info *yy_start_state_list[%d] =\n", lastsc
* 2 + 1);
416 outn ("static yyconst struct yy_trans_info **yy_start_state_list =0;");
421 for (i
= 0; i
<= lastsc
* 2; ++i
)
422 out_dec (" &yy_transition[%d],\n", base
[i
]);
432 /* mkecstbl - Make equivalence-class tables. */
434 struct yytbl_data
*mkecstbl (void)
437 struct yytbl_data
*tbl
= 0;
438 flex_int32_t
*tdata
= 0;
440 tbl
= (struct yytbl_data
*) calloc (1, sizeof (struct yytbl_data
));
441 yytbl_data_init (tbl
, YYTD_ID_EC
);
442 tbl
->td_flags
|= YYTD_DATA32
;
444 tbl
->td_lolen
= csize
;
446 tbl
->td_data
= tdata
=
447 (flex_int32_t
*) calloc (tbl
->td_lolen
, sizeof (flex_int32_t
));
449 for (i
= 1; i
< csize
; ++i
) {
450 ecgroup
[i
] = ABS (ecgroup
[i
]);
451 tdata
[i
] = ecgroup
[i
];
454 buf_prints (&yydmap_buf
,
455 "\t{YYTD_ID_EC, (void**)&yy_ec, sizeof(%s)},\n",
461 /* Generate equivalence-class tables. */
468 out_str_dec (get_int32_decl (), "yy_ec", csize
);
470 for (i
= 1; i
< csize
; ++i
) {
471 ecgroup
[i
] = ABS (ecgroup
[i
]);
478 fputs (_("\n\nEquivalence Classes:\n\n"), stderr
);
482 for (j
= 0; j
< numrows
; ++j
) {
483 for (i
= j
; i
< csize
; i
= i
+ numrows
) {
484 fprintf (stderr
, "%4s = %-2d",
485 readable_form (i
), ecgroup
[i
]);
496 /* Generate the code to find the action number. */
498 void gen_find_action ()
501 indent_puts ("yy_act = yy_current_state[-1].yy_nxt;");
504 indent_puts ("yy_act = yy_accept[yy_current_state];");
507 indent_puts ("yy_current_state = *--YY_G(yy_state_ptr);");
508 indent_puts ("YY_G(yy_lp) = yy_accept[yy_current_state];");
510 outn ("find_rule: /* we branch to this label when backing up */");
513 ("for ( ; ; ) /* until we find what rule we matched */");
520 ("if ( YY_G(yy_lp) && YY_G(yy_lp) < yy_accept[yy_current_state + 1] )");
523 indent_puts ("yy_act = yy_acclist[YY_G(yy_lp)];");
525 if (variable_trailing_context_rules
) {
527 ("if ( yy_act & YY_TRAILING_HEAD_MASK ||");
528 indent_puts (" YY_G(yy_looking_for_trail_begin) )");
533 ("if ( yy_act == YY_G(yy_looking_for_trail_begin) )");
536 indent_puts ("YY_G(yy_looking_for_trail_begin) = 0;");
537 indent_puts ("yy_act &= ~YY_TRAILING_HEAD_MASK;");
538 indent_puts ("break;");
546 ("else if ( yy_act & YY_TRAILING_MASK )");
550 ("YY_G(yy_looking_for_trail_begin) = yy_act & ~YY_TRAILING_MASK;");
552 ("YY_G(yy_looking_for_trail_begin) |= YY_TRAILING_HEAD_MASK;");
555 /* Remember matched text in case we back up
559 ("YY_G(yy_full_match) = yy_cp;");
561 ("YY_G(yy_full_state) = YY_G(yy_state_ptr);");
562 indent_puts ("YY_G(yy_full_lp) = YY_G(yy_lp);");
568 indent_puts ("else");
571 indent_puts ("YY_G(yy_full_match) = yy_cp;");
573 ("YY_G(yy_full_state) = YY_G(yy_state_ptr);");
574 indent_puts ("YY_G(yy_full_lp) = YY_G(yy_lp);");
575 indent_puts ("break;");
579 indent_puts ("++YY_G(yy_lp);");
580 indent_puts ("goto find_rule;");
584 /* Remember matched text in case we back up due to
585 * trailing context plus REJECT.
589 indent_puts ("YY_G(yy_full_match) = yy_cp;");
590 indent_puts ("break;");
598 indent_puts ("--yy_cp;");
600 /* We could consolidate the following two lines with those at
601 * the beginning, but at the cost of complaints that we're
602 * branching inside a loop.
604 indent_puts ("yy_current_state = *--YY_G(yy_state_ptr);");
605 indent_puts ("YY_G(yy_lp) = yy_accept[yy_current_state];");
612 else { /* compressed */
613 indent_puts ("yy_act = yy_accept[yy_current_state];");
615 if (interactive
&& !reject
) {
616 /* Do the guaranteed-needed backing up to figure out
619 indent_puts ("if ( yy_act == 0 )");
621 indent_puts ("{ /* have to back up */");
623 ("yy_cp = YY_G(yy_last_accepting_cpos);");
625 ("yy_current_state = YY_G(yy_last_accepting_state);");
627 ("yy_act = yy_accept[yy_current_state];");
634 /* mkftbl - make the full table and return the struct .
635 * you should call mkecstbl() after this.
638 struct yytbl_data
*mkftbl (void)
641 int end_of_buffer_action
= num_rules
+ 1;
642 struct yytbl_data
*tbl
;
643 flex_int32_t
*tdata
= 0;
645 tbl
= (struct yytbl_data
*) calloc (1, sizeof (struct yytbl_data
));
646 yytbl_data_init (tbl
, YYTD_ID_ACCEPT
);
647 tbl
->td_flags
|= YYTD_DATA32
;
648 tbl
->td_hilen
= 0; /* it's a one-dimensional array */
649 tbl
->td_lolen
= lastdfa
+ 1;
651 tbl
->td_data
= tdata
=
652 (flex_int32_t
*) calloc (tbl
->td_lolen
, sizeof (flex_int32_t
));
654 dfaacc
[end_of_buffer_state
].dfaacc_state
= end_of_buffer_action
;
656 for (i
= 1; i
<= lastdfa
; ++i
) {
657 register int anum
= dfaacc
[i
].dfaacc_state
;
662 fprintf (stderr
, _("state # %d accepts: [%d]\n"),
666 buf_prints (&yydmap_buf
,
667 "\t{YYTD_ID_ACCEPT, (void**)&yy_accept, sizeof(%s)},\n",
668 long_align
? "flex_int32_t" : "flex_int16_t");
673 /* genftbl - generate full transition table */
678 int end_of_buffer_action
= num_rules
+ 1;
680 out_str_dec (long_align
? get_int32_decl () : get_int16_decl (),
681 "yy_accept", lastdfa
+ 1);
683 dfaacc
[end_of_buffer_state
].dfaacc_state
= end_of_buffer_action
;
685 for (i
= 1; i
<= lastdfa
; ++i
) {
686 register int anum
= dfaacc
[i
].dfaacc_state
;
691 fprintf (stderr
, _("state # %d accepts: [%d]\n"),
700 /* Don't have to dump the actual full table entries - they were
701 * created on-the-fly.
706 /* Generate the code to find the next compressed-table state. */
708 void gen_next_compressed_state (char_map
)
711 indent_put2s ("register YY_CHAR yy_c = %s;", char_map
);
713 /* Save the backing-up info \before/ computing the next state
714 * because we always compute one more state than needed - we
715 * always proceed until we reach a jam state
720 ("while ( yy_chk[yy_base[yy_current_state] + yy_c] != yy_current_state )");
723 indent_puts ("yy_current_state = (int) yy_def[yy_current_state];");
726 /* We've arrange it so that templates are never chained
727 * to one another. This means we can afford to make a
728 * very simple test to see if we need to convert to
729 * yy_c's meta-equivalence class without worrying
730 * about erroneously looking up the meta-equivalence
735 /* lastdfa + 2 is the beginning of the templates */
736 out_dec ("if ( yy_current_state >= %d )\n", lastdfa
+ 2);
739 indent_puts ("yy_c = yy_meta[(unsigned int) yy_c];");
747 ("yy_current_state = yy_nxt[yy_base[yy_current_state] + (unsigned int) yy_c];");
751 /* Generate the code to find the next match. */
753 void gen_next_match ()
755 /* NOTE - changes in here should be reflected in gen_next_state() and
758 char *char_map
= useecs
?
759 "yy_ec[YY_SC_TO_UI(*yy_cp)] " : "YY_SC_TO_UI(*yy_cp)";
761 char *char_map_2
= useecs
?
762 "yy_ec[YY_SC_TO_UI(*++yy_cp)] " : "YY_SC_TO_UI(*++yy_cp)";
767 ("while ( (yy_current_state = yy_nxt[yy_current_state][ %s ]) > 0 )",
771 ("while ( (yy_current_state = yy_nxt[yy_current_state*YY_NXT_LOLEN + %s ]) > 0 )",
776 if (num_backing_up
> 0) {
782 indent_puts ("++yy_cp;");
784 if (num_backing_up
> 0)
791 indent_puts ("yy_current_state = -yy_current_state;");
797 ("register yyconst struct yy_trans_info *yy_trans_info;\n");
798 indent_puts ("register YY_CHAR yy_c;\n");
799 indent_put2s ("for ( yy_c = %s;", char_map
);
801 (" (yy_trans_info = &yy_current_state[(unsigned int) yy_c])->");
802 indent_puts ("yy_verify == yy_c;");
803 indent_put2s (" yy_c = %s )", char_map_2
);
807 if (num_backing_up
> 0)
810 indent_puts ("yy_current_state += yy_trans_info->yy_nxt;");
812 if (num_backing_up
> 0) {
822 else { /* compressed */
828 gen_next_state (false);
830 indent_puts ("++yy_cp;");
839 out_dec ("while ( yy_base[yy_current_state] != %d );\n", jambase
);
841 out_dec ("while ( yy_current_state != %d );\n",
844 if (!reject
&& !interactive
) {
845 /* Do the guaranteed-needed backing up to figure out
849 ("yy_cp = YY_G(yy_last_accepting_cpos);");
851 ("yy_current_state = YY_G(yy_last_accepting_state);");
857 /* Generate the code to find the next state. */
859 void gen_next_state (worry_about_NULs
)
860 int worry_about_NULs
;
861 { /* NOTE - changes in here should be reflected in gen_next_match() */
864 if (worry_about_NULs
&& !nultrans
) {
866 snprintf (char_map
, sizeof(char_map
),
867 "(*yy_cp ? yy_ec[YY_SC_TO_UI(*yy_cp)] : %d)",
870 snprintf (char_map
, sizeof(char_map
),
871 "(*yy_cp ? YY_SC_TO_UI(*yy_cp) : %d)",
876 strcpy (char_map
, useecs
?
877 "yy_ec[YY_SC_TO_UI(*yy_cp)]" :
878 "YY_SC_TO_UI(*yy_cp)");
880 if (worry_about_NULs
&& nultrans
) {
881 if (!fulltbl
&& !fullspd
)
882 /* Compressed tables back up *before* they match. */
885 indent_puts ("if ( *yy_cp )");
893 ("yy_current_state = yy_nxt[yy_current_state][%s];",
897 ("yy_current_state = yy_nxt[yy_current_state*YY_NXT_LOLEN + %s];",
903 ("yy_current_state += yy_current_state[%s].yy_nxt;",
907 gen_next_compressed_state (char_map
);
909 if (worry_about_NULs
&& nultrans
) {
913 indent_puts ("else");
916 ("yy_current_state = yy_NUL_trans[yy_current_state];");
920 if (fullspd
|| fulltbl
)
924 indent_puts ("*YY_G(yy_state_ptr)++ = yy_current_state;");
928 /* Generate the code to make a NUL transition. */
930 void gen_NUL_trans ()
931 { /* NOTE - changes in here should be reflected in gen_next_match() */
932 /* Only generate a definition for "yy_cp" if we'll generate code
933 * that uses it. Otherwise lint and the like complain.
935 int need_backing_up
= (num_backing_up
> 0 && !reject
);
937 if (need_backing_up
&& (!nultrans
|| fullspd
|| fulltbl
))
938 /* We're going to need yy_cp lying around for the call
939 * below to gen_backing_up().
941 indent_puts ("register char *yy_cp = YY_G(yy_c_buf_p);");
947 ("yy_current_state = yy_NUL_trans[yy_current_state];");
948 indent_puts ("yy_is_jam = (yy_current_state == 0);");
954 out_dec ("yy_current_state = yy_nxt[yy_current_state][%d];\n", NUL_ec
);
956 out_dec ("yy_current_state = yy_nxt[yy_current_state*YY_NXT_LOLEN + %d];\n", NUL_ec
);
957 indent_puts ("yy_is_jam = (yy_current_state <= 0);");
962 out_dec ("register int yy_c = %d;\n", NUL_ec
);
965 ("register yyconst struct yy_trans_info *yy_trans_info;\n");
967 ("yy_trans_info = &yy_current_state[(unsigned int) yy_c];");
968 indent_puts ("yy_current_state += yy_trans_info->yy_nxt;");
971 ("yy_is_jam = (yy_trans_info->yy_verify != yy_c);");
977 snprintf (NUL_ec_str
, sizeof(NUL_ec_str
), "%d", NUL_ec
);
978 gen_next_compressed_state (NUL_ec_str
);
981 out_dec ("yy_is_jam = (yy_current_state == %d);\n",
985 /* Only stack this state if it's a transition we
986 * actually make. If we stack it on a jam, then
987 * the state stack and yy_c_buf_p get out of sync.
989 indent_puts ("if ( ! yy_is_jam )");
992 ("*YY_G(yy_state_ptr)++ = yy_current_state;");
997 /* If we've entered an accepting state, back up; note that
998 * compressed tables have *already* done such backing up, so
999 * we needn't bother with it again.
1001 if (need_backing_up
&& (fullspd
|| fulltbl
)) {
1003 indent_puts ("if ( ! yy_is_jam )");
1013 /* Generate the code to find the start state. */
1015 void gen_start_state ()
1020 ("yy_current_state = yy_start_state_list[YY_G(yy_start) + YY_AT_BOL()];");
1024 ("yy_current_state = yy_start_state_list[YY_G(yy_start)];");
1028 indent_puts ("yy_current_state = YY_G(yy_start);");
1031 indent_puts ("yy_current_state += YY_AT_BOL();");
1034 /* Set up for storing up states. */
1035 outn ("m4_ifdef( [[M4_YY_USES_REJECT]],\n[[");
1037 ("YY_G(yy_state_ptr) = YY_G(yy_state_buf);");
1039 ("*YY_G(yy_state_ptr)++ = yy_current_state;");
1046 /* gentabs - generate data statements for the transition tables */
1050 int i
, j
, k
, *accset
, nacc
, *acc_array
, total_states
;
1051 int end_of_buffer_action
= num_rules
+ 1;
1052 struct yytbl_data
*yyacc_tbl
= 0, *yymeta_tbl
= 0, *yybase_tbl
= 0,
1053 *yydef_tbl
= 0, *yynxt_tbl
= 0, *yychk_tbl
= 0, *yyacclist_tbl
=0;
1054 flex_int32_t
*yyacc_data
= 0, *yybase_data
= 0, *yydef_data
= 0,
1055 *yynxt_data
= 0, *yychk_data
= 0, *yyacclist_data
=0;
1056 flex_int32_t yybase_curr
= 0, yyacclist_curr
=0,yyacc_curr
=0;
1058 acc_array
= allocate_integer_array (current_max_dfas
);
1061 /* The compressed table format jams by entering the "jam state",
1062 * losing information about the previous state in the process.
1063 * In order to recover the previous state, we effectively need
1064 * to keep backing-up information.
1069 /* Write out accepting list and pointer list.
1071 * First we generate the "yy_acclist" array. In the process,
1072 * we compute the indices that will go into the "yy_accept"
1073 * array, and save the indices in the dfaacc array.
1075 int EOB_accepting_list
[2];
1077 /* Set up accepting structures for the End Of Buffer state. */
1078 EOB_accepting_list
[0] = 0;
1079 EOB_accepting_list
[1] = end_of_buffer_action
;
1080 accsiz
[end_of_buffer_state
] = 1;
1081 dfaacc
[end_of_buffer_state
].dfaacc_set
=
1084 out_str_dec (long_align
? get_int32_decl () :
1085 get_int16_decl (), "yy_acclist", MAX (numas
,
1088 buf_prints (&yydmap_buf
,
1089 "\t{YYTD_ID_ACCLIST, (void**)&yy_acclist, sizeof(%s)},\n",
1090 long_align
? "flex_int32_t" : "flex_int16_t");
1092 yyacclist_tbl
= (struct yytbl_data
*)calloc(1,sizeof(struct yytbl_data
));
1093 yytbl_data_init (yyacclist_tbl
, YYTD_ID_ACCLIST
);
1094 yyacclist_tbl
->td_lolen
= MAX(numas
,1) + 1;
1095 yyacclist_tbl
->td_data
= yyacclist_data
=
1096 (flex_int32_t
*) calloc (yyacclist_tbl
->td_lolen
, sizeof (flex_int32_t
));
1099 j
= 1; /* index into "yy_acclist" array */
1101 for (i
= 1; i
<= lastdfa
; ++i
) {
1104 if (accsiz
[i
] != 0) {
1105 accset
= dfaacc
[i
].dfaacc_set
;
1110 _("state # %d accepts: "),
1113 for (k
= 1; k
<= nacc
; ++k
) {
1114 int accnum
= accset
[k
];
1118 if (variable_trailing_context_rules
1120 YY_TRAILING_HEAD_MASK
)
1122 && accnum
<= num_rules
1123 && rule_type
[accnum
] ==
1125 /* Special hack to flag
1126 * accepting number as part
1127 * of trailing context rule.
1129 accnum
|= YY_TRAILING_MASK
;
1133 yyacclist_data
[yyacclist_curr
++] = accnum
;
1136 fprintf (stderr
, "[%d]",
1150 /* add accepting number for the "jam" state */
1155 yytbl_data_compress (yyacclist_tbl
);
1156 if (yytbl_data_fwrite (&tableswr
, yyacclist_tbl
) < 0)
1157 flexerror (_("Could not write yyacclist_tbl"));
1158 yytbl_data_destroy (yyacclist_tbl
);
1159 yyacclist_tbl
= NULL
;
1164 dfaacc
[end_of_buffer_state
].dfaacc_state
=
1165 end_of_buffer_action
;
1167 for (i
= 1; i
<= lastdfa
; ++i
)
1168 acc_array
[i
] = dfaacc
[i
].dfaacc_state
;
1170 /* add accepting number for jam state */
1174 /* Begin generating yy_accept */
1176 /* Spit out "yy_accept" array. If we're doing "reject", it'll be
1177 * pointers into the "yy_acclist" array. Otherwise it's actual
1178 * accepting numbers. In either case, we just dump the numbers.
1181 /* "lastdfa + 2" is the size of "yy_accept"; includes room for C arrays
1182 * beginning at 0 and for "jam" state.
1187 /* We put a "cap" on the table associating lists of accepting
1188 * numbers with state numbers. This is needed because we tell
1189 * where the end of an accepting list is by looking at where
1190 * the list for the next state starts.
1194 out_str_dec (long_align
? get_int32_decl () : get_int16_decl (),
1197 buf_prints (&yydmap_buf
,
1198 "\t{YYTD_ID_ACCEPT, (void**)&yy_accept, sizeof(%s)},\n",
1199 long_align
? "flex_int32_t" : "flex_int16_t");
1202 (struct yytbl_data
*) calloc (1,
1203 sizeof (struct yytbl_data
));
1204 yytbl_data_init (yyacc_tbl
, YYTD_ID_ACCEPT
);
1205 yyacc_tbl
->td_lolen
= k
;
1206 yyacc_tbl
->td_data
= yyacc_data
=
1207 (flex_int32_t
*) calloc (yyacc_tbl
->td_lolen
, sizeof (flex_int32_t
));
1210 for (i
= 1; i
<= lastdfa
; ++i
) {
1211 mkdata (acc_array
[i
]);
1212 yyacc_data
[yyacc_curr
++] = acc_array
[i
];
1214 if (!reject
&& trace
&& acc_array
[i
])
1215 fprintf (stderr
, _("state # %d accepts: [%d]\n"),
1219 /* Add entry for "jam" state. */
1220 mkdata (acc_array
[i
]);
1221 yyacc_data
[yyacc_curr
++] = acc_array
[i
];
1224 /* Add "cap" for the list. */
1225 mkdata (acc_array
[i
]);
1226 yyacc_data
[yyacc_curr
++] = acc_array
[i
];
1231 yytbl_data_compress (yyacc_tbl
);
1232 if (yytbl_data_fwrite (&tableswr
, yyacc_tbl
) < 0)
1233 flexerror (_("Could not write yyacc_tbl"));
1234 yytbl_data_destroy (yyacc_tbl
);
1237 /* End generating yy_accept */
1243 struct yytbl_data
*tbl
;
1246 yytbl_data_compress (tbl
);
1247 if (yytbl_data_fwrite (&tableswr
, tbl
) < 0)
1248 flexerror (_("Could not write ecstbl"));
1249 yytbl_data_destroy (tbl
);
1255 /* Begin generating yy_meta */
1256 /* Write out meta-equivalence classes (used to index
1259 flex_int32_t
*yymecs_data
= 0;
1261 (struct yytbl_data
*) calloc (1,
1264 yytbl_data_init (yymeta_tbl
, YYTD_ID_META
);
1265 yymeta_tbl
->td_lolen
= numecs
+ 1;
1266 yymeta_tbl
->td_data
= yymecs_data
=
1267 (flex_int32_t
*) calloc (yymeta_tbl
->td_lolen
,
1268 sizeof (flex_int32_t
));
1271 fputs (_("\n\nMeta-Equivalence Classes:\n"),
1274 out_str_dec (get_int32_decl (), "yy_meta", numecs
+ 1);
1275 buf_prints (&yydmap_buf
,
1276 "\t{YYTD_ID_META, (void**)&yy_meta, sizeof(%s)},\n",
1279 for (i
= 1; i
<= numecs
; ++i
) {
1281 fprintf (stderr
, "%d = %d\n",
1282 i
, ABS (tecbck
[i
]));
1284 mkdata (ABS (tecbck
[i
]));
1285 yymecs_data
[i
] = ABS (tecbck
[i
]);
1290 yytbl_data_compress (yymeta_tbl
);
1291 if (yytbl_data_fwrite (&tableswr
, yymeta_tbl
) < 0)
1293 ("Could not write yymeta_tbl"));
1294 yytbl_data_destroy (yymeta_tbl
);
1297 /* End generating yy_meta */
1300 total_states
= lastdfa
+ numtemps
;
1302 /* Begin generating yy_base */
1303 out_str_dec ((tblend
>= INT16_MAX
|| long_align
) ?
1304 get_int32_decl () : get_int16_decl (),
1305 "yy_base", total_states
+ 1);
1307 buf_prints (&yydmap_buf
,
1308 "\t{YYTD_ID_BASE, (void**)&yy_base, sizeof(%s)},\n",
1309 (tblend
>= INT16_MAX
1310 || long_align
) ? "flex_int32_t" : "flex_int16_t");
1312 (struct yytbl_data
*) calloc (1,
1313 sizeof (struct yytbl_data
));
1314 yytbl_data_init (yybase_tbl
, YYTD_ID_BASE
);
1315 yybase_tbl
->td_lolen
= total_states
+ 1;
1316 yybase_tbl
->td_data
= yybase_data
=
1317 (flex_int32_t
*) calloc (yybase_tbl
->td_lolen
,
1318 sizeof (flex_int32_t
));
1321 for (i
= 1; i
<= lastdfa
; ++i
) {
1322 register int d
= def
[i
];
1324 if (base
[i
] == JAMSTATE
)
1331 /* Template reference. */
1333 def
[i
] = lastdfa
- d
+ 1;
1337 yybase_data
[yybase_curr
++] = base
[i
];
1340 /* Generate jam state's base index. */
1342 yybase_data
[yybase_curr
++] = base
[i
];
1344 for (++i
/* skip jam state */ ; i
<= total_states
; ++i
) {
1346 yybase_data
[yybase_curr
++] = base
[i
];
1352 yytbl_data_compress (yybase_tbl
);
1353 if (yytbl_data_fwrite (&tableswr
, yybase_tbl
) < 0)
1354 flexerror (_("Could not write yybase_tbl"));
1355 yytbl_data_destroy (yybase_tbl
);
1358 /* End generating yy_base */
1361 /* Begin generating yy_def */
1362 out_str_dec ((total_states
>= INT16_MAX
|| long_align
) ?
1363 get_int32_decl () : get_int16_decl (),
1364 "yy_def", total_states
+ 1);
1366 buf_prints (&yydmap_buf
,
1367 "\t{YYTD_ID_DEF, (void**)&yy_def, sizeof(%s)},\n",
1368 (total_states
>= INT16_MAX
1369 || long_align
) ? "flex_int32_t" : "flex_int16_t");
1372 (struct yytbl_data
*) calloc (1,
1373 sizeof (struct yytbl_data
));
1374 yytbl_data_init (yydef_tbl
, YYTD_ID_DEF
);
1375 yydef_tbl
->td_lolen
= total_states
+ 1;
1376 yydef_tbl
->td_data
= yydef_data
=
1377 (flex_int32_t
*) calloc (yydef_tbl
->td_lolen
, sizeof (flex_int32_t
));
1379 for (i
= 1; i
<= total_states
; ++i
) {
1381 yydef_data
[i
] = def
[i
];
1386 yytbl_data_compress (yydef_tbl
);
1387 if (yytbl_data_fwrite (&tableswr
, yydef_tbl
) < 0)
1388 flexerror (_("Could not write yydef_tbl"));
1389 yytbl_data_destroy (yydef_tbl
);
1392 /* End generating yy_def */
1395 /* Begin generating yy_nxt */
1396 out_str_dec ((total_states
>= INT16_MAX
|| long_align
) ?
1397 get_int32_decl () : get_int16_decl (), "yy_nxt",
1400 buf_prints (&yydmap_buf
,
1401 "\t{YYTD_ID_NXT, (void**)&yy_nxt, sizeof(%s)},\n",
1402 (total_states
>= INT16_MAX
1403 || long_align
) ? "flex_int32_t" : "flex_int16_t");
1406 (struct yytbl_data
*) calloc (1,
1407 sizeof (struct yytbl_data
));
1408 yytbl_data_init (yynxt_tbl
, YYTD_ID_NXT
);
1409 yynxt_tbl
->td_lolen
= tblend
+ 1;
1410 yynxt_tbl
->td_data
= yynxt_data
=
1411 (flex_int32_t
*) calloc (yynxt_tbl
->td_lolen
, sizeof (flex_int32_t
));
1413 for (i
= 1; i
<= tblend
; ++i
) {
1414 /* Note, the order of the following test is important.
1415 * If chk[i] is 0, then nxt[i] is undefined.
1417 if (chk
[i
] == 0 || nxt
[i
] == 0)
1418 nxt
[i
] = jamstate
; /* new state is the JAM state */
1421 yynxt_data
[i
] = nxt
[i
];
1426 yytbl_data_compress (yynxt_tbl
);
1427 if (yytbl_data_fwrite (&tableswr
, yynxt_tbl
) < 0)
1428 flexerror (_("Could not write yynxt_tbl"));
1429 yytbl_data_destroy (yynxt_tbl
);
1432 /* End generating yy_nxt */
1434 /* Begin generating yy_chk */
1435 out_str_dec ((total_states
>= INT16_MAX
|| long_align
) ?
1436 get_int32_decl () : get_int16_decl (), "yy_chk",
1439 buf_prints (&yydmap_buf
,
1440 "\t{YYTD_ID_CHK, (void**)&yy_chk, sizeof(%s)},\n",
1441 (total_states
>= INT16_MAX
1442 || long_align
) ? "flex_int32_t" : "flex_int16_t");
1445 (struct yytbl_data
*) calloc (1,
1446 sizeof (struct yytbl_data
));
1447 yytbl_data_init (yychk_tbl
, YYTD_ID_CHK
);
1448 yychk_tbl
->td_lolen
= tblend
+ 1;
1449 yychk_tbl
->td_data
= yychk_data
=
1450 (flex_int32_t
*) calloc (yychk_tbl
->td_lolen
, sizeof (flex_int32_t
));
1452 for (i
= 1; i
<= tblend
; ++i
) {
1457 yychk_data
[i
] = chk
[i
];
1462 yytbl_data_compress (yychk_tbl
);
1463 if (yytbl_data_fwrite (&tableswr
, yychk_tbl
) < 0)
1464 flexerror (_("Could not write yychk_tbl"));
1465 yytbl_data_destroy (yychk_tbl
);
1468 /* End generating yy_chk */
1470 flex_free ((void *) acc_array
);
1474 /* Write out a formatted string (with a secondary string argument) at the
1475 * current indentation level, adding a final newline.
1478 void indent_put2s (fmt
, arg
)
1479 const char *fmt
, *arg
;
1487 /* Write out a string at the current indentation level, adding a final
1491 void indent_puts (str
)
1499 /* make_tables - generate transition tables and finishes generating output file
1505 int did_eof_rule
= false;
1506 struct yytbl_data
*yynultrans_tbl
;
1509 skelout (); /* %% [2.0] - break point in skel */
1511 /* First, take care of YY_DO_BEFORE_ACTION depending on yymore
1516 if (yymore_used
&& !yytext_is_array
) {
1517 indent_puts ("YY_G(yytext_ptr) -= YY_G(yy_more_len); \\");
1519 ("yyleng = (size_t) (yy_cp - YY_G(yytext_ptr)); \\");
1523 indent_puts ("yyleng = (size_t) (yy_cp - yy_bp); \\");
1525 /* Now also deal with copying yytext_ptr to yytext if needed. */
1526 skelout (); /* %% [3.0] - break point in skel */
1527 if (yytext_is_array
) {
1530 ("if ( yyleng + YY_G(yy_more_offset) >= YYLMAX ) \\");
1532 indent_puts ("if ( yyleng >= YYLMAX ) \\");
1536 ("YY_FATAL_ERROR( \"token too large, exceeds YYLMAX\" ); \\");
1541 ("yy_flex_strncpy( &yytext[YY_G(yy_more_offset)], YY_G(yytext_ptr), yyleng + 1 M4_YY_CALL_LAST_ARG); \\");
1542 indent_puts ("yyleng += YY_G(yy_more_offset); \\");
1544 ("YY_G(yy_prev_more_offset) = YY_G(yy_more_offset); \\");
1545 indent_puts ("YY_G(yy_more_offset) = 0; \\");
1549 ("yy_flex_strncpy( yytext, YY_G(yytext_ptr), yyleng + 1 M4_YY_CALL_LAST_ARG); \\");
1555 skelout (); /* %% [4.0] - break point in skel */
1558 /* This is where we REALLY begin generating the tables. */
1560 out_dec ("#define YY_NUM_RULES %d\n", num_rules
);
1561 out_dec ("#define YY_END_OF_BUFFER %d\n", num_rules
+ 1);
1564 /* Need to define the transet type as a size large
1565 * enough to hold the biggest offset.
1567 int total_table_size
= tblend
+ numecs
+ 1;
1568 char *trans_offset_type
=
1569 (total_table_size
>= INT16_MAX
|| long_align
) ?
1570 "flex_int32_t" : "flex_int16_t";
1573 indent_puts ("struct yy_trans_info");
1577 /* We require that yy_verify and yy_nxt must be of the same size int. */
1578 indent_put2s ("%s yy_verify;", trans_offset_type
);
1580 /* In cases where its sister yy_verify *is* a "yes, there is
1581 * a transition", yy_nxt is the offset (in records) to the
1582 * next state. In most cases where there is no transition,
1583 * the value of yy_nxt is irrelevant. If yy_nxt is the -1th
1584 * record of a state, though, then yy_nxt is the action number
1588 indent_put2s ("%s yy_nxt;", trans_offset_type
);
1593 /* We generate a bogus 'struct yy_trans_info' data type
1594 * so we can guarantee that it is always declared in the skel.
1595 * This is so we can compile "sizeof(struct yy_trans_info)"
1599 ("/* This struct is not used in this scanner,");
1600 indent_puts (" but its presence is necessary. */");
1601 indent_puts ("struct yy_trans_info");
1604 indent_puts ("flex_int32_t yy_verify;");
1605 indent_puts ("flex_int32_t yy_nxt;");
1613 struct yytbl_data
*tbl
;
1616 yytbl_data_compress (tbl
);
1617 if (yytbl_data_fwrite (&tableswr
, tbl
) < 0)
1618 flexerror (_("Could not write ftbl"));
1619 yytbl_data_destroy (tbl
);
1622 yytbl_data_compress (tbl
);
1623 if (yytbl_data_fwrite (&tableswr
, tbl
) < 0)
1624 flexerror (_("Could not write ssltbl"));
1625 yytbl_data_destroy (tbl
);
1630 yytbl_data_compress (tbl
);
1631 if (yytbl_data_fwrite (&tableswr
, tbl
) < 0)
1633 ("Could not write ecstbl"));
1634 yytbl_data_destroy (tbl
);
1642 struct yytbl_data
*tbl
;
1645 yytbl_data_compress (tbl
);
1646 if (yytbl_data_fwrite (&tableswr
, tbl
) < 0)
1647 flexerror (_("Could not write ftbl"));
1648 yytbl_data_destroy (tbl
);
1653 yytbl_data_compress (tbl
);
1654 if (yytbl_data_fwrite (&tableswr
, tbl
) < 0)
1656 ("Could not write ecstbl"));
1657 yytbl_data_destroy (tbl
);
1670 struct yytbl_data
*tbl
;
1673 yytbl_data_compress (tbl
);
1674 if (yytbl_data_fwrite (&tableswr
, tbl
) < 0)
1675 flexerror (_("Could not write eoltbl"));
1676 yytbl_data_destroy (tbl
);
1681 /* Definitions for backing up. We don't need them if REJECT
1682 * is being used because then we use an alternative backin-up
1683 * technique instead.
1685 if (num_backing_up
> 0 && !reject
) {
1686 if (!C_plus_plus
&& !reentrant
) {
1688 ("static yy_state_type yy_last_accepting_state;");
1690 ("static char *yy_last_accepting_cpos;\n");
1695 flex_int32_t
*yynultrans_data
= 0;
1697 /* Begin generating yy_NUL_trans */
1698 out_str_dec (get_state_decl (), "yy_NUL_trans",
1700 buf_prints (&yydmap_buf
,
1701 "\t{YYTD_ID_NUL_TRANS, (void**)&yy_NUL_trans, sizeof(%s)},\n",
1702 (fullspd
) ? "struct yy_trans_info*" :
1706 (struct yytbl_data
*) calloc (1,
1709 yytbl_data_init (yynultrans_tbl
, YYTD_ID_NUL_TRANS
);
1711 yynultrans_tbl
->td_flags
|= YYTD_PTRANS
;
1712 yynultrans_tbl
->td_lolen
= lastdfa
+ 1;
1713 yynultrans_tbl
->td_data
= yynultrans_data
=
1714 (flex_int32_t
*) calloc (yynultrans_tbl
->td_lolen
,
1715 sizeof (flex_int32_t
));
1717 for (i
= 1; i
<= lastdfa
; ++i
) {
1719 out_dec (" &yy_transition[%d],\n",
1721 yynultrans_data
[i
] = base
[i
];
1724 mkdata (nultrans
[i
]);
1725 yynultrans_data
[i
] = nultrans
[i
];
1731 yytbl_data_compress (yynultrans_tbl
);
1732 if (yytbl_data_fwrite (&tableswr
, yynultrans_tbl
) <
1735 ("Could not write yynultrans_tbl"));
1736 yytbl_data_destroy (yynultrans_tbl
);
1737 yynultrans_tbl
= NULL
;
1739 /* End generating yy_NUL_trans */
1742 if (!C_plus_plus
&& !reentrant
) {
1743 indent_puts ("extern int yy_flex_debug;");
1744 indent_put2s ("int yy_flex_debug = %s;\n",
1745 ddebug
? "1" : "0");
1748 if (ddebug
) { /* Spit out table mapping rules to line numbers. */
1749 out_str_dec (long_align
? get_int32_decl () :
1750 get_int16_decl (), "yy_rule_linenum",
1752 for (i
= 1; i
< num_rules
; ++i
)
1753 mkdata (rule_linenum
[i
]);
1758 outn ("m4_ifdef( [[M4_YY_USES_REJECT]],\n[[");
1759 /* Declare state buffer variables. */
1760 if (!C_plus_plus
&& !reentrant
) {
1761 outn ("static yy_state_type *yy_state_buf=0, *yy_state_ptr=0;");
1762 outn ("static char *yy_full_match;");
1763 outn ("static int yy_lp;");
1766 if (variable_trailing_context_rules
) {
1767 if (!C_plus_plus
&& !reentrant
) {
1768 outn ("static int yy_looking_for_trail_begin = 0;");
1769 outn ("static int yy_full_lp;");
1770 outn ("static int *yy_full_state;");
1773 out_hex ("#define YY_TRAILING_MASK 0x%x\n",
1774 (unsigned int) YY_TRAILING_MASK
);
1775 out_hex ("#define YY_TRAILING_HEAD_MASK 0x%x\n",
1776 (unsigned int) YY_TRAILING_HEAD_MASK
);
1779 outn ("#define REJECT \\");
1781 outn ("*yy_cp = YY_G(yy_hold_char); /* undo effects of setting up yytext */ \\");
1782 outn ("yy_cp = YY_G(yy_full_match); /* restore poss. backed-over text */ \\");
1784 if (variable_trailing_context_rules
) {
1785 outn ("YY_G(yy_lp) = YY_G(yy_full_lp); /* restore orig. accepting pos. */ \\");
1786 outn ("YY_G(yy_state_ptr) = YY_G(yy_full_state); /* restore orig. state */ \\");
1787 outn ("yy_current_state = *YY_G(yy_state_ptr); /* restore curr. state */ \\");
1790 outn ("++YY_G(yy_lp); \\");
1791 outn ("goto find_rule; \\");
1798 outn ("/* The intent behind this definition is that it'll catch");
1799 outn (" * any uses of REJECT which flex missed.");
1801 outn ("#define REJECT reject_used_but_not_detected");
1806 if (yytext_is_array
) {
1808 indent_puts ("static int yy_more_offset = 0;");
1809 indent_puts ("static int yy_prev_more_offset = 0;");
1812 else if (!reentrant
) {
1814 ("static int yy_more_flag = 0;");
1816 ("static int yy_more_len = 0;");
1820 if (yytext_is_array
) {
1822 ("#define yymore() (YY_G(yy_more_offset) = yy_flex_strlen( yytext M4_YY_CALL_LAST_ARG))");
1823 indent_puts ("#define YY_NEED_STRLEN");
1824 indent_puts ("#define YY_MORE_ADJ 0");
1826 ("#define YY_RESTORE_YY_MORE_OFFSET \\");
1828 indent_puts ("{ \\");
1830 ("YY_G(yy_more_offset) = YY_G(yy_prev_more_offset); \\");
1831 indent_puts ("yyleng -= YY_G(yy_more_offset); \\");
1837 ("#define yymore() (YY_G(yy_more_flag) = 1)");
1839 ("#define YY_MORE_ADJ YY_G(yy_more_len)");
1840 indent_puts ("#define YY_RESTORE_YY_MORE_OFFSET");
1846 ("#define yymore() yymore_used_but_not_detected");
1847 indent_puts ("#define YY_MORE_ADJ 0");
1848 indent_puts ("#define YY_RESTORE_YY_MORE_OFFSET");
1852 if (yytext_is_array
) {
1853 outn ("#ifndef YYLMAX");
1854 outn ("#define YYLMAX 8192");
1857 outn ("char yytext[YYLMAX];");
1858 outn ("char *yytext_ptr;");
1864 outn ("char *yytext;");
1868 out (&action_array
[defs1_offset
]);
1870 line_directive_out (stdout
, 0);
1872 skelout (); /* %% [5.0] - break point in skel */
1876 outn ("\terrno=0; \\");
1877 outn ("\twhile ( (result = read( fileno(yyin), (char *) buf, max_size )) < 0 ) \\");
1879 outn ("\t\tif( errno != EINTR) \\");
1881 outn ("\t\t\tYY_FATAL_ERROR( \"input in flex scanner failed\" ); \\");
1882 outn ("\t\t\tbreak; \\");
1884 outn ("\t\terrno=0; \\");
1885 outn ("\t\tclearerr(yyin); \\");
1890 outn ("\tif ( YY_CURRENT_BUFFER_LVALUE->yy_is_interactive ) \\");
1892 outn ("\t\tint c = '*'; \\");
1893 outn ("\t\tsize_t n; \\");
1894 outn ("\t\tfor ( n = 0; n < max_size && \\");
1895 outn ("\t\t\t (c = getc( yyin )) != EOF && c != '\\n'; ++n ) \\");
1896 outn ("\t\t\tbuf[n] = (char) c; \\");
1897 outn ("\t\tif ( c == '\\n' ) \\");
1898 outn ("\t\t\tbuf[n++] = (char) c; \\");
1899 outn ("\t\tif ( c == EOF && ferror( yyin ) ) \\");
1900 outn ("\t\t\tYY_FATAL_ERROR( \"input in flex scanner failed\" ); \\");
1901 outn ("\t\tresult = n; \\");
1905 outn ("\t\terrno=0; \\");
1906 outn ("\t\twhile ( (result = fread(buf, 1, max_size, yyin))==0 && ferror(yyin)) \\");
1907 outn ("\t\t\t{ \\");
1908 outn ("\t\t\tif( errno != EINTR) \\");
1909 outn ("\t\t\t\t{ \\");
1910 outn ("\t\t\t\tYY_FATAL_ERROR( \"input in flex scanner failed\" ); \\");
1911 outn ("\t\t\t\tbreak; \\");
1912 outn ("\t\t\t\t} \\");
1913 outn ("\t\t\terrno=0; \\");
1914 outn ("\t\t\tclearerr(yyin); \\");
1915 outn ("\t\t\t} \\");
1920 skelout (); /* %% [6.0] - break point in skel */
1922 indent_puts ("#define YY_RULE_SETUP \\");
1925 indent_puts ("if ( yyleng > 0 ) \\");
1927 indent_puts ("YY_CURRENT_BUFFER_LVALUE->yy_at_bol = \\");
1928 indent_puts ("\t\t(yytext[yyleng - 1] == '\\n'); \\");
1931 indent_puts ("YY_USER_ACTION");
1934 skelout (); /* %% [7.0] - break point in skel */
1936 /* Copy prolog to output file. */
1937 out (&action_array
[prolog_offset
]);
1939 line_directive_out (stdout
, 0);
1941 skelout (); /* %% [8.0] - break point in skel */
1945 if (yymore_used
&& !yytext_is_array
) {
1946 indent_puts ("YY_G(yy_more_len) = 0;");
1947 indent_puts ("if ( YY_G(yy_more_flag) )");
1951 ("YY_G(yy_more_len) = YY_G(yy_c_buf_p) - YY_G(yytext_ptr);");
1952 indent_puts ("YY_G(yy_more_flag) = 0;");
1957 skelout (); /* %% [9.0] - break point in skel */
1961 /* Note, don't use any indentation. */
1965 skelout (); /* %% [10.0] - break point in skel */
1969 skelout (); /* %% [11.0] - break point in skel */
1970 outn ("m4_ifdef( [[M4_YY_USE_LINENO]],[[");
1972 ("if ( yy_act != YY_END_OF_BUFFER && yy_rule_can_match_eol[yy_act] )");
1975 indent_puts ("yy_size_t yyl;");
1977 out_str ("for ( yyl = %s; yyl < yyleng; ++yyl )\n",
1978 yymore_used
? (yytext_is_array
? "YY_G(yy_prev_more_offset)" :
1979 "YY_G(yy_more_len)") : "0");
1981 indent_puts ("if ( yytext[yyl] == '\\n' )");
1983 indent_puts ("M4_YY_INCR_LINENO();");
1990 skelout (); /* %% [12.0] - break point in skel */
1992 indent_puts ("if ( yy_flex_debug )");
1996 indent_puts ("if ( yy_act == 0 )");
1998 indent_puts (C_plus_plus
?
1999 "std::cerr << \"--scanner backing up\\n\";" :
2000 "fprintf( stderr, \"--scanner backing up\\n\" );");
2004 out_dec ("else if ( yy_act < %d )\n", num_rules
);
2009 ("std::cerr << \"--accepting rule at line \" << yy_rule_linenum[yy_act] <<");
2011 (" \"(\\\"\" << yytext << \"\\\")\\n\";");
2015 ("fprintf( stderr, \"--accepting rule at line %ld (\\\"%s\\\")\\n\",");
2018 (" (long)yy_rule_linenum[yy_act], yytext );");
2024 out_dec ("else if ( yy_act == %d )\n", num_rules
);
2029 ("std::cerr << \"--accepting default rule (\\\"\" << yytext << \"\\\")\\n\";");
2033 ("fprintf( stderr, \"--accepting default rule (\\\"%s\\\")\\n\",");
2034 indent_puts (" yytext );");
2040 out_dec ("else if ( yy_act == %d )\n", num_rules
+ 1);
2043 indent_puts (C_plus_plus
?
2044 "std::cerr << \"--(end of buffer or a NUL)\\n\";" :
2045 "fprintf( stderr, \"--(end of buffer or a NUL)\\n\" );");
2055 ("std::cerr << \"--EOF (start condition \" << YY_START << \")\\n\";");
2059 ("fprintf( stderr, \"--EOF (start condition %d)\\n\", YY_START );");
2068 /* Copy actions to output file. */
2069 skelout (); /* %% [13.0] - break point in skel */
2072 out (&action_array
[action_offset
]);
2074 line_directive_out (stdout
, 0);
2076 /* generate cases for any missing EOF rules */
2077 for (i
= 1; i
<= lastsc
; ++i
)
2080 out_str ("case YY_STATE_EOF(%s):\n", scname
[i
]);
2081 did_eof_rule
= true;
2086 indent_puts ("yyterminate();");
2091 /* Generate code for handling NUL's, if needed. */
2093 /* First, deal with backing up and setting up yy_cp if the scanner
2094 * finds that it should JAM on the NUL.
2096 skelout (); /* %% [14.0] - break point in skel */
2099 if (fullspd
|| fulltbl
)
2100 indent_puts ("yy_cp = YY_G(yy_c_buf_p);");
2102 else { /* compressed table */
2103 if (!reject
&& !interactive
) {
2104 /* Do the guaranteed-needed backing up to figure
2108 ("yy_cp = YY_G(yy_last_accepting_cpos);");
2110 ("yy_current_state = YY_G(yy_last_accepting_state);");
2114 /* Still need to initialize yy_cp, though
2115 * yy_current_state was set up by
2116 * yy_get_previous_state().
2118 indent_puts ("yy_cp = YY_G(yy_c_buf_p);");
2122 /* Generate code for yy_get_previous_state(). */
2124 skelout (); /* %% [15.0] - break point in skel */
2129 skelout (); /* %% [16.0] - break point in skel */
2130 gen_next_state (true);
2133 skelout (); /* %% [17.0] - break point in skel */
2136 skelout (); /* %% [18.0] - break point in skel */
2137 skelout (); /* %% [19.0] - break point in skel */
2138 /* Update BOL and yylineno inside of input(). */
2141 ("YY_CURRENT_BUFFER_LVALUE->yy_at_bol = (c == '\\n');");
2144 ("if ( YY_CURRENT_BUFFER_LVALUE->yy_at_bol )");
2146 indent_puts ("M4_YY_INCR_LINENO();");
2151 else if (do_yylineno
) {
2152 indent_puts ("if ( c == '\\n' )");
2154 indent_puts ("M4_YY_INCR_LINENO();");
2160 /* Copy remainder of input to output. */
2162 line_directive_out (stdout
, 1);
2166 (void) flexscan (); /* copy remainder of input to output */