Mercurial > hg > Members > masakoha > testcode
changeset 225:0c28ff35b4f0
add generateSequentialSearch
author | Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp> |
---|---|
date | Fri, 15 Jan 2016 16:47:03 +0900 |
parents | 474fc9f844db |
children | b4022ba23de5 |
files | regexParser/generateSequentialSearch.cc regexParser/generateSequentialSearch.h regexParser/subsetConstruction.cc regexParser/subsetConstruction.h |
diffstat | 4 files changed, 66 insertions(+), 42 deletions(-) [+] |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/regexParser/generateSequentialSearch.cc Fri Jan 15 16:47:03 2016 +0900 @@ -0,0 +1,60 @@ +#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); +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/regexParser/generateSequentialSearch.h Fri Jan 15 16:47:03 2016 +0900 @@ -0,0 +1,3 @@ +#include "regexParser.h" + +extern void exportState(TransitionGeneratorPtr tg);
--- a/regexParser/subsetConstruction.cc Fri Jan 15 16:12:19 2016 +0900 +++ b/regexParser/subsetConstruction.cc Fri Jan 15 16:47:03 2016 +0900 @@ -314,48 +314,6 @@ return tgv; } -void exportState(TransitionGeneratorPtr tg) { - StatePtr state = tg->stateList; - FILE *fp = fopen("state.cc","w"); - char s[SIZE]; - fputs("unsigned char *buff, *buffptr, buffend;\n",fp); - for (;state;state = state->next) { - sprintf(s,"void state%lx() {\n",state->bitState.bitContainer); - fputs(s,fp); - 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) { - sprintf(s," if (c=='%c') state%lu();\n",(unsigned char)begin, bi.bitContainer); - fputs(s,fp); - } else { - sprintf(s," if (c<'%c') state1();\n",(unsigned char)begin); - fputs(s,fp); - sprintf(s," else if (c<='%c') state%lu();\n",(unsigned char)end, bi.bitContainer); - fputs(s,fp); - } - } - sprintf(s," else state1();\n"); - fputs(s,fp); - } - fputs("}\n\n",fp); - } - fclose(fp); -} - void printState(StatePtr state) { printf("state : %lx\n",state->bitState.bitContainer); long nodeNumber = 0;
--- a/regexParser/subsetConstruction.h Fri Jan 15 16:12:19 2016 +0900 +++ b/regexParser/subsetConstruction.h Fri Jan 15 16:47:03 2016 +0900 @@ -5,6 +5,9 @@ extern void setState(CharClassPtr cc, BitVector bi); extern StatePtr createState(TGValue tgv,NodePtr n); extern TGValue generateTransitionList(NodePtr n); +extern CharClassPtr getNext(CharClassWalkerPtr walk); +extern bool hasNext(CharClassWalkerPtr walk); +extern CharClassWalkerPtr createCharClassWalker (CharClassPtr next); extern void printState(TransitionGeneratorPtr tg); extern SCValue createSCValue(TGValue tgv) ; extern SCValue subsetConstruction(SCValue scv) ;