summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAdrian Thurston <thurston@complang.org>2008-11-09 00:27:56 +0000
committerAdrian Thurston <thurston@complang.org>2008-11-09 00:27:56 +0000
commit8bd44760137d615df994e1773d98d894139b7422 (patch)
treeab6f066b6a4d82505cdb85dc827dccfee06d3e4c
parentfac60a6b6e1cc360d9aaa04e53c9f37cb927f3bf (diff)
downloadcolm-8bd44760137d615df994e1773d98d894139b7422.tar.gz
Only store the original tree in Alg::parsed if the tree was changed.
-rw-r--r--colm/pdarun.cpp14
1 files changed, 10 insertions, 4 deletions
diff --git a/colm/pdarun.cpp b/colm/pdarun.cpp
index 795a95f6..0fa9d028 100644
--- a/colm/pdarun.cpp
+++ b/colm/pdarun.cpp
@@ -122,8 +122,7 @@ bool been_committed( Kid *kid )
}
/* The top level of the stack is linked right-to-left. Trees underneath are
- * left to right natural order. */
-
+ * linked left-to-right. */
void commit_kid( PdaRun *parser, Tree **root, Kid *lel )
{
Alg *alg = 0;
@@ -459,8 +458,8 @@ again:
/* Take a copy of the lhs and store it in alg. May need it during
* reverse parsing. */
- redAlg->parsed = redLel->tree;
- tree_upref( redAlg->parsed );
+ Tree *parsed = redLel->tree;
+ tree_upref( parsed );
/* Execute it. */
execution.execute( root );
@@ -474,6 +473,13 @@ again:
* while in the environment. */
redLel->tree = execution.lhs;
+ /* If the lhs changed then store the original, otherwise downref
+ * since we took a copy above. */
+ if ( parsed != redLel->tree )
+ redAlg->parsed = parsed;
+ else
+ tree_downref( prg, root, parsed );
+
/* Perhaps the execution environment is telling us we need to
* reject the reduction. */
induceReject = execution.reject;