Remove Epsilon Nodes
This commit is contained in:
parent
fea4292700
commit
46b9bc4cf4
@ -34,7 +34,6 @@ void _debug_print_tree(const Node& node, int depth, const string& prefix = "") {
|
||||
|
||||
Node parse(vector<Token> tokens) {
|
||||
reverse(tokens.begin(), tokens.end());
|
||||
tokens.pop_back(); // Remove the last ';'
|
||||
|
||||
if (tokens.size() == 0)
|
||||
throw ParseException();
|
||||
@ -50,6 +49,7 @@ Node parse(vector<Token> tokens) {
|
||||
ParseReturn ret = parse_instruction(tokens);
|
||||
tokens = ret.tokens;
|
||||
|
||||
if (get<InnerNode>(ret.node).type != NodeType::Epsilon) {
|
||||
InnerNode new_node = {
|
||||
.type=NodeType::Prog,
|
||||
.children={node, ret.node}
|
||||
@ -57,6 +57,8 @@ Node parse(vector<Token> tokens) {
|
||||
node = new_node;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
return node;
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user