From 7cd143c0c42779778eec755d4386ea752fb5f1f4 Mon Sep 17 00:00:00 2001 From: "Sven M. Hallberg" <pesco@khjk.org> Date: Fri, 21 Jun 2013 15:06:31 +0200 Subject: [PATCH] piggy-back the next shift directly onto the reduce --- src/backends/lr.c | 21 +++++++++++++-------- 1 file changed, 13 insertions(+), 8 deletions(-) diff --git a/src/backends/lr.c b/src/backends/lr.c index 2f7d5e48..03264b5c 100644 --- a/src/backends/lr.c +++ b/src/backends/lr.c @@ -268,12 +268,7 @@ bool h_lrengine_step(HLREngine *engine, const HLRAction *action) assert(action->type == HLR_SHIFT || action->type == HLR_REDUCE); - if(action->type == HLR_SHIFT) { - h_slist_push(left, (void *)(uintptr_t)engine->state); - h_slist_drop(right); // symbol (discard) - h_slist_push(left, h_slist_drop(right)); // semantic value - engine->state = action->nextstate; - } else { + if(action->type == HLR_REDUCE) { assert(action->type == HLR_REDUCE); size_t len = action->production.length; HCFChoice *symbol = action->production.lhs; @@ -318,8 +313,18 @@ bool h_lrengine_step(HLREngine *engine, const HLRAction *action) // this is LR, building a right-most derivation bottom-up, so no reduce can // follow a reduce. we can also assume no conflict follows for GLR if we // use LALR tables, because only terminal symbols (lookahead) get reduces. - const HLRAction *next = h_lr_lookup(engine->table, engine->state, symbol); - assert(next == NULL || next->type == HLR_SHIFT); + action = h_lr_lookup(engine->table, engine->state, symbol); + if(action == NULL) + return false; // no handle after reduce; terminate + assert(action->type == HLR_SHIFT); + } + + // this could be the original action, or a shift piggy-backed onto reduce + if(action->type == HLR_SHIFT) { + h_slist_push(left, (void *)(uintptr_t)engine->state); + h_slist_drop(right); // symbol (discard) + h_slist_push(left, h_slist_drop(right)); // semantic value + engine->state = action->nextstate; } return true; -- GitLab