Mercurial > hg > Members > masakoha > testcode
changeset 57:71b497d25273
fix literal()
author | Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp> |
---|---|
date | Thu, 11 Jun 2015 19:50:02 +0900 |
parents | 8901bc071d33 |
children | 4053c3e0fa7f |
files | c/regexParser/main.cc |
diffstat | 1 files changed, 14 insertions(+), 12 deletions(-) [+] |
line wrap: on
line diff
--- a/c/regexParser/main.cc Thu Jun 11 16:24:40 2015 +0900 +++ b/c/regexParser/main.cc Thu Jun 11 19:50:02 2015 +0900 @@ -10,10 +10,10 @@ #include <stdio.h> #include <stdlib.h> #include <string.h> + char *ptr; - typedef struct node { - int character; + char character; struct node *left; struct node *right; } Node, *NodePtr; @@ -23,11 +23,10 @@ NodePtr _or(); NodePtr asterisk(); NodePtr regex(); -NodePtr createNode(int,NodePtr,NodePtr); +NodePtr createNode(char,NodePtr,NodePtr); -NodePtr createNode(int character, NodePtr left, NodePtr right) { - NodePtr n; - n = (NodePtr)malloc(sizeof(Node)); +NodePtr createNode(char character, NodePtr left, NodePtr right) { + NodePtr n = (NodePtr)malloc(sizeof(Node)); n->character = character; n->left = left; n->right = right; @@ -43,13 +42,15 @@ // <literal> ::= [a-z][A-Z][0-9] NodePtr literal() { char c = *ptr; - createNode(c,0,0); + NodePtr n = createNode(c,0,0); + ptr++; + return n; } // <string> ::= <literal><literal>* NodePtr string() { char c = *ptr; - NodePtr n = (NodePtr)malloc(sizeof(Node)); + NodePtr n; if (('a'<=c && c<='z')||('A'<=c && c<='Z')||('0'<=c && c<='9')) { n = createNode(0,literal(),string()); @@ -81,15 +82,16 @@ NodePtr n; - while (int c = *ptr++) { + while (char c = *ptr) { if (c == '(') { ptr++; - _or(); + n = _or(); } else if (c == '[') { - charClass(); + n = charClass(); } else { - n = createNode(0,string(),regex()); + n = string(); } + ptr++; } return n;