1 /* dfa - DFA construction routines */
3 /* Copyright (c) 1990 The Regents of the University of California. */
4 /* All rights reserved. */
6 /* This code is derived from software contributed to Berkeley by */
9 /* The United States Government has rights in this work pursuant */
10 /* to contract no. DE-AC03-76SF00098 between the United States */
11 /* Department of Energy and the University of California. */
13 /* Redistribution and use in source and binary forms, with or without */
14 /* modification, are permitted provided that the following conditions */
17 /* 1. Redistributions of source code must retain the above copyright */
18 /* notice, this list of conditions and the following disclaimer. */
19 /* 2. Redistributions in binary form must reproduce the above copyright */
20 /* notice, this list of conditions and the following disclaimer in the */
21 /* documentation and/or other materials provided with the distribution. */
23 /* Neither the name of the University nor the names of its contributors */
24 /* may be used to endorse or promote products derived from this software */
25 /* without specific prior written permission. */
27 /* THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR */
28 /* IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED */
29 /* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR */
32 __RCSID("$NetBSD: dfa.c,v 1.3 2014/10/30 18:44:05 christos Exp $");
36 /* declare functions that have forward references */
38 void dump_associated_rules
PROTO ((FILE *, int));
39 void dump_transitions
PROTO ((FILE *, int[]));
40 void sympartition
PROTO ((int[], int, int[], int[]));
41 int symfollowset
PROTO ((int[], int, int, int[]));
44 /* check_for_backing_up - check a DFA state for backing up
47 * void check_for_backing_up( int ds, int state[numecs] );
49 * ds is the number of the state to check and state[] is its out-transitions,
50 * indexed by equivalence class.
53 void check_for_backing_up (ds
, state
)
57 if ((reject
&& !dfaacc
[ds
].dfaacc_set
) || (!reject
&& !dfaacc
[ds
].dfaacc_state
)) { /* state is non-accepting */
60 if (backing_up_report
) {
61 fprintf (backing_up_file
,
62 _("State #%d is non-accepting -\n"), ds
);
64 /* identify the state */
65 dump_associated_rules (backing_up_file
, ds
);
67 /* Now identify it further using the out- and
70 dump_transitions (backing_up_file
, state
);
72 putc ('\n', backing_up_file
);
78 /* check_trailing_context - check to see if NFA state set constitutes
79 * "dangerous" trailing context
82 * void check_trailing_context( int nfa_states[num_states+1], int num_states,
83 * int accset[nacc+1], int nacc );
86 * Trailing context is "dangerous" if both the head and the trailing
87 * part are of variable size \and/ there's a DFA state which contains
88 * both an accepting state for the head part of the rule and NFA states
89 * which occur after the beginning of the trailing context.
91 * When such a rule is matched, it's impossible to tell if having been
92 * in the DFA state indicates the beginning of the trailing context or
93 * further-along scanning of the pattern. In these cases, a warning
96 * nfa_states[1 .. num_states] is the list of NFA states in the DFA.
97 * accset[1 .. nacc] is the list of accepting numbers for the DFA state.
100 void check_trailing_context (nfa_states
, num_states
, accset
, nacc
)
101 int *nfa_states
, num_states
;
107 for (i
= 1; i
<= num_states
; ++i
) {
108 int ns
= nfa_states
[i
];
109 register int type
= state_type
[ns
];
110 register int ar
= assoc_rule
[ns
];
112 if (type
== STATE_NORMAL
|| rule_type
[ar
] != RULE_VARIABLE
) { /* do nothing */
115 else if (type
== STATE_TRAILING_CONTEXT
) {
116 /* Potential trouble. Scan set of accepting numbers
117 * for the one marking the end of the "head". We
118 * assume that this looping will be fairly cheap
119 * since it's rare that an accepting number set
122 for (j
= 1; j
<= nacc
; ++j
)
123 if (accset
[j
] & YY_TRAILING_HEAD_MASK
) {
125 ("dangerous trailing context"),
134 /* dump_associated_rules - list the rules associated with a DFA state
136 * Goes through the set of NFA states associated with the DFA and
137 * extracts the first MAX_ASSOC_RULES unique rules, sorts them,
138 * and writes a report to the given file.
141 void dump_associated_rules (file
, ds
)
146 register int num_associated_rules
= 0;
147 int rule_set
[MAX_ASSOC_RULES
+ 1];
149 int size
= dfasiz
[ds
];
151 for (i
= 1; i
<= size
; ++i
) {
152 register int rule_num
= rule_linenum
[assoc_rule
[dset
[i
]]];
154 for (j
= 1; j
<= num_associated_rules
; ++j
)
155 if (rule_num
== rule_set
[j
])
158 if (j
> num_associated_rules
) { /* new rule */
159 if (num_associated_rules
< MAX_ASSOC_RULES
)
160 rule_set
[++num_associated_rules
] =
165 qsort (&rule_set
[1], num_associated_rules
, sizeof (rule_set
[1]), intcmp
);
167 fprintf (file
, _(" associated rule line numbers:"));
169 for (i
= 1; i
<= num_associated_rules
; ++i
) {
173 fprintf (file
, "\t%d", rule_set
[i
]);
180 /* dump_transitions - list the transitions associated with a DFA state
183 * dump_transitions( FILE *file, int state[numecs] );
185 * Goes through the set of out-transitions and lists them in human-readable
186 * form (i.e., not as equivalence classes); also lists jam transitions
187 * (i.e., all those which are not out-transitions, plus EOF). The dump
188 * is done to the given file.
191 void dump_transitions (file
, state
)
196 int out_char_set
[CSIZE
];
198 for (i
= 0; i
< csize
; ++i
) {
199 ec
= ABS (ecgroup
[i
]);
200 out_char_set
[i
] = state
[ec
];
203 fprintf (file
, _(" out-transitions: "));
205 list_character_set (file
, out_char_set
);
207 /* now invert the members of the set to get the jam transitions */
208 for (i
= 0; i
< csize
; ++i
)
209 out_char_set
[i
] = !out_char_set
[i
];
211 fprintf (file
, _("\n jam-transitions: EOF "));
213 list_character_set (file
, out_char_set
);
219 /* epsclosure - construct the epsilon closure of a set of ndfa states
222 * int *epsclosure( int t[num_states], int *numstates_addr,
223 * int accset[num_rules+1], int *nacc_addr,
224 * int *hashval_addr );
227 * The epsilon closure is the set of all states reachable by an arbitrary
228 * number of epsilon transitions, which themselves do not have epsilon
229 * transitions going out, unioned with the set of states which have non-null
230 * accepting numbers. t is an array of size numstates of nfa state numbers.
231 * Upon return, t holds the epsilon closure and *numstates_addr is updated.
232 * accset holds a list of the accepting numbers, and the size of accset is
233 * given by *nacc_addr. t may be subjected to reallocation if it is not
234 * large enough to hold the epsilon closure.
236 * hashval is the hash value for the dfa corresponding to the state set.
239 int *epsclosure (t
, ns_addr
, accset
, nacc_addr
, hv_addr
)
240 int *t
, *ns_addr
, accset
[], *nacc_addr
, *hv_addr
;
242 register int stkpos
, ns
, tsp
;
243 int numstates
= *ns_addr
, nacc
, hashval
, transsym
, nfaccnum
;
245 static int did_stk_init
= false, *stk
;
247 #define MARK_STATE(state) \
248 do{ trans1[state] = trans1[state] - MARKER_DIFFERENCE;} while(0)
250 #define IS_MARKED(state) (trans1[state] < 0)
252 #define UNMARK_STATE(state) \
253 do{ trans1[state] = trans1[state] + MARKER_DIFFERENCE;} while(0)
255 #define CHECK_ACCEPT(state) \
257 nfaccnum = accptnum[state]; \
258 if ( nfaccnum != NIL ) \
259 accset[++nacc] = nfaccnum; \
262 #define DO_REALLOCATION() \
264 current_max_dfa_size += MAX_DFA_SIZE_INCREMENT; \
266 t = reallocate_integer_array( t, current_max_dfa_size ); \
267 stk = reallocate_integer_array( stk, current_max_dfa_size ); \
270 #define PUT_ON_STACK(state) \
272 if ( ++stkend >= current_max_dfa_size ) \
274 stk[stkend] = state; \
278 #define ADD_STATE(state) \
280 if ( ++numstates >= current_max_dfa_size ) \
282 t[numstates] = state; \
286 #define STACK_STATE(state) \
288 PUT_ON_STACK(state); \
289 CHECK_ACCEPT(state); \
290 if ( nfaccnum != NIL || transchar[state] != SYM_EPSILON ) \
296 stk
= allocate_integer_array (current_max_dfa_size
);
300 nacc
= stkend
= hashval
= 0;
302 for (nstate
= 1; nstate
<= numstates
; ++nstate
) {
305 /* The state could be marked if we've already pushed it onto
308 if (!IS_MARKED (ns
)) {
315 for (stkpos
= 1; stkpos
<= stkend
; ++stkpos
) {
317 transsym
= transchar
[ns
];
319 if (transsym
== SYM_EPSILON
) {
320 tsp
= trans1
[ns
] + MARKER_DIFFERENCE
;
322 if (tsp
!= NO_TRANSITION
) {
323 if (!IS_MARKED (tsp
))
328 if (tsp
!= NO_TRANSITION
335 /* Clear out "visit" markers. */
337 for (stkpos
= 1; stkpos
<= stkend
; ++stkpos
) {
338 if (IS_MARKED (stk
[stkpos
]))
339 UNMARK_STATE (stk
[stkpos
]);
342 ("consistency check failed in epsclosure()"));
345 *ns_addr
= numstates
;
353 /* increase_max_dfas - increase the maximum number of DFAs */
355 void increase_max_dfas ()
357 current_max_dfas
+= MAX_DFAS_INCREMENT
;
361 base
= reallocate_integer_array (base
, current_max_dfas
);
362 def
= reallocate_integer_array (def
, current_max_dfas
);
363 dfasiz
= reallocate_integer_array (dfasiz
, current_max_dfas
);
364 accsiz
= reallocate_integer_array (accsiz
, current_max_dfas
);
365 dhash
= reallocate_integer_array (dhash
, current_max_dfas
);
366 dss
= reallocate_int_ptr_array (dss
, current_max_dfas
);
367 dfaacc
= reallocate_dfaacc_union (dfaacc
, current_max_dfas
);
371 reallocate_integer_array (nultrans
,
376 /* ntod - convert an ndfa to a dfa
378 * Creates the dfa corresponding to the ndfa we've constructed. The
379 * dfa starts out in state #1.
384 int *accset
, ds
, nacc
, newds
;
385 int sym
, hashval
, numstates
, dsize
;
386 int num_full_table_rows
=0; /* used only for -f */
388 int targptr
, totaltrans
, i
, comstate
, comfreq
, targ
;
389 int symlist
[CSIZE
+ 1];
390 int num_start_states
;
391 int todo_head
, todo_next
;
393 struct yytbl_data
*yynxt_tbl
= 0;
394 flex_int32_t
*yynxt_data
= 0, yynxt_curr
= 0;
396 /* Note that the following are indexed by *equivalence classes*
397 * and not by characters. Since equivalence classes are indexed
398 * beginning with 1, even if the scanner accepts NUL's, this
399 * means that (since every character is potentially in its own
400 * equivalence class) these arrays must have room for indices
401 * from 1 to CSIZE, so their size must be CSIZE + 1.
403 int duplist
[CSIZE
+ 1], state
[CSIZE
+ 1];
404 int targfreq
[CSIZE
+ 1], targstate
[CSIZE
+ 1];
406 /* accset needs to be large enough to hold all of the rules present
407 * in the input, *plus* their YY_TRAILING_HEAD_MASK variants.
409 accset
= allocate_integer_array ((num_rules
+ 1) * 2);
410 nset
= allocate_integer_array (current_max_dfa_size
);
412 /* The "todo" queue is represented by the head, which is the DFA
413 * state currently being processed, and the "next", which is the
414 * next DFA state number available (not in use). We depend on the
415 * fact that snstods() returns DFA's \in increasing order/, and thus
416 * need only know the bounds of the dfas to be processed.
418 todo_head
= todo_next
= 0;
420 for (i
= 0; i
<= csize
; ++i
) {
425 for (i
= 0; i
<= num_rules
; ++i
)
430 fputs (_("\n\nDFA Dump:\n\n"), stderr
);
435 /* Check to see whether we should build a separate table for
436 * transitions on NUL characters. We don't do this for full-speed
437 * (-F) scanners, since for them we don't have a simple state
438 * number lying around with which to index the table. We also
439 * don't bother doing it for scanners unless (1) NUL is in its own
440 * equivalence class (indicated by a positive value of
441 * ecgroup[NUL]), (2) NUL's equivalence class is the last
442 * equivalence class, and (3) the number of equivalence classes is
443 * the same as the number of characters. This latter case comes
444 * about when useecs is false or when it's true but every character
445 * still manages to land in its own class (unlikely, but it's
446 * cheap to check for). If all these things are true then the
447 * character code needed to represent NUL's equivalence class for
448 * indexing the tables is going to take one more bit than the
449 * number of characters, and therefore we won't be assured of
450 * being able to fit it into a YY_CHAR variable. This rules out
451 * storing the transitions in a compressed table, since the code
452 * for interpreting them uses a YY_CHAR variable (perhaps it
453 * should just use an integer, though; this is worth pondering ...
456 * Finally, for full tables, we want the number of entries in the
457 * table to be a power of two so the array references go fast (it
458 * will just take a shift to compute the major index). If
459 * encoding NUL's transitions in the table will spoil this, we
460 * give it its own table (note that this will be the case if we're
461 * not using equivalence classes).
464 /* Note that the test for ecgroup[0] == numecs below accomplishes
465 * both (1) and (2) above
467 if (!fullspd
&& ecgroup
[0] == numecs
) {
468 /* NUL is alone in its equivalence class, which is the
471 int use_NUL_table
= (numecs
== csize
);
473 if (fulltbl
&& !use_NUL_table
) {
474 /* We still may want to use the table if numecs
479 for (power_of_two
= 1; power_of_two
<= csize
;
481 if (numecs
== power_of_two
) {
482 use_NUL_table
= true;
489 allocate_integer_array (current_max_dfas
);
491 /* From now on, nultrans != nil indicates that we're
492 * saving null transitions for later, separate encoding.
498 for (i
= 0; i
<= numecs
; ++i
)
501 place_state (state
, 0, 0);
502 dfaacc
[0].dfaacc_state
= 0;
507 /* We won't be including NUL's transitions in the
508 * table, so build it for entries from 0 .. numecs - 1.
510 num_full_table_rows
= numecs
;
513 /* Take into account the fact that we'll be including
514 * the NUL entries in the transition table. Build it
517 num_full_table_rows
= numecs
+ 1;
519 /* Begin generating yy_nxt[][]
520 * This spans the entire LONG function.
521 * This table is tricky because we don't know how big it will be.
522 * So we'll have to realloc() on the way...
523 * we'll wait until we can calculate yynxt_tbl->td_hilen.
526 (struct yytbl_data
*) calloc (1,
529 yytbl_data_init (yynxt_tbl
, YYTD_ID_NXT
);
530 yynxt_tbl
->td_hilen
= 1;
531 yynxt_tbl
->td_lolen
= num_full_table_rows
;
532 yynxt_tbl
->td_data
= yynxt_data
=
533 (flex_int32_t
*) calloc (yynxt_tbl
->td_lolen
*
535 sizeof (flex_int32_t
));
538 buf_prints (&yydmap_buf
,
539 "\t{YYTD_ID_NXT, (void**)&yy_nxt, sizeof(%s)},\n",
540 long_align
? "flex_int32_t" : "flex_int16_t");
542 /* Unless -Ca, declare it "short" because it's a real
543 * long-shot that that won't be large enough.
547 ("static yyconst %s yy_nxt[][%d] =\n {\n",
548 long_align
? "flex_int32_t" : "flex_int16_t",
549 num_full_table_rows
);
551 out_dec ("#undef YY_NXT_LOLEN\n#define YY_NXT_LOLEN (%d)\n", num_full_table_rows
);
552 out_str ("static yyconst %s *yy_nxt =0;\n",
553 long_align
? "flex_int32_t" : "flex_int16_t");
560 /* Generate 0 entries for state #0. */
561 for (i
= 0; i
< num_full_table_rows
; ++i
) {
563 yynxt_data
[yynxt_curr
++] = 0;
571 /* Create the first states. */
573 num_start_states
= lastsc
* 2;
575 for (i
= 1; i
<= num_start_states
; ++i
) {
578 /* For each start condition, make one state for the case when
579 * we're at the beginning of the line (the '^' operator) and
580 * one for the case when we're not.
583 nset
[numstates
] = scset
[(i
/ 2) + 1];
586 mkbranch (scbol
[i
/ 2], scset
[i
/ 2]);
588 nset
= epsclosure (nset
, &numstates
, accset
, &nacc
,
591 if (snstods (nset
, numstates
, accset
, nacc
, hashval
, &ds
)) {
596 if (variable_trailing_context_rules
&& nacc
> 0)
597 check_trailing_context (nset
, numstates
,
603 if (!snstods (nset
, 0, accset
, 0, 0, &end_of_buffer_state
))
605 ("could not create unique end-of-buffer state"));
613 while (todo_head
< todo_next
) {
617 for (i
= 1; i
<= numecs
; ++i
)
626 fprintf (stderr
, _("state # %d:\n"), ds
);
628 sympartition (dset
, dsize
, symlist
, duplist
);
630 for (sym
= 1; sym
<= numecs
; ++sym
) {
634 if (duplist
[sym
] == NIL
) {
635 /* Symbol has unique out-transitions. */
637 symfollowset (dset
, dsize
,
639 nset
= epsclosure (nset
,
645 (nset
, numstates
, accset
, nacc
,
652 if (variable_trailing_context_rules
&& nacc
> 0)
653 check_trailing_context
667 targfreq
[++targptr
] = 1;
668 targstate
[targptr
] = newds
;
673 /* sym's equivalence class has the same
674 * transitions as duplist(sym)'s
677 targ
= state
[duplist
[sym
]];
685 /* Update frequency count for
690 while (targstate
[++i
] != targ
) ;
702 numsnpairs
+= totaltrans
;
704 if (ds
> num_start_states
)
705 check_for_backing_up (ds
, state
);
708 nultrans
[ds
] = state
[NUL_ec
];
709 state
[NUL_ec
] = 0; /* remove transition */
714 /* Each time we hit here, it's another td_hilen, so we realloc. */
715 yynxt_tbl
->td_hilen
++;
716 yynxt_tbl
->td_data
= yynxt_data
=
717 (flex_int32_t
*) realloc (yynxt_data
,
718 yynxt_tbl
->td_hilen
*
719 yynxt_tbl
->td_lolen
*
720 sizeof (flex_int32_t
));
726 /* Supply array's 0-element. */
727 if (ds
== end_of_buffer_state
) {
728 mk2data (-end_of_buffer_state
);
729 yynxt_data
[yynxt_curr
++] =
730 -end_of_buffer_state
;
733 mk2data (end_of_buffer_state
);
734 yynxt_data
[yynxt_curr
++] =
738 for (i
= 1; i
< num_full_table_rows
; ++i
) {
739 /* Jams are marked by negative of state
742 mk2data (state
[i
] ? state
[i
] : -ds
);
743 yynxt_data
[yynxt_curr
++] =
744 state
[i
] ? state
[i
] : -ds
;
753 place_state (state
, ds
, totaltrans
);
755 else if (ds
== end_of_buffer_state
)
756 /* Special case this state to make sure it does what
757 * it's supposed to, i.e., jam on end-of-buffer.
759 stack1 (ds
, 0, 0, JAMSTATE
);
761 else { /* normal, compressed state */
763 /* Determine which destination state is the most
764 * common, and how many transitions to it there are.
770 for (i
= 1; i
<= targptr
; ++i
)
771 if (targfreq
[i
] > comfreq
) {
772 comfreq
= targfreq
[i
];
773 comstate
= targstate
[i
];
776 bldtbl (state
, ds
, totaltrans
, comstate
, comfreq
);
783 yytbl_data_compress (yynxt_tbl
);
784 if (yytbl_data_fwrite (&tableswr
, yynxt_tbl
) < 0)
786 ("Could not write yynxt_tbl[][]"));
789 yytbl_data_destroy (yynxt_tbl
);
795 cmptmps (); /* create compressed template entries */
797 /* Create tables for all the states with only one
801 mk1tbl (onestate
[onesp
], onesym
[onesp
],
802 onenext
[onesp
], onedef
[onesp
]);
809 flex_free ((void *) accset
);
810 flex_free ((void *) nset
);
814 /* snstods - converts a set of ndfa states into a dfa state
817 * is_new_state = snstods( int sns[numstates], int numstates,
818 * int accset[num_rules+1], int nacc,
819 * int hashval, int *newds_addr );
821 * On return, the dfa state number is in newds.
824 int snstods (sns
, numstates
, accset
, nacc
, hashval
, newds_addr
)
825 int sns
[], numstates
, accset
[], nacc
, hashval
, *newds_addr
;
831 for (i
= 1; i
<= lastdfa
; ++i
)
832 if (hashval
== dhash
[i
]) {
833 if (numstates
== dfasiz
[i
]) {
837 /* We sort the states in sns so we
838 * can compare it to oldsns quickly.
840 qsort (&sns
[1], numstates
, sizeof (sns
[1]), intcmp
);
844 for (j
= 1; j
<= numstates
; ++j
)
845 if (sns
[j
] != oldsns
[j
])
861 /* Make a new dfa. */
863 if (++lastdfa
>= current_max_dfas
)
864 increase_max_dfas ();
868 dss
[newds
] = allocate_integer_array (numstates
+ 1);
870 /* If we haven't already sorted the states in sns, we do so now,
871 * so that future comparisons with it can be made quickly.
875 qsort (&sns
[1], numstates
, sizeof (sns
[1]), intcmp
);
877 for (i
= 1; i
<= numstates
; ++i
)
878 dss
[newds
][i
] = sns
[i
];
880 dfasiz
[newds
] = numstates
;
881 dhash
[newds
] = hashval
;
885 dfaacc
[newds
].dfaacc_set
= (int *) 0;
887 dfaacc
[newds
].dfaacc_state
= 0;
893 /* We sort the accepting set in increasing order so the
894 * disambiguating rule that the first rule listed is considered
895 * match in the event of ties will work.
898 qsort (&accset
[1], nacc
, sizeof (accset
[1]), intcmp
);
900 dfaacc
[newds
].dfaacc_set
=
901 allocate_integer_array (nacc
+ 1);
903 /* Save the accepting set for later */
904 for (i
= 1; i
<= nacc
; ++i
) {
905 dfaacc
[newds
].dfaacc_set
[i
] = accset
[i
];
907 if (accset
[i
] <= num_rules
)
908 /* Who knows, perhaps a REJECT can yield
911 rule_useful
[accset
[i
]] = true;
914 accsiz
[newds
] = nacc
;
918 /* Find lowest numbered rule so the disambiguating rule
923 for (i
= 1; i
<= nacc
; ++i
)
927 dfaacc
[newds
].dfaacc_state
= j
;
930 rule_useful
[j
] = true;
939 /* symfollowset - follow the symbol transitions one step
942 * numstates = symfollowset( int ds[current_max_dfa_size], int dsize,
943 * int transsym, int nset[current_max_dfa_size] );
946 int symfollowset (ds
, dsize
, transsym
, nset
)
947 int ds
[], dsize
, transsym
, nset
[];
949 int ns
, tsp
, sym
, i
, j
, lenccl
, ch
, numstates
, ccllist
;
953 for (i
= 1; i
<= dsize
; ++i
) { /* for each nfa state ns in the state set of ds */
958 if (sym
< 0) { /* it's a character class */
960 ccllist
= cclmap
[sym
];
961 lenccl
= ccllen
[sym
];
964 for (j
= 0; j
< lenccl
; ++j
) {
965 /* Loop through negated character
968 ch
= ccltbl
[ccllist
+ j
];
974 /* Transsym isn't in negated
979 else if (ch
== transsym
)
984 /* Didn't find transsym in ccl. */
985 nset
[++numstates
] = tsp
;
989 for (j
= 0; j
< lenccl
; ++j
) {
990 ch
= ccltbl
[ccllist
+ j
];
997 else if (ch
== transsym
) {
998 nset
[++numstates
] = tsp
;
1004 else if (sym
== SYM_EPSILON
) { /* do nothing */
1007 else if (ABS (ecgroup
[sym
]) == transsym
)
1008 nset
[++numstates
] = tsp
;
1017 /* sympartition - partition characters with same out-transitions
1020 * sympartition( int ds[current_max_dfa_size], int numstates,
1021 * int symlist[numecs], int duplist[numecs] );
1024 void sympartition (ds
, numstates
, symlist
, duplist
)
1025 int ds
[], numstates
;
1026 int symlist
[], duplist
[];
1028 int tch
, i
, j
, k
, ns
, dupfwd
[CSIZE
+ 1], lenccl
, cclp
, ich
;
1030 /* Partitioning is done by creating equivalence classes for those
1031 * characters which have out-transitions from the given state. Thus
1032 * we are really creating equivalence classes of equivalence classes.
1035 for (i
= 1; i
<= numecs
; ++i
) { /* initialize equivalence class list */
1041 dupfwd
[numecs
] = NIL
;
1043 for (i
= 1; i
<= numstates
; ++i
) {
1045 tch
= transchar
[ns
];
1047 if (tch
!= SYM_EPSILON
) {
1048 if (tch
< -lastccl
|| tch
>= csize
) {
1050 ("bad transition character detected in sympartition()"));
1053 if (tch
>= 0) { /* character transition */
1054 int ec
= ecgroup
[tch
];
1056 mkechar (ec
, dupfwd
, duplist
);
1060 else { /* character class */
1063 lenccl
= ccllen
[tch
];
1065 mkeccl (ccltbl
+ cclp
, lenccl
, dupfwd
,
1066 duplist
, numecs
, NUL_ec
);
1071 for (k
= 0; k
< lenccl
; ++k
) {
1072 ich
= ccltbl
[cclp
+ k
];
1077 for (++j
; j
< ich
; ++j
)
1081 for (++j
; j
<= numecs
; ++j
)
1086 for (k
= 0; k
< lenccl
; ++k
) {
1087 ich
= ccltbl
[cclp
+ k
];