Mercurial > hg > Members > masakoha > testcode
annotate c/regexParser/subsetConstraction.cc @ 153:e2e717fbeb2f pairPro
fix
author | Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp> |
---|---|
date | Fri, 18 Dec 2015 14:02:41 +0900 |
parents | 1c9e8ba64f6a |
children | 1fad21fd6028 |
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 |
153 | 17 CharClassPtr cc1 = charClassMerge(cc,cc->cond.range.begin,cc->cond.range.end,nextState); |
152 | 18 if (cc->left) { |
19 cc1->left = charClassMerge(cc->left,begin,end,nextState); | |
20 return cc1; | |
21 } else { | |
153 | 22 CharClassPtr cc2 = charClassMerge(begin,end,0,0); |
152 | 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 { | |
153 | 39 cc->right = charClassMerge(begin,end,0,0); |
152 | 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 | |
153 | 51 } else if (begin < cc->cond.range.begin) { // 5 |
152 | 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 | |
142 | 60 TGValue generateTransition(NodePtr n,TransitionGenerator tg) { |
141
71f36a59cf6a
add appendState
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
139
diff
changeset
|
61 if (n->tokenType == '+') { |
142 | 62 TGValue tgv = generateTransition(n->left,tg); |
63 if (tgv.asterisk) { | |
64 TGValue tgv1 = generateTransition(n->right,tg); | |
153 | 65 tgv.ts->nextState->bitContainer |= tgv1.ts->nextState->bitContainer; |
142 | 66 return tgv; |
67 } | |
153 | 68 TGValue tgv1 = generateTransition(n->right,tg); |
69 tgv.ts->nextState = tgv1.ts->nextState; | |
142 | 70 return tgv; |
141
71f36a59cf6a
add appendState
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
139
diff
changeset
|
71 } else if (n->tokenType == '|') { |
153 | 72 TGValue tgv = generateTransition(n->left,tg); |
73 TGValue tgv1 = generateTransition(n->right,tg); | |
74 tgv.ts = appendTransition(tgv.ts,tgv1.ts); | |
75 return tgv; | |
141
71f36a59cf6a
add appendState
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
139
diff
changeset
|
76 } else if (n->tokenType == '*') { |
153 | 77 TGValue tgv = generateTransition(n->left,tg); |
78 tgv.asterisk = true; | |
79 return tgv; | |
144
d8a4922eceae
remove some errors (not working)
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
143
diff
changeset
|
80 } else if (n->tokenType == 'c'){ |
d8a4922eceae
remove some errors (not working)
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
143
diff
changeset
|
81 |
d8a4922eceae
remove some errors (not working)
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
143
diff
changeset
|
82 } else if (n->tokenType == 'a'){ |
153 | 83 TGValue tgv; |
84 tgv.ts = (TransitionPtr)malloc(sizeof(Transition)); | |
85 tgv.ts->condition = n->cc; | |
86 tgv.ts->nextState = (BitVectorPtr)malloc(sizeof(BitVector)); | |
87 bitSet(tgv.ts->nextState,n->nodeNumber); | |
88 tg.ts = appendTransition(tg.ts,tgv.ts); | |
89 return tgv; | |
141
71f36a59cf6a
add appendState
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
139
diff
changeset
|
90 } else { |
144
d8a4922eceae
remove some errors (not working)
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
143
diff
changeset
|
91 // error |
141
71f36a59cf6a
add appendState
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
139
diff
changeset
|
92 } |
71f36a59cf6a
add appendState
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
139
diff
changeset
|
93 } |
71f36a59cf6a
add appendState
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
139
diff
changeset
|
94 |
153 | 95 void printTransitionList(TransitionPtr ts) { |
96 for (;ts;ts = ts->next) { | |
97 printf("\n"); | |
98 } | |
99 } | |
100 | |
144
d8a4922eceae
remove some errors (not working)
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
143
diff
changeset
|
101 TransitionGenerator generateTransitionList(NodePtr n) { |
d8a4922eceae
remove some errors (not working)
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
143
diff
changeset
|
102 TransitionGenerator tg; |
153 | 103 tg.ts = (TransitionPtr)malloc(sizeof(Transition)); |
141
71f36a59cf6a
add appendState
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
139
diff
changeset
|
104 generateTransition(n,tg); |
153 | 105 printTransitionList(tg.ts); |
141
71f36a59cf6a
add appendState
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
139
diff
changeset
|
106 return tg; |
71f36a59cf6a
add appendState
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
139
diff
changeset
|
107 } |