summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAdrian Thurston <thurston@complang.org>2008-11-09 17:47:29 +0000
committerAdrian Thurston <thurston@complang.org>2008-11-09 17:47:29 +0000
commitf4d8fc2a9ece4efc584028ab0353df9a5f459808 (patch)
treec2a621bddbdbce4b04bfe13046f2628208369535
parent8bd44760137d615df994e1773d98d894139b7422 (diff)
downloadcolm-f4d8fc2a9ece4efc584028ab0353df9a5f459808.tar.gz
The order of node visitation in the commit code was changed. It was previously
motivated by the need to execute final actions in kelbt. These were executed in the same order that try actions were executed in. Now we want to walk the undo code stack as we commit so instead visit in the order that that unparsing would visit in: rightmost, topmost.
-rw-r--r--colm/bytecode.cpp2
-rw-r--r--colm/bytecode.h2
-rw-r--r--colm/pdarun.cpp66
3 files changed, 35 insertions, 35 deletions
diff --git a/colm/bytecode.cpp b/colm/bytecode.cpp
index 7636160f..8edd1df0 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();
- full_commit( &parser );
+ commit_full( &parser );
Tree *tree = parser.getParsedRoot( stopId > 0 );
tree_upref( tree );
parser.clean();
diff --git a/colm/bytecode.h b/colm/bytecode.h
index 3e45a79a..796af736 100644
--- a/colm/bytecode.h
+++ b/colm/bytecode.h
@@ -422,7 +422,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 full_commit( PdaRun *parser );
+void commit_full( PdaRun *parser );
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 0fa9d028..00cbb975 100644
--- a/colm/pdarun.cpp
+++ b/colm/pdarun.cpp
@@ -136,22 +136,6 @@ head:
if ( alg->parsed != 0 )
tree = alg->parsed;
- /* Recurse only on non-generated trees. */
- if ( !(alg->flags & AF_GENERATED) && tree->child != 0 ) {
- vm_push( (Tree*)lel );
- lel = tree_child( parser->prg, tree );
-
- while ( lel != 0 ) {
- if ( !been_committed( lel ) )
- goto head;
-
- upwards:
- lel = lel->next;
- }
-
- lel = (Kid*)vm_pop();
- }
-
/* Commit */
#ifdef COLM_LOG_PARSE
cerr << "commit visiting: " <<
@@ -171,14 +155,41 @@ head:
}
alg->flags |= AF_COMMITTED;
- if ( sp != root )
- goto upwards;
+ /* Recurse only on non-generated trees. */
+ if ( !(alg->flags & AF_GENERATED) && tree->child != 0 ) {
+ vm_push( (Tree*)lel );
+ lel = tree_child( parser->prg, tree );
+
+ if ( lel != 0 ) {
+ while ( lel != 0 ) {
+ vm_push( (Tree*)lel );
+ lel = lel->next;
+ }
+
+ backwards:
+ lel = (Kid*)vm_pop();
+ if ( !been_committed( lel ) )
+ goto head;
+ }
+
+ upwards:
+ lel = (Kid*)vm_pop();
+ }
+
+
+ if ( sp != root ) {
+ Kid *next = (Kid*)vm_top();
+ if ( next->next == lel )
+ goto backwards;
+ else
+ goto upwards;
+ }
parser->numRetry = 0;
assert( sp == root );
}
-void full_commit( PdaRun *parser )
+void commit_full( PdaRun *parser )
{
#ifdef COLM_LOG_PARSE
cerr << "running full commit" << endl;
@@ -186,23 +197,12 @@ void full_commit( PdaRun *parser )
Tree **sp = parser->root;
Kid *kid = parser->stackTop;
- long topLevel = 0;
- while ( kid != 0 && !been_committed( kid ) ) {
- vm_push( (Tree*)kid );
- kid = kid->next;
- topLevel += 1;
- }
- while ( topLevel > 0 ) {
- kid = (Kid*)vm_pop();
+ while ( kid != 0 && !been_committed( kid ) ) {
commit_kid( parser, sp, kid );
- topLevel -= 1;
+ kid = kid->next;
}
- /* After running the commit the the stack should be where it
- * was when we started. */
- assert( sp == parser->root );
-
/* We cannot always clear all the rcode here. We may need to backup over
* the parse statement. We depend on the context flag. */
if ( !parser->revertOn ) {
@@ -383,7 +383,7 @@ again:
}
if ( tables->commitLen[pos] != 0 )
- full_commit( this );
+ commit_full( this );
if ( *action & act_rb ) {
int objectLength, reduction = *action >> 2;