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 */
35 /* declare functions that have forward references */
37 void dump_associated_rules
PROTO ((FILE *, int));
38 void dump_transitions
PROTO ((FILE *, int[]));
39 void sympartition
PROTO ((int[], int, int[], int[]));
40 int symfollowset
PROTO ((int[], int, int, int[]));
43 /* check_for_backing_up - check a DFA state for backing up
46 * void check_for_backing_up( int ds, int state[numecs] );
48 * ds is the number of the state to check and state[] is its out-transitions,
49 * indexed by equivalence class.
52 void check_for_backing_up (ds
, state
)
56 if ((reject
&& !dfaacc
[ds
].dfaacc_set
) || (!reject
&& !dfaacc
[ds
].dfaacc_state
)) { /* state is non-accepting */
59 if (backing_up_report
) {
60 fprintf (backing_up_file
,
61 _("State #%d is non-accepting -\n"), ds
);
63 /* identify the state */
64 dump_associated_rules (backing_up_file
, ds
);
66 /* Now identify it further using the out- and
69 dump_transitions (backing_up_file
, state
);
71 putc ('\n', backing_up_file
);
77 /* check_trailing_context - check to see if NFA state set constitutes
78 * "dangerous" trailing context
81 * void check_trailing_context( int nfa_states[num_states+1], int num_states,
82 * int accset[nacc+1], int nacc );
85 * Trailing context is "dangerous" if both the head and the trailing
86 * part are of variable size \and/ there's a DFA state which contains
87 * both an accepting state for the head part of the rule and NFA states
88 * which occur after the beginning of the trailing context.
90 * When such a rule is matched, it's impossible to tell if having been
91 * in the DFA state indicates the beginning of the trailing context or
92 * further-along scanning of the pattern. In these cases, a warning
95 * nfa_states[1 .. num_states] is the list of NFA states in the DFA.
96 * accset[1 .. nacc] is the list of accepting numbers for the DFA state.
99 void check_trailing_context (nfa_states
, num_states
, accset
, nacc
)
100 int *nfa_states
, num_states
;
106 for (i
= 1; i
<= num_states
; ++i
) {
107 int ns
= nfa_states
[i
];
108 register int type
= state_type
[ns
];
109 register int ar
= assoc_rule
[ns
];
111 if (type
== STATE_NORMAL
|| rule_type
[ar
] != RULE_VARIABLE
) { /* do nothing */
114 else if (type
== STATE_TRAILING_CONTEXT
) {
115 /* Potential trouble. Scan set of accepting numbers
116 * for the one marking the end of the "head". We
117 * assume that this looping will be fairly cheap
118 * since it's rare that an accepting number set
121 for (j
= 1; j
<= nacc
; ++j
)
122 if (accset
[j
] & YY_TRAILING_HEAD_MASK
) {
124 ("dangerous trailing context"),
133 /* dump_associated_rules - list the rules associated with a DFA state
135 * Goes through the set of NFA states associated with the DFA and
136 * extracts the first MAX_ASSOC_RULES unique rules, sorts them,
137 * and writes a report to the given file.
140 void dump_associated_rules (file
, ds
)
145 register int num_associated_rules
= 0;
146 int rule_set
[MAX_ASSOC_RULES
+ 1];
148 int size
= dfasiz
[ds
];
150 for (i
= 1; i
<= size
; ++i
) {
151 register int rule_num
= rule_linenum
[assoc_rule
[dset
[i
]]];
153 for (j
= 1; j
<= num_associated_rules
; ++j
)
154 if (rule_num
== rule_set
[j
])
157 if (j
> num_associated_rules
) { /* new rule */
158 if (num_associated_rules
< MAX_ASSOC_RULES
)
159 rule_set
[++num_associated_rules
] =
164 qsort (&rule_set
[1], num_associated_rules
, sizeof (rule_set
[1]), intcmp
);
166 fprintf (file
, _(" associated rule line numbers:"));
168 for (i
= 1; i
<= num_associated_rules
; ++i
) {
172 fprintf (file
, "\t%d", rule_set
[i
]);
179 /* dump_transitions - list the transitions associated with a DFA state
182 * dump_transitions( FILE *file, int state[numecs] );
184 * Goes through the set of out-transitions and lists them in human-readable
185 * form (i.e., not as equivalence classes); also lists jam transitions
186 * (i.e., all those which are not out-transitions, plus EOF). The dump
187 * is done to the given file.
190 void dump_transitions (file
, state
)
195 int out_char_set
[CSIZE
];
197 for (i
= 0; i
< csize
; ++i
) {
198 ec
= ABS (ecgroup
[i
]);
199 out_char_set
[i
] = state
[ec
];
202 fprintf (file
, _(" out-transitions: "));
204 list_character_set (file
, out_char_set
);
206 /* now invert the members of the set to get the jam transitions */
207 for (i
= 0; i
< csize
; ++i
)
208 out_char_set
[i
] = !out_char_set
[i
];
210 fprintf (file
, _("\n jam-transitions: EOF "));
212 list_character_set (file
, out_char_set
);
218 /* epsclosure - construct the epsilon closure of a set of ndfa states
221 * int *epsclosure( int t[num_states], int *numstates_addr,
222 * int accset[num_rules+1], int *nacc_addr,
223 * int *hashval_addr );
226 * The epsilon closure is the set of all states reachable by an arbitrary
227 * number of epsilon transitions, which themselves do not have epsilon
228 * transitions going out, unioned with the set of states which have non-null
229 * accepting numbers. t is an array of size numstates of nfa state numbers.
230 * Upon return, t holds the epsilon closure and *numstates_addr is updated.
231 * accset holds a list of the accepting numbers, and the size of accset is
232 * given by *nacc_addr. t may be subjected to reallocation if it is not
233 * large enough to hold the epsilon closure.
235 * hashval is the hash value for the dfa corresponding to the state set.
238 int *epsclosure (t
, ns_addr
, accset
, nacc_addr
, hv_addr
)
239 int *t
, *ns_addr
, accset
[], *nacc_addr
, *hv_addr
;
241 register int stkpos
, ns
, tsp
;
242 int numstates
= *ns_addr
, nacc
, hashval
, transsym
, nfaccnum
;
244 static int did_stk_init
= false, *stk
;
246 #define MARK_STATE(state) \
247 do{ trans1[state] = trans1[state] - MARKER_DIFFERENCE;} while(0)
249 #define IS_MARKED(state) (trans1[state] < 0)
251 #define UNMARK_STATE(state) \
252 do{ trans1[state] = trans1[state] + MARKER_DIFFERENCE;} while(0)
254 #define CHECK_ACCEPT(state) \
256 nfaccnum = accptnum[state]; \
257 if ( nfaccnum != NIL ) \
258 accset[++nacc] = nfaccnum; \
261 #define DO_REALLOCATION() \
263 current_max_dfa_size += MAX_DFA_SIZE_INCREMENT; \
265 t = reallocate_integer_array( t, current_max_dfa_size ); \
266 stk = reallocate_integer_array( stk, current_max_dfa_size ); \
269 #define PUT_ON_STACK(state) \
271 if ( ++stkend >= current_max_dfa_size ) \
273 stk[stkend] = state; \
277 #define ADD_STATE(state) \
279 if ( ++numstates >= current_max_dfa_size ) \
281 t[numstates] = state; \
285 #define STACK_STATE(state) \
287 PUT_ON_STACK(state); \
288 CHECK_ACCEPT(state); \
289 if ( nfaccnum != NIL || transchar[state] != SYM_EPSILON ) \
295 stk
= allocate_integer_array (current_max_dfa_size
);
299 nacc
= stkend
= hashval
= 0;
301 for (nstate
= 1; nstate
<= numstates
; ++nstate
) {
304 /* The state could be marked if we've already pushed it onto
307 if (!IS_MARKED (ns
)) {
314 for (stkpos
= 1; stkpos
<= stkend
; ++stkpos
) {
316 transsym
= transchar
[ns
];
318 if (transsym
== SYM_EPSILON
) {
319 tsp
= trans1
[ns
] + MARKER_DIFFERENCE
;
321 if (tsp
!= NO_TRANSITION
) {
322 if (!IS_MARKED (tsp
))
327 if (tsp
!= NO_TRANSITION
334 /* Clear out "visit" markers. */
336 for (stkpos
= 1; stkpos
<= stkend
; ++stkpos
) {
337 if (IS_MARKED (stk
[stkpos
]))
338 UNMARK_STATE (stk
[stkpos
]);
341 ("consistency check failed in epsclosure()"));
344 *ns_addr
= numstates
;
352 /* increase_max_dfas - increase the maximum number of DFAs */
354 void increase_max_dfas ()
356 current_max_dfas
+= MAX_DFAS_INCREMENT
;
360 base
= reallocate_integer_array (base
, current_max_dfas
);
361 def
= reallocate_integer_array (def
, current_max_dfas
);
362 dfasiz
= reallocate_integer_array (dfasiz
, current_max_dfas
);
363 accsiz
= reallocate_integer_array (accsiz
, current_max_dfas
);
364 dhash
= reallocate_integer_array (dhash
, current_max_dfas
);
365 dss
= reallocate_int_ptr_array (dss
, current_max_dfas
);
366 dfaacc
= reallocate_dfaacc_union (dfaacc
, current_max_dfas
);
370 reallocate_integer_array (nultrans
,
375 /* ntod - convert an ndfa to a dfa
377 * Creates the dfa corresponding to the ndfa we've constructed. The
378 * dfa starts out in state #1.
383 int *accset
, ds
, nacc
, newds
;
384 int sym
, hashval
, numstates
, dsize
;
385 int num_full_table_rows
=0; /* used only for -f */
387 int targptr
, totaltrans
, i
, comstate
, comfreq
, targ
;
388 int symlist
[CSIZE
+ 1];
389 int num_start_states
;
390 int todo_head
, todo_next
;
392 struct yytbl_data
*yynxt_tbl
= 0;
393 flex_int32_t
*yynxt_data
= 0, yynxt_curr
= 0;
395 /* Note that the following are indexed by *equivalence classes*
396 * and not by characters. Since equivalence classes are indexed
397 * beginning with 1, even if the scanner accepts NUL's, this
398 * means that (since every character is potentially in its own
399 * equivalence class) these arrays must have room for indices
400 * from 1 to CSIZE, so their size must be CSIZE + 1.
402 int duplist
[CSIZE
+ 1], state
[CSIZE
+ 1];
403 int targfreq
[CSIZE
+ 1], targstate
[CSIZE
+ 1];
405 /* accset needs to be large enough to hold all of the rules present
406 * in the input, *plus* their YY_TRAILING_HEAD_MASK variants.
408 accset
= allocate_integer_array ((num_rules
+ 1) * 2);
409 nset
= allocate_integer_array (current_max_dfa_size
);
411 /* The "todo" queue is represented by the head, which is the DFA
412 * state currently being processed, and the "next", which is the
413 * next DFA state number available (not in use). We depend on the
414 * fact that snstods() returns DFA's \in increasing order/, and thus
415 * need only know the bounds of the dfas to be processed.
417 todo_head
= todo_next
= 0;
419 for (i
= 0; i
<= csize
; ++i
) {
424 for (i
= 0; i
<= num_rules
; ++i
)
429 fputs (_("\n\nDFA Dump:\n\n"), stderr
);
434 /* Check to see whether we should build a separate table for
435 * transitions on NUL characters. We don't do this for full-speed
436 * (-F) scanners, since for them we don't have a simple state
437 * number lying around with which to index the table. We also
438 * don't bother doing it for scanners unless (1) NUL is in its own
439 * equivalence class (indicated by a positive value of
440 * ecgroup[NUL]), (2) NUL's equivalence class is the last
441 * equivalence class, and (3) the number of equivalence classes is
442 * the same as the number of characters. This latter case comes
443 * about when useecs is false or when it's true but every character
444 * still manages to land in its own class (unlikely, but it's
445 * cheap to check for). If all these things are true then the
446 * character code needed to represent NUL's equivalence class for
447 * indexing the tables is going to take one more bit than the
448 * number of characters, and therefore we won't be assured of
449 * being able to fit it into a YY_CHAR variable. This rules out
450 * storing the transitions in a compressed table, since the code
451 * for interpreting them uses a YY_CHAR variable (perhaps it
452 * should just use an integer, though; this is worth pondering ...
455 * Finally, for full tables, we want the number of entries in the
456 * table to be a power of two so the array references go fast (it
457 * will just take a shift to compute the major index). If
458 * encoding NUL's transitions in the table will spoil this, we
459 * give it its own table (note that this will be the case if we're
460 * not using equivalence classes).
463 /* Note that the test for ecgroup[0] == numecs below accomplishes
464 * both (1) and (2) above
466 if (!fullspd
&& ecgroup
[0] == numecs
) {
467 /* NUL is alone in its equivalence class, which is the
470 int use_NUL_table
= (numecs
== csize
);
472 if (fulltbl
&& !use_NUL_table
) {
473 /* We still may want to use the table if numecs
478 for (power_of_two
= 1; power_of_two
<= csize
;
480 if (numecs
== power_of_two
) {
481 use_NUL_table
= true;
488 allocate_integer_array (current_max_dfas
);
490 /* From now on, nultrans != nil indicates that we're
491 * saving null transitions for later, separate encoding.
497 for (i
= 0; i
<= numecs
; ++i
)
500 place_state (state
, 0, 0);
501 dfaacc
[0].dfaacc_state
= 0;
506 /* We won't be including NUL's transitions in the
507 * table, so build it for entries from 0 .. numecs - 1.
509 num_full_table_rows
= numecs
;
512 /* Take into account the fact that we'll be including
513 * the NUL entries in the transition table. Build it
516 num_full_table_rows
= numecs
+ 1;
518 /* Begin generating yy_nxt[][]
519 * This spans the entire LONG function.
520 * This table is tricky because we don't know how big it will be.
521 * So we'll have to realloc() on the way...
522 * we'll wait until we can calculate yynxt_tbl->td_hilen.
525 (struct yytbl_data
*) calloc (1,
528 yytbl_data_init (yynxt_tbl
, YYTD_ID_NXT
);
529 yynxt_tbl
->td_hilen
= 1;
530 yynxt_tbl
->td_lolen
= num_full_table_rows
;
531 yynxt_tbl
->td_data
= yynxt_data
=
532 (flex_int32_t
*) calloc (yynxt_tbl
->td_lolen
*
534 sizeof (flex_int32_t
));
537 buf_prints (&yydmap_buf
,
538 "\t{YYTD_ID_NXT, (void**)&yy_nxt, sizeof(%s)},\n",
539 long_align
? "flex_int32_t" : "flex_int16_t");
541 /* Unless -Ca, declare it "short" because it's a real
542 * long-shot that that won't be large enough.
546 ("static yyconst %s yy_nxt[][%d] =\n {\n",
547 long_align
? "flex_int32_t" : "flex_int16_t",
548 num_full_table_rows
);
550 out_dec ("#undef YY_NXT_LOLEN\n#define YY_NXT_LOLEN (%d)\n", num_full_table_rows
);
551 out_str ("static yyconst %s *yy_nxt =0;\n",
552 long_align
? "flex_int32_t" : "flex_int16_t");
559 /* Generate 0 entries for state #0. */
560 for (i
= 0; i
< num_full_table_rows
; ++i
) {
562 yynxt_data
[yynxt_curr
++] = 0;
570 /* Create the first states. */
572 num_start_states
= lastsc
* 2;
574 for (i
= 1; i
<= num_start_states
; ++i
) {
577 /* For each start condition, make one state for the case when
578 * we're at the beginning of the line (the '^' operator) and
579 * one for the case when we're not.
582 nset
[numstates
] = scset
[(i
/ 2) + 1];
585 mkbranch (scbol
[i
/ 2], scset
[i
/ 2]);
587 nset
= epsclosure (nset
, &numstates
, accset
, &nacc
,
590 if (snstods (nset
, numstates
, accset
, nacc
, hashval
, &ds
)) {
595 if (variable_trailing_context_rules
&& nacc
> 0)
596 check_trailing_context (nset
, numstates
,
602 if (!snstods (nset
, 0, accset
, 0, 0, &end_of_buffer_state
))
604 ("could not create unique end-of-buffer state"));
612 while (todo_head
< todo_next
) {
616 for (i
= 1; i
<= numecs
; ++i
)
625 fprintf (stderr
, _("state # %d:\n"), ds
);
627 sympartition (dset
, dsize
, symlist
, duplist
);
629 for (sym
= 1; sym
<= numecs
; ++sym
) {
633 if (duplist
[sym
] == NIL
) {
634 /* Symbol has unique out-transitions. */
636 symfollowset (dset
, dsize
,
638 nset
= epsclosure (nset
,
644 (nset
, numstates
, accset
, nacc
,
651 if (variable_trailing_context_rules
&& nacc
> 0)
652 check_trailing_context
666 targfreq
[++targptr
] = 1;
667 targstate
[targptr
] = newds
;
672 /* sym's equivalence class has the same
673 * transitions as duplist(sym)'s
676 targ
= state
[duplist
[sym
]];
684 /* Update frequency count for
689 while (targstate
[++i
] != targ
) ;
701 numsnpairs
+= totaltrans
;
703 if (ds
> num_start_states
)
704 check_for_backing_up (ds
, state
);
707 nultrans
[ds
] = state
[NUL_ec
];
708 state
[NUL_ec
] = 0; /* remove transition */
713 /* Each time we hit here, it's another td_hilen, so we realloc. */
714 yynxt_tbl
->td_hilen
++;
715 yynxt_tbl
->td_data
= yynxt_data
=
716 (flex_int32_t
*) realloc (yynxt_data
,
717 yynxt_tbl
->td_hilen
*
718 yynxt_tbl
->td_lolen
*
719 sizeof (flex_int32_t
));
725 /* Supply array's 0-element. */
726 if (ds
== end_of_buffer_state
) {
727 mk2data (-end_of_buffer_state
);
728 yynxt_data
[yynxt_curr
++] =
729 -end_of_buffer_state
;
732 mk2data (end_of_buffer_state
);
733 yynxt_data
[yynxt_curr
++] =
737 for (i
= 1; i
< num_full_table_rows
; ++i
) {
738 /* Jams are marked by negative of state
741 mk2data (state
[i
] ? state
[i
] : -ds
);
742 yynxt_data
[yynxt_curr
++] =
743 state
[i
] ? state
[i
] : -ds
;
752 place_state (state
, ds
, totaltrans
);
754 else if (ds
== end_of_buffer_state
)
755 /* Special case this state to make sure it does what
756 * it's supposed to, i.e., jam on end-of-buffer.
758 stack1 (ds
, 0, 0, JAMSTATE
);
760 else { /* normal, compressed state */
762 /* Determine which destination state is the most
763 * common, and how many transitions to it there are.
769 for (i
= 1; i
<= targptr
; ++i
)
770 if (targfreq
[i
] > comfreq
) {
771 comfreq
= targfreq
[i
];
772 comstate
= targstate
[i
];
775 bldtbl (state
, ds
, totaltrans
, comstate
, comfreq
);
782 yytbl_data_compress (yynxt_tbl
);
783 if (yytbl_data_fwrite (&tableswr
, yynxt_tbl
) < 0)
785 ("Could not write yynxt_tbl[][]"));
788 yytbl_data_destroy (yynxt_tbl
);
794 cmptmps (); /* create compressed template entries */
796 /* Create tables for all the states with only one
800 mk1tbl (onestate
[onesp
], onesym
[onesp
],
801 onenext
[onesp
], onedef
[onesp
]);
808 flex_free ((void *) accset
);
809 flex_free ((void *) nset
);
813 /* snstods - converts a set of ndfa states into a dfa state
816 * is_new_state = snstods( int sns[numstates], int numstates,
817 * int accset[num_rules+1], int nacc,
818 * int hashval, int *newds_addr );
820 * On return, the dfa state number is in newds.
823 int snstods (sns
, numstates
, accset
, nacc
, hashval
, newds_addr
)
824 int sns
[], numstates
, accset
[], nacc
, hashval
, *newds_addr
;
830 for (i
= 1; i
<= lastdfa
; ++i
)
831 if (hashval
== dhash
[i
]) {
832 if (numstates
== dfasiz
[i
]) {
836 /* We sort the states in sns so we
837 * can compare it to oldsns quickly.
839 qsort (&sns
[1], numstates
, sizeof (sns
[1]), intcmp
);
843 for (j
= 1; j
<= numstates
; ++j
)
844 if (sns
[j
] != oldsns
[j
])
860 /* Make a new dfa. */
862 if (++lastdfa
>= current_max_dfas
)
863 increase_max_dfas ();
867 dss
[newds
] = allocate_integer_array (numstates
+ 1);
869 /* If we haven't already sorted the states in sns, we do so now,
870 * so that future comparisons with it can be made quickly.
874 qsort (&sns
[1], numstates
, sizeof (sns
[1]), intcmp
);
876 for (i
= 1; i
<= numstates
; ++i
)
877 dss
[newds
][i
] = sns
[i
];
879 dfasiz
[newds
] = numstates
;
880 dhash
[newds
] = hashval
;
884 dfaacc
[newds
].dfaacc_set
= (int *) 0;
886 dfaacc
[newds
].dfaacc_state
= 0;
892 /* We sort the accepting set in increasing order so the
893 * disambiguating rule that the first rule listed is considered
894 * match in the event of ties will work.
897 qsort (&accset
[1], nacc
, sizeof (accset
[1]), intcmp
);
899 dfaacc
[newds
].dfaacc_set
=
900 allocate_integer_array (nacc
+ 1);
902 /* Save the accepting set for later */
903 for (i
= 1; i
<= nacc
; ++i
) {
904 dfaacc
[newds
].dfaacc_set
[i
] = accset
[i
];
906 if (accset
[i
] <= num_rules
)
907 /* Who knows, perhaps a REJECT can yield
910 rule_useful
[accset
[i
]] = true;
913 accsiz
[newds
] = nacc
;
917 /* Find lowest numbered rule so the disambiguating rule
922 for (i
= 1; i
<= nacc
; ++i
)
926 dfaacc
[newds
].dfaacc_state
= j
;
929 rule_useful
[j
] = true;
938 /* symfollowset - follow the symbol transitions one step
941 * numstates = symfollowset( int ds[current_max_dfa_size], int dsize,
942 * int transsym, int nset[current_max_dfa_size] );
945 int symfollowset (ds
, dsize
, transsym
, nset
)
946 int ds
[], dsize
, transsym
, nset
[];
948 int ns
, tsp
, sym
, i
, j
, lenccl
, ch
, numstates
, ccllist
;
952 for (i
= 1; i
<= dsize
; ++i
) { /* for each nfa state ns in the state set of ds */
957 if (sym
< 0) { /* it's a character class */
959 ccllist
= cclmap
[sym
];
960 lenccl
= ccllen
[sym
];
963 for (j
= 0; j
< lenccl
; ++j
) {
964 /* Loop through negated character
967 ch
= ccltbl
[ccllist
+ j
];
973 /* Transsym isn't in negated
978 else if (ch
== transsym
)
983 /* Didn't find transsym in ccl. */
984 nset
[++numstates
] = tsp
;
988 for (j
= 0; j
< lenccl
; ++j
) {
989 ch
= ccltbl
[ccllist
+ j
];
996 else if (ch
== transsym
) {
997 nset
[++numstates
] = tsp
;
1003 else if (sym
== SYM_EPSILON
) { /* do nothing */
1006 else if (ABS (ecgroup
[sym
]) == transsym
)
1007 nset
[++numstates
] = tsp
;
1016 /* sympartition - partition characters with same out-transitions
1019 * sympartition( int ds[current_max_dfa_size], int numstates,
1020 * int symlist[numecs], int duplist[numecs] );
1023 void sympartition (ds
, numstates
, symlist
, duplist
)
1024 int ds
[], numstates
;
1025 int symlist
[], duplist
[];
1027 int tch
, i
, j
, k
, ns
, dupfwd
[CSIZE
+ 1], lenccl
, cclp
, ich
;
1029 /* Partitioning is done by creating equivalence classes for those
1030 * characters which have out-transitions from the given state. Thus
1031 * we are really creating equivalence classes of equivalence classes.
1034 for (i
= 1; i
<= numecs
; ++i
) { /* initialize equivalence class list */
1040 dupfwd
[numecs
] = NIL
;
1042 for (i
= 1; i
<= numstates
; ++i
) {
1044 tch
= transchar
[ns
];
1046 if (tch
!= SYM_EPSILON
) {
1047 if (tch
< -lastccl
|| tch
>= csize
) {
1049 ("bad transition character detected in sympartition()"));
1052 if (tch
>= 0) { /* character transition */
1053 int ec
= ecgroup
[tch
];
1055 mkechar (ec
, dupfwd
, duplist
);
1059 else { /* character class */
1062 lenccl
= ccllen
[tch
];
1064 mkeccl (ccltbl
+ cclp
, lenccl
, dupfwd
,
1065 duplist
, numecs
, NUL_ec
);
1070 for (k
= 0; k
< lenccl
; ++k
) {
1071 ich
= ccltbl
[cclp
+ k
];
1076 for (++j
; j
< ich
; ++j
)
1080 for (++j
; j
<= numecs
; ++j
)
1085 for (k
= 0; k
< lenccl
; ++k
) {
1086 ich
= ccltbl
[cclp
+ k
];