summaryrefslogtreecommitdiffhomepage
path: root/grammer.cpp
diff options
context:
space:
mode:
authorRoland Reichwein <mail@reichwein.it>2020-02-15 15:42:20 +0100
committerRoland Reichwein <mail@reichwein.it>2020-02-15 15:42:20 +0100
commit0950c449066770292beae220ba4289ce124b4680 (patch)
tree49dc92b5890b3323dd092d1f68c4fdf9ae4e0ecb /grammer.cpp
parented724a70c92560f13213d745409f45d8c60cf5e0 (diff)
Bugfixing
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;