Mercurial > hg > Applications > Grep
diff c/regexParser/subsetConstraction.cc @ 137:c292c67b3100 pairPro
add generateTransitionList function
author | masa |
---|---|
date | Fri, 04 Dec 2015 20:32:09 +0900 |
parents | 166136236891 |
children | 6c258910cacb |
line wrap: on
line diff
--- a/c/regexParser/subsetConstraction.cc Fri Dec 04 19:10:00 2015 +0900 +++ b/c/regexParser/subsetConstraction.cc Fri Dec 04 20:32:09 2015 +0900 @@ -3,86 +3,35 @@ #include <ctype.h> #include "subsetConstraction.h" -void printBitVectorList (BitVectorListPtr bvl) { - bool isFirstPrint = true; - for (int i = 0; i < 256; i++) { - if (bvl->next[i] != NULL) { - if (isFirstPrint){ - puts("----"); - printf(" state : "); bitPrint(bvl->bi); - isFirstPrint = false; - } - printf("input char : %c\n",i); - printf("next state : ");bitPrint(bvl->next[i]->bi); - bvl->isLoop = bvl->isLoopAnker; +typedef struct transitionGenerator { + TransitionListPtr tl; + StatePtr state; + long stateMax; +} TransitionGenerator, *TransitionGeneratorPtr; + +typedef struct tgValue { + TransitionListPtr tl; + bool asterisk; +} TGValue, *TGValuePtr; + +TGValue generateTransitionList(NodePtr n,TransitionGeneretorPtr tg) { + + if (n->left != NULL) { + TGValue tl = generateTransitionList(n->left, tg); + } + if (n->tokenType == 'a') { + printf("%*c",d*4, ' '); + for (int i = 0; i < n->cc->cond->w->length; i++) { + putchar(n->cc->cond->w->word[i]); } + printf("(%lu)\n",n->nodeNumber); + } else if (n->tokenType == 'c') { + TGValue tl = generateTransitionList(n->cc,tg); + } else { + printf("%*c%c(%lu)\n",d*4, ' ',n->tokenType,n->nodeNumber); } - for (int i = 0; i < 256; i++) { - if ((bvl->next[i] != NULL) && !(bvl->isLoop && bvl->isLoopAnker)) { - // if ((bvl->next[i] != NULL) ) { - printBitVectorList(bvl->next[i]); - } + if (n->right != NULL) { + TGValue tl = generateTransitionList(n->right, tg); } } - -const -BitVectorListPtr descendTreeNode(NodePtr n,BitVectorListPtr bvl, BitVectorListPtr prev, bool &fromOr, bool &fromAsterisk) { - bool leftIsOr, rightIsOr; - if (n->cc->cond->character == '*') { - bvl = descendTreeNode(n->left, bvl, prev, leftIsOr, fromAsterisk); - unsigned char repertChar = 0; - for (int i = 0; i < 256; i++) { - if (prev->next[i] != NULL) repertChar = i; - } - setNextBitVectorList(repertChar, bvl, prev->next[repertChar]); // here - bvl->isLoopAnker = true; - fromAsterisk = true; - - return prev; - } else if (n->cc->cond->character == '|') { - bvl = descendTreeNode(n->left, bvl, prev, leftIsOr, fromAsterisk); - setNextBitVectorList(n->left->cc->cond->character, prev, bvl); - bvl = descendTreeNode(n->right, bvl, prev, rightIsOr, fromAsterisk); - setNextBitVectorList(n->right->cc->cond->character, prev, bvl); - fromOr = true; - return prev; - } else if (n->cc->cond->character == '+') { - bvl = descendTreeNode(n->left, bvl, prev, leftIsOr, fromAsterisk); - setNextBitVectorList(n->left->cc->cond->character, prev, bvl); - prev = bvl; - bvl = descendTreeNode(n->right, bvl, prev, rightIsOr, fromAsterisk); - - if (leftIsOr){ - for (int i = 0; i < 256; i++) - if (prev->next[i] != NULL) - setNextBitVectorList(n->right->cc->cond->character, prev->next[i], bvl); - } - else { - setNextBitVectorList(n->right->cc->cond->character, prev, bvl); - } - - fromOr = false; - } else if (n->tokenType == 'a') { - bvl = createBitVector(n,bvl); - fromOr = false; - } - return bvl; -} - -const -BitVectorListPtr setNextBitVectorList(unsigned char inputChar, BitVectorListPtr bvl, BitVectorListPtr next){ - if (isalnum((int)inputChar)){ - bvl->next[(int)inputChar] = next; - } - return next; -} - -BitVectorListPtr createBitVectorList(NodePtr n) { - BitVectorListPtr bvl = initBitVector(); - bool fromOr = false; - bool fromAsterisk = false; - descendTreeNode(n, bvl, bvl, fromOr, fromAsterisk); - printBitVectorList(bvl); - return bvl; -}