diff --git a/src/backends/lalr.c b/src/backends/lalr.c index 74d37bd2b3d524e1b440d77cdd92591bfae4970b..ba10e0ca8587c866b72e96d03c1351a9a037d8a2 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; }