Mercurial > hg > Members > masakoha > testcode
changeset 111:1d30f70702df pairPro
add determinize.cc and transition.cc
author | masa |
---|---|
date | Sat, 21 Nov 2015 18:04:25 +0900 |
parents | a3adc5c24e19 |
children | ec485345daf9 |
files | c/regexParser/determinize.cc c/regexParser/regexParser.h c/regexParser/transition.cc |
diffstat | 3 files changed, 63 insertions(+), 12 deletions(-) [+] |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/c/regexParser/determinize.cc Sat Nov 21 18:04:25 2015 +0900 @@ -0,0 +1,16 @@ +#include "transition.h" + +TransitionPtr determinize(TransitionPtr cond, TransitionPtr list) { + TransitionPtr x0 = createTransition(x->condition, x->nextState); + TransitionPtr x1 = x0; + for(;;) { + if (x->next == NULL) { + x1->next = y; + return x0; + } + x = x->next; + x1->next = createTransition(x->condition, x->nextState); + x1 = x1->next; + } + return x0; +}
--- a/c/regexParser/regexParser.h Fri Nov 20 21:02:00 2015 +0900 +++ b/c/regexParser/regexParser.h Sat Nov 21 18:04:25 2015 +0900 @@ -1,10 +1,15 @@ typedef struct charClass { - unsigned char table[256]; - struct utf8Range { - unsigned char *begin; - unsigned char *end; - struct utf8Range *next; - } *rangeList; + unsigned char type; + union condition { + struct utf8Range { + unsigned char *begin; + unsigned char *end; + struct utf8Range *next; + } rangeList; + unsigned char character; + WordPtr w; + } *conditionList; + struct charClass *next; } CharClass, *CharClassPtr; typedef struct word { @@ -14,12 +19,8 @@ typedef struct node { unsigned char tokenType; - int nodeNumber; - union value { - CharClassPtr cc; - unsigned char character; - WordPtr w; - } Value, *ValuePtr; + unsigned long nodeNumber; + CharClassPtr cc; struct node *left; struct node *right; } Node, *NodePtr;
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/c/regexParser/transition.cc Sat Nov 21 18:04:25 2015 +0900 @@ -0,0 +1,34 @@ +#include "transition.h" + +TransitionPtr createTransition(CharClassPtr cc, BitVectorPtr state) { + TransitionPtr transition = (TransitionPtr)malloc(sizeof(Transition)); + transition->condition = cc; + transition->nextState = state; + return transition; +} + +TransitionPtr appendTransition0(TransitionPtr x, TransitionPtr y) { + TransitionPtr x0 = x; + for(;;) { + if (x->next == NULL) { + x->next = y + return x0; + } + } + return x; +} + +TransitionPtr appendTransition(TransitionPtr x, TransitionPtr y) { + TransitionPtr x0 = createTransition(x->condition, x->nextState); + TransitionPtr x1 = x0; + for(;;) { + if (x->next == NULL) { + x1->next = y; + return x0; + } + x = x->next; + x1->next = createTransition(x->condition, x->nextState); + x1 = x1->next; + } + return x0; +}