summaryrefslogtreecommitdiffhomepage
path: root/grammer.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'grammer.cpp')
-rw-r--r--grammer.cpp22
1 files changed, 10 insertions, 12 deletions
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<std::pair<std::string, index_t>> 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<int32_t>{}});
//root stays, tokens_used stays
- std::cout << "AddNode(): " << index << std::endl;
+ std::cout << "AddNode(): " << parent.type << "->" << child_type << ": "<< index << std::endl;
DumpTree();
return index;