From 561821d011ccac2d0433737c14f152e60664e3d5 Mon Sep 17 00:00:00 2001 From: Max Brunsfeld Date: Thu, 13 Jul 2017 13:41:56 -0700 Subject: [PATCH] Remove precedence and associativity methods from ParseAction --- .../build_tables/build_parse_table.cc | 6 ++--- src/compiler/parse_table.cc | 24 ------------------- src/compiler/parse_table.h | 5 +--- 3 files changed, 4 insertions(+), 31 deletions(-) diff --git a/src/compiler/build_tables/build_parse_table.cc b/src/compiler/build_tables/build_parse_table.cc index f61e1271..a14563d2 100644 --- a/src/compiler/build_tables/build_parse_table.cc +++ b/src/compiler/build_tables/build_parse_table.cc @@ -208,7 +208,7 @@ class ParseTableBuilder { if (existing_action.type == ParseActionTypeAccept || processing_recovery_states) { entry.actions.push_back(action); } else { - int existing_precedence = existing_action.precedence(); + int existing_precedence = existing_action.production->back().precedence; if (precedence > existing_precedence) { for (const ParseAction &old_action : entry.actions) fragile_productions.insert(old_action.production); @@ -472,7 +472,7 @@ class ParseTableBuilder { string handle_conflict(const ParseItemSet &item_set, const SymbolSequence &preceding_symbols, ParseStateId state_id, Symbol lookahead) { ParseTableEntry &entry = parse_table.states[state_id].terminal_entries[lookahead]; - int reduction_precedence = entry.actions.front().precedence(); + int reduction_precedence = entry.actions.front().production->back().precedence; set shift_items; bool considered_associativity = false; @@ -524,7 +524,7 @@ class ParseTableBuilder { bool has_right_associative_reductions = false; for (const ParseAction &action : entry.actions) { if (action.type != ParseActionTypeReduce) break; - switch (action.associativity()) { + switch (action.production->back().associativity) { case rules::AssociativityLeft: has_left_associative_reductions = true; break; diff --git a/src/compiler/parse_table.cc b/src/compiler/parse_table.cc index 82c4429c..28e0fbe9 100644 --- a/src/compiler/parse_table.cc +++ b/src/compiler/parse_table.cc @@ -64,30 +64,6 @@ ParseAction ParseAction::Reduce(Symbol symbol, size_t consumed_symbol_count, return result; } -int ParseAction::precedence() const { - if (consumed_symbol_count >= production->size()) { - if (production->empty()) { - return 0; - } else { - return production->back().precedence; - } - } else { - return production->at(consumed_symbol_count).precedence; - } -} - -rules::Associativity ParseAction::associativity() const { - if (consumed_symbol_count >= production->size()) { - if (production->empty()) { - return rules::AssociativityNone; - } else { - return production->back().associativity; - } - } else { - return production->at(consumed_symbol_count).associativity; - } -} - bool ParseAction::operator==(const ParseAction &other) const { return (type == other.type && extra == other.extra && fragile == other.fragile && symbol == other.symbol && diff --git a/src/compiler/parse_table.h b/src/compiler/parse_table.h index 8a127bed..e1630b32 100644 --- a/src/compiler/parse_table.h +++ b/src/compiler/parse_table.h @@ -28,13 +28,10 @@ struct ParseAction { static ParseAction Error(); static ParseAction Shift(ParseStateId state_index); static ParseAction Recover(ParseStateId state_index); - static ParseAction Reduce(rules::Symbol symbol, size_t consumed_symbol_count, - const Production &); + static ParseAction Reduce(rules::Symbol symbol, size_t child_count, const Production &); static ParseAction ShiftExtra(); bool operator==(const ParseAction &) const; bool operator<(const ParseAction &) const; - rules::Associativity associativity() const; - int precedence() const; const Production *production; size_t consumed_symbol_count;