Mercurial > hg > Members > masakoha > testcode
changeset 67:4842ca2cf8ee
print character
author | Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp> |
---|---|
date | Tue, 11 Aug 2015 15:25:21 +0900 |
parents | f8fb3b463f70 |
children | d27b3af1fe75 |
files | c/regexParser/main.cc |
diffstat | 1 files changed, 20 insertions(+), 16 deletions(-) [+] |
line wrap: on
line diff
--- a/c/regexParser/main.cc Tue Aug 04 16:41:41 2015 +0900 +++ b/c/regexParser/main.cc Tue Aug 11 15:25:21 2015 +0900 @@ -24,8 +24,8 @@ unsigned char type; union value { charClass *cc; - unsigned char *string; - }; + unsigned char character; + } Value, *ValuePtr; struct node *self; struct node *left; struct node *right; @@ -42,7 +42,7 @@ NodePtr orexp(); NodePtr asterisk(); NodePtr regex(); -NodePtr createNode(char,NodePtr,NodePtr); +NodePtr createNode(unsigned char,NodePtr,NodePtr); extern void token(); extern NodePtr regexAtom(); @@ -58,7 +58,7 @@ void printNodeDate(NodePtr n) { puts("---------------------"); - // printf("Self Node char : %c\n", n->character); + printf("Self Node char : %c\n", n->Value.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); @@ -66,10 +66,10 @@ puts(""); } -NodePtr createNode(char character, NodePtr left, NodePtr right) { +NodePtr createNode(unsigned char character, NodePtr left, NodePtr right) { NodePtr n = (NodePtr)malloc(sizeof(Node)); n->self = n; - // n->character = character; + n->Value.character = character; n->left = left; n->right = right; @@ -79,8 +79,14 @@ // <charClass> ::= '['<literal>'-'<literal>']' NodePtr charClass() { - ptr++; NodePtr n = (NodePtr)malloc(sizeof(Node)); + unsigned char startChar = *ptr; + while (*ptr == '-') { + ptr++; + } + unsigned char endChar = *ptr; + unsigned char *charTable = (unsigned char*)malloc(sizeof(char)*256); + return n; } @@ -122,15 +128,16 @@ if ((*ptr == '(') || (*ptr == ')')) { tokenType = *ptr++; tokenValue = 0; - return ; + if (ptr[1] == ')') { + ptr++; + } + return; } else if (*ptr == '[') { tokenType = '['; tokenValue = *ptr; if (ptr[1] == ']') { ptr++; } - while (*ptr != ']') ptr++; - ptr++; return; } else if (*ptr == '|'){ tokenType = '|'; @@ -185,11 +192,8 @@ NodePtr n1 = regex(); n = createNode('+',n,n1); } - } - return n; -} - - + } return n; +} /* * e.g. * @@ -216,7 +220,7 @@ * */ void printTree(NodePtr n) { - + }