From 531a4de1fcea1df2b2b0d9303d82aa23c6285fb0 Mon Sep 17 00:00:00 2001 From: Matthias Schiffer Date: Wed, 1 Apr 2015 02:42:54 +0200 Subject: generator: split different actions into different maps --- src/generator.cpp | 26 +++++++++++++++----------- 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 &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 items; std::map, size_t> itemsets; - std::multimap, std::pair> actions; + std::map, unsigned> shifts; + std::map reductions; std::map, unsigned> gotos; void close_set(std::set *set); -- cgit v1.2.3