Mercurial > hg > Applications > Grep
comparison regexParser/subsetConstraction.cc @ 190:3e8e5780ad4a pairPro
change node::State to State
author | Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp> |
---|---|
date | Fri, 25 Dec 2015 15:30:52 +0900 |
parents | fccf7941ecc2 |
children | 02031fb73af8 |
comparison
equal
deleted
inserted
replaced
189:fccf7941ecc2 | 190:3e8e5780ad4a |
---|---|
1 #include <stdio.h> | 1 #include <stdio.h> |
2 #include <stdlib.h> | 2 #include <stdlib.h> |
3 #include <ctype.h> | 3 #include <ctype.h> |
4 #include "subsetConstraction.h" | 4 #include "subsetConstraction.h" |
5 #include "node.h" | |
5 | 6 |
6 CharClassPtr createCharClassWord(unsigned char *w, CharClassPtr cc1, CharClassPtr cc2) { | 7 CharClassPtr createCharClassWord(unsigned char *w, CharClassPtr cc1, CharClassPtr cc2) { |
7 CharClassPtr cc = NEW(CharClass); | 8 CharClassPtr cc = NEW(CharClass); |
8 return cc; | 9 return cc; |
9 } | 10 } |
184 if (cc->right) { | 185 if (cc->right) { |
185 setState(cc->right,bi); | 186 setState(cc->right,bi); |
186 } | 187 } |
187 } | 188 } |
188 | 189 |
189 CharClassPtr mergeTransition(node::StatePtr x,CharClassPtr y) { | 190 CharClassPtr mergeTransition(StatePtr x,CharClassPtr y) { |
190 if (x->cc == NULL) { | 191 if (x->cc == NULL) { |
191 return y; | 192 return y; |
192 } | 193 } |
193 CharClassWalkerPtr walk = createCharClassWalker(x->cc); | 194 CharClassWalkerPtr walk = createCharClassWalker(x->cc); |
194 CharClassPtr ccy = y; | 195 CharClassPtr ccy = y; |
206 /** | 207 /** |
207 作成する state を linked list | 208 作成する state を linked list |
208 bitvector を index とした配列に BitVectorPtr を格納 | 209 bitvector を index とした配列に BitVectorPtr を格納 |
209 state に対応する NodePtr を | 210 state に対応する NodePtr を |
210 */ | 211 */ |
211 node::StatePtr createState(TGValue tg,NodePtr n) { | 212 StatePtr createState(TGValue tg,NodePtr n) { |
212 node::StatePtr s = NEW(node::State); | 213 StatePtr s = NEW(State); |
213 s->next = tg.tg->currentState; | 214 s->next = tg.tg->currentState; |
214 tg.tg->currentState = s; | 215 tg.tg->currentState = s; |
215 s->node = n; | 216 s->node = n; |
216 BitVector bi = createBitVector(n->stateNum); | 217 BitVector bi = createBitVector(n->stateNum); |
217 s->bitState = bi; | 218 s->bitState = bi; |
271 tgRight.asterisk = false; | 272 tgRight.asterisk = false; |
272 tgRight = generateTransition(n->right,tgRight); | 273 tgRight = generateTransition(n->right,tgRight); |
273 tgRight.asterisk = true; | 274 tgRight.asterisk = true; |
274 return tgRight; | 275 return tgRight; |
275 } | 276 } |
276 node::StatePtr left = tg.tgState; | 277 StatePtr left = tg.tgState; |
277 tg.tgState = n->left->state; | 278 tg.tgState = n->left->state; |
278 // tg.tg->stateArray[tg.tgState->bitState.bitContainer] = tg.tgState; | 279 // tg.tg->stateArray[tg.tgState->bitState.bitContainer] = tg.tgState; |
279 TGValue tgLeft = generateTransition(n->left,tg); | 280 TGValue tgLeft = generateTransition(n->left,tg); |
280 tg.tgState = left; | 281 tg.tgState = left; |
281 TGValue tgv1 = generateTransition(n->right,tgLeft); | 282 TGValue tgv1 = generateTransition(n->right,tgLeft); |
302 | 303 |
303 TransitionGeneratorPtr createTransitionGenerator() { | 304 TransitionGeneratorPtr createTransitionGenerator() { |
304 TransitionGeneratorPtr tg = NEW(TransitionGenerator); | 305 TransitionGeneratorPtr tg = NEW(TransitionGenerator); |
305 tg->stateMax = 0; | 306 tg->stateMax = 0; |
306 tg->stack = NULL; | 307 tg->stack = NULL; |
307 tg->state = NEW(node::State); | 308 tg->state = NEW(State); |
308 tg->stateArray = NULL; | 309 tg->stateArray = NULL; |
309 tg->currentState = NULL; | 310 tg->currentState = NULL; |
310 return tg; | 311 return tg; |
311 } | 312 } |
312 | 313 |
320 tgv.tg->endState = createState(tgv,eof); | 321 tgv.tg->endState = createState(tgv,eof); |
321 tgv.stateBegin = 0; | 322 tgv.stateBegin = 0; |
322 tgv.stateEnd = 1; | 323 tgv.stateEnd = 1; |
323 stateAllocate(n,tgv); | 324 stateAllocate(n,tgv); |
324 tgv.tg->stateMax = tg->stateMax; | 325 tgv.tg->stateMax = tg->stateMax; |
325 tgv.tg->stateArray = (node::StatePtr)calloc(tg->stateMax,sizeof(node::StatePtr)); | 326 BitVector bi = createBitVector(tg->stateMax); |
327 tgv.tg->stateArray = (StatePtr)calloc(bi.bitContainer*2,sizeof(StatePtr)); | |
326 generateTransition(n,tgv); | 328 generateTransition(n,tgv); |
327 return tg; | 329 return tg; |
328 } | 330 } |
331 | |
332 void printState(StatePtr state) { | |
333 printf("state : %lx\n",state->bitState.bitContainer); | |
334 long nodeNumber = 0; | |
335 if (state->node) { | |
336 printf("node : %c %d -> %d\n",state->node->tokenType,state->node->stateNum,state->node->nextStateNum); | |
337 nodeNumber = state->node->stateNum; | |
338 } | |
339 printCharacterClass(state->cc,nodeNumber,4); | |
340 } | |
341 | |
342 void printState(TransitionGeneratorPtr tg) { | |
343 StatePtr state = tg->currentState; | |
344 for (;state;state = state->next) { | |
345 printState(state); | |
346 putchar('\n'); | |
347 } | |
348 } |