diff options
Diffstat (limited to 'src/generator.hpp')
-rw-r--r-- | src/generator.hpp | 65 |
1 files changed, 6 insertions, 59 deletions
diff --git a/src/generator.hpp b/src/generator.hpp index b0bd4c9..576fccb 100644 --- a/src/generator.hpp +++ b/src/generator.hpp @@ -26,7 +26,7 @@ #pragma once -#include "item.hpp" +#include "grammar.hpp" #include <stdexcept> #include <set> @@ -44,7 +44,8 @@ public: }; private: - std::vector<std::tuple<item_t, std::vector<std::string>, std::string>> rules; + grammar_t grammar; + std::map<item_t, size_t> rule_ids; std::multimap<std::string, size_t> nonterms; @@ -60,14 +61,6 @@ private: std::set<size_t> shift_conflicts; - std::map<std::string, std::string> nonterm_types; - std::map<symbol_t, std::pair<std::string, std::string>> term_types; - - std::string header_block; - std::string source_block; - - std::vector<std::pair<std::string, std::string>> extra_args; - void close_set(std::set<item_t> *set); std::set<item_t> get_set(const std::string &nonterm); @@ -100,34 +93,8 @@ private: void generate_itemsets(); public: - const std::string & get_nonterm_type(const std::string &sym) const { - static const std::string empty; - - auto it = nonterm_types.find(sym); - if (it == nonterm_types.end()) - return empty; - else - return it->second; - } - - const std::pair<std::string, std::string> & get_term_type(const symbol_t &sym) const { - static const std::pair<std::string, std::string> empty; - - auto it = term_types.find(sym); - if (it == term_types.end()) - return empty; - else - return it->second; - } - - const std::string & get_type(const symbol_t &sym) const { - switch (sym.get_type()) { - case SYMBOL_TYPE_NONTERM: - return get_nonterm_type(sym.get_value()); - - default: - return get_term_type(sym).first; - } + const grammar_t & get_grammar() const { + return grammar; } const std::set<std::string> & get_nonterminals() const { @@ -142,10 +109,6 @@ public: return itemsets.size(); } - const std::vector<std::tuple<item_t, std::vector<std::string>, std::string>> & get_rules() const { - return rules; - } - const std::map<size_t, size_t> & get_reductions() const { return reductions; } @@ -158,24 +121,8 @@ public: return gotos; } - const std::string & get_header_block() const { - return header_block; - } - - const std::string & get_source_block() const { - return source_block; - } - - const std::vector<std::pair<std::string, std::string>> & get_extra_args() const { - return extra_args; - } - - generator_t(const std::vector<std::tuple<item_t, std::vector<std::string>, std::string>> &rules0, - const std::map<std::string, std::string> &nonterm_types0, - const std::map<symbol_t, std::pair<std::string, std::string>> &term_types0, - const std::string &header_block0, const std::string &source_block0, - const std::vector<std::pair<std::string, std::string>> &extra_args0); + generator_t(const grammar_t &grammar0); }; } |