summaryrefslogtreecommitdiff
path: root/gen.c
diff options
context:
space:
mode:
authorVern Paxson <vern@ee.lbl.gov>1993-04-14 22:41:35 +0000
committerVern Paxson <vern@ee.lbl.gov>1993-04-14 22:41:35 +0000
commitda65ac15e3bf4e7391dc967aed49394798d21bf5 (patch)
treea902cd44cadb4d8e8e5a3901b244dad56a852aae /gen.c
parent38bb4c0fcd54539764cf2db73d3cc58d60cdc579 (diff)
Reformatting.
Diffstat (limited to 'gen.c')
-rw-r--r--gen.c1974
1 files changed, 997 insertions, 977 deletions
diff --git a/gen.c b/gen.c
index b1f6e98..db3f4a1 100644
--- a/gen.c
+++ b/gen.c
@@ -42,14 +42,14 @@ void indent_put2s PROTO((char [], char []));
void indent_puts PROTO((char []));
-static int indent_level = 0; /* each level is 4 spaces */
+static int indent_level = 0; /* each level is 8 spaces */
#define indent_up() (++indent_level)
#define indent_down() (--indent_level)
#define set_indent(indent_val) indent_level = indent_val
-/* *everything* is done in terms of arrays starting at 1, so provide
- * a null entry for the zero element of all C arrays
+/* *Everything* is done in terms of arrays starting at 1, so provide
+ * a null entry for the zero element of all C arrays.
*/
static char C_short_decl[] = "static const short int %s[%d] =\n { 0,\n";
static char C_long_decl[] = "static const long int %s[%d] =\n { 0,\n";
@@ -57,1278 +57,1298 @@ static char C_state_decl[] =
"static const yy_state_type %s[%d] =\n { 0,\n";
-/* indent to the current level */
+/* Indent to the current level. */
void do_indent()
+ {
+ register int i = indent_level * 8;
- {
- register int i = indent_level * 4;
+ while ( i >= 8 )
+ {
+ putchar( '\t' );
+ i -= 8;
+ }
- while ( i >= 8 )
- {
- putchar( '\t' );
- i -= 8;
- }
-
- while ( i > 0 )
- {
- putchar( ' ' );
- --i;
+ while ( i > 0 )
+ {
+ putchar( ' ' );
+ --i;
+ }
}
- }
-/* generate the code to keep backtracking information */
+/* Generate the code to keep backtracking information. */
void gen_backtracking()
+ {
+ if ( reject || num_backtracking == 0 )
+ return;
- {
- if ( reject || num_backtracking == 0 )
- return;
-
- if ( fullspd )
- indent_puts( "if ( yy_current_state[-1].yy_nxt )" );
- else
- indent_puts( "if ( yy_accept[yy_current_state] )" );
+ if ( fullspd )
+ indent_puts( "if ( yy_current_state[-1].yy_nxt )" );
+ else
+ indent_puts( "if ( yy_accept[yy_current_state] )" );
- 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();
- }
+ 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();
+ }
-/* generate the code to perform the backtrack */
+/* Generate the code to perform the backtrack. */
void gen_bt_action()
+ {
+ if ( reject || num_backtracking == 0 )
+ return;
- {
- if ( reject || num_backtracking == 0 )
- return;
-
- set_indent( 3 );
+ set_indent( 3 );
- indent_puts( "case 0: /* must backtrack */" );
- indent_puts( "/* undo the effects of YY_DO_BEFORE_ACTION */" );
- indent_puts( "*yy_cp = yy_hold_char;" );
+ indent_puts( "case 0: /* must backtrack */" );
+ indent_puts( "/* undo the effects of YY_DO_BEFORE_ACTION */" );
+ indent_puts( "*yy_cp = yy_hold_char;" );
- if ( fullspd || fulltbl )
- indent_puts( "yy_cp = yy_last_accepting_cpos + 1;" );
- else
- /* backtracking info for compressed tables is taken \after/
- * yy_cp has been incremented for the next state
- */
- indent_puts( "yy_cp = yy_last_accepting_cpos;" );
+ if ( fullspd || fulltbl )
+ indent_puts( "yy_cp = yy_last_accepting_cpos + 1;" );
+ else
+ /* Backtracking info for compressed tables is taken \after/
+ * yy_cp has been incremented for the next state.
+ */
+ indent_puts( "yy_cp = yy_last_accepting_cpos;" );
- indent_puts( "yy_current_state = yy_last_accepting_state;" );
- indent_puts( "goto yy_find_action;" );
- putchar( '\n' );
+ indent_puts( "yy_current_state = yy_last_accepting_state;" );
+ indent_puts( "goto yy_find_action;" );
+ putchar( '\n' );
- set_indent( 0 );
- }
+ set_indent( 0 );
+ }
-/* genctbl - generates full speed compressed transition table
- *
- * synopsis
- * genctbl();
- */
+/* genctbl - generates full speed compressed transition table */
void genctbl()
-
- {
- register int i;
- int end_of_buffer_action = num_rules + 1;
-
- /* table of verify for transition and offset to next state */
- printf( "static const struct yy_trans_info yy_transition[%d] =\n",
- tblend + numecs + 1 );
- printf( " {\n" );
-
- /* 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[chk[i]]. 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.
- */
- /* at this point, we're guaranteed that there's enough room in nxt[]
- * and chk[] to hold tblend + numecs entries. We need just two 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.
- */
-
- base[lastdfa + 1] = tblend + 2;
- nxt[tblend + 1] = end_of_buffer_action;
- chk[tblend + 1] = numecs + 1;
- chk[tblend + 2] = 1; /* anything but EOB */
- nxt[tblend + 2] = 0; /* so that "make test" won't show arb. differences */
-
- /* make sure every state has a end-of-buffer transition and an action # */
- for ( i = 0; i <= lastdfa; ++i )
{
- register int anum = dfaacc[i].dfaacc_state;
+ register int i;
+ int end_of_buffer_action = num_rules + 1;
+
+ /* Table of verify for transition and offset to next state. */
+ printf( "static const struct yy_trans_info yy_transition[%d] =\n",
+ tblend + numecs + 1 );
+ printf( " {\n" );
+
+ /* 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[chk[i]]. 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.
+ */
- chk[base[i]] = EOB_POSITION;
- chk[base[i] - 1] = ACTION_POSITION;
- nxt[base[i] - 1] = anum; /* action number */
- }
+ /* At this point, we're guaranteed that there's enough room in nxt[]
+ * and chk[] to hold tblend + numecs entries. We need just two 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.
+ */
- for ( i = 0; i <= tblend; ++i )
- {
- if ( chk[i] == EOB_POSITION )
- transition_struct_out( 0, base[lastdfa + 1] - i );
+ base[lastdfa + 1] = tblend + 2;
+ nxt[tblend + 1] = end_of_buffer_action;
+ chk[tblend + 1] = numecs + 1;
+ chk[tblend + 2] = 1; /* anything but EOB */
- else if ( chk[i] == ACTION_POSITION )
- transition_struct_out( 0, nxt[i] );
+ /* So that "make test" won't show arb. differences. */
+ nxt[tblend + 2] = 0;
- else if ( chk[i] > numecs || chk[i] == 0 )
- transition_struct_out( 0, 0 ); /* unused slot */
+ /* Make sure every state has a end-of-buffer transition and an
+ * action #.
+ */
+ for ( i = 0; i <= lastdfa; ++i )
+ {
+ register int anum = dfaacc[i].dfaacc_state;
- else /* verify, transition */
- transition_struct_out( chk[i], base[nxt[i]] - (i - chk[i]) );
- }
+ chk[base[i]] = EOB_POSITION;
+ chk[base[i] - 1] = ACTION_POSITION;
+ nxt[base[i] - 1] = anum; /* action number */
+ }
+ for ( i = 0; i <= tblend; ++i )
+ {
+ if ( chk[i] == EOB_POSITION )
+ transition_struct_out( 0, base[lastdfa + 1] - i );
- /* 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] );
+ else if ( chk[i] == ACTION_POSITION )
+ transition_struct_out( 0, nxt[i] );
- printf( " };\n" );
- printf( "\n" );
+ else if ( chk[i] > numecs || chk[i] == 0 )
+ transition_struct_out( 0, 0 ); /* unused slot */
- /* table of pointers to start states */
- printf( "static const struct yy_trans_info *yy_start_state_list[%d] =\n",
- lastsc * 2 + 1 );
- printf( " {\n" );
+ else /* verify, transition */
+ transition_struct_out( chk[i],
+ base[nxt[i]] - (i - chk[i]) );
+ }
- for ( i = 0; i <= lastsc * 2; ++i )
- printf( " &yy_transition[%d],\n", base[i] );
- dataend();
+ /* 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] );
- if ( useecs )
- genecs();
- }
+ printf( " };\n" );
+ printf( "\n" );
+ /* Table of pointers to start states. */
+ printf(
+ "static const struct yy_trans_info *yy_start_state_list[%d] =\n",
+ lastsc * 2 + 1 );
+ printf( " {\n" ); /* } so vi doesn't get confused */
-/* generate equivalence-class tables */
+ for ( i = 0; i <= lastsc * 2; ++i )
+ printf( " &yy_transition[%d],\n", base[i] );
-void genecs()
+ dataend();
+
+ if ( useecs )
+ genecs();
+ }
- {
- register int i, j;
- static char C_char_decl[] = "static const %s %s[%d] =\n { 0,\n";
- int numrows;
- Char clower();
- if ( numecs < csize )
- printf( C_char_decl, "YY_CHAR", "yy_ec", csize );
- else
- printf( C_char_decl, "short", "yy_ec", csize );
+/* Generate equivalence-class tables. */
- for ( i = 1; i < csize; ++i )
+void genecs()
{
- if ( caseins && (i >= 'A') && (i <= 'Z') )
- ecgroup[i] = ecgroup[clower( i )];
+ Char clower();
+ static char C_char_decl[] = "static const %s %s[%d] =\n { 0,\n";
+ /* } so vi doesn't get confused */
+ register int i, j;
+ int numrows;
+
+ if ( numecs < csize )
+ printf( C_char_decl, "YY_CHAR", "yy_ec", csize );
+ else
+ printf( C_char_decl, "short", "yy_ec", csize );
- ecgroup[i] = abs( ecgroup[i] );
- mkdata( ecgroup[i] );
- }
+ for ( i = 1; i < csize; ++i )
+ {
+ if ( caseins && (i >= 'A') && (i <= 'Z') )
+ ecgroup[i] = ecgroup[clower( i )];
- dataend();
+ ecgroup[i] = abs( ecgroup[i] );
+ mkdata( ecgroup[i] );
+ }
- if ( trace )
- {
- char *readable_form();
+ dataend();
- fputs( "\n\nEquivalence Classes:\n\n", stderr );
+ if ( trace )
+ {
+ char *readable_form();
- numrows = csize / 8;
+ fputs( "\n\nEquivalence Classes:\n\n", stderr );
- for ( j = 0; j < numrows; ++j )
- {
- for ( i = j; i < csize; i = i + numrows )
- {
- fprintf( stderr, "%4s = %-2d", readable_form( i ), ecgroup[i] );
+ numrows = csize / 8;
- putc( ' ', stderr );
- }
+ for ( j = 0; j < numrows; ++j )
+ {
+ for ( i = j; i < csize; i = i + numrows )
+ {
+ fprintf( stderr, "%4s = %-2d",
+ readable_form( i ), ecgroup[i] );
+
+ putc( ' ', stderr );
+ }
- putc( '\n', stderr );
- }
+ putc( '\n', stderr );
+ }
+ }
}
- }
-/* generate the code to find the action number */
+/* Generate the code to find the action number. */
void gen_find_action()
+ {
+ if ( fullspd )
+ indent_puts( "yy_act = yy_current_state[-1].yy_nxt;" );
- {
- if ( fullspd )
- indent_puts( "yy_act = yy_current_state[-1].yy_nxt;" );
+ else if ( fulltbl )
+ indent_puts( "yy_act = yy_accept[yy_current_state];" );
- else if ( fulltbl )
- indent_puts( "yy_act = yy_accept[yy_current_state];" );
+ else if ( reject )
+ {
+ indent_puts( "yy_current_state = *--yy_state_ptr;" );
+ indent_puts( "yy_lp = yy_accept[yy_current_state];" );
- else if ( reject )
- {
- indent_puts( "yy_current_state = *--yy_state_ptr;" );
- indent_puts( "yy_lp = yy_accept[yy_current_state];" );
+ puts(
+ "find_rule: /* we branch to this label when backtracking */" );
- puts( "find_rule: /* we branch to this label when backtracking */" );
+ indent_puts(
+ "for ( ; ; ) /* until we find what rule we matched */" );
- indent_puts( "for ( ; ; ) /* until we find what rule we matched */" );
+ indent_up();
- indent_up();
+ indent_puts( "{" );
- indent_puts( "{" );
+ 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];" );
- 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];" );
-
- 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(
+ 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(
"yy_looking_for_trail_begin = yy_act & ~YY_TRAILING_MASK;" );
- indent_puts(
+ indent_puts(
"yy_looking_for_trail_begin |= YY_TRAILING_HEAD_MASK;" );
- if ( real_reject )
+ 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
{
- /* remember matched text in case we back up due to REJECT */
+ /* 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( "yy_full_state = yy_state_ptr;" );
- indent_puts( "yy_full_lp = yy_lp;" );
+ indent_puts( "break;" );
+ indent_puts( "}" );
+ indent_down();
}
- indent_puts( "}" );
- indent_down();
+ 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_cp;" );
- indent_puts( "++yy_lp;" );
- indent_puts( "goto find_rule;" );
- }
+ /* 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];" );
- else
- {
- /* 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();
- }
+ indent_puts( "}" );
- indent_puts( "}" );
- indent_down();
-
- indent_puts( "--yy_cp;" );
-
- /* 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];" );
-
- indent_puts( "}" );
+ indent_down();
+ }
- indent_down();
+ else
+ /* compressed */
+ indent_puts( "yy_act = yy_accept[yy_current_state];" );
}
- else
- /* compressed */
- indent_puts( "yy_act = yy_accept[yy_current_state];" );
- }
-
-/* genftbl - generates full transition table
- *
- * synopsis
- * genftbl();
- */
+/* genftbl - generates full transition table */
void genftbl()
+ {
+ register int i;
+ int end_of_buffer_action = num_rules + 1;
- {
- register int i;
- int end_of_buffer_action = num_rules + 1;
-
- printf( C_short_decl, "yy_accept", lastdfa + 1 );
-
+ printf( C_short_decl, "yy_accept", lastdfa + 1 );
- dfaacc[end_of_buffer_state].dfaacc_state = end_of_buffer_action;
+ dfaacc[end_of_buffer_state].dfaacc_state = end_of_buffer_action;
- for ( i = 1; i <= lastdfa; ++i )
- {
- register int anum = dfaacc[i].dfaacc_state;
+ for ( i = 1; i <= lastdfa; ++i )
+ {
+ register int anum = dfaacc[i].dfaacc_state;
- mkdata( anum );
+ mkdata( anum );
- if ( trace && anum )
- fprintf( stderr, "state # %d accepts: [%d]\n", i, anum );
- }
+ if ( trace && anum )
+ fprintf( stderr, "state # %d accepts: [%d]\n",
+ i, anum );
+ }
- dataend();
+ dataend();
- if ( useecs )
- genecs();
+ if ( useecs )
+ genecs();
- /* don't have to dump the actual full table entries - they were created
- * on-the-fly
- */
- }
+ /* Don't have to dump the actual full table entries - they were
+ * created on-the-fly.
+ */
+ }
-/* generate the code to find the next compressed-table state */
+/* Generate the code to find the next compressed-table state. */
void gen_next_compressed_state( char_map )
char *char_map;
-
- {
- indent_put2s( "register YY_CHAR yy_c = %s;", char_map );
-
- /* save the backtracking 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_backtracking();
-
- indent_puts(
- "while ( yy_chk[yy_base[yy_current_state] + yy_c] != yy_current_state )" );
- indent_up();
- indent_puts( "{" );
- indent_puts( "yy_current_state = yy_def[yy_current_state];" );
-
- if ( usemecs )
{
- /* we've arrange it so that templates are never chained
- * to one another. This means we can afford 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
+ indent_put2s( "register YY_CHAR yy_c = %s;", char_map );
+
+ /* Save the backtracking info \before/ computing the next state
+ * because we always compute one more state than needed - we
+ * always proceed until we reach a jam state
*/
- do_indent();
- /* lastdfa + 2 is the beginning of the templates */
- printf( "if ( yy_current_state >= %d )\n", lastdfa + 2 );
+ gen_backtracking();
+ indent_puts(
+"while ( yy_chk[yy_base[yy_current_state] + yy_c] != yy_current_state )" );
indent_up();
- indent_puts( "yy_c = yy_meta[(unsigned int) yy_c];" );
- indent_down();
- }
+ indent_puts( "{" );
+ indent_puts( "yy_current_state = yy_def[yy_current_state];" );
- indent_puts( "}" );
- indent_down();
+ if ( usemecs )
+ {
+ /* We've arrange it so that templates are never chained
+ * to one another. This means we can afford 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 */
+ printf( "if ( yy_current_state >= %d )\n", lastdfa + 2 );
+
+ indent_up();
+ indent_puts( "yy_c = yy_meta[(unsigned int) yy_c];" );
+ indent_down();
+ }
- indent_puts(
+ indent_puts( "}" );
+ indent_down();
+
+ indent_puts(
"yy_current_state = yy_nxt[yy_base[yy_current_state] + yy_c];" );
- }
+ }
-/* generate the code to find the next match */
+/* Generate the code to find the next match. */
void gen_next_match()
-
- {
- /* NOTE - changes in here should be reflected in gen_next_state() and
- * gen_NUL_trans()
- */
- char *char_map = useecs ? "yy_ec[*yy_cp]" : "*yy_cp";
- char *char_map_2 = useecs ? "yy_ec[*++yy_cp]" : "*++yy_cp";
-
- if ( fulltbl )
{
- indent_put2s(
- "while ( (yy_current_state = yy_nxt[yy_current_state][%s]) > 0 )",
- char_map );
+ /* NOTE - changes in here should be reflected in gen_next_state() and
+ * gen_NUL_trans().
+ */
+ char *char_map = useecs ? "yy_ec[*yy_cp]" : "*yy_cp";
+ char *char_map_2 = useecs ? "yy_ec[*++yy_cp]" : "*++yy_cp";
- indent_up();
+ if ( fulltbl )
+ {
+ indent_put2s(
+ "while ( (yy_current_state = yy_nxt[yy_current_state][%s]) > 0 )",
+ char_map );
- if ( num_backtracking > 0 )
- {
- indent_puts( "{" );
- gen_backtracking();
- putchar( '\n' );
- }
+ indent_up();
- indent_puts( "++yy_cp;" );
+ if ( num_backtracking > 0 )
+ {
+ indent_puts( "{" ); /* } for vi */
+ gen_backtracking();
+ putchar( '\n' );
+ }
- if ( num_backtracking > 0 )
- indent_puts( "}" );
+ indent_puts( "++yy_cp;" );
- indent_down();
+ if ( num_backtracking > 0 )
+ /* { for vi */
+ indent_puts( "}" );
- putchar( '\n' );
- indent_puts( "yy_current_state = -yy_current_state;" );
- }
+ indent_down();
- else if ( fullspd )
- {
- indent_puts( "{" );
- indent_puts( "register const struct yy_trans_info *yy_trans_info;\n" );
- indent_puts( "register YY_CHAR yy_c;\n" );
- indent_put2s( "for ( yy_c = %s;", char_map );
- indent_puts(
+ putchar( '\n' );
+ indent_puts( "yy_current_state = -yy_current_state;" );
+ }
+
+ else if ( fullspd )
+ {
+ indent_puts( "{" ); /* } for vi */
+ indent_puts(
+ "register const struct yy_trans_info *yy_trans_info;\n" );
+ indent_puts( "register YY_CHAR yy_c;\n" );
+ indent_put2s( "for ( yy_c = %s;", char_map );
+ indent_puts(
" (yy_trans_info = &yy_current_state[yy_c])->yy_verify == yy_c;" );
- indent_put2s( " yy_c = %s )", char_map_2 );
+ indent_put2s( " yy_c = %s )", char_map_2 );
- indent_up();
+ indent_up();
- if ( num_backtracking > 0 )
- indent_puts( "{" );
+ if ( num_backtracking > 0 )
+ indent_puts( "{" ); /* } for vi */
- indent_puts( "yy_current_state += yy_trans_info->yy_nxt;" );
+ indent_puts( "yy_current_state += yy_trans_info->yy_nxt;" );
- if ( num_backtracking > 0 )
- {
- putchar( '\n' );
- gen_backtracking();
- indent_puts( "}" );
- }
+ if ( num_backtracking > 0 )
+ {
+ putchar( '\n' );
+ gen_backtracking(); /* { for vi */
+ indent_puts( "}" );
+ }
- indent_down();
- indent_puts( "}" );
- }
+ indent_down(); /* { for vi */
+ indent_puts( "}" );
+ }
- else
- { /* compressed */
- indent_puts( "do" );
+ else
+ { /* compressed */
+ indent_puts( "do" );
- indent_up();
- indent_puts( "{" );
+ indent_up();
+ indent_puts( "{" ); /* } for vi */
- gen_next_state( false );
+ gen_next_state( false );
- indent_puts( "++yy_cp;" );
+ indent_puts( "++yy_cp;" );
- indent_puts( "}" );
- indent_down();
+ /* { for vi */
+ indent_puts( "}" );
+ indent_down();
- do_indent();
+ do_indent();
- if ( interactive )
- printf( "while ( yy_base[yy_current_state] != %d );\n", jambase );
- else
- printf( "while ( yy_current_state != %d );\n", jamstate );
-
- if ( ! reject && ! interactive )
- {
- /* do the guaranteed-needed backtrack to figure out the match */
- indent_puts( "yy_cp = yy_last_accepting_cpos;" );
- indent_puts( "yy_current_state = yy_last_accepting_state;" );
- }
+ if ( interactive )
+ printf( "while ( yy_base[yy_current_state] != %d );\n",
+ jambase );
+ else
+ printf( "while ( yy_current_state != %d );\n",
+ jamstate );
+
+ if ( ! reject && ! interactive )
+ {
+ /* Do the guaranteed-needed backtrack to figure out
+ * the match.
+ */
+ indent_puts( "yy_cp = yy_last_accepting_cpos;" );
+ indent_puts(
+ "yy_current_state = yy_last_accepting_state;" );
+ }
+ }
}
- }
-/* generate the code to find the next state */
+/* Generate the code to find the next state. */
void gen_next_state( worry_about_NULs )
int worry_about_NULs;
+ { /* NOTE - changes in here should be reflected in get_next_match() */
+ char char_map[256];
- { /* NOTE - changes in here should be reflected in get_next_match() */
- char char_map[256];
+ if ( worry_about_NULs && ! nultrans )
+ {
+ if ( useecs )
+ (void) sprintf( char_map,
+ "(*yy_cp ? yy_ec[*yy_cp] : %d)", NUL_ec );
+ else
+ (void) sprintf( char_map,
+ "(*yy_cp ? *yy_cp : %d)", NUL_ec );
+ }
- if ( worry_about_NULs && ! nultrans )
- {
- if ( useecs )
- (void) sprintf( char_map, "(*yy_cp ? yy_ec[*yy_cp] : %d)", NUL_ec );
else
- (void) sprintf( char_map, "(*yy_cp ? *yy_cp : %d)", NUL_ec );
- }
-
- else
- (void) strcpy( char_map, useecs ? "yy_ec[*yy_cp]" : "*yy_cp" );
-
- if ( worry_about_NULs && nultrans )
- {
- if ( ! fulltbl && ! fullspd )
- /* compressed tables backtrack *before* they match */
- gen_backtracking();
-
- indent_puts( "if ( *yy_cp )" );
- indent_up();
- indent_puts( "{" );
- }
-
- if ( fulltbl )
- indent_put2s( "yy_current_state = yy_nxt[yy_current_state][%s];",
- char_map );
-
- else if ( fullspd )
- indent_put2s( "yy_current_state += yy_current_state[%s].yy_nxt;",
- char_map );
-
- else
- gen_next_compressed_state( char_map );
-
- if ( worry_about_NULs && nultrans )
- {
- indent_puts( "}" );
- indent_down();
- indent_puts( "else" );
- indent_up();
- indent_puts( "yy_current_state = yy_NUL_trans[yy_current_state];" );
- indent_down();
- }
-
- if ( fullspd || fulltbl )
- gen_backtracking();
-
- if ( reject )
- indent_puts( "*yy_state_ptr++ = yy_current_state;" );
- }
+ (void) strcpy( char_map, useecs ? "yy_ec[*yy_cp]" : "*yy_cp" );
+ if ( worry_about_NULs && nultrans )
+ {
+ if ( ! fulltbl && ! fullspd )
+ /* Compressed tables backtrack *before* they match. */
+ gen_backtracking();
-/* generate the code to make a NUL transition */
+ indent_puts( "if ( *yy_cp )" );
+ indent_up();
+ indent_puts( "{" ); /* } for vi */
+ }
-void gen_NUL_trans()
+ if ( fulltbl )
+ indent_put2s(
+ "yy_current_state = yy_nxt[yy_current_state][%s];",
+ char_map );
- { /* NOTE - changes in here should be reflected in get_next_match() */
- int need_backtracking = (num_backtracking > 0 && ! reject);
+ else if ( fullspd )
+ indent_put2s(
+ "yy_current_state += yy_current_state[%s].yy_nxt;",
+ char_map );
- if ( need_backtracking )
- /* we'll need yy_cp lying around for the gen_backtracking() */
- indent_puts( "register YY_CHAR *yy_cp = yy_c_buf_p;" );
+ else
+ gen_next_compressed_state( char_map );
- putchar( '\n' );
+ 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();
+ }
- if ( nultrans )
- {
- indent_puts( "yy_current_state = yy_NUL_trans[yy_current_state];" );
- indent_puts( "yy_is_jam = (yy_current_state == 0);" );
- }
+ if ( fullspd || fulltbl )
+ gen_backtracking();
- else if ( fulltbl )
- {
- do_indent();
- printf( "yy_current_state = yy_nxt[yy_current_state][%d];\n",
- NUL_ec );
- indent_puts( "yy_is_jam = (yy_current_state <= 0);" );
+ if ( reject )
+ indent_puts( "*yy_state_ptr++ = yy_current_state;" );
}
- else if ( fullspd )
- {
- do_indent();
- printf( "register int yy_c = %d;\n", NUL_ec );
- indent_puts(
- "register const struct yy_trans_info *yy_trans_info;\n" );
- indent_puts( "yy_trans_info = &yy_current_state[yy_c];" );
- indent_puts( "yy_current_state += yy_trans_info->yy_nxt;" );
+/* Generate the code to make a NUL transition. */
- indent_puts( "yy_is_jam = (yy_trans_info->yy_verify != yy_c);" );
- }
+void gen_NUL_trans()
+ { /* NOTE - changes in here should be reflected in get_next_match() */
+ int need_backtracking = (num_backtracking > 0 && ! reject);
- else
- {
- char NUL_ec_str[20];
+ if ( need_backtracking )
+ /* We'll need yy_cp lying around for the gen_backtracking(). */
+ indent_puts( "register YY_CHAR *yy_cp = yy_c_buf_p;" );
- (void) sprintf( NUL_ec_str, "%d", NUL_ec );
- gen_next_compressed_state( NUL_ec_str );
+ putchar( '\n' );
- if ( reject )
- indent_puts( "*yy_state_ptr++ = yy_current_state;" );
+ if ( nultrans )
+ {
+ indent_puts(
+ "yy_current_state = yy_NUL_trans[yy_current_state];" );
+ indent_puts( "yy_is_jam = (yy_current_state == 0);" );
+ }
- do_indent();
+ else if ( fulltbl )
+ {
+ do_indent();
+ printf( "yy_current_state = yy_nxt[yy_current_state][%d];\n",
+ NUL_ec );
+ indent_puts( "yy_is_jam = (yy_current_state <= 0);" );
+ }
- printf( "yy_is_jam = (yy_current_state == %d);\n", jamstate );
- }
+ else if ( fullspd )
+ {
+ do_indent();
+ printf( "register int yy_c = %d;\n", NUL_ec );
- /* if we've entered an accepting state, backtrack; note that
- * compressed tables have *already* done such backtracking, so
- * we needn't bother with it again
- */
- if ( need_backtracking && (fullspd || fulltbl) )
- {
- putchar( '\n' );
- indent_puts( "if ( ! yy_is_jam )" );
- indent_up();
- indent_puts( "{" );
- gen_backtracking();
- indent_puts( "}" );
- indent_down();
- }
- }
+ indent_puts(
+ "register const struct yy_trans_info *yy_trans_info;\n" );
+ indent_puts( "yy_trans_info = &yy_current_state[yy_c];" );
+ indent_puts( "yy_current_state += yy_trans_info->yy_nxt;" );
+ indent_puts(
+ "yy_is_jam = (yy_trans_info->yy_verify != yy_c);" );
+ }
-/* generate the code to find the start state */
+ else
+ {
+ char NUL_ec_str[20];
-void gen_start_state()
+ (void) sprintf( NUL_ec_str, "%d", NUL_ec );
+ gen_next_compressed_state( NUL_ec_str );
- {
- if ( fullspd )
- indent_put2s( "yy_current_state = yy_start_state_list[yy_start%s];",
- bol_needed ? " + (yy_bp[-1] == '\\n' ? 1 : 0)" : "" );
+ if ( reject )
+ indent_puts( "*yy_state_ptr++ = yy_current_state;" );
- else
- {
- indent_puts( "yy_current_state = yy_start;" );
+ do_indent();
- if ( bol_needed )
- {
- indent_puts( "if ( yy_bp[-1] == '\\n' )" );
- indent_up();
- indent_puts( "++yy_current_state;" );
- indent_down();
- }
+ printf( "yy_is_jam = (yy_current_state == %d);\n", jamstate );
+ }
- if ( reject )
- {
- /* set up for storing up states */
- indent_puts( "yy_state_ptr = yy_state_buf;" );
- indent_puts( "*yy_state_ptr++ = yy_current_state;" );
- }
+ /* If we've entered an accepting state, backtrack; note that
+ * compressed tables have *already* done such backtracking, so
+ * we needn't bother with it again.
+ */
+ if ( need_backtracking && (fullspd || fulltbl) )
+ {
+ putchar( '\n' );
+ indent_puts( "if ( ! yy_is_jam )" );
+ indent_up();
+ indent_puts( "{" );
+ gen_backtracking();
+ indent_puts( "}" );
+ indent_down();
+ }
}
- }
-/* gentabs - generate data statements for the transition tables
- *
- * synopsis
- * gentabs();
- */
+/* Generate the code to find the start state. */
-void gentabs()
+void gen_start_state()
+ {
+ if ( fullspd )
+ indent_put2s(
+ "yy_current_state = yy_start_state_list[yy_start%s];",
+ bol_needed ? " + (yy_bp[-1] == '\\n' ? 1 : 0)" : "" );
+
+ else
+ {
+ indent_puts( "yy_current_state = yy_start;" );
- {
- int i, j, k, *accset, nacc, *acc_array, total_states;
- int end_of_buffer_action = num_rules + 1;
+ if ( bol_needed )
+ {
+ indent_puts( "if ( yy_bp[-1] == '\\n' )" );
+ indent_up();
+ indent_puts( "++yy_current_state;" );
+ indent_down();
+ }
- /* *everything* is done in terms of arrays starting at 1, so provide
- * a null entry for the zero element of all C arrays
- */
- static char C_char_decl[] =
- "static const YY_CHAR %s[%d] =\n { 0,\n";
+ if ( reject )
+ {
+ /* Set up for storing up states. */
+ indent_puts( "yy_state_ptr = yy_state_buf;" );
+ indent_puts( "*yy_state_ptr++ = yy_current_state;" );
+ }
+ }
+ }
- acc_array = allocate_integer_array( current_max_dfas );
- nummt = 0;
- /* 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 backtracking information.
- */
- ++num_backtracking;
+/* gentabs - generate data statements for the transition tables */
- if ( reject )
+void gentabs()
{
- /* 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];
+ int i, j, k, *accset, nacc, *acc_array, total_states;
+ int end_of_buffer_action = num_rules + 1;
- /* 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;
-
- printf( C_short_decl, "yy_acclist", max( numas, 1 ) + 1 );
+ /* *Everything* is done in terms of arrays starting at 1, so provide
+ * a null entry for the zero element of all C arrays.
+ */
+ static char C_char_decl[] =
+ "static const YY_CHAR %s[%d] =\n { 0,\n"; /* } for vi */
- j = 1; /* index into "yy_acclist" array */
+ acc_array = allocate_integer_array( current_max_dfas );
+ nummt = 0;
- for ( i = 1; i <= lastdfa; ++i )
- {
- acc_array[i] = j;
+ /* 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 backtracking information.
+ */
+ ++num_backtracking;
- if ( accsiz[i] != 0 )
+ if ( reject )
{
- accset = dfaacc[i].dfaacc_set;
- nacc = accsiz[i];
+ /* 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];
- if ( trace )
- fprintf( stderr, "state # %d accepts: ", i );
+ /* 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;
- for ( k = 1; k <= nacc; ++k )
- {
- int accnum = accset[k];
+ printf( C_short_decl, "yy_acclist", max( numas, 1 ) + 1 );
- ++j;
+ j = 1; /* index into "yy_acclist" array */
- if ( variable_trailing_context_rules &&
- ! (accnum & YY_TRAILING_HEAD_MASK) &&
- accnum > 0 && accnum <= num_rules &&
- rule_type[accnum] == RULE_VARIABLE )
+ for ( i = 1; i <= lastdfa; ++i )
{
- /* special hack to flag accepting number as part
- * of trailing context rule
- */
- accnum |= YY_TRAILING_MASK;
+ acc_array[i] = j;
+
+ if ( accsiz[i] != 0 )
+ {
+ accset = dfaacc[i].dfaacc_set;
+ nacc = accsiz[i];
+
+ if ( trace )
+ fprintf( stderr,
+ "state # %d accepts: ", i );
+
+ 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 );
+ }
+ }
+ }
}
- mkdata( accnum );
+ /* add accepting number for the "jam" state */
+ acc_array[i] = j;
- if ( trace )
- {
- fprintf( stderr, "[%d]", accset[k] );
-
- if ( k < nacc )
- fputs( ", ", stderr );
- else
- putc( '\n', stderr );
- }
- }
+ dataend();
}
- }
-
- /* add accepting number for the "jam" state */
- acc_array[i] = j;
- dataend();
- }
+ else
+ {
+ dfaacc[end_of_buffer_state].dfaacc_state = end_of_buffer_action;
- else
- {
- dfaacc[end_of_buffer_state].dfaacc_state = end_of_buffer_action;
+ for ( i = 1; i <= lastdfa; ++i )
+ acc_array[i] = dfaacc[i].dfaacc_state;
- for ( i = 1; i <= lastdfa; ++i )
- acc_array[i] = dfaacc[i].dfaacc_state;
+ /* add accepting number for jam state */
+ acc_array[i] = 0;
+ }
- /* add accepting number for jam state */
- acc_array[i] = 0;
- }
+ /* 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.
+ */
- /* 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.
- */
-
- /* "lastdfa + 2" is the size of "yy_accept"; includes room for C arrays
- * beginning at 0 and for "jam" state
- */
- k = lastdfa + 2;
-
- 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.
+ /* "lastdfa + 2" is the size of "yy_accept"; includes room for C arrays
+ * beginning at 0 and for "jam" state.
*/
- ++k;
+ k = lastdfa + 2;
- printf( C_short_decl, "yy_accept", k );
+ 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;
- for ( i = 1; i <= lastdfa; ++i )
- {
- mkdata( acc_array[i] );
+ printf( C_short_decl, "yy_accept", k );
- if ( ! reject && trace && acc_array[i] )
- fprintf( stderr, "state # %d accepts: [%d]\n", i, acc_array[i] );
- }
+ for ( i = 1; i <= lastdfa; ++i )
+ {
+ mkdata( acc_array[i] );
- /* add entry for "jam" state */
- mkdata( acc_array[i] );
+ if ( ! reject && trace && acc_array[i] )
+ fprintf( stderr, "state # %d accepts: [%d]\n",
+ i, acc_array[i] );
+ }
- if ( reject )
- /* add "cap" for the list */
+ /* Add entry for "jam" state. */
mkdata( acc_array[i] );
- dataend();
+ if ( reject )
+ /* Add "cap" for the list. */
+ mkdata( acc_array[i] );
- if ( useecs )
- genecs();
+ dataend();
- if ( usemecs )
- {
- /* write out meta-equivalence classes (used to index templates with) */
+ if ( useecs )
+ genecs();
- if ( trace )
- fputs( "\n\nMeta-Equivalence Classes:\n", stderr );
+ if ( usemecs )
+ {
+ /* Write out meta-equivalence classes (used to index
+ * templates with).
+ */
- printf( C_char_decl, "yy_meta", numecs + 1 );
+ if ( trace )
+ fputs( "\n\nMeta-Equivalence Classes:\n", stderr );
- for ( i = 1; i <= numecs; ++i )
- {
- if ( trace )
- fprintf( stderr, "%d = %d\n", i, abs( tecbck[i] ) );
+ printf( C_char_decl, "yy_meta", numecs + 1 );
- mkdata( abs( tecbck[i] ) );
- }
+ for ( i = 1; i <= numecs; ++i )
+ {
+ if ( trace )
+ fprintf( stderr, "%d = %d\n",
+ i, abs( tecbck[i] ) );
- dataend();
- }
+ mkdata( abs( tecbck[i] ) );
+ }
- total_states = lastdfa + numtemps;
+ dataend();
+ }
- printf( total_states > MAX_SHORT ? C_long_decl : C_short_decl,
- "yy_base", total_states + 1 );
+ total_states = lastdfa + numtemps;
- for ( i = 1; i <= lastdfa; ++i )
- {
- register int d = def[i];
+ printf( total_states > MAX_SHORT ? C_long_decl : C_short_decl,
+ "yy_base", total_states + 1 );
- if ( base[i] == JAMSTATE )
- base[i] = jambase;
+ for ( i = 1; i <= lastdfa; ++i )
+ {
+ register int d = def[i];
- if ( d == JAMSTATE )
- def[i] = jamstate;
+ if ( base[i] == JAMSTATE )
+ base[i] = jambase;
- else if ( d < 0 )
- {
- /* template reference */
- ++tmpuses;
- def[i] = lastdfa - d + 1;
- }
+ if ( d == JAMSTATE )
+ def[i] = jamstate;
- mkdata( base[i] );
- }
+ else if ( d < 0 )
+ {
+ /* Template reference. */
+ ++tmpuses;
+ def[i] = lastdfa - d + 1;
+ }
- /* generate jam state's base index */
- mkdata( base[i] );
+ mkdata( base[i] );
+ }
- for ( ++i /* skip jam state */; i <= total_states; ++i )
- {
+ /* Generate jam state's base index. */
mkdata( base[i] );
- def[i] = jamstate;
- }
- dataend();
+ for ( ++i /* skip jam state */; i <= total_states; ++i )
+ {
+ mkdata( base[i] );
+ def[i] = jamstate;
+ }
- printf( tblend > MAX_SHORT ? C_long_decl : C_short_decl,
- "yy_def", total_states + 1 );
+ dataend();
- for ( i = 1; i <= total_states; ++i )
- mkdata( def[i] );
+ printf( tblend > MAX_SHORT ? C_long_decl : C_short_decl,
+ "yy_def", total_states + 1 );
- dataend();
+ for ( i = 1; i <= total_states; ++i )
+ mkdata( def[i] );
- printf( lastdfa > MAX_SHORT ? C_long_decl : C_short_decl,
- "yy_nxt", tblend + 1 );
+ dataend();
- for ( i = 1; i <= tblend; ++i )
- {
- if ( nxt[i] == 0 || chk[i] == 0 )
- nxt[i] = jamstate; /* new state is the JAM state */
+ printf( lastdfa > MAX_SHORT ? C_long_decl : C_short_decl,
+ "yy_nxt", tblend + 1 );
- mkdata( nxt[i] );
- }
+ for ( i = 1; i <= tblend; ++i )
+ {
+ if ( nxt[i] == 0 || chk[i] == 0 )
+ nxt[i] = jamstate; /* new state is the JAM state */
- dataend();
+ mkdata( nxt[i] );
+ }
- printf( lastdfa > MAX_SHORT ? C_long_decl : C_short_decl,
- "yy_chk", tblend + 1 );
+ dataend();
- for ( i = 1; i <= tblend; ++i )
- {
- if ( chk[i] == 0 )
- ++nummt;
+ printf( lastdfa > MAX_SHORT ? C_long_decl : C_short_decl,
+ "yy_chk", tblend + 1 );
- mkdata( chk[i] );
- }
+ for ( i = 1; i <= tblend; ++i )
+ {
+ if ( chk[i] == 0 )
+ ++nummt;
+
+ mkdata( chk[i] );
+ }
- dataend();
- }
+ dataend();
+ }
-/* write out a formatted string (with a secondary string argument) at the
- * current indentation level, adding a final newline
+/* Write out a formatted string (with a secondary string argument) at the
+ * current indentation level, adding a final newline.
*/
void indent_put2s( fmt, arg )
char fmt[], arg[];
-
- {
- do_indent();
- printf( fmt, arg );
- putchar( '\n' );
- }
+ {
+ do_indent();
+ printf( fmt, arg );
+ putchar( '\n' );
+ }
-/* write out a string at the current indentation level, adding a final
- * newline
+/* Write out a string at the current indentation level, adding a final
+ * newline.
*/
void indent_puts( str )
char str[];
-
- {
- do_indent();
- puts( str );
- }
+ {
+ do_indent();
+ puts( str );
+ }
-/* make_tables - generate transition tables
- *
- * synopsis
- * make_tables();
- *
- * Generates transition tables and finishes generating output file
+/* make_tables - generate transition tables and finishes generating output file
*/
void make_tables()
+ {
+ register int i;
+ int did_eof_rule = false;
- {
- register int i;
- int did_eof_rule = false;
-
- skelout();
+ skelout();
- /* first, take care of YY_DO_BEFORE_ACTION depending on yymore being used */
- set_indent( 2 );
+ /* First, take care of YY_DO_BEFORE_ACTION depending on yymore
+ * being used.
+ */
+ set_indent( 2 );
- if ( yymore_used )
- {
- indent_puts( "yytext_ptr -= yy_more_len; \\" );
- indent_puts( "yyleng = yy_cp - yytext_ptr; \\" );
- }
+ if ( yymore_used )
+ {
+ indent_puts( "yytext_ptr -= yy_more_len; \\" );
+ indent_puts( "yyleng = yy_cp - yytext_ptr; \\" );
+ }
- else
- indent_puts( "yyleng = yy_cp - yy_bp; \\" );
+ else
+ indent_puts( "yyleng = yy_cp - yy_bp; \\" );
- /* now also deal with copying yytext_ptr to yytext if needed */
- skelout();
- if ( yytext_is_array )
- {
- indent_puts( "if ( yyleng >= YYLMAX ) \\" );
- indent_up();
- indent_puts(
+ /* Now also deal with copying yytext_ptr to yytext if needed. */
+ skelout();
+ if ( yytext_is_array )
+ {
+ indent_puts( "if ( yyleng >= YYLMAX ) \\" );
+ indent_up();
+ indent_puts(
"YY_FATAL_ERROR( \"token too large, exceeds YYLMAX\" ); \\" );
- indent_down();
- indent_puts( "strcpy( yytext, (char *) yytext_ptr ); \\" );
- }
+ indent_down();
+ indent_puts( "strcpy( yytext, (char *) yytext_ptr ); \\" );
+ }
- set_indent( 0 );
-
- skelout();
+ set_indent( 0 );
+ skelout();
- printf( "#define YY_END_OF_BUFFER %d\n", num_rules + 1 );
- 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" : "short";
+ printf( "#define YY_END_OF_BUFFER %d\n", num_rules + 1 );
- set_indent( 0 );
- indent_puts( "struct yy_trans_info" );
- indent_up();
- indent_puts( "{" );
- 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();
+ 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" : "short";
+
+ set_indent( 0 );
+ indent_puts( "struct yy_trans_info" );
+ indent_up();
+ indent_puts( "{" ); /* } for vi */
+ 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();
+
+ indent_puts(
+ "typedef const struct yy_trans_info *yy_state_type;" );
+ }
- indent_puts( "typedef const struct yy_trans_info *yy_state_type;" );
- }
-
- else
- indent_puts( "typedef int yy_state_type;" );
+ else
+ indent_puts( "typedef int yy_state_type;" );
- if ( fullspd )
- genctbl();
+ if ( fullspd )
+ genctbl();
+ else if ( fulltbl )
+ genftbl();
+ else
+ gentabs();
- else if ( fulltbl )
- genftbl();
+ if ( num_backtracking > 0 )
+ {
+ indent_puts( "static yy_state_type yy_last_accepting_state;" );
+ indent_puts( "static YY_CHAR *yy_last_accepting_cpos;\n" );
+ }
- else
- gentabs();
+ if ( nultrans )
+ {
+ printf( C_state_decl, "yy_NUL_trans", lastdfa + 1 );
- if ( num_backtracking > 0 )
- {
- indent_puts( "static yy_state_type yy_last_accepting_state;" );
- indent_puts( "static YY_CHAR *yy_last_accepting_cpos;\n" );
- }
+ for ( i = 1; i <= lastdfa; ++i )
+ {
+ if ( fullspd )
+ {
+ if ( nultrans )
+ printf( " &yy_transition[%d],\n",
+ base[i] );
+ else
+ printf( " 0,\n" );
+ }
- if ( nultrans )
- {
- printf( C_state_decl, "yy_NUL_trans", lastdfa + 1 );
+ else
+ mkdata( nultrans[i] );
+ }
- for ( i = 1; i <= lastdfa; ++i )
- {
- if ( fullspd )
- {
- if ( nultrans )
- printf( " &yy_transition[%d],\n", base[i] );
- else
- printf( " 0,\n" );
+ dataend();
}
-
- else
- mkdata( nultrans[i] );
- }
-
- dataend();
- }
- if ( ddebug )
- { /* spit out table mapping rules to line numbers */
- indent_puts( "extern int yy_flex_debug;" );
- indent_puts( "int yy_flex_debug = 1;\n" );
+ if ( ddebug )
+ { /* Spit out table mapping rules to line numbers. */
+ indent_puts( "extern int yy_flex_debug;" );
+ indent_puts( "int yy_flex_debug = 1;\n" );
- printf( C_short_decl, "yy_rule_linenum", num_rules );
- for ( i = 1; i < num_rules; ++i )
- mkdata( rule_linenum[i] );
- dataend();
- }
+ printf( C_short_decl, "yy_rule_linenum", num_rules );
+ for ( i = 1; i < num_rules; ++i )
+ mkdata( rule_linenum[i] );
+ dataend();
+ }
- if ( reject )
- {
- /* declare state buffer variables */
- puts(
+ if ( reject )
+ {
+ /* Declare state buffer variables. */
+ puts(
"static yy_state_type yy_state_buf[YY_BUF_SIZE + 2], *yy_state_ptr;" );
- puts( "static YY_CHAR *yy_full_match;" );
- puts( "static int yy_lp;" );
-
- if ( variable_trailing_context_rules )
- {
- puts( "static int yy_looking_for_trail_begin = 0;" );
- puts( "static int yy_full_lp;" );
- puts( "static int *yy_full_state;" );
- printf( "#define YY_TRAILING_MASK 0x%x\n",
- (unsigned int) YY_TRAILING_MASK );
- printf( "#define YY_TRAILING_HEAD_MASK 0x%x\n",
- (unsigned int) YY_TRAILING_HEAD_MASK );
- }
-
- puts( "#define REJECT \\" );
- puts( "{ \\" );
- puts(
+ puts( "static YY_CHAR *yy_full_match;" );
+ puts( "static int yy_lp;" );
+
+ if ( variable_trailing_context_rules )
+ {
+ puts( "static int yy_looking_for_trail_begin = 0;" );
+ puts( "static int yy_full_lp;" );
+ puts( "static int *yy_full_state;" );
+ printf( "#define YY_TRAILING_MASK 0x%x\n",
+ (unsigned int) YY_TRAILING_MASK );
+ printf( "#define YY_TRAILING_HEAD_MASK 0x%x\n",
+ (unsigned int) YY_TRAILING_HEAD_MASK );
+ }
+
+ puts( "#define REJECT \\" );
+ puts( "{ \\" ); /* } for vi */
+ puts(
"*yy_cp = yy_hold_char; /* undo effects of setting up yytext */ \\" );
- puts(
- "yy_cp = yy_full_match; /* restore poss. backed-over text */ \\" );
+ puts(
+ "yy_cp = yy_full_match; /* restore poss. backed-over text */ \\" );
- if ( variable_trailing_context_rules )
- {
- puts( "yy_lp = yy_full_lp; /* restore orig. accepting pos. */ \\" );
- puts(
+ if ( variable_trailing_context_rules )
+ {
+ puts(
+ "yy_lp = yy_full_lp; /* restore orig. accepting pos. */ \\" );
+ puts(
"yy_state_ptr = yy_full_state; /* restore orig. state */ \\" );
- puts(
- "yy_current_state = *yy_state_ptr; /* restore curr. state */ \\" );
- }
-
- puts( "++yy_lp; \\" );
- puts( "goto find_rule; \\" );
- puts( "}" );
- }
-
- else
- {
- puts( "/* the intent behind this definition is that it'll catch" );
- puts( " * any uses of REJECT which flex missed" );
- puts( " */" );
- puts( "#define REJECT reject_used_but_not_detected" );
- }
-
- if ( yymore_used )
- {
- indent_puts( "static int yy_more_flag = 0;" );
- indent_puts( "static int yy_doing_yy_more = 0;" );
- indent_puts( "static int yy_more_len = 0;" );
- indent_puts(
- "#define yymore() do { yy_more_flag = 1; } while ( 0 )" );
- indent_puts(
- "#define YY_MORE_ADJ (yy_doing_yy_more ? yy_more_len : 0)" );
- }
+ puts(
+ "yy_current_state = *yy_state_ptr; /* restore curr. state */ \\" );
+ }
- else
- {
- indent_puts( "#define yymore() yymore_used_but_not_detected" );
- indent_puts( "#define YY_MORE_ADJ 0" );
- }
+ puts( "++yy_lp; \\" );
+ puts( "goto find_rule; \\" );
+ /* { for vi */
+ puts( "}" );
+ }
- skelout();
+ else
+ {
+ puts(
+ "/* The intent behind this definition is that it'll catch" );
+ puts( " * any uses of REJECT which flex missed." );
+ puts( " */" );
+ puts( "#define REJECT reject_used_but_not_detected" );
+ }
- /* copy prolog to output file */
- fputs( prolog, stdout );
+ if ( yymore_used )
+ {
+ indent_puts( "static int yy_more_flag = 0;" );
+ indent_puts( "static int yy_doing_yy_more = 0;" );
+ indent_puts( "static int yy_more_len = 0;" );
+ indent_puts(
+ "#define yymore() do { yy_more_flag = 1; } while ( 0 )" );
+ indent_puts(
+ "#define YY_MORE_ADJ (yy_doing_yy_more ? yy_more_len : 0)" );
+ }
- skelout();
+ else
+ {
+ indent_puts( "#define yymore() yymore_used_but_not_detected" );
+ indent_puts( "#define YY_MORE_ADJ 0" );
+ }
- set_indent( 2 );
+ skelout();
- if ( yymore_used )
- {
- indent_puts( "yy_more_len = 0;" );
- indent_puts( "yy_doing_yy_more = yy_more_flag;" );
- indent_puts( "if ( yy_doing_yy_more )" );
- indent_up();
- indent_puts( "{" );
- indent_puts( "yy_more_len = yyleng;" );
- indent_puts( "yy_more_flag = 0;" );
- indent_puts( "}" );
- indent_down();
- }
+ /* Copy prolog to output file. */
+ fputs( prolog, stdout );
- skelout();
+ skelout();
- gen_start_state();
+ set_indent( 2 );
- /* note, don't use any indentation */
- puts( "yy_match:" );
- gen_next_match();
+ if ( yymore_used )
+ {
+ indent_puts( "yy_more_len = 0;" );
+ indent_puts( "yy_doing_yy_more = yy_more_flag;" );
+ indent_puts( "if ( yy_doing_yy_more )" );
+ indent_up();
+ indent_puts( "{" );
+ indent_puts( "yy_more_len = yyleng;" );
+ indent_puts( "yy_more_flag = 0;" );
+ indent_puts( "}" );
+ indent_down();
+ }
- skelout();
- set_indent( 2 );
- gen_find_action();
+ skelout();
- skelout();
- if ( ddebug )
- {
- indent_puts( "if ( yy_flex_debug )" );
- indent_up();
+ gen_start_state();
- indent_puts( "{" );
- indent_puts( "if ( yy_act == 0 )" );
- indent_up();
- indent_puts( "fprintf( stderr, \"--scanner backtracking\\n\" );" );
- indent_down();
+ /* Note, don't use any indentation. */
+ puts( "yy_match:" );
+ gen_next_match();
- do_indent();
- printf( "else if ( yy_act < %d )\n", num_rules );
- indent_up();
- indent_puts(
- "fprintf( stderr, \"--accepting rule at line %d (\\\"%s\\\")\\n\"," );
- indent_puts( " yy_rule_linenum[yy_act], yytext );" );
- indent_down();
+ skelout();
+ set_indent( 2 );
+ gen_find_action();
- do_indent();
- printf( "else if ( yy_act == %d )\n", num_rules );
- indent_up();
- indent_puts(
+ skelout();
+ if ( ddebug )
+ {
+ indent_puts( "if ( yy_flex_debug )" );
+ indent_up();
+
+ indent_puts( "{" );
+ indent_puts( "if ( yy_act == 0 )" );
+ indent_up();
+ indent_puts(
+ "fprintf( stderr, \"--scanner backtracking\\n\" );" );
+ indent_down();
+
+ do_indent();
+ printf( "else if ( yy_act < %d )\n", num_rules );
+ indent_up();
+ indent_puts(
+ "fprintf(
+ stderr, \"--accepting rule at line %d (\\\"%s\\\")\\n\"," );
+ indent_puts( " yy_rule_linenum[yy_act], yytext );" );
+ indent_down();
+
+ do_indent();
+ printf( "else if ( yy_act == %d )\n", num_rules );
+ indent_up();
+ indent_puts(
"fprintf( stderr, \"--accepting default rule (\\\"%s\\\")\\n\"," );
- indent_puts( " yytext );" );
- indent_down();
+ indent_puts( " yytext );" );
+ indent_down();
+
+ do_indent();
+ printf( "else if ( yy_act == %d )\n", num_rules + 1 );
+ indent_up();
+ indent_puts(
+ "fprintf( stderr, \"--(end of buffer or a NUL)\\n\" );" );
+ indent_down();
+
+ do_indent();
+ printf( "else\n" );
+ indent_up();
+ indent_puts( "fprintf( stderr, \"--EOF\\n\" );" );
+ indent_down();
+
+ indent_puts( "}" );
+ indent_down();
+ }
- do_indent();
- printf( "else if ( yy_act == %d )\n", num_rules + 1 );
+ /* Copy actions to output file. */
+ skelout();
indent_up();
- indent_puts( "fprintf( stderr, \"--(end of buffer or a NUL)\\n\" );" );
- indent_down();
+ gen_bt_action();
+ fputs( action, stdout );
- do_indent();
- printf( "else\n" );
- indent_up();
- indent_puts( "fprintf( stderr, \"--EOF\\n\" );" );
- indent_down();
+ /* generate cases for any missing EOF rules */
+ for ( i = 1; i <= lastsc; ++i )
+ if ( ! sceof[i] )
+ {
+ do_indent();
+ printf( "case YY_STATE_EOF(%s):\n", scname[i] );
+ did_eof_rule = true;
+ }
- indent_puts( "}" );
- indent_down();
- }
+ if ( did_eof_rule )
+ {
+ indent_up();
+ indent_puts( "yyterminate();" );
+ indent_down();
+ }
- /* copy actions to output file */
- skelout();
- indent_up();
- gen_bt_action();
- fputs( action, stdout );
-
- /* generate cases for any missing EOF rules */
- for ( i = 1; i <= lastsc; ++i )
- if ( ! sceof[i] )
- {
- do_indent();
- printf( "case YY_STATE_EOF(%s):\n", scname[i] );
- did_eof_rule = true;
- }
-
- if ( did_eof_rule )
- {
- indent_up();
- indent_puts( "yyterminate();" );
- indent_down();
- }
+ /* Generate code for handling NUL's, if needed. */
- /* generate code for handling NUL's, if needed */
-
- /* first, deal with backtracking and setting up yy_cp if the scanner
- * finds that it should JAM on the NUL
- */
- skelout();
- set_indent( 7 );
-
- if ( fullspd || fulltbl )
- indent_puts( "yy_cp = yy_c_buf_p;" );
-
- else
- { /* compressed table */
- if ( ! reject && ! interactive )
- {
- /* do the guaranteed-needed backtrack to figure out the match */
- indent_puts( "yy_cp = yy_last_accepting_cpos;" );
- indent_puts( "yy_current_state = yy_last_accepting_state;" );
- }
- }
+ /* First, deal with backtracking and setting up yy_cp if the scanner
+ * finds that it should JAM on the NUL>
+ */
+ skelout();
+ set_indent( 7 );
+ if ( fullspd || fulltbl )
+ indent_puts( "yy_cp = yy_c_buf_p;" );
+
+ else
+ { /* compressed table */
+ if ( ! reject && ! interactive )
+ {
+ /* Do the guaranteed-needed backtrack to figure
+ * out the match.
+ */
+ indent_puts( "yy_cp = yy_last_accepting_cpos;" );
+ indent_puts(
+ "yy_current_state = yy_last_accepting_state;" );
+ }
+ }
- /* generate code for yy_get_previous_state() */
- set_indent( 1 );
- skelout();
- if ( bol_needed )
- indent_puts( "register YY_CHAR *yy_bp = yytext_ptr;\n" );
+ /* Generate code for yy_get_previous_state(). */
+ set_indent( 1 );
+ skelout();
- gen_start_state();
+ if ( bol_needed )
+ indent_puts( "register YY_CHAR *yy_bp = yytext_ptr;\n" );
+
+ gen_start_state();
- set_indent( 2 );
- skelout();
- gen_next_state( true );
+ set_indent( 2 );
+ skelout();
+ gen_next_state( true );
- set_indent( 1 );
- skelout();
- gen_NUL_trans();
+ set_indent( 1 );
+ skelout();
+ gen_NUL_trans();
- skelout();
+ skelout();
- /* copy remainder of input to output */
+ /* Copy remainder of input to output. */
- line_directive_out( stdout );
- (void) flexscan(); /* copy remainder of input to output */
- }
+ line_directive_out( stdout );
+ (void) flexscan(); /* copy remainder of input to output */
+ }