Mercurial > hg > Applications > Grep
view regexParser/transition.cc @ 167:3bf2c6d6d53e pairPro
move regexparser dir
author | masa |
---|---|
date | Sat, 19 Dec 2015 15:38:45 +0900 |
parents | c/regexParser/transition.cc@71f36a59cf6a |
children | 540fc12871d9 |
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; }