Mercurial > hg > Applications > Grep
comparison regexParser/subsetConstruction.cc @ 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 | 4dc8d327cc7d |
children | e430b7d0b33d |
comparison
equal
deleted
inserted
replaced
221:78174ff2f338 | 222:c38a7b2dd996 |
---|---|
5 #include "regexParser.h" | 5 #include "regexParser.h" |
6 #include "subsetConstruction.h" | 6 #include "subsetConstruction.h" |
7 #include "node.h" | 7 #include "node.h" |
8 #include "BitVector.h" | 8 #include "BitVector.h" |
9 #include "error.h" | 9 #include "error.h" |
10 | |
11 #define SIZE 256 | |
10 | 12 |
11 CharClassPtr createCharClassRange(unsigned long begin, unsigned long end,unsigned long state, CharClassPtr left, CharClassPtr right) { | 13 CharClassPtr createCharClassRange(unsigned long begin, unsigned long end,unsigned long state, CharClassPtr left, CharClassPtr right) { |
12 CharClassPtr cc = NEW(CharClass); | 14 CharClassPtr cc = NEW(CharClass); |
13 cc->type = 'r'; | 15 cc->type = 'r'; |
14 cc->cond.range.begin = begin; | 16 cc->cond.range.begin = begin; |
308 tgv.tg->stateArray[endState->bitState.bitContainer] = endState; | 310 tgv.tg->stateArray[endState->bitState.bitContainer] = endState; |
309 tgv.startState = startState; | 311 tgv.startState = startState; |
310 tgv.endState = endState; | 312 tgv.endState = endState; |
311 tgv = generateTransition(n,tgv,2); | 313 tgv = generateTransition(n,tgv,2); |
312 return tgv; | 314 return tgv; |
315 } | |
316 | |
317 void exportState(TransitionGeneratorPtr tg) { | |
318 StatePtr state = tg->stateList; | |
319 FILE *fp = fopen("state.cc","w"); | |
320 char s[SIZE]; | |
321 | |
322 fputs("unsigned char *buff, *buffptr, buffend;\n",fp); | |
323 for (;state;state = state->next) { | |
324 sprintf(s,"void state%lx() {\n",state->bitState.bitContainer); | |
325 fputs(s,fp); | |
326 if (state->cc->cond.range.begin == state->cc->cond.range.end) { | |
327 if (state->cc) { // not Accept | |
328 fputs(" unsigned char c = *buffptr++;\n",fp); | |
329 sprintf(s," if (c='%c') state%lu();\n",(unsigned char)state->cc->cond.range.begin, state->cc->nextState.bitContainer); | |
330 fputs(s,fp); | |
331 } else { // Accept | |
332 fputs(" // Accept\n",fp); | |
333 } | |
334 } else { | |
335 if (state->cc) { // not Accept | |
336 fputs(" unsigned char c = *buffptr++;\n",fp); | |
337 sprintf(s," if (c<'%c') state%lu();\n",(unsigned char)state->cc->cond.range.begin, state->cc->nextState.bitContainer); | |
338 fputs(s,fp); | |
339 sprintf(s," if (c<'%c') state%lu();\n",(unsigned char)state->cc->cond.range.end, state->cc->nextState.bitContainer); | |
340 fputs(s,fp); | |
341 } else { // Accept | |
342 fputs(" // Accept\n",fp); | |
343 } | |
344 } | |
345 fputs("}\n",fp); | |
346 } | |
347 fclose(fp); | |
313 } | 348 } |
314 | 349 |
315 void printState(StatePtr state) { | 350 void printState(StatePtr state) { |
316 printf("state : %lx\n",state->bitState.bitContainer); | 351 printf("state : %lx\n",state->bitState.bitContainer); |
317 long nodeNumber = 0; | 352 long nodeNumber = 0; |