From b777ffc52d8608183dd0098664b238faa7780234 Mon Sep 17 00:00:00 2001 From: Robin Jadoul Date: Thu, 19 Jan 2017 13:06:23 +0100 Subject: [PATCH] Skipping tokens while recovering errors in the generated parser --- templates/c++/lr.h | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/templates/c++/lr.h b/templates/c++/lr.h index b96158b..e9e01cd 100644 --- a/templates/c++/lr.h +++ b/templates/c++/lr.h @@ -150,6 +150,13 @@ Value {{name}}::parse() { stateStack.push(TABLE[stateStack.top()][verr] >> 2); valueStack.emplace(std::move(errorVal)); + + while (tok != {{name}}_Symbol::T_EOF && (TABLE[stateStack.top()][static_cast(tok.symbol)] & 0x3) == ERROR) { + tok = lex(); + } + if ((TABLE[stateStack.top()][static_cast(tok.symbol)] & 0x3) == ERROR) { + throw SyntaxError("Syntax error: could not recover"); + } } break; case SHIFT: