Mercurial > hg > Members > masakoha > testcode
view regexParser/generateSequentialSearch.cc @ 226:b4022ba23de5
add sequentialSearch
author | Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp> |
---|---|
date | Fri, 15 Jan 2016 17:53:11 +0900 |
parents | 0c28ff35b4f0 |
children | 8be58af605da |
line wrap: on
line source
#include <stdio.h> #include "generateSequentialSearch.h" #include "subsetConstruction.h" void exportState(TransitionGeneratorPtr tg) { StatePtr state = tg->stateList; FILE *fp = fopen("state.cc","w"); for (;state;state = state->next) { fprintf(fp,"void state%lx();\n",state->bitState.bitContainer); } fputs( "void stateSkip(BufferList buff) {\n" " buff.matchBegin = buff.buffptr;\n" " state1(buff);\n" "}\n" "\n" "void stateMatch(BufferList buff) {\n" " fwrite(buff.matchBegin,buff.buffptr-buff.matchBegin,1,stdout);\n" " puts(\"\\n\");\n" " stateSkip(buff);\n" "}\n" ,fp); fputs("\n",fp); for (state = tg->stateList;state;state = state->next) { fprintf(fp,"void state%lx(BufferList buff) {\n",state->bitState.bitContainer); if (state->bitState.bitContainer == 2) { // Accept fputs(" stateMatch(buff);\n",fp); } else { // not Accept fputs(" if (buff.buffptr >= buff.buffend) return;\n",fp); fputs(" unsigned char c = *buffptr++;\n",fp); CharClassWalkerPtr ccw = createCharClassWalker(state->cc); bool flag = true; 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 (flag) { flag = false; } else { fputs(" else ",fp); } if (begin == end) { fprintf(fp," if (c=='%c') state%lx(buff);\n",(unsigned char)begin, bi.bitContainer); } else { fprintf(fp," if (c<'%c') stateSkip(buff);\n",(unsigned char)begin); fprintf(fp," else if (c<='%c') state%lx(buff);\n",(unsigned char)end, bi.bitContainer); } } if (state->bitState.bitContainer == 2) { fprintf(fp," else stateMatch(buff);\n"); } else { fprintf(fp," else stateSkip(buff);\n"); } } fputs("}\n\n",fp); } fclose(fp); }