summaryrefslogtreecommitdiffhomepage
path: root/bnf.h
diff options
context:
space:
mode:
authorRoland Reichwein <mail@reichwein.it>2020-03-30 18:33:01 +0200
committerRoland Reichwein <mail@reichwein.it>2020-03-30 18:33:01 +0200
commit79fbc8bf495770e4a8b7c66c46acf07f4e47e568 (patch)
tree174c0f3c194013c39a73f6a50ed8866784388c07 /bnf.h
parent2eb2383387d16fc919c07e1a6b9211406576b893 (diff)
Speed up compile
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