{
register int i, ec;
- int out_char_set[CSIZE + 1];
+ int out_char_set[CSIZE];
- for ( i = 1; i <= csize; ++i )
+ for ( i = (uses_NUL ? 0 : 1); i < csize; ++i )
{
ec = abs( ecgroup[i] );
out_char_set[i] = state[ec];
list_character_set( file, out_char_set );
/* now invert the members of the set to get the jam transitions */
- for ( i = 1; i <= csize; ++i )
+ for ( i = (uses_NUL ? 0 : 1); i < csize; ++i )
out_char_set[i] = ! out_char_set[i];
fprintf( file, "\n jam-transitions: EOF " );
{
int *accset, ds, nacc, newds;
- int duplist[CSIZE + 1], sym, hashval, numstates, dsize;
- int targfreq[CSIZE + 1], targstate[CSIZE + 1], state[CSIZE + 1];
+ int sym, hashval, numstates, dsize;
int *nset, *dset;
int targptr, totaltrans, i, comstate, comfreq, targ;
int *epsclosure(), snstods(), symlist[CSIZE + 1];
int num_start_states;
int todo_head, todo_next;
+ /* note that the following are indexed by *equivalence classes*
+ * and not by characters. Since equivalence classes are indexed
+ * beginning with 1, even if the scanner accepts NUL's, this
+ * means that (since every character is potentially in its own
+ * equivalence class) these arrays must have room for indices
+ * from 1 to CSIZE, so their size must be CSIZE + 1.
+ */
+ int duplist[CSIZE + 1], state[CSIZE + 1];
+ int targfreq[CSIZE + 1], targstate[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 ( tch != SYM_EPSILON )
{
if ( tch < -lastccl || tch > csize )
- flexfatal( "bad transition character detected in sympartition()" );
+ flexfatal(
+ "bad transition character detected in sympartition()" );
if ( tch > 0 )
{ /* character transition */
{
register int i, j;
- static char C_char_decl[] = "static const YY_CHAR %s[%d] =\n { 0,\n";
+ static char C_char_decl[] =
+ "static const YY_CHAR %s[%d] =\n { %d,\n";
int numrows;
Char clower();
- printf( C_char_decl, "yy_ec", csize + 1 );
+ printf( C_char_decl, "yy_ec", csize, uses_NUL ? abs( ecgroup[0] ) : 0 );
- for ( i = 1; i <= csize; ++i )
+ for ( i = 1; i < csize; ++i )
{
if ( caseins && (i >= 'A') && (i <= 'Z') )
ecgroup[i] = ecgroup[clower( i )];
if ( trace )
{
+ char *readable_form();
+
fputs( "\n\nEquivalence Classes:\n\n", stderr );
+ if ( uses_NUL )
+ {
+ fprintf( stderr, "%4s = %-2d\n",
+ readable_form( 0 ), ecgroup[0] );
+ }
+
numrows = (csize + 1) / 8;
for ( j = 1; j <= numrows; ++j )
{
- for ( i = j; i <= csize; i = i + numrows )
+ for ( i = j; i < csize; i = i + numrows )
{
- char *readable_form();
-
fprintf( stderr, "%4s = %-2d",
readable_form( i ), ecgroup[i] );
int variable_trailing_context_rules;
int numtemps, numprots, protprev[MSP], protnext[MSP], prottbl[MSP];
int protcomst[MSP], firstprot, lastprot, protsave[PROT_SAVE_SIZE];
-int numecs, nextecm[CSIZE + 1], ecgroup[CSIZE + 1], nummecs, tecfwd[CSIZE + 1];
+int numecs, nextecm[CSIZE], ecgroup[CSIZE], nummecs, tecfwd[CSIZE + 1];
int tecbck[CSIZE + 1];
int *xlation = (int *) 0;
int num_xlations;
char *starttime, *endtime, nmstr[MAXLINE];
int sectnum, nummt, hshcol, dfaeql, numeps, eps2, num_reallocs;
int tmpuses, totnst, peakpairs, numuniq, numdup, hshsave;
-int num_backtracking, bol_needed;
+int num_backtracking, bol_needed, uses_NUL;
FILE *temp_action_file;
FILE *backtrack_file;
int end_of_buffer_state;
static int outfile_created = 0;
-/* flex - main program
- *
- * synopsis (from the shell)
- * flex [-v] [file ...]
- */
-
main( argc, argv )
int argc;
char **argv;
(void) unlink( outfile );
}
- if ( backtrack_report )
+ if ( backtrack_report && backtrack_file )
{
if ( num_backtracking == 0 )
fprintf( backtrack_file, "No backtracking.\n" );
numecs = numeps = eps2 = num_reallocs = hshcol = dfaeql = totnst = 0;
numuniq = numdup = hshsave = eofseen = datapos = dataline = 0;
num_backtracking = onesp = numprots = 0;
- variable_trailing_context_rules = bol_needed = false;
+ variable_trailing_context_rules = bol_needed = uses_NUL = false;
linenum = sectnum = 1;
firstprot = NIL;
if ( useecs )
{
/* set up doubly-linked equivalence classes */
- ecgroup[1] = NIL;
+ ecgroup[0] = NIL;
- for ( i = 2; i <= csize; ++i )
+ for ( i = 1; i < csize; ++i )
{
ecgroup[i] = i - 1;
nextecm[i - 1] = i;
else
{ /* put everything in its own equivalence class */
- for ( i = 1; i <= csize; ++i )
+ for ( i = 0; i < csize; ++i )
{
ecgroup[i] = i;
nextecm[i] = BAD_SUBSCRIPT; /* to catch errors */
else if ( useecs )
{
- numecs = cre8ecs( nextecm, ecgroup, csize );
+ if ( uses_NUL )
+ numecs = cre8ecs( nextecm, ecgroup, csize, 0 );
+ else
+ numecs = cre8ecs( nextecm, ecgroup, csize - 1, 1 );
+
ccl2ecl();
}
array[sptr] = c;
- if ( esc_char == '\0' )
- {
- synerr( "escape sequence for null not allowed" );
- return ( 1 );
- }
-
return ( esc_char );
}
++rulelen;
if ( $1 == '\0' )
- synerr( "null in rule" );
+ uses_NUL = true;
if ( caseins && $1 >= 'A' && $1 <= 'Z' )
$1 = clower( $1 );
ccl : ccl CHAR '-' CHAR
{
+ if ( $2 == '\0' || $4 == '\0' )
+ uses_NUL = true;
+
if ( $2 > $4 )
synerr( "negative range in character class" );
| ccl CHAR
{
+ if ( $2 == '\0' )
+ uses_NUL = true;
+
if ( caseins )
if ( $2 >= 'A' && $2 <= 'Z' )
$2 = clower( $2 );
string : string CHAR
{
+ if ( $2 == '\0' )
+ uses_NUL = true;
+
if ( caseins )
if ( $2 >= 'A' && $2 <= 'Z' )
$2 = clower( $2 );
char *malloc();
++linenum;
- xlation = (int *) malloc( sizeof( int ) * (csize + 1) );
-
- for ( i = 1; i <= csize; ++i )
- xlation[i] = 0;
+ xlation = (int *) malloc( sizeof( int ) * csize );
if ( ! xlation )
flexfatal(
"dynamic memory failure building %t table" );
+ for ( i = 0; i < csize; ++i )
+ xlation[i] = 0;
+
num_xlations = 0;
BEGIN(XLATION);
* transitions
*/
- nummecs = cre8ecs( tecfwd, tecbck, numecs );
+ nummecs = cre8ecs( tecfwd, tecbck, numecs, 1 );
}
else