Add 'extra' field to symbol metadata

This stores whether a symbol is only ever used as a ubiquitous token. This will
allow ubiquitous nodes to be reused more effectively: if they are always
ubiquitous, then they can be reused immediately, and otherwise, they must be
broken down in case they need to be used structurally.
This commit is contained in:
Max Brunsfeld 2015-12-02 07:36:31 -08:00
parent f08554e958
commit ad619d95f6
13 changed files with 439 additions and 414 deletions

View file

@ -104,6 +104,13 @@ set<Symbol> ParseState::expected_inputs() const {
return result;
}
set<Symbol> ParseTable::all_symbols() const {
set<Symbol> result;
for (auto &pair : symbols)
result.insert(pair.first);
return result;
}
ParseStateId ParseTable::add_state() {
states.push_back(ParseState());
return states.size() - 1;
@ -111,14 +118,16 @@ ParseStateId ParseTable::add_state() {
ParseAction &ParseTable::set_action(ParseStateId id, Symbol symbol,
ParseAction action) {
symbols.insert(symbol);
bool structural = action.type != ParseActionTypeShiftExtra;
symbols[symbol].structural += structural;
states[id].actions[symbol] = vector<ParseAction>({ action });
return *states[id].actions[symbol].begin();
}
ParseAction &ParseTable::add_action(ParseStateId id, Symbol symbol,
ParseAction action) {
symbols.insert(symbol);
bool structural = action.type != ParseActionTypeShiftExtra;
symbols[symbol].structural += structural;
states[id].actions[symbol].push_back(action);
return *states[id].actions[symbol].rbegin();
}