From 0950c449066770292beae220ba4289ce124b4680 Mon Sep 17 00:00:00 2001 From: Roland Reichwein Date: Sat, 15 Feb 2020 15:42:20 +0100 Subject: Bugfixing --- grammer.cpp | 22 ++++++++++------------ 1 file changed, 10 insertions(+), 12 deletions(-) (limited to 'grammer.cpp') diff --git a/grammer.cpp b/grammer.cpp index bbaaa79..55e31c8 100644 --- a/grammer.cpp +++ b/grammer.cpp @@ -77,7 +77,7 @@ void Compiler::DumpTree() std::cout << "--- Nodes ------------------------------------" << std::endl; std::cout << "root_node_id=" << root_node_id << std::endl; for (const auto& node : nodes) { - std::cout << node.type << "(" << node.node_id << "): "; + std::cout << node.type << "(" << node.node_id << "):"; for (const auto& child : node.child_ids) { std::cout << " " << child; } @@ -382,26 +382,24 @@ index_t Compiler::AddNode(const std::string& child_type, index_t parent_index) index_t index = nodes.size(); parent.child_ids.push_back(index); - index_t variant; + index_t variant{}; std::deque> alternatives; - const auto& lists { bnf[parent.type] }; + const auto& variants { bnf[child_type] }; bool found{false}; - for (int i = 0; i < lists.size(); i++) { // variants - if (lists[i].size() > 0 && lists[i][0] == child_type) { - if (!found) { // use first match - variant = i; - found = true; - } else { // defer all others - alternatives.emplace_back(child_type, i); - } + for (int i = 0; i < variants.size(); i++) { // variants + if (!found) { // use first match + variant = i; + found = true; + } else { // defer all others + alternatives.emplace_back(child_type, i); } } nodes.emplace_back(TreeNode{parent_index, index, child_type, variant, alternatives, std::vector{}}); //root stays, tokens_used stays - std::cout << "AddNode(): " << index << std::endl; + std::cout << "AddNode(): " << parent.type << "->" << child_type << ": "<< index << std::endl; DumpTree(); return index; -- cgit v1.2.3