Mercurial > hg > Members > masakoha > testcode
view regexParser/generateSequentialSearch.cc @ 225:0c28ff35b4f0
add generateSequentialSearch
author | Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp> |
---|---|
date | Fri, 15 Jan 2016 16:47:03 +0900 |
parents | |
children | b4022ba23de5 |
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"); fputs("unsigned char *buff, *buffptr, buffend;\n",fp); fputs( "void stateSkip() {\n" " matchBegin = buffptr;\n" " state1();\n" "}\n" "\n" "void stateMatch() {\n" " fwrite(matchBegin,buffptr-matchBegin,1,fp);\n" " fputs(\"\\n\");\n" " stateSkip();\n" "}\n" ,fp); for (;state;state = state->next) { fprintf(fp,"void state%lx();\n",state->bitState.bitContainer); } fputs("\n",fp); for (;state;state = state->next) { fprintf(fp,"void state%lx() {\n",state->bitState.bitContainer); if (state->bitState.bitContainer == 2) { // Accept fputs(" // Accept\n",fp); } else { // not Accept 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%lu();\n",(unsigned char)begin, bi.bitContainer); } else { fprintf(fp," if (c<'%c') state1();\n",(unsigned char)begin); fprintf(fp," else if (c<='%c') state%lu();\n",(unsigned char)end, bi.bitContainer); } } if (state->bitState.bitContainer == 2) { fprintf(fp," else stateMatch();\n"); } else { fprintf(fp," else stateSkip();\n"); } } fputs("}\n\n",fp); } fclose(fp); }