# HG changeset patch # User masa # Date 1448096665 -32400 # Node ID 1d30f70702df1ce075450bc4c6d83e0fb4506a22 # Parent a3adc5c24e1957bdd3f3429e02c83342778268c4 add determinize.cc and transition.cc diff -r a3adc5c24e19 -r 1d30f70702df c/regexParser/determinize.cc --- /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; +} diff -r a3adc5c24e19 -r 1d30f70702df c/regexParser/regexParser.h --- 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; diff -r a3adc5c24e19 -r 1d30f70702df c/regexParser/transition.cc --- /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; +}