summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/item.hpp7
-rw-r--r--src/state.cpp5
-rw-r--r--src/symbol.hpp5
3 files changed, 3 insertions, 14 deletions
diff --git a/src/item.hpp b/src/item.hpp
index 58987b8..faebf79 100644
--- a/src/item.hpp
+++ b/src/item.hpp
@@ -61,7 +61,7 @@ struct item_t : public std::tuple<std::string, std::vector<symbol_t>, unsigned>
return std::get<2>(*this);
}
- bool can_shift() const {
+ bool has_next() const {
return get_point() < get_rhs().size();
}
@@ -70,10 +70,7 @@ struct item_t : public std::tuple<std::string, std::vector<symbol_t>, unsigned>
}
symbol_t get_next_symbol() const {
- if (can_shift())
- return get_rhs()[get_point()];
- else
- return symbol_t::make_end();
+ return get_rhs()[get_point()];
}
};
diff --git a/src/state.cpp b/src/state.cpp
index e798dce..958ab3e 100644
--- a/src/state.cpp
+++ b/src/state.cpp
@@ -55,11 +55,8 @@ void state_t::add_rule_terminal(unsigned char term) {
void state_t::add_rule() {
rules.emplace(current.get_lhs(), current);
- while (true) {
+ while (current.has_next()) {
items.emplace(current.get_next_symbol(), current);
- if (!current.can_shift())
- break;
-
current.shift();
}
}
diff --git a/src/symbol.hpp b/src/symbol.hpp
index 31b006d..68222e2 100644
--- a/src/symbol.hpp
+++ b/src/symbol.hpp
@@ -33,7 +33,6 @@
namespace solar {
enum symbol_type_t {
- SYMBOL_TYPE_END,
SYMBOL_TYPE_NONTERM,
SYMBOL_TYPE_TERM,
SYMBOL_TYPE_CHAR,
@@ -50,10 +49,6 @@ struct symbol_t : public std::tuple<symbol_type_t, std::string> {
return std::get<1>(*this);
}
- static symbol_t make_end() {
- return symbol_t(SYMBOL_TYPE_END, "");
- }
-
static symbol_t make_nonterm(const char *value) {
return symbol_t(SYMBOL_TYPE_NONTERM, value);
}