generator: split different actions into different maps
This commit is contained in:
parent
3f1b701ad1
commit
531a4de1fc
2 changed files with 17 additions and 12 deletions
|
@ -96,10 +96,12 @@ void generator_t::generate_itemsets() {
|
||||||
|
|
||||||
auto added = add_set(entry.second);
|
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)
|
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
|
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)
|
if (added.second)
|
||||||
queue.push(*added.first);
|
queue.push(*added.first);
|
||||||
|
@ -108,12 +110,10 @@ void generator_t::generate_itemsets() {
|
||||||
for (const item_t &item : cur.first) {
|
for (const item_t &item : cur.first) {
|
||||||
auto it = rule_ids.find(item);
|
auto it = rule_ids.find(item);
|
||||||
if (it != rule_ids.end()) {
|
if (it != rule_ids.end()) {
|
||||||
//if (it->second) {
|
if (it->second)
|
||||||
// for (const symbol_t &term : terminals)
|
reductions.emplace(cur.second, it->second);
|
||||||
// transitions.emplace(std::make_pair(cur.second, term), std::make_pair('r', it->second));
|
else
|
||||||
//}
|
shifts.emplace(std::make_pair(cur.second, symbol_t::make_nonterm("")), 0);
|
||||||
|
|
||||||
actions.emplace(std::make_pair(cur.second, symbol_t::make_term("")), std::make_pair('r', it->second));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -191,17 +191,21 @@ generator_t::generator_t(const std::vector<item_t> &rules0) : rules(rules0) {
|
||||||
}
|
}
|
||||||
|
|
||||||
printf("Actions:\n");
|
printf("Actions:\n");
|
||||||
for (const auto &a : actions) {
|
for (const auto &a : shifts) {
|
||||||
printf("%u ", unsigned(a.first.first));
|
printf("%u ", unsigned(a.first.first));
|
||||||
|
|
||||||
if (a.second.second) {
|
if (!a.first.second.get_value().empty()) {
|
||||||
print_symbol(a.first.second);
|
print_symbol(a.first.second);
|
||||||
printf(" -> %c%u\n", a.second.first, unsigned(a.second.second));
|
printf(" -> s%u\n", unsigned(a.second));
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
printf("$ -> acc\n");
|
printf("$ -> acc\n");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
for (const auto &a : reductions)
|
||||||
|
printf("%u -> r%u\n", unsigned(a.first), unsigned(a.second));
|
||||||
|
|
||||||
printf("\n");
|
printf("\n");
|
||||||
|
|
||||||
printf("Gotos:\n");
|
printf("Gotos:\n");
|
||||||
|
|
|
@ -45,7 +45,8 @@ private:
|
||||||
std::multimap<symbol_t, item_t> items;
|
std::multimap<symbol_t, item_t> items;
|
||||||
std::map<std::set<item_t>, size_t> itemsets;
|
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;
|
std::map<std::pair<unsigned, symbol_t>, unsigned> gotos;
|
||||||
|
|
||||||
void close_set(std::set<item_t> *set);
|
void close_set(std::set<item_t> *set);
|
||||||
|
|
Reference in a new issue