changeset 109:6401c708f5dd impl-bitvector

fix printBitVectorList (print Loop when include asterisk node)
author Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
date Fri, 20 Nov 2015 15:19:09 +0900
parents 70069d4647a0
children a3adc5c24e19 ab1e3e45541d
files c/regexParser/bitVector.h c/regexParser/createBitVectorList.cc
diffstat 2 files changed, 17 insertions(+), 9 deletions(-) [+]
line wrap: on
line diff
--- a/c/regexParser/bitVector.h	Thu Nov 19 17:48:36 2015 +0900
+++ b/c/regexParser/bitVector.h	Fri Nov 20 15:19:09 2015 +0900
@@ -8,4 +8,6 @@
     BitVectorPtr bi;
     bitVectorList* initBvl;
     bitVectorList* next[256];
+    bool isLoopAnker;
+    bool isLoop;
 }BitVectorList, *BitVectorListPtr;
--- a/c/regexParser/createBitVectorList.cc	Thu Nov 19 17:48:36 2015 +0900
+++ b/c/regexParser/createBitVectorList.cc	Fri Nov 20 15:19:09 2015 +0900
@@ -62,38 +62,43 @@
             }
             printf("input char : %c\n",i);
             printf("next state : ");bitPrint(bvl->next[i]->bi);
+            bvl->isLoop = bvl->isLoopAnker;
         }
     }
 
     for (int i = 0; i < 256; i++) {
-        if (bvl->next[i] != NULL) {
+        if ((bvl->next[i] != NULL) && !(bvl->isLoop && bvl->isLoopAnker)) {
+        // if ((bvl->next[i] != NULL) ) {
             printBitVectorList(bvl->next[i]);
         }
     }
 }
 
-BitVectorListPtr descendTreeNode(NodePtr n,BitVectorListPtr bvl, BitVectorListPtr prev, bool &fromOr) {
+BitVectorListPtr descendTreeNode(NodePtr n,BitVectorListPtr bvl, BitVectorListPtr prev, bool &fromOr, bool &fromAsterisk) {
     bool leftIsOr, rightIsOr;
     if (n->Value.character == '*') {
-        bvl = descendTreeNode(n->left, bvl, prev, leftIsOr);
+        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, prev->next[repertChar], bvl); // here
+        setNextBitVectorList(repertChar, bvl, prev->next[repertChar]); // here
+        bvl->isLoopAnker = true;
+        fromAsterisk = true;
+
         return prev;
     } else if (n->Value.character == '|') {
-        bvl = descendTreeNode(n->left, bvl, prev, leftIsOr);
+        bvl = descendTreeNode(n->left, bvl, prev, leftIsOr, fromAsterisk);
         setNextBitVectorList(n->left->Value.character, prev, bvl);
-        bvl = descendTreeNode(n->right, bvl, prev, rightIsOr);
+        bvl = descendTreeNode(n->right, bvl, prev, rightIsOr, fromAsterisk);
         setNextBitVectorList(n->right->Value.character, prev, bvl);
         fromOr = true;
         return prev;
     } else if (n->Value.character == '+') {
-        bvl = descendTreeNode(n->left, bvl, prev, leftIsOr);
+        bvl = descendTreeNode(n->left, bvl, prev, leftIsOr, fromAsterisk);
         setNextBitVectorList(n->left->Value.character, prev, bvl);
         prev = bvl;
-        bvl = descendTreeNode(n->right, bvl, prev, rightIsOr);
+        bvl = descendTreeNode(n->right, bvl, prev, rightIsOr, fromAsterisk);
 
         if (leftIsOr){
             for (int i = 0; i < 256; i++)
@@ -122,7 +127,8 @@
 BitVectorListPtr createBitVectorList(NodePtr n) {
     BitVectorListPtr bvl = initBitVector();
     bool fromOr = false;
-    descendTreeNode(n, bvl, bvl, fromOr);
+    bool fromAsterisk = false;
+    descendTreeNode(n, bvl, bvl, fromOr, fromAsterisk);
     printBitVectorList(bvl);
     return bvl;
 }