From: Vern Paxson Date: Sat, 13 Feb 1988 11:00:46 +0000 (+0000) Subject: Beta Release. X-Git-Tag: flex-2-5-5b~658 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=c58120445fe8edf709bbb987a3d665f6d5201b55;p=flex Beta Release. --- diff --git a/ccl.c b/ccl.c index fa15c02..a99241b 100644 --- a/ccl.c +++ b/ccl.c @@ -1,7 +1,15 @@ -/* lexccl - routines for character classes */ +/* flexccl - routines for character classes */ /* - * Copyright (c) University of California, 1987 + * Copyright (c) 1987, the University of California + * + * 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. + * + * This program may be redistributed. Enhancements and derivative works + * may be created provided the new works, if made available to the general + * public, are made available for use by anyone. */ #include "flexdef.h" @@ -13,6 +21,7 @@ * char ch; * ccladd( cclp, ch ); */ + ccladd( cclp, ch ) int cclp; char ch; @@ -51,6 +60,7 @@ char ch; * int cclinit(); * new_ccl = cclinit(); */ + int cclinit() { @@ -90,6 +100,7 @@ int cclinit() * int cclp; * cclnegate( ccl ); */ + cclnegate( cclp ) int cclp; diff --git a/dfa.c b/dfa.c index d709df8..e5cc9a2 100644 --- a/dfa.c +++ b/dfa.c @@ -1,7 +1,15 @@ -/* lexdfa - DFA construction routines */ +/* flexdfa - DFA construction routines */ /* - * Copyright (c) University of California, 1987 + * Copyright (c) 1987, the University of California + * + * 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. + * + * This program may be redistributed. Enhancements and derivative works + * may be created provided the new works, if made available to the general + * public, are made available for use by anyone. */ #include "flexdef.h" @@ -26,6 +34,7 @@ * * hashval is the hash value for the dfa corresponding to the state set */ + int *epsclosure( t, ns_addr, accset, nacc_addr, hv_addr ) int *t, *ns_addr, accset[], *nacc_addr, *hv_addr; @@ -136,7 +145,7 @@ int *t, *ns_addr, accset[], *nacc_addr, *hv_addr; UNMARK_STATE(stk[stkpos]) } else - lexfatal( "consistency check failed in epsclosure()" ); + flexfatal( "consistency check failed in epsclosure()" ); } *ns_addr = numstates; @@ -166,7 +175,7 @@ increase_max_dfas() dhash = reallocate_integer_array( dhash, current_max_dfas ); todo = reallocate_integer_array( todo, current_max_dfas ); dss = reallocate_integer_pointer_array( dss, current_max_dfas ); - dfaacc = reallocate_integer_pointer_array( dfaacc, current_max_dfas ); + dfaacc = reallocate_dfaacc_union( dfaacc, current_max_dfas ); /* fix up todo queue */ if ( todo_next < todo_head ) @@ -190,6 +199,7 @@ increase_max_dfas() * * on return, the dfa state number is in newds. */ + int snstods( sns, numstates, accset, nacc, hashval, newds_addr ) int sns[], numstates, accset[], nacc, hashval, *newds_addr; @@ -242,7 +252,7 @@ int sns[], numstates, accset[], nacc, hashval, *newds_addr; newds = lastdfa; if ( ! (dss[newds] = (int *) malloc( (unsigned) ((numstates + 1) * sizeof( int )) )) ) - lexfatal( "dynamic memory failure in snstods()" ); + flexfatal( "dynamic memory failure in snstods()" ); /* if we haven't already sorted the states in sns, we do so now, so that * future comparisons with it can be made quickly @@ -259,7 +269,7 @@ int sns[], numstates, accset[], nacc, hashval, *newds_addr; if ( nacc == 0 ) { - dfaacc[newds] = 0; + dfaacc[newds].dfaacc_state = 0; accsiz[newds] = 0; } @@ -273,13 +283,15 @@ int sns[], numstates, accset[], nacc, hashval, *newds_addr; bubble( accset, nacc ); - if ( ! (dfaacc[newds] = - (int *) malloc( (unsigned) ((nacc + 1) * sizeof( int )) )) ) - lexfatal( "dynamic memory failure in snstods()" ); + dfaacc[newds].dfaacc_state = + (int) malloc( (unsigned) ((nacc + 1) * sizeof( int )) ); + + if ( ! dfaacc[newds].dfaacc_state ) + flexfatal( "dynamic memory failure in snstods()" ); /* save the accepting set for later */ for ( i = 1; i <= nacc; ++i ) - dfaacc[newds][i] = accset[i]; + dfaacc[newds].dfaacc_set[i] = accset[i]; accsiz[newds] = nacc; } @@ -292,7 +304,7 @@ int sns[], numstates, accset[], nacc, hashval, *newds_addr; if ( accset[i] < j ) j = accset[i]; - dfaacc[newds] = (int *) j; + dfaacc[newds].dfaacc_state = j; } *newds_addr = newds; @@ -308,6 +320,7 @@ int sns[], numstates, accset[], nacc, hashval, *newds_addr; * int nset[current_max_dfa_size], numstates; * numstates = symfollowset( ds, dsize, transsym, nset ); */ + int symfollowset( ds, dsize, transsym, nset ) int ds[], dsize, transsym, nset[]; @@ -363,7 +376,7 @@ int ds[], dsize, transsym, nset[]; } else if ( sym >= 'A' && sym <= 'Z' && caseins ) - lexfatal( "consistency check failed in symfollowset" ); + flexfatal( "consistency check failed in symfollowset" ); else if ( sym == SYM_EPSILON ) { /* do nothing */ @@ -387,6 +400,7 @@ bottom: * symlist[numecs]; * sympartition( ds, numstates, symlist, duplist ); */ + sympartition( ds, numstates, symlist, duplist ) int ds[], numstates, duplist[]; int symlist[]; @@ -416,7 +430,7 @@ int symlist[]; if ( tch != SYM_EPSILON ) { if ( tch < -lastccl || tch > CSIZE ) - lexfatal( "bad transition character detected in sympartition()" ); + flexfatal( "bad transition character detected in sympartition()" ); if ( tch > 0 ) { /* character transition */ diff --git a/ecs.c b/ecs.c index 2a60c9b..8c01338 100644 --- a/ecs.c +++ b/ecs.c @@ -1,7 +1,15 @@ -/* lexecs - equivalence class routines */ +/* flexecs - equivalence class routines */ /* - * Copyright (c) University of California, 1987 + * Copyright (c) 1987, the University of California + * + * 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. + * + * This program may be redistributed. Enhancements and derivative works + * may be created provided the new works, if made available to the general + * public, are made available for use by anyone. */ #include "flexdef.h" @@ -11,6 +19,7 @@ * synopsis * ccl2ecl(); */ + ccl2ecl() { @@ -54,6 +63,7 @@ ccl2ecl() * is the backward linked-list, and num is the number of class members. * Returned is the number of classes. */ + int cre8ecs( fwd, bck, num ) int fwd[], bck[], num; @@ -91,6 +101,7 @@ int fwd[], bck[], num; * number of elements in the ccl, fwd is the forward link-list of equivalent * characters, bck is the backward link-list, and llsiz size of the link-list */ + mkeccl( ccls, lenccl, fwd, bck, llsiz ) char ccls[]; int lenccl, fwd[], bck[], llsiz; @@ -171,6 +182,7 @@ next_pt: * int tch, fwd[], bck[]; * mkechar( tch, fwd, bck ); */ + mkechar( tch, fwd, bck ) int tch, fwd[], bck[]; diff --git a/flexdef.h b/flexdef.h index b41b649..d668a03 100644 --- a/flexdef.h +++ b/flexdef.h @@ -1,17 +1,35 @@ /* - * Symbol definitions for flex. + * Definitions for flex. * * modification history * -------------------- - * 02a vp 27jun86 .translated into C/FTL + * 02b kg, vp 30sep87 .added definitions for fast scanner; misc. cleanup + * 02a vp 27jun86 .translated into C/FTL */ /* - * Copyright (c) University of California, 1987 + * Copyright (c) 1987, the University of California + * + * 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. + * + * This program may be redistributed. Enhancements and derivative works + * may be created provided the new works, if made available to the general + * public, are made available for use by anyone. */ #include +#ifdef SV +#include +#define bzero(s, n) memset((char *)(s), '\000', (unsigned)(n)) +#else +#include +#endif + +char *sprintf(); /* keep lint happy */ + /* maximum line length we'll have to deal with */ #define MAXLINE BUFSIZ @@ -30,13 +48,21 @@ #define DEFAULT_SKELETON_FILE "flex.skel" #endif -/* maximum number of characters per line recognized by Fortran compiler */ -#define DATALINEWIDTH 72 +#ifndef FAST_SKELETON_FILE +#define FAST_SKELETON_FILE "flex.fastskel" +#endif + +/* special nxt[] action number for the "at the end of the input buffer" state */ +/* note: -1 is already taken by YY_NEW_FILE */ +#define END_OF_BUFFER_ACTION -3 +/* action number for default action for fast scanners */ +#define DEFAULT_ACTION -2 -/* string to indent Fortran data statements with */ -#define DATAINDENTSTR " " -/* width of dataindent string in Fortran columns */ -#define DATAINDENTWIDTH 6 +/* special chk[] values marking the slots taking by end-of-buffer and action + * numbers + */ +#define EOB_POSITION -1 +#define ACTION_POSITION -2 /* number of data items per line for -f output */ #define NUMDATAITEMS 10 @@ -46,6 +72,9 @@ */ #define NUMDATALINES 10 +/* transition_struct_out() definitions */ +#define TRANS_STRUCT_PRINT_LENGTH 15 + /* returns true if an nfa state has an epsilon out-transition slot * that can be used. This definition is currently not used. */ @@ -186,11 +215,22 @@ #define MSP 50 /* maximum number of saved protos (protos on the proto queue) */ +/* maximum number of out-transitions a state can have that we'll rummage + * around through the interior of the internal fast table looking for a + * spot for it + */ +#define MAX_XTIONS_FOR_FULL_INTERIOR_FIT 4 + /* number that, if used to subscript an array, has a good chance of producing * an error; should be small enough to fit into a short */ #define BAD_SUBSCRIPT -32767 +/* absolute value of largest number that can be stored in a short, with a + * bit of slop thrown in for general paranoia. + */ +#define MAX_SHORT 32766 + /* Declarations for global variables. */ @@ -231,10 +271,13 @@ extern struct hash_entry *ccltab[CCL_HASH_SIZE]; * fulltbl - if true (-cf flag), don't compress the DFA state table * usemecs - if true (-cm flag), use meta-equivalence classes * reject - if true (-r flag), generate tables for REJECT macro + * fullspd - if true (-F flag), use Jacobson method of table representation + * gen_line_dirs - if true (i.e., no -L flag), generate #line directives */ extern int printstats, syntaxerror, eofseen, ddebug, trace, spprdflt; -extern int interactive, caseins, genftl, useecs, fulltbl, usemecs, reject; +extern int interactive, caseins, useecs, fulltbl, usemecs, reject; +extern int fullspd, gen_line_dirs; /* variables used in the flex input routines: @@ -243,13 +286,16 @@ extern int interactive, caseins, genftl, useecs, fulltbl, usemecs, reject; * statement. Used to generate readable -f output * skelfile - fd of the skeleton file * yyin - input file + * temp_action_file - temporary file to hold actions + * action_file_name - name of the temporary file * infilename - name of input file * linenum - current input line number */ extern int datapos, dataline, linenum; -extern FILE *skelfile, *yyin; +extern FILE *skelfile, *yyin, *temp_action_file; extern char *infilename; +extern char *action_file_name; /* variables for stack of states having only one out-transition: @@ -352,15 +398,21 @@ extern int lastsc, current_max_scs, *scset, *scbol, *scxclu, *actvsc; * numsnpairs - number of state/nextstate transition pairs * jambase - position in base/def where the default jam table starts * jamstate - state number corresponding to "jam" state + * end_of_buffer_state - end-of-buffer dfa state number */ extern int current_max_dfa_size, current_max_xpairs; extern int current_max_template_xpairs, current_max_dfas; extern int lastdfa, lasttemp, *nxt, *chk, *tnxt; -extern int *base, *def, tblend, firstfree, **dss, *dfasiz, **dfaacc; +extern int *base, *def, tblend, firstfree, **dss, *dfasiz; +extern union dfaacc_union + { + int *dfaacc_set; + int dfaacc_state; + } *dfaacc; extern int *accsiz, *dhash, *todo, todo_head, todo_next, numas; extern int numsnpairs, jambase, jamstate; - +extern int end_of_buffer_state; /* variables for ccl information: * lastccl - ccl index of the last created ccl @@ -414,9 +466,16 @@ char *allocate_array(), *reallocate_array(); #define allocate_integer_pointer_array(size) \ (int **) allocate_array( size, sizeof( int * ) ) +#define allocate_dfaacc_union(size) \ + (union dfaacc_union *) \ + allocate_array( size, sizeof( union dfaacc_union ) ) + #define reallocate_integer_pointer_array(array,size) \ (int **) reallocate_array( (char *) array, size, sizeof( int * ) ) +#define reallocate_dfaacc_union(array, size) \ + (union dfaacc_union *) reallocate_array( (char *) array, size, sizeof( union dfaacc_union ) ) + #define allocate_character_array(size) allocate_array( size, sizeof( char ) ) #define reallocate_character_array(array,size) \ diff --git a/main.c b/main.c index d0a7ae1..aff4dc4 100644 --- a/main.c +++ b/main.c @@ -1,21 +1,31 @@ /* flex - tool to generate fast lexical analyzers * - * Copyright (c) University of California, 1987 * + * Copyright (c) 1987, the University of California + * + * 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. + * + * This program may be redistributed. Enhancements and derivative works + * may be created provided the new works, if made available to the general + * public, are made available for use by anyone. * - * ver date who remarks - * --- ---- --- ------------------------------------------------------- - * 04a 27Jun86 VP .translated from Ratfor into C - * 01a 22Aug83 VP .written. Original version by Jef Poskanzer. + * + * ver date who remarks + * --- ---- ------ ------------------------------------------------------- + * 04b 30sep87 kg, vp .implemented (part of) Van Jacobson's fast scanner design + * 04a 27jun86 vp .translated from Ratfor into C + * 01a 22aug83 vp .written. Original version by Jef Poskanzer. */ - #include "flexdef.h" /* these globals are all defined and commented in flexdef.h */ int printstats, syntaxerror, eofseen, ddebug, trace, spprdflt; -int interactive, caseins, genftl, useecs, fulltbl, usemecs, reject; +int interactive, caseins, useecs, fulltbl, usemecs, reject; +int fullspd, gen_line_dirs; int datapos, dataline, linenum; FILE *skelfile = NULL; char *infilename = NULL; @@ -32,7 +42,8 @@ int lastsc, current_max_scs, *scset, *scbol, *scxclu, *actvsc; int current_max_dfa_size, current_max_xpairs; int current_max_template_xpairs, current_max_dfas; int lastdfa, *nxt, *chk, *tnxt; -int *base, *def, tblend, firstfree, numtemps, **dss, *dfasiz, **dfaacc; +int *base, *def, tblend, firstfree, numtemps, **dss, *dfasiz; +union dfaacc_union *dfaacc; int *accsiz, *dhash, *todo, todo_head, todo_next, numas; int numsnpairs, jambase, jamstate; int lastccl, current_maxccls, *cclmap, *ccllen, *cclng, cclreuse; @@ -41,6 +52,9 @@ char *ccltbl; char *starttime, *endtime, nmstr[MAXLINE]; int sectnum, nummt, hshcol, dfaeql, numeps, eps2, num_reallocs; int tmpuses, totnst, peakpairs, numuniq, numdup, hshsave; +FILE *temp_action_file; +int end_of_buffer_state; +char *action_file_name = "/tmp/flexXXXXXX"; /* flex - main program @@ -54,7 +68,8 @@ int argc; char **argv; { - lexinit( argc, argv ); + flexinit( argc, argv ); + readin(); if ( ! syntaxerror ) @@ -62,21 +77,21 @@ char **argv; /* convert the ndfa to a dfa */ ntod(); - /* generate the ratfor state transition tables from the dfa */ - gentabs(); + /* generate the C state transition tables from the DFA */ + make_tables(); } - /* note, lexend does not return. It exits with its argument as status. */ + /* note, flexend does not return. It exits with its argument as status. */ - lexend( 0 ); + flexend( 0 ); } -/* lexend - terminate flex +/* flexend - terminate flex * * synopsis * int status; - * lexend( status ); + * flexend( status ); * * status is exit status. * @@ -84,7 +99,7 @@ char **argv; * This routine does not return. */ -lexend( status ) +flexend( status ) int status; { @@ -94,6 +109,9 @@ int status; if ( skelfile != NULL ) (void) fclose( skelfile ); + (void) fclose( temp_action_file ); + (void) unlink( action_file_name ); + if ( printstats ) { endtime = gettime(); @@ -102,9 +120,6 @@ int status; fprintf( stderr, " started at %s, finished at %s\n", starttime, endtime ); - if ( ! genftl ) - fprintf( stderr, " Ratfor scanner generated\n" ); - fprintf( stderr, " %d/%d NFA states\n", lastnfa, current_mns ); fprintf( stderr, " %d/%d DFA states (%d words)\n", lastdfa, current_max_dfas, totnst ); @@ -175,26 +190,25 @@ int status; } -/* lexinit - initialize flex +/* flexinit - initialize flex * * synopsis * int argc; * char **argv; - * lexinit( argc, argv ); + * flexinit( argc, argv ); */ -lexinit( argc, argv ) +flexinit( argc, argv ) int argc; char **argv; { - int i; - char *arg, *skelname = DEFAULT_SKELETON_FILE, *gettime(), clower(); - int sawcmpflag, use_stdout; + int i, sawcmpflag, use_stdout; + char *arg, *skelname = NULL, *gettime(), clower(), *mktemp(); printstats = syntaxerror = trace = spprdflt = interactive = caseins = false; - ddebug = fulltbl = reject = false; - usemecs = genftl = useecs = true; + ddebug = fulltbl = reject = fullspd = false; + gen_line_dirs = usemecs = useecs = true; sawcmpflag = false; use_stdout = false; @@ -212,7 +226,7 @@ char **argv; { case 'c': if ( i != 1 ) - lexerror( "-c flag must be given separately" ); + flexerror( "-c flag must be given separately" ); if ( ! sawcmpflag ) { @@ -262,21 +276,22 @@ char **argv; caseins = true; break; - case 'l': - use_stdout = false; - break; - - case 'n': - printstats = false; + case 'L': + gen_line_dirs = false; break; case 'r': reject = true; break; + case 'F': + fullspd = true; + useecs = usemecs = false; + break; + case 'S': if ( i != 1 ) - lexerror( "-S flag must be given separately" ); + flexerror( "-S flag must be given separately" ); skelname = arg + i + 1; goto get_next_arg; @@ -307,23 +322,41 @@ get_next_arg: /* used by -c and -S flags in lieu of a "continue 2" control */ } if ( fulltbl && usemecs ) - lexerror( "full table and -cm don't make sense together" ); + flexerror( "full table and -cm don't make sense together" ); if ( fulltbl && interactive ) - lexerror( "full table and -I are (currently) incompatible" ); + flexerror( "full table and -I are (currently) incompatible" ); + + if ( (fulltbl || fullspd) && reject ) + flexerror( "reject (-r) cannot be used with -f or -F" ); + + if ( fulltbl && fullspd ) + flexerror( "full table and -F are mutually exclusive" ); + + if ( ! skelname ) + { + static char skeleton_name_storage[400]; + + skelname = skeleton_name_storage; + + if ( fullspd || fulltbl ) + (void) strcpy( skelname, FAST_SKELETON_FILE ); + else + (void) strcpy( skelname, DEFAULT_SKELETON_FILE ); + } if ( ! use_stdout ) { FILE *prev_stdout = freopen( "lex.yy.c", "w", stdout ); if ( prev_stdout == NULL ) - lexerror( "could not create lex.yy.c" ); + flexerror( "could not create lex.yy.c" ); } if ( argc ) { if ( argc > 1 ) - lexerror( "extraneous argument(s) given" ); + flexerror( "extraneous argument(s) given" ); yyin = fopen( infilename = argv[0], "r" ); @@ -343,6 +376,11 @@ get_next_arg: /* used by -c and -S flags in lieu of a "continue 2" control */ if ( (skelfile = fopen( skelname, "r" )) == NULL ) lerrsf( "can't open skeleton file %s", skelname ); + (void) mktemp( action_file_name ); + + if ( (temp_action_file = fopen( action_file_name, "w" )) == NULL ) + lerrsf( "can't open temporary action file %s", action_file_name ); + lastdfa = lastnfa = accnum = numas = numsnpairs = tmpuses = 0; numecs = numeps = eps2 = num_reallocs = hshcol = dfaeql = totnst = 0; numuniq = numdup = hshsave = eofseen = datapos = dataline = 0; @@ -388,60 +426,35 @@ get_next_arg: /* used by -c and -S flags in lieu of a "continue 2" control */ * synopsis * readin(); */ + readin() { - if ( genftl ) - { - fputs( "#define YYDEFAULTACTION ", stdout ); - - if ( spprdflt ) - fputs( "YYFATALERROR( \"flex scanner jammed\" )", stdout ); - else - fputs( "ECHO", stdout ); - - fputs( ";\n", stdout ); - - if ( ddebug ) - puts( "#define LEX_DEBUG" ); - if ( useecs ) - puts( "#define LEX_USE_ECS" ); - if ( usemecs ) - puts( "#define LEX_USE_MECS" ); - if ( interactive ) - puts( "#define LEX_INTERACTIVE_SCANNER" ); - if ( reject ) - puts( "#define LEX_REJECT_ENABLED" ); - if ( fulltbl ) - puts( "#define LEX_FULL_TABLE" ); - } + fputs( "#define YY_DEFAULT_ACTION ", stdout ); + if ( spprdflt ) + fputs( "YY_FATAL_ERROR( \"flex scanner jammed\" )", stdout ); else - { - fputs( "define(YYDEFAULTACTION,", stdout ); - - if ( spprdflt ) - fputs( "call error( \"flex scanner jammed\" )", stdout ); - else - fputs( "ECHO", stdout ); + fputs( "ECHO", stdout ); - fputs( ")\n", stdout ); + fputs( ";\n", stdout ); - if ( ddebug ) - puts( "define(LEX_DEBUG,)" ); - if ( useecs ) - puts( "define(LEX_USE_ECS,)" ); - if ( usemecs ) - puts( "define(LEX_USE_MECS,)" ); - if ( reject ) - puts( "define(LEX_REJECT_ENABLED,)" ); - if ( fulltbl ) - puts( "define(LEX_FULL_TABLE,)" ); - } + if ( ddebug ) + puts( "#define FLEX_DEBUG" ); + if ( useecs ) + puts( "#define FLEX_USE_ECS" ); + if ( usemecs ) + puts( "#define FLEX_USE_MECS" ); + if ( interactive ) + puts( "#define FLEX_INTERACTIVE_SCANNER" ); + if ( reject ) + puts( "#define FLEX_REJECT_ENABLED" ); + if ( fulltbl ) + puts( "#define FLEX_FULL_TABLE" ); skelout(); - line_directive_out(); + line_directive_out( stdout ); if ( yyparse() ) lerrif( "fatal parse error at line %d", linenum ); @@ -454,6 +467,7 @@ readin() else numecs = CSIZE; + } @@ -503,5 +517,5 @@ set_up_initial_allocations() dhash = allocate_integer_array( current_max_dfas ); todo = allocate_integer_array( current_max_dfas ); dss = allocate_integer_pointer_array( current_max_dfas ); - dfaacc = allocate_integer_pointer_array( current_max_dfas ); + dfaacc = allocate_dfaacc_union( current_max_dfas ); } diff --git a/misc.c b/misc.c index 3364e4c..157c3d3 100644 --- a/misc.c +++ b/misc.c @@ -1,7 +1,15 @@ -/* lexmisc - miscellaneous flex routines */ +/* flexmisc - miscellaneous flex routines */ /* - * Copyright (c) University of California, 1987 + * Copyright (c) 1987, the University of California + * + * 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. + * + * This program may be redistributed. Enhancements and derivative works + * may be created provided the new works, if made available to the general + * public, are made available for use by anyone. */ #include @@ -10,6 +18,27 @@ char *malloc(), *realloc(); +/* action_out - write the actions from the temporary file to lex.yy.c + * + * synopsis + * action_out(); + * + * Copies the action file up to %% (or end-of-file) to lex.yy.c + */ + +action_out() + + { + char buf[MAXLINE]; + + while ( fgets( buf, MAXLINE, temp_action_file ) != NULL ) + if ( buf[0] == '%' && buf[1] == '%' ) + break; + else + fputs( buf, stdout ); + } + + /* allocate_array - allocate memory for an integer array of the given size */ char *allocate_array( size, element_size ) @@ -19,7 +48,7 @@ int size, element_size; register char *mem = malloc( (unsigned) (element_size * size) ); if ( mem == NULL ) - lexfatal( "memory allocation failed in allocate_array()" ); + flexfatal( "memory allocation failed in allocate_array()" ); return ( mem ); } @@ -92,7 +121,7 @@ register char *str; copy = malloc( (unsigned) ((c - str + 1) * sizeof( char )) ); if ( copy == NULL ) - lexfatal( "dynamic memory failure in copy_string()" ); + flexfatal( "dynamic memory failure in copy_string()" ); for ( c = copy; (*c++ = *str++); ) ; @@ -151,9 +180,8 @@ dataend() if ( datapos > 0 ) dataflush(); - if ( genftl ) - /* add terminator for initialization */ - puts( " } ;\n" ); + /* add terminator for initialization */ + puts( " } ;\n" ); dataline = 0; } @@ -170,23 +198,19 @@ dataflush() { putchar( '\n' ); - if ( genftl ) + if ( ++dataline >= NUMDATALINES ) { - if ( ++dataline >= NUMDATALINES ) - { - /* put out a blank line so that the table is grouped into - * large blocks that enable the user to find elements easily - */ - putchar( '\n' ); - dataline = 0; - } + /* put out a blank line so that the table is grouped into + * large blocks that enable the user to find elements easily + */ + putchar( '\n' ); + dataline = 0; } /* reset the number of characters written on the current line */ datapos = 0; } - /* gettime - return current time * * synopsis @@ -230,7 +254,7 @@ int arg; { char errmsg[MAXLINE]; (void) sprintf( errmsg, msg, arg ); - lexerror( errmsg ); + flexerror( errmsg ); } @@ -246,199 +270,115 @@ char msg[], arg[]; { char errmsg[MAXLINE]; + (void) sprintf( errmsg, msg, arg ); - lexerror( errmsg ); + flexerror( errmsg ); } -/* lexerror - report an error message and terminate +/* flexerror - report an error message and terminate * * synopsis * char msg[]; - * lexerror( msg ); + * flexerror( msg ); */ -lexerror( msg ) +flexerror( msg ) char msg[]; { fprintf( stderr, "flex: %s\n", msg ); - lexend( 1 ); + flexend( 1 ); } -/* lexfatal - report a fatal error message and terminate +/* flexfatal - report a fatal error message and terminate * * synopsis * char msg[]; - * lexfatal( msg ); + * flexfatal( msg ); */ -lexfatal( msg ) +flexfatal( msg ) char msg[]; { fprintf( stderr, "flex: fatal internal error %s\n", msg ); - lexend( 1 ); + flexend( 1 ); } /* line_directive_out - spit out a "# line" statement */ -line_directive_out() +line_directive_out( output_file_name ) +FILE *output_file_name; { - if ( infilename ) - printf( "# line %d \"%s\"\n", linenum, infilename ); + if ( infilename && gen_line_dirs ) + fprintf( output_file_name, "# line %d \"%s\"\n", linenum, infilename ); } /* mk2data - generate a data statement for a two-dimensional array * * synopsis - * char name; - * int row, column, value; - * mk2data( name, row, column, value ); + * int value; + * mk2data( value ); * - * generates a data statement initializing "name(row, column)" to "value" - * Note that name is only a character; NOT a string. If we're generating - * FTL (-f flag), "name", "row", and "column" get ignored. + * generates a data statement initializing the current 2-D array to "value" */ -mk2data( name, row, column, value ) -char name; -int row, column, value; +mk2data( value ) +int value; { - int datalen; - static char dindent[] = DATAINDENTSTR; - - if ( genftl ) + if ( datapos >= NUMDATAITEMS ) { - if ( datapos >= NUMDATAITEMS ) - { - putchar( ',' ); - dataflush(); - } - - if ( datapos == 0 ) - /* indent */ - fputs( " ", stdout ); - - else - putchar( ',' ); - - ++datapos; - - printf( "%5d", value ); + putchar( ',' ); + dataflush(); } - else - { - /* figure out length of data statement to be written. 7 is the constant - * overhead of a one character name, '(', ',', and ')' to delimit - * the array reference, a '/' and a '/' to delimit the value, and - * room for a blank or a comma between this data statement and the - * previous one - */ - - datalen = 7 + numdigs( row ) + numdigs( column ) + numdigs( value ); - - if ( datalen + datapos >= DATALINEWIDTH | datapos == 0 ) - { - if ( datapos != 0 ) - dataflush(); - - /* precede data statement with '%' so rat4 preprocessor doesn't have - * to bother looking at it -- speed hack - */ - printf( "%%%sdata ", dindent ); + if ( datapos == 0 ) + /* indent */ + fputs( " ", stdout ); - /* 4 is the constant overhead of writing out the word "DATA" */ - datapos = DATAINDENTWIDTH + 4 + datalen; - } + else + putchar( ',' ); - else - { - putchar( ',' ); - datapos = datapos + datalen; - } + ++datapos; - printf( "%c(%d,%d)/%d/", name, row, column, value ); - } + printf( "%5d", value ); } /* mkdata - generate a data statement * * synopsis - * char name; - * int arrayelm, value; - * mkdata( name, arrayelm, value ); + * int value; + * mkdata( value ); * - * generates a data statement initializing "name(arrayelm)" to "value" - * Note that name is only a character; NOT a string. If we're generating - * FTL (-f flag), "name" and "arrayelm" get ignored. + * generates a data statement initializing the current array element to + * "value" */ -mkdata( name, arrayelm, value ) -char name; -int arrayelm, value; +mkdata( value ) +int value; { - int datalen; - static char dindent[] = DATAINDENTSTR; - - if ( genftl ) + if ( datapos >= NUMDATAITEMS ) { - if ( datapos >= NUMDATAITEMS ) - { - putchar( ',' ); - dataflush(); - } - - if ( datapos == 0 ) - /* indent */ - fputs( " ", stdout ); - - else - putchar( ',' ); - - ++datapos; - - printf( "%5d", value ); + putchar( ',' ); + dataflush(); } - else - { - /* figure out length of data statement to be written. 6 is the constant - * overhead of a one character name, '(' and ')' to delimit the array - * reference, a '/' and a '/' to delimit the value, and room for a - * blank or a comma between this data statement and the previous one - */ - - datalen = 6 + numdigs( arrayelm ) + numdigs( value ); - - if ( datalen + datapos >= DATALINEWIDTH | datapos == 0 ) - { - if ( datapos != 0 ) - dataflush(); - - /* precede data statement with '%' so rat4 preprocessor doesn't have - * to bother looking at it -- speed hack - */ - printf( "%%%sdata ", dindent ); + if ( datapos == 0 ) + /* indent */ + fputs( " ", stdout ); - /* 4 is the constant overhead of writing out the word "DATA" */ - datapos = DATAINDENTWIDTH + 4 + datalen; - } + else + putchar( ',' ); - else - { - putchar( ',' ); - datapos = datapos + datalen; - } + ++datapos; - printf( "%c(%d)/%d/", name, arrayelm, value ); - } + printf( "%5d", value ); } @@ -542,42 +482,6 @@ char array[]; } -/* numdigs - number of digits (includes leading sign) in number - * - * synopsis - * int numdigs, x; - * num = numdigs( x ); - */ -int numdigs( x ) -int x; - - { - if ( x < 0 ) - { - /* the only negative numbers we expect to encounter are very - * small ones - */ - if ( x < -9 ) - lexfatal( "assumption of small negative numbers botched in numdigs()" ); - - return ( 2 ); - } - - if ( x < 10 ) - return ( 1 ); - else if ( x < 100 ) - return ( 2 ); - else if ( x < 1000 ) - return ( 3 ); - else if ( x < 10000 ) - return ( 4 ); - else if ( x < 100000 ) - return ( 5 ); - else - return ( 6 ); - } - - /* otoi - convert an octal digit string to an integer value * * synopsis: @@ -618,13 +522,13 @@ int size, element_size; (unsigned) (size * element_size )); if ( new_array == NULL ) - lexfatal( "attempt to increase array size failed" ); + flexfatal( "attempt to increase array size failed" ); return ( new_array ); } -/* skelout - write out one section of the lexskel file +/* skelout - write out one section of the skeleton file * * synopsis * skelout(); @@ -644,3 +548,33 @@ skelout() else fputs( buf, stdout ); } + + +/* transition_struct_out - output a yy_trans_info structure + * + * synopsis + * int element_v, element_n; + * transition_struct_out( element_v, element_n ); + * + * outputs the yy_trans_info structure with the two elements, element_v and + * element_n. Formats the output with spaces and carriage returns. + */ + +transition_struct_out( element_v, element_n ) +int element_v, element_n; + + { + printf( "%7d, %5d,", element_v, element_n ); + + datapos += TRANS_STRUCT_PRINT_LENGTH; + + if ( datapos >= 75 ) + { + printf( "\n" ); + + if ( ++dataline % 10 == 0 ) + printf( "\n" ); + + datapos = 0; + } + } diff --git a/nfa.c b/nfa.c index d514ce1..9b93892 100644 --- a/nfa.c +++ b/nfa.c @@ -1,7 +1,15 @@ -/* lexnfa - NFA construction routines */ +/* flexnfa - NFA construction routines */ /* - * Copyright (c) University of California, 1987 + * Copyright (c) 1987, the University of California + * + * 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. + * + * This program may be redistributed. Enhancements and derivative works + * may be created provided the new works, if made available to the general + * public, are made available for use by anyone. */ #include "flexdef.h" @@ -20,34 +28,46 @@ * characters in the pattern, or zero if the trailing context has variable * length. */ + add_accept( mach, headcnt, trailcnt ) int mach, headcnt, trailcnt; { int astate; - printf( "case %d:\n", ++accnum ); + fprintf( temp_action_file, "case %d:\n", ++accnum ); if ( headcnt > 0 || trailcnt > 0 ) { /* do trailing context magic to not match the trailing characters */ - printf( "YYDOBEFORESCAN; /* undo effects of setting up yytext */\n" ); + fprintf( temp_action_file, + "YY_DO_BEFORE_SCAN; /* undo effects of setting up yytext */\n" ); if ( headcnt > 0 ) { - if ( ! genftl || headcnt > 1 ) - printf( "yycbufp = yybbufp + %d;\n", - genftl ? headcnt - 1 : headcnt ); + int head_offset = headcnt - 1; + + if ( fullspd || fulltbl ) + /* with the fast skeleton, yy_c_buf_p points to the *next* + * character to scan, rather than the one that was last + * scanned + */ + ++head_offset; + + if ( head_offset > 0 ) + fprintf( temp_action_file, "yy_c_buf_p = yy_b_buf_p + %d;\n", + head_offset ); + else - printf( "yycbufp = yybbufp;\n" ); + fprintf( temp_action_file, "yy_c_buf_p = yy_b_buf_p;\n" ); } else - printf( "yycbufp -= %d;\n", trailcnt ); - - printf( "YYDOBEFOREACTION; /* set up yytext again */\n" ); + fprintf( temp_action_file, "yy_c_buf_p -= %d;\n", trailcnt ); + + fprintf( temp_action_file, "YY_DO_BEFORE_ACTION; /* set up yytext again */\n" ); } - line_directive_out(); + line_directive_out( temp_action_file ); /* hang the accepting number off an epsilon state. if it is associated * with a state that has a non-epsilon out-transition, then the state @@ -76,6 +96,7 @@ int mach, headcnt, trailcnt; * singl - a singleton machine * num - the number of copies of singl to be present in newsng */ + int copysingl( singl, num ) int singl, num; @@ -97,6 +118,7 @@ int singl, num; * int state1; * dumpnfa( state1 ); */ + dumpnfa( state1 ) int state1; @@ -150,6 +172,7 @@ int state1; * also note that the original MUST be contiguous, with its low and high * states accessible by the arrays firstst and lastst */ + int dupmachine( mach ) int mach; @@ -197,6 +220,7 @@ int mach; * and then last, and will fail if either of the sub-patterns fails. * FIRST is set to new by the operation. last is unmolested. */ + int link_machines( first, last ) int first, last; @@ -232,6 +256,7 @@ int first, last; * the resulting machine CANNOT be used with any other "mk" operation except * more mkbranch's. Compare with mkor() */ + int mkbranch( first, second ) int first, second; @@ -260,6 +285,7 @@ int first, second; * * new - a new state which matches the closure of "state" */ + int mkclos( state ) int state; @@ -281,6 +307,7 @@ int state; * 1. mach must be the last machine created * 2. mach is destroyed by the call */ + int mkopt( mach ) int mach; @@ -319,6 +346,7 @@ int mach; * the code is rather convoluted because an attempt is made to minimize * the number of epsilon states needed */ + int mkor( first, second ) int first, second; @@ -379,6 +407,7 @@ int first, second; * * new - a machine matching the positive closure of "state" */ + int mkposcl( state ) int state; @@ -411,6 +440,7 @@ int state; * note * if "ub" is INFINITY then "new" matches "lb" or more occurances of "mach" */ + int mkrep( mach, lb, ub ) int mach, lb, ub; @@ -457,6 +487,7 @@ int mach, lb, ub; * CONTIGUOUS. Change it and you will have to rewrite DUPMACHINE (kludge * that it admittedly is) */ + int mkstate( sym ) int sym; @@ -523,6 +554,7 @@ int sym; * statefrom - the state from which the transition is to be made * stateto - the state to which the transition is to be made */ + mkxtion( statefrom, stateto ) int statefrom, stateto; @@ -532,7 +564,7 @@ int statefrom, stateto; else if ( (transchar[statefrom] != SYM_EPSILON) || (trans2[statefrom] != NO_TRANSITION) ) - lexfatal( "found too many transitions in mkxtion()" ); + flexfatal( "found too many transitions in mkxtion()" ); else { /* second out-transition for an epsilon state */ diff --git a/parse.y b/parse.y index b5cb379..f5094e5 100644 --- a/parse.y +++ b/parse.y @@ -1,7 +1,15 @@ -/* lexparse.y - parser for flex input */ +/* flexparse.y - parser for flex input */ /* - * Copyright (c) University of California, 1987 + * Copyright (c) 1987, the University of California + * + * 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. + * + * This program may be redistributed. Enhancements and derivative works + * may be created provided the new works, if made available to the general + * public, are made available for use by anyone. */ %token CHAR NUMBER SECTEND SCDECL XSCDECL WHITESPACE NAME PREVCCL @@ -63,7 +71,7 @@ namelist1 : namelist1 WHITESPACE NAME { synerr( "bad start condition list" ); } ; -sect2 : sect2 initforrule lexrule '\n' +sect2 : sect2 initforrule flexrule '\n' | ; @@ -75,7 +83,7 @@ initforrule : } ; -lexrule : scon '^' re eol +flexrule : scon '^' re eol { pat = link_machines( $3, $4 ); add_accept( pat, headcnt, trailcnt ); diff --git a/scan.l b/scan.l index 5f344dc..c1fcaa4 100644 --- a/scan.l +++ b/scan.l @@ -1,25 +1,27 @@ /* flexscan.l - scanner for flex input */ /* - * Copyright (c) University of California, 1987 + * Copyright (c) 1987, the University of California + * + * 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. + * + * This program may be redistributed. Enhancements and derivative works + * may be created provided the new works, if made available to the general + * public, are made available for use by anyone. */ %{ #include "flexdef.h" -#include "strings.h" #include "y.tab.h" -#undef YYDECL -#define YYDECL \ - int lexscan() +#define ACTION_ECHO fprintf( temp_action_file, "%s", yytext ) +#define MARK_END_OF_PROLOG fprintf( temp_action_file, "%%%% end of prolog\n" ); -#undef yywrap -#define yywrap(result) \ - { \ - if ( ! did_second_skelout ) \ - skelout(); \ - result = 1; \ - } +#undef YY_DECL +#define YY_DECL \ + int flexscan() #define RETURNCHAR \ yylval = yytext[0]; \ @@ -52,20 +54,19 @@ ESCSEQ \\([^^\n]|"^".|0[0-9]{1,3}) static int bracelevel; int i, cclval; char nmdef[MAXLINE], myesc(); - static int didadef, did_second_skelout = false; + static int didadef; ^{WS}.*\n ++linenum; ECHO; /* indented code */ -^#.*\n ++linenum; ECHO; /* either a Ratfor comment or a CPP directive */ +^#.*\n ++linenum; ECHO; /* treat as a comment */ ^"/*" ECHO; BEGIN(C_COMMENT); ^"%s"(tart)? return ( SCDECL ); ^"%x" return ( XSCDECL ); -^"%{".*\n ++linenum; line_directive_out(); BEGIN(CODEBLOCK); +^"%{".*\n ++linenum; line_directive_out( stdout ); BEGIN(CODEBLOCK); {WS} return ( WHITESPACE ); ^"%%".* { sectnum = 2; - skelout(); - line_directive_out(); + line_directive_out( stdout ); BEGIN(SECT2PROLOG); return ( SECTEND ); } @@ -127,13 +128,12 @@ ESCSEQ \\([^^\n]|"^".|0[0-9]{1,3}) .*\n/[^ \t\n] { ++linenum; - ECHO; - skelout(); - did_second_skelout = true; + ACTION_ECHO; + MARK_END_OF_PROLOG; BEGIN(SECT2); } -.*\n ++linenum; ECHO; +.*\n ++linenum; ACTION_ECHO; ^{OPTWS}\n ++linenum; /* allow blank lines in section 2 */ ^{WS}.*\n { @@ -154,7 +154,14 @@ ESCSEQ \\([^^\n]|"^".|0[0-9]{1,3}) } {WS}"|".*\n ++linenum; return ( '\n' ); -{WS} | +{WS} { /* needs to be separate from following rule due to + * bug with trailing context + */ + bracelevel = 0; + BEGIN(ACTION); + return ( '\n' ); + } + {OPTWS}/\n { bracelevel = 0; BEGIN(ACTION); @@ -281,47 +288,45 @@ ESCSEQ \\([^^\n]|"^".|0[0-9]{1,3}) {OPTWS}"%}".* bracelevel = 0; -.* ECHO; +.* ACTION_ECHO; \n { ++linenum; - ECHO; + ACTION_ECHO; if ( bracelevel == 0 ) { - if ( genftl ) - puts( "\tbreak;" ); + fputs( "\tbreak;\n", temp_action_file ); BEGIN(SECT2); } } -"{" ECHO; ++bracelevel; -"}" ECHO; --bracelevel; -[^{}"'/\n]+ ECHO; -"/*" ECHO; BEGIN(ACTION_COMMENT); -"'"([^'\\\n]|\\.)*"'" ECHO; /* character constant */ -\" ECHO; BEGIN(ACTION_STRING); +"{" ACTION_ECHO; ++bracelevel; +"}" ACTION_ECHO; --bracelevel; +[^{}"'/\n]+ ACTION_ECHO; +"/*" ACTION_ECHO; BEGIN(ACTION_COMMENT); +"'"([^'\\\n]|\\.)*"'" ACTION_ECHO; /* character constant */ +\" ACTION_ECHO; BEGIN(ACTION_STRING); \n { ++linenum; - ECHO; + ACTION_ECHO; if ( bracelevel == 0 ) { - if ( genftl ) - puts( "\tbreak;" ); + fputs( "\tbreak;\n", temp_action_file ); BEGIN(SECT2); } } -. ECHO; +. ACTION_ECHO; -"*/" ECHO; BEGIN(ACTION); -[^*\n]+ ECHO; -"*" ECHO; -\n ++linenum; ECHO; -. ECHO; +"*/" ACTION_ECHO; BEGIN(ACTION); +[^*\n]+ ACTION_ECHO; +"*" ACTION_ECHO; +\n ++linenum; ACTION_ECHO; +. ACTION_ECHO; -[^"\\\n]+ ECHO; -\\. ECHO; -\n ++linenum; ECHO; -\" ECHO; BEGIN(ACTION); -. ECHO; +[^"\\\n]+ ACTION_ECHO; +\\. ACTION_ECHO; +\n ++linenum; ACTION_ECHO; +\" ACTION_ECHO; BEGIN(ACTION); +. ACTION_ECHO; {ESCSEQ} { @@ -339,32 +344,35 @@ ESCSEQ \\([^^\n]|"^".|0[0-9]{1,3}) .|\n { register int numchars; - /* black magic - we know the names of a lex scanner's + /* black magic - we know the names of a flex scanner's * internal variables. We cap the input buffer with * an end-of-string and dump it to the output. */ - YYDOBEFORESCAN; /* recover from setting up yytext */ + YY_DO_BEFORE_SCAN; /* recover from setting up yytext */ - yychbuf[yyebufp + 1] = '\0'; +#ifdef FLEX_FAST_SKEL + fputs( yy_c_buf_p + 1, stdout ); +#else + yy_ch_buf[yy_e_buf_p + 1] = '\0'; /* ignore the first character; it's the second '%' * put back by the yyless(1) above */ - fputs( yychbuf + yycbufp + 1, stdout ); + fputs( yy_ch_buf + yy_c_buf_p + 1, stdout ); +#endif /* if we don't do this, the data written by write() * can get overwritten when stdout is finally flushed */ (void) fflush( stdout ); - while ( (numchars = read( fileno(yyin), yychbuf, - YYBUFMAX )) > 0 ) - (void) write( fileno(stdout), yychbuf, numchars ); + while ( (numchars = read( fileno(yyin), yy_ch_buf, + YY_BUF_MAX )) > 0 ) + (void) write( fileno(stdout), yy_ch_buf, numchars ); if ( numchars < 0 ) - lexerror( "fatal read error in section 3" ); + flexerror( "fatal read error in section 3" ); return ( EOF ); } - %% diff --git a/sym.c b/sym.c index af50831..776a163 100644 --- a/sym.c +++ b/sym.c @@ -1,7 +1,15 @@ -/* lexsym - symbol table routines */ +/* flexsym - symbol table routines */ /* - * Copyright (c) University of California, 1987 + * Copyright (c) 1987, the University of California + * + * 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. + * + * This program may be redistributed. Enhancements and derivative works + * may be created provided the new works, if made available to the general + * public, are made available for use by anyone. */ #include "flexdef.h" @@ -49,7 +57,7 @@ int table_size; new_entry = (struct hash_entry *) malloc( sizeof( struct hash_entry ) ); if ( new_entry == NULL ) - lexfatal( "symbol table memory allocation failed" ); + flexfatal( "symbol table memory allocation failed" ); if ( (successor = table[hash_val]) ) { @@ -76,6 +84,7 @@ int table_size; * int cclnum; * cclinstal( ccltxt, cclnum ); */ + cclinstal( ccltxt, cclnum ) char ccltxt[]; int cclnum; @@ -98,6 +107,7 @@ int cclnum; * int ccllookup, cclval; * cclval/0 = ccllookup( ccltxt ); */ + int ccllookup( ccltxt ) char ccltxt[]; @@ -194,6 +204,7 @@ int hash_size; * char nd[], def[]; * ndinstal( nd, def ); */ + ndinstal( nd, def ) char nd[], def[]; @@ -213,6 +224,7 @@ char nd[], def[]; * char *ndlookup(); * def/NULL = ndlookup( nd ); */ + char *ndlookup( nd ) char nd[]; @@ -233,6 +245,7 @@ char nd[]; * NOTE * the start condition is Exclusive if xcluflg is true */ + scinstal( str, xcluflg ) char str[]; int xcluflg; @@ -240,19 +253,13 @@ int xcluflg; { char *copy_string(); - if ( genftl ) - { - /* bit of a hack. We know how the default start-condition is - * declared, and don't put out a define for it, because it - * would come out as "#define 0 1" - */ + /* bit of a hack. We know how the default start-condition is + * declared, and don't put out a define for it, because it + * would come out as "#define 0 1" + */ - if ( strcmp( str, "0" ) ) - printf( "#define %s %d\n", str, lastsc * 2 ); - } - - else - printf( "define(YYLEX_SC_%s,%d)\n", str, lastsc * 2 ); + if ( strcmp( str, "0" ) ) + printf( "#define %s %d\n", str, lastsc * 2 ); if ( ++lastsc >= current_max_scs ) { @@ -283,6 +290,7 @@ int xcluflg; * int sclookup; * scnum/0 = sclookup( str ); */ + int sclookup( str ) char str[]; diff --git a/tblcmp.c b/tblcmp.c index ae9bfd7..8fb9a67 100644 --- a/tblcmp.c +++ b/tblcmp.c @@ -1,7 +1,15 @@ -/* lexcmp - table compression routines */ +/* flexcmp - table compression routines */ /* - * Copyright (c) University of California, 1987 + * Copyright (c) 1987, the University of California + * + * 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. + * + * This program may be redistributed. Enhancements and derivative works + * may be created provided the new works, if made available to the general + * public, are made available for use by anyone. */ #include "flexdef.h" @@ -40,6 +48,7 @@ * state on EVERY transition character, and therefore cost only one * difference. */ + bldtbl( state, statenum, totaltrans, comstate, comfreq ) int state[], statenum, totaltrans, comstate, comfreq; @@ -185,6 +194,7 @@ int state[], statenum, totaltrans, comstate, comfreq; * up at the top end of the nxt array; they will now be compressed and have * table entries made for them. */ + cmptmps() { @@ -274,98 +284,231 @@ expand_nxt_chk() } -/* gentabs - generate data statements for the transition tables +/* find_table_space - finds a space in the table for a state to be placed * * synopsis - * gentabs(); + * int *state, numtrans, block_start; + * int find_table_space(); + * + * block_start = find_table_space( state, numtrans ); + * + * State is the state to be added to the full speed transition table. + * Numtrans is the number of out-transititions for the state. + * + * find_table_space() returns the position of the start of the first block (in + * chk) able to accomodate the state + * + * In determining if a state will or will not fit, find_table_space() must take + * into account the fact that an end-of-buffer state will be added at [0], + * and an action number will be added in [-1]. */ -gentabs() +int find_table_space( state, numtrans ) +int *state, numtrans; + { - int i, j, k, numrows, *accset, nacc, *acc_array; - char clower(); + /* firstfree is the position of the first possible occurence of two + * consecutive unused records in the chk and nxt arrays + */ + register int i; + register int *state_ptr, *chk_ptr; + register int *ptr_to_last_entry_in_state; - /* *everything* is done in terms of arrays starting at 1, so provide - * a null entry for the zero element of all FTL arrays + /* if there are too many out-transititions, put the state at the end of + * nxt and chk */ - static char ftl_long_decl[] = "static long int %c[%d] =\n { 0,\n"; - static char ftl_short_decl[] = "static short int %c[%d] =\n { 0,\n"; - static char ftl_char_decl[] = "static char %c[%d] =\n { 0,\n"; + if ( numtrans > MAX_XTIONS_FOR_FULL_INTERIOR_FIT ) + { + /* if table is empty, return the first available spot in chk/nxt, + * which should be 1 + */ + if ( tblend < 2 ) + return ( 1 ); - acc_array = allocate_integer_array( current_max_dfas ); - nummt = 0; + i = tblend - numecs; /* start searching for table space near the + * end of chk/nxt arrays + */ + } - if ( fulltbl ) - jambase = lastdfa + 1; /* home of "jam" pseudo-state */ + else + i = firstfree; /* start searching for table space from the + * beginning (skipping only the elements + * which will definitely not hold the new + * state) + */ - printf( "#define YYJAM %d\n", jamstate ); - printf( "#define YYJAMBASE %d\n", jambase ); + while ( 1 ) /* loops until a space is found */ + { + if ( i + numecs > current_max_xpairs ) + expand_nxt_chk(); - if ( usemecs ) - printf( "#define YYTEMPLATE %d\n", lastdfa + 2 ); + /* loops until space for end-of-buffer and action number are found */ + while ( 1 ) + { + if ( chk[i - 1] == 0 ) /* check for action number space */ + { + if ( chk[i] == 0 ) /* check for end-of-buffer space */ + break; -#ifdef NOTDEF -/* unsupported code */ - if ( ! genftl ) - { /* ratfor scanner */ - static char vardata[] = "%%%sdata %s/%d/\n"; - static char dindent[] = DATAINDENTSTR; - static char arydecl[] = "integer %c(%d)\n"; - static char ary2decl[] = "integer %c(%d,%d)\n"; + else + i += 2; /* since i != 0, there is no use checking to + * see if (++i) - 1 == 0, because that's the + * same as i == 0, so we skip a space + */ + } - skelout(); + else + ++i; - if ( reject ) - { - /* write out the pointers into the accepting lists for each state, - * and the accepting lists - */ + if ( i + numecs > current_max_xpairs ) + expand_nxt_chk(); + } - /* alist needs to be lastdfa + 2 because we tell where a state's - * accepting list ends by checking the beginning of the next state, - * and there's an entry in alist for the default, "jam" pseudo-state - * (this latter entry is needed because states jam by making - * a transition to the state; see the flex skeleton. By the way, - * I *think* we could get rid of the jam state entirely by - * slight modification of the skeleton ...) - */ + /* if we started search from the beginning, store the new firstfree for + * the next call of find_table_space() + */ + if ( numtrans <= MAX_XTIONS_FOR_FULL_INTERIOR_FIT ) + firstfree = i + 1; - printf( arydecl, ALIST, lastdfa + 2 ); + /* check to see if all elements in chk (and therefore nxt) that are + * needed for the new state have not yet been taken + */ - printf( arydecl, ACCEPT, max( numas, 1 ) ); - } + state_ptr = &state[1]; + ptr_to_last_entry_in_state = &chk[i + numecs + 1]; + + for ( chk_ptr = &chk[i + 1]; chk_ptr != ptr_to_last_entry_in_state; + ++chk_ptr ) + if ( *(state_ptr++) != 0 && *chk_ptr != 0 ) + break; + + if ( chk_ptr == ptr_to_last_entry_in_state ) + return ( i ); else - printf( arydecl, ALIST, lastdfa + 1 ); + ++i; + } + } - if ( useecs ) - printf( arydecl, ECARRAY, CSIZE ); - if ( usemecs ) - printf( arydecl, MATCHARRAY, numecs ); - if ( fulltbl ) - { - printf( ary2decl, NEXTARRAY, lastdfa, numecs ); - printf( vardata, dindent, "yyjam", 0 ); - } +/* genctbl - generates full speed compressed transition table + * + * synopsis + * genctbl(); + */ - else - { - printf( arydecl, BASEARRAY, lastdfa + numtemps ); - printf( arydecl, DEFARRAY, lastdfa + numtemps ); - printf( arydecl, NEXTARRAY, tblend ); - printf( arydecl, CHECKARRAY, tblend ); +genctbl() - printf( vardata, dindent, "yyjam", jambase ); + { + register int i; - /* the first template begins right after the default jam table, - * which itself begins right after the last dfa - */ + /* table of verify for transition and offset to next state */ + printf( "static 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 guarenteed 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 guarenteed 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. + */ - printf( vardata, dindent, "yytmp", lastdfa + 2 ); - } + base[lastdfa + 1] = tblend + 2; + nxt[tblend + 1] = END_OF_BUFFER_ACTION; + chk[tblend + 1] = numecs + 1; + chk[tblend + 2] = 1; /* anything but EOB */ + + /* make sure every state has a end-of-buffer transition and an action # */ + for ( i = 0; i <= lastdfa; ++i ) + { + chk[base[i]] = EOB_POSITION; + chk[base[i] - 1] = ACTION_POSITION; + nxt[base[i] - 1] = dfaacc[i].dfaacc_state; /* action number */ } -#endif NOTDEF + + for ( i = 0; i <= lastsc * 2; ++i ) + nxt[base[i] - 1] = DEFAULT_ACTION; + + dataline = 0; + datapos = 0; + + for ( i = 0; i <= tblend; ++i ) + { + if ( chk[i] == EOB_POSITION ) + transition_struct_out( 0, base[lastdfa + 1] - i ); + + else if ( chk[i] == ACTION_POSITION ) + transition_struct_out( 0, nxt[i] ); + + else if ( chk[i] > numecs || chk[i] == 0 ) + transition_struct_out( 0, 0 ); /* unused slot */ + + else /* verify, transitition */ + transition_struct_out( chk[i], base[nxt[i]] - (i - chk[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] ); + + printf( " };\n" ); + printf( "\n" ); + + /* table of pointers to start states */ + printf( "static struct yy_trans_info *yy_state_ptr[%d] =\n", + lastsc * 2 + 1 ); + printf( " {\n" ); + + for ( i = 0; i <= lastsc * 2; ++i ) + printf( " &yy_transition[%d],\n", base[i] ); + + printf( " };\n" ); + } + + +/* gentabs - generate data statements for the transition tables + * + * synopsis + * gentabs(); + */ + +gentabs() + + { + int i, j, k, numrows, *accset, nacc, *acc_array; + char clower(); + + /* *everything* is done in terms of arrays starting at 1, so provide + * a null entry for the zero element of all FTL arrays + */ + static char ftl_long_decl[] = "static long int %c[%d] =\n { 0,\n"; + static char ftl_short_decl[] = "static short int %c[%d] =\n { 0,\n"; + static char ftl_char_decl[] = "static char %c[%d] =\n { 0,\n"; + + acc_array = allocate_integer_array( current_max_dfas ); + nummt = 0; + + if ( fulltbl ) + jambase = lastdfa + 1; /* home of "jam" pseudo-state */ + + printf( "#define YY_JAM %d\n", jamstate ); + printf( "#define YY_JAM_BASE %d\n", jambase ); + + if ( usemecs ) + printf( "#define YY_TEMPLATE %d\n", lastdfa + 2 ); if ( reject ) { @@ -375,9 +518,8 @@ gentabs() * indices in the dfaacc array */ - if ( genftl ) - printf( accnum > 127 ? ftl_short_decl : ftl_char_decl, - ACCEPT, max( numas, 1 ) + 1 ); + printf( accnum > 127 ? ftl_short_decl : ftl_char_decl, + ACCEPT, max( numas, 1 ) + 1 ); j = 1; /* index into ACCEPT array */ @@ -387,7 +529,7 @@ gentabs() if ( accsiz[i] != 0 ) { - accset = dfaacc[i]; + accset = dfaacc[i].dfaacc_set; nacc = accsiz[i]; if ( trace ) @@ -395,7 +537,8 @@ gentabs() for ( k = 1; k <= nacc; ++k ) { - mkdata( ACCEPT, j++, accset[k] ); + ++j; + mkdata( accset[k] ); if ( trace ) { @@ -419,7 +562,7 @@ gentabs() else { for ( i = 1; i <= lastdfa; ++i ) - acc_array[i] = (int) dfaacc[i]; + acc_array[i] = dfaacc[i].dfaacc_state; acc_array[i] = 0; /* add (null) accepting number for jam state */ } @@ -429,39 +572,42 @@ gentabs() * In either case, we just dump the numbers. */ - if ( genftl ) - { - /* "lastdfa + 2" is the size of ALIST; includes room for FTL arrays - * beginning at 0 and for "jam" state + /* "lastdfa + 2" is the size of ALIST; includes room for FTL 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. */ - k = lastdfa + 2; + ++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; + printf( ((reject && numas > 126) || accnum > 127) ? + ftl_short_decl : ftl_char_decl, ALIST, k ); - printf( ((reject && numas > 126) || accnum > 127) ? - ftl_short_decl : ftl_char_decl, ALIST, k ); - } + /* set up default actions */ + for ( i = 1; i <= lastsc * 2; ++i ) + acc_array[i] = DEFAULT_ACTION; + + acc_array[end_of_buffer_state] = END_OF_BUFFER_ACTION; for ( i = 1; i <= lastdfa; ++i ) { - mkdata( ALIST, i, acc_array[i] ); + mkdata( acc_array[i] ); if ( ! reject && trace && acc_array[i] ) fprintf( stderr, "state # %d accepts: [%d]\n", i, acc_array[i] ); } /* add entry for "jam" state */ - mkdata( ALIST, i, acc_array[i] ); + mkdata( acc_array[i] ); if ( reject ) /* add "cap" for the list */ - mkdata( ALIST, i + 1, acc_array[i] ); + mkdata( acc_array[i] ); dataend(); @@ -469,8 +615,7 @@ gentabs() { /* write out equivalence classes */ - if ( genftl ) - printf( ftl_char_decl, ECARRAY, CSIZE + 1 ); + printf( ftl_char_decl, ECARRAY, CSIZE + 1 ); for ( i = 1; i <= CSIZE; ++i ) { @@ -478,7 +623,7 @@ gentabs() ecgroup[i] = ecgroup[clower( i )]; ecgroup[i] = abs( ecgroup[i] ); - mkdata( ECARRAY, i, ecgroup[i] ); + mkdata( ecgroup[i] ); } dataend(); @@ -522,15 +667,14 @@ gentabs() if ( trace ) fputs( "\n\nMeta-Equivalence Classes:\n", stderr ); - if ( genftl ) - printf( ftl_char_decl, MATCHARRAY, numecs + 1 ); + printf( ftl_char_decl, MATCHARRAY, numecs + 1 ); for ( i = 1; i <= numecs; ++i ) { if ( trace ) fprintf( stderr, "%d = %d\n", i, abs( tecbck[i] ) ); - mkdata( MATCHARRAY, i, abs( tecbck[i] ) ); + mkdata( abs( tecbck[i] ) ); } dataend(); @@ -540,9 +684,8 @@ gentabs() { int total_states = lastdfa + numtemps; - if ( genftl ) - printf( tblend > 32766 ? ftl_long_decl : ftl_short_decl, - BASEARRAY, total_states + 1 ); + printf( tblend > MAX_SHORT ? ftl_long_decl : ftl_short_decl, + BASEARRAY, total_states + 1 ); for ( i = 1; i <= lastdfa; ++i ) { @@ -561,64 +704,54 @@ gentabs() def[i] = lastdfa - d + 1; } - mkdata( BASEARRAY, i, base[i] ); + mkdata( base[i] ); } /* generate jam state's base index */ - mkdata( BASEARRAY, i, base[i] ); + mkdata( base[i] ); for ( ++i /* skip jam state */; i <= total_states; ++i ) { - mkdata( BASEARRAY, i, base[i] ); + mkdata( base[i] ); def[i] = jamstate; } dataend(); - if ( genftl ) - printf( tblend > 32766 ? ftl_long_decl : ftl_short_decl, - DEFARRAY, total_states + 1 ); + printf( tblend > MAX_SHORT ? ftl_long_decl : ftl_short_decl, + DEFARRAY, total_states + 1 ); for ( i = 1; i <= total_states; ++i ) - mkdata( DEFARRAY, i, def[i] ); + mkdata( def[i] ); dataend(); - if ( genftl ) - printf( lastdfa > 32766 ? ftl_long_decl : ftl_short_decl, - NEXTARRAY, tblend + 1 ); + printf( lastdfa > MAX_SHORT ? ftl_long_decl : ftl_short_decl, + NEXTARRAY, tblend + 1 ); for ( i = 1; i <= tblend; ++i ) { if ( nxt[i] == 0 ) nxt[i] = jamstate; /* new state is the JAM state */ - mkdata( NEXTARRAY, i, nxt[i] ); + mkdata( nxt[i] ); } dataend(); - if ( genftl ) - printf( lastdfa > 32766 ? ftl_long_decl : ftl_short_decl, - CHECKARRAY, tblend + 1 ); + printf( lastdfa > MAX_SHORT ? ftl_long_decl : ftl_short_decl, + CHECKARRAY, tblend + 1 ); for ( i = 1; i <= tblend; ++i ) { if ( chk[i] == 0 ) ++nummt; - mkdata( CHECKARRAY, i, chk[i] ); + mkdata( chk[i] ); } dataend(); } - - skelout(); - - /* copy remainder of input to output */ - - line_directive_out(); - (void) lexscan(); /* copy remainder of input to output */ } @@ -663,11 +796,65 @@ inittbl() } +/* make_tables - generate transition tables + * + * synopsis + * make_tables(); + * + * Generates transition tables and finishes generating output file + */ + +make_tables() + + { + if ( fullspd ) + { /* need to define YY_TRANS_OFFSET_TYPE as a size large + * enough to hold the biggest offset + */ + int total_table_size = tblend + numecs + 1; + + printf( "#define YY_TRANS_OFFSET_TYPE %s\n", + total_table_size > MAX_SHORT ? "long" : "short" ); + } + + if ( fullspd || fulltbl ) + skelout(); + + /* compute the tables and copy them to output file */ + if ( fullspd ) + genctbl(); + + else + gentabs(); + + skelout(); + + (void) fclose( temp_action_file ); + temp_action_file = fopen( action_file_name, "r" ); + + /* copy prolog from action_file to output file */ + action_out(); + + skelout(); + + /* copy actions from action_file to output file */ + action_out(); + + skelout(); + + /* copy remainder of input to output */ + + line_directive_out( stdout ); + (void) flexscan(); /* copy remainder of input to output */ + } + + /* mkdeftbl - make the default, "jam" table entries * * synopsis * mkdeftbl(); */ + mkdeftbl() { @@ -716,6 +903,7 @@ mkdeftbl() * the tables are searched for an interior spot that will accomodate the * state array. */ + mkentry( state, numchars, statenum, deflink, totaltrans ) register int *state; int numchars, statenum, deflink, totaltrans; @@ -848,6 +1036,7 @@ int numchars, statenum, deflink, totaltrans; * int state, sym, onenxt, onedef; * mk1tbl( state, sym, onenxt, onedef ); */ + mk1tbl( state, sym, onenxt, onedef ) int state, sym, onenxt, onedef; @@ -880,6 +1069,7 @@ int state, sym, onenxt, onedef; * int state[], statenum, comstate; * mkprot( state, statenum, comstate ); */ + mkprot( state, statenum, comstate ) int state[], statenum, comstate; @@ -923,6 +1113,7 @@ int state[], statenum, comstate; * int state[], statenum, comstate, totaltrans; * mktemplate( state, statenum, comstate, totaltrans ); */ + mktemplate( state, statenum, comstate ) int state[], statenum, comstate; @@ -980,6 +1171,7 @@ int state[], statenum, comstate; * int qelm; * mv2front( qelm ); */ + mv2front( qelm ) int qelm; @@ -1020,6 +1212,12 @@ ntod() int targptr, totaltrans, i, comstate, comfreq, targ; int *epsclosure(), snstods(), symlist[CSIZE + 1]; + /* this is so find_table_space(...) will know where to start looking in + * chk/nxt for unused records for space to put in the state + */ + if ( fullspd ) + firstfree = 0; + accset = allocate_integer_array( accnum + 1 ); nset = allocate_integer_array( current_max_dfa_size ); @@ -1053,29 +1251,30 @@ ntod() inittbl(); - if ( genftl ) - skelout(); + if ( fullspd ) + { + for ( i = 0; i <= numecs; ++i ) + state[i] = 0; + place_state( state, 0, 0 ); + } if ( fulltbl ) { - if ( genftl ) - { - /* declare it "short" because it's a real long-shot that that - * won't be large enough - */ - printf( "static short int %c[][%d] =\n {\n", NEXTARRAY, - numecs + 1 ); + /* declare it "short" because it's a real long-shot that that + * won't be large enough + */ + printf( "static short int %c[][%d] =\n {\n", NEXTARRAY, + numecs + 1 ); /* '}' so vi doesn't get too confused */ - /* generate 0 entries for state #0 */ - for ( i = 0; i <= numecs; ++i ) - mk2data( NEXTARRAY, 0, 0, 0 ); + /* generate 0 entries for state #0 */ + for ( i = 0; i <= numecs; ++i ) + mk2data( 0 ); - /* force ',' and dataflush() next call to mk2data */ - datapos = NUMDATAITEMS; + /* force ',' and dataflush() next call to mk2data */ + datapos = NUMDATAITEMS; - /* force extra blank line next dataflush() */ - dataline = NUMDATALINES; - } + /* force extra blank line next dataflush() */ + dataline = NUMDATALINES; } /* create the first states */ @@ -1105,6 +1304,17 @@ ntod() } } + if ( fulltbl ) + { + if ( ! snstods( nset, 0, accset, 0, 0, &end_of_buffer_state ) ) + flexfatal( "could not create unique end-of-buffer state" ); + + numas += 1; + + todo[todo_next] = end_of_buffer_state; + ADD_QUEUE_ELEMENT(todo_next); + } + while ( todo_head != todo_next ) { targptr = 0; @@ -1193,28 +1403,25 @@ ntod() if ( fulltbl ) { - if ( genftl ) - { - /* supply array's 0-element */ - mk2data( NEXTARRAY, 0, 0, 0 ); - - for ( i = 1; i <= numecs; ++i ) - mk2data( NEXTARRAY, 0, 0, state[i] ); + /* supply array's 0-element */ + if ( ds == end_of_buffer_state ) + mk2data( 0 ); + else + mk2data( end_of_buffer_state ); - /* force ',' and dataflush() next call to mk2data */ - datapos = NUMDATAITEMS; + for ( i = 1; i <= numecs; ++i ) + mk2data( state[i] ); - /* force extra blank line next dataflush() */ - dataline = NUMDATALINES; - } + /* force ',' and dataflush() next call to mk2data */ + datapos = NUMDATAITEMS; - else - { - for ( i = 1; i <= numecs; ++i ) - mk2data( NEXTARRAY, ds, i, state[i] ); - } + /* force extra blank line next dataflush() */ + dataline = NUMDATALINES; } + else if ( fullspd ) + place_state( state, ds, totaltrans ); + else { /* determine which destination state is the most common, and @@ -1252,6 +1459,53 @@ ntod() mkdeftbl(); } + + } + + +/* place_state - place a state into full speed transition table + * + * synopsis + * int *state, statenum, transnum; + * place_state( state, statenum, transnum ); + * + * State is the statenum'th state. It is indexed by equivalence class and + * gives the number of the state to enter for a given equivalence class. + * Transnum is the number of out-transitions for the state. + */ + +place_state( state, statenum, transnum ) +int *state, statenum, transnum; + + { + register int i; + register int *state_ptr; + int position = find_table_space( state, transnum ); + + /* base is the table of start positions */ + base[statenum] = position; + + /* put in action number marker; this non-zero number makes sure that + * find_table_space() knows that this position in chk/nxt is taken + * and should not be used for another accepting number in another state + */ + chk[position - 1] = 1; + + /* put in end-of-buffer marker; this is for the same purposes as above */ + chk[position] = 1; + + /* place the state into chk and nxt */ + state_ptr = &state[1]; + + for ( i = 1; i <= numecs; ++i, ++state_ptr ) + if ( *state_ptr != 0 ) + { + chk[position + i] = i; + nxt[position + i] = *state_ptr; + } + + if ( position + numecs > tblend ) + tblend = position + numecs; } @@ -1265,6 +1519,7 @@ ntod() * state is pushed onto it, to be processed later by mk1tbl. If there's * no room, we process the sucker right now. */ + stack1( statenum, sym, nextstate, deflink ) int statenum, sym, nextstate, deflink; @@ -1300,6 +1555,7 @@ int statenum, sym, nextstate, deflink; * between "state" and "pr" is returned as function value. Note that this * number is "numecs" minus the number of "SAME_TRANS" entries in "ext". */ + int tbldiff( state, pr, ext ) int state[], pr, ext[]; diff --git a/yylex.c b/yylex.c index f4300aa..0694cab 100644 --- a/yylex.c +++ b/yylex.c @@ -2,7 +2,15 @@ #include "y.tab.h" /* - * Copyright (c) University of California, 1987 + * Copyright (c) 1987, the University of California + * + * 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. + * + * This program may be redistributed. Enhancements and derivative works + * may be created provided the new works, if made available to the general + * public, are made available for use by anyone. */ /* yylex - scan for a regular expression token @@ -13,6 +21,7 @@ * * token - return token found */ + int yylex() { @@ -22,7 +31,7 @@ int yylex() if ( eofseen ) toktype = EOF; else - toktype = lexscan(); + toktype = flexscan(); if ( toktype == EOF ) { @@ -102,7 +111,7 @@ int yylex() fputs( "%%\n", stderr ); /* we set beglin to be true so we'll start - * writing out numbers as we echo rules. lexscan() has + * writing out numbers as we echo rules. flexscan() has * already assigned sectnum */