Mercurial > hg > Members > masakoha > testcode
changeset 71:58d2b10988c9
move ptr++ in token()
author | Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp> |
---|---|
date | Tue, 25 Aug 2015 20:56:26 +0900 |
parents | 87dff3a124ab |
children | c4b934048e2a |
files | c/regexParser/main.cc |
diffstat | 1 files changed, 10 insertions(+), 4 deletions(-) [+] |
line wrap: on
line diff
--- a/c/regexParser/main.cc Tue Aug 25 13:02:56 2015 +0900 +++ b/c/regexParser/main.cc Tue Aug 25 20:56:26 2015 +0900 @@ -98,11 +98,9 @@ // <group> ::= '('<regex>')' NodePtr group() { - ptr++; NodePtr n = regex(); if (*ptr == ')') { n = createNode('(',n,0); - ptr++; } else { // ) reqiured } @@ -110,9 +108,11 @@ } + void token() { while (*ptr != '\0') { if ((*ptr == '(') || (*ptr == ')')) { + ptr++; tokenType = '('; tokenValue = 0; if (ptr[1] == ')') { @@ -120,6 +120,7 @@ } return; } else if (*ptr == '[') { + ptr++; tokenType = '['; tokenValue = *ptr; if (ptr[1] == ']') { @@ -127,10 +128,12 @@ } return; } else if (*ptr == '|'){ + ptr++; tokenType = '|'; tokenValue = 0; return; } else if (*ptr == '*'){ + ptr++; tokenType = '*'; tokenValue = 0; return; @@ -150,6 +153,10 @@ */ } + + tokenType = 0; + tokenValue = 0; + return; } // <regexAtom> ::= <literal>|<charClass>|<group> @@ -170,9 +177,8 @@ while (*ptr) { token(); if (tokenType == '*') { - n = createNode('*',n,0); ptr++; + n = createNode('*',n,0); } else if (tokenType == '|') { - ptr++; NodePtr n1 = regex(); n = createNode('|',n,n1); } else {