Mercurial > hg > Members > masakoha > testcode
annotate c/regexParser/subsetConstraction.cc @ 144:d8a4922eceae pairPro
remove some errors (not working)
author | Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp> |
---|---|
date | Mon, 14 Dec 2015 17:14:33 +0900 |
parents | 32977f5a2ed0 |
children | 1c74ac7d56ec |
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> |
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 static |
d8a4922eceae
remove some errors (not working)
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
143
diff
changeset
|
7 CharClassPtr createCharClassWord(unsigned char *w, CharClassPtr cc1, CharClassPtr cc2) { |
d8a4922eceae
remove some errors (not working)
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
143
diff
changeset
|
8 return cc1; |
d8a4922eceae
remove some errors (not working)
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
143
diff
changeset
|
9 } |
d8a4922eceae
remove some errors (not working)
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
143
diff
changeset
|
10 |
143 | 11 CharClassPtr charClassMerge(CharClassPtr src, CharClassPtr add) { |
12 // 重なっているccの領域を分割する | |
13 // 必要ならばnextStateを重ねあわせる | |
14 // 変更があった場合は新しくリストを作って返す | |
15 if (src->type == 'a') { | |
16 if (add->type == 'a') { | |
17 if (src->cond.w.word[0] > add->cond.w.word[0]) { | |
18 // add のほうが小さいので小さい順のccをつくる | |
144
d8a4922eceae
remove some errors (not working)
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
143
diff
changeset
|
19 CharClassPtr left = charClassMerge(add->left,src); |
d8a4922eceae
remove some errors (not working)
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
143
diff
changeset
|
20 return createCharClassWord(add->cond.w.word, left, add->right); |
143 | 21 } else { |
144
d8a4922eceae
remove some errors (not working)
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
143
diff
changeset
|
22 |
143 | 23 } |
24 } else if (add->type == 'c') { | |
25 if (src->cond.w.word[0] < add->cond.range.begin) { | |
26 | |
144
d8a4922eceae
remove some errors (not working)
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
143
diff
changeset
|
27 } else if (src->cond.w.word[0] < add->cond.range.end) { |
d8a4922eceae
remove some errors (not working)
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
143
diff
changeset
|
28 |
d8a4922eceae
remove some errors (not working)
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
143
diff
changeset
|
29 } |
d8a4922eceae
remove some errors (not working)
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
143
diff
changeset
|
30 } |
143 | 31 } else if (src->type == 'c') { |
32 | |
33 } | |
34 } | |
35 | |
141
71f36a59cf6a
add appendState
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
139
diff
changeset
|
36 void printTransition(TransitionPtr ts) { |
144
d8a4922eceae
remove some errors (not working)
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
143
diff
changeset
|
37 |
141
71f36a59cf6a
add appendState
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
139
diff
changeset
|
38 } |
71f36a59cf6a
add appendState
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
139
diff
changeset
|
39 |
142 | 40 TGValue generateTransition(NodePtr n,TransitionGenerator tg) { |
141
71f36a59cf6a
add appendState
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
139
diff
changeset
|
41 if (n->tokenType == '+') { |
142 | 42 TGValue tgv = generateTransition(n->left,tg); |
43 if (tgv.asterisk) { | |
44 TGValue tgv1 = generateTransition(n->right,tg); | |
144
d8a4922eceae
remove some errors (not working)
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
143
diff
changeset
|
45 tgv.ts->state->bitContainer |= tgv1.ts->state->bitContainer; |
142 | 46 return tgv; |
47 } | |
144
d8a4922eceae
remove some errors (not working)
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
143
diff
changeset
|
48 bitSet(tgv.ts->state,n->right->nodeNumber); |
142 | 49 return tgv; |
141
71f36a59cf6a
add appendState
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
139
diff
changeset
|
50 } else if (n->tokenType == '|') { |
144
d8a4922eceae
remove some errors (not working)
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
143
diff
changeset
|
51 |
141
71f36a59cf6a
add appendState
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
139
diff
changeset
|
52 } else if (n->tokenType == '*') { |
144
d8a4922eceae
remove some errors (not working)
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
143
diff
changeset
|
53 |
d8a4922eceae
remove some errors (not working)
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
143
diff
changeset
|
54 } else if (n->tokenType == 'c'){ |
d8a4922eceae
remove some errors (not working)
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
143
diff
changeset
|
55 |
d8a4922eceae
remove some errors (not working)
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
143
diff
changeset
|
56 } else if (n->tokenType == 'a'){ |
d8a4922eceae
remove some errors (not working)
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
143
diff
changeset
|
57 |
141
71f36a59cf6a
add appendState
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
139
diff
changeset
|
58 } else { |
144
d8a4922eceae
remove some errors (not working)
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
143
diff
changeset
|
59 // error |
141
71f36a59cf6a
add appendState
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
139
diff
changeset
|
60 } |
71f36a59cf6a
add appendState
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
139
diff
changeset
|
61 } |
71f36a59cf6a
add appendState
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
139
diff
changeset
|
62 |
71f36a59cf6a
add appendState
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
139
diff
changeset
|
63 StatePtr createStateList(NodePtr n) { |
71f36a59cf6a
add appendState
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
139
diff
changeset
|
64 StatePtr s0 = NULL; |
137 | 65 if (n->left != NULL) { |
141
71f36a59cf6a
add appendState
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
139
diff
changeset
|
66 s0 = createStateList(n->left); |
137 | 67 } |
141
71f36a59cf6a
add appendState
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
139
diff
changeset
|
68 |
137 | 69 if (n->tokenType == 'a') { |
141
71f36a59cf6a
add appendState
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
139
diff
changeset
|
70 BitVectorPtr bi = createBitVector(n); |
71f36a59cf6a
add appendState
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
139
diff
changeset
|
71 StatePtr s1 = createState(bi,0,0); |
71f36a59cf6a
add appendState
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
139
diff
changeset
|
72 } else if (n->tokenType == '+' || n->tokenType == '|') { |
144
d8a4922eceae
remove some errors (not working)
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
143
diff
changeset
|
73 |
104
3eb3cb5d581f
implemented 'or' node translator
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
103
diff
changeset
|
74 } |
105
766fc2476f01
fix indent size
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
104
diff
changeset
|
75 |
137 | 76 if (n->right != NULL) { |
141
71f36a59cf6a
add appendState
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
139
diff
changeset
|
77 s0 = createStateList(n->right); |
104
3eb3cb5d581f
implemented 'or' node translator
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
103
diff
changeset
|
78 } |
141
71f36a59cf6a
add appendState
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
139
diff
changeset
|
79 return s0; |
104
3eb3cb5d581f
implemented 'or' node translator
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
103
diff
changeset
|
80 } |
141
71f36a59cf6a
add appendState
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
139
diff
changeset
|
81 |
144
d8a4922eceae
remove some errors (not working)
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
143
diff
changeset
|
82 TransitionGenerator generateTransitionList(NodePtr n) { |
d8a4922eceae
remove some errors (not working)
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
143
diff
changeset
|
83 TransitionGenerator tg; |
d8a4922eceae
remove some errors (not working)
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
143
diff
changeset
|
84 tg.state = createStateList(n); |
141
71f36a59cf6a
add appendState
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
139
diff
changeset
|
85 generateTransition(n,tg); |
71f36a59cf6a
add appendState
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
139
diff
changeset
|
86 return tg; |
71f36a59cf6a
add appendState
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
139
diff
changeset
|
87 } |