1 /* $NetBSD: gen.c,v 1.11 2014/10/30 18:44:05 christos Exp $ */
3 /* gen - actual generation (writing) of flex scanners */
5 /* Copyright (c) 1990 The Regents of the University of California. */
6 /* All rights reserved. */
8 /* This code is derived from software contributed to Berkeley by */
11 /* The United States Government has rights in this work pursuant */
12 /* to contract no. DE-AC03-76SF00098 between the United States */
13 /* Department of Energy and the University of California. */
15 /* This file is part of flex. */
17 /* Redistribution and use in source and binary forms, with or without */
18 /* modification, are permitted provided that the following conditions */
21 /* 1. Redistributions of source code must retain the above copyright */
22 /* notice, this list of conditions and the following disclaimer. */
23 /* 2. Redistributions in binary form must reproduce the above copyright */
24 /* notice, this list of conditions and the following disclaimer in the */
25 /* documentation and/or other materials provided with the distribution. */
27 /* Neither the name of the University nor the names of its contributors */
28 /* may be used to endorse or promote products derived from this software */
29 /* without specific prior written permission. */
31 /* THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR */
32 /* IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED */
33 /* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR */
36 __RCSID("$NetBSD: gen.c,v 1.11 2014/10/30 18:44:05 christos Exp $");
41 /* declare functions that have forward references */
43 void gen_next_state
PROTO ((int));
44 void genecs
PROTO ((void));
45 void indent_put2s
PROTO ((const char *, const char *));
46 void indent_puts
PROTO ((const char *));
49 static int indent_level
= 0; /* each level is 8 spaces */
51 #define indent_up() (++indent_level)
52 #define indent_down() (--indent_level)
53 #define set_indent(indent_val) indent_level = indent_val
55 /* Almost everything is done in terms of arrays starting at 1, so provide
56 * a null entry for the zero element of all C arrays. (The exception
57 * to this is that the fast table representation generally uses the
58 * 0 elements of its arrays, too.)
61 static const char *get_int16_decl (void)
64 ? "static yyconst flex_int16_t %s[%d] =\n { 0,\n"
65 : "static yyconst flex_int16_t * %s = 0;\n";
69 static const char *get_int32_decl (void)
72 ? "static yyconst flex_int32_t %s[%d] =\n { 0,\n"
73 : "static yyconst flex_int32_t * %s = 0;\n";
76 static const char *get_uint16_decl (void)
79 ? "static yyconst flex_uint16_t %s[%d] =\n { 0,\n"
80 : "static yyconst flex_uint16_t * %s = 0;\n";
83 static const char *get_uint32_decl (void)
86 ? "static yyconst flex_uint32_t %s[%d] =\n { 0,\n"
87 : "static yyconst flex_uint32_t * %s = 0;\n";
90 static const char *get_yy_char_decl (void)
93 ? "static yyconst YY_CHAR %s[%d] =\n { 0,\n"
94 : "static yyconst YY_CHAR * %s = 0;\n";
96 static const char *get_state_decl (void)
99 ? "static yyconst yy_state_type %s[%d] =\n { 0,\n"
100 : "static yyconst yy_state_type * %s = 0;\n";
103 /* Indent to the current level. */
107 register int i
= indent_level
* 8;
121 /** Make the table for possible eol matches.
122 * @return the newly allocated rule_can_match_eol table
124 static struct yytbl_data
*mkeoltbl (void)
127 flex_int8_t
*tdata
= 0;
128 struct yytbl_data
*tbl
;
130 tbl
= (struct yytbl_data
*) calloc (1, sizeof (struct yytbl_data
));
131 yytbl_data_init (tbl
, YYTD_ID_RULE_CAN_MATCH_EOL
);
132 tbl
->td_flags
= YYTD_DATA8
;
133 tbl
->td_lolen
= num_rules
+ 1;
134 tbl
->td_data
= tdata
=
135 (flex_int8_t
*) calloc (tbl
->td_lolen
, sizeof (flex_int8_t
));
137 for (i
= 1; i
<= num_rules
; i
++)
138 tdata
[i
] = rule_has_nl
[i
] ? 1 : 0;
140 buf_prints (&yydmap_buf
,
141 "\t{YYTD_ID_RULE_CAN_MATCH_EOL, (void**)&yy_rule_can_match_eol, sizeof(%s)},\n",
146 /* Generate the table for possible eol matches. */
147 static void geneoltbl (void)
151 outn ("m4_ifdef( [[M4_YY_USE_LINENO]],[[");
152 outn ("/* Table of booleans, true if rule could match eol. */");
153 out_str_dec (get_int32_decl (), "yy_rule_can_match_eol",
157 for (i
= 1; i
<= num_rules
; i
++) {
158 out_dec ("%d, ", rule_has_nl
[i
] ? 1 : 0);
159 /* format nicely, 20 numbers per line. */
169 /* Generate the code to keep backing-up information. */
171 void gen_backing_up ()
173 if (reject
|| num_backing_up
== 0)
177 indent_puts ("if ( yy_current_state[-1].yy_nxt )");
179 indent_puts ("if ( yy_accept[yy_current_state] )");
183 indent_puts ("YY_G(yy_last_accepting_state) = yy_current_state;");
184 indent_puts ("YY_G(yy_last_accepting_cpos) = yy_cp;");
190 /* Generate the code to perform the backing up. */
192 void gen_bu_action ()
194 if (reject
|| num_backing_up
== 0)
199 indent_puts ("case 0: /* must back up */");
200 indent_puts ("/* undo the effects of YY_DO_BEFORE_ACTION */");
201 indent_puts ("*yy_cp = YY_G(yy_hold_char);");
203 if (fullspd
|| fulltbl
)
204 indent_puts ("yy_cp = YY_G(yy_last_accepting_cpos) + 1;");
206 /* Backing-up info for compressed tables is taken \after/
207 * yy_cp has been incremented for the next state.
209 indent_puts ("yy_cp = YY_G(yy_last_accepting_cpos);");
211 indent_puts ("yy_current_state = YY_G(yy_last_accepting_state);");
212 indent_puts ("goto yy_find_action;");
218 /** mkctbl - make full speed compressed transition table
219 * This is an array of structs; each struct a pair of integers.
220 * You should call mkssltbl() immediately after this.
221 * Then, I think, mkecstbl(). Arrrg.
222 * @return the newly allocated trans table
225 static struct yytbl_data
*mkctbl (void)
228 struct yytbl_data
*tbl
= 0;
229 flex_int32_t
*tdata
= 0, curr
= 0;
230 int end_of_buffer_action
= num_rules
+ 1;
232 buf_prints (&yydmap_buf
,
233 "\t{YYTD_ID_TRANSITION, (void**)&yy_transition, sizeof(%s)},\n",
234 ((tblend
+ numecs
+ 1) >= INT16_MAX
235 || long_align
) ? "flex_int32_t" : "flex_int16_t");
237 tbl
= (struct yytbl_data
*) calloc (1, sizeof (struct yytbl_data
));
238 yytbl_data_init (tbl
, YYTD_ID_TRANSITION
);
239 tbl
->td_flags
= YYTD_DATA32
| YYTD_STRUCT
;
241 tbl
->td_lolen
= tblend
+ numecs
+ 1; /* number of structs */
243 tbl
->td_data
= tdata
=
244 (flex_int32_t
*) calloc (tbl
->td_lolen
* 2, sizeof (flex_int32_t
));
246 /* We want the transition to be represented as the offset to the
247 * next state, not the actual state number, which is what it currently
248 * is. The offset is base[nxt[i]] - (base of current state)]. That's
249 * just the difference between the starting points of the two involved
250 * states (to - from).
252 * First, though, we need to find some way to put in our end-of-buffer
253 * flags and states. We do this by making a state with absolutely no
254 * transitions. We put it at the end of the table.
257 /* We need to have room in nxt/chk for two more slots: One for the
258 * action and one for the end-of-buffer transition. We now *assume*
259 * that we're guaranteed the only character we'll try to index this
260 * nxt/chk pair with is EOB, i.e., 0, so we don't have to make sure
261 * there's room for jam entries for other characters.
264 while (tblend
+ 2 >= current_max_xpairs
)
267 while (lastdfa
+ 1 >= current_max_dfas
)
268 increase_max_dfas ();
270 base
[lastdfa
+ 1] = tblend
+ 2;
271 nxt
[tblend
+ 1] = end_of_buffer_action
;
272 chk
[tblend
+ 1] = numecs
+ 1;
273 chk
[tblend
+ 2] = 1; /* anything but EOB */
275 /* So that "make test" won't show arb. differences. */
278 /* Make sure every state has an end-of-buffer transition and an
281 for (i
= 0; i
<= lastdfa
; ++i
) {
282 int anum
= dfaacc
[i
].dfaacc_state
;
283 int offset
= base
[i
];
285 chk
[offset
] = EOB_POSITION
;
286 chk
[offset
- 1] = ACTION_POSITION
;
287 nxt
[offset
- 1] = anum
; /* action number */
290 for (i
= 0; i
<= tblend
; ++i
) {
291 if (chk
[i
] == EOB_POSITION
) {
293 tdata
[curr
++] = base
[lastdfa
+ 1] - i
;
296 else if (chk
[i
] == ACTION_POSITION
) {
298 tdata
[curr
++] = nxt
[i
];
301 else if (chk
[i
] > numecs
|| chk
[i
] == 0) {
305 else { /* verify, transition */
307 tdata
[curr
++] = chk
[i
];
308 tdata
[curr
++] = base
[nxt
[i
]] - (i
- chk
[i
]);
313 /* Here's the final, end-of-buffer state. */
314 tdata
[curr
++] = chk
[tblend
+ 1];
315 tdata
[curr
++] = nxt
[tblend
+ 1];
317 tdata
[curr
++] = chk
[tblend
+ 2];
318 tdata
[curr
++] = nxt
[tblend
+ 2];
324 /** Make start_state_list table.
325 * @return the newly allocated start_state_list table
327 static struct yytbl_data
*mkssltbl (void)
329 struct yytbl_data
*tbl
= 0;
330 flex_int32_t
*tdata
= 0;
333 tbl
= (struct yytbl_data
*) calloc (1, sizeof (struct yytbl_data
));
334 yytbl_data_init (tbl
, YYTD_ID_START_STATE_LIST
);
335 tbl
->td_flags
= YYTD_DATA32
| YYTD_PTRANS
;
337 tbl
->td_lolen
= lastsc
* 2 + 1;
339 tbl
->td_data
= tdata
=
340 (flex_int32_t
*) calloc (tbl
->td_lolen
, sizeof (flex_int32_t
));
342 for (i
= 0; i
<= lastsc
* 2; ++i
)
345 buf_prints (&yydmap_buf
,
346 "\t{YYTD_ID_START_STATE_LIST, (void**)&yy_start_state_list, sizeof(%s)},\n",
347 "struct yy_trans_info*");
354 /* genctbl - generates full speed compressed transition table */
359 int end_of_buffer_action
= num_rules
+ 1;
361 /* Table of verify for transition and offset to next state. */
363 out_dec ("static yyconst struct yy_trans_info yy_transition[%d] =\n {\n", tblend
+ numecs
+ 1);
365 outn ("static yyconst struct yy_trans_info *yy_transition = 0;");
367 /* We want the transition to be represented as the offset to the
368 * next state, not the actual state number, which is what it currently
369 * is. The offset is base[nxt[i]] - (base of current state)]. That's
370 * just the difference between the starting points of the two involved
371 * states (to - from).
373 * First, though, we need to find some way to put in our end-of-buffer
374 * flags and states. We do this by making a state with absolutely no
375 * transitions. We put it at the end of the table.
378 /* We need to have room in nxt/chk for two more slots: One for the
379 * action and one for the end-of-buffer transition. We now *assume*
380 * that we're guaranteed the only character we'll try to index this
381 * nxt/chk pair with is EOB, i.e., 0, so we don't have to make sure
382 * there's room for jam entries for other characters.
385 while (tblend
+ 2 >= current_max_xpairs
)
388 while (lastdfa
+ 1 >= current_max_dfas
)
389 increase_max_dfas ();
391 base
[lastdfa
+ 1] = tblend
+ 2;
392 nxt
[tblend
+ 1] = end_of_buffer_action
;
393 chk
[tblend
+ 1] = numecs
+ 1;
394 chk
[tblend
+ 2] = 1; /* anything but EOB */
396 /* So that "make test" won't show arb. differences. */
399 /* Make sure every state has an end-of-buffer transition and an
402 for (i
= 0; i
<= lastdfa
; ++i
) {
403 int anum
= dfaacc
[i
].dfaacc_state
;
404 int offset
= base
[i
];
406 chk
[offset
] = EOB_POSITION
;
407 chk
[offset
- 1] = ACTION_POSITION
;
408 nxt
[offset
- 1] = anum
; /* action number */
411 for (i
= 0; i
<= tblend
; ++i
) {
412 if (chk
[i
] == EOB_POSITION
)
413 transition_struct_out (0, base
[lastdfa
+ 1] - i
);
415 else if (chk
[i
] == ACTION_POSITION
)
416 transition_struct_out (0, nxt
[i
]);
418 else if (chk
[i
] > numecs
|| chk
[i
] == 0)
419 transition_struct_out (0, 0); /* unused slot */
421 else /* verify, transition */
422 transition_struct_out (chk
[i
],
428 /* Here's the final, end-of-buffer state. */
429 transition_struct_out (chk
[tblend
+ 1], nxt
[tblend
+ 1]);
430 transition_struct_out (chk
[tblend
+ 2], nxt
[tblend
+ 2]);
435 /* Table of pointers to start states. */
437 out_dec ("static yyconst struct yy_trans_info *yy_start_state_list[%d] =\n", lastsc
* 2 + 1);
439 outn ("static yyconst struct yy_trans_info **yy_start_state_list =0;");
444 for (i
= 0; i
<= lastsc
* 2; ++i
)
445 out_dec (" &yy_transition[%d],\n", base
[i
]);
455 /* mkecstbl - Make equivalence-class tables. */
456 static struct yytbl_data
*mkecstbl (void)
459 struct yytbl_data
*tbl
= 0;
460 flex_int32_t
*tdata
= 0;
462 tbl
= (struct yytbl_data
*) calloc (1, sizeof (struct yytbl_data
));
463 yytbl_data_init (tbl
, YYTD_ID_EC
);
464 tbl
->td_flags
|= YYTD_DATA32
;
466 tbl
->td_lolen
= csize
;
468 tbl
->td_data
= tdata
=
469 (flex_int32_t
*) calloc (tbl
->td_lolen
, sizeof (flex_int32_t
));
471 for (i
= 1; i
< csize
; ++i
) {
472 ecgroup
[i
] = ABS (ecgroup
[i
]);
473 tdata
[i
] = ecgroup
[i
];
476 buf_prints (&yydmap_buf
,
477 "\t{YYTD_ID_EC, (void**)&yy_ec, sizeof(%s)},\n",
483 /* Generate equivalence-class tables. */
490 out_str_dec (get_yy_char_decl (), "yy_ec", csize
);
492 for (i
= 1; i
< csize
; ++i
) {
493 ecgroup
[i
] = ABS (ecgroup
[i
]);
500 fputs (_("\n\nEquivalence Classes:\n\n"), stderr
);
504 for (j
= 0; j
< numrows
; ++j
) {
505 for (i
= j
; i
< csize
; i
= i
+ numrows
) {
506 fprintf (stderr
, "%4s = %-2d",
507 readable_form (i
), ecgroup
[i
]);
518 /* Generate the code to find the action number. */
520 void gen_find_action ()
523 indent_puts ("yy_act = yy_current_state[-1].yy_nxt;");
526 indent_puts ("yy_act = yy_accept[yy_current_state];");
529 indent_puts ("yy_current_state = *--YY_G(yy_state_ptr);");
530 indent_puts ("YY_G(yy_lp) = yy_accept[yy_current_state];");
532 if (!variable_trailing_context_rules
)
533 outn ("m4_ifdef( [[M4_YY_USES_REJECT]],\n[[");
534 outn ("find_rule: /* we branch to this label when backing up */");
535 if (!variable_trailing_context_rules
)
539 ("for ( ; ; ) /* until we find what rule we matched */");
546 ("if ( YY_G(yy_lp) && YY_G(yy_lp) < yy_accept[yy_current_state + 1] )");
549 indent_puts ("yy_act = yy_acclist[YY_G(yy_lp)];");
551 if (variable_trailing_context_rules
) {
553 ("if ( yy_act & YY_TRAILING_HEAD_MASK ||");
554 indent_puts (" YY_G(yy_looking_for_trail_begin) )");
559 ("if ( yy_act == YY_G(yy_looking_for_trail_begin) )");
562 indent_puts ("YY_G(yy_looking_for_trail_begin) = 0;");
563 indent_puts ("yy_act &= ~YY_TRAILING_HEAD_MASK;");
564 indent_puts ("break;");
572 ("else if ( yy_act & YY_TRAILING_MASK )");
576 ("YY_G(yy_looking_for_trail_begin) = yy_act & ~YY_TRAILING_MASK;");
578 ("YY_G(yy_looking_for_trail_begin) |= YY_TRAILING_HEAD_MASK;");
581 /* Remember matched text in case we back up
585 ("YY_G(yy_full_match) = yy_cp;");
587 ("YY_G(yy_full_state) = YY_G(yy_state_ptr);");
588 indent_puts ("YY_G(yy_full_lp) = YY_G(yy_lp);");
594 indent_puts ("else");
597 indent_puts ("YY_G(yy_full_match) = yy_cp;");
599 ("YY_G(yy_full_state) = YY_G(yy_state_ptr);");
600 indent_puts ("YY_G(yy_full_lp) = YY_G(yy_lp);");
601 indent_puts ("break;");
605 indent_puts ("++YY_G(yy_lp);");
606 indent_puts ("goto find_rule;");
610 /* Remember matched text in case we back up due to
611 * trailing context plus REJECT.
615 indent_puts ("YY_G(yy_full_match) = yy_cp;");
616 indent_puts ("break;");
624 indent_puts ("--yy_cp;");
626 /* We could consolidate the following two lines with those at
627 * the beginning, but at the cost of complaints that we're
628 * branching inside a loop.
630 indent_puts ("yy_current_state = *--YY_G(yy_state_ptr);");
631 indent_puts ("YY_G(yy_lp) = yy_accept[yy_current_state];");
638 else { /* compressed */
639 indent_puts ("yy_act = yy_accept[yy_current_state];");
641 if (interactive
&& !reject
) {
642 /* Do the guaranteed-needed backing up to figure out
645 indent_puts ("if ( yy_act == 0 )");
647 indent_puts ("{ /* have to back up */");
649 ("yy_cp = YY_G(yy_last_accepting_cpos);");
651 ("yy_current_state = YY_G(yy_last_accepting_state);");
653 ("yy_act = yy_accept[yy_current_state];");
660 /* mkftbl - make the full table and return the struct .
661 * you should call mkecstbl() after this.
664 struct yytbl_data
*mkftbl (void)
667 int end_of_buffer_action
= num_rules
+ 1;
668 struct yytbl_data
*tbl
;
669 flex_int32_t
*tdata
= 0;
671 tbl
= (struct yytbl_data
*) calloc (1, sizeof (struct yytbl_data
));
672 yytbl_data_init (tbl
, YYTD_ID_ACCEPT
);
673 tbl
->td_flags
|= YYTD_DATA32
;
674 tbl
->td_hilen
= 0; /* it's a one-dimensional array */
675 tbl
->td_lolen
= lastdfa
+ 1;
677 tbl
->td_data
= tdata
=
678 (flex_int32_t
*) calloc (tbl
->td_lolen
, sizeof (flex_int32_t
));
680 dfaacc
[end_of_buffer_state
].dfaacc_state
= end_of_buffer_action
;
682 for (i
= 1; i
<= lastdfa
; ++i
) {
683 register int anum
= dfaacc
[i
].dfaacc_state
;
688 fprintf (stderr
, _("state # %d accepts: [%d]\n"),
692 buf_prints (&yydmap_buf
,
693 "\t{YYTD_ID_ACCEPT, (void**)&yy_accept, sizeof(%s)},\n",
694 long_align
? "flex_int32_t" : "flex_int16_t");
699 /* genftbl - generate full transition table */
704 int end_of_buffer_action
= num_rules
+ 1;
706 out_str_dec (long_align
? get_int32_decl () : get_int16_decl (),
707 "yy_accept", lastdfa
+ 1);
709 dfaacc
[end_of_buffer_state
].dfaacc_state
= end_of_buffer_action
;
711 for (i
= 1; i
<= lastdfa
; ++i
) {
712 register int anum
= dfaacc
[i
].dfaacc_state
;
717 fprintf (stderr
, _("state # %d accepts: [%d]\n"),
726 /* Don't have to dump the actual full table entries - they were
727 * created on-the-fly.
732 /* Generate the code to find the next compressed-table state. */
734 void gen_next_compressed_state (char_map
)
737 indent_put2s ("register YY_CHAR yy_c = %s;", char_map
);
739 /* Save the backing-up info \before/ computing the next state
740 * because we always compute one more state than needed - we
741 * always proceed until we reach a jam state
746 ("while ( yy_chk[yy_base[yy_current_state] + yy_c] != yy_current_state )");
749 indent_puts ("yy_current_state = (int) yy_def[yy_current_state];");
752 /* We've arrange it so that templates are never chained
753 * to one another. This means we can afford to make a
754 * very simple test to see if we need to convert to
755 * yy_c's meta-equivalence class without worrying
756 * about erroneously looking up the meta-equivalence
761 /* lastdfa + 2 is the beginning of the templates */
762 out_dec ("if ( yy_current_state >= %d )\n", lastdfa
+ 2);
765 indent_puts ("yy_c = yy_meta[(unsigned int) yy_c];");
773 ("yy_current_state = yy_nxt[yy_base[yy_current_state] + (unsigned int) yy_c];");
777 /* Generate the code to find the next match. */
779 void gen_next_match ()
781 /* NOTE - changes in here should be reflected in gen_next_state() and
784 char *char_map
= useecs
?
785 "yy_ec[YY_SC_TO_UI(*yy_cp)] " : "YY_SC_TO_UI(*yy_cp)";
787 char *char_map_2
= useecs
?
788 "yy_ec[YY_SC_TO_UI(*++yy_cp)] " : "YY_SC_TO_UI(*++yy_cp)";
793 ("while ( (yy_current_state = yy_nxt[yy_current_state][ %s ]) > 0 )",
797 ("while ( (yy_current_state = yy_nxt[yy_current_state*YY_NXT_LOLEN + %s ]) > 0 )",
802 if (num_backing_up
> 0) {
808 indent_puts ("++yy_cp;");
810 if (num_backing_up
> 0)
817 indent_puts ("yy_current_state = -yy_current_state;");
823 ("register yyconst struct yy_trans_info *yy_trans_info;\n");
824 indent_puts ("register YY_CHAR yy_c;\n");
825 indent_put2s ("for ( yy_c = %s;", char_map
);
827 (" (yy_trans_info = &yy_current_state[(unsigned int) yy_c])->");
828 indent_puts ("yy_verify == yy_c;");
829 indent_put2s (" yy_c = %s )", char_map_2
);
833 if (num_backing_up
> 0)
836 indent_puts ("yy_current_state += yy_trans_info->yy_nxt;");
838 if (num_backing_up
> 0) {
848 else { /* compressed */
854 gen_next_state (false);
856 indent_puts ("++yy_cp;");
865 out_dec ("while ( yy_base[yy_current_state] != %d );\n", jambase
);
867 out_dec ("while ( yy_current_state != %d );\n",
870 if (!reject
&& !interactive
) {
871 /* Do the guaranteed-needed backing up to figure out
875 ("yy_cp = YY_G(yy_last_accepting_cpos);");
877 ("yy_current_state = YY_G(yy_last_accepting_state);");
883 /* Generate the code to find the next state. */
885 void gen_next_state (worry_about_NULs
)
886 int worry_about_NULs
;
887 { /* NOTE - changes in here should be reflected in gen_next_match() */
890 if (worry_about_NULs
&& !nultrans
) {
892 snprintf (char_map
, sizeof(char_map
),
893 "(*yy_cp ? yy_ec[YY_SC_TO_UI(*yy_cp)] : %d)",
896 snprintf (char_map
, sizeof(char_map
),
897 "(*yy_cp ? YY_SC_TO_UI(*yy_cp) : %d)",
902 strcpy (char_map
, useecs
?
903 "yy_ec[YY_SC_TO_UI(*yy_cp)] " :
904 "YY_SC_TO_UI(*yy_cp)");
906 if (worry_about_NULs
&& nultrans
) {
907 if (!fulltbl
&& !fullspd
)
908 /* Compressed tables back up *before* they match. */
911 indent_puts ("if ( *yy_cp )");
919 ("yy_current_state = yy_nxt[yy_current_state][%s];",
923 ("yy_current_state = yy_nxt[yy_current_state*YY_NXT_LOLEN + %s];",
929 ("yy_current_state += yy_current_state[%s].yy_nxt;",
933 gen_next_compressed_state (char_map
);
935 if (worry_about_NULs
&& nultrans
) {
939 indent_puts ("else");
942 ("yy_current_state = yy_NUL_trans[yy_current_state];");
946 if (fullspd
|| fulltbl
)
950 indent_puts ("*YY_G(yy_state_ptr)++ = yy_current_state;");
954 /* Generate the code to make a NUL transition. */
956 void gen_NUL_trans ()
957 { /* NOTE - changes in here should be reflected in gen_next_match() */
958 /* Only generate a definition for "yy_cp" if we'll generate code
959 * that uses it. Otherwise lint and the like complain.
961 int need_backing_up
= (num_backing_up
> 0 && !reject
);
963 if (need_backing_up
&& (!nultrans
|| fullspd
|| fulltbl
))
964 /* We're going to need yy_cp lying around for the call
965 * below to gen_backing_up().
967 indent_puts ("register char *yy_cp = YY_G(yy_c_buf_p);");
973 ("yy_current_state = yy_NUL_trans[yy_current_state];");
974 indent_puts ("yy_is_jam = (yy_current_state == 0);");
980 out_dec ("yy_current_state = yy_nxt[yy_current_state][%d];\n", NUL_ec
);
982 out_dec ("yy_current_state = yy_nxt[yy_current_state*YY_NXT_LOLEN + %d];\n", NUL_ec
);
983 indent_puts ("yy_is_jam = (yy_current_state <= 0);");
988 out_dec ("register int yy_c = %d;\n", NUL_ec
);
991 ("register yyconst struct yy_trans_info *yy_trans_info;\n");
993 ("yy_trans_info = &yy_current_state[(unsigned int) yy_c];");
994 indent_puts ("yy_current_state += yy_trans_info->yy_nxt;");
997 ("yy_is_jam = (yy_trans_info->yy_verify != yy_c);");
1001 char NUL_ec_str
[20];
1003 snprintf (NUL_ec_str
, sizeof(NUL_ec_str
), "%d", NUL_ec
);
1004 gen_next_compressed_state (NUL_ec_str
);
1007 out_dec ("yy_is_jam = (yy_current_state == %d);\n",
1011 /* Only stack this state if it's a transition we
1012 * actually make. If we stack it on a jam, then
1013 * the state stack and yy_c_buf_p get out of sync.
1015 indent_puts ("if ( ! yy_is_jam )");
1018 ("*YY_G(yy_state_ptr)++ = yy_current_state;");
1023 /* If we've entered an accepting state, back up; note that
1024 * compressed tables have *already* done such backing up, so
1025 * we needn't bother with it again.
1027 if (need_backing_up
&& (fullspd
|| fulltbl
)) {
1029 indent_puts ("if ( ! yy_is_jam )");
1039 /* Generate the code to find the start state. */
1041 void gen_start_state ()
1046 ("yy_current_state = yy_start_state_list[YY_G(yy_start) + YY_AT_BOL()];");
1050 ("yy_current_state = yy_start_state_list[YY_G(yy_start)];");
1054 indent_puts ("yy_current_state = YY_G(yy_start);");
1057 indent_puts ("yy_current_state += YY_AT_BOL();");
1060 /* Set up for storing up states. */
1061 outn ("m4_ifdef( [[M4_YY_USES_REJECT]],\n[[");
1063 ("YY_G(yy_state_ptr) = YY_G(yy_state_buf);");
1065 ("*YY_G(yy_state_ptr)++ = yy_current_state;");
1072 /* gentabs - generate data statements for the transition tables */
1076 int i
, j
, k
, *accset
, nacc
, *acc_array
, total_states
;
1077 int end_of_buffer_action
= num_rules
+ 1;
1078 struct yytbl_data
*yyacc_tbl
= 0, *yymeta_tbl
= 0, *yybase_tbl
= 0,
1079 *yydef_tbl
= 0, *yynxt_tbl
= 0, *yychk_tbl
= 0, *yyacclist_tbl
=0;
1080 flex_int32_t
*yyacc_data
= 0, *yybase_data
= 0, *yydef_data
= 0,
1081 *yynxt_data
= 0, *yychk_data
= 0, *yyacclist_data
=0;
1082 flex_int32_t yybase_curr
= 0, yyacclist_curr
=0,yyacc_curr
=0;
1084 acc_array
= allocate_integer_array (current_max_dfas
);
1087 /* The compressed table format jams by entering the "jam state",
1088 * losing information about the previous state in the process.
1089 * In order to recover the previous state, we effectively need
1090 * to keep backing-up information.
1095 /* Write out accepting list and pointer list.
1097 * First we generate the "yy_acclist" array. In the process,
1098 * we compute the indices that will go into the "yy_accept"
1099 * array, and save the indices in the dfaacc array.
1101 int EOB_accepting_list
[2];
1103 /* Set up accepting structures for the End Of Buffer state. */
1104 EOB_accepting_list
[0] = 0;
1105 EOB_accepting_list
[1] = end_of_buffer_action
;
1106 accsiz
[end_of_buffer_state
] = 1;
1107 dfaacc
[end_of_buffer_state
].dfaacc_set
=
1110 out_str_dec (long_align
? get_int32_decl () :
1111 get_int16_decl (), "yy_acclist", MAX (numas
,
1114 buf_prints (&yydmap_buf
,
1115 "\t{YYTD_ID_ACCLIST, (void**)&yy_acclist, sizeof(%s)},\n",
1116 long_align
? "flex_int32_t" : "flex_int16_t");
1118 yyacclist_tbl
= (struct yytbl_data
*)calloc(1,sizeof(struct yytbl_data
));
1119 yytbl_data_init (yyacclist_tbl
, YYTD_ID_ACCLIST
);
1120 yyacclist_tbl
->td_lolen
= MAX(numas
,1) + 1;
1121 yyacclist_tbl
->td_data
= yyacclist_data
=
1122 (flex_int32_t
*) calloc (yyacclist_tbl
->td_lolen
, sizeof (flex_int32_t
));
1125 j
= 1; /* index into "yy_acclist" array */
1127 for (i
= 1; i
<= lastdfa
; ++i
) {
1130 if (accsiz
[i
] != 0) {
1131 accset
= dfaacc
[i
].dfaacc_set
;
1136 _("state # %d accepts: "),
1139 for (k
= 1; k
<= nacc
; ++k
) {
1140 int accnum
= accset
[k
];
1144 if (variable_trailing_context_rules
1146 YY_TRAILING_HEAD_MASK
)
1148 && accnum
<= num_rules
1149 && rule_type
[accnum
] ==
1151 /* Special hack to flag
1152 * accepting number as part
1153 * of trailing context rule.
1155 accnum
|= YY_TRAILING_MASK
;
1159 yyacclist_data
[yyacclist_curr
++] = accnum
;
1162 fprintf (stderr
, "[%d]",
1176 /* add accepting number for the "jam" state */
1181 yytbl_data_compress (yyacclist_tbl
);
1182 if (yytbl_data_fwrite (&tableswr
, yyacclist_tbl
) < 0)
1183 flexerror (_("Could not write yyacclist_tbl"));
1184 yytbl_data_destroy (yyacclist_tbl
);
1185 yyacclist_tbl
= NULL
;
1190 dfaacc
[end_of_buffer_state
].dfaacc_state
=
1191 end_of_buffer_action
;
1193 for (i
= 1; i
<= lastdfa
; ++i
)
1194 acc_array
[i
] = dfaacc
[i
].dfaacc_state
;
1196 /* add accepting number for jam state */
1200 /* Begin generating yy_accept */
1202 /* Spit out "yy_accept" array. If we're doing "reject", it'll be
1203 * pointers into the "yy_acclist" array. Otherwise it's actual
1204 * accepting numbers. In either case, we just dump the numbers.
1207 /* "lastdfa + 2" is the size of "yy_accept"; includes room for C arrays
1208 * beginning at 0 and for "jam" state.
1213 /* We put a "cap" on the table associating lists of accepting
1214 * numbers with state numbers. This is needed because we tell
1215 * where the end of an accepting list is by looking at where
1216 * the list for the next state starts.
1220 out_str_dec (long_align
? get_int32_decl () : get_int16_decl (),
1223 buf_prints (&yydmap_buf
,
1224 "\t{YYTD_ID_ACCEPT, (void**)&yy_accept, sizeof(%s)},\n",
1225 long_align
? "flex_int32_t" : "flex_int16_t");
1228 (struct yytbl_data
*) calloc (1,
1229 sizeof (struct yytbl_data
));
1230 yytbl_data_init (yyacc_tbl
, YYTD_ID_ACCEPT
);
1231 yyacc_tbl
->td_lolen
= k
;
1232 yyacc_tbl
->td_data
= yyacc_data
=
1233 (flex_int32_t
*) calloc (yyacc_tbl
->td_lolen
, sizeof (flex_int32_t
));
1236 for (i
= 1; i
<= lastdfa
; ++i
) {
1237 mkdata (acc_array
[i
]);
1238 yyacc_data
[yyacc_curr
++] = acc_array
[i
];
1240 if (!reject
&& trace
&& acc_array
[i
])
1241 fprintf (stderr
, _("state # %d accepts: [%d]\n"),
1245 /* Add entry for "jam" state. */
1246 mkdata (acc_array
[i
]);
1247 yyacc_data
[yyacc_curr
++] = acc_array
[i
];
1250 /* Add "cap" for the list. */
1251 mkdata (acc_array
[i
]);
1252 yyacc_data
[yyacc_curr
++] = acc_array
[i
];
1257 yytbl_data_compress (yyacc_tbl
);
1258 if (yytbl_data_fwrite (&tableswr
, yyacc_tbl
) < 0)
1259 flexerror (_("Could not write yyacc_tbl"));
1260 yytbl_data_destroy (yyacc_tbl
);
1263 /* End generating yy_accept */
1269 struct yytbl_data
*tbl
;
1272 yytbl_data_compress (tbl
);
1273 if (yytbl_data_fwrite (&tableswr
, tbl
) < 0)
1274 flexerror (_("Could not write ecstbl"));
1275 yytbl_data_destroy (tbl
);
1281 /* Begin generating yy_meta */
1282 /* Write out meta-equivalence classes (used to index
1285 flex_int32_t
*yymecs_data
= 0;
1287 (struct yytbl_data
*) calloc (1,
1290 yytbl_data_init (yymeta_tbl
, YYTD_ID_META
);
1291 yymeta_tbl
->td_lolen
= numecs
+ 1;
1292 yymeta_tbl
->td_data
= yymecs_data
=
1293 (flex_int32_t
*) calloc (yymeta_tbl
->td_lolen
,
1294 sizeof (flex_int32_t
));
1297 fputs (_("\n\nMeta-Equivalence Classes:\n"),
1300 out_str_dec (get_yy_char_decl (), "yy_meta", numecs
+ 1);
1301 buf_prints (&yydmap_buf
,
1302 "\t{YYTD_ID_META, (void**)&yy_meta, sizeof(%s)},\n",
1305 for (i
= 1; i
<= numecs
; ++i
) {
1307 fprintf (stderr
, "%d = %d\n",
1308 i
, ABS (tecbck
[i
]));
1310 mkdata (ABS (tecbck
[i
]));
1311 yymecs_data
[i
] = ABS (tecbck
[i
]);
1316 yytbl_data_compress (yymeta_tbl
);
1317 if (yytbl_data_fwrite (&tableswr
, yymeta_tbl
) < 0)
1319 ("Could not write yymeta_tbl"));
1320 yytbl_data_destroy (yymeta_tbl
);
1323 /* End generating yy_meta */
1326 total_states
= lastdfa
+ numtemps
;
1328 /* Begin generating yy_base */
1329 out_str_dec ((tblend
>= INT16_MAX
|| long_align
) ?
1330 get_uint32_decl () : get_uint16_decl (),
1331 "yy_base", total_states
+ 1);
1333 buf_prints (&yydmap_buf
,
1334 "\t{YYTD_ID_BASE, (void**)&yy_base, sizeof(%s)},\n",
1335 (tblend
>= INT16_MAX
1336 || long_align
) ? "flex_uint32_t" : "flex_uint16_t");
1338 (struct yytbl_data
*) calloc (1,
1339 sizeof (struct yytbl_data
));
1340 yytbl_data_init (yybase_tbl
, YYTD_ID_BASE
);
1341 yybase_tbl
->td_lolen
= total_states
+ 1;
1342 yybase_tbl
->td_data
= yybase_data
=
1343 (flex_int32_t
*) calloc (yybase_tbl
->td_lolen
,
1344 sizeof (flex_int32_t
));
1347 for (i
= 1; i
<= lastdfa
; ++i
) {
1348 register int d
= def
[i
];
1350 if (base
[i
] == JAMSTATE
)
1357 /* Template reference. */
1359 def
[i
] = lastdfa
- d
+ 1;
1363 yybase_data
[yybase_curr
++] = base
[i
];
1366 /* Generate jam state's base index. */
1368 yybase_data
[yybase_curr
++] = base
[i
];
1370 for (++i
/* skip jam state */ ; i
<= total_states
; ++i
) {
1372 yybase_data
[yybase_curr
++] = base
[i
];
1378 yytbl_data_compress (yybase_tbl
);
1379 if (yytbl_data_fwrite (&tableswr
, yybase_tbl
) < 0)
1380 flexerror (_("Could not write yybase_tbl"));
1381 yytbl_data_destroy (yybase_tbl
);
1384 /* End generating yy_base */
1387 /* Begin generating yy_def */
1388 out_str_dec ((total_states
>= INT16_MAX
|| long_align
) ?
1389 get_int32_decl () : get_int16_decl (),
1390 "yy_def", total_states
+ 1);
1392 buf_prints (&yydmap_buf
,
1393 "\t{YYTD_ID_DEF, (void**)&yy_def, sizeof(%s)},\n",
1394 (total_states
>= INT16_MAX
1395 || long_align
) ? "flex_int32_t" : "flex_int16_t");
1398 (struct yytbl_data
*) calloc (1,
1399 sizeof (struct yytbl_data
));
1400 yytbl_data_init (yydef_tbl
, YYTD_ID_DEF
);
1401 yydef_tbl
->td_lolen
= total_states
+ 1;
1402 yydef_tbl
->td_data
= yydef_data
=
1403 (flex_int32_t
*) calloc (yydef_tbl
->td_lolen
, sizeof (flex_int32_t
));
1405 for (i
= 1; i
<= total_states
; ++i
) {
1407 yydef_data
[i
] = def
[i
];
1412 yytbl_data_compress (yydef_tbl
);
1413 if (yytbl_data_fwrite (&tableswr
, yydef_tbl
) < 0)
1414 flexerror (_("Could not write yydef_tbl"));
1415 yytbl_data_destroy (yydef_tbl
);
1418 /* End generating yy_def */
1421 /* Begin generating yy_nxt */
1422 out_str_dec ((total_states
>= INT16_MAX
|| long_align
) ?
1423 get_uint32_decl () : get_uint16_decl (), "yy_nxt",
1426 buf_prints (&yydmap_buf
,
1427 "\t{YYTD_ID_NXT, (void**)&yy_nxt, sizeof(%s)},\n",
1428 (total_states
>= INT16_MAX
1429 || long_align
) ? "flex_uint32_t" : "flex_uint16_t");
1432 (struct yytbl_data
*) calloc (1,
1433 sizeof (struct yytbl_data
));
1434 yytbl_data_init (yynxt_tbl
, YYTD_ID_NXT
);
1435 yynxt_tbl
->td_lolen
= tblend
+ 1;
1436 yynxt_tbl
->td_data
= yynxt_data
=
1437 (flex_int32_t
*) calloc (yynxt_tbl
->td_lolen
, sizeof (flex_int32_t
));
1439 for (i
= 1; i
<= tblend
; ++i
) {
1440 /* Note, the order of the following test is important.
1441 * If chk[i] is 0, then nxt[i] is undefined.
1443 if (chk
[i
] == 0 || nxt
[i
] == 0)
1444 nxt
[i
] = jamstate
; /* new state is the JAM state */
1447 yynxt_data
[i
] = nxt
[i
];
1452 yytbl_data_compress (yynxt_tbl
);
1453 if (yytbl_data_fwrite (&tableswr
, yynxt_tbl
) < 0)
1454 flexerror (_("Could not write yynxt_tbl"));
1455 yytbl_data_destroy (yynxt_tbl
);
1458 /* End generating yy_nxt */
1460 /* Begin generating yy_chk */
1461 out_str_dec ((total_states
>= INT16_MAX
|| long_align
) ?
1462 get_int32_decl () : get_int16_decl (), "yy_chk",
1465 buf_prints (&yydmap_buf
,
1466 "\t{YYTD_ID_CHK, (void**)&yy_chk, sizeof(%s)},\n",
1467 (total_states
>= INT16_MAX
1468 || long_align
) ? "flex_int32_t" : "flex_int16_t");
1471 (struct yytbl_data
*) calloc (1,
1472 sizeof (struct yytbl_data
));
1473 yytbl_data_init (yychk_tbl
, YYTD_ID_CHK
);
1474 yychk_tbl
->td_lolen
= tblend
+ 1;
1475 yychk_tbl
->td_data
= yychk_data
=
1476 (flex_int32_t
*) calloc (yychk_tbl
->td_lolen
, sizeof (flex_int32_t
));
1478 for (i
= 1; i
<= tblend
; ++i
) {
1483 yychk_data
[i
] = chk
[i
];
1488 yytbl_data_compress (yychk_tbl
);
1489 if (yytbl_data_fwrite (&tableswr
, yychk_tbl
) < 0)
1490 flexerror (_("Could not write yychk_tbl"));
1491 yytbl_data_destroy (yychk_tbl
);
1494 /* End generating yy_chk */
1496 flex_free ((void *) acc_array
);
1500 /* Write out a formatted string (with a secondary string argument) at the
1501 * current indentation level, adding a final newline.
1504 void indent_put2s (fmt
, arg
)
1505 const char *fmt
, *arg
;
1513 /* Write out a string at the current indentation level, adding a final
1517 void indent_puts (str
)
1525 /* make_tables - generate transition tables and finishes generating output file
1531 int did_eof_rule
= false;
1532 struct yytbl_data
*yynultrans_tbl
;
1535 skelout (); /* %% [2.0] - break point in skel */
1537 /* First, take care of YY_DO_BEFORE_ACTION depending on yymore
1542 if (yymore_used
&& !yytext_is_array
) {
1543 indent_puts ("YY_G(yytext_ptr) -= YY_G(yy_more_len); \\");
1545 ("yyleng = (size_t) (yy_cp - YY_G(yytext_ptr)); \\");
1549 indent_puts ("yyleng = (size_t) (yy_cp - yy_bp); \\");
1551 /* Now also deal with copying yytext_ptr to yytext if needed. */
1552 skelout (); /* %% [3.0] - break point in skel */
1553 if (yytext_is_array
) {
1556 ("if ( yyleng + YY_G(yy_more_offset) >= YYLMAX ) \\");
1558 indent_puts ("if ( yyleng >= YYLMAX ) \\");
1562 ("YY_FATAL_ERROR( \"token too large, exceeds YYLMAX\" ); \\");
1567 ("yy_flex_strncpy( &yytext[YY_G(yy_more_offset)], YY_G(yytext_ptr), yyleng + 1 M4_YY_CALL_LAST_ARG); \\");
1568 indent_puts ("yyleng += YY_G(yy_more_offset); \\");
1570 ("YY_G(yy_prev_more_offset) = YY_G(yy_more_offset); \\");
1571 indent_puts ("YY_G(yy_more_offset) = 0; \\");
1575 ("yy_flex_strncpy( yytext, YY_G(yytext_ptr), yyleng + 1 M4_YY_CALL_LAST_ARG); \\");
1581 skelout (); /* %% [4.0] - break point in skel */
1584 /* This is where we REALLY begin generating the tables. */
1586 out_dec ("#define YY_NUM_RULES %d\n", num_rules
);
1587 out_dec ("#define YY_END_OF_BUFFER %d\n", num_rules
+ 1);
1590 /* Need to define the transet type as a size large
1591 * enough to hold the biggest offset.
1593 int total_table_size
= tblend
+ numecs
+ 1;
1594 char *trans_offset_type
=
1595 (total_table_size
>= INT16_MAX
|| long_align
) ?
1596 "flex_int32_t" : "flex_int16_t";
1599 indent_puts ("struct yy_trans_info");
1603 /* We require that yy_verify and yy_nxt must be of the same size int. */
1604 indent_put2s ("%s yy_verify;", trans_offset_type
);
1606 /* In cases where its sister yy_verify *is* a "yes, there is
1607 * a transition", yy_nxt is the offset (in records) to the
1608 * next state. In most cases where there is no transition,
1609 * the value of yy_nxt is irrelevant. If yy_nxt is the -1th
1610 * record of a state, though, then yy_nxt is the action number
1614 indent_put2s ("%s yy_nxt;", trans_offset_type
);
1619 /* We generate a bogus 'struct yy_trans_info' data type
1620 * so we can guarantee that it is always declared in the skel.
1621 * This is so we can compile "sizeof(struct yy_trans_info)"
1625 ("/* This struct is not used in this scanner,");
1626 indent_puts (" but its presence is necessary. */");
1627 indent_puts ("struct yy_trans_info");
1630 indent_puts ("flex_int32_t yy_verify;");
1631 indent_puts ("flex_int32_t yy_nxt;");
1639 struct yytbl_data
*tbl
;
1642 yytbl_data_compress (tbl
);
1643 if (yytbl_data_fwrite (&tableswr
, tbl
) < 0)
1644 flexerror (_("Could not write ftbl"));
1645 yytbl_data_destroy (tbl
);
1648 yytbl_data_compress (tbl
);
1649 if (yytbl_data_fwrite (&tableswr
, tbl
) < 0)
1650 flexerror (_("Could not write ssltbl"));
1651 yytbl_data_destroy (tbl
);
1656 yytbl_data_compress (tbl
);
1657 if (yytbl_data_fwrite (&tableswr
, tbl
) < 0)
1659 ("Could not write ecstbl"));
1660 yytbl_data_destroy (tbl
);
1668 struct yytbl_data
*tbl
;
1671 yytbl_data_compress (tbl
);
1672 if (yytbl_data_fwrite (&tableswr
, tbl
) < 0)
1673 flexerror (_("Could not write ftbl"));
1674 yytbl_data_destroy (tbl
);
1679 yytbl_data_compress (tbl
);
1680 if (yytbl_data_fwrite (&tableswr
, tbl
) < 0)
1682 ("Could not write ecstbl"));
1683 yytbl_data_destroy (tbl
);
1696 struct yytbl_data
*tbl
;
1699 yytbl_data_compress (tbl
);
1700 if (yytbl_data_fwrite (&tableswr
, tbl
) < 0)
1701 flexerror (_("Could not write eoltbl"));
1702 yytbl_data_destroy (tbl
);
1707 /* Definitions for backing up. We don't need them if REJECT
1708 * is being used because then we use an alternative backin-up
1709 * technique instead.
1711 if (num_backing_up
> 0 && !reject
) {
1712 if (!C_plus_plus
&& !reentrant
) {
1714 ("static yy_state_type yy_last_accepting_state;");
1716 ("static char *yy_last_accepting_cpos;\n");
1721 flex_int32_t
*yynultrans_data
= 0;
1723 /* Begin generating yy_NUL_trans */
1724 out_str_dec (get_state_decl (), "yy_NUL_trans",
1726 buf_prints (&yydmap_buf
,
1727 "\t{YYTD_ID_NUL_TRANS, (void**)&yy_NUL_trans, sizeof(%s)},\n",
1728 (fullspd
) ? "struct yy_trans_info*" :
1732 (struct yytbl_data
*) calloc (1,
1735 yytbl_data_init (yynultrans_tbl
, YYTD_ID_NUL_TRANS
);
1737 yynultrans_tbl
->td_flags
|= YYTD_PTRANS
;
1738 yynultrans_tbl
->td_lolen
= lastdfa
+ 1;
1739 yynultrans_tbl
->td_data
= yynultrans_data
=
1740 (flex_int32_t
*) calloc (yynultrans_tbl
->td_lolen
,
1741 sizeof (flex_int32_t
));
1743 for (i
= 1; i
<= lastdfa
; ++i
) {
1745 out_dec (" &yy_transition[%d],\n",
1747 yynultrans_data
[i
] = base
[i
];
1750 mkdata (nultrans
[i
]);
1751 yynultrans_data
[i
] = nultrans
[i
];
1757 yytbl_data_compress (yynultrans_tbl
);
1758 if (yytbl_data_fwrite (&tableswr
, yynultrans_tbl
) <
1761 ("Could not write yynultrans_tbl"));
1762 yytbl_data_destroy (yynultrans_tbl
);
1763 yynultrans_tbl
= NULL
;
1765 /* End generating yy_NUL_trans */
1768 if (!C_plus_plus
&& !reentrant
) {
1769 indent_puts ("extern int yy_flex_debug;");
1770 indent_put2s ("int yy_flex_debug = %s;\n",
1771 ddebug
? "1" : "0");
1774 if (ddebug
) { /* Spit out table mapping rules to line numbers. */
1775 out_str_dec (long_align
? get_int32_decl () :
1776 get_int16_decl (), "yy_rule_linenum",
1778 for (i
= 1; i
< num_rules
; ++i
)
1779 mkdata (rule_linenum
[i
]);
1784 outn ("m4_ifdef( [[M4_YY_USES_REJECT]],\n[[");
1785 /* Declare state buffer variables. */
1786 if (!C_plus_plus
&& !reentrant
) {
1787 outn ("static yy_state_type *yy_state_buf=0, *yy_state_ptr=0;");
1788 outn ("static char *yy_full_match;");
1789 outn ("static int yy_lp;");
1792 if (variable_trailing_context_rules
) {
1793 if (!C_plus_plus
&& !reentrant
) {
1794 outn ("static int yy_looking_for_trail_begin = 0;");
1795 outn ("static int yy_full_lp;");
1796 outn ("static int *yy_full_state;");
1799 out_hex ("#define YY_TRAILING_MASK 0x%x\n",
1800 (unsigned int) YY_TRAILING_MASK
);
1801 out_hex ("#define YY_TRAILING_HEAD_MASK 0x%x\n",
1802 (unsigned int) YY_TRAILING_HEAD_MASK
);
1805 outn ("#define REJECT \\");
1807 outn ("*yy_cp = YY_G(yy_hold_char); /* undo effects of setting up yytext */ \\");
1808 outn ("yy_cp = YY_G(yy_full_match); /* restore poss. backed-over text */ \\");
1810 if (variable_trailing_context_rules
) {
1811 outn ("YY_G(yy_lp) = YY_G(yy_full_lp); /* restore orig. accepting pos. */ \\");
1812 outn ("YY_G(yy_state_ptr) = YY_G(yy_full_state); /* restore orig. state */ \\");
1813 outn ("yy_current_state = *YY_G(yy_state_ptr); /* restore curr. state */ \\");
1816 outn ("++YY_G(yy_lp); \\");
1817 outn ("goto find_rule; \\");
1824 outn ("/* The intent behind this definition is that it'll catch");
1825 outn (" * any uses of REJECT which flex missed.");
1827 outn ("#define REJECT reject_used_but_not_detected");
1832 if (yytext_is_array
) {
1834 indent_puts ("static int yy_more_offset = 0;");
1835 indent_puts ("static int yy_prev_more_offset = 0;");
1838 else if (!reentrant
) {
1840 ("static int yy_more_flag = 0;");
1842 ("static int yy_more_len = 0;");
1846 if (yytext_is_array
) {
1848 ("#define yymore() (YY_G(yy_more_offset) = yy_flex_strlen( yytext M4_YY_CALL_LAST_ARG))");
1849 indent_puts ("#define YY_NEED_STRLEN");
1850 indent_puts ("#define YY_MORE_ADJ 0");
1852 ("#define YY_RESTORE_YY_MORE_OFFSET \\");
1854 indent_puts ("{ \\");
1856 ("YY_G(yy_more_offset) = YY_G(yy_prev_more_offset); \\");
1857 indent_puts ("yyleng -= YY_G(yy_more_offset); \\");
1863 ("#define yymore() (YY_G(yy_more_flag) = 1)");
1865 ("#define YY_MORE_ADJ YY_G(yy_more_len)");
1866 indent_puts ("#define YY_RESTORE_YY_MORE_OFFSET");
1872 ("#define yymore() yymore_used_but_not_detected");
1873 indent_puts ("#define YY_MORE_ADJ 0");
1874 indent_puts ("#define YY_RESTORE_YY_MORE_OFFSET");
1878 if (yytext_is_array
) {
1879 outn ("#ifndef YYLMAX");
1880 outn ("#define YYLMAX 8192");
1883 outn ("char yytext[YYLMAX];");
1884 outn ("char *yytext_ptr;");
1890 outn ("char *yytext;");
1894 out (&action_array
[defs1_offset
]);
1896 line_directive_out (stdout
, 0);
1898 skelout (); /* %% [5.0] - break point in skel */
1902 outn ("\terrno=0; \\");
1903 outn ("\twhile ( (result = read( fileno(yyin), (char *) buf, max_size )) < 0 ) \\");
1905 outn ("\t\tif( errno != EINTR) \\");
1907 outn ("\t\t\tYY_FATAL_ERROR( \"input in flex scanner failed\" ); \\");
1908 outn ("\t\t\tbreak; \\");
1910 outn ("\t\terrno=0; \\");
1911 outn ("\t\tclearerr(yyin); \\");
1916 outn ("\tif ( YY_CURRENT_BUFFER_LVALUE->yy_is_interactive ) \\");
1918 outn ("\t\tint c = '*'; \\");
1919 outn ("\t\tsize_t n; \\");
1920 outn ("\t\tfor ( n = 0; n < max_size && \\");
1921 outn ("\t\t\t (c = getc( yyin )) != EOF && c != '\\n'; ++n ) \\");
1922 outn ("\t\t\tbuf[n] = (char) c; \\");
1923 outn ("\t\tif ( c == '\\n' ) \\");
1924 outn ("\t\t\tbuf[n++] = (char) c; \\");
1925 outn ("\t\tif ( c == EOF && ferror( yyin ) ) \\");
1926 outn ("\t\t\tYY_FATAL_ERROR( \"input in flex scanner failed\" ); \\");
1927 outn ("\t\tresult = n; \\");
1931 outn ("\t\terrno=0; \\");
1932 outn ("\t\twhile ( (result = fread(buf, 1, max_size, yyin))==0 && ferror(yyin)) \\");
1933 outn ("\t\t\t{ \\");
1934 outn ("\t\t\tif( errno != EINTR) \\");
1935 outn ("\t\t\t\t{ \\");
1936 outn ("\t\t\t\tYY_FATAL_ERROR( \"input in flex scanner failed\" ); \\");
1937 outn ("\t\t\t\tbreak; \\");
1938 outn ("\t\t\t\t} \\");
1939 outn ("\t\t\terrno=0; \\");
1940 outn ("\t\t\tclearerr(yyin); \\");
1941 outn ("\t\t\t} \\");
1946 skelout (); /* %% [6.0] - break point in skel */
1948 indent_puts ("#define YY_RULE_SETUP \\");
1951 indent_puts ("if ( yyleng > 0 ) \\");
1953 indent_puts ("YY_CURRENT_BUFFER_LVALUE->yy_at_bol = \\");
1954 indent_puts ("\t\t(yytext[yyleng - 1] == '\\n'); \\");
1957 indent_puts ("YY_USER_ACTION");
1960 skelout (); /* %% [7.0] - break point in skel */
1962 /* Copy prolog to output file. */
1963 out (&action_array
[prolog_offset
]);
1965 line_directive_out (stdout
, 0);
1967 skelout (); /* %% [8.0] - break point in skel */
1971 if (yymore_used
&& !yytext_is_array
) {
1972 indent_puts ("YY_G(yy_more_len) = 0;");
1973 indent_puts ("if ( YY_G(yy_more_flag) )");
1977 ("YY_G(yy_more_len) = YY_G(yy_c_buf_p) - YY_G(yytext_ptr);");
1978 indent_puts ("YY_G(yy_more_flag) = 0;");
1983 skelout (); /* %% [9.0] - break point in skel */
1987 /* Note, don't use any indentation. */
1991 skelout (); /* %% [10.0] - break point in skel */
1995 skelout (); /* %% [11.0] - break point in skel */
1996 outn ("m4_ifdef( [[M4_YY_USE_LINENO]],[[");
1998 ("if ( yy_act != YY_END_OF_BUFFER && yy_rule_can_match_eol[yy_act] )");
2001 indent_puts ("yy_size_t yyl;");
2003 out_str ("for ( yyl = %s; yyl < yyleng; ++yyl )\n",
2004 yymore_used
? (yytext_is_array
? "YY_G(yy_prev_more_offset)" :
2005 "YY_G(yy_more_len)") : "0");
2007 indent_puts ("if ( yytext[yyl] == '\\n' )");
2009 indent_puts ("M4_YY_INCR_LINENO();");
2016 skelout (); /* %% [12.0] - break point in skel */
2018 indent_puts ("if ( yy_flex_debug )");
2022 indent_puts ("if ( yy_act == 0 )");
2024 indent_puts (C_plus_plus
?
2025 "std::cerr << \"--scanner backing up\\n\";" :
2026 "fprintf( stderr, \"--scanner backing up\\n\" );");
2030 out_dec ("else if ( yy_act < %d )\n", num_rules
);
2035 ("std::cerr << \"--accepting rule at line \" << yy_rule_linenum[yy_act] <<");
2037 (" \"(\\\"\" << yytext << \"\\\")\\n\";");
2041 ("fprintf( stderr, \"--accepting rule at line %ld (\\\"%s\\\")\\n\",");
2044 (" (long)yy_rule_linenum[yy_act], yytext );");
2050 out_dec ("else if ( yy_act == %d )\n", num_rules
);
2055 ("std::cerr << \"--accepting default rule (\\\"\" << yytext << \"\\\")\\n\";");
2059 ("fprintf( stderr, \"--accepting default rule (\\\"%s\\\")\\n\",");
2060 indent_puts (" yytext );");
2066 out_dec ("else if ( yy_act == %d )\n", num_rules
+ 1);
2069 indent_puts (C_plus_plus
?
2070 "std::cerr << \"--(end of buffer or a NUL)\\n\";" :
2071 "fprintf( stderr, \"--(end of buffer or a NUL)\\n\" );");
2081 ("std::cerr << \"--EOF (start condition \" << YY_START << \")\\n\";");
2085 ("fprintf( stderr, \"--EOF (start condition %d)\\n\", YY_START );");
2094 /* Copy actions to output file. */
2095 skelout (); /* %% [13.0] - break point in skel */
2098 out (&action_array
[action_offset
]);
2100 line_directive_out (stdout
, 0);
2102 /* generate cases for any missing EOF rules */
2103 for (i
= 1; i
<= lastsc
; ++i
)
2106 out_str ("case YY_STATE_EOF(%s):\n", scname
[i
]);
2107 did_eof_rule
= true;
2112 indent_puts ("yyterminate();");
2117 /* Generate code for handling NUL's, if needed. */
2119 /* First, deal with backing up and setting up yy_cp if the scanner
2120 * finds that it should JAM on the NUL.
2122 skelout (); /* %% [14.0] - break point in skel */
2125 if (fullspd
|| fulltbl
)
2126 indent_puts ("yy_cp = YY_G(yy_c_buf_p);");
2128 else { /* compressed table */
2129 if (!reject
&& !interactive
) {
2130 /* Do the guaranteed-needed backing up to figure
2134 ("yy_cp = YY_G(yy_last_accepting_cpos);");
2136 ("yy_current_state = YY_G(yy_last_accepting_state);");
2140 /* Still need to initialize yy_cp, though
2141 * yy_current_state was set up by
2142 * yy_get_previous_state().
2144 indent_puts ("yy_cp = YY_G(yy_c_buf_p);");
2148 /* Generate code for yy_get_previous_state(). */
2150 skelout (); /* %% [15.0] - break point in skel */
2155 skelout (); /* %% [16.0] - break point in skel */
2156 gen_next_state (true);
2159 skelout (); /* %% [17.0] - break point in skel */
2162 skelout (); /* %% [18.0] - break point in skel */
2163 skelout (); /* %% [19.0] - break point in skel */
2164 /* Update BOL and yylineno inside of input(). */
2167 ("YY_CURRENT_BUFFER_LVALUE->yy_at_bol = (c == '\\n');");
2170 ("if ( YY_CURRENT_BUFFER_LVALUE->yy_at_bol )");
2172 indent_puts ("M4_YY_INCR_LINENO();");
2177 else if (do_yylineno
) {
2178 indent_puts ("if ( c == '\\n' )");
2180 indent_puts ("M4_YY_INCR_LINENO();");
2186 /* Copy remainder of input to output. */
2188 line_directive_out (stdout
, 1);
2192 (void) flexscan (); /* copy remainder of input to output */