From 8517313a45a629e27e198f9188647cbefc5985b3 Mon Sep 17 00:00:00 2001 From: Max Brunsfeld Date: Thu, 22 Jun 2017 15:33:07 -0700 Subject: [PATCH] :art: --- .../build_tables/build_parse_table.cc | 31 ++++++++----------- .../build_tables/lex_table_builder.cc | 12 +++---- 2 files changed, 17 insertions(+), 26 deletions(-) diff --git a/src/compiler/build_tables/build_parse_table.cc b/src/compiler/build_tables/build_parse_table.cc index ca9405a0..c5519555 100644 --- a/src/compiler/build_tables/build_parse_table.cc +++ b/src/compiler/build_tables/build_parse_table.cc @@ -413,26 +413,22 @@ class ParseTableBuilder { ParseState &state = parse_table.states[i]; ParseState &other = parse_table.states[j]; - if (state.nonterminal_entries != other.nonterminal_entries) - return false; + if (state.nonterminal_entries != other.nonterminal_entries) return false; for (auto &entry : state.terminal_entries) { Symbol lookahead = entry.first; - const vector &actions = entry.second.actions; - auto &incompatible_tokens = incompatible_tokens_by_index[lookahead.index]; - const auto &other_entry = other.terminal_entries.find(lookahead); + if (other_entry == other.terminal_entries.end()) { + if (entry.second.actions.back().type != ParseActionTypeReduce) return false; + if (!has_entry(other, entry.second)) return false; + if (lookahead.is_external()) return false; if (!lookahead.is_built_in()) { - for (const Symbol &incompatible_token : incompatible_tokens) { + for (const Symbol &incompatible_token : incompatible_tokens_by_index[lookahead.index]) { if (other.terminal_entries.count(incompatible_token)) return false; } } - if (actions.back().type != ParseActionTypeReduce) - return false; - if (!has_entry(other, entry.second)) - return false; } else if (entry.second != other_entry->second) { return false; } @@ -442,26 +438,25 @@ class ParseTableBuilder { for (auto &entry : other.terminal_entries) { Symbol lookahead = entry.first; - const vector &actions = entry.second.actions; - auto &incompatible_tokens = incompatible_tokens_by_index[lookahead.index]; if (!state.terminal_entries.count(lookahead)) { + if (entry.second.actions.back().type != ParseActionTypeReduce) return false; + if (!has_entry(state, entry.second)) return false; + if (lookahead.is_external()) return false; if (!lookahead.is_built_in()) { - for (const Symbol &incompatible_token : incompatible_tokens) { + for (const Symbol &incompatible_token : incompatible_tokens_by_index[lookahead.index]) { if (state.terminal_entries.count(incompatible_token)) return false; } } - if (actions.back().type != ParseActionTypeReduce) - return false; - if (!has_entry(state, entry.second)) - return false; + symbols_to_merge.insert(lookahead); } } - for (const Symbol &lookahead : symbols_to_merge) + for (const Symbol &lookahead : symbols_to_merge) { state.terminal_entries[lookahead] = other.terminal_entries.find(lookahead)->second; + } return true; } diff --git a/src/compiler/build_tables/lex_table_builder.cc b/src/compiler/build_tables/lex_table_builder.cc index 71553abb..4101f854 100644 --- a/src/compiler/build_tables/lex_table_builder.cc +++ b/src/compiler/build_tables/lex_table_builder.cc @@ -194,15 +194,11 @@ class LexTableBuilderImpl : public LexTableBuilder { AcceptTokenAction action(item.lhs, completion_status.precedence.max, item.lhs.is_built_in() || grammar.variables[item.lhs.index].is_string); - - auto current_action = lex_table.states[state_id].accept_action; - if (current_action.is_present()) { - if (!conflict_manager.resolve(action, current_action)) { - continue; - } + AcceptTokenAction &existing_action = lex_table.states[state_id].accept_action; + if (!existing_action.is_present() || + conflict_manager.resolve(action, existing_action)) { + lex_table.states[state_id].accept_action = action; } - - lex_table.states[state_id].accept_action = action; } } }