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