summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAdrian Thurston <thurston@complang.org>2009-02-22 03:18:29 +0000
committerAdrian Thurston <thurston@complang.org>2009-02-22 03:18:29 +0000
commit76ab0efa0b78d21fa8f2f2398a2d232386640bd0 (patch)
treef93b38c4d0e139b7b4e40f2ee7cc1abebe559821
parent3765c038c21e22ad8901a657c9fa0537fd796e70 (diff)
downloadcolm-76ab0efa0b78d21fa8f2f2398a2d232386640bd0.tar.gz
implemented nonassoc
-rw-r--r--colm/parsedata.h1
-rw-r--r--colm/pdabuild.cpp26
2 files changed, 24 insertions, 3 deletions
diff --git a/colm/parsedata.h b/colm/parsedata.h
index a2331651..1e69935b 100644
--- a/colm/parsedata.h
+++ b/colm/parsedata.h
@@ -520,6 +520,7 @@ struct ParseData
void resolvePrecedence( PdaGraph *pdaGraph );
KlangEl *predOf( PdaTrans *trans, long action );
bool precedenceSwap( long action1, long action2, KlangEl *l1, KlangEl *l2 );
+ bool precedenceRemoveBoth( KlangEl *l1, KlangEl *l2 );
void initKeyOps();
diff --git a/colm/pdabuild.cpp b/colm/pdabuild.cpp
index 576d6bf6..37fe8304 100644
--- a/colm/pdabuild.cpp
+++ b/colm/pdabuild.cpp
@@ -934,12 +934,20 @@ bool ParseData::precedenceSwap( long action1, long action2, KlangEl *l1, KlangEl
return swap;
}
+bool ParseData::precedenceRemoveBoth( KlangEl *l1, KlangEl *l2 )
+{
+ if ( l1->predValue == l2->predValue && l1->predType == PredNonassoc )
+ return true;
+ return false;
+}
+
void ParseData::resolvePrecedence( PdaGraph *pdaGraph )
{
for ( PdaStateList::Iter state = pdaGraph->stateList; state.lte(); state++ ) {
assert( CmpDotSet::compare( state->dotSet, state->dotSet2 ) == 0 );
- for ( TransMap::Iter tel = state->transMap; tel.lte(); tel++ ) {
- PdaTrans *trans = tel->value;
+
+ for ( long t = 0; t < state->transMap.length(); /* increment at end */ ) {
+ PdaTrans *trans = state->transMap[t].value;
again:
/* Find action with precedence. */
@@ -960,12 +968,24 @@ again:
long t = trans->actions[i];
trans->actions[i] = trans->actions[j];
trans->actions[j] = t;
- goto again;
}
+
+ trans->actions.remove( j );
+ if ( precedenceRemoveBoth( li, lj ) )
+ trans->actions.remove( i );
+
+ goto again;
}
}
}
}
+
+ /* If there are still actions then move to the next one. If not,
+ * (due to nonassoc) then remove the transition. */
+ if ( trans->actions.length() > 0 )
+ t += 1;
+ else
+ state->transMap.vremove( t );
}
}
}