commit 62374cf018ebabcca7d6f4bd1f2a8afd8ef6e3ad Author: Tanmai Khanna Date: Wed Aug 12 00:58:02 2020 +0530 added variable wblank map | tests added diff --git a/src/matcher.h b/src/matcher.h index 499aabb..da69cab 100644 --- a/src/matcher.h +++ b/src/matcher.h @@ -358,6 +358,7 @@ public: int lastWord; int id; map stringVars; + map wblankVars; vector chunkVars; ParseNode() : first(0), last(0), firstWord(0), lastWord(0), id(-1) @@ -393,6 +394,7 @@ public: mx = prevNode->mx; length = prev->length+1; stringVars = prev->stringVars; + wblankVars = prev->wblankVars; chunkVars = prev->chunkVars; weight = (w == 0) ? prev->weight : w; if(next->isBlank) @@ -418,6 +420,7 @@ public: firstWord = prev->lastWord+1; lastWord = firstWord; stringVars = prev->stringVars; + wblankVars = prev->wblankVars; chunkVars = prev->chunkVars; if(next->isBlank) { @@ -446,6 +449,7 @@ public: firstWord = other->firstWord; lastWord = other->lastWord; stringVars = other->stringVars; + wblankVars = other->wblankVars; chunkVars = other->chunkVars; } void getChunks(list& chls, int count) diff --git a/src/rtx_processor.cc b/src/rtx_processor.cc index 5a2adbf..b002598 100644 --- a/src/rtx_processor.cc +++ b/src/rtx_processor.cc @@ -659,6 +659,8 @@ RTXProcessor::applyRule(const wstring& rule) wstring var = popString(); wstring val = popString(); currentBranch->stringVars[var] = val; + currentBranch->wblankVars[var] = theWblankStack[stackIdx+1]; + theWblankStack[stackIdx+1].clear(); if(printingSteps) { wcerr << " -> " << var << " = '" << val << "'" << endl; } } break; @@ -840,7 +842,8 @@ RTXProcessor::applyRule(const wstring& rule) { wstring name = popString(); wstring val = currentBranch->stringVars[name]; - pushStack(val); + wstring wblank_val = currentBranch->wblankVars[name]; + pushStack(val, wblank_val); if(printingSteps) { wcerr << " -> " << name << " = " << val << endl; } } break; @@ -1401,6 +1404,7 @@ RTXProcessor::checkForReduce(vector& result, ParseNode* node) cur->init(back, currentOutput[0], weight); } cur->stringVars = node->stringVars; + cur->wblankVars = node->wblankVars; cur->chunkVars = node->chunkVars; cur->id = node->id; if(temp.size() == 0) @@ -1420,6 +1424,7 @@ RTXProcessor::checkForReduce(vector& result, ParseNode* node) cur = parsePool.next(); cur->init(*it, temp.back()); cur->stringVars = (*it)->stringVars; + cur->wblankVars = (*it)->wblankVars; cur->chunkVars = (*it)->chunkVars; cur->firstWord = first; cur->lastWord = last; @@ -1796,6 +1801,7 @@ RTXProcessor::processGLR(FILE *in, FILE *out) temp->init(mx, next); temp->id = ++newBranchId; temp->stringVars = variables; + temp->wblankVars = wblank_variables; temp->chunkVars = vector(varCount, NULL); checkForReduce(parseGraph, temp); } @@ -1810,6 +1816,7 @@ RTXProcessor::processGLR(FILE *in, FILE *out) tempNode->init(parseGraph[i], next, true); tempNode->id = parseGraph[i]->id; tempNode->stringVars = parseGraph[i]->stringVars; + tempNode->wblankVars = parseGraph[i]->wblankVars; tempNode->chunkVars = parseGraph[i]->chunkVars; checkForReduce(temp, tempNode); } @@ -1865,6 +1872,7 @@ RTXProcessor::processGLR(FILE *in, FILE *out) parseGraph.clear(); outputAll(out); variables = currentBranch->stringVars; + wblank_variables = currentBranch->wblankVars; fflush(out); vector wblanks; vector sources; diff --git a/src/rtx_processor.h b/src/rtx_processor.h index 2c92607..72200aa 100644 --- a/src/rtx_processor.h +++ b/src/rtx_processor.h @@ -56,6 +56,12 @@ private: * name => value */ map variables; + + /** + * Virtual machine global variables to wblank map + * name => value + */ + map wblank_variables; /** * Lists diff --git a/tests/WblankVariableTRX.input b/tests/WblankVariableTRX.input new file mode 100644 index 0000000..785faaf --- /dev/null +++ b/tests/WblankVariableTRX.input @@ -0,0 +1,2 @@ +[[t:b:123abc]]^the/el$ [[t:i:asfkl3]]^green/verde$ [[t:s:098sjd]]^dragon/dragón$ [[t:b:po234f]]^sleep/duerme$[[t:b:8snx23]]^./.$ +[[t:i:xyzkm2]]^the/el$ [[t:n:124fcd]]^green/verde$ [[t:b:832dax]]^dragon/dragón$ [[t:s:24nda1]]^sleep/duerme$[[t:i:512rw9]]^./.$ diff --git a/tests/WblankVariableTRX.output b/tests/WblankVariableTRX.output new file mode 100644 index 0000000..775c35c --- /dev/null +++ b/tests/WblankVariableTRX.output @@ -0,0 +1,2 @@ +[[t:b:123abc]]^el$ [[t:s:098sjd; t:s:098sjd]]^dragón$ [[t:i:asfkl3]]^verde$ [[t:b:po234f; t:b:po234f]]^duerme$[[t:b:8snx23]]^.$ +[[t:i:xyzkm2]]^el$ [[t:b:832dax; t:b:832dax]]^dragón$ [[t:n:124fcd]]^verde$ [[t:s:24nda1; t:s:24nda1]]^duerme$[[t:i:512rw9]]^.$ diff --git a/tests/WblankVariableTRX.trx b/tests/WblankVariableTRX.trx new file mode 100644 index 0000000..e9089ab --- /dev/null +++ b/tests/WblankVariableTRX.trx @@ -0,0 +1,95 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +