Mercurial > hg > Applications > Grep
comparison regexParser/generateSequentialSearchCbC.cc @ 301:4cb6eea3ab12
add CbC version
author | Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp> |
---|---|
date | Thu, 04 Feb 2016 03:26:18 +0900 |
parents | |
children | 1d79e61a9365 |
comparison
equal
deleted
inserted
replaced
300:3e78631a6222 | 301:4cb6eea3ab12 |
---|---|
1 #include <stdio.h> | |
2 #include <stdlib.h> | |
3 | |
4 #include "generateSequentialSearch.h" | |
5 #include "subsetConstruction.h" | |
6 | |
7 void | |
8 generateState1(StatePtr state,long stateNum, bool accept, FILE *fp, TransitionGeneratorPtr tg) { | |
9 fprintf(fp,"__code state%lx(TSValue tsv) {\n",stateNum); | |
10 if (accept && state->accept) { | |
11 fputs(" tsv=tsv.tg->stateMatch(tsv);\n",fp); | |
12 } | |
13 fputs(" if (tsv.buff.buffptr >= tsv.buff.buffend) _exit(0);\n",fp); | |
14 CharClassWalkerPtr ccw = createCharClassWalker(state->cc); | |
15 if (hasNext(ccw)) fputs(" unsigned char c = *tsv.buff.buffptr++;\n",fp); | |
16 fputs(" if (0) ;\n",fp); | |
17 while (hasNext(ccw)) { | |
18 CharClassPtr cc = getNext(ccw); | |
19 unsigned long begin = cc->cond.range.begin; | |
20 unsigned long end = cc->cond.range.end; | |
21 BitVector bi = cc->nextState; | |
22 if (begin == end) { | |
23 fprintf(fp," else if (c=='%c') { goto state%lx(tsv);}\n",(unsigned char)begin, bi.bitContainer); | |
24 } else { | |
25 fprintf(fp," else if (c<'%c') { tsv=tsv.tg->stateSkip(tsv);goto state0(tsv);}\n",(unsigned char)begin); | |
26 fprintf(fp," else if (c<='%c') { goto state%lx(tsv);} \n",(unsigned char)end, bi.bitContainer); | |
27 } | |
28 } | |
29 free(ccw); | |
30 fprintf(fp," else { tsv=tsv.tg->stateSkip(tsv); goto state0(tsv);}\n"); | |
31 fputs("}\n\n",fp); | |
32 } | |
33 | |
34 void | |
35 exportState(TransitionGeneratorPtr tg) { | |
36 StatePtr state = tg->stateList; | |
37 FILE *fp = fopen("stateCbC.cc","w"); | |
38 if (fp==NULL) { | |
39 perror(""); | |
40 fprintf(stderr,"cannot write stateCbC.cc\n"); | |
41 exit(1); | |
42 } | |
43 for (;state;state = state->next) { | |
44 fprintf(fp,"__code state%lx(TSValue tsv);\n",state->bitState.bitContainer); | |
45 } | |
46 fputs("\n",fp); | |
47 // initial state must not accept empty string | |
48 generateState1(tg->stateList,0L,false,fp,tg); | |
49 for (state = tg->stateList;state;state = state->next) { | |
50 generateState1(state,state->bitState.bitContainer,true,fp,tg); | |
51 } | |
52 fclose(fp); | |
53 } |