annotate regexParser/subsetConstraction.cc @ 183:7ae0a3070647 pairPro

implement generateTransitionList
author Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
date Thu, 24 Dec 2015 20:02:09 +0900
parents dbe004d03ef0
children 1da1b2eacb84
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>
117
166136236891 add header files
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents: 116
diff changeset
4 #include "subsetConstraction.h"
96
b807383bcc43 add createBitVectorList.cc
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
5
144
d8a4922eceae remove some errors (not working)
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents: 143
diff changeset
6 CharClassPtr createCharClassWord(unsigned char *w, CharClassPtr cc1, CharClassPtr cc2) {
146
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents: 144
diff changeset
7 CharClassPtr cc = NEW(CharClass);
154
1fad21fd6028 remove errors and warnings
masa
parents: 153
diff changeset
8 return cc;
171
684363c44d6f remove some warning and error (not working)
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents: 170
diff changeset
9 }
168
6b31d6ef9ba4 impl createCharClassRange()
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents: 167
diff changeset
10
6b31d6ef9ba4 impl createCharClassRange()
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents: 167
diff changeset
11 CharClassPtr createCharClassRange(unsigned long begin, unsigned long end,unsigned long state, CharClassPtr left, CharClassPtr right) {
6b31d6ef9ba4 impl createCharClassRange()
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents: 167
diff changeset
12 CharClassPtr cc = NEW(CharClass);
6b31d6ef9ba4 impl createCharClassRange()
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents: 167
diff changeset
13 cc->type = 'r';
6b31d6ef9ba4 impl createCharClassRange()
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents: 167
diff changeset
14 cc->cond.range.begin = begin;
6b31d6ef9ba4 impl createCharClassRange()
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents: 167
diff changeset
15 cc->cond.range.end = end;
6b31d6ef9ba4 impl createCharClassRange()
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents: 167
diff changeset
16 cc->left = left;
6b31d6ef9ba4 impl createCharClassRange()
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents: 167
diff changeset
17 cc->right = right;
6b31d6ef9ba4 impl createCharClassRange()
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents: 167
diff changeset
18 cc->nextState.bitContainer = state;
6b31d6ef9ba4 impl createCharClassRange()
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents: 167
diff changeset
19 return cc;
144
d8a4922eceae remove some errors (not working)
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents: 143
diff changeset
20 }
d8a4922eceae remove some errors (not working)
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents: 143
diff changeset
21
166
96854eba17e5 implement mergeCCTree()
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents: 163
diff changeset
22 CharClassPtr mergeCCTree(CharClassPtr cc,unsigned char mBegin,unsigned char mEnd,BitVector nextState) {
96854eba17e5 implement mergeCCTree()
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents: 163
diff changeset
23 CharClassPtr cc1;
96854eba17e5 implement mergeCCTree()
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents: 163
diff changeset
24 if (cc) {
96854eba17e5 implement mergeCCTree()
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents: 163
diff changeset
25 cc1 = charClassMerge(cc,mBegin,mEnd,nextState);
96854eba17e5 implement mergeCCTree()
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents: 163
diff changeset
26 } else {
168
6b31d6ef9ba4 impl createCharClassRange()
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents: 167
diff changeset
27 cc1 = createCharClassRange(mBegin,mEnd,nextState.bitContainer,NULL,NULL);
166
96854eba17e5 implement mergeCCTree()
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents: 163
diff changeset
28 }
96854eba17e5 implement mergeCCTree()
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents: 163
diff changeset
29 return cc1;
96854eba17e5 implement mergeCCTree()
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents: 163
diff changeset
30 }
96854eba17e5 implement mergeCCTree()
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents: 163
diff changeset
31
152
1c9e8ba64f6a add implement charclassMerge (not working)
masa
parents: 148
diff changeset
32 CharClassPtr charClassMerge(CharClassPtr cc,unsigned long begin, unsigned long end, BitVector nextState) {
143
32977f5a2ed0 add charClassMerge
masa
parents: 142
diff changeset
33 // 重なっているccの領域を分割する
32977f5a2ed0 add charClassMerge
masa
parents: 142
diff changeset
34 // 必要ならばnextStateを重ねあわせる
32977f5a2ed0 add charClassMerge
masa
parents: 142
diff changeset
35 // 変更があった場合は新しくリストを作って返す
152
1c9e8ba64f6a add implement charclassMerge (not working)
masa
parents: 148
diff changeset
36 if (end < cc->cond.range.begin ) { // 1
1c9e8ba64f6a add implement charclassMerge (not working)
masa
parents: 148
diff changeset
37 if (cc->left) {
156
b5ecfc008bcf impl charClassMerge(not working)
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents: 155
diff changeset
38 return createCharClassRange(cc->cond.range.begin,cc->cond.range.end,charClassMerge(cc->left,begin,end,nextState),cc->right);
152
1c9e8ba64f6a add implement charclassMerge (not working)
masa
parents: 148
diff changeset
39 } else {
168
6b31d6ef9ba4 impl createCharClassRange()
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents: 167
diff changeset
40 return createCharClassRange(begin,end,nextState.bitContainer,NULL,cc);
152
1c9e8ba64f6a add implement charclassMerge (not working)
masa
parents: 148
diff changeset
41 }
163
f0a347cd9c6a fix subsetconstraction.cc
masa
parents: 157
diff changeset
42 } else if (end == cc->cond.range.begin && begin != end ) { // 2
166
96854eba17e5 implement mergeCCTree()
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents: 163
diff changeset
43 CharClassPtr cc1 = mergeCCTree(cc->left,begin,end-1,nextState);
156
b5ecfc008bcf impl charClassMerge(not working)
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents: 155
diff changeset
44 if (cc->cond.range.begin == cc->cond.range.end) {
168
6b31d6ef9ba4 impl createCharClassRange()
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents: 167
diff changeset
45 return createCharClassRange(cc->cond.range.begin,cc->cond.range.end,
6b31d6ef9ba4 impl createCharClassRange()
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents: 167
diff changeset
46 cc->nextState.bitContainer | nextState.bitContainer, cc1,cc->right);
155
6cd0141bed6c impl charClassMerge
masa
parents: 154
diff changeset
47 }
168
6b31d6ef9ba4 impl createCharClassRange()
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents: 167
diff changeset
48 CharClassPtr cc3 = createCharClassRange(cc->cond.range.begin+1,cc->cond.range.end,cc->nextState.bitContainer,cc->left,cc->right);
6b31d6ef9ba4 impl createCharClassRange()
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents: 167
diff changeset
49 return createCharClassRange(cc->cond.range.begin,cc->cond.range.begin,
6b31d6ef9ba4 impl createCharClassRange()
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents: 167
diff changeset
50 cc->nextState.bitContainer | nextState.bitContainer,cc1,cc3);
163
f0a347cd9c6a fix subsetconstraction.cc
masa
parents: 157
diff changeset
51 } else if (end < cc->cond.range.end) { // range.begin < end
155
6cd0141bed6c impl charClassMerge
masa
parents: 154
diff changeset
52 if (begin < cc->cond.range.begin) { // 3
166
96854eba17e5 implement mergeCCTree()
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents: 163
diff changeset
53 CharClassPtr cc1 = mergeCCTree(cc->left,begin,cc->cond.range.begin-1,nextState);
168
6b31d6ef9ba4 impl createCharClassRange()
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents: 167
diff changeset
54 CharClassPtr cc3 = createCharClassRange(end+1,cc->cond.range.end,cc->nextState.bitContainer,cc->left,cc->right);
6b31d6ef9ba4 impl createCharClassRange()
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents: 167
diff changeset
55 return createCharClassRange(cc->cond.range.begin,end,cc->nextState.bitContainer | nextState.bitContainer,cc1,cc3);
152
1c9e8ba64f6a add implement charclassMerge (not working)
masa
parents: 148
diff changeset
56 }
155
6cd0141bed6c impl charClassMerge
masa
parents: 154
diff changeset
57 if (begin == cc->cond.range.begin) { // 6
168
6b31d6ef9ba4 impl createCharClassRange()
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents: 167
diff changeset
58 CharClassPtr cc2 = createCharClassRange(end+1,cc->cond.range.end,cc->nextState.bitContainer,NULL,cc->right);
6b31d6ef9ba4 impl createCharClassRange()
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents: 167
diff changeset
59 return createCharClassRange(begin,end,cc->nextState.bitContainer | nextState.bitContainer,cc->left,cc2);
155
6cd0141bed6c impl charClassMerge
masa
parents: 154
diff changeset
60 }
6cd0141bed6c impl charClassMerge
masa
parents: 154
diff changeset
61 // 9
168
6b31d6ef9ba4 impl createCharClassRange()
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents: 167
diff changeset
62 CharClassPtr cc2 = createCharClassRange(cc->cond.range.begin,begin-1,cc->nextState.bitContainer,cc->left,NULL);
6b31d6ef9ba4 impl createCharClassRange()
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents: 167
diff changeset
63 CharClassPtr cc3 = createCharClassRange(end+1,cc->cond.range.end,cc->nextState.bitContainer,NULL,cc->right);
6b31d6ef9ba4 impl createCharClassRange()
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents: 167
diff changeset
64 return createCharClassRange(begin,end,cc->nextState.bitContainer | nextState.bitContainer,cc2,cc3);
155
6cd0141bed6c impl charClassMerge
masa
parents: 154
diff changeset
65 } else if (end == cc->cond.range.end) {
6cd0141bed6c impl charClassMerge
masa
parents: 154
diff changeset
66 if (begin == cc->cond.range.begin) { // 7
168
6b31d6ef9ba4 impl createCharClassRange()
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents: 167
diff changeset
67 return createCharClassRange(begin,end,cc->nextState.bitContainer | nextState.bitContainer,cc->left,cc->right);
155
6cd0141bed6c impl charClassMerge
masa
parents: 154
diff changeset
68 } else if (begin < cc->cond.range.begin) { // 4
166
96854eba17e5 implement mergeCCTree()
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents: 163
diff changeset
69 CharClassPtr cc1 = mergeCCTree(cc->left,begin,cc->cond.range.begin-1,nextState);
168
6b31d6ef9ba4 impl createCharClassRange()
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents: 167
diff changeset
70 return createCharClassRange(cc->cond.range.begin,end,cc->nextState.bitContainer | nextState.bitContainer,cc1,cc->right);
155
6cd0141bed6c impl charClassMerge
masa
parents: 154
diff changeset
71 }
163
f0a347cd9c6a fix subsetconstraction.cc
masa
parents: 157
diff changeset
72 // 10 cond.range.begin < begin
168
6b31d6ef9ba4 impl createCharClassRange()
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents: 167
diff changeset
73 CharClassPtr cc2 = createCharClassRange(begin,cc->cond.range.end,cc->nextState.bitContainer | nextState.bitContainer,NULL,cc->right);
6b31d6ef9ba4 impl createCharClassRange()
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents: 167
diff changeset
74 return createCharClassRange(cc->cond.range.begin,begin-1,cc->nextState.bitContainer,cc->left,cc2);
143
32977f5a2ed0 add charClassMerge
masa
parents: 142
diff changeset
75 }
155
6cd0141bed6c impl charClassMerge
masa
parents: 154
diff changeset
76 if (begin > cc->cond.range.end ) { // 13
6cd0141bed6c impl charClassMerge
masa
parents: 154
diff changeset
77 if (cc->right) {
156
b5ecfc008bcf impl charClassMerge(not working)
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents: 155
diff changeset
78 return createCharClassRange(cc->cond.range.begin,cc->cond.range.end,cc->left,charClassMerge(cc->right,begin,end,nextState));
155
6cd0141bed6c impl charClassMerge
masa
parents: 154
diff changeset
79 } else {
168
6b31d6ef9ba4 impl createCharClassRange()
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents: 167
diff changeset
80 return createCharClassRange(begin,end,nextState.bitContainer,cc,NULL);
155
6cd0141bed6c impl charClassMerge
masa
parents: 154
diff changeset
81 }
152
1c9e8ba64f6a add implement charclassMerge (not working)
masa
parents: 148
diff changeset
82 }
155
6cd0141bed6c impl charClassMerge
masa
parents: 154
diff changeset
83 if (begin >= cc->cond.range.begin && begin <= cc->cond.range.end) {
163
f0a347cd9c6a fix subsetconstraction.cc
masa
parents: 157
diff changeset
84 if (end > cc->cond.range.end) { // cond.range.end < end
155
6cd0141bed6c impl charClassMerge
masa
parents: 154
diff changeset
85 if (begin == cc->cond.range.begin) { // 8
166
96854eba17e5 implement mergeCCTree()
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents: 163
diff changeset
86 CharClassPtr cc1 = mergeCCTree(cc->right,cc->cond.range.end+1,end,nextState);
168
6b31d6ef9ba4 impl createCharClassRange()
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents: 167
diff changeset
87 return createCharClassRange(cc->cond.range.begin,cc->cond.range.end,
6b31d6ef9ba4 impl createCharClassRange()
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents: 167
diff changeset
88 cc->nextState.bitContainer | nextState.bitContainer,cc->left,cc1);
155
6cd0141bed6c impl charClassMerge
masa
parents: 154
diff changeset
89 }
156
b5ecfc008bcf impl charClassMerge(not working)
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents: 155
diff changeset
90 if (begin > cc->cond.range.begin) { // 11
166
96854eba17e5 implement mergeCCTree()
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents: 163
diff changeset
91 CharClassPtr cc1 = mergeCCTree(cc->right,cc->cond.range.end+1,end,nextState);
168
6b31d6ef9ba4 impl createCharClassRange()
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents: 167
diff changeset
92 CharClassPtr cc3 = createCharClassRange(cc->cond.range.begin,begin-1,cc->nextState.bitContainer,cc->left,NULL);
6b31d6ef9ba4 impl createCharClassRange()
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents: 167
diff changeset
93 return createCharClassRange(begin,cc->cond.range.end,cc->nextState.bitContainer | nextState.bitContainer,cc3,cc1);
156
b5ecfc008bcf impl charClassMerge(not working)
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents: 155
diff changeset
94 }
155
6cd0141bed6c impl charClassMerge
masa
parents: 154
diff changeset
95 }
163
f0a347cd9c6a fix subsetconstraction.cc
masa
parents: 157
diff changeset
96 // begin != end && end != cc->cond.range.end
f0a347cd9c6a fix subsetconstraction.cc
masa
parents: 157
diff changeset
97 if (begin == cc->cond.range.end) { // 12
166
96854eba17e5 implement mergeCCTree()
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents: 163
diff changeset
98 CharClassPtr cc1 = mergeCCTree(cc->right,begin+1,end,nextState);
156
b5ecfc008bcf impl charClassMerge(not working)
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents: 155
diff changeset
99 if (cc->cond.range.begin == cc->cond.range.end) {
168
6b31d6ef9ba4 impl createCharClassRange()
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents: 167
diff changeset
100 return createCharClassRange(cc->cond.range.begin,cc->cond.range.end,cc->nextState.bitContainer | nextState.bitContainer,cc1,cc->right);
156
b5ecfc008bcf impl charClassMerge(not working)
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents: 155
diff changeset
101 }
168
6b31d6ef9ba4 impl createCharClassRange()
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents: 167
diff changeset
102 CharClassPtr cc3 = createCharClassRange(cc->cond.range.begin,cc->cond.range.end-1,cc->nextState.bitContainer,cc->left,NULL);
6b31d6ef9ba4 impl createCharClassRange()
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents: 167
diff changeset
103 return createCharClassRange(cc->cond.range.end,cc->cond.range.end,cc->nextState.bitContainer | nextState.bitContainer,cc1,cc3);
155
6cd0141bed6c impl charClassMerge
masa
parents: 154
diff changeset
104 }
156
b5ecfc008bcf impl charClassMerge(not working)
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents: 155
diff changeset
105 } else if (begin < cc->cond.range.begin) { // 5
166
96854eba17e5 implement mergeCCTree()
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents: 163
diff changeset
106 CharClassPtr cc1 = mergeCCTree(cc->left,begin,cc->cond.range.begin-1,nextState);
96854eba17e5 implement mergeCCTree()
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents: 163
diff changeset
107 CharClassPtr cc3 = mergeCCTree(cc->right,cc->cond.range.end+1,end,nextState);
168
6b31d6ef9ba4 impl createCharClassRange()
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents: 167
diff changeset
108 return createCharClassRange(cc->cond.range.begin,cc->cond.range.end,cc->nextState.bitContainer | nextState.bitContainer,cc1,cc3);
152
1c9e8ba64f6a add implement charclassMerge (not working)
masa
parents: 148
diff changeset
109 } else {
1c9e8ba64f6a add implement charclassMerge (not working)
masa
parents: 148
diff changeset
110 printf("charClassMerge Error : begin %lu end %lu cc->begin %lu cc->end %lu\n", begin,end,cc->cond.range.begin,cc->cond.range.end);
1c9e8ba64f6a add implement charclassMerge (not working)
masa
parents: 148
diff changeset
111 }
1c9e8ba64f6a add implement charclassMerge (not working)
masa
parents: 148
diff changeset
112 return cc;
143
32977f5a2ed0 add charClassMerge
masa
parents: 142
diff changeset
113 }
32977f5a2ed0 add charClassMerge
masa
parents: 142
diff changeset
114
181
3c4db09b8581 change return value findLeftMost()
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents: 180
diff changeset
115 void findLeftMost(CharClassPtr next,CharClassWalkerPtr walk) {
169
313f1c176328 implement mergeTransition
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents: 168
diff changeset
116 while (next->left) {
171
684363c44d6f remove some warning and error (not working)
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents: 170
diff changeset
117 CharClassStackPtr ccs = NEW(CharClassStack);
180
d97bcab546e8 implement getNext
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents: 178
diff changeset
118 ccs->next = walk->stack;
d97bcab546e8 implement getNext
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents: 178
diff changeset
119 ccs->turn = LEFT;
171
684363c44d6f remove some warning and error (not working)
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents: 170
diff changeset
120 ccs->cc = next;
180
d97bcab546e8 implement getNext
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents: 178
diff changeset
121 walk->stack = ccs;
169
313f1c176328 implement mergeTransition
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents: 168
diff changeset
122 next = next->left;
313f1c176328 implement mergeTransition
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents: 168
diff changeset
123 }
172
540fc12871d9 remove some warnings and errors (not working)
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents: 171
diff changeset
124 walk->next = next;
169
313f1c176328 implement mergeTransition
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents: 168
diff changeset
125 }
313f1c176328 implement mergeTransition
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents: 168
diff changeset
126
313f1c176328 implement mergeTransition
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents: 168
diff changeset
127 CharClassWalkerPtr createCharClassWalker (CharClassPtr next) {
313f1c176328 implement mergeTransition
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents: 168
diff changeset
128 CharClassWalkerPtr walk = NEW(CharClassWalker);
313f1c176328 implement mergeTransition
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents: 168
diff changeset
129 walk->next = NULL;
180
d97bcab546e8 implement getNext
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents: 178
diff changeset
130 walk->stack = NULL;
169
313f1c176328 implement mergeTransition
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents: 168
diff changeset
131 if (!next) return walk;
313f1c176328 implement mergeTransition
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents: 168
diff changeset
132 if (!next->left) {
313f1c176328 implement mergeTransition
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents: 168
diff changeset
133 walk->next = next;
313f1c176328 implement mergeTransition
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents: 168
diff changeset
134 return walk;
313f1c176328 implement mergeTransition
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents: 168
diff changeset
135 }
181
3c4db09b8581 change return value findLeftMost()
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents: 180
diff changeset
136 findLeftMost(next,walk);
169
313f1c176328 implement mergeTransition
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents: 168
diff changeset
137 return walk;
313f1c176328 implement mergeTransition
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents: 168
diff changeset
138 }
313f1c176328 implement mergeTransition
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents: 168
diff changeset
139
313f1c176328 implement mergeTransition
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents: 168
diff changeset
140 bool hasNext(CharClassWalkerPtr walk) {
313f1c176328 implement mergeTransition
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents: 168
diff changeset
141 return walk->next != NULL;
313f1c176328 implement mergeTransition
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents: 168
diff changeset
142 }
313f1c176328 implement mergeTransition
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents: 168
diff changeset
143
180
d97bcab546e8 implement getNext
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents: 178
diff changeset
144 CharClassStackPtr charClassStackPop(CharClassWalkerPtr walk) {
d97bcab546e8 implement getNext
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents: 178
diff changeset
145 if (!walk->stack) {
d97bcab546e8 implement getNext
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents: 178
diff changeset
146 return NULL;
d97bcab546e8 implement getNext
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents: 178
diff changeset
147 }
d97bcab546e8 implement getNext
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents: 178
diff changeset
148 CharClassStackPtr prev = walk->stack->next;
d97bcab546e8 implement getNext
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents: 178
diff changeset
149 free(walk->stack);
d97bcab546e8 implement getNext
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents: 178
diff changeset
150 walk->stack = prev;
d97bcab546e8 implement getNext
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents: 178
diff changeset
151 return prev;
d97bcab546e8 implement getNext
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents: 178
diff changeset
152 }
d97bcab546e8 implement getNext
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents: 178
diff changeset
153
169
313f1c176328 implement mergeTransition
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents: 168
diff changeset
154 CharClassPtr getNext(CharClassWalkerPtr walk) {
313f1c176328 implement mergeTransition
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents: 168
diff changeset
155 CharClassPtr current = walk->next;
180
d97bcab546e8 implement getNext
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents: 178
diff changeset
156 walk->next = NULL;
d97bcab546e8 implement getNext
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents: 178
diff changeset
157 while (walk->stack) {
d97bcab546e8 implement getNext
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents: 178
diff changeset
158 while (walk->stack->turn == RIGHT) {
d97bcab546e8 implement getNext
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents: 178
diff changeset
159 if (charClassStackPop(walk) == NULL) {
d97bcab546e8 implement getNext
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents: 178
diff changeset
160 return current;
d97bcab546e8 implement getNext
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents: 178
diff changeset
161 }
d97bcab546e8 implement getNext
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents: 178
diff changeset
162 }
d97bcab546e8 implement getNext
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents: 178
diff changeset
163 if (walk->stack->turn == LEFT) {
d97bcab546e8 implement getNext
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents: 178
diff changeset
164 walk->next = walk->stack->cc;
181
3c4db09b8581 change return value findLeftMost()
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents: 180
diff changeset
165 walk->stack->turn = SELF;
180
d97bcab546e8 implement getNext
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents: 178
diff changeset
166 return current;
d97bcab546e8 implement getNext
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents: 178
diff changeset
167 }
d97bcab546e8 implement getNext
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents: 178
diff changeset
168 if (current->right) {
d97bcab546e8 implement getNext
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents: 178
diff changeset
169 walk->stack->turn = RIGHT;
181
3c4db09b8581 change return value findLeftMost()
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents: 180
diff changeset
170 findLeftMost(current->right,walk);
180
d97bcab546e8 implement getNext
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents: 178
diff changeset
171 return current;
d97bcab546e8 implement getNext
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents: 178
diff changeset
172 }
d97bcab546e8 implement getNext
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents: 178
diff changeset
173 charClassStackPop(walk);
169
313f1c176328 implement mergeTransition
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents: 168
diff changeset
174 }
313f1c176328 implement mergeTransition
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents: 168
diff changeset
175 return current;
313f1c176328 implement mergeTransition
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents: 168
diff changeset
176 }
313f1c176328 implement mergeTransition
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents: 168
diff changeset
177
182
dbe004d03ef0 implement stateAllocate()
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents: 181
diff changeset
178 void setState(CharClassPtr cc, BitVector bi) {
dbe004d03ef0 implement stateAllocate()
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents: 181
diff changeset
179 setState(cc,bi);
dbe004d03ef0 implement stateAllocate()
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents: 181
diff changeset
180 if (cc->left) {
dbe004d03ef0 implement stateAllocate()
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents: 181
diff changeset
181 setState(cc->left,bi);
dbe004d03ef0 implement stateAllocate()
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents: 181
diff changeset
182 }
dbe004d03ef0 implement stateAllocate()
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents: 181
diff changeset
183 cc->nextState = bi;
dbe004d03ef0 implement stateAllocate()
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents: 181
diff changeset
184 if (cc->right) {
dbe004d03ef0 implement stateAllocate()
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents: 181
diff changeset
185 setState(cc->right,bi);
dbe004d03ef0 implement stateAllocate()
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents: 181
diff changeset
186 }
dbe004d03ef0 implement stateAllocate()
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents: 181
diff changeset
187 }
dbe004d03ef0 implement stateAllocate()
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents: 181
diff changeset
188
178
5e8c6857934c implement charClassMerge
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents: 177
diff changeset
189 CharClassPtr mergeTransition(StatePtr x,CharClassPtr y) {
5e8c6857934c implement charClassMerge
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents: 177
diff changeset
190 if (x->cc == NULL) {
5e8c6857934c implement charClassMerge
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents: 177
diff changeset
191 return y;
5e8c6857934c implement charClassMerge
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents: 177
diff changeset
192 }
5e8c6857934c implement charClassMerge
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents: 177
diff changeset
193 CharClassWalkerPtr walk = createCharClassWalker(x->cc);
5e8c6857934c implement charClassMerge
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents: 177
diff changeset
194 CharClassPtr ccy = y;
172
540fc12871d9 remove some warnings and errors (not working)
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents: 171
diff changeset
195 BitVector bi;
169
313f1c176328 implement mergeTransition
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents: 168
diff changeset
196 for (CharClassPtr cc = getNext(walk); hasNext(walk); cc=getNext(walk)) {
171
684363c44d6f remove some warning and error (not working)
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents: 170
diff changeset
197 unsigned long begin = cc->cond.range.begin;
684363c44d6f remove some warning and error (not working)
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents: 170
diff changeset
198 unsigned long end = cc->cond.range.end;
172
540fc12871d9 remove some warnings and errors (not working)
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents: 171
diff changeset
199 bi = cc->nextState;
171
684363c44d6f remove some warning and error (not working)
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents: 170
diff changeset
200 ccy = charClassMerge(ccy,begin,end,bi);
169
313f1c176328 implement mergeTransition
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents: 168
diff changeset
201 }
313f1c176328 implement mergeTransition
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents: 168
diff changeset
202 free(walk);
178
5e8c6857934c implement charClassMerge
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents: 177
diff changeset
203 return ccy;
169
313f1c176328 implement mergeTransition
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents: 168
diff changeset
204 }
313f1c176328 implement mergeTransition
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents: 168
diff changeset
205
183
7ae0a3070647 implement generateTransitionList
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents: 182
diff changeset
206 /**
7ae0a3070647 implement generateTransitionList
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents: 182
diff changeset
207 作成する state を linked list
7ae0a3070647 implement generateTransitionList
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents: 182
diff changeset
208 bitvector を index とした配列に BitVectorPtr を格納
7ae0a3070647 implement generateTransitionList
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents: 182
diff changeset
209 state に対応する NodePtr を
7ae0a3070647 implement generateTransitionList
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents: 182
diff changeset
210 */
7ae0a3070647 implement generateTransitionList
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents: 182
diff changeset
211 TGValue createState(TGValue tg,NodePtr n) {
7ae0a3070647 implement generateTransitionList
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents: 182
diff changeset
212 StatePtr s = NEW(State);
7ae0a3070647 implement generateTransitionList
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents: 182
diff changeset
213 s->next = tg.tg->currentState;
7ae0a3070647 implement generateTransitionList
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents: 182
diff changeset
214 tg.tg->currentState = s;
7ae0a3070647 implement generateTransitionList
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents: 182
diff changeset
215 s->node = n;
7ae0a3070647 implement generateTransitionList
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents: 182
diff changeset
216 BitVector bi = createBitVector(tg.stateBegin);
7ae0a3070647 implement generateTransitionList
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents: 182
diff changeset
217 s->bitState = bi;
7ae0a3070647 implement generateTransitionList
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents: 182
diff changeset
218 s->cc = NULL;
7ae0a3070647 implement generateTransitionList
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents: 182
diff changeset
219 }
7ae0a3070647 implement generateTransitionList
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents: 182
diff changeset
220
182
dbe004d03ef0 implement stateAllocate()
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents: 181
diff changeset
221 TGValue stateAllocate(NodePtr n,TGValue tg) {
141
71f36a59cf6a add appendState
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents: 139
diff changeset
222 if (n->tokenType == '+') {
182
dbe004d03ef0 implement stateAllocate()
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents: 181
diff changeset
223 TGValue tgLeft = stateAllocate(n->left,tg);
dbe004d03ef0 implement stateAllocate()
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents: 181
diff changeset
224 if (tgLeft.asterisk) {
dbe004d03ef0 implement stateAllocate()
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents: 181
diff changeset
225 TGValue tgRight = tgLeft;
dbe004d03ef0 implement stateAllocate()
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents: 181
diff changeset
226 tgRight.asterisk = false;
dbe004d03ef0 implement stateAllocate()
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents: 181
diff changeset
227 tgRight = stateAllocate(n->right,tgRight);
dbe004d03ef0 implement stateAllocate()
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents: 181
diff changeset
228 tgRight.asterisk = true;
dbe004d03ef0 implement stateAllocate()
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents: 181
diff changeset
229 return tgRight;
142
de0f332d560c insert charClassMerge function
masa
parents: 141
diff changeset
230 }
182
dbe004d03ef0 implement stateAllocate()
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents: 181
diff changeset
231 TGValue tgRight = tgLeft;
dbe004d03ef0 implement stateAllocate()
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents: 181
diff changeset
232 tgRight.stateBegin = ++tgRight.stateNum;
183
7ae0a3070647 implement generateTransitionList
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents: 182
diff changeset
233 n->right->state = createState(tgRight,n->right);
182
dbe004d03ef0 implement stateAllocate()
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents: 181
diff changeset
234 TGValue tgv1 = stateAllocate(n->right,tgLeft);
dbe004d03ef0 implement stateAllocate()
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents: 181
diff changeset
235 return tgLeft;
dbe004d03ef0 implement stateAllocate()
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents: 181
diff changeset
236 } else if (n->tokenType == '|') {
dbe004d03ef0 implement stateAllocate()
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents: 181
diff changeset
237 TGValue tgv = stateAllocate(n->left,tg);
dbe004d03ef0 implement stateAllocate()
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents: 181
diff changeset
238 TGValue tgv1 = stateAllocate(n->right,tgv);
dbe004d03ef0 implement stateAllocate()
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents: 181
diff changeset
239 return tgv1;
dbe004d03ef0 implement stateAllocate()
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents: 181
diff changeset
240 } else if (n->tokenType == '*') {
dbe004d03ef0 implement stateAllocate()
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents: 181
diff changeset
241 TGValue tgAstah = tg;
dbe004d03ef0 implement stateAllocate()
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents: 181
diff changeset
242 tgAstah.stateEnd = tgAstah.stateBegin;
dbe004d03ef0 implement stateAllocate()
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents: 181
diff changeset
243 tgAstah = stateAllocate(n->left,tgAstah);
dbe004d03ef0 implement stateAllocate()
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents: 181
diff changeset
244 tgAstah.asterisk = true;
dbe004d03ef0 implement stateAllocate()
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents: 181
diff changeset
245 return tgAstah;
dbe004d03ef0 implement stateAllocate()
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents: 181
diff changeset
246 } else if (n->tokenType == 'c' || n->tokenType == 'a'){
dbe004d03ef0 implement stateAllocate()
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents: 181
diff changeset
247 TGValue tgv = tg;
dbe004d03ef0 implement stateAllocate()
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents: 181
diff changeset
248 tgv.asterisk = false;
183
7ae0a3070647 implement generateTransitionList
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents: 182
diff changeset
249 n->stateNum = tg.stateBegin;
7ae0a3070647 implement generateTransitionList
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents: 182
diff changeset
250 n->nextStateNum = tg.stateEnd;
7ae0a3070647 implement generateTransitionList
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents: 182
diff changeset
251 return tgv;
7ae0a3070647 implement generateTransitionList
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents: 182
diff changeset
252 } else {
7ae0a3070647 implement generateTransitionList
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents: 182
diff changeset
253 return tg;
7ae0a3070647 implement generateTransitionList
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents: 182
diff changeset
254 }
7ae0a3070647 implement generateTransitionList
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents: 182
diff changeset
255 }
7ae0a3070647 implement generateTransitionList
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents: 182
diff changeset
256
7ae0a3070647 implement generateTransitionList
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents: 182
diff changeset
257 TGValue generateTransition(NodePtr n,TGValue tg) {
7ae0a3070647 implement generateTransitionList
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents: 182
diff changeset
258 if (n->tokenType == '+') {
7ae0a3070647 implement generateTransitionList
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents: 182
diff changeset
259 StatePtr left = tg.state;
7ae0a3070647 implement generateTransitionList
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents: 182
diff changeset
260 tg.state = n->left->state;
7ae0a3070647 implement generateTransitionList
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents: 182
diff changeset
261 tg.tg.stateArray[tg.state->bitState.bitContainer] = tg.state;
7ae0a3070647 implement generateTransitionList
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents: 182
diff changeset
262 TGValue tgLeft = generateTransition(n->left,tg);
7ae0a3070647 implement generateTransitionList
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents: 182
diff changeset
263 tg.state = left;
7ae0a3070647 implement generateTransitionList
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents: 182
diff changeset
264 TGValue tgv1 = generateTransition(n->right,tgLeft);
7ae0a3070647 implement generateTransitionList
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents: 182
diff changeset
265 return tgv1;
7ae0a3070647 implement generateTransitionList
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents: 182
diff changeset
266 } else if (n->tokenType == '|') {
7ae0a3070647 implement generateTransitionList
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents: 182
diff changeset
267 TGValue tgv = generateTransition(n->left,tg);
7ae0a3070647 implement generateTransitionList
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents: 182
diff changeset
268 TGValue tgv1 = generateTransition(n->right,tgv);
7ae0a3070647 implement generateTransitionList
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents: 182
diff changeset
269 return tgv1;
7ae0a3070647 implement generateTransitionList
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents: 182
diff changeset
270 } else if (n->tokenType == '*') {
7ae0a3070647 implement generateTransitionList
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents: 182
diff changeset
271 tgAstah = generateTransition(n->left,tgAstah);
7ae0a3070647 implement generateTransitionList
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents: 182
diff changeset
272 return tgAstah;
7ae0a3070647 implement generateTransitionList
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents: 182
diff changeset
273 } else if (n->tokenType == 'c' || n->tokenType == 'a'){
7ae0a3070647 implement generateTransitionList
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents: 182
diff changeset
274 TGValue tgv = tg;
7ae0a3070647 implement generateTransitionList
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents: 182
diff changeset
275 BitVector bi = createBitVector(n->nextStateNum);
182
dbe004d03ef0 implement stateAllocate()
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents: 181
diff changeset
276 setState(n->cc,bi);
dbe004d03ef0 implement stateAllocate()
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents: 181
diff changeset
277 tgv.state->cc = mergeTransition(tgv.state,n->cc);
dbe004d03ef0 implement stateAllocate()
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents: 181
diff changeset
278 return tgv;
dbe004d03ef0 implement stateAllocate()
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents: 181
diff changeset
279 } else {
183
7ae0a3070647 implement generateTransitionList
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents: 182
diff changeset
280 return tg;
182
dbe004d03ef0 implement stateAllocate()
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents: 181
diff changeset
281 }
141
71f36a59cf6a add appendState
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents: 139
diff changeset
282 }
71f36a59cf6a add appendState
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents: 139
diff changeset
283
153
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents: 152
diff changeset
284 void printTransitionList(TransitionPtr ts) {
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents: 152
diff changeset
285 for (;ts;ts = ts->next) {
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents: 152
diff changeset
286 printf("\n");
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents: 152
diff changeset
287 }
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents: 152
diff changeset
288 }
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents: 152
diff changeset
289
175
3be0fbcd4b52 implement createTransitionGenerator
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents: 173
diff changeset
290 TransitionGenerator createTransitionGenerator() {
144
d8a4922eceae remove some errors (not working)
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents: 143
diff changeset
291 TransitionGenerator tg;
173
masa
parents: 172
diff changeset
292 tg.ts = NEW(Transition);
175
3be0fbcd4b52 implement createTransitionGenerator
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents: 173
diff changeset
293 tg.state = NEW(State);
3be0fbcd4b52 implement createTransitionGenerator
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents: 173
diff changeset
294 tg.transitionList = NEW(Transition);
176
c092dd0e1ae0 implement appendState() and serchState()
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents: 175
diff changeset
295 // Init State : 00...00(64bit)
175
3be0fbcd4b52 implement createTransitionGenerator
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents: 173
diff changeset
296 BitVectorPtr initStateBi = NEW(BitVector);
3be0fbcd4b52 implement createTransitionGenerator
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents: 173
diff changeset
297 bitSet(initStateBi,INIT_STATE_BIT);
177
8de9a33f6ae5 change createState aug
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents: 176
diff changeset
298 StatePtr initState = createState(*initStateBi);
176
c092dd0e1ae0 implement appendState() and serchState()
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents: 175
diff changeset
299 // Last State : 10...00(64bit)
175
3be0fbcd4b52 implement createTransitionGenerator
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents: 173
diff changeset
300 BitVectorPtr lastStateBi = NEW(BitVector);
3be0fbcd4b52 implement createTransitionGenerator
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents: 173
diff changeset
301 bitSet(lastStateBi,END_STATE_BIT);
177
8de9a33f6ae5 change createState aug
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents: 176
diff changeset
302 StatePtr lastState = createState(*lastStateBi);
176
c092dd0e1ae0 implement appendState() and serchState()
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents: 175
diff changeset
303 tg.stateArray = appendState(initState,lastState);
c092dd0e1ae0 implement appendState() and serchState()
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents: 175
diff changeset
304 tg.stateArrayLast = lastState;
177
8de9a33f6ae5 change createState aug
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents: 176
diff changeset
305 tg.currentState = initState;
175
3be0fbcd4b52 implement createTransitionGenerator
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents: 173
diff changeset
306 tg.nextState = NEW(State);
3be0fbcd4b52 implement createTransitionGenerator
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents: 173
diff changeset
307 return tg;
3be0fbcd4b52 implement createTransitionGenerator
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents: 173
diff changeset
308 }
3be0fbcd4b52 implement createTransitionGenerator
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents: 173
diff changeset
309
3be0fbcd4b52 implement createTransitionGenerator
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents: 173
diff changeset
310 TransitionGenerator generateTransitionList(NodePtr n) {
3be0fbcd4b52 implement createTransitionGenerator
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents: 173
diff changeset
311 TransitionGenerator tg = createTransitionGenerator();
183
7ae0a3070647 implement generateTransitionList
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents: 182
diff changeset
312 TGValue tgv;
7ae0a3070647 implement generateTransitionList
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents: 182
diff changeset
313 tgv.asterisk = false;
7ae0a3070647 implement generateTransitionList
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents: 182
diff changeset
314 tgv.tg = tg;
7ae0a3070647 implement generateTransitionList
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents: 182
diff changeset
315 StatePtr start = createState(tgv,n);
7ae0a3070647 implement generateTransitionList
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents: 182
diff changeset
316 NodePtr eof = createNode();
7ae0a3070647 implement generateTransitionList
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents: 182
diff changeset
317 StatePtr end = createState(tgv,eof);
7ae0a3070647 implement generateTransitionList
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents: 182
diff changeset
318 tgv.stateBegin = 0;
7ae0a3070647 implement generateTransitionList
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents: 182
diff changeset
319 tgv.stateEnd = 1;
7ae0a3070647 implement generateTransitionList
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents: 182
diff changeset
320 stateAllocate(n,tgv);
7ae0a3070647 implement generateTransitionList
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents: 182
diff changeset
321 tgv.tg.stateArray = (StatePtr)calloc(tg.stateNum,sizeof(StatePtr));
7ae0a3070647 implement generateTransitionList
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents: 182
diff changeset
322 generateTransition(n,tgv);
153
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents: 152
diff changeset
323 printTransitionList(tg.ts);
141
71f36a59cf6a add appendState
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents: 139
diff changeset
324 return tg;
71f36a59cf6a add appendState
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents: 139
diff changeset
325 }