FYI: Reply from HP-UX
[git/dscho.git] / flex-2.5.33 / gen.c
blobb78f59581d26fe808cfd42be4b1c19fec0e8a0e0
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 */
7 /* Vern Paxson. */
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 */
17 /* are met: */
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 */
32 /* PURPOSE. */
34 #include "flexdef.h"
35 #include "tables.h"
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)
60 return (gentables)
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)
68 return (gentables)
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)
75 return (gentables)
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. */
82 void do_indent ()
84 register int i = indent_level * 8;
86 while (i >= 8) {
87 outc ('\t');
88 i -= 8;
91 while (i > 0) {
92 outc (' ');
93 --i;
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)
103 int i;
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",
119 "flex_int32_t");
120 return tbl;
123 /* Generate the table for possible eol matches. */
124 static void geneoltbl ()
126 int i;
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",
131 num_rules + 1);
133 if (gentables) {
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. */
137 if ((i % 20) == 19)
138 out ("\n ");
140 out (" };\n");
142 outn ("]])");
146 /* Generate the code to keep backing-up information. */
148 void gen_backing_up ()
150 if (reject || num_backing_up == 0)
151 return;
153 if (fullspd)
154 indent_puts ("if ( yy_current_state[-1].yy_nxt )");
155 else
156 indent_puts ("if ( yy_accept[yy_current_state] )");
158 indent_up ();
159 indent_puts ("{");
160 indent_puts ("YY_G(yy_last_accepting_state) = yy_current_state;");
161 indent_puts ("YY_G(yy_last_accepting_cpos) = yy_cp;");
162 indent_puts ("}");
163 indent_down ();
167 /* Generate the code to perform the backing up. */
169 void gen_bu_action ()
171 if (reject || num_backing_up == 0)
172 return;
174 set_indent (3);
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;");
182 else
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;");
190 outc ('\n');
192 set_indent (0);
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)
204 register int i;
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;
217 tbl->td_hilen = 0;
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)
242 expand_nxt_chk ();
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. */
253 nxt[tblend + 2] = 0;
255 /* Make sure every state has an end-of-buffer transition and an
256 * action #.
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) {
269 tdata[curr++] = 0;
270 tdata[curr++] = base[lastdfa + 1] - i;
273 else if (chk[i] == ACTION_POSITION) {
274 tdata[curr++] = 0;
275 tdata[curr++] = nxt[i];
278 else if (chk[i] > numecs || chk[i] == 0) {
279 tdata[curr++] = 0;
280 tdata[curr++] = 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];
297 return tbl;
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;
308 flex_int32_t i;
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;
313 tbl->td_hilen = 0;
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)
320 tdata[i] = base[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*");
326 return tbl;
331 /* genctbl - generates full speed compressed transition table */
333 void genctbl ()
335 register int i;
336 int end_of_buffer_action = num_rules + 1;
338 /* Table of verify for transition and offset to next state. */
339 if (gentables)
340 out_dec ("static yyconst struct yy_trans_info yy_transition[%d] =\n {\n", tblend + numecs + 1);
341 else
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)
363 expand_nxt_chk ();
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. */
374 nxt[tblend + 2] = 0;
376 /* Make sure every state has an end-of-buffer transition and an
377 * action #.
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],
400 base[nxt[i]] - (i -
401 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]);
409 if (gentables)
410 outn (" };\n");
412 /* Table of pointers to start states. */
413 if (gentables)
414 out_dec ("static yyconst struct yy_trans_info *yy_start_state_list[%d] =\n", lastsc * 2 + 1);
415 else
416 outn ("static yyconst struct yy_trans_info **yy_start_state_list =0;");
418 if (gentables) {
419 outn (" {");
421 for (i = 0; i <= lastsc * 2; ++i)
422 out_dec (" &yy_transition[%d],\n", base[i]);
424 dataend ();
427 if (useecs)
428 genecs ();
432 /* mkecstbl - Make equivalence-class tables. */
434 struct yytbl_data *mkecstbl (void)
436 register int i;
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;
443 tbl->td_hilen = 0;
444 tbl->td_lolen = csize;
446 tbl->td_data = tdata =
447 (flex_int32_t *) calloc (tbl->td_lolen, sizeof (flex_int32_t));
449 for (i = 1; i < csize; ++i) {
450 if (caseins && isupper (i))
451 ecgroup[i] = ecgroup[tolower (i)];
453 ecgroup[i] = ABS (ecgroup[i]);
454 tdata[i] = ecgroup[i];
457 buf_prints (&yydmap_buf,
458 "\t{YYTD_ID_EC, (void**)&yy_ec, sizeof(%s)},\n",
459 "flex_int32_t");
461 return tbl;
464 /* Generate equivalence-class tables. */
466 void genecs ()
468 register int i, j;
469 int numrows;
471 out_str_dec (get_int32_decl (), "yy_ec", csize);
473 for (i = 1; i < csize; ++i) {
474 if (caseins && (i >= 'A') && (i <= 'Z'))
475 ecgroup[i] = ecgroup[clower (i)];
477 ecgroup[i] = ABS (ecgroup[i]);
478 mkdata (ecgroup[i]);
481 dataend ();
483 if (trace) {
484 fputs (_("\n\nEquivalence Classes:\n\n"), stderr);
486 numrows = csize / 8;
488 for (j = 0; j < numrows; ++j) {
489 for (i = j; i < csize; i = i + numrows) {
490 fprintf (stderr, "%4s = %-2d",
491 readable_form (i), ecgroup[i]);
493 putc (' ', stderr);
496 putc ('\n', stderr);
502 /* Generate the code to find the action number. */
504 void gen_find_action ()
506 if (fullspd)
507 indent_puts ("yy_act = yy_current_state[-1].yy_nxt;");
509 else if (fulltbl)
510 indent_puts ("yy_act = yy_accept[yy_current_state];");
512 else if (reject) {
513 indent_puts ("yy_current_state = *--YY_G(yy_state_ptr);");
514 indent_puts ("YY_G(yy_lp) = yy_accept[yy_current_state];");
516 outn ("find_rule: /* we branch to this label when backing up */");
518 indent_puts
519 ("for ( ; ; ) /* until we find what rule we matched */");
521 indent_up ();
523 indent_puts ("{");
525 indent_puts
526 ("if ( YY_G(yy_lp) && YY_G(yy_lp) < yy_accept[yy_current_state + 1] )");
527 indent_up ();
528 indent_puts ("{");
529 indent_puts ("yy_act = yy_acclist[YY_G(yy_lp)];");
531 if (variable_trailing_context_rules) {
532 indent_puts
533 ("if ( yy_act & YY_TRAILING_HEAD_MASK ||");
534 indent_puts (" yy_looking_for_trail_begin )");
535 indent_up ();
536 indent_puts ("{");
538 indent_puts
539 ("if ( yy_act == yy_looking_for_trail_begin )");
540 indent_up ();
541 indent_puts ("{");
542 indent_puts ("yy_looking_for_trail_begin = 0;");
543 indent_puts ("yy_act &= ~YY_TRAILING_HEAD_MASK;");
544 indent_puts ("break;");
545 indent_puts ("}");
546 indent_down ();
548 indent_puts ("}");
549 indent_down ();
551 indent_puts
552 ("else if ( yy_act & YY_TRAILING_MASK )");
553 indent_up ();
554 indent_puts ("{");
555 indent_puts
556 ("yy_looking_for_trail_begin = yy_act & ~YY_TRAILING_MASK;");
557 indent_puts
558 ("yy_looking_for_trail_begin |= YY_TRAILING_HEAD_MASK;");
560 if (real_reject) {
561 /* Remember matched text in case we back up
562 * due to REJECT.
564 indent_puts
565 ("YY_G(yy_full_match) = yy_cp;");
566 indent_puts
567 ("yy_full_state = YY_G(yy_state_ptr);");
568 indent_puts ("yy_full_lp = YY_G(yy_lp);");
571 indent_puts ("}");
572 indent_down ();
574 indent_puts ("else");
575 indent_up ();
576 indent_puts ("{");
577 indent_puts ("YY_G(yy_full_match) = yy_cp;");
578 indent_puts
579 ("yy_full_state = YY_G(yy_state_ptr);");
580 indent_puts ("yy_full_lp = YY_G(yy_lp);");
581 indent_puts ("break;");
582 indent_puts ("}");
583 indent_down ();
585 indent_puts ("++YY_G(yy_lp);");
586 indent_puts ("goto find_rule;");
589 else {
590 /* Remember matched text in case we back up due to
591 * trailing context plus REJECT.
593 indent_up ();
594 indent_puts ("{");
595 indent_puts ("YY_G(yy_full_match) = yy_cp;");
596 indent_puts ("break;");
597 indent_puts ("}");
598 indent_down ();
601 indent_puts ("}");
602 indent_down ();
604 indent_puts ("--yy_cp;");
606 /* We could consolidate the following two lines with those at
607 * the beginning, but at the cost of complaints that we're
608 * branching inside a loop.
610 indent_puts ("yy_current_state = *--YY_G(yy_state_ptr);");
611 indent_puts ("YY_G(yy_lp) = yy_accept[yy_current_state];");
613 indent_puts ("}");
615 indent_down ();
618 else { /* compressed */
619 indent_puts ("yy_act = yy_accept[yy_current_state];");
621 if (interactive && !reject) {
622 /* Do the guaranteed-needed backing up to figure out
623 * the match.
625 indent_puts ("if ( yy_act == 0 )");
626 indent_up ();
627 indent_puts ("{ /* have to back up */");
628 indent_puts
629 ("yy_cp = YY_G(yy_last_accepting_cpos);");
630 indent_puts
631 ("yy_current_state = YY_G(yy_last_accepting_state);");
632 indent_puts
633 ("yy_act = yy_accept[yy_current_state];");
634 indent_puts ("}");
635 indent_down ();
640 /* mkftbl - make the full table and return the struct .
641 * you should call mkecstbl() after this.
644 struct yytbl_data *mkftbl (void)
646 register int i;
647 int end_of_buffer_action = num_rules + 1;
648 struct yytbl_data *tbl;
649 flex_int32_t *tdata = 0;
651 tbl = (struct yytbl_data *) calloc (1, sizeof (struct yytbl_data));
652 yytbl_data_init (tbl, YYTD_ID_ACCEPT);
653 tbl->td_flags |= YYTD_DATA32;
654 tbl->td_hilen = 0; /* it's a one-dimensional array */
655 tbl->td_lolen = lastdfa + 1;
657 tbl->td_data = tdata =
658 (flex_int32_t *) calloc (tbl->td_lolen, sizeof (flex_int32_t));
660 dfaacc[end_of_buffer_state].dfaacc_state = end_of_buffer_action;
662 for (i = 1; i <= lastdfa; ++i) {
663 register int anum = dfaacc[i].dfaacc_state;
665 tdata[i] = anum;
667 if (trace && anum)
668 fprintf (stderr, _("state # %d accepts: [%d]\n"),
669 i, anum);
672 buf_prints (&yydmap_buf,
673 "\t{YYTD_ID_ACCEPT, (void**)&yy_accept, sizeof(%s)},\n",
674 long_align ? "flex_int32_t" : "flex_int16_t");
675 return tbl;
679 /* genftbl - generate full transition table */
681 void genftbl ()
683 register int i;
684 int end_of_buffer_action = num_rules + 1;
686 out_str_dec (long_align ? get_int32_decl () : get_int16_decl (),
687 "yy_accept", lastdfa + 1);
689 dfaacc[end_of_buffer_state].dfaacc_state = end_of_buffer_action;
691 for (i = 1; i <= lastdfa; ++i) {
692 register int anum = dfaacc[i].dfaacc_state;
694 mkdata (anum);
696 if (trace && anum)
697 fprintf (stderr, _("state # %d accepts: [%d]\n"),
698 i, anum);
701 dataend ();
703 if (useecs)
704 genecs ();
706 /* Don't have to dump the actual full table entries - they were
707 * created on-the-fly.
712 /* Generate the code to find the next compressed-table state. */
714 void gen_next_compressed_state (char_map)
715 char *char_map;
717 indent_put2s ("register YY_CHAR yy_c = %s;", char_map);
719 /* Save the backing-up info \before/ computing the next state
720 * because we always compute one more state than needed - we
721 * always proceed until we reach a jam state
723 gen_backing_up ();
725 indent_puts
726 ("while ( yy_chk[yy_base[yy_current_state] + yy_c] != yy_current_state )");
727 indent_up ();
728 indent_puts ("{");
729 indent_puts ("yy_current_state = (int) yy_def[yy_current_state];");
731 if (usemecs) {
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
737 * class twice
739 do_indent ();
741 /* lastdfa + 2 is the beginning of the templates */
742 out_dec ("if ( yy_current_state >= %d )\n", lastdfa + 2);
744 indent_up ();
745 indent_puts ("yy_c = yy_meta[(unsigned int) yy_c];");
746 indent_down ();
749 indent_puts ("}");
750 indent_down ();
752 indent_puts
753 ("yy_current_state = yy_nxt[yy_base[yy_current_state] + (unsigned int) yy_c];");
757 /* Generate the code to find the next match. */
759 void gen_next_match ()
761 /* NOTE - changes in here should be reflected in gen_next_state() and
762 * gen_NUL_trans().
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)";
770 if (fulltbl) {
771 if (gentables)
772 indent_put2s
773 ("while ( (yy_current_state = yy_nxt[yy_current_state][ %s ]) > 0 )",
774 char_map);
775 else
776 indent_put2s
777 ("while ( (yy_current_state = yy_nxt[yy_current_state*YY_NXT_LOLEN + %s ]) > 0 )",
778 char_map);
780 indent_up ();
782 if (num_backing_up > 0) {
783 indent_puts ("{");
784 gen_backing_up ();
785 outc ('\n');
788 indent_puts ("++yy_cp;");
790 if (num_backing_up > 0)
792 indent_puts ("}");
794 indent_down ();
796 outc ('\n');
797 indent_puts ("yy_current_state = -yy_current_state;");
800 else if (fullspd) {
801 indent_puts ("{");
802 indent_puts
803 ("register yyconst struct yy_trans_info *yy_trans_info;\n");
804 indent_puts ("register YY_CHAR yy_c;\n");
805 indent_put2s ("for ( yy_c = %s;", char_map);
806 indent_puts
807 (" (yy_trans_info = &yy_current_state[(unsigned int) yy_c])->");
808 indent_puts ("yy_verify == yy_c;");
809 indent_put2s (" yy_c = %s )", char_map_2);
811 indent_up ();
813 if (num_backing_up > 0)
814 indent_puts ("{");
816 indent_puts ("yy_current_state += yy_trans_info->yy_nxt;");
818 if (num_backing_up > 0) {
819 outc ('\n');
820 gen_backing_up ();
821 indent_puts ("}");
824 indent_down ();
825 indent_puts ("}");
828 else { /* compressed */
829 indent_puts ("do");
831 indent_up ();
832 indent_puts ("{");
834 gen_next_state (false);
836 indent_puts ("++yy_cp;");
839 indent_puts ("}");
840 indent_down ();
842 do_indent ();
844 if (interactive)
845 out_dec ("while ( yy_base[yy_current_state] != %d );\n", jambase);
846 else
847 out_dec ("while ( yy_current_state != %d );\n",
848 jamstate);
850 if (!reject && !interactive) {
851 /* Do the guaranteed-needed backing up to figure out
852 * the match.
854 indent_puts
855 ("yy_cp = YY_G(yy_last_accepting_cpos);");
856 indent_puts
857 ("yy_current_state = YY_G(yy_last_accepting_state);");
863 /* Generate the code to find the next state. */
865 void gen_next_state (worry_about_NULs)
866 int worry_about_NULs;
867 { /* NOTE - changes in here should be reflected in gen_next_match() */
868 char char_map[256];
870 if (worry_about_NULs && !nultrans) {
871 if (useecs)
872 (void) sprintf (char_map,
873 "(*yy_cp ? yy_ec[YY_SC_TO_UI(*yy_cp)] : %d)",
874 NUL_ec);
875 else
876 (void) sprintf (char_map,
877 "(*yy_cp ? YY_SC_TO_UI(*yy_cp) : %d)",
878 NUL_ec);
881 else
882 strcpy (char_map, useecs ?
883 "yy_ec[YY_SC_TO_UI(*yy_cp)]" :
884 "YY_SC_TO_UI(*yy_cp)");
886 if (worry_about_NULs && nultrans) {
887 if (!fulltbl && !fullspd)
888 /* Compressed tables back up *before* they match. */
889 gen_backing_up ();
891 indent_puts ("if ( *yy_cp )");
892 indent_up ();
893 indent_puts ("{");
896 if (fulltbl) {
897 if (gentables)
898 indent_put2s
899 ("yy_current_state = yy_nxt[yy_current_state][%s];",
900 char_map);
901 else
902 indent_put2s
903 ("yy_current_state = yy_nxt[yy_current_state*YY_NXT_LOLEN + %s];",
904 char_map);
907 else if (fullspd)
908 indent_put2s
909 ("yy_current_state += yy_current_state[%s].yy_nxt;",
910 char_map);
912 else
913 gen_next_compressed_state (char_map);
915 if (worry_about_NULs && nultrans) {
917 indent_puts ("}");
918 indent_down ();
919 indent_puts ("else");
920 indent_up ();
921 indent_puts
922 ("yy_current_state = yy_NUL_trans[yy_current_state];");
923 indent_down ();
926 if (fullspd || fulltbl)
927 gen_backing_up ();
929 if (reject)
930 indent_puts ("*YY_G(yy_state_ptr)++ = yy_current_state;");
934 /* Generate the code to make a NUL transition. */
936 void gen_NUL_trans ()
937 { /* NOTE - changes in here should be reflected in gen_next_match() */
938 /* Only generate a definition for "yy_cp" if we'll generate code
939 * that uses it. Otherwise lint and the like complain.
941 int need_backing_up = (num_backing_up > 0 && !reject);
943 if (need_backing_up && (!nultrans || fullspd || fulltbl))
944 /* We're going to need yy_cp lying around for the call
945 * below to gen_backing_up().
947 indent_puts ("register char *yy_cp = YY_G(yy_c_buf_p);");
949 outc ('\n');
951 if (nultrans) {
952 indent_puts
953 ("yy_current_state = yy_NUL_trans[yy_current_state];");
954 indent_puts ("yy_is_jam = (yy_current_state == 0);");
957 else if (fulltbl) {
958 do_indent ();
959 if (gentables)
960 out_dec ("yy_current_state = yy_nxt[yy_current_state][%d];\n", NUL_ec);
961 else
962 out_dec ("yy_current_state = yy_nxt[yy_current_state*YY_NXT_LOLEN + %d];\n", NUL_ec);
963 indent_puts ("yy_is_jam = (yy_current_state <= 0);");
966 else if (fullspd) {
967 do_indent ();
968 out_dec ("register int yy_c = %d;\n", NUL_ec);
970 indent_puts
971 ("register yyconst struct yy_trans_info *yy_trans_info;\n");
972 indent_puts
973 ("yy_trans_info = &yy_current_state[(unsigned int) yy_c];");
974 indent_puts ("yy_current_state += yy_trans_info->yy_nxt;");
976 indent_puts
977 ("yy_is_jam = (yy_trans_info->yy_verify != yy_c);");
980 else {
981 char NUL_ec_str[20];
983 (void) sprintf (NUL_ec_str, "%d", NUL_ec);
984 gen_next_compressed_state (NUL_ec_str);
986 do_indent ();
987 out_dec ("yy_is_jam = (yy_current_state == %d);\n",
988 jamstate);
990 if (reject) {
991 /* Only stack this state if it's a transition we
992 * actually make. If we stack it on a jam, then
993 * the state stack and yy_c_buf_p get out of sync.
995 indent_puts ("if ( ! yy_is_jam )");
996 indent_up ();
997 indent_puts
998 ("*YY_G(yy_state_ptr)++ = yy_current_state;");
999 indent_down ();
1003 /* If we've entered an accepting state, back up; note that
1004 * compressed tables have *already* done such backing up, so
1005 * we needn't bother with it again.
1007 if (need_backing_up && (fullspd || fulltbl)) {
1008 outc ('\n');
1009 indent_puts ("if ( ! yy_is_jam )");
1010 indent_up ();
1011 indent_puts ("{");
1012 gen_backing_up ();
1013 indent_puts ("}");
1014 indent_down ();
1019 /* Generate the code to find the start state. */
1021 void gen_start_state ()
1023 if (fullspd) {
1024 if (bol_needed) {
1025 indent_puts
1026 ("yy_current_state = yy_start_state_list[YY_G(yy_start) + YY_AT_BOL()];");
1028 else
1029 indent_puts
1030 ("yy_current_state = yy_start_state_list[YY_G(yy_start)];");
1033 else {
1034 indent_puts ("yy_current_state = YY_G(yy_start);");
1036 if (bol_needed)
1037 indent_puts ("yy_current_state += YY_AT_BOL();");
1039 if (reject) {
1040 /* Set up for storing up states. */
1041 outn ("m4_ifdef( [[M4_YY_USES_REJECT]],\n[[");
1042 indent_puts
1043 ("YY_G(yy_state_ptr) = YY_G(yy_state_buf);");
1044 indent_puts
1045 ("*YY_G(yy_state_ptr)++ = yy_current_state;");
1046 outn ("]])");
1052 /* gentabs - generate data statements for the transition tables */
1054 void gentabs ()
1056 int i, j, k, *accset, nacc, *acc_array, total_states;
1057 int end_of_buffer_action = num_rules + 1;
1058 struct yytbl_data *yyacc_tbl = 0, *yymeta_tbl = 0, *yybase_tbl = 0,
1059 *yydef_tbl = 0, *yynxt_tbl = 0, *yychk_tbl = 0, *yyacclist_tbl=0;
1060 flex_int32_t *yyacc_data = 0, *yybase_data = 0, *yydef_data = 0,
1061 *yynxt_data = 0, *yychk_data = 0, *yyacclist_data=0;
1062 flex_int32_t yybase_curr = 0, yyacclist_curr=0,yyacc_curr=0;
1064 acc_array = allocate_integer_array (current_max_dfas);
1065 nummt = 0;
1067 /* The compressed table format jams by entering the "jam state",
1068 * losing information about the previous state in the process.
1069 * In order to recover the previous state, we effectively need
1070 * to keep backing-up information.
1072 ++num_backing_up;
1074 if (reject) {
1075 /* Write out accepting list and pointer list.
1077 * First we generate the "yy_acclist" array. In the process,
1078 * we compute the indices that will go into the "yy_accept"
1079 * array, and save the indices in the dfaacc array.
1081 int EOB_accepting_list[2];
1083 /* Set up accepting structures for the End Of Buffer state. */
1084 EOB_accepting_list[0] = 0;
1085 EOB_accepting_list[1] = end_of_buffer_action;
1086 accsiz[end_of_buffer_state] = 1;
1087 dfaacc[end_of_buffer_state].dfaacc_set =
1088 EOB_accepting_list;
1090 out_str_dec (long_align ? get_int32_decl () :
1091 get_int16_decl (), "yy_acclist", MAX (numas,
1092 1) + 1);
1094 buf_prints (&yydmap_buf,
1095 "\t{YYTD_ID_ACCLIST, (void**)&yy_acclist, sizeof(%s)},\n",
1096 long_align ? "flex_int32_t" : "flex_int16_t");
1098 yyacclist_tbl = (struct yytbl_data*)calloc(1,sizeof(struct yytbl_data));
1099 yytbl_data_init (yyacclist_tbl, YYTD_ID_ACCLIST);
1100 yyacclist_tbl->td_lolen = MAX(numas,1) + 1;
1101 yyacclist_tbl->td_data = yyacclist_data =
1102 (flex_int32_t *) calloc (yyacclist_tbl->td_lolen, sizeof (flex_int32_t));
1103 yyacclist_curr = 1;
1105 j = 1; /* index into "yy_acclist" array */
1107 for (i = 1; i <= lastdfa; ++i) {
1108 acc_array[i] = j;
1110 if (accsiz[i] != 0) {
1111 accset = dfaacc[i].dfaacc_set;
1112 nacc = accsiz[i];
1114 if (trace)
1115 fprintf (stderr,
1116 _("state # %d accepts: "),
1119 for (k = 1; k <= nacc; ++k) {
1120 int accnum = accset[k];
1122 ++j;
1124 if (variable_trailing_context_rules
1125 && !(accnum &
1126 YY_TRAILING_HEAD_MASK)
1127 && accnum > 0
1128 && accnum <= num_rules
1129 && rule_type[accnum] ==
1130 RULE_VARIABLE) {
1131 /* Special hack to flag
1132 * accepting number as part
1133 * of trailing context rule.
1135 accnum |= YY_TRAILING_MASK;
1138 mkdata (accnum);
1139 yyacclist_data[yyacclist_curr++] = accnum;
1141 if (trace) {
1142 fprintf (stderr, "[%d]",
1143 accset[k]);
1145 if (k < nacc)
1146 fputs (", ",
1147 stderr);
1148 else
1149 putc ('\n',
1150 stderr);
1156 /* add accepting number for the "jam" state */
1157 acc_array[i] = j;
1159 dataend ();
1160 if (tablesext) {
1161 yytbl_data_compress (yyacclist_tbl);
1162 if (yytbl_data_fwrite (&tableswr, yyacclist_tbl) < 0)
1163 flexerror (_("Could not write yyacclist_tbl"));
1164 yytbl_data_destroy (yyacclist_tbl);
1165 yyacclist_tbl = NULL;
1169 else {
1170 dfaacc[end_of_buffer_state].dfaacc_state =
1171 end_of_buffer_action;
1173 for (i = 1; i <= lastdfa; ++i)
1174 acc_array[i] = dfaacc[i].dfaacc_state;
1176 /* add accepting number for jam state */
1177 acc_array[i] = 0;
1180 /* Begin generating yy_accept */
1182 /* Spit out "yy_accept" array. If we're doing "reject", it'll be
1183 * pointers into the "yy_acclist" array. Otherwise it's actual
1184 * accepting numbers. In either case, we just dump the numbers.
1187 /* "lastdfa + 2" is the size of "yy_accept"; includes room for C arrays
1188 * beginning at 0 and for "jam" state.
1190 k = lastdfa + 2;
1192 if (reject)
1193 /* We put a "cap" on the table associating lists of accepting
1194 * numbers with state numbers. This is needed because we tell
1195 * where the end of an accepting list is by looking at where
1196 * the list for the next state starts.
1198 ++k;
1200 out_str_dec (long_align ? get_int32_decl () : get_int16_decl (),
1201 "yy_accept", k);
1203 buf_prints (&yydmap_buf,
1204 "\t{YYTD_ID_ACCEPT, (void**)&yy_accept, sizeof(%s)},\n",
1205 long_align ? "flex_int32_t" : "flex_int16_t");
1207 yyacc_tbl =
1208 (struct yytbl_data *) calloc (1,
1209 sizeof (struct yytbl_data));
1210 yytbl_data_init (yyacc_tbl, YYTD_ID_ACCEPT);
1211 yyacc_tbl->td_lolen = k;
1212 yyacc_tbl->td_data = yyacc_data =
1213 (flex_int32_t *) calloc (yyacc_tbl->td_lolen, sizeof (flex_int32_t));
1214 yyacc_curr=1;
1216 for (i = 1; i <= lastdfa; ++i) {
1217 mkdata (acc_array[i]);
1218 yyacc_data[yyacc_curr++] = acc_array[i];
1220 if (!reject && trace && acc_array[i])
1221 fprintf (stderr, _("state # %d accepts: [%d]\n"),
1222 i, acc_array[i]);
1225 /* Add entry for "jam" state. */
1226 mkdata (acc_array[i]);
1227 yyacc_data[yyacc_curr++] = acc_array[i];
1229 if (reject) {
1230 /* Add "cap" for the list. */
1231 mkdata (acc_array[i]);
1232 yyacc_data[yyacc_curr++] = acc_array[i];
1235 dataend ();
1236 if (tablesext) {
1237 yytbl_data_compress (yyacc_tbl);
1238 if (yytbl_data_fwrite (&tableswr, yyacc_tbl) < 0)
1239 flexerror (_("Could not write yyacc_tbl"));
1240 yytbl_data_destroy (yyacc_tbl);
1241 yyacc_tbl = NULL;
1243 /* End generating yy_accept */
1245 if (useecs) {
1247 genecs ();
1248 if (tablesext) {
1249 struct yytbl_data *tbl;
1251 tbl = mkecstbl ();
1252 yytbl_data_compress (tbl);
1253 if (yytbl_data_fwrite (&tableswr, tbl) < 0)
1254 flexerror (_("Could not write ecstbl"));
1255 yytbl_data_destroy (tbl);
1256 tbl = 0;
1260 if (usemecs) {
1261 /* Begin generating yy_meta */
1262 /* Write out meta-equivalence classes (used to index
1263 * templates with).
1265 flex_int32_t *yymecs_data = 0;
1266 yymeta_tbl =
1267 (struct yytbl_data *) calloc (1,
1268 sizeof (struct
1269 yytbl_data));
1270 yytbl_data_init (yymeta_tbl, YYTD_ID_META);
1271 yymeta_tbl->td_lolen = numecs + 1;
1272 yymeta_tbl->td_data = yymecs_data =
1273 (flex_int32_t *) calloc (yymeta_tbl->td_lolen,
1274 sizeof (flex_int32_t));
1276 if (trace)
1277 fputs (_("\n\nMeta-Equivalence Classes:\n"),
1278 stderr);
1280 out_str_dec (get_int32_decl (), "yy_meta", numecs + 1);
1281 buf_prints (&yydmap_buf,
1282 "\t{YYTD_ID_META, (void**)&yy_meta, sizeof(%s)},\n",
1283 "flex_int32_t");
1285 for (i = 1; i <= numecs; ++i) {
1286 if (trace)
1287 fprintf (stderr, "%d = %d\n",
1288 i, ABS (tecbck[i]));
1290 mkdata (ABS (tecbck[i]));
1291 yymecs_data[i] = ABS (tecbck[i]);
1294 dataend ();
1295 if (tablesext) {
1296 yytbl_data_compress (yymeta_tbl);
1297 if (yytbl_data_fwrite (&tableswr, yymeta_tbl) < 0)
1298 flexerror (_
1299 ("Could not write yymeta_tbl"));
1300 yytbl_data_destroy (yymeta_tbl);
1301 yymeta_tbl = NULL;
1303 /* End generating yy_meta */
1306 total_states = lastdfa + numtemps;
1308 /* Begin generating yy_base */
1309 out_str_dec ((tblend >= INT16_MAX || long_align) ?
1310 get_int32_decl () : get_int16_decl (),
1311 "yy_base", total_states + 1);
1313 buf_prints (&yydmap_buf,
1314 "\t{YYTD_ID_BASE, (void**)&yy_base, sizeof(%s)},\n",
1315 (tblend >= INT16_MAX
1316 || long_align) ? "flex_int32_t" : "flex_int16_t");
1317 yybase_tbl =
1318 (struct yytbl_data *) calloc (1,
1319 sizeof (struct yytbl_data));
1320 yytbl_data_init (yybase_tbl, YYTD_ID_BASE);
1321 yybase_tbl->td_lolen = total_states + 1;
1322 yybase_tbl->td_data = yybase_data =
1323 (flex_int32_t *) calloc (yybase_tbl->td_lolen,
1324 sizeof (flex_int32_t));
1325 yybase_curr = 1;
1327 for (i = 1; i <= lastdfa; ++i) {
1328 register int d = def[i];
1330 if (base[i] == JAMSTATE)
1331 base[i] = jambase;
1333 if (d == JAMSTATE)
1334 def[i] = jamstate;
1336 else if (d < 0) {
1337 /* Template reference. */
1338 ++tmpuses;
1339 def[i] = lastdfa - d + 1;
1342 mkdata (base[i]);
1343 yybase_data[yybase_curr++] = base[i];
1346 /* Generate jam state's base index. */
1347 mkdata (base[i]);
1348 yybase_data[yybase_curr++] = base[i];
1350 for (++i /* skip jam state */ ; i <= total_states; ++i) {
1351 mkdata (base[i]);
1352 yybase_data[yybase_curr++] = base[i];
1353 def[i] = jamstate;
1356 dataend ();
1357 if (tablesext) {
1358 yytbl_data_compress (yybase_tbl);
1359 if (yytbl_data_fwrite (&tableswr, yybase_tbl) < 0)
1360 flexerror (_("Could not write yybase_tbl"));
1361 yytbl_data_destroy (yybase_tbl);
1362 yybase_tbl = NULL;
1364 /* End generating yy_base */
1367 /* Begin generating yy_def */
1368 out_str_dec ((total_states >= INT16_MAX || long_align) ?
1369 get_int32_decl () : get_int16_decl (),
1370 "yy_def", total_states + 1);
1372 buf_prints (&yydmap_buf,
1373 "\t{YYTD_ID_DEF, (void**)&yy_def, sizeof(%s)},\n",
1374 (total_states >= INT16_MAX
1375 || long_align) ? "flex_int32_t" : "flex_int16_t");
1377 yydef_tbl =
1378 (struct yytbl_data *) calloc (1,
1379 sizeof (struct yytbl_data));
1380 yytbl_data_init (yydef_tbl, YYTD_ID_DEF);
1381 yydef_tbl->td_lolen = total_states + 1;
1382 yydef_tbl->td_data = yydef_data =
1383 (flex_int32_t *) calloc (yydef_tbl->td_lolen, sizeof (flex_int32_t));
1385 for (i = 1; i <= total_states; ++i) {
1386 mkdata (def[i]);
1387 yydef_data[i] = def[i];
1390 dataend ();
1391 if (tablesext) {
1392 yytbl_data_compress (yydef_tbl);
1393 if (yytbl_data_fwrite (&tableswr, yydef_tbl) < 0)
1394 flexerror (_("Could not write yydef_tbl"));
1395 yytbl_data_destroy (yydef_tbl);
1396 yydef_tbl = NULL;
1398 /* End generating yy_def */
1401 /* Begin generating yy_nxt */
1402 out_str_dec ((total_states >= INT16_MAX || long_align) ?
1403 get_int32_decl () : get_int16_decl (), "yy_nxt",
1404 tblend + 1);
1406 buf_prints (&yydmap_buf,
1407 "\t{YYTD_ID_NXT, (void**)&yy_nxt, sizeof(%s)},\n",
1408 (total_states >= INT16_MAX
1409 || long_align) ? "flex_int32_t" : "flex_int16_t");
1411 yynxt_tbl =
1412 (struct yytbl_data *) calloc (1,
1413 sizeof (struct yytbl_data));
1414 yytbl_data_init (yynxt_tbl, YYTD_ID_NXT);
1415 yynxt_tbl->td_lolen = tblend + 1;
1416 yynxt_tbl->td_data = yynxt_data =
1417 (flex_int32_t *) calloc (yynxt_tbl->td_lolen, sizeof (flex_int32_t));
1419 for (i = 1; i <= tblend; ++i) {
1420 /* Note, the order of the following test is important.
1421 * If chk[i] is 0, then nxt[i] is undefined.
1423 if (chk[i] == 0 || nxt[i] == 0)
1424 nxt[i] = jamstate; /* new state is the JAM state */
1426 mkdata (nxt[i]);
1427 yynxt_data[i] = nxt[i];
1430 dataend ();
1431 if (tablesext) {
1432 yytbl_data_compress (yynxt_tbl);
1433 if (yytbl_data_fwrite (&tableswr, yynxt_tbl) < 0)
1434 flexerror (_("Could not write yynxt_tbl"));
1435 yytbl_data_destroy (yynxt_tbl);
1436 yynxt_tbl = NULL;
1438 /* End generating yy_nxt */
1440 /* Begin generating yy_chk */
1441 out_str_dec ((total_states >= INT16_MAX || long_align) ?
1442 get_int32_decl () : get_int16_decl (), "yy_chk",
1443 tblend + 1);
1445 buf_prints (&yydmap_buf,
1446 "\t{YYTD_ID_CHK, (void**)&yy_chk, sizeof(%s)},\n",
1447 (total_states >= INT16_MAX
1448 || long_align) ? "flex_int32_t" : "flex_int16_t");
1450 yychk_tbl =
1451 (struct yytbl_data *) calloc (1,
1452 sizeof (struct yytbl_data));
1453 yytbl_data_init (yychk_tbl, YYTD_ID_CHK);
1454 yychk_tbl->td_lolen = tblend + 1;
1455 yychk_tbl->td_data = yychk_data =
1456 (flex_int32_t *) calloc (yychk_tbl->td_lolen, sizeof (flex_int32_t));
1458 for (i = 1; i <= tblend; ++i) {
1459 if (chk[i] == 0)
1460 ++nummt;
1462 mkdata (chk[i]);
1463 yychk_data[i] = chk[i];
1466 dataend ();
1467 if (tablesext) {
1468 yytbl_data_compress (yychk_tbl);
1469 if (yytbl_data_fwrite (&tableswr, yychk_tbl) < 0)
1470 flexerror (_("Could not write yychk_tbl"));
1471 yytbl_data_destroy (yychk_tbl);
1472 yychk_tbl = NULL;
1474 /* End generating yy_chk */
1476 flex_free ((void *) acc_array);
1480 /* Write out a formatted string (with a secondary string argument) at the
1481 * current indentation level, adding a final newline.
1484 void indent_put2s (fmt, arg)
1485 const char *fmt, *arg;
1487 do_indent ();
1488 out_str (fmt, arg);
1489 outn ("");
1493 /* Write out a string at the current indentation level, adding a final
1494 * newline.
1497 void indent_puts (str)
1498 const char *str;
1500 do_indent ();
1501 outn (str);
1505 /* make_tables - generate transition tables and finishes generating output file
1508 void make_tables ()
1510 register int i;
1511 int did_eof_rule = false;
1512 struct yytbl_data *yynultrans_tbl;
1515 skelout (); /* %% [2.0] - break point in skel */
1517 /* First, take care of YY_DO_BEFORE_ACTION depending on yymore
1518 * being used.
1520 set_indent (1);
1522 if (yymore_used && !yytext_is_array) {
1523 indent_puts ("YY_G(yytext_ptr) -= YY_G(yy_more_len); \\");
1524 indent_puts
1525 ("yyleng = (size_t) (yy_cp - YY_G(yytext_ptr)); \\");
1528 else
1529 indent_puts ("yyleng = (size_t) (yy_cp - yy_bp); \\");
1531 /* Now also deal with copying yytext_ptr to yytext if needed. */
1532 skelout (); /* %% [3.0] - break point in skel */
1533 if (yytext_is_array) {
1534 if (yymore_used)
1535 indent_puts
1536 ("if ( yyleng + YY_G(yy_more_offset) >= YYLMAX ) \\");
1537 else
1538 indent_puts ("if ( yyleng >= YYLMAX ) \\");
1540 indent_up ();
1541 indent_puts
1542 ("YY_FATAL_ERROR( \"token too large, exceeds YYLMAX\" ); \\");
1543 indent_down ();
1545 if (yymore_used) {
1546 indent_puts
1547 ("yy_flex_strncpy( &yytext[YY_G(yy_more_offset)], YY_G(yytext_ptr), yyleng + 1 M4_YY_CALL_LAST_ARG); \\");
1548 indent_puts ("yyleng += YY_G(yy_more_offset); \\");
1549 indent_puts
1550 ("YY_G(yy_prev_more_offset) = YY_G(yy_more_offset); \\");
1551 indent_puts ("YY_G(yy_more_offset) = 0; \\");
1553 else {
1554 indent_puts
1555 ("yy_flex_strncpy( yytext, YY_G(yytext_ptr), yyleng + 1 M4_YY_CALL_LAST_ARG); \\");
1559 set_indent (0);
1561 skelout (); /* %% [4.0] - break point in skel */
1564 /* This is where we REALLY begin generating the tables. */
1566 out_dec ("#define YY_NUM_RULES %d\n", num_rules);
1567 out_dec ("#define YY_END_OF_BUFFER %d\n", num_rules + 1);
1569 if (fullspd) {
1570 /* Need to define the transet type as a size large
1571 * enough to hold the biggest offset.
1573 int total_table_size = tblend + numecs + 1;
1574 char *trans_offset_type =
1575 (total_table_size >= INT16_MAX || long_align) ?
1576 "flex_int32_t" : "flex_int16_t";
1578 set_indent (0);
1579 indent_puts ("struct yy_trans_info");
1580 indent_up ();
1581 indent_puts ("{");
1583 /* We require that yy_verify and yy_nxt must be of the same size int. */
1584 indent_put2s ("%s yy_verify;", trans_offset_type);
1586 /* In cases where its sister yy_verify *is* a "yes, there is
1587 * a transition", yy_nxt is the offset (in records) to the
1588 * next state. In most cases where there is no transition,
1589 * the value of yy_nxt is irrelevant. If yy_nxt is the -1th
1590 * record of a state, though, then yy_nxt is the action number
1591 * for that state.
1594 indent_put2s ("%s yy_nxt;", trans_offset_type);
1595 indent_puts ("};");
1596 indent_down ();
1598 else {
1599 /* We generate a bogus 'struct yy_trans_info' data type
1600 * so we can guarantee that it is always declared in the skel.
1601 * This is so we can compile "sizeof(struct yy_trans_info)"
1602 * in any scanner.
1604 indent_puts
1605 ("/* This struct is not used in this scanner,");
1606 indent_puts (" but its presence is necessary. */");
1607 indent_puts ("struct yy_trans_info");
1608 indent_up ();
1609 indent_puts ("{");
1610 indent_puts ("flex_int32_t yy_verify;");
1611 indent_puts ("flex_int32_t yy_nxt;");
1612 indent_puts ("};");
1613 indent_down ();
1616 if (fullspd) {
1617 genctbl ();
1618 if (tablesext) {
1619 struct yytbl_data *tbl;
1621 tbl = mkctbl ();
1622 yytbl_data_compress (tbl);
1623 if (yytbl_data_fwrite (&tableswr, tbl) < 0)
1624 flexerror (_("Could not write ftbl"));
1625 yytbl_data_destroy (tbl);
1627 tbl = mkssltbl ();
1628 yytbl_data_compress (tbl);
1629 if (yytbl_data_fwrite (&tableswr, tbl) < 0)
1630 flexerror (_("Could not write ssltbl"));
1631 yytbl_data_destroy (tbl);
1632 tbl = 0;
1634 if (useecs) {
1635 tbl = mkecstbl ();
1636 yytbl_data_compress (tbl);
1637 if (yytbl_data_fwrite (&tableswr, tbl) < 0)
1638 flexerror (_
1639 ("Could not write ecstbl"));
1640 yytbl_data_destroy (tbl);
1641 tbl = 0;
1645 else if (fulltbl) {
1646 genftbl ();
1647 if (tablesext) {
1648 struct yytbl_data *tbl;
1650 tbl = mkftbl ();
1651 yytbl_data_compress (tbl);
1652 if (yytbl_data_fwrite (&tableswr, tbl) < 0)
1653 flexerror (_("Could not write ftbl"));
1654 yytbl_data_destroy (tbl);
1655 tbl = 0;
1657 if (useecs) {
1658 tbl = mkecstbl ();
1659 yytbl_data_compress (tbl);
1660 if (yytbl_data_fwrite (&tableswr, tbl) < 0)
1661 flexerror (_
1662 ("Could not write ecstbl"));
1663 yytbl_data_destroy (tbl);
1664 tbl = 0;
1668 else
1669 gentabs ();
1671 if (do_yylineno) {
1673 geneoltbl ();
1675 if (tablesext) {
1676 struct yytbl_data *tbl;
1678 tbl = mkeoltbl ();
1679 yytbl_data_compress (tbl);
1680 if (yytbl_data_fwrite (&tableswr, tbl) < 0)
1681 flexerror (_("Could not write eoltbl"));
1682 yytbl_data_destroy (tbl);
1683 tbl = 0;
1687 /* Definitions for backing up. We don't need them if REJECT
1688 * is being used because then we use an alternative backin-up
1689 * technique instead.
1691 if (num_backing_up > 0 && !reject) {
1692 if (!C_plus_plus && !reentrant) {
1693 indent_puts
1694 ("static yy_state_type yy_last_accepting_state;");
1695 indent_puts
1696 ("static char *yy_last_accepting_cpos;\n");
1700 if (nultrans) {
1701 flex_int32_t *yynultrans_data = 0;
1703 /* Begin generating yy_NUL_trans */
1704 out_str_dec (get_state_decl (), "yy_NUL_trans",
1705 lastdfa + 1);
1706 buf_prints (&yydmap_buf,
1707 "\t{YYTD_ID_NUL_TRANS, (void**)&yy_NUL_trans, sizeof(%s)},\n",
1708 (fullspd) ? "struct yy_trans_info*" :
1709 "flex_int32_t");
1711 yynultrans_tbl =
1712 (struct yytbl_data *) calloc (1,
1713 sizeof (struct
1714 yytbl_data));
1715 yytbl_data_init (yynultrans_tbl, YYTD_ID_NUL_TRANS);
1716 if (fullspd)
1717 yynultrans_tbl->td_flags |= YYTD_PTRANS;
1718 yynultrans_tbl->td_lolen = lastdfa + 1;
1719 yynultrans_tbl->td_data = yynultrans_data =
1720 (flex_int32_t *) calloc (yynultrans_tbl->td_lolen,
1721 sizeof (flex_int32_t));
1723 for (i = 1; i <= lastdfa; ++i) {
1724 if (fullspd) {
1725 out_dec (" &yy_transition[%d],\n",
1726 base[i]);
1727 yynultrans_data[i] = base[i];
1729 else {
1730 mkdata (nultrans[i]);
1731 yynultrans_data[i] = nultrans[i];
1735 dataend ();
1736 if (tablesext) {
1737 yytbl_data_compress (yynultrans_tbl);
1738 if (yytbl_data_fwrite (&tableswr, yynultrans_tbl) <
1740 flexerror (_
1741 ("Could not write yynultrans_tbl"));
1742 yytbl_data_destroy (yynultrans_tbl);
1743 yynultrans_tbl = NULL;
1745 /* End generating yy_NUL_trans */
1748 if (!C_plus_plus && !reentrant) {
1749 indent_puts ("extern int yy_flex_debug;");
1750 indent_put2s ("int yy_flex_debug = %s;\n",
1751 ddebug ? "1" : "0");
1754 if (ddebug) { /* Spit out table mapping rules to line numbers. */
1755 out_str_dec (long_align ? get_int32_decl () :
1756 get_int16_decl (), "yy_rule_linenum",
1757 num_rules);
1758 for (i = 1; i < num_rules; ++i)
1759 mkdata (rule_linenum[i]);
1760 dataend ();
1763 if (reject) {
1764 outn ("m4_ifdef( [[M4_YY_USES_REJECT]],\n[[");
1765 /* Declare state buffer variables. */
1766 if (!C_plus_plus && !reentrant) {
1767 outn ("static yy_state_type *yy_state_buf=0, *yy_state_ptr=0;");
1768 outn ("static char *yy_full_match;");
1769 outn ("static int yy_lp;");
1772 if (variable_trailing_context_rules) {
1773 if (!C_plus_plus) {
1774 outn ("static int yy_looking_for_trail_begin = 0;");
1775 outn ("static int yy_full_lp;");
1776 outn ("static int *yy_full_state;");
1779 out_hex ("#define YY_TRAILING_MASK 0x%x\n",
1780 (unsigned int) YY_TRAILING_MASK);
1781 out_hex ("#define YY_TRAILING_HEAD_MASK 0x%x\n",
1782 (unsigned int) YY_TRAILING_HEAD_MASK);
1785 outn ("#define REJECT \\");
1786 outn ("{ \\");
1787 outn ("*yy_cp = YY_G(yy_hold_char); /* undo effects of setting up yytext */ \\");
1788 outn ("yy_cp = YY_G(yy_full_match); /* restore poss. backed-over text */ \\");
1790 if (variable_trailing_context_rules) {
1791 outn ("YY_G(yy_lp) = yy_full_lp; /* restore orig. accepting pos. */ \\");
1792 outn ("YY_G(yy_state_ptr) = yy_full_state; /* restore orig. state */ \\");
1793 outn ("yy_current_state = *YY_G(yy_state_ptr); /* restore curr. state */ \\");
1796 outn ("++YY_G(yy_lp); \\");
1797 outn ("goto find_rule; \\");
1799 outn ("}");
1800 outn ("]])\n");
1803 else {
1804 outn ("/* The intent behind this definition is that it'll catch");
1805 outn (" * any uses of REJECT which flex missed.");
1806 outn (" */");
1807 outn ("#define REJECT reject_used_but_not_detected");
1810 if (yymore_used) {
1811 if (!C_plus_plus) {
1812 if (yytext_is_array) {
1813 if (!reentrant){
1814 indent_puts ("static int yy_more_offset = 0;");
1815 indent_puts ("static int yy_prev_more_offset = 0;");
1818 else if (!reentrant) {
1819 indent_puts
1820 ("static int yy_more_flag = 0;");
1821 indent_puts
1822 ("static int yy_more_len = 0;");
1826 if (yytext_is_array) {
1827 indent_puts
1828 ("#define yymore() (YY_G(yy_more_offset) = yy_flex_strlen( yytext M4_YY_CALL_LAST_ARG))");
1829 indent_puts ("#define YY_NEED_STRLEN");
1830 indent_puts ("#define YY_MORE_ADJ 0");
1831 indent_puts
1832 ("#define YY_RESTORE_YY_MORE_OFFSET \\");
1833 indent_up ();
1834 indent_puts ("{ \\");
1835 indent_puts
1836 ("YY_G(yy_more_offset) = YY_G(yy_prev_more_offset); \\");
1837 indent_puts ("yyleng -= YY_G(yy_more_offset); \\");
1838 indent_puts ("}");
1839 indent_down ();
1841 else {
1842 indent_puts
1843 ("#define yymore() (YY_G(yy_more_flag) = 1)");
1844 indent_puts
1845 ("#define YY_MORE_ADJ YY_G(yy_more_len)");
1846 indent_puts ("#define YY_RESTORE_YY_MORE_OFFSET");
1850 else {
1851 indent_puts
1852 ("#define yymore() yymore_used_but_not_detected");
1853 indent_puts ("#define YY_MORE_ADJ 0");
1854 indent_puts ("#define YY_RESTORE_YY_MORE_OFFSET");
1857 if (!C_plus_plus) {
1858 if (yytext_is_array) {
1859 outn ("#ifndef YYLMAX");
1860 outn ("#define YYLMAX 8192");
1861 outn ("#endif\n");
1862 if (!reentrant){
1863 outn ("char yytext[YYLMAX];");
1864 outn ("char *yytext_ptr;");
1868 else {
1869 if(! reentrant)
1870 outn ("char *yytext;");
1874 out (&action_array[defs1_offset]);
1876 line_directive_out (stdout, 0);
1878 skelout (); /* %% [5.0] - break point in skel */
1880 if (!C_plus_plus) {
1881 if (use_read) {
1882 outn ("\terrno=0; \\");
1883 outn ("\twhile ( (result = read( fileno(yyin), (char *) buf, max_size )) < 0 ) \\");
1884 outn ("\t{ \\");
1885 outn ("\t\tif( errno != EINTR) \\");
1886 outn ("\t\t{ \\");
1887 outn ("\t\t\tYY_FATAL_ERROR( \"input in flex scanner failed\" ); \\");
1888 outn ("\t\t\tbreak; \\");
1889 outn ("\t\t} \\");
1890 outn ("\t\terrno=0; \\");
1891 outn ("\t\tclearerr(yyin); \\");
1892 outn ("\t}\\");
1895 else {
1896 outn ("\tif ( YY_CURRENT_BUFFER_LVALUE->yy_is_interactive ) \\");
1897 outn ("\t\t{ \\");
1898 outn ("\t\tint c = '*'; \\");
1899 outn ("\t\tsize_t n; \\");
1900 outn ("\t\tfor ( n = 0; n < max_size && \\");
1901 outn ("\t\t\t (c = getc( yyin )) != EOF && c != '\\n'; ++n ) \\");
1902 outn ("\t\t\tbuf[n] = (char) c; \\");
1903 outn ("\t\tif ( c == '\\n' ) \\");
1904 outn ("\t\t\tbuf[n++] = (char) c; \\");
1905 outn ("\t\tif ( c == EOF && ferror( yyin ) ) \\");
1906 outn ("\t\t\tYY_FATAL_ERROR( \"input in flex scanner failed\" ); \\");
1907 outn ("\t\tresult = n; \\");
1908 outn ("\t\t} \\");
1909 outn ("\telse \\");
1910 outn ("\t\t{ \\");
1911 outn ("\t\terrno=0; \\");
1912 outn ("\t\twhile ( (result = fread(buf, 1, max_size, yyin))==0 && ferror(yyin)) \\");
1913 outn ("\t\t\t{ \\");
1914 outn ("\t\t\tif( errno != EINTR) \\");
1915 outn ("\t\t\t\t{ \\");
1916 outn ("\t\t\t\tYY_FATAL_ERROR( \"input in flex scanner failed\" ); \\");
1917 outn ("\t\t\t\tbreak; \\");
1918 outn ("\t\t\t\t} \\");
1919 outn ("\t\t\terrno=0; \\");
1920 outn ("\t\t\tclearerr(yyin); \\");
1921 outn ("\t\t\t} \\");
1922 outn ("\t\t}\\");
1926 skelout (); /* %% [6.0] - break point in skel */
1928 indent_puts ("#define YY_RULE_SETUP \\");
1929 indent_up ();
1930 if (bol_needed) {
1931 indent_puts ("if ( yyleng > 0 ) \\");
1932 indent_up ();
1933 indent_puts ("YY_CURRENT_BUFFER_LVALUE->yy_at_bol = \\");
1934 indent_puts ("\t\t(yytext[yyleng - 1] == '\\n'); \\");
1935 indent_down ();
1937 indent_puts ("YY_USER_ACTION");
1938 indent_down ();
1940 skelout (); /* %% [7.0] - break point in skel */
1942 /* Copy prolog to output file. */
1943 out (&action_array[prolog_offset]);
1945 line_directive_out (stdout, 0);
1947 skelout (); /* %% [8.0] - break point in skel */
1949 set_indent (2);
1951 if (yymore_used && !yytext_is_array) {
1952 indent_puts ("YY_G(yy_more_len) = 0;");
1953 indent_puts ("if ( YY_G(yy_more_flag) )");
1954 indent_up ();
1955 indent_puts ("{");
1956 indent_puts
1957 ("YY_G(yy_more_len) = YY_G(yy_c_buf_p) - YY_G(yytext_ptr);");
1958 indent_puts ("YY_G(yy_more_flag) = 0;");
1959 indent_puts ("}");
1960 indent_down ();
1963 skelout (); /* %% [9.0] - break point in skel */
1965 gen_start_state ();
1967 /* Note, don't use any indentation. */
1968 outn ("yy_match:");
1969 gen_next_match ();
1971 skelout (); /* %% [10.0] - break point in skel */
1972 set_indent (2);
1973 gen_find_action ();
1975 skelout (); /* %% [11.0] - break point in skel */
1976 outn ("m4_ifdef( [[M4_YY_USE_LINENO]],[[");
1977 indent_puts
1978 ("if ( yy_act != YY_END_OF_BUFFER && yy_rule_can_match_eol[yy_act] )");
1979 indent_up ();
1980 indent_puts ("{");
1981 indent_puts ("int yyl;");
1982 do_indent ();
1983 out_str ("for ( yyl = %s; yyl < yyleng; ++yyl )\n",
1984 yymore_used ? (yytext_is_array ? "YY_G(yy_prev_more_offset)" :
1985 "YY_G(yy_more_len)") : "0");
1986 indent_up ();
1987 indent_puts ("if ( yytext[yyl] == '\\n' )");
1988 indent_up ();
1989 indent_puts ("M4_YY_INCR_LINENO();");
1990 indent_down ();
1991 indent_down ();
1992 indent_puts ("}");
1993 indent_down ();
1994 outn ("]])");
1996 skelout (); /* %% [12.0] - break point in skel */
1997 if (ddebug) {
1998 indent_puts ("if ( yy_flex_debug )");
1999 indent_up ();
2001 indent_puts ("{");
2002 indent_puts ("if ( yy_act == 0 )");
2003 indent_up ();
2004 indent_puts (C_plus_plus ?
2005 "std::cerr << \"--scanner backing up\\n\";" :
2006 "fprintf( stderr, \"--scanner backing up\\n\" );");
2007 indent_down ();
2009 do_indent ();
2010 out_dec ("else if ( yy_act < %d )\n", num_rules);
2011 indent_up ();
2013 if (C_plus_plus) {
2014 indent_puts
2015 ("std::cerr << \"--accepting rule at line \" << yy_rule_linenum[yy_act] <<");
2016 indent_puts
2017 (" \"(\\\"\" << yytext << \"\\\")\\n\";");
2019 else {
2020 indent_puts
2021 ("fprintf( stderr, \"--accepting rule at line %ld (\\\"%s\\\")\\n\",");
2023 indent_puts
2024 (" (long)yy_rule_linenum[yy_act], yytext );");
2027 indent_down ();
2029 do_indent ();
2030 out_dec ("else if ( yy_act == %d )\n", num_rules);
2031 indent_up ();
2033 if (C_plus_plus) {
2034 indent_puts
2035 ("std::cerr << \"--accepting default rule (\\\"\" << yytext << \"\\\")\\n\";");
2037 else {
2038 indent_puts
2039 ("fprintf( stderr, \"--accepting default rule (\\\"%s\\\")\\n\",");
2040 indent_puts (" yytext );");
2043 indent_down ();
2045 do_indent ();
2046 out_dec ("else if ( yy_act == %d )\n", num_rules + 1);
2047 indent_up ();
2049 indent_puts (C_plus_plus ?
2050 "std::cerr << \"--(end of buffer or a NUL)\\n\";" :
2051 "fprintf( stderr, \"--(end of buffer or a NUL)\\n\" );");
2053 indent_down ();
2055 do_indent ();
2056 outn ("else");
2057 indent_up ();
2059 if (C_plus_plus) {
2060 indent_puts
2061 ("std::cerr << \"--EOF (start condition \" << YY_START << \")\\n\";");
2063 else {
2064 indent_puts
2065 ("fprintf( stderr, \"--EOF (start condition %d)\\n\", YY_START );");
2068 indent_down ();
2070 indent_puts ("}");
2071 indent_down ();
2074 /* Copy actions to output file. */
2075 skelout (); /* %% [13.0] - break point in skel */
2076 indent_up ();
2077 gen_bu_action ();
2078 out (&action_array[action_offset]);
2080 line_directive_out (stdout, 0);
2082 /* generate cases for any missing EOF rules */
2083 for (i = 1; i <= lastsc; ++i)
2084 if (!sceof[i]) {
2085 do_indent ();
2086 out_str ("case YY_STATE_EOF(%s):\n", scname[i]);
2087 did_eof_rule = true;
2090 if (did_eof_rule) {
2091 indent_up ();
2092 indent_puts ("yyterminate();");
2093 indent_down ();
2097 /* Generate code for handling NUL's, if needed. */
2099 /* First, deal with backing up and setting up yy_cp if the scanner
2100 * finds that it should JAM on the NUL.
2102 skelout (); /* %% [14.0] - break point in skel */
2103 set_indent (4);
2105 if (fullspd || fulltbl)
2106 indent_puts ("yy_cp = YY_G(yy_c_buf_p);");
2108 else { /* compressed table */
2109 if (!reject && !interactive) {
2110 /* Do the guaranteed-needed backing up to figure
2111 * out the match.
2113 indent_puts
2114 ("yy_cp = YY_G(yy_last_accepting_cpos);");
2115 indent_puts
2116 ("yy_current_state = YY_G(yy_last_accepting_state);");
2119 else
2120 /* Still need to initialize yy_cp, though
2121 * yy_current_state was set up by
2122 * yy_get_previous_state().
2124 indent_puts ("yy_cp = YY_G(yy_c_buf_p);");
2128 /* Generate code for yy_get_previous_state(). */
2129 set_indent (1);
2130 skelout (); /* %% [15.0] - break point in skel */
2132 gen_start_state ();
2134 set_indent (2);
2135 skelout (); /* %% [16.0] - break point in skel */
2136 gen_next_state (true);
2138 set_indent (1);
2139 skelout (); /* %% [17.0] - break point in skel */
2140 gen_NUL_trans ();
2142 skelout (); /* %% [18.0] - break point in skel */
2143 skelout (); /* %% [19.0] - break point in skel */
2144 /* Update BOL and yylineno inside of input(). */
2145 if (bol_needed) {
2146 indent_puts
2147 ("YY_CURRENT_BUFFER_LVALUE->yy_at_bol = (c == '\\n');");
2148 if (do_yylineno) {
2149 indent_puts
2150 ("if ( YY_CURRENT_BUFFER_LVALUE->yy_at_bol )");
2151 indent_up ();
2152 indent_puts ("M4_YY_INCR_LINENO();");
2153 indent_down ();
2157 else if (do_yylineno) {
2158 indent_puts ("if ( c == '\\n' )");
2159 indent_up ();
2160 indent_puts ("M4_YY_INCR_LINENO();");
2161 indent_down ();
2164 skelout ();
2166 /* Copy remainder of input to output. */
2168 line_directive_out (stdout, 1);
2170 if (sectnum == 3) {
2171 OUT_BEGIN_CODE ();
2172 (void) flexscan (); /* copy remainder of input to output */
2173 OUT_END_CODE ();