diff regexParser/subsetConstraction.cc @ 201:b8bc24abaf8a

add TODO and fix CharClassWalker
author Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
date Sat, 26 Dec 2015 18:13:32 +0900
parents 35608dc85e83
children 39ca25ed0607
line wrap: on
line diff
--- a/regexParser/subsetConstraction.cc	Sat Dec 26 17:23:25 2015 +0900
+++ b/regexParser/subsetConstraction.cc	Sat Dec 26 18:13:32 2015 +0900
@@ -117,11 +117,13 @@
     while (next->left) {
         CharClassStackPtr ccs = NEW(CharClassStack);
         ccs->next = walk->stack;
-        ccs->turn = LEFT;
+        ccs->turn = walk->turn;
+        walk->turn = LEFT;
         ccs->cc = next;
         walk->stack = ccs;
         next = next->left;
     }
+    walk->turn = SELF;
     walk->next = next;
 }
 
@@ -130,10 +132,6 @@
     walk->next = NULL;
     walk->stack = NULL;
     if (!next) return walk;
-    if (!next->left) {
-        walk->next = next;
-        return walk;
-    }
     findLeftMost(next,walk);
     return walk;
 }
@@ -143,36 +141,32 @@
 }
 
 CharClassStackPtr charClassStackPop(CharClassWalkerPtr walk) {
-    if (!walk->stack) {
-        return NULL;
-    }
     CharClassStackPtr prev = walk->stack->next;
     free(walk->stack);
     walk->stack = prev;
+    walk->turn = prev->turn;
     return prev;
 }
 
 CharClassPtr getNext(CharClassWalkerPtr walk) {
     CharClassPtr current = walk->next;
     walk->next = NULL;
-    while (walk->stack) {
-        while (walk->stack->turn == RIGHT) {
-            if (charClassStackPop(walk) == NULL) {
-                return current;
-            }
-        }
-        if (walk->stack->turn == LEFT) {
-            walk->next = walk->stack->cc;
-            walk->stack->turn = SELF;
-            return current;
-        }
+    if (walk->turn == SELF) {
         if (current->right) {
-            walk->stack->turn = RIGHT;
+            walk->turn = RIGHT;
             findLeftMost(current->right,walk);
             return current;
         }
+    }
+    while (walk->stack) {
+        walk->next = walk->stack->cc;
         charClassStackPop(walk);
-    }
+        if (walk->turn == LEFT) {
+            walk->turn = SELF;
+            return current;
+        }
+    } 
+    walk->next = NULL;
     return current;
 }
 
@@ -229,7 +223,6 @@
 TGValue stateAllocate(NodePtr n,TGValue tgv) {
     if (n->tokenType == '+') {
         TGValue tgvLeft = stateAllocate(n->left,tgv);
-        n->left->state = createState(tgvLeft,n->left);
         if (tgvLeft.asterisk) {
             TGValue tgvRight = tgvLeft;
             tgvRight.asterisk = false;
@@ -340,12 +333,9 @@
     printf("state : %lx\n",state->bitState.bitContainer);
     long nodeNumber = 0;
     if (state->node) {
-        if (state->node->nextState) {
-            printf("node : %c %lx -> %lx\n",state->node->tokenType,
-                state->bitState.bitContainer,state->node->nextState->bitState.bitContainer);
+        printf("node : %c %lx -> %d\n",state->node->tokenType,state->bitState.bitContainer,state->node->nextStateNum);
         if (state->node->state)
             nodeNumber = state->node->state->bitState.bitContainer;
-        }
     }
     if (state->cc) {
         printCharacterClass(state->cc,nodeNumber,4);