Mercurial > hg > Applications > Grep
view regexParser/generateSequentialSearch.cc @ 308:1188debbef10
separate CharClass
author | Shinji KONO <kono@ie.u-ryukyu.ac.jp> |
---|---|
date | Mon, 08 Feb 2016 12:45:45 +0900 |
parents | 63213964502a |
children | c9ac6f06e706 |
line wrap: on
line source
#include <stdio.h> #include <stdlib.h> #include "generateSequentialSearch.h" #include "CharClass.h" #include "subsetConstruction.h" void generateState1(StatePtr state,long stateNum, bool accept, FILE *fp, TransitionGeneratorPtr tg) { fprintf(fp,"TSValue state%lx(TSValue tsv) {\n",stateNum); if (accept && state->accept) { fputs(" tsv=tsv.tg->stateMatch(tsv);\n",fp); } fputs(" if (tsv.buff.buffptr >= tsv.buff.buffend) return tsv;\n",fp); CharClassWalkerPtr ccw = createCharClassWalker(state->cc); if (hasNext(ccw)) fputs(" unsigned char c = *tsv.buff.buffptr++;\n",fp); fputs(" if (0) ;\n",fp); while (hasNext(ccw)) { CharClassPtr cc = getNext(ccw); unsigned long begin = cc->cond.range.begin; unsigned long end = cc->cond.range.end; BitVector bi = cc->nextState; if (begin == end) { fprintf(fp," else if (c=='%c') { return state%lx(tsv);}\n",(unsigned char)begin, bi.bitContainer); } else { fprintf(fp," else if (c<'%c') { tsv=tsv.tg->stateSkip(tsv);return state0(tsv);}\n",(unsigned char)begin); fprintf(fp," else if (c<='%c') { return state%lx(tsv);} \n",(unsigned char)end, bi.bitContainer); } } free(ccw); fprintf(fp," else { tsv=tsv.tg->stateSkip(tsv); return state0(tsv);}\n"); fputs("}\n\n",fp); } void exportState(TransitionGeneratorPtr tg) { StatePtr state = tg->stateList; FILE *fp = fopen("state.cc","w"); if (fp==NULL) { perror(""); fprintf(stderr,"cannot write state.cc\n"); exit(1); } for (;state;state = state->next) { fprintf(fp,"TSValue state%lx(TSValue tsv);\n",state->bitState.bitContainer); } fputs("\n",fp); // initial state must not accept empty string generateState1(tg->stateList,0L,false,fp,tg); for (state = tg->stateList;state;state = state->next) { generateState1(state,state->bitState.bitContainer,true,fp,tg); } fclose(fp); }