107 for ( i = 1; i <= num_states; ++
i )
109 int ns = nfa_states[
i];
124 for ( j = 1; j <= nacc; ++j )
128 "%s: Dangerous trailing context in rule at line %d\n",
152 int num_associated_rules = 0;
157 for ( i = 1; i <= size; ++
i )
161 for ( j = 1; j <= num_associated_rules; ++j )
162 if ( rule_num == rule_set[j] )
165 if ( j > num_associated_rules )
168 rule_set[++num_associated_rules] = rule_num;
172 bubble( rule_set, num_associated_rules );
174 fprintf( file,
" associated rule line numbers:" );
176 for ( i = 1; i <= num_associated_rules; ++
i )
181 fprintf( file,
"\t%d", rule_set[i] );
204 int out_char_set[
CSIZE];
206 for ( i = 0; i <
csize; ++
i )
209 out_char_set[
i] = state[ec];
212 fprintf( file,
" out-transitions: " );
217 for ( i = 0; i <
csize; ++
i )
218 out_char_set[i] = ! out_char_set[i];
220 fprintf( file,
"\n jam-transitions: EOF " );
249 int *
epsclosure(
int *t,
int *ns_addr,
int accset[],
int *nacc_addr,
int *hv_addr)
252 int numstates = *ns_addr, nacc, hashval, transsym, nfaccnum;
254 static int did_stk_init =
false, *stk;
256 #define MARK_STATE(state) \ 257 trans1[state] = trans1[state] - MARKER_DIFFERENCE; 259 #define IS_MARKED(state) (trans1[state] < 0) 261 #define UNMARK_STATE(state) \ 262 trans1[state] = trans1[state] + MARKER_DIFFERENCE; 264 #define CHECK_ACCEPT(state) \ 266 nfaccnum = accptnum[state]; \ 267 if ( nfaccnum != NIL ) \ 268 accset[++nacc] = nfaccnum; \ 271 #define DO_REALLOCATION \ 273 current_max_dfa_size += MAX_DFA_SIZE_INCREMENT; \ 275 t = reallocate_integer_array( t, current_max_dfa_size ); \ 276 stk = reallocate_integer_array( stk, current_max_dfa_size ); \ 279 #define PUT_ON_STACK(state) \ 281 if ( ++stkend >= current_max_dfa_size ) \ 283 stk[stkend] = state; \ 287 #define ADD_STATE(state) \ 289 if ( ++numstates >= current_max_dfa_size ) \ 291 t[numstates] = state; \ 292 hashval = hashval + state; \ 295 #define STACK_STATE(state) \ 297 PUT_ON_STACK(state) \ 298 CHECK_ACCEPT(state) \ 299 if ( nfaccnum != NIL || transchar[state] != SYM_EPSILON ) \ 303 if ( ! did_stk_init )
309 nacc = stkend = hashval = 0;
311 for ( nstate = 1; nstate <= numstates; ++nstate )
322 hashval = hashval + ns;
325 for ( stkpos = 1; stkpos <= stkend; ++stkpos )
350 for ( stkpos = 1; stkpos <= stkend; ++stkpos )
357 flexfatal(
"consistency check failed in epsclosure()" );
360 *ns_addr = numstates;
400 int *accset, ds, nacc, newds;
401 int sym, hashval, numstates, dsize;
402 int num_full_table_rows = 0;
404 int targptr, totaltrans,
i, comstate, comfreq, targ;
405 int *
epsclosure(
int *t,
int *ns_addr,
int *accset,
int *nacc_addr,
int *hv_addr);
406 int snstods(
int *sns,
int numstates,
int *accset,
int nacc,
int hashval,
int *newds_addr);
407 int symlist[
CSIZE + 1];
408 int num_start_states;
409 int todo_head, todo_next;
419 int targfreq[
CSIZE + 1], targstate[
CSIZE + 1];
436 todo_head = todo_next = 0;
438 for ( i = 0; i <=
csize; ++
i )
450 fputs(
"\n\nDFA Dump:\n\n",
stderr );
488 if (
fulltbl && ! use_NUL_table )
492 for ( power_of_two = 1; power_of_two <=
csize; power_of_two *= 2 )
493 if (
numecs == power_of_two )
495 use_NUL_table =
true;
510 for ( i = 0; i <=
numecs; ++
i )
521 num_full_table_rows =
numecs;
528 num_full_table_rows =
numecs + 1;
533 printf(
"static short int yy_nxt[][%d] =\n {\n",
535 num_full_table_rows );
538 for ( i = 0; i < num_full_table_rows; ++
i )
550 num_start_states =
lastsc * 2;
552 for ( i = 1; i <= num_start_states; ++
i )
561 nset[numstates] =
scset[(i / 2) + 1];
565 nset =
epsclosure( nset, &numstates, accset, &nacc, &hashval );
567 if (
snstods( nset, numstates, accset, nacc, hashval, &ds ) )
581 flexfatal(
"could not create unique end-of-buffer state" );
588 while ( todo_head < todo_next )
593 for ( i = 1; i <=
numecs; ++
i )
602 fprintf(
stderr,
"state # %d:\n", ds );
606 for ( sym = 1; sym <=
numecs; ++sym )
612 if ( duplist[sym] ==
NIL )
618 if (
snstods( nset, numstates, accset,
619 nacc, hashval, &newds ) )
633 fprintf(
stderr,
"\t%d\t%d\n", sym, newds );
635 targfreq[++targptr] = 1;
636 targstate[targptr] = newds;
645 targ = state[duplist[sym]];
649 fprintf(
stderr,
"\t%d\t%d\n", sym, targ );
654 while ( targstate[++i] != targ )
672 for ( i =
'A', j =
'a'; i <=
'Z'; ++
i, ++j )
676 if ( ds > num_start_states )
693 for ( i = 1; i < num_full_table_rows; ++
i )
695 mk2data( state[i] ? state[i] : -ds );
722 for ( i = 1; i <= targptr; ++
i )
723 if ( targfreq[i] > comfreq )
725 comfreq = targfreq[
i];
726 comstate = targstate[
i];
729 bldtbl( state, ds, totaltrans, comstate, comfreq );
763 int snstods(
int sns[],
int numstates,
int accset[],
int nacc,
int hashval,
int *newds_addr)
770 if ( hashval ==
dhash[i] )
772 if ( numstates ==
dfasiz[i] )
786 for ( j = 1; j <= numstates; ++j )
787 if ( sns[j] != oldsns[j] )
811 dss[newds] = (
int *) malloc( (
unsigned) ((numstates + 1) *
sizeof(
int )) );
814 flexfatal(
"dynamic memory failure in snstods()" );
823 for ( i = 1; i <= numstates; ++
i )
824 dss[newds][i] = sns[i];
826 dfasiz[newds] = numstates;
827 dhash[newds] = hashval;
850 (
int *) malloc( (
unsigned) ((nacc + 1) *
sizeof(
int )) );
852 if ( !
dfaacc[newds].dfaacc_set )
853 flexfatal(
"dynamic memory failure in snstods()" );
856 for ( i = 1; i <= nacc; ++
i )
857 dfaacc[newds].dfaacc_set[i] = accset[i];
866 for ( i = 1; i <= nacc; ++
i )
889 int ns, tsp, sym,
i, j, lenccl, ch, numstates;
894 for ( i = 1; i <= dsize; ++
i )
908 for ( j = 0; j < lenccl; ++j )
918 else if ( ch == transsym )
923 nset[++numstates] = tsp;
927 for ( j = 0; j < lenccl; ++j )
937 else if ( ch == transsym )
939 nset[++numstates] = tsp;
945 else if ( sym >=
'A' && sym <=
'Z' &&
caseins )
946 flexfatal(
"consistency check failed in symfollowset" );
952 else if ( abs(
ecgroup[sym] ) == transsym )
953 nset[++numstates] = tsp;
959 return ( numstates );
971 void sympartition(
int ds[],
int numstates,
int symlist[],
int duplist[])
973 int tch,
i, j, k, ns, dupfwd[
CSIZE + 1], lenccl, cclp, ich;
980 for ( i = 1; i <=
numecs; ++
i )
989 for ( i = 1; i <= numstates; ++
i )
996 if ( tch < -lastccl || tch >
csize )
998 if ( tch > csize && tch <=
CSIZE )
1003 "bad transition character detected in sympartition()" );
1011 mkechar( ec, dupfwd, duplist );
1028 for ( k = 0; k < lenccl; ++k )
1035 for ( ++j; j < ich; ++j )
1039 for ( ++j; j <=
numecs; ++j )
1044 for ( k = 0; k < lenccl; ++k )
#define MAX_DFAS_INCREMENT
void stack1(int, int, int, int)
int variable_trailing_context_rules
#define YY_TRAILING_HEAD_MASK
void mk1tbl(int, int, int, int)
int symfollowset(int[], int, int, int[])
pvd::StructureConstPtr type
void sympartition(int[], int, int[], int[])
union dfaacc_union * dfaacc
#define STATE_TRAILING_CONTEXT
#define UNMARK_STATE(state)
void check_trailing_context(int *nfa_states, int num_states, int *accset, int nacc)
#define STACK_STATE(state)
int onestate[ONE_STACK_SIZE]
#define PUT_ON_STACK(state)
#define allocate_integer_array(size)
void dump_transitions(FILE *, int[])
void check_for_backtracking(int ds, int state[])
void list_character_set(FILE *file, int cset[])
void flexerror(char[]) NORETURN
int onesym[ONE_STACK_SIZE]
#define MARKER_DIFFERENCE
int * epsclosure(int *t, int *ns_addr, int accset[], int *nacc_addr, int *hv_addr)
#define reallocate_int_ptr_array(array, size)
#define reallocate_integer_array(array, size)
int onedef[ONE_STACK_SIZE]
int onenext[ONE_STACK_SIZE]
int snstods(int sns[], int numstates, int accset[], int nacc, int hashval, int *newds_addr)
void increase_max_dfas(void)
void dump_associated_rules(FILE *, int)
void bldtbl(int[], int, int, int, int)
#define reallocate_dfaacc_union(array, size)
#define CHECK_ACCEPT(state)
void mkeccl(unsigned char ccls[], int lenccl, int fwd[], int bck[], int llsiz, int NUL_mapping)
void mkechar(int tch, int fwd[], int bck[])
void place_state(int *, int, int)