Mercurial > hg > Members > masakoha > testcode
annotate regexParser/transition.cc @ 177:8de9a33f6ae5 pairPro
change createState aug
author | Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp> |
---|---|
date | Wed, 23 Dec 2015 17:28:59 +0900 |
parents | c092dd0e1ae0 |
children | d97bcab546e8 |
rev | line source |
---|---|
116
66c633575b53
remove error and warning
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
112
diff
changeset
|
1 #include <stdlib.h> |
111 | 2 #include "transition.h" |
3 | |
176
c092dd0e1ae0
implement appendState() and serchState()
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
175
diff
changeset
|
4 StatePtr searchState(StatePtr stateArray, StatePtr state) { |
c092dd0e1ae0
implement appendState() and serchState()
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
175
diff
changeset
|
5 while(stateArray) { |
c092dd0e1ae0
implement appendState() and serchState()
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
175
diff
changeset
|
6 if (stateArray->bitState.bitContainer == state->bitState.bitContainer) { |
c092dd0e1ae0
implement appendState() and serchState()
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
175
diff
changeset
|
7 return stateArray; |
c092dd0e1ae0
implement appendState() and serchState()
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
175
diff
changeset
|
8 } |
c092dd0e1ae0
implement appendState() and serchState()
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
175
diff
changeset
|
9 if (stateArray->next == NULL) { |
177
8de9a33f6ae5
change createState aug
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
176
diff
changeset
|
10 StatePtr s = createState(state->bitState); |
176
c092dd0e1ae0
implement appendState() and serchState()
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
175
diff
changeset
|
11 stateArray = appendState(stateArray,s); |
c092dd0e1ae0
implement appendState() and serchState()
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
175
diff
changeset
|
12 return stateArray; |
c092dd0e1ae0
implement appendState() and serchState()
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
175
diff
changeset
|
13 } |
c092dd0e1ae0
implement appendState() and serchState()
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
175
diff
changeset
|
14 stateArray = stateArray->next; |
c092dd0e1ae0
implement appendState() and serchState()
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
175
diff
changeset
|
15 } |
c092dd0e1ae0
implement appendState() and serchState()
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
175
diff
changeset
|
16 return stateArray; |
c092dd0e1ae0
implement appendState() and serchState()
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
175
diff
changeset
|
17 } |
c092dd0e1ae0
implement appendState() and serchState()
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
175
diff
changeset
|
18 |
177
8de9a33f6ae5
change createState aug
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
176
diff
changeset
|
19 StatePtr createState(BitVector bi) { |
8de9a33f6ae5
change createState aug
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
176
diff
changeset
|
20 StatePtr state = NEW(State); |
175
3be0fbcd4b52
implement createTransitionGenerator
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
172
diff
changeset
|
21 state->bitState = bi; |
3be0fbcd4b52
implement createTransitionGenerator
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
172
diff
changeset
|
22 state->transition = NEW(Transition); |
3be0fbcd4b52
implement createTransitionGenerator
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
172
diff
changeset
|
23 state->nextNode = NEW(Node); |
177
8de9a33f6ae5
change createState aug
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
176
diff
changeset
|
24 return state; |
175
3be0fbcd4b52
implement createTransitionGenerator
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
172
diff
changeset
|
25 } |
3be0fbcd4b52
implement createTransitionGenerator
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
172
diff
changeset
|
26 |
176
c092dd0e1ae0
implement appendState() and serchState()
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
175
diff
changeset
|
27 StatePtr appendState(StatePtr x,StatePtr y) { |
177
8de9a33f6ae5
change createState aug
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
176
diff
changeset
|
28 StatePtr x0 = createState(x->bitState); |
176
c092dd0e1ae0
implement appendState() and serchState()
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
175
diff
changeset
|
29 StatePtr x1 = x0; |
c092dd0e1ae0
implement appendState() and serchState()
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
175
diff
changeset
|
30 for(;;) { |
c092dd0e1ae0
implement appendState() and serchState()
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
175
diff
changeset
|
31 if (x->next == NULL) { |
c092dd0e1ae0
implement appendState() and serchState()
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
175
diff
changeset
|
32 x1->next = y; |
c092dd0e1ae0
implement appendState() and serchState()
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
175
diff
changeset
|
33 return x0; |
c092dd0e1ae0
implement appendState() and serchState()
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
175
diff
changeset
|
34 } |
c092dd0e1ae0
implement appendState() and serchState()
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
175
diff
changeset
|
35 x = x->next; |
177
8de9a33f6ae5
change createState aug
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
176
diff
changeset
|
36 x1->next = createState(x->bitState); |
176
c092dd0e1ae0
implement appendState() and serchState()
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
175
diff
changeset
|
37 x1 = x1->next; |
c092dd0e1ae0
implement appendState() and serchState()
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
175
diff
changeset
|
38 } |
c092dd0e1ae0
implement appendState() and serchState()
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
175
diff
changeset
|
39 return x0; |
c092dd0e1ae0
implement appendState() and serchState()
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
175
diff
changeset
|
40 } |
c092dd0e1ae0
implement appendState() and serchState()
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
175
diff
changeset
|
41 |
111 | 42 TransitionPtr createTransition(CharClassPtr cc, BitVectorPtr state) { |
175
3be0fbcd4b52
implement createTransitionGenerator
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
172
diff
changeset
|
43 TransitionPtr transition = NEW(Transition); |
111 | 44 transition->condition = cc; |
172
540fc12871d9
remove some warnings and errors (not working)
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
167
diff
changeset
|
45 transition->condition->nextState = *state; |
111 | 46 return transition; |
47 } | |
48 | |
49 TransitionPtr appendTransition0(TransitionPtr x, TransitionPtr y) { | |
50 TransitionPtr x0 = x; | |
51 for(;;) { | |
52 if (x->next == NULL) { | |
116
66c633575b53
remove error and warning
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
112
diff
changeset
|
53 x->next = y; |
111 | 54 return x0; |
55 } | |
56 } | |
57 return x; | |
58 } | |
59 | |
60 TransitionPtr appendTransition(TransitionPtr x, TransitionPtr y) { | |
172
540fc12871d9
remove some warnings and errors (not working)
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
167
diff
changeset
|
61 TransitionPtr x0 = createTransition(x->condition, &x->condition->nextState); |
111 | 62 TransitionPtr x1 = x0; |
63 for(;;) { | |
64 if (x->next == NULL) { | |
65 x1->next = y; | |
66 return x0; | |
67 } | |
68 x = x->next; | |
172
540fc12871d9
remove some warnings and errors (not working)
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
167
diff
changeset
|
69 x1->next = createTransition(x->condition, &x->condition->nextState); |
111 | 70 x1 = x1->next; |
71 } | |
72 return x0; | |
73 } |