annotate 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
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
96
b807383bcc43 add createBitVectorList.cc
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1 #include <stdio.h>
b807383bcc43 add createBitVectorList.cc
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
2 #include <stdlib.h>
101
2cc097419169 fix print
masasann
parents: 100
diff changeset
3 #include <ctype.h>
96
b807383bcc43 add createBitVectorList.cc
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
4 #include "bitVector.h"
b807383bcc43 add createBitVectorList.cc
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
5 #include "regexParser.h"
b807383bcc43 add createBitVectorList.cc
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
6
b807383bcc43 add createBitVectorList.cc
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
7 extern BitVectorPtr bitSet(int);
b807383bcc43 add createBitVectorList.cc
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
8 extern void bitPrint(BitVectorPtr);
b807383bcc43 add createBitVectorList.cc
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
9 BitVectorListPtr createBitVector(NodePtr);
104
3eb3cb5d581f implemented 'or' node translator
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents: 103
diff changeset
10 BitVectorListPtr descendTreeNode(NodePtr, BitVectorListPtr, BitVectorListPtr, bool&);
107
c9f5ee891b5e change variable of setNextBitVectorList()
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents: 105
diff changeset
11 BitVectorListPtr setNextBitVectorList(unsigned char, BitVectorListPtr, BitVectorListPtr);
96
b807383bcc43 add createBitVectorList.cc
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
12
99
1e5b56e8263b remove some variable
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents: 98
diff changeset
13 BitVectorListPtr initBvl;
96
b807383bcc43 add createBitVectorList.cc
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
14
100
804e51f19f17 implement allocateBitVectorList
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents: 99
diff changeset
15 BitVectorListPtr allocateBitVectorList() {
105
766fc2476f01 fix indent size
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents: 104
diff changeset
16 BitVectorListPtr bvl = (BitVectorListPtr)malloc(sizeof(BitVectorList));
766fc2476f01 fix indent size
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents: 104
diff changeset
17 bvl->self = bvl;
766fc2476f01 fix indent size
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents: 104
diff changeset
18 bvl->bi = (BitVectorPtr)malloc(sizeof(BitVector));
100
804e51f19f17 implement allocateBitVectorList
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents: 99
diff changeset
19
105
766fc2476f01 fix indent size
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents: 104
diff changeset
20 return bvl;
100
804e51f19f17 implement allocateBitVectorList
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents: 99
diff changeset
21 }
804e51f19f17 implement allocateBitVectorList
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents: 99
diff changeset
22
96
b807383bcc43 add createBitVectorList.cc
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
23 BitVectorListPtr createBitVector(NodePtr n,BitVectorListPtr bvl) {
105
766fc2476f01 fix indent size
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents: 104
diff changeset
24 BitVectorListPtr nextBvl = allocateBitVectorList();
766fc2476f01 fix indent size
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents: 104
diff changeset
25 nextBvl->bi = bitSet(n->nodeNumber);
766fc2476f01 fix indent size
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents: 104
diff changeset
26 nextBvl->initBvl = initBvl;
766fc2476f01 fix indent size
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents: 104
diff changeset
27 return nextBvl;
96
b807383bcc43 add createBitVectorList.cc
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
28 }
b807383bcc43 add createBitVectorList.cc
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
29
100
804e51f19f17 implement allocateBitVectorList
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents: 99
diff changeset
30
96
b807383bcc43 add createBitVectorList.cc
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
31 BitVectorListPtr initBitVector() {
105
766fc2476f01 fix indent size
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents: 104
diff changeset
32
766fc2476f01 fix indent size
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents: 104
diff changeset
33 BitVectorListPtr bvl = allocateBitVectorList();
766fc2476f01 fix indent size
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents: 104
diff changeset
34 bvl->initBvl = initBvl = bvl;
766fc2476f01 fix indent size
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents: 104
diff changeset
35 bvl->bi = bitSet(0);
100
804e51f19f17 implement allocateBitVectorList
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents: 99
diff changeset
36
105
766fc2476f01 fix indent size
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents: 104
diff changeset
37 for (int i = 0; i < 256; i++) {
766fc2476f01 fix indent size
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents: 104
diff changeset
38 bvl->next[i] = NULL;
766fc2476f01 fix indent size
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents: 104
diff changeset
39 }
100
804e51f19f17 implement allocateBitVectorList
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents: 99
diff changeset
40
105
766fc2476f01 fix indent size
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents: 104
diff changeset
41 return bvl;
96
b807383bcc43 add createBitVectorList.cc
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
42 }
b807383bcc43 add createBitVectorList.cc
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
43
101
2cc097419169 fix print
masasann
parents: 100
diff changeset
44 void printBitVectorList (BitVectorListPtr bvl) {
105
766fc2476f01 fix indent size
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents: 104
diff changeset
45 bool isFirstPrint = true;
766fc2476f01 fix indent size
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents: 104
diff changeset
46 for (int i = 0; i < 256; i++) {
766fc2476f01 fix indent size
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents: 104
diff changeset
47 if (bvl->next[i] != NULL) {
766fc2476f01 fix indent size
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents: 104
diff changeset
48 if (isFirstPrint){
766fc2476f01 fix indent size
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents: 104
diff changeset
49 puts("----");
766fc2476f01 fix indent size
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents: 104
diff changeset
50 printf(" state : "); bitPrint(bvl->bi);
766fc2476f01 fix indent size
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents: 104
diff changeset
51 isFirstPrint = false;
766fc2476f01 fix indent size
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents: 104
diff changeset
52 }
766fc2476f01 fix indent size
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents: 104
diff changeset
53 printf("input char : %c\n",i);
766fc2476f01 fix indent size
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents: 104
diff changeset
54 printf("next state : ");bitPrint(bvl->next[i]->bi);
766fc2476f01 fix indent size
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents: 104
diff changeset
55 }
104
3eb3cb5d581f implemented 'or' node translator
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents: 103
diff changeset
56 }
105
766fc2476f01 fix indent size
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents: 104
diff changeset
57
766fc2476f01 fix indent size
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents: 104
diff changeset
58 for (int i = 0; i < 256; i++) {
766fc2476f01 fix indent size
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents: 104
diff changeset
59 if (bvl->next[i] != NULL) {
766fc2476f01 fix indent size
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents: 104
diff changeset
60 printBitVectorList(bvl->next[i]);
766fc2476f01 fix indent size
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents: 104
diff changeset
61 }
104
3eb3cb5d581f implemented 'or' node translator
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents: 103
diff changeset
62 }
3eb3cb5d581f implemented 'or' node translator
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents: 103
diff changeset
63 }
3eb3cb5d581f implemented 'or' node translator
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents: 103
diff changeset
64
3eb3cb5d581f implemented 'or' node translator
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents: 103
diff changeset
65 BitVectorListPtr descendTreeNode(NodePtr n,BitVectorListPtr bvl, BitVectorListPtr prev, bool &fromOr) {
105
766fc2476f01 fix indent size
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents: 104
diff changeset
66 bool leftIsOr, rightIsOr;
107
c9f5ee891b5e change variable of setNextBitVectorList()
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents: 105
diff changeset
67 if (n->Value.character == '*') {
c9f5ee891b5e change variable of setNextBitVectorList()
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents: 105
diff changeset
68 bvl = descendTreeNode(n->left, bvl, prev, leftIsOr);
c9f5ee891b5e change variable of setNextBitVectorList()
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents: 105
diff changeset
69 unsigned char repertChar = 0;
c9f5ee891b5e change variable of setNextBitVectorList()
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents: 105
diff changeset
70 for (int i = 0; i < 256; i++) {
c9f5ee891b5e change variable of setNextBitVectorList()
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents: 105
diff changeset
71 if (prev->next[i] != NULL) repertChar = i;
c9f5ee891b5e change variable of setNextBitVectorList()
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents: 105
diff changeset
72 }
c9f5ee891b5e change variable of setNextBitVectorList()
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents: 105
diff changeset
73 setNextBitVectorList(repertChar, prev->next[repertChar], bvl); // here
c9f5ee891b5e change variable of setNextBitVectorList()
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents: 105
diff changeset
74 return prev;
105
766fc2476f01 fix indent size
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents: 104
diff changeset
75 } else if (n->Value.character == '|') {
766fc2476f01 fix indent size
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents: 104
diff changeset
76 bvl = descendTreeNode(n->left, bvl, prev, leftIsOr);
107
c9f5ee891b5e change variable of setNextBitVectorList()
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents: 105
diff changeset
77 setNextBitVectorList(n->left->Value.character, prev, bvl);
105
766fc2476f01 fix indent size
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents: 104
diff changeset
78 bvl = descendTreeNode(n->right, bvl, prev, rightIsOr);
107
c9f5ee891b5e change variable of setNextBitVectorList()
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents: 105
diff changeset
79 setNextBitVectorList(n->right->Value.character, prev, bvl);
105
766fc2476f01 fix indent size
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents: 104
diff changeset
80 fromOr = true;
766fc2476f01 fix indent size
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents: 104
diff changeset
81 return prev;
766fc2476f01 fix indent size
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents: 104
diff changeset
82 } else if (n->Value.character == '+') {
766fc2476f01 fix indent size
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents: 104
diff changeset
83 bvl = descendTreeNode(n->left, bvl, prev, leftIsOr);
107
c9f5ee891b5e change variable of setNextBitVectorList()
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents: 105
diff changeset
84 setNextBitVectorList(n->left->Value.character, prev, bvl);
105
766fc2476f01 fix indent size
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents: 104
diff changeset
85 prev = bvl;
766fc2476f01 fix indent size
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents: 104
diff changeset
86 bvl = descendTreeNode(n->right, bvl, prev, rightIsOr);
104
3eb3cb5d581f implemented 'or' node translator
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents: 103
diff changeset
87
105
766fc2476f01 fix indent size
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents: 104
diff changeset
88 if (leftIsOr){
766fc2476f01 fix indent size
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents: 104
diff changeset
89 for (int i = 0; i < 256; i++)
766fc2476f01 fix indent size
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents: 104
diff changeset
90 if (prev->next[i] != NULL)
107
c9f5ee891b5e change variable of setNextBitVectorList()
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents: 105
diff changeset
91 setNextBitVectorList(n->right->Value.character, prev->next[i], bvl);
105
766fc2476f01 fix indent size
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents: 104
diff changeset
92 }
766fc2476f01 fix indent size
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents: 104
diff changeset
93 else {
107
c9f5ee891b5e change variable of setNextBitVectorList()
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents: 105
diff changeset
94 setNextBitVectorList(n->right->Value.character, prev, bvl);
105
766fc2476f01 fix indent size
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents: 104
diff changeset
95 }
766fc2476f01 fix indent size
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents: 104
diff changeset
96
766fc2476f01 fix indent size
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents: 104
diff changeset
97 fromOr = false;
766fc2476f01 fix indent size
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents: 104
diff changeset
98 } else if (n->tokenType == 'a') {
766fc2476f01 fix indent size
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents: 104
diff changeset
99 bvl = createBitVector(n,bvl);
766fc2476f01 fix indent size
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents: 104
diff changeset
100 fromOr = false;
101
2cc097419169 fix print
masasann
parents: 100
diff changeset
101 }
105
766fc2476f01 fix indent size
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents: 104
diff changeset
102 return bvl;
101
2cc097419169 fix print
masasann
parents: 100
diff changeset
103 }
96
b807383bcc43 add createBitVectorList.cc
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
104
107
c9f5ee891b5e change variable of setNextBitVectorList()
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents: 105
diff changeset
105 BitVectorListPtr setNextBitVectorList(unsigned char inputChar, BitVectorListPtr bvl, BitVectorListPtr next){
c9f5ee891b5e change variable of setNextBitVectorList()
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents: 105
diff changeset
106 if (isalnum((int)inputChar)){
c9f5ee891b5e change variable of setNextBitVectorList()
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents: 105
diff changeset
107 bvl->next[(int)inputChar] = next;
105
766fc2476f01 fix indent size
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents: 104
diff changeset
108 }
766fc2476f01 fix indent size
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents: 104
diff changeset
109 return next;
101
2cc097419169 fix print
masasann
parents: 100
diff changeset
110 }
96
b807383bcc43 add createBitVectorList.cc
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
111
b807383bcc43 add createBitVectorList.cc
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
112 BitVectorListPtr createBitVectorList(NodePtr n) {
105
766fc2476f01 fix indent size
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents: 104
diff changeset
113 BitVectorListPtr bvl = initBitVector();
766fc2476f01 fix indent size
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents: 104
diff changeset
114 bool fromOr = false;
766fc2476f01 fix indent size
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents: 104
diff changeset
115 descendTreeNode(n, bvl, bvl, fromOr);
766fc2476f01 fix indent size
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents: 104
diff changeset
116 printBitVectorList(bvl);
766fc2476f01 fix indent size
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents: 104
diff changeset
117 return bvl;
96
b807383bcc43 add createBitVectorList.cc
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
118 }