Mercurial > hg > Members > masakoha > testcode
changeset 222:c38a7b2dd996
implement exportState function (not correct working)
author | Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp> |
---|---|
date | Thu, 14 Jan 2016 21:46:35 +0900 |
parents | 78174ff2f338 |
children | e430b7d0b33d |
files | regexParser/Makefile regexParser/main.cc regexParser/subsetConstruction.cc regexParser/subsetConstruction.h |
diffstat | 4 files changed, 39 insertions(+), 2 deletions(-) [+] |
line wrap: on
line diff
--- a/regexParser/Makefile Sat Jan 02 15:34:37 2016 +0900 +++ b/regexParser/Makefile Thu Jan 14 21:46:35 2016 +0900 @@ -29,7 +29,7 @@ clean: rm -f $(TARGET) $(OBJS) - rm -f *~ \#* *.gcda *.gcno *.gcov + rm -f *~ \#* *.gcda *.gcno *.gcov state.cc .SUFFIXES: .cc .o
--- a/regexParser/main.cc Sat Jan 02 15:34:37 2016 +0900 +++ b/regexParser/main.cc Thu Jan 14 21:46:35 2016 +0900 @@ -31,12 +31,13 @@ TGValue tgv = generateTransitionList(n); printTree(n); printState(tgv.tg); + exportState(tgv.tg); } else if (subset) { TGValue tgv = generateTransitionList(n); SCValue scv = createSCValue(tgv); subsetConstruction(scv); // Determinization printState(tgv.tg); + exportState(tgv.tg); } - return 0; }
--- a/regexParser/subsetConstruction.cc Sat Jan 02 15:34:37 2016 +0900 +++ b/regexParser/subsetConstruction.cc Thu Jan 14 21:46:35 2016 +0900 @@ -8,6 +8,8 @@ #include "BitVector.h" #include "error.h" +#define SIZE 256 + CharClassPtr createCharClassRange(unsigned long begin, unsigned long end,unsigned long state, CharClassPtr left, CharClassPtr right) { CharClassPtr cc = NEW(CharClass); cc->type = 'r'; @@ -312,6 +314,39 @@ 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->cc->cond.range.begin == state->cc->cond.range.end) { + if (state->cc) { // not Accept + fputs(" unsigned char c = *buffptr++;\n",fp); + sprintf(s," if (c='%c') state%lu();\n",(unsigned char)state->cc->cond.range.begin, state->cc->nextState.bitContainer); + fputs(s,fp); + } else { // Accept + fputs(" // Accept\n",fp); + } + } else { + if (state->cc) { // not Accept + fputs(" unsigned char c = *buffptr++;\n",fp); + sprintf(s," if (c<'%c') state%lu();\n",(unsigned char)state->cc->cond.range.begin, state->cc->nextState.bitContainer); + fputs(s,fp); + sprintf(s," if (c<'%c') state%lu();\n",(unsigned char)state->cc->cond.range.end, state->cc->nextState.bitContainer); + fputs(s,fp); + } else { // Accept + fputs(" // Accept\n",fp); + } + } + fputs("}\n",fp); + } + fclose(fp); +} + void printState(StatePtr state) { printf("state : %lx\n",state->bitState.bitContainer); long nodeNumber = 0;
--- a/regexParser/subsetConstruction.h Sat Jan 02 15:34:37 2016 +0900 +++ b/regexParser/subsetConstruction.h Thu Jan 14 21:46:35 2016 +0900 @@ -1,6 +1,7 @@ extern CharClassPtr charClassMerge(CharClassPtr cc,unsigned long begin, unsigned long end, BitVector nextState); extern TGValue createTGValue(); extern CharClassPtr mergeTransition(StatePtr x,CharClassPtr y); +extern void exportState(TransitionGeneratorPtr tg); extern void setState(CharClassPtr cc, BitVector bi); extern StatePtr createState(TGValue tgv,NodePtr n); extern TGValue generateTransitionList(NodePtr n);