Mercurial > hg > Members > masakoha > testcode
changeset 124:c363a66dc1a7 pairPro
fix
author | masa |
---|---|
date | Tue, 01 Dec 2015 17:06:26 +0900 |
parents | 8ce93ffaf1ad |
children | b061cd8205cc |
files | c/regexParser/regexParser.cc |
diffstat | 1 files changed, 22 insertions(+), 12 deletions(-) [+] |
line wrap: on
line diff
--- a/c/regexParser/regexParser.cc Tue Dec 01 00:09:09 2015 +0900 +++ b/c/regexParser/regexParser.cc Tue Dec 01 17:06:26 2015 +0900 @@ -75,6 +75,7 @@ } i++; } + // TODO literal support n->cc->cond->w->word = (unsigned char*)malloc(sizeof(unsigned char)*(i+1)); strncpy((char*)n->cc->cond->w->word, (char*)ri->ptr,i+1); @@ -104,9 +105,6 @@ ri->ptr++; ri->tokenType = '('; ri->tokenValue = NULL; - if (ri->ptr[1] == ')') { - ri->ptr++; - } return; } else if (ri->ptr[0] == ')') { ri->ptr++; @@ -117,9 +115,6 @@ ri->ptr++; ri->tokenType = 'c'; ri->tokenValue = ri->ptr; - if (ri->ptr[1] == ']') { - ri->ptr++; - } return; } else if (ri->ptr[0] == '|'){ ri->ptr++; @@ -152,36 +147,51 @@ return; } -// <regexAtom> ::= <literal>|<charClass>|<group> +// <regexAtom> ::= <literal>|<charClass> static NodePtr regexAtom(RegexInfoPtr ri) { token(ri); NodePtr n = NULL; - if (ri->tokenType == 'a') n = literal(ri); - else if (ri->tokenType == 'c') n = charClass(ri); - else if (ri->tokenType == '(') n = group(ri); + if (ri->tokenType == 'c') n = charClass(ri); return n; } // <regex> ::= <regexAtom> | <regexAtom><regex>'*' | <regexAtom>'*' | <regexAtom>'|'<regex> | <regexAtom><regex> | '(' regex ')' NodePtr regex(RegexInfoPtr ri) { - NodePtr n = regexAtom(ri); + NodePtr n = NULL; while (ri->ptr[0]) { token(ri); if (ri->tokenType == '*') { + // TODO literal support unsigned char *syntax = (unsigned char*)malloc(sizeof(unsigned char)); syntax[0] = '*'; - n = createNode(ri,syntax,n,0); + NodePtr n1 = createNode(ri,syntax,n->right,0); + + unsigned char *syntax1 = (unsigned char*)malloc(sizeof(unsigned char)); + syntax1[0] = '+'; + + n = createNode(ri,syntax1,n->left,n1); } else if (ri->tokenType == '|') { NodePtr n1 = regex(ri); unsigned char *syntax = (unsigned char*)malloc(sizeof(unsigned char)); syntax[0] = '|'; n = createNode(ri,syntax,n,n1); + } else if (ri->tokenType == '(') { + NodePtr n1 = regex(ri); + unsigned char *syntax = (unsigned char*)malloc(sizeof(unsigned char)); + syntax[0] = '+'; + n = createNode(ri,syntax,n,n1); } else if (ri->tokenType == ')') { return n; + } else if (ri->tokenType == 'a') { + NodePtr n1 = literal(ri); + unsigned char *syntax = (unsigned char*)malloc(sizeof(unsigned char)); + syntax[0] = '+'; + n = createNode(ri,syntax,n,n1); } else { + // return NULL NodePtr n1 = regex(ri); unsigned char *syntax = (unsigned char*)malloc(sizeof(unsigned char)); syntax[0] = '+';