diff options
author | Adrian Thurston <thurston@complang.org> | 2008-11-11 01:34:19 +0000 |
---|---|---|
committer | Adrian Thurston <thurston@complang.org> | 2008-11-11 01:34:19 +0000 |
commit | 5c7d8263513519b09e2638eb9cb64be1cb6d6c51 (patch) | |
tree | a65cbd165dd3bcaa81ac6c847f54354a86b855d3 | |
parent | eca13f865eb3d00191f1e88d0d83e5a8ef70c5b8 (diff) | |
download | colm-5c7d8263513519b09e2638eb9cb64be1cb6d6c51.tar.gz |
When committing we need to take into account the causeReduce of the next input
item that is waiting in the parse function.
-rw-r--r-- | colm/bytecode.cpp | 2 | ||||
-rw-r--r-- | colm/bytecode.h | 2 | ||||
-rw-r--r-- | colm/pdarun.cpp | 23 |
3 files changed, 17 insertions, 10 deletions
diff --git a/colm/bytecode.cpp b/colm/bytecode.cpp index 63fd3903..32627b5b 100644 --- a/colm/bytecode.cpp +++ b/colm/bytecode.cpp @@ -121,7 +121,7 @@ Tree *call_parser( Tree **&sp, Program *prg, Stream *stream, PdaTables *tables = prg->rtd->parsers[parserId]; PdaRun parser( sp, prg, tables, stream->scanner, stopId, revertOn ); parser.run(); - commit_full( &parser ); + commit_full( &parser, 0 ); Tree *tree = parser.getParsedRoot( stopId > 0 ); tree_upref( tree ); parser.clean(); diff --git a/colm/bytecode.h b/colm/bytecode.h index 36a79266..b46c8e40 100644 --- a/colm/bytecode.h +++ b/colm/bytecode.h @@ -424,7 +424,7 @@ void rcode_downref( Program *prg, Tree **stack_root, Code *instr ); void rcode_downref_all( Program *prg, Tree **stack_root, CodeVect *cv ); void parsed_downref( Program *prg, Tree **root, Tree *tree ); void parsed_downref_all( PdaRun *parser ); -void commit_full( PdaRun *parser ); +void commit_full( PdaRun *parser, long commitReduce ); bool match_pattern( Tree **bindings, Program *prg, long pat, Kid *kid, bool checkNext ); Head *make_literal( Program *prg, long litoffset ); diff --git a/colm/pdarun.cpp b/colm/pdarun.cpp index 8f2193d4..ba5d6042 100644 --- a/colm/pdarun.cpp +++ b/colm/pdarun.cpp @@ -149,13 +149,12 @@ Code *backup_over_rcode( Code *rcode ) /* The top level of the stack is linked right-to-left. Trees underneath are * linked left-to-right. */ -void commit_kid( PdaRun *parser, Tree **root, Kid *lel, Code *&rcode ) +void commit_kid( PdaRun *parser, Tree **root, Kid *lel, Code *&rcode, long &causeReduce ) { Alg *alg = 0; Tree *tree = 0; Tree **sp = root; Tree *restore = 0; - long causeReduce = 0; head: /* Commit */ @@ -200,8 +199,9 @@ head: /* Check causeReduce, might be time to backup over the reverse code * belonging to a nonterminal that caused previous reductions. */ - if ( tree->id >= parser->tables->rtd->firstNonTermId && - !(alg->flags & AF_GENERATED) && causeReduce > 0 ) + if ( causeReduce > 0 && + tree->id >= parser->tables->rtd->firstNonTermId && + !(alg->flags & AF_GENERATED) ) { causeReduce -= 1; @@ -261,7 +261,7 @@ backup: assert( sp == root ); } -void commit_full( PdaRun *parser ) +void commit_full( PdaRun *parser, long causeReduce ) { #ifdef COLM_LOG_PARSE cerr << "running full commit" << endl; @@ -275,7 +275,7 @@ void commit_full( PdaRun *parser ) /* The top level of the stack is linked right to left. This is the * traversal order we need for committing. */ while ( kid != 0 && !been_committed( kid ) ) { - commit_kid( parser, sp, kid, rcode ); + commit_kid( parser, sp, kid, rcode, causeReduce ); kid = kid->next; } @@ -458,8 +458,15 @@ again: #endif } - if ( tables->commitLen[pos] != 0 ) - commit_full( this ); + if ( tables->commitLen[pos] != 0 ) { + long causeReduce = 0; + if ( input != 0 ) { + Alg *alg = input->tree->alg; + if ( alg->flags & AF_HAS_RCODE ) + causeReduce = alg->causeReduce; + } + commit_full( this, causeReduce ); + } if ( *action & act_rb ) { int objectLength, reduction = *action >> 2; |