view c/regexParser/subsetConstraction.cc @ 152:1c9e8ba64f6a pairPro

add implement charclassMerge (not working)
author masa
date Wed, 16 Dec 2015 17:28:53 +0900
parents d1ebba6e117a
children e2e717fbeb2f
line wrap: on
line source

#include <stdio.h>
#include <stdlib.h>
#include <ctype.h>
#include "subsetConstraction.h"

static
CharClassPtr createCharClassWord(unsigned char *w, CharClassPtr cc1, CharClassPtr cc2) {
    CharClassPtr cc = NEW(CharClass);
    return cc1;
}

CharClassPtr charClassMerge(CharClassPtr cc,unsigned long begin, unsigned long end, BitVector nextState) {
    // 重なっているccの領域を分割する
    // 必要ならばnextStateを重ねあわせる
    // 変更があった場合は新しくリストを作って返す
    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;
        }
        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) {

}

TGValue generateTransition(NodePtr n,TransitionGenerator tg) {
    if (n->tokenType == '+') {
        TGValue tgv = generateTransition(n->left,tg);
        if (tgv.asterisk) {
            TGValue tgv1 = generateTransition(n->right,tg);
            tgv.ts->state->bitContainer |= tgv1.ts->state->bitContainer;
            return tgv;
        }
        bitSet(tgv.ts->state,n->right->nodeNumber);
        return tgv;
    } else if (n->tokenType == '|') {

    } else if (n->tokenType == '*') {

    } else if (n->tokenType == 'c'){

    } else if (n->tokenType == 'a'){

    } else {
        // error
    }
}

TransitionGenerator generateTransitionList(NodePtr n) {
    TransitionGenerator tg;
    generateTransition(n,tg);
    return tg;
}