NetBSD/usr.bin/lex/gen.c

1627 lines
36 KiB
C
Raw Normal View History

1993-05-04 11:44:39 +04:00
/* gen - actual generation (writing) of flex scanners */
1993-03-21 12:45:37 +03:00
/*-
* Copyright (c) 1990 The Regents of the University of California.
* All rights reserved.
*
* This code is derived from software contributed to Berkeley by
1993-05-04 11:44:39 +04:00
* Vern Paxson.
1993-03-21 12:45:37 +03:00
*
* The United States Government has rights in this work pursuant
* to contract no. DE-AC03-76SF00098 between the United States
* Department of Energy and the University of California.
*
1993-05-04 11:44:39 +04:00
* Redistribution and use in source and binary forms are permitted provided
* that: (1) source distributions retain this entire copyright notice and
* comment, and (2) distributions including binaries display the following
* acknowledgement: ``This product includes software developed by the
* University of California, Berkeley and its contributors'' in the
* documentation or other materials provided with the distribution and in
* all advertising materials mentioning features or use of this software.
* Neither the name of the University nor the names of its contributors may
* be used to endorse or promote products derived from this software without
* specific prior written permission.
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR IMPLIED
* WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
1993-03-21 12:45:37 +03:00
*/
1998-10-11 00:48:04 +04:00
/* $NetBSD: gen.c,v 1.13 1998/10/10 20:48:04 itohy Exp $ */
1993-03-21 12:45:37 +03:00
#include "flexdef.h"
1993-05-04 11:44:39 +04:00
1993-03-21 12:45:37 +03:00
/* declare functions that have forward references */
void gen_next_state PROTO((int));
1993-12-02 22:17:24 +03:00
void genecs PROTO((void));
1993-03-21 12:45:37 +03:00
void indent_put2s PROTO((char [], char []));
void indent_puts PROTO((char []));
1993-12-02 22:17:24 +03:00
static int indent_level = 0; /* each level is 8 spaces */
1993-03-21 12:45:37 +03:00
#define indent_up() (++indent_level)
#define indent_down() (--indent_level)
#define set_indent(indent_val) indent_level = indent_val
1993-12-14 05:09:50 +03:00
/* Almost everything is done in terms of arrays starting at 1, so provide
* a null entry for the zero element of all C arrays. (The exception
* to this is that the fast table representation generally uses the
* 0 elements of its arrays, too.)
1993-03-21 12:45:37 +03:00
*/
1995-05-05 09:35:08 +04:00
static char C_int_decl[] = "static yyconst int %s[%d] =\n { 0,\n";
static char C_short_decl[] = "static yyconst short int %s[%d] =\n { 0,\n";
static char C_long_decl[] = "static yyconst long int %s[%d] =\n { 0,\n";
1993-03-21 12:45:37 +03:00
static char C_state_decl[] =
1995-05-05 09:35:08 +04:00
"static yyconst yy_state_type %s[%d] =\n { 0,\n";
1993-03-21 12:45:37 +03:00
1993-12-02 22:17:24 +03:00
/* Indent to the current level. */
1993-03-21 12:45:37 +03:00
void do_indent()
{
1993-12-02 22:17:24 +03:00
register int i = indent_level * 8;
1993-03-21 12:45:37 +03:00
1993-12-02 22:17:24 +03:00
while ( i >= 8 )
{
1995-05-05 09:35:08 +04:00
outc( '\t' );
1993-12-02 22:17:24 +03:00
i -= 8;
}
1993-03-21 12:45:37 +03:00
1993-12-02 22:17:24 +03:00
while ( i > 0 )
{
1995-05-05 09:35:08 +04:00
outc( ' ' );
1993-12-02 22:17:24 +03:00
--i;
}
}
1993-03-21 12:45:37 +03:00
1993-12-02 22:17:24 +03:00
/* Generate the code to keep backing-up information. */
1993-03-21 12:45:37 +03:00
1993-12-02 22:17:24 +03:00
void gen_backing_up()
{
if ( reject || num_backing_up == 0 )
return;
1993-03-21 12:45:37 +03:00
1993-12-02 22:17:24 +03:00
if ( fullspd )
indent_puts( "if ( yy_current_state[-1].yy_nxt )" );
else
indent_puts( "if ( yy_accept[yy_current_state] )" );
1993-03-21 12:45:37 +03:00
1993-12-02 22:17:24 +03:00
indent_up();
indent_puts( "{" );
indent_puts( "yy_last_accepting_state = yy_current_state;" );
indent_puts( "yy_last_accepting_cpos = yy_cp;" );
indent_puts( "}" );
indent_down();
}
1993-03-21 12:45:37 +03:00
1993-12-02 22:17:24 +03:00
/* Generate the code to perform the backing up. */
1993-03-21 12:45:37 +03:00
1993-12-02 22:17:24 +03:00
void gen_bu_action()
{
if ( reject || num_backing_up == 0 )
return;
1993-03-21 12:45:37 +03:00
1993-12-02 22:17:24 +03:00
set_indent( 3 );
1993-03-21 12:45:37 +03:00
1993-12-02 22:17:24 +03:00
indent_puts( "case 0: /* must back up */" );
indent_puts( "/* undo the effects of YY_DO_BEFORE_ACTION */" );
indent_puts( "*yy_cp = yy_hold_char;" );
1993-03-21 12:45:37 +03:00
1993-12-02 22:17:24 +03:00
if ( fullspd || fulltbl )
indent_puts( "yy_cp = yy_last_accepting_cpos + 1;" );
else
/* Backing-up info for compressed tables is taken \after/
* yy_cp has been incremented for the next state.
*/
indent_puts( "yy_cp = yy_last_accepting_cpos;" );
1993-03-21 12:45:37 +03:00
1993-12-02 22:17:24 +03:00
indent_puts( "yy_current_state = yy_last_accepting_state;" );
indent_puts( "goto yy_find_action;" );
1995-05-05 09:35:08 +04:00
outc( '\n' );
1993-03-21 12:45:37 +03:00
1993-12-02 22:17:24 +03:00
set_indent( 0 );
}
1993-03-21 12:45:37 +03:00
1993-12-02 22:17:24 +03:00
/* genctbl - generates full speed compressed transition table */
1993-03-21 12:45:37 +03:00
void genctbl()
{
1993-12-02 22:17:24 +03:00
register int i;
int end_of_buffer_action = num_rules + 1;
/* Table of verify for transition and offset to next state. */
1995-05-05 09:35:08 +04:00
out_dec( "static yyconst struct yy_trans_info yy_transition[%d] =\n",
1993-12-02 22:17:24 +03:00
tblend + numecs + 1 );
1995-05-05 09:35:08 +04:00
outn( " {" );
1993-12-02 22:17:24 +03:00
/* We want the transition to be represented as the offset to the
* next state, not the actual state number, which is what it currently
* is. The offset is base[nxt[i]] - (base of current state)]. That's
* just the difference between the starting points of the two involved
* states (to - from).
*
* First, though, we need to find some way to put in our end-of-buffer
* flags and states. We do this by making a state with absolutely no
* transitions. We put it at the end of the table.
*/
1993-03-21 12:45:37 +03:00
1993-12-02 22:17:24 +03:00
/* We need to have room in nxt/chk for two more slots: One for the
* action and one for the end-of-buffer transition. We now *assume*
* that we're guaranteed the only character we'll try to index this
* nxt/chk pair with is EOB, i.e., 0, so we don't have to make sure
* there's room for jam entries for other characters.
*/
1993-03-21 12:45:37 +03:00
1993-12-02 22:17:24 +03:00
while ( tblend + 2 >= current_max_xpairs )
expand_nxt_chk();
1993-03-21 12:45:37 +03:00
1993-12-02 22:17:24 +03:00
while ( lastdfa + 1 >= current_max_dfas )
increase_max_dfas();
1993-03-21 12:45:37 +03:00
1993-12-02 22:17:24 +03:00
base[lastdfa + 1] = tblend + 2;
nxt[tblend + 1] = end_of_buffer_action;
chk[tblend + 1] = numecs + 1;
chk[tblend + 2] = 1; /* anything but EOB */
1993-03-21 12:45:37 +03:00
1993-12-02 22:17:24 +03:00
/* So that "make test" won't show arb. differences. */
nxt[tblend + 2] = 0;
1993-03-21 12:45:37 +03:00
1993-12-14 05:09:50 +03:00
/* Make sure every state has an end-of-buffer transition and an
1993-12-02 22:17:24 +03:00
* action #.
*/
for ( i = 0; i <= lastdfa; ++i )
{
1993-12-14 05:09:50 +03:00
int anum = dfaacc[i].dfaacc_state;
int offset = base[i];
1993-03-21 12:45:37 +03:00
1993-12-14 05:09:50 +03:00
chk[offset] = EOB_POSITION;
chk[offset - 1] = ACTION_POSITION;
nxt[offset - 1] = anum; /* action number */
1993-12-02 22:17:24 +03:00
}
1993-03-21 12:45:37 +03:00
1993-12-02 22:17:24 +03:00
for ( i = 0; i <= tblend; ++i )
{
if ( chk[i] == EOB_POSITION )
transition_struct_out( 0, base[lastdfa + 1] - i );
1993-03-21 12:45:37 +03:00
1993-12-02 22:17:24 +03:00
else if ( chk[i] == ACTION_POSITION )
transition_struct_out( 0, nxt[i] );
1993-03-21 12:45:37 +03:00
1993-12-02 22:17:24 +03:00
else if ( chk[i] > numecs || chk[i] == 0 )
transition_struct_out( 0, 0 ); /* unused slot */
1993-03-21 12:45:37 +03:00
1993-12-02 22:17:24 +03:00
else /* verify, transition */
transition_struct_out( chk[i],
base[nxt[i]] - (i - chk[i]) );
}
1993-03-21 12:45:37 +03:00
1993-12-02 22:17:24 +03:00
/* Here's the final, end-of-buffer state. */
transition_struct_out( chk[tblend + 1], nxt[tblend + 1] );
transition_struct_out( chk[tblend + 2], nxt[tblend + 2] );
1993-03-21 12:45:37 +03:00
1995-05-05 09:35:08 +04:00
outn( " };\n" );
1993-03-21 12:45:37 +03:00
1993-12-02 22:17:24 +03:00
/* Table of pointers to start states. */
1995-05-05 09:35:08 +04:00
out_dec(
"static yyconst struct yy_trans_info *yy_start_state_list[%d] =\n",
1993-12-02 22:17:24 +03:00
lastsc * 2 + 1 );
1995-05-05 09:35:08 +04:00
outn( " {" ); /* } so vi doesn't get confused */
1993-03-21 12:45:37 +03:00
1993-12-02 22:17:24 +03:00
for ( i = 0; i <= lastsc * 2; ++i )
1995-05-05 09:35:08 +04:00
out_dec( " &yy_transition[%d],\n", base[i] );
1993-03-21 12:45:37 +03:00
1993-12-02 22:17:24 +03:00
dataend();
1993-03-21 12:45:37 +03:00
1993-12-02 22:17:24 +03:00
if ( useecs )
genecs();
1993-03-21 12:45:37 +03:00
}
1993-12-02 22:17:24 +03:00
/* Generate equivalence-class tables. */
void genecs()
1993-03-21 12:45:37 +03:00
{
1993-12-02 22:17:24 +03:00
register int i, j;
int numrows;
1995-05-05 09:35:08 +04:00
out_str_dec( C_int_decl, "yy_ec", csize );
1993-03-21 12:45:37 +03:00
1993-12-02 22:17:24 +03:00
for ( i = 1; i < csize; ++i )
{
if ( caseins && (i >= 'A') && (i <= 'Z') )
ecgroup[i] = ecgroup[clower( i )];
1993-03-21 12:45:37 +03:00
1993-12-09 22:06:03 +03:00
ecgroup[i] = ABS( ecgroup[i] );
1993-12-02 22:17:24 +03:00
mkdata( ecgroup[i] );
}
dataend();
1993-03-21 12:45:37 +03:00
1993-12-02 22:17:24 +03:00
if ( trace )
1993-03-21 12:45:37 +03:00
{
1995-05-05 09:35:08 +04:00
fputs( _( "\n\nEquivalence Classes:\n\n" ), stderr );
1993-03-21 12:45:37 +03:00
1993-12-02 22:17:24 +03:00
numrows = csize / 8;
for ( j = 0; j < numrows; ++j )
{
for ( i = j; i < csize; i = i + numrows )
{
fprintf( stderr, "%4s = %-2d",
readable_form( i ), ecgroup[i] );
1993-03-21 12:45:37 +03:00
1993-12-02 22:17:24 +03:00
putc( ' ', stderr );
}
putc( '\n', stderr );
}
}
1993-03-21 12:45:37 +03:00
}
1993-12-02 22:17:24 +03:00
/* Generate the code to find the action number. */
1993-03-21 12:45:37 +03:00
void gen_find_action()
1993-12-02 22:17:24 +03:00
{
if ( fullspd )
indent_puts( "yy_act = yy_current_state[-1].yy_nxt;" );
1993-03-21 12:45:37 +03:00
1993-12-02 22:17:24 +03:00
else if ( fulltbl )
indent_puts( "yy_act = yy_accept[yy_current_state];" );
1993-03-21 12:45:37 +03:00
1993-12-02 22:17:24 +03:00
else if ( reject )
{
indent_puts( "yy_current_state = *--yy_state_ptr;" );
indent_puts( "yy_lp = yy_accept[yy_current_state];" );
1993-03-21 12:45:37 +03:00
1995-05-05 09:35:08 +04:00
outn(
1993-12-02 22:17:24 +03:00
"find_rule: /* we branch to this label when backing up */" );
1993-03-21 12:45:37 +03:00
1993-12-02 22:17:24 +03:00
indent_puts(
"for ( ; ; ) /* until we find what rule we matched */" );
1993-03-21 12:45:37 +03:00
1993-12-02 22:17:24 +03:00
indent_up();
1993-03-21 12:45:37 +03:00
1993-12-02 22:17:24 +03:00
indent_puts( "{" );
1993-03-21 12:45:37 +03:00
1993-12-02 22:17:24 +03:00
indent_puts(
"if ( yy_lp && yy_lp < yy_accept[yy_current_state + 1] )" );
indent_up();
indent_puts( "{" );
indent_puts( "yy_act = yy_acclist[yy_lp];" );
1993-03-21 12:45:37 +03:00
1993-12-02 22:17:24 +03:00
if ( variable_trailing_context_rules )
{
indent_puts( "if ( yy_act & YY_TRAILING_HEAD_MASK ||" );
indent_puts( " yy_looking_for_trail_begin )" );
indent_up();
indent_puts( "{" );
indent_puts(
"if ( yy_act == yy_looking_for_trail_begin )" );
indent_up();
indent_puts( "{" );
indent_puts( "yy_looking_for_trail_begin = 0;" );
indent_puts( "yy_act &= ~YY_TRAILING_HEAD_MASK;" );
indent_puts( "break;" );
indent_puts( "}" );
indent_down();
indent_puts( "}" );
indent_down();
indent_puts( "else if ( yy_act & YY_TRAILING_MASK )" );
indent_up();
indent_puts( "{" );
indent_puts(
1993-03-21 12:45:37 +03:00
"yy_looking_for_trail_begin = yy_act & ~YY_TRAILING_MASK;" );
1993-12-02 22:17:24 +03:00
indent_puts(
1993-03-21 12:45:37 +03:00
"yy_looking_for_trail_begin |= YY_TRAILING_HEAD_MASK;" );
1993-12-02 22:17:24 +03:00
if ( real_reject )
{
/* Remember matched text in case we back up
* due to REJECT.
*/
indent_puts( "yy_full_match = yy_cp;" );
indent_puts( "yy_full_state = yy_state_ptr;" );
indent_puts( "yy_full_lp = yy_lp;" );
}
indent_puts( "}" );
indent_down();
indent_puts( "else" );
indent_up();
indent_puts( "{" );
indent_puts( "yy_full_match = yy_cp;" );
indent_puts( "yy_full_state = yy_state_ptr;" );
indent_puts( "yy_full_lp = yy_lp;" );
indent_puts( "break;" );
indent_puts( "}" );
indent_down();
indent_puts( "++yy_lp;" );
indent_puts( "goto find_rule;" );
}
else
1995-05-05 09:35:08 +04:00
{
/* Remember matched text in case we back up due to
* trailing context plus REJECT.
*/
indent_up();
indent_puts( "{" );
indent_puts( "yy_full_match = yy_cp;" );
indent_puts( "break;" );
indent_puts( "}" );
indent_down();
}
1993-03-21 12:45:37 +03:00
1993-12-02 22:17:24 +03:00
indent_puts( "}" );
indent_down();
1993-03-21 12:45:37 +03:00
1993-12-02 22:17:24 +03:00
indent_puts( "--yy_cp;" );
1993-03-21 12:45:37 +03:00
1993-12-02 22:17:24 +03:00
/* We could consolidate the following two lines with those at
* the beginning, but at the cost of complaints that we're
* branching inside a loop.
*/
indent_puts( "yy_current_state = *--yy_state_ptr;" );
indent_puts( "yy_lp = yy_accept[yy_current_state];" );
1993-03-21 12:45:37 +03:00
1993-12-02 22:17:24 +03:00
indent_puts( "}" );
1993-03-21 12:45:37 +03:00
1993-12-02 22:17:24 +03:00
indent_down();
}
1993-03-21 12:45:37 +03:00
1993-12-02 22:17:24 +03:00
else
1995-05-05 09:35:08 +04:00
{ /* compressed */
1993-12-02 22:17:24 +03:00
indent_puts( "yy_act = yy_accept[yy_current_state];" );
1995-05-05 09:35:08 +04:00
if ( interactive && ! reject )
{
/* Do the guaranteed-needed backing up to figure out
* the match.
*/
indent_puts( "if ( yy_act == 0 )" );
indent_up();
indent_puts( "{ /* have to back up */" );
indent_puts( "yy_cp = yy_last_accepting_cpos;" );
indent_puts(
"yy_current_state = yy_last_accepting_state;" );
indent_puts( "yy_act = yy_accept[yy_current_state];" );
indent_puts( "}" );
indent_down();
}
}
1993-03-21 12:45:37 +03:00
}
1995-05-05 09:35:08 +04:00
/* genftbl - generate full transition table */
1993-03-21 12:45:37 +03:00
void genftbl()
1993-12-02 22:17:24 +03:00
{
register int i;
int end_of_buffer_action = num_rules + 1;
1995-05-05 09:35:08 +04:00
out_str_dec( long_align ? C_long_decl : C_short_decl,
1993-12-02 22:17:24 +03:00
"yy_accept", lastdfa + 1 );
1993-03-21 12:45:37 +03:00
1993-12-02 22:17:24 +03:00
dfaacc[end_of_buffer_state].dfaacc_state = end_of_buffer_action;
1993-03-21 12:45:37 +03:00
1993-12-02 22:17:24 +03:00
for ( i = 1; i <= lastdfa; ++i )
{
register int anum = dfaacc[i].dfaacc_state;
1993-03-21 12:45:37 +03:00
1993-12-02 22:17:24 +03:00
mkdata( anum );
1993-03-21 12:45:37 +03:00
1993-12-02 22:17:24 +03:00
if ( trace && anum )
1995-05-05 09:35:08 +04:00
fprintf( stderr, _( "state # %d accepts: [%d]\n" ),
1993-12-02 22:17:24 +03:00
i, anum );
}
1993-03-21 12:45:37 +03:00
1993-12-02 22:17:24 +03:00
dataend();
1993-03-21 12:45:37 +03:00
1993-12-02 22:17:24 +03:00
if ( useecs )
genecs();
1993-03-21 12:45:37 +03:00
1993-12-02 22:17:24 +03:00
/* Don't have to dump the actual full table entries - they were
* created on-the-fly.
*/
1993-03-21 12:45:37 +03:00
}
1993-12-02 22:17:24 +03:00
/* Generate the code to find the next compressed-table state. */
1993-03-21 12:45:37 +03:00
1993-12-02 22:17:24 +03:00
void gen_next_compressed_state( char_map )
char *char_map;
{
indent_put2s( "register YY_CHAR yy_c = %s;", char_map );
1993-03-21 12:45:37 +03:00
1993-12-02 22:17:24 +03:00
/* Save the backing-up info \before/ computing the next state
* because we always compute one more state than needed - we
* always proceed until we reach a jam state
*/
gen_backing_up();
indent_puts(
"while ( yy_chk[yy_base[yy_current_state] + yy_c] != yy_current_state )" );
indent_up();
indent_puts( "{" );
indent_puts( "yy_current_state = (int) yy_def[yy_current_state];" );
1993-03-21 12:45:37 +03:00
1993-12-02 22:17:24 +03:00
if ( usemecs )
{
/* We've arrange it so that templates are never chained
* to one another. This means we can afford to make a
* very simple test to see if we need to convert to
* yy_c's meta-equivalence class without worrying
* about erroneously looking up the meta-equivalence
* class twice
*/
do_indent();
/* lastdfa + 2 is the beginning of the templates */
1995-05-05 09:35:08 +04:00
out_dec( "if ( yy_current_state >= %d )\n", lastdfa + 2 );
1993-12-02 22:17:24 +03:00
indent_up();
indent_puts( "yy_c = yy_meta[(unsigned int) yy_c];" );
indent_down();
}
1993-03-21 12:45:37 +03:00
1993-12-02 22:17:24 +03:00
indent_puts( "}" );
indent_down();
1993-03-21 12:45:37 +03:00
1993-12-02 22:17:24 +03:00
indent_puts(
"yy_current_state = yy_nxt[yy_base[yy_current_state] + (unsigned int) yy_c];" );
}
1993-03-21 12:45:37 +03:00
1993-12-02 22:17:24 +03:00
/* Generate the code to find the next match. */
1993-03-21 12:45:37 +03:00
1993-12-02 22:17:24 +03:00
void gen_next_match()
1993-03-21 12:45:37 +03:00
{
1993-12-02 22:17:24 +03:00
/* NOTE - changes in here should be reflected in gen_next_state() and
* gen_NUL_trans().
1993-03-21 12:45:37 +03:00
*/
1993-12-09 22:06:03 +03:00
char *char_map = useecs ?
"yy_ec[YY_SC_TO_UI(*yy_cp)]" :
"YY_SC_TO_UI(*yy_cp)";
char *char_map_2 = useecs ?
"yy_ec[YY_SC_TO_UI(*++yy_cp)]" :
"YY_SC_TO_UI(*++yy_cp)";
1993-03-21 12:45:37 +03:00
1993-12-02 22:17:24 +03:00
if ( fulltbl )
{
indent_put2s(
1993-12-09 22:06:03 +03:00
"while ( (yy_current_state = yy_nxt[yy_current_state][%s]) > 0 )",
1993-12-02 22:17:24 +03:00
char_map );
1993-03-21 12:45:37 +03:00
1993-12-02 22:17:24 +03:00
indent_up();
1993-03-21 12:45:37 +03:00
1993-12-02 22:17:24 +03:00
if ( num_backing_up > 0 )
{
indent_puts( "{" ); /* } for vi */
gen_backing_up();
1995-05-05 09:35:08 +04:00
outc( '\n' );
1993-12-02 22:17:24 +03:00
}
1993-03-21 12:45:37 +03:00
1993-12-02 22:17:24 +03:00
indent_puts( "++yy_cp;" );
1993-03-21 12:45:37 +03:00
1993-12-02 22:17:24 +03:00
if ( num_backing_up > 0 )
/* { for vi */
indent_puts( "}" );
1993-03-21 12:45:37 +03:00
1993-12-02 22:17:24 +03:00
indent_down();
1993-03-21 12:45:37 +03:00
1995-05-05 09:35:08 +04:00
outc( '\n' );
1993-12-02 22:17:24 +03:00
indent_puts( "yy_current_state = -yy_current_state;" );
}
1993-03-21 12:45:37 +03:00
1993-12-02 22:17:24 +03:00
else if ( fullspd )
{
indent_puts( "{" ); /* } for vi */
indent_puts(
1995-05-05 09:35:08 +04:00
"register yyconst struct yy_trans_info *yy_trans_info;\n" );
1993-12-02 22:17:24 +03:00
indent_puts( "register YY_CHAR yy_c;\n" );
indent_put2s( "for ( yy_c = %s;", char_map );
indent_puts(
" (yy_trans_info = &yy_current_state[(unsigned int) yy_c])->" );
indent_puts( "yy_verify == yy_c;" );
indent_put2s( " yy_c = %s )", char_map_2 );
1993-03-21 12:45:37 +03:00
1993-12-02 22:17:24 +03:00
indent_up();
1993-03-21 12:45:37 +03:00
1993-12-02 22:17:24 +03:00
if ( num_backing_up > 0 )
indent_puts( "{" ); /* } for vi */
1993-03-21 12:45:37 +03:00
1993-12-02 22:17:24 +03:00
indent_puts( "yy_current_state += yy_trans_info->yy_nxt;" );
1993-03-21 12:45:37 +03:00
1993-12-02 22:17:24 +03:00
if ( num_backing_up > 0 )
{
1995-05-05 09:35:08 +04:00
outc( '\n' );
1993-12-02 22:17:24 +03:00
gen_backing_up(); /* { for vi */
indent_puts( "}" );
}
1993-03-21 12:45:37 +03:00
1993-12-02 22:17:24 +03:00
indent_down(); /* { for vi */
indent_puts( "}" );
}
1993-03-21 12:45:37 +03:00
1993-12-02 22:17:24 +03:00
else
{ /* compressed */
indent_puts( "do" );
1993-03-21 12:45:37 +03:00
1993-12-02 22:17:24 +03:00
indent_up();
indent_puts( "{" ); /* } for vi */
1993-03-21 12:45:37 +03:00
1993-12-02 22:17:24 +03:00
gen_next_state( false );
1993-03-21 12:45:37 +03:00
1993-12-02 22:17:24 +03:00
indent_puts( "++yy_cp;" );
1993-03-21 12:45:37 +03:00
1993-12-02 22:17:24 +03:00
/* { for vi */
indent_puts( "}" );
indent_down();
1993-03-21 12:45:37 +03:00
1993-12-02 22:17:24 +03:00
do_indent();
1993-03-21 12:45:37 +03:00
1993-12-02 22:17:24 +03:00
if ( interactive )
1995-05-05 09:35:08 +04:00
out_dec( "while ( yy_base[yy_current_state] != %d );\n",
1993-12-02 22:17:24 +03:00
jambase );
else
1995-05-05 09:35:08 +04:00
out_dec( "while ( yy_current_state != %d );\n",
1993-12-02 22:17:24 +03:00
jamstate );
1993-03-21 12:45:37 +03:00
1993-12-02 22:17:24 +03:00
if ( ! reject && ! interactive )
{
/* Do the guaranteed-needed backing up to figure out
* the match.
*/
indent_puts( "yy_cp = yy_last_accepting_cpos;" );
indent_puts(
"yy_current_state = yy_last_accepting_state;" );
}
}
}
1993-03-21 12:45:37 +03:00
1993-12-02 22:17:24 +03:00
/* Generate the code to find the next state. */
1993-03-21 12:45:37 +03:00
1993-12-02 22:17:24 +03:00
void gen_next_state( worry_about_NULs )
int worry_about_NULs;
1995-05-05 09:35:08 +04:00
{ /* NOTE - changes in here should be reflected in gen_next_match() */
1993-12-02 22:17:24 +03:00
char char_map[256];
1993-03-21 12:45:37 +03:00
1993-12-02 22:17:24 +03:00
if ( worry_about_NULs && ! nultrans )
{
if ( useecs )
(void) sprintf( char_map,
1993-12-09 22:06:03 +03:00
"(*yy_cp ? yy_ec[YY_SC_TO_UI(*yy_cp)] : %d)",
1993-12-02 22:17:24 +03:00
NUL_ec );
else
(void) sprintf( char_map,
1993-12-09 22:06:03 +03:00
"(*yy_cp ? YY_SC_TO_UI(*yy_cp) : %d)", NUL_ec );
1993-12-02 22:17:24 +03:00
}
1993-03-21 12:45:37 +03:00
else
1995-05-05 09:35:08 +04:00
strcpy( char_map, useecs ?
"yy_ec[YY_SC_TO_UI(*yy_cp)]" : "YY_SC_TO_UI(*yy_cp)" );
1993-03-21 12:45:37 +03:00
1993-12-02 22:17:24 +03:00
if ( worry_about_NULs && nultrans )
{
if ( ! fulltbl && ! fullspd )
/* Compressed tables back up *before* they match. */
gen_backing_up();
1993-03-21 12:45:37 +03:00
1993-12-02 22:17:24 +03:00
indent_puts( "if ( *yy_cp )" );
indent_up();
indent_puts( "{" ); /* } for vi */
}
1993-03-21 12:45:37 +03:00
1993-12-02 22:17:24 +03:00
if ( fulltbl )
indent_put2s(
1993-12-09 22:06:03 +03:00
"yy_current_state = yy_nxt[yy_current_state][%s];",
1993-12-02 22:17:24 +03:00
char_map );
1993-03-21 12:45:37 +03:00
1993-12-02 22:17:24 +03:00
else if ( fullspd )
indent_put2s(
1993-12-09 22:06:03 +03:00
"yy_current_state += yy_current_state[%s].yy_nxt;",
1993-12-02 22:17:24 +03:00
char_map );
1993-03-21 12:45:37 +03:00
else
1993-12-02 22:17:24 +03:00
gen_next_compressed_state( char_map );
1993-03-21 12:45:37 +03:00
1993-12-02 22:17:24 +03:00
if ( worry_about_NULs && nultrans )
{
/* { for vi */
indent_puts( "}" );
indent_down();
indent_puts( "else" );
indent_up();
indent_puts(
"yy_current_state = yy_NUL_trans[yy_current_state];" );
indent_down();
}
1993-03-21 12:45:37 +03:00
1993-12-02 22:17:24 +03:00
if ( fullspd || fulltbl )
gen_backing_up();
1993-03-21 12:45:37 +03:00
1993-12-02 22:17:24 +03:00
if ( reject )
indent_puts( "*yy_state_ptr++ = yy_current_state;" );
1993-03-21 12:45:37 +03:00
}
1993-12-02 22:17:24 +03:00
/* Generate the code to make a NUL transition. */
1993-03-21 12:45:37 +03:00
void gen_NUL_trans()
1995-05-05 09:35:08 +04:00
{ /* NOTE - changes in here should be reflected in gen_next_match() */
/* Only generate a definition for "yy_cp" if we'll generate code
* that uses it. Otherwise lint and the like complain.
*/
1993-12-02 22:17:24 +03:00
int need_backing_up = (num_backing_up > 0 && ! reject);
1993-03-21 12:45:37 +03:00
1995-05-05 09:35:08 +04:00
if ( need_backing_up && (! nultrans || fullspd || fulltbl) )
/* We're going to need yy_cp lying around for the call
* below to gen_backing_up().
*/
1993-12-02 22:17:24 +03:00
indent_puts( "register char *yy_cp = yy_c_buf_p;" );
1993-03-21 12:45:37 +03:00
1995-05-05 09:35:08 +04:00
outc( '\n' );
1993-03-21 12:45:37 +03:00
1993-12-02 22:17:24 +03:00
if ( nultrans )
{
indent_puts(
"yy_current_state = yy_NUL_trans[yy_current_state];" );
indent_puts( "yy_is_jam = (yy_current_state == 0);" );
}
1993-03-21 12:45:37 +03:00
1993-12-02 22:17:24 +03:00
else if ( fulltbl )
{
do_indent();
1995-05-05 09:35:08 +04:00
out_dec( "yy_current_state = yy_nxt[yy_current_state][%d];\n",
1993-12-02 22:17:24 +03:00
NUL_ec );
indent_puts( "yy_is_jam = (yy_current_state <= 0);" );
}
1993-03-21 12:45:37 +03:00
1993-12-02 22:17:24 +03:00
else if ( fullspd )
{
do_indent();
1995-05-05 09:35:08 +04:00
out_dec( "register int yy_c = %d;\n", NUL_ec );
1993-03-21 12:45:37 +03:00
1993-12-02 22:17:24 +03:00
indent_puts(
1995-05-05 09:35:08 +04:00
"register yyconst struct yy_trans_info *yy_trans_info;\n" );
1993-12-02 22:17:24 +03:00
indent_puts(
"yy_trans_info = &yy_current_state[(unsigned int) yy_c];" );
indent_puts( "yy_current_state += yy_trans_info->yy_nxt;" );
1993-03-21 12:45:37 +03:00
1993-12-02 22:17:24 +03:00
indent_puts(
"yy_is_jam = (yy_trans_info->yy_verify != yy_c);" );
}
1993-03-21 12:45:37 +03:00
1993-12-02 22:17:24 +03:00
else
{
char NUL_ec_str[20];
1993-03-21 12:45:37 +03:00
1993-12-02 22:17:24 +03:00
(void) sprintf( NUL_ec_str, "%d", NUL_ec );
gen_next_compressed_state( NUL_ec_str );
1993-03-21 12:45:37 +03:00
1993-12-02 22:17:24 +03:00
do_indent();
1995-05-05 09:35:08 +04:00
out_dec( "yy_is_jam = (yy_current_state == %d);\n", jamstate );
1996-12-10 10:18:37 +03:00
if ( reject )
{
/* Only stack this state if it's a transition we
* actually make. If we stack it on a jam, then
* the state stack and yy_c_buf_p get out of sync.
*/
indent_puts( "if ( ! yy_is_jam )" );
indent_up();
indent_puts( "*yy_state_ptr++ = yy_current_state;" );
indent_down();
}
1993-12-02 22:17:24 +03:00
}
1993-03-21 12:45:37 +03:00
1993-12-02 22:17:24 +03:00
/* If we've entered an accepting state, back up; note that
* compressed tables have *already* done such backing up, so
* we needn't bother with it again.
*/
if ( need_backing_up && (fullspd || fulltbl) )
{
1995-05-05 09:35:08 +04:00
outc( '\n' );
1993-12-02 22:17:24 +03:00
indent_puts( "if ( ! yy_is_jam )" );
indent_up();
indent_puts( "{" );
gen_backing_up();
indent_puts( "}" );
indent_down();
}
1993-03-21 12:45:37 +03:00
}
1993-12-02 22:17:24 +03:00
/* Generate the code to find the start state. */
1993-03-21 12:45:37 +03:00
void gen_start_state()
{
1993-12-02 22:17:24 +03:00
if ( fullspd )
1995-05-05 09:35:08 +04:00
{
if ( bol_needed )
{
indent_puts(
"yy_current_state = yy_start_state_list[yy_start + YY_AT_BOL()];" );
}
else
indent_puts(
"yy_current_state = yy_start_state_list[yy_start];" );
}
1993-03-21 12:45:37 +03:00
1993-12-02 22:17:24 +03:00
else
{
indent_puts( "yy_current_state = yy_start;" );
1993-03-21 12:45:37 +03:00
1993-12-02 22:17:24 +03:00
if ( bol_needed )
1995-05-05 09:35:08 +04:00
indent_puts( "yy_current_state += YY_AT_BOL();" );
1993-12-02 22:17:24 +03:00
if ( reject )
{
/* Set up for storing up states. */
indent_puts( "yy_state_ptr = yy_state_buf;" );
indent_puts( "*yy_state_ptr++ = yy_current_state;" );
}
}
1993-03-21 12:45:37 +03:00
}
1993-12-02 22:17:24 +03:00
/* gentabs - generate data statements for the transition tables */
1993-03-21 12:45:37 +03:00
void gentabs()
{
1993-12-02 22:17:24 +03:00
int i, j, k, *accset, nacc, *acc_array, total_states;
int end_of_buffer_action = num_rules + 1;
1993-03-21 12:45:37 +03:00
1993-12-02 22:17:24 +03:00
acc_array = allocate_integer_array( current_max_dfas );
nummt = 0;
1993-03-21 12:45:37 +03:00
1993-12-02 22:17:24 +03:00
/* The compressed table format jams by entering the "jam state",
* losing information about the previous state in the process.
* In order to recover the previous state, we effectively need
* to keep backing-up information.
*/
++num_backing_up;
1993-03-21 12:45:37 +03:00
1993-12-02 22:17:24 +03:00
if ( reject )
1993-03-21 12:45:37 +03:00
{
1993-12-02 22:17:24 +03:00
/* Write out accepting list and pointer list.
*
* First we generate the "yy_acclist" array. In the process,
* we compute the indices that will go into the "yy_accept"
* array, and save the indices in the dfaacc array.
*/
int EOB_accepting_list[2];
/* Set up accepting structures for the End Of Buffer state. */
EOB_accepting_list[0] = 0;
EOB_accepting_list[1] = end_of_buffer_action;
accsiz[end_of_buffer_state] = 1;
dfaacc[end_of_buffer_state].dfaacc_set = EOB_accepting_list;
1995-05-05 09:35:08 +04:00
out_str_dec( long_align ? C_long_decl : C_short_decl,
1993-12-09 22:06:03 +03:00
"yy_acclist", MAX( numas, 1 ) + 1 );
1993-12-02 22:17:24 +03:00
j = 1; /* index into "yy_acclist" array */
for ( i = 1; i <= lastdfa; ++i )
1993-03-21 12:45:37 +03:00
{
1993-12-02 22:17:24 +03:00
acc_array[i] = j;
if ( accsiz[i] != 0 )
{
accset = dfaacc[i].dfaacc_set;
nacc = accsiz[i];
if ( trace )
fprintf( stderr,
1995-05-05 09:35:08 +04:00
_( "state # %d accepts: " ),
i );
1993-12-02 22:17:24 +03:00
for ( k = 1; k <= nacc; ++k )
{
int accnum = accset[k];
++j;
if ( variable_trailing_context_rules &&
! (accnum & YY_TRAILING_HEAD_MASK) &&
accnum > 0 && accnum <= num_rules &&
rule_type[accnum] == RULE_VARIABLE )
{
/* Special hack to flag
* accepting number as part
* of trailing context rule.
*/
accnum |= YY_TRAILING_MASK;
}
mkdata( accnum );
if ( trace )
{
fprintf( stderr, "[%d]",
accset[k] );
if ( k < nacc )
fputs( ", ", stderr );
else
putc( '\n', stderr );
}
}
}
1993-03-21 12:45:37 +03:00
}
1993-12-02 22:17:24 +03:00
/* add accepting number for the "jam" state */
acc_array[i] = j;
1993-03-21 12:45:37 +03:00
1993-12-02 22:17:24 +03:00
dataend();
1993-03-21 12:45:37 +03:00
}
1993-12-02 22:17:24 +03:00
else
{
dfaacc[end_of_buffer_state].dfaacc_state = end_of_buffer_action;
1993-03-21 12:45:37 +03:00
1993-12-02 22:17:24 +03:00
for ( i = 1; i <= lastdfa; ++i )
acc_array[i] = dfaacc[i].dfaacc_state;
1993-03-21 12:45:37 +03:00
1993-12-02 22:17:24 +03:00
/* add accepting number for jam state */
acc_array[i] = 0;
}
1993-03-21 12:45:37 +03:00
1993-12-02 22:17:24 +03:00
/* Spit out "yy_accept" array. If we're doing "reject", it'll be
* pointers into the "yy_acclist" array. Otherwise it's actual
* accepting numbers. In either case, we just dump the numbers.
*/
1993-03-21 12:45:37 +03:00
1993-12-02 22:17:24 +03:00
/* "lastdfa + 2" is the size of "yy_accept"; includes room for C arrays
* beginning at 0 and for "jam" state.
1993-03-21 12:45:37 +03:00
*/
1993-12-02 22:17:24 +03:00
k = lastdfa + 2;
1993-03-21 12:45:37 +03:00
1993-12-02 22:17:24 +03:00
if ( reject )
/* We put a "cap" on the table associating lists of accepting
* numbers with state numbers. This is needed because we tell
* where the end of an accepting list is by looking at where
* the list for the next state starts.
*/
++k;
1993-03-21 12:45:37 +03:00
1995-05-05 09:35:08 +04:00
out_str_dec( long_align ? C_long_decl : C_short_decl, "yy_accept", k );
1993-03-21 12:45:37 +03:00
1993-12-02 22:17:24 +03:00
for ( i = 1; i <= lastdfa; ++i )
{
mkdata( acc_array[i] );
1993-03-21 12:45:37 +03:00
1993-12-02 22:17:24 +03:00
if ( ! reject && trace && acc_array[i] )
1995-05-05 09:35:08 +04:00
fprintf( stderr, _( "state # %d accepts: [%d]\n" ),
1993-12-02 22:17:24 +03:00
i, acc_array[i] );
}
1993-03-21 12:45:37 +03:00
1993-12-02 22:17:24 +03:00
/* Add entry for "jam" state. */
1993-03-21 12:45:37 +03:00
mkdata( acc_array[i] );
1993-12-02 22:17:24 +03:00
if ( reject )
/* Add "cap" for the list. */
mkdata( acc_array[i] );
1993-03-21 12:45:37 +03:00
1993-12-02 22:17:24 +03:00
dataend();
1993-03-21 12:45:37 +03:00
1993-12-02 22:17:24 +03:00
if ( useecs )
genecs();
1993-03-21 12:45:37 +03:00
1993-12-02 22:17:24 +03:00
if ( usemecs )
{
/* Write out meta-equivalence classes (used to index
* templates with).
*/
1993-03-21 12:45:37 +03:00
1993-12-02 22:17:24 +03:00
if ( trace )
1995-05-05 09:35:08 +04:00
fputs( _( "\n\nMeta-Equivalence Classes:\n" ),
stderr );
1993-03-21 12:45:37 +03:00
1995-05-05 09:35:08 +04:00
out_str_dec( C_int_decl, "yy_meta", numecs + 1 );
1993-03-21 12:45:37 +03:00
1993-12-02 22:17:24 +03:00
for ( i = 1; i <= numecs; ++i )
{
if ( trace )
fprintf( stderr, "%d = %d\n",
1993-12-09 22:06:03 +03:00
i, ABS( tecbck[i] ) );
1993-03-21 12:45:37 +03:00
1993-12-09 22:06:03 +03:00
mkdata( ABS( tecbck[i] ) );
1993-12-02 22:17:24 +03:00
}
1993-03-21 12:45:37 +03:00
1993-12-02 22:17:24 +03:00
dataend();
}
1993-03-21 12:45:37 +03:00
1993-12-02 22:17:24 +03:00
total_states = lastdfa + numtemps;
1993-03-21 12:45:37 +03:00
1995-05-05 09:35:08 +04:00
out_str_dec( (tblend >= MAX_SHORT || long_align) ?
1993-12-02 22:17:24 +03:00
C_long_decl : C_short_decl,
"yy_base", total_states + 1 );
1993-03-21 12:45:37 +03:00
1993-12-02 22:17:24 +03:00
for ( i = 1; i <= lastdfa; ++i )
{
register int d = def[i];
1993-03-21 12:45:37 +03:00
1993-12-02 22:17:24 +03:00
if ( base[i] == JAMSTATE )
base[i] = jambase;
1993-03-21 12:45:37 +03:00
1993-12-02 22:17:24 +03:00
if ( d == JAMSTATE )
def[i] = jamstate;
1993-03-21 12:45:37 +03:00
1993-12-02 22:17:24 +03:00
else if ( d < 0 )
{
/* Template reference. */
++tmpuses;
def[i] = lastdfa - d + 1;
}
1993-03-21 12:45:37 +03:00
1993-12-02 22:17:24 +03:00
mkdata( base[i] );
}
1993-03-21 12:45:37 +03:00
1993-12-02 22:17:24 +03:00
/* Generate jam state's base index. */
1993-03-21 12:45:37 +03:00
mkdata( base[i] );
1993-12-02 22:17:24 +03:00
for ( ++i /* skip jam state */; i <= total_states; ++i )
{
mkdata( base[i] );
def[i] = jamstate;
}
1993-03-21 12:45:37 +03:00
1993-12-02 22:17:24 +03:00
dataend();
1993-03-21 12:45:37 +03:00
1995-05-05 09:35:08 +04:00
out_str_dec( (total_states >= MAX_SHORT || long_align) ?
1993-12-02 22:17:24 +03:00
C_long_decl : C_short_decl,
"yy_def", total_states + 1 );
1993-03-21 12:45:37 +03:00
1993-12-02 22:17:24 +03:00
for ( i = 1; i <= total_states; ++i )
mkdata( def[i] );
1993-03-21 12:45:37 +03:00
1993-12-02 22:17:24 +03:00
dataend();
1993-03-21 12:45:37 +03:00
1995-05-05 09:35:08 +04:00
out_str_dec( (total_states >= MAX_SHORT || long_align) ?
1993-12-02 22:17:24 +03:00
C_long_decl : C_short_decl,
"yy_nxt", tblend + 1 );
1993-03-21 12:45:37 +03:00
1993-12-02 22:17:24 +03:00
for ( i = 1; i <= tblend; ++i )
{
1995-05-05 09:35:08 +04:00
/* Note, the order of the following test is important.
* If chk[i] is 0, then nxt[i] is undefined.
*/
if ( chk[i] == 0 || nxt[i] == 0 )
1993-12-02 22:17:24 +03:00
nxt[i] = jamstate; /* new state is the JAM state */
1993-03-21 12:45:37 +03:00
1993-12-02 22:17:24 +03:00
mkdata( nxt[i] );
}
1993-03-21 12:45:37 +03:00
1993-12-02 22:17:24 +03:00
dataend();
1993-03-21 12:45:37 +03:00
1995-05-05 09:35:08 +04:00
out_str_dec( (total_states >= MAX_SHORT || long_align) ?
1993-12-02 22:17:24 +03:00
C_long_decl : C_short_decl,
"yy_chk", tblend + 1 );
1993-03-21 12:45:37 +03:00
1993-12-02 22:17:24 +03:00
for ( i = 1; i <= tblend; ++i )
{
if ( chk[i] == 0 )
++nummt;
mkdata( chk[i] );
}
1993-03-21 12:45:37 +03:00
1993-12-02 22:17:24 +03:00
dataend();
1998-10-11 00:48:04 +04:00
free(acc_array);
1993-12-02 22:17:24 +03:00
}
1993-03-21 12:45:37 +03:00
1993-12-02 22:17:24 +03:00
/* Write out a formatted string (with a secondary string argument) at the
* current indentation level, adding a final newline.
1993-03-21 12:45:37 +03:00
*/
void indent_put2s( fmt, arg )
char fmt[], arg[];
1993-12-02 22:17:24 +03:00
{
do_indent();
1995-05-05 09:35:08 +04:00
out_str( fmt, arg );
outn( "" );
1993-12-02 22:17:24 +03:00
}
1993-03-21 12:45:37 +03:00
1993-12-02 22:17:24 +03:00
/* Write out a string at the current indentation level, adding a final
* newline.
1993-03-21 12:45:37 +03:00
*/
void indent_puts( str )
char str[];
1993-12-02 22:17:24 +03:00
{
do_indent();
1995-05-05 09:35:08 +04:00
outn( str );
1993-12-02 22:17:24 +03:00
}
1993-03-21 12:45:37 +03:00
1993-12-02 22:17:24 +03:00
/* make_tables - generate transition tables and finishes generating output file
1993-03-21 12:45:37 +03:00
*/
void make_tables()
{
1993-12-02 22:17:24 +03:00
register int i;
int did_eof_rule = false;
1993-03-21 12:45:37 +03:00
1993-12-02 22:17:24 +03:00
skelout();
1993-03-21 12:45:37 +03:00
1993-12-02 22:17:24 +03:00
/* First, take care of YY_DO_BEFORE_ACTION depending on yymore
* being used.
*/
set_indent( 1 );
1993-03-21 12:45:37 +03:00
1996-12-10 10:18:37 +03:00
if ( yymore_used && ! yytext_is_array )
1993-12-02 22:17:24 +03:00
{
indent_puts( "yytext_ptr -= yy_more_len; \\" );
1995-05-05 09:35:08 +04:00
indent_puts( "yyleng = (int) (yy_cp - yytext_ptr); \\" );
1993-12-02 22:17:24 +03:00
}
1993-03-21 12:45:37 +03:00
1993-12-02 22:17:24 +03:00
else
1995-05-05 09:35:08 +04:00
indent_puts( "yyleng = (int) (yy_cp - yy_bp); \\" );
1993-03-21 12:45:37 +03:00
1993-12-02 22:17:24 +03:00
/* Now also deal with copying yytext_ptr to yytext if needed. */
skelout();
if ( yytext_is_array )
{
1996-12-10 10:18:37 +03:00
if ( yymore_used )
indent_puts(
"if ( yyleng + yy_more_offset >= YYLMAX ) \\" );
else
indent_puts( "if ( yyleng >= YYLMAX ) \\" );
1993-12-02 22:17:24 +03:00
indent_up();
indent_puts(
"YY_FATAL_ERROR( \"token too large, exceeds YYLMAX\" ); \\" );
indent_down();
1996-12-10 10:18:37 +03:00
if ( yymore_used )
{
indent_puts(
"yy_flex_strncpy( &yytext[yy_more_offset], yytext_ptr, yyleng + 1 ); \\" );
indent_puts( "yyleng += yy_more_offset; \\" );
indent_puts(
"yy_prev_more_offset = yy_more_offset; \\" );
indent_puts( "yy_more_offset = 0; \\" );
}
else
{
indent_puts(
1994-08-19 20:22:11 +04:00
"yy_flex_strncpy( yytext, yytext_ptr, yyleng + 1 ); \\" );
1996-12-10 10:18:37 +03:00
}
1993-12-02 22:17:24 +03:00
}
1993-03-21 12:45:37 +03:00
set_indent( 0 );
1993-12-02 22:17:24 +03:00
skelout();
1993-03-21 12:45:37 +03:00
1995-05-05 09:35:08 +04:00
out_dec( "#define YY_NUM_RULES %d\n", num_rules );
out_dec( "#define YY_END_OF_BUFFER %d\n", num_rules + 1 );
1993-03-21 12:45:37 +03:00
1993-12-02 22:17:24 +03:00
if ( fullspd )
{
/* Need to define the transet type as a size large
* enough to hold the biggest offset.
*/
int total_table_size = tblend + numecs + 1;
char *trans_offset_type =
(total_table_size >= MAX_SHORT || long_align) ?
"long" : "short";
set_indent( 0 );
indent_puts( "struct yy_trans_info" );
indent_up();
indent_puts( "{" ); /* } for vi */
if ( long_align )
indent_puts( "long yy_verify;" );
else
indent_puts( "short yy_verify;" );
/* In cases where its sister yy_verify *is* a "yes, there is
* a transition", yy_nxt is the offset (in records) to the
* next state. In most cases where there is no transition,
* the value of yy_nxt is irrelevant. If yy_nxt is the -1th
* record of a state, though, then yy_nxt is the action number
* for that state.
*/
indent_put2s( "%s yy_nxt;", trans_offset_type );
indent_puts( "};" );
indent_down();
}
1993-03-21 12:45:37 +03:00
1993-12-02 22:17:24 +03:00
if ( fullspd )
genctbl();
else if ( fulltbl )
genftbl();
else
gentabs();
1993-03-21 12:45:37 +03:00
1993-12-02 22:17:24 +03:00
/* Definitions for backing up. We don't need them if REJECT
* is being used because then we use an alternative backin-up
* technique instead.
*/
if ( num_backing_up > 0 && ! reject )
1993-03-21 12:45:37 +03:00
{
1993-12-02 22:17:24 +03:00
if ( ! C_plus_plus )
{
indent_puts(
"static yy_state_type yy_last_accepting_state;" );
indent_puts(
"static char *yy_last_accepting_cpos;\n" );
}
1993-03-21 12:45:37 +03:00
}
1993-12-02 22:17:24 +03:00
if ( nultrans )
{
1995-05-05 09:35:08 +04:00
out_str_dec( C_state_decl, "yy_NUL_trans", lastdfa + 1 );
1993-03-21 12:45:37 +03:00
1993-12-02 22:17:24 +03:00
for ( i = 1; i <= lastdfa; ++i )
{
if ( fullspd )
1995-05-05 09:35:08 +04:00
out_dec( " &yy_transition[%d],\n", base[i] );
1993-12-02 22:17:24 +03:00
else
mkdata( nultrans[i] );
}
1993-03-21 12:45:37 +03:00
1993-12-02 22:17:24 +03:00
dataend();
}
1993-03-21 12:45:37 +03:00
1993-12-02 22:17:24 +03:00
if ( ddebug )
{ /* Spit out table mapping rules to line numbers. */
1995-05-05 09:35:08 +04:00
if ( ! C_plus_plus )
{
indent_puts( "extern int yy_flex_debug;" );
indent_puts( "int yy_flex_debug = 1;\n" );
}
1993-12-02 22:17:24 +03:00
1995-05-05 09:35:08 +04:00
out_str_dec( long_align ? C_long_decl : C_short_decl,
1993-12-02 22:17:24 +03:00
"yy_rule_linenum", num_rules );
for ( i = 1; i < num_rules; ++i )
mkdata( rule_linenum[i] );
dataend();
}
if ( reject )
{
/* Declare state buffer variables. */
if ( ! C_plus_plus )
{
1995-05-05 09:35:08 +04:00
outn(
1993-03-21 12:45:37 +03:00
"static yy_state_type yy_state_buf[YY_BUF_SIZE + 2], *yy_state_ptr;" );
1995-05-05 09:35:08 +04:00
outn( "static char *yy_full_match;" );
outn( "static int yy_lp;" );
1993-12-02 22:17:24 +03:00
}
if ( variable_trailing_context_rules )
{
if ( ! C_plus_plus )
{
1995-05-05 09:35:08 +04:00
outn(
1993-12-02 22:17:24 +03:00
"static int yy_looking_for_trail_begin = 0;" );
1995-05-05 09:35:08 +04:00
outn( "static int yy_full_lp;" );
outn( "static int *yy_full_state;" );
1993-12-02 22:17:24 +03:00
}
1995-05-05 09:35:08 +04:00
out_hex( "#define YY_TRAILING_MASK 0x%x\n",
1993-12-02 22:17:24 +03:00
(unsigned int) YY_TRAILING_MASK );
1995-05-05 09:35:08 +04:00
out_hex( "#define YY_TRAILING_HEAD_MASK 0x%x\n",
1993-12-02 22:17:24 +03:00
(unsigned int) YY_TRAILING_HEAD_MASK );
}
1995-05-05 09:35:08 +04:00
outn( "#define REJECT \\" );
outn( "{ \\" ); /* } for vi */
outn(
1993-03-21 12:45:37 +03:00
"*yy_cp = yy_hold_char; /* undo effects of setting up yytext */ \\" );
1995-05-05 09:35:08 +04:00
outn(
1993-12-02 22:17:24 +03:00
"yy_cp = yy_full_match; /* restore poss. backed-over text */ \\" );
1993-03-21 12:45:37 +03:00
1993-12-02 22:17:24 +03:00
if ( variable_trailing_context_rules )
{
1995-05-05 09:35:08 +04:00
outn(
1993-12-02 22:17:24 +03:00
"yy_lp = yy_full_lp; /* restore orig. accepting pos. */ \\" );
1995-05-05 09:35:08 +04:00
outn(
1993-03-21 12:45:37 +03:00
"yy_state_ptr = yy_full_state; /* restore orig. state */ \\" );
1995-05-05 09:35:08 +04:00
outn(
1993-12-02 22:17:24 +03:00
"yy_current_state = *yy_state_ptr; /* restore curr. state */ \\" );
}
1993-03-21 12:45:37 +03:00
1995-05-05 09:35:08 +04:00
outn( "++yy_lp; \\" );
outn( "goto find_rule; \\" );
1993-12-02 22:17:24 +03:00
/* { for vi */
1995-05-05 09:35:08 +04:00
outn( "}" );
1993-12-02 22:17:24 +03:00
}
1993-03-21 12:45:37 +03:00
1993-12-02 22:17:24 +03:00
else
{
1995-05-05 09:35:08 +04:00
outn(
1993-12-02 22:17:24 +03:00
"/* The intent behind this definition is that it'll catch" );
1995-05-05 09:35:08 +04:00
outn( " * any uses of REJECT which flex missed." );
outn( " */" );
outn( "#define REJECT reject_used_but_not_detected" );
1993-12-02 22:17:24 +03:00
}
1993-03-21 12:45:37 +03:00
1993-12-02 22:17:24 +03:00
if ( yymore_used )
{
if ( ! C_plus_plus )
{
1996-12-10 10:18:37 +03:00
if ( yytext_is_array )
{
indent_puts( "static int yy_more_offset = 0;" );
indent_puts(
"static int yy_prev_more_offset = 0;" );
}
else
{
indent_puts( "static int yy_more_flag = 0;" );
indent_puts( "static int yy_more_len = 0;" );
}
1993-12-02 22:17:24 +03:00
}
1993-03-21 12:45:37 +03:00
1996-12-10 10:18:37 +03:00
if ( yytext_is_array )
{
indent_puts(
"#define yymore() (yy_more_offset = yy_flex_strlen( yytext ))" );
indent_puts( "#define YY_NEED_STRLEN" );
indent_puts( "#define YY_MORE_ADJ 0" );
indent_puts( "#define YY_RESTORE_YY_MORE_OFFSET \\" );
indent_up();
indent_puts( "{ \\" );
indent_puts( "yy_more_offset = yy_prev_more_offset; \\" );
indent_puts( "yyleng -= yy_more_offset; \\" );
indent_puts( "}" );
indent_down();
}
else
{
indent_puts( "#define yymore() (yy_more_flag = 1)" );
indent_puts( "#define YY_MORE_ADJ yy_more_len" );
indent_puts( "#define YY_RESTORE_YY_MORE_OFFSET" );
}
1993-12-02 22:17:24 +03:00
}
1993-03-21 12:45:37 +03:00
1993-12-02 22:17:24 +03:00
else
{
indent_puts( "#define yymore() yymore_used_but_not_detected" );
indent_puts( "#define YY_MORE_ADJ 0" );
1996-12-10 10:18:37 +03:00
indent_puts( "#define YY_RESTORE_YY_MORE_OFFSET" );
1993-12-02 22:17:24 +03:00
}
1993-03-21 12:45:37 +03:00
1993-12-02 22:17:24 +03:00
if ( ! C_plus_plus )
{
if ( yytext_is_array )
{
1995-05-05 09:35:08 +04:00
outn( "#ifndef YYLMAX" );
outn( "#define YYLMAX 8192" );
outn( "#endif\n" );
outn( "char yytext[YYLMAX];" );
outn( "char *yytext_ptr;" );
1993-12-02 22:17:24 +03:00
}
1993-03-21 12:45:37 +03:00
1993-12-02 22:17:24 +03:00
else
1995-05-05 09:35:08 +04:00
outn( "char *yytext;" );
1993-12-02 22:17:24 +03:00
}
1993-03-21 12:45:37 +03:00
1995-05-05 09:35:08 +04:00
out( &action_array[defs1_offset] );
line_directive_out( stdout, 0 );
1993-03-21 12:45:37 +03:00
1993-12-02 22:17:24 +03:00
skelout();
1993-03-21 12:45:37 +03:00
1993-12-02 22:17:24 +03:00
if ( ! C_plus_plus )
{
if ( use_read )
{
1995-05-05 09:35:08 +04:00
outn(
"\tif ( (result = read( fileno(yyin), (char *) buf, max_size )) < 0 ) \\" );
outn(
"\t\tYY_FATAL_ERROR( \"input in flex scanner failed\" );" );
1993-12-02 22:17:24 +03:00
}
1993-03-21 12:45:37 +03:00
1993-12-02 22:17:24 +03:00
else
{
1995-05-05 09:35:08 +04:00
outn(
"\tif ( yy_current_buffer->yy_is_interactive ) \\" );
outn( "\t\t{ \\" );
outn( "\t\tint c = '*', n; \\" );
outn( "\t\tfor ( n = 0; n < max_size && \\" );
outn( "\t\t\t (c = getc( yyin )) != EOF && c != '\\n'; ++n ) \\" );
outn( "\t\t\tbuf[n] = (char) c; \\" );
outn( "\t\tif ( c == '\\n' ) \\" );
outn( "\t\t\tbuf[n++] = (char) c; \\" );
outn( "\t\tif ( c == EOF && ferror( yyin ) ) \\" );
outn(
"\t\t\tYY_FATAL_ERROR( \"input in flex scanner failed\" ); \\" );
outn( "\t\tresult = n; \\" );
outn( "\t\t} \\" );
outn(
"\telse if ( ((result = fread( buf, 1, max_size, yyin )) == 0) \\" );
outn( "\t\t && ferror( yyin ) ) \\" );
outn(
"\t\tYY_FATAL_ERROR( \"input in flex scanner failed\" );" );
1993-12-02 22:17:24 +03:00
}
}
1993-03-21 12:45:37 +03:00
1993-12-02 22:17:24 +03:00
skelout();
1993-03-21 12:45:37 +03:00
1995-05-05 09:35:08 +04:00
indent_puts( "#define YY_RULE_SETUP \\" );
indent_up();
if ( bol_needed )
{
indent_puts( "if ( yyleng > 0 ) \\" );
indent_up();
indent_puts( "yy_current_buffer->yy_at_bol = \\" );
indent_puts( "\t\t(yytext[yyleng - 1] == '\\n'); \\" );
indent_down();
}
indent_puts( "YY_USER_ACTION" );
indent_down();
skelout();
1993-12-02 22:17:24 +03:00
/* Copy prolog to output file. */
1995-05-05 09:35:08 +04:00
out( &action_array[prolog_offset] );
line_directive_out( stdout, 0 );
1993-03-21 12:45:37 +03:00
1993-12-02 22:17:24 +03:00
skelout();
1993-03-21 12:45:37 +03:00
1993-12-02 22:17:24 +03:00
set_indent( 2 );
1993-03-21 12:45:37 +03:00
1996-12-10 10:18:37 +03:00
if ( yymore_used && ! yytext_is_array )
1993-12-02 22:17:24 +03:00
{
indent_puts( "yy_more_len = 0;" );
indent_puts( "if ( yy_more_flag )" );
indent_up();
indent_puts( "{" );
1996-12-10 10:18:37 +03:00
indent_puts( "yy_more_len = yy_c_buf_p - yytext_ptr;" );
1993-12-02 22:17:24 +03:00
indent_puts( "yy_more_flag = 0;" );
indent_puts( "}" );
indent_down();
}
1993-03-21 12:45:37 +03:00
1993-12-02 22:17:24 +03:00
skelout();
1993-03-21 12:45:37 +03:00
1993-12-02 22:17:24 +03:00
gen_start_state();
/* Note, don't use any indentation. */
1995-05-05 09:35:08 +04:00
outn( "yy_match:" );
1993-12-02 22:17:24 +03:00
gen_next_match();
skelout();
set_indent( 2 );
gen_find_action();
skelout();
1995-05-05 09:35:08 +04:00
if ( do_yylineno )
1993-12-02 22:17:24 +03:00
{
indent_puts( "if ( yy_act != YY_END_OF_BUFFER )" );
indent_up();
indent_puts( "{" );
indent_puts( "int yyl;" );
indent_puts( "for ( yyl = 0; yyl < yyleng; ++yyl )" );
indent_up();
indent_puts( "if ( yytext[yyl] == '\\n' )" );
indent_up();
indent_puts( "++yylineno;" );
indent_down();
indent_down();
indent_puts( "}" );
indent_down();
}
skelout();
if ( ddebug )
{
indent_puts( "if ( yy_flex_debug )" );
indent_up();
indent_puts( "{" );
indent_puts( "if ( yy_act == 0 )" );
indent_up();
1995-05-05 09:35:08 +04:00
indent_puts( C_plus_plus ?
"cerr << \"--scanner backing up\\n\";" :
1993-12-02 22:17:24 +03:00
"fprintf( stderr, \"--scanner backing up\\n\" );" );
indent_down();
do_indent();
1995-05-05 09:35:08 +04:00
out_dec( "else if ( yy_act < %d )\n", num_rules );
1993-12-02 22:17:24 +03:00
indent_up();
1995-05-05 09:35:08 +04:00
if ( C_plus_plus )
{
indent_puts(
"cerr << \"--accepting rule at line \" << yy_rule_linenum[yy_act] <<" );
indent_puts(
" \"(\\\"\" << yytext << \"\\\")\\n\";" );
}
else
{
indent_puts(
1993-03-21 12:45:37 +03:00
"fprintf( stderr, \"--accepting rule at line %d (\\\"%s\\\")\\n\"," );
1995-05-05 09:35:08 +04:00
indent_puts(
" yy_rule_linenum[yy_act], yytext );" );
}
1993-12-02 22:17:24 +03:00
indent_down();
1993-03-21 12:45:37 +03:00
1993-12-02 22:17:24 +03:00
do_indent();
1995-05-05 09:35:08 +04:00
out_dec( "else if ( yy_act == %d )\n", num_rules );
1993-12-02 22:17:24 +03:00
indent_up();
1995-05-05 09:35:08 +04:00
if ( C_plus_plus )
{
indent_puts(
"cerr << \"--accepting default rule (\\\"\" << yytext << \"\\\")\\n\";" );
}
else
{
indent_puts(
1993-03-21 12:45:37 +03:00
"fprintf( stderr, \"--accepting default rule (\\\"%s\\\")\\n\"," );
1995-05-05 09:35:08 +04:00
indent_puts( " yytext );" );
}
1993-12-02 22:17:24 +03:00
indent_down();
do_indent();
1995-05-05 09:35:08 +04:00
out_dec( "else if ( yy_act == %d )\n", num_rules + 1 );
1993-12-02 22:17:24 +03:00
indent_up();
1995-05-05 09:35:08 +04:00
indent_puts( C_plus_plus ?
"cerr << \"--(end of buffer or a NUL)\\n\";" :
"fprintf( stderr, \"--(end of buffer or a NUL)\\n\" );" );
1993-12-02 22:17:24 +03:00
indent_down();
do_indent();
1995-05-05 09:35:08 +04:00
outn( "else" );
1993-12-02 22:17:24 +03:00
indent_up();
1995-05-05 09:35:08 +04:00
if ( C_plus_plus )
{
indent_puts(
"cerr << \"--EOF (start condition \" << YY_START << \")\\n\";" );
}
else
{
indent_puts(
1993-12-02 22:17:24 +03:00
"fprintf( stderr, \"--EOF (start condition %d)\\n\", YY_START );" );
1995-05-05 09:35:08 +04:00
}
1993-12-02 22:17:24 +03:00
indent_down();
indent_puts( "}" );
indent_down();
}
1993-03-21 12:45:37 +03:00
1993-12-02 22:17:24 +03:00
/* Copy actions to output file. */
skelout();
1993-03-21 12:45:37 +03:00
indent_up();
1993-12-02 22:17:24 +03:00
gen_bu_action();
1995-05-05 09:35:08 +04:00
out( &action_array[action_offset] );
line_directive_out( stdout, 0 );
1993-03-21 12:45:37 +03:00
1993-12-02 22:17:24 +03:00
/* generate cases for any missing EOF rules */
for ( i = 1; i <= lastsc; ++i )
if ( ! sceof[i] )
{
do_indent();
1995-05-05 09:35:08 +04:00
out_str( "case YY_STATE_EOF(%s):\n", scname[i] );
1993-12-02 22:17:24 +03:00
did_eof_rule = true;
}
1993-03-21 12:45:37 +03:00
1993-12-02 22:17:24 +03:00
if ( did_eof_rule )
{
indent_up();
indent_puts( "yyterminate();" );
indent_down();
}
1993-03-21 12:45:37 +03:00
1993-12-02 22:17:24 +03:00
/* Generate code for handling NUL's, if needed. */
1993-03-21 12:45:37 +03:00
1993-12-02 22:17:24 +03:00
/* First, deal with backing up and setting up yy_cp if the scanner
1994-08-19 20:22:11 +04:00
* finds that it should JAM on the NUL.
1993-12-02 22:17:24 +03:00
*/
skelout();
1995-05-05 09:35:08 +04:00
set_indent( 4 );
1993-12-02 22:17:24 +03:00
if ( fullspd || fulltbl )
indent_puts( "yy_cp = yy_c_buf_p;" );
else
{ /* compressed table */
if ( ! reject && ! interactive )
{
/* Do the guaranteed-needed backing up to figure
* out the match.
*/
indent_puts( "yy_cp = yy_last_accepting_cpos;" );
indent_puts(
"yy_current_state = yy_last_accepting_state;" );
}
1994-08-19 20:22:11 +04:00
else
/* Still need to initialize yy_cp, though
* yy_current_state was set up by
* yy_get_previous_state().
*/
indent_puts( "yy_cp = yy_c_buf_p;" );
1993-12-02 22:17:24 +03:00
}
1993-03-21 12:45:37 +03:00
1993-12-02 22:17:24 +03:00
/* Generate code for yy_get_previous_state(). */
set_indent( 1 );
skelout();
1993-03-21 12:45:37 +03:00
1993-12-02 22:17:24 +03:00
gen_start_state();
1993-03-21 12:45:37 +03:00
1993-12-02 22:17:24 +03:00
set_indent( 2 );
skelout();
gen_next_state( true );
1993-03-21 12:45:37 +03:00
1993-12-02 22:17:24 +03:00
set_indent( 1 );
skelout();
gen_NUL_trans();
1993-03-21 12:45:37 +03:00
1993-12-02 22:17:24 +03:00
skelout();
1995-05-05 09:35:08 +04:00
if ( do_yylineno )
1993-12-02 22:17:24 +03:00
{ /* update yylineno inside of unput() */
indent_puts( "if ( c == '\\n' )" );
indent_up();
indent_puts( "--yylineno;" );
indent_down();
}
1993-03-21 12:45:37 +03:00
1995-05-05 09:35:08 +04:00
skelout();
/* Update BOL and yylineno inside of input(). */
if ( bol_needed )
{
indent_puts( "yy_current_buffer->yy_at_bol = (c == '\\n');" );
if ( do_yylineno )
{
indent_puts( "if ( yy_current_buffer->yy_at_bol )" );
indent_up();
indent_puts( "++yylineno;" );
indent_down();
}
}
else if ( do_yylineno )
{
indent_puts( "if ( c == '\\n' )" );
indent_up();
indent_puts( "++yylineno;" );
indent_down();
}
1993-12-02 22:17:24 +03:00
skelout();
1993-03-21 12:45:37 +03:00
1993-12-02 22:17:24 +03:00
/* Copy remainder of input to output. */
1995-05-05 09:35:08 +04:00
line_directive_out( stdout, 1 );
1993-12-02 22:17:24 +03:00
if ( sectnum == 3 )
(void) flexscan(); /* copy remainder of input to output */
}