changeset 106:5bf012313690

fix
author Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
date Fri, 19 Feb 2016 13:19:29 +0900
parents 7e40d0e6fba0
children efdc04a5746c
files slide/s6/index.html
diffstat 1 files changed, 41 insertions(+), 41 deletions(-) [+]
line wrap: on
line diff
--- a/slide/s6/index.html	Fri Feb 19 12:20:54 2016 +0900
+++ b/slide/s6/index.html	Fri Feb 19 13:19:29 2016 +0900
@@ -619,6 +619,36 @@
       <div class='slide'>
     <h2>並列処理時の正規表現のマッチング</h2>
 <pre>
+static
+TSValue stateNothing(TSValue tsv) {
+    return tsv;
+}
+
+static
+TSValue stateSkip(TSValue tsv) {
+    tsv.current = tsv.tg->stateStart->tState;
+    if (tsv.matchEnd) {
+        addResult(tsv,false,tsv.matchBegin,tsv.matchEnd);
+        tsv.matchEnd = NULL;
+    }
+    tsv.matchBegin = tsv.buff.buffptr;  // next char may be matchBegin
+    return tsv;
+}
+
+static
+TSValue stateMatch(TSValue tsv) {
+    tsv.matchEnd = tsv.buff.buffptr;  // next char of the match
+    return tsv;
+}
+
+typedef struct ccv {
+    unsigned long begin;
+    unsigned long end;
+    Word w;
+    BitVector state;
+    struct tState *tState;
+} CCV,*CCVPtr;
+
 typedef struct tState {
     State *state;
     tsValue (*stateSkip)(tsValue);
@@ -626,55 +656,25 @@
     int ccvSize;
     CCVPtr ccv;
 } TState, *TStatePtr;
-
-TStatePtr generateTState(StatePtr state, TransitionGeneratorPtr tg) {
-    TStatePtr tState = NEW(TState);
-    tState->state = state;
-    int ccvSize = 0;
-    CharClassWalkerPtr ccw = createCharClassWalker(state->cc);
-    while (hasNext(ccw)) {
-        getNext(ccw);
-        ccvSize++;
-    }
-    tState->ccvSize = ccvSize;
-    if (state->accept) {
-        tState->stateMatch  = tg->stateMatch;
-        tState->stateSkip  = tg->stateSkip;
-    } else {
-        tState->stateMatch  = tg->stateNothing;
-        tState->stateSkip  = tg->stateSkip;
-    }
-    if (ccvSize == 0) {
-        tState->ccv = NULL;
-        state->tState = tState;
-        return tState;
-    } else tState->ccv = (ccv*)malloc(sizeof(ccv)*ccvSize);
-    ccw = createCharClassWalker(state->cc);
-    int i = 0;
-    while (hasNext(ccw)) {
-        CharClassPtr cc = getNext(ccw);
-        unsigned long begin = cc->cond.range.begin;
-        unsigned long end = cc->cond.range.end;
-        struct ccv *ccv = &tState->ccv[i++];
-        ccv->begin = begin;
-        ccv->end = end;
-        ccv->tState = NULL;
-        ccv->state = cc->nextState;
-        ccv->w = cc->cond.w;
-    }
-    free(ccw);
-    state->tState = tState;
-    return tState;
-}
 </pre>
 
 <ul>
 <li>
-tState
+tState は状態を持ってる。
+</li>
+<li>
+文字クラスの Range の情報と遷移先は ccv に格納している。
 </li>
 <li>
+ある状態が Range にマッチする文字が入力された場合は次の状態に遷移する。
 </li>
 <li>
+ある状態が受理状態で Range にマッチしない文字が入力されたら、tState->stateSkip には stateSkip、tState->stateMatch には stateMatch を設定する。<br>
+受理状態でない場合は、tState->stateMatch に stateNothing を設定する。
+</li>
+<li>
+tState は新しい状態に遷移するときに初めて生成される。<br>
+thread ごとに on the fly で生成されるので、使わない状態は生成されない。
 </li>
 </ul>
       </div>