summaryrefslogtreecommitdiffhomepage
path: root/grammer.h
diff options
context:
space:
mode:
authorRoland Reichwein <mail@reichwein.it>2020-01-23 21:53:57 +0100
committerRoland Reichwein <mail@reichwein.it>2020-01-23 21:53:57 +0100
commite172ed9f799501c234c8da18cef829244473f1d7 (patch)
tree2c36c8adef69bd7c1b61efc1fe91188ab61ca6d8 /grammer.h
parentf7cdbb6635d62a0347be579cb8dd6badec22956d (diff)
Added grammer
Diffstat (limited to 'grammer.h')
-rw-r--r--grammer.h37
1 files changed, 34 insertions, 3 deletions
diff --git a/grammer.h b/grammer.h
index 01ea681..87aa1ad 100644
--- a/grammer.h
+++ b/grammer.h
@@ -5,18 +5,49 @@
namespace Gram {
+struct TreeNode {
+ index_t parent{};
+ std::vector<index_t> childs; // fill Token by Token
+ std::vector<std::string> child_types; // fill always
+ Token token;
+};
+
+class Tree {
+private:
+ std::map<index_t, TreeNode> nodes; // index 0 = non existing; index starting at 1
+ index_t node_num{};
+ index_t root{};
+ index_t last{};
+
+public:
+ void clear();
+ bool Valid(const std::string& Top) const;
+ bool AddFirstNode(const Token& token, const BNF& bnf, const std::map<std::string, std::set<std::string>>& reverseBNF);
+ std::vector<TreeNode> getParentTreeNode(const BNF& bnf, const std::map<std::string, std::set<std::string>>& reverseBNF);
+ index_t GetLast();
+ void AddRootNode(const TreeNode& newRootNode);
+ void RemoveRootNode();
+ std::vector<std::string> GetPath(std::string a, std::string b, const BNF& bnf, const std::map<std::string, std::set<std::string>>& reverseBNF);
+ index_t AddNode(const std::string& name, const std::string& child_name, index_t parent_index, const BNF& bnf, const std::map<std::string, std::set<std::string>>& reverseBNF);
+ void AddPath(const std::vector<std::string>& path, index_t current_index, const BNF& bnf, const std::map<std::string, std::set<std::string>>& reverseBNF);
+ bool Add(const Token& token, const BNF& bnf, const std::map<std::string, std::set<std::string>>& reverseBNF);
+ void Resolve(const BNF& bnf, const std::map<std::string, std::set<std::string>>& reverseBNF);
+
+ void Dump();
+};
+
class Compiler
{
private:
- const BNF &m_bnf;
- const std::string& m_Top;
+ const BNF &bnf;
+ const std::string& Top;
std::map<std::string, std::set<std::string>> ReverseBNF;
public:
Compiler(const BNF& bnf, const std::string& Top);
- ProgramNode compile(std::vector<Token> Tokens);
+ Tree compile(std::vector<Token> Tokens);
};
} // namespace Gram