diff options
author | Matthias Schiffer <mschiffer@universe-factory.net> | 2015-04-10 21:02:29 +0200 |
---|---|---|
committer | Matthias Schiffer <mschiffer@universe-factory.net> | 2015-04-10 21:02:29 +0200 |
commit | 4976085b722319a29a84e0591ba52d6cfd94b3da (patch) | |
tree | 0e04fe03f249c45e7cac1a144e021770ee519807 | |
parent | aeaeba2d7362a055c5c78f410a743ea977d8cd36 (diff) | |
download | solar-4976085b722319a29a84e0591ba52d6cfd94b3da.tar solar-4976085b722319a29a84e0591ba52d6cfd94b3da.zip |
generator_slr: fix follow set generation
Looks like my source of information was incomplete...
-rw-r--r-- | src/generator_slr.cpp | 36 |
1 files changed, 18 insertions, 18 deletions
diff --git a/src/generator_slr.cpp b/src/generator_slr.cpp index a8e081a..2989ee1 100644 --- a/src/generator_slr.cpp +++ b/src/generator_slr.cpp @@ -92,31 +92,31 @@ 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(); + if (next.has_next()) { + const symbol_t &next_sym = next.get_next_symbol(); - 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; - else - changed = changed || rhs.insert(sym2).second; + if (next_sym.get_type() == SYMBOL_TYPE_NONTERM) { + for (const symbol_t &sym2 : first_sets[next_sym.get_value()]) { + if (sym2 == symbol_t::empty()) + has_empty = true; + else + changed = changed || rhs.insert(sym2).second; + } } + else { + changed = changed || rhs.insert(next_sym).second; + } + + continue; } - else { - changed = changed || rhs.insert(next_sym).second; - } - } - else { - next_empty = true; - } - if (next_empty) { for (const symbol_t &sym2 : lhs) changed = changed || rhs.insert(sym2).second; } |