diff options
author | Adrian Thurston <thurston@complang.org> | 2011-11-19 06:15:16 +0000 |
---|---|---|
committer | Adrian Thurston <thurston@complang.org> | 2011-11-19 06:15:16 +0000 |
commit | 1afd6c564f69918e6f5beea1984f56856b169beb (patch) | |
tree | 077c7a54cbc943192d101297c1ce66679f631b4d /colm | |
parent | 4dd3e3c3635657b7cf0b984ef795ecfa20eb9b2f (diff) | |
download | colm-1afd6c564f69918e6f5beea1984f56856b169beb.tar.gz |
Use zero for the null region. Required shifting the array over by one.
Entirely removed tree arg to pushBtPoint. Backtracking points are all computed
now from accumIgnore and the token list.
Diffstat (limited to 'colm')
-rw-r--r-- | colm/fsmrun.c | 12 | ||||
-rw-r--r-- | colm/pdabuild.cc | 10 | ||||
-rw-r--r-- | colm/pdarun.c | 29 | ||||
-rw-r--r-- | colm/pdarun.h | 2 |
4 files changed, 23 insertions, 30 deletions
diff --git a/colm/fsmrun.c b/colm/fsmrun.c index 4b2d97c5..a64988fc 100644 --- a/colm/fsmrun.c +++ b/colm/fsmrun.c @@ -497,9 +497,6 @@ void ignoreTree( Program *prg, PdaRun *pdaRun, Tree *tree ) if ( pdaRun->tables->tokenRegions[pt(tree)->region+1] != 0 ) pdaRun->numRetry += 1; } - else { - pt(tree)->region = -1; - } /* Add the ignore string to the head of the ignore list. */ Kid *ignore = kidAllocate( prg ); @@ -759,8 +756,6 @@ void sendIgnore( Program *prg, Tree **sp, InputStream *inputStream, FsmRun *fsmR tree->id = id; tree->tokdata = ignoreStr; - pt(tree)->region = pdaRun->nextRegionInd; - incrementConsumed( pdaRun ); /* Send it to the pdaRun. */ @@ -1116,7 +1111,7 @@ case PcrPreEof: debug( REALM_PARSE, "invoking parse error from the scanner\n" ); /* Fall through to send null (error). */ - pushBtPoint( prg, pdaRun, 0 ); + pushBtPoint( prg, pdaRun ); } else { debug( REALM_PARSE, "no alternate scanning regions\n" ); @@ -1124,7 +1119,7 @@ case PcrPreEof: /* There are no alternative scanning regions to try, nor are * there any alternatives stored in the current parse tree. No * choice but to end the parse. */ - pushBtPoint( prg, pdaRun, 0 ); + pushBtPoint( prg, pdaRun ); reportParseError( prg, sp, pdaRun ); pdaRun->parseError = 1; @@ -1203,9 +1198,6 @@ case PcrGeneration: if ( pdaRun->tables->tokenRegions[pt(pdaRun->input2->tree)->region+1] != 0 ) pdaRun->numRetry += 1; } - else - pt(pdaRun->input2->tree)->region = -1; - } assert( pdaRun->input1 == 0 ); diff --git a/colm/pdabuild.cc b/colm/pdabuild.cc index 007d7205..00fe768f 100644 --- a/colm/pdabuild.cc +++ b/colm/pdabuild.cc @@ -1842,9 +1842,10 @@ PdaTables *ParseData::makePdaTables( PdaGraph *pdaGraph ) pdaTables->commitLen[count++] = asi->key.commitLen; /* - * tokenRegionInds + * tokenRegionInds. Start at one so region index 0 is null (unset). */ - count = pos = 0; + count = 0; + pos = 1; pdaTables->tokenRegionInds = new int[pdaTables->numStates]; for ( PdaStateList::Iter state = pdaGraph->stateList; state.lte(); state++ ) { pdaTables->tokenRegionInds[count++] = pos; @@ -1852,10 +1853,10 @@ PdaTables *ParseData::makePdaTables( PdaGraph *pdaGraph ) } /* - * tokenRegions + * tokenRegions. Build in a null at the beginning. */ - count = 0; + count = 1; for ( PdaStateList::Iter state = pdaGraph->stateList; state.lte(); state++ ) count += state->regions.length() + 1; @@ -1863,6 +1864,7 @@ PdaTables *ParseData::makePdaTables( PdaGraph *pdaGraph ) pdaTables->tokenRegions = new int[pdaTables->numRegionItems]; count = 0; + pdaTables->tokenRegions[count++] = 0; for ( PdaStateList::Iter state = pdaGraph->stateList; state.lte(); state++ ) { for ( RegionVect::Iter reg = state->regions; reg.lte(); reg++ ) pdaTables->tokenRegions[count++] = (*reg)->id + 1; diff --git a/colm/pdarun.c b/colm/pdarun.c index 2262ecdf..aceb1753 100644 --- a/colm/pdarun.c +++ b/colm/pdarun.c @@ -353,14 +353,13 @@ void commitFull( Program *prg, Tree **sp, PdaRun *pdaRun, long causeReduce ) } /* Tree null means compute from what we find in the parser. */ -void pushBtPoint( Program *prg, PdaRun *pdaRun, Tree *tree ) +void pushBtPoint( Program *prg, PdaRun *pdaRun ) { - if ( tree == 0 ) { - if ( pdaRun->accumIgnore != 0 ) - tree = pdaRun->accumIgnore->tree; - else if ( pdaRun->tokenList != 0 ) - tree = pdaRun->tokenList->kid->tree; - } + Tree *tree = 0; + if ( pdaRun->accumIgnore != 0 ) + tree = pdaRun->accumIgnore->tree; + else if ( pdaRun->tokenList != 0 ) + tree = pdaRun->tokenList->kid->tree; if ( tree != 0 ) { debug( REALM_PARSE, "pushing bt point with location byte %d\n", @@ -457,7 +456,7 @@ again: if ( pdaRun->lel->tree->id < pdaRun->tables->keys[pdaRun->curState<<1] || pdaRun->lel->tree->id > pdaRun->tables->keys[(pdaRun->curState<<1)+1] ) { debug( REALM_PARSE, "parse error, no transition 1\n" ); - pushBtPoint( prg, pdaRun, 0 ); + pushBtPoint( prg, pdaRun ); goto parseError; } @@ -467,14 +466,14 @@ again: owner = pdaRun->tables->owners[indPos]; if ( owner != pdaRun->curState ) { debug( REALM_PARSE, "parse error, no transition 2\n" ); - pushBtPoint( prg, pdaRun, 0 ); + pushBtPoint( prg, pdaRun ); goto parseError; } pos = pdaRun->tables->indicies[indPos]; if ( pos < 0 ) { debug( REALM_PARSE, "parse error, no transition 3\n" ); - pushBtPoint( prg, pdaRun, 0 ); + pushBtPoint( prg, pdaRun ); goto parseError; } @@ -663,7 +662,7 @@ case PcrReduction: pdaRun->redLel->next = pdaRun->stackTop; pdaRun->stackTop = pdaRun->redLel; /* FIXME: What is the right argument here? */ - pushBtPoint( prg, pdaRun, pdaRun->lel->tree ); + pushBtPoint( prg, pdaRun ); goto parseError; } @@ -697,7 +696,7 @@ parseError: * current input1 token then we are finished with it. Send it back. */ if ( pt(pdaRun->input1->tree)->causeReduce == 0 ) { long region = pt(pdaRun->input1->tree)->region; - pdaRun->next = region >= 0 ? region + 1 : -1; + pdaRun->next = region > 0 ? region + 1 : 0; long pcr = sendBack( prg, sp, pdaRun, fsmRun, inputStream, pdaRun->input1, PcrStart ); while ( pcr != PcrDone ) { @@ -708,7 +707,7 @@ case PcrRevToken: pdaRun->input1 = 0; - if ( pdaRun->next >= 0 && pdaRun->tables->tokenRegions[pdaRun->next] != 0 ) { + if ( pdaRun->next > 0 && pdaRun->tables->tokenRegions[pdaRun->next] != 0 ) { debug( REALM_PARSE, "found a new region\n" ); pdaRun->numRetry -= 1; pdaRun->cs = stackTopTarget( prg, pdaRun ); @@ -735,7 +734,7 @@ case PcrRevToken: pdaRun->ignore6->next = 0; long region = pt(pdaRun->ignore6->tree)->region; - pdaRun->next = region >= 0 ? region + 1 : -1; + pdaRun->next = region > 0 ? region + 1 : 0; long pcr = sendBackIgnore( prg, sp, pdaRun, fsmRun, inputStream, pdaRun->ignore6, PcrStart ); while ( pcr != PcrDone ) { @@ -746,7 +745,7 @@ case PcrRevIgnore: pcr = sendBackIgnore( prg, sp, pdaRun, fsmRun, inputStream, pdaRun->ignore6, entry ); } - if ( pdaRun->next >= 0 && pdaRun->tables->tokenRegions[pdaRun->next] != 0 ) { + if ( pdaRun->next > 0 && pdaRun->tables->tokenRegions[pdaRun->next] != 0 ) { debug( REALM_PARSE, "found a new region\n" ); pdaRun->numRetry -= 1; pdaRun->cs = stackTopTarget( prg, pdaRun ); diff --git a/colm/pdarun.h b/colm/pdarun.h index f039e325..41a0283e 100644 --- a/colm/pdarun.h +++ b/colm/pdarun.h @@ -374,7 +374,7 @@ long parseLoop( struct ColmProgram *prg, Tree **sp, PdaRun *pdaRun, FsmRun *fsmRun, InputStream *inputStream, long entry ); void initBindings( PdaRun *pdaRun ); Tree *getParsedRoot( PdaRun *pdaRun, int stop ); -void pushBtPoint( struct ColmProgram *prg, PdaRun *pdaRun, Tree *tree ); +void pushBtPoint( struct ColmProgram *prg, PdaRun *pdaRun ); void undoParseStream( struct ColmProgram *prg, Tree **sp, InputStream *inputStream, FsmRun *fsmRun, PdaRun *pdaRun, long consumed ); void attachIgnore( struct ColmProgram *prg, Tree **sp, PdaRun *pdaRun, Kid *input ); |