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 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 (void)
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 static struct yytbl_data *mkecstbl (void)
437 struct yytbl_data *tbl = 0;
438 flex_int32_t *tdata = 0;
440 tbl = (struct yytbl_data *) calloc (1, sizeof (struct yytbl_data));
441 yytbl_data_init (tbl, YYTD_ID_EC);
442 tbl->td_flags |= YYTD_DATA32;
444 tbl->td_lolen = csize;
446 tbl->td_data = tdata =
447 (flex_int32_t *) calloc (tbl->td_lolen, sizeof (flex_int32_t));
449 for (i = 1; i < csize; ++i) {
450 ecgroup[i] = ABS (ecgroup[i]);
451 tdata[i] = ecgroup[i];
454 buf_prints (&yydmap_buf,
455 "\t{YYTD_ID_EC, (void**)&yy_ec, sizeof(%s)},\n",
461 /* Generate equivalence-class tables. */
468 out_str_dec (get_int32_decl (), "yy_ec", csize);
470 for (i = 1; i < csize; ++i) {
471 ecgroup[i] = ABS (ecgroup[i]);
478 fputs (_("\n\nEquivalence Classes:\n\n"), stderr);
482 for (j = 0; j < numrows; ++j) {
483 for (i = j; i < csize; i = i + numrows) {
484 fprintf (stderr, "%4s = %-2d",
485 readable_form (i), ecgroup[i]);
496 /* Generate the code to find the action number. */
498 void gen_find_action ()
501 indent_puts ("yy_act = yy_current_state[-1].yy_nxt;");
504 indent_puts ("yy_act = yy_accept[yy_current_state];");
507 indent_puts ("yy_current_state = *--YY_G(yy_state_ptr);");
508 indent_puts ("YY_G(yy_lp) = yy_accept[yy_current_state];");
510 outn ("goto find_rule; /* avoid `defined but not used' warning */");
511 outn ("find_rule: /* we branch to this label when backing up */");
514 ("for ( ; ; ) /* until we find what rule we matched */");
521 ("if ( YY_G(yy_lp) && YY_G(yy_lp) < yy_accept[yy_current_state + 1] )");
524 indent_puts ("yy_act = yy_acclist[YY_G(yy_lp)];");
526 if (variable_trailing_context_rules) {
528 ("if ( yy_act & YY_TRAILING_HEAD_MASK ||");
529 indent_puts (" YY_G(yy_looking_for_trail_begin) )");
534 ("if ( yy_act == YY_G(yy_looking_for_trail_begin) )");
537 indent_puts ("YY_G(yy_looking_for_trail_begin) = 0;");
538 indent_puts ("yy_act &= ~YY_TRAILING_HEAD_MASK;");
539 indent_puts ("break;");
547 ("else if ( yy_act & YY_TRAILING_MASK )");
551 ("YY_G(yy_looking_for_trail_begin) = yy_act & ~YY_TRAILING_MASK;");
553 ("YY_G(yy_looking_for_trail_begin) |= YY_TRAILING_HEAD_MASK;");
556 /* Remember matched text in case we back up
560 ("YY_G(yy_full_match) = yy_cp;");
562 ("YY_G(yy_full_state) = YY_G(yy_state_ptr);");
563 indent_puts ("YY_G(yy_full_lp) = YY_G(yy_lp);");
569 indent_puts ("else");
572 indent_puts ("YY_G(yy_full_match) = yy_cp;");
574 ("YY_G(yy_full_state) = YY_G(yy_state_ptr);");
575 indent_puts ("YY_G(yy_full_lp) = YY_G(yy_lp);");
576 indent_puts ("break;");
580 indent_puts ("++YY_G(yy_lp);");
581 indent_puts ("goto find_rule;");
585 /* Remember matched text in case we back up due to
586 * trailing context plus REJECT.
590 indent_puts ("YY_G(yy_full_match) = yy_cp;");
591 indent_puts ("break;");
599 indent_puts ("--yy_cp;");
601 /* We could consolidate the following two lines with those at
602 * the beginning, but at the cost of complaints that we're
603 * branching inside a loop.
605 indent_puts ("yy_current_state = *--YY_G(yy_state_ptr);");
606 indent_puts ("YY_G(yy_lp) = yy_accept[yy_current_state];");
613 else { /* compressed */
614 indent_puts ("yy_act = yy_accept[yy_current_state];");
616 if (interactive && !reject) {
617 /* Do the guaranteed-needed backing up to figure out
620 indent_puts ("if ( yy_act == 0 )");
622 indent_puts ("{ /* have to back up */");
624 ("yy_cp = YY_G(yy_last_accepting_cpos);");
626 ("yy_current_state = YY_G(yy_last_accepting_state);");
628 ("yy_act = yy_accept[yy_current_state];");
635 /* mkftbl - make the full table and return the struct .
636 * you should call mkecstbl() after this.
639 struct yytbl_data *mkftbl (void)
642 int end_of_buffer_action = num_rules + 1;
643 struct yytbl_data *tbl;
644 flex_int32_t *tdata = 0;
646 tbl = (struct yytbl_data *) calloc (1, sizeof (struct yytbl_data));
647 yytbl_data_init (tbl, YYTD_ID_ACCEPT);
648 tbl->td_flags |= YYTD_DATA32;
649 tbl->td_hilen = 0; /* it's a one-dimensional array */
650 tbl->td_lolen = lastdfa + 1;
652 tbl->td_data = tdata =
653 (flex_int32_t *) calloc (tbl->td_lolen, sizeof (flex_int32_t));
655 dfaacc[end_of_buffer_state].dfaacc_state = end_of_buffer_action;
657 for (i = 1; i <= lastdfa; ++i) {
658 int anum = dfaacc[i].dfaacc_state;
663 fprintf (stderr, _("state # %d accepts: [%d]\n"),
667 buf_prints (&yydmap_buf,
668 "\t{YYTD_ID_ACCEPT, (void**)&yy_accept, sizeof(%s)},\n",
669 long_align ? "flex_int32_t" : "flex_int16_t");
674 /* genftbl - generate full transition table */
679 int end_of_buffer_action = num_rules + 1;
681 out_str_dec (long_align ? get_int32_decl () : get_int16_decl (),
682 "yy_accept", lastdfa + 1);
684 dfaacc[end_of_buffer_state].dfaacc_state = end_of_buffer_action;
686 for (i = 1; i <= lastdfa; ++i) {
687 int anum = dfaacc[i].dfaacc_state;
692 fprintf (stderr, _("state # %d accepts: [%d]\n"),
701 /* Don't have to dump the actual full table entries - they were
702 * created on-the-fly.
707 /* Generate the code to find the next compressed-table state. */
709 void gen_next_compressed_state (char_map)
712 indent_put2s ("YY_CHAR yy_c = %s;", char_map);
714 /* Save the backing-up info \before/ computing the next state
715 * because we always compute one more state than needed - we
716 * always proceed until we reach a jam state
721 ("while ( yy_chk[yy_base[yy_current_state] + yy_c] != yy_current_state )");
724 indent_puts ("yy_current_state = (int) yy_def[yy_current_state];");
727 /* We've arrange it so that templates are never chained
728 * to one another. This means we can afford to make a
729 * very simple test to see if we need to convert to
730 * yy_c's meta-equivalence class without worrying
731 * about erroneously looking up the meta-equivalence
736 /* lastdfa + 2 is the beginning of the templates */
737 out_dec ("if ( yy_current_state >= %d )\n", lastdfa + 2);
740 indent_puts ("yy_c = yy_meta[(unsigned int) yy_c];");
748 ("yy_current_state = yy_nxt[yy_base[yy_current_state] + (unsigned int) yy_c];");
752 /* Generate the code to find the next match. */
754 void gen_next_match ()
756 /* NOTE - changes in here should be reflected in gen_next_state() and
759 char *char_map = useecs ?
760 "yy_ec[YY_SC_TO_UI(*yy_cp)] " : "YY_SC_TO_UI(*yy_cp)";
762 char *char_map_2 = useecs ?
763 "yy_ec[YY_SC_TO_UI(*++yy_cp)] " : "YY_SC_TO_UI(*++yy_cp)";
768 ("while ( (yy_current_state = yy_nxt[yy_current_state][ %s ]) > 0 )",
772 ("while ( (yy_current_state = yy_nxt[yy_current_state*YY_NXT_LOLEN + %s ]) > 0 )",
777 if (num_backing_up > 0) {
783 indent_puts ("++yy_cp;");
785 if (num_backing_up > 0)
792 indent_puts ("yy_current_state = -yy_current_state;");
798 ("yyconst struct yy_trans_info *yy_trans_info;\n");
799 indent_puts ("YY_CHAR yy_c;\n");
800 indent_put2s ("for ( yy_c = %s;", char_map);
802 (" (yy_trans_info = &yy_current_state[(unsigned int) yy_c])->");
803 indent_puts ("yy_verify == yy_c;");
804 indent_put2s (" yy_c = %s )", char_map_2);
808 if (num_backing_up > 0)
811 indent_puts ("yy_current_state += yy_trans_info->yy_nxt;");
813 if (num_backing_up > 0) {
823 else { /* compressed */
829 gen_next_state (false);
831 indent_puts ("++yy_cp;");
840 out_dec ("while ( yy_base[yy_current_state] != %d );\n", jambase);
842 out_dec ("while ( yy_current_state != %d );\n",
845 if (!reject && !interactive) {
846 /* Do the guaranteed-needed backing up to figure out
850 ("yy_cp = YY_G(yy_last_accepting_cpos);");
852 ("yy_current_state = YY_G(yy_last_accepting_state);");
858 /* Generate the code to find the next state. */
860 void gen_next_state (worry_about_NULs)
861 int worry_about_NULs;
862 { /* NOTE - changes in here should be reflected in gen_next_match() */
865 if (worry_about_NULs && !nultrans) {
867 snprintf (char_map, sizeof(char_map),
868 "(*yy_cp ? yy_ec[YY_SC_TO_UI(*yy_cp)] : %d)",
871 snprintf (char_map, sizeof(char_map),
872 "(*yy_cp ? YY_SC_TO_UI(*yy_cp) : %d)",
877 strcpy (char_map, useecs ?
878 "yy_ec[YY_SC_TO_UI(*yy_cp)] " :
879 "YY_SC_TO_UI(*yy_cp)");
881 if (worry_about_NULs && nultrans) {
882 if (!fulltbl && !fullspd)
883 /* Compressed tables back up *before* they match. */
886 indent_puts ("if ( *yy_cp )");
894 ("yy_current_state = yy_nxt[yy_current_state][%s];",
898 ("yy_current_state = yy_nxt[yy_current_state*YY_NXT_LOLEN + %s];",
904 ("yy_current_state += yy_current_state[%s].yy_nxt;",
908 gen_next_compressed_state (char_map);
910 if (worry_about_NULs && nultrans) {
914 indent_puts ("else");
917 ("yy_current_state = yy_NUL_trans[yy_current_state];");
921 if (fullspd || fulltbl)
925 indent_puts ("*YY_G(yy_state_ptr)++ = yy_current_state;");
929 /* Generate the code to make a NUL transition. */
931 void gen_NUL_trans ()
932 { /* NOTE - changes in here should be reflected in gen_next_match() */
933 /* Only generate a definition for "yy_cp" if we'll generate code
934 * that uses it. Otherwise lint and the like complain.
936 int need_backing_up = (num_backing_up > 0 && !reject);
938 if (need_backing_up && (!nultrans || fullspd || fulltbl))
939 /* We're going to need yy_cp lying around for the call
940 * below to gen_backing_up().
942 indent_puts ("char *yy_cp = YY_G(yy_c_buf_p);");
948 ("yy_current_state = yy_NUL_trans[yy_current_state];");
949 indent_puts ("yy_is_jam = (yy_current_state == 0);");
955 out_dec ("yy_current_state = yy_nxt[yy_current_state][%d];\n", NUL_ec);
957 out_dec ("yy_current_state = yy_nxt[yy_current_state*YY_NXT_LOLEN + %d];\n", NUL_ec);
958 indent_puts ("yy_is_jam = (yy_current_state <= 0);");
963 out_dec ("int yy_c = %d;\n", NUL_ec);
966 ("yyconst struct yy_trans_info *yy_trans_info;\n");
968 ("yy_trans_info = &yy_current_state[(unsigned int) yy_c];");
969 indent_puts ("yy_current_state += yy_trans_info->yy_nxt;");
972 ("yy_is_jam = (yy_trans_info->yy_verify != yy_c);");
978 snprintf (NUL_ec_str, sizeof(NUL_ec_str), "%d", NUL_ec);
979 gen_next_compressed_state (NUL_ec_str);
982 out_dec ("yy_is_jam = (yy_current_state == %d);\n",
986 /* Only stack this state if it's a transition we
987 * actually make. If we stack it on a jam, then
988 * the state stack and yy_c_buf_p get out of sync.
990 indent_puts ("if ( ! yy_is_jam )");
993 ("*YY_G(yy_state_ptr)++ = yy_current_state;");
998 /* If we've entered an accepting state, back up; note that
999 * compressed tables have *already* done such backing up, so
1000 * we needn't bother with it again.
1002 if (need_backing_up && (fullspd || fulltbl)) {
1004 indent_puts ("if ( ! yy_is_jam )");
1014 /* Generate the code to find the start state. */
1016 void gen_start_state ()
1021 ("yy_current_state = yy_start_state_list[YY_G(yy_start) + YY_AT_BOL()];");
1025 ("yy_current_state = yy_start_state_list[YY_G(yy_start)];");
1029 indent_puts ("yy_current_state = YY_G(yy_start);");
1032 indent_puts ("yy_current_state += YY_AT_BOL();");
1035 /* Set up for storing up states. */
1036 outn ("m4_ifdef( [[M4_YY_USES_REJECT]],\n[[");
1038 ("YY_G(yy_state_ptr) = YY_G(yy_state_buf);");
1040 ("*YY_G(yy_state_ptr)++ = yy_current_state;");
1047 /* gentabs - generate data statements for the transition tables */
1051 int i, j, k, *accset, nacc, *acc_array, total_states;
1052 int end_of_buffer_action = num_rules + 1;
1053 struct yytbl_data *yyacc_tbl = 0, *yymeta_tbl = 0, *yybase_tbl = 0,
1054 *yydef_tbl = 0, *yynxt_tbl = 0, *yychk_tbl = 0, *yyacclist_tbl=0;
1055 flex_int32_t *yyacc_data = 0, *yybase_data = 0, *yydef_data = 0,
1056 *yynxt_data = 0, *yychk_data = 0, *yyacclist_data=0;
1057 flex_int32_t yybase_curr = 0, yyacclist_curr=0,yyacc_curr=0;
1059 acc_array = allocate_integer_array (current_max_dfas);
1062 /* The compressed table format jams by entering the "jam state",
1063 * losing information about the previous state in the process.
1064 * In order to recover the previous state, we effectively need
1065 * to keep backing-up information.
1070 /* Write out accepting list and pointer list.
1072 * First we generate the "yy_acclist" array. In the process,
1073 * we compute the indices that will go into the "yy_accept"
1074 * array, and save the indices in the dfaacc array.
1076 int EOB_accepting_list[2];
1078 /* Set up accepting structures for the End Of Buffer state. */
1079 EOB_accepting_list[0] = 0;
1080 EOB_accepting_list[1] = end_of_buffer_action;
1081 accsiz[end_of_buffer_state] = 1;
1082 dfaacc[end_of_buffer_state].dfaacc_set =
1085 out_str_dec (long_align ? get_int32_decl () :
1086 get_int16_decl (), "yy_acclist", MAX (numas,
1089 buf_prints (&yydmap_buf,
1090 "\t{YYTD_ID_ACCLIST, (void**)&yy_acclist, sizeof(%s)},\n",
1091 long_align ? "flex_int32_t" : "flex_int16_t");
1093 yyacclist_tbl = (struct yytbl_data*)calloc(1,sizeof(struct yytbl_data));
1094 yytbl_data_init (yyacclist_tbl, YYTD_ID_ACCLIST);
1095 yyacclist_tbl->td_lolen = MAX(numas,1) + 1;
1096 yyacclist_tbl->td_data = yyacclist_data =
1097 (flex_int32_t *) calloc (yyacclist_tbl->td_lolen, sizeof (flex_int32_t));
1100 j = 1; /* index into "yy_acclist" array */
1102 for (i = 1; i <= lastdfa; ++i) {
1105 if (accsiz[i] != 0) {
1106 accset = dfaacc[i].dfaacc_set;
1111 _("state # %d accepts: "),
1114 for (k = 1; k <= nacc; ++k) {
1115 int accnum = accset[k];
1119 if (variable_trailing_context_rules
1121 YY_TRAILING_HEAD_MASK)
1123 && accnum <= num_rules
1124 && rule_type[accnum] ==
1126 /* Special hack to flag
1127 * accepting number as part
1128 * of trailing context rule.
1130 accnum |= YY_TRAILING_MASK;
1134 yyacclist_data[yyacclist_curr++] = accnum;
1137 fprintf (stderr, "[%d]",
1151 /* add accepting number for the "jam" state */
1156 yytbl_data_compress (yyacclist_tbl);
1157 if (yytbl_data_fwrite (&tableswr, yyacclist_tbl) < 0)
1158 flexerror (_("Could not write yyacclist_tbl"));
1159 yytbl_data_destroy (yyacclist_tbl);
1160 yyacclist_tbl = NULL;
1165 dfaacc[end_of_buffer_state].dfaacc_state =
1166 end_of_buffer_action;
1168 for (i = 1; i <= lastdfa; ++i)
1169 acc_array[i] = dfaacc[i].dfaacc_state;
1171 /* add accepting number for jam state */
1175 /* Begin generating yy_accept */
1177 /* Spit out "yy_accept" array. If we're doing "reject", it'll be
1178 * pointers into the "yy_acclist" array. Otherwise it's actual
1179 * accepting numbers. In either case, we just dump the numbers.
1182 /* "lastdfa + 2" is the size of "yy_accept"; includes room for C arrays
1183 * beginning at 0 and for "jam" state.
1188 /* We put a "cap" on the table associating lists of accepting
1189 * numbers with state numbers. This is needed because we tell
1190 * where the end of an accepting list is by looking at where
1191 * the list for the next state starts.
1195 out_str_dec (long_align ? get_int32_decl () : get_int16_decl (),
1198 buf_prints (&yydmap_buf,
1199 "\t{YYTD_ID_ACCEPT, (void**)&yy_accept, sizeof(%s)},\n",
1200 long_align ? "flex_int32_t" : "flex_int16_t");
1203 (struct yytbl_data *) calloc (1,
1204 sizeof (struct yytbl_data));
1205 yytbl_data_init (yyacc_tbl, YYTD_ID_ACCEPT);
1206 yyacc_tbl->td_lolen = k;
1207 yyacc_tbl->td_data = yyacc_data =
1208 (flex_int32_t *) calloc (yyacc_tbl->td_lolen, sizeof (flex_int32_t));
1211 for (i = 1; i <= lastdfa; ++i) {
1212 mkdata (acc_array[i]);
1213 yyacc_data[yyacc_curr++] = acc_array[i];
1215 if (!reject && trace && acc_array[i])
1216 fprintf (stderr, _("state # %d accepts: [%d]\n"),
1220 /* Add entry for "jam" state. */
1221 mkdata (acc_array[i]);
1222 yyacc_data[yyacc_curr++] = acc_array[i];
1225 /* Add "cap" for the list. */
1226 mkdata (acc_array[i]);
1227 yyacc_data[yyacc_curr++] = acc_array[i];
1232 yytbl_data_compress (yyacc_tbl);
1233 if (yytbl_data_fwrite (&tableswr, yyacc_tbl) < 0)
1234 flexerror (_("Could not write yyacc_tbl"));
1235 yytbl_data_destroy (yyacc_tbl);
1238 /* End generating yy_accept */
1244 struct yytbl_data *tbl;
1247 yytbl_data_compress (tbl);
1248 if (yytbl_data_fwrite (&tableswr, tbl) < 0)
1249 flexerror (_("Could not write ecstbl"));
1250 yytbl_data_destroy (tbl);
1256 /* Begin generating yy_meta */
1257 /* Write out meta-equivalence classes (used to index
1260 flex_int32_t *yymecs_data = 0;
1262 (struct yytbl_data *) calloc (1,
1265 yytbl_data_init (yymeta_tbl, YYTD_ID_META);
1266 yymeta_tbl->td_lolen = numecs + 1;
1267 yymeta_tbl->td_data = yymecs_data =
1268 (flex_int32_t *) calloc (yymeta_tbl->td_lolen,
1269 sizeof (flex_int32_t));
1272 fputs (_("\n\nMeta-Equivalence Classes:\n"),
1275 out_str_dec (get_int32_decl (), "yy_meta", numecs + 1);
1276 buf_prints (&yydmap_buf,
1277 "\t{YYTD_ID_META, (void**)&yy_meta, sizeof(%s)},\n",
1280 for (i = 1; i <= numecs; ++i) {
1282 fprintf (stderr, "%d = %d\n",
1283 i, ABS (tecbck[i]));
1285 mkdata (ABS (tecbck[i]));
1286 yymecs_data[i] = ABS (tecbck[i]);
1291 yytbl_data_compress (yymeta_tbl);
1292 if (yytbl_data_fwrite (&tableswr, yymeta_tbl) < 0)
1294 ("Could not write yymeta_tbl"));
1295 yytbl_data_destroy (yymeta_tbl);
1298 /* End generating yy_meta */
1301 total_states = lastdfa + numtemps;
1303 /* Begin generating yy_base */
1304 out_str_dec ((tblend >= INT16_MAX || long_align) ?
1305 get_int32_decl () : get_int16_decl (),
1306 "yy_base", total_states + 1);
1308 buf_prints (&yydmap_buf,
1309 "\t{YYTD_ID_BASE, (void**)&yy_base, sizeof(%s)},\n",
1310 (tblend >= INT16_MAX
1311 || long_align) ? "flex_int32_t" : "flex_int16_t");
1313 (struct yytbl_data *) calloc (1,
1314 sizeof (struct yytbl_data));
1315 yytbl_data_init (yybase_tbl, YYTD_ID_BASE);
1316 yybase_tbl->td_lolen = total_states + 1;
1317 yybase_tbl->td_data = yybase_data =
1318 (flex_int32_t *) calloc (yybase_tbl->td_lolen,
1319 sizeof (flex_int32_t));
1322 for (i = 1; i <= lastdfa; ++i) {
1325 if (base[i] == JAMSTATE)
1332 /* Template reference. */
1334 def[i] = lastdfa - d + 1;
1338 yybase_data[yybase_curr++] = base[i];
1341 /* Generate jam state's base index. */
1343 yybase_data[yybase_curr++] = base[i];
1345 for (++i /* skip jam state */ ; i <= total_states; ++i) {
1347 yybase_data[yybase_curr++] = base[i];
1353 yytbl_data_compress (yybase_tbl);
1354 if (yytbl_data_fwrite (&tableswr, yybase_tbl) < 0)
1355 flexerror (_("Could not write yybase_tbl"));
1356 yytbl_data_destroy (yybase_tbl);
1359 /* End generating yy_base */
1362 /* Begin generating yy_def */
1363 out_str_dec ((total_states >= INT16_MAX || long_align) ?
1364 get_int32_decl () : get_int16_decl (),
1365 "yy_def", total_states + 1);
1367 buf_prints (&yydmap_buf,
1368 "\t{YYTD_ID_DEF, (void**)&yy_def, sizeof(%s)},\n",
1369 (total_states >= INT16_MAX
1370 || long_align) ? "flex_int32_t" : "flex_int16_t");
1373 (struct yytbl_data *) calloc (1,
1374 sizeof (struct yytbl_data));
1375 yytbl_data_init (yydef_tbl, YYTD_ID_DEF);
1376 yydef_tbl->td_lolen = total_states + 1;
1377 yydef_tbl->td_data = yydef_data =
1378 (flex_int32_t *) calloc (yydef_tbl->td_lolen, sizeof (flex_int32_t));
1380 for (i = 1; i <= total_states; ++i) {
1382 yydef_data[i] = def[i];
1387 yytbl_data_compress (yydef_tbl);
1388 if (yytbl_data_fwrite (&tableswr, yydef_tbl) < 0)
1389 flexerror (_("Could not write yydef_tbl"));
1390 yytbl_data_destroy (yydef_tbl);
1393 /* End generating yy_def */
1396 /* Begin generating yy_nxt */
1397 out_str_dec ((total_states >= INT16_MAX || long_align) ?
1398 get_int32_decl () : get_int16_decl (), "yy_nxt",
1401 buf_prints (&yydmap_buf,
1402 "\t{YYTD_ID_NXT, (void**)&yy_nxt, sizeof(%s)},\n",
1403 (total_states >= INT16_MAX
1404 || long_align) ? "flex_int32_t" : "flex_int16_t");
1407 (struct yytbl_data *) calloc (1,
1408 sizeof (struct yytbl_data));
1409 yytbl_data_init (yynxt_tbl, YYTD_ID_NXT);
1410 yynxt_tbl->td_lolen = tblend + 1;
1411 yynxt_tbl->td_data = yynxt_data =
1412 (flex_int32_t *) calloc (yynxt_tbl->td_lolen, sizeof (flex_int32_t));
1414 for (i = 1; i <= tblend; ++i) {
1415 /* Note, the order of the following test is important.
1416 * If chk[i] is 0, then nxt[i] is undefined.
1418 if (chk[i] == 0 || nxt[i] == 0)
1419 nxt[i] = jamstate; /* new state is the JAM state */
1422 yynxt_data[i] = nxt[i];
1427 yytbl_data_compress (yynxt_tbl);
1428 if (yytbl_data_fwrite (&tableswr, yynxt_tbl) < 0)
1429 flexerror (_("Could not write yynxt_tbl"));
1430 yytbl_data_destroy (yynxt_tbl);
1433 /* End generating yy_nxt */
1435 /* Begin generating yy_chk */
1436 out_str_dec ((total_states >= INT16_MAX || long_align) ?
1437 get_int32_decl () : get_int16_decl (), "yy_chk",
1440 buf_prints (&yydmap_buf,
1441 "\t{YYTD_ID_CHK, (void**)&yy_chk, sizeof(%s)},\n",
1442 (total_states >= INT16_MAX
1443 || long_align) ? "flex_int32_t" : "flex_int16_t");
1446 (struct yytbl_data *) calloc (1,
1447 sizeof (struct yytbl_data));
1448 yytbl_data_init (yychk_tbl, YYTD_ID_CHK);
1449 yychk_tbl->td_lolen = tblend + 1;
1450 yychk_tbl->td_data = yychk_data =
1451 (flex_int32_t *) calloc (yychk_tbl->td_lolen, sizeof (flex_int32_t));
1453 for (i = 1; i <= tblend; ++i) {
1458 yychk_data[i] = chk[i];
1463 yytbl_data_compress (yychk_tbl);
1464 if (yytbl_data_fwrite (&tableswr, yychk_tbl) < 0)
1465 flexerror (_("Could not write yychk_tbl"));
1466 yytbl_data_destroy (yychk_tbl);
1469 /* End generating yy_chk */
1471 flex_free ((void *) acc_array);
1475 /* Write out a formatted string (with a secondary string argument) at the
1476 * current indentation level, adding a final newline.
1479 void indent_put2s (fmt, arg)
1480 const char *fmt, *arg;
1488 /* Write out a string at the current indentation level, adding a final
1492 void indent_puts (str)
1500 /* make_tables - generate transition tables and finishes generating output file
1506 int did_eof_rule = false;
1507 struct yytbl_data *yynultrans_tbl;
1510 skelout (); /* %% [2.0] - break point in skel */
1512 /* First, take care of YY_DO_BEFORE_ACTION depending on yymore
1517 if (yymore_used && !yytext_is_array) {
1518 indent_puts ("YY_G(yytext_ptr) -= YY_G(yy_more_len); \\");
1520 ("yyleng = (size_t) (yy_cp - YY_G(yytext_ptr)); \\");
1524 indent_puts ("yyleng = (size_t) (yy_cp - yy_bp); \\");
1526 /* Now also deal with copying yytext_ptr to yytext if needed. */
1527 skelout (); /* %% [3.0] - break point in skel */
1528 if (yytext_is_array) {
1531 ("if ( yyleng + YY_G(yy_more_offset) >= YYLMAX ) \\");
1533 indent_puts ("if ( yyleng >= YYLMAX ) \\");
1537 ("YY_FATAL_ERROR( \"token too large, exceeds YYLMAX\" ); \\");
1542 ("yy_flex_strncpy( &yytext[YY_G(yy_more_offset)], YY_G(yytext_ptr), yyleng + 1 M4_YY_CALL_LAST_ARG); \\");
1543 indent_puts ("yyleng += YY_G(yy_more_offset); \\");
1545 ("YY_G(yy_prev_more_offset) = YY_G(yy_more_offset); \\");
1546 indent_puts ("YY_G(yy_more_offset) = 0; \\");
1550 ("yy_flex_strncpy( yytext, YY_G(yytext_ptr), yyleng + 1 M4_YY_CALL_LAST_ARG); \\");
1556 skelout (); /* %% [4.0] - break point in skel */
1559 /* This is where we REALLY begin generating the tables. */
1561 out_dec ("#define YY_NUM_RULES %d\n", num_rules);
1562 out_dec ("#define YY_END_OF_BUFFER %d\n", num_rules + 1);
1565 /* Need to define the transet type as a size large
1566 * enough to hold the biggest offset.
1568 int total_table_size = tblend + numecs + 1;
1569 char *trans_offset_type =
1570 (total_table_size >= INT16_MAX || long_align) ?
1571 "flex_int32_t" : "flex_int16_t";
1574 indent_puts ("struct yy_trans_info");
1578 /* We require that yy_verify and yy_nxt must be of the same size int. */
1579 indent_put2s ("%s yy_verify;", trans_offset_type);
1581 /* In cases where its sister yy_verify *is* a "yes, there is
1582 * a transition", yy_nxt is the offset (in records) to the
1583 * next state. In most cases where there is no transition,
1584 * the value of yy_nxt is irrelevant. If yy_nxt is the -1th
1585 * record of a state, though, then yy_nxt is the action number
1589 indent_put2s ("%s yy_nxt;", trans_offset_type);
1594 /* We generate a bogus 'struct yy_trans_info' data type
1595 * so we can guarantee that it is always declared in the skel.
1596 * This is so we can compile "sizeof(struct yy_trans_info)"
1600 ("/* This struct is not used in this scanner,");
1601 indent_puts (" but its presence is necessary. */");
1602 indent_puts ("struct yy_trans_info");
1605 indent_puts ("flex_int32_t yy_verify;");
1606 indent_puts ("flex_int32_t yy_nxt;");
1614 struct yytbl_data *tbl;
1617 yytbl_data_compress (tbl);
1618 if (yytbl_data_fwrite (&tableswr, tbl) < 0)
1619 flexerror (_("Could not write ftbl"));
1620 yytbl_data_destroy (tbl);
1623 yytbl_data_compress (tbl);
1624 if (yytbl_data_fwrite (&tableswr, tbl) < 0)
1625 flexerror (_("Could not write ssltbl"));
1626 yytbl_data_destroy (tbl);
1631 yytbl_data_compress (tbl);
1632 if (yytbl_data_fwrite (&tableswr, tbl) < 0)
1634 ("Could not write ecstbl"));
1635 yytbl_data_destroy (tbl);
1643 struct yytbl_data *tbl;
1646 yytbl_data_compress (tbl);
1647 if (yytbl_data_fwrite (&tableswr, tbl) < 0)
1648 flexerror (_("Could not write ftbl"));
1649 yytbl_data_destroy (tbl);
1654 yytbl_data_compress (tbl);
1655 if (yytbl_data_fwrite (&tableswr, tbl) < 0)
1657 ("Could not write ecstbl"));
1658 yytbl_data_destroy (tbl);
1671 struct yytbl_data *tbl;
1674 yytbl_data_compress (tbl);
1675 if (yytbl_data_fwrite (&tableswr, tbl) < 0)
1676 flexerror (_("Could not write eoltbl"));
1677 yytbl_data_destroy (tbl);
1682 /* Definitions for backing up. We don't need them if REJECT
1683 * is being used because then we use an alternative backin-up
1684 * technique instead.
1686 if (num_backing_up > 0 && !reject) {
1687 if (!C_plus_plus && !reentrant) {
1689 ("static yy_state_type yy_last_accepting_state;");
1691 ("static char *yy_last_accepting_cpos;\n");
1696 flex_int32_t *yynultrans_data = 0;
1698 /* Begin generating yy_NUL_trans */
1699 out_str_dec (get_state_decl (), "yy_NUL_trans",
1701 buf_prints (&yydmap_buf,
1702 "\t{YYTD_ID_NUL_TRANS, (void**)&yy_NUL_trans, sizeof(%s)},\n",
1703 (fullspd) ? "struct yy_trans_info*" :
1707 (struct yytbl_data *) calloc (1,
1710 yytbl_data_init (yynultrans_tbl, YYTD_ID_NUL_TRANS);
1712 yynultrans_tbl->td_flags |= YYTD_PTRANS;
1713 yynultrans_tbl->td_lolen = lastdfa + 1;
1714 yynultrans_tbl->td_data = yynultrans_data =
1715 (flex_int32_t *) calloc (yynultrans_tbl->td_lolen,
1716 sizeof (flex_int32_t));
1718 for (i = 1; i <= lastdfa; ++i) {
1720 out_dec (" &yy_transition[%d],\n",
1722 yynultrans_data[i] = base[i];
1725 mkdata (nultrans[i]);
1726 yynultrans_data[i] = nultrans[i];
1732 yytbl_data_compress (yynultrans_tbl);
1733 if (yytbl_data_fwrite (&tableswr, yynultrans_tbl) <
1736 ("Could not write yynultrans_tbl"));
1737 yytbl_data_destroy (yynultrans_tbl);
1738 yynultrans_tbl = NULL;
1740 /* End generating yy_NUL_trans */
1743 if (!C_plus_plus && !reentrant) {
1744 indent_puts ("extern int yy_flex_debug;");
1745 indent_put2s ("int yy_flex_debug = %s;\n",
1746 ddebug ? "1" : "0");
1749 if (ddebug) { /* Spit out table mapping rules to line numbers. */
1750 out_str_dec (long_align ? get_int32_decl () :
1751 get_int16_decl (), "yy_rule_linenum",
1753 for (i = 1; i < num_rules; ++i)
1754 mkdata (rule_linenum[i]);
1759 outn ("m4_ifdef( [[M4_YY_USES_REJECT]],\n[[");
1760 /* Declare state buffer variables. */
1761 if (!C_plus_plus && !reentrant) {
1762 outn ("static yy_state_type *yy_state_buf=0, *yy_state_ptr=0;");
1763 outn ("static char *yy_full_match;");
1764 outn ("static int yy_lp;");
1767 if (variable_trailing_context_rules) {
1768 if (!C_plus_plus && !reentrant) {
1769 outn ("static int yy_looking_for_trail_begin = 0;");
1770 outn ("static int yy_full_lp;");
1771 outn ("static int *yy_full_state;");
1774 out_hex ("#define YY_TRAILING_MASK 0x%x\n",
1775 (unsigned int) YY_TRAILING_MASK);
1776 out_hex ("#define YY_TRAILING_HEAD_MASK 0x%x\n",
1777 (unsigned int) YY_TRAILING_HEAD_MASK);
1780 outn ("#define REJECT \\");
1782 outn ("*yy_cp = YY_G(yy_hold_char); /* undo effects of setting up yytext */ \\");
1783 outn ("yy_cp = YY_G(yy_full_match); /* restore poss. backed-over text */ \\");
1785 if (variable_trailing_context_rules) {
1786 outn ("YY_G(yy_lp) = YY_G(yy_full_lp); /* restore orig. accepting pos. */ \\");
1787 outn ("YY_G(yy_state_ptr) = YY_G(yy_full_state); /* restore orig. state */ \\");
1788 outn ("yy_current_state = *YY_G(yy_state_ptr); /* restore curr. state */ \\");
1791 outn ("++YY_G(yy_lp); \\");
1792 outn ("goto find_rule; \\");
1799 outn ("/* The intent behind this definition is that it'll catch");
1800 outn (" * any uses of REJECT which flex missed.");
1802 outn ("#define REJECT reject_used_but_not_detected");
1807 if (yytext_is_array) {
1809 indent_puts ("static int yy_more_offset = 0;");
1810 indent_puts ("static int yy_prev_more_offset = 0;");
1813 else if (!reentrant) {
1815 ("static int yy_more_flag = 0;");
1817 ("static int yy_more_len = 0;");
1821 if (yytext_is_array) {
1823 ("#define yymore() (YY_G(yy_more_offset) = yy_flex_strlen( yytext M4_YY_CALL_LAST_ARG))");
1824 indent_puts ("#define YY_NEED_STRLEN");
1825 indent_puts ("#define YY_MORE_ADJ 0");
1827 ("#define YY_RESTORE_YY_MORE_OFFSET \\");
1829 indent_puts ("{ \\");
1831 ("YY_G(yy_more_offset) = YY_G(yy_prev_more_offset); \\");
1832 indent_puts ("yyleng -= YY_G(yy_more_offset); \\");
1838 ("#define yymore() (YY_G(yy_more_flag) = 1)");
1840 ("#define YY_MORE_ADJ YY_G(yy_more_len)");
1841 indent_puts ("#define YY_RESTORE_YY_MORE_OFFSET");
1847 ("#define yymore() yymore_used_but_not_detected");
1848 indent_puts ("#define YY_MORE_ADJ 0");
1849 indent_puts ("#define YY_RESTORE_YY_MORE_OFFSET");
1853 if (yytext_is_array) {
1854 outn ("#ifndef YYLMAX");
1855 outn ("#define YYLMAX 8192");
1858 outn ("char yytext[YYLMAX];");
1859 outn ("char *yytext_ptr;");
1865 outn ("char *yytext;");
1869 out (&action_array[defs1_offset]);
1871 line_directive_out (stdout, 0);
1873 skelout (); /* %% [5.0] - break point in skel */
1877 outn ("\terrno=0; \\");
1878 outn ("\twhile ( (result = read( fileno(yyin), (char *) buf, max_size )) < 0 ) \\");
1880 outn ("\t\tif( errno != EINTR) \\");
1882 outn ("\t\t\tYY_FATAL_ERROR( \"input in flex scanner failed\" ); \\");
1883 outn ("\t\t\tbreak; \\");
1885 outn ("\t\terrno=0; \\");
1886 outn ("\t\tclearerr(yyin); \\");
1891 outn ("\tif ( YY_CURRENT_BUFFER_LVALUE->yy_is_interactive ) \\");
1893 outn ("\t\tint c = '*'; \\");
1894 outn ("\t\tsize_t n; \\");
1895 outn ("\t\tfor ( n = 0; n < max_size && \\");
1896 outn ("\t\t\t (c = getc( yyin )) != EOF && c != '\\n'; ++n ) \\");
1897 outn ("\t\t\tbuf[n] = (char) c; \\");
1898 outn ("\t\tif ( c == '\\n' ) \\");
1899 outn ("\t\t\tbuf[n++] = (char) c; \\");
1900 outn ("\t\tif ( c == EOF && ferror( yyin ) ) \\");
1901 outn ("\t\t\tYY_FATAL_ERROR( \"input in flex scanner failed\" ); \\");
1902 outn ("\t\tresult = n; \\");
1906 outn ("\t\terrno=0; \\");
1907 outn ("\t\twhile ( (result = fread(buf, 1, max_size, yyin))==0 && ferror(yyin)) \\");
1908 outn ("\t\t\t{ \\");
1909 outn ("\t\t\tif( errno != EINTR) \\");
1910 outn ("\t\t\t\t{ \\");
1911 outn ("\t\t\t\tYY_FATAL_ERROR( \"input in flex scanner failed\" ); \\");
1912 outn ("\t\t\t\tbreak; \\");
1913 outn ("\t\t\t\t} \\");
1914 outn ("\t\t\terrno=0; \\");
1915 outn ("\t\t\tclearerr(yyin); \\");
1916 outn ("\t\t\t} \\");
1921 skelout (); /* %% [6.0] - break point in skel */
1923 indent_puts ("#define YY_RULE_SETUP \\");
1926 indent_puts ("if ( yyleng > 0 ) \\");
1928 indent_puts ("YY_CURRENT_BUFFER_LVALUE->yy_at_bol = \\");
1929 indent_puts ("\t\t(yytext[yyleng - 1] == '\\n'); \\");
1932 indent_puts ("YY_USER_ACTION");
1935 skelout (); /* %% [7.0] - break point in skel */
1937 /* Copy prolog to output file. */
1938 out (&action_array[prolog_offset]);
1940 line_directive_out (stdout, 0);
1942 skelout (); /* %% [8.0] - break point in skel */
1946 if (yymore_used && !yytext_is_array) {
1947 indent_puts ("YY_G(yy_more_len) = 0;");
1948 indent_puts ("if ( YY_G(yy_more_flag) )");
1952 ("YY_G(yy_more_len) = YY_G(yy_c_buf_p) - YY_G(yytext_ptr);");
1953 indent_puts ("YY_G(yy_more_flag) = 0;");
1958 skelout (); /* %% [9.0] - break point in skel */
1962 /* Note, don't use any indentation. */
1966 skelout (); /* %% [10.0] - break point in skel */
1970 skelout (); /* %% [11.0] - break point in skel */
1971 outn ("m4_ifdef( [[M4_YY_USE_LINENO]],[[");
1973 ("if ( yy_act != YY_END_OF_BUFFER && yy_rule_can_match_eol[yy_act] )");
1976 indent_puts ("yy_size_t yyl;");
1978 out_str ("for ( yyl = %s; yyl < yyleng; ++yyl )\n",
1979 yymore_used ? (yytext_is_array ? "YY_G(yy_prev_more_offset)" :
1980 "YY_G(yy_more_len)") : "0");
1982 indent_puts ("if ( yytext[yyl] == '\\n' )");
1984 indent_puts ("M4_YY_INCR_LINENO();");
1991 skelout (); /* %% [12.0] - break point in skel */
1993 indent_puts ("if ( yy_flex_debug )");
1997 indent_puts ("if ( yy_act == 0 )");
1999 indent_puts (C_plus_plus ?
2000 "std::cerr << \"--scanner backing up\\n\";" :
2001 "fprintf( stderr, \"--scanner backing up\\n\" );");
2005 out_dec ("else if ( yy_act < %d )\n", num_rules);
2010 ("std::cerr << \"--accepting rule at line \" << yy_rule_linenum[yy_act] <<");
2012 (" \"(\\\"\" << yytext << \"\\\")\\n\";");
2016 ("fprintf( stderr, \"--accepting rule at line %ld (\\\"%s\\\")\\n\",");
2019 (" (long)yy_rule_linenum[yy_act], yytext );");
2025 out_dec ("else if ( yy_act == %d )\n", num_rules);
2030 ("std::cerr << \"--accepting default rule (\\\"\" << yytext << \"\\\")\\n\";");
2034 ("fprintf( stderr, \"--accepting default rule (\\\"%s\\\")\\n\",");
2035 indent_puts (" yytext );");
2041 out_dec ("else if ( yy_act == %d )\n", num_rules + 1);
2044 indent_puts (C_plus_plus ?
2045 "std::cerr << \"--(end of buffer or a NUL)\\n\";" :
2046 "fprintf( stderr, \"--(end of buffer or a NUL)\\n\" );");
2056 ("std::cerr << \"--EOF (start condition \" << YY_START << \")\\n\";");
2060 ("fprintf( stderr, \"--EOF (start condition %d)\\n\", YY_START );");
2069 /* Copy actions to output file. */
2070 skelout (); /* %% [13.0] - break point in skel */
2073 out (&action_array[action_offset]);
2075 line_directive_out (stdout, 0);
2077 /* generate cases for any missing EOF rules */
2078 for (i = 1; i <= lastsc; ++i)
2081 out_str ("case YY_STATE_EOF(%s):\n", scname[i]);
2082 did_eof_rule = true;
2087 indent_puts ("yyterminate();");
2092 /* Generate code for handling NUL's, if needed. */
2094 /* First, deal with backing up and setting up yy_cp if the scanner
2095 * finds that it should JAM on the NUL.
2097 skelout (); /* %% [14.0] - break point in skel */
2100 if (fullspd || fulltbl)
2101 indent_puts ("yy_cp = YY_G(yy_c_buf_p);");
2103 else { /* compressed table */
2104 if (!reject && !interactive) {
2105 /* Do the guaranteed-needed backing up to figure
2109 ("yy_cp = YY_G(yy_last_accepting_cpos);");
2111 ("yy_current_state = YY_G(yy_last_accepting_state);");
2115 /* Still need to initialize yy_cp, though
2116 * yy_current_state was set up by
2117 * yy_get_previous_state().
2119 indent_puts ("yy_cp = YY_G(yy_c_buf_p);");
2123 /* Generate code for yy_get_previous_state(). */
2125 skelout (); /* %% [15.0] - break point in skel */
2130 skelout (); /* %% [16.0] - break point in skel */
2131 gen_next_state (true);
2134 skelout (); /* %% [17.0] - break point in skel */
2137 skelout (); /* %% [18.0] - break point in skel */
2138 skelout (); /* %% [19.0] - break point in skel */
2139 /* Update BOL and yylineno inside of input(). */
2142 ("YY_CURRENT_BUFFER_LVALUE->yy_at_bol = (c == '\\n');");
2145 ("if ( YY_CURRENT_BUFFER_LVALUE->yy_at_bol )");
2147 indent_puts ("M4_YY_INCR_LINENO();");
2152 else if (do_yylineno) {
2153 indent_puts ("if ( c == '\\n' )");
2155 indent_puts ("M4_YY_INCR_LINENO();");
2161 /* Copy remainder of input to output. */
2163 line_directive_out (stdout, 1);
2167 (void) flexscan (); /* copy remainder of input to output */