From 0ee1994078c8a5e5cbb15454b4e2024a629d6166 Mon Sep 17 00:00:00 2001 From: Max Brunsfeld Date: Sun, 17 Jul 2016 07:25:57 -0700 Subject: [PATCH] Don't have both shift and shift-extra actions in recovery states --- src/compiler/build_tables/build_parse_table.cc | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/src/compiler/build_tables/build_parse_table.cc b/src/compiler/build_tables/build_parse_table.cc index d027e1e8..def80f55 100644 --- a/src/compiler/build_tables/build_parse_table.cc +++ b/src/compiler/build_tables/build_parse_table.cc @@ -115,13 +115,12 @@ class ParseTableBuilder { void build_error_parse_state() { ParseState error_state; - for (const Symbol &symbol : recovery_tokens(lexical_grammar)) { + for (const Symbol &symbol : recovery_tokens(lexical_grammar)) add_out_of_context_parse_state(&error_state, symbol); - } - for (const Symbol &symbol : grammar.extra_tokens) { - error_state.entries[symbol].actions.push_back(ParseAction::ShiftExtra()); - } + for (const Symbol &symbol : grammar.extra_tokens) + if (!error_state.entries.count(symbol)) + error_state.entries[symbol].actions.push_back(ParseAction::ShiftExtra()); for (size_t i = 0; i < grammar.variables.size(); i++) { Symbol symbol(i, false); @@ -197,8 +196,13 @@ class ParseTableBuilder { void add_shift_extra_actions(ParseStateId state_id) { ParseAction action = ParseAction::ShiftExtra(); + ParseState &state = parse_table.states[state_id]; for (const Symbol &extra_symbol : grammar.extra_tokens) - add_action(state_id, extra_symbol, action, null_item_set); + if (!state.entries.count(extra_symbol) || + (allow_any_conflict && + state.entries[extra_symbol].actions.back().type == + ParseActionTypeReduce)) + parse_table.add_action(state_id, extra_symbol, action); } void add_reduce_extra_actions(ParseStateId state_id) {