Mercurial > hg > Members > masakoha > testcode
changeset 122:188d866227a4 pairPro
fix
author | Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp> |
---|---|
date | Mon, 30 Nov 2015 23:43:53 +0900 |
parents | aa266a4db47c |
children | 8ce93ffaf1ad |
files | c/regexParser/regexParser.cc c/regexParser/regexParser.h |
diffstat | 2 files changed, 31 insertions(+), 10 deletions(-) [+] |
line wrap: on
line diff
--- a/c/regexParser/regexParser.cc Thu Nov 26 21:17:26 2015 +0900 +++ b/c/regexParser/regexParser.cc Mon Nov 30 23:43:53 2015 +0900 @@ -1,5 +1,7 @@ #include <stdlib.h> #include <stdio.h> +#include <string.h> +#include <ctype.h> #include "regexParser.h" #include "error.h" @@ -42,7 +44,6 @@ if (ri->tokenType == 'a') { 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; @@ -55,13 +56,31 @@ // <charClass> ::= '['<literal>'-'<literal>']' static NodePtr charClass(RegexInfoPtr ri) { - NodePtr n = (NodePtr)malloc(sizeof(Node)); + NodePtr n = allocateNode(); if (n == NULL) { mallocFailedMessage(); } - while (ri->ptr[0] == '-') { - ri->ptr++; + + n->tokenType = ri->tokenType; + n->nodeNumber = ri->nodeNumber; + ri->nodeNumber++; + n->cc->cond->w = (WordPtr)malloc(sizeof(Word)); + + int i = 0; + + while (ri->ptr[i] != ']') { + if (ri->ptr[i] == '-') { + n->cc->begin = ri->ptr[i-1]; + n->cc->end = ri->ptr[i+1]; + } + i++; } + + n->cc->cond->w->word = (unsigned char*)malloc(sizeof(unsigned char)*(i+1)); + strncpy((char*)n->cc->cond->w->word, (char*)ri->ptr,i+1); + n->cc->cond->w->word[i] = '\0'; + ri->ptr += i+1; + return n; } @@ -96,7 +115,7 @@ return; } else if (ri->ptr[0] == '[') { ri->ptr++; - ri->tokenType = '['; + ri->tokenType = 'c'; ri->tokenValue = ri->ptr; if (ri->ptr[1] == ']') { ri->ptr++; @@ -124,7 +143,9 @@ } else { ri->tokenType = 'a'; ri->tokenValue = ri->ptr; - ri->ptr++; + while (isalnum(ri->ptr[0])) { + ri->ptr++; + } return; } } @@ -138,13 +159,13 @@ token(ri); NodePtr n = NULL; if (ri->tokenType == 'a') n = literal(ri); - else if (ri->tokenType == '[') n = charClass(ri); + else if (ri->tokenType == 'c') n = charClass(ri); else if (ri->tokenType == '(') n = group(ri); return n; } -// <regex> ::= <regexAtom>|<regexAtom>'*'|<regexAtom>'|'<regex>|<regexAtom><regex> +// <regex> ::= <regexAtom> | <regexAtom><regex>'*' | <regexAtom>'*' | <regexAtom>'|'<regex> | <regexAtom><regex> | '(' regex ')' NodePtr regex(RegexInfoPtr ri) { NodePtr n = regexAtom(ri); while (ri->ptr[0]) {
--- a/c/regexParser/regexParser.h Thu Nov 26 21:17:26 2015 +0900 +++ b/c/regexParser/regexParser.h Mon Nov 30 23:43:53 2015 +0900 @@ -15,8 +15,8 @@ ConditionList cond; struct charClass *left; struct charClass *right; - unsigned long *begin; - unsigned long *end; + unsigned char begin; + unsigned char end; } CharClass, *CharClassPtr; typedef struct node {