1 /* $NetBSD: gen.c,v 1.5 2017/01/02 23:21:14 christos Exp $ */
2
3 /* gen - actual generation (writing) of flex scanners */
4
5 /* Copyright (c) 1990 The Regents of the University of California. */
6 /* All rights reserved. */
7
8 /* This code is derived from software contributed to Berkeley by */
9 /* Vern Paxson. */
10
11 /* The United States Government has rights in this work pursuant */
12 /* to contract no. DE-AC03-76SF00098 between the United States */
13 /* Department of Energy and the University of California. */
14
15 /* This file is part of flex. */
16
17 /* Redistribution and use in source and binary forms, with or without */
18 /* modification, are permitted provided that the following conditions */
19 /* are met: */
20
21 /* 1. Redistributions of source code must retain the above copyright */
22 /* notice, this list of conditions and the following disclaimer. */
23 /* 2. Redistributions in binary form must reproduce the above copyright */
24 /* notice, this list of conditions and the following disclaimer in the */
25 /* documentation and/or other materials provided with the distribution. */
26
27 /* Neither the name of the University nor the names of its contributors */
28 /* may be used to endorse or promote products derived from this software */
29 /* without specific prior written permission. */
30
31 /* THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR */
32 /* IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED */
33 /* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR */
34 /* PURPOSE. */
35 #include "flexdef.h"
36 __RCSID("$NetBSD: gen.c,v 1.5 2017/01/02 23:21:14 christos Exp $");
37
38 #include "tables.h"
39
40
41 /* declare functions that have forward references */
42
43 void genecs(void);
44
45
46 static int indent_level = 0; /* each level is 8 spaces */
47
48 #define set_indent(indent_val) indent_level = indent_val
49
50 /* Almost everything is done in terms of arrays starting at 1, so provide
51 * a null entry for the zero element of all C arrays. (The exception
52 * to this is that the fast table representation generally uses the
53 * 0 elements of its arrays, too.)
54 */
55
get_int16_decl(void)56 static const char *get_int16_decl (void)
57 {
58 return (gentables)
59 ? "static const flex_int16_t %s[%d] =\n { 0,\n"
60 : "static const flex_int16_t * %s = 0;\n";
61 }
62
63
get_int32_decl(void)64 static const char *get_int32_decl (void)
65 {
66 return (gentables)
67 ? "static const flex_int32_t %s[%d] =\n { 0,\n"
68 : "static const flex_int32_t * %s = 0;\n";
69 }
70
get_state_decl(void)71 static const char *get_state_decl (void)
72 {
73 return (gentables)
74 ? "static const yy_state_type %s[%d] =\n { 0,\n"
75 : "static const yy_state_type * %s = 0;\n";
76 }
77
get_yy_char_decl(void)78 static const char *get_yy_char_decl (void)
79 {
80 return (gentables)
81 ? "static const YY_CHAR %s[%d] =\n { 0,\n"
82 : "static const YY_CHAR * %s = 0;\n";
83 }
84
85 /* Indent to the current level. */
86
do_indent(void)87 void do_indent (void)
88 {
89 int i = indent_level * 8;
90
91 while (i >= 8) {
92 outc ('\t');
93 i -= 8;
94 }
95
96 while (i > 0) {
97 outc (' ');
98 --i;
99 }
100 }
101
102
103 /** Make the table for possible eol matches.
104 * @return the newly allocated rule_can_match_eol table
105 */
mkeoltbl(void)106 static struct yytbl_data *mkeoltbl (void)
107 {
108 int i;
109 flex_int8_t *tdata = 0;
110 struct yytbl_data *tbl;
111
112 tbl = calloc(1, sizeof (struct yytbl_data));
113 yytbl_data_init (tbl, YYTD_ID_RULE_CAN_MATCH_EOL);
114 tbl->td_flags = YYTD_DATA8;
115 tbl->td_lolen = (flex_uint32_t) (num_rules + 1);
116 tbl->td_data = tdata =
117 calloc(tbl->td_lolen, sizeof (flex_int8_t));
118
119 for (i = 1; i <= num_rules; i++)
120 tdata[i] = rule_has_nl[i] ? 1 : 0;
121
122 buf_prints (&yydmap_buf,
123 "\t{YYTD_ID_RULE_CAN_MATCH_EOL, (void**)&yy_rule_can_match_eol, sizeof(%s)},\n",
124 "flex_int32_t");
125 return tbl;
126 }
127
128 /* Generate the table for possible eol matches. */
geneoltbl(void)129 static void geneoltbl (void)
130 {
131 int i;
132
133 outn ("m4_ifdef( [[M4_YY_USE_LINENO]],[[");
134 outn ("/* Table of booleans, true if rule could match eol. */");
135 out_str_dec (get_int32_decl (), "yy_rule_can_match_eol",
136 num_rules + 1);
137
138 if (gentables) {
139 for (i = 1; i <= num_rules; i++) {
140 out_dec ("%d, ", rule_has_nl[i] ? 1 : 0);
141 /* format nicely, 20 numbers per line. */
142 if ((i % 20) == 19)
143 out ("\n ");
144 }
145 out (" };\n");
146 }
147 outn ("]])");
148 }
149
150
151 /* Generate the code to keep backing-up information. */
152
gen_backing_up(void)153 void gen_backing_up (void)
154 {
155 if (reject || num_backing_up == 0)
156 return;
157
158 if (fullspd)
159 indent_puts ("if ( yy_current_state[-1].yy_nxt )");
160 else
161 indent_puts ("if ( yy_accept[yy_current_state] )");
162
163 ++indent_level;
164 indent_puts ("{");
165 indent_puts ("YY_G(yy_last_accepting_state) = yy_current_state;");
166 indent_puts ("YY_G(yy_last_accepting_cpos) = yy_cp;");
167 indent_puts ("}");
168 --indent_level;
169 }
170
171
172 /* Generate the code to perform the backing up. */
173
gen_bu_action(void)174 void gen_bu_action (void)
175 {
176 if (reject || num_backing_up == 0)
177 return;
178
179 set_indent (3);
180
181 indent_puts ("case 0: /* must back up */");
182 indent_puts ("/* undo the effects of YY_DO_BEFORE_ACTION */");
183 indent_puts ("*yy_cp = YY_G(yy_hold_char);");
184
185 if (fullspd || fulltbl)
186 indent_puts ("yy_cp = YY_G(yy_last_accepting_cpos) + 1;");
187 else
188 /* Backing-up info for compressed tables is taken \after/
189 * yy_cp has been incremented for the next state.
190 */
191 indent_puts ("yy_cp = YY_G(yy_last_accepting_cpos);");
192
193 indent_puts ("yy_current_state = YY_G(yy_last_accepting_state);");
194 indent_puts ("goto yy_find_action;");
195 outc ('\n');
196
197 set_indent (0);
198 }
199
200 /** mkctbl - make full speed compressed transition table
201 * This is an array of structs; each struct a pair of integers.
202 * You should call mkssltbl() immediately after this.
203 * Then, I think, mkecstbl(). Arrrg.
204 * @return the newly allocated trans table
205 */
206
mkctbl(void)207 static struct yytbl_data *mkctbl (void)
208 {
209 int i;
210 struct yytbl_data *tbl = 0;
211 flex_int32_t *tdata = 0, curr = 0;
212 int end_of_buffer_action = num_rules + 1;
213
214 buf_prints (&yydmap_buf,
215 "\t{YYTD_ID_TRANSITION, (void**)&yy_transition, sizeof(%s)},\n",
216 ((tblend + numecs + 1) >= INT16_MAX
217 || long_align) ? "flex_int32_t" : "flex_int16_t");
218
219 tbl = calloc(1, sizeof (struct yytbl_data));
220 yytbl_data_init (tbl, YYTD_ID_TRANSITION);
221 tbl->td_flags = YYTD_DATA32 | YYTD_STRUCT;
222 tbl->td_hilen = 0;
223 tbl->td_lolen = (flex_uint32_t) (tblend + numecs + 1); /* number of structs */
224
225 tbl->td_data = tdata =
226 calloc(tbl->td_lolen * 2, sizeof (flex_int32_t));
227
228 /* We want the transition to be represented as the offset to the
229 * next state, not the actual state number, which is what it currently
230 * is. The offset is base[nxt[i]] - (base of current state)]. That's
231 * just the difference between the starting points of the two involved
232 * states (to - from).
233 *
234 * First, though, we need to find some way to put in our end-of-buffer
235 * flags and states. We do this by making a state with absolutely no
236 * transitions. We put it at the end of the table.
237 */
238
239 /* We need to have room in nxt/chk for two more slots: One for the
240 * action and one for the end-of-buffer transition. We now *assume*
241 * that we're guaranteed the only character we'll try to index this
242 * nxt/chk pair with is EOB, i.e., 0, so we don't have to make sure
243 * there's room for jam entries for other characters.
244 */
245
246 while (tblend + 2 >= current_max_xpairs)
247 expand_nxt_chk ();
248
249 while (lastdfa + 1 >= current_max_dfas)
250 increase_max_dfas ();
251
252 base[lastdfa + 1] = tblend + 2;
253 nxt[tblend + 1] = end_of_buffer_action;
254 chk[tblend + 1] = numecs + 1;
255 chk[tblend + 2] = 1; /* anything but EOB */
256
257 /* So that "make test" won't show arb. differences. */
258 nxt[tblend + 2] = 0;
259
260 /* Make sure every state has an end-of-buffer transition and an
261 * action #.
262 */
263 for (i = 0; i <= lastdfa; ++i) {
264 int anum = dfaacc[i].dfaacc_state;
265 int offset = base[i];
266
267 chk[offset] = EOB_POSITION;
268 chk[offset - 1] = ACTION_POSITION;
269 nxt[offset - 1] = anum; /* action number */
270 }
271
272 for (i = 0; i <= tblend; ++i) {
273 if (chk[i] == EOB_POSITION) {
274 tdata[curr++] = 0;
275 tdata[curr++] = base[lastdfa + 1] - i;
276 }
277
278 else if (chk[i] == ACTION_POSITION) {
279 tdata[curr++] = 0;
280 tdata[curr++] = nxt[i];
281 }
282
283 else if (chk[i] > numecs || chk[i] == 0) {
284 tdata[curr++] = 0;
285 tdata[curr++] = 0;
286 }
287 else { /* verify, transition */
288
289 tdata[curr++] = chk[i];
290 tdata[curr++] = base[nxt[i]] - (i - chk[i]);
291 }
292 }
293
294
295 /* Here's the final, end-of-buffer state. */
296 tdata[curr++] = chk[tblend + 1];
297 tdata[curr++] = nxt[tblend + 1];
298
299 tdata[curr++] = chk[tblend + 2];
300 tdata[curr++] = nxt[tblend + 2];
301
302 return tbl;
303 }
304
305
306 /** Make start_state_list table.
307 * @return the newly allocated start_state_list table
308 */
mkssltbl(void)309 static struct yytbl_data *mkssltbl (void)
310 {
311 struct yytbl_data *tbl = 0;
312 flex_int32_t *tdata = 0;
313 flex_int32_t i;
314
315 tbl = calloc(1, sizeof (struct yytbl_data));
316 yytbl_data_init (tbl, YYTD_ID_START_STATE_LIST);
317 tbl->td_flags = YYTD_DATA32 | YYTD_PTRANS;
318 tbl->td_hilen = 0;
319 tbl->td_lolen = (flex_uint32_t) (lastsc * 2 + 1);
320
321 tbl->td_data = tdata =
322 calloc(tbl->td_lolen, sizeof (flex_int32_t));
323
324 for (i = 0; i <= lastsc * 2; ++i)
325 tdata[i] = base[i];
326
327 buf_prints (&yydmap_buf,
328 "\t{YYTD_ID_START_STATE_LIST, (void**)&yy_start_state_list, sizeof(%s)},\n",
329 "struct yy_trans_info*");
330
331 return tbl;
332 }
333
334
335
336 /* genctbl - generates full speed compressed transition table */
337
genctbl(void)338 void genctbl (void)
339 {
340 int i;
341 int end_of_buffer_action = num_rules + 1;
342
343 /* Table of verify for transition and offset to next state. */
344 if (gentables)
345 out_dec ("static const struct yy_trans_info yy_transition[%d] =\n {\n", tblend + numecs + 1);
346 else
347 outn ("static const struct yy_trans_info *yy_transition = 0;");
348
349 /* We want the transition to be represented as the offset to the
350 * next state, not the actual state number, which is what it currently
351 * is. The offset is base[nxt[i]] - (base of current state)]. That's
352 * just the difference between the starting points of the two involved
353 * states (to - from).
354 *
355 * First, though, we need to find some way to put in our end-of-buffer
356 * flags and states. We do this by making a state with absolutely no
357 * transitions. We put it at the end of the table.
358 */
359
360 /* We need to have room in nxt/chk for two more slots: One for the
361 * action and one for the end-of-buffer transition. We now *assume*
362 * that we're guaranteed the only character we'll try to index this
363 * nxt/chk pair with is EOB, i.e., 0, so we don't have to make sure
364 * there's room for jam entries for other characters.
365 */
366
367 while (tblend + 2 >= current_max_xpairs)
368 expand_nxt_chk ();
369
370 while (lastdfa + 1 >= current_max_dfas)
371 increase_max_dfas ();
372
373 base[lastdfa + 1] = tblend + 2;
374 nxt[tblend + 1] = end_of_buffer_action;
375 chk[tblend + 1] = numecs + 1;
376 chk[tblend + 2] = 1; /* anything but EOB */
377
378 /* So that "make test" won't show arb. differences. */
379 nxt[tblend + 2] = 0;
380
381 /* Make sure every state has an end-of-buffer transition and an
382 * action #.
383 */
384 for (i = 0; i <= lastdfa; ++i) {
385 int anum = dfaacc[i].dfaacc_state;
386 int offset = base[i];
387
388 chk[offset] = EOB_POSITION;
389 chk[offset - 1] = ACTION_POSITION;
390 nxt[offset - 1] = anum; /* action number */
391 }
392
393 for (i = 0; i <= tblend; ++i) {
394 if (chk[i] == EOB_POSITION)
395 transition_struct_out (0, base[lastdfa + 1] - i);
396
397 else if (chk[i] == ACTION_POSITION)
398 transition_struct_out (0, nxt[i]);
399
400 else if (chk[i] > numecs || chk[i] == 0)
401 transition_struct_out (0, 0); /* unused slot */
402
403 else /* verify, transition */
404 transition_struct_out (chk[i],
405 base[nxt[i]] - (i -
406 chk[i]));
407 }
408
409
410 /* Here's the final, end-of-buffer state. */
411 transition_struct_out (chk[tblend + 1], nxt[tblend + 1]);
412 transition_struct_out (chk[tblend + 2], nxt[tblend + 2]);
413
414 if (gentables)
415 outn (" };\n");
416
417 /* Table of pointers to start states. */
418 if (gentables)
419 out_dec ("static const struct yy_trans_info *yy_start_state_list[%d] =\n", lastsc * 2 + 1);
420 else
421 outn ("static const struct yy_trans_info **yy_start_state_list =0;");
422
423 if (gentables) {
424 outn (" {");
425
426 for (i = 0; i <= lastsc * 2; ++i)
427 out_dec (" &yy_transition[%d],\n", base[i]);
428
429 dataend ();
430 }
431
432 if (useecs)
433 genecs ();
434 }
435
436
437 /* mkecstbl - Make equivalence-class tables. */
438
mkecstbl(void)439 static struct yytbl_data *mkecstbl (void)
440 {
441 int i;
442 struct yytbl_data *tbl = 0;
443 flex_int32_t *tdata = 0;
444
445 tbl = calloc(1, sizeof (struct yytbl_data));
446 yytbl_data_init (tbl, YYTD_ID_EC);
447 tbl->td_flags |= YYTD_DATA32;
448 tbl->td_hilen = 0;
449 tbl->td_lolen = (flex_uint32_t) csize;
450
451 tbl->td_data = tdata =
452 calloc(tbl->td_lolen, sizeof (flex_int32_t));
453
454 for (i = 1; i < csize; ++i) {
455 ecgroup[i] = ABS (ecgroup[i]);
456 tdata[i] = ecgroup[i];
457 }
458
459 buf_prints (&yydmap_buf,
460 "\t{YYTD_ID_EC, (void**)&yy_ec, sizeof(%s)},\n",
461 "YY_CHAR");
462
463 return tbl;
464 }
465
466 /* Generate equivalence-class tables. */
467
genecs(void)468 void genecs (void)
469 {
470 int i, j;
471 int numrows;
472
473 out_str_dec (get_yy_char_decl (), "yy_ec", csize);
474
475 for (i = 1; i < csize; ++i) {
476 ecgroup[i] = ABS (ecgroup[i]);
477 mkdata (ecgroup[i]);
478 }
479
480 dataend ();
481
482 if (trace) {
483 fputs (_("\n\nEquivalence Classes:\n\n"), stderr);
484
485 numrows = csize / 8;
486
487 for (j = 0; j < numrows; ++j) {
488 for (i = j; i < csize; i = i + numrows) {
489 fprintf (stderr, "%4s = %-2d",
490 readable_form (i), ecgroup[i]);
491
492 putc (' ', stderr);
493 }
494
495 putc ('\n', stderr);
496 }
497 }
498 }
499
500
501 /* Generate the code to find the action number. */
502
gen_find_action(void)503 void gen_find_action (void)
504 {
505 if (fullspd)
506 indent_puts ("yy_act = yy_current_state[-1].yy_nxt;");
507
508 else if (fulltbl)
509 indent_puts ("yy_act = yy_accept[yy_current_state];");
510
511 else if (reject) {
512 indent_puts ("yy_current_state = *--YY_G(yy_state_ptr);");
513 indent_puts ("YY_G(yy_lp) = yy_accept[yy_current_state];");
514
515 if (!variable_trailing_context_rules)
516 outn ("m4_ifdef( [[M4_YY_USES_REJECT]],\n[[");
517 if(reject_really_used)
518 outn ("find_rule: /* we branch to this label when backing up */");
519 if (!variable_trailing_context_rules)
520 outn ("]])\n");
521
522 indent_puts
523 ("for ( ; ; ) /* until we find what rule we matched */");
524
525 ++indent_level;
526
527 indent_puts ("{");
528
529 indent_puts
530 ("if ( YY_G(yy_lp) && YY_G(yy_lp) < yy_accept[yy_current_state + 1] )");
531 ++indent_level;
532 indent_puts ("{");
533 indent_puts ("yy_act = yy_acclist[YY_G(yy_lp)];");
534
535 if (variable_trailing_context_rules) {
536 indent_puts
537 ("if ( yy_act & YY_TRAILING_HEAD_MASK ||");
538 indent_puts (" YY_G(yy_looking_for_trail_begin) )");
539 ++indent_level;
540 indent_puts ("{");
541
542 indent_puts
543 ("if ( yy_act == YY_G(yy_looking_for_trail_begin) )");
544 ++indent_level;
545 indent_puts ("{");
546 indent_puts ("YY_G(yy_looking_for_trail_begin) = 0;");
547 indent_puts ("yy_act &= ~YY_TRAILING_HEAD_MASK;");
548 indent_puts ("break;");
549 indent_puts ("}");
550 --indent_level;
551
552 indent_puts ("}");
553 --indent_level;
554
555 indent_puts
556 ("else if ( yy_act & YY_TRAILING_MASK )");
557 ++indent_level;
558 indent_puts ("{");
559 indent_puts
560 ("YY_G(yy_looking_for_trail_begin) = yy_act & ~YY_TRAILING_MASK;");
561 indent_puts
562 ("YY_G(yy_looking_for_trail_begin) |= YY_TRAILING_HEAD_MASK;");
563
564 if (real_reject) {
565 /* Remember matched text in case we back up
566 * due to REJECT.
567 */
568 indent_puts
569 ("YY_G(yy_full_match) = yy_cp;");
570 indent_puts
571 ("YY_G(yy_full_state) = YY_G(yy_state_ptr);");
572 indent_puts ("YY_G(yy_full_lp) = YY_G(yy_lp);");
573 }
574
575 indent_puts ("}");
576 --indent_level;
577
578 indent_puts ("else");
579 ++indent_level;
580 indent_puts ("{");
581 indent_puts ("YY_G(yy_full_match) = yy_cp;");
582 indent_puts
583 ("YY_G(yy_full_state) = YY_G(yy_state_ptr);");
584 indent_puts ("YY_G(yy_full_lp) = YY_G(yy_lp);");
585 indent_puts ("break;");
586 indent_puts ("}");
587 --indent_level;
588
589 indent_puts ("++YY_G(yy_lp);");
590 indent_puts ("goto find_rule;");
591 }
592
593 else {
594 /* Remember matched text in case we back up due to
595 * trailing context plus REJECT.
596 */
597 ++indent_level;
598 indent_puts ("{");
599 indent_puts ("YY_G(yy_full_match) = yy_cp;");
600 indent_puts ("break;");
601 indent_puts ("}");
602 --indent_level;
603 }
604
605 indent_puts ("}");
606 --indent_level;
607
608 indent_puts ("--yy_cp;");
609
610 /* We could consolidate the following two lines with those at
611 * the beginning, but at the cost of complaints that we're
612 * branching inside a loop.
613 */
614 indent_puts ("yy_current_state = *--YY_G(yy_state_ptr);");
615 indent_puts ("YY_G(yy_lp) = yy_accept[yy_current_state];");
616
617 indent_puts ("}");
618
619 --indent_level;
620 }
621
622 else { /* compressed */
623 indent_puts ("yy_act = yy_accept[yy_current_state];");
624
625 if (interactive && !reject) {
626 /* Do the guaranteed-needed backing up to figure out
627 * the match.
628 */
629 indent_puts ("if ( yy_act == 0 )");
630 ++indent_level;
631 indent_puts ("{ /* have to back up */");
632 indent_puts
633 ("yy_cp = YY_G(yy_last_accepting_cpos);");
634 indent_puts
635 ("yy_current_state = YY_G(yy_last_accepting_state);");
636 indent_puts
637 ("yy_act = yy_accept[yy_current_state];");
638 indent_puts ("}");
639 --indent_level;
640 }
641 }
642 }
643
644 /* mkftbl - make the full table and return the struct .
645 * you should call mkecstbl() after this.
646 */
647
mkftbl(void)648 struct yytbl_data *mkftbl (void)
649 {
650 int i;
651 int end_of_buffer_action = num_rules + 1;
652 struct yytbl_data *tbl;
653 flex_int32_t *tdata = 0;
654
655 tbl = calloc(1, sizeof (struct yytbl_data));
656 yytbl_data_init (tbl, YYTD_ID_ACCEPT);
657 tbl->td_flags |= YYTD_DATA32;
658 tbl->td_hilen = 0; /* it's a one-dimensional array */
659 tbl->td_lolen = (flex_uint32_t) (lastdfa + 1);
660
661 tbl->td_data = tdata =
662 calloc(tbl->td_lolen, sizeof (flex_int32_t));
663
664 dfaacc[end_of_buffer_state].dfaacc_state = end_of_buffer_action;
665
666 for (i = 1; i <= lastdfa; ++i) {
667 int anum = dfaacc[i].dfaacc_state;
668
669 tdata[i] = anum;
670
671 if (trace && anum)
672 fprintf (stderr, _("state # %d accepts: [%d]\n"),
673 i, anum);
674 }
675
676 buf_prints (&yydmap_buf,
677 "\t{YYTD_ID_ACCEPT, (void**)&yy_accept, sizeof(%s)},\n",
678 long_align ? "flex_int32_t" : "flex_int16_t");
679 return tbl;
680 }
681
682
683 /* genftbl - generate full transition table */
684
genftbl(void)685 void genftbl (void)
686 {
687 int i;
688 int end_of_buffer_action = num_rules + 1;
689
690 out_str_dec (long_align ? get_int32_decl () : get_int16_decl (),
691 "yy_accept", lastdfa + 1);
692
693 dfaacc[end_of_buffer_state].dfaacc_state = end_of_buffer_action;
694
695 for (i = 1; i <= lastdfa; ++i) {
696 int anum = dfaacc[i].dfaacc_state;
697
698 mkdata (anum);
699
700 if (trace && anum)
701 fprintf (stderr, _("state # %d accepts: [%d]\n"),
702 i, anum);
703 }
704
705 dataend ();
706
707 if (useecs)
708 genecs ();
709
710 /* Don't have to dump the actual full table entries - they were
711 * created on-the-fly.
712 */
713 }
714
715
716 /* Generate the code to find the next compressed-table state. */
717
gen_next_compressed_state(char * char_map)718 void gen_next_compressed_state (char *char_map)
719 {
720 indent_put2s ("YY_CHAR yy_c = %s;", char_map);
721
722 /* Save the backing-up info \before/ computing the next state
723 * because we always compute one more state than needed - we
724 * always proceed until we reach a jam state
725 */
726 gen_backing_up ();
727
728 indent_puts
729 ("while ( yy_chk[yy_base[yy_current_state] + yy_c] != yy_current_state )");
730 ++indent_level;
731 indent_puts ("{");
732 indent_puts ("yy_current_state = (int) yy_def[yy_current_state];");
733
734 if (usemecs) {
735 /* We've arrange it so that templates are never chained
736 * to one another. This means we can afford to make a
737 * very simple test to see if we need to convert to
738 * yy_c's meta-equivalence class without worrying
739 * about erroneously looking up the meta-equivalence
740 * class twice
741 */
742 do_indent ();
743
744 /* lastdfa + 2 is the beginning of the templates */
745 out_dec ("if ( yy_current_state >= %d )\n", lastdfa + 2);
746
747 ++indent_level;
748 indent_puts ("yy_c = yy_meta[yy_c];");
749 --indent_level;
750 }
751
752 indent_puts ("}");
753 --indent_level;
754
755 indent_puts
756 ("yy_current_state = yy_nxt[yy_base[yy_current_state] + yy_c];");
757 }
758
759
760 /* Generate the code to find the next match. */
761
gen_next_match(void)762 void gen_next_match (void)
763 {
764 /* NOTE - changes in here should be reflected in gen_next_state() and
765 * gen_NUL_trans().
766 */
767 char *char_map = useecs ?
768 "yy_ec[YY_SC_TO_UI(*yy_cp)] " : "YY_SC_TO_UI(*yy_cp)";
769
770 char *char_map_2 = useecs ?
771 "yy_ec[YY_SC_TO_UI(*++yy_cp)] " : "YY_SC_TO_UI(*++yy_cp)";
772
773 if (fulltbl) {
774 if (gentables)
775 indent_put2s
776 ("while ( (yy_current_state = yy_nxt[yy_current_state][ %s ]) > 0 )",
777 char_map);
778 else
779 indent_put2s
780 ("while ( (yy_current_state = yy_nxt[yy_current_state*YY_NXT_LOLEN + %s ]) > 0 )",
781 char_map);
782
783 ++indent_level;
784
785 if (num_backing_up > 0) {
786 indent_puts ("{");
787 gen_backing_up ();
788 outc ('\n');
789 }
790
791 indent_puts ("++yy_cp;");
792
793 if (num_backing_up > 0)
794
795 indent_puts ("}");
796
797 --indent_level;
798
799 outc ('\n');
800 indent_puts ("yy_current_state = -yy_current_state;");
801 }
802
803 else if (fullspd) {
804 indent_puts ("{");
805 indent_puts
806 ("const struct yy_trans_info *yy_trans_info;\n");
807 indent_puts ("YY_CHAR yy_c;\n");
808 indent_put2s ("for ( yy_c = %s;", char_map);
809 indent_puts
810 (" (yy_trans_info = &yy_current_state[yy_c])->");
811 indent_puts ("yy_verify == yy_c;");
812 indent_put2s (" yy_c = %s )", char_map_2);
813
814 ++indent_level;
815
816 if (num_backing_up > 0)
817 indent_puts ("{");
818
819 indent_puts ("yy_current_state += yy_trans_info->yy_nxt;");
820
821 if (num_backing_up > 0) {
822 outc ('\n');
823 gen_backing_up ();
824 indent_puts ("}");
825 }
826
827 --indent_level;
828 indent_puts ("}");
829 }
830
831 else { /* compressed */
832 indent_puts ("do");
833
834 ++indent_level;
835 indent_puts ("{");
836
837 gen_next_state (false);
838
839 indent_puts ("++yy_cp;");
840
841
842 indent_puts ("}");
843 --indent_level;
844
845 do_indent ();
846
847 if (interactive)
848 out_dec ("while ( yy_base[yy_current_state] != %d );\n", jambase);
849 else
850 out_dec ("while ( yy_current_state != %d );\n",
851 jamstate);
852
853 if (!reject && !interactive) {
854 /* Do the guaranteed-needed backing up to figure out
855 * the match.
856 */
857 indent_puts
858 ("yy_cp = YY_G(yy_last_accepting_cpos);");
859 indent_puts
860 ("yy_current_state = YY_G(yy_last_accepting_state);");
861 }
862 }
863 }
864
865
866 /* Generate the code to find the next state. */
867
gen_next_state(int worry_about_NULs)868 void gen_next_state (int worry_about_NULs)
869 { /* NOTE - changes in here should be reflected in gen_next_match() */
870 char char_map[256];
871
872 if (worry_about_NULs && !nultrans) {
873 if (useecs)
874 snprintf (char_map, sizeof(char_map),
875 "(*yy_cp ? yy_ec[YY_SC_TO_UI(*yy_cp)] : %d)",
876 NUL_ec);
877 else
878 snprintf (char_map, sizeof(char_map),
879 "(*yy_cp ? YY_SC_TO_UI(*yy_cp) : %d)",
880 NUL_ec);
881 }
882
883 else
884 strcpy (char_map, useecs ?
885 "yy_ec[YY_SC_TO_UI(*yy_cp)] " :
886 "YY_SC_TO_UI(*yy_cp)");
887
888 if (worry_about_NULs && nultrans) {
889 if (!fulltbl && !fullspd)
890 /* Compressed tables back up *before* they match. */
891 gen_backing_up ();
892
893 indent_puts ("if ( *yy_cp )");
894 ++indent_level;
895 indent_puts ("{");
896 }
897
898 if (fulltbl) {
899 if (gentables)
900 indent_put2s
901 ("yy_current_state = yy_nxt[yy_current_state][%s];",
902 char_map);
903 else
904 indent_put2s
905 ("yy_current_state = yy_nxt[yy_current_state*YY_NXT_LOLEN + %s];",
906 char_map);
907 }
908
909 else if (fullspd)
910 indent_put2s
911 ("yy_current_state += yy_current_state[%s].yy_nxt;",
912 char_map);
913
914 else
915 gen_next_compressed_state (char_map);
916
917 if (worry_about_NULs && nultrans) {
918
919 indent_puts ("}");
920 --indent_level;
921 indent_puts ("else");
922 ++indent_level;
923 indent_puts
924 ("yy_current_state = yy_NUL_trans[yy_current_state];");
925 --indent_level;
926 }
927
928 if (fullspd || fulltbl)
929 gen_backing_up ();
930
931 if (reject)
932 indent_puts ("*YY_G(yy_state_ptr)++ = yy_current_state;");
933 }
934
935
936 /* Generate the code to make a NUL transition. */
937
gen_NUL_trans(void)938 void gen_NUL_trans (void)
939 { /* NOTE - changes in here should be reflected in gen_next_match() */
940 /* Only generate a definition for "yy_cp" if we'll generate code
941 * that uses it. Otherwise lint and the like complain.
942 */
943 int need_backing_up = (num_backing_up > 0 && !reject);
944
945 if (need_backing_up && (!nultrans || fullspd || fulltbl))
946 /* We're going to need yy_cp lying around for the call
947 * below to gen_backing_up().
948 */
949 indent_puts ("char *yy_cp = YY_G(yy_c_buf_p);");
950
951 outc ('\n');
952
953 if (nultrans) {
954 indent_puts
955 ("yy_current_state = yy_NUL_trans[yy_current_state];");
956 indent_puts ("yy_is_jam = (yy_current_state == 0);");
957 }
958
959 else if (fulltbl) {
960 do_indent ();
961 if (gentables)
962 out_dec ("yy_current_state = yy_nxt[yy_current_state][%d];\n", NUL_ec);
963 else
964 out_dec ("yy_current_state = yy_nxt[yy_current_state*YY_NXT_LOLEN + %d];\n", NUL_ec);
965 indent_puts ("yy_is_jam = (yy_current_state <= 0);");
966 }
967
968 else if (fullspd) {
969 do_indent ();
970 out_dec ("int yy_c = %d;\n", NUL_ec);
971
972 indent_puts
973 ("const struct yy_trans_info *yy_trans_info;\n");
974 indent_puts
975 ("yy_trans_info = &yy_current_state[(unsigned int) yy_c];");
976 indent_puts ("yy_current_state += yy_trans_info->yy_nxt;");
977
978 indent_puts
979 ("yy_is_jam = (yy_trans_info->yy_verify != yy_c);");
980 }
981
982 else {
983 char NUL_ec_str[20];
984
985 snprintf (NUL_ec_str, sizeof(NUL_ec_str), "%d", NUL_ec);
986 gen_next_compressed_state (NUL_ec_str);
987
988 do_indent ();
989 out_dec ("yy_is_jam = (yy_current_state == %d);\n",
990 jamstate);
991
992 if (reject) {
993 /* Only stack this state if it's a transition we
994 * actually make. If we stack it on a jam, then
995 * the state stack and yy_c_buf_p get out of sync.
996 */
997 indent_puts ("if ( ! yy_is_jam )");
998 ++indent_level;
999 indent_puts
1000 ("*YY_G(yy_state_ptr)++ = yy_current_state;");
1001 --indent_level;
1002 }
1003 }
1004
1005 /* If we've entered an accepting state, back up; note that
1006 * compressed tables have *already* done such backing up, so
1007 * we needn't bother with it again.
1008 */
1009 if (need_backing_up && (fullspd || fulltbl)) {
1010 outc ('\n');
1011 indent_puts ("if ( ! yy_is_jam )");
1012 ++indent_level;
1013 indent_puts ("{");
1014 gen_backing_up ();
1015 indent_puts ("}");
1016 --indent_level;
1017 }
1018 }
1019
1020
1021 /* Generate the code to find the start state. */
1022
gen_start_state(void)1023 void gen_start_state (void)
1024 {
1025 if (fullspd) {
1026 if (bol_needed) {
1027 indent_puts
1028 ("yy_current_state = yy_start_state_list[YY_G(yy_start) + YY_AT_BOL()];");
1029 }
1030 else
1031 indent_puts
1032 ("yy_current_state = yy_start_state_list[YY_G(yy_start)];");
1033 }
1034
1035 else {
1036 indent_puts ("yy_current_state = YY_G(yy_start);");
1037
1038 if (bol_needed)
1039 indent_puts ("yy_current_state += YY_AT_BOL();");
1040
1041 if (reject) {
1042 /* Set up for storing up states. */
1043 outn ("m4_ifdef( [[M4_YY_USES_REJECT]],\n[[");
1044 indent_puts
1045 ("YY_G(yy_state_ptr) = YY_G(yy_state_buf);");
1046 indent_puts
1047 ("*YY_G(yy_state_ptr)++ = yy_current_state;");
1048 outn ("]])");
1049 }
1050 }
1051 }
1052
1053
1054 /* gentabs - generate data statements for the transition tables */
1055
gentabs(void)1056 void gentabs (void)
1057 {
1058 int i, j, k, *accset, nacc, *acc_array, total_states;
1059 int end_of_buffer_action = num_rules + 1;
1060 struct yytbl_data *yyacc_tbl = 0, *yymeta_tbl = 0, *yybase_tbl = 0,
1061 *yydef_tbl = 0, *yynxt_tbl = 0, *yychk_tbl = 0, *yyacclist_tbl=0;
1062 flex_int32_t *yyacc_data = 0, *yybase_data = 0, *yydef_data = 0,
1063 *yynxt_data = 0, *yychk_data = 0, *yyacclist_data=0;
1064 flex_int32_t yybase_curr = 0, yyacclist_curr=0,yyacc_curr=0;
1065
1066 acc_array = allocate_integer_array (current_max_dfas);
1067 nummt = 0;
1068
1069 /* The compressed table format jams by entering the "jam state",
1070 * losing information about the previous state in the process.
1071 * In order to recover the previous state, we effectively need
1072 * to keep backing-up information.
1073 */
1074 ++num_backing_up;
1075
1076 if (reject) {
1077 /* Write out accepting list and pointer list.
1078
1079 * First we generate the "yy_acclist" array. In the process,
1080 * we compute the indices that will go into the "yy_accept"
1081 * array, and save the indices in the dfaacc array.
1082 */
1083 int EOB_accepting_list[2];
1084
1085 /* Set up accepting structures for the End Of Buffer state. */
1086 EOB_accepting_list[0] = 0;
1087 EOB_accepting_list[1] = end_of_buffer_action;
1088 accsiz[end_of_buffer_state] = 1;
1089 dfaacc[end_of_buffer_state].dfaacc_set =
1090 EOB_accepting_list;
1091
1092 out_str_dec (long_align ? get_int32_decl () :
1093 get_int16_decl (), "yy_acclist", MAX (numas,
1094 1) + 1);
1095
1096 buf_prints (&yydmap_buf,
1097 "\t{YYTD_ID_ACCLIST, (void**)&yy_acclist, sizeof(%s)},\n",
1098 long_align ? "flex_int32_t" : "flex_int16_t");
1099
1100 yyacclist_tbl = calloc(1,sizeof(struct yytbl_data));
1101 yytbl_data_init (yyacclist_tbl, YYTD_ID_ACCLIST);
1102 yyacclist_tbl->td_lolen = (flex_uint32_t) (MAX(numas,1) + 1);
1103 yyacclist_tbl->td_data = yyacclist_data =
1104 calloc(yyacclist_tbl->td_lolen, sizeof (flex_int32_t));
1105 yyacclist_curr = 1;
1106
1107 j = 1; /* index into "yy_acclist" array */
1108
1109 for (i = 1; i <= lastdfa; ++i) {
1110 acc_array[i] = j;
1111
1112 if (accsiz[i] != 0) {
1113 accset = dfaacc[i].dfaacc_set;
1114 nacc = accsiz[i];
1115
1116 if (trace)
1117 fprintf (stderr,
1118 _("state # %d accepts: "),
1119 i);
1120
1121 for (k = 1; k <= nacc; ++k) {
1122 int accnum = accset[k];
1123
1124 ++j;
1125
1126 if (variable_trailing_context_rules
1127 && !(accnum &
1128 YY_TRAILING_HEAD_MASK)
1129 && accnum > 0
1130 && accnum <= num_rules
1131 && rule_type[accnum] ==
1132 RULE_VARIABLE) {
1133 /* Special hack to flag
1134 * accepting number as part
1135 * of trailing context rule.
1136 */
1137 accnum |= YY_TRAILING_MASK;
1138 }
1139
1140 mkdata (accnum);
1141 yyacclist_data[yyacclist_curr++] = accnum;
1142
1143 if (trace) {
1144 fprintf (stderr, "[%d]",
1145 accset[k]);
1146
1147 if (k < nacc)
1148 fputs (", ",
1149 stderr);
1150 else
1151 putc ('\n',
1152 stderr);
1153 }
1154 }
1155 }
1156 }
1157
1158 /* add accepting number for the "jam" state */
1159 acc_array[i] = j;
1160
1161 dataend ();
1162 if (tablesext) {
1163 yytbl_data_compress (yyacclist_tbl);
1164 if (yytbl_data_fwrite (&tableswr, yyacclist_tbl) < 0)
1165 flexerror (_("Could not write yyacclist_tbl"));
1166 yytbl_data_destroy (yyacclist_tbl);
1167 yyacclist_tbl = NULL;
1168 }
1169 }
1170
1171 else {
1172 dfaacc[end_of_buffer_state].dfaacc_state =
1173 end_of_buffer_action;
1174
1175 for (i = 1; i <= lastdfa; ++i)
1176 acc_array[i] = dfaacc[i].dfaacc_state;
1177
1178 /* add accepting number for jam state */
1179 acc_array[i] = 0;
1180 }
1181
1182 /* Begin generating yy_accept */
1183
1184 /* Spit out "yy_accept" array. If we're doing "reject", it'll be
1185 * pointers into the "yy_acclist" array. Otherwise it's actual
1186 * accepting numbers. In either case, we just dump the numbers.
1187 */
1188
1189 /* "lastdfa + 2" is the size of "yy_accept"; includes room for C arrays
1190 * beginning at 0 and for "jam" state.
1191 */
1192 k = lastdfa + 2;
1193
1194 if (reject)
1195 /* We put a "cap" on the table associating lists of accepting
1196 * numbers with state numbers. This is needed because we tell
1197 * where the end of an accepting list is by looking at where
1198 * the list for the next state starts.
1199 */
1200 ++k;
1201
1202 out_str_dec (long_align ? get_int32_decl () : get_int16_decl (),
1203 "yy_accept", k);
1204
1205 buf_prints (&yydmap_buf,
1206 "\t{YYTD_ID_ACCEPT, (void**)&yy_accept, sizeof(%s)},\n",
1207 long_align ? "flex_int32_t" : "flex_int16_t");
1208
1209 yyacc_tbl = calloc(1, sizeof (struct yytbl_data));
1210 yytbl_data_init (yyacc_tbl, YYTD_ID_ACCEPT);
1211 yyacc_tbl->td_lolen = (flex_uint32_t) k;
1212 yyacc_tbl->td_data = yyacc_data =
1213 calloc(yyacc_tbl->td_lolen, sizeof (flex_int32_t));
1214 yyacc_curr=1;
1215
1216 for (i = 1; i <= lastdfa; ++i) {
1217 mkdata (acc_array[i]);
1218 yyacc_data[yyacc_curr++] = acc_array[i];
1219
1220 if (!reject && trace && acc_array[i])
1221 fprintf (stderr, _("state # %d accepts: [%d]\n"),
1222 i, acc_array[i]);
1223 }
1224
1225 /* Add entry for "jam" state. */
1226 mkdata (acc_array[i]);
1227 yyacc_data[yyacc_curr++] = acc_array[i];
1228
1229 if (reject) {
1230 /* Add "cap" for the list. */
1231 mkdata (acc_array[i]);
1232 yyacc_data[yyacc_curr++] = acc_array[i];
1233 }
1234
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;
1242 }
1243 /* End generating yy_accept */
1244
1245 if (useecs) {
1246
1247 genecs ();
1248 if (tablesext) {
1249 struct yytbl_data *tbl;
1250
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;
1257 }
1258 }
1259
1260 if (usemecs) {
1261 /* Begin generating yy_meta */
1262 /* Write out meta-equivalence classes (used to index
1263 * templates with).
1264 */
1265 flex_int32_t *yymecs_data = 0;
1266 yymeta_tbl = calloc(1, sizeof (struct yytbl_data));
1267 yytbl_data_init (yymeta_tbl, YYTD_ID_META);
1268 yymeta_tbl->td_lolen = (flex_uint32_t) (numecs + 1);
1269 yymeta_tbl->td_data = yymecs_data =
1270 calloc(yymeta_tbl->td_lolen,
1271 sizeof (flex_int32_t));
1272
1273 if (trace)
1274 fputs (_("\n\nMeta-Equivalence Classes:\n"),
1275 stderr);
1276
1277 out_str_dec (get_yy_char_decl (), "yy_meta", numecs + 1);
1278 buf_prints (&yydmap_buf,
1279 "\t{YYTD_ID_META, (void**)&yy_meta, sizeof(%s)},\n",
1280 "YY_CHAR");
1281
1282 for (i = 1; i <= numecs; ++i) {
1283 if (trace)
1284 fprintf (stderr, "%d = %d\n",
1285 i, ABS (tecbck[i]));
1286
1287 mkdata (ABS (tecbck[i]));
1288 yymecs_data[i] = ABS (tecbck[i]);
1289 }
1290
1291 dataend ();
1292 if (tablesext) {
1293 yytbl_data_compress (yymeta_tbl);
1294 if (yytbl_data_fwrite (&tableswr, yymeta_tbl) < 0)
1295 flexerror (_
1296 ("Could not write yymeta_tbl"));
1297 yytbl_data_destroy (yymeta_tbl);
1298 yymeta_tbl = NULL;
1299 }
1300 /* End generating yy_meta */
1301 }
1302
1303 total_states = lastdfa + numtemps;
1304
1305 /* Begin generating yy_base */
1306 out_str_dec ((tblend >= INT16_MAX || long_align) ?
1307 get_int32_decl () : get_int16_decl (),
1308 "yy_base", total_states + 1);
1309
1310 buf_prints (&yydmap_buf,
1311 "\t{YYTD_ID_BASE, (void**)&yy_base, sizeof(%s)},\n",
1312 (tblend >= INT16_MAX
1313 || long_align) ? "flex_int32_t" : "flex_int16_t");
1314 yybase_tbl = calloc (1, sizeof (struct yytbl_data));
1315 yytbl_data_init (yybase_tbl, YYTD_ID_BASE);
1316 yybase_tbl->td_lolen = (flex_uint32_t) (total_states + 1);
1317 yybase_tbl->td_data = yybase_data =
1318 calloc(yybase_tbl->td_lolen,
1319 sizeof (flex_int32_t));
1320 yybase_curr = 1;
1321
1322 for (i = 1; i <= lastdfa; ++i) {
1323 int d = def[i];
1324
1325 if (base[i] == JAMSTATE)
1326 base[i] = jambase;
1327
1328 if (d == JAMSTATE)
1329 def[i] = jamstate;
1330
1331 else if (d < 0) {
1332 /* Template reference. */
1333 ++tmpuses;
1334 def[i] = lastdfa - d + 1;
1335 }
1336
1337 mkdata (base[i]);
1338 yybase_data[yybase_curr++] = base[i];
1339 }
1340
1341 /* Generate jam state's base index. */
1342 mkdata (base[i]);
1343 yybase_data[yybase_curr++] = base[i];
1344
1345 for (++i /* skip jam state */ ; i <= total_states; ++i) {
1346 mkdata (base[i]);
1347 yybase_data[yybase_curr++] = base[i];
1348 def[i] = jamstate;
1349 }
1350
1351 dataend ();
1352 if (tablesext) {
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);
1357 yybase_tbl = NULL;
1358 }
1359 /* End generating yy_base */
1360
1361
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);
1366
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");
1371
1372 yydef_tbl = calloc(1, sizeof (struct yytbl_data));
1373 yytbl_data_init (yydef_tbl, YYTD_ID_DEF);
1374 yydef_tbl->td_lolen = (flex_uint32_t) (total_states + 1);
1375 yydef_tbl->td_data = yydef_data =
1376 calloc(yydef_tbl->td_lolen, sizeof (flex_int32_t));
1377
1378 for (i = 1; i <= total_states; ++i) {
1379 mkdata (def[i]);
1380 yydef_data[i] = def[i];
1381 }
1382
1383 dataend ();
1384 if (tablesext) {
1385 yytbl_data_compress (yydef_tbl);
1386 if (yytbl_data_fwrite (&tableswr, yydef_tbl) < 0)
1387 flexerror (_("Could not write yydef_tbl"));
1388 yytbl_data_destroy (yydef_tbl);
1389 yydef_tbl = NULL;
1390 }
1391 /* End generating yy_def */
1392
1393
1394 /* Begin generating yy_nxt */
1395 out_str_dec ((total_states >= INT16_MAX || long_align) ?
1396 get_int32_decl () : get_int16_decl (), "yy_nxt",
1397 tblend + 1);
1398
1399 buf_prints (&yydmap_buf,
1400 "\t{YYTD_ID_NXT, (void**)&yy_nxt, sizeof(%s)},\n",
1401 (total_states >= INT16_MAX
1402 || long_align) ? "flex_int32_t" : "flex_int16_t");
1403
1404 yynxt_tbl = calloc (1, sizeof (struct yytbl_data));
1405 yytbl_data_init (yynxt_tbl, YYTD_ID_NXT);
1406 yynxt_tbl->td_lolen = (flex_uint32_t) (tblend + 1);
1407 yynxt_tbl->td_data = yynxt_data =
1408 calloc (yynxt_tbl->td_lolen, sizeof (flex_int32_t));
1409
1410 for (i = 1; i <= tblend; ++i) {
1411 /* Note, the order of the following test is important.
1412 * If chk[i] is 0, then nxt[i] is undefined.
1413 */
1414 if (chk[i] == 0 || nxt[i] == 0)
1415 nxt[i] = jamstate; /* new state is the JAM state */
1416
1417 mkdata (nxt[i]);
1418 yynxt_data[i] = nxt[i];
1419 }
1420
1421 dataend ();
1422 if (tablesext) {
1423 yytbl_data_compress (yynxt_tbl);
1424 if (yytbl_data_fwrite (&tableswr, yynxt_tbl) < 0)
1425 flexerror (_("Could not write yynxt_tbl"));
1426 yytbl_data_destroy (yynxt_tbl);
1427 yynxt_tbl = NULL;
1428 }
1429 /* End generating yy_nxt */
1430
1431 /* Begin generating yy_chk */
1432 out_str_dec ((total_states >= INT16_MAX || long_align) ?
1433 get_int32_decl () : get_int16_decl (), "yy_chk",
1434 tblend + 1);
1435
1436 buf_prints (&yydmap_buf,
1437 "\t{YYTD_ID_CHK, (void**)&yy_chk, sizeof(%s)},\n",
1438 (total_states >= INT16_MAX
1439 || long_align) ? "flex_int32_t" : "flex_int16_t");
1440
1441 yychk_tbl = calloc (1, sizeof (struct yytbl_data));
1442 yytbl_data_init (yychk_tbl, YYTD_ID_CHK);
1443 yychk_tbl->td_lolen = (flex_uint32_t) (tblend + 1);
1444 yychk_tbl->td_data = yychk_data =
1445 calloc(yychk_tbl->td_lolen, sizeof (flex_int32_t));
1446
1447 for (i = 1; i <= tblend; ++i) {
1448 if (chk[i] == 0)
1449 ++nummt;
1450
1451 mkdata (chk[i]);
1452 yychk_data[i] = chk[i];
1453 }
1454
1455 dataend ();
1456 if (tablesext) {
1457 yytbl_data_compress (yychk_tbl);
1458 if (yytbl_data_fwrite (&tableswr, yychk_tbl) < 0)
1459 flexerror (_("Could not write yychk_tbl"));
1460 yytbl_data_destroy (yychk_tbl);
1461 yychk_tbl = NULL;
1462 }
1463 /* End generating yy_chk */
1464
1465 free(acc_array);
1466 }
1467
1468
1469 /* Write out a formatted string (with a secondary string argument) at the
1470 * current indentation level, adding a final newline.
1471 */
1472
indent_put2s(const char * fmt,const char * arg)1473 void indent_put2s (const char *fmt, const char *arg)
1474 {
1475 do_indent ();
1476 out_str (fmt, arg);
1477 outn ("");
1478 }
1479
1480
1481 /* Write out a string at the current indentation level, adding a final
1482 * newline.
1483 */
1484
indent_puts(const char * str)1485 void indent_puts (const char *str)
1486 {
1487 do_indent ();
1488 outn (str);
1489 }
1490
1491
1492 /* make_tables - generate transition tables and finishes generating output file
1493 */
1494
make_tables(void)1495 void make_tables (void)
1496 {
1497 int i;
1498 int did_eof_rule = false;
1499 struct yytbl_data *yynultrans_tbl = NULL;
1500
1501
1502 skelout (); /* %% [2.0] - break point in skel */
1503
1504 /* First, take care of YY_DO_BEFORE_ACTION depending on yymore
1505 * being used.
1506 */
1507 set_indent (1);
1508
1509 if (yymore_used && !yytext_is_array) {
1510 indent_puts ("YY_G(yytext_ptr) -= YY_G(yy_more_len); \\");
1511 indent_puts
1512 ("yyleng = (yy_size_t)(yy_cp - YY_G(yytext_ptr)); \\");
1513 }
1514
1515 else
1516 indent_puts ("yyleng = (yy_size_t)(yy_cp - yy_bp); \\");
1517
1518 /* Now also deal with copying yytext_ptr to yytext if needed. */
1519 skelout (); /* %% [3.0] - break point in skel */
1520 if (yytext_is_array) {
1521 if (yymore_used)
1522 indent_puts
1523 ("if ( yyleng + YY_G(yy_more_offset) >= YYLMAX ) \\");
1524 else
1525 indent_puts ("if ( yyleng >= YYLMAX ) \\");
1526
1527 ++indent_level;
1528 indent_puts
1529 ("YY_FATAL_ERROR( \"token too large, exceeds YYLMAX\" ); \\");
1530 --indent_level;
1531
1532 if (yymore_used) {
1533 indent_puts
1534 ("yy_flex_strncpy( &yytext[YY_G(yy_more_offset)], YY_G(yytext_ptr), yyleng + 1 M4_YY_CALL_LAST_ARG); \\");
1535 indent_puts ("yyleng += YY_G(yy_more_offset); \\");
1536 indent_puts
1537 ("YY_G(yy_prev_more_offset) = YY_G(yy_more_offset); \\");
1538 indent_puts ("YY_G(yy_more_offset) = 0; \\");
1539 }
1540 else {
1541 indent_puts
1542 ("yy_flex_strncpy( yytext, YY_G(yytext_ptr), yyleng + 1 M4_YY_CALL_LAST_ARG); \\");
1543 }
1544 }
1545
1546 set_indent (0);
1547
1548 skelout (); /* %% [4.0] - break point in skel */
1549
1550
1551 /* This is where we REALLY begin generating the tables. */
1552
1553 out_dec ("#define YY_NUM_RULES %d\n", num_rules);
1554 out_dec ("#define YY_END_OF_BUFFER %d\n", num_rules + 1);
1555
1556 if (fullspd) {
1557 /* Need to define the transet type as a size large
1558 * enough to hold the biggest offset.
1559 */
1560 int total_table_size = tblend + numecs + 1;
1561 char *trans_offset_type =
1562 (total_table_size >= INT16_MAX || long_align) ?
1563 "flex_int32_t" : "flex_int16_t";
1564
1565 set_indent (0);
1566 indent_puts ("struct yy_trans_info");
1567 ++indent_level;
1568 indent_puts ("{");
1569
1570 /* We require that yy_verify and yy_nxt must be of the same size int. */
1571 indent_put2s ("%s yy_verify;", trans_offset_type);
1572
1573 /* In cases where its sister yy_verify *is* a "yes, there is
1574 * a transition", yy_nxt is the offset (in records) to the
1575 * next state. In most cases where there is no transition,
1576 * the value of yy_nxt is irrelevant. If yy_nxt is the -1th
1577 * record of a state, though, then yy_nxt is the action number
1578 * for that state.
1579 */
1580
1581 indent_put2s ("%s yy_nxt;", trans_offset_type);
1582 indent_puts ("};");
1583 --indent_level;
1584 }
1585 else {
1586 /* We generate a bogus 'struct yy_trans_info' data type
1587 * so we can guarantee that it is always declared in the skel.
1588 * This is so we can compile "sizeof(struct yy_trans_info)"
1589 * in any scanner.
1590 */
1591 indent_puts
1592 ("/* This struct is not used in this scanner,");
1593 indent_puts (" but its presence is necessary. */");
1594 indent_puts ("struct yy_trans_info");
1595 ++indent_level;
1596 indent_puts ("{");
1597 indent_puts ("flex_int32_t yy_verify;");
1598 indent_puts ("flex_int32_t yy_nxt;");
1599 indent_puts ("};");
1600 --indent_level;
1601 }
1602
1603 if (fullspd) {
1604 genctbl ();
1605 if (tablesext) {
1606 struct yytbl_data *tbl;
1607
1608 tbl = mkctbl ();
1609 yytbl_data_compress (tbl);
1610 if (yytbl_data_fwrite (&tableswr, tbl) < 0)
1611 flexerror (_("Could not write ftbl"));
1612 yytbl_data_destroy (tbl);
1613
1614 tbl = mkssltbl ();
1615 yytbl_data_compress (tbl);
1616 if (yytbl_data_fwrite (&tableswr, tbl) < 0)
1617 flexerror (_("Could not write ssltbl"));
1618 yytbl_data_destroy (tbl);
1619 tbl = 0;
1620
1621 if (useecs) {
1622 tbl = mkecstbl ();
1623 yytbl_data_compress (tbl);
1624 if (yytbl_data_fwrite (&tableswr, tbl) < 0)
1625 flexerror (_
1626 ("Could not write ecstbl"));
1627 yytbl_data_destroy (tbl);
1628 tbl = 0;
1629 }
1630 }
1631 }
1632 else if (fulltbl) {
1633 genftbl ();
1634 if (tablesext) {
1635 struct yytbl_data *tbl;
1636
1637 tbl = mkftbl ();
1638 yytbl_data_compress (tbl);
1639 if (yytbl_data_fwrite (&tableswr, tbl) < 0)
1640 flexerror (_("Could not write ftbl"));
1641 yytbl_data_destroy (tbl);
1642 tbl = 0;
1643
1644 if (useecs) {
1645 tbl = mkecstbl ();
1646 yytbl_data_compress (tbl);
1647 if (yytbl_data_fwrite (&tableswr, tbl) < 0)
1648 flexerror (_
1649 ("Could not write ecstbl"));
1650 yytbl_data_destroy (tbl);
1651 tbl = 0;
1652 }
1653 }
1654 }
1655 else
1656 gentabs ();
1657
1658 if (do_yylineno) {
1659
1660 geneoltbl ();
1661
1662 if (tablesext) {
1663 struct yytbl_data *tbl;
1664
1665 tbl = mkeoltbl ();
1666 yytbl_data_compress (tbl);
1667 if (yytbl_data_fwrite (&tableswr, tbl) < 0)
1668 flexerror (_("Could not write eoltbl"));
1669 yytbl_data_destroy (tbl);
1670 tbl = 0;
1671 }
1672 }
1673
1674 /* Definitions for backing up. We don't need them if REJECT
1675 * is being used because then we use an alternative backin-up
1676 * technique instead.
1677 */
1678 if (num_backing_up > 0 && !reject) {
1679 if (!C_plus_plus && !reentrant) {
1680 indent_puts
1681 ("static yy_state_type yy_last_accepting_state;");
1682 indent_puts
1683 ("static char *yy_last_accepting_cpos;\n");
1684 }
1685 }
1686
1687 if (nultrans) {
1688 flex_int32_t *yynultrans_data = 0;
1689
1690 /* Begin generating yy_NUL_trans */
1691 out_str_dec (get_state_decl (), "yy_NUL_trans",
1692 lastdfa + 1);
1693 buf_prints (&yydmap_buf,
1694 "\t{YYTD_ID_NUL_TRANS, (void**)&yy_NUL_trans, sizeof(%s)},\n",
1695 (fullspd) ? "struct yy_trans_info*" :
1696 "flex_int32_t");
1697
1698 yynultrans_tbl = calloc(1, sizeof (struct yytbl_data));
1699 yytbl_data_init (yynultrans_tbl, YYTD_ID_NUL_TRANS);
1700 if (fullspd)
1701 yynultrans_tbl->td_flags |= YYTD_PTRANS;
1702 yynultrans_tbl->td_lolen = (flex_uint32_t) (lastdfa + 1);
1703 yynultrans_tbl->td_data = yynultrans_data =
1704 calloc(yynultrans_tbl->td_lolen,
1705 sizeof (flex_int32_t));
1706
1707 for (i = 1; i <= lastdfa; ++i) {
1708 if (fullspd) {
1709 out_dec (" &yy_transition[%d],\n",
1710 base[i]);
1711 yynultrans_data[i] = base[i];
1712 }
1713 else {
1714 mkdata (nultrans[i]);
1715 yynultrans_data[i] = nultrans[i];
1716 }
1717 }
1718
1719 dataend ();
1720 if (tablesext) {
1721 yytbl_data_compress (yynultrans_tbl);
1722 if (yytbl_data_fwrite (&tableswr, yynultrans_tbl) <
1723 0)
1724 flexerror (_
1725 ("Could not write yynultrans_tbl"));
1726 }
1727
1728 if (yynultrans_tbl != NULL) {
1729 yytbl_data_destroy (yynultrans_tbl);
1730 yynultrans_tbl = NULL;
1731 }
1732
1733 /* End generating yy_NUL_trans */
1734 }
1735
1736 if (!C_plus_plus && !reentrant) {
1737 indent_puts ("extern int yy_flex_debug;");
1738 indent_put2s ("int yy_flex_debug = %s;\n",
1739 ddebug ? "1" : "0");
1740 }
1741
1742 if (ddebug) { /* Spit out table mapping rules to line numbers. */
1743 out_str_dec (long_align ? get_int32_decl () :
1744 get_int16_decl (), "yy_rule_linenum",
1745 num_rules);
1746 for (i = 1; i < num_rules; ++i)
1747 mkdata (rule_linenum[i]);
1748 dataend ();
1749 }
1750
1751 if (reject) {
1752 outn ("m4_ifdef( [[M4_YY_USES_REJECT]],\n[[");
1753 /* Declare state buffer variables. */
1754 if (!C_plus_plus && !reentrant) {
1755 outn ("static yy_state_type *yy_state_buf=0, *yy_state_ptr=0;");
1756 outn ("static char *yy_full_match;");
1757 outn ("static int yy_lp;");
1758 }
1759
1760 if (variable_trailing_context_rules) {
1761 if (!C_plus_plus && !reentrant) {
1762 outn ("static int yy_looking_for_trail_begin = 0;");
1763 outn ("static int yy_full_lp;");
1764 outn ("static int *yy_full_state;");
1765 }
1766
1767 out_hex ("#define YY_TRAILING_MASK 0x%x\n",
1768 (unsigned int) YY_TRAILING_MASK);
1769 out_hex ("#define YY_TRAILING_HEAD_MASK 0x%x\n",
1770 (unsigned int) YY_TRAILING_HEAD_MASK);
1771 }
1772
1773 outn ("#define REJECT \\");
1774 outn ("{ \\");
1775 outn ("*yy_cp = YY_G(yy_hold_char); /* undo effects of setting up yytext */ \\");
1776 outn ("yy_cp = YY_G(yy_full_match); /* restore poss. backed-over text */ \\");
1777
1778 if (variable_trailing_context_rules) {
1779 outn ("YY_G(yy_lp) = YY_G(yy_full_lp); /* restore orig. accepting pos. */ \\");
1780 outn ("YY_G(yy_state_ptr) = YY_G(yy_full_state); /* restore orig. state */ \\");
1781 outn ("yy_current_state = *YY_G(yy_state_ptr); /* restore curr. state */ \\");
1782 }
1783
1784 outn ("++YY_G(yy_lp); \\");
1785 outn ("goto find_rule; \\");
1786
1787 outn ("}");
1788 outn ("]])\n");
1789 }
1790
1791 else {
1792 outn ("/* The intent behind this definition is that it'll catch");
1793 outn (" * any uses of REJECT which flex missed.");
1794 outn (" */");
1795 outn ("#define REJECT reject_used_but_not_detected");
1796 }
1797
1798 if (yymore_used) {
1799 if (!C_plus_plus) {
1800 if (yytext_is_array) {
1801 if (!reentrant){
1802 indent_puts ("static int yy_more_offset = 0;");
1803 indent_puts ("static int yy_prev_more_offset = 0;");
1804 }
1805 }
1806 else if (!reentrant) {
1807 indent_puts
1808 ("static int yy_more_flag = 0;");
1809 indent_puts
1810 ("static int yy_more_len = 0;");
1811 }
1812 }
1813
1814 if (yytext_is_array) {
1815 indent_puts
1816 ("#define yymore() (YY_G(yy_more_offset) = yy_flex_strlen( yytext M4_YY_CALL_LAST_ARG))");
1817 indent_puts ("#define YY_NEED_STRLEN");
1818 indent_puts ("#define YY_MORE_ADJ 0");
1819 indent_puts
1820 ("#define YY_RESTORE_YY_MORE_OFFSET \\");
1821 ++indent_level;
1822 indent_puts ("{ \\");
1823 indent_puts
1824 ("YY_G(yy_more_offset) = YY_G(yy_prev_more_offset); \\");
1825 indent_puts ("yyleng -= YY_G(yy_more_offset); \\");
1826 indent_puts ("}");
1827 --indent_level;
1828 }
1829 else {
1830 indent_puts
1831 ("#define yymore() (YY_G(yy_more_flag) = 1)");
1832 indent_puts
1833 ("#define YY_MORE_ADJ YY_G(yy_more_len)");
1834 indent_puts ("#define YY_RESTORE_YY_MORE_OFFSET");
1835 }
1836 }
1837
1838 else {
1839 indent_puts
1840 ("#define yymore() yymore_used_but_not_detected");
1841 indent_puts ("#define YY_MORE_ADJ 0");
1842 indent_puts ("#define YY_RESTORE_YY_MORE_OFFSET");
1843 }
1844
1845 if (!C_plus_plus) {
1846 if (yytext_is_array) {
1847 outn ("#ifndef YYLMAX");
1848 outn ("#define YYLMAX 8192");
1849 outn ("#endif\n");
1850 if (!reentrant){
1851 outn ("char yytext[YYLMAX];");
1852 outn ("char *yytext_ptr;");
1853 }
1854 }
1855
1856 else {
1857 if(! reentrant)
1858 outn ("char *yytext;");
1859 }
1860 }
1861
1862 out (&action_array[defs1_offset]);
1863
1864 line_directive_out (stdout, 0);
1865
1866 skelout (); /* %% [5.0] - break point in skel */
1867
1868 if (!C_plus_plus) {
1869 if (use_read) {
1870 outn ("\terrno=0; \\");
1871 outn ("\twhile ( (result = (int) read( fileno(yyin), buf, (yy_size_t) max_size )) < 0 ) \\");
1872 outn ("\t{ \\");
1873 outn ("\t\tif( errno != EINTR) \\");
1874 outn ("\t\t{ \\");
1875 outn ("\t\t\tYY_FATAL_ERROR( \"input in flex scanner failed\" ); \\");
1876 outn ("\t\t\tbreak; \\");
1877 outn ("\t\t} \\");
1878 outn ("\t\terrno=0; \\");
1879 outn ("\t\tclearerr(yyin); \\");
1880 outn ("\t}\\");
1881 }
1882
1883 else {
1884 outn ("\tif ( YY_CURRENT_BUFFER_LVALUE->yy_is_interactive ) \\");
1885 outn ("\t\t{ \\");
1886 outn ("\t\tint c = '*'; \\");
1887 outn ("\t\tyy_size_t n; \\");
1888 outn ("\t\tfor ( n = 0; n < max_size && \\");
1889 outn ("\t\t\t (c = getc( yyin )) != EOF && c != '\\n'; ++n ) \\");
1890 outn ("\t\t\tbuf[n] = (char) c; \\");
1891 outn ("\t\tif ( c == '\\n' ) \\");
1892 outn ("\t\t\tbuf[n++] = (char) c; \\");
1893 outn ("\t\tif ( c == EOF && ferror( yyin ) ) \\");
1894 outn ("\t\t\tYY_FATAL_ERROR( \"input in flex scanner failed\" ); \\");
1895 outn ("\t\tresult = n; \\");
1896 outn ("\t\t} \\");
1897 outn ("\telse \\");
1898 outn ("\t\t{ \\");
1899 outn ("\t\terrno=0; \\");
1900 outn ("\t\twhile ( (result = fread(buf, 1, (yy_size_t) max_size, yyin)) == 0 && ferror(yyin)) \\");
1901 outn ("\t\t\t{ \\");
1902 outn ("\t\t\tif( errno != EINTR) \\");
1903 outn ("\t\t\t\t{ \\");
1904 outn ("\t\t\t\tYY_FATAL_ERROR( \"input in flex scanner failed\" ); \\");
1905 outn ("\t\t\t\tbreak; \\");
1906 outn ("\t\t\t\t} \\");
1907 outn ("\t\t\terrno=0; \\");
1908 outn ("\t\t\tclearerr(yyin); \\");
1909 outn ("\t\t\t} \\");
1910 outn ("\t\t}\\");
1911 }
1912 }
1913
1914 skelout (); /* %% [6.0] - break point in skel */
1915
1916 indent_puts ("#define YY_RULE_SETUP \\");
1917 ++indent_level;
1918 if (bol_needed) {
1919 indent_puts ("if ( yyleng > 0 ) \\");
1920 ++indent_level;
1921 indent_puts ("YY_CURRENT_BUFFER_LVALUE->yy_at_bol = \\");
1922 indent_puts ("\t\t(yytext[yyleng - 1] == '\\n'); \\");
1923 --indent_level;
1924 }
1925 indent_puts ("YY_USER_ACTION");
1926 --indent_level;
1927
1928 skelout (); /* %% [7.0] - break point in skel */
1929
1930 /* Copy prolog to output file. */
1931 out (&action_array[prolog_offset]);
1932
1933 line_directive_out (stdout, 0);
1934
1935 skelout (); /* %% [8.0] - break point in skel */
1936
1937 set_indent (2);
1938
1939 if (yymore_used && !yytext_is_array) {
1940 indent_puts ("YY_G(yy_more_len) = 0;");
1941 indent_puts ("if ( YY_G(yy_more_flag) )");
1942 ++indent_level;
1943 indent_puts ("{");
1944 indent_puts
1945 ("YY_G(yy_more_len) = (int) (YY_G(yy_c_buf_p) - YY_G(yytext_ptr));");
1946 indent_puts ("YY_G(yy_more_flag) = 0;");
1947 indent_puts ("}");
1948 --indent_level;
1949 }
1950
1951 skelout (); /* %% [9.0] - break point in skel */
1952
1953 gen_start_state ();
1954
1955 /* Note, don't use any indentation. */
1956 outn ("yy_match:");
1957 gen_next_match ();
1958
1959 skelout (); /* %% [10.0] - break point in skel */
1960 set_indent (2);
1961 gen_find_action ();
1962
1963 skelout (); /* %% [11.0] - break point in skel */
1964 outn ("m4_ifdef( [[M4_YY_USE_LINENO]],[[");
1965 indent_puts
1966 ("if ( yy_act != YY_END_OF_BUFFER && yy_rule_can_match_eol[yy_act] )");
1967 ++indent_level;
1968 indent_puts ("{");
1969 indent_puts ("yy_size_t yyl;");
1970 do_indent ();
1971 out_str ("for ( yyl = %s; yyl < yyleng; ++yyl )\n",
1972 yymore_used ? (yytext_is_array ? "YY_G(yy_prev_more_offset)" :
1973 "YY_G(yy_more_len)") : "0");
1974 ++indent_level;
1975 indent_puts ("if ( yytext[yyl] == '\\n' )");
1976 ++indent_level;
1977 indent_puts ("M4_YY_INCR_LINENO();");
1978 --indent_level;
1979 --indent_level;
1980 indent_puts ("}");
1981 --indent_level;
1982 outn ("]])");
1983
1984 skelout (); /* %% [12.0] - break point in skel */
1985 if (ddebug) {
1986 indent_puts ("if ( yy_flex_debug )");
1987 ++indent_level;
1988
1989 indent_puts ("{");
1990 indent_puts ("if ( yy_act == 0 )");
1991 ++indent_level;
1992 indent_puts (C_plus_plus ?
1993 "std::cerr << \"--scanner backing up\\n\";" :
1994 "fprintf( stderr, \"--scanner backing up\\n\" );");
1995 --indent_level;
1996
1997 do_indent ();
1998 out_dec ("else if ( yy_act < %d )\n", num_rules);
1999 ++indent_level;
2000
2001 if (C_plus_plus) {
2002 indent_puts
2003 ("std::cerr << \"--accepting rule at line \" << yy_rule_linenum[yy_act] <<");
2004 indent_puts
2005 (" \"(\\\"\" << yytext << \"\\\")\\n\";");
2006 }
2007 else {
2008 indent_puts
2009 ("fprintf( stderr, \"--accepting rule at line %ld (\\\"%s\\\")\\n\",");
2010
2011 indent_puts
2012 (" (long)yy_rule_linenum[yy_act], yytext );");
2013 }
2014
2015 --indent_level;
2016
2017 do_indent ();
2018 out_dec ("else if ( yy_act == %d )\n", num_rules);
2019 ++indent_level;
2020
2021 if (C_plus_plus) {
2022 indent_puts
2023 ("std::cerr << \"--accepting default rule (\\\"\" << yytext << \"\\\")\\n\";");
2024 }
2025 else {
2026 indent_puts
2027 ("fprintf( stderr, \"--accepting default rule (\\\"%s\\\")\\n\",");
2028 indent_puts (" yytext );");
2029 }
2030
2031 --indent_level;
2032
2033 do_indent ();
2034 out_dec ("else if ( yy_act == %d )\n", num_rules + 1);
2035 ++indent_level;
2036
2037 indent_puts (C_plus_plus ?
2038 "std::cerr << \"--(end of buffer or a NUL)\\n\";" :
2039 "fprintf( stderr, \"--(end of buffer or a NUL)\\n\" );");
2040
2041 --indent_level;
2042
2043 do_indent ();
2044 outn ("else");
2045 ++indent_level;
2046
2047 if (C_plus_plus) {
2048 indent_puts
2049 ("std::cerr << \"--EOF (start condition \" << YY_START << \")\\n\";");
2050 }
2051 else {
2052 indent_puts
2053 ("fprintf( stderr, \"--EOF (start condition %d)\\n\", YY_START );");
2054 }
2055
2056 --indent_level;
2057
2058 indent_puts ("}");
2059 --indent_level;
2060 }
2061
2062 /* Copy actions to output file. */
2063 skelout (); /* %% [13.0] - break point in skel */
2064 ++indent_level;
2065 gen_bu_action ();
2066 out (&action_array[action_offset]);
2067
2068 line_directive_out (stdout, 0);
2069
2070 /* generate cases for any missing EOF rules */
2071 for (i = 1; i <= lastsc; ++i)
2072 if (!sceof[i]) {
2073 do_indent ();
2074 out_str ("case YY_STATE_EOF(%s):\n", scname[i]);
2075 did_eof_rule = true;
2076 }
2077
2078 if (did_eof_rule) {
2079 ++indent_level;
2080 indent_puts ("yyterminate();");
2081 --indent_level;
2082 }
2083
2084
2085 /* Generate code for handling NUL's, if needed. */
2086
2087 /* First, deal with backing up and setting up yy_cp if the scanner
2088 * finds that it should JAM on the NUL.
2089 */
2090 skelout (); /* %% [14.0] - break point in skel */
2091 set_indent (4);
2092
2093 if (fullspd || fulltbl)
2094 indent_puts ("yy_cp = YY_G(yy_c_buf_p);");
2095
2096 else { /* compressed table */
2097 if (!reject && !interactive) {
2098 /* Do the guaranteed-needed backing up to figure
2099 * out the match.
2100 */
2101 indent_puts
2102 ("yy_cp = YY_G(yy_last_accepting_cpos);");
2103 indent_puts
2104 ("yy_current_state = YY_G(yy_last_accepting_state);");
2105 }
2106
2107 else
2108 /* Still need to initialize yy_cp, though
2109 * yy_current_state was set up by
2110 * yy_get_previous_state().
2111 */
2112 indent_puts ("yy_cp = YY_G(yy_c_buf_p);");
2113 }
2114
2115
2116 /* Generate code for yy_get_previous_state(). */
2117 set_indent (1);
2118 skelout (); /* %% [15.0] - break point in skel */
2119
2120 gen_start_state ();
2121
2122 set_indent (2);
2123 skelout (); /* %% [16.0] - break point in skel */
2124 gen_next_state (true);
2125
2126 set_indent (1);
2127 skelout (); /* %% [17.0] - break point in skel */
2128 gen_NUL_trans ();
2129
2130 skelout (); /* %% [18.0] - break point in skel */
2131 skelout (); /* %% [19.0] - break point in skel */
2132 /* Update BOL and yylineno inside of input(). */
2133 if (bol_needed) {
2134 indent_puts
2135 ("YY_CURRENT_BUFFER_LVALUE->yy_at_bol = (c == '\\n');");
2136 if (do_yylineno) {
2137 indent_puts
2138 ("if ( YY_CURRENT_BUFFER_LVALUE->yy_at_bol )");
2139 ++indent_level;
2140 indent_puts ("M4_YY_INCR_LINENO();");
2141 --indent_level;
2142 }
2143 }
2144
2145 else if (do_yylineno) {
2146 indent_puts ("if ( c == '\\n' )");
2147 ++indent_level;
2148 indent_puts ("M4_YY_INCR_LINENO();");
2149 --indent_level;
2150 }
2151
2152 skelout ();
2153
2154 /* Copy remainder of input to output. */
2155
2156 line_directive_out (stdout, 1);
2157
2158 if (sectnum == 3) {
2159 OUT_BEGIN_CODE ();
2160 if (!no_section3_escape)
2161 fputs("[[", stdout);
2162 (void) flexscan (); /* copy remainder of input to output */
2163 if (!no_section3_escape)
2164 fputs("]]", stdout);
2165 OUT_END_CODE ();
2166 }
2167 }
2168