Mercurial > hg > Members > masakoha > testcode
view c/regexParser/createBitVectorList.cc @ 107:c9f5ee891b5e impl-bitvector
change variable of setNextBitVectorList()
author | Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp> |
---|---|
date | Thu, 19 Nov 2015 17:23:06 +0900 |
parents | 766fc2476f01 |
children | 70069d4647a0 |
line wrap: on
line source
#include <stdio.h> #include <stdlib.h> #include <ctype.h> #include "bitVector.h" #include "regexParser.h" extern BitVectorPtr bitSet(int); extern void bitPrint(BitVectorPtr); BitVectorListPtr createBitVector(NodePtr); BitVectorListPtr descendTreeNode(NodePtr, BitVectorListPtr, BitVectorListPtr, bool&); BitVectorListPtr setNextBitVectorList(unsigned char, BitVectorListPtr, BitVectorListPtr); BitVectorListPtr initBvl; BitVectorListPtr allocateBitVectorList() { BitVectorListPtr bvl = (BitVectorListPtr)malloc(sizeof(BitVectorList)); bvl->self = bvl; bvl->bi = (BitVectorPtr)malloc(sizeof(BitVector)); return bvl; } BitVectorListPtr createBitVector(NodePtr n,BitVectorListPtr bvl) { BitVectorListPtr nextBvl = allocateBitVectorList(); nextBvl->bi = bitSet(n->nodeNumber); nextBvl->initBvl = initBvl; return nextBvl; } BitVectorListPtr initBitVector() { BitVectorListPtr bvl = allocateBitVectorList(); bvl->initBvl = initBvl = bvl; bvl->bi = bitSet(0); for (int i = 0; i < 256; i++) { bvl->next[i] = NULL; } return bvl; } void printBitVectorList (BitVectorListPtr bvl) { bool isFirstPrint = true; for (int i = 0; i < 256; i++) { if (bvl->next[i] != NULL) { if (isFirstPrint){ puts("----"); printf(" state : "); bitPrint(bvl->bi); isFirstPrint = 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, bool &fromOr) { bool leftIsOr, rightIsOr; if (n->Value.character == '*') { bvl = descendTreeNode(n->left, bvl, prev, leftIsOr); unsigned char repertChar = 0; for (int i = 0; i < 256; i++) { if (prev->next[i] != NULL) repertChar = i; } setNextBitVectorList(repertChar, prev->next[repertChar], bvl); // here return prev; } else if (n->Value.character == '|') { bvl = descendTreeNode(n->left, bvl, prev, leftIsOr); setNextBitVectorList(n->left->Value.character, prev, bvl); bvl = descendTreeNode(n->right, bvl, prev, rightIsOr); setNextBitVectorList(n->right->Value.character, prev, bvl); fromOr = true; return prev; } else if (n->Value.character == '+') { bvl = descendTreeNode(n->left, bvl, prev, leftIsOr); setNextBitVectorList(n->left->Value.character, prev, bvl); prev = bvl; bvl = descendTreeNode(n->right, bvl, prev, rightIsOr); if (leftIsOr){ for (int i = 0; i < 256; i++) if (prev->next[i] != NULL) setNextBitVectorList(n->right->Value.character, prev->next[i], bvl); } else { setNextBitVectorList(n->right->Value.character, prev, bvl); } fromOr = false; } else if (n->tokenType == 'a') { bvl = createBitVector(n,bvl); fromOr = false; } return bvl; } BitVectorListPtr setNextBitVectorList(unsigned char inputChar, BitVectorListPtr bvl, BitVectorListPtr next){ if (isalnum((int)inputChar)){ bvl->next[(int)inputChar] = next; } return next; } BitVectorListPtr createBitVectorList(NodePtr n) { BitVectorListPtr bvl = initBitVector(); bool fromOr = false; descendTreeNode(n, bvl, bvl, fromOr); printBitVectorList(bvl); return bvl; }