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