From c9da57dec2a121f1c7d9e4924646523a08f76c9b Mon Sep 17 00:00:00 2001 From: Robin Jadoul Date: Sun, 22 Jan 2017 12:59:35 +0100 Subject: [PATCH] Cleaner collection of expected terminals --- templates/c++/lr.h | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/templates/c++/lr.h b/templates/c++/lr.h index a63d480..2fc88f7 100644 --- a/templates/c++/lr.h +++ b/templates/c++/lr.h @@ -154,11 +154,11 @@ Value {{name}}::parse() { { constexpr std::uint64_t verr = static_cast({{name}}_Symbol::V_error); std::vector<{{name}}_Symbol> expected; - {{#symbols}} - if ({{name}}_Symbol::{{symbol}} <= {{name}}_Symbol::{{last_terminal}} && (TABLE[stateStack.top()][static_cast({{name}}_Symbol::{{symbol}})] & 0x3) != ERROR) { - expected.emplace_back({{name}}_Symbol::{{symbol}}); + std::uint64_t top = stateStack.top(); + for (std::uint64_t i = 0; i <= static_cast({{name}}_Symbol::{{last_terminal}}); i++) { + if ((TABLE[top][i] & 0x3) != ERROR) + expected.emplace_back(static_cast<{{name}}_Symbol>(i)); } - {{/symbols}} Value errorVal = error(tok, expected); while (!valueStack.empty() && (TABLE[stateStack.top()][verr] & 0x3) == ERROR) {