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