Mercurial > hg > Applications > Grep
changeset 228:399380ad95b7
fix generateTransitionGenerator
author | Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp> |
---|---|
date | Fri, 15 Jan 2016 19:48:53 +0900 |
parents | 8be58af605da |
children | f2454c17e410 |
files | regexParser/bitVector.h regexParser/main.cc regexParser/subsetConstruction.cc |
diffstat | 3 files changed, 18 insertions(+), 6 deletions(-) [+] |
line wrap: on
line diff
--- a/regexParser/bitVector.h Fri Jan 15 19:11:35 2016 +0900 +++ b/regexParser/bitVector.h Fri Jan 15 19:48:53 2016 +0900 @@ -1,6 +1,6 @@ extern BitVector createBitVector(int state); extern const BitVectorPtr allocateBitVector(); -extern void bitSet(BitVectorPtr bi, int bitSetPosition); +extern BitVector bitSet(BitVector bi, int bitSetPosition); extern void bitPrint(BitVectorPtr bi); inline int searchBit(BitVector bi) {
--- a/regexParser/main.cc Fri Jan 15 19:11:35 2016 +0900 +++ b/regexParser/main.cc Fri Jan 15 19:48:53 2016 +0900 @@ -9,6 +9,7 @@ { bool generate = true; bool subset = false; + bool generateSequentialSearch = false; RegexInfo ri; ri.stateNumber = 1; @@ -19,6 +20,8 @@ generate = false; } else if (strcmp(argv[i],"-subset") == 0) { subset = true; + } else if (strcmp(argv[i],"-seq") == 0) { + generateSequentialSearch = true; } } if (!ri.ptr) return 0; @@ -31,13 +34,17 @@ TGValue tgv = generateTransitionList(n); printTree(n); printState(tgv.tg); - exportState(tgv.tg); + if (generateSequentialSearch) { + exportState(tgv.tg); + } } else if (subset) { TGValue tgv = generateTransitionList(n); SCValue scv = createSCValue(tgv); subsetConstruction(scv); // Determinization printState(tgv.tg); - exportState(tgv.tg); + if (generateSequentialSearch) { + exportState(tgv.tg); + } } return 0; }
--- a/regexParser/subsetConstruction.cc Fri Jan 15 19:11:35 2016 +0900 +++ b/regexParser/subsetConstruction.cc Fri Jan 15 19:48:53 2016 +0900 @@ -212,7 +212,7 @@ /** pass 1 : 正規表現に必要な状態を探して、それぞれに番号を割り振る 前が * でない + は新しく状態を作る - * があったら、次の状態はその時の先頭の状態になる + * があったら、次の状態はその時の先頭の状態か次の状態が終了状態ならば終了状態との組み合わせになる 常に先頭の状態を返す 最後が*ならば、それを持ち歩く pass 2: @@ -250,9 +250,14 @@ return tgv2; } else if (n->tokenType == '*') { TGValue tgvAstah = tgv; - tgvAstah.endState = tgvAstah.startState; + if (tgvAstah.endState->bitState.bitContainer & 2) { + tgvAstah.endState = tgvAstah.startState; + tgvAstah.endState->bitState = bitSet(tgvAstah.endState->bitState,1); + } else { + tgvAstah.endState = tgvAstah.startState; + } tgvAstah = generateTransition(n->left,tgvAstah,pass); - tgvAstah.asterisk = tgvAstah.startState; + tgvAstah.asterisk = tgvAstah.endState; return tgvAstah; } else if (n->tokenType == 'c' || n->tokenType == 'a'){ TGValue tgv1 = tgv;