summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorRoland Reichwein <mail@reichwein.it>2020-02-15 15:06:25 +0100
committerRoland Reichwein <mail@reichwein.it>2020-02-15 15:06:25 +0100
commited724a70c92560f13213d745409f45d8c60cf5e0 (patch)
tree05d52432cdee4d0de83029078748a41e0efa8691
parent991b493afc385de84e916e7e23e9313825d6e6d9 (diff)
Debug code
-rw-r--r--grammer.cpp16
1 files changed, 14 insertions, 2 deletions
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<int32_t, size_t>{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<int32_t>{}});
//root stays, tokens_used stays
+ std::cout << "AddNode(): " << index << std::endl;
+ DumpTree();
+
return index;
}
@@ -408,6 +415,9 @@ void Compiler::AddPath(const std::vector<std::string>& 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) {