Mercurial > hg > Members > masakoha > testcode
changeset 234:df4d04b3c34a
implement grepWalk (not confirm correct working)
author | Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp> |
---|---|
date | Tue, 19 Jan 2016 14:52:33 +0900 |
parents | 6d0a0126ddda |
children | 4aab1e93a971 |
files | regexParser/grepWalk.cc |
diffstat | 1 files changed, 43 insertions(+), 1 deletions(-) [+] |
line wrap: on
line diff
--- a/regexParser/grepWalk.cc Tue Jan 19 13:19:05 2016 +0900 +++ b/regexParser/grepWalk.cc Tue Jan 19 14:52:33 2016 +0900 @@ -1,7 +1,49 @@ #include <stdio.h> #include "grepWalk.h" +#include "subsetConstruction.h" + +void grepMatch(TransitionGeneratorPtr tg,Buffer buff); +void grep(TransitionGeneratorPtr tg,Buffer buff); +void grepSkip(TransitionGeneratorPtr tg,Buffer buff); + +void grepMatch(TransitionGeneratorPtr tg,Buffer buff) { + fwrite(buff.matchBegin,buff.buffptr-buff.matchBegin,1,stdout); + puts("\n"); + grepSkip(tg,buff); +} + +void grep(TransitionGeneratorPtr tg,Buffer buff,unsigned long d) { + unsigned char c = *buff.buffptr++; + StatePtr state = tg->stateList; + bool found = false; + + while (state->bitState.bitContainer != d) state = state->next; + CharClassWalkerPtr ccw = createCharClassWalker(state->cc); + CharClassPtr cc = NULL; + while (hasNext(ccw)) { + cc = getNext(ccw); + unsigned long begin = cc->cond.range.begin; + unsigned long end = cc->cond.range.end; + if (c < begin) found = false; + else if (c < end) found = true; + if (found == true) break; + } + + if (found == false) { + grepSkip(tg,buff); + } else if (found == true && (cc->nextState.bitContainer == 2)) { // Accept + grepMatch(tg,buff); + } else { + grep(tg,buff,cc->nextState.bitContainer); + } +} + +void grepSkip(TransitionGeneratorPtr tg,Buffer buff) { + buff.matchBegin = buff.buffptr; + grep(tg,buff,1); // 1 is initState +} void grepWalk(TransitionGeneratorPtr tg, Buffer buff) { - + grepSkip(tg,buff); }