Mercurial > hg > Applications > Grep
comparison regexParser/generateSequentialSearch.cc @ 324:879dc5d1cb6a default tip
fix
author | mir3636 |
---|---|
date | Fri, 27 May 2016 21:21:09 +0900 |
parents | c9ac6f06e706 |
children |
comparison
equal
deleted
inserted
replaced
323:672c1be4eec7 | 324:879dc5d1cb6a |
---|---|
2 #include <stdlib.h> | 2 #include <stdlib.h> |
3 | 3 |
4 #include "generateSequentialSearch.h" | 4 #include "generateSequentialSearch.h" |
5 #include "CharClass.h" | 5 #include "CharClass.h" |
6 #include "subsetConstruction.h" | 6 #include "subsetConstruction.h" |
7 #include "bmSearch.h" | |
8 | |
9 static void | |
10 wordMatch(const char* cond,FILE* fp,unsigned long begin,CharClassPtr cc,BitVector bi) { | |
11 fprintf(fp," else if (c%s'%c') { \n",cond,(unsigned char)begin); | |
12 WordPtr w; | |
13 for (w = &cc->cond.w;w;w = w->next) { | |
14 // match the word. | |
15 fprintf(fp," if (strncmp(\"%s\",(const char *)tsv.buff.buffptr-1,%d)==0) { tsv.buff.buffptr += %d;return state%lx(tsv);}\n",(const char *)w->word,w->length,w->length - 1,bi.bitContainer); | |
16 } | |
17 fprintf(fp," tsv=tsv.tg->stateSkip(tsv);return state0(tsv);;\n } \n"); | |
18 } | |
7 | 19 |
8 static void | 20 static void |
9 generateState1(StatePtr state,long stateNum, bool accept, FILE *fp, TransitionGeneratorPtr tg) { | 21 generateState1(StatePtr state,long stateNum, bool accept, FILE *fp, TransitionGeneratorPtr tg) { |
10 fprintf(fp,"static TSValue state%lx(TSValue tsv) {\n",stateNum); | 22 fprintf(fp,"static TSValue state%lx(TSValue tsv) {\n",stateNum); |
11 if (accept && state->accept) { | 23 if (accept && state->accept) { |
19 CharClassPtr cc = getNext(ccw); | 31 CharClassPtr cc = getNext(ccw); |
20 unsigned long begin = cc->cond.range.begin; | 32 unsigned long begin = cc->cond.range.begin; |
21 unsigned long end = cc->cond.range.end; | 33 unsigned long end = cc->cond.range.end; |
22 BitVector bi = cc->nextState; | 34 BitVector bi = cc->nextState; |
23 if (begin == end) { | 35 if (begin == end) { |
24 fprintf(fp," else if (c=='%c') { return state%lx(tsv);}\n",(unsigned char)begin, bi.bitContainer); | 36 if (cc->cond.w.word) { |
37 wordMatch("==",fp,begin,cc,bi); | |
38 } else { | |
39 fprintf(fp," else if (c=='%c') { return state%lx(tsv);}\n",(unsigned char)begin, bi.bitContainer); | |
40 } | |
25 } else { | 41 } else { |
26 fprintf(fp," else if (c<'%c') { tsv=tsv.tg->stateSkip(tsv);return state0(tsv);}\n",(unsigned char)begin); | 42 fprintf(fp," else if (c<'%c') { tsv=tsv.tg->stateSkip(tsv);return state0(tsv);}\n",(unsigned char)begin); |
27 fprintf(fp," else if (c<='%c') { return state%lx(tsv);} \n",(unsigned char)end, bi.bitContainer); | 43 if (cc->cond.w.word) { |
44 wordMatch("<=",fp,begin,cc,bi); | |
45 } else { | |
46 fprintf(fp," else if (c<='%c') { return state%lx(tsv);} \n",(unsigned char)end, bi.bitContainer); | |
47 } | |
28 } | 48 } |
29 } | 49 } |
30 free(ccw); | 50 free(ccw); |
31 fprintf(fp," else { tsv=tsv.tg->stateSkip(tsv); return state0(tsv);}\n"); | 51 fprintf(fp," else { tsv=tsv.tg->stateSkip(tsv); return state0(tsv);}\n"); |
32 fputs("}\n\n",fp); | 52 fputs("}\n\n",fp); |
50 generateState1(tg->stateList,0L,false,fp,tg); | 70 generateState1(tg->stateList,0L,false,fp,tg); |
51 for (state = tg->stateList;state;state = state->next) { | 71 for (state = tg->stateList;state;state = state->next) { |
52 if (state->bitState.bitContainer!=1) // state1 always unused but state0 | 72 if (state->bitState.bitContainer!=1) // state1 always unused but state0 |
53 generateState1(state,state->bitState.bitContainer,true,fp,tg); | 73 generateState1(state,state->bitState.bitContainer,true,fp,tg); |
54 } | 74 } |
75 checkBMSearch(tg->stateStart->cc); | |
76 tsv.current = generateTState(tg->stateStart,tg); | |
55 fclose(fp); | 77 fclose(fp); |
56 } | 78 } |
57 | 79 |
58 | 80 |