Mercurial > hg > Members > masakoha > testcode
annotate c/regexParser/subsetConstraction.cc @ 152:1c9e8ba64f6a pairPro
add implement charclassMerge (not working)
author | masa |
---|---|
date | Wed, 16 Dec 2015 17:28:53 +0900 |
parents | d1ebba6e117a |
children | e2e717fbeb2f |
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) { |
146 | 8 CharClassPtr cc = NEW(CharClass); |
144
d8a4922eceae
remove some errors (not working)
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
143
diff
changeset
|
9 return cc1; |
d8a4922eceae
remove some errors (not working)
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
143
diff
changeset
|
10 } |
d8a4922eceae
remove some errors (not working)
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
143
diff
changeset
|
11 |
152 | 12 CharClassPtr charClassMerge(CharClassPtr cc,unsigned long begin, unsigned long end, BitVector nextState) { |
143 | 13 // 重なっているccの領域を分割する |
14 // 必要ならばnextStateを重ねあわせる | |
15 // 変更があった場合は新しくリストを作って返す | |
152 | 16 if (end < cc->cond.range.begin ) { // 1 |
17 CharClassPtr cc1 = createCharClassRange(cc->cond.range.begin,cc->cond.range.end,cc->left,cc->right); | |
18 if (cc->left) { | |
19 cc1->left = charClassMerge(cc->left,begin,end,nextState); | |
20 return cc1; | |
21 } else { | |
22 CharClassPtr cc2 = createCharClassRange(begin,end,0,0); | |
23 cc2->nextState = nextState; | |
24 cc1->left = cc2; | |
25 return cc1; | |
26 } | |
27 } else if (end == cc->cond.range.begin ) { // 2 | |
28 cc->cond.range.begin = begin; | |
29 return cc; | |
30 } else if (end <= cc->cond.range.end) { // 3,4,6,7,9,10 | |
31 if (begin < cc->cond.range.begin) { // 3,4 | |
32 cc->cond.range.begin = begin; | |
144
d8a4922eceae
remove some errors (not working)
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
143
diff
changeset
|
33 } |
152 | 34 return cc; |
35 } else if (begin > cc->cond.range.end ) { // 13 | |
36 if (cc->right) { | |
37 cc->right = charClassMerge(cc->right,begin,end); | |
38 } else { | |
39 cc->right = createCharClassRange(begin,end,0,0); | |
40 } | |
41 return cc; | |
143 | 42 } |
152 | 43 if (cc->right) { |
44 CharClassPtr right = cc->right; | |
45 begin = cc->cond.range.begin; | |
46 free(cc); | |
47 return charClassMerge(right,begin,end); | |
48 } | |
49 if (begin >= cc->cond.range.begin && begin <= cc->cond.range.end) { // 12 | |
50 if (end > cc->cond.range.end) cc->cond.range.end = end; // 11,8 | |
51 } else if (begin < cc->cond.range.begin) { // 6 | |
52 cc->cond.range.begin = begin; | |
53 cc->cond.range.end = end; | |
54 } else { | |
55 printf("charClassMerge Error : begin %lu end %lu cc->begin %lu cc->end %lu\n", begin,end,cc->cond.range.begin,cc->cond.range.end); | |
56 } | |
57 return cc; | |
143 | 58 } |
59 | |
141
71f36a59cf6a
add appendState
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
139
diff
changeset
|
60 void printTransition(TransitionPtr ts) { |
144
d8a4922eceae
remove some errors (not working)
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
143
diff
changeset
|
61 |
141
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 |
142 | 64 TGValue generateTransition(NodePtr n,TransitionGenerator tg) { |
141
71f36a59cf6a
add appendState
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
139
diff
changeset
|
65 if (n->tokenType == '+') { |
142 | 66 TGValue tgv = generateTransition(n->left,tg); |
67 if (tgv.asterisk) { | |
68 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
|
69 tgv.ts->state->bitContainer |= tgv1.ts->state->bitContainer; |
142 | 70 return tgv; |
71 } | |
144
d8a4922eceae
remove some errors (not working)
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
143
diff
changeset
|
72 bitSet(tgv.ts->state,n->right->nodeNumber); |
142 | 73 return tgv; |
141
71f36a59cf6a
add appendState
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
139
diff
changeset
|
74 } else if (n->tokenType == '|') { |
144
d8a4922eceae
remove some errors (not working)
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
143
diff
changeset
|
75 |
141
71f36a59cf6a
add appendState
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
139
diff
changeset
|
76 } else if (n->tokenType == '*') { |
144
d8a4922eceae
remove some errors (not working)
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
143
diff
changeset
|
77 |
d8a4922eceae
remove some errors (not working)
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
143
diff
changeset
|
78 } else if (n->tokenType == 'c'){ |
d8a4922eceae
remove some errors (not working)
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
143
diff
changeset
|
79 |
d8a4922eceae
remove some errors (not working)
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
143
diff
changeset
|
80 } else if (n->tokenType == 'a'){ |
d8a4922eceae
remove some errors (not working)
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
143
diff
changeset
|
81 |
141
71f36a59cf6a
add appendState
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
139
diff
changeset
|
82 } else { |
144
d8a4922eceae
remove some errors (not working)
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
143
diff
changeset
|
83 // error |
141
71f36a59cf6a
add appendState
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
139
diff
changeset
|
84 } |
71f36a59cf6a
add appendState
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
139
diff
changeset
|
85 } |
71f36a59cf6a
add appendState
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
139
diff
changeset
|
86 |
144
d8a4922eceae
remove some errors (not working)
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
143
diff
changeset
|
87 TransitionGenerator generateTransitionList(NodePtr n) { |
d8a4922eceae
remove some errors (not working)
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
143
diff
changeset
|
88 TransitionGenerator tg; |
141
71f36a59cf6a
add appendState
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
139
diff
changeset
|
89 generateTransition(n,tg); |
71f36a59cf6a
add appendState
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
139
diff
changeset
|
90 return tg; |
71f36a59cf6a
add appendState
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
139
diff
changeset
|
91 } |