summaryrefslogtreecommitdiffhomepage
path: root/bnf.h
diff options
context:
space:
mode:
Diffstat (limited to 'bnf.h')
-rw-r--r--bnf.h23
1 files changed, 19 insertions, 4 deletions
diff --git a/bnf.h b/bnf.h
index 148b6d1..0430a2c 100644
--- a/bnf.h
+++ b/bnf.h
@@ -1,17 +1,32 @@
#pragma once
+#include "minicc.h"
+
#include <deque>
-#include <unordered_map>
-#include <set>
#include <string>
+#include <unordered_map>
+#include <unordered_set>
#include <utility>
#include <vector>
using BNF = std::unordered_map<std::string, std::vector<std::vector<std::string>>>;
-std::unordered_map<std::string, std::set<std::string>> Reverse(BNF bnf); // unused now, remove?
-std::unordered_map<std::string, std::set<std::string>> reverseFirst(BNF bnf);
+std::unordered_map<std::string, std::unordered_set<std::string>> Reverse(const BNF& bnf); // unused now, remove?
+std::unordered_map<std::string, std::unordered_set<std::string>> reverseFirst(const BNF& bnf);
BNF SubBNF(const BNF& bnf, const std::string& top);
bool isTerminal(const BNF& bnf, const std::string& symbol);
+std::unordered_set<std::string> getTerminals(const BNF& bnf);
+
+struct PairHash {
+ size_t operator()(const std::pair<std::string,size_t>& p) const noexcept
+ {
+ size_t h0 {std::hash<std::string>{}(p.first)};
+ size_t h1 {std::hash<size_t >{}(p.second)};
+ return h0 ^ (h1 << 1);
+ }
+};
+std::unordered_set<std::pair<std::string, size_t>, PairHash> getEmptyPositions(const BNF& bnf);
+
+std::unordered_map<std::string, std::unordered_set<std::pair<std::string, index_t>, PairHash>> reversePosFirst(const BNF& bnf); // like reverseFirstPos, but including variant