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 */
43 static int indent_level = 0; /* each level is 8 spaces */
45 #define set_indent(indent_val) indent_level = indent_val
47 /* Almost everything is done in terms of arrays starting at 1, so provide
48 * a null entry for the zero element of all C arrays. (The exception
49 * to this is that the fast table representation generally uses the
50 * 0 elements of its arrays, too.)
53 static const char *get_int16_decl (void)
56 ? "static const flex_int16_t %s[%d] =\n { 0,\n"
57 : "static const flex_int16_t * %s = 0;\n";
61 static const char *get_int32_decl (void)
64 ? "static const flex_int32_t %s[%d] =\n { 0,\n"
65 : "static const flex_int32_t * %s = 0;\n";
68 static const char *get_state_decl (void)
71 ? "static const yy_state_type %s[%d] =\n { 0,\n"
72 : "static const yy_state_type * %s = 0;\n";
75 static const char *get_yy_char_decl (void)
78 ? "static const YY_CHAR %s[%d] =\n { 0,\n"
79 : "static const YY_CHAR * %s = 0;\n";
82 /* Indent to the current level. */
86 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 = 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 = (flex_uint32_t) (num_rules + 1);
113 tbl->td_data = tdata =
114 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 (void)
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 (void)
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 = 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 = (flex_uint32_t) (tblend + numecs + 1); /* number of structs */
222 tbl->td_data = tdata =
223 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 = 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 = (flex_uint32_t) (lastsc * 2 + 1);
318 tbl->td_data = tdata =
319 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 const struct yy_trans_info yy_transition[%d] =\n {\n", tblend + numecs + 1);
344 outn ("static const 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 const struct yy_trans_info *yy_start_state_list[%d] =\n", lastsc * 2 + 1);
418 outn ("static const 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. */
436 static struct yytbl_data *mkecstbl (void)
439 struct yytbl_data *tbl = 0;
440 flex_int32_t *tdata = 0;
442 tbl = calloc(1, sizeof (struct yytbl_data));
443 yytbl_data_init (tbl, YYTD_ID_EC);
444 tbl->td_flags |= YYTD_DATA32;
446 tbl->td_lolen = (flex_uint32_t) csize;
448 tbl->td_data = tdata =
449 calloc(tbl->td_lolen, sizeof (flex_int32_t));
451 for (i = 1; i < csize; ++i) {
452 ecgroup[i] = ABS (ecgroup[i]);
453 tdata[i] = ecgroup[i];
456 buf_prints (&yydmap_buf,
457 "\t{YYTD_ID_EC, (void**)&yy_ec, sizeof(%s)},\n",
463 /* Generate equivalence-class tables. */
470 out_str_dec (get_yy_char_decl (), "yy_ec", csize);
472 for (i = 1; i < csize; ++i) {
473 ecgroup[i] = ABS (ecgroup[i]);
480 fputs (_("\n\nEquivalence Classes:\n\n"), stderr);
484 for (j = 0; j < numrows; ++j) {
485 for (i = j; i < csize; i = i + numrows) {
486 fprintf (stderr, "%4s = %-2d",
487 readable_form (i), ecgroup[i]);
498 /* Generate the code to find the action number. */
500 void gen_find_action (void)
503 indent_puts ("yy_act = yy_current_state[-1].yy_nxt;");
506 indent_puts ("yy_act = yy_accept[yy_current_state];");
509 indent_puts ("yy_current_state = *--YY_G(yy_state_ptr);");
510 indent_puts ("YY_G(yy_lp) = yy_accept[yy_current_state];");
512 if (!variable_trailing_context_rules)
513 outn ("m4_ifdef( [[M4_YY_USES_REJECT]],\n[[");
514 if(reject_really_used)
515 outn ("find_rule: /* we branch to this label when backing up */");
516 if (!variable_trailing_context_rules)
520 ("for ( ; ; ) /* until we find what rule we matched */");
527 ("if ( YY_G(yy_lp) && YY_G(yy_lp) < yy_accept[yy_current_state + 1] )");
530 indent_puts ("yy_act = yy_acclist[YY_G(yy_lp)];");
532 if (variable_trailing_context_rules) {
534 ("if ( yy_act & YY_TRAILING_HEAD_MASK ||");
535 indent_puts (" YY_G(yy_looking_for_trail_begin) )");
540 ("if ( yy_act == YY_G(yy_looking_for_trail_begin) )");
543 indent_puts ("YY_G(yy_looking_for_trail_begin) = 0;");
544 indent_puts ("yy_act &= ~YY_TRAILING_HEAD_MASK;");
545 indent_puts ("break;");
553 ("else if ( yy_act & YY_TRAILING_MASK )");
557 ("YY_G(yy_looking_for_trail_begin) = yy_act & ~YY_TRAILING_MASK;");
559 ("YY_G(yy_looking_for_trail_begin) |= YY_TRAILING_HEAD_MASK;");
562 /* Remember matched text in case we back up
566 ("YY_G(yy_full_match) = yy_cp;");
568 ("YY_G(yy_full_state) = YY_G(yy_state_ptr);");
569 indent_puts ("YY_G(yy_full_lp) = YY_G(yy_lp);");
575 indent_puts ("else");
578 indent_puts ("YY_G(yy_full_match) = yy_cp;");
580 ("YY_G(yy_full_state) = YY_G(yy_state_ptr);");
581 indent_puts ("YY_G(yy_full_lp) = YY_G(yy_lp);");
582 indent_puts ("break;");
586 indent_puts ("++YY_G(yy_lp);");
587 indent_puts ("goto find_rule;");
591 /* Remember matched text in case we back up due to
592 * trailing context plus REJECT.
596 indent_puts ("YY_G(yy_full_match) = yy_cp;");
597 indent_puts ("break;");
605 indent_puts ("--yy_cp;");
607 /* We could consolidate the following two lines with those at
608 * the beginning, but at the cost of complaints that we're
609 * branching inside a loop.
611 indent_puts ("yy_current_state = *--YY_G(yy_state_ptr);");
612 indent_puts ("YY_G(yy_lp) = yy_accept[yy_current_state];");
619 else { /* compressed */
620 indent_puts ("yy_act = yy_accept[yy_current_state];");
622 if (interactive && !reject) {
623 /* Do the guaranteed-needed backing up to figure out
626 indent_puts ("if ( yy_act == 0 )");
628 indent_puts ("{ /* have to back up */");
630 ("yy_cp = YY_G(yy_last_accepting_cpos);");
632 ("yy_current_state = YY_G(yy_last_accepting_state);");
634 ("yy_act = yy_accept[yy_current_state];");
641 /* mkftbl - make the full table and return the struct .
642 * you should call mkecstbl() after this.
645 struct yytbl_data *mkftbl (void)
648 int end_of_buffer_action = num_rules + 1;
649 struct yytbl_data *tbl;
650 flex_int32_t *tdata = 0;
652 tbl = calloc(1, sizeof (struct yytbl_data));
653 yytbl_data_init (tbl, YYTD_ID_ACCEPT);
654 tbl->td_flags |= YYTD_DATA32;
655 tbl->td_hilen = 0; /* it's a one-dimensional array */
656 tbl->td_lolen = (flex_uint32_t) (lastdfa + 1);
658 tbl->td_data = tdata =
659 calloc(tbl->td_lolen, sizeof (flex_int32_t));
661 dfaacc[end_of_buffer_state].dfaacc_state = end_of_buffer_action;
663 for (i = 1; i <= lastdfa; ++i) {
664 int anum = dfaacc[i].dfaacc_state;
669 fprintf (stderr, _("state # %d accepts: [%d]\n"),
673 buf_prints (&yydmap_buf,
674 "\t{YYTD_ID_ACCEPT, (void**)&yy_accept, sizeof(%s)},\n",
675 long_align ? "flex_int32_t" : "flex_int16_t");
680 /* genftbl - generate full transition table */
685 int end_of_buffer_action = num_rules + 1;
687 out_str_dec (long_align ? get_int32_decl () : get_int16_decl (),
688 "yy_accept", lastdfa + 1);
690 dfaacc[end_of_buffer_state].dfaacc_state = end_of_buffer_action;
692 for (i = 1; i <= lastdfa; ++i) {
693 int anum = dfaacc[i].dfaacc_state;
698 fprintf (stderr, _("state # %d accepts: [%d]\n"),
707 /* Don't have to dump the actual full table entries - they were
708 * created on-the-fly.
713 /* Generate the code to find the next compressed-table state. */
715 void gen_next_compressed_state (char *char_map)
717 indent_put2s ("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[yy_c];");
753 ("yy_current_state = yy_nxt[yy_base[yy_current_state] + yy_c];");
757 /* Generate the code to find the next match. */
759 void gen_next_match (void)
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 ("const struct yy_trans_info *yy_trans_info;\n");
804 indent_puts ("YY_CHAR yy_c;\n");
805 indent_put2s ("for ( yy_c = %s;", char_map);
807 (" (yy_trans_info = &yy_current_state[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 (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 (void)
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 ("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 ("int yy_c = %d;\n", NUL_ec);
970 ("const 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 (void)
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 = calloc(1,sizeof(struct yytbl_data));
1098 yytbl_data_init (yyacclist_tbl, YYTD_ID_ACCLIST);
1099 yyacclist_tbl->td_lolen = (flex_uint32_t) (MAX(numas,1) + 1);
1100 yyacclist_tbl->td_data = yyacclist_data =
1101 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");
1206 yyacc_tbl = calloc(1, sizeof (struct yytbl_data));
1207 yytbl_data_init (yyacc_tbl, YYTD_ID_ACCEPT);
1208 yyacc_tbl->td_lolen = (flex_uint32_t) k;
1209 yyacc_tbl->td_data = yyacc_data =
1210 calloc(yyacc_tbl->td_lolen, sizeof (flex_int32_t));
1213 for (i = 1; i <= lastdfa; ++i) {
1214 mkdata (acc_array[i]);
1215 yyacc_data[yyacc_curr++] = acc_array[i];
1217 if (!reject && trace && acc_array[i])
1218 fprintf (stderr, _("state # %d accepts: [%d]\n"),
1222 /* Add entry for "jam" state. */
1223 mkdata (acc_array[i]);
1224 yyacc_data[yyacc_curr++] = acc_array[i];
1227 /* Add "cap" for the list. */
1228 mkdata (acc_array[i]);
1229 yyacc_data[yyacc_curr++] = acc_array[i];
1234 yytbl_data_compress (yyacc_tbl);
1235 if (yytbl_data_fwrite (&tableswr, yyacc_tbl) < 0)
1236 flexerror (_("Could not write yyacc_tbl"));
1237 yytbl_data_destroy (yyacc_tbl);
1240 /* End generating yy_accept */
1246 struct yytbl_data *tbl;
1249 yytbl_data_compress (tbl);
1250 if (yytbl_data_fwrite (&tableswr, tbl) < 0)
1251 flexerror (_("Could not write ecstbl"));
1252 yytbl_data_destroy (tbl);
1258 /* Begin generating yy_meta */
1259 /* Write out meta-equivalence classes (used to index
1262 flex_int32_t *yymecs_data = 0;
1263 yymeta_tbl = calloc(1, sizeof (struct yytbl_data));
1264 yytbl_data_init (yymeta_tbl, YYTD_ID_META);
1265 yymeta_tbl->td_lolen = (flex_uint32_t) (numecs + 1);
1266 yymeta_tbl->td_data = yymecs_data =
1267 calloc(yymeta_tbl->td_lolen,
1268 sizeof (flex_int32_t));
1271 fputs (_("\n\nMeta-Equivalence Classes:\n"),
1274 out_str_dec (get_yy_char_decl (), "yy_meta", numecs + 1);
1275 buf_prints (&yydmap_buf,
1276 "\t{YYTD_ID_META, (void**)&yy_meta, sizeof(%s)},\n",
1279 for (i = 1; i <= numecs; ++i) {
1281 fprintf (stderr, "%d = %d\n",
1282 i, ABS (tecbck[i]));
1284 mkdata (ABS (tecbck[i]));
1285 yymecs_data[i] = ABS (tecbck[i]);
1290 yytbl_data_compress (yymeta_tbl);
1291 if (yytbl_data_fwrite (&tableswr, yymeta_tbl) < 0)
1293 ("Could not write yymeta_tbl"));
1294 yytbl_data_destroy (yymeta_tbl);
1297 /* End generating yy_meta */
1300 total_states = lastdfa + numtemps;
1302 /* Begin generating yy_base */
1303 out_str_dec ((tblend >= INT16_MAX || long_align) ?
1304 get_int32_decl () : get_int16_decl (),
1305 "yy_base", total_states + 1);
1307 buf_prints (&yydmap_buf,
1308 "\t{YYTD_ID_BASE, (void**)&yy_base, sizeof(%s)},\n",
1309 (tblend >= INT16_MAX
1310 || long_align) ? "flex_int32_t" : "flex_int16_t");
1311 yybase_tbl = calloc (1, sizeof (struct yytbl_data));
1312 yytbl_data_init (yybase_tbl, YYTD_ID_BASE);
1313 yybase_tbl->td_lolen = (flex_uint32_t) (total_states + 1);
1314 yybase_tbl->td_data = yybase_data =
1315 calloc(yybase_tbl->td_lolen,
1316 sizeof (flex_int32_t));
1319 for (i = 1; i <= lastdfa; ++i) {
1322 if (base[i] == JAMSTATE)
1329 /* Template reference. */
1331 def[i] = lastdfa - d + 1;
1335 yybase_data[yybase_curr++] = base[i];
1338 /* Generate jam state's base index. */
1340 yybase_data[yybase_curr++] = base[i];
1342 for (++i /* skip jam state */ ; i <= total_states; ++i) {
1344 yybase_data[yybase_curr++] = base[i];
1350 yytbl_data_compress (yybase_tbl);
1351 if (yytbl_data_fwrite (&tableswr, yybase_tbl) < 0)
1352 flexerror (_("Could not write yybase_tbl"));
1353 yytbl_data_destroy (yybase_tbl);
1356 /* End generating yy_base */
1359 /* Begin generating yy_def */
1360 out_str_dec ((total_states >= INT16_MAX || long_align) ?
1361 get_int32_decl () : get_int16_decl (),
1362 "yy_def", total_states + 1);
1364 buf_prints (&yydmap_buf,
1365 "\t{YYTD_ID_DEF, (void**)&yy_def, sizeof(%s)},\n",
1366 (total_states >= INT16_MAX
1367 || long_align) ? "flex_int32_t" : "flex_int16_t");
1369 yydef_tbl = calloc(1, sizeof (struct yytbl_data));
1370 yytbl_data_init (yydef_tbl, YYTD_ID_DEF);
1371 yydef_tbl->td_lolen = (flex_uint32_t) (total_states + 1);
1372 yydef_tbl->td_data = yydef_data =
1373 calloc(yydef_tbl->td_lolen, sizeof (flex_int32_t));
1375 for (i = 1; i <= total_states; ++i) {
1377 yydef_data[i] = def[i];
1382 yytbl_data_compress (yydef_tbl);
1383 if (yytbl_data_fwrite (&tableswr, yydef_tbl) < 0)
1384 flexerror (_("Could not write yydef_tbl"));
1385 yytbl_data_destroy (yydef_tbl);
1388 /* End generating yy_def */
1391 /* Begin generating yy_nxt */
1392 out_str_dec ((total_states >= INT16_MAX || long_align) ?
1393 get_int32_decl () : get_int16_decl (), "yy_nxt",
1396 buf_prints (&yydmap_buf,
1397 "\t{YYTD_ID_NXT, (void**)&yy_nxt, sizeof(%s)},\n",
1398 (total_states >= INT16_MAX
1399 || long_align) ? "flex_int32_t" : "flex_int16_t");
1401 yynxt_tbl = calloc (1, sizeof (struct yytbl_data));
1402 yytbl_data_init (yynxt_tbl, YYTD_ID_NXT);
1403 yynxt_tbl->td_lolen = (flex_uint32_t) (tblend + 1);
1404 yynxt_tbl->td_data = yynxt_data =
1405 calloc (yynxt_tbl->td_lolen, sizeof (flex_int32_t));
1407 for (i = 1; i <= tblend; ++i) {
1408 /* Note, the order of the following test is important.
1409 * If chk[i] is 0, then nxt[i] is undefined.
1411 if (chk[i] == 0 || nxt[i] == 0)
1412 nxt[i] = jamstate; /* new state is the JAM state */
1415 yynxt_data[i] = nxt[i];
1420 yytbl_data_compress (yynxt_tbl);
1421 if (yytbl_data_fwrite (&tableswr, yynxt_tbl) < 0)
1422 flexerror (_("Could not write yynxt_tbl"));
1423 yytbl_data_destroy (yynxt_tbl);
1426 /* End generating yy_nxt */
1428 /* Begin generating yy_chk */
1429 out_str_dec ((total_states >= INT16_MAX || long_align) ?
1430 get_int32_decl () : get_int16_decl (), "yy_chk",
1433 buf_prints (&yydmap_buf,
1434 "\t{YYTD_ID_CHK, (void**)&yy_chk, sizeof(%s)},\n",
1435 (total_states >= INT16_MAX
1436 || long_align) ? "flex_int32_t" : "flex_int16_t");
1438 yychk_tbl = calloc (1, sizeof (struct yytbl_data));
1439 yytbl_data_init (yychk_tbl, YYTD_ID_CHK);
1440 yychk_tbl->td_lolen = (flex_uint32_t) (tblend + 1);
1441 yychk_tbl->td_data = yychk_data =
1442 calloc(yychk_tbl->td_lolen, sizeof (flex_int32_t));
1444 for (i = 1; i <= tblend; ++i) {
1449 yychk_data[i] = chk[i];
1454 yytbl_data_compress (yychk_tbl);
1455 if (yytbl_data_fwrite (&tableswr, yychk_tbl) < 0)
1456 flexerror (_("Could not write yychk_tbl"));
1457 yytbl_data_destroy (yychk_tbl);
1460 /* End generating yy_chk */
1466 /* Write out a formatted string (with a secondary string argument) at the
1467 * current indentation level, adding a final newline.
1470 void indent_put2s (const char *fmt, const char *arg)
1478 /* Write out a string at the current indentation level, adding a final
1482 void indent_puts (const char *str)
1489 /* make_tables - generate transition tables and finishes generating output file
1492 void make_tables (void)
1495 int did_eof_rule = false;
1496 struct yytbl_data *yynultrans_tbl = NULL;
1499 skelout (); /* %% [2.0] - break point in skel */
1501 /* First, take care of YY_DO_BEFORE_ACTION depending on yymore
1506 if (yymore_used && !yytext_is_array) {
1507 indent_puts ("YY_G(yytext_ptr) -= YY_G(yy_more_len); \\");
1509 ("yyleng = (int) (yy_cp - YY_G(yytext_ptr)); \\");
1513 indent_puts ("yyleng = (int) (yy_cp - yy_bp); \\");
1515 /* Now also deal with copying yytext_ptr to yytext if needed. */
1516 skelout (); /* %% [3.0] - break point in skel */
1517 if (yytext_is_array) {
1520 ("if ( yyleng + YY_G(yy_more_offset) >= YYLMAX ) \\");
1522 indent_puts ("if ( yyleng >= YYLMAX ) \\");
1526 ("YY_FATAL_ERROR( \"token too large, exceeds YYLMAX\" ); \\");
1531 ("yy_flex_strncpy( &yytext[YY_G(yy_more_offset)], YY_G(yytext_ptr), yyleng + 1 M4_YY_CALL_LAST_ARG); \\");
1532 indent_puts ("yyleng += YY_G(yy_more_offset); \\");
1534 ("YY_G(yy_prev_more_offset) = YY_G(yy_more_offset); \\");
1535 indent_puts ("YY_G(yy_more_offset) = 0; \\");
1539 ("yy_flex_strncpy( yytext, YY_G(yytext_ptr), yyleng + 1 M4_YY_CALL_LAST_ARG); \\");
1545 skelout (); /* %% [4.0] - break point in skel */
1548 /* This is where we REALLY begin generating the tables. */
1550 out_dec ("#define YY_NUM_RULES %d\n", num_rules);
1551 out_dec ("#define YY_END_OF_BUFFER %d\n", num_rules + 1);
1554 /* Need to define the transet type as a size large
1555 * enough to hold the biggest offset.
1557 int total_table_size = tblend + numecs + 1;
1558 char *trans_offset_type =
1559 (total_table_size >= INT16_MAX || long_align) ?
1560 "flex_int32_t" : "flex_int16_t";
1563 indent_puts ("struct yy_trans_info");
1567 /* We require that yy_verify and yy_nxt must be of the same size int. */
1568 indent_put2s ("%s yy_verify;", trans_offset_type);
1570 /* In cases where its sister yy_verify *is* a "yes, there is
1571 * a transition", yy_nxt is the offset (in records) to the
1572 * next state. In most cases where there is no transition,
1573 * the value of yy_nxt is irrelevant. If yy_nxt is the -1th
1574 * record of a state, though, then yy_nxt is the action number
1578 indent_put2s ("%s yy_nxt;", trans_offset_type);
1583 /* We generate a bogus 'struct yy_trans_info' data type
1584 * so we can guarantee that it is always declared in the skel.
1585 * This is so we can compile "sizeof(struct yy_trans_info)"
1589 ("/* This struct is not used in this scanner,");
1590 indent_puts (" but its presence is necessary. */");
1591 indent_puts ("struct yy_trans_info");
1594 indent_puts ("flex_int32_t yy_verify;");
1595 indent_puts ("flex_int32_t yy_nxt;");
1603 struct yytbl_data *tbl;
1606 yytbl_data_compress (tbl);
1607 if (yytbl_data_fwrite (&tableswr, tbl) < 0)
1608 flexerror (_("Could not write ftbl"));
1609 yytbl_data_destroy (tbl);
1612 yytbl_data_compress (tbl);
1613 if (yytbl_data_fwrite (&tableswr, tbl) < 0)
1614 flexerror (_("Could not write ssltbl"));
1615 yytbl_data_destroy (tbl);
1620 yytbl_data_compress (tbl);
1621 if (yytbl_data_fwrite (&tableswr, tbl) < 0)
1623 ("Could not write ecstbl"));
1624 yytbl_data_destroy (tbl);
1632 struct yytbl_data *tbl;
1635 yytbl_data_compress (tbl);
1636 if (yytbl_data_fwrite (&tableswr, tbl) < 0)
1637 flexerror (_("Could not write ftbl"));
1638 yytbl_data_destroy (tbl);
1643 yytbl_data_compress (tbl);
1644 if (yytbl_data_fwrite (&tableswr, tbl) < 0)
1646 ("Could not write ecstbl"));
1647 yytbl_data_destroy (tbl);
1660 struct yytbl_data *tbl;
1663 yytbl_data_compress (tbl);
1664 if (yytbl_data_fwrite (&tableswr, tbl) < 0)
1665 flexerror (_("Could not write eoltbl"));
1666 yytbl_data_destroy (tbl);
1671 /* Definitions for backing up. We don't need them if REJECT
1672 * is being used because then we use an alternative backin-up
1673 * technique instead.
1675 if (num_backing_up > 0 && !reject) {
1676 if (!C_plus_plus && !reentrant) {
1678 ("static yy_state_type yy_last_accepting_state;");
1680 ("static char *yy_last_accepting_cpos;\n");
1685 flex_int32_t *yynultrans_data = 0;
1687 /* Begin generating yy_NUL_trans */
1688 out_str_dec (get_state_decl (), "yy_NUL_trans",
1690 buf_prints (&yydmap_buf,
1691 "\t{YYTD_ID_NUL_TRANS, (void**)&yy_NUL_trans, sizeof(%s)},\n",
1692 (fullspd) ? "struct yy_trans_info*" :
1695 yynultrans_tbl = calloc(1, sizeof (struct yytbl_data));
1696 yytbl_data_init (yynultrans_tbl, YYTD_ID_NUL_TRANS);
1698 yynultrans_tbl->td_flags |= YYTD_PTRANS;
1699 yynultrans_tbl->td_lolen = (flex_uint32_t) (lastdfa + 1);
1700 yynultrans_tbl->td_data = yynultrans_data =
1701 calloc(yynultrans_tbl->td_lolen,
1702 sizeof (flex_int32_t));
1704 for (i = 1; i <= lastdfa; ++i) {
1706 out_dec (" &yy_transition[%d],\n",
1708 yynultrans_data[i] = base[i];
1711 mkdata (nultrans[i]);
1712 yynultrans_data[i] = nultrans[i];
1718 yytbl_data_compress (yynultrans_tbl);
1719 if (yytbl_data_fwrite (&tableswr, yynultrans_tbl) <
1722 ("Could not write yynultrans_tbl"));
1725 if (yynultrans_tbl != NULL) {
1726 yytbl_data_destroy (yynultrans_tbl);
1727 yynultrans_tbl = NULL;
1730 /* End generating yy_NUL_trans */
1733 if (!C_plus_plus && !reentrant) {
1734 indent_puts ("extern int yy_flex_debug;");
1735 indent_put2s ("int yy_flex_debug = %s;\n",
1736 ddebug ? "1" : "0");
1739 if (ddebug) { /* Spit out table mapping rules to line numbers. */
1740 out_str_dec (long_align ? get_int32_decl () :
1741 get_int16_decl (), "yy_rule_linenum",
1743 for (i = 1; i < num_rules; ++i)
1744 mkdata (rule_linenum[i]);
1749 outn ("m4_ifdef( [[M4_YY_USES_REJECT]],\n[[");
1750 /* Declare state buffer variables. */
1751 if (!C_plus_plus && !reentrant) {
1752 outn ("static yy_state_type *yy_state_buf=0, *yy_state_ptr=0;");
1753 outn ("static char *yy_full_match;");
1754 outn ("static int yy_lp;");
1757 if (variable_trailing_context_rules) {
1758 if (!C_plus_plus && !reentrant) {
1759 outn ("static int yy_looking_for_trail_begin = 0;");
1760 outn ("static int yy_full_lp;");
1761 outn ("static int *yy_full_state;");
1764 out_hex ("#define YY_TRAILING_MASK 0x%x\n",
1765 (unsigned int) YY_TRAILING_MASK);
1766 out_hex ("#define YY_TRAILING_HEAD_MASK 0x%x\n",
1767 (unsigned int) YY_TRAILING_HEAD_MASK);
1770 outn ("#define REJECT \\");
1772 outn ("*yy_cp = YY_G(yy_hold_char); /* undo effects of setting up yytext */ \\");
1773 outn ("yy_cp = YY_G(yy_full_match); /* restore poss. backed-over text */ \\");
1775 if (variable_trailing_context_rules) {
1776 outn ("YY_G(yy_lp) = YY_G(yy_full_lp); /* restore orig. accepting pos. */ \\");
1777 outn ("YY_G(yy_state_ptr) = YY_G(yy_full_state); /* restore orig. state */ \\");
1778 outn ("yy_current_state = *YY_G(yy_state_ptr); /* restore curr. state */ \\");
1781 outn ("++YY_G(yy_lp); \\");
1782 outn ("goto find_rule; \\");
1789 outn ("/* The intent behind this definition is that it'll catch");
1790 outn (" * any uses of REJECT which flex missed.");
1792 outn ("#define REJECT reject_used_but_not_detected");
1797 if (yytext_is_array) {
1799 indent_puts ("static int yy_more_offset = 0;");
1800 indent_puts ("static int yy_prev_more_offset = 0;");
1803 else if (!reentrant) {
1805 ("static int yy_more_flag = 0;");
1807 ("static int yy_more_len = 0;");
1811 if (yytext_is_array) {
1813 ("#define yymore() (YY_G(yy_more_offset) = yy_flex_strlen( yytext M4_YY_CALL_LAST_ARG))");
1814 indent_puts ("#define YY_NEED_STRLEN");
1815 indent_puts ("#define YY_MORE_ADJ 0");
1817 ("#define YY_RESTORE_YY_MORE_OFFSET \\");
1819 indent_puts ("{ \\");
1821 ("YY_G(yy_more_offset) = YY_G(yy_prev_more_offset); \\");
1822 indent_puts ("yyleng -= YY_G(yy_more_offset); \\");
1828 ("#define yymore() (YY_G(yy_more_flag) = 1)");
1830 ("#define YY_MORE_ADJ YY_G(yy_more_len)");
1831 indent_puts ("#define YY_RESTORE_YY_MORE_OFFSET");
1837 ("#define yymore() yymore_used_but_not_detected");
1838 indent_puts ("#define YY_MORE_ADJ 0");
1839 indent_puts ("#define YY_RESTORE_YY_MORE_OFFSET");
1843 if (yytext_is_array) {
1844 outn ("#ifndef YYLMAX");
1845 outn ("#define YYLMAX 8192");
1848 outn ("char yytext[YYLMAX];");
1849 outn ("char *yytext_ptr;");
1855 outn ("char *yytext;");
1859 out (&action_array[defs1_offset]);
1861 line_directive_out (stdout, 0);
1863 skelout (); /* %% [5.0] - break point in skel */
1867 outn ("\terrno=0; \\");
1868 outn ("\twhile ( (result = (int) read( fileno(yyin), buf, (yy_size_t) max_size )) < 0 ) \\");
1870 outn ("\t\tif( errno != EINTR) \\");
1872 outn ("\t\t\tYY_FATAL_ERROR( \"input in flex scanner failed\" ); \\");
1873 outn ("\t\t\tbreak; \\");
1875 outn ("\t\terrno=0; \\");
1876 outn ("\t\tclearerr(yyin); \\");
1881 outn ("\tif ( YY_CURRENT_BUFFER_LVALUE->yy_is_interactive ) \\");
1883 outn ("\t\tint c = '*'; \\");
1884 outn ("\t\tint n; \\");
1885 outn ("\t\tfor ( n = 0; n < max_size && \\");
1886 outn ("\t\t\t (c = getc( yyin )) != EOF && c != '\\n'; ++n ) \\");
1887 outn ("\t\t\tbuf[n] = (char) c; \\");
1888 outn ("\t\tif ( c == '\\n' ) \\");
1889 outn ("\t\t\tbuf[n++] = (char) c; \\");
1890 outn ("\t\tif ( c == EOF && ferror( yyin ) ) \\");
1891 outn ("\t\t\tYY_FATAL_ERROR( \"input in flex scanner failed\" ); \\");
1892 outn ("\t\tresult = n; \\");
1896 outn ("\t\terrno=0; \\");
1897 outn ("\t\twhile ( (result = (int) fread(buf, 1, (yy_size_t) max_size, yyin)) == 0 && ferror(yyin)) \\");
1898 outn ("\t\t\t{ \\");
1899 outn ("\t\t\tif( errno != EINTR) \\");
1900 outn ("\t\t\t\t{ \\");
1901 outn ("\t\t\t\tYY_FATAL_ERROR( \"input in flex scanner failed\" ); \\");
1902 outn ("\t\t\t\tbreak; \\");
1903 outn ("\t\t\t\t} \\");
1904 outn ("\t\t\terrno=0; \\");
1905 outn ("\t\t\tclearerr(yyin); \\");
1906 outn ("\t\t\t} \\");
1911 skelout (); /* %% [6.0] - break point in skel */
1913 indent_puts ("#define YY_RULE_SETUP \\");
1916 indent_puts ("if ( yyleng > 0 ) \\");
1918 indent_puts ("YY_CURRENT_BUFFER_LVALUE->yy_at_bol = \\");
1919 indent_puts ("\t\t(yytext[yyleng - 1] == '\\n'); \\");
1922 indent_puts ("YY_USER_ACTION");
1925 skelout (); /* %% [7.0] - break point in skel */
1927 /* Copy prolog to output file. */
1928 out (&action_array[prolog_offset]);
1930 line_directive_out (stdout, 0);
1932 skelout (); /* %% [8.0] - break point in skel */
1936 if (yymore_used && !yytext_is_array) {
1937 indent_puts ("YY_G(yy_more_len) = 0;");
1938 indent_puts ("if ( YY_G(yy_more_flag) )");
1942 ("YY_G(yy_more_len) = (int) (YY_G(yy_c_buf_p) - YY_G(yytext_ptr));");
1943 indent_puts ("YY_G(yy_more_flag) = 0;");
1948 skelout (); /* %% [9.0] - break point in skel */
1952 /* Note, don't use any indentation. */
1956 skelout (); /* %% [10.0] - break point in skel */
1960 skelout (); /* %% [11.0] - break point in skel */
1961 outn ("m4_ifdef( [[M4_YY_USE_LINENO]],[[");
1963 ("if ( yy_act != YY_END_OF_BUFFER && yy_rule_can_match_eol[yy_act] )");
1966 indent_puts ("int yyl;");
1968 out_str ("for ( yyl = %s; yyl < yyleng; ++yyl )\n",
1969 yymore_used ? (yytext_is_array ? "YY_G(yy_prev_more_offset)" :
1970 "YY_G(yy_more_len)") : "0");
1972 indent_puts ("if ( yytext[yyl] == '\\n' )");
1974 indent_puts ("M4_YY_INCR_LINENO();");
1981 skelout (); /* %% [12.0] - break point in skel */
1983 indent_puts ("if ( yy_flex_debug )");
1987 indent_puts ("if ( yy_act == 0 )");
1989 indent_puts (C_plus_plus ?
1990 "std::cerr << \"--scanner backing up\\n\";" :
1991 "fprintf( stderr, \"--scanner backing up\\n\" );");
1995 out_dec ("else if ( yy_act < %d )\n", num_rules);
2000 ("std::cerr << \"--accepting rule at line \" << yy_rule_linenum[yy_act] <<");
2002 (" \"(\\\"\" << yytext << \"\\\")\\n\";");
2006 ("fprintf( stderr, \"--accepting rule at line %ld (\\\"%s\\\")\\n\",");
2009 (" (long)yy_rule_linenum[yy_act], yytext );");
2015 out_dec ("else if ( yy_act == %d )\n", num_rules);
2020 ("std::cerr << \"--accepting default rule (\\\"\" << yytext << \"\\\")\\n\";");
2024 ("fprintf( stderr, \"--accepting default rule (\\\"%s\\\")\\n\",");
2025 indent_puts (" yytext );");
2031 out_dec ("else if ( yy_act == %d )\n", num_rules + 1);
2034 indent_puts (C_plus_plus ?
2035 "std::cerr << \"--(end of buffer or a NUL)\\n\";" :
2036 "fprintf( stderr, \"--(end of buffer or a NUL)\\n\" );");
2046 ("std::cerr << \"--EOF (start condition \" << YY_START << \")\\n\";");
2050 ("fprintf( stderr, \"--EOF (start condition %d)\\n\", YY_START );");
2059 /* Copy actions to output file. */
2060 skelout (); /* %% [13.0] - break point in skel */
2063 out (&action_array[action_offset]);
2065 line_directive_out (stdout, 0);
2067 /* generate cases for any missing EOF rules */
2068 for (i = 1; i <= lastsc; ++i)
2071 out_str ("case YY_STATE_EOF(%s):\n", scname[i]);
2072 did_eof_rule = true;
2077 indent_puts ("yyterminate();");
2082 /* Generate code for handling NUL's, if needed. */
2084 /* First, deal with backing up and setting up yy_cp if the scanner
2085 * finds that it should JAM on the NUL.
2087 skelout (); /* %% [14.0] - break point in skel */
2090 if (fullspd || fulltbl)
2091 indent_puts ("yy_cp = YY_G(yy_c_buf_p);");
2093 else { /* compressed table */
2094 if (!reject && !interactive) {
2095 /* Do the guaranteed-needed backing up to figure
2099 ("yy_cp = YY_G(yy_last_accepting_cpos);");
2101 ("yy_current_state = YY_G(yy_last_accepting_state);");
2105 /* Still need to initialize yy_cp, though
2106 * yy_current_state was set up by
2107 * yy_get_previous_state().
2109 indent_puts ("yy_cp = YY_G(yy_c_buf_p);");
2113 /* Generate code for yy_get_previous_state(). */
2115 skelout (); /* %% [15.0] - break point in skel */
2120 skelout (); /* %% [16.0] - break point in skel */
2121 gen_next_state (true);
2124 skelout (); /* %% [17.0] - break point in skel */
2127 skelout (); /* %% [18.0] - break point in skel */
2128 skelout (); /* %% [19.0] - break point in skel */
2129 /* Update BOL and yylineno inside of input(). */
2132 ("YY_CURRENT_BUFFER_LVALUE->yy_at_bol = (c == '\\n');");
2135 ("if ( YY_CURRENT_BUFFER_LVALUE->yy_at_bol )");
2137 indent_puts ("M4_YY_INCR_LINENO();");
2142 else if (do_yylineno) {
2143 indent_puts ("if ( c == '\\n' )");
2145 indent_puts ("M4_YY_INCR_LINENO();");
2151 /* Copy remainder of input to output. */
2153 line_directive_out (stdout, 1);
2157 if (!no_section3_escape)
2158 fputs("[[", stdout);
2159 (void) flexscan (); /* copy remainder of input to output */
2160 if (!no_section3_escape)
2161 fputs("]]", stdout);