# HG changeset patch # User Masataka Kohagura # Date 1448261659 -32400 # Node ID ec485345daf90a42bd3b76d1e50a41f3b3d31f81 # Parent 1d30f70702df1ce075450bc4c6d83e0fb4506a22 some function use static diff -r 1d30f70702df -r ec485345daf9 c/regexParser/createRegexParser.cc --- a/c/regexParser/createRegexParser.cc Sat Nov 21 18:04:25 2015 +0900 +++ b/c/regexParser/createRegexParser.cc Mon Nov 23 15:54:19 2015 +0900 @@ -2,11 +2,11 @@ #include #include "regexParser.h" -NodePtr createNode(RegexInfoPtr,unsigned char,NodePtr,NodePtr); -NodePtr charClass(RegexInfoPtr); -NodePtr group(RegexInfoPtr); -void token(RegexInfoPtr); -NodePtr regexAtom(RegexInfoPtr); +static NodePtr createNode(RegexInfoPtr,unsigned char,NodePtr,NodePtr); +static NodePtr charClass(RegexInfoPtr); +static NodePtr group(RegexInfoPtr); +static void token(RegexInfoPtr); +static NodePtr regexAtom(RegexInfoPtr); NodePtr regex(RegexInfoPtr); /** @@ -15,11 +15,12 @@ * regexPosition(state) * stateTransitionTable */ + +static NodePtr createNode(RegexInfoPtr ri,unsigned char character, NodePtr left, NodePtr right) { NodePtr n = (NodePtr)malloc(sizeof(Node)); if (n == NULL) { - fprintf(stderr, "Failed to allocate memory.\n"); - exit(-1); + mallocFailedMessage(); } n->tokenType = ri->tokenType; @@ -44,11 +45,11 @@ } // ::= '[''-'']' +static NodePtr charClass(RegexInfoPtr ri) { NodePtr n = (NodePtr)malloc(sizeof(Node)); if (n == NULL) { - fprintf(stderr, "Failed to allocate memory.\n"); - exit(-1); + mallocFailedMessage(); } while (ri->ptr[0] == '-') { ri->ptr++; @@ -57,6 +58,7 @@ } // ::= [a-z][A-Z][0-9] +static NodePtr literal(RegexInfoPtr ri) { NodePtr n = createNode(ri,ri->ptr[0],0,0); ri->ptr++; @@ -64,12 +66,12 @@ } // ::= '('')' +static NodePtr group(RegexInfoPtr ri) { return regex(ri); } - - +static void token(RegexInfoPtr ri) { while (ri->ptr[0] != '\0') { if (ri->ptr[0] == '('){ @@ -124,6 +126,7 @@ } // ::= || +static NodePtr regexAtom(RegexInfoPtr ri) { token(ri); diff -r 1d30f70702df -r ec485345daf9 c/regexParser/node.cc --- a/c/regexParser/node.cc Sat Nov 21 18:04:25 2015 +0900 +++ b/c/regexParser/node.cc Mon Nov 23 15:54:19 2015 +0900 @@ -1,10 +1,12 @@ #include #include "regexParser.h" -void descendTree(NodePtr n, int d) { +static void descendTree(NodePtr,int); +void printTree(NodePtr); + +static void descendTree(NodePtr n, int d) { if (n->right != NULL) { - d++; - descendTree(n->right, d); + descendTree(n->right, d+1); d--; } if (n->tokenType == 'a') { @@ -14,8 +16,7 @@ } if (n->left != NULL) { - d++; - descendTree(n->left, d); + descendTree(n->left, d+1); d--; } } diff -r 1d30f70702df -r ec485345daf9 c/regexParser/transition.cc --- a/c/regexParser/transition.cc Sat Nov 21 18:04:25 2015 +0900 +++ b/c/regexParser/transition.cc Mon Nov 23 15:54:19 2015 +0900 @@ -1,5 +1,9 @@ #include "transition.h" +TransitionPtr createTransition(CharClass,BitVectorPtr); +TransitionPtr appendTransition0(TransitionPtr,TransitionPtr); +TransitionPtr appendTransition(TransitionPtr,TransitionPtr); + TransitionPtr createTransition(CharClassPtr cc, BitVectorPtr state) { TransitionPtr transition = (TransitionPtr)malloc(sizeof(Transition)); transition->condition = cc; diff -r 1d30f70702df -r ec485345daf9 c/regexParser/transition.h --- a/c/regexParser/transition.h Sat Nov 21 18:04:25 2015 +0900 +++ b/c/regexParser/transition.h Mon Nov 23 15:54:19 2015 +0900 @@ -11,17 +11,16 @@ } State; StatePtr; /* 正規表現木を辿って transition のList をつくる - HcarClass のかさなりを判定して重なりのない新しいCharClassをつくる + CharClass のかさなりを判定して重なりのない新しいCharClassをつくる 重なっている状態はbitvectorのorをとる 重なっている状態はそれぞれの状態について木をたどる - + nextState == 0 は正規表現の末端を表す nextState == 1 は受理状態を表す 正規表現のノードの番号 n に対応する 2^n のbitをセットした状態 - - + | の場合は両方のListを結合する + の場合は左のノードに * がある場合は右のリストも結合する - 左のノードにあすたがない場合は、右のほうだけみる + 左のノードに*がない場合は、右のほうだけみる * は直下のリストを使って、次の状態を自分自身にする */