summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMatthias Schiffer <mschiffer@universe-factory.net>2015-04-01 02:42:54 +0200
committerMatthias Schiffer <mschiffer@universe-factory.net>2015-04-01 02:42:54 +0200
commit531a4de1fcea1df2b2b0d9303d82aa23c6285fb0 (patch)
tree7df1d662e59fdd4e5a7ccb1f6d4515597e9df47d
parent3f1b701ad15458829468ce176ee6cecd16c4b420 (diff)
downloadsolar-531a4de1fcea1df2b2b0d9303d82aa23c6285fb0.tar
solar-531a4de1fcea1df2b2b0d9303d82aa23c6285fb0.zip
generator: split different actions into different maps
-rw-r--r--src/generator.cpp26
-rw-r--r--src/generator.hpp3
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);