changeset 152:1c9e8ba64f6a pairPro

add implement charclassMerge (not working)
author masa
date Wed, 16 Dec 2015 17:28:53 +0900
parents 6ba059ce9109
children e2e717fbeb2f
files c/regexParser/Makefile c/regexParser/regexParser.cc c/regexParser/subsetConstraction.cc
diffstat 3 files changed, 45 insertions(+), 25 deletions(-) [+]
line wrap: on
line diff
--- a/c/regexParser/Makefile	Wed Dec 16 17:09:56 2015 +0900
+++ b/c/regexParser/Makefile	Wed Dec 16 17:28:53 2015 +0900
@@ -3,7 +3,7 @@
 CC= clang++
 
 SRCS_TMP = $(wildcard *.cc)
-SRCS_EXCLUDE =  determinize.cc
+SRCS_EXCLUDE =  determinize.cc subsetConstraction.cc
 SRCS = $(filter-out $(SRCS_EXCLUDE),$(SRCS_TMP))
 OBJS = $(SRCS:.cc=.o)
 
--- a/c/regexParser/regexParser.cc	Wed Dec 16 17:09:56 2015 +0900
+++ b/c/regexParser/regexParser.cc	Wed Dec 16 17:28:53 2015 +0900
@@ -88,15 +88,12 @@
 CharClassPtr insertCharClass(CharClassPtr cc, unsigned long begin, unsigned long end) {
 
     if (end < cc->cond.range.begin ) { // 1
-        CharClassPtr cc1 = createCharClassRange(cc->cond.range.begin,cc->cond.range.end,cc->left,cc->right);
         if (cc->left) {
-            cc1->left = insertCharClass(cc->left,begin,end);
-            return cc1;
+            cc->left = insertCharClass(cc->left,begin,end);
         } else {
-            CharClassPtr cc2 = createCharClassRange(begin,end,0,0);
-            cc1->left = cc2;
-            return cc1;
+            cc->left = createCharClassRange(begin,end,0,0);
         }
+        return cc;
     } else if (end == cc->cond.range.begin ) { // 2
         cc->cond.range.begin = begin;
         return cc;
--- a/c/regexParser/subsetConstraction.cc	Wed Dec 16 17:09:56 2015 +0900
+++ b/c/regexParser/subsetConstraction.cc	Wed Dec 16 17:28:53 2015 +0900
@@ -9,29 +9,52 @@
     return cc1;
 }
 
-CharClassPtr charClassMerge(CharClassPtr src, CharClassPtr add) {
+CharClassPtr charClassMerge(CharClassPtr cc,unsigned long begin, unsigned long end, BitVector nextState) {
     // 重なっているccの領域を分割する
     // 必要ならばnextStateを重ねあわせる
     // 変更があった場合は新しくリストを作って返す
-    if (src->type == 'a') {
-        if (add->type == 'a') {
-            if (src->cond.w.word[0] > add->cond.w.word[0]) {
-                // add のほうが小さいので小さい順のccをつくる
-                CharClassPtr left = charClassMerge(add->left,src);
-                return createCharClassWord(add->cond.w.word, left, add->right);
-            } else {
-
-            }
-        } else if (add->type == 'c') {
-            if (src->cond.w.word[0] < add->cond.range.begin) {
-
-            } else if (src->cond.w.word[0] < add->cond.range.end) {
-
-            }
+    if (end < cc->cond.range.begin ) { // 1
+        CharClassPtr cc1 = createCharClassRange(cc->cond.range.begin,cc->cond.range.end,cc->left,cc->right);
+        if (cc->left) {
+            cc1->left = charClassMerge(cc->left,begin,end,nextState);
+            return cc1;
+        } else {
+            CharClassPtr cc2 = createCharClassRange(begin,end,0,0);
+            cc2->nextState = nextState;
+            cc1->left = cc2;
+            return cc1;
+        }
+    } else if (end == cc->cond.range.begin ) { // 2
+        cc->cond.range.begin = begin;
+        return cc;
+    } else if (end <= cc->cond.range.end) {  // 3,4,6,7,9,10
+        if (begin < cc->cond.range.begin) {  // 3,4
+            cc->cond.range.begin = begin;
         }
-    } else if (src->type == 'c') {
-
+        return cc;
+    } else if (begin > cc->cond.range.end ) { // 13
+        if (cc->right) {
+            cc->right = charClassMerge(cc->right,begin,end);
+        } else {
+            cc->right = createCharClassRange(begin,end,0,0);
+        }
+        return cc;
     }
+    if (cc->right) {
+        CharClassPtr right = cc->right;
+        begin = cc->cond.range.begin;
+        free(cc);
+        return charClassMerge(right,begin,end);
+    }
+    if (begin >= cc->cond.range.begin && begin <= cc->cond.range.end) { // 12
+        if (end > cc->cond.range.end) cc->cond.range.end = end; // 11,8
+    } else if (begin < cc->cond.range.begin) { // 6
+        cc->cond.range.begin = begin;
+        cc->cond.range.end = end;
+    } else {
+        printf("charClassMerge Error : begin %lu end %lu cc->begin %lu cc->end %lu\n", begin,end,cc->cond.range.begin,cc->cond.range.end);
+    }
+    return cc;
 }
 
 void printTransition(TransitionPtr ts) {