summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorMatthias Schiffer <mschiffer@universe-factory.net>2015-04-02 01:43:43 +0200
committerMatthias Schiffer <mschiffer@universe-factory.net>2015-04-02 01:43:43 +0200
commitab2d315aa2daf404bc6abab2f8f20f72803b8898 (patch)
treec8f0e3eb20b4ec3c80e5dc02e2bb82833066a901 /src
parent531a4de1fcea1df2b2b0d9303d82aa23c6285fb0 (diff)
downloadsolar-ab2d315aa2daf404bc6abab2f8f20f72803b8898.tar
solar-ab2d315aa2daf404bc6abab2f8f20f72803b8898.zip
generator: remove printing, add some getters
Diffstat (limited to 'src')
-rw-r--r--src/generator.cpp72
-rw-r--r--src/generator.hpp18
2 files changed, 11 insertions, 79 deletions
diff --git a/src/generator.cpp b/src/generator.cpp
index c6aec3a..a9a20aa 100644
--- a/src/generator.cpp
+++ b/src/generator.cpp
@@ -119,39 +119,6 @@ void generator_t::generate_itemsets() {
}
}
-void generator_t::print_symbol(const symbol_t &sym) {
- switch (sym.get_type()) {
- case SYMBOL_TYPE_CHAR:
- printf("'%c'", sym.get_value()[0]);
- break;
-
- default:
- printf("%s", sym.get_value().c_str());
- }
-}
-
-void generator_t::print_item(const item_t &item, bool point) {
- printf("%s |=", item.get_lhs().c_str());
-
- for (size_t i = 0; i <= item.get_rhs().size(); i++) {
- if (i == item.get_point() && point)
- printf(" .");
-
- if (i == item.get_rhs().size())
- break;
-
- printf(" ");
- print_symbol(item.get_rhs()[i]);
- }
-
- printf("\n");
-}
-
-void generator_t::print_set(const std::set<item_t> &set) {
- for (const item_t &item : set)
- print_item(item, true);
-}
-
generator_t::generator_t(const std::vector<item_t> &rules0) : rules(rules0) {
for (size_t i = 0; i < rules.size(); i++) {
item_t rule = rules[i];
@@ -172,45 +139,6 @@ generator_t::generator_t(const std::vector<item_t> &rules0) : rules(rules0) {
}
generate_itemsets();
-
- printf("Rules:\n");
- for (size_t i = 0; i < rules.size(); i++) {
- printf("(%u) ", unsigned(i));
- print_item(rules[i], false);
- }
- printf("\n");
-
- const std::set<item_t> *setlist[itemsets.size()];
- for (const auto &entry : itemsets)
- setlist[entry.second] = &entry.first;
-
- for (size_t i = 0; i < itemsets.size(); i++) {
- printf("Item %u:\n", unsigned(i));
- print_set(*setlist[i]);
- printf("\n");
- }
-
- printf("Actions:\n");
- for (const auto &a : shifts) {
- printf("%u ", unsigned(a.first.first));
-
- if (!a.first.second.get_value().empty()) {
- print_symbol(a.first.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");
- for (const auto &g : gotos)
- printf("%u %s -> %u\n", unsigned(g.first.first), g.first.second.get_value().c_str(), unsigned(g.second));
}
}
diff --git a/src/generator.hpp b/src/generator.hpp
index 715dd98..5396d3e 100644
--- a/src/generator.hpp
+++ b/src/generator.hpp
@@ -45,9 +45,9 @@ private:
std::multimap<symbol_t, item_t> items;
std::map<std::set<item_t>, size_t> itemsets;
- 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<size_t, symbol_t>, size_t> shifts;
+ std::map<size_t, size_t> reductions;
+ std::map<std::pair<size_t, symbol_t>, size_t> gotos;
void close_set(std::set<item_t> *set);
std::set<item_t> get_set(const std::string &nonterm);
@@ -58,11 +58,15 @@ private:
void generate_itemsets();
- static void print_symbol(const symbol_t &sym);
- static void print_item(const item_t &item, bool point);
- static void print_set(const std::set<item_t> &set);
-
public:
+ const std::set<symbol_t> & get_terminals() const {
+ return terminals;
+ }
+
+ size_t get_state_count() const {
+ return itemsets.size();
+ }
+
generator_t(const std::vector<item_t> &rules0);
};