Annotation of src/usr.bin/lex/gen.c, Revision 1.10
1.10 ! millert 1: /* $OpenBSD: gen.c,v 1.9 2002/05/31 22:49:29 deraadt Exp $ */
1.2 deraadt 2:
1.1 deraadt 3: /* gen - actual generation (writing) of flex scanners */
4:
5: /*-
6: * Copyright (c) 1990 The Regents of the University of California.
7: * All rights reserved.
8: *
9: * This code is derived from software contributed to Berkeley by
10: * Vern Paxson.
11: *
12: * The United States Government has rights in this work pursuant
13: * to contract no. DE-AC03-76SF00098 between the United States
14: * Department of Energy and the University of California.
15: *
1.5 deraadt 16: * Redistribution and use in source and binary forms, with or without
1.10 ! millert 17: * modification, are permitted provided that the following conditions
! 18: * are met:
! 19: *
! 20: * 1. Redistributions of source code must retain the above copyright
! 21: * notice, this list of conditions and the following disclaimer.
! 22: * 2. Redistributions in binary form must reproduce the above copyright
! 23: * notice, this list of conditions and the following disclaimer in the
! 24: * documentation and/or other materials provided with the distribution.
! 25: *
! 26: * Neither the name of the University nor the names of its contributors
! 27: * may be used to endorse or promote products derived from this software
! 28: * without specific prior written permission.
! 29: *
! 30: * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
! 31: * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
! 32: * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
! 33: * PURPOSE.
1.1 deraadt 34: */
35:
1.10 ! millert 36: /* $Header: /cvs/src/usr.bin/lex/gen.c,v 1.9 2002/05/31 22:49:29 deraadt Exp $ */
1.1 deraadt 37:
38: #include "flexdef.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((char [], char []));
46: void indent_puts PROTO((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: static char C_int_decl[] = "static yyconst int %s[%d] =\n { 0,\n";
61: static char C_short_decl[] = "static yyconst short int %s[%d] =\n { 0,\n";
62: static char C_long_decl[] = "static yyconst long int %s[%d] =\n { 0,\n";
63: static char C_state_decl[] =
64: "static yyconst yy_state_type %s[%d] =\n { 0,\n";
65:
66:
67: /* Indent to the current level. */
68:
69: void do_indent()
70: {
1.6 mpech 71: int i = indent_level * 8;
1.1 deraadt 72:
73: while ( i >= 8 )
74: {
75: outc( '\t' );
76: i -= 8;
77: }
78:
79: while ( i > 0 )
80: {
81: outc( ' ' );
82: --i;
83: }
84: }
85:
86:
87: /* Generate the code to keep backing-up information. */
88:
89: void gen_backing_up()
90: {
91: if ( reject || num_backing_up == 0 )
92: return;
93:
94: if ( fullspd )
95: indent_puts( "if ( yy_current_state[-1].yy_nxt )" );
96: else
97: indent_puts( "if ( yy_accept[yy_current_state] )" );
98:
99: indent_up();
100: indent_puts( "{" );
101: indent_puts( "yy_last_accepting_state = yy_current_state;" );
102: indent_puts( "yy_last_accepting_cpos = yy_cp;" );
103: indent_puts( "}" );
104: indent_down();
105: }
106:
107:
108: /* Generate the code to perform the backing up. */
109:
110: void gen_bu_action()
111: {
112: if ( reject || num_backing_up == 0 )
113: return;
114:
115: set_indent( 3 );
116:
117: indent_puts( "case 0: /* must back up */" );
118: indent_puts( "/* undo the effects of YY_DO_BEFORE_ACTION */" );
119: indent_puts( "*yy_cp = yy_hold_char;" );
120:
121: if ( fullspd || fulltbl )
122: indent_puts( "yy_cp = yy_last_accepting_cpos + 1;" );
123: else
124: /* Backing-up info for compressed tables is taken \after/
125: * yy_cp has been incremented for the next state.
126: */
127: indent_puts( "yy_cp = yy_last_accepting_cpos;" );
128:
129: indent_puts( "yy_current_state = yy_last_accepting_state;" );
130: indent_puts( "goto yy_find_action;" );
131: outc( '\n' );
132:
133: set_indent( 0 );
134: }
135:
136:
137: /* genctbl - generates full speed compressed transition table */
138:
139: void genctbl()
140: {
1.6 mpech 141: int i;
1.1 deraadt 142: int end_of_buffer_action = num_rules + 1;
143:
144: /* Table of verify for transition and offset to next state. */
145: out_dec( "static yyconst struct yy_trans_info yy_transition[%d] =\n",
146: tblend + numecs + 1 );
147: outn( " {" );
148:
149: /* We want the transition to be represented as the offset to the
150: * next state, not the actual state number, which is what it currently
151: * is. The offset is base[nxt[i]] - (base of current state)]. That's
152: * just the difference between the starting points of the two involved
153: * states (to - from).
154: *
155: * First, though, we need to find some way to put in our end-of-buffer
156: * flags and states. We do this by making a state with absolutely no
157: * transitions. We put it at the end of the table.
158: */
159:
160: /* We need to have room in nxt/chk for two more slots: One for the
161: * action and one for the end-of-buffer transition. We now *assume*
162: * that we're guaranteed the only character we'll try to index this
163: * nxt/chk pair with is EOB, i.e., 0, so we don't have to make sure
164: * there's room for jam entries for other characters.
165: */
166:
167: while ( tblend + 2 >= current_max_xpairs )
168: expand_nxt_chk();
169:
170: while ( lastdfa + 1 >= current_max_dfas )
171: increase_max_dfas();
172:
173: base[lastdfa + 1] = tblend + 2;
174: nxt[tblend + 1] = end_of_buffer_action;
175: chk[tblend + 1] = numecs + 1;
176: chk[tblend + 2] = 1; /* anything but EOB */
177:
178: /* So that "make test" won't show arb. differences. */
179: nxt[tblend + 2] = 0;
180:
181: /* Make sure every state has an end-of-buffer transition and an
182: * action #.
183: */
184: for ( i = 0; i <= lastdfa; ++i )
185: {
186: int anum = dfaacc[i].dfaacc_state;
187: int offset = base[i];
188:
189: chk[offset] = EOB_POSITION;
190: chk[offset - 1] = ACTION_POSITION;
191: nxt[offset - 1] = anum; /* action number */
192: }
193:
194: for ( i = 0; i <= tblend; ++i )
195: {
196: if ( chk[i] == EOB_POSITION )
197: transition_struct_out( 0, base[lastdfa + 1] - i );
198:
199: else if ( chk[i] == ACTION_POSITION )
200: transition_struct_out( 0, nxt[i] );
201:
202: else if ( chk[i] > numecs || chk[i] == 0 )
203: transition_struct_out( 0, 0 ); /* unused slot */
204:
205: else /* verify, transition */
206: transition_struct_out( chk[i],
207: base[nxt[i]] - (i - chk[i]) );
208: }
209:
210:
211: /* Here's the final, end-of-buffer state. */
212: transition_struct_out( chk[tblend + 1], nxt[tblend + 1] );
213: transition_struct_out( chk[tblend + 2], nxt[tblend + 2] );
214:
215: outn( " };\n" );
216:
217: /* Table of pointers to start states. */
218: out_dec(
219: "static yyconst struct yy_trans_info *yy_start_state_list[%d] =\n",
220: lastsc * 2 + 1 );
221: outn( " {" ); /* } so vi doesn't get confused */
222:
223: for ( i = 0; i <= lastsc * 2; ++i )
224: out_dec( " &yy_transition[%d],\n", base[i] );
225:
226: dataend();
227:
228: if ( useecs )
229: genecs();
230: }
231:
232:
233: /* Generate equivalence-class tables. */
234:
235: void genecs()
236: {
1.6 mpech 237: int i, j;
1.1 deraadt 238: int numrows;
239:
240: out_str_dec( C_int_decl, "yy_ec", csize );
241:
242: for ( i = 1; i < csize; ++i )
243: {
244: if ( caseins && (i >= 'A') && (i <= 'Z') )
245: ecgroup[i] = ecgroup[clower( i )];
246:
247: ecgroup[i] = ABS( ecgroup[i] );
248: mkdata( ecgroup[i] );
249: }
250:
251: dataend();
252:
253: if ( trace )
254: {
255: fputs( _( "\n\nEquivalence Classes:\n\n" ), stderr );
256:
257: numrows = csize / 8;
258:
259: for ( j = 0; j < numrows; ++j )
260: {
261: for ( i = j; i < csize; i = i + numrows )
262: {
263: fprintf( stderr, "%4s = %-2d",
264: readable_form( i ), ecgroup[i] );
265:
266: putc( ' ', stderr );
267: }
268:
269: putc( '\n', stderr );
270: }
271: }
272: }
273:
274:
275: /* Generate the code to find the action number. */
276:
277: void gen_find_action()
278: {
279: if ( fullspd )
280: indent_puts( "yy_act = yy_current_state[-1].yy_nxt;" );
281:
282: else if ( fulltbl )
283: indent_puts( "yy_act = yy_accept[yy_current_state];" );
284:
285: else if ( reject )
286: {
287: indent_puts( "yy_current_state = *--yy_state_ptr;" );
288: indent_puts( "yy_lp = yy_accept[yy_current_state];" );
289:
290: outn(
291: "find_rule: /* we branch to this label when backing up */" );
292:
293: indent_puts(
294: "for ( ; ; ) /* until we find what rule we matched */" );
295:
296: indent_up();
297:
298: indent_puts( "{" );
299:
300: indent_puts(
301: "if ( yy_lp && yy_lp < yy_accept[yy_current_state + 1] )" );
302: indent_up();
303: indent_puts( "{" );
304: indent_puts( "yy_act = yy_acclist[yy_lp];" );
305:
306: if ( variable_trailing_context_rules )
307: {
308: indent_puts( "if ( yy_act & YY_TRAILING_HEAD_MASK ||" );
309: indent_puts( " yy_looking_for_trail_begin )" );
310: indent_up();
311: indent_puts( "{" );
312:
313: indent_puts(
314: "if ( yy_act == yy_looking_for_trail_begin )" );
315: indent_up();
316: indent_puts( "{" );
317: indent_puts( "yy_looking_for_trail_begin = 0;" );
318: indent_puts( "yy_act &= ~YY_TRAILING_HEAD_MASK;" );
319: indent_puts( "break;" );
320: indent_puts( "}" );
321: indent_down();
322:
323: indent_puts( "}" );
324: indent_down();
325:
326: indent_puts( "else if ( yy_act & YY_TRAILING_MASK )" );
327: indent_up();
328: indent_puts( "{" );
329: indent_puts(
330: "yy_looking_for_trail_begin = yy_act & ~YY_TRAILING_MASK;" );
331: indent_puts(
332: "yy_looking_for_trail_begin |= YY_TRAILING_HEAD_MASK;" );
333:
334: if ( real_reject )
335: {
336: /* Remember matched text in case we back up
337: * due to REJECT.
338: */
339: indent_puts( "yy_full_match = yy_cp;" );
340: indent_puts( "yy_full_state = yy_state_ptr;" );
341: indent_puts( "yy_full_lp = yy_lp;" );
342: }
343:
344: indent_puts( "}" );
345: indent_down();
346:
347: indent_puts( "else" );
348: indent_up();
349: indent_puts( "{" );
350: indent_puts( "yy_full_match = yy_cp;" );
351: indent_puts( "yy_full_state = yy_state_ptr;" );
352: indent_puts( "yy_full_lp = yy_lp;" );
353: indent_puts( "break;" );
354: indent_puts( "}" );
355: indent_down();
356:
357: indent_puts( "++yy_lp;" );
358: indent_puts( "goto find_rule;" );
359: }
360:
361: else
362: {
363: /* Remember matched text in case we back up due to
364: * trailing context plus REJECT.
365: */
366: indent_up();
367: indent_puts( "{" );
368: indent_puts( "yy_full_match = yy_cp;" );
369: indent_puts( "break;" );
370: indent_puts( "}" );
371: indent_down();
372: }
373:
374: indent_puts( "}" );
375: indent_down();
376:
377: indent_puts( "--yy_cp;" );
378:
379: /* We could consolidate the following two lines with those at
380: * the beginning, but at the cost of complaints that we're
381: * branching inside a loop.
382: */
383: indent_puts( "yy_current_state = *--yy_state_ptr;" );
384: indent_puts( "yy_lp = yy_accept[yy_current_state];" );
385:
386: indent_puts( "}" );
387:
388: indent_down();
389: }
390:
391: else
392: { /* compressed */
393: indent_puts( "yy_act = yy_accept[yy_current_state];" );
394:
395: if ( interactive && ! reject )
396: {
397: /* Do the guaranteed-needed backing up to figure out
398: * the match.
399: */
400: indent_puts( "if ( yy_act == 0 )" );
401: indent_up();
402: indent_puts( "{ /* have to back up */" );
403: indent_puts( "yy_cp = yy_last_accepting_cpos;" );
404: indent_puts(
405: "yy_current_state = yy_last_accepting_state;" );
406: indent_puts( "yy_act = yy_accept[yy_current_state];" );
407: indent_puts( "}" );
408: indent_down();
409: }
410: }
411: }
412:
413:
414: /* genftbl - generate full transition table */
415:
416: void genftbl()
417: {
1.6 mpech 418: int i;
1.1 deraadt 419: int end_of_buffer_action = num_rules + 1;
420:
421: out_str_dec( long_align ? C_long_decl : C_short_decl,
422: "yy_accept", lastdfa + 1 );
423:
424: dfaacc[end_of_buffer_state].dfaacc_state = end_of_buffer_action;
425:
426: for ( i = 1; i <= lastdfa; ++i )
427: {
1.6 mpech 428: int anum = dfaacc[i].dfaacc_state;
1.1 deraadt 429:
430: mkdata( anum );
431:
432: if ( trace && anum )
433: fprintf( stderr, _( "state # %d accepts: [%d]\n" ),
434: i, anum );
435: }
436:
437: dataend();
438:
439: if ( useecs )
440: genecs();
441:
442: /* Don't have to dump the actual full table entries - they were
443: * created on-the-fly.
444: */
445: }
446:
447:
448: /* Generate the code to find the next compressed-table state. */
449:
450: void gen_next_compressed_state( char_map )
451: char *char_map;
452: {
453: indent_put2s( "register YY_CHAR yy_c = %s;", char_map );
454:
455: /* Save the backing-up info \before/ computing the next state
456: * because we always compute one more state than needed - we
457: * always proceed until we reach a jam state
458: */
459: gen_backing_up();
460:
461: indent_puts(
462: "while ( yy_chk[yy_base[yy_current_state] + yy_c] != yy_current_state )" );
463: indent_up();
464: indent_puts( "{" );
465: indent_puts( "yy_current_state = (int) yy_def[yy_current_state];" );
466:
467: if ( usemecs )
468: {
469: /* We've arrange it so that templates are never chained
470: * to one another. This means we can afford to make a
471: * very simple test to see if we need to convert to
472: * yy_c's meta-equivalence class without worrying
473: * about erroneously looking up the meta-equivalence
474: * class twice
475: */
476: do_indent();
477:
478: /* lastdfa + 2 is the beginning of the templates */
479: out_dec( "if ( yy_current_state >= %d )\n", lastdfa + 2 );
480:
481: indent_up();
482: indent_puts( "yy_c = yy_meta[(unsigned int) yy_c];" );
483: indent_down();
484: }
485:
486: indent_puts( "}" );
487: indent_down();
488:
489: indent_puts(
490: "yy_current_state = yy_nxt[yy_base[yy_current_state] + (unsigned int) yy_c];" );
491: }
492:
493:
494: /* Generate the code to find the next match. */
495:
496: void gen_next_match()
497: {
498: /* NOTE - changes in here should be reflected in gen_next_state() and
499: * gen_NUL_trans().
500: */
501: char *char_map = useecs ?
502: "yy_ec[YY_SC_TO_UI(*yy_cp)]" :
503: "YY_SC_TO_UI(*yy_cp)";
504:
505: char *char_map_2 = useecs ?
506: "yy_ec[YY_SC_TO_UI(*++yy_cp)]" :
507: "YY_SC_TO_UI(*++yy_cp)";
508:
509: if ( fulltbl )
510: {
511: indent_put2s(
512: "while ( (yy_current_state = yy_nxt[yy_current_state][%s]) > 0 )",
513: char_map );
514:
515: indent_up();
516:
517: if ( num_backing_up > 0 )
518: {
519: indent_puts( "{" ); /* } for vi */
520: gen_backing_up();
521: outc( '\n' );
522: }
523:
524: indent_puts( "++yy_cp;" );
525:
526: if ( num_backing_up > 0 )
527: /* { for vi */
528: indent_puts( "}" );
529:
530: indent_down();
531:
532: outc( '\n' );
533: indent_puts( "yy_current_state = -yy_current_state;" );
534: }
535:
536: else if ( fullspd )
537: {
538: indent_puts( "{" ); /* } for vi */
539: indent_puts(
540: "register yyconst struct yy_trans_info *yy_trans_info;\n" );
541: indent_puts( "register YY_CHAR yy_c;\n" );
542: indent_put2s( "for ( yy_c = %s;", char_map );
543: indent_puts(
544: " (yy_trans_info = &yy_current_state[(unsigned int) yy_c])->" );
545: indent_puts( "yy_verify == yy_c;" );
546: indent_put2s( " yy_c = %s )", char_map_2 );
547:
548: indent_up();
549:
550: if ( num_backing_up > 0 )
551: indent_puts( "{" ); /* } for vi */
552:
553: indent_puts( "yy_current_state += yy_trans_info->yy_nxt;" );
554:
555: if ( num_backing_up > 0 )
556: {
557: outc( '\n' );
558: gen_backing_up(); /* { for vi */
559: indent_puts( "}" );
560: }
561:
562: indent_down(); /* { for vi */
563: indent_puts( "}" );
564: }
565:
566: else
567: { /* compressed */
568: indent_puts( "do" );
569:
570: indent_up();
571: indent_puts( "{" ); /* } for vi */
572:
573: gen_next_state( false );
574:
575: indent_puts( "++yy_cp;" );
576:
577: /* { for vi */
578: indent_puts( "}" );
579: indent_down();
580:
581: do_indent();
582:
583: if ( interactive )
584: out_dec( "while ( yy_base[yy_current_state] != %d );\n",
585: jambase );
586: else
587: out_dec( "while ( yy_current_state != %d );\n",
588: jamstate );
589:
590: if ( ! reject && ! interactive )
591: {
592: /* Do the guaranteed-needed backing up to figure out
593: * the match.
594: */
595: indent_puts( "yy_cp = yy_last_accepting_cpos;" );
596: indent_puts(
597: "yy_current_state = yy_last_accepting_state;" );
598: }
599: }
600: }
601:
602:
603: /* Generate the code to find the next state. */
604:
605: void gen_next_state( worry_about_NULs )
606: int worry_about_NULs;
607: { /* NOTE - changes in here should be reflected in gen_next_match() */
608: char char_map[256];
609:
610: if ( worry_about_NULs && ! nultrans )
611: {
612: if ( useecs )
1.9 deraadt 613: (void) snprintf( char_map, sizeof char_map,
1.1 deraadt 614: "(*yy_cp ? yy_ec[YY_SC_TO_UI(*yy_cp)] : %d)",
615: NUL_ec );
616: else
1.9 deraadt 617: (void) snprintf( char_map, sizeof char_map,
1.1 deraadt 618: "(*yy_cp ? YY_SC_TO_UI(*yy_cp) : %d)", NUL_ec );
619: }
620:
621: else
1.9 deraadt 622: strlcpy( char_map, useecs ?
623: "yy_ec[YY_SC_TO_UI(*yy_cp)]" : "YY_SC_TO_UI(*yy_cp)",
624: sizeof char_map );
1.1 deraadt 625:
626: if ( worry_about_NULs && nultrans )
627: {
628: if ( ! fulltbl && ! fullspd )
629: /* Compressed tables back up *before* they match. */
630: gen_backing_up();
631:
632: indent_puts( "if ( *yy_cp )" );
633: indent_up();
634: indent_puts( "{" ); /* } for vi */
635: }
636:
637: if ( fulltbl )
638: indent_put2s(
639: "yy_current_state = yy_nxt[yy_current_state][%s];",
640: char_map );
641:
642: else if ( fullspd )
643: indent_put2s(
644: "yy_current_state += yy_current_state[%s].yy_nxt;",
645: char_map );
646:
647: else
648: gen_next_compressed_state( char_map );
649:
650: if ( worry_about_NULs && nultrans )
651: {
652: /* { for vi */
653: indent_puts( "}" );
654: indent_down();
655: indent_puts( "else" );
656: indent_up();
657: indent_puts(
658: "yy_current_state = yy_NUL_trans[yy_current_state];" );
659: indent_down();
660: }
661:
662: if ( fullspd || fulltbl )
663: gen_backing_up();
664:
665: if ( reject )
666: indent_puts( "*yy_state_ptr++ = yy_current_state;" );
667: }
668:
669:
670: /* Generate the code to make a NUL transition. */
671:
672: void gen_NUL_trans()
673: { /* NOTE - changes in here should be reflected in gen_next_match() */
674: /* Only generate a definition for "yy_cp" if we'll generate code
675: * that uses it. Otherwise lint and the like complain.
676: */
677: int need_backing_up = (num_backing_up > 0 && ! reject);
678:
679: if ( need_backing_up && (! nultrans || fullspd || fulltbl) )
680: /* We're going to need yy_cp lying around for the call
681: * below to gen_backing_up().
682: */
683: indent_puts( "register char *yy_cp = yy_c_buf_p;" );
684:
685: outc( '\n' );
686:
687: if ( nultrans )
688: {
689: indent_puts(
690: "yy_current_state = yy_NUL_trans[yy_current_state];" );
691: indent_puts( "yy_is_jam = (yy_current_state == 0);" );
692: }
693:
694: else if ( fulltbl )
695: {
696: do_indent();
697: out_dec( "yy_current_state = yy_nxt[yy_current_state][%d];\n",
698: NUL_ec );
699: indent_puts( "yy_is_jam = (yy_current_state <= 0);" );
700: }
701:
702: else if ( fullspd )
703: {
704: do_indent();
705: out_dec( "register int yy_c = %d;\n", NUL_ec );
706:
707: indent_puts(
708: "register yyconst struct yy_trans_info *yy_trans_info;\n" );
709: indent_puts(
710: "yy_trans_info = &yy_current_state[(unsigned int) yy_c];" );
711: indent_puts( "yy_current_state += yy_trans_info->yy_nxt;" );
712:
713: indent_puts(
714: "yy_is_jam = (yy_trans_info->yy_verify != yy_c);" );
715: }
716:
717: else
718: {
719: char NUL_ec_str[20];
720:
1.9 deraadt 721: (void) snprintf( NUL_ec_str, sizeof NUL_ec_str, "%d", NUL_ec );
1.1 deraadt 722: gen_next_compressed_state( NUL_ec_str );
723:
1.3 millert 724: do_indent();
725: out_dec( "yy_is_jam = (yy_current_state == %d);\n", jamstate );
726:
1.1 deraadt 727: if ( reject )
1.3 millert 728: {
729: /* Only stack this state if it's a transition we
730: * actually make. If we stack it on a jam, then
731: * the state stack and yy_c_buf_p get out of sync.
732: */
733: indent_puts( "if ( ! yy_is_jam )" );
734: indent_up();
1.1 deraadt 735: indent_puts( "*yy_state_ptr++ = yy_current_state;" );
1.3 millert 736: indent_down();
737: }
1.1 deraadt 738: }
739:
740: /* If we've entered an accepting state, back up; note that
741: * compressed tables have *already* done such backing up, so
742: * we needn't bother with it again.
743: */
744: if ( need_backing_up && (fullspd || fulltbl) )
745: {
746: outc( '\n' );
747: indent_puts( "if ( ! yy_is_jam )" );
748: indent_up();
749: indent_puts( "{" );
750: gen_backing_up();
751: indent_puts( "}" );
752: indent_down();
753: }
754: }
755:
756:
757: /* Generate the code to find the start state. */
758:
759: void gen_start_state()
760: {
761: if ( fullspd )
762: {
763: if ( bol_needed )
764: {
765: indent_puts(
766: "yy_current_state = yy_start_state_list[yy_start + YY_AT_BOL()];" );
767: }
768: else
769: indent_puts(
770: "yy_current_state = yy_start_state_list[yy_start];" );
771: }
772:
773: else
774: {
775: indent_puts( "yy_current_state = yy_start;" );
776:
777: if ( bol_needed )
778: indent_puts( "yy_current_state += YY_AT_BOL();" );
779:
780: if ( reject )
781: {
782: /* Set up for storing up states. */
783: indent_puts( "yy_state_ptr = yy_state_buf;" );
784: indent_puts( "*yy_state_ptr++ = yy_current_state;" );
785: }
786: }
787: }
788:
789:
790: /* gentabs - generate data statements for the transition tables */
791:
792: void gentabs()
793: {
794: int i, j, k, *accset, nacc, *acc_array, total_states;
795: int end_of_buffer_action = num_rules + 1;
796:
797: acc_array = allocate_integer_array( current_max_dfas );
798: nummt = 0;
799:
800: /* The compressed table format jams by entering the "jam state",
801: * losing information about the previous state in the process.
802: * In order to recover the previous state, we effectively need
803: * to keep backing-up information.
804: */
805: ++num_backing_up;
806:
807: if ( reject )
808: {
809: /* Write out accepting list and pointer list.
810: *
811: * First we generate the "yy_acclist" array. In the process,
812: * we compute the indices that will go into the "yy_accept"
813: * array, and save the indices in the dfaacc array.
814: */
815: int EOB_accepting_list[2];
816:
817: /* Set up accepting structures for the End Of Buffer state. */
818: EOB_accepting_list[0] = 0;
819: EOB_accepting_list[1] = end_of_buffer_action;
820: accsiz[end_of_buffer_state] = 1;
821: dfaacc[end_of_buffer_state].dfaacc_set = EOB_accepting_list;
822:
823: out_str_dec( long_align ? C_long_decl : C_short_decl,
824: "yy_acclist", MAX( numas, 1 ) + 1 );
825:
826: j = 1; /* index into "yy_acclist" array */
827:
828: for ( i = 1; i <= lastdfa; ++i )
829: {
830: acc_array[i] = j;
831:
832: if ( accsiz[i] != 0 )
833: {
834: accset = dfaacc[i].dfaacc_set;
835: nacc = accsiz[i];
836:
837: if ( trace )
838: fprintf( stderr,
839: _( "state # %d accepts: " ),
840: i );
841:
842: for ( k = 1; k <= nacc; ++k )
843: {
844: int accnum = accset[k];
845:
846: ++j;
847:
848: if ( variable_trailing_context_rules &&
849: ! (accnum & YY_TRAILING_HEAD_MASK) &&
850: accnum > 0 && accnum <= num_rules &&
851: rule_type[accnum] == RULE_VARIABLE )
852: {
853: /* Special hack to flag
854: * accepting number as part
855: * of trailing context rule.
856: */
857: accnum |= YY_TRAILING_MASK;
858: }
859:
860: mkdata( accnum );
861:
862: if ( trace )
863: {
864: fprintf( stderr, "[%d]",
865: accset[k] );
866:
867: if ( k < nacc )
868: fputs( ", ", stderr );
869: else
870: putc( '\n', stderr );
871: }
872: }
873: }
874: }
875:
876: /* add accepting number for the "jam" state */
877: acc_array[i] = j;
878:
879: dataend();
880: }
881:
882: else
883: {
884: dfaacc[end_of_buffer_state].dfaacc_state = end_of_buffer_action;
885:
886: for ( i = 1; i <= lastdfa; ++i )
887: acc_array[i] = dfaacc[i].dfaacc_state;
888:
889: /* add accepting number for jam state */
890: acc_array[i] = 0;
891: }
892:
893: /* Spit out "yy_accept" array. If we're doing "reject", it'll be
894: * pointers into the "yy_acclist" array. Otherwise it's actual
895: * accepting numbers. In either case, we just dump the numbers.
896: */
897:
898: /* "lastdfa + 2" is the size of "yy_accept"; includes room for C arrays
899: * beginning at 0 and for "jam" state.
900: */
901: k = lastdfa + 2;
902:
903: if ( reject )
904: /* We put a "cap" on the table associating lists of accepting
905: * numbers with state numbers. This is needed because we tell
906: * where the end of an accepting list is by looking at where
907: * the list for the next state starts.
908: */
909: ++k;
910:
911: out_str_dec( long_align ? C_long_decl : C_short_decl, "yy_accept", k );
912:
913: for ( i = 1; i <= lastdfa; ++i )
914: {
915: mkdata( acc_array[i] );
916:
917: if ( ! reject && trace && acc_array[i] )
918: fprintf( stderr, _( "state # %d accepts: [%d]\n" ),
919: i, acc_array[i] );
920: }
921:
922: /* Add entry for "jam" state. */
923: mkdata( acc_array[i] );
924:
925: if ( reject )
926: /* Add "cap" for the list. */
927: mkdata( acc_array[i] );
928:
929: dataend();
930:
931: if ( useecs )
932: genecs();
933:
934: if ( usemecs )
935: {
936: /* Write out meta-equivalence classes (used to index
937: * templates with).
938: */
939:
940: if ( trace )
941: fputs( _( "\n\nMeta-Equivalence Classes:\n" ),
942: stderr );
943:
944: out_str_dec( C_int_decl, "yy_meta", numecs + 1 );
945:
946: for ( i = 1; i <= numecs; ++i )
947: {
948: if ( trace )
949: fprintf( stderr, "%d = %d\n",
950: i, ABS( tecbck[i] ) );
951:
952: mkdata( ABS( tecbck[i] ) );
953: }
954:
955: dataend();
956: }
957:
958: total_states = lastdfa + numtemps;
959:
960: out_str_dec( (tblend >= MAX_SHORT || long_align) ?
961: C_long_decl : C_short_decl,
962: "yy_base", total_states + 1 );
963:
964: for ( i = 1; i <= lastdfa; ++i )
965: {
1.6 mpech 966: int d = def[i];
1.1 deraadt 967:
968: if ( base[i] == JAMSTATE )
969: base[i] = jambase;
970:
971: if ( d == JAMSTATE )
972: def[i] = jamstate;
973:
974: else if ( d < 0 )
975: {
976: /* Template reference. */
977: ++tmpuses;
978: def[i] = lastdfa - d + 1;
979: }
980:
981: mkdata( base[i] );
982: }
983:
984: /* Generate jam state's base index. */
985: mkdata( base[i] );
986:
987: for ( ++i /* skip jam state */; i <= total_states; ++i )
988: {
989: mkdata( base[i] );
990: def[i] = jamstate;
991: }
992:
993: dataend();
994:
995: out_str_dec( (total_states >= MAX_SHORT || long_align) ?
996: C_long_decl : C_short_decl,
997: "yy_def", total_states + 1 );
998:
999: for ( i = 1; i <= total_states; ++i )
1000: mkdata( def[i] );
1001:
1002: dataend();
1003:
1004: out_str_dec( (total_states >= MAX_SHORT || long_align) ?
1005: C_long_decl : C_short_decl,
1006: "yy_nxt", tblend + 1 );
1007:
1008: for ( i = 1; i <= tblend; ++i )
1009: {
1010: /* Note, the order of the following test is important.
1011: * If chk[i] is 0, then nxt[i] is undefined.
1012: */
1013: if ( chk[i] == 0 || nxt[i] == 0 )
1014: nxt[i] = jamstate; /* new state is the JAM state */
1015:
1016: mkdata( nxt[i] );
1017: }
1018:
1019: dataend();
1020:
1021: out_str_dec( (total_states >= MAX_SHORT || long_align) ?
1022: C_long_decl : C_short_decl,
1023: "yy_chk", tblend + 1 );
1024:
1025: for ( i = 1; i <= tblend; ++i )
1026: {
1027: if ( chk[i] == 0 )
1028: ++nummt;
1029:
1030: mkdata( chk[i] );
1031: }
1032:
1033: dataend();
1.4 deraadt 1034: free(acc_array);
1.1 deraadt 1035: }
1036:
1037:
1038: /* Write out a formatted string (with a secondary string argument) at the
1039: * current indentation level, adding a final newline.
1040: */
1041:
1042: void indent_put2s( fmt, arg )
1043: char fmt[], arg[];
1044: {
1045: do_indent();
1046: out_str( fmt, arg );
1047: outn( "" );
1048: }
1049:
1050:
1051: /* Write out a string at the current indentation level, adding a final
1052: * newline.
1053: */
1054:
1055: void indent_puts( str )
1056: char str[];
1057: {
1058: do_indent();
1059: outn( str );
1060: }
1061:
1062:
1063: /* make_tables - generate transition tables and finishes generating output file
1064: */
1065:
1066: void make_tables()
1067: {
1.6 mpech 1068: int i;
1.1 deraadt 1069: int did_eof_rule = false;
1070:
1071: skelout();
1072:
1073: /* First, take care of YY_DO_BEFORE_ACTION depending on yymore
1074: * being used.
1075: */
1076: set_indent( 1 );
1077:
1.3 millert 1078: if ( yymore_used && ! yytext_is_array )
1.1 deraadt 1079: {
1080: indent_puts( "yytext_ptr -= yy_more_len; \\" );
1081: indent_puts( "yyleng = (int) (yy_cp - yytext_ptr); \\" );
1082: }
1083:
1084: else
1085: indent_puts( "yyleng = (int) (yy_cp - yy_bp); \\" );
1086:
1087: /* Now also deal with copying yytext_ptr to yytext if needed. */
1088: skelout();
1089: if ( yytext_is_array )
1090: {
1.3 millert 1091: if ( yymore_used )
1092: indent_puts(
1093: "if ( yyleng + yy_more_offset >= YYLMAX ) \\" );
1094: else
1095: indent_puts( "if ( yyleng >= YYLMAX ) \\" );
1096:
1.1 deraadt 1097: indent_up();
1098: indent_puts(
1099: "YY_FATAL_ERROR( \"token too large, exceeds YYLMAX\" ); \\" );
1100: indent_down();
1.3 millert 1101:
1102: if ( yymore_used )
1103: {
1104: indent_puts(
1105: "yy_flex_strncpy( &yytext[yy_more_offset], yytext_ptr, yyleng + 1 ); \\" );
1106: indent_puts( "yyleng += yy_more_offset; \\" );
1107: indent_puts(
1108: "yy_prev_more_offset = yy_more_offset; \\" );
1109: indent_puts( "yy_more_offset = 0; \\" );
1110: }
1111: else
1112: {
1113: indent_puts(
1.1 deraadt 1114: "yy_flex_strncpy( yytext, yytext_ptr, yyleng + 1 ); \\" );
1.3 millert 1115: }
1.1 deraadt 1116: }
1117:
1118: set_indent( 0 );
1119:
1120: skelout();
1121:
1122:
1123: out_dec( "#define YY_NUM_RULES %d\n", num_rules );
1124: out_dec( "#define YY_END_OF_BUFFER %d\n", num_rules + 1 );
1125:
1126: if ( fullspd )
1127: {
1128: /* Need to define the transet type as a size large
1129: * enough to hold the biggest offset.
1130: */
1131: int total_table_size = tblend + numecs + 1;
1132: char *trans_offset_type =
1133: (total_table_size >= MAX_SHORT || long_align) ?
1134: "long" : "short";
1135:
1136: set_indent( 0 );
1137: indent_puts( "struct yy_trans_info" );
1138: indent_up();
1139: indent_puts( "{" ); /* } for vi */
1140:
1141: if ( long_align )
1142: indent_puts( "long yy_verify;" );
1143: else
1144: indent_puts( "short yy_verify;" );
1145:
1146: /* In cases where its sister yy_verify *is* a "yes, there is
1147: * a transition", yy_nxt is the offset (in records) to the
1148: * next state. In most cases where there is no transition,
1149: * the value of yy_nxt is irrelevant. If yy_nxt is the -1th
1150: * record of a state, though, then yy_nxt is the action number
1151: * for that state.
1152: */
1153:
1154: indent_put2s( "%s yy_nxt;", trans_offset_type );
1155: indent_puts( "};" );
1156: indent_down();
1157: }
1158:
1159: if ( fullspd )
1160: genctbl();
1161: else if ( fulltbl )
1162: genftbl();
1163: else
1164: gentabs();
1165:
1166: /* Definitions for backing up. We don't need them if REJECT
1167: * is being used because then we use an alternative backin-up
1168: * technique instead.
1169: */
1170: if ( num_backing_up > 0 && ! reject )
1171: {
1172: if ( ! C_plus_plus )
1173: {
1174: indent_puts(
1175: "static yy_state_type yy_last_accepting_state;" );
1176: indent_puts(
1177: "static char *yy_last_accepting_cpos;\n" );
1178: }
1179: }
1180:
1181: if ( nultrans )
1182: {
1183: out_str_dec( C_state_decl, "yy_NUL_trans", lastdfa + 1 );
1184:
1185: for ( i = 1; i <= lastdfa; ++i )
1186: {
1187: if ( fullspd )
1188: out_dec( " &yy_transition[%d],\n", base[i] );
1189: else
1190: mkdata( nultrans[i] );
1191: }
1192:
1193: dataend();
1194: }
1195:
1196: if ( ddebug )
1197: { /* Spit out table mapping rules to line numbers. */
1198: if ( ! C_plus_plus )
1199: {
1200: indent_puts( "extern int yy_flex_debug;" );
1201: indent_puts( "int yy_flex_debug = 1;\n" );
1202: }
1203:
1204: out_str_dec( long_align ? C_long_decl : C_short_decl,
1205: "yy_rule_linenum", num_rules );
1206: for ( i = 1; i < num_rules; ++i )
1207: mkdata( rule_linenum[i] );
1208: dataend();
1209: }
1210:
1211: if ( reject )
1212: {
1213: /* Declare state buffer variables. */
1214: if ( ! C_plus_plus )
1215: {
1216: outn(
1217: "static yy_state_type yy_state_buf[YY_BUF_SIZE + 2], *yy_state_ptr;" );
1218: outn( "static char *yy_full_match;" );
1219: outn( "static int yy_lp;" );
1220: }
1221:
1222: if ( variable_trailing_context_rules )
1223: {
1224: if ( ! C_plus_plus )
1225: {
1226: outn(
1227: "static int yy_looking_for_trail_begin = 0;" );
1228: outn( "static int yy_full_lp;" );
1229: outn( "static int *yy_full_state;" );
1230: }
1231:
1232: out_hex( "#define YY_TRAILING_MASK 0x%x\n",
1233: (unsigned int) YY_TRAILING_MASK );
1234: out_hex( "#define YY_TRAILING_HEAD_MASK 0x%x\n",
1235: (unsigned int) YY_TRAILING_HEAD_MASK );
1236: }
1237:
1238: outn( "#define REJECT \\" );
1239: outn( "{ \\" ); /* } for vi */
1240: outn(
1241: "*yy_cp = yy_hold_char; /* undo effects of setting up yytext */ \\" );
1242: outn(
1243: "yy_cp = yy_full_match; /* restore poss. backed-over text */ \\" );
1244:
1245: if ( variable_trailing_context_rules )
1246: {
1247: outn(
1248: "yy_lp = yy_full_lp; /* restore orig. accepting pos. */ \\" );
1249: outn(
1250: "yy_state_ptr = yy_full_state; /* restore orig. state */ \\" );
1251: outn(
1252: "yy_current_state = *yy_state_ptr; /* restore curr. state */ \\" );
1253: }
1254:
1255: outn( "++yy_lp; \\" );
1256: outn( "goto find_rule; \\" );
1257: /* { for vi */
1258: outn( "}" );
1259: }
1260:
1261: else
1262: {
1263: outn(
1264: "/* The intent behind this definition is that it'll catch" );
1265: outn( " * any uses of REJECT which flex missed." );
1266: outn( " */" );
1267: outn( "#define REJECT reject_used_but_not_detected" );
1268: }
1269:
1270: if ( yymore_used )
1271: {
1272: if ( ! C_plus_plus )
1273: {
1.3 millert 1274: if ( yytext_is_array )
1275: {
1276: indent_puts( "static int yy_more_offset = 0;" );
1277: indent_puts(
1278: "static int yy_prev_more_offset = 0;" );
1279: }
1280: else
1281: {
1282: indent_puts( "static int yy_more_flag = 0;" );
1283: indent_puts( "static int yy_more_len = 0;" );
1284: }
1.1 deraadt 1285: }
1286:
1.3 millert 1287: if ( yytext_is_array )
1288: {
1289: indent_puts(
1290: "#define yymore() (yy_more_offset = yy_flex_strlen( yytext ))" );
1291: indent_puts( "#define YY_NEED_STRLEN" );
1292: indent_puts( "#define YY_MORE_ADJ 0" );
1293: indent_puts( "#define YY_RESTORE_YY_MORE_OFFSET \\" );
1294: indent_up();
1295: indent_puts( "{ \\" );
1296: indent_puts( "yy_more_offset = yy_prev_more_offset; \\" );
1297: indent_puts( "yyleng -= yy_more_offset; \\" );
1298: indent_puts( "}" );
1299: indent_down();
1300: }
1301: else
1302: {
1303: indent_puts( "#define yymore() (yy_more_flag = 1)" );
1304: indent_puts( "#define YY_MORE_ADJ yy_more_len" );
1305: indent_puts( "#define YY_RESTORE_YY_MORE_OFFSET" );
1306: }
1.1 deraadt 1307: }
1308:
1309: else
1310: {
1311: indent_puts( "#define yymore() yymore_used_but_not_detected" );
1312: indent_puts( "#define YY_MORE_ADJ 0" );
1.3 millert 1313: indent_puts( "#define YY_RESTORE_YY_MORE_OFFSET" );
1.1 deraadt 1314: }
1315:
1316: if ( ! C_plus_plus )
1317: {
1318: if ( yytext_is_array )
1319: {
1320: outn( "#ifndef YYLMAX" );
1321: outn( "#define YYLMAX 8192" );
1322: outn( "#endif\n" );
1323: outn( "char yytext[YYLMAX];" );
1324: outn( "char *yytext_ptr;" );
1325: }
1326:
1327: else
1328: outn( "char *yytext;" );
1329: }
1330:
1331: out( &action_array[defs1_offset] );
1332:
1333: line_directive_out( stdout, 0 );
1334:
1335: skelout();
1336:
1337: if ( ! C_plus_plus )
1338: {
1339: if ( use_read )
1340: {
1341: outn(
1342: "\tif ( (result = read( fileno(yyin), (char *) buf, max_size )) < 0 ) \\" );
1343: outn(
1344: "\t\tYY_FATAL_ERROR( \"input in flex scanner failed\" );" );
1345: }
1346:
1347: else
1348: {
1349: outn(
1350: "\tif ( yy_current_buffer->yy_is_interactive ) \\" );
1351: outn( "\t\t{ \\" );
1352: outn( "\t\tint c = '*', n; \\" );
1353: outn( "\t\tfor ( n = 0; n < max_size && \\" );
1354: outn( "\t\t\t (c = getc( yyin )) != EOF && c != '\\n'; ++n ) \\" );
1355: outn( "\t\t\tbuf[n] = (char) c; \\" );
1356: outn( "\t\tif ( c == '\\n' ) \\" );
1357: outn( "\t\t\tbuf[n++] = (char) c; \\" );
1358: outn( "\t\tif ( c == EOF && ferror( yyin ) ) \\" );
1359: outn(
1360: "\t\t\tYY_FATAL_ERROR( \"input in flex scanner failed\" ); \\" );
1361: outn( "\t\tresult = n; \\" );
1362: outn( "\t\t} \\" );
1363: outn(
1364: "\telse if ( ((result = fread( buf, 1, max_size, yyin )) == 0) \\" );
1365: outn( "\t\t && ferror( yyin ) ) \\" );
1366: outn(
1367: "\t\tYY_FATAL_ERROR( \"input in flex scanner failed\" );" );
1368: }
1369: }
1370:
1371: skelout();
1372:
1373: indent_puts( "#define YY_RULE_SETUP \\" );
1374: indent_up();
1375: if ( bol_needed )
1376: {
1377: indent_puts( "if ( yyleng > 0 ) \\" );
1378: indent_up();
1379: indent_puts( "yy_current_buffer->yy_at_bol = \\" );
1380: indent_puts( "\t\t(yytext[yyleng - 1] == '\\n'); \\" );
1381: indent_down();
1382: }
1383: indent_puts( "YY_USER_ACTION" );
1384: indent_down();
1385:
1386: skelout();
1387:
1388: /* Copy prolog to output file. */
1389: out( &action_array[prolog_offset] );
1390:
1391: line_directive_out( stdout, 0 );
1392:
1393: skelout();
1394:
1395: set_indent( 2 );
1396:
1.3 millert 1397: if ( yymore_used && ! yytext_is_array )
1.1 deraadt 1398: {
1399: indent_puts( "yy_more_len = 0;" );
1400: indent_puts( "if ( yy_more_flag )" );
1401: indent_up();
1402: indent_puts( "{" );
1.3 millert 1403: indent_puts( "yy_more_len = yy_c_buf_p - yytext_ptr;" );
1.1 deraadt 1404: indent_puts( "yy_more_flag = 0;" );
1405: indent_puts( "}" );
1406: indent_down();
1407: }
1408:
1409: skelout();
1410:
1411: gen_start_state();
1412:
1413: /* Note, don't use any indentation. */
1414: outn( "yy_match:" );
1415: gen_next_match();
1416:
1417: skelout();
1418: set_indent( 2 );
1419: gen_find_action();
1420:
1421: skelout();
1422: if ( do_yylineno )
1423: {
1424: indent_puts( "if ( yy_act != YY_END_OF_BUFFER )" );
1425: indent_up();
1426: indent_puts( "{" );
1427: indent_puts( "int yyl;" );
1428: indent_puts( "for ( yyl = 0; yyl < yyleng; ++yyl )" );
1429: indent_up();
1430: indent_puts( "if ( yytext[yyl] == '\\n' )" );
1431: indent_up();
1432: indent_puts( "++yylineno;" );
1433: indent_down();
1434: indent_down();
1435: indent_puts( "}" );
1436: indent_down();
1437: }
1438:
1439: skelout();
1440: if ( ddebug )
1441: {
1442: indent_puts( "if ( yy_flex_debug )" );
1443: indent_up();
1444:
1445: indent_puts( "{" );
1446: indent_puts( "if ( yy_act == 0 )" );
1447: indent_up();
1448: indent_puts( C_plus_plus ?
1449: "cerr << \"--scanner backing up\\n\";" :
1450: "fprintf( stderr, \"--scanner backing up\\n\" );" );
1451: indent_down();
1452:
1453: do_indent();
1454: out_dec( "else if ( yy_act < %d )\n", num_rules );
1455: indent_up();
1456:
1457: if ( C_plus_plus )
1458: {
1459: indent_puts(
1460: "cerr << \"--accepting rule at line \" << yy_rule_linenum[yy_act] <<" );
1461: indent_puts(
1462: " \"(\\\"\" << yytext << \"\\\")\\n\";" );
1463: }
1464: else
1465: {
1466: indent_puts(
1467: "fprintf( stderr, \"--accepting rule at line %d (\\\"%s\\\")\\n\"," );
1468:
1469: indent_puts(
1470: " yy_rule_linenum[yy_act], yytext );" );
1471: }
1472:
1473: indent_down();
1474:
1475: do_indent();
1476: out_dec( "else if ( yy_act == %d )\n", num_rules );
1477: indent_up();
1478:
1479: if ( C_plus_plus )
1480: {
1481: indent_puts(
1482: "cerr << \"--accepting default rule (\\\"\" << yytext << \"\\\")\\n\";" );
1483: }
1484: else
1485: {
1486: indent_puts(
1487: "fprintf( stderr, \"--accepting default rule (\\\"%s\\\")\\n\"," );
1488: indent_puts( " yytext );" );
1489: }
1490:
1491: indent_down();
1492:
1493: do_indent();
1494: out_dec( "else if ( yy_act == %d )\n", num_rules + 1 );
1495: indent_up();
1496:
1497: indent_puts( C_plus_plus ?
1498: "cerr << \"--(end of buffer or a NUL)\\n\";" :
1499: "fprintf( stderr, \"--(end of buffer or a NUL)\\n\" );" );
1500:
1501: indent_down();
1502:
1503: do_indent();
1504: outn( "else" );
1505: indent_up();
1506:
1507: if ( C_plus_plus )
1508: {
1509: indent_puts(
1510: "cerr << \"--EOF (start condition \" << YY_START << \")\\n\";" );
1511: }
1512: else
1513: {
1514: indent_puts(
1515: "fprintf( stderr, \"--EOF (start condition %d)\\n\", YY_START );" );
1516: }
1517:
1518: indent_down();
1519:
1520: indent_puts( "}" );
1521: indent_down();
1522: }
1523:
1524: /* Copy actions to output file. */
1525: skelout();
1526: indent_up();
1527: gen_bu_action();
1528: out( &action_array[action_offset] );
1529:
1530: line_directive_out( stdout, 0 );
1531:
1532: /* generate cases for any missing EOF rules */
1533: for ( i = 1; i <= lastsc; ++i )
1534: if ( ! sceof[i] )
1535: {
1536: do_indent();
1537: out_str( "case YY_STATE_EOF(%s):\n", scname[i] );
1538: did_eof_rule = true;
1539: }
1540:
1541: if ( did_eof_rule )
1542: {
1543: indent_up();
1544: indent_puts( "yyterminate();" );
1545: indent_down();
1546: }
1547:
1548:
1549: /* Generate code for handling NUL's, if needed. */
1550:
1551: /* First, deal with backing up and setting up yy_cp if the scanner
1552: * finds that it should JAM on the NUL.
1553: */
1554: skelout();
1555: set_indent( 4 );
1556:
1557: if ( fullspd || fulltbl )
1558: indent_puts( "yy_cp = yy_c_buf_p;" );
1559:
1560: else
1561: { /* compressed table */
1562: if ( ! reject && ! interactive )
1563: {
1564: /* Do the guaranteed-needed backing up to figure
1565: * out the match.
1566: */
1567: indent_puts( "yy_cp = yy_last_accepting_cpos;" );
1568: indent_puts(
1569: "yy_current_state = yy_last_accepting_state;" );
1570: }
1571:
1572: else
1573: /* Still need to initialize yy_cp, though
1574: * yy_current_state was set up by
1575: * yy_get_previous_state().
1576: */
1577: indent_puts( "yy_cp = yy_c_buf_p;" );
1578: }
1579:
1580:
1581: /* Generate code for yy_get_previous_state(). */
1582: set_indent( 1 );
1583: skelout();
1584:
1585: gen_start_state();
1586:
1587: set_indent( 2 );
1588: skelout();
1589: gen_next_state( true );
1590:
1591: set_indent( 1 );
1592: skelout();
1593: gen_NUL_trans();
1594:
1595: skelout();
1596: if ( do_yylineno )
1597: { /* update yylineno inside of unput() */
1598: indent_puts( "if ( c == '\\n' )" );
1599: indent_up();
1600: indent_puts( "--yylineno;" );
1601: indent_down();
1602: }
1603:
1604: skelout();
1605: /* Update BOL and yylineno inside of input(). */
1606: if ( bol_needed )
1607: {
1608: indent_puts( "yy_current_buffer->yy_at_bol = (c == '\\n');" );
1609: if ( do_yylineno )
1610: {
1611: indent_puts( "if ( yy_current_buffer->yy_at_bol )" );
1612: indent_up();
1613: indent_puts( "++yylineno;" );
1614: indent_down();
1615: }
1616: }
1617:
1618: else if ( do_yylineno )
1619: {
1620: indent_puts( "if ( c == '\\n' )" );
1621: indent_up();
1622: indent_puts( "++yylineno;" );
1623: indent_down();
1624: }
1625:
1626: skelout();
1627:
1628: /* Copy remainder of input to output. */
1629:
1630: line_directive_out( stdout, 1 );
1631:
1632: if ( sectnum == 3 )
1633: (void) flexscan(); /* copy remainder of input to output */
1634: }