Mercurial > hg > Members > masakoha > testcode
diff c/regexParser/regexParser.cc @ 118:31b0ba0050fa testcode
text
author | Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp> |
---|---|
date | Thu, 26 Nov 2015 17:19:00 +0900 |
parents | 66c633575b53 |
children | 5d29b6a1b50f |
line wrap: on
line diff
--- a/c/regexParser/regexParser.cc Wed Nov 25 14:58:03 2015 +0900 +++ b/c/regexParser/regexParser.cc Thu Nov 26 17:19:00 2015 +0900 @@ -3,7 +3,8 @@ #include "regexParser.h" #include "error.h" -static NodePtr createNode(RegexInfoPtr,unsigned char,NodePtr,NodePtr); +static NodePtr allocateNode(); +static NodePtr createNode(RegexInfoPtr,unsigned char*,NodePtr,NodePtr); static NodePtr charClass(RegexInfoPtr); static NodePtr group(RegexInfoPtr); static void token(RegexInfoPtr); @@ -17,6 +18,7 @@ * stateTransitionTable */ +static NodePtr allocateNode() { NodePtr n = (NodePtr)malloc(sizeof(node)); n->cc = (CharClassPtr)malloc(sizeof(CharClass)); @@ -25,14 +27,13 @@ } static -NodePtr createNode(RegexInfoPtr ri,unsigned char character, NodePtr left, NodePtr right) { +NodePtr createNode(RegexInfoPtr ri,unsigned char *character, NodePtr left, NodePtr right) { NodePtr n = allocateNode(); if (n == NULL) { mallocFailedMessage(); } n->tokenType = ri->tokenType; - n->cc->cond->character = character; n->left = left; n->right = right; @@ -40,6 +41,13 @@ n->nodeNumber = ri->nodeNumber; ri->nodeNumber++; ri->tokenType = 0; + n->cc->cond->w = getWord(ri->tokenValue); + ri->ptr += n->cc->cond->w->length-1; + } else { + WordPtr w = (WordPtr)malloc(sizeof(Word)); + w->word = character; + w->length = 1; + n->cc->cond->w = w; } return n; } @@ -60,8 +68,7 @@ // <literal> ::= [a-z][A-Z][0-9] static NodePtr literal(RegexInfoPtr ri) { - NodePtr n = createNode(ri,ri->ptr[0],0,0); - ri->ptr++; + NodePtr n = createNode(ri,ri->ptr,0,0); return n; } @@ -77,7 +84,7 @@ if (ri->ptr[0] == '('){ ri->ptr++; ri->tokenType = '('; - ri->tokenValue = 0; + ri->tokenValue = NULL; if (ri->ptr[1] == ')') { ri->ptr++; } @@ -85,12 +92,12 @@ } else if (ri->ptr[0] == ')') { ri->ptr++; ri->tokenType = ')'; - ri->tokenValue = ri->ptr[0]; + ri->tokenValue = ri->ptr; return; } else if (ri->ptr[0] == '[') { ri->ptr++; ri->tokenType = '['; - ri->tokenValue = ri->ptr[0]; + ri->tokenValue = ri->ptr; if (ri->ptr[1] == ']') { ri->ptr++; } @@ -98,12 +105,12 @@ } else if (ri->ptr[0] == '|'){ ri->ptr++; ri->tokenType = '|'; - ri->tokenValue = 0; + ri->tokenValue = NULL; return; } else if (ri->ptr[0] == '*'){ ri->ptr++; ri->tokenType = '*'; - ri->tokenValue = 0; + ri->tokenValue = NULL; return; } else if (ri->ptr[0] == '\\'){ // need more proccesing @@ -116,7 +123,8 @@ */ } else { ri->tokenType = 'a'; - ri->tokenValue = ri->ptr[0]; + ri->tokenValue = ri->ptr; + ri->ptr++; return; } } @@ -144,15 +152,21 @@ while (ri->ptr[0]) { token(ri); if (ri->tokenType == '*') { - n = createNode(ri,'*',n,0); + unsigned char *syntax = (unsigned char*)malloc(sizeof(unsigned char)); + syntax[0] = '*'; + n = createNode(ri,syntax,n,0); } else if (ri->tokenType == '|') { NodePtr n1 = regex(ri); - n = createNode(ri,'|',n,n1); + unsigned char *syntax = (unsigned char*)malloc(sizeof(unsigned char)); + syntax[0] = '|'; + n = createNode(ri,syntax,n,n1); } else if (ri->tokenType == ')') { return n; } else { NodePtr n1 = regex(ri); - n = createNode(ri,'+',n,n1); + unsigned char *syntax = (unsigned char*)malloc(sizeof(unsigned char)); + syntax[0] = '+'; + n = createNode(ri,syntax,n,n1); } } return n; }