Mercurial > hg > Members > masakoha > testcode
changeset 101:2cc097419169 impl-bitvector
fix print
author | masasann |
---|---|
date | Tue, 17 Nov 2015 06:51:12 +0900 |
parents | 804e51f19f17 |
children | 07f4761c6c58 |
files | c/regexParser/createBitVectorList.cc |
diffstat | 1 files changed, 42 insertions(+), 22 deletions(-) [+] |
line wrap: on
line diff
--- a/c/regexParser/createBitVectorList.cc Tue Nov 17 03:17:07 2015 +0900 +++ b/c/regexParser/createBitVectorList.cc Tue Nov 17 06:51:12 2015 +0900 @@ -1,5 +1,6 @@ #include <stdio.h> #include <stdlib.h> +#include <ctype.h> #include "bitVector.h" #include "regexParser.h" @@ -7,6 +8,7 @@ extern void bitPrint(BitVectorPtr); BitVectorListPtr createBitVector(NodePtr); BitVectorListPtr descendTreeNode(NodePtr,BitVectorListPtr); +BitVectorListPtr setNextBitVectorList(BitVectorListPtr bvl, BitVectorListPtr next, NodePtr n); BitVectorListPtr initBvl; @@ -19,22 +21,13 @@ } BitVectorListPtr createBitVector(NodePtr n,BitVectorListPtr bvl) { - BitVectorListPtr nextBvl = bvl->next[(int)n->Value.character] = allocateBitVectorList(); - nextBvl->self = bvl->next[(int)n->Value.character]; + // BitVectorListPtr nextBvl = bvl->next[(int)n->Value.character] = allocateBitVectorList(); + BitVectorListPtr nextBvl = allocateBitVectorList(); + // nextBvl->self = bvl->next[(int)n->Value.character]; nextBvl->bi = bitSet(n->nodeNumber); nextBvl->initBvl = initBvl; - puts("-----"); - printf(" state : "); bitPrint(bvl->bi); - for (int i = 0; i < 256; i++) { - if (bvl->next[i] != NULL) { - printf("input char : %c\n",i); - } - } - printf("next state : ");bitPrint(bvl->next[(int)n->Value.character]->bi); - puts("-----"); - - return bvl->next[(int)n->Value.character]; + return nextBvl; } @@ -51,27 +44,54 @@ return bvl; } +void printBitVectorList (BitVectorListPtr bvl) { + bool flag = true; + for (int i = 0; i < 256; i++) { + if (bvl->next[i] != NULL) { + if (flag){ + puts("----"); + printf(" state : "); bitPrint(bvl->bi); + flag = false; + } + printf("input char : %c\n",i); + printf("next state : ");bitPrint(bvl->next[i]->bi); + } + } + + for (int i = 0; i < 256; i++) { + if (bvl->next[i] != NULL) { + printBitVectorList(bvl->next[i]); + } + } +} BitVectorListPtr descendTreeNode(NodePtr n,BitVectorListPtr bvl) { - + BitVectorListPtr prev = bvl; if (n->tokenType == '*') { - bvl = descendTreeNode(n->left,bvl); - } else if (n->tokenType == '|') { - bvl = descendTreeNode(n->left,bvl); - bvl = descendTreeNode(n->parent->right,bvl); + + } else if (n->Value.character == '|') { + setNextBitVectorList(prev,descendTreeNode(n->left,bvl),n->left); + bvl = setNextBitVectorList(bvl,descendTreeNode(n->right,bvl),n->right); + } else if (n->Value.character == '+') { - bvl = descendTreeNode(n->left,bvl); - bvl = descendTreeNode(n->right,bvl); + bvl = setNextBitVectorList(prev,descendTreeNode(n->left,bvl),n->left); + bvl = setNextBitVectorList(bvl,descendTreeNode(n->right,bvl),n->right); } else if (n->tokenType == 'a') { bvl = createBitVector(n,bvl); } + return bvl; +} - return bvl; +BitVectorListPtr setNextBitVectorList(BitVectorListPtr bvl, BitVectorListPtr next, NodePtr n){ + if (isalnum((int)n->Value.character)){ + bvl->next[(int)n->Value.character] = next; + } + return next; } BitVectorListPtr createBitVectorList(NodePtr n) { BitVectorListPtr bvl = initBitVector(); descendTreeNode(n,bvl); - + printBitVectorList(bvl); return bvl; }