From 46b9bc4cf46e71da5ce8002f11e154916ae698f4 Mon Sep 17 00:00:00 2001 From: augustin64 Date: Fri, 10 Nov 2023 19:13:25 +0100 Subject: [PATCH] Remove Epsilon Nodes --- src/parser.cpp | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/src/parser.cpp b/src/parser.cpp index 925bfdd..8bd3218 100644 --- a/src/parser.cpp +++ b/src/parser.cpp @@ -34,7 +34,6 @@ void _debug_print_tree(const Node& node, int depth, const string& prefix = "") { Node parse(vector tokens) { reverse(tokens.begin(), tokens.end()); - tokens.pop_back(); // Remove the last ';' if (tokens.size() == 0) throw ParseException(); @@ -50,11 +49,14 @@ Node parse(vector tokens) { ParseReturn ret = parse_instruction(tokens); tokens = ret.tokens; - InnerNode new_node = { - .type=NodeType::Prog, - .children={node, ret.node} - }; - node = new_node; + if (get(ret.node).type != NodeType::Epsilon) { + InnerNode new_node = { + .type=NodeType::Prog, + .children={node, ret.node} + }; + node = new_node; + } + } return node;