Remove Epsilon Nodes

This commit is contained in:
augustin64 2023-11-10 19:13:25 +01:00
parent fea4292700
commit 46b9bc4cf4

View File

@ -34,7 +34,6 @@ void _debug_print_tree(const Node& node, int depth, const string& prefix = "") {
Node parse(vector<Token> tokens) { Node parse(vector<Token> tokens) {
reverse(tokens.begin(), tokens.end()); reverse(tokens.begin(), tokens.end());
tokens.pop_back(); // Remove the last ';'
if (tokens.size() == 0) if (tokens.size() == 0)
throw ParseException(); throw ParseException();
@ -50,11 +49,14 @@ Node parse(vector<Token> tokens) {
ParseReturn ret = parse_instruction(tokens); ParseReturn ret = parse_instruction(tokens);
tokens = ret.tokens; tokens = ret.tokens;
InnerNode new_node = { if (get<InnerNode>(ret.node).type != NodeType::Epsilon) {
.type=NodeType::Prog, InnerNode new_node = {
.children={node, ret.node} .type=NodeType::Prog,
}; .children={node, ret.node}
node = new_node; };
node = new_node;
}
} }
return node; return node;