Mercurial > hg > Members > masakoha > testcode
changeset 144:d8a4922eceae pairPro
remove some errors (not working)
author | Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp> |
---|---|
date | Mon, 14 Dec 2015 17:14:33 +0900 |
parents | 32977f5a2ed0 |
children | 50217a0545e8 |
files | c/regexParser/bitVector.h c/regexParser/main.cc c/regexParser/node.cc c/regexParser/regexParser.cc c/regexParser/regexParser.h c/regexParser/subsetConstraction.cc c/regexParser/subsetConstraction.h c/regexParser/transition.h |
diffstat | 8 files changed, 56 insertions(+), 78 deletions(-) [+] |
line wrap: on
line diff
--- a/c/regexParser/bitVector.h Fri Dec 11 15:04:58 2015 +0900 +++ b/c/regexParser/bitVector.h Mon Dec 14 17:14:33 2015 +0900 @@ -1,10 +1,6 @@ #include "regexParser.h" #define BITBLOCK 64 -typedef struct bitVector { - unsigned long bitContainer; -}BitVector,*BitVectorPtr; - BitVectorPtr createBitVector(NodePtr n); const BitVectorPtr allocateBitVector(); void bitSet(BitVectorPtr bi, int bitSetPosition);
--- a/c/regexParser/main.cc Fri Dec 11 15:04:58 2015 +0900 +++ b/c/regexParser/main.cc Mon Dec 14 17:14:33 2015 +0900 @@ -22,6 +22,5 @@ printf("regex : %s\n",ri->ptr); NodePtr n = regex(ri); printTree(n); - TransitionGeneratorPtr tg = generateTransitionList(n); return 0; }
--- a/c/regexParser/node.cc Fri Dec 11 15:04:58 2015 +0900 +++ b/c/regexParser/node.cc Mon Dec 14 17:14:33 2015 +0900 @@ -4,8 +4,8 @@ static void printCharacterClass(CharClassPtr cc, long nodeNumber,int d) { if (cc->type == 'r') { printf("%*c",d*4, ' '); - for (RangeListPtr range = cc->cond->range; range; range = range->next) { - printf("[%c-%c] ",*range->begin,*range->end); + for (RangeList range = cc->cond.range; range.begin != 0; range = *range.next) { + printf("[%c-%c] ",(unsigned char)range.begin,(unsigned char)range.end); } printf("(%lu)\n",nodeNumber); } @@ -19,8 +19,8 @@ } if (n->tokenType == 'a') { printf("%*c",d*4, ' '); - for (int i = 0; i < n->cc->cond->w->length; i++) { - putchar(n->cc->cond->w->word[i]); + for (int i = 0; i < n->cc->cond.w.length; i++) { + putchar(n->cc->cond.w.word[i]); } printf("(%lu)\n",n->nodeNumber); } else if (n->tokenType == 'c') {
--- a/c/regexParser/regexParser.cc Fri Dec 11 15:04:58 2015 +0900 +++ b/c/regexParser/regexParser.cc Mon Dec 14 17:14:33 2015 +0900 @@ -3,7 +3,6 @@ #include <string.h> #include <ctype.h> #include "regexParser.h" -#include "error.h" static NodePtr charClass(RegexInfoPtr); static void token(RegexInfoPtr); @@ -27,18 +26,6 @@ } static -CharClassPtr createCharClassWord(RegexInfoPtr ri) { - CharClassPtr cc = NEW(CharClass); - cc->type = 'a'; - cc->cond.w.word = ri->tokenValue; - cc->cond.w.length = ri->ptr - ri->tokenValue; - cc->nextState.bitContainer = 0; - token(ri); - - return cc; -} - -static NodePtr createNode(RegexInfoPtr ri,unsigned char type,CharClassPtr cc, NodePtr left, NodePtr right) { NodePtr n = allocateNode(); @@ -52,24 +39,18 @@ return n; } +CharClassPtr createCharClassWord(RegexInfoPtr ri) { + CharClassPtr cc = NEW(CharClass); + cc->type = 'a'; + cc->cond.w.word = ri->tokenValue; + cc->cond.w.length = ri->ptr - ri->tokenValue; + cc->nextState.bitContainer = 0; + return cc; +} + CharClassPtr charClassMerge(CharClassPtr cc, unsigned char begin, unsigned char end, CharClassPtr next) { - 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 (src->cond->w.word[0] < add->end) { - } else if (src->type == 'c') { - - } + CharClassPtr cc1 = NEW(CharClass); + return cc1; } // <charClass> ::= '['<literal>'-'<literal>']' @@ -80,24 +61,24 @@ cc->type = 'r'; cc->nextState.bitContainer = 0; RangeListPtr rangeList = &cc->cond.range; - rangeList->begin = ri->ptr; - rangeList->end = ri->ptr; + rangeList->begin = (unsigned long)*ri->ptr; + rangeList->end = (unsigned long)*ri->ptr; for (ri->ptr++; *ri->ptr && *ri->ptr != ']'; ri->ptr++) { if (*ri->ptr == '-') { - rangeList->end = ri->ptr + 1; + rangeList->end = (unsigned long)(ri->ptr + 1); ri->ptr++; continue; } if (ri->ptr[0] == 0 || ri->ptr[0] == ']') break; - if (ri->ptr[0] == rangeList->end[0] + 1) { - rangeList->end = ri->ptr; + if (ri->ptr[0] == rangeList->end + 1) { + rangeList->end = (unsigned long)ri->ptr; continue; } rangeList->next = NEW(RangeList); rangeList = rangeList->next; - rangeList->begin = ri->ptr; - rangeList->end = ri->ptr; + rangeList->begin = (unsigned long)ri->ptr; + rangeList->end = (unsigned long)ri->ptr; rangeList->next = NULL; } // TODO literal support @@ -111,6 +92,7 @@ static NodePtr literal(RegexInfoPtr ri) { CharClassPtr cc = createCharClassWord(ri); + token(ri); NodePtr n = createNode(ri,'a',cc,0,0); return n; }
--- a/c/regexParser/regexParser.h Fri Dec 11 15:04:58 2015 +0900 +++ b/c/regexParser/regexParser.h Mon Dec 14 17:14:33 2015 +0900 @@ -2,6 +2,10 @@ #define NEW(type) (type*)malloc(sizeof(type)) +typedef struct bitVector { + unsigned long bitContainer; +}BitVector,*BitVectorPtr; + typedef struct word { unsigned char *word; int length;
--- a/c/regexParser/subsetConstraction.cc Fri Dec 11 15:04:58 2015 +0900 +++ b/c/regexParser/subsetConstraction.cc Mon Dec 14 17:14:33 2015 +0900 @@ -3,6 +3,11 @@ #include <ctype.h> #include "subsetConstraction.h" +static +CharClassPtr createCharClassWord(unsigned char *w, CharClassPtr cc1, CharClassPtr cc2) { + return cc1; +} + CharClassPtr charClassMerge(CharClassPtr src, CharClassPtr add) { // 重なっているccの領域を分割する // 必要ならばnextStateを重ねあわせる @@ -11,56 +16,48 @@ 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); + 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 (src->cond->w.word[0] < add->end) { + } else if (src->cond.w.word[0] < add->cond.range.end) { + + } + } } else if (src->type == 'c') { } } void printTransition(TransitionPtr ts) { - for (;;) { - printf("Input Condition : %c\n",ts->condition->cond->w->word); - printf("Next State : "); bitPrint(ts->nextState); printf("\n"); - if (ts->next == NULL) break; - ts = ts->next; - } + } 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.state |= tgv1.state; + tgv.ts->state->bitContainer |= tgv1.ts->state->bitContainer; return tgv; } - tgv.state = n->right->nodeNumber; + bitSet(tgv.ts->state,n->right->nodeNumber); return tgv; } else if (n->tokenType == '|') { - tgv0 = generateTransition(n->left,tg); - tgv1 = generateTransition(n->right,tg); - tg->state->transition = appendTransition(tgv0->ts,tgv1->ts); + } else if (n->tokenType == '*') { - tgv0 = generateTransition(n->left,tg); - tgv0->asterisk = true; + + } else if (n->tokenType == 'c'){ + + } else if (n->tokenType == 'a'){ + } else { - tgv0 = (TGValuePtr)malloc(sizeof(TGValue)); - BitVectorPtr bi = createBitVector(n); - tgv0->ts = createTransition(n->cc,bi); - tgv0->asterisk = false; + // error } - - return tgv0; } StatePtr createStateList(NodePtr n) { @@ -73,7 +70,7 @@ BitVectorPtr bi = createBitVector(n); StatePtr s1 = createState(bi,0,0); } else if (n->tokenType == '+' || n->tokenType == '|') { - + } if (n->right != NULL) { @@ -82,10 +79,9 @@ return s0; } -TransitionGeneratorPtr generateTransitionList(NodePtr n) { - TransitionGeneratorPtr tg = (TransitionGeneratorPtr)malloc(sizeof(TransitionGenerator)); - int d = 0; - tg->state = createStateList(n); +TransitionGenerator generateTransitionList(NodePtr n) { + TransitionGenerator tg; + tg.state = createStateList(n); generateTransition(n,tg); return tg; }
--- a/c/regexParser/subsetConstraction.h Fri Dec 11 15:04:58 2015 +0900 +++ b/c/regexParser/subsetConstraction.h Mon Dec 14 17:14:33 2015 +0900 @@ -12,6 +12,6 @@ } TGValue, *TGValuePtr; void printTransition(TransitionPtr ts); -TGValuePtr generateTransition(NodePtr n,TransitionGeneratorPtr tg); +TGValue generateTransition(NodePtr n,TransitionGenerator tg); StatePtr createStateList(NodePtr n); -TransitionGeneratorPtr generateTransitionList(NodePtr n); +TransitionGenerator generateTransitionList(NodePtr n);