From eeaa0db45c3d0ab8a958893e7ce0e3f4e4a0692c Mon Sep 17 00:00:00 2001 From: "Sven M. Hallberg" <pesco@khjk.org> Date: Tue, 11 Feb 2020 21:46:10 +0100 Subject: [PATCH] handle conflict entries in follow_transition() fixes issue 91 --- src/backends/lalr.c | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/src/backends/lalr.c b/src/backends/lalr.c index 74d37bd2..ba10e0ca 100644 --- a/src/backends/lalr.c +++ b/src/backends/lalr.c @@ -31,7 +31,23 @@ static size_t follow_transition(const HLRTable *table, size_t x, HCFChoice *A) { HLRAction *action = lrtable_lookup(table, x, A); assert(action != NULL); + + // we are interested in a transition out of state x, i.e. a shift action. + // while there could also be reduce actions associated with A in state x, + // those are not what we are here for. so if action is a conflict, search it + // for the shift. there will only be one and it will be the bottom element. + if(action->type == HLR_CONFLICT) { + HSlistNode *x; + for(x=action->branches->head; x; x=x->next) { + action = x->elem; + assert(action->type != HLR_CONFLICT); // no nesting of conflicts + if(action->type == HLR_SHIFT) + break; + } + assert(x != NULL && x->next == NULL); // shift found at the bottom + } assert(action->type == HLR_SHIFT); + return action->nextstate; } -- GitLab