Mercurial > hg > Members > masakoha > testcode
changeset 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 | a436526756b9 |
files | c/regexParser/Makefile c/regexParser/node.cc c/regexParser/regexParser.cc c/regexParser/regexParser.h |
diffstat | 4 files changed, 20 insertions(+), 5 deletions(-) [+] |
line wrap: on
line diff
--- a/c/regexParser/Makefile Tue Dec 01 23:05:53 2015 +0900 +++ b/c/regexParser/Makefile Wed Dec 02 17:51:02 2015 +0900 @@ -32,3 +32,5 @@ ./$(TARGET) -regex "abc*d" ./$(TARGET) -regex "(ab)c*d" ./$(TARGET) -regex "a(b)c" + ./$(TARGET) -regex "(a|b|c)d" + ./$(TARGET) -regex "(a|b|c)*d"
--- a/c/regexParser/node.cc Tue Dec 01 23:05:53 2015 +0900 +++ b/c/regexParser/node.cc Wed Dec 02 17:51:02 2015 +0900 @@ -7,8 +7,11 @@ descendTree(n->right, d); d--; } - - printf("%*c%s(%lu)\n",d*4, ' ',n->cc->cond->w->word,n->nodeNumber); + if (n->tokenType != 'a') { + printf("%*c%c(%lu)\n",d*4, ' ',n->tokenType,n->nodeNumber); + } else { + printf("%*c%s(%lu)\n",d*4, ' ',n->cc->cond->w->word,n->nodeNumber); + } if (n->left != NULL) { d++;
--- a/c/regexParser/regexParser.cc Tue Dec 01 23:05:53 2015 +0900 +++ b/c/regexParser/regexParser.cc Wed Dec 02 17:51:02 2015 +0900 @@ -79,7 +79,7 @@ int i = 0; RangeListPtr rangeList = cc->cond->range; - + while (ri->ptr[i] != ']') { if (ri->ptr[i] == '-') i++; @@ -132,6 +132,7 @@ ri->ptr++; ri->tokenType = '|'; ri->tokenValue = NULL; + ri->orFlag = true; return; } else if (ri->ptr[0] == '*'){ ri->ptr++; @@ -153,13 +154,16 @@ while (isalnum(ri->ptr[0])) { ri->ptr++; } + if (ri->ptr[0] == '*') { + ri->astarFlag = true; + } return; } } return; } -// <regexAtom> ::= <literal>|<charClass> +// <regexAtom> ::= <literal>|<charClass>|<group> static NodePtr regexAtom(RegexInfoPtr ri) { @@ -172,7 +176,7 @@ return n; } -// <regex> ::= <regexAtom> | <regexAtom>'*' | <regexAtom>'|'<regex> | <regexAtom><regex> | '(' regex ')' +// <regex> ::= <regexAtom> | <regexAtom>'*'<regex> | <regexAtom>'|'<regex> | <regexAtom><regex> | NodePtr regex(RegexInfoPtr ri) { NodePtr n = regexAtom(ri); while (ri->ptr[0]) { @@ -183,6 +187,10 @@ NodePtr n1 = regex(ri); n = createNode(ri,'|',n,n1); } else if (ri->tokenType == ')') { + if (ri->orFlag == true) { + ri->ptr--; + ri->orFlag = false; + } return n; } else { // return NULL