diff regexParser/subsetConstruction.cc @ 217:a9e3512120e2

NFA generation end
author Shinji KONO <kono@ie.u-ryukyu.ac.jp>
date Wed, 30 Dec 2015 18:37:01 +0900
parents 4852bfa85db4
children d10fa72d8f31
line wrap: on
line diff
--- a/regexParser/subsetConstruction.cc	Wed Dec 30 15:05:06 2015 +0900
+++ b/regexParser/subsetConstruction.cc	Wed Dec 30 18:37:01 2015 +0900
@@ -224,8 +224,8 @@
         TGValue tgvLeft = tgv;
         tgvLeft.endState = n->right->state;
         tgvLeft.asterisk = NULL;
-        tgvLeft = generateTransition(n->left,tgv,pass);
-        TGValue tgvRight = tgvLeft;
+        tgvLeft = generateTransition(n->left,tgvLeft,pass);
+        TGValue tgvRight = tgv;
         if (tgvLeft.asterisk) {
             n->right->state = tgv.endState;
             tgvRight.startState = tgvRight.asterisk;
@@ -237,8 +237,8 @@
         if (pass==1) {
             n->right->state = tgvRight.startState = createState(tgvRight,n->right);
         } else {
-            tgvLeft.startState = n->right->state;
-            tgvLeft.tg->stateArray[tgvLeft.startState->bitState.bitContainer] = tgvLeft.startState ;
+            tgvRight.startState = n->right->state;
+            tgvRight.tg->stateArray[tgvRight.startState->bitState.bitContainer] = tgvRight.startState ;
         }
         tgvRight = generateTransition(n->right,tgvRight,pass);
         tgvLeft.asterisk = tgvRight.asterisk;
@@ -257,11 +257,12 @@
         TGValue tgv1 = tgv;
         if (pass==1) {
             n->stateNum = tgv.startState->stateNum;
-            n->nextStateNum = tgv.endState->stateNum;
-            n->state = tgv.startState;;
+            n->state = tgv.startState;
+        } else {
+            int nextState = tgv.endState->stateNum;
+            n->nextStateNum = nextState;
             n->nextState = tgv.endState;
-        } else {
-            BitVector bi = createBitVector(n->nextStateNum);
+            BitVector bi = createBitVector(nextState);
             setState(n->cc,bi);
             tgv1.startState->cc = mergeTransition(tgv1.startState,n->cc);
         }
@@ -294,6 +295,8 @@
     StatePtr startState = tgv.startState = createState(tgv,n);
     NodePtr eof = createNode(NULL,'e',NULL,NULL,NULL);
     StatePtr endState = tgv.endState = createState(tgv,eof);
+    tgv.startState = startState;
+    tgv.endState = endState;
     tgv = generateTransition(n,tgv,1);
     printTree(n);
     if (tgv.tg->totalStateCount > BITBLOCK) {
@@ -303,6 +306,8 @@
     tgv.tg->stateArray = (StatePtr*)calloc(bi.bitContainer*2,sizeof(StatePtr*));
     tgv.tg->stateArray[startState->bitState.bitContainer] = startState;
     tgv.tg->stateArray[endState->bitState.bitContainer] = endState;
+    tgv.startState = startState;
+    tgv.endState = endState;
     tgv = generateTransition(n,tgv,2);
     return tgv;
 }