Delete node now is replaced by deconstructor
This commit is contained in:
parent
f0fc180319
commit
9a727aa83b
4 changed files with 8 additions and 12 deletions
|
@ -38,5 +38,6 @@ void interpret_file(char* fileName) {
|
||||||
struct Environment* env = new Environment();
|
struct Environment* env = new Environment();
|
||||||
eval_statement(result, env);
|
eval_statement(result, env);
|
||||||
delete_environment(env);
|
delete_environment(env);
|
||||||
delete_tree(result);
|
|
||||||
|
delete result;
|
||||||
}
|
}
|
|
@ -73,15 +73,6 @@ void print_tree(struct Node* node, int tabs) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void delete_tree(struct Node* node) {
|
|
||||||
if (!node) { return; }
|
|
||||||
for(int i = 0; i < node->num_children; i++) {
|
|
||||||
delete_tree(node->children[i]);
|
|
||||||
}
|
|
||||||
free(node);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
struct Value* eval_expression(struct Node* node, struct Environment* env) {
|
struct Value* eval_expression(struct Node* node, struct Environment* env) {
|
||||||
/* base case */
|
/* base case */
|
||||||
|
|
|
@ -28,13 +28,17 @@ struct Node {
|
||||||
children[i] = nullptr;
|
children[i] = nullptr;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
~Node() {
|
||||||
|
for (int i = 0; i < num_children; i++) {
|
||||||
|
delete children[i];
|
||||||
|
}
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
// Abstract Syntax Tree Functions
|
// Abstract Syntax Tree Functions
|
||||||
// struct Node* make_node(int type, struct Value* value, std::string id);
|
// struct Node* make_node(int type, struct Value* value, std::string id);
|
||||||
void attach_node(struct Node* parent, struct Node* child);
|
void attach_node(struct Node* parent, struct Node* child);
|
||||||
void print_tree(struct Node* node, int tabs);
|
void print_tree(struct Node* node, int tabs);
|
||||||
void delete_tree(struct Node* node);
|
|
||||||
|
|
||||||
// Interpreting AST
|
// Interpreting AST
|
||||||
void eval_statement(struct Node* node, struct Environment* env);
|
void eval_statement(struct Node* node, struct Environment* env);
|
||||||
|
|
|
@ -70,5 +70,5 @@ void start_shell() {
|
||||||
}
|
}
|
||||||
|
|
||||||
delete_environment(env);
|
delete_environment(env);
|
||||||
delete_tree(result);
|
delete result;
|
||||||
}
|
}
|
Reference in a new issue