Mercurial > hg > Applications > Grep
comparison regexParser/generateSequentialSearch.cc @ 312:c9ac6f06e706
add loop
author | Shinji KONO <kono@ie.u-ryukyu.ac.jp> |
---|---|
date | Tue, 09 Feb 2016 10:59:22 +0900 |
parents | 1188debbef10 |
children | 879dc5d1cb6a |
comparison
equal
deleted
inserted
replaced
311:1d79e61a9365 | 312:c9ac6f06e706 |
---|---|
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 | 7 |
8 void | 8 static void |
9 generateState1(StatePtr state,long stateNum, bool accept, FILE *fp, TransitionGeneratorPtr tg) { | 9 generateState1(StatePtr state,long stateNum, bool accept, FILE *fp, TransitionGeneratorPtr tg) { |
10 fprintf(fp,"TSValue state%lx(TSValue tsv) {\n",stateNum); | 10 fprintf(fp,"static TSValue state%lx(TSValue tsv) {\n",stateNum); |
11 if (accept && state->accept) { | 11 if (accept && state->accept) { |
12 fputs(" tsv=tsv.tg->stateMatch(tsv);\n",fp); | 12 fputs(" tsv=tsv.tg->stateMatch(tsv);\n",fp); |
13 } | 13 } |
14 fputs(" if (tsv.buff.buffptr >= tsv.buff.buffend) return tsv;\n",fp); | 14 fputs(" if (tsv.buff.buffptr >= tsv.buff.buffend) return tsv;\n",fp); |
15 CharClassWalkerPtr ccw = createCharClassWalker(state->cc); | 15 CharClassWalkerPtr ccw = createCharClassWalker(state->cc); |
28 } | 28 } |
29 } | 29 } |
30 free(ccw); | 30 free(ccw); |
31 fprintf(fp," else { tsv=tsv.tg->stateSkip(tsv); return state0(tsv);}\n"); | 31 fprintf(fp," else { tsv=tsv.tg->stateSkip(tsv); return state0(tsv);}\n"); |
32 fputs("}\n\n",fp); | 32 fputs("}\n\n",fp); |
33 } | 33 } |
34 | 34 |
35 void | 35 void |
36 exportState(TransitionGeneratorPtr tg) { | 36 exportState(TransitionGeneratorPtr tg) { |
37 StatePtr state = tg->stateList; | 37 StatePtr state = tg->stateList; |
38 FILE *fp = fopen("state.cc","w"); | 38 FILE *fp = fopen("state.cc","w"); |
40 perror(""); | 40 perror(""); |
41 fprintf(stderr,"cannot write state.cc\n"); | 41 fprintf(stderr,"cannot write state.cc\n"); |
42 exit(1); | 42 exit(1); |
43 } | 43 } |
44 for (;state;state = state->next) { | 44 for (;state;state = state->next) { |
45 fprintf(fp,"TSValue state%lx(TSValue tsv);\n",state->bitState.bitContainer); | 45 if (state->bitState.bitContainer!=1) // state1 always unused but state0 |
46 fprintf(fp,"static TSValue state%lx(TSValue tsv);\n",state->bitState.bitContainer); | |
46 } | 47 } |
47 fputs("\n",fp); | 48 fputs("\n",fp); |
48 // initial state must not accept empty string | 49 // initial state must not accept empty string |
49 generateState1(tg->stateList,0L,false,fp,tg); | 50 generateState1(tg->stateList,0L,false,fp,tg); |
50 for (state = tg->stateList;state;state = state->next) { | 51 for (state = tg->stateList;state;state = state->next) { |
51 generateState1(state,state->bitState.bitContainer,true,fp,tg); | 52 if (state->bitState.bitContainer!=1) // state1 always unused but state0 |
53 generateState1(state,state->bitState.bitContainer,true,fp,tg); | |
52 } | 54 } |
53 fclose(fp); | 55 fclose(fp); |
54 } | 56 } |
57 | |
58 |