Remove precedence and associativity methods from ParseAction

This commit is contained in:
Max Brunsfeld 2017-07-13 13:41:56 -07:00
parent d646889922
commit 561821d011
3 changed files with 4 additions and 31 deletions

View file

@ -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<ParseItem> 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;

View file

@ -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 &&

View file

@ -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;