Mercurial > hg > Applications > Grep
annotate regexParser/subsetConstraction.cc @ 214:a94f57af1600
remove allocateCCstate createCCState
author | Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp> |
---|---|
date | Mon, 28 Dec 2015 20:32:36 +0900 |
parents | 11b6332f0a42 |
children | 63e9224c7b2b |
rev | line source |
---|---|
96
b807383bcc43
add createBitVectorList.cc
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
1 #include <stdio.h> |
b807383bcc43
add createBitVectorList.cc
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
2 #include <stdlib.h> |
101 | 3 #include <ctype.h> |
191
02031fb73af8
remove somefiles and fix header files
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
190
diff
changeset
|
4 |
02031fb73af8
remove somefiles and fix header files
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
190
diff
changeset
|
5 #include "regexParser.h" |
117
166136236891
add header files
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
116
diff
changeset
|
6 #include "subsetConstraction.h" |
190
3e8e5780ad4a
change node::State to State
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
189
diff
changeset
|
7 #include "node.h" |
191
02031fb73af8
remove somefiles and fix header files
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
190
diff
changeset
|
8 #include "BitVector.h" |
192
ecf70fb215a5
print charclass
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
191
diff
changeset
|
9 #include "error.h" |
168
6b31d6ef9ba4
impl createCharClassRange()
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
167
diff
changeset
|
10 |
6b31d6ef9ba4
impl createCharClassRange()
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
167
diff
changeset
|
11 CharClassPtr createCharClassRange(unsigned long begin, unsigned long end,unsigned long state, CharClassPtr left, CharClassPtr right) { |
6b31d6ef9ba4
impl createCharClassRange()
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
167
diff
changeset
|
12 CharClassPtr cc = NEW(CharClass); |
6b31d6ef9ba4
impl createCharClassRange()
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
167
diff
changeset
|
13 cc->type = 'r'; |
6b31d6ef9ba4
impl createCharClassRange()
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
167
diff
changeset
|
14 cc->cond.range.begin = begin; |
6b31d6ef9ba4
impl createCharClassRange()
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
167
diff
changeset
|
15 cc->cond.range.end = end; |
192
ecf70fb215a5
print charclass
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
191
diff
changeset
|
16 cc->cond.range.next = NULL; |
168
6b31d6ef9ba4
impl createCharClassRange()
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
167
diff
changeset
|
17 cc->left = left; |
6b31d6ef9ba4
impl createCharClassRange()
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
167
diff
changeset
|
18 cc->right = right; |
6b31d6ef9ba4
impl createCharClassRange()
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
167
diff
changeset
|
19 cc->nextState.bitContainer = state; |
6b31d6ef9ba4
impl createCharClassRange()
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
167
diff
changeset
|
20 return cc; |
144
d8a4922eceae
remove some errors (not working)
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
143
diff
changeset
|
21 } |
d8a4922eceae
remove some errors (not working)
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
143
diff
changeset
|
22 |
166
96854eba17e5
implement mergeCCTree()
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
163
diff
changeset
|
23 CharClassPtr mergeCCTree(CharClassPtr cc,unsigned char mBegin,unsigned char mEnd,BitVector nextState) { |
96854eba17e5
implement mergeCCTree()
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
163
diff
changeset
|
24 CharClassPtr cc1; |
96854eba17e5
implement mergeCCTree()
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
163
diff
changeset
|
25 if (cc) { |
96854eba17e5
implement mergeCCTree()
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
163
diff
changeset
|
26 cc1 = charClassMerge(cc,mBegin,mEnd,nextState); |
96854eba17e5
implement mergeCCTree()
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
163
diff
changeset
|
27 } else { |
168
6b31d6ef9ba4
impl createCharClassRange()
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
167
diff
changeset
|
28 cc1 = createCharClassRange(mBegin,mEnd,nextState.bitContainer,NULL,NULL); |
166
96854eba17e5
implement mergeCCTree()
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
163
diff
changeset
|
29 } |
96854eba17e5
implement mergeCCTree()
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
163
diff
changeset
|
30 return cc1; |
96854eba17e5
implement mergeCCTree()
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
163
diff
changeset
|
31 } |
96854eba17e5
implement mergeCCTree()
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
163
diff
changeset
|
32 |
152 | 33 CharClassPtr charClassMerge(CharClassPtr cc,unsigned long begin, unsigned long end, BitVector nextState) { |
143 | 34 // 重なっているccの領域を分割する |
35 // 必要ならばnextStateを重ねあわせる | |
36 // 変更があった場合は新しくリストを作って返す | |
152 | 37 if (end < cc->cond.range.begin ) { // 1 |
38 if (cc->left) { | |
188
109d22faf7b5
remove errors and warnings
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
187
diff
changeset
|
39 return createCharClassRange(cc->cond.range.begin,cc->cond.range.end,nextState.bitContainer,charClassMerge(cc->left,begin,end,nextState),cc->right); |
152 | 40 } else { |
168
6b31d6ef9ba4
impl createCharClassRange()
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
167
diff
changeset
|
41 return createCharClassRange(begin,end,nextState.bitContainer,NULL,cc); |
152 | 42 } |
163 | 43 } else if (end == cc->cond.range.begin && begin != end ) { // 2 |
166
96854eba17e5
implement mergeCCTree()
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
163
diff
changeset
|
44 CharClassPtr cc1 = mergeCCTree(cc->left,begin,end-1,nextState); |
156
b5ecfc008bcf
impl charClassMerge(not working)
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
155
diff
changeset
|
45 if (cc->cond.range.begin == cc->cond.range.end) { |
168
6b31d6ef9ba4
impl createCharClassRange()
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
167
diff
changeset
|
46 return createCharClassRange(cc->cond.range.begin,cc->cond.range.end, |
6b31d6ef9ba4
impl createCharClassRange()
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
167
diff
changeset
|
47 cc->nextState.bitContainer | nextState.bitContainer, cc1,cc->right); |
155 | 48 } |
168
6b31d6ef9ba4
impl createCharClassRange()
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
167
diff
changeset
|
49 CharClassPtr cc3 = createCharClassRange(cc->cond.range.begin+1,cc->cond.range.end,cc->nextState.bitContainer,cc->left,cc->right); |
6b31d6ef9ba4
impl createCharClassRange()
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
167
diff
changeset
|
50 return createCharClassRange(cc->cond.range.begin,cc->cond.range.begin, |
6b31d6ef9ba4
impl createCharClassRange()
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
167
diff
changeset
|
51 cc->nextState.bitContainer | nextState.bitContainer,cc1,cc3); |
163 | 52 } else if (end < cc->cond.range.end) { // range.begin < end |
155 | 53 if (begin < cc->cond.range.begin) { // 3 |
166
96854eba17e5
implement mergeCCTree()
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
163
diff
changeset
|
54 CharClassPtr cc1 = mergeCCTree(cc->left,begin,cc->cond.range.begin-1,nextState); |
168
6b31d6ef9ba4
impl createCharClassRange()
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
167
diff
changeset
|
55 CharClassPtr cc3 = createCharClassRange(end+1,cc->cond.range.end,cc->nextState.bitContainer,cc->left,cc->right); |
6b31d6ef9ba4
impl createCharClassRange()
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
167
diff
changeset
|
56 return createCharClassRange(cc->cond.range.begin,end,cc->nextState.bitContainer | nextState.bitContainer,cc1,cc3); |
152 | 57 } |
155 | 58 if (begin == cc->cond.range.begin) { // 6 |
168
6b31d6ef9ba4
impl createCharClassRange()
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
167
diff
changeset
|
59 CharClassPtr cc2 = createCharClassRange(end+1,cc->cond.range.end,cc->nextState.bitContainer,NULL,cc->right); |
6b31d6ef9ba4
impl createCharClassRange()
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
167
diff
changeset
|
60 return createCharClassRange(begin,end,cc->nextState.bitContainer | nextState.bitContainer,cc->left,cc2); |
155 | 61 } |
62 // 9 | |
168
6b31d6ef9ba4
impl createCharClassRange()
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
167
diff
changeset
|
63 CharClassPtr cc2 = createCharClassRange(cc->cond.range.begin,begin-1,cc->nextState.bitContainer,cc->left,NULL); |
6b31d6ef9ba4
impl createCharClassRange()
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
167
diff
changeset
|
64 CharClassPtr cc3 = createCharClassRange(end+1,cc->cond.range.end,cc->nextState.bitContainer,NULL,cc->right); |
6b31d6ef9ba4
impl createCharClassRange()
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
167
diff
changeset
|
65 return createCharClassRange(begin,end,cc->nextState.bitContainer | nextState.bitContainer,cc2,cc3); |
155 | 66 } else if (end == cc->cond.range.end) { |
67 if (begin == cc->cond.range.begin) { // 7 | |
168
6b31d6ef9ba4
impl createCharClassRange()
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
167
diff
changeset
|
68 return createCharClassRange(begin,end,cc->nextState.bitContainer | nextState.bitContainer,cc->left,cc->right); |
155 | 69 } else if (begin < cc->cond.range.begin) { // 4 |
166
96854eba17e5
implement mergeCCTree()
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
163
diff
changeset
|
70 CharClassPtr cc1 = mergeCCTree(cc->left,begin,cc->cond.range.begin-1,nextState); |
168
6b31d6ef9ba4
impl createCharClassRange()
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
167
diff
changeset
|
71 return createCharClassRange(cc->cond.range.begin,end,cc->nextState.bitContainer | nextState.bitContainer,cc1,cc->right); |
155 | 72 } |
163 | 73 // 10 cond.range.begin < begin |
168
6b31d6ef9ba4
impl createCharClassRange()
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
167
diff
changeset
|
74 CharClassPtr cc2 = createCharClassRange(begin,cc->cond.range.end,cc->nextState.bitContainer | nextState.bitContainer,NULL,cc->right); |
6b31d6ef9ba4
impl createCharClassRange()
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
167
diff
changeset
|
75 return createCharClassRange(cc->cond.range.begin,begin-1,cc->nextState.bitContainer,cc->left,cc2); |
143 | 76 } |
155 | 77 if (begin > cc->cond.range.end ) { // 13 |
78 if (cc->right) { | |
188
109d22faf7b5
remove errors and warnings
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
187
diff
changeset
|
79 return createCharClassRange(cc->cond.range.begin,cc->cond.range.end,nextState.bitContainer,cc->left,charClassMerge(cc->right,begin,end,nextState)); |
155 | 80 } else { |
168
6b31d6ef9ba4
impl createCharClassRange()
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
167
diff
changeset
|
81 return createCharClassRange(begin,end,nextState.bitContainer,cc,NULL); |
155 | 82 } |
152 | 83 } |
155 | 84 if (begin >= cc->cond.range.begin && begin <= cc->cond.range.end) { |
163 | 85 if (end > cc->cond.range.end) { // cond.range.end < end |
155 | 86 if (begin == cc->cond.range.begin) { // 8 |
166
96854eba17e5
implement mergeCCTree()
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
163
diff
changeset
|
87 CharClassPtr cc1 = mergeCCTree(cc->right,cc->cond.range.end+1,end,nextState); |
168
6b31d6ef9ba4
impl createCharClassRange()
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
167
diff
changeset
|
88 return createCharClassRange(cc->cond.range.begin,cc->cond.range.end, |
6b31d6ef9ba4
impl createCharClassRange()
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
167
diff
changeset
|
89 cc->nextState.bitContainer | nextState.bitContainer,cc->left,cc1); |
155 | 90 } |
211
bc596e357a52
delete conditional branch in charClassMerge() (pattern 12)
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
209
diff
changeset
|
91 if (begin > cc->cond.range.begin) { // 11,12 |
166
96854eba17e5
implement mergeCCTree()
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
163
diff
changeset
|
92 CharClassPtr cc1 = mergeCCTree(cc->right,cc->cond.range.end+1,end,nextState); |
168
6b31d6ef9ba4
impl createCharClassRange()
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
167
diff
changeset
|
93 CharClassPtr cc3 = createCharClassRange(cc->cond.range.begin,begin-1,cc->nextState.bitContainer,cc->left,NULL); |
6b31d6ef9ba4
impl createCharClassRange()
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
167
diff
changeset
|
94 return createCharClassRange(begin,cc->cond.range.end,cc->nextState.bitContainer | nextState.bitContainer,cc3,cc1); |
156
b5ecfc008bcf
impl charClassMerge(not working)
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
155
diff
changeset
|
95 } |
155 | 96 } |
156
b5ecfc008bcf
impl charClassMerge(not working)
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
155
diff
changeset
|
97 } else if (begin < cc->cond.range.begin) { // 5 |
166
96854eba17e5
implement mergeCCTree()
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
163
diff
changeset
|
98 CharClassPtr cc1 = mergeCCTree(cc->left,begin,cc->cond.range.begin-1,nextState); |
96854eba17e5
implement mergeCCTree()
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
163
diff
changeset
|
99 CharClassPtr cc3 = mergeCCTree(cc->right,cc->cond.range.end+1,end,nextState); |
168
6b31d6ef9ba4
impl createCharClassRange()
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
167
diff
changeset
|
100 return createCharClassRange(cc->cond.range.begin,cc->cond.range.end,cc->nextState.bitContainer | nextState.bitContainer,cc1,cc3); |
152 | 101 } else { |
102 printf("charClassMerge Error : begin %lu end %lu cc->begin %lu cc->end %lu\n", begin,end,cc->cond.range.begin,cc->cond.range.end); | |
103 } | |
104 return cc; | |
143 | 105 } |
106 | |
181
3c4db09b8581
change return value findLeftMost()
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
180
diff
changeset
|
107 void findLeftMost(CharClassPtr next,CharClassWalkerPtr walk) { |
169
313f1c176328
implement mergeTransition
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
168
diff
changeset
|
108 while (next->left) { |
171
684363c44d6f
remove some warning and error (not working)
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
170
diff
changeset
|
109 CharClassStackPtr ccs = NEW(CharClassStack); |
180
d97bcab546e8
implement getNext
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
178
diff
changeset
|
110 ccs->next = walk->stack; |
201
b8bc24abaf8a
add TODO and fix CharClassWalker
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
198
diff
changeset
|
111 ccs->turn = walk->turn; |
b8bc24abaf8a
add TODO and fix CharClassWalker
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
198
diff
changeset
|
112 walk->turn = LEFT; |
171
684363c44d6f
remove some warning and error (not working)
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
170
diff
changeset
|
113 ccs->cc = next; |
180
d97bcab546e8
implement getNext
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
178
diff
changeset
|
114 walk->stack = ccs; |
169
313f1c176328
implement mergeTransition
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
168
diff
changeset
|
115 next = next->left; |
313f1c176328
implement mergeTransition
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
168
diff
changeset
|
116 } |
201
b8bc24abaf8a
add TODO and fix CharClassWalker
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
198
diff
changeset
|
117 walk->turn = SELF; |
172
540fc12871d9
remove some warnings and errors (not working)
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
171
diff
changeset
|
118 walk->next = next; |
169
313f1c176328
implement mergeTransition
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
168
diff
changeset
|
119 } |
313f1c176328
implement mergeTransition
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
168
diff
changeset
|
120 |
313f1c176328
implement mergeTransition
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
168
diff
changeset
|
121 CharClassWalkerPtr createCharClassWalker (CharClassPtr next) { |
313f1c176328
implement mergeTransition
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
168
diff
changeset
|
122 CharClassWalkerPtr walk = NEW(CharClassWalker); |
313f1c176328
implement mergeTransition
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
168
diff
changeset
|
123 walk->next = NULL; |
180
d97bcab546e8
implement getNext
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
178
diff
changeset
|
124 walk->stack = NULL; |
169
313f1c176328
implement mergeTransition
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
168
diff
changeset
|
125 if (!next) return walk; |
181
3c4db09b8581
change return value findLeftMost()
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
180
diff
changeset
|
126 findLeftMost(next,walk); |
169
313f1c176328
implement mergeTransition
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
168
diff
changeset
|
127 return walk; |
313f1c176328
implement mergeTransition
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
168
diff
changeset
|
128 } |
313f1c176328
implement mergeTransition
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
168
diff
changeset
|
129 |
313f1c176328
implement mergeTransition
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
168
diff
changeset
|
130 bool hasNext(CharClassWalkerPtr walk) { |
313f1c176328
implement mergeTransition
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
168
diff
changeset
|
131 return walk->next != NULL; |
313f1c176328
implement mergeTransition
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
168
diff
changeset
|
132 } |
313f1c176328
implement mergeTransition
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
168
diff
changeset
|
133 |
180
d97bcab546e8
implement getNext
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
178
diff
changeset
|
134 CharClassStackPtr charClassStackPop(CharClassWalkerPtr walk) { |
d97bcab546e8
implement getNext
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
178
diff
changeset
|
135 CharClassStackPtr prev = walk->stack->next; |
209
959f8c00da17
fix charClassStackPop()
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
208
diff
changeset
|
136 walk->turn = walk->stack->turn; |
180
d97bcab546e8
implement getNext
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
178
diff
changeset
|
137 free(walk->stack); |
d97bcab546e8
implement getNext
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
178
diff
changeset
|
138 walk->stack = prev; |
d97bcab546e8
implement getNext
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
178
diff
changeset
|
139 return prev; |
d97bcab546e8
implement getNext
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
178
diff
changeset
|
140 } |
d97bcab546e8
implement getNext
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
178
diff
changeset
|
141 |
169
313f1c176328
implement mergeTransition
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
168
diff
changeset
|
142 CharClassPtr getNext(CharClassWalkerPtr walk) { |
313f1c176328
implement mergeTransition
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
168
diff
changeset
|
143 CharClassPtr current = walk->next; |
180
d97bcab546e8
implement getNext
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
178
diff
changeset
|
144 walk->next = NULL; |
201
b8bc24abaf8a
add TODO and fix CharClassWalker
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
198
diff
changeset
|
145 if (walk->turn == SELF) { |
180
d97bcab546e8
implement getNext
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
178
diff
changeset
|
146 if (current->right) { |
201
b8bc24abaf8a
add TODO and fix CharClassWalker
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
198
diff
changeset
|
147 walk->turn = RIGHT; |
181
3c4db09b8581
change return value findLeftMost()
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
180
diff
changeset
|
148 findLeftMost(current->right,walk); |
180
d97bcab546e8
implement getNext
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
178
diff
changeset
|
149 return current; |
d97bcab546e8
implement getNext
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
178
diff
changeset
|
150 } |
201
b8bc24abaf8a
add TODO and fix CharClassWalker
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
198
diff
changeset
|
151 } |
b8bc24abaf8a
add TODO and fix CharClassWalker
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
198
diff
changeset
|
152 while (walk->stack) { |
b8bc24abaf8a
add TODO and fix CharClassWalker
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
198
diff
changeset
|
153 walk->next = walk->stack->cc; |
180
d97bcab546e8
implement getNext
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
178
diff
changeset
|
154 charClassStackPop(walk); |
201
b8bc24abaf8a
add TODO and fix CharClassWalker
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
198
diff
changeset
|
155 if (walk->turn == LEFT) { |
b8bc24abaf8a
add TODO and fix CharClassWalker
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
198
diff
changeset
|
156 walk->turn = SELF; |
b8bc24abaf8a
add TODO and fix CharClassWalker
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
198
diff
changeset
|
157 return current; |
b8bc24abaf8a
add TODO and fix CharClassWalker
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
198
diff
changeset
|
158 } |
b8bc24abaf8a
add TODO and fix CharClassWalker
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
198
diff
changeset
|
159 } |
b8bc24abaf8a
add TODO and fix CharClassWalker
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
198
diff
changeset
|
160 walk->next = NULL; |
169
313f1c176328
implement mergeTransition
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
168
diff
changeset
|
161 return current; |
313f1c176328
implement mergeTransition
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
168
diff
changeset
|
162 } |
313f1c176328
implement mergeTransition
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
168
diff
changeset
|
163 |
182
dbe004d03ef0
implement stateAllocate()
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
181
diff
changeset
|
164 void setState(CharClassPtr cc, BitVector bi) { |
189 | 165 cc->nextState = bi; |
182
dbe004d03ef0
implement stateAllocate()
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
181
diff
changeset
|
166 if (cc->left) { |
dbe004d03ef0
implement stateAllocate()
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
181
diff
changeset
|
167 setState(cc->left,bi); |
dbe004d03ef0
implement stateAllocate()
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
181
diff
changeset
|
168 } |
dbe004d03ef0
implement stateAllocate()
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
181
diff
changeset
|
169 cc->nextState = bi; |
dbe004d03ef0
implement stateAllocate()
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
181
diff
changeset
|
170 if (cc->right) { |
dbe004d03ef0
implement stateAllocate()
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
181
diff
changeset
|
171 setState(cc->right,bi); |
dbe004d03ef0
implement stateAllocate()
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
181
diff
changeset
|
172 } |
dbe004d03ef0
implement stateAllocate()
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
181
diff
changeset
|
173 } |
dbe004d03ef0
implement stateAllocate()
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
181
diff
changeset
|
174 |
190
3e8e5780ad4a
change node::State to State
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
189
diff
changeset
|
175 CharClassPtr mergeTransition(StatePtr x,CharClassPtr y) { |
178
5e8c6857934c
implement charClassMerge
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
177
diff
changeset
|
176 if (x->cc == NULL) { |
5e8c6857934c
implement charClassMerge
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
177
diff
changeset
|
177 return y; |
5e8c6857934c
implement charClassMerge
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
177
diff
changeset
|
178 } |
5e8c6857934c
implement charClassMerge
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
177
diff
changeset
|
179 CharClassWalkerPtr walk = createCharClassWalker(x->cc); |
5e8c6857934c
implement charClassMerge
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
177
diff
changeset
|
180 CharClassPtr ccy = y; |
172
540fc12871d9
remove some warnings and errors (not working)
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
171
diff
changeset
|
181 BitVector bi; |
208
2ec95755238e
fix mergetest
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
204
diff
changeset
|
182 while (hasNext(walk)) { |
2ec95755238e
fix mergetest
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
204
diff
changeset
|
183 CharClassPtr cc = getNext(walk); |
171
684363c44d6f
remove some warning and error (not working)
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
170
diff
changeset
|
184 unsigned long begin = cc->cond.range.begin; |
684363c44d6f
remove some warning and error (not working)
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
170
diff
changeset
|
185 unsigned long end = cc->cond.range.end; |
172
540fc12871d9
remove some warnings and errors (not working)
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
171
diff
changeset
|
186 bi = cc->nextState; |
171
684363c44d6f
remove some warning and error (not working)
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
170
diff
changeset
|
187 ccy = charClassMerge(ccy,begin,end,bi); |
169
313f1c176328
implement mergeTransition
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
168
diff
changeset
|
188 } |
313f1c176328
implement mergeTransition
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
168
diff
changeset
|
189 free(walk); |
178
5e8c6857934c
implement charClassMerge
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
177
diff
changeset
|
190 return ccy; |
169
313f1c176328
implement mergeTransition
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
168
diff
changeset
|
191 } |
313f1c176328
implement mergeTransition
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
168
diff
changeset
|
192 |
183
7ae0a3070647
implement generateTransitionList
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
182
diff
changeset
|
193 /** |
186
3e8aae8beba9
fix createTransitionGenerator()
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
185
diff
changeset
|
194 作成する state を linked list |
3e8aae8beba9
fix createTransitionGenerator()
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
185
diff
changeset
|
195 bitvector を index とした配列に BitVectorPtr を格納 |
3e8aae8beba9
fix createTransitionGenerator()
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
185
diff
changeset
|
196 state に対応する NodePtr を |
183
7ae0a3070647
implement generateTransitionList
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
182
diff
changeset
|
197 */ |
195
4fefd80c05f2
change variable name (TGValue tg -> TGValue tgv)
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
192
diff
changeset
|
198 StatePtr createState(TGValue tgv,NodePtr n) { |
190
3e8e5780ad4a
change node::State to State
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
189
diff
changeset
|
199 StatePtr s = NEW(State); |
213
11b6332f0a42
fix tgv.tg->totalStateCount increment
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
212
diff
changeset
|
200 s->stateNum = n->stateNum = tgv.tg->totalStateCount; |
195
4fefd80c05f2
change variable name (TGValue tg -> TGValue tgv)
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
192
diff
changeset
|
201 s->next = tgv.tg->stateList; |
4fefd80c05f2
change variable name (TGValue tg -> TGValue tgv)
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
192
diff
changeset
|
202 tgv.tg->stateList = s; |
183
7ae0a3070647
implement generateTransitionList
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
182
diff
changeset
|
203 s->node = n; |
187
ef798db705e9
remove some warnings and errors(not working)
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
186
diff
changeset
|
204 BitVector bi = createBitVector(n->stateNum); |
183
7ae0a3070647
implement generateTransitionList
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
182
diff
changeset
|
205 s->bitState = bi; |
214
a94f57af1600
remove allocateCCstate createCCState
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
213
diff
changeset
|
206 tgv.tg->totalStateCount++; |
208
2ec95755238e
fix mergetest
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
204
diff
changeset
|
207 s->cc = n->cc; |
187
ef798db705e9
remove some warnings and errors(not working)
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
186
diff
changeset
|
208 return s; |
183
7ae0a3070647
implement generateTransitionList
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
182
diff
changeset
|
209 } |
7ae0a3070647
implement generateTransitionList
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
182
diff
changeset
|
210 |
185
d25f4f3b4c34
add comment
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
184
diff
changeset
|
211 /** |
186
3e8aae8beba9
fix createTransitionGenerator()
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
185
diff
changeset
|
212 正規表現に必要な状態を探して、それぞれに番号を割り振る |
3e8aae8beba9
fix createTransitionGenerator()
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
185
diff
changeset
|
213 前が * でない + は新しく状態を作る |
3e8aae8beba9
fix createTransitionGenerator()
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
185
diff
changeset
|
214 * があったら、次の状態はその時の先頭の状態になる |
185
d25f4f3b4c34
add comment
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
184
diff
changeset
|
215 */ |
195
4fefd80c05f2
change variable name (TGValue tg -> TGValue tgv)
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
192
diff
changeset
|
216 TGValue stateAllocate(NodePtr n,TGValue tgv) { |
141
71f36a59cf6a
add appendState
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
139
diff
changeset
|
217 if (n->tokenType == '+') { |
195
4fefd80c05f2
change variable name (TGValue tg -> TGValue tgv)
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
192
diff
changeset
|
218 TGValue tgvLeft = stateAllocate(n->left,tgv); |
4fefd80c05f2
change variable name (TGValue tg -> TGValue tgv)
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
192
diff
changeset
|
219 if (tgvLeft.asterisk) { |
4fefd80c05f2
change variable name (TGValue tg -> TGValue tgv)
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
192
diff
changeset
|
220 TGValue tgvRight = tgvLeft; |
4fefd80c05f2
change variable name (TGValue tg -> TGValue tgv)
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
192
diff
changeset
|
221 tgvRight.asterisk = false; |
4fefd80c05f2
change variable name (TGValue tg -> TGValue tgv)
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
192
diff
changeset
|
222 tgvRight = stateAllocate(n->right,tgvRight); |
4fefd80c05f2
change variable name (TGValue tg -> TGValue tgv)
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
192
diff
changeset
|
223 tgvRight.asterisk = true; |
4fefd80c05f2
change variable name (TGValue tg -> TGValue tgv)
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
192
diff
changeset
|
224 return tgvRight; |
142 | 225 } |
195
4fefd80c05f2
change variable name (TGValue tg -> TGValue tgv)
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
192
diff
changeset
|
226 TGValue tgvRight = tgvLeft; |
4fefd80c05f2
change variable name (TGValue tg -> TGValue tgv)
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
192
diff
changeset
|
227 n->right->state = createState(tgvRight,n->right); |
4fefd80c05f2
change variable name (TGValue tg -> TGValue tgv)
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
192
diff
changeset
|
228 tgvRight.startState = n->right->state; |
214
a94f57af1600
remove allocateCCstate createCCState
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
213
diff
changeset
|
229 tgvRight.asterisk = false; |
a94f57af1600
remove allocateCCstate createCCState
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
213
diff
changeset
|
230 tgvRight = stateAllocate(n->right,tgvRight); |
a94f57af1600
remove allocateCCstate createCCState
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
213
diff
changeset
|
231 return tgvRight; |
182
dbe004d03ef0
implement stateAllocate()
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
181
diff
changeset
|
232 } else if (n->tokenType == '|') { |
195
4fefd80c05f2
change variable name (TGValue tg -> TGValue tgv)
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
192
diff
changeset
|
233 TGValue tgv1 = stateAllocate(n->left,tgv); |
4fefd80c05f2
change variable name (TGValue tg -> TGValue tgv)
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
192
diff
changeset
|
234 TGValue tgv2 = stateAllocate(n->right,tgv1); |
4fefd80c05f2
change variable name (TGValue tg -> TGValue tgv)
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
192
diff
changeset
|
235 return tgv2; |
182
dbe004d03ef0
implement stateAllocate()
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
181
diff
changeset
|
236 } else if (n->tokenType == '*') { |
195
4fefd80c05f2
change variable name (TGValue tg -> TGValue tgv)
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
192
diff
changeset
|
237 TGValue tgvAstah = tgv; |
4fefd80c05f2
change variable name (TGValue tg -> TGValue tgv)
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
192
diff
changeset
|
238 tgvAstah.endState = tgvAstah.startState; |
4fefd80c05f2
change variable name (TGValue tg -> TGValue tgv)
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
192
diff
changeset
|
239 tgvAstah = stateAllocate(n->left,tgvAstah); |
4fefd80c05f2
change variable name (TGValue tg -> TGValue tgv)
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
192
diff
changeset
|
240 tgvAstah.asterisk = true; |
4fefd80c05f2
change variable name (TGValue tg -> TGValue tgv)
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
192
diff
changeset
|
241 return tgvAstah; |
182
dbe004d03ef0
implement stateAllocate()
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
181
diff
changeset
|
242 } else if (n->tokenType == 'c' || n->tokenType == 'a'){ |
195
4fefd80c05f2
change variable name (TGValue tg -> TGValue tgv)
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
192
diff
changeset
|
243 TGValue tgv1 = tgv; |
4fefd80c05f2
change variable name (TGValue tg -> TGValue tgv)
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
192
diff
changeset
|
244 tgv1.asterisk = false; |
4fefd80c05f2
change variable name (TGValue tg -> TGValue tgv)
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
192
diff
changeset
|
245 n->stateNum = tgv.startState->stateNum; |
4fefd80c05f2
change variable name (TGValue tg -> TGValue tgv)
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
192
diff
changeset
|
246 n->nextStateNum = tgv.endState->stateNum; |
213
11b6332f0a42
fix tgv.tg->totalStateCount increment
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
212
diff
changeset
|
247 n->state = tgv.startState;; |
195
4fefd80c05f2
change variable name (TGValue tg -> TGValue tgv)
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
192
diff
changeset
|
248 n->nextState = tgv.endState; |
4fefd80c05f2
change variable name (TGValue tg -> TGValue tgv)
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
192
diff
changeset
|
249 return tgv1; |
4fefd80c05f2
change variable name (TGValue tg -> TGValue tgv)
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
192
diff
changeset
|
250 } else { |
183
7ae0a3070647
implement generateTransitionList
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
182
diff
changeset
|
251 return tgv; |
7ae0a3070647
implement generateTransitionList
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
182
diff
changeset
|
252 } |
7ae0a3070647
implement generateTransitionList
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
182
diff
changeset
|
253 } |
7ae0a3070647
implement generateTransitionList
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
182
diff
changeset
|
254 |
185
d25f4f3b4c34
add comment
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
184
diff
changeset
|
255 /** |
186
3e8aae8beba9
fix createTransitionGenerator()
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
185
diff
changeset
|
256 割り当てられた状態に沿って charclass の行き先を書き換える |
3e8aae8beba9
fix createTransitionGenerator()
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
185
diff
changeset
|
257 書き換えた charclass を merge する |
3e8aae8beba9
fix createTransitionGenerator()
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
185
diff
changeset
|
258 前の部分に * がない + は新しい状態をつくるので、state を切り替えて生成する |
185
d25f4f3b4c34
add comment
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
184
diff
changeset
|
259 */ |
195
4fefd80c05f2
change variable name (TGValue tg -> TGValue tgv)
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
192
diff
changeset
|
260 TGValue generateTransition(NodePtr n,TGValue tgv) { |
183
7ae0a3070647
implement generateTransitionList
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
182
diff
changeset
|
261 if (n->tokenType == '+') { |
195
4fefd80c05f2
change variable name (TGValue tg -> TGValue tgv)
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
192
diff
changeset
|
262 TGValue tgvLeft = generateTransition(n->left,tgv); |
4fefd80c05f2
change variable name (TGValue tg -> TGValue tgv)
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
192
diff
changeset
|
263 if (tgvLeft.asterisk) { |
4fefd80c05f2
change variable name (TGValue tg -> TGValue tgv)
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
192
diff
changeset
|
264 TGValue tgvRight = tgvLeft; |
4fefd80c05f2
change variable name (TGValue tg -> TGValue tgv)
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
192
diff
changeset
|
265 tgvRight.asterisk = false; |
4fefd80c05f2
change variable name (TGValue tg -> TGValue tgv)
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
192
diff
changeset
|
266 tgvRight = generateTransition(n->right,tgvRight); |
4fefd80c05f2
change variable name (TGValue tg -> TGValue tgv)
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
192
diff
changeset
|
267 tgvRight.asterisk = true; |
4fefd80c05f2
change variable name (TGValue tg -> TGValue tgv)
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
192
diff
changeset
|
268 return tgvRight; |
185
d25f4f3b4c34
add comment
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
184
diff
changeset
|
269 } |
214
a94f57af1600
remove allocateCCstate createCCState
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
213
diff
changeset
|
270 TGValue tgvRight = tgvLeft; |
195
4fefd80c05f2
change variable name (TGValue tg -> TGValue tgv)
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
192
diff
changeset
|
271 StatePtr left = tgvLeft.startState; |
4fefd80c05f2
change variable name (TGValue tg -> TGValue tgv)
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
192
diff
changeset
|
272 tgvLeft.startState = n->right->state; |
4fefd80c05f2
change variable name (TGValue tg -> TGValue tgv)
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
192
diff
changeset
|
273 tgvLeft.tg->stateArray[tgvLeft.startState->bitState.bitContainer] = left; |
214
a94f57af1600
remove allocateCCstate createCCState
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
213
diff
changeset
|
274 tgvRight.asterisk = false; |
a94f57af1600
remove allocateCCstate createCCState
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
213
diff
changeset
|
275 tgvRight = generateTransition(n->right,tgvRight); |
a94f57af1600
remove allocateCCstate createCCState
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
213
diff
changeset
|
276 return tgvRight; |
183
7ae0a3070647
implement generateTransitionList
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
182
diff
changeset
|
277 } else if (n->tokenType == '|') { |
195
4fefd80c05f2
change variable name (TGValue tg -> TGValue tgv)
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
192
diff
changeset
|
278 TGValue tgv1 = generateTransition(n->left,tgv); |
4fefd80c05f2
change variable name (TGValue tg -> TGValue tgv)
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
192
diff
changeset
|
279 TGValue tgv2 = generateTransition(n->right,tgv1); |
4fefd80c05f2
change variable name (TGValue tg -> TGValue tgv)
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
192
diff
changeset
|
280 return tgv2; |
183
7ae0a3070647
implement generateTransitionList
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
182
diff
changeset
|
281 } else if (n->tokenType == '*') { |
195
4fefd80c05f2
change variable name (TGValue tg -> TGValue tgv)
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
192
diff
changeset
|
282 TGValue tgvAstah = generateTransition(n->left,tgv); |
4fefd80c05f2
change variable name (TGValue tg -> TGValue tgv)
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
192
diff
changeset
|
283 tgvAstah.asterisk = true; |
4fefd80c05f2
change variable name (TGValue tg -> TGValue tgv)
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
192
diff
changeset
|
284 return tgvAstah; |
183
7ae0a3070647
implement generateTransitionList
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
182
diff
changeset
|
285 } else if (n->tokenType == 'c' || n->tokenType == 'a'){ |
195
4fefd80c05f2
change variable name (TGValue tg -> TGValue tgv)
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
192
diff
changeset
|
286 TGValue tgv1 = tgv; |
4fefd80c05f2
change variable name (TGValue tg -> TGValue tgv)
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
192
diff
changeset
|
287 tgv1.asterisk = false; |
183
7ae0a3070647
implement generateTransitionList
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
182
diff
changeset
|
288 BitVector bi = createBitVector(n->nextStateNum); |
182
dbe004d03ef0
implement stateAllocate()
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
181
diff
changeset
|
289 setState(n->cc,bi); |
195
4fefd80c05f2
change variable name (TGValue tg -> TGValue tgv)
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
192
diff
changeset
|
290 tgv1.startState->cc = mergeTransition(tgv1.startState,n->cc); |
4fefd80c05f2
change variable name (TGValue tg -> TGValue tgv)
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
192
diff
changeset
|
291 return tgv1; |
4fefd80c05f2
change variable name (TGValue tg -> TGValue tgv)
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
192
diff
changeset
|
292 } else { |
182
dbe004d03ef0
implement stateAllocate()
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
181
diff
changeset
|
293 return tgv; |
dbe004d03ef0
implement stateAllocate()
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
181
diff
changeset
|
294 } |
141
71f36a59cf6a
add appendState
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
139
diff
changeset
|
295 } |
71f36a59cf6a
add appendState
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
139
diff
changeset
|
296 |
186
3e8aae8beba9
fix createTransitionGenerator()
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
185
diff
changeset
|
297 TransitionGeneratorPtr createTransitionGenerator() { |
3e8aae8beba9
fix createTransitionGenerator()
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
185
diff
changeset
|
298 TransitionGeneratorPtr tg = NEW(TransitionGenerator); |
213
11b6332f0a42
fix tgv.tg->totalStateCount increment
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
212
diff
changeset
|
299 tg->totalStateCount = 0; |
186
3e8aae8beba9
fix createTransitionGenerator()
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
185
diff
changeset
|
300 tg->stack = NULL; |
3e8aae8beba9
fix createTransitionGenerator()
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
185
diff
changeset
|
301 tg->stateArray = NULL; |
192
ecf70fb215a5
print charclass
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
191
diff
changeset
|
302 tg->stateList = NULL; |
175
3be0fbcd4b52
implement createTransitionGenerator
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
173
diff
changeset
|
303 return tg; |
3be0fbcd4b52
implement createTransitionGenerator
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
173
diff
changeset
|
304 } |
3be0fbcd4b52
implement createTransitionGenerator
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
173
diff
changeset
|
305 |
208
2ec95755238e
fix mergetest
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
204
diff
changeset
|
306 TGValue createTGValue() { |
183
7ae0a3070647
implement generateTransitionList
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
182
diff
changeset
|
307 TGValue tgv; |
213
11b6332f0a42
fix tgv.tg->totalStateCount increment
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
212
diff
changeset
|
308 tgv.startState = NULL; |
11b6332f0a42
fix tgv.tg->totalStateCount increment
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
212
diff
changeset
|
309 tgv.endState = NULL; |
183
7ae0a3070647
implement generateTransitionList
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
182
diff
changeset
|
310 tgv.asterisk = false; |
213
11b6332f0a42
fix tgv.tg->totalStateCount increment
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
212
diff
changeset
|
311 tgv.tg = createTransitionGenerator(); |
208
2ec95755238e
fix mergetest
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
204
diff
changeset
|
312 return tgv; |
2ec95755238e
fix mergetest
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
204
diff
changeset
|
313 } |
2ec95755238e
fix mergetest
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
204
diff
changeset
|
314 |
2ec95755238e
fix mergetest
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
204
diff
changeset
|
315 TransitionGeneratorPtr generateTransitionList(NodePtr n) { |
2ec95755238e
fix mergetest
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
204
diff
changeset
|
316 TGValue tgv = createTGValue(); |
192
ecf70fb215a5
print charclass
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
191
diff
changeset
|
317 StatePtr startState = tgv.startState = createState(tgv,n); |
184
1da1b2eacb84
gather struct
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
183
diff
changeset
|
318 NodePtr eof = createNode(NULL,'e',NULL,NULL,NULL); |
192
ecf70fb215a5
print charclass
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
191
diff
changeset
|
319 StatePtr endState = tgv.endState = createState(tgv,eof); |
ecf70fb215a5
print charclass
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
191
diff
changeset
|
320 tgv = stateAllocate(n,tgv); |
208
2ec95755238e
fix mergetest
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
204
diff
changeset
|
321 if (tgv.tg->totalStateCount > BITBLOCK) { |
192
ecf70fb215a5
print charclass
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
191
diff
changeset
|
322 errorMassege("StateMax > BITBLOCK",__LINE__,__FILE__); |
ecf70fb215a5
print charclass
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
191
diff
changeset
|
323 } |
208
2ec95755238e
fix mergetest
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
204
diff
changeset
|
324 BitVector bi = createBitVector(tgv.tg->totalStateCount); |
192
ecf70fb215a5
print charclass
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
191
diff
changeset
|
325 tgv.tg->stateArray = (StatePtr*)calloc(bi.bitContainer*2,sizeof(StatePtr*)); |
ecf70fb215a5
print charclass
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
191
diff
changeset
|
326 tgv.tg->stateArray[startState->bitState.bitContainer] = startState; |
ecf70fb215a5
print charclass
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
191
diff
changeset
|
327 tgv.tg->stateArray[endState->bitState.bitContainer] = endState; |
183
7ae0a3070647
implement generateTransitionList
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
182
diff
changeset
|
328 generateTransition(n,tgv); |
208
2ec95755238e
fix mergetest
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
204
diff
changeset
|
329 return tgv.tg; |
141
71f36a59cf6a
add appendState
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
139
diff
changeset
|
330 } |
190
3e8e5780ad4a
change node::State to State
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
189
diff
changeset
|
331 |
3e8e5780ad4a
change node::State to State
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
189
diff
changeset
|
332 void printState(StatePtr state) { |
3e8e5780ad4a
change node::State to State
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
189
diff
changeset
|
333 printf("state : %lx\n",state->bitState.bitContainer); |
3e8e5780ad4a
change node::State to State
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
189
diff
changeset
|
334 long nodeNumber = 0; |
3e8e5780ad4a
change node::State to State
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
189
diff
changeset
|
335 if (state->node) { |
201
b8bc24abaf8a
add TODO and fix CharClassWalker
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
198
diff
changeset
|
336 printf("node : %c %lx -> %d\n",state->node->tokenType,state->bitState.bitContainer,state->node->nextStateNum); |
195
4fefd80c05f2
change variable name (TGValue tg -> TGValue tgv)
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
192
diff
changeset
|
337 if (state->node->state) |
4fefd80c05f2
change variable name (TGValue tg -> TGValue tgv)
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
192
diff
changeset
|
338 nodeNumber = state->node->state->bitState.bitContainer; |
190
3e8e5780ad4a
change node::State to State
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
189
diff
changeset
|
339 } |
192
ecf70fb215a5
print charclass
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
191
diff
changeset
|
340 if (state->cc) { |
ecf70fb215a5
print charclass
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
191
diff
changeset
|
341 printCharacterClass(state->cc,nodeNumber,4); |
ecf70fb215a5
print charclass
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
191
diff
changeset
|
342 } |
190
3e8e5780ad4a
change node::State to State
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
189
diff
changeset
|
343 } |
3e8e5780ad4a
change node::State to State
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
189
diff
changeset
|
344 |
3e8e5780ad4a
change node::State to State
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
189
diff
changeset
|
345 void printState(TransitionGeneratorPtr tg) { |
192
ecf70fb215a5
print charclass
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
191
diff
changeset
|
346 StatePtr state = tg->stateList; |
190
3e8e5780ad4a
change node::State to State
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
189
diff
changeset
|
347 for (;state;state = state->next) { |
3e8e5780ad4a
change node::State to State
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
189
diff
changeset
|
348 printState(state); |
3e8e5780ad4a
change node::State to State
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
189
diff
changeset
|
349 putchar('\n'); |
3e8e5780ad4a
change node::State to State
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
189
diff
changeset
|
350 } |
3e8e5780ad4a
change node::State to State
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
189
diff
changeset
|
351 } |
202
39ca25ed0607
add searchBit test
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
201
diff
changeset
|
352 |
39ca25ed0607
add searchBit test
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
201
diff
changeset
|
353 SCValue createSCValue(TGValue tgv) { |
39ca25ed0607
add searchBit test
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
201
diff
changeset
|
354 SCValue scv; |
39ca25ed0607
add searchBit test
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
201
diff
changeset
|
355 scv.stateTop = tgv.tg->stateList; |
39ca25ed0607
add searchBit test
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
201
diff
changeset
|
356 scv.stateEnd = scv.stateTop; |
39ca25ed0607
add searchBit test
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
201
diff
changeset
|
357 while (scv.stateEnd->next) { |
39ca25ed0607
add searchBit test
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
201
diff
changeset
|
358 scv.stateEnd = scv.stateEnd->next; |
39ca25ed0607
add searchBit test
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
201
diff
changeset
|
359 } |
203
e809a2dd0731
add scValue
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
202
diff
changeset
|
360 return scv; |
202
39ca25ed0607
add searchBit test
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
201
diff
changeset
|
361 } |
39ca25ed0607
add searchBit test
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
201
diff
changeset
|
362 |
39ca25ed0607
add searchBit test
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
201
diff
changeset
|
363 SCValue createState(SCValue scv,BitVector bi) { |
39ca25ed0607
add searchBit test
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
201
diff
changeset
|
364 StatePtr s = NEW(State); |
39ca25ed0607
add searchBit test
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
201
diff
changeset
|
365 s->stateNum = ++scv.tg->totalStateCount; |
39ca25ed0607
add searchBit test
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
201
diff
changeset
|
366 s->next = NULL; |
39ca25ed0607
add searchBit test
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
201
diff
changeset
|
367 scv.stateEnd->next = s; |
39ca25ed0607
add searchBit test
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
201
diff
changeset
|
368 scv.stateEnd = s; |
39ca25ed0607
add searchBit test
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
201
diff
changeset
|
369 s->bitState = bi; |
39ca25ed0607
add searchBit test
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
201
diff
changeset
|
370 s->cc = NULL; |
39ca25ed0607
add searchBit test
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
201
diff
changeset
|
371 return scv; |
39ca25ed0607
add searchBit test
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
201
diff
changeset
|
372 } |
39ca25ed0607
add searchBit test
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
201
diff
changeset
|
373 |
39ca25ed0607
add searchBit test
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
201
diff
changeset
|
374 /** |
39ca25ed0607
add searchBit test
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
201
diff
changeset
|
375 現在のステートに含まれる組み合わせ状態をとってくる |
39ca25ed0607
add searchBit test
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
201
diff
changeset
|
376 組み合わされた個々の charclass をmerge して新しい charclass をつくり、組み合わせ状態に登録する |
39ca25ed0607
add searchBit test
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
201
diff
changeset
|
377 生成した状態は stateArray に格納するA |
39ca25ed0607
add searchBit test
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
201
diff
changeset
|
378 新しい状態ができなくなったら終了 |
39ca25ed0607
add searchBit test
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
201
diff
changeset
|
379 |
39ca25ed0607
add searchBit test
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
201
diff
changeset
|
380 charClassMerge の段階で新しい状態をリストに登録したら、charclasswalk をする必要がなくなる |
39ca25ed0607
add searchBit test
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
201
diff
changeset
|
381 */ |
39ca25ed0607
add searchBit test
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
201
diff
changeset
|
382 SCValue subsetConstraction(SCValue scv) { |
39ca25ed0607
add searchBit test
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
201
diff
changeset
|
383 for (;scv.stateTop;scv.stateTop = scv.stateTop->next) { |
204
e6e862e92fdc
remove warning and error
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
203
diff
changeset
|
384 CharClassWalkerPtr cw = createCharClassWalker(scv.stateTop->cc); |
202
39ca25ed0607
add searchBit test
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
201
diff
changeset
|
385 while (hasNext(cw)) { |
39ca25ed0607
add searchBit test
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
201
diff
changeset
|
386 CharClassPtr cc = getNext(cw); |
204
e6e862e92fdc
remove warning and error
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
203
diff
changeset
|
387 BitVector bi = cc->nextState; |
e6e862e92fdc
remove warning and error
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
203
diff
changeset
|
388 if (scv.stateArray[bi.bitContainer]) continue; |
202
39ca25ed0607
add searchBit test
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
201
diff
changeset
|
389 scv = createState(scv,bi); |
39ca25ed0607
add searchBit test
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
201
diff
changeset
|
390 StatePtr s = scv.stateEnd; |
39ca25ed0607
add searchBit test
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
201
diff
changeset
|
391 for (;bi.bitContainer;) { |
39ca25ed0607
add searchBit test
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
201
diff
changeset
|
392 int bitPosition = searchBit(bi); |
39ca25ed0607
add searchBit test
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
201
diff
changeset
|
393 unsigned long baseNum = 1 << bitPosition; |
39ca25ed0607
add searchBit test
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
201
diff
changeset
|
394 bi.bitContainer ^= baseNum; |
39ca25ed0607
add searchBit test
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
201
diff
changeset
|
395 StatePtr base = scv.stateArray[baseNum]; |
39ca25ed0607
add searchBit test
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
201
diff
changeset
|
396 if (base == NULL) {// error |
39ca25ed0607
add searchBit test
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
201
diff
changeset
|
397 continue; |
39ca25ed0607
add searchBit test
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
201
diff
changeset
|
398 } |
39ca25ed0607
add searchBit test
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
201
diff
changeset
|
399 CharClassPtr merge = mergeTransition(s,base->cc); |
39ca25ed0607
add searchBit test
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
201
diff
changeset
|
400 s->cc = merge; |
39ca25ed0607
add searchBit test
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
201
diff
changeset
|
401 } |
204
e6e862e92fdc
remove warning and error
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
203
diff
changeset
|
402 scv.stateArray[bi.bitContainer] = s; |
202
39ca25ed0607
add searchBit test
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
201
diff
changeset
|
403 } |
39ca25ed0607
add searchBit test
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
201
diff
changeset
|
404 } |
204
e6e862e92fdc
remove warning and error
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
203
diff
changeset
|
405 return scv; |
202
39ca25ed0607
add searchBit test
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
201
diff
changeset
|
406 } |