summaryrefslogtreecommitdiffhomepage
path: root/grammer.h
diff options
context:
space:
mode:
authorRoland Reichwein <mail@reichwein.it>2020-03-31 18:46:49 +0200
committerRoland Reichwein <mail@reichwein.it>2020-03-31 18:46:49 +0200
commitcd6c436cb70c4323c7d14ebd74f89bb0914649f2 (patch)
tree1bdb2a8409b2b370bcaa5e1b6cf091c0c8e1f779 /grammer.h
parentbed46a062c442656b1bc16d965e12405297029d3 (diff)
Optimization: Replace head recursion by tail recursion in matching
Diffstat (limited to 'grammer.h')
-rw-r--r--grammer.h10
1 files changed, 5 insertions, 5 deletions
diff --git a/grammer.h b/grammer.h
index 9b72d3a..a8a3356 100644
--- a/grammer.h
+++ b/grammer.h
@@ -39,11 +39,9 @@ private:
// Input
std::vector<Token> tokens;
- BNF &bnf; // not const for access via operator[]
+ BNF m_bnf; // not const for access via operator[]
const std::string m_top;
- //std::unordered_map<std::string, std::unordered_set<std::string>> ReverseBNF; // possible parent types of a given type; unused now: remove?
- //std::unordered_map<std::string, std::unordered_set<std::string>> reversedFirst; // possible parent types of first childs of a given type
std::unordered_map<std::string, std::unordered_set<std::pair<std::string, index_t>, PairHash>> reversedPosFirst; // possible parent types of first childs of a given type
std::deque<index_t> symbol_variants;
@@ -81,12 +79,14 @@ private:
return h0 ^ (h1 << 1) ^ (h2 << 2);
}
};
+ // map combination of non-terminal+terminal symbol combination to list of
+ // possible BNF positions for the specified non-terminal symbol
std::unordered_map<std::pair<std::string, std::string>, std::vector<size_t>, PairHashSS> m_match_lut;
+ std::unordered_map<std::string, size_t> m_empty_lut; // list of non-terminal symbols that can lead to empty token list (maps to variant)
+
void fillStartCache();
void constructTree();
- std::vector<std::string> m_symbol_list;
- index_t m_symbol_list_pos{};
public:
Compiler(BNF& bnf, const std::string& top);