generator_slr: fix follow set generation

Looks like my source of information was incomplete...
This commit is contained in:
Matthias Schiffer 2015-04-10 21:02:29 +02:00
parent aeaeba2d73
commit 4976085b72

View file

@ -92,10 +92,12 @@ void generator_slr_t::generate_follow_sets() {
const std::set<symbol_t> &lhs = follow_sets[item.get_lhs()];
std::set<symbol_t> &rhs = follow_sets[sym.get_value()];
bool has_empty = true;
item_t next = item;
next.shift();
bool next_empty = false;
while (has_empty) {
has_empty = false;
next.shift();
if (next.has_next()) {
const symbol_t &next_sym = next.get_next_symbol();
@ -103,7 +105,7 @@ void generator_slr_t::generate_follow_sets() {
if (next_sym.get_type() == SYMBOL_TYPE_NONTERM) {
for (const symbol_t &sym2 : first_sets[next_sym.get_value()]) {
if (sym2 == symbol_t::empty())
next_empty = true;
has_empty = true;
else
changed = changed || rhs.insert(sym2).second;
}
@ -111,12 +113,10 @@ void generator_slr_t::generate_follow_sets() {
else {
changed = changed || rhs.insert(next_sym).second;
}
}
else {
next_empty = true;
continue;
}
if (next_empty) {
for (const symbol_t &sym2 : lhs)
changed = changed || rhs.insert(sym2).second;
}