Mercurial > hg > Members > masakoha > testcode
comparison regexParser/subsetConstraction.cc @ 178:5e8c6857934c pairPro
implement charClassMerge
author | Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp> |
---|---|
date | Wed, 23 Dec 2015 19:17:36 +0900 |
parents | 8de9a33f6ae5 |
children | d97bcab546e8 |
comparison
equal
deleted
inserted
replaced
177:8de9a33f6ae5 | 178:5e8c6857934c |
---|---|
157 walk->next = ret; | 157 walk->next = ret; |
158 } | 158 } |
159 return current; | 159 return current; |
160 } | 160 } |
161 | 161 |
162 TransitionPtr mergeTransition(TransitionPtr x,TransitionPtr y) { | 162 CharClassPtr mergeTransition(StatePtr x,CharClassPtr y) { |
163 CharClassWalkerPtr walk = createCharClassWalker(x->condition); | 163 if (x->cc == NULL) { |
164 CharClassPtr ccy = y->condition; | 164 return y; |
165 } | |
166 CharClassWalkerPtr walk = createCharClassWalker(x->cc); | |
167 CharClassPtr ccy = y; | |
165 BitVector bi; | 168 BitVector bi; |
166 for (CharClassPtr cc = getNext(walk); hasNext(walk); cc=getNext(walk)) { | 169 for (CharClassPtr cc = getNext(walk); hasNext(walk); cc=getNext(walk)) { |
167 unsigned long begin = cc->cond.range.begin; | 170 unsigned long begin = cc->cond.range.begin; |
168 unsigned long end = cc->cond.range.end; | 171 unsigned long end = cc->cond.range.end; |
169 bi = cc->nextState; | 172 bi = cc->nextState; |
170 ccy = charClassMerge(ccy,begin,end,bi); | 173 ccy = charClassMerge(ccy,begin,end,bi); |
171 } | 174 } |
172 TransitionPtr z = createTransition(ccy,&bi); | |
173 free(walk); | 175 free(walk); |
174 return z; | 176 return ccy; |
175 } | 177 } |
176 | 178 |
177 TGValue generateTransition(NodePtr n,TransitionGenerator tg) { | 179 TGValue generateTransition(NodePtr n,TGValue tg) { |
178 TGValue tgv2; | 180 TGValue tgv2; |
179 if (n->tokenType == '+') { | 181 if (n->tokenType == '+') { |
180 TGValue tgv = generateTransition(n->right,tg); | 182 TGValue tgv = generateTransition(n->right,tg); |
181 TGValue tgv1 = generateTransition(n->left,tg); | |
182 if (tgv.asterisk) { | 183 if (tgv.asterisk) { |
183 tgv1.ts = mergeTransition(tgv.ts,tgv1.ts); | 184 TGValue tgv1 = generateTransition(n->left,tgv); |
184 return tgv1; | 185 return tgv1; |
185 } | 186 } |
187 TGValue tgLeft = createTransitionGenerator(tgv); | |
188 TGValue tgv1 = generateTransition(n->left,tgLeft); | |
186 return tgv; | 189 return tgv; |
187 } else if (n->tokenType == '|') { | 190 } else if (n->tokenType == '|') { |
188 TGValue tgv = generateTransition(n->left,tg); | 191 TGValue tgv = generateTransition(n->left,tg); |
189 TGValue tgv1 = generateTransition(n->right,tg); | 192 TGValue tgv1 = generateTransition(n->right,tgv); |
190 tgv.tg = tgv1.tg; | 193 tgv.tg = tgv1.tg; |
191 tgv.ts = mergeTransition(tgv.ts,tgv1.ts); | |
192 tgv.asterisk |= tgv1.asterisk; | 194 tgv.asterisk |= tgv1.asterisk; |
193 return tgv; | 195 return tgv; |
194 } else if (n->tokenType == '*') { | 196 } else if (n->tokenType == '*') { |
195 TGValue tgv = generateTransition(n->left,tg); | 197 TGValue tgv = generateTransition(n->left,tg); |
196 tgv.asterisk = true; | 198 tgv.asterisk = true; |
197 return tgv; | 199 return tgv; |
198 } else if (n->tokenType == 'c'){ | 200 } else if (n->tokenType == 'c' || n->tokenType == 'a'){ |
199 tgv2.ts = createTransition(n->cc,0); | 201 TGValue tgv = tg; |
200 return tgv2; | 202 tgv.ts = mergeTransition(tgv.ts,n->cc); |
201 } else if (n->tokenType == 'a'){ | |
202 TGValue tgv; | |
203 tgv.ts = NEW(Transition); | |
204 tgv.ts->condition = n->cc; | |
205 bitSet(&tgv.ts->condition->nextState,n->nodeNumber); | |
206 tg.ts = appendTransition(tg.ts,tgv.ts); | |
207 return tgv; | 203 return tgv; |
208 } else { | 204 } else { |
209 // error | 205 // error |
210 } | 206 } |
211 return tgv2; | 207 return tgv2; |