diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/generator.cpp | 26 | ||||
-rw-r--r-- | src/generator.hpp | 3 |
2 files changed, 17 insertions, 12 deletions
diff --git a/src/generator.cpp b/src/generator.cpp index ec5d1f8..c6aec3a 100644 --- a/src/generator.cpp +++ b/src/generator.cpp @@ -96,10 +96,12 @@ void generator_t::generate_itemsets() { auto added = add_set(entry.second); + auto action = std::make_pair(std::make_pair(cur.second, entry.first), added.first->second); + if (entry.first.get_type() == SYMBOL_TYPE_NONTERM) - gotos.emplace(std::make_pair(cur.second, entry.first), added.first->second); + gotos.insert(std::move(action)); else - actions.emplace(std::make_pair(cur.second, entry.first), std::make_pair('s', added.first->second)); + shifts.insert(std::move(action)); if (added.second) queue.push(*added.first); @@ -108,12 +110,10 @@ void generator_t::generate_itemsets() { for (const item_t &item : cur.first) { auto it = rule_ids.find(item); if (it != rule_ids.end()) { - //if (it->second) { - // for (const symbol_t &term : terminals) - // transitions.emplace(std::make_pair(cur.second, term), std::make_pair('r', it->second)); - //} - - actions.emplace(std::make_pair(cur.second, symbol_t::make_term("")), std::make_pair('r', it->second)); + if (it->second) + reductions.emplace(cur.second, it->second); + else + shifts.emplace(std::make_pair(cur.second, symbol_t::make_nonterm("")), 0); } } } @@ -191,17 +191,21 @@ generator_t::generator_t(const std::vector<item_t> &rules0) : rules(rules0) { } printf("Actions:\n"); - for (const auto &a : actions) { + for (const auto &a : shifts) { printf("%u ", unsigned(a.first.first)); - if (a.second.second) { + if (!a.first.second.get_value().empty()) { print_symbol(a.first.second); - printf(" -> %c%u\n", a.second.first, unsigned(a.second.second)); + printf(" -> s%u\n", unsigned(a.second)); } else { printf("$ -> acc\n"); } } + + for (const auto &a : reductions) + printf("%u -> r%u\n", unsigned(a.first), unsigned(a.second)); + printf("\n"); printf("Gotos:\n"); diff --git a/src/generator.hpp b/src/generator.hpp index 955739f..715dd98 100644 --- a/src/generator.hpp +++ b/src/generator.hpp @@ -45,7 +45,8 @@ private: std::multimap<symbol_t, item_t> items; std::map<std::set<item_t>, size_t> itemsets; - std::multimap<std::pair<unsigned, symbol_t>, std::pair<char, unsigned>> actions; + std::map<std::pair<unsigned, symbol_t>, unsigned> shifts; + std::map<unsigned, unsigned> reductions; std::map<std::pair<unsigned, symbol_t>, unsigned> gotos; void close_set(std::set<item_t> *set); |