From ed724a70c92560f13213d745409f45d8c60cf5e0 Mon Sep 17 00:00:00 2001 From: Roland Reichwein Date: Sat, 15 Feb 2020 15:06:25 +0100 Subject: Debug code --- grammer.cpp | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) (limited to 'grammer.cpp') diff --git a/grammer.cpp b/grammer.cpp index 2fc136c..bbaaa79 100644 --- a/grammer.cpp +++ b/grammer.cpp @@ -95,12 +95,16 @@ void Compiler::DumpTree() index_t token_id {TokenIdFromChildId(current_index)}; std::cout << "Token(" << token_id << "): " << tokens[token_id].type << "(" << tokens[token_id].value << ")"; } else { - std::cout << "Node(" << current_index << "): " << nodes[current_index].type; + auto& node {nodes[current_index]}; + std::cout << "Node(" << current_index << "): " << node.type << "/" << node.variant; - auto child_ids{nodes[current_index].child_ids}; + auto child_ids{node.child_ids}; for (int i = 0; i < child_ids.size(); i++) { todo.insert(todo.begin() + i, std::pair{child_ids[i], indent + 1}); } + if (node.alternatives.size()) { + std::cout << ", " << node.alternatives.size() << " alternatives available"; + } } std::cout << std::endl; @@ -397,6 +401,9 @@ index_t Compiler::AddNode(const std::string& child_type, index_t parent_index) nodes.emplace_back(TreeNode{parent_index, index, child_type, variant, alternatives, std::vector{}}); //root stays, tokens_used stays + std::cout << "AddNode(): " << index << std::endl; + DumpTree(); + return index; } @@ -408,6 +415,9 @@ void Compiler::AddPath(const std::vector& path, index_t current_ind nodes.back().child_ids.emplace_back(ChildIdFromTokenId(tokens_used)); tokens_used++; + + std::cout << "AddPath(): token " << tokens.back().type << std::endl; + DumpTree(); } bool Compiler::FillTree() @@ -423,6 +433,8 @@ bool Compiler::FillTree() if (next_child == tokens[tokens_used].type) { // add token directly node.child_ids.push_back(ChildIdFromTokenId(tokens_used)); tokens_used++; + std::cout << "tokens_used++: " << tokens_used << std::endl; + DumpTree(); } else { // add inner nodes auto list = GetPath(next_child, tokens[tokens_used].type); if (list.size() > 0) { -- cgit v1.2.3