summaryrefslogtreecommitdiffstats
path: root/src/generator.hpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/generator.hpp')
-rw-r--r--src/generator.hpp30
1 files changed, 9 insertions, 21 deletions
diff --git a/src/generator.hpp b/src/generator.hpp
index 1ad70ab..024b630 100644
--- a/src/generator.hpp
+++ b/src/generator.hpp
@@ -56,11 +56,8 @@ private:
std::map<std::set<item_t>, size_t> itemsets;
std::map<std::pair<size_t, symbol_t>, size_t> shifts;
- std::map<size_t, size_t> reductions;
std::map<std::pair<size_t, std::string>, size_t> gotos;
- std::set<size_t> shift_conflicts;
-
void close_set(std::set<item_t> *set);
std::set<item_t> get_set(const std::string &nonterm);
@@ -69,20 +66,10 @@ private:
return itemsets.insert(std::make_pair(set, itemsets.size()));
}
- void add_reduction(size_t from, size_t to) {
- if (reductions.count(from))
- throw conflict_error("reduce/reduce conflict");
- if (shift_conflicts.count(from))
- throw conflict_error("shift/reduce conflict");
-
- reductions.insert(std::make_pair(from, to));
- }
-
void add_shift(size_t from, const symbol_t &sym, size_t to) {
- if (reductions.count(from))
+ if (has_reduce_conflict(from, sym))
throw conflict_error("shift/reduce conflict");
- shift_conflicts.insert(from);
shifts.insert(std::make_pair(std::make_pair(from, sym), to));
}
@@ -90,7 +77,11 @@ private:
gotos.insert(std::make_pair(std::make_pair(from, nonterm), to));
}
- void generate_itemsets();
+protected:
+ virtual bool has_reduce_conflict(size_t from, const symbol_t &sym) = 0;
+ virtual void add_reduction(size_t from, size_t to) = 0;
+
+ generator_t(const grammar_t &grammar0);
public:
const grammar_t & get_grammar() const {
@@ -109,10 +100,6 @@ public:
return itemsets.size();
}
- const std::map<size_t, size_t> & get_reductions() const {
- return reductions;
- }
-
const std::map<std::pair<size_t, symbol_t>, size_t> & get_shifts() const {
return shifts;
}
@@ -121,8 +108,9 @@ public:
return gotos;
}
-protected:
- generator_t(const grammar_t &grammar0);
+ virtual ~generator_t() {}
+
+ void generate();
};
}