Mercurial > hg > Applications > Grep
comparison c/regexParser/regexParser.cc @ 128:f827682d4687 pairPro
fix
author | Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp> |
---|---|
date | Tue, 01 Dec 2015 22:50:58 +0900 |
parents | b061cd8205cc |
children | b930be74a16e |
comparison
equal
deleted
inserted
replaced
127:b061cd8205cc | 128:f827682d4687 |
---|---|
164 NodePtr regexAtom(RegexInfoPtr ri) { | 164 NodePtr regexAtom(RegexInfoPtr ri) { |
165 | 165 |
166 token(ri); | 166 token(ri); |
167 NodePtr n = NULL; | 167 NodePtr n = NULL; |
168 if (ri->tokenType == 'c') n = charClass(ri); | 168 if (ri->tokenType == 'c') n = charClass(ri); |
169 if (ri->tokenType == 'a') n = literal(ri); | |
170 if (ri->tokenType == '(') n = group(ri); | |
169 | 171 |
170 return n; | 172 return n; |
171 } | 173 } |
172 | 174 |
173 // <regex> ::= <regexAtom> | <regexAtom>'*' | <regexAtom>'|'<regex> | <regexAtom><regex> | '(' regex ')' | 175 // <regex> ::= <regexAtom> | <regexAtom>'*' | <regexAtom>'|'<regex> | <regexAtom><regex> | '(' regex ')' |
174 NodePtr regex(RegexInfoPtr ri) { | 176 NodePtr regex(RegexInfoPtr ri) { |
175 NodePtr n = NULL; | 177 NodePtr n = regexAtom(ri); |
176 while (ri->ptr[0]) { | 178 while (ri->ptr[0]) { |
177 token(ri); | 179 token(ri); |
178 if (ri->tokenType == '*') { | 180 if (ri->tokenType == '*') { |
179 n = createNode(ri,'*',n,0); | 181 n = createNode(ri,'*',n,0); |
180 } else if (ri->tokenType == '|') { | 182 } else if (ri->tokenType == '|') { |
181 NodePtr n1 = regex(ri); | 183 NodePtr n1 = regex(ri); |
182 n = createNode(ri,'|',n,n1); | 184 n = createNode(ri,'|',n,n1); |
183 } else if (ri->tokenType == ')') { | 185 } else if (ri->tokenType == ')') { |
184 return n; | 186 return n; |
185 } else if (ri->tokenType == 'a') { | |
186 NodePtr n1 = literal(ri); | |
187 unsigned char *syntax = (unsigned char*)malloc(sizeof(unsigned char)); | |
188 syntax[0] = '+'; | |
189 n = createNode(ri,syntax,n,n1); | |
190 } else { | 187 } else { |
191 // return NULL | 188 // return NULL |
192 NodePtr n1 = regex(ri); | 189 NodePtr n1 = regex(ri); |
193 n = createNode(ri,'a',n,n1); | 190 n = createNode(ri,'a',n,n1); |
194 } | 191 } |