Mercurial > hg > Members > masakoha > testcode
view regexParser/transition.cc @ 176:c092dd0e1ae0 pairPro
implement appendState() and serchState()
author | Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp> |
---|---|
date | Wed, 23 Dec 2015 15:41:27 +0900 |
parents | 3be0fbcd4b52 |
children | 8de9a33f6ae5 |
line wrap: on
line source
#include <stdlib.h> #include "transition.h" StatePtr searchState(StatePtr stateArray, StatePtr state) { while(stateArray) { if (stateArray->bitState.bitContainer == state->bitState.bitContainer) { return stateArray; } if (stateArray->next == NULL) { StatePtr s = createState(state,state->bitState); stateArray = appendState(stateArray,s); return stateArray; } stateArray = stateArray->next; } return stateArray; } StatePtr createState(StatePtr state,BitVector bi) { StatePtr s = state; state = NEW(State); state->bitState = bi; state->transition = NEW(Transition); state->nextNode = NEW(Node); return s; } StatePtr appendState(StatePtr x,StatePtr y) { StatePtr x0 = createState(x,x->bitState); StatePtr x1 = x0; for(;;) { if (x->next == NULL) { x1->next = y; return x0; } x = x->next; x1->next = createState(x,x->bitState); x1 = x1->next; } return x0; } TransitionPtr createTransition(CharClassPtr cc, BitVectorPtr state) { TransitionPtr transition = NEW(Transition); transition->condition = cc; transition->condition->nextState = *state; return transition; } TransitionPtr appendTransition0(TransitionPtr x, TransitionPtr y) { TransitionPtr x0 = x; for(;;) { if (x->next == NULL) { x->next = y; return x0; } } return x; } TransitionPtr appendTransition(TransitionPtr x, TransitionPtr y) { TransitionPtr x0 = createTransition(x->condition, &x->condition->nextState); TransitionPtr x1 = x0; for(;;) { if (x->next == NULL) { x1->next = y; return x0; } x = x->next; x1->next = createTransition(x->condition, &x->condition->nextState); x1 = x1->next; } return x0; }