Fix item-set-closure bug w/ empty productions
This commit is contained in:
parent
216ce8c80b
commit
8725e96a65
7 changed files with 5600 additions and 5576 deletions
|
|
@ -112,13 +112,18 @@ class ParseTableBuilder {
|
|||
};
|
||||
|
||||
CompletionStatus get_completion_status(const ParseItem &item) {
|
||||
CompletionStatus result = { false, 0, rules::AssociativityNone };
|
||||
const Production &production =
|
||||
grammar.productions(item.lhs())[item.production_index];
|
||||
if (item.step_index == production.size()) {
|
||||
const ProductionStep &last_step = production[item.step_index - 1];
|
||||
return { true, last_step.precedence, last_step.associativity };
|
||||
result.is_done = true;
|
||||
if (item.step_index > 0) {
|
||||
const ProductionStep &last_step = production[item.step_index - 1];
|
||||
result.precedence = last_step.precedence;
|
||||
result.associativity = last_step.associativity;
|
||||
}
|
||||
}
|
||||
return { false, 0, rules::AssociativityNone };
|
||||
return result;
|
||||
}
|
||||
|
||||
void add_reduce_actions(const ParseItemSet &item_set, ParseStateId state_id) {
|
||||
|
|
|
|||
|
|
@ -72,11 +72,11 @@ ParseItemSet item_set_closure(const ParseItemSet &input_item_set,
|
|||
// Add each of the next symbol's productions to be processed recursively.
|
||||
size_t i = 0;
|
||||
for (const Production &production : grammar.productions(next_symbol)) {
|
||||
if (!production.empty())
|
||||
items_to_process.push_back({
|
||||
ParseItem(next_symbol, i, 0, production[0].rule_id),
|
||||
next_lookahead_symbols,
|
||||
});
|
||||
int rule_id = production.empty() ? 0 : production[0].rule_id;
|
||||
items_to_process.push_back({
|
||||
ParseItem(next_symbol, i, 0, rule_id),
|
||||
next_lookahead_symbols,
|
||||
});
|
||||
i++;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue