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