From 46c49fb5517446f357093c6a4f739747402f5347 Mon Sep 17 00:00:00 2001 From: picomeg <megordon5@gmail.com> Date: Wed, 22 Jul 2020 17:22:02 +0100 Subject: [PATCH] Quick fix for ticket 60 bug: make sure when comparing states for merge that we also check to confirm both engines have consume the same number of tokens (and thus have actually both arrived at the same state for the same partial input stream) --- src/backends/glr.c | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/src/backends/glr.c b/src/backends/glr.c index ea69ea37..a1be5a6c 100644 --- a/src/backends/glr.c +++ b/src/backends/glr.c @@ -175,8 +175,17 @@ static bool glr_step(HParseResult **result, HSlist *engines, for(x=engines->head; x; x=x->next) { HLREngine *eng = x->elem; if(eng->state == engine->state) { - x->elem = lrengine_merge(eng, engine); - break; + // check they've both actually consumed the same number of tokens from the input as well + // the way this is implemented, the engines do not always consume tokens in lockstep + // I think this is the cause of the bug. + // TODO: confirm I understand GLR correctly + // TODO: ?--shall we try to actually change it to move in lockstep--? + // This is a quick fix, it may not be entirely the correct way to go about it. + + if(eng->input.index == engine->input.index) { + x->elem = lrengine_merge(eng, engine); + break; + } } } if(!x) // no merge happened -- GitLab