comparison c/regexParser/regexParser.cc @ 130:7925e9abb078 pairPro

add or flag
author Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
date Wed, 02 Dec 2015 17:51:02 +0900
parents b930be74a16e
children fb4c8adf3a80
comparison
equal deleted inserted replaced
129:b930be74a16e 130:7925e9abb078
77 cc->cond->range->next = NULL; 77 cc->cond->range->next = NULL;
78 78
79 int i = 0; 79 int i = 0;
80 80
81 RangeListPtr rangeList = cc->cond->range; 81 RangeListPtr rangeList = cc->cond->range;
82 82
83 while (ri->ptr[i] != ']') { 83 while (ri->ptr[i] != ']') {
84 if (ri->ptr[i] == '-') i++; 84 if (ri->ptr[i] == '-') i++;
85 85
86 rangeList->end = ri->ptr + i; 86 rangeList->end = ri->ptr + i;
87 rangeList->next = NEW(RangeList); 87 rangeList->next = NEW(RangeList);
130 return; 130 return;
131 } else if (ri->ptr[0] == '|'){ 131 } else if (ri->ptr[0] == '|'){
132 ri->ptr++; 132 ri->ptr++;
133 ri->tokenType = '|'; 133 ri->tokenType = '|';
134 ri->tokenValue = NULL; 134 ri->tokenValue = NULL;
135 ri->orFlag = true;
135 return; 136 return;
136 } else if (ri->ptr[0] == '*'){ 137 } else if (ri->ptr[0] == '*'){
137 ri->ptr++; 138 ri->ptr++;
138 ri->tokenType = '*'; 139 ri->tokenType = '*';
139 ri->tokenValue = NULL; 140 ri->tokenValue = NULL;
151 ri->tokenType = 'a'; 152 ri->tokenType = 'a';
152 ri->tokenValue = ri->ptr; 153 ri->tokenValue = ri->ptr;
153 while (isalnum(ri->ptr[0])) { 154 while (isalnum(ri->ptr[0])) {
154 ri->ptr++; 155 ri->ptr++;
155 } 156 }
157 if (ri->ptr[0] == '*') {
158 ri->astarFlag = true;
159 }
156 return; 160 return;
157 } 161 }
158 } 162 }
159 return; 163 return;
160 } 164 }
161 165
162 // <regexAtom> ::= <literal>|<charClass> 166 // <regexAtom> ::= <literal>|<charClass>|<group>
163 static 167 static
164 NodePtr regexAtom(RegexInfoPtr ri) { 168 NodePtr regexAtom(RegexInfoPtr ri) {
165 169
166 token(ri); 170 token(ri);
167 NodePtr n = NULL; 171 NodePtr n = NULL;
170 if (ri->tokenType == '(') n = group(ri); 174 if (ri->tokenType == '(') n = group(ri);
171 175
172 return n; 176 return n;
173 } 177 }
174 178
175 // <regex> ::= <regexAtom> | <regexAtom>'*' | <regexAtom>'|'<regex> | <regexAtom><regex> | '(' regex ')' 179 // <regex> ::= <regexAtom> | <regexAtom>'*'<regex> | <regexAtom>'|'<regex> | <regexAtom><regex> |
176 NodePtr regex(RegexInfoPtr ri) { 180 NodePtr regex(RegexInfoPtr ri) {
177 NodePtr n = regexAtom(ri); 181 NodePtr n = regexAtom(ri);
178 while (ri->ptr[0]) { 182 while (ri->ptr[0]) {
179 token(ri); 183 token(ri);
180 if (ri->tokenType == '*') { 184 if (ri->tokenType == '*') {
181 n = createNode(ri,'*',n,0); 185 n = createNode(ri,'*',n,0);
182 } else if (ri->tokenType == '|') { 186 } else if (ri->tokenType == '|') {
183 NodePtr n1 = regex(ri); 187 NodePtr n1 = regex(ri);
184 n = createNode(ri,'|',n,n1); 188 n = createNode(ri,'|',n,n1);
185 } else if (ri->tokenType == ')') { 189 } else if (ri->tokenType == ')') {
190 if (ri->orFlag == true) {
191 ri->ptr--;
192 ri->orFlag = false;
193 }
186 return n; 194 return n;
187 } else { 195 } else {
188 // return NULL 196 // return NULL
189 NodePtr n1 = regex(ri); 197 NodePtr n1 = regex(ri);
190 n = createNode(ri,'a',n,n1); 198 n = createNode(ri,'a',n,n1);