rsalz@uunet.uu.net (Rich Salz) (06/23/89)
Submitted-by: Vern Paxson <vern@csam.lbl.gov> Posting-number: Volume 19, Issue 60 Archive-name: flex2/part06 #! /bin/sh # This is a shell archive. Remove anything before this line, then unpack # it by saving it into a file and typing "sh file". To overwrite existing # files, type "sh file -c". You can also feed this as standard input via # unshar, or by typing "sh <file", e.g.. If this archive is complete, you # will see the following message at the end: # "End of archive 6 (of 7)." # Contents: flex/gen.c # Wrapped by rsalz@prune.bbn.com on Thu Jun 22 19:01:54 1989 PATH=/bin:/usr/bin:/usr/ucb ; export PATH if test -f 'flex/gen.c' -a "${1}" != "-c" ; then echo shar: Will not clobber existing file \"'flex/gen.c'\" else echo shar: Extracting \"'flex/gen.c'\" \(25254 characters\) sed "s/^X//" >'flex/gen.c' <<'END_OF_FILE' X/* gen - actual generation (writing) of flex scanners */ X X/* X * Copyright (c) 1989 The Regents of the University of California. X * All rights reserved. X * X * This code is derived from software contributed to Berkeley by X * Vern Paxson. X * X * The United States Government has rights in this work pursuant to X * contract no. DE-AC03-76SF00098 between the United States Department of X * Energy and the University of California. X * X * Redistribution and use in source and binary forms are permitted X * provided that the above copyright notice and this paragraph are X * duplicated in all such forms and that any documentation, X * advertising materials, and other materials related to such X * distribution and use acknowledge that the software was developed X * by the University of California, Berkeley. The name of the X * University may not be used to endorse or promote products derived X * from this software without specific prior written permission. X * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR X * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED X * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. X */ X X#ifndef lint X Xstatic char copyright[] = X "@(#) Copyright (c) 1989 The Regents of the University of California.\n"; Xstatic char CR_continuation[] = "@(#) All rights reserved.\n"; X Xstatic char rcsid[] = X "@(#) $Header: gen.c,v 2.0 89/06/20 15:49:54 vern Locked $ (LBL)"; X X#endif X X#include "flexdef.h" X X Xstatic int indent_level = 0; /* each level is 4 spaces */ X X#define indent_up() (++indent_level) X#define indent_down() (--indent_level) X#define set_indent(indent_val) indent_level = indent_val X X X X/* indent to the current level */ X Xdo_indent() X X { X register int i = indent_level * 4; X X while ( i >= 8 ) X { X putchar( '\t' ); X i -= 8; X } X X while ( i > 0 ) X { X putchar( ' ' ); X --i; X } X } X X X/* generate the code to keep backtracking information */ X Xgen_backtracking() X X { X if ( reject || num_backtracking == 0 ) X return; X X if ( fullspd ) X indent_puts( "if ( yy_current_state[-1].yy_nxt )" ); X else X indent_puts( "if ( yy_accept[yy_current_state] )" ); X X indent_up(); X indent_puts( "{" ); X indent_puts( "yy_last_accepting_state = yy_current_state;" ); X indent_puts( "yy_last_accepting_cpos = yy_cp;" ); X indent_puts( "}" ); X indent_down(); X } X X X/* generate the code to perform the backtrack */ X Xgen_bt_action() X X { X if ( reject || num_backtracking == 0 ) X return; X X set_indent( 4 ); X X indent_puts( "case 0: /* must backtrack */" ); X indent_puts( "/* undo the effects of YY_DO_BEFORE_ACTION */" ); X indent_puts( "*yy_cp = yy_hold_char;" ); X X if ( fullspd || fulltbl ) X indent_puts( "yy_cp = yy_last_accepting_cpos + 1;" ); X else X /* backtracking info for compressed tables is taken \after/ X * yy_cp has been incremented for the next state X */ X indent_puts( "yy_cp = yy_last_accepting_cpos;" ); X X indent_puts( "yy_current_state = yy_last_accepting_state;" ); X indent_puts( "continue; /* go to \"YY_DO_BEFORE_ACTION\" */" ); X putchar( '\n' ); X X set_indent( 0 ); X } X X X/* genctbl - generates full speed compressed transition table X * X * synopsis X * genctbl(); X */ X Xgenctbl() X X { X register int i; X int end_of_buffer_action = num_rules + 1; X X /* table of verify for transition and offset to next state */ X printf( "static const struct yy_trans_info yy_transition[%d] =\n", X tblend + numecs + 1 ); X printf( " {\n" ); X X /* We want the transition to be represented as the offset to the X * next state, not the actual state number, which is what it currently is. X * The offset is base[nxt[i]] - base[chk[i]]. That's just the X * difference between the starting points of the two involved states X * (to - from). X * X * first, though, we need to find some way to put in our end-of-buffer X * flags and states. We do this by making a state with absolutely no X * transitions. We put it at the end of the table. X */ X /* at this point, we're guaranteed that there's enough room in nxt[] X * and chk[] to hold tblend + numecs entries. We need just two slots. X * One for the action and one for the end-of-buffer transition. We X * now *assume* that we're guaranteed the only character we'll try to X * index this nxt/chk pair with is EOB, i.e., 0, so we don't have to X * make sure there's room for jam entries for other characters. X */ X X base[lastdfa + 1] = tblend + 2; X nxt[tblend + 1] = end_of_buffer_action; X chk[tblend + 1] = numecs + 1; X chk[tblend + 2] = 1; /* anything but EOB */ X nxt[tblend + 2] = 0; /* so that "make test" won't show arb. differences */ X X /* make sure every state has a end-of-buffer transition and an action # */ X for ( i = 0; i <= lastdfa; ++i ) X { X register int anum = dfaacc[i].dfaacc_state; X X chk[base[i]] = EOB_POSITION; X chk[base[i] - 1] = ACTION_POSITION; X nxt[base[i] - 1] = anum; /* action number */ X } X X dataline = 0; X datapos = 0; X X for ( i = 0; i <= tblend; ++i ) X { X if ( chk[i] == EOB_POSITION ) X transition_struct_out( 0, base[lastdfa + 1] - i ); X X else if ( chk[i] == ACTION_POSITION ) X transition_struct_out( 0, nxt[i] ); X X else if ( chk[i] > numecs || chk[i] == 0 ) X transition_struct_out( 0, 0 ); /* unused slot */ X X else /* verify, transition */ X transition_struct_out( chk[i], base[nxt[i]] - (i - chk[i]) ); X } X X X /* here's the final, end-of-buffer state */ X transition_struct_out( chk[tblend + 1], nxt[tblend + 1] ); X transition_struct_out( chk[tblend + 2], nxt[tblend + 2] ); X X printf( " };\n" ); X printf( "\n" ); X X /* table of pointers to start states */ X printf( "static const struct yy_trans_info *yy_start_state_list[%d] =\n", X lastsc * 2 + 1 ); X printf( " {\n" ); X X for ( i = 0; i <= lastsc * 2; ++i ) X printf( " &yy_transition[%d],\n", base[i] ); X X printf( " };\n" ); X X if ( useecs ) X genecs(); X } X X X/* generate equivalence-class tables */ X Xgenecs() X X { X register int i, j; X static char C_char_decl[] = "static const char %s[%d] =\n { 0,\n"; X int numrows; X char clower(); X X printf( C_char_decl, ECARRAY, CSIZE + 1 ); X X for ( i = 1; i <= CSIZE; ++i ) X { X if ( caseins && (i >= 'A') && (i <= 'Z') ) X ecgroup[i] = ecgroup[clower( i )]; X X ecgroup[i] = abs( ecgroup[i] ); X mkdata( ecgroup[i] ); X } X X dataend(); X X if ( trace ) X { X fputs( "\n\nEquivalence Classes:\n\n", stderr ); X X numrows = (CSIZE + 1) / 8; X X for ( j = 1; j <= numrows; ++j ) X { X for ( i = j; i <= CSIZE; i = i + numrows ) X { X char *readable_form(); X X fprintf( stderr, "%4s = %-2d", X readable_form( i ), ecgroup[i] ); X X putc( ' ', stderr ); X } X X putc( '\n', stderr ); X } X } X } X X X/* generate the code to find the action number */ X Xgen_find_action() X X { X if ( fullspd ) X indent_puts( "yy_act = yy_current_state[-1].yy_nxt;" ); X X else if ( fulltbl ) X indent_puts( "yy_act = yy_accept[yy_current_state];" ); X X else if ( reject ) X { X indent_puts( "yy_current_state = *--yy_state_ptr;" ); X indent_puts( "yy_lp = yy_accept[yy_current_state];" ); X X puts( "find_rule: /* we branch to this label when backtracking */" ); X X indent_puts( "for ( ; ; ) /* until we find what rule we matched */" ); X X indent_up(); X X indent_puts( "{" ); X X indent_puts( "if ( yy_lp && yy_lp < yy_accept[yy_current_state + 1] )" ); X indent_up(); X indent_puts( "{" ); X indent_puts( "yy_act = yy_acclist[yy_lp];" ); X X if ( variable_trailing_context_rules ) X { X indent_puts( "if ( yy_act & YY_TRAILING_HEAD_MASK ||" ); X indent_puts( " yy_looking_for_trail_begin )" ); X indent_up(); X indent_puts( "{" ); X X indent_puts( "if ( yy_act == yy_looking_for_trail_begin )" ); X indent_up(); X indent_puts( "{" ); X indent_puts( "yy_looking_for_trail_begin = 0;" ); X indent_puts( "yy_act &= ~YY_TRAILING_HEAD_MASK;" ); X indent_puts( "break;" ); X indent_puts( "}" ); X indent_down(); X X indent_puts( "}" ); X indent_down(); X X indent_puts( "else if ( yy_act & YY_TRAILING_MASK )" ); X indent_up(); X indent_puts( "{" ); X indent_puts( X "yy_looking_for_trail_begin = yy_act & ~YY_TRAILING_MASK;" ); X indent_puts( X "yy_looking_for_trail_begin |= YY_TRAILING_HEAD_MASK;" ); X X if ( real_reject ) X { X /* remember matched text in case we back up due to REJECT */ X indent_puts( "yy_full_match = yy_cp;" ); X indent_puts( "yy_full_state = yy_state_ptr;" ); X indent_puts( "yy_full_lp = yy_lp;" ); X } X X indent_puts( "}" ); X indent_down(); X X indent_puts( "else" ); X indent_up(); X indent_puts( "{" ); X indent_puts( "yy_full_match = yy_cp;" ); X indent_puts( "yy_full_state = yy_state_ptr;" ); X indent_puts( "yy_full_lp = yy_lp;" ); X indent_puts( "break;" ); X indent_puts( "}" ); X indent_down(); X X indent_puts( "++yy_lp;" ); X indent_puts( "goto find_rule;" ); X } X X else X { X /* remember matched text in case we back up due to trailing context X * plus REJECT X */ X indent_up(); X indent_puts( "{" ); X indent_puts( "yy_full_match = yy_cp;" ); X indent_puts( "break;" ); X indent_puts( "}" ); X indent_down(); X } X X indent_puts( "}" ); X indent_down(); X X indent_puts( "--yy_cp;" ); X X /* we could consolidate the following two lines with those at X * the beginning, but at the cost of complaints that we're X * branching inside a loop X */ X indent_puts( "yy_current_state = *--yy_state_ptr;" ); X indent_puts( "yy_lp = yy_accept[yy_current_state];" ); X X indent_puts( "}" ); X X indent_down(); X } X X else X /* compressed */ X indent_puts( "yy_act = yy_accept[yy_current_state];" ); X } X X X/* genftbl - generates full transition table X * X * synopsis X * genftbl(); X */ X Xgenftbl() X X { X register int i; X int end_of_buffer_action = num_rules + 1; X X /* *everything* is done in terms of arrays starting at 1, so provide X * a null entry for the zero element of all C arrays X */ X static char C_short_decl[] = X "static const short int %s[%d] =\n { 0,\n"; X X printf( C_short_decl, ALIST, lastdfa + 1 ); X X X dfaacc[end_of_buffer_state].dfaacc_state = end_of_buffer_action; X X for ( i = 1; i <= lastdfa; ++i ) X { X register int anum = dfaacc[i].dfaacc_state; X X mkdata( anum ); X X if ( trace && anum ) X fprintf( stderr, "state # %d accepts: [%d]\n", i, anum ); X } X X dataend(); X X if ( useecs ) X genecs(); X X /* don't have to dump the actual full table entries - they were created X * on-the-fly X */ X } X X X/* generate the code to find the next compressed-table state */ X Xgen_next_compressed_state() X X { X char *char_map = useecs ? "yy_ec[*yy_cp]" : "*yy_cp"; X X indent_put2s( "register char yy_c = %s;", char_map ); X X /* save the backtracking info \before/ computing the next state X * because we always compute one more state than needed - we X * always proceed until we reach a jam state X */ X gen_backtracking(); X X indent_puts( X "while ( yy_chk[yy_base[yy_current_state] + yy_c] != yy_current_state )" ); X indent_up(); X indent_puts( "{" ); X indent_puts( "yy_current_state = yy_def[yy_current_state];" ); X X if ( usemecs ) X { X /* we've arrange it so that templates are never chained X * to one another. This means we can afford make a X * very simple test to see if we need to convert to X * yy_c's meta-equivalence class without worrying X * about erroneously looking up the meta-equivalence X * class twice X */ X do_indent(); X /* lastdfa + 2 is the beginning of the templates */ X printf( "if ( yy_current_state >= %d )\n", lastdfa + 2 ); X X indent_up(); X indent_puts( "yy_c = yy_meta[yy_c];" ); X indent_down(); X } X X indent_puts( "}" ); X indent_down(); X X indent_puts( X "yy_current_state = yy_nxt[yy_base[yy_current_state] + yy_c];" ); X } X X X/* generate the code to find the next match */ X Xgen_next_match() X X { /* NOTE - changes in here should be reflected in get_next_state() */ X char *char_map = useecs ? "yy_ec[*yy_cp]" : "*yy_cp"; X char *char_map_2 = useecs ? "yy_ec[*++yy_cp]" : "*++yy_cp"; X X if ( fulltbl ) X { X indent_put2s( X "while ( (yy_current_state = yy_nxt[yy_current_state][%s]) > 0 )", X char_map ); X X indent_up(); X X if ( num_backtracking > 0 ) X { X indent_puts( "{" ); X gen_backtracking(); X putchar( '\n' ); X } X X indent_puts( "++yy_cp;" ); X X if ( num_backtracking > 0 ) X indent_puts( "}" ); X X indent_down(); X X putchar( '\n' ); X indent_puts( "yy_current_state = -yy_current_state;" ); X } X X else if ( fullspd ) X { X indent_puts( "{" ); X indent_puts( "register struct yy_trans_info *yy_trans_info;\n" ); X indent_puts( "register char yy_c;\n" ); X indent_put2s( "for ( yy_c = %s;", char_map ); X indent_puts( X " (yy_trans_info = &yy_current_state[yy_c])->yy_verify == yy_c;" ); X indent_put2s( " yy_c = %s )", char_map_2 ); X X indent_up(); X X if ( num_backtracking > 0 ) X indent_puts( "{" ); X X indent_puts( "yy_current_state += yy_trans_info->yy_nxt;" ); X X if ( num_backtracking > 0 ) X { X putchar( '\n' ); X gen_backtracking(); X indent_puts( "}" ); X } X X indent_down(); X indent_puts( "}" ); X } X X else X { /* compressed */ X indent_puts( "do" ); X X indent_up(); X indent_puts( "{" ); X X gen_next_state(); X X indent_puts( "++yy_cp;" ); X X indent_puts( "}" ); X indent_down(); X X do_indent(); X X if ( interactive ) X printf( "while ( yy_base[yy_current_state] != %d );\n", jambase ); X else X printf( "while ( yy_current_state != %d );\n", jamstate ); X X if ( ! reject && ! interactive ) X { X /* do the guaranteed-needed backtrack to figure out the match */ X indent_puts( "yy_cp = yy_last_accepting_cpos;" ); X indent_puts( "yy_current_state = yy_last_accepting_state;" ); X } X } X } X X X/* generate the code to find the next state */ X Xgen_next_state() X X { /* NOTE - changes in here should be reflected in get_next_match() */ X char *char_map = useecs ? "yy_ec[*yy_cp]" : "*yy_cp"; X X if ( fulltbl ) X { X indent_put2s( "yy_current_state = yy_nxt[yy_current_state][%s];", X char_map ); X gen_backtracking(); X } X X else if ( fullspd ) X { X indent_put2s( "yy_current_state += yy_current_state[%s].yy_nxt;", X char_map ); X gen_backtracking(); X } X X else X { X gen_next_compressed_state(); X X if ( reject ) X indent_puts( "*yy_state_ptr++ = yy_current_state;" ); X } X } X X X/* generate the code to find the start state */ X Xgen_start_state() X X { X if ( fullspd ) X indent_put2s( "yy_current_state = yy_start_state_list[yy_start%s];", X bol_needed ? " + (yy_bp[-1] == '\\n' ? 1 : 0)" : "" ); X X else X { X indent_puts( "yy_current_state = yy_start;" ); X X if ( bol_needed ) X { X indent_puts( "if ( yy_bp[-1] == '\\n' )" ); X indent_up(); X indent_puts( "++yy_current_state;" ); X indent_down(); X } X X if ( reject ) X { X /* set up for storing up states */ X indent_puts( "yy_state_ptr = yy_state_buf;" ); X indent_puts( "*yy_state_ptr++ = yy_current_state;" ); X } X } X } X X X/* gentabs - generate data statements for the transition tables X * X * synopsis X * gentabs(); X */ X Xgentabs() X X { X int i, j, k, *accset, nacc, *acc_array, total_states; X int end_of_buffer_action = num_rules + 1; X X /* *everything* is done in terms of arrays starting at 1, so provide X * a null entry for the zero element of all C arrays X */ X static char C_long_decl[] = X "static const long int %s[%d] =\n { 0,\n"; X static char C_short_decl[] = X "static const short int %s[%d] =\n { 0,\n"; X static char C_char_decl[] = X "static const char %s[%d] =\n { 0,\n"; X X acc_array = allocate_integer_array( current_max_dfas ); X nummt = 0; X X /* the compressed table format jams by entering the "jam state", X * losing information about the previous state in the process. X * In order to recover the previous state, we effectively need X * to keep backtracking information. X */ X ++num_backtracking; X X if ( reject ) X { X /* write out accepting list and pointer list X * X * first we generate the ACCEPT array. In the process, we compute X * the indices that will go into the ALIST array, and save the X * indices in the dfaacc array X */ X int EOB_accepting_list[2]; X X printf( C_short_decl, ACCEPT, max( numas, 1 ) + 1 ); X X /* set up accepting structures for the End Of Buffer state */ X EOB_accepting_list[0] = 0; X EOB_accepting_list[1] = end_of_buffer_action; X accsiz[end_of_buffer_state] = 1; X dfaacc[end_of_buffer_state].dfaacc_set = EOB_accepting_list; X X j = 1; /* index into ACCEPT array */ X X for ( i = 1; i <= lastdfa; ++i ) X { X acc_array[i] = j; X X if ( accsiz[i] != 0 ) X { X accset = dfaacc[i].dfaacc_set; X nacc = accsiz[i]; X X if ( trace ) X fprintf( stderr, "state # %d accepts: ", i ); X X for ( k = 1; k <= nacc; ++k ) X { X int accnum = accset[k]; X X ++j; X X if ( variable_trailing_context_rules && X ! (accnum & YY_TRAILING_HEAD_MASK) && X accnum > 0 && X rule_type[accnum] == RULE_VARIABLE ) X { X /* special hack to flag accepting number as part X * of trailing context rule X */ X accnum |= YY_TRAILING_MASK; X } X X mkdata( accnum ); X X if ( trace ) X { X fprintf( stderr, "[%d]", accset[k] ); X X if ( k < nacc ) X fputs( ", ", stderr ); X else X putc( '\n', stderr ); X } X } X } X } X X /* add accepting number for the "jam" state */ X acc_array[i] = j; X X dataend(); X } X X else X { X dfaacc[end_of_buffer_state].dfaacc_state = end_of_buffer_action; X X for ( i = 1; i <= lastdfa; ++i ) X acc_array[i] = dfaacc[i].dfaacc_state; X X /* add accepting number for jam state */ X acc_array[i] = 0; X } X X /* spit out ALIST array. If we're doing "reject", it'll be pointers X * into the ACCEPT array. Otherwise it's actual accepting numbers. X * In either case, we just dump the numbers. X */ X X /* "lastdfa + 2" is the size of ALIST; includes room for C arrays X * beginning at 0 and for "jam" state X */ X k = lastdfa + 2; X X if ( reject ) X /* we put a "cap" on the table associating lists of accepting X * numbers with state numbers. This is needed because we tell X * where the end of an accepting list is by looking at where X * the list for the next state starts. X */ X ++k; X X printf( C_short_decl, ALIST, k ); X X for ( i = 1; i <= lastdfa; ++i ) X { X mkdata( acc_array[i] ); X X if ( ! reject && trace && acc_array[i] ) X fprintf( stderr, "state # %d accepts: [%d]\n", i, acc_array[i] ); X } X X /* add entry for "jam" state */ X mkdata( acc_array[i] ); X X if ( reject ) X /* add "cap" for the list */ X mkdata( acc_array[i] ); X X dataend(); X X if ( useecs ) X genecs(); X X if ( usemecs ) X { X /* write out meta-equivalence classes (used to index templates with) */ X X if ( trace ) X fputs( "\n\nMeta-Equivalence Classes:\n", stderr ); X X printf( C_char_decl, MATCHARRAY, numecs + 1 ); X X for ( i = 1; i <= numecs; ++i ) X { X if ( trace ) X fprintf( stderr, "%d = %d\n", i, abs( tecbck[i] ) ); X X mkdata( abs( tecbck[i] ) ); X } X X dataend(); X } X X total_states = lastdfa + numtemps; X X printf( tblend > MAX_SHORT ? C_long_decl : C_short_decl, X BASEARRAY, total_states + 1 ); X X for ( i = 1; i <= lastdfa; ++i ) X { X register int d = def[i]; X X if ( base[i] == JAMSTATE ) X base[i] = jambase; X X if ( d == JAMSTATE ) X def[i] = jamstate; X X else if ( d < 0 ) X { X /* template reference */ X ++tmpuses; X def[i] = lastdfa - d + 1; X } X X mkdata( base[i] ); X } X X /* generate jam state's base index */ X mkdata( base[i] ); X X for ( ++i /* skip jam state */; i <= total_states; ++i ) X { X mkdata( base[i] ); X def[i] = jamstate; X } X X dataend(); X X printf( tblend > MAX_SHORT ? C_long_decl : C_short_decl, X DEFARRAY, total_states + 1 ); X X for ( i = 1; i <= total_states; ++i ) X mkdata( def[i] ); X X dataend(); X X printf( lastdfa > MAX_SHORT ? C_long_decl : C_short_decl, X NEXTARRAY, tblend + 1 ); X X for ( i = 1; i <= tblend; ++i ) X { X if ( nxt[i] == 0 || chk[i] == 0 ) X nxt[i] = jamstate; /* new state is the JAM state */ X X mkdata( nxt[i] ); X } X X dataend(); X X printf( lastdfa > MAX_SHORT ? C_long_decl : C_short_decl, X CHECKARRAY, tblend + 1 ); X X for ( i = 1; i <= tblend; ++i ) X { X if ( chk[i] == 0 ) X ++nummt; X X mkdata( chk[i] ); X } X X dataend(); X } X X X/* write out a formatted string (with a secondary string argument) at the X * current indentation level, adding a final newline X */ X Xindent_put2s( fmt, arg ) Xchar fmt[], arg[]; X X { X do_indent(); X printf( fmt, arg ); X putchar( '\n' ); X } X X X/* write out a string at the current indentation level, adding a final X * newline X */ X Xindent_puts( str ) Xchar str[]; X X { X do_indent(); X puts( str ); X } X X X/* make_tables - generate transition tables X * X * synopsis X * make_tables(); X * X * Generates transition tables and finishes generating output file X */ X Xmake_tables() X X { X register int i; X int did_eof_rule = false; X X printf( "#define YY_END_OF_BUFFER %d\n", num_rules + 1 ); X X if ( fullspd ) X { /* need to define the transet type as a size large X * enough to hold the biggest offset X */ X int total_table_size = tblend + numecs + 1; X char *trans_offset_type = X total_table_size > MAX_SHORT ? "long" : "short"; X X set_indent( 0 ); X indent_puts( "struct yy_trans_info" ); X indent_up(); X indent_puts( "{" ); X indent_puts( "short yy_verify;" ); X X /* in cases where its sister yy_verify *is* a "yes, there is a X * transition", yy_nxt is the offset (in records) to the next state. X * In most cases where there is no transition, the value of yy_nxt X * is irrelevant. If yy_nxt is the -1th record of a state, though, X * then yy_nxt is the action number for that state X */ X X indent_put2s( "%s yy_nxt;", trans_offset_type ); X indent_puts( "};" ); X indent_down(); X X indent_puts( "typedef struct yy_trans_info *yy_state_type;" ); X } X X else X indent_puts( "typedef int yy_state_type;" ); X X if ( fullspd ) X genctbl(); X X else if ( fulltbl ) X genftbl(); X X else X gentabs(); X X if ( reject ) X { X /* declare state buffer variables */ X puts( "yy_state_type yy_state_buf[YY_BUF_SIZE + 2], *yy_state_ptr;" ); X puts( "char *yy_full_match;" ); X puts( "int yy_lp;" ); X X if ( variable_trailing_context_rules ) X { X puts( "int yy_looking_for_trail_begin = 0;" ); X puts( "int yy_full_lp;" ); X puts( "int *yy_full_state;" ); X printf( "#define YY_TRAILING_MASK 0x%x\n", YY_TRAILING_MASK ); X printf( "#define YY_TRAILING_HEAD_MASK 0x%x\n", X YY_TRAILING_HEAD_MASK ); X } X X puts( "#define REJECT \\" ); X puts( "{ \\" ); X puts( X "*yy_cp = yy_hold_char; /* undo effects of setting up yytext */ \\" ); X puts( X "yy_cp = yy_full_match; /* restore poss. backed-over text */ \\" ); X X if ( variable_trailing_context_rules ) X { X puts( "yy_lp = yy_full_lp; /* restore orig. accepting pos. */ \\" ); X puts( X "yy_state_ptr = yy_full_state; /* restore orig. state */ \\" ); X puts( X "yy_current_state = *yy_state_ptr; /* restore curr. state */ \\" ); X } X X puts( "++yy_lp; \\" ); X puts( "goto find_rule; \\" ); X puts( "}" ); X } X X else X { X puts( "/* the intent behind this definition is that it'll catch" ); X puts( " * any uses of REJECT which flex missed" ); X puts( " */" ); X puts( "#define REJECT reject_used_but_not_detected" ); X } X X if ( yymore_used ) X { X indent_puts( "static char *yy_more_pos = (char *) 0;" ); X indent_puts( "#define yymore() (yy_more_pos = yy_bp)" ); X } X X else X indent_puts( "#define yymore() yymore_used_but_not_detected" ); X X X skelout(); X X (void) fclose( temp_action_file ); X temp_action_file = fopen( action_file_name, "r" ); X X /* copy prolog from action_file to output file */ X action_out(); X X skelout(); X X set_indent( 2 ); X X if ( yymore_used ) X { X indent_puts( "if ( yy_more_pos )" ); X indent_up(); X indent_puts( "{" ); X indent_puts( "yy_bp = yy_more_pos;" ); X indent_puts( "yy_more_pos = (char *) 0;" ); X indent_puts( "}" ); X indent_down(); X indent_puts( "else" ); X indent_up(); X indent_puts( "yy_bp = yy_cp;" ); X indent_down(); X } X X else X indent_puts( "yy_bp = yy_cp;" ); X X skelout(); X X gen_start_state(); X gen_next_match(); X X skelout(); X set_indent( 3 ); X gen_find_action(); X X /* copy actions from action_file to output file */ X skelout(); X indent_up(); X gen_bt_action(); X action_out(); X X /* generate cases for any missing EOF rules */ X for ( i = 1; i <= lastsc; ++i ) X if ( ! sceof[i] ) X { X do_indent(); X printf( "case YY_STATE_EOF(%s):\n", scname[i] ); X did_eof_rule = true; X } X X if ( did_eof_rule ) X { X indent_up(); X indent_puts( "yyterminate();" ); X indent_down(); X } X X X /* generate code for yy_get_previous_state() */ X set_indent( 1 ); X skelout(); X X if ( bol_needed ) X indent_puts( "register char *yy_bp = yytext;\n" ); X X gen_start_state(); X X set_indent( 2 ); X skelout(); X gen_next_state(); X X skelout(); X X /* copy remainder of input to output */ X X line_directive_out( stdout ); X (void) flexscan(); /* copy remainder of input to output */ X } END_OF_FILE if test 25254 -ne `wc -c <'flex/gen.c'`; then echo shar: \"'flex/gen.c'\" unpacked with wrong size! fi # end of 'flex/gen.c' fi echo shar: End of archive 6 \(of 7\). cp /dev/null ark6isdone MISSING="" for I in 1 2 3 4 5 6 7 ; do if test ! -f ark${I}isdone ; then MISSING="${MISSING} ${I}" fi done if test "${MISSING}" = "" ; then echo You have unpacked all 7 archives. rm -f ark[1-9]isdone else echo You still need to unpack the following archives: echo " " ${MISSING} fi ## End of shell archive. exit 0 -- Please send comp.sources.unix-related mail to rsalz@uunet.uu.net. Use a domain-based address or give alternate paths, or you may lose out.