annotate c/regexParser/subsetConstraction.cc @ 154:1fad21fd6028 pairPro

remove errors and warnings
author masa
date Fri, 18 Dec 2015 14:16:02 +0900
parents e2e717fbeb2f
children 6cd0141bed6c
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;
144
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
152
1c9e8ba64f6a add implement charclassMerge (not working)
masa
parents: 148
diff changeset
11 CharClassPtr charClassMerge(CharClassPtr cc,unsigned long begin, unsigned long end, BitVector nextState) {
143
32977f5a2ed0 add charClassMerge
masa
parents: 142
diff changeset
12 // 重なっているccの領域を分割する
32977f5a2ed0 add charClassMerge
masa
parents: 142
diff changeset
13 // 必要ならばnextStateを重ねあわせる
32977f5a2ed0 add charClassMerge
masa
parents: 142
diff changeset
14 // 変更があった場合は新しくリストを作って返す
152
1c9e8ba64f6a add implement charclassMerge (not working)
masa
parents: 148
diff changeset
15 if (end < cc->cond.range.begin ) { // 1
153
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents: 152
diff changeset
16 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
17 if (cc->left) {
1c9e8ba64f6a add implement charclassMerge (not working)
masa
parents: 148
diff changeset
18 cc1->left = charClassMerge(cc->left,begin,end,nextState);
1c9e8ba64f6a add implement charclassMerge (not working)
masa
parents: 148
diff changeset
19 return cc1;
1c9e8ba64f6a add implement charclassMerge (not working)
masa
parents: 148
diff changeset
20 } else {
154
1fad21fd6028 remove errors and warnings
masa
parents: 153
diff changeset
21 CharClassPtr cc2 = charClassMerge(cc,begin,end,nextState);
152
1c9e8ba64f6a add implement charclassMerge (not working)
masa
parents: 148
diff changeset
22 cc2->nextState = nextState;
1c9e8ba64f6a add implement charclassMerge (not working)
masa
parents: 148
diff changeset
23 cc1->left = cc2;
1c9e8ba64f6a add implement charclassMerge (not working)
masa
parents: 148
diff changeset
24 return cc1;
1c9e8ba64f6a add implement charclassMerge (not working)
masa
parents: 148
diff changeset
25 }
1c9e8ba64f6a add implement charclassMerge (not working)
masa
parents: 148
diff changeset
26 } else if (end == cc->cond.range.begin ) { // 2
1c9e8ba64f6a add implement charclassMerge (not working)
masa
parents: 148
diff changeset
27 cc->cond.range.begin = begin;
1c9e8ba64f6a add implement charclassMerge (not working)
masa
parents: 148
diff changeset
28 return cc;
1c9e8ba64f6a add implement charclassMerge (not working)
masa
parents: 148
diff changeset
29 } else if (end <= cc->cond.range.end) { // 3,4,6,7,9,10
1c9e8ba64f6a add implement charclassMerge (not working)
masa
parents: 148
diff changeset
30 if (begin < cc->cond.range.begin) { // 3,4
1c9e8ba64f6a add implement charclassMerge (not working)
masa
parents: 148
diff changeset
31 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
32 }
152
1c9e8ba64f6a add implement charclassMerge (not working)
masa
parents: 148
diff changeset
33 return cc;
1c9e8ba64f6a add implement charclassMerge (not working)
masa
parents: 148
diff changeset
34 } else if (begin > cc->cond.range.end ) { // 13
1c9e8ba64f6a add implement charclassMerge (not working)
masa
parents: 148
diff changeset
35 if (cc->right) {
154
1fad21fd6028 remove errors and warnings
masa
parents: 153
diff changeset
36 cc->right = charClassMerge(cc->right,begin,end,nextState);
152
1c9e8ba64f6a add implement charclassMerge (not working)
masa
parents: 148
diff changeset
37 } else {
154
1fad21fd6028 remove errors and warnings
masa
parents: 153
diff changeset
38 cc->right = charClassMerge(cc,begin,end,nextState);
152
1c9e8ba64f6a add implement charclassMerge (not working)
masa
parents: 148
diff changeset
39 }
1c9e8ba64f6a add implement charclassMerge (not working)
masa
parents: 148
diff changeset
40 return cc;
143
32977f5a2ed0 add charClassMerge
masa
parents: 142
diff changeset
41 }
152
1c9e8ba64f6a add implement charclassMerge (not working)
masa
parents: 148
diff changeset
42 if (cc->right) {
1c9e8ba64f6a add implement charclassMerge (not working)
masa
parents: 148
diff changeset
43 CharClassPtr right = cc->right;
1c9e8ba64f6a add implement charclassMerge (not working)
masa
parents: 148
diff changeset
44 begin = cc->cond.range.begin;
1c9e8ba64f6a add implement charclassMerge (not working)
masa
parents: 148
diff changeset
45 free(cc);
154
1fad21fd6028 remove errors and warnings
masa
parents: 153
diff changeset
46 return charClassMerge(right,begin,end,nextState);
152
1c9e8ba64f6a add implement charclassMerge (not working)
masa
parents: 148
diff changeset
47 }
1c9e8ba64f6a add implement charclassMerge (not working)
masa
parents: 148
diff changeset
48 if (begin >= cc->cond.range.begin && begin <= cc->cond.range.end) { // 12
1c9e8ba64f6a add implement charclassMerge (not working)
masa
parents: 148
diff changeset
49 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
50 } else if (begin < cc->cond.range.begin) { // 5
152
1c9e8ba64f6a add implement charclassMerge (not working)
masa
parents: 148
diff changeset
51 cc->cond.range.begin = begin;
1c9e8ba64f6a add implement charclassMerge (not working)
masa
parents: 148
diff changeset
52 cc->cond.range.end = end;
1c9e8ba64f6a add implement charclassMerge (not working)
masa
parents: 148
diff changeset
53 } else {
1c9e8ba64f6a add implement charclassMerge (not working)
masa
parents: 148
diff changeset
54 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
55 }
1c9e8ba64f6a add implement charclassMerge (not working)
masa
parents: 148
diff changeset
56 return cc;
143
32977f5a2ed0 add charClassMerge
masa
parents: 142
diff changeset
57 }
32977f5a2ed0 add charClassMerge
masa
parents: 142
diff changeset
58
142
de0f332d560c insert charClassMerge function
masa
parents: 141
diff changeset
59 TGValue generateTransition(NodePtr n,TransitionGenerator tg) {
154
1fad21fd6028 remove errors and warnings
masa
parents: 153
diff changeset
60 TGValue tgv2;
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'){
154
1fad21fd6028 remove errors and warnings
masa
parents: 153
diff changeset
81 return tgv2;
144
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 }
154
1fad21fd6028 remove errors and warnings
masa
parents: 153
diff changeset
93 return tgv2;
141
71f36a59cf6a add appendState
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents: 139
diff changeset
94 }
71f36a59cf6a add appendState
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents: 139
diff changeset
95
153
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents: 152
diff changeset
96 void printTransitionList(TransitionPtr ts) {
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents: 152
diff changeset
97 for (;ts;ts = ts->next) {
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents: 152
diff changeset
98 printf("\n");
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 }
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents: 152
diff changeset
101
144
d8a4922eceae remove some errors (not working)
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents: 143
diff changeset
102 TransitionGenerator generateTransitionList(NodePtr n) {
d8a4922eceae remove some errors (not working)
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents: 143
diff changeset
103 TransitionGenerator tg;
153
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents: 152
diff changeset
104 tg.ts = (TransitionPtr)malloc(sizeof(Transition));
141
71f36a59cf6a add appendState
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents: 139
diff changeset
105 generateTransition(n,tg);
153
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents: 152
diff changeset
106 printTransitionList(tg.ts);
141
71f36a59cf6a add appendState
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents: 139
diff changeset
107 return tg;
71f36a59cf6a add appendState
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents: 139
diff changeset
108 }