Mercurial > hg > Members > masakoha > testcode
view c/regexParser/subsetConstraction.cc @ 153:e2e717fbeb2f pairPro
fix
author | Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp> |
---|---|
date | Fri, 18 Dec 2015 14:02:41 +0900 |
parents | 1c9e8ba64f6a |
children | 1fad21fd6028 |
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 = charClassMerge(cc,cc->cond.range.begin,cc->cond.range.end,nextState); if (cc->left) { cc1->left = charClassMerge(cc->left,begin,end,nextState); return cc1; } else { CharClassPtr cc2 = charClassMerge(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 = charClassMerge(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) { // 5 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; } 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->nextState->bitContainer |= tgv1.ts->nextState->bitContainer; return tgv; } TGValue tgv1 = generateTransition(n->right,tg); tgv.ts->nextState = tgv1.ts->nextState; return tgv; } else if (n->tokenType == '|') { TGValue tgv = generateTransition(n->left,tg); TGValue tgv1 = generateTransition(n->right,tg); tgv.ts = appendTransition(tgv.ts,tgv1.ts); return tgv; } else if (n->tokenType == '*') { TGValue tgv = generateTransition(n->left,tg); tgv.asterisk = true; return tgv; } else if (n->tokenType == 'c'){ } else if (n->tokenType == 'a'){ TGValue tgv; tgv.ts = (TransitionPtr)malloc(sizeof(Transition)); tgv.ts->condition = n->cc; tgv.ts->nextState = (BitVectorPtr)malloc(sizeof(BitVector)); bitSet(tgv.ts->nextState,n->nodeNumber); tg.ts = appendTransition(tg.ts,tgv.ts); return tgv; } else { // error } } void printTransitionList(TransitionPtr ts) { for (;ts;ts = ts->next) { printf("\n"); } } TransitionGenerator generateTransitionList(NodePtr n) { TransitionGenerator tg; tg.ts = (TransitionPtr)malloc(sizeof(Transition)); generateTransition(n,tg); printTransitionList(tg.ts); return tg; }