summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAdrian Thurston <thurston@complang.org>2015-05-08 12:56:11 -0400
committerAdrian Thurston <thurston@complang.org>2015-05-08 12:56:11 -0400
commit97689b1dca307140d17e70bd56c51a302f994c8c (patch)
tree38600bdf0624da1aefbe381c0c3e9dac6ac3981a
parentb671ce2b6db990339bd6bbbd0694e00945dd55b3 (diff)
downloadcolm-97689b1dca307140d17e70bd56c51a302f994c8c.tar.gz
check shift count when undoing a reduced thing
There are actually two places where we unshift and need to check for arrival at the most recent commit point. Fixes some apparent spins when getting to a parse error.
-rw-r--r--src/pdarun.c10
1 files changed, 10 insertions, 0 deletions
diff --git a/src/pdarun.c b/src/pdarun.c
index b207fefd..b5105379 100644
--- a/src/pdarun.c
+++ b/src/pdarun.c
@@ -1766,6 +1766,7 @@ case PcrReverse:
/* Either we are dealing with a terminal that was shifted or a
* nonterminal that was reduced. */
if ( pdaRun->parseInput->id < prg->rtd->firstNonTermId ) {
+ /* This is a terminal. */
assert( pdaRun->parseInput->retryUpper == 0 );
if ( pdaRun->parseInput->retryLower != 0 ) {
@@ -1777,6 +1778,15 @@ case PcrReverse:
}
if ( pdaRun->parseInput->causeReduce != 0 ) {
+ /* The terminal caused a reduce. Unshift the reduced thing
+ * (will unreduce in the next step. */
+ if ( pdaRun->shiftCount == pdaRun->commitShiftCount ) {
+ debug( prg, REALM_PARSE, "backed up to commit point, "
+ "failing parse\n" );
+ goto fail;
+ }
+ pdaRun->shiftCount -= 1;
+
pdaRun->undoLel = pdaRun->stackTop;
/* Check if we've arrived at the stack sentinal. This guard