Mercurial > hg > Applications > Grep
view c/regexParser/transition.cc @ 162:d7f762404113 pairPro
add TestCode
author | masa |
---|---|
date | Fri, 18 Dec 2015 19:31:13 +0900 |
parents | 71f36a59cf6a |
children |
line wrap: on
line source
#include <stdlib.h> #include "transition.h" StatePtr createState(BitVectorPtr bi, TransitionPtr ts, StatePtr next) { StatePtr s = (StatePtr)malloc(sizeof(State)); s->bitState = bi; s->transition = ts; s->next = next; return s; } StatePtr appendState(StatePtr x, StatePtr y) { if (x == NULL) { x = createState(y->bitState,y->transition,y->next); return x; } StatePtr x0 = createState(x->bitState, x->transition, x->next); StatePtr x1 = x0; for(;;) { if (x->next == NULL) { x1->next = y; return x0; } x = x->next; x1->next = createState(x->bitState, x->transition, x->next); x1 = x1->next; } return x0; } TransitionPtr createTransition(CharClassPtr cc, BitVectorPtr state) { TransitionPtr transition = (TransitionPtr)malloc(sizeof(Transition)); transition->condition = cc; transition->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->nextState); TransitionPtr x1 = x0; for(;;) { if (x->next == NULL) { x1->next = y; return x0; } x = x->next; x1->next = createTransition(x->condition, x->nextState); x1 = x1->next; } return x0; }