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