Mercurial > hg > Members > masakoha > testcode
annotate c/regexParser/createBitVectorList.cc @ 101:2cc097419169 impl-bitvector
fix print
author | masasann |
---|---|
date | Tue, 17 Nov 2015 06:51:12 +0900 |
parents | 804e51f19f17 |
children | 07f4761c6c58 |
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 | 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 | 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) { |
101 | 24 // BitVectorListPtr nextBvl = bvl->next[(int)n->Value.character] = allocateBitVectorList(); |
25 BitVectorListPtr nextBvl = allocateBitVectorList(); | |
26 // 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
|
27 nextBvl->bi = bitSet(n->nodeNumber); |
99
1e5b56e8263b
remove some variable
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
98
diff
changeset
|
28 nextBvl->initBvl = initBvl; |
98
d0d2262d4edf
implement if (NodeChar == '+')
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
96
diff
changeset
|
29 |
101 | 30 return nextBvl; |
96
b807383bcc43
add createBitVectorList.cc
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
31 } |
b807383bcc43
add createBitVectorList.cc
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
32 |
100
804e51f19f17
implement allocateBitVectorList
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
99
diff
changeset
|
33 |
96
b807383bcc43
add createBitVectorList.cc
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
34 BitVectorListPtr initBitVector() { |
100
804e51f19f17
implement allocateBitVectorList
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
99
diff
changeset
|
35 |
804e51f19f17
implement allocateBitVectorList
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
99
diff
changeset
|
36 BitVectorListPtr bvl = allocateBitVectorList(); |
804e51f19f17
implement allocateBitVectorList
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
99
diff
changeset
|
37 bvl->initBvl = initBvl = bvl; |
98
d0d2262d4edf
implement if (NodeChar == '+')
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
96
diff
changeset
|
38 bvl->bi = bitSet(0); |
100
804e51f19f17
implement allocateBitVectorList
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
99
diff
changeset
|
39 |
804e51f19f17
implement allocateBitVectorList
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
99
diff
changeset
|
40 for (int i = 0; i < 256; i++) { |
804e51f19f17
implement allocateBitVectorList
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
99
diff
changeset
|
41 bvl->next[i] = NULL; |
804e51f19f17
implement allocateBitVectorList
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
99
diff
changeset
|
42 } |
804e51f19f17
implement allocateBitVectorList
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
99
diff
changeset
|
43 |
96
b807383bcc43
add createBitVectorList.cc
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
44 return bvl; |
b807383bcc43
add createBitVectorList.cc
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
45 } |
b807383bcc43
add createBitVectorList.cc
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
46 |
101 | 47 void printBitVectorList (BitVectorListPtr bvl) { |
48 bool flag = true; | |
49 for (int i = 0; i < 256; i++) { | |
50 if (bvl->next[i] != NULL) { | |
51 if (flag){ | |
52 puts("----"); | |
53 printf(" state : "); bitPrint(bvl->bi); | |
54 flag = false; | |
55 } | |
56 printf("input char : %c\n",i); | |
57 printf("next state : ");bitPrint(bvl->next[i]->bi); | |
58 } | |
59 } | |
60 | |
61 for (int i = 0; i < 256; i++) { | |
62 if (bvl->next[i] != NULL) { | |
63 printBitVectorList(bvl->next[i]); | |
64 } | |
65 } | |
66 } | |
96
b807383bcc43
add createBitVectorList.cc
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
67 |
b807383bcc43
add createBitVectorList.cc
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
68 BitVectorListPtr descendTreeNode(NodePtr n,BitVectorListPtr bvl) { |
101 | 69 BitVectorListPtr prev = bvl; |
96
b807383bcc43
add createBitVectorList.cc
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
70 if (n->tokenType == '*') { |
101 | 71 |
72 } else if (n->Value.character == '|') { | |
73 setNextBitVectorList(prev,descendTreeNode(n->left,bvl),n->left); | |
74 bvl = setNextBitVectorList(bvl,descendTreeNode(n->right,bvl),n->right); | |
75 | |
96
b807383bcc43
add createBitVectorList.cc
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
76 } else if (n->Value.character == '+') { |
101 | 77 bvl = setNextBitVectorList(prev,descendTreeNode(n->left,bvl),n->left); |
78 bvl = setNextBitVectorList(bvl,descendTreeNode(n->right,bvl),n->right); | |
98
d0d2262d4edf
implement if (NodeChar == '+')
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
96
diff
changeset
|
79 } else if (n->tokenType == 'a') { |
d0d2262d4edf
implement if (NodeChar == '+')
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
96
diff
changeset
|
80 bvl = createBitVector(n,bvl); |
96
b807383bcc43
add createBitVectorList.cc
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
81 } |
101 | 82 return bvl; |
83 } | |
96
b807383bcc43
add createBitVectorList.cc
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
84 |
101 | 85 BitVectorListPtr setNextBitVectorList(BitVectorListPtr bvl, BitVectorListPtr next, NodePtr n){ |
86 if (isalnum((int)n->Value.character)){ | |
87 bvl->next[(int)n->Value.character] = next; | |
88 } | |
89 return next; | |
96
b807383bcc43
add createBitVectorList.cc
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
90 } |
b807383bcc43
add createBitVectorList.cc
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
91 |
b807383bcc43
add createBitVectorList.cc
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
92 BitVectorListPtr createBitVectorList(NodePtr n) { |
b807383bcc43
add createBitVectorList.cc
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
93 BitVectorListPtr bvl = initBitVector(); |
b807383bcc43
add createBitVectorList.cc
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
94 descendTreeNode(n,bvl); |
101 | 95 printBitVectorList(bvl); |
96
b807383bcc43
add createBitVectorList.cc
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
96 return bvl; |
b807383bcc43
add createBitVectorList.cc
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
97 } |