1 /* $NetBSD: gen.c,v 1.4 2009/10/27 01:44:01 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 */
40 /* declare functions that have forward references */
42 void gen_next_state
PROTO ((int));
43 void genecs
PROTO ((void));
44 void indent_put2s
PROTO ((const char *, const char *));
45 void indent_puts
PROTO ((const char *));
48 static int indent_level
= 0; /* each level is 8 spaces */
50 #define indent_up() (++indent_level)
51 #define indent_down() (--indent_level)
52 #define set_indent(indent_val) indent_level = indent_val
54 /* Almost everything is done in terms of arrays starting at 1, so provide
55 * a null entry for the zero element of all C arrays. (The exception
56 * to this is that the fast table representation generally uses the
57 * 0 elements of its arrays, too.)
60 static const char *get_int16_decl (void)
63 ? "static yyconst flex_int16_t %s[%d] =\n { 0,\n"
64 : "static yyconst flex_int16_t * %s = 0;\n";
68 static const char *get_int32_decl (void)
71 ? "static yyconst flex_int32_t %s[%d] =\n { 0,\n"
72 : "static yyconst flex_int32_t * %s = 0;\n";
75 static const char *get_state_decl (void)
78 ? "static yyconst yy_state_type %s[%d] =\n { 0,\n"
79 : "static yyconst yy_state_type * %s = 0;\n";
82 /* Indent to the current level. */
86 register int i
= indent_level
* 8;
100 /** Make the table for possible eol matches.
101 * @return the newly allocated rule_can_match_eol table
103 static struct yytbl_data
*mkeoltbl (void)
106 flex_int8_t
*tdata
= 0;
107 struct yytbl_data
*tbl
;
109 tbl
= (struct yytbl_data
*) calloc (1, sizeof (struct yytbl_data
));
110 yytbl_data_init (tbl
, YYTD_ID_RULE_CAN_MATCH_EOL
);
111 tbl
->td_flags
= YYTD_DATA8
;
112 tbl
->td_lolen
= num_rules
+ 1;
113 tbl
->td_data
= tdata
=
114 (flex_int8_t
*) calloc (tbl
->td_lolen
, sizeof (flex_int8_t
));
116 for (i
= 1; i
<= num_rules
; i
++)
117 tdata
[i
] = rule_has_nl
[i
] ? 1 : 0;
119 buf_prints (&yydmap_buf
,
120 "\t{YYTD_ID_RULE_CAN_MATCH_EOL, (void**)&yy_rule_can_match_eol, sizeof(%s)},\n",
125 /* Generate the table for possible eol matches. */
126 static void geneoltbl (void)
130 outn ("m4_ifdef( [[M4_YY_USE_LINENO]],[[");
131 outn ("/* Table of booleans, true if rule could match eol. */");
132 out_str_dec (get_int32_decl (), "yy_rule_can_match_eol",
136 for (i
= 1; i
<= num_rules
; i
++) {
137 out_dec ("%d, ", rule_has_nl
[i
] ? 1 : 0);
138 /* format nicely, 20 numbers per line. */
148 /* Generate the code to keep backing-up information. */
150 void gen_backing_up ()
152 if (reject
|| num_backing_up
== 0)
156 indent_puts ("if ( yy_current_state[-1].yy_nxt )");
158 indent_puts ("if ( yy_accept[yy_current_state] )");
162 indent_puts ("YY_G(yy_last_accepting_state) = yy_current_state;");
163 indent_puts ("YY_G(yy_last_accepting_cpos) = yy_cp;");
169 /* Generate the code to perform the backing up. */
171 void gen_bu_action ()
173 if (reject
|| num_backing_up
== 0)
178 indent_puts ("case 0: /* must back up */");
179 indent_puts ("/* undo the effects of YY_DO_BEFORE_ACTION */");
180 indent_puts ("*yy_cp = YY_G(yy_hold_char);");
182 if (fullspd
|| fulltbl
)
183 indent_puts ("yy_cp = YY_G(yy_last_accepting_cpos) + 1;");
185 /* Backing-up info for compressed tables is taken \after/
186 * yy_cp has been incremented for the next state.
188 indent_puts ("yy_cp = YY_G(yy_last_accepting_cpos);");
190 indent_puts ("yy_current_state = YY_G(yy_last_accepting_state);");
191 indent_puts ("goto yy_find_action;");
197 /** mkctbl - make full speed compressed transition table
198 * This is an array of structs; each struct a pair of integers.
199 * You should call mkssltbl() immediately after this.
200 * Then, I think, mkecstbl(). Arrrg.
201 * @return the newly allocated trans table
204 static struct yytbl_data
*mkctbl (void)
207 struct yytbl_data
*tbl
= 0;
208 flex_int32_t
*tdata
= 0, curr
= 0;
209 int end_of_buffer_action
= num_rules
+ 1;
211 buf_prints (&yydmap_buf
,
212 "\t{YYTD_ID_TRANSITION, (void**)&yy_transition, sizeof(%s)},\n",
213 ((tblend
+ numecs
+ 1) >= INT16_MAX
214 || long_align
) ? "flex_int32_t" : "flex_int16_t");
216 tbl
= (struct yytbl_data
*) calloc (1, sizeof (struct yytbl_data
));
217 yytbl_data_init (tbl
, YYTD_ID_TRANSITION
);
218 tbl
->td_flags
= YYTD_DATA32
| YYTD_STRUCT
;
220 tbl
->td_lolen
= tblend
+ numecs
+ 1; /* number of structs */
222 tbl
->td_data
= tdata
=
223 (flex_int32_t
*) calloc (tbl
->td_lolen
* 2, sizeof (flex_int32_t
));
225 /* We want the transition to be represented as the offset to the
226 * next state, not the actual state number, which is what it currently
227 * is. The offset is base[nxt[i]] - (base of current state)]. That's
228 * just the difference between the starting points of the two involved
229 * states (to - from).
231 * First, though, we need to find some way to put in our end-of-buffer
232 * flags and states. We do this by making a state with absolutely no
233 * transitions. We put it at the end of the table.
236 /* We need to have room in nxt/chk for two more slots: One for the
237 * action and one for the end-of-buffer transition. We now *assume*
238 * that we're guaranteed the only character we'll try to index this
239 * nxt/chk pair with is EOB, i.e., 0, so we don't have to make sure
240 * there's room for jam entries for other characters.
243 while (tblend
+ 2 >= current_max_xpairs
)
246 while (lastdfa
+ 1 >= current_max_dfas
)
247 increase_max_dfas ();
249 base
[lastdfa
+ 1] = tblend
+ 2;
250 nxt
[tblend
+ 1] = end_of_buffer_action
;
251 chk
[tblend
+ 1] = numecs
+ 1;
252 chk
[tblend
+ 2] = 1; /* anything but EOB */
254 /* So that "make test" won't show arb. differences. */
257 /* Make sure every state has an end-of-buffer transition and an
260 for (i
= 0; i
<= lastdfa
; ++i
) {
261 int anum
= dfaacc
[i
].dfaacc_state
;
262 int offset
= base
[i
];
264 chk
[offset
] = EOB_POSITION
;
265 chk
[offset
- 1] = ACTION_POSITION
;
266 nxt
[offset
- 1] = anum
; /* action number */
269 for (i
= 0; i
<= tblend
; ++i
) {
270 if (chk
[i
] == EOB_POSITION
) {
272 tdata
[curr
++] = base
[lastdfa
+ 1] - i
;
275 else if (chk
[i
] == ACTION_POSITION
) {
277 tdata
[curr
++] = nxt
[i
];
280 else if (chk
[i
] > numecs
|| chk
[i
] == 0) {
284 else { /* verify, transition */
286 tdata
[curr
++] = chk
[i
];
287 tdata
[curr
++] = base
[nxt
[i
]] - (i
- chk
[i
]);
292 /* Here's the final, end-of-buffer state. */
293 tdata
[curr
++] = chk
[tblend
+ 1];
294 tdata
[curr
++] = nxt
[tblend
+ 1];
296 tdata
[curr
++] = chk
[tblend
+ 2];
297 tdata
[curr
++] = nxt
[tblend
+ 2];
303 /** Make start_state_list table.
304 * @return the newly allocated start_state_list table
306 static struct yytbl_data
*mkssltbl (void)
308 struct yytbl_data
*tbl
= 0;
309 flex_int32_t
*tdata
= 0;
312 tbl
= (struct yytbl_data
*) calloc (1, sizeof (struct yytbl_data
));
313 yytbl_data_init (tbl
, YYTD_ID_START_STATE_LIST
);
314 tbl
->td_flags
= YYTD_DATA32
| YYTD_PTRANS
;
316 tbl
->td_lolen
= lastsc
* 2 + 1;
318 tbl
->td_data
= tdata
=
319 (flex_int32_t
*) calloc (tbl
->td_lolen
, sizeof (flex_int32_t
));
321 for (i
= 0; i
<= lastsc
* 2; ++i
)
324 buf_prints (&yydmap_buf
,
325 "\t{YYTD_ID_START_STATE_LIST, (void**)&yy_start_state_list, sizeof(%s)},\n",
326 "struct yy_trans_info*");
333 /* genctbl - generates full speed compressed transition table */
338 int end_of_buffer_action
= num_rules
+ 1;
340 /* Table of verify for transition and offset to next state. */
342 out_dec ("static yyconst struct yy_trans_info yy_transition[%d] =\n {\n", tblend
+ numecs
+ 1);
344 outn ("static yyconst struct yy_trans_info *yy_transition = 0;");
346 /* We want the transition to be represented as the offset to the
347 * next state, not the actual state number, which is what it currently
348 * is. The offset is base[nxt[i]] - (base of current state)]. That's
349 * just the difference between the starting points of the two involved
350 * states (to - from).
352 * First, though, we need to find some way to put in our end-of-buffer
353 * flags and states. We do this by making a state with absolutely no
354 * transitions. We put it at the end of the table.
357 /* We need to have room in nxt/chk for two more slots: One for the
358 * action and one for the end-of-buffer transition. We now *assume*
359 * that we're guaranteed the only character we'll try to index this
360 * nxt/chk pair with is EOB, i.e., 0, so we don't have to make sure
361 * there's room for jam entries for other characters.
364 while (tblend
+ 2 >= current_max_xpairs
)
367 while (lastdfa
+ 1 >= current_max_dfas
)
368 increase_max_dfas ();
370 base
[lastdfa
+ 1] = tblend
+ 2;
371 nxt
[tblend
+ 1] = end_of_buffer_action
;
372 chk
[tblend
+ 1] = numecs
+ 1;
373 chk
[tblend
+ 2] = 1; /* anything but EOB */
375 /* So that "make test" won't show arb. differences. */
378 /* Make sure every state has an end-of-buffer transition and an
381 for (i
= 0; i
<= lastdfa
; ++i
) {
382 int anum
= dfaacc
[i
].dfaacc_state
;
383 int offset
= base
[i
];
385 chk
[offset
] = EOB_POSITION
;
386 chk
[offset
- 1] = ACTION_POSITION
;
387 nxt
[offset
- 1] = anum
; /* action number */
390 for (i
= 0; i
<= tblend
; ++i
) {
391 if (chk
[i
] == EOB_POSITION
)
392 transition_struct_out (0, base
[lastdfa
+ 1] - i
);
394 else if (chk
[i
] == ACTION_POSITION
)
395 transition_struct_out (0, nxt
[i
]);
397 else if (chk
[i
] > numecs
|| chk
[i
] == 0)
398 transition_struct_out (0, 0); /* unused slot */
400 else /* verify, transition */
401 transition_struct_out (chk
[i
],
407 /* Here's the final, end-of-buffer state. */
408 transition_struct_out (chk
[tblend
+ 1], nxt
[tblend
+ 1]);
409 transition_struct_out (chk
[tblend
+ 2], nxt
[tblend
+ 2]);
414 /* Table of pointers to start states. */
416 out_dec ("static yyconst struct yy_trans_info *yy_start_state_list[%d] =\n", lastsc
* 2 + 1);
418 outn ("static yyconst struct yy_trans_info **yy_start_state_list =0;");
423 for (i
= 0; i
<= lastsc
* 2; ++i
)
424 out_dec (" &yy_transition[%d],\n", base
[i
]);
434 /* mkecstbl - Make equivalence-class tables. */
435 static struct yytbl_data
*mkecstbl (void)
438 struct yytbl_data
*tbl
= 0;
439 flex_int32_t
*tdata
= 0;
441 tbl
= (struct yytbl_data
*) calloc (1, sizeof (struct yytbl_data
));
442 yytbl_data_init (tbl
, YYTD_ID_EC
);
443 tbl
->td_flags
|= YYTD_DATA32
;
445 tbl
->td_lolen
= csize
;
447 tbl
->td_data
= tdata
=
448 (flex_int32_t
*) calloc (tbl
->td_lolen
, sizeof (flex_int32_t
));
450 for (i
= 1; i
< csize
; ++i
) {
451 ecgroup
[i
] = ABS (ecgroup
[i
]);
452 tdata
[i
] = ecgroup
[i
];
455 buf_prints (&yydmap_buf
,
456 "\t{YYTD_ID_EC, (void**)&yy_ec, sizeof(%s)},\n",
462 /* Generate equivalence-class tables. */
469 out_str_dec (get_int32_decl (), "yy_ec", csize
);
471 for (i
= 1; i
< csize
; ++i
) {
472 ecgroup
[i
] = ABS (ecgroup
[i
]);
479 fputs (_("\n\nEquivalence Classes:\n\n"), stderr
);
483 for (j
= 0; j
< numrows
; ++j
) {
484 for (i
= j
; i
< csize
; i
= i
+ numrows
) {
485 fprintf (stderr
, "%4s = %-2d",
486 readable_form (i
), ecgroup
[i
]);
497 /* Generate the code to find the action number. */
499 void gen_find_action ()
502 indent_puts ("yy_act = yy_current_state[-1].yy_nxt;");
505 indent_puts ("yy_act = yy_accept[yy_current_state];");
508 indent_puts ("yy_current_state = *--YY_G(yy_state_ptr);");
509 indent_puts ("YY_G(yy_lp) = yy_accept[yy_current_state];");
511 if (!variable_trailing_context_rules
)
512 outn ("#ifdef YY_USES_REJECT");
513 outn ("find_rule: /* we branch to this label when backing up */");
514 if (!variable_trailing_context_rules
)
518 ("for ( ; ; ) /* until we find what rule we matched */");
525 ("if ( YY_G(yy_lp) && YY_G(yy_lp) < yy_accept[yy_current_state + 1] )");
528 indent_puts ("yy_act = yy_acclist[YY_G(yy_lp)];");
530 if (variable_trailing_context_rules
) {
532 ("if ( yy_act & YY_TRAILING_HEAD_MASK ||");
533 indent_puts (" YY_G(yy_looking_for_trail_begin) )");
538 ("if ( yy_act == YY_G(yy_looking_for_trail_begin) )");
541 indent_puts ("YY_G(yy_looking_for_trail_begin) = 0;");
542 indent_puts ("yy_act &= ~YY_TRAILING_HEAD_MASK;");
543 indent_puts ("break;");
551 ("else if ( yy_act & YY_TRAILING_MASK )");
555 ("YY_G(yy_looking_for_trail_begin) = yy_act & ~YY_TRAILING_MASK;");
557 ("YY_G(yy_looking_for_trail_begin) |= YY_TRAILING_HEAD_MASK;");
560 /* Remember matched text in case we back up
564 ("YY_G(yy_full_match) = yy_cp;");
566 ("YY_G(yy_full_state) = YY_G(yy_state_ptr);");
567 indent_puts ("YY_G(yy_full_lp) = YY_G(yy_lp);");
573 indent_puts ("else");
576 indent_puts ("YY_G(yy_full_match) = yy_cp;");
578 ("YY_G(yy_full_state) = YY_G(yy_state_ptr);");
579 indent_puts ("YY_G(yy_full_lp) = YY_G(yy_lp);");
580 indent_puts ("break;");
584 indent_puts ("++YY_G(yy_lp);");
585 indent_puts ("goto find_rule;");
589 /* Remember matched text in case we back up due to
590 * trailing context plus REJECT.
594 indent_puts ("YY_G(yy_full_match) = yy_cp;");
595 indent_puts ("break;");
603 indent_puts ("--yy_cp;");
605 /* We could consolidate the following two lines with those at
606 * the beginning, but at the cost of complaints that we're
607 * branching inside a loop.
609 indent_puts ("yy_current_state = *--YY_G(yy_state_ptr);");
610 indent_puts ("YY_G(yy_lp) = yy_accept[yy_current_state];");
617 else { /* compressed */
618 indent_puts ("yy_act = yy_accept[yy_current_state];");
620 if (interactive
&& !reject
) {
621 /* Do the guaranteed-needed backing up to figure out
624 indent_puts ("if ( yy_act == 0 )");
626 indent_puts ("{ /* have to back up */");
628 ("yy_cp = YY_G(yy_last_accepting_cpos);");
630 ("yy_current_state = YY_G(yy_last_accepting_state);");
632 ("yy_act = yy_accept[yy_current_state];");
639 /* mkftbl - make the full table and return the struct .
640 * you should call mkecstbl() after this.
643 struct yytbl_data
*mkftbl (void)
646 int end_of_buffer_action
= num_rules
+ 1;
647 struct yytbl_data
*tbl
;
648 flex_int32_t
*tdata
= 0;
650 tbl
= (struct yytbl_data
*) calloc (1, sizeof (struct yytbl_data
));
651 yytbl_data_init (tbl
, YYTD_ID_ACCEPT
);
652 tbl
->td_flags
|= YYTD_DATA32
;
653 tbl
->td_hilen
= 0; /* it's a one-dimensional array */
654 tbl
->td_lolen
= lastdfa
+ 1;
656 tbl
->td_data
= tdata
=
657 (flex_int32_t
*) calloc (tbl
->td_lolen
, sizeof (flex_int32_t
));
659 dfaacc
[end_of_buffer_state
].dfaacc_state
= end_of_buffer_action
;
661 for (i
= 1; i
<= lastdfa
; ++i
) {
662 register int anum
= dfaacc
[i
].dfaacc_state
;
667 fprintf (stderr
, _("state # %d accepts: [%d]\n"),
671 buf_prints (&yydmap_buf
,
672 "\t{YYTD_ID_ACCEPT, (void**)&yy_accept, sizeof(%s)},\n",
673 long_align
? "flex_int32_t" : "flex_int16_t");
678 /* genftbl - generate full transition table */
683 int end_of_buffer_action
= num_rules
+ 1;
685 out_str_dec (long_align
? get_int32_decl () : get_int16_decl (),
686 "yy_accept", lastdfa
+ 1);
688 dfaacc
[end_of_buffer_state
].dfaacc_state
= end_of_buffer_action
;
690 for (i
= 1; i
<= lastdfa
; ++i
) {
691 register int anum
= dfaacc
[i
].dfaacc_state
;
696 fprintf (stderr
, _("state # %d accepts: [%d]\n"),
705 /* Don't have to dump the actual full table entries - they were
706 * created on-the-fly.
711 /* Generate the code to find the next compressed-table state. */
713 void gen_next_compressed_state (char_map
)
716 indent_put2s ("register YY_CHAR yy_c = %s;", char_map
);
718 /* Save the backing-up info \before/ computing the next state
719 * because we always compute one more state than needed - we
720 * always proceed until we reach a jam state
725 ("while ( yy_chk[yy_base[yy_current_state] + yy_c] != yy_current_state )");
728 indent_puts ("yy_current_state = (int) yy_def[yy_current_state];");
731 /* We've arrange it so that templates are never chained
732 * to one another. This means we can afford to make a
733 * very simple test to see if we need to convert to
734 * yy_c's meta-equivalence class without worrying
735 * about erroneously looking up the meta-equivalence
740 /* lastdfa + 2 is the beginning of the templates */
741 out_dec ("if ( yy_current_state >= %d )\n", lastdfa
+ 2);
744 indent_puts ("yy_c = yy_meta[(unsigned int) yy_c];");
752 ("yy_current_state = yy_nxt[yy_base[yy_current_state] + (unsigned int) yy_c];");
756 /* Generate the code to find the next match. */
758 void gen_next_match ()
760 /* NOTE - changes in here should be reflected in gen_next_state() and
763 char *char_map
= useecs
?
764 "yy_ec[YY_SC_TO_UI(*yy_cp)] " : "YY_SC_TO_UI(*yy_cp)";
766 char *char_map_2
= useecs
?
767 "yy_ec[YY_SC_TO_UI(*++yy_cp)] " : "YY_SC_TO_UI(*++yy_cp)";
772 ("while ( (yy_current_state = yy_nxt[yy_current_state][ %s ]) > 0 )",
776 ("while ( (yy_current_state = yy_nxt[yy_current_state*YY_NXT_LOLEN + %s ]) > 0 )",
781 if (num_backing_up
> 0) {
787 indent_puts ("++yy_cp;");
789 if (num_backing_up
> 0)
796 indent_puts ("yy_current_state = -yy_current_state;");
802 ("register yyconst struct yy_trans_info *yy_trans_info;\n");
803 indent_puts ("register YY_CHAR yy_c;\n");
804 indent_put2s ("for ( yy_c = %s;", char_map
);
806 (" (yy_trans_info = &yy_current_state[(unsigned int) yy_c])->");
807 indent_puts ("yy_verify == yy_c;");
808 indent_put2s (" yy_c = %s )", char_map_2
);
812 if (num_backing_up
> 0)
815 indent_puts ("yy_current_state += yy_trans_info->yy_nxt;");
817 if (num_backing_up
> 0) {
827 else { /* compressed */
833 gen_next_state (false);
835 indent_puts ("++yy_cp;");
844 out_dec ("while ( yy_base[yy_current_state] != %d );\n", jambase
);
846 out_dec ("while ( yy_current_state != %d );\n",
849 if (!reject
&& !interactive
) {
850 /* Do the guaranteed-needed backing up to figure out
854 ("yy_cp = YY_G(yy_last_accepting_cpos);");
856 ("yy_current_state = YY_G(yy_last_accepting_state);");
862 /* Generate the code to find the next state. */
864 void gen_next_state (worry_about_NULs
)
865 int worry_about_NULs
;
866 { /* NOTE - changes in here should be reflected in gen_next_match() */
869 if (worry_about_NULs
&& !nultrans
) {
871 snprintf (char_map
, sizeof(char_map
),
872 "(*yy_cp ? yy_ec[YY_SC_TO_UI(*yy_cp)] : %d)",
875 snprintf (char_map
, sizeof(char_map
),
876 "(*yy_cp ? YY_SC_TO_UI(*yy_cp) : %d)",
881 strcpy (char_map
, useecs
?
882 "yy_ec[YY_SC_TO_UI(*yy_cp)]" :
883 "YY_SC_TO_UI(*yy_cp)");
885 if (worry_about_NULs
&& nultrans
) {
886 if (!fulltbl
&& !fullspd
)
887 /* Compressed tables back up *before* they match. */
890 indent_puts ("if ( *yy_cp )");
898 ("yy_current_state = yy_nxt[yy_current_state][%s];",
902 ("yy_current_state = yy_nxt[yy_current_state*YY_NXT_LOLEN + %s];",
908 ("yy_current_state += yy_current_state[%s].yy_nxt;",
912 gen_next_compressed_state (char_map
);
914 if (worry_about_NULs
&& nultrans
) {
918 indent_puts ("else");
921 ("yy_current_state = yy_NUL_trans[yy_current_state];");
925 if (fullspd
|| fulltbl
)
929 indent_puts ("*YY_G(yy_state_ptr)++ = yy_current_state;");
933 /* Generate the code to make a NUL transition. */
935 void gen_NUL_trans ()
936 { /* NOTE - changes in here should be reflected in gen_next_match() */
937 /* Only generate a definition for "yy_cp" if we'll generate code
938 * that uses it. Otherwise lint and the like complain.
940 int need_backing_up
= (num_backing_up
> 0 && !reject
);
942 if (need_backing_up
&& (!nultrans
|| fullspd
|| fulltbl
))
943 /* We're going to need yy_cp lying around for the call
944 * below to gen_backing_up().
946 indent_puts ("register char *yy_cp = YY_G(yy_c_buf_p);");
952 ("yy_current_state = yy_NUL_trans[yy_current_state];");
953 indent_puts ("yy_is_jam = (yy_current_state == 0);");
959 out_dec ("yy_current_state = yy_nxt[yy_current_state][%d];\n", NUL_ec
);
961 out_dec ("yy_current_state = yy_nxt[yy_current_state*YY_NXT_LOLEN + %d];\n", NUL_ec
);
962 indent_puts ("yy_is_jam = (yy_current_state <= 0);");
967 out_dec ("register int yy_c = %d;\n", NUL_ec
);
970 ("register yyconst struct yy_trans_info *yy_trans_info;\n");
972 ("yy_trans_info = &yy_current_state[(unsigned int) yy_c];");
973 indent_puts ("yy_current_state += yy_trans_info->yy_nxt;");
976 ("yy_is_jam = (yy_trans_info->yy_verify != yy_c);");
982 snprintf (NUL_ec_str
, sizeof(NUL_ec_str
), "%d", NUL_ec
);
983 gen_next_compressed_state (NUL_ec_str
);
986 out_dec ("yy_is_jam = (yy_current_state == %d);\n",
990 /* Only stack this state if it's a transition we
991 * actually make. If we stack it on a jam, then
992 * the state stack and yy_c_buf_p get out of sync.
994 indent_puts ("if ( ! yy_is_jam )");
997 ("*YY_G(yy_state_ptr)++ = yy_current_state;");
1002 /* If we've entered an accepting state, back up; note that
1003 * compressed tables have *already* done such backing up, so
1004 * we needn't bother with it again.
1006 if (need_backing_up
&& (fullspd
|| fulltbl
)) {
1008 indent_puts ("if ( ! yy_is_jam )");
1018 /* Generate the code to find the start state. */
1020 void gen_start_state ()
1025 ("yy_current_state = yy_start_state_list[YY_G(yy_start) + YY_AT_BOL()];");
1029 ("yy_current_state = yy_start_state_list[YY_G(yy_start)];");
1033 indent_puts ("yy_current_state = YY_G(yy_start);");
1036 indent_puts ("yy_current_state += YY_AT_BOL();");
1039 /* Set up for storing up states. */
1040 outn ("m4_ifdef( [[M4_YY_USES_REJECT]],\n[[");
1042 ("YY_G(yy_state_ptr) = YY_G(yy_state_buf);");
1044 ("*YY_G(yy_state_ptr)++ = yy_current_state;");
1051 /* gentabs - generate data statements for the transition tables */
1055 int i
, j
, k
, *accset
, nacc
, *acc_array
, total_states
;
1056 int end_of_buffer_action
= num_rules
+ 1;
1057 struct yytbl_data
*yyacc_tbl
= 0, *yymeta_tbl
= 0, *yybase_tbl
= 0,
1058 *yydef_tbl
= 0, *yynxt_tbl
= 0, *yychk_tbl
= 0, *yyacclist_tbl
=0;
1059 flex_int32_t
*yyacc_data
= 0, *yybase_data
= 0, *yydef_data
= 0,
1060 *yynxt_data
= 0, *yychk_data
= 0, *yyacclist_data
=0;
1061 flex_int32_t yybase_curr
= 0, yyacclist_curr
=0,yyacc_curr
=0;
1063 acc_array
= allocate_integer_array (current_max_dfas
);
1066 /* The compressed table format jams by entering the "jam state",
1067 * losing information about the previous state in the process.
1068 * In order to recover the previous state, we effectively need
1069 * to keep backing-up information.
1074 /* Write out accepting list and pointer list.
1076 * First we generate the "yy_acclist" array. In the process,
1077 * we compute the indices that will go into the "yy_accept"
1078 * array, and save the indices in the dfaacc array.
1080 int EOB_accepting_list
[2];
1082 /* Set up accepting structures for the End Of Buffer state. */
1083 EOB_accepting_list
[0] = 0;
1084 EOB_accepting_list
[1] = end_of_buffer_action
;
1085 accsiz
[end_of_buffer_state
] = 1;
1086 dfaacc
[end_of_buffer_state
].dfaacc_set
=
1089 out_str_dec (long_align
? get_int32_decl () :
1090 get_int16_decl (), "yy_acclist", MAX (numas
,
1093 buf_prints (&yydmap_buf
,
1094 "\t{YYTD_ID_ACCLIST, (void**)&yy_acclist, sizeof(%s)},\n",
1095 long_align
? "flex_int32_t" : "flex_int16_t");
1097 yyacclist_tbl
= (struct yytbl_data
*)calloc(1,sizeof(struct yytbl_data
));
1098 yytbl_data_init (yyacclist_tbl
, YYTD_ID_ACCLIST
);
1099 yyacclist_tbl
->td_lolen
= MAX(numas
,1) + 1;
1100 yyacclist_tbl
->td_data
= yyacclist_data
=
1101 (flex_int32_t
*) calloc (yyacclist_tbl
->td_lolen
, sizeof (flex_int32_t
));
1104 j
= 1; /* index into "yy_acclist" array */
1106 for (i
= 1; i
<= lastdfa
; ++i
) {
1109 if (accsiz
[i
] != 0) {
1110 accset
= dfaacc
[i
].dfaacc_set
;
1115 _("state # %d accepts: "),
1118 for (k
= 1; k
<= nacc
; ++k
) {
1119 int accnum
= accset
[k
];
1123 if (variable_trailing_context_rules
1125 YY_TRAILING_HEAD_MASK
)
1127 && accnum
<= num_rules
1128 && rule_type
[accnum
] ==
1130 /* Special hack to flag
1131 * accepting number as part
1132 * of trailing context rule.
1134 accnum
|= YY_TRAILING_MASK
;
1138 yyacclist_data
[yyacclist_curr
++] = accnum
;
1141 fprintf (stderr
, "[%d]",
1155 /* add accepting number for the "jam" state */
1160 yytbl_data_compress (yyacclist_tbl
);
1161 if (yytbl_data_fwrite (&tableswr
, yyacclist_tbl
) < 0)
1162 flexerror (_("Could not write yyacclist_tbl"));
1163 yytbl_data_destroy (yyacclist_tbl
);
1164 yyacclist_tbl
= NULL
;
1169 dfaacc
[end_of_buffer_state
].dfaacc_state
=
1170 end_of_buffer_action
;
1172 for (i
= 1; i
<= lastdfa
; ++i
)
1173 acc_array
[i
] = dfaacc
[i
].dfaacc_state
;
1175 /* add accepting number for jam state */
1179 /* Begin generating yy_accept */
1181 /* Spit out "yy_accept" array. If we're doing "reject", it'll be
1182 * pointers into the "yy_acclist" array. Otherwise it's actual
1183 * accepting numbers. In either case, we just dump the numbers.
1186 /* "lastdfa + 2" is the size of "yy_accept"; includes room for C arrays
1187 * beginning at 0 and for "jam" state.
1192 /* We put a "cap" on the table associating lists of accepting
1193 * numbers with state numbers. This is needed because we tell
1194 * where the end of an accepting list is by looking at where
1195 * the list for the next state starts.
1199 out_str_dec (long_align
? get_int32_decl () : get_int16_decl (),
1202 buf_prints (&yydmap_buf
,
1203 "\t{YYTD_ID_ACCEPT, (void**)&yy_accept, sizeof(%s)},\n",
1204 long_align
? "flex_int32_t" : "flex_int16_t");
1207 (struct yytbl_data
*) calloc (1,
1208 sizeof (struct yytbl_data
));
1209 yytbl_data_init (yyacc_tbl
, YYTD_ID_ACCEPT
);
1210 yyacc_tbl
->td_lolen
= k
;
1211 yyacc_tbl
->td_data
= yyacc_data
=
1212 (flex_int32_t
*) calloc (yyacc_tbl
->td_lolen
, sizeof (flex_int32_t
));
1215 for (i
= 1; i
<= lastdfa
; ++i
) {
1216 mkdata (acc_array
[i
]);
1217 yyacc_data
[yyacc_curr
++] = acc_array
[i
];
1219 if (!reject
&& trace
&& acc_array
[i
])
1220 fprintf (stderr
, _("state # %d accepts: [%d]\n"),
1224 /* Add entry for "jam" state. */
1225 mkdata (acc_array
[i
]);
1226 yyacc_data
[yyacc_curr
++] = acc_array
[i
];
1229 /* Add "cap" for the list. */
1230 mkdata (acc_array
[i
]);
1231 yyacc_data
[yyacc_curr
++] = acc_array
[i
];
1236 yytbl_data_compress (yyacc_tbl
);
1237 if (yytbl_data_fwrite (&tableswr
, yyacc_tbl
) < 0)
1238 flexerror (_("Could not write yyacc_tbl"));
1239 yytbl_data_destroy (yyacc_tbl
);
1242 /* End generating yy_accept */
1248 struct yytbl_data
*tbl
;
1251 yytbl_data_compress (tbl
);
1252 if (yytbl_data_fwrite (&tableswr
, tbl
) < 0)
1253 flexerror (_("Could not write ecstbl"));
1254 yytbl_data_destroy (tbl
);
1260 /* Begin generating yy_meta */
1261 /* Write out meta-equivalence classes (used to index
1264 flex_int32_t
*yymecs_data
= 0;
1266 (struct yytbl_data
*) calloc (1,
1269 yytbl_data_init (yymeta_tbl
, YYTD_ID_META
);
1270 yymeta_tbl
->td_lolen
= numecs
+ 1;
1271 yymeta_tbl
->td_data
= yymecs_data
=
1272 (flex_int32_t
*) calloc (yymeta_tbl
->td_lolen
,
1273 sizeof (flex_int32_t
));
1276 fputs (_("\n\nMeta-Equivalence Classes:\n"),
1279 out_str_dec (get_int32_decl (), "yy_meta", numecs
+ 1);
1280 buf_prints (&yydmap_buf
,
1281 "\t{YYTD_ID_META, (void**)&yy_meta, sizeof(%s)},\n",
1284 for (i
= 1; i
<= numecs
; ++i
) {
1286 fprintf (stderr
, "%d = %d\n",
1287 i
, ABS (tecbck
[i
]));
1289 mkdata (ABS (tecbck
[i
]));
1290 yymecs_data
[i
] = ABS (tecbck
[i
]);
1295 yytbl_data_compress (yymeta_tbl
);
1296 if (yytbl_data_fwrite (&tableswr
, yymeta_tbl
) < 0)
1298 ("Could not write yymeta_tbl"));
1299 yytbl_data_destroy (yymeta_tbl
);
1302 /* End generating yy_meta */
1305 total_states
= lastdfa
+ numtemps
;
1307 /* Begin generating yy_base */
1308 out_str_dec ((tblend
>= INT16_MAX
|| long_align
) ?
1309 get_int32_decl () : get_int16_decl (),
1310 "yy_base", total_states
+ 1);
1312 buf_prints (&yydmap_buf
,
1313 "\t{YYTD_ID_BASE, (void**)&yy_base, sizeof(%s)},\n",
1314 (tblend
>= INT16_MAX
1315 || long_align
) ? "flex_int32_t" : "flex_int16_t");
1317 (struct yytbl_data
*) calloc (1,
1318 sizeof (struct yytbl_data
));
1319 yytbl_data_init (yybase_tbl
, YYTD_ID_BASE
);
1320 yybase_tbl
->td_lolen
= total_states
+ 1;
1321 yybase_tbl
->td_data
= yybase_data
=
1322 (flex_int32_t
*) calloc (yybase_tbl
->td_lolen
,
1323 sizeof (flex_int32_t
));
1326 for (i
= 1; i
<= lastdfa
; ++i
) {
1327 register int d
= def
[i
];
1329 if (base
[i
] == JAMSTATE
)
1336 /* Template reference. */
1338 def
[i
] = lastdfa
- d
+ 1;
1342 yybase_data
[yybase_curr
++] = base
[i
];
1345 /* Generate jam state's base index. */
1347 yybase_data
[yybase_curr
++] = base
[i
];
1349 for (++i
/* skip jam state */ ; i
<= total_states
; ++i
) {
1351 yybase_data
[yybase_curr
++] = base
[i
];
1357 yytbl_data_compress (yybase_tbl
);
1358 if (yytbl_data_fwrite (&tableswr
, yybase_tbl
) < 0)
1359 flexerror (_("Could not write yybase_tbl"));
1360 yytbl_data_destroy (yybase_tbl
);
1363 /* End generating yy_base */
1366 /* Begin generating yy_def */
1367 out_str_dec ((total_states
>= INT16_MAX
|| long_align
) ?
1368 get_int32_decl () : get_int16_decl (),
1369 "yy_def", total_states
+ 1);
1371 buf_prints (&yydmap_buf
,
1372 "\t{YYTD_ID_DEF, (void**)&yy_def, sizeof(%s)},\n",
1373 (total_states
>= INT16_MAX
1374 || long_align
) ? "flex_int32_t" : "flex_int16_t");
1377 (struct yytbl_data
*) calloc (1,
1378 sizeof (struct yytbl_data
));
1379 yytbl_data_init (yydef_tbl
, YYTD_ID_DEF
);
1380 yydef_tbl
->td_lolen
= total_states
+ 1;
1381 yydef_tbl
->td_data
= yydef_data
=
1382 (flex_int32_t
*) calloc (yydef_tbl
->td_lolen
, sizeof (flex_int32_t
));
1384 for (i
= 1; i
<= total_states
; ++i
) {
1386 yydef_data
[i
] = def
[i
];
1391 yytbl_data_compress (yydef_tbl
);
1392 if (yytbl_data_fwrite (&tableswr
, yydef_tbl
) < 0)
1393 flexerror (_("Could not write yydef_tbl"));
1394 yytbl_data_destroy (yydef_tbl
);
1397 /* End generating yy_def */
1400 /* Begin generating yy_nxt */
1401 out_str_dec ((total_states
>= INT16_MAX
|| long_align
) ?
1402 get_int32_decl () : get_int16_decl (), "yy_nxt",
1405 buf_prints (&yydmap_buf
,
1406 "\t{YYTD_ID_NXT, (void**)&yy_nxt, sizeof(%s)},\n",
1407 (total_states
>= INT16_MAX
1408 || long_align
) ? "flex_int32_t" : "flex_int16_t");
1411 (struct yytbl_data
*) calloc (1,
1412 sizeof (struct yytbl_data
));
1413 yytbl_data_init (yynxt_tbl
, YYTD_ID_NXT
);
1414 yynxt_tbl
->td_lolen
= tblend
+ 1;
1415 yynxt_tbl
->td_data
= yynxt_data
=
1416 (flex_int32_t
*) calloc (yynxt_tbl
->td_lolen
, sizeof (flex_int32_t
));
1418 for (i
= 1; i
<= tblend
; ++i
) {
1419 /* Note, the order of the following test is important.
1420 * If chk[i] is 0, then nxt[i] is undefined.
1422 if (chk
[i
] == 0 || nxt
[i
] == 0)
1423 nxt
[i
] = jamstate
; /* new state is the JAM state */
1426 yynxt_data
[i
] = nxt
[i
];
1431 yytbl_data_compress (yynxt_tbl
);
1432 if (yytbl_data_fwrite (&tableswr
, yynxt_tbl
) < 0)
1433 flexerror (_("Could not write yynxt_tbl"));
1434 yytbl_data_destroy (yynxt_tbl
);
1437 /* End generating yy_nxt */
1439 /* Begin generating yy_chk */
1440 out_str_dec ((total_states
>= INT16_MAX
|| long_align
) ?
1441 get_int32_decl () : get_int16_decl (), "yy_chk",
1444 buf_prints (&yydmap_buf
,
1445 "\t{YYTD_ID_CHK, (void**)&yy_chk, sizeof(%s)},\n",
1446 (total_states
>= INT16_MAX
1447 || long_align
) ? "flex_int32_t" : "flex_int16_t");
1450 (struct yytbl_data
*) calloc (1,
1451 sizeof (struct yytbl_data
));
1452 yytbl_data_init (yychk_tbl
, YYTD_ID_CHK
);
1453 yychk_tbl
->td_lolen
= tblend
+ 1;
1454 yychk_tbl
->td_data
= yychk_data
=
1455 (flex_int32_t
*) calloc (yychk_tbl
->td_lolen
, sizeof (flex_int32_t
));
1457 for (i
= 1; i
<= tblend
; ++i
) {
1462 yychk_data
[i
] = chk
[i
];
1467 yytbl_data_compress (yychk_tbl
);
1468 if (yytbl_data_fwrite (&tableswr
, yychk_tbl
) < 0)
1469 flexerror (_("Could not write yychk_tbl"));
1470 yytbl_data_destroy (yychk_tbl
);
1473 /* End generating yy_chk */
1475 flex_free ((void *) acc_array
);
1479 /* Write out a formatted string (with a secondary string argument) at the
1480 * current indentation level, adding a final newline.
1483 void indent_put2s (fmt
, arg
)
1484 const char *fmt
, *arg
;
1492 /* Write out a string at the current indentation level, adding a final
1496 void indent_puts (str
)
1504 /* make_tables - generate transition tables and finishes generating output file
1510 int did_eof_rule
= false;
1511 struct yytbl_data
*yynultrans_tbl
;
1514 skelout (); /* %% [2.0] - break point in skel */
1516 /* First, take care of YY_DO_BEFORE_ACTION depending on yymore
1521 if (yymore_used
&& !yytext_is_array
) {
1522 indent_puts ("YY_G(yytext_ptr) -= YY_G(yy_more_len); \\");
1524 ("yyleng = (size_t) (yy_cp - YY_G(yytext_ptr)); \\");
1528 indent_puts ("yyleng = (size_t) (yy_cp - yy_bp); \\");
1530 /* Now also deal with copying yytext_ptr to yytext if needed. */
1531 skelout (); /* %% [3.0] - break point in skel */
1532 if (yytext_is_array
) {
1535 ("if ( yyleng + YY_G(yy_more_offset) >= YYLMAX ) \\");
1537 indent_puts ("if ( yyleng >= YYLMAX ) \\");
1541 ("YY_FATAL_ERROR( \"token too large, exceeds YYLMAX\" ); \\");
1546 ("yy_flex_strncpy( &yytext[YY_G(yy_more_offset)], YY_G(yytext_ptr), yyleng + 1 M4_YY_CALL_LAST_ARG); \\");
1547 indent_puts ("yyleng += YY_G(yy_more_offset); \\");
1549 ("YY_G(yy_prev_more_offset) = YY_G(yy_more_offset); \\");
1550 indent_puts ("YY_G(yy_more_offset) = 0; \\");
1554 ("yy_flex_strncpy( yytext, YY_G(yytext_ptr), yyleng + 1 M4_YY_CALL_LAST_ARG); \\");
1560 skelout (); /* %% [4.0] - break point in skel */
1563 /* This is where we REALLY begin generating the tables. */
1565 out_dec ("#define YY_NUM_RULES %d\n", num_rules
);
1566 out_dec ("#define YY_END_OF_BUFFER %d\n", num_rules
+ 1);
1569 /* Need to define the transet type as a size large
1570 * enough to hold the biggest offset.
1572 int total_table_size
= tblend
+ numecs
+ 1;
1573 char *trans_offset_type
=
1574 (total_table_size
>= INT16_MAX
|| long_align
) ?
1575 "flex_int32_t" : "flex_int16_t";
1578 indent_puts ("struct yy_trans_info");
1582 /* We require that yy_verify and yy_nxt must be of the same size int. */
1583 indent_put2s ("%s yy_verify;", trans_offset_type
);
1585 /* In cases where its sister yy_verify *is* a "yes, there is
1586 * a transition", yy_nxt is the offset (in records) to the
1587 * next state. In most cases where there is no transition,
1588 * the value of yy_nxt is irrelevant. If yy_nxt is the -1th
1589 * record of a state, though, then yy_nxt is the action number
1593 indent_put2s ("%s yy_nxt;", trans_offset_type
);
1598 /* We generate a bogus 'struct yy_trans_info' data type
1599 * so we can guarantee that it is always declared in the skel.
1600 * This is so we can compile "sizeof(struct yy_trans_info)"
1604 ("/* This struct is not used in this scanner,");
1605 indent_puts (" but its presence is necessary. */");
1606 indent_puts ("struct yy_trans_info");
1609 indent_puts ("flex_int32_t yy_verify;");
1610 indent_puts ("flex_int32_t yy_nxt;");
1618 struct yytbl_data
*tbl
;
1621 yytbl_data_compress (tbl
);
1622 if (yytbl_data_fwrite (&tableswr
, tbl
) < 0)
1623 flexerror (_("Could not write ftbl"));
1624 yytbl_data_destroy (tbl
);
1627 yytbl_data_compress (tbl
);
1628 if (yytbl_data_fwrite (&tableswr
, tbl
) < 0)
1629 flexerror (_("Could not write ssltbl"));
1630 yytbl_data_destroy (tbl
);
1635 yytbl_data_compress (tbl
);
1636 if (yytbl_data_fwrite (&tableswr
, tbl
) < 0)
1638 ("Could not write ecstbl"));
1639 yytbl_data_destroy (tbl
);
1647 struct yytbl_data
*tbl
;
1650 yytbl_data_compress (tbl
);
1651 if (yytbl_data_fwrite (&tableswr
, tbl
) < 0)
1652 flexerror (_("Could not write ftbl"));
1653 yytbl_data_destroy (tbl
);
1658 yytbl_data_compress (tbl
);
1659 if (yytbl_data_fwrite (&tableswr
, tbl
) < 0)
1661 ("Could not write ecstbl"));
1662 yytbl_data_destroy (tbl
);
1675 struct yytbl_data
*tbl
;
1678 yytbl_data_compress (tbl
);
1679 if (yytbl_data_fwrite (&tableswr
, tbl
) < 0)
1680 flexerror (_("Could not write eoltbl"));
1681 yytbl_data_destroy (tbl
);
1686 /* Definitions for backing up. We don't need them if REJECT
1687 * is being used because then we use an alternative backin-up
1688 * technique instead.
1690 if (num_backing_up
> 0 && !reject
) {
1691 if (!C_plus_plus
&& !reentrant
) {
1693 ("static yy_state_type yy_last_accepting_state;");
1695 ("static char *yy_last_accepting_cpos;\n");
1700 flex_int32_t
*yynultrans_data
= 0;
1702 /* Begin generating yy_NUL_trans */
1703 out_str_dec (get_state_decl (), "yy_NUL_trans",
1705 buf_prints (&yydmap_buf
,
1706 "\t{YYTD_ID_NUL_TRANS, (void**)&yy_NUL_trans, sizeof(%s)},\n",
1707 (fullspd
) ? "struct yy_trans_info*" :
1711 (struct yytbl_data
*) calloc (1,
1714 yytbl_data_init (yynultrans_tbl
, YYTD_ID_NUL_TRANS
);
1716 yynultrans_tbl
->td_flags
|= YYTD_PTRANS
;
1717 yynultrans_tbl
->td_lolen
= lastdfa
+ 1;
1718 yynultrans_tbl
->td_data
= yynultrans_data
=
1719 (flex_int32_t
*) calloc (yynultrans_tbl
->td_lolen
,
1720 sizeof (flex_int32_t
));
1722 for (i
= 1; i
<= lastdfa
; ++i
) {
1724 out_dec (" &yy_transition[%d],\n",
1726 yynultrans_data
[i
] = base
[i
];
1729 mkdata (nultrans
[i
]);
1730 yynultrans_data
[i
] = nultrans
[i
];
1736 yytbl_data_compress (yynultrans_tbl
);
1737 if (yytbl_data_fwrite (&tableswr
, yynultrans_tbl
) <
1740 ("Could not write yynultrans_tbl"));
1741 yytbl_data_destroy (yynultrans_tbl
);
1742 yynultrans_tbl
= NULL
;
1744 /* End generating yy_NUL_trans */
1747 if (!C_plus_plus
&& !reentrant
) {
1748 indent_puts ("extern int yy_flex_debug;");
1749 indent_put2s ("int yy_flex_debug = %s;\n",
1750 ddebug
? "1" : "0");
1753 if (ddebug
) { /* Spit out table mapping rules to line numbers. */
1754 out_str_dec (long_align
? get_int32_decl () :
1755 get_int16_decl (), "yy_rule_linenum",
1757 for (i
= 1; i
< num_rules
; ++i
)
1758 mkdata (rule_linenum
[i
]);
1763 outn ("m4_ifdef( [[M4_YY_USES_REJECT]],\n[[");
1764 /* Declare state buffer variables. */
1765 if (!C_plus_plus
&& !reentrant
) {
1766 outn ("static yy_state_type *yy_state_buf=0, *yy_state_ptr=0;");
1767 outn ("static char *yy_full_match;");
1768 outn ("static int yy_lp;");
1771 if (variable_trailing_context_rules
) {
1772 if (!C_plus_plus
&& !reentrant
) {
1773 outn ("static int yy_looking_for_trail_begin = 0;");
1774 outn ("static int yy_full_lp;");
1775 outn ("static int *yy_full_state;");
1778 out_hex ("#define YY_TRAILING_MASK 0x%x\n",
1779 (unsigned int) YY_TRAILING_MASK
);
1780 out_hex ("#define YY_TRAILING_HEAD_MASK 0x%x\n",
1781 (unsigned int) YY_TRAILING_HEAD_MASK
);
1784 outn ("#define REJECT \\");
1786 outn ("*yy_cp = YY_G(yy_hold_char); /* undo effects of setting up yytext */ \\");
1787 outn ("yy_cp = YY_G(yy_full_match); /* restore poss. backed-over text */ \\");
1789 if (variable_trailing_context_rules
) {
1790 outn ("YY_G(yy_lp) = YY_G(yy_full_lp); /* restore orig. accepting pos. */ \\");
1791 outn ("YY_G(yy_state_ptr) = YY_G(yy_full_state); /* restore orig. state */ \\");
1792 outn ("yy_current_state = *YY_G(yy_state_ptr); /* restore curr. state */ \\");
1795 outn ("++YY_G(yy_lp); \\");
1796 outn ("goto find_rule; \\");
1803 outn ("/* The intent behind this definition is that it'll catch");
1804 outn (" * any uses of REJECT which flex missed.");
1806 outn ("#define REJECT reject_used_but_not_detected");
1811 if (yytext_is_array
) {
1813 indent_puts ("static int yy_more_offset = 0;");
1814 indent_puts ("static int yy_prev_more_offset = 0;");
1817 else if (!reentrant
) {
1819 ("static int yy_more_flag = 0;");
1821 ("static int yy_more_len = 0;");
1825 if (yytext_is_array
) {
1827 ("#define yymore() (YY_G(yy_more_offset) = yy_flex_strlen( yytext M4_YY_CALL_LAST_ARG))");
1828 indent_puts ("#define YY_NEED_STRLEN");
1829 indent_puts ("#define YY_MORE_ADJ 0");
1831 ("#define YY_RESTORE_YY_MORE_OFFSET \\");
1833 indent_puts ("{ \\");
1835 ("YY_G(yy_more_offset) = YY_G(yy_prev_more_offset); \\");
1836 indent_puts ("yyleng -= YY_G(yy_more_offset); \\");
1842 ("#define yymore() (YY_G(yy_more_flag) = 1)");
1844 ("#define YY_MORE_ADJ YY_G(yy_more_len)");
1845 indent_puts ("#define YY_RESTORE_YY_MORE_OFFSET");
1851 ("#define yymore() yymore_used_but_not_detected");
1852 indent_puts ("#define YY_MORE_ADJ 0");
1853 indent_puts ("#define YY_RESTORE_YY_MORE_OFFSET");
1857 if (yytext_is_array
) {
1858 outn ("#ifndef YYLMAX");
1859 outn ("#define YYLMAX 8192");
1862 outn ("char yytext[YYLMAX];");
1863 outn ("char *yytext_ptr;");
1869 outn ("char *yytext;");
1873 out (&action_array
[defs1_offset
]);
1875 line_directive_out (stdout
, 0);
1877 skelout (); /* %% [5.0] - break point in skel */
1881 outn ("\terrno=0; \\");
1882 outn ("\twhile ( (result = read( fileno(yyin), (char *) buf, max_size )) < 0 ) \\");
1884 outn ("\t\tif( errno != EINTR) \\");
1886 outn ("\t\t\tYY_FATAL_ERROR( \"input in flex scanner failed\" ); \\");
1887 outn ("\t\t\tbreak; \\");
1889 outn ("\t\terrno=0; \\");
1890 outn ("\t\tclearerr(yyin); \\");
1895 outn ("\tif ( YY_CURRENT_BUFFER_LVALUE->yy_is_interactive ) \\");
1897 outn ("\t\tint c = '*'; \\");
1898 outn ("\t\tsize_t n; \\");
1899 outn ("\t\tfor ( n = 0; n < max_size && \\");
1900 outn ("\t\t\t (c = getc( yyin )) != EOF && c != '\\n'; ++n ) \\");
1901 outn ("\t\t\tbuf[n] = (char) c; \\");
1902 outn ("\t\tif ( c == '\\n' ) \\");
1903 outn ("\t\t\tbuf[n++] = (char) c; \\");
1904 outn ("\t\tif ( c == EOF && ferror( yyin ) ) \\");
1905 outn ("\t\t\tYY_FATAL_ERROR( \"input in flex scanner failed\" ); \\");
1906 outn ("\t\tresult = n; \\");
1910 outn ("\t\terrno=0; \\");
1911 outn ("\t\twhile ( (result = fread(buf, 1, max_size, yyin))==0 && ferror(yyin)) \\");
1912 outn ("\t\t\t{ \\");
1913 outn ("\t\t\tif( errno != EINTR) \\");
1914 outn ("\t\t\t\t{ \\");
1915 outn ("\t\t\t\tYY_FATAL_ERROR( \"input in flex scanner failed\" ); \\");
1916 outn ("\t\t\t\tbreak; \\");
1917 outn ("\t\t\t\t} \\");
1918 outn ("\t\t\terrno=0; \\");
1919 outn ("\t\t\tclearerr(yyin); \\");
1920 outn ("\t\t\t} \\");
1925 skelout (); /* %% [6.0] - break point in skel */
1927 indent_puts ("#define YY_RULE_SETUP \\");
1930 indent_puts ("if ( yyleng > 0 ) \\");
1932 indent_puts ("YY_CURRENT_BUFFER_LVALUE->yy_at_bol = \\");
1933 indent_puts ("\t\t(yytext[yyleng - 1] == '\\n'); \\");
1936 indent_puts ("YY_USER_ACTION");
1939 skelout (); /* %% [7.0] - break point in skel */
1941 /* Copy prolog to output file. */
1942 out (&action_array
[prolog_offset
]);
1944 line_directive_out (stdout
, 0);
1946 skelout (); /* %% [8.0] - break point in skel */
1950 if (yymore_used
&& !yytext_is_array
) {
1951 indent_puts ("YY_G(yy_more_len) = 0;");
1952 indent_puts ("if ( YY_G(yy_more_flag) )");
1956 ("YY_G(yy_more_len) = YY_G(yy_c_buf_p) - YY_G(yytext_ptr);");
1957 indent_puts ("YY_G(yy_more_flag) = 0;");
1962 skelout (); /* %% [9.0] - break point in skel */
1966 /* Note, don't use any indentation. */
1970 skelout (); /* %% [10.0] - break point in skel */
1974 skelout (); /* %% [11.0] - break point in skel */
1975 outn ("m4_ifdef( [[M4_YY_USE_LINENO]],[[");
1977 ("if ( yy_act != YY_END_OF_BUFFER && yy_rule_can_match_eol[yy_act] )");
1980 indent_puts ("int yyl;");
1982 out_str ("for ( yyl = %s; yyl < yyleng; ++yyl )\n",
1983 yymore_used
? (yytext_is_array
? "YY_G(yy_prev_more_offset)" :
1984 "YY_G(yy_more_len)") : "0");
1986 indent_puts ("if ( yytext[yyl] == '\\n' )");
1988 indent_puts ("M4_YY_INCR_LINENO();");
1995 skelout (); /* %% [12.0] - break point in skel */
1997 indent_puts ("if ( yy_flex_debug )");
2001 indent_puts ("if ( yy_act == 0 )");
2003 indent_puts (C_plus_plus
?
2004 "std::cerr << \"--scanner backing up\\n\";" :
2005 "fprintf( stderr, \"--scanner backing up\\n\" );");
2009 out_dec ("else if ( yy_act < %d )\n", num_rules
);
2014 ("std::cerr << \"--accepting rule at line \" << yy_rule_linenum[yy_act] <<");
2016 (" \"(\\\"\" << yytext << \"\\\")\\n\";");
2020 ("fprintf( stderr, \"--accepting rule at line %ld (\\\"%s\\\")\\n\",");
2023 (" (long)yy_rule_linenum[yy_act], yytext );");
2029 out_dec ("else if ( yy_act == %d )\n", num_rules
);
2034 ("std::cerr << \"--accepting default rule (\\\"\" << yytext << \"\\\")\\n\";");
2038 ("fprintf( stderr, \"--accepting default rule (\\\"%s\\\")\\n\",");
2039 indent_puts (" yytext );");
2045 out_dec ("else if ( yy_act == %d )\n", num_rules
+ 1);
2048 indent_puts (C_plus_plus
?
2049 "std::cerr << \"--(end of buffer or a NUL)\\n\";" :
2050 "fprintf( stderr, \"--(end of buffer or a NUL)\\n\" );");
2060 ("std::cerr << \"--EOF (start condition \" << YY_START << \")\\n\";");
2064 ("fprintf( stderr, \"--EOF (start condition %d)\\n\", YY_START );");
2073 /* Copy actions to output file. */
2074 skelout (); /* %% [13.0] - break point in skel */
2077 out (&action_array
[action_offset
]);
2079 line_directive_out (stdout
, 0);
2081 /* generate cases for any missing EOF rules */
2082 for (i
= 1; i
<= lastsc
; ++i
)
2085 out_str ("case YY_STATE_EOF(%s):\n", scname
[i
]);
2086 did_eof_rule
= true;
2091 indent_puts ("yyterminate();");
2096 /* Generate code for handling NUL's, if needed. */
2098 /* First, deal with backing up and setting up yy_cp if the scanner
2099 * finds that it should JAM on the NUL.
2101 skelout (); /* %% [14.0] - break point in skel */
2104 if (fullspd
|| fulltbl
)
2105 indent_puts ("yy_cp = YY_G(yy_c_buf_p);");
2107 else { /* compressed table */
2108 if (!reject
&& !interactive
) {
2109 /* Do the guaranteed-needed backing up to figure
2113 ("yy_cp = YY_G(yy_last_accepting_cpos);");
2115 ("yy_current_state = YY_G(yy_last_accepting_state);");
2119 /* Still need to initialize yy_cp, though
2120 * yy_current_state was set up by
2121 * yy_get_previous_state().
2123 indent_puts ("yy_cp = YY_G(yy_c_buf_p);");
2127 /* Generate code for yy_get_previous_state(). */
2129 skelout (); /* %% [15.0] - break point in skel */
2134 skelout (); /* %% [16.0] - break point in skel */
2135 gen_next_state (true);
2138 skelout (); /* %% [17.0] - break point in skel */
2141 skelout (); /* %% [18.0] - break point in skel */
2142 skelout (); /* %% [19.0] - break point in skel */
2143 /* Update BOL and yylineno inside of input(). */
2146 ("YY_CURRENT_BUFFER_LVALUE->yy_at_bol = (c == '\\n');");
2149 ("if ( YY_CURRENT_BUFFER_LVALUE->yy_at_bol )");
2151 indent_puts ("M4_YY_INCR_LINENO();");
2156 else if (do_yylineno
) {
2157 indent_puts ("if ( c == '\\n' )");
2159 indent_puts ("M4_YY_INCR_LINENO();");
2165 /* Copy remainder of input to output. */
2167 line_directive_out (stdout
, 1);
2171 (void) flexscan (); /* copy remainder of input to output */