From 1babdc43e19f56cbb6e37265a0ebdae6b89caabc Mon Sep 17 00:00:00 2001 From: Max Brunsfeld Date: Sat, 24 Oct 2015 12:49:26 -0700 Subject: [PATCH] Add reduce-extra actions for all symbols --- .../build_tables/build_parse_table.cc | 21 +++++++------------ 1 file changed, 8 insertions(+), 13 deletions(-) diff --git a/src/compiler/build_tables/build_parse_table.cc b/src/compiler/build_tables/build_parse_table.cc index 8d4c91dc..40d786ca 100644 --- a/src/compiler/build_tables/build_parse_table.cc +++ b/src/compiler/build_tables/build_parse_table.cc @@ -159,26 +159,21 @@ class ParseTableBuilder { } void add_reduce_extra_actions(ParseStateId state_id) { + const ParseState &state = parse_table.states[state_id]; const ParseItemSet item_set; - const map> &actions = - parse_table.states[state_id].actions; for (const Symbol &ubiquitous_symbol : grammar.ubiquitous_tokens) { - const auto &entry = actions.find(ubiquitous_symbol); - if (entry == actions.end()) + const auto &actions_for_symbol = state.actions.find(ubiquitous_symbol); + if (actions_for_symbol == state.actions.end()) continue; - for (const auto &action : entry->second) { + for (const ParseAction &action : actions_for_symbol->second) if (action.type == ParseActionTypeShift) { - size_t shift_state_id = action.state_index; - for (const auto &pair : actions) { - const Symbol &lookahead_sym = pair.first; - ParseAction reduce_extra = - ParseAction::ReduceExtra(ubiquitous_symbol); - add_action(shift_state_id, lookahead_sym, reduce_extra, item_set); - } + size_t dest_state_id = action.state_index; + ParseAction reduce_extra = ParseAction::ReduceExtra(ubiquitous_symbol); + for (const auto &symbol : parse_table.symbols) + add_action(dest_state_id, symbol, reduce_extra, item_set); } - } } }