Mercurial > hg > Members > masakoha > testcode
changeset 74:b11dfc48f698
fix grouping function
author | masa |
---|---|
date | Fri, 28 Aug 2015 18:35:14 +0900 |
parents | 0a5dd7486bb2 |
children | 6541eae41a73 |
files | c/regexParser/main.cc |
diffstat | 1 files changed, 9 insertions(+), 2 deletions(-) [+] |
line wrap: on
line diff
--- a/c/regexParser/main.cc Thu Aug 27 16:57:28 2015 +0900 +++ b/c/regexParser/main.cc Fri Aug 28 18:35:14 2015 +0900 @@ -90,7 +90,7 @@ if (*ptr == ')') { n = createNode('(',n,0); } else { - n = regex(); + n = createNode('+', regex(),0); } return n; } @@ -99,7 +99,7 @@ void token() { while (*ptr != '\0') { - if ((*ptr == '(') || (*ptr == ')')) { + if (*ptr == '('){ ptr++; tokenType = '('; tokenValue = 0; @@ -107,6 +107,11 @@ ptr++; } return; + } else if (*ptr == ')') { + ptr++; + tokenType = ')'; + tokenValue = *ptr; + return; } else if (*ptr == '[') { ptr++; tokenType = '['; @@ -168,6 +173,8 @@ } else if (tokenType == '|') { NodePtr n1 = regex(); n = createNode('|',n,n1); + } else if (tokenType == ')') { + return n; } else { NodePtr n1 = regex(); n = createNode('+',n,n1);