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