annotate c/regexParser/createBitVectorList.cc @ 103:4ad2a75dec4a impl-bitvector

fix if statement in descendTreeNode.cc
author Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
date Tue, 17 Nov 2015 19:37:29 +0900
parents 07f4761c6c58
children 3eb3cb5d581f
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);
b807383bcc43 add createBitVectorList.cc
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
10 BitVectorListPtr descendTreeNode(NodePtr,BitVectorListPtr);
101
2cc097419169 fix print
masasann
parents: 100
diff changeset
11 BitVectorListPtr setNextBitVectorList(BitVectorListPtr bvl, BitVectorListPtr next, NodePtr n);
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() {
804e51f19f17 implement allocateBitVectorList
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents: 99
diff changeset
16 BitVectorListPtr bvl = (BitVectorListPtr)malloc(sizeof(BitVectorList));
804e51f19f17 implement allocateBitVectorList
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents: 99
diff changeset
17 bvl->self = bvl;
804e51f19f17 implement allocateBitVectorList
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents: 99
diff changeset
18 bvl->bi = (BitVectorPtr)malloc(sizeof(BitVector));
804e51f19f17 implement allocateBitVectorList
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents: 99
diff changeset
19
804e51f19f17 implement allocateBitVectorList
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents: 99
diff changeset
20 return bvl;
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) {
102
07f4761c6c58 revert descendTreeNode function
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents: 101
diff changeset
24 BitVectorListPtr nextBvl = bvl->next[(int)n->Value.character] = allocateBitVectorList();
07f4761c6c58 revert descendTreeNode function
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents: 101
diff changeset
25 nextBvl->self = bvl->next[(int)n->Value.character];
98
d0d2262d4edf implement if (NodeChar == '+')
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents: 96
diff changeset
26 nextBvl->bi = bitSet(n->nodeNumber);
99
1e5b56e8263b remove some variable
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents: 98
diff changeset
27 nextBvl->initBvl = initBvl;
98
d0d2262d4edf implement if (NodeChar == '+')
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents: 96
diff changeset
28
101
2cc097419169 fix print
masasann
parents: 100
diff changeset
29 return nextBvl;
96
b807383bcc43 add createBitVectorList.cc
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
30 }
b807383bcc43 add createBitVectorList.cc
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
31
100
804e51f19f17 implement allocateBitVectorList
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents: 99
diff changeset
32
96
b807383bcc43 add createBitVectorList.cc
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
33 BitVectorListPtr initBitVector() {
100
804e51f19f17 implement allocateBitVectorList
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents: 99
diff changeset
34
804e51f19f17 implement allocateBitVectorList
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents: 99
diff changeset
35 BitVectorListPtr bvl = allocateBitVectorList();
804e51f19f17 implement allocateBitVectorList
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents: 99
diff changeset
36 bvl->initBvl = initBvl = bvl;
98
d0d2262d4edf implement if (NodeChar == '+')
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents: 96
diff changeset
37 bvl->bi = bitSet(0);
100
804e51f19f17 implement allocateBitVectorList
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents: 99
diff changeset
38
804e51f19f17 implement allocateBitVectorList
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents: 99
diff changeset
39 for (int i = 0; i < 256; i++) {
804e51f19f17 implement allocateBitVectorList
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents: 99
diff changeset
40 bvl->next[i] = NULL;
804e51f19f17 implement allocateBitVectorList
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents: 99
diff changeset
41 }
804e51f19f17 implement allocateBitVectorList
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents: 99
diff changeset
42
96
b807383bcc43 add createBitVectorList.cc
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
43 return bvl;
b807383bcc43 add createBitVectorList.cc
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
44 }
b807383bcc43 add createBitVectorList.cc
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
45
101
2cc097419169 fix print
masasann
parents: 100
diff changeset
46 void printBitVectorList (BitVectorListPtr bvl) {
102
07f4761c6c58 revert descendTreeNode function
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents: 101
diff changeset
47 bool initPrintFlag = true;
101
2cc097419169 fix print
masasann
parents: 100
diff changeset
48 for (int i = 0; i < 256; i++) {
2cc097419169 fix print
masasann
parents: 100
diff changeset
49 if (bvl->next[i] != NULL) {
102
07f4761c6c58 revert descendTreeNode function
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents: 101
diff changeset
50 if (initPrintFlag) {
07f4761c6c58 revert descendTreeNode function
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents: 101
diff changeset
51 puts("----");
07f4761c6c58 revert descendTreeNode function
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents: 101
diff changeset
52 printf(" state : "); bitPrint(bvl->bi);
07f4761c6c58 revert descendTreeNode function
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents: 101
diff changeset
53 initPrintFlag = false;
07f4761c6c58 revert descendTreeNode function
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents: 101
diff changeset
54 }
101
2cc097419169 fix print
masasann
parents: 100
diff changeset
55 printf("input char : %c\n",i);
102
07f4761c6c58 revert descendTreeNode function
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents: 101
diff changeset
56 printf("next state : "); bitPrint(bvl->next[i]->bi);
101
2cc097419169 fix print
masasann
parents: 100
diff changeset
57 }
2cc097419169 fix print
masasann
parents: 100
diff changeset
58 }
2cc097419169 fix print
masasann
parents: 100
diff changeset
59
2cc097419169 fix print
masasann
parents: 100
diff changeset
60 for (int i = 0; i < 256; i++) {
2cc097419169 fix print
masasann
parents: 100
diff changeset
61 if (bvl->next[i] != NULL) {
2cc097419169 fix print
masasann
parents: 100
diff changeset
62 printBitVectorList(bvl->next[i]);
2cc097419169 fix print
masasann
parents: 100
diff changeset
63 }
2cc097419169 fix print
masasann
parents: 100
diff changeset
64 }
2cc097419169 fix print
masasann
parents: 100
diff changeset
65 }
96
b807383bcc43 add createBitVectorList.cc
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
66
b807383bcc43 add createBitVectorList.cc
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
67 BitVectorListPtr descendTreeNode(NodePtr n,BitVectorListPtr bvl) {
102
07f4761c6c58 revert descendTreeNode function
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents: 101
diff changeset
68
103
4ad2a75dec4a fix if statement in descendTreeNode.cc
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents: 102
diff changeset
69 if (n->Value.character == '*') {
102
07f4761c6c58 revert descendTreeNode function
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents: 101
diff changeset
70 bvl = descendTreeNode(n->left,bvl);
103
4ad2a75dec4a fix if statement in descendTreeNode.cc
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents: 102
diff changeset
71 } else if (n->Value.character == '|') {
102
07f4761c6c58 revert descendTreeNode function
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents: 101
diff changeset
72 bvl = descendTreeNode(n->left,bvl);
07f4761c6c58 revert descendTreeNode function
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents: 101
diff changeset
73 bvl = descendTreeNode(n->parent->right,bvl);
96
b807383bcc43 add createBitVectorList.cc
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
74 } else if (n->Value.character == '+') {
102
07f4761c6c58 revert descendTreeNode function
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents: 101
diff changeset
75 bvl = descendTreeNode(n->left,bvl);
07f4761c6c58 revert descendTreeNode function
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents: 101
diff changeset
76 bvl = descendTreeNode(n->right,bvl);
98
d0d2262d4edf implement if (NodeChar == '+')
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents: 96
diff changeset
77 } else if (n->tokenType == 'a') {
d0d2262d4edf implement if (NodeChar == '+')
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents: 96
diff changeset
78 bvl = createBitVector(n,bvl);
96
b807383bcc43 add createBitVectorList.cc
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
79 }
101
2cc097419169 fix print
masasann
parents: 100
diff changeset
80 return bvl;
2cc097419169 fix print
masasann
parents: 100
diff changeset
81 }
96
b807383bcc43 add createBitVectorList.cc
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
82
b807383bcc43 add createBitVectorList.cc
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
83 BitVectorListPtr createBitVectorList(NodePtr n) {
b807383bcc43 add createBitVectorList.cc
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
84 BitVectorListPtr bvl = initBitVector();
b807383bcc43 add createBitVectorList.cc
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
85 descendTreeNode(n,bvl);
101
2cc097419169 fix print
masasann
parents: 100
diff changeset
86 printBitVectorList(bvl);
96
b807383bcc43 add createBitVectorList.cc
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
87 return bvl;
b807383bcc43 add createBitVectorList.cc
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
88 }