From 4976085b722319a29a84e0591ba52d6cfd94b3da Mon Sep 17 00:00:00 2001 From: Matthias Schiffer Date: Fri, 10 Apr 2015 21:02:29 +0200 Subject: generator_slr: fix follow set generation Looks like my source of information was incomplete... --- src/generator_slr.cpp | 36 ++++++++++++++++++------------------ 1 file changed, 18 insertions(+), 18 deletions(-) (limited to 'src') 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 &lhs = follow_sets[item.get_lhs()]; std::set &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; } -- cgit v1.2.3