summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAdrian Thurston <thurston@complang.org>2015-10-21 13:03:30 -0400
committerAdrian Thurston <thurston@complang.org>2015-10-21 13:03:30 -0400
commit0b175a8ed019785233618b3bb8e3c064e567f2ec (patch)
tree96af4d993e2c2505ec31aa543d796f1cf9538d99
parent924fbf2224b7e39e68230c568ef4ce3ac57eb569 (diff)
downloadcolm-0b175a8ed019785233618b3bb8e3c064e567f2ec.tar.gz
allow multiple reducers
selection is currently manual using a numberical identifier
-rw-r--r--src/parsetree.h11
-rw-r--r--src/reduce.cc14
2 files changed, 20 insertions, 5 deletions
diff --git a/src/parsetree.h b/src/parsetree.h
index fc53be89..2e5bcb49 100644
--- a/src/parsetree.h
+++ b/src/parsetree.h
@@ -978,7 +978,11 @@ typedef Vector<ReduceAction*> ReduceActionVect;
struct Reduction
{
Reduction( const InputLoc &loc, String name )
- : loc(loc), name(name) {}
+ : loc(loc), name(name)
+ {
+ static int nextId = 0;
+ id = nextId++;
+ }
InputLoc loc;
String name;
@@ -1843,7 +1847,8 @@ typedef DList<Constructor> ConsList;
struct ParserText
{
static ParserText *cons( const InputLoc &loc,
- Namespace *nspace, ConsItemList *list, bool used, bool reduce )
+ Namespace *nspace, ConsItemList *list,
+ bool used, bool reduce )
{
ParserText *p = new ParserText;
p->loc = loc;
@@ -1867,6 +1872,8 @@ struct ParserText
bool parse;
bool used;
bool reduce;
+ String reducerClass;
+
ParserText *prev, *next;
};
diff --git a/src/reduce.cc b/src/reduce.cc
index 271560e1..989329ee 100644
--- a/src/reduce.cc
+++ b/src/reduce.cc
@@ -298,14 +298,19 @@ void Compiler::writeCommit()
"\n"
" if ( !( lel->flags & PF_COMMITTED ) ) {\n"
" /* Now can execute the reduction action. */\n"
- " switch ( kid->tree->id ) {\n";
+ " switch ( reducer->current ) {\n";
for ( ReductionVect::Iter r = rootNamespace->reductions; r.lte(); r++ ) {
+ Reduction *reduction = *r;
+
+ *outStream <<
+ " case " << reduction->id << ": { switch ( kid->tree->id ) {\n";
+
/* Populate a vector with the reduce actions. */
Vector<ReduceAction*> actions;
- actions.setAsNew( (*r)->reduceActions.length() );
+ actions.setAsNew( reduction->reduceActions.length() );
long pos = 0;
- for ( ReduceActionList::Iter rdi = (*r)->reduceActions; rdi.lte(); rdi++ )
+ for ( ReduceActionList::Iter rdi = reduction->reduceActions; rdi.lte(); rdi++ )
actions[pos++] = rdi;
/* Sort it by lhs id, then prod num. */
@@ -354,6 +359,9 @@ void Compiler::writeCommit()
" break;\n"
" }\n";
}
+
+ *outStream <<
+ " } break; }\n";
}
*outStream <<