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