comparison 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
comparison
equal deleted inserted replaced
140:84a2a5209d3a 141:71f36a59cf6a
1 #include <stdlib.h> 1 #include <stdlib.h>
2 #include "transition.h" 2 #include "transition.h"
3
4 StatePtr createState(BitVectorPtr bi, TransitionPtr ts, StatePtr next) {
5 StatePtr s = (StatePtr)malloc(sizeof(State));
6 s->bitState = bi;
7 s->transition = ts;
8 s->next = next;
9 return s;
10 }
11
12 StatePtr appendState(StatePtr x, StatePtr y) {
13 if (x == NULL) {
14 x = createState(y->bitState,y->transition,y->next);
15 return x;
16 }
17
18 StatePtr x0 = createState(x->bitState, x->transition, x->next);
19 StatePtr x1 = x0;
20 for(;;) {
21 if (x->next == NULL) {
22 x1->next = y;
23 return x0;
24 }
25 x = x->next;
26 x1->next = createState(x->bitState, x->transition, x->next);
27 x1 = x1->next;
28 }
29 return x0;
30 }
3 31
4 TransitionPtr createTransition(CharClassPtr cc, BitVectorPtr state) { 32 TransitionPtr createTransition(CharClassPtr cc, BitVectorPtr state) {
5 TransitionPtr transition = (TransitionPtr)malloc(sizeof(Transition)); 33 TransitionPtr transition = (TransitionPtr)malloc(sizeof(Transition));
6 transition->condition = cc; 34 transition->condition = cc;
7 transition->nextState = state; 35 transition->nextState = state;