1 /* gen - actual generation (writing) of flex scanners */
3 /* Copyright (c) 1990 The Regents of the University of California. */
4 /* All rights reserved. */
6 /* This code is derived from software contributed to Berkeley by */
9 /* The United States Government has rights in this work pursuant */
10 /* to contract no. DE-AC03-76SF00098 between the United States */
11 /* Department of Energy and the University of California. */
13 /* This file is part of flex. */
15 /* Redistribution and use in source and binary forms, with or without */
16 /* modification, are permitted provided that the following conditions */
19 /* 1. Redistributions of source code must retain the above copyright */
20 /* notice, this list of conditions and the following disclaimer. */
21 /* 2. Redistributions in binary form must reproduce the above copyright */
22 /* notice, this list of conditions and the following disclaimer in the */
23 /* documentation and/or other materials provided with the distribution. */
25 /* Neither the name of the University nor the names of its contributors */
26 /* may be used to endorse or promote products derived from this software */
27 /* without specific prior written permission. */
29 /* THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR */
30 /* IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED */
31 /* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR */
38 /* declare functions that have forward references */
40 void gen_next_state
PROTO ((int));
41 void genecs
PROTO ((void));
42 void indent_put2s
PROTO ((const char *, const char *));
43 void indent_puts
PROTO ((const char *));
46 static int indent_level
= 0; /* each level is 8 spaces */
48 #define indent_up() (++indent_level)
49 #define indent_down() (--indent_level)
50 #define set_indent(indent_val) indent_level = indent_val
52 /* Almost everything is done in terms of arrays starting at 1, so provide
53 * a null entry for the zero element of all C arrays. (The exception
54 * to this is that the fast table representation generally uses the
55 * 0 elements of its arrays, too.)
58 static const char *get_int16_decl (void)
61 ? "static yyconst flex_int16_t %s[%d] =\n { 0,\n"
62 : "static yyconst flex_int16_t * %s = 0;\n";
66 static const char *get_int32_decl (void)
69 ? "static yyconst flex_int32_t %s[%d] =\n { 0,\n"
70 : "static yyconst flex_int32_t * %s = 0;\n";
73 static const char *get_state_decl (void)
76 ? "static yyconst yy_state_type %s[%d] =\n { 0,\n"
77 : "static yyconst yy_state_type * %s = 0;\n";
80 /* Indent to the current level. */
84 register int i
= indent_level
* 8;
98 /** Make the table for possible eol matches.
99 * @return the newly allocated rule_can_match_eol table
101 static struct yytbl_data
*mkeoltbl (void)
104 flex_int8_t
*tdata
= 0;
105 struct yytbl_data
*tbl
;
107 tbl
= (struct yytbl_data
*) calloc (1, sizeof (struct yytbl_data
));
108 yytbl_data_init (tbl
, YYTD_ID_RULE_CAN_MATCH_EOL
);
109 tbl
->td_flags
= YYTD_DATA8
;
110 tbl
->td_lolen
= num_rules
+ 1;
111 tbl
->td_data
= tdata
=
112 (flex_int8_t
*) calloc (tbl
->td_lolen
, sizeof (flex_int8_t
));
114 for (i
= 1; i
<= num_rules
; i
++)
115 tdata
[i
] = rule_has_nl
[i
] ? 1 : 0;
117 buf_prints (&yydmap_buf
,
118 "\t{YYTD_ID_RULE_CAN_MATCH_EOL, (void**)&yy_rule_can_match_eol, sizeof(%s)},\n",
123 /* Generate the table for possible eol matches. */
124 static void geneoltbl ()
128 outn ("m4_ifdef( [[M4_YY_USE_LINENO]],[[");
129 outn ("/* Table of booleans, true if rule could match eol. */");
130 out_str_dec (get_int32_decl (), "yy_rule_can_match_eol",
134 for (i
= 1; i
<= num_rules
; i
++) {
135 out_dec ("%d, ", rule_has_nl
[i
] ? 1 : 0);
136 /* format nicely, 20 numbers per line. */
146 /* Generate the code to keep backing-up information. */
148 void gen_backing_up ()
150 if (reject
|| num_backing_up
== 0)
154 indent_puts ("if ( yy_current_state[-1].yy_nxt )");
156 indent_puts ("if ( yy_accept[yy_current_state] )");
160 indent_puts ("YY_G(yy_last_accepting_state) = yy_current_state;");
161 indent_puts ("YY_G(yy_last_accepting_cpos) = yy_cp;");
167 /* Generate the code to perform the backing up. */
169 void gen_bu_action ()
171 if (reject
|| num_backing_up
== 0)
176 indent_puts ("case 0: /* must back up */");
177 indent_puts ("/* undo the effects of YY_DO_BEFORE_ACTION */");
178 indent_puts ("*yy_cp = YY_G(yy_hold_char);");
180 if (fullspd
|| fulltbl
)
181 indent_puts ("yy_cp = YY_G(yy_last_accepting_cpos) + 1;");
183 /* Backing-up info for compressed tables is taken \after/
184 * yy_cp has been incremented for the next state.
186 indent_puts ("yy_cp = YY_G(yy_last_accepting_cpos);");
188 indent_puts ("yy_current_state = YY_G(yy_last_accepting_state);");
189 indent_puts ("goto yy_find_action;");
195 /** mkctbl - make full speed compressed transition table
196 * This is an array of structs; each struct a pair of integers.
197 * You should call mkssltbl() immediately after this.
198 * Then, I think, mkecstbl(). Arrrg.
199 * @return the newly allocated trans table
202 static struct yytbl_data
*mkctbl (void)
205 struct yytbl_data
*tbl
= 0;
206 flex_int32_t
*tdata
= 0, curr
= 0;
207 int end_of_buffer_action
= num_rules
+ 1;
209 buf_prints (&yydmap_buf
,
210 "\t{YYTD_ID_TRANSITION, (void**)&yy_transition, sizeof(%s)},\n",
211 ((tblend
+ numecs
+ 1) >= INT16_MAX
212 || long_align
) ? "flex_int32_t" : "flex_int16_t");
214 tbl
= (struct yytbl_data
*) calloc (1, sizeof (struct yytbl_data
));
215 yytbl_data_init (tbl
, YYTD_ID_TRANSITION
);
216 tbl
->td_flags
= YYTD_DATA32
| YYTD_STRUCT
;
218 tbl
->td_lolen
= tblend
+ numecs
+ 1; /* number of structs */
220 tbl
->td_data
= tdata
=
221 (flex_int32_t
*) calloc (tbl
->td_lolen
* 2, sizeof (flex_int32_t
));
223 /* We want the transition to be represented as the offset to the
224 * next state, not the actual state number, which is what it currently
225 * is. The offset is base[nxt[i]] - (base of current state)]. That's
226 * just the difference between the starting points of the two involved
227 * states (to - from).
229 * First, though, we need to find some way to put in our end-of-buffer
230 * flags and states. We do this by making a state with absolutely no
231 * transitions. We put it at the end of the table.
234 /* We need to have room in nxt/chk for two more slots: One for the
235 * action and one for the end-of-buffer transition. We now *assume*
236 * that we're guaranteed the only character we'll try to index this
237 * nxt/chk pair with is EOB, i.e., 0, so we don't have to make sure
238 * there's room for jam entries for other characters.
241 while (tblend
+ 2 >= current_max_xpairs
)
244 while (lastdfa
+ 1 >= current_max_dfas
)
245 increase_max_dfas ();
247 base
[lastdfa
+ 1] = tblend
+ 2;
248 nxt
[tblend
+ 1] = end_of_buffer_action
;
249 chk
[tblend
+ 1] = numecs
+ 1;
250 chk
[tblend
+ 2] = 1; /* anything but EOB */
252 /* So that "make test" won't show arb. differences. */
255 /* Make sure every state has an end-of-buffer transition and an
258 for (i
= 0; i
<= lastdfa
; ++i
) {
259 int anum
= dfaacc
[i
].dfaacc_state
;
260 int offset
= base
[i
];
262 chk
[offset
] = EOB_POSITION
;
263 chk
[offset
- 1] = ACTION_POSITION
;
264 nxt
[offset
- 1] = anum
; /* action number */
267 for (i
= 0; i
<= tblend
; ++i
) {
268 if (chk
[i
] == EOB_POSITION
) {
270 tdata
[curr
++] = base
[lastdfa
+ 1] - i
;
273 else if (chk
[i
] == ACTION_POSITION
) {
275 tdata
[curr
++] = nxt
[i
];
278 else if (chk
[i
] > numecs
|| chk
[i
] == 0) {
282 else { /* verify, transition */
284 tdata
[curr
++] = chk
[i
];
285 tdata
[curr
++] = base
[nxt
[i
]] - (i
- chk
[i
]);
290 /* Here's the final, end-of-buffer state. */
291 tdata
[curr
++] = chk
[tblend
+ 1];
292 tdata
[curr
++] = nxt
[tblend
+ 1];
294 tdata
[curr
++] = chk
[tblend
+ 2];
295 tdata
[curr
++] = nxt
[tblend
+ 2];
301 /** Make start_state_list table.
302 * @return the newly allocated start_state_list table
304 static struct yytbl_data
*mkssltbl (void)
306 struct yytbl_data
*tbl
= 0;
307 flex_int32_t
*tdata
= 0;
310 tbl
= (struct yytbl_data
*) calloc (1, sizeof (struct yytbl_data
));
311 yytbl_data_init (tbl
, YYTD_ID_START_STATE_LIST
);
312 tbl
->td_flags
= YYTD_DATA32
| YYTD_PTRANS
;
314 tbl
->td_lolen
= lastsc
* 2 + 1;
316 tbl
->td_data
= tdata
=
317 (flex_int32_t
*) calloc (tbl
->td_lolen
, sizeof (flex_int32_t
));
319 for (i
= 0; i
<= lastsc
* 2; ++i
)
322 buf_prints (&yydmap_buf
,
323 "\t{YYTD_ID_START_STATE_LIST, (void**)&yy_start_state_list, sizeof(%s)},\n",
324 "struct yy_trans_info*");
331 /* genctbl - generates full speed compressed transition table */
336 int end_of_buffer_action
= num_rules
+ 1;
338 /* Table of verify for transition and offset to next state. */
340 out_dec ("static yyconst struct yy_trans_info yy_transition[%d] =\n {\n", tblend
+ numecs
+ 1);
342 outn ("static yyconst struct yy_trans_info *yy_transition = 0;");
344 /* We want the transition to be represented as the offset to the
345 * next state, not the actual state number, which is what it currently
346 * is. The offset is base[nxt[i]] - (base of current state)]. That's
347 * just the difference between the starting points of the two involved
348 * states (to - from).
350 * First, though, we need to find some way to put in our end-of-buffer
351 * flags and states. We do this by making a state with absolutely no
352 * transitions. We put it at the end of the table.
355 /* We need to have room in nxt/chk for two more slots: One for the
356 * action and one for the end-of-buffer transition. We now *assume*
357 * that we're guaranteed the only character we'll try to index this
358 * nxt/chk pair with is EOB, i.e., 0, so we don't have to make sure
359 * there's room for jam entries for other characters.
362 while (tblend
+ 2 >= current_max_xpairs
)
365 while (lastdfa
+ 1 >= current_max_dfas
)
366 increase_max_dfas ();
368 base
[lastdfa
+ 1] = tblend
+ 2;
369 nxt
[tblend
+ 1] = end_of_buffer_action
;
370 chk
[tblend
+ 1] = numecs
+ 1;
371 chk
[tblend
+ 2] = 1; /* anything but EOB */
373 /* So that "make test" won't show arb. differences. */
376 /* Make sure every state has an end-of-buffer transition and an
379 for (i
= 0; i
<= lastdfa
; ++i
) {
380 int anum
= dfaacc
[i
].dfaacc_state
;
381 int offset
= base
[i
];
383 chk
[offset
] = EOB_POSITION
;
384 chk
[offset
- 1] = ACTION_POSITION
;
385 nxt
[offset
- 1] = anum
; /* action number */
388 for (i
= 0; i
<= tblend
; ++i
) {
389 if (chk
[i
] == EOB_POSITION
)
390 transition_struct_out (0, base
[lastdfa
+ 1] - i
);
392 else if (chk
[i
] == ACTION_POSITION
)
393 transition_struct_out (0, nxt
[i
]);
395 else if (chk
[i
] > numecs
|| chk
[i
] == 0)
396 transition_struct_out (0, 0); /* unused slot */
398 else /* verify, transition */
399 transition_struct_out (chk
[i
],
405 /* Here's the final, end-of-buffer state. */
406 transition_struct_out (chk
[tblend
+ 1], nxt
[tblend
+ 1]);
407 transition_struct_out (chk
[tblend
+ 2], nxt
[tblend
+ 2]);
412 /* Table of pointers to start states. */
414 out_dec ("static yyconst struct yy_trans_info *yy_start_state_list[%d] =\n", lastsc
* 2 + 1);
416 outn ("static yyconst struct yy_trans_info **yy_start_state_list =0;");
421 for (i
= 0; i
<= lastsc
* 2; ++i
)
422 out_dec (" &yy_transition[%d],\n", base
[i
]);
432 /* mkecstbl - Make equivalence-class tables. */
434 struct yytbl_data
*mkecstbl (void)
437 struct yytbl_data
*tbl
= 0;
438 flex_int32_t
*tdata
= 0;
440 tbl
= (struct yytbl_data
*) calloc (1, sizeof (struct yytbl_data
));
441 yytbl_data_init (tbl
, YYTD_ID_EC
);
442 tbl
->td_flags
|= YYTD_DATA32
;
444 tbl
->td_lolen
= csize
;
446 tbl
->td_data
= tdata
=
447 (flex_int32_t
*) calloc (tbl
->td_lolen
, sizeof (flex_int32_t
));
449 for (i
= 1; i
< csize
; ++i
) {
450 if (caseins
&& isupper (i
))
451 ecgroup
[i
] = ecgroup
[tolower (i
)];
453 ecgroup
[i
] = ABS (ecgroup
[i
]);
454 tdata
[i
] = ecgroup
[i
];
457 buf_prints (&yydmap_buf
,
458 "\t{YYTD_ID_EC, (void**)&yy_ec, sizeof(%s)},\n",
464 /* Generate equivalence-class tables. */
471 out_str_dec (get_int32_decl (), "yy_ec", csize
);
473 for (i
= 1; i
< csize
; ++i
) {
474 if (caseins
&& (i
>= 'A') && (i
<= 'Z'))
475 ecgroup
[i
] = ecgroup
[clower (i
)];
477 ecgroup
[i
] = ABS (ecgroup
[i
]);
484 fputs (_("\n\nEquivalence Classes:\n\n"), stderr
);
488 for (j
= 0; j
< numrows
; ++j
) {
489 for (i
= j
; i
< csize
; i
= i
+ numrows
) {
490 fprintf (stderr
, "%4s = %-2d",
491 readable_form (i
), ecgroup
[i
]);
502 /* Generate the code to find the action number. */
504 void gen_find_action ()
507 indent_puts ("yy_act = yy_current_state[-1].yy_nxt;");
510 indent_puts ("yy_act = yy_accept[yy_current_state];");
513 indent_puts ("yy_current_state = *--YY_G(yy_state_ptr);");
514 indent_puts ("YY_G(yy_lp) = yy_accept[yy_current_state];");
516 outn ("find_rule: /* we branch to this label when backing up */");
519 ("for ( ; ; ) /* until we find what rule we matched */");
526 ("if ( YY_G(yy_lp) && YY_G(yy_lp) < yy_accept[yy_current_state + 1] )");
529 indent_puts ("yy_act = yy_acclist[YY_G(yy_lp)];");
531 if (variable_trailing_context_rules
) {
533 ("if ( yy_act & YY_TRAILING_HEAD_MASK ||");
534 indent_puts (" yy_looking_for_trail_begin )");
539 ("if ( yy_act == yy_looking_for_trail_begin )");
542 indent_puts ("yy_looking_for_trail_begin = 0;");
543 indent_puts ("yy_act &= ~YY_TRAILING_HEAD_MASK;");
544 indent_puts ("break;");
552 ("else if ( yy_act & YY_TRAILING_MASK )");
556 ("yy_looking_for_trail_begin = yy_act & ~YY_TRAILING_MASK;");
558 ("yy_looking_for_trail_begin |= YY_TRAILING_HEAD_MASK;");
561 /* Remember matched text in case we back up
565 ("YY_G(yy_full_match) = yy_cp;");
567 ("yy_full_state = YY_G(yy_state_ptr);");
568 indent_puts ("yy_full_lp = YY_G(yy_lp);");
574 indent_puts ("else");
577 indent_puts ("YY_G(yy_full_match) = yy_cp;");
579 ("yy_full_state = YY_G(yy_state_ptr);");
580 indent_puts ("yy_full_lp = YY_G(yy_lp);");
581 indent_puts ("break;");
585 indent_puts ("++YY_G(yy_lp);");
586 indent_puts ("goto find_rule;");
590 /* Remember matched text in case we back up due to
591 * trailing context plus REJECT.
595 indent_puts ("YY_G(yy_full_match) = yy_cp;");
596 indent_puts ("break;");
604 indent_puts ("--yy_cp;");
606 /* We could consolidate the following two lines with those at
607 * the beginning, but at the cost of complaints that we're
608 * branching inside a loop.
610 indent_puts ("yy_current_state = *--YY_G(yy_state_ptr);");
611 indent_puts ("YY_G(yy_lp) = yy_accept[yy_current_state];");
618 else { /* compressed */
619 indent_puts ("yy_act = yy_accept[yy_current_state];");
621 if (interactive
&& !reject
) {
622 /* Do the guaranteed-needed backing up to figure out
625 indent_puts ("if ( yy_act == 0 )");
627 indent_puts ("{ /* have to back up */");
629 ("yy_cp = YY_G(yy_last_accepting_cpos);");
631 ("yy_current_state = YY_G(yy_last_accepting_state);");
633 ("yy_act = yy_accept[yy_current_state];");
640 /* mkftbl - make the full table and return the struct .
641 * you should call mkecstbl() after this.
644 struct yytbl_data
*mkftbl (void)
647 int end_of_buffer_action
= num_rules
+ 1;
648 struct yytbl_data
*tbl
;
649 flex_int32_t
*tdata
= 0;
651 tbl
= (struct yytbl_data
*) calloc (1, sizeof (struct yytbl_data
));
652 yytbl_data_init (tbl
, YYTD_ID_ACCEPT
);
653 tbl
->td_flags
|= YYTD_DATA32
;
654 tbl
->td_hilen
= 0; /* it's a one-dimensional array */
655 tbl
->td_lolen
= lastdfa
+ 1;
657 tbl
->td_data
= tdata
=
658 (flex_int32_t
*) calloc (tbl
->td_lolen
, sizeof (flex_int32_t
));
660 dfaacc
[end_of_buffer_state
].dfaacc_state
= end_of_buffer_action
;
662 for (i
= 1; i
<= lastdfa
; ++i
) {
663 register int anum
= dfaacc
[i
].dfaacc_state
;
668 fprintf (stderr
, _("state # %d accepts: [%d]\n"),
672 buf_prints (&yydmap_buf
,
673 "\t{YYTD_ID_ACCEPT, (void**)&yy_accept, sizeof(%s)},\n",
674 long_align
? "flex_int32_t" : "flex_int16_t");
679 /* genftbl - generate full transition table */
684 int end_of_buffer_action
= num_rules
+ 1;
686 out_str_dec (long_align
? get_int32_decl () : get_int16_decl (),
687 "yy_accept", lastdfa
+ 1);
689 dfaacc
[end_of_buffer_state
].dfaacc_state
= end_of_buffer_action
;
691 for (i
= 1; i
<= lastdfa
; ++i
) {
692 register int anum
= dfaacc
[i
].dfaacc_state
;
697 fprintf (stderr
, _("state # %d accepts: [%d]\n"),
706 /* Don't have to dump the actual full table entries - they were
707 * created on-the-fly.
712 /* Generate the code to find the next compressed-table state. */
714 void gen_next_compressed_state (char_map
)
717 indent_put2s ("register YY_CHAR yy_c = %s;", char_map
);
719 /* Save the backing-up info \before/ computing the next state
720 * because we always compute one more state than needed - we
721 * always proceed until we reach a jam state
726 ("while ( yy_chk[yy_base[yy_current_state] + yy_c] != yy_current_state )");
729 indent_puts ("yy_current_state = (int) yy_def[yy_current_state];");
732 /* We've arrange it so that templates are never chained
733 * to one another. This means we can afford to make a
734 * very simple test to see if we need to convert to
735 * yy_c's meta-equivalence class without worrying
736 * about erroneously looking up the meta-equivalence
741 /* lastdfa + 2 is the beginning of the templates */
742 out_dec ("if ( yy_current_state >= %d )\n", lastdfa
+ 2);
745 indent_puts ("yy_c = yy_meta[(unsigned int) yy_c];");
753 ("yy_current_state = yy_nxt[yy_base[yy_current_state] + (unsigned int) yy_c];");
757 /* Generate the code to find the next match. */
759 void gen_next_match ()
761 /* NOTE - changes in here should be reflected in gen_next_state() and
764 char *char_map
= useecs
?
765 "yy_ec[YY_SC_TO_UI(*yy_cp)] " : "YY_SC_TO_UI(*yy_cp)";
767 char *char_map_2
= useecs
?
768 "yy_ec[YY_SC_TO_UI(*++yy_cp)] " : "YY_SC_TO_UI(*++yy_cp)";
773 ("while ( (yy_current_state = yy_nxt[yy_current_state][ %s ]) > 0 )",
777 ("while ( (yy_current_state = yy_nxt[yy_current_state*YY_NXT_LOLEN + %s ]) > 0 )",
782 if (num_backing_up
> 0) {
788 indent_puts ("++yy_cp;");
790 if (num_backing_up
> 0)
797 indent_puts ("yy_current_state = -yy_current_state;");
803 ("register yyconst struct yy_trans_info *yy_trans_info;\n");
804 indent_puts ("register YY_CHAR yy_c;\n");
805 indent_put2s ("for ( yy_c = %s;", char_map
);
807 (" (yy_trans_info = &yy_current_state[(unsigned int) yy_c])->");
808 indent_puts ("yy_verify == yy_c;");
809 indent_put2s (" yy_c = %s )", char_map_2
);
813 if (num_backing_up
> 0)
816 indent_puts ("yy_current_state += yy_trans_info->yy_nxt;");
818 if (num_backing_up
> 0) {
828 else { /* compressed */
834 gen_next_state (false);
836 indent_puts ("++yy_cp;");
845 out_dec ("while ( yy_base[yy_current_state] != %d );\n", jambase
);
847 out_dec ("while ( yy_current_state != %d );\n",
850 if (!reject
&& !interactive
) {
851 /* Do the guaranteed-needed backing up to figure out
855 ("yy_cp = YY_G(yy_last_accepting_cpos);");
857 ("yy_current_state = YY_G(yy_last_accepting_state);");
863 /* Generate the code to find the next state. */
865 void gen_next_state (worry_about_NULs
)
866 int worry_about_NULs
;
867 { /* NOTE - changes in here should be reflected in gen_next_match() */
870 if (worry_about_NULs
&& !nultrans
) {
872 (void) sprintf (char_map
,
873 "(*yy_cp ? yy_ec[YY_SC_TO_UI(*yy_cp)] : %d)",
876 (void) sprintf (char_map
,
877 "(*yy_cp ? YY_SC_TO_UI(*yy_cp) : %d)",
882 strcpy (char_map
, useecs
?
883 "yy_ec[YY_SC_TO_UI(*yy_cp)]" :
884 "YY_SC_TO_UI(*yy_cp)");
886 if (worry_about_NULs
&& nultrans
) {
887 if (!fulltbl
&& !fullspd
)
888 /* Compressed tables back up *before* they match. */
891 indent_puts ("if ( *yy_cp )");
899 ("yy_current_state = yy_nxt[yy_current_state][%s];",
903 ("yy_current_state = yy_nxt[yy_current_state*YY_NXT_LOLEN + %s];",
909 ("yy_current_state += yy_current_state[%s].yy_nxt;",
913 gen_next_compressed_state (char_map
);
915 if (worry_about_NULs
&& nultrans
) {
919 indent_puts ("else");
922 ("yy_current_state = yy_NUL_trans[yy_current_state];");
926 if (fullspd
|| fulltbl
)
930 indent_puts ("*YY_G(yy_state_ptr)++ = yy_current_state;");
934 /* Generate the code to make a NUL transition. */
936 void gen_NUL_trans ()
937 { /* NOTE - changes in here should be reflected in gen_next_match() */
938 /* Only generate a definition for "yy_cp" if we'll generate code
939 * that uses it. Otherwise lint and the like complain.
941 int need_backing_up
= (num_backing_up
> 0 && !reject
);
943 if (need_backing_up
&& (!nultrans
|| fullspd
|| fulltbl
))
944 /* We're going to need yy_cp lying around for the call
945 * below to gen_backing_up().
947 indent_puts ("register char *yy_cp = YY_G(yy_c_buf_p);");
953 ("yy_current_state = yy_NUL_trans[yy_current_state];");
954 indent_puts ("yy_is_jam = (yy_current_state == 0);");
960 out_dec ("yy_current_state = yy_nxt[yy_current_state][%d];\n", NUL_ec
);
962 out_dec ("yy_current_state = yy_nxt[yy_current_state*YY_NXT_LOLEN + %d];\n", NUL_ec
);
963 indent_puts ("yy_is_jam = (yy_current_state <= 0);");
968 out_dec ("register int yy_c = %d;\n", NUL_ec
);
971 ("register yyconst struct yy_trans_info *yy_trans_info;\n");
973 ("yy_trans_info = &yy_current_state[(unsigned int) yy_c];");
974 indent_puts ("yy_current_state += yy_trans_info->yy_nxt;");
977 ("yy_is_jam = (yy_trans_info->yy_verify != yy_c);");
983 (void) sprintf (NUL_ec_str
, "%d", NUL_ec
);
984 gen_next_compressed_state (NUL_ec_str
);
987 out_dec ("yy_is_jam = (yy_current_state == %d);\n",
991 /* Only stack this state if it's a transition we
992 * actually make. If we stack it on a jam, then
993 * the state stack and yy_c_buf_p get out of sync.
995 indent_puts ("if ( ! yy_is_jam )");
998 ("*YY_G(yy_state_ptr)++ = yy_current_state;");
1003 /* If we've entered an accepting state, back up; note that
1004 * compressed tables have *already* done such backing up, so
1005 * we needn't bother with it again.
1007 if (need_backing_up
&& (fullspd
|| fulltbl
)) {
1009 indent_puts ("if ( ! yy_is_jam )");
1019 /* Generate the code to find the start state. */
1021 void gen_start_state ()
1026 ("yy_current_state = yy_start_state_list[YY_G(yy_start) + YY_AT_BOL()];");
1030 ("yy_current_state = yy_start_state_list[YY_G(yy_start)];");
1034 indent_puts ("yy_current_state = YY_G(yy_start);");
1037 indent_puts ("yy_current_state += YY_AT_BOL();");
1040 /* Set up for storing up states. */
1041 outn ("m4_ifdef( [[M4_YY_USES_REJECT]],\n[[");
1043 ("YY_G(yy_state_ptr) = YY_G(yy_state_buf);");
1045 ("*YY_G(yy_state_ptr)++ = yy_current_state;");
1052 /* gentabs - generate data statements for the transition tables */
1056 int i
, j
, k
, *accset
, nacc
, *acc_array
, total_states
;
1057 int end_of_buffer_action
= num_rules
+ 1;
1058 struct yytbl_data
*yyacc_tbl
= 0, *yymeta_tbl
= 0, *yybase_tbl
= 0,
1059 *yydef_tbl
= 0, *yynxt_tbl
= 0, *yychk_tbl
= 0, *yyacclist_tbl
=0;
1060 flex_int32_t
*yyacc_data
= 0, *yybase_data
= 0, *yydef_data
= 0,
1061 *yynxt_data
= 0, *yychk_data
= 0, *yyacclist_data
=0;
1062 flex_int32_t yybase_curr
= 0, yyacclist_curr
=0,yyacc_curr
=0;
1064 acc_array
= allocate_integer_array (current_max_dfas
);
1067 /* The compressed table format jams by entering the "jam state",
1068 * losing information about the previous state in the process.
1069 * In order to recover the previous state, we effectively need
1070 * to keep backing-up information.
1075 /* Write out accepting list and pointer list.
1077 * First we generate the "yy_acclist" array. In the process,
1078 * we compute the indices that will go into the "yy_accept"
1079 * array, and save the indices in the dfaacc array.
1081 int EOB_accepting_list
[2];
1083 /* Set up accepting structures for the End Of Buffer state. */
1084 EOB_accepting_list
[0] = 0;
1085 EOB_accepting_list
[1] = end_of_buffer_action
;
1086 accsiz
[end_of_buffer_state
] = 1;
1087 dfaacc
[end_of_buffer_state
].dfaacc_set
=
1090 out_str_dec (long_align
? get_int32_decl () :
1091 get_int16_decl (), "yy_acclist", MAX (numas
,
1094 buf_prints (&yydmap_buf
,
1095 "\t{YYTD_ID_ACCLIST, (void**)&yy_acclist, sizeof(%s)},\n",
1096 long_align
? "flex_int32_t" : "flex_int16_t");
1098 yyacclist_tbl
= (struct yytbl_data
*)calloc(1,sizeof(struct yytbl_data
));
1099 yytbl_data_init (yyacclist_tbl
, YYTD_ID_ACCLIST
);
1100 yyacclist_tbl
->td_lolen
= MAX(numas
,1) + 1;
1101 yyacclist_tbl
->td_data
= yyacclist_data
=
1102 (flex_int32_t
*) calloc (yyacclist_tbl
->td_lolen
, sizeof (flex_int32_t
));
1105 j
= 1; /* index into "yy_acclist" array */
1107 for (i
= 1; i
<= lastdfa
; ++i
) {
1110 if (accsiz
[i
] != 0) {
1111 accset
= dfaacc
[i
].dfaacc_set
;
1116 _("state # %d accepts: "),
1119 for (k
= 1; k
<= nacc
; ++k
) {
1120 int accnum
= accset
[k
];
1124 if (variable_trailing_context_rules
1126 YY_TRAILING_HEAD_MASK
)
1128 && accnum
<= num_rules
1129 && rule_type
[accnum
] ==
1131 /* Special hack to flag
1132 * accepting number as part
1133 * of trailing context rule.
1135 accnum
|= YY_TRAILING_MASK
;
1139 yyacclist_data
[yyacclist_curr
++] = accnum
;
1142 fprintf (stderr
, "[%d]",
1156 /* add accepting number for the "jam" state */
1161 yytbl_data_compress (yyacclist_tbl
);
1162 if (yytbl_data_fwrite (&tableswr
, yyacclist_tbl
) < 0)
1163 flexerror (_("Could not write yyacclist_tbl"));
1164 yytbl_data_destroy (yyacclist_tbl
);
1165 yyacclist_tbl
= NULL
;
1170 dfaacc
[end_of_buffer_state
].dfaacc_state
=
1171 end_of_buffer_action
;
1173 for (i
= 1; i
<= lastdfa
; ++i
)
1174 acc_array
[i
] = dfaacc
[i
].dfaacc_state
;
1176 /* add accepting number for jam state */
1180 /* Begin generating yy_accept */
1182 /* Spit out "yy_accept" array. If we're doing "reject", it'll be
1183 * pointers into the "yy_acclist" array. Otherwise it's actual
1184 * accepting numbers. In either case, we just dump the numbers.
1187 /* "lastdfa + 2" is the size of "yy_accept"; includes room for C arrays
1188 * beginning at 0 and for "jam" state.
1193 /* We put a "cap" on the table associating lists of accepting
1194 * numbers with state numbers. This is needed because we tell
1195 * where the end of an accepting list is by looking at where
1196 * the list for the next state starts.
1200 out_str_dec (long_align
? get_int32_decl () : get_int16_decl (),
1203 buf_prints (&yydmap_buf
,
1204 "\t{YYTD_ID_ACCEPT, (void**)&yy_accept, sizeof(%s)},\n",
1205 long_align
? "flex_int32_t" : "flex_int16_t");
1208 (struct yytbl_data
*) calloc (1,
1209 sizeof (struct yytbl_data
));
1210 yytbl_data_init (yyacc_tbl
, YYTD_ID_ACCEPT
);
1211 yyacc_tbl
->td_lolen
= k
;
1212 yyacc_tbl
->td_data
= yyacc_data
=
1213 (flex_int32_t
*) calloc (yyacc_tbl
->td_lolen
, sizeof (flex_int32_t
));
1216 for (i
= 1; i
<= lastdfa
; ++i
) {
1217 mkdata (acc_array
[i
]);
1218 yyacc_data
[yyacc_curr
++] = acc_array
[i
];
1220 if (!reject
&& trace
&& acc_array
[i
])
1221 fprintf (stderr
, _("state # %d accepts: [%d]\n"),
1225 /* Add entry for "jam" state. */
1226 mkdata (acc_array
[i
]);
1227 yyacc_data
[yyacc_curr
++] = acc_array
[i
];
1230 /* Add "cap" for the list. */
1231 mkdata (acc_array
[i
]);
1232 yyacc_data
[yyacc_curr
++] = acc_array
[i
];
1237 yytbl_data_compress (yyacc_tbl
);
1238 if (yytbl_data_fwrite (&tableswr
, yyacc_tbl
) < 0)
1239 flexerror (_("Could not write yyacc_tbl"));
1240 yytbl_data_destroy (yyacc_tbl
);
1243 /* End generating yy_accept */
1249 struct yytbl_data
*tbl
;
1252 yytbl_data_compress (tbl
);
1253 if (yytbl_data_fwrite (&tableswr
, tbl
) < 0)
1254 flexerror (_("Could not write ecstbl"));
1255 yytbl_data_destroy (tbl
);
1261 /* Begin generating yy_meta */
1262 /* Write out meta-equivalence classes (used to index
1265 flex_int32_t
*yymecs_data
= 0;
1267 (struct yytbl_data
*) calloc (1,
1270 yytbl_data_init (yymeta_tbl
, YYTD_ID_META
);
1271 yymeta_tbl
->td_lolen
= numecs
+ 1;
1272 yymeta_tbl
->td_data
= yymecs_data
=
1273 (flex_int32_t
*) calloc (yymeta_tbl
->td_lolen
,
1274 sizeof (flex_int32_t
));
1277 fputs (_("\n\nMeta-Equivalence Classes:\n"),
1280 out_str_dec (get_int32_decl (), "yy_meta", numecs
+ 1);
1281 buf_prints (&yydmap_buf
,
1282 "\t{YYTD_ID_META, (void**)&yy_meta, sizeof(%s)},\n",
1285 for (i
= 1; i
<= numecs
; ++i
) {
1287 fprintf (stderr
, "%d = %d\n",
1288 i
, ABS (tecbck
[i
]));
1290 mkdata (ABS (tecbck
[i
]));
1291 yymecs_data
[i
] = ABS (tecbck
[i
]);
1296 yytbl_data_compress (yymeta_tbl
);
1297 if (yytbl_data_fwrite (&tableswr
, yymeta_tbl
) < 0)
1299 ("Could not write yymeta_tbl"));
1300 yytbl_data_destroy (yymeta_tbl
);
1303 /* End generating yy_meta */
1306 total_states
= lastdfa
+ numtemps
;
1308 /* Begin generating yy_base */
1309 out_str_dec ((tblend
>= INT16_MAX
|| long_align
) ?
1310 get_int32_decl () : get_int16_decl (),
1311 "yy_base", total_states
+ 1);
1313 buf_prints (&yydmap_buf
,
1314 "\t{YYTD_ID_BASE, (void**)&yy_base, sizeof(%s)},\n",
1315 (tblend
>= INT16_MAX
1316 || long_align
) ? "flex_int32_t" : "flex_int16_t");
1318 (struct yytbl_data
*) calloc (1,
1319 sizeof (struct yytbl_data
));
1320 yytbl_data_init (yybase_tbl
, YYTD_ID_BASE
);
1321 yybase_tbl
->td_lolen
= total_states
+ 1;
1322 yybase_tbl
->td_data
= yybase_data
=
1323 (flex_int32_t
*) calloc (yybase_tbl
->td_lolen
,
1324 sizeof (flex_int32_t
));
1327 for (i
= 1; i
<= lastdfa
; ++i
) {
1328 register int d
= def
[i
];
1330 if (base
[i
] == JAMSTATE
)
1337 /* Template reference. */
1339 def
[i
] = lastdfa
- d
+ 1;
1343 yybase_data
[yybase_curr
++] = base
[i
];
1346 /* Generate jam state's base index. */
1348 yybase_data
[yybase_curr
++] = base
[i
];
1350 for (++i
/* skip jam state */ ; i
<= total_states
; ++i
) {
1352 yybase_data
[yybase_curr
++] = base
[i
];
1358 yytbl_data_compress (yybase_tbl
);
1359 if (yytbl_data_fwrite (&tableswr
, yybase_tbl
) < 0)
1360 flexerror (_("Could not write yybase_tbl"));
1361 yytbl_data_destroy (yybase_tbl
);
1364 /* End generating yy_base */
1367 /* Begin generating yy_def */
1368 out_str_dec ((total_states
>= INT16_MAX
|| long_align
) ?
1369 get_int32_decl () : get_int16_decl (),
1370 "yy_def", total_states
+ 1);
1372 buf_prints (&yydmap_buf
,
1373 "\t{YYTD_ID_DEF, (void**)&yy_def, sizeof(%s)},\n",
1374 (total_states
>= INT16_MAX
1375 || long_align
) ? "flex_int32_t" : "flex_int16_t");
1378 (struct yytbl_data
*) calloc (1,
1379 sizeof (struct yytbl_data
));
1380 yytbl_data_init (yydef_tbl
, YYTD_ID_DEF
);
1381 yydef_tbl
->td_lolen
= total_states
+ 1;
1382 yydef_tbl
->td_data
= yydef_data
=
1383 (flex_int32_t
*) calloc (yydef_tbl
->td_lolen
, sizeof (flex_int32_t
));
1385 for (i
= 1; i
<= total_states
; ++i
) {
1387 yydef_data
[i
] = def
[i
];
1392 yytbl_data_compress (yydef_tbl
);
1393 if (yytbl_data_fwrite (&tableswr
, yydef_tbl
) < 0)
1394 flexerror (_("Could not write yydef_tbl"));
1395 yytbl_data_destroy (yydef_tbl
);
1398 /* End generating yy_def */
1401 /* Begin generating yy_nxt */
1402 out_str_dec ((total_states
>= INT16_MAX
|| long_align
) ?
1403 get_int32_decl () : get_int16_decl (), "yy_nxt",
1406 buf_prints (&yydmap_buf
,
1407 "\t{YYTD_ID_NXT, (void**)&yy_nxt, sizeof(%s)},\n",
1408 (total_states
>= INT16_MAX
1409 || long_align
) ? "flex_int32_t" : "flex_int16_t");
1412 (struct yytbl_data
*) calloc (1,
1413 sizeof (struct yytbl_data
));
1414 yytbl_data_init (yynxt_tbl
, YYTD_ID_NXT
);
1415 yynxt_tbl
->td_lolen
= tblend
+ 1;
1416 yynxt_tbl
->td_data
= yynxt_data
=
1417 (flex_int32_t
*) calloc (yynxt_tbl
->td_lolen
, sizeof (flex_int32_t
));
1419 for (i
= 1; i
<= tblend
; ++i
) {
1420 /* Note, the order of the following test is important.
1421 * If chk[i] is 0, then nxt[i] is undefined.
1423 if (chk
[i
] == 0 || nxt
[i
] == 0)
1424 nxt
[i
] = jamstate
; /* new state is the JAM state */
1427 yynxt_data
[i
] = nxt
[i
];
1432 yytbl_data_compress (yynxt_tbl
);
1433 if (yytbl_data_fwrite (&tableswr
, yynxt_tbl
) < 0)
1434 flexerror (_("Could not write yynxt_tbl"));
1435 yytbl_data_destroy (yynxt_tbl
);
1438 /* End generating yy_nxt */
1440 /* Begin generating yy_chk */
1441 out_str_dec ((total_states
>= INT16_MAX
|| long_align
) ?
1442 get_int32_decl () : get_int16_decl (), "yy_chk",
1445 buf_prints (&yydmap_buf
,
1446 "\t{YYTD_ID_CHK, (void**)&yy_chk, sizeof(%s)},\n",
1447 (total_states
>= INT16_MAX
1448 || long_align
) ? "flex_int32_t" : "flex_int16_t");
1451 (struct yytbl_data
*) calloc (1,
1452 sizeof (struct yytbl_data
));
1453 yytbl_data_init (yychk_tbl
, YYTD_ID_CHK
);
1454 yychk_tbl
->td_lolen
= tblend
+ 1;
1455 yychk_tbl
->td_data
= yychk_data
=
1456 (flex_int32_t
*) calloc (yychk_tbl
->td_lolen
, sizeof (flex_int32_t
));
1458 for (i
= 1; i
<= tblend
; ++i
) {
1463 yychk_data
[i
] = chk
[i
];
1468 yytbl_data_compress (yychk_tbl
);
1469 if (yytbl_data_fwrite (&tableswr
, yychk_tbl
) < 0)
1470 flexerror (_("Could not write yychk_tbl"));
1471 yytbl_data_destroy (yychk_tbl
);
1474 /* End generating yy_chk */
1476 flex_free ((void *) acc_array
);
1480 /* Write out a formatted string (with a secondary string argument) at the
1481 * current indentation level, adding a final newline.
1484 void indent_put2s (fmt
, arg
)
1485 const char *fmt
, *arg
;
1493 /* Write out a string at the current indentation level, adding a final
1497 void indent_puts (str
)
1505 /* make_tables - generate transition tables and finishes generating output file
1511 int did_eof_rule
= false;
1512 struct yytbl_data
*yynultrans_tbl
;
1515 skelout (); /* %% [2.0] - break point in skel */
1517 /* First, take care of YY_DO_BEFORE_ACTION depending on yymore
1522 if (yymore_used
&& !yytext_is_array
) {
1523 indent_puts ("YY_G(yytext_ptr) -= YY_G(yy_more_len); \\");
1525 ("yyleng = (size_t) (yy_cp - YY_G(yytext_ptr)); \\");
1529 indent_puts ("yyleng = (size_t) (yy_cp - yy_bp); \\");
1531 /* Now also deal with copying yytext_ptr to yytext if needed. */
1532 skelout (); /* %% [3.0] - break point in skel */
1533 if (yytext_is_array
) {
1536 ("if ( yyleng + YY_G(yy_more_offset) >= YYLMAX ) \\");
1538 indent_puts ("if ( yyleng >= YYLMAX ) \\");
1542 ("YY_FATAL_ERROR( \"token too large, exceeds YYLMAX\" ); \\");
1547 ("yy_flex_strncpy( &yytext[YY_G(yy_more_offset)], YY_G(yytext_ptr), yyleng + 1 M4_YY_CALL_LAST_ARG); \\");
1548 indent_puts ("yyleng += YY_G(yy_more_offset); \\");
1550 ("YY_G(yy_prev_more_offset) = YY_G(yy_more_offset); \\");
1551 indent_puts ("YY_G(yy_more_offset) = 0; \\");
1555 ("yy_flex_strncpy( yytext, YY_G(yytext_ptr), yyleng + 1 M4_YY_CALL_LAST_ARG); \\");
1561 skelout (); /* %% [4.0] - break point in skel */
1564 /* This is where we REALLY begin generating the tables. */
1566 out_dec ("#define YY_NUM_RULES %d\n", num_rules
);
1567 out_dec ("#define YY_END_OF_BUFFER %d\n", num_rules
+ 1);
1570 /* Need to define the transet type as a size large
1571 * enough to hold the biggest offset.
1573 int total_table_size
= tblend
+ numecs
+ 1;
1574 char *trans_offset_type
=
1575 (total_table_size
>= INT16_MAX
|| long_align
) ?
1576 "flex_int32_t" : "flex_int16_t";
1579 indent_puts ("struct yy_trans_info");
1583 /* We require that yy_verify and yy_nxt must be of the same size int. */
1584 indent_put2s ("%s yy_verify;", trans_offset_type
);
1586 /* In cases where its sister yy_verify *is* a "yes, there is
1587 * a transition", yy_nxt is the offset (in records) to the
1588 * next state. In most cases where there is no transition,
1589 * the value of yy_nxt is irrelevant. If yy_nxt is the -1th
1590 * record of a state, though, then yy_nxt is the action number
1594 indent_put2s ("%s yy_nxt;", trans_offset_type
);
1599 /* We generate a bogus 'struct yy_trans_info' data type
1600 * so we can guarantee that it is always declared in the skel.
1601 * This is so we can compile "sizeof(struct yy_trans_info)"
1605 ("/* This struct is not used in this scanner,");
1606 indent_puts (" but its presence is necessary. */");
1607 indent_puts ("struct yy_trans_info");
1610 indent_puts ("flex_int32_t yy_verify;");
1611 indent_puts ("flex_int32_t yy_nxt;");
1619 struct yytbl_data
*tbl
;
1622 yytbl_data_compress (tbl
);
1623 if (yytbl_data_fwrite (&tableswr
, tbl
) < 0)
1624 flexerror (_("Could not write ftbl"));
1625 yytbl_data_destroy (tbl
);
1628 yytbl_data_compress (tbl
);
1629 if (yytbl_data_fwrite (&tableswr
, tbl
) < 0)
1630 flexerror (_("Could not write ssltbl"));
1631 yytbl_data_destroy (tbl
);
1636 yytbl_data_compress (tbl
);
1637 if (yytbl_data_fwrite (&tableswr
, tbl
) < 0)
1639 ("Could not write ecstbl"));
1640 yytbl_data_destroy (tbl
);
1648 struct yytbl_data
*tbl
;
1651 yytbl_data_compress (tbl
);
1652 if (yytbl_data_fwrite (&tableswr
, tbl
) < 0)
1653 flexerror (_("Could not write ftbl"));
1654 yytbl_data_destroy (tbl
);
1659 yytbl_data_compress (tbl
);
1660 if (yytbl_data_fwrite (&tableswr
, tbl
) < 0)
1662 ("Could not write ecstbl"));
1663 yytbl_data_destroy (tbl
);
1676 struct yytbl_data
*tbl
;
1679 yytbl_data_compress (tbl
);
1680 if (yytbl_data_fwrite (&tableswr
, tbl
) < 0)
1681 flexerror (_("Could not write eoltbl"));
1682 yytbl_data_destroy (tbl
);
1687 /* Definitions for backing up. We don't need them if REJECT
1688 * is being used because then we use an alternative backin-up
1689 * technique instead.
1691 if (num_backing_up
> 0 && !reject
) {
1692 if (!C_plus_plus
&& !reentrant
) {
1694 ("static yy_state_type yy_last_accepting_state;");
1696 ("static char *yy_last_accepting_cpos;\n");
1701 flex_int32_t
*yynultrans_data
= 0;
1703 /* Begin generating yy_NUL_trans */
1704 out_str_dec (get_state_decl (), "yy_NUL_trans",
1706 buf_prints (&yydmap_buf
,
1707 "\t{YYTD_ID_NUL_TRANS, (void**)&yy_NUL_trans, sizeof(%s)},\n",
1708 (fullspd
) ? "struct yy_trans_info*" :
1712 (struct yytbl_data
*) calloc (1,
1715 yytbl_data_init (yynultrans_tbl
, YYTD_ID_NUL_TRANS
);
1717 yynultrans_tbl
->td_flags
|= YYTD_PTRANS
;
1718 yynultrans_tbl
->td_lolen
= lastdfa
+ 1;
1719 yynultrans_tbl
->td_data
= yynultrans_data
=
1720 (flex_int32_t
*) calloc (yynultrans_tbl
->td_lolen
,
1721 sizeof (flex_int32_t
));
1723 for (i
= 1; i
<= lastdfa
; ++i
) {
1725 out_dec (" &yy_transition[%d],\n",
1727 yynultrans_data
[i
] = base
[i
];
1730 mkdata (nultrans
[i
]);
1731 yynultrans_data
[i
] = nultrans
[i
];
1737 yytbl_data_compress (yynultrans_tbl
);
1738 if (yytbl_data_fwrite (&tableswr
, yynultrans_tbl
) <
1741 ("Could not write yynultrans_tbl"));
1742 yytbl_data_destroy (yynultrans_tbl
);
1743 yynultrans_tbl
= NULL
;
1745 /* End generating yy_NUL_trans */
1748 if (!C_plus_plus
&& !reentrant
) {
1749 indent_puts ("extern int yy_flex_debug;");
1750 indent_put2s ("int yy_flex_debug = %s;\n",
1751 ddebug
? "1" : "0");
1754 if (ddebug
) { /* Spit out table mapping rules to line numbers. */
1755 out_str_dec (long_align
? get_int32_decl () :
1756 get_int16_decl (), "yy_rule_linenum",
1758 for (i
= 1; i
< num_rules
; ++i
)
1759 mkdata (rule_linenum
[i
]);
1764 outn ("m4_ifdef( [[M4_YY_USES_REJECT]],\n[[");
1765 /* Declare state buffer variables. */
1766 if (!C_plus_plus
&& !reentrant
) {
1767 outn ("static yy_state_type *yy_state_buf=0, *yy_state_ptr=0;");
1768 outn ("static char *yy_full_match;");
1769 outn ("static int yy_lp;");
1772 if (variable_trailing_context_rules
) {
1774 outn ("static int yy_looking_for_trail_begin = 0;");
1775 outn ("static int yy_full_lp;");
1776 outn ("static int *yy_full_state;");
1779 out_hex ("#define YY_TRAILING_MASK 0x%x\n",
1780 (unsigned int) YY_TRAILING_MASK
);
1781 out_hex ("#define YY_TRAILING_HEAD_MASK 0x%x\n",
1782 (unsigned int) YY_TRAILING_HEAD_MASK
);
1785 outn ("#define REJECT \\");
1787 outn ("*yy_cp = YY_G(yy_hold_char); /* undo effects of setting up yytext */ \\");
1788 outn ("yy_cp = YY_G(yy_full_match); /* restore poss. backed-over text */ \\");
1790 if (variable_trailing_context_rules
) {
1791 outn ("YY_G(yy_lp) = yy_full_lp; /* restore orig. accepting pos. */ \\");
1792 outn ("YY_G(yy_state_ptr) = yy_full_state; /* restore orig. state */ \\");
1793 outn ("yy_current_state = *YY_G(yy_state_ptr); /* restore curr. state */ \\");
1796 outn ("++YY_G(yy_lp); \\");
1797 outn ("goto find_rule; \\");
1804 outn ("/* The intent behind this definition is that it'll catch");
1805 outn (" * any uses of REJECT which flex missed.");
1807 outn ("#define REJECT reject_used_but_not_detected");
1812 if (yytext_is_array
) {
1814 indent_puts ("static int yy_more_offset = 0;");
1815 indent_puts ("static int yy_prev_more_offset = 0;");
1818 else if (!reentrant
) {
1820 ("static int yy_more_flag = 0;");
1822 ("static int yy_more_len = 0;");
1826 if (yytext_is_array
) {
1828 ("#define yymore() (YY_G(yy_more_offset) = yy_flex_strlen( yytext M4_YY_CALL_LAST_ARG))");
1829 indent_puts ("#define YY_NEED_STRLEN");
1830 indent_puts ("#define YY_MORE_ADJ 0");
1832 ("#define YY_RESTORE_YY_MORE_OFFSET \\");
1834 indent_puts ("{ \\");
1836 ("YY_G(yy_more_offset) = YY_G(yy_prev_more_offset); \\");
1837 indent_puts ("yyleng -= YY_G(yy_more_offset); \\");
1843 ("#define yymore() (YY_G(yy_more_flag) = 1)");
1845 ("#define YY_MORE_ADJ YY_G(yy_more_len)");
1846 indent_puts ("#define YY_RESTORE_YY_MORE_OFFSET");
1852 ("#define yymore() yymore_used_but_not_detected");
1853 indent_puts ("#define YY_MORE_ADJ 0");
1854 indent_puts ("#define YY_RESTORE_YY_MORE_OFFSET");
1858 if (yytext_is_array
) {
1859 outn ("#ifndef YYLMAX");
1860 outn ("#define YYLMAX 8192");
1863 outn ("char yytext[YYLMAX];");
1864 outn ("char *yytext_ptr;");
1870 outn ("char *yytext;");
1874 out (&action_array
[defs1_offset
]);
1876 line_directive_out (stdout
, 0);
1878 skelout (); /* %% [5.0] - break point in skel */
1882 outn ("\terrno=0; \\");
1883 outn ("\twhile ( (result = read( fileno(yyin), (char *) buf, max_size )) < 0 ) \\");
1885 outn ("\t\tif( errno != EINTR) \\");
1887 outn ("\t\t\tYY_FATAL_ERROR( \"input in flex scanner failed\" ); \\");
1888 outn ("\t\t\tbreak; \\");
1890 outn ("\t\terrno=0; \\");
1891 outn ("\t\tclearerr(yyin); \\");
1896 outn ("\tif ( YY_CURRENT_BUFFER_LVALUE->yy_is_interactive ) \\");
1898 outn ("\t\tint c = '*'; \\");
1899 outn ("\t\tsize_t n; \\");
1900 outn ("\t\tfor ( n = 0; n < max_size && \\");
1901 outn ("\t\t\t (c = getc( yyin )) != EOF && c != '\\n'; ++n ) \\");
1902 outn ("\t\t\tbuf[n] = (char) c; \\");
1903 outn ("\t\tif ( c == '\\n' ) \\");
1904 outn ("\t\t\tbuf[n++] = (char) c; \\");
1905 outn ("\t\tif ( c == EOF && ferror( yyin ) ) \\");
1906 outn ("\t\t\tYY_FATAL_ERROR( \"input in flex scanner failed\" ); \\");
1907 outn ("\t\tresult = n; \\");
1911 outn ("\t\terrno=0; \\");
1912 outn ("\t\twhile ( (result = fread(buf, 1, max_size, yyin))==0 && ferror(yyin)) \\");
1913 outn ("\t\t\t{ \\");
1914 outn ("\t\t\tif( errno != EINTR) \\");
1915 outn ("\t\t\t\t{ \\");
1916 outn ("\t\t\t\tYY_FATAL_ERROR( \"input in flex scanner failed\" ); \\");
1917 outn ("\t\t\t\tbreak; \\");
1918 outn ("\t\t\t\t} \\");
1919 outn ("\t\t\terrno=0; \\");
1920 outn ("\t\t\tclearerr(yyin); \\");
1921 outn ("\t\t\t} \\");
1926 skelout (); /* %% [6.0] - break point in skel */
1928 indent_puts ("#define YY_RULE_SETUP \\");
1931 indent_puts ("if ( yyleng > 0 ) \\");
1933 indent_puts ("YY_CURRENT_BUFFER_LVALUE->yy_at_bol = \\");
1934 indent_puts ("\t\t(yytext[yyleng - 1] == '\\n'); \\");
1937 indent_puts ("YY_USER_ACTION");
1940 skelout (); /* %% [7.0] - break point in skel */
1942 /* Copy prolog to output file. */
1943 out (&action_array
[prolog_offset
]);
1945 line_directive_out (stdout
, 0);
1947 skelout (); /* %% [8.0] - break point in skel */
1951 if (yymore_used
&& !yytext_is_array
) {
1952 indent_puts ("YY_G(yy_more_len) = 0;");
1953 indent_puts ("if ( YY_G(yy_more_flag) )");
1957 ("YY_G(yy_more_len) = YY_G(yy_c_buf_p) - YY_G(yytext_ptr);");
1958 indent_puts ("YY_G(yy_more_flag) = 0;");
1963 skelout (); /* %% [9.0] - break point in skel */
1967 /* Note, don't use any indentation. */
1971 skelout (); /* %% [10.0] - break point in skel */
1975 skelout (); /* %% [11.0] - break point in skel */
1976 outn ("m4_ifdef( [[M4_YY_USE_LINENO]],[[");
1978 ("if ( yy_act != YY_END_OF_BUFFER && yy_rule_can_match_eol[yy_act] )");
1981 indent_puts ("int yyl;");
1983 out_str ("for ( yyl = %s; yyl < yyleng; ++yyl )\n",
1984 yymore_used
? (yytext_is_array
? "YY_G(yy_prev_more_offset)" :
1985 "YY_G(yy_more_len)") : "0");
1987 indent_puts ("if ( yytext[yyl] == '\\n' )");
1989 indent_puts ("M4_YY_INCR_LINENO();");
1996 skelout (); /* %% [12.0] - break point in skel */
1998 indent_puts ("if ( yy_flex_debug )");
2002 indent_puts ("if ( yy_act == 0 )");
2004 indent_puts (C_plus_plus
?
2005 "std::cerr << \"--scanner backing up\\n\";" :
2006 "fprintf( stderr, \"--scanner backing up\\n\" );");
2010 out_dec ("else if ( yy_act < %d )\n", num_rules
);
2015 ("std::cerr << \"--accepting rule at line \" << yy_rule_linenum[yy_act] <<");
2017 (" \"(\\\"\" << yytext << \"\\\")\\n\";");
2021 ("fprintf( stderr, \"--accepting rule at line %ld (\\\"%s\\\")\\n\",");
2024 (" (long)yy_rule_linenum[yy_act], yytext );");
2030 out_dec ("else if ( yy_act == %d )\n", num_rules
);
2035 ("std::cerr << \"--accepting default rule (\\\"\" << yytext << \"\\\")\\n\";");
2039 ("fprintf( stderr, \"--accepting default rule (\\\"%s\\\")\\n\",");
2040 indent_puts (" yytext );");
2046 out_dec ("else if ( yy_act == %d )\n", num_rules
+ 1);
2049 indent_puts (C_plus_plus
?
2050 "std::cerr << \"--(end of buffer or a NUL)\\n\";" :
2051 "fprintf( stderr, \"--(end of buffer or a NUL)\\n\" );");
2061 ("std::cerr << \"--EOF (start condition \" << YY_START << \")\\n\";");
2065 ("fprintf( stderr, \"--EOF (start condition %d)\\n\", YY_START );");
2074 /* Copy actions to output file. */
2075 skelout (); /* %% [13.0] - break point in skel */
2078 out (&action_array
[action_offset
]);
2080 line_directive_out (stdout
, 0);
2082 /* generate cases for any missing EOF rules */
2083 for (i
= 1; i
<= lastsc
; ++i
)
2086 out_str ("case YY_STATE_EOF(%s):\n", scname
[i
]);
2087 did_eof_rule
= true;
2092 indent_puts ("yyterminate();");
2097 /* Generate code for handling NUL's, if needed. */
2099 /* First, deal with backing up and setting up yy_cp if the scanner
2100 * finds that it should JAM on the NUL.
2102 skelout (); /* %% [14.0] - break point in skel */
2105 if (fullspd
|| fulltbl
)
2106 indent_puts ("yy_cp = YY_G(yy_c_buf_p);");
2108 else { /* compressed table */
2109 if (!reject
&& !interactive
) {
2110 /* Do the guaranteed-needed backing up to figure
2114 ("yy_cp = YY_G(yy_last_accepting_cpos);");
2116 ("yy_current_state = YY_G(yy_last_accepting_state);");
2120 /* Still need to initialize yy_cp, though
2121 * yy_current_state was set up by
2122 * yy_get_previous_state().
2124 indent_puts ("yy_cp = YY_G(yy_c_buf_p);");
2128 /* Generate code for yy_get_previous_state(). */
2130 skelout (); /* %% [15.0] - break point in skel */
2135 skelout (); /* %% [16.0] - break point in skel */
2136 gen_next_state (true);
2139 skelout (); /* %% [17.0] - break point in skel */
2142 skelout (); /* %% [18.0] - break point in skel */
2143 skelout (); /* %% [19.0] - break point in skel */
2144 /* Update BOL and yylineno inside of input(). */
2147 ("YY_CURRENT_BUFFER_LVALUE->yy_at_bol = (c == '\\n');");
2150 ("if ( YY_CURRENT_BUFFER_LVALUE->yy_at_bol )");
2152 indent_puts ("M4_YY_INCR_LINENO();");
2157 else if (do_yylineno
) {
2158 indent_puts ("if ( c == '\\n' )");
2160 indent_puts ("M4_YY_INCR_LINENO();");
2166 /* Copy remainder of input to output. */
2168 line_directive_out (stdout
, 1);
2172 (void) flexscan (); /* copy remainder of input to output */