Mercurial > hg > Members > masakoha > testcode
view regexParser/generateSequentialSearchCbC.cc @ 306:1e7f37b92d9a current
Removed tag help
author | Shinji KONO <kono@ie.u-ryukyu.ac.jp> |
---|---|
date | Mon, 08 Feb 2016 12:26:26 +0900 |
parents | 4cb6eea3ab12 |
children | 1d79e61a9365 |
line wrap: on
line source
#include <stdio.h> #include <stdlib.h> #include "generateSequentialSearch.h" #include "subsetConstruction.h" void generateState1(StatePtr state,long stateNum, bool accept, FILE *fp, TransitionGeneratorPtr tg) { fprintf(fp,"__code 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) _exit(0);\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') { goto state%lx(tsv);}\n",(unsigned char)begin, bi.bitContainer); } else { fprintf(fp," else if (c<'%c') { tsv=tsv.tg->stateSkip(tsv);goto state0(tsv);}\n",(unsigned char)begin); fprintf(fp," else if (c<='%c') { goto state%lx(tsv);} \n",(unsigned char)end, bi.bitContainer); } } free(ccw); fprintf(fp," else { tsv=tsv.tg->stateSkip(tsv); goto state0(tsv);}\n"); fputs("}\n\n",fp); } void exportState(TransitionGeneratorPtr tg) { StatePtr state = tg->stateList; FILE *fp = fopen("stateCbC.cc","w"); if (fp==NULL) { perror(""); fprintf(stderr,"cannot write stateCbC.cc\n"); exit(1); } for (;state;state = state->next) { fprintf(fp,"__code 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); }