Mercurial > hg > Members > masakoha > testcode
changeset 175:3be0fbcd4b52 pairPro
implement createTransitionGenerator
author | Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp> |
---|---|
date | Tue, 22 Dec 2015 20:27:26 +0900 |
parents | b9e913030a47 |
children | c092dd0e1ae0 |
files | regexParser/regexParser.cc regexParser/regexParser.h regexParser/subsetConstraction.cc regexParser/subsetConstraction.h regexParser/transition.cc regexParser/transition.h |
diffstat | 6 files changed, 39 insertions(+), 5 deletions(-) [+] |
line wrap: on
line diff
--- a/regexParser/regexParser.cc Tue Dec 22 18:48:11 2015 +0900 +++ b/regexParser/regexParser.cc Tue Dec 22 20:27:26 2015 +0900 @@ -37,7 +37,7 @@ n->nodeNumber = ri->nodeNumber; ri->nodeNumber++; } else { - n->nodeNumber = 0; + n->nodeNumber = SYNTAX_NODENUMBER; } return n;
--- a/regexParser/regexParser.h Tue Dec 22 18:48:11 2015 +0900 +++ b/regexParser/regexParser.h Tue Dec 22 20:27:26 2015 +0900 @@ -1,6 +1,7 @@ #include "error.h" #define NEW(type) (type*)malloc(sizeof(type)) +#define SYNTAX_NODENUMBER 100 typedef struct bitVector { unsigned long bitContainer;
--- a/regexParser/subsetConstraction.cc Tue Dec 22 18:48:11 2015 +0900 +++ b/regexParser/subsetConstraction.cc Tue Dec 22 20:27:26 2015 +0900 @@ -200,7 +200,7 @@ return tgv2; } else if (n->tokenType == 'a'){ TGValue tgv; - tgv.ts = (TransitionPtr)malloc(sizeof(Transition)); + tgv.ts = NEW(Transition); tgv.ts->condition = n->cc; bitSet(&tgv.ts->condition->nextState,n->nodeNumber); tg.ts = appendTransition(tg.ts,tgv.ts); @@ -217,9 +217,25 @@ } } -TransitionGenerator generateTransitionList(NodePtr n) { +TransitionGenerator createTransitionGenerator() { TransitionGenerator tg; tg.ts = NEW(Transition); + tg.state = NEW(State); + tg.transitionList = NEW(Transition); + BitVectorPtr initStateBi = NEW(BitVector); + bitSet(initStateBi,INIT_STATE_BIT); + tg.stateArray = createState(tg.stateArray,*initStateBi); + BitVectorPtr lastStateBi = NEW(BitVector); + bitSet(lastStateBi,END_STATE_BIT); + tg.stateArray = createState(tg.stateArray,*lastStateBi); + tg.stateArrayLast = NEW(State); + tg.currentState = NEW(State); + tg.nextState = NEW(State); + return tg; +} + +TransitionGenerator generateTransitionList(NodePtr n) { + TransitionGenerator tg = createTransitionGenerator(); generateTransition(n,tg); printTransitionList(tg.ts); return tg;
--- a/regexParser/subsetConstraction.h Tue Dec 22 18:48:11 2015 +0900 +++ b/regexParser/subsetConstraction.h Tue Dec 22 20:27:26 2015 +0900 @@ -1,5 +1,6 @@ #include "transition.h" - +#define INIT_STATE_BIT 0 +#define END_STATE_BIT 63 typedef struct stateStack { BitVector state; struct stateStack *next;
--- a/regexParser/transition.cc Tue Dec 22 18:48:11 2015 +0900 +++ b/regexParser/transition.cc Tue Dec 22 20:27:26 2015 +0900 @@ -1,8 +1,22 @@ #include <stdlib.h> #include "transition.h" +StatePtr createState(StatePtr state,BitVector bi) { + StatePtr s = state; + if (state != NULL) { + while (state->next) { + state = state->next; + } + } + state = NEW(State); + state->bitState = bi; + state->transition = NEW(Transition); + state->nextNode = NEW(Node); + return s; +} + TransitionPtr createTransition(CharClassPtr cc, BitVectorPtr state) { - TransitionPtr transition = (TransitionPtr)malloc(sizeof(Transition)); + TransitionPtr transition = NEW(Transition); transition->condition = cc; transition->condition->nextState = *state; return transition;
--- a/regexParser/transition.h Tue Dec 22 18:48:11 2015 +0900 +++ b/regexParser/transition.h Tue Dec 22 20:27:26 2015 +0900 @@ -6,11 +6,13 @@ } Transition, *TransitionPtr; typedef struct state { + BitVector bitState; TransitionPtr transition; NodePtr nextNode; struct state *next; } State, *StatePtr; +StatePtr createState(StatePtr state,BitVector bi); TransitionPtr createTransition(CharClassPtr cc, BitVectorPtr state); TransitionPtr appendTransition0(TransitionPtr curr,TransitionPtr next); TransitionPtr appendTransition(TransitionPtr curr,TransitionPtr next);