Mercurial > hg > Applications > Grep
annotate regexParser/CharClass.cc @ 320:da02a7258d54
fix
author | mir3636 |
---|---|
date | Sun, 08 May 2016 23:31:14 +0900 |
parents | 7b8234c090f7 |
children |
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" |
216 | 6 #include "subsetConstruction.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 |
308 | 11 #include "CharClass.h" |
12 | |
309 | 13 CharClassPtr createCharClassRange(unsigned long begin, unsigned long end,unsigned long state, CharClassPtr left, CharClassPtr right) { |
14 CharClassPtr cc = NEW(CharClass); | |
15 cc->cond.range.begin = begin; | |
16 cc->cond.range.end = end; | |
17 cc->cond.w.word = NULL; | |
18 cc->cond.w.length = 0; | |
310
df27e6cab846
CharClassMerge with Word ( no match implementation )
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
309
diff
changeset
|
19 cc->cond.w.next = NULL; |
319 | 20 cc->cond.w.bm = NULL; |
309 | 21 cc->left = left; |
22 cc->right = right; | |
23 cc->nextState.bitContainer = state; | |
24 return cc; | |
25 } | |
308 | 26 |
27 CharClassPtr createCharClassWord(RegexInfoPtr ri) { | |
28 CharClassPtr cc = NEW(CharClass); | |
29 cc->left = NULL; | |
30 cc->right = NULL; | |
31 cc->cond.w.word = ri->tokenValue; | |
32 cc->cond.w.length = ri->ptr - ri->tokenValue; | |
310
df27e6cab846
CharClassMerge with Word ( no match implementation )
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
309
diff
changeset
|
33 cc->cond.w.next = NULL; |
319 | 34 cc->cond.w.bm = NULL; |
308 | 35 cc->cond.range.begin = cc->cond.range.end = *ri->tokenValue; |
36 return cc; | |
37 } | |
38 | |
310
df27e6cab846
CharClassMerge with Word ( no match implementation )
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
309
diff
changeset
|
39 CharClassPtr createCharClassRangeWord(unsigned long begin, unsigned long end,CharClassPtr cc,CharClassPtr m, CharClassPtr left, CharClassPtr right) { |
df27e6cab846
CharClassMerge with Word ( no match implementation )
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
309
diff
changeset
|
40 // same range and seme nextState? |
df27e6cab846
CharClassMerge with Word ( no match implementation )
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
309
diff
changeset
|
41 CharClassPtr ncc = NEW(CharClass); |
df27e6cab846
CharClassMerge with Word ( no match implementation )
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
309
diff
changeset
|
42 ncc->cond.range.begin = begin; |
df27e6cab846
CharClassMerge with Word ( no match implementation )
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
309
diff
changeset
|
43 ncc->cond.range.end = end; |
df27e6cab846
CharClassMerge with Word ( no match implementation )
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
309
diff
changeset
|
44 ncc->cond.w = cc->cond.w; |
df27e6cab846
CharClassMerge with Word ( no match implementation )
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
309
diff
changeset
|
45 ncc->left = left; |
df27e6cab846
CharClassMerge with Word ( no match implementation )
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
309
diff
changeset
|
46 ncc->right = right; |
df27e6cab846
CharClassMerge with Word ( no match implementation )
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
309
diff
changeset
|
47 if (!m) { |
df27e6cab846
CharClassMerge with Word ( no match implementation )
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
309
diff
changeset
|
48 ncc->nextState.bitContainer = cc->nextState.bitContainer; |
df27e6cab846
CharClassMerge with Word ( no match implementation )
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
309
diff
changeset
|
49 return ncc; |
df27e6cab846
CharClassMerge with Word ( no match implementation )
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
309
diff
changeset
|
50 } |
df27e6cab846
CharClassMerge with Word ( no match implementation )
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
309
diff
changeset
|
51 if (m->cond.w.word) { |
315 | 52 WordPtr n = &ncc->cond.w; |
53 n->word = m->cond.w.word; | |
54 n->length = m->cond.w.length; | |
55 n->next = &cc->cond.w; | |
310
df27e6cab846
CharClassMerge with Word ( no match implementation )
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
309
diff
changeset
|
56 } |
df27e6cab846
CharClassMerge with Word ( no match implementation )
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
309
diff
changeset
|
57 ncc->nextState.bitContainer = m->nextState.bitContainer | cc->nextState.bitContainer; |
df27e6cab846
CharClassMerge with Word ( no match implementation )
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
309
diff
changeset
|
58 return ncc; |
df27e6cab846
CharClassMerge with Word ( no match implementation )
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
309
diff
changeset
|
59 } |
df27e6cab846
CharClassMerge with Word ( no match implementation )
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
309
diff
changeset
|
60 |
df27e6cab846
CharClassMerge with Word ( no match implementation )
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
309
diff
changeset
|
61 |
308 | 62 /* |
63 cond.range.begin cond.range.end | |
64 |----------------| | |
65 1.b---e | |
66 2.b------e | |
67 3.b------------e | |
68 4.b-----------------------e | |
69 5.b----------------------------e | |
70 | |
71 |----------------| | |
72 6. b---------e | |
73 7. b----------------e | |
74 8. b---------------------e | |
75 | |
76 |----------------| | |
77 9. b-----e | |
78 10. b--------e | |
79 11. b-------------e | |
80 | |
81 |----------------| | |
82 12. b-----e | |
83 | |
84 |----------------| | |
85 13. b--e | |
86 | |
87 */ | |
88 CharClassPtr insertCharClass(CharClassPtr cc, unsigned long begin, unsigned long end) { | |
89 if (begin>end) { | |
90 unsigned long tmp = begin; begin = end; end = tmp; | |
91 } | |
92 if (cc == NULL) { | |
93 return createCharClassRange(begin,end,0,0,0); | |
94 } | |
95 if (end < cc->cond.range.begin ) { // 1 | |
96 if (cc->left) { | |
97 cc->left = insertCharClass(cc->left,begin,end); | |
98 } else { | |
99 cc->left = createCharClassRange(begin,end,0,0,0); | |
100 } | |
101 return cc; | |
102 } else if (end == cc->cond.range.begin ) { // 2 | |
103 cc->cond.range.begin = begin; | |
104 return cc; | |
105 } else if (end <= cc->cond.range.end) { // 3,4,6,7,9,10 | |
106 if (begin < cc->cond.range.begin) { // 3,4 | |
107 cc->cond.range.begin = begin; | |
108 } | |
109 return cc; | |
110 } else if (begin > cc->cond.range.end ) { // 13 | |
111 if (cc->right) { | |
112 cc->right = insertCharClass(cc->right,begin,end); | |
113 } else { | |
114 cc->right = createCharClassRange(begin,end,0,0,0); | |
115 } | |
116 return cc; | |
117 } | |
118 if (cc->right) { | |
119 CharClassPtr right = cc->right; | |
120 begin = cc->cond.range.begin; | |
121 free(cc); | |
122 return insertCharClass(right,begin,end); | |
123 } | |
124 if (begin >= cc->cond.range.begin && begin <= cc->cond.range.end) { // 12 | |
125 if (end > cc->cond.range.end) cc->cond.range.end = end; // 11,8 | |
126 } else if (begin < cc->cond.range.begin) { // 5 | |
127 cc->cond.range.begin = begin; | |
128 cc->cond.range.end = end; | |
129 } else { | |
130 printf("insertCharClass Error : begin %lu end %lu cc->begin %lu cc->end %lu\n", begin,end,cc->cond.range.begin,cc->cond.range.end); | |
131 } | |
132 return cc; | |
133 } | |
134 | |
222
c38a7b2dd996
implement exportState function (not correct working)
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
220
diff
changeset
|
135 |
144
d8a4922eceae
remove some errors (not working)
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
143
diff
changeset
|
136 |
310
df27e6cab846
CharClassMerge with Word ( no match implementation )
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
309
diff
changeset
|
137 CharClassPtr charClassMerge(CharClassPtr cc,unsigned long begin, unsigned long end, CharClassPtr m) ; |
308 | 138 |
310
df27e6cab846
CharClassMerge with Word ( no match implementation )
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
309
diff
changeset
|
139 CharClassPtr mergeCCTree(CharClassPtr cc,unsigned char mBegin,unsigned char mEnd,CharClassPtr m) { |
166
96854eba17e5
implement mergeCCTree()
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
163
diff
changeset
|
140 CharClassPtr cc1; |
96854eba17e5
implement mergeCCTree()
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
163
diff
changeset
|
141 if (cc) { |
310
df27e6cab846
CharClassMerge with Word ( no match implementation )
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
309
diff
changeset
|
142 cc1 = charClassMerge(cc,mBegin,mEnd,m); |
166
96854eba17e5
implement mergeCCTree()
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
163
diff
changeset
|
143 } else { |
310
df27e6cab846
CharClassMerge with Word ( no match implementation )
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
309
diff
changeset
|
144 cc1 = createCharClassRangeWord(mBegin,mEnd,m,NULL,NULL,NULL); |
166
96854eba17e5
implement mergeCCTree()
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
163
diff
changeset
|
145 } |
96854eba17e5
implement mergeCCTree()
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
163
diff
changeset
|
146 return cc1; |
96854eba17e5
implement mergeCCTree()
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
163
diff
changeset
|
147 } |
96854eba17e5
implement mergeCCTree()
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
163
diff
changeset
|
148 |
261
2b36dde3ffb7
add cond.range image above charClassMerge
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
257
diff
changeset
|
149 /* |
2b36dde3ffb7
add cond.range image above charClassMerge
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
257
diff
changeset
|
150 cond.range.begin cond.range.end |
2b36dde3ffb7
add cond.range image above charClassMerge
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
257
diff
changeset
|
151 |----------------| |
2b36dde3ffb7
add cond.range image above charClassMerge
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
257
diff
changeset
|
152 1.b---e |
2b36dde3ffb7
add cond.range image above charClassMerge
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
257
diff
changeset
|
153 2.b------e |
2b36dde3ffb7
add cond.range image above charClassMerge
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
257
diff
changeset
|
154 3.b------------e |
2b36dde3ffb7
add cond.range image above charClassMerge
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
257
diff
changeset
|
155 4.b-----------------------e |
2b36dde3ffb7
add cond.range image above charClassMerge
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
257
diff
changeset
|
156 5.b----------------------------e |
2b36dde3ffb7
add cond.range image above charClassMerge
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
257
diff
changeset
|
157 |
2b36dde3ffb7
add cond.range image above charClassMerge
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
257
diff
changeset
|
158 |----------------| |
2b36dde3ffb7
add cond.range image above charClassMerge
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
257
diff
changeset
|
159 6. b---------e |
2b36dde3ffb7
add cond.range image above charClassMerge
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
257
diff
changeset
|
160 7. b----------------e |
2b36dde3ffb7
add cond.range image above charClassMerge
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
257
diff
changeset
|
161 8. b---------------------e |
2b36dde3ffb7
add cond.range image above charClassMerge
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
257
diff
changeset
|
162 |
2b36dde3ffb7
add cond.range image above charClassMerge
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
257
diff
changeset
|
163 |----------------| |
2b36dde3ffb7
add cond.range image above charClassMerge
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
257
diff
changeset
|
164 9. b-----e |
2b36dde3ffb7
add cond.range image above charClassMerge
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
257
diff
changeset
|
165 10. b--------e |
2b36dde3ffb7
add cond.range image above charClassMerge
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
257
diff
changeset
|
166 11. b-------------e |
2b36dde3ffb7
add cond.range image above charClassMerge
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
257
diff
changeset
|
167 |
2b36dde3ffb7
add cond.range image above charClassMerge
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
257
diff
changeset
|
168 |----------------| |
2b36dde3ffb7
add cond.range image above charClassMerge
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
257
diff
changeset
|
169 12. b-----e |
2b36dde3ffb7
add cond.range image above charClassMerge
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
257
diff
changeset
|
170 |
2b36dde3ffb7
add cond.range image above charClassMerge
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
257
diff
changeset
|
171 |----------------| |
2b36dde3ffb7
add cond.range image above charClassMerge
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
257
diff
changeset
|
172 13. b--e |
2b36dde3ffb7
add cond.range image above charClassMerge
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
257
diff
changeset
|
173 |
2b36dde3ffb7
add cond.range image above charClassMerge
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
257
diff
changeset
|
174 */ |
2b36dde3ffb7
add cond.range image above charClassMerge
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
257
diff
changeset
|
175 |
310
df27e6cab846
CharClassMerge with Word ( no match implementation )
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
309
diff
changeset
|
176 CharClassPtr charClassMerge(CharClassPtr cc,unsigned long begin, unsigned long end, CharClassPtr m) { |
143 | 177 // 重なっているccの領域を分割する |
178 // 必要ならばnextStateを重ねあわせる | |
179 // 変更があった場合は新しくリストを作って返す | |
152 | 180 if (end < cc->cond.range.begin ) { // 1 |
181 if (cc->left) { | |
310
df27e6cab846
CharClassMerge with Word ( no match implementation )
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
309
diff
changeset
|
182 return createCharClassRangeWord(cc->cond.range.begin,cc->cond.range.end,m,NULL,charClassMerge(cc->left,begin,end,m),cc->right); |
152 | 183 } else { |
310
df27e6cab846
CharClassMerge with Word ( no match implementation )
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
309
diff
changeset
|
184 return createCharClassRangeWord(begin,end,m,NULL,NULL,cc); |
152 | 185 } |
163 | 186 } else if (end == cc->cond.range.begin && begin != end ) { // 2 |
310
df27e6cab846
CharClassMerge with Word ( no match implementation )
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
309
diff
changeset
|
187 CharClassPtr cc1 = mergeCCTree(cc->left,begin,end-1,m); |
156
b5ecfc008bcf
impl charClassMerge(not working)
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
155
diff
changeset
|
188 if (cc->cond.range.begin == cc->cond.range.end) { |
310
df27e6cab846
CharClassMerge with Word ( no match implementation )
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
309
diff
changeset
|
189 return createCharClassRangeWord(cc->cond.range.begin,cc->cond.range.end, |
df27e6cab846
CharClassMerge with Word ( no match implementation )
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
309
diff
changeset
|
190 cc,m, cc1,cc->right); |
155 | 191 } |
310
df27e6cab846
CharClassMerge with Word ( no match implementation )
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
309
diff
changeset
|
192 CharClassPtr cc3 = createCharClassRangeWord(cc->cond.range.begin+1,cc->cond.range.end,cc,NULL,cc->left,cc->right); |
df27e6cab846
CharClassMerge with Word ( no match implementation )
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
309
diff
changeset
|
193 return createCharClassRangeWord(cc->cond.range.begin,cc->cond.range.begin, |
df27e6cab846
CharClassMerge with Word ( no match implementation )
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
309
diff
changeset
|
194 cc,m,cc1,cc3); |
163 | 195 } else if (end < cc->cond.range.end) { // range.begin < end |
155 | 196 if (begin < cc->cond.range.begin) { // 3 |
310
df27e6cab846
CharClassMerge with Word ( no match implementation )
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
309
diff
changeset
|
197 CharClassPtr cc1 = mergeCCTree(cc->left,begin,cc->cond.range.begin-1,m); |
df27e6cab846
CharClassMerge with Word ( no match implementation )
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
309
diff
changeset
|
198 CharClassPtr cc3 = createCharClassRangeWord(end+1,cc->cond.range.end,cc,NULL,cc->left,cc->right); |
df27e6cab846
CharClassMerge with Word ( no match implementation )
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
309
diff
changeset
|
199 return createCharClassRangeWord(cc->cond.range.begin,end,m,cc,cc1,cc3); |
152 | 200 } |
155 | 201 if (begin == cc->cond.range.begin) { // 6 |
310
df27e6cab846
CharClassMerge with Word ( no match implementation )
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
309
diff
changeset
|
202 CharClassPtr cc2 = createCharClassRangeWord(end+1,cc->cond.range.end,cc,NULL,NULL,cc->right); |
df27e6cab846
CharClassMerge with Word ( no match implementation )
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
309
diff
changeset
|
203 return createCharClassRangeWord(begin,end,cc,m,cc->left,cc2); |
155 | 204 } |
205 // 9 | |
310
df27e6cab846
CharClassMerge with Word ( no match implementation )
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
309
diff
changeset
|
206 CharClassPtr cc2 = createCharClassRangeWord(cc->cond.range.begin,begin-1,cc,NULL,cc->left,NULL); |
df27e6cab846
CharClassMerge with Word ( no match implementation )
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
309
diff
changeset
|
207 CharClassPtr cc3 = createCharClassRangeWord(end+1,cc->cond.range.end,cc,NULL,NULL,cc->right); |
df27e6cab846
CharClassMerge with Word ( no match implementation )
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
309
diff
changeset
|
208 return createCharClassRangeWord(begin,end,cc,m,cc2,cc3); |
155 | 209 } else if (end == cc->cond.range.end) { |
210 if (begin == cc->cond.range.begin) { // 7 | |
310
df27e6cab846
CharClassMerge with Word ( no match implementation )
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
309
diff
changeset
|
211 return createCharClassRangeWord(begin,end,cc,m,cc->left,cc->right); |
155 | 212 } else if (begin < cc->cond.range.begin) { // 4 |
310
df27e6cab846
CharClassMerge with Word ( no match implementation )
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
309
diff
changeset
|
213 CharClassPtr cc1 = mergeCCTree(cc->left,begin,cc->cond.range.begin-1,m); |
df27e6cab846
CharClassMerge with Word ( no match implementation )
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
309
diff
changeset
|
214 return createCharClassRangeWord(cc->cond.range.begin,end,cc,m,cc1,cc->right); |
155 | 215 } |
163 | 216 // 10 cond.range.begin < begin |
310
df27e6cab846
CharClassMerge with Word ( no match implementation )
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
309
diff
changeset
|
217 CharClassPtr cc2 = createCharClassRangeWord(begin,cc->cond.range.end,cc,m,NULL,cc->right); |
df27e6cab846
CharClassMerge with Word ( no match implementation )
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
309
diff
changeset
|
218 return createCharClassRangeWord(cc->cond.range.begin,begin-1,cc,NULL,cc->left,cc2); |
143 | 219 } |
155 | 220 if (begin > cc->cond.range.end ) { // 13 |
221 if (cc->right) { | |
310
df27e6cab846
CharClassMerge with Word ( no match implementation )
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
309
diff
changeset
|
222 return createCharClassRangeWord(cc->cond.range.begin,cc->cond.range.end,cc,NULL,cc->left,charClassMerge(cc->right,begin,end,m)); |
155 | 223 } else { |
310
df27e6cab846
CharClassMerge with Word ( no match implementation )
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
309
diff
changeset
|
224 return createCharClassRangeWord(begin,end,m,NULL,cc,NULL); |
155 | 225 } |
152 | 226 } |
155 | 227 if (begin >= cc->cond.range.begin && begin <= cc->cond.range.end) { |
163 | 228 if (end > cc->cond.range.end) { // cond.range.end < end |
155 | 229 if (begin == cc->cond.range.begin) { // 8 |
310
df27e6cab846
CharClassMerge with Word ( no match implementation )
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
309
diff
changeset
|
230 CharClassPtr cc1 = mergeCCTree(cc->right,cc->cond.range.end+1,end,m); |
df27e6cab846
CharClassMerge with Word ( no match implementation )
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
309
diff
changeset
|
231 return createCharClassRangeWord(cc->cond.range.begin,cc->cond.range.end, |
df27e6cab846
CharClassMerge with Word ( no match implementation )
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
309
diff
changeset
|
232 cc,m,cc->left,cc1); |
155 | 233 } |
211
bc596e357a52
delete conditional branch in charClassMerge() (pattern 12)
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
209
diff
changeset
|
234 if (begin > cc->cond.range.begin) { // 11,12 |
310
df27e6cab846
CharClassMerge with Word ( no match implementation )
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
309
diff
changeset
|
235 CharClassPtr cc1 = mergeCCTree(cc->right,cc->cond.range.end+1,end,m); |
df27e6cab846
CharClassMerge with Word ( no match implementation )
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
309
diff
changeset
|
236 CharClassPtr cc3 = createCharClassRangeWord(cc->cond.range.begin,begin-1,cc,m,cc->left,NULL); |
df27e6cab846
CharClassMerge with Word ( no match implementation )
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
309
diff
changeset
|
237 return createCharClassRangeWord(begin,cc->cond.range.end,cc,m,cc3,cc1); |
156
b5ecfc008bcf
impl charClassMerge(not working)
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
155
diff
changeset
|
238 } |
155 | 239 } |
156
b5ecfc008bcf
impl charClassMerge(not working)
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
155
diff
changeset
|
240 } else if (begin < cc->cond.range.begin) { // 5 |
310
df27e6cab846
CharClassMerge with Word ( no match implementation )
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
309
diff
changeset
|
241 CharClassPtr cc1 = mergeCCTree(cc->left,begin,cc->cond.range.begin-1,m); |
df27e6cab846
CharClassMerge with Word ( no match implementation )
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
309
diff
changeset
|
242 CharClassPtr cc3 = mergeCCTree(cc->right,cc->cond.range.end+1,end,m); |
df27e6cab846
CharClassMerge with Word ( no match implementation )
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
309
diff
changeset
|
243 return createCharClassRangeWord(cc->cond.range.begin,cc->cond.range.end,cc,m,cc1,cc3); |
152 | 244 } else { |
245 printf("charClassMerge Error : begin %lu end %lu cc->begin %lu cc->end %lu\n", begin,end,cc->cond.range.begin,cc->cond.range.end); | |
246 } | |
247 return cc; | |
143 | 248 } |
249 | |
181
3c4db09b8581
change return value findLeftMost()
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
180
diff
changeset
|
250 void findLeftMost(CharClassPtr next,CharClassWalkerPtr walk) { |
169
313f1c176328
implement mergeTransition
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
168
diff
changeset
|
251 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
|
252 CharClassStackPtr ccs = NEW(CharClassStack); |
180
d97bcab546e8
implement getNext
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
178
diff
changeset
|
253 ccs->next = walk->stack; |
201
b8bc24abaf8a
add TODO and fix CharClassWalker
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
198
diff
changeset
|
254 ccs->turn = walk->turn; |
b8bc24abaf8a
add TODO and fix CharClassWalker
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
198
diff
changeset
|
255 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
|
256 ccs->cc = next; |
180
d97bcab546e8
implement getNext
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
178
diff
changeset
|
257 walk->stack = ccs; |
169
313f1c176328
implement mergeTransition
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
168
diff
changeset
|
258 next = next->left; |
313f1c176328
implement mergeTransition
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
168
diff
changeset
|
259 } |
201
b8bc24abaf8a
add TODO and fix CharClassWalker
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
198
diff
changeset
|
260 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
|
261 walk->next = next; |
169
313f1c176328
implement mergeTransition
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
168
diff
changeset
|
262 } |
313f1c176328
implement mergeTransition
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
168
diff
changeset
|
263 |
313f1c176328
implement mergeTransition
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
168
diff
changeset
|
264 CharClassWalkerPtr createCharClassWalker (CharClassPtr next) { |
313f1c176328
implement mergeTransition
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
168
diff
changeset
|
265 CharClassWalkerPtr walk = NEW(CharClassWalker); |
313f1c176328
implement mergeTransition
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
168
diff
changeset
|
266 walk->next = NULL; |
180
d97bcab546e8
implement getNext
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
178
diff
changeset
|
267 walk->stack = NULL; |
241
87ad91af8a15
turn initialization in charclasswalk
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
239
diff
changeset
|
268 walk->turn = LEFT; |
169
313f1c176328
implement mergeTransition
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
168
diff
changeset
|
269 if (!next) return walk; |
181
3c4db09b8581
change return value findLeftMost()
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
180
diff
changeset
|
270 findLeftMost(next,walk); |
169
313f1c176328
implement mergeTransition
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
168
diff
changeset
|
271 return walk; |
313f1c176328
implement mergeTransition
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
168
diff
changeset
|
272 } |
313f1c176328
implement mergeTransition
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
168
diff
changeset
|
273 |
313f1c176328
implement mergeTransition
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
168
diff
changeset
|
274 bool hasNext(CharClassWalkerPtr walk) { |
313f1c176328
implement mergeTransition
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
168
diff
changeset
|
275 return walk->next != NULL; |
313f1c176328
implement mergeTransition
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
168
diff
changeset
|
276 } |
313f1c176328
implement mergeTransition
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
168
diff
changeset
|
277 |
180
d97bcab546e8
implement getNext
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
178
diff
changeset
|
278 CharClassStackPtr charClassStackPop(CharClassWalkerPtr walk) { |
d97bcab546e8
implement getNext
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
178
diff
changeset
|
279 CharClassStackPtr prev = walk->stack->next; |
209
959f8c00da17
fix charClassStackPop()
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
208
diff
changeset
|
280 walk->turn = walk->stack->turn; |
180
d97bcab546e8
implement getNext
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
178
diff
changeset
|
281 free(walk->stack); |
d97bcab546e8
implement getNext
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
178
diff
changeset
|
282 walk->stack = prev; |
d97bcab546e8
implement getNext
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
178
diff
changeset
|
283 return prev; |
d97bcab546e8
implement getNext
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
178
diff
changeset
|
284 } |
d97bcab546e8
implement getNext
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
178
diff
changeset
|
285 |
169
313f1c176328
implement mergeTransition
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
168
diff
changeset
|
286 CharClassPtr getNext(CharClassWalkerPtr walk) { |
313f1c176328
implement mergeTransition
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
168
diff
changeset
|
287 CharClassPtr current = walk->next; |
180
d97bcab546e8
implement getNext
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
178
diff
changeset
|
288 walk->next = NULL; |
201
b8bc24abaf8a
add TODO and fix CharClassWalker
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
198
diff
changeset
|
289 if (walk->turn == SELF) { |
180
d97bcab546e8
implement getNext
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
178
diff
changeset
|
290 if (current->right) { |
201
b8bc24abaf8a
add TODO and fix CharClassWalker
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
198
diff
changeset
|
291 walk->turn = RIGHT; |
181
3c4db09b8581
change return value findLeftMost()
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
180
diff
changeset
|
292 findLeftMost(current->right,walk); |
180
d97bcab546e8
implement getNext
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
178
diff
changeset
|
293 return current; |
d97bcab546e8
implement getNext
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
178
diff
changeset
|
294 } |
201
b8bc24abaf8a
add TODO and fix CharClassWalker
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
198
diff
changeset
|
295 } |
b8bc24abaf8a
add TODO and fix CharClassWalker
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
198
diff
changeset
|
296 while (walk->stack) { |
b8bc24abaf8a
add TODO and fix CharClassWalker
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
198
diff
changeset
|
297 walk->next = walk->stack->cc; |
180
d97bcab546e8
implement getNext
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
178
diff
changeset
|
298 charClassStackPop(walk); |
201
b8bc24abaf8a
add TODO and fix CharClassWalker
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
198
diff
changeset
|
299 if (walk->turn == LEFT) { |
b8bc24abaf8a
add TODO and fix CharClassWalker
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
198
diff
changeset
|
300 walk->turn = SELF; |
b8bc24abaf8a
add TODO and fix CharClassWalker
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
198
diff
changeset
|
301 return current; |
b8bc24abaf8a
add TODO and fix CharClassWalker
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
198
diff
changeset
|
302 } |
254
21b9ba76f91b
remove warning
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
250
diff
changeset
|
303 } |
169
313f1c176328
implement mergeTransition
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
168
diff
changeset
|
304 return current; |
313f1c176328
implement mergeTransition
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
168
diff
changeset
|
305 } |
313f1c176328
implement mergeTransition
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
168
diff
changeset
|
306 |
182
dbe004d03ef0
implement stateAllocate()
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
181
diff
changeset
|
307 void setState(CharClassPtr cc, BitVector bi) { |
248
2b1fbfb92d54
implement tSearch
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
244
diff
changeset
|
308 // if (word case) setNext(bitVector to the word list) |
189 | 309 cc->nextState = bi; |
182
dbe004d03ef0
implement stateAllocate()
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
181
diff
changeset
|
310 if (cc->left) { |
dbe004d03ef0
implement stateAllocate()
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
181
diff
changeset
|
311 setState(cc->left,bi); |
dbe004d03ef0
implement stateAllocate()
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
181
diff
changeset
|
312 } |
dbe004d03ef0
implement stateAllocate()
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
181
diff
changeset
|
313 if (cc->right) { |
dbe004d03ef0
implement stateAllocate()
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
181
diff
changeset
|
314 setState(cc->right,bi); |
dbe004d03ef0
implement stateAllocate()
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
181
diff
changeset
|
315 } |
dbe004d03ef0
implement stateAllocate()
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
181
diff
changeset
|
316 } |
dbe004d03ef0
implement stateAllocate()
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
181
diff
changeset
|
317 |
190
3e8e5780ad4a
change node::State to State
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
189
diff
changeset
|
318 CharClassPtr mergeTransition(StatePtr x,CharClassPtr y) { |
178
5e8c6857934c
implement charClassMerge
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
177
diff
changeset
|
319 if (x->cc == NULL) { |
5e8c6857934c
implement charClassMerge
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
177
diff
changeset
|
320 return y; |
5e8c6857934c
implement charClassMerge
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
177
diff
changeset
|
321 } |
5e8c6857934c
implement charClassMerge
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
177
diff
changeset
|
322 CharClassWalkerPtr walk = createCharClassWalker(x->cc); |
5e8c6857934c
implement charClassMerge
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
177
diff
changeset
|
323 CharClassPtr ccy = y; |
208
2ec95755238e
fix mergetest
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
204
diff
changeset
|
324 while (hasNext(walk)) { |
2ec95755238e
fix mergetest
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
204
diff
changeset
|
325 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
|
326 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
|
327 unsigned long end = cc->cond.range.end; |
310
df27e6cab846
CharClassMerge with Word ( no match implementation )
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
309
diff
changeset
|
328 ccy = charClassMerge(ccy,begin,end,cc); |
169
313f1c176328
implement mergeTransition
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
168
diff
changeset
|
329 } |
313f1c176328
implement mergeTransition
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
168
diff
changeset
|
330 free(walk); |
178
5e8c6857934c
implement charClassMerge
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
177
diff
changeset
|
331 return ccy; |
169
313f1c176328
implement mergeTransition
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
168
diff
changeset
|
332 } |
313f1c176328
implement mergeTransition
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
168
diff
changeset
|
333 |
308 | 334 /* end */ |