Mercurial > hg > Applications > Grep
diff c/regexParser/transition.cc @ 141:71f36a59cf6a pairPro
add appendState
author | Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp> |
---|---|
date | Fri, 11 Dec 2015 13:12:42 +0900 |
parents | 84a2a5209d3a |
children |
line wrap: on
line diff
--- a/c/regexParser/transition.cc Wed Dec 09 19:57:22 2015 +0900 +++ b/c/regexParser/transition.cc Fri Dec 11 13:12:42 2015 +0900 @@ -1,6 +1,34 @@ #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;