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