diff options
author | Adrian Thurston <thurston@complang.org> | 2015-10-05 12:54:50 -0400 |
---|---|---|
committer | Adrian Thurston <thurston@complang.org> | 2015-10-05 12:54:50 -0400 |
commit | 2c8090f0b665281827c7867f957a224f1d1b6cae (patch) | |
tree | 29510e0a5b18e5ccb397ce7f35bf93243c9366e3 /src | |
parent | 904ac5cc1675b19249750e3f5492cba720dda4c5 (diff) | |
download | colm-2c8090f0b665281827c7867f957a224f1d1b6cae.tar.gz |
traverse both parse tree and real tree during reduce
Diffstat (limited to 'src')
-rw-r--r-- | src/commit.c | 1 | ||||
-rw-r--r-- | src/compiler.cc | 15 | ||||
-rw-r--r-- | src/pdarun.c | 10 |
3 files changed, 18 insertions, 8 deletions
diff --git a/src/commit.c b/src/commit.c index ed92190e..2d1d84d5 100644 --- a/src/commit.c +++ b/src/commit.c @@ -82,7 +82,6 @@ static int been_committed( parse_tree_t *parse_tree ) return parse_tree->flags & PF_COMMITTED; } - void commit_clear( program_t *prg, tree_t **root, struct pda_run *pda_run ) { tree_t **sp = root; diff --git a/src/compiler.cc b/src/compiler.cc index cd95caf7..008788c5 100644 --- a/src/compiler.cc +++ b/src/compiler.cc @@ -1148,26 +1148,31 @@ void Compiler::writeCommit() " tree_t **sp = root;\n" "\n" " parse_tree_t *lel = pt;\n" + " kid_t *kid = pt->shadow;\n" "\n" "recurse:\n" "\n" " if ( lel->child != 0 ) {\n" " /* There are children. Must process all children first. */\n" " vm_push_ptree( lel );\n" + " vm_push_kid( kid );\n" "\n" " lel = lel->child;\n" + " kid = kid->tree->child;\n" " while ( lel != 0 ) {\n" " goto recurse;\n" " resume:\n" " lel = lel->next;\n" + " kid = kid->next;\n" " }\n" "\n" + " kid = vm_pop_kid();\n" " lel = vm_pop_ptree();\n" " }\n" "\n" - " /* Now can execute the reduction action. */\n" - " if ( lel->shadow != 0 ) {\n" - " switch ( lel->shadow->tree->id ) {\n"; + " if ( !( lel->flags & PF_COMMITTED ) ) {\n" + " /* Now can execute the reduction action. */\n" + " switch ( kid->tree->id ) {\n"; for ( ReductionVect::Iter r = rootNamespace->reductions; r.lte(); r++ ) { for ( ReduceActionList::Iter rdi = (*r)->reduceActions; rdi.lte(); rdi++ ) { @@ -1176,7 +1181,7 @@ void Compiler::writeCommit() *outStream << " case " << lelId << ": \n" - " if ( lel->shadow->tree->prod_num == " << prodNum << " ) {\n" + " if ( kid->tree->prod_num == " << prodNum << " ) {\n" " " << rdi->txt << "\n" " }\n" " break;\n"; @@ -1189,10 +1194,10 @@ void Compiler::writeCommit() "\n" " commit_clear_parse_tree( prg, sp, pda_run, lel->child );\n" " lel->child = 0;\n" - " pt->flags |= PF_COMMITTED;\n" "\n" " if ( sp != root )\n" " goto resume;\n" + " pt->flags |= PF_COMMITTED;\n" "}\n" "\n"; } diff --git a/src/pdarun.c b/src/pdarun.c index 68cbe280..d06659f3 100644 --- a/src/pdarun.c +++ b/src/pdarun.c @@ -1382,8 +1382,9 @@ again: pda_run->commit_shift_count = pda_run->shift_count; /* Not in a reverting context and the parser result is not used. */ - if ( ! pda_run->revert_on && pda_run->not_used ) + if ( pda_run->not_used ) { commit_reduce( prg, sp, pda_run ); + } } /* @@ -2132,7 +2133,12 @@ long colm_parse_finish( tree_t **result, program_t *prg, tree_t **sp, /* FIXME: need something here to check that we are not stopped waiting for * more data when we are actually expected to finish. This check doesn't * work (at time of writing). */ - //assert( (pdaRun->stopTarget > 0 && pdaRun->stopParsing) || streamToImpl( input )->eofSent ); + //assert( (pdaRun->stopTarget > 0 && pdaRun->stopParsing) || + // streamToImpl( input )->eofSent ); + + /* Flush out anything not committed. */ + if ( pda_run->not_used ) + commit_reduce( prg, sp, pda_run ); if ( !revert_on ) colm_rcode_downref_all( prg, sp, &pda_run->reverse_code ); |