Mercurial > hg > Applications > Grep
changeset 60:8616a045a7f4
impl asterisk
author | Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp> |
---|---|
date | Tue, 14 Jul 2015 15:30:34 +0900 |
parents | af189c727733 |
children | 67cade0e35b0 |
files | c/regexParser/main.cc |
diffstat | 1 files changed, 17 insertions(+), 5 deletions(-) [+] |
line wrap: on
line diff
--- a/c/regexParser/main.cc Tue Jul 14 14:08:36 2015 +0900 +++ b/c/regexParser/main.cc Tue Jul 14 15:30:34 2015 +0900 @@ -30,6 +30,16 @@ NodePtr regex(); NodePtr createNode(char,NodePtr,NodePtr); +void printNodeDate(NodePtr n) { + puts("---------------------"); + printf("Self Node char : %c\n", n->character); + printf("Self Node addr : %p\n", n->self); + printf("left Node addr : %p\n", n->left); + printf("right Node addr : %p\n", n->right); + puts("---------------------"); + puts(""); +} + NodePtr createNode(char character, NodePtr left, NodePtr right) { NodePtr n = (NodePtr)malloc(sizeof(Node)); n->self = n; @@ -37,14 +47,13 @@ n->left = left; n->right = right; + printNodeDate(n); return n; } // <charClass> ::= '['<literal>'-'<literal>']' NodePtr charClass() { - ptr++; - NodePtr n = createNode(0,0,0); - return n; + } // <literal> ::= [a-z][A-Z][0-9] @@ -59,7 +68,6 @@ NodePtr string() { char c = *ptr; NodePtr n = NULL; - printf("%c\n",c); if (('a'<=c && c<='z')||('A'<=c && c<='Z')||('0'<=c && c<='9')) { n = createNode(0,literal(),string()); } else { @@ -92,7 +100,9 @@ // <*> ::= <regex>'*' NodePtr asterisk() { - + ptr++; + NodePtr n = createNode('*',regexHeadNode,regex()); + return n; } // <regex> ::= <string>|<or>|<charClass>|<group>|<*> @@ -107,6 +117,8 @@ n = charClass(); } else if (*ptr == '|'){ n = _or(); + } else if (*ptr == '*'){ + n = asterisk(); } else { n = string(); regexHeadNode = n;