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
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 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
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents: 144
diff changeset
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
1c9e8ba64f6a add implement charclassMerge (not working)
masa
parents: 148
diff changeset
12 CharClassPtr charClassMerge(CharClassPtr cc,unsigned long begin, unsigned long end, BitVector nextState) {
143
32977f5a2ed0 add charClassMerge
masa
parents: 142
diff changeset
13 // 重なっているccの領域を分割する
32977f5a2ed0 add charClassMerge
masa
parents: 142
diff changeset
14 // 必要ならばnextStateを重ねあわせる
32977f5a2ed0 add charClassMerge
masa
parents: 142
diff changeset
15 // 変更があった場合は新しくリストを作って返す
152
1c9e8ba64f6a add implement charclassMerge (not working)
masa
parents: 148
diff changeset
16 if (end < cc->cond.range.begin ) { // 1
153
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents: 152
diff changeset
17 CharClassPtr cc1 = charClassMerge(cc,cc->cond.range.begin,cc->cond.range.end,nextState);
152
1c9e8ba64f6a add implement charclassMerge (not working)
masa
parents: 148
diff changeset
18 if (cc->left) {
1c9e8ba64f6a add implement charclassMerge (not working)
masa
parents: 148
diff changeset
19 cc1->left = charClassMerge(cc->left,begin,end,nextState);
1c9e8ba64f6a add implement charclassMerge (not working)
masa
parents: 148
diff changeset
20 return cc1;
1c9e8ba64f6a add implement charclassMerge (not working)
masa
parents: 148
diff changeset
21 } else {
153
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents: 152
diff changeset
22 CharClassPtr cc2 = charClassMerge(begin,end,0,0);
152
1c9e8ba64f6a add implement charclassMerge (not working)
masa
parents: 148
diff changeset
23 cc2->nextState = nextState;
1c9e8ba64f6a add implement charclassMerge (not working)
masa
parents: 148
diff changeset
24 cc1->left = cc2;
1c9e8ba64f6a add implement charclassMerge (not working)
masa
parents: 148
diff changeset
25 return cc1;
1c9e8ba64f6a add implement charclassMerge (not working)
masa
parents: 148
diff changeset
26 }
1c9e8ba64f6a add implement charclassMerge (not working)
masa
parents: 148
diff changeset
27 } else if (end == cc->cond.range.begin ) { // 2
1c9e8ba64f6a add implement charclassMerge (not working)
masa
parents: 148
diff changeset
28 cc->cond.range.begin = begin;
1c9e8ba64f6a add implement charclassMerge (not working)
masa
parents: 148
diff changeset
29 return cc;
1c9e8ba64f6a add implement charclassMerge (not working)
masa
parents: 148
diff changeset
30 } else if (end <= cc->cond.range.end) { // 3,4,6,7,9,10
1c9e8ba64f6a add implement charclassMerge (not working)
masa
parents: 148
diff changeset
31 if (begin < cc->cond.range.begin) { // 3,4
1c9e8ba64f6a add implement charclassMerge (not working)
masa
parents: 148
diff changeset
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
1c9e8ba64f6a add implement charclassMerge (not working)
masa
parents: 148
diff changeset
34 return cc;
1c9e8ba64f6a add implement charclassMerge (not working)
masa
parents: 148
diff changeset
35 } else if (begin > cc->cond.range.end ) { // 13
1c9e8ba64f6a add implement charclassMerge (not working)
masa
parents: 148
diff changeset
36 if (cc->right) {
1c9e8ba64f6a add implement charclassMerge (not working)
masa
parents: 148
diff changeset
37 cc->right = charClassMerge(cc->right,begin,end);
1c9e8ba64f6a add implement charclassMerge (not working)
masa
parents: 148
diff changeset
38 } else {
153
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents: 152
diff changeset
39 cc->right = charClassMerge(begin,end,0,0);
152
1c9e8ba64f6a add implement charclassMerge (not working)
masa
parents: 148
diff changeset
40 }
1c9e8ba64f6a add implement charclassMerge (not working)
masa
parents: 148
diff changeset
41 return cc;
143
32977f5a2ed0 add charClassMerge
masa
parents: 142
diff changeset
42 }
152
1c9e8ba64f6a add implement charclassMerge (not working)
masa
parents: 148
diff changeset
43 if (cc->right) {
1c9e8ba64f6a add implement charclassMerge (not working)
masa
parents: 148
diff changeset
44 CharClassPtr right = cc->right;
1c9e8ba64f6a add implement charclassMerge (not working)
masa
parents: 148
diff changeset
45 begin = cc->cond.range.begin;
1c9e8ba64f6a add implement charclassMerge (not working)
masa
parents: 148
diff changeset
46 free(cc);
1c9e8ba64f6a add implement charclassMerge (not working)
masa
parents: 148
diff changeset
47 return charClassMerge(right,begin,end);
1c9e8ba64f6a add implement charclassMerge (not working)
masa
parents: 148
diff changeset
48 }
1c9e8ba64f6a add implement charclassMerge (not working)
masa
parents: 148
diff changeset
49 if (begin >= cc->cond.range.begin && begin <= cc->cond.range.end) { // 12
1c9e8ba64f6a add implement charclassMerge (not working)
masa
parents: 148
diff changeset
50 if (end > cc->cond.range.end) cc->cond.range.end = end; // 11,8
153
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents: 152
diff changeset
51 } else if (begin < cc->cond.range.begin) { // 5
152
1c9e8ba64f6a add implement charclassMerge (not working)
masa
parents: 148
diff changeset
52 cc->cond.range.begin = begin;
1c9e8ba64f6a add implement charclassMerge (not working)
masa
parents: 148
diff changeset
53 cc->cond.range.end = end;
1c9e8ba64f6a add implement charclassMerge (not working)
masa
parents: 148
diff changeset
54 } else {
1c9e8ba64f6a add implement charclassMerge (not working)
masa
parents: 148
diff changeset
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);
1c9e8ba64f6a add implement charclassMerge (not working)
masa
parents: 148
diff changeset
56 }
1c9e8ba64f6a add implement charclassMerge (not working)
masa
parents: 148
diff changeset
57 return cc;
143
32977f5a2ed0 add charClassMerge
masa
parents: 142
diff changeset
58 }
32977f5a2ed0 add charClassMerge
masa
parents: 142
diff changeset
59
142
de0f332d560c insert charClassMerge function
masa
parents: 141
diff changeset
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
de0f332d560c insert charClassMerge function
masa
parents: 141
diff changeset
62 TGValue tgv = generateTransition(n->left,tg);
de0f332d560c insert charClassMerge function
masa
parents: 141
diff changeset
63 if (tgv.asterisk) {
de0f332d560c insert charClassMerge function
masa
parents: 141
diff changeset
64 TGValue tgv1 = generateTransition(n->right,tg);
153
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents: 152
diff changeset
65 tgv.ts->nextState->bitContainer |= tgv1.ts->nextState->bitContainer;
142
de0f332d560c insert charClassMerge function
masa
parents: 141
diff changeset
66 return tgv;
de0f332d560c insert charClassMerge function
masa
parents: 141
diff changeset
67 }
153
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents: 152
diff changeset
68 TGValue tgv1 = generateTransition(n->right,tg);
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents: 152
diff changeset
69 tgv.ts->nextState = tgv1.ts->nextState;
142
de0f332d560c insert charClassMerge function
masa
parents: 141
diff changeset
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
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents: 152
diff changeset
72 TGValue tgv = generateTransition(n->left,tg);
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents: 152
diff changeset
73 TGValue tgv1 = generateTransition(n->right,tg);
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents: 152
diff changeset
74 tgv.ts = appendTransition(tgv.ts,tgv1.ts);
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents: 152
diff changeset
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
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents: 152
diff changeset
77 TGValue tgv = generateTransition(n->left,tg);
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents: 152
diff changeset
78 tgv.asterisk = true;
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents: 152
diff changeset
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
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents: 152
diff changeset
83 TGValue tgv;
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents: 152
diff changeset
84 tgv.ts = (TransitionPtr)malloc(sizeof(Transition));
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents: 152
diff changeset
85 tgv.ts->condition = n->cc;
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents: 152
diff changeset
86 tgv.ts->nextState = (BitVectorPtr)malloc(sizeof(BitVector));
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents: 152
diff changeset
87 bitSet(tgv.ts->nextState,n->nodeNumber);
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents: 152
diff changeset
88 tg.ts = appendTransition(tg.ts,tgv.ts);
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents: 152
diff changeset
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
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents: 152
diff changeset
95 void printTransitionList(TransitionPtr ts) {
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents: 152
diff changeset
96 for (;ts;ts = ts->next) {
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents: 152
diff changeset
97 printf("\n");
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents: 152
diff changeset
98 }
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents: 152
diff changeset
99 }
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents: 152
diff changeset
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
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents: 152
diff changeset
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
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents: 152
diff changeset
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 }