3 /* dfa - DFA construction routines */
5 /* Copyright (c) 1990 The Regents of the University of California. */
6 /* All rights reserved. */
8 /* This code is derived from software contributed to Berkeley by */
11 /* The United States Government has rights in this work pursuant */
12 /* to contract no. DE-AC03-76SF00098 between the United States */
13 /* Department of Energy and the University of California. */
15 /* Redistribution and use in source and binary forms, with or without */
16 /* modification, are permitted provided that the following conditions */
19 /* 1. Redistributions of source code must retain the above copyright */
20 /* notice, this list of conditions and the following disclaimer. */
21 /* 2. Redistributions in binary form must reproduce the above copyright */
22 /* notice, this list of conditions and the following disclaimer in the */
23 /* documentation and/or other materials provided with the distribution. */
25 /* Neither the name of the University nor the names of its contributors */
26 /* may be used to endorse or promote products derived from this software */
27 /* without specific prior written permission. */
29 /* THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR */
30 /* IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED */
31 /* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR */
37 /* declare functions that have forward references */
39 void dump_associated_rules
PROTO ((FILE *, int));
40 void dump_transitions
PROTO ((FILE *, int[]));
41 void sympartition
PROTO ((int[], int, int[], int[]));
42 int symfollowset
PROTO ((int[], int, int, int[]));
45 /* check_for_backing_up - check a DFA state for backing up
48 * void check_for_backing_up( int ds, int state[numecs] );
50 * ds is the number of the state to check and state[] is its out-transitions,
51 * indexed by equivalence class.
54 void check_for_backing_up (ds
, state
)
58 if ((reject
&& !dfaacc
[ds
].dfaacc_set
) || (!reject
&& !dfaacc
[ds
].dfaacc_state
)) { /* state is non-accepting */
61 if (backing_up_report
) {
62 fprintf (backing_up_file
,
63 _("State #%d is non-accepting -\n"), ds
);
65 /* identify the state */
66 dump_associated_rules (backing_up_file
, ds
);
68 /* Now identify it further using the out- and
71 dump_transitions (backing_up_file
, state
);
73 putc ('\n', backing_up_file
);
79 /* check_trailing_context - check to see if NFA state set constitutes
80 * "dangerous" trailing context
83 * void check_trailing_context( int nfa_states[num_states+1], int num_states,
84 * int accset[nacc+1], int nacc );
87 * Trailing context is "dangerous" if both the head and the trailing
88 * part are of variable size \and/ there's a DFA state which contains
89 * both an accepting state for the head part of the rule and NFA states
90 * which occur after the beginning of the trailing context.
92 * When such a rule is matched, it's impossible to tell if having been
93 * in the DFA state indicates the beginning of the trailing context or
94 * further-along scanning of the pattern. In these cases, a warning
97 * nfa_states[1 .. num_states] is the list of NFA states in the DFA.
98 * accset[1 .. nacc] is the list of accepting numbers for the DFA state.
101 void check_trailing_context (nfa_states
, num_states
, accset
, nacc
)
102 int *nfa_states
, num_states
;
108 for (i
= 1; i
<= num_states
; ++i
) {
109 int ns
= nfa_states
[i
];
110 register int type
= state_type
[ns
];
111 register int ar
= assoc_rule
[ns
];
113 if (type
== STATE_NORMAL
|| rule_type
[ar
] != RULE_VARIABLE
) { /* do nothing */
116 else if (type
== STATE_TRAILING_CONTEXT
) {
117 /* Potential trouble. Scan set of accepting numbers
118 * for the one marking the end of the "head". We
119 * assume that this looping will be fairly cheap
120 * since it's rare that an accepting number set
123 for (j
= 1; j
<= nacc
; ++j
)
124 if (accset
[j
] & YY_TRAILING_HEAD_MASK
) {
126 ("dangerous trailing context"),
135 /* dump_associated_rules - list the rules associated with a DFA state
137 * Goes through the set of NFA states associated with the DFA and
138 * extracts the first MAX_ASSOC_RULES unique rules, sorts them,
139 * and writes a report to the given file.
142 void dump_associated_rules (file
, ds
)
147 register int num_associated_rules
= 0;
148 int rule_set
[MAX_ASSOC_RULES
+ 1];
150 int size
= dfasiz
[ds
];
152 for (i
= 1; i
<= size
; ++i
) {
153 register int rule_num
= rule_linenum
[assoc_rule
[dset
[i
]]];
155 for (j
= 1; j
<= num_associated_rules
; ++j
)
156 if (rule_num
== rule_set
[j
])
159 if (j
> num_associated_rules
) { /* new rule */
160 if (num_associated_rules
< MAX_ASSOC_RULES
)
161 rule_set
[++num_associated_rules
] =
166 bubble (rule_set
, num_associated_rules
);
168 fprintf (file
, _(" associated rule line numbers:"));
170 for (i
= 1; i
<= num_associated_rules
; ++i
) {
174 fprintf (file
, "\t%d", rule_set
[i
]);
181 /* dump_transitions - list the transitions associated with a DFA state
184 * dump_transitions( FILE *file, int state[numecs] );
186 * Goes through the set of out-transitions and lists them in human-readable
187 * form (i.e., not as equivalence classes); also lists jam transitions
188 * (i.e., all those which are not out-transitions, plus EOF). The dump
189 * is done to the given file.
192 void dump_transitions (file
, state
)
197 int out_char_set
[CSIZE
];
199 for (i
= 0; i
< csize
; ++i
) {
200 ec
= ABS (ecgroup
[i
]);
201 out_char_set
[i
] = state
[ec
];
204 fprintf (file
, _(" out-transitions: "));
206 list_character_set (file
, out_char_set
);
208 /* now invert the members of the set to get the jam transitions */
209 for (i
= 0; i
< csize
; ++i
)
210 out_char_set
[i
] = !out_char_set
[i
];
212 fprintf (file
, _("\n jam-transitions: EOF "));
214 list_character_set (file
, out_char_set
);
220 /* epsclosure - construct the epsilon closure of a set of ndfa states
223 * int *epsclosure( int t[num_states], int *numstates_addr,
224 * int accset[num_rules+1], int *nacc_addr,
225 * int *hashval_addr );
228 * The epsilon closure is the set of all states reachable by an arbitrary
229 * number of epsilon transitions, which themselves do not have epsilon
230 * transitions going out, unioned with the set of states which have non-null
231 * accepting numbers. t is an array of size numstates of nfa state numbers.
232 * Upon return, t holds the epsilon closure and *numstates_addr is updated.
233 * accset holds a list of the accepting numbers, and the size of accset is
234 * given by *nacc_addr. t may be subjected to reallocation if it is not
235 * large enough to hold the epsilon closure.
237 * hashval is the hash value for the dfa corresponding to the state set.
240 int *epsclosure (t
, ns_addr
, accset
, nacc_addr
, hv_addr
)
241 int *t
, *ns_addr
, accset
[], *nacc_addr
, *hv_addr
;
243 register int stkpos
, ns
, tsp
;
244 int numstates
= *ns_addr
, nacc
, hashval
, transsym
, nfaccnum
;
246 static int did_stk_init
= false, *stk
;
248 #define MARK_STATE(state) \
249 do{ trans1[state] = trans1[state] - MARKER_DIFFERENCE;} while(0)
251 #define IS_MARKED(state) (trans1[state] < 0)
253 #define UNMARK_STATE(state) \
254 do{ trans1[state] = trans1[state] + MARKER_DIFFERENCE;} while(0)
256 #define CHECK_ACCEPT(state) \
258 nfaccnum = accptnum[state]; \
259 if ( nfaccnum != NIL ) \
260 accset[++nacc] = nfaccnum; \
263 #define DO_REALLOCATION() \
265 current_max_dfa_size += MAX_DFA_SIZE_INCREMENT; \
267 t = reallocate_integer_array( t, current_max_dfa_size ); \
268 stk = reallocate_integer_array( stk, current_max_dfa_size ); \
271 #define PUT_ON_STACK(state) \
273 if ( ++stkend >= current_max_dfa_size ) \
275 stk[stkend] = state; \
279 #define ADD_STATE(state) \
281 if ( ++numstates >= current_max_dfa_size ) \
283 t[numstates] = state; \
287 #define STACK_STATE(state) \
289 PUT_ON_STACK(state); \
290 CHECK_ACCEPT(state); \
291 if ( nfaccnum != NIL || transchar[state] != SYM_EPSILON ) \
297 stk
= allocate_integer_array (current_max_dfa_size
);
301 nacc
= stkend
= hashval
= 0;
303 for (nstate
= 1; nstate
<= numstates
; ++nstate
) {
306 /* The state could be marked if we've already pushed it onto
309 if (!IS_MARKED (ns
)) {
316 for (stkpos
= 1; stkpos
<= stkend
; ++stkpos
) {
318 transsym
= transchar
[ns
];
320 if (transsym
== SYM_EPSILON
) {
321 tsp
= trans1
[ns
] + MARKER_DIFFERENCE
;
323 if (tsp
!= NO_TRANSITION
) {
324 if (!IS_MARKED (tsp
))
329 if (tsp
!= NO_TRANSITION
336 /* Clear out "visit" markers. */
338 for (stkpos
= 1; stkpos
<= stkend
; ++stkpos
) {
339 if (IS_MARKED (stk
[stkpos
]))
340 UNMARK_STATE (stk
[stkpos
]);
343 ("consistency check failed in epsclosure()"));
346 *ns_addr
= numstates
;
354 /* increase_max_dfas - increase the maximum number of DFAs */
356 void increase_max_dfas ()
358 current_max_dfas
+= MAX_DFAS_INCREMENT
;
362 base
= reallocate_integer_array (base
, current_max_dfas
);
363 def
= reallocate_integer_array (def
, current_max_dfas
);
364 dfasiz
= reallocate_integer_array (dfasiz
, current_max_dfas
);
365 accsiz
= reallocate_integer_array (accsiz
, current_max_dfas
);
366 dhash
= reallocate_integer_array (dhash
, current_max_dfas
);
367 dss
= reallocate_int_ptr_array (dss
, current_max_dfas
);
368 dfaacc
= reallocate_dfaacc_union (dfaacc
, current_max_dfas
);
372 reallocate_integer_array (nultrans
,
377 /* ntod - convert an ndfa to a dfa
379 * Creates the dfa corresponding to the ndfa we've constructed. The
380 * dfa starts out in state #1.
385 int *accset
, ds
, nacc
, newds
;
386 int sym
, hashval
, numstates
, dsize
;
387 int num_full_table_rows
=0; /* used only for -f */
389 int targptr
, totaltrans
, i
, comstate
, comfreq
, targ
;
390 int symlist
[CSIZE
+ 1];
391 int num_start_states
;
392 int todo_head
, todo_next
;
394 struct yytbl_data
*yynxt_tbl
= 0;
395 flex_int32_t
*yynxt_data
= 0, yynxt_curr
= 0;
397 /* Note that the following are indexed by *equivalence classes*
398 * and not by characters. Since equivalence classes are indexed
399 * beginning with 1, even if the scanner accepts NUL's, this
400 * means that (since every character is potentially in its own
401 * equivalence class) these arrays must have room for indices
402 * from 1 to CSIZE, so their size must be CSIZE + 1.
404 int duplist
[CSIZE
+ 1], state
[CSIZE
+ 1];
405 int targfreq
[CSIZE
+ 1], targstate
[CSIZE
+ 1];
407 /* accset needs to be large enough to hold all of the rules present
408 * in the input, *plus* their YY_TRAILING_HEAD_MASK variants.
410 accset
= allocate_integer_array ((num_rules
+ 1) * 2);
411 nset
= allocate_integer_array (current_max_dfa_size
);
413 /* The "todo" queue is represented by the head, which is the DFA
414 * state currently being processed, and the "next", which is the
415 * next DFA state number available (not in use). We depend on the
416 * fact that snstods() returns DFA's \in increasing order/, and thus
417 * need only know the bounds of the dfas to be processed.
419 todo_head
= todo_next
= 0;
421 for (i
= 0; i
<= csize
; ++i
) {
426 for (i
= 0; i
<= num_rules
; ++i
)
431 fputs (_("\n\nDFA Dump:\n\n"), stderr
);
436 /* Check to see whether we should build a separate table for
437 * transitions on NUL characters. We don't do this for full-speed
438 * (-F) scanners, since for them we don't have a simple state
439 * number lying around with which to index the table. We also
440 * don't bother doing it for scanners unless (1) NUL is in its own
441 * equivalence class (indicated by a positive value of
442 * ecgroup[NUL]), (2) NUL's equivalence class is the last
443 * equivalence class, and (3) the number of equivalence classes is
444 * the same as the number of characters. This latter case comes
445 * about when useecs is false or when it's true but every character
446 * still manages to land in its own class (unlikely, but it's
447 * cheap to check for). If all these things are true then the
448 * character code needed to represent NUL's equivalence class for
449 * indexing the tables is going to take one more bit than the
450 * number of characters, and therefore we won't be assured of
451 * being able to fit it into a YY_CHAR variable. This rules out
452 * storing the transitions in a compressed table, since the code
453 * for interpreting them uses a YY_CHAR variable (perhaps it
454 * should just use an integer, though; this is worth pondering ...
457 * Finally, for full tables, we want the number of entries in the
458 * table to be a power of two so the array references go fast (it
459 * will just take a shift to compute the major index). If
460 * encoding NUL's transitions in the table will spoil this, we
461 * give it its own table (note that this will be the case if we're
462 * not using equivalence classes).
465 /* Note that the test for ecgroup[0] == numecs below accomplishes
466 * both (1) and (2) above
468 if (!fullspd
&& ecgroup
[0] == numecs
) {
469 /* NUL is alone in its equivalence class, which is the
472 int use_NUL_table
= (numecs
== csize
);
474 if (fulltbl
&& !use_NUL_table
) {
475 /* We still may want to use the table if numecs
480 for (power_of_two
= 1; power_of_two
<= csize
;
482 if (numecs
== power_of_two
) {
483 use_NUL_table
= true;
490 allocate_integer_array (current_max_dfas
);
492 /* From now on, nultrans != nil indicates that we're
493 * saving null transitions for later, separate encoding.
499 for (i
= 0; i
<= numecs
; ++i
)
502 place_state (state
, 0, 0);
503 dfaacc
[0].dfaacc_state
= 0;
508 /* We won't be including NUL's transitions in the
509 * table, so build it for entries from 0 .. numecs - 1.
511 num_full_table_rows
= numecs
;
514 /* Take into account the fact that we'll be including
515 * the NUL entries in the transition table. Build it
518 num_full_table_rows
= numecs
+ 1;
520 /* Begin generating yy_nxt[][]
521 * This spans the entire LONG function.
522 * This table is tricky because we don't know how big it will be.
523 * So we'll have to realloc() on the way...
524 * we'll wait until we can calculate yynxt_tbl->td_hilen.
527 (struct yytbl_data
*) calloc (1,
530 yytbl_data_init (yynxt_tbl
, YYTD_ID_NXT
);
531 yynxt_tbl
->td_hilen
= 1;
532 yynxt_tbl
->td_lolen
= num_full_table_rows
;
533 yynxt_tbl
->td_data
= yynxt_data
=
534 (flex_int32_t
*) calloc (yynxt_tbl
->td_lolen
*
536 sizeof (flex_int32_t
));
539 buf_prints (&yydmap_buf
,
540 "\t{YYTD_ID_NXT, (void**)&yy_nxt, sizeof(%s)},\n",
541 long_align
? "flex_int32_t" : "flex_int16_t");
543 /* Unless -Ca, declare it "short" because it's a real
544 * long-shot that that won't be large enough.
548 ("static yyconst %s yy_nxt[][%d] =\n {\n",
549 long_align
? "flex_int32_t" : "flex_int16_t",
550 num_full_table_rows
);
552 out_dec ("#undef YY_NXT_LOLEN\n#define YY_NXT_LOLEN (%d)\n", num_full_table_rows
);
553 out_str ("static yyconst %s *yy_nxt =0;\n",
554 long_align
? "flex_int32_t" : "flex_int16_t");
561 /* Generate 0 entries for state #0. */
562 for (i
= 0; i
< num_full_table_rows
; ++i
) {
564 yynxt_data
[yynxt_curr
++] = 0;
572 /* Create the first states. */
574 num_start_states
= lastsc
* 2;
576 for (i
= 1; i
<= num_start_states
; ++i
) {
579 /* For each start condition, make one state for the case when
580 * we're at the beginning of the line (the '^' operator) and
581 * one for the case when we're not.
584 nset
[numstates
] = scset
[(i
/ 2) + 1];
587 mkbranch (scbol
[i
/ 2], scset
[i
/ 2]);
589 nset
= epsclosure (nset
, &numstates
, accset
, &nacc
,
592 if (snstods (nset
, numstates
, accset
, nacc
, hashval
, &ds
)) {
597 if (variable_trailing_context_rules
&& nacc
> 0)
598 check_trailing_context (nset
, numstates
,
604 if (!snstods (nset
, 0, accset
, 0, 0, &end_of_buffer_state
))
606 ("could not create unique end-of-buffer state"));
614 while (todo_head
< todo_next
) {
618 for (i
= 1; i
<= numecs
; ++i
)
627 fprintf (stderr
, _("state # %d:\n"), ds
);
629 sympartition (dset
, dsize
, symlist
, duplist
);
631 for (sym
= 1; sym
<= numecs
; ++sym
) {
635 if (duplist
[sym
] == NIL
) {
636 /* Symbol has unique out-transitions. */
638 symfollowset (dset
, dsize
,
640 nset
= epsclosure (nset
,
646 (nset
, numstates
, accset
, nacc
,
653 if (variable_trailing_context_rules
&& nacc
> 0)
654 check_trailing_context
668 targfreq
[++targptr
] = 1;
669 targstate
[targptr
] = newds
;
674 /* sym's equivalence class has the same
675 * transitions as duplist(sym)'s
678 targ
= state
[duplist
[sym
]];
686 /* Update frequency count for
691 while (targstate
[++i
] != targ
) ;
703 numsnpairs
+= totaltrans
;
705 if (ds
> num_start_states
)
706 check_for_backing_up (ds
, state
);
709 nultrans
[ds
] = state
[NUL_ec
];
710 state
[NUL_ec
] = 0; /* remove transition */
715 /* Each time we hit here, it's another td_hilen, so we realloc. */
716 yynxt_tbl
->td_hilen
++;
717 yynxt_tbl
->td_data
= yynxt_data
=
718 (flex_int32_t
*) realloc (yynxt_data
,
719 yynxt_tbl
->td_hilen
*
720 yynxt_tbl
->td_lolen
*
721 sizeof (flex_int32_t
));
727 /* Supply array's 0-element. */
728 if (ds
== end_of_buffer_state
) {
729 mk2data (-end_of_buffer_state
);
730 yynxt_data
[yynxt_curr
++] =
731 -end_of_buffer_state
;
734 mk2data (end_of_buffer_state
);
735 yynxt_data
[yynxt_curr
++] =
739 for (i
= 1; i
< num_full_table_rows
; ++i
) {
740 /* Jams are marked by negative of state
743 mk2data (state
[i
] ? state
[i
] : -ds
);
744 yynxt_data
[yynxt_curr
++] =
745 state
[i
] ? state
[i
] : -ds
;
754 place_state (state
, ds
, totaltrans
);
756 else if (ds
== end_of_buffer_state
)
757 /* Special case this state to make sure it does what
758 * it's supposed to, i.e., jam on end-of-buffer.
760 stack1 (ds
, 0, 0, JAMSTATE
);
762 else { /* normal, compressed state */
764 /* Determine which destination state is the most
765 * common, and how many transitions to it there are.
771 for (i
= 1; i
<= targptr
; ++i
)
772 if (targfreq
[i
] > comfreq
) {
773 comfreq
= targfreq
[i
];
774 comstate
= targstate
[i
];
777 bldtbl (state
, ds
, totaltrans
, comstate
, comfreq
);
784 yytbl_data_compress (yynxt_tbl
);
785 if (yytbl_data_fwrite (&tableswr
, yynxt_tbl
) < 0)
787 ("Could not write yynxt_tbl[][]"));
790 yytbl_data_destroy (yynxt_tbl
);
796 cmptmps (); /* create compressed template entries */
798 /* Create tables for all the states with only one
802 mk1tbl (onestate
[onesp
], onesym
[onesp
],
803 onenext
[onesp
], onedef
[onesp
]);
810 flex_free ((void *) accset
);
811 flex_free ((void *) nset
);
815 /* snstods - converts a set of ndfa states into a dfa state
818 * is_new_state = snstods( int sns[numstates], int numstates,
819 * int accset[num_rules+1], int nacc,
820 * int hashval, int *newds_addr );
822 * On return, the dfa state number is in newds.
825 int snstods (sns
, numstates
, accset
, nacc
, hashval
, newds_addr
)
826 int sns
[], numstates
, accset
[], nacc
, hashval
, *newds_addr
;
832 for (i
= 1; i
<= lastdfa
; ++i
)
833 if (hashval
== dhash
[i
]) {
834 if (numstates
== dfasiz
[i
]) {
838 /* We sort the states in sns so we
839 * can compare it to oldsns quickly.
840 * We use bubble because there probably
841 * aren't very many states.
843 bubble (sns
, numstates
);
847 for (j
= 1; j
<= numstates
; ++j
)
848 if (sns
[j
] != oldsns
[j
])
864 /* Make a new dfa. */
866 if (++lastdfa
>= current_max_dfas
)
867 increase_max_dfas ();
871 dss
[newds
] = allocate_integer_array (numstates
+ 1);
873 /* If we haven't already sorted the states in sns, we do so now,
874 * so that future comparisons with it can be made quickly.
878 bubble (sns
, numstates
);
880 for (i
= 1; i
<= numstates
; ++i
)
881 dss
[newds
][i
] = sns
[i
];
883 dfasiz
[newds
] = numstates
;
884 dhash
[newds
] = hashval
;
888 dfaacc
[newds
].dfaacc_set
= (int *) 0;
890 dfaacc
[newds
].dfaacc_state
= 0;
896 /* We sort the accepting set in increasing order so the
897 * disambiguating rule that the first rule listed is considered
898 * match in the event of ties will work. We use a bubble
899 * sort since the list is probably quite small.
902 bubble (accset
, nacc
);
904 dfaacc
[newds
].dfaacc_set
=
905 allocate_integer_array (nacc
+ 1);
907 /* Save the accepting set for later */
908 for (i
= 1; i
<= nacc
; ++i
) {
909 dfaacc
[newds
].dfaacc_set
[i
] = accset
[i
];
911 if (accset
[i
] <= num_rules
)
912 /* Who knows, perhaps a REJECT can yield
915 rule_useful
[accset
[i
]] = true;
918 accsiz
[newds
] = nacc
;
922 /* Find lowest numbered rule so the disambiguating rule
927 for (i
= 1; i
<= nacc
; ++i
)
931 dfaacc
[newds
].dfaacc_state
= j
;
934 rule_useful
[j
] = true;
943 /* symfollowset - follow the symbol transitions one step
946 * numstates = symfollowset( int ds[current_max_dfa_size], int dsize,
947 * int transsym, int nset[current_max_dfa_size] );
950 int symfollowset (ds
, dsize
, transsym
, nset
)
951 int ds
[], dsize
, transsym
, nset
[];
953 int ns
, tsp
, sym
, i
, j
, lenccl
, ch
, numstates
, ccllist
;
957 for (i
= 1; i
<= dsize
; ++i
) { /* for each nfa state ns in the state set of ds */
962 if (sym
< 0) { /* it's a character class */
964 ccllist
= cclmap
[sym
];
965 lenccl
= ccllen
[sym
];
968 for (j
= 0; j
< lenccl
; ++j
) {
969 /* Loop through negated character
972 ch
= ccltbl
[ccllist
+ j
];
978 /* Transsym isn't in negated
983 else if (ch
== transsym
)
988 /* Didn't find transsym in ccl. */
989 nset
[++numstates
] = tsp
;
993 for (j
= 0; j
< lenccl
; ++j
) {
994 ch
= ccltbl
[ccllist
+ j
];
1001 else if (ch
== transsym
) {
1002 nset
[++numstates
] = tsp
;
1008 else if (sym
== SYM_EPSILON
) { /* do nothing */
1011 else if (ABS (ecgroup
[sym
]) == transsym
)
1012 nset
[++numstates
] = tsp
;
1021 /* sympartition - partition characters with same out-transitions
1024 * sympartition( int ds[current_max_dfa_size], int numstates,
1025 * int symlist[numecs], int duplist[numecs] );
1028 void sympartition (ds
, numstates
, symlist
, duplist
)
1029 int ds
[], numstates
;
1030 int symlist
[], duplist
[];
1032 int tch
, i
, j
, k
, ns
, dupfwd
[CSIZE
+ 1], lenccl
, cclp
, ich
;
1034 /* Partitioning is done by creating equivalence classes for those
1035 * characters which have out-transitions from the given state. Thus
1036 * we are really creating equivalence classes of equivalence classes.
1039 for (i
= 1; i
<= numecs
; ++i
) { /* initialize equivalence class list */
1045 dupfwd
[numecs
] = NIL
;
1047 for (i
= 1; i
<= numstates
; ++i
) {
1049 tch
= transchar
[ns
];
1051 if (tch
!= SYM_EPSILON
) {
1052 if (tch
< -lastccl
|| tch
>= csize
) {
1054 ("bad transition character detected in sympartition()"));
1057 if (tch
>= 0) { /* character transition */
1058 int ec
= ecgroup
[tch
];
1060 mkechar (ec
, dupfwd
, duplist
);
1064 else { /* character class */
1067 lenccl
= ccllen
[tch
];
1069 mkeccl (ccltbl
+ cclp
, lenccl
, dupfwd
,
1070 duplist
, numecs
, NUL_ec
);
1075 for (k
= 0; k
< lenccl
; ++k
) {
1076 ich
= ccltbl
[cclp
+ k
];
1081 for (++j
; j
< ich
; ++j
)
1085 for (++j
; j
<= numecs
; ++j
)
1090 for (k
= 0; k
< lenccl
; ++k
) {
1091 ich
= ccltbl
[cclp
+ k
];