diff options
author | Roland Reichwein <mail@reichwein.it> | 2020-03-31 18:46:49 +0200 |
---|---|---|
committer | Roland Reichwein <mail@reichwein.it> | 2020-03-31 18:46:49 +0200 |
commit | cd6c436cb70c4323c7d14ebd74f89bb0914649f2 (patch) | |
tree | 1bdb2a8409b2b370bcaa5e1b6cf091c0c8e1f779 /grammer.h | |
parent | bed46a062c442656b1bc16d965e12405297029d3 (diff) |
Optimization: Replace head recursion by tail recursion in matching
Diffstat (limited to 'grammer.h')
-rw-r--r-- | grammer.h | 10 |
1 files changed, 5 insertions, 5 deletions
@@ -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); |