From 65f156cd0e605c11a40877d8c070a185def699e5 Mon Sep 17 00:00:00 2001 From: Norihiro Tanaka Date: Mon, 22 Oct 2018 23:22:40 +0900 Subject: [PATCH 1/6] dfa: remove unneeded code By the addition of beg, a code for the initial state is unnecessary, so remove it. dfa.c (epsclosure): Remove a code for the initial state. (dfaanalyze): Print follows for BEG in debug mode. --- lib/dfa.c | 12 +++++------- 1 files changed, 5 insertions(+), 7 deletions(-) diff --git a/lib/dfa.c b/lib/dfa.c index d04bcbe..af55469 100644 --- a/lib/dfa.c +++ b/lib/dfa.c @@ -2248,7 +2248,7 @@ state_index (struct dfa *d, position_set const *s, int context) constraint. Repeat exhaustively until no funny positions are left. S->elems must be large enough to hold the result. */ static void -epsclosure (position_set *initial, struct dfa const *d) +epsclosure (struct dfa const *d) { position_set tmp; alloc_position_set (&tmp, d->nleaves); @@ -2288,8 +2288,6 @@ epsclosure (position_set *initial, struct dfa const *d) for (size_t j = 0; j < d->tindex; j++) if (i != j && d->follows[j].nelem > 0) replace (&d->follows[j], i, &d->follows[i], constraint, &tmp); - - replace (initial, i, &d->follows[i], constraint, &tmp); } free (tmp.elems); } @@ -2680,9 +2678,9 @@ dfaanalyze (struct dfa *d, bool searchflag) #ifdef DEBUG for (size_t i = 0; i < d->tindex; ++i) - if (d->tokens[i] < NOTCHAR || d->tokens[i] == BACKREF - || d->tokens[i] == ANYCHAR || d->tokens[i] == MBCSET - || d->tokens[i] >= CSET) + if (d->tokens[i] == BEG || d->tokens[i] < NOTCHAR + || d->tokens[i] == BACKREF || d->tokens[i] == ANYCHAR + || d->tokens[i] == MBCSET || d->tokens[i] >= CSET) { fprintf (stderr, "follows(%zu:", i); prtok (d->tokens[i]); @@ -2698,7 +2696,7 @@ dfaanalyze (struct dfa *d, bool searchflag) /* For each follow set that is the follow set of a real position, replace it with its epsilon closure. */ - epsclosure (&d->follows[0], d); + epsclosure (d); /* Context wanted by some position. */ int separate_contexts = state_separate_contexts (&d->follows[0]); -- 1.7.1