summaryrefslogtreecommitdiff
path: root/comp/lucas-standen-NEA/code/proto/ast/astg.c
diff options
context:
space:
mode:
Diffstat (limited to 'comp/lucas-standen-NEA/code/proto/ast/astg.c')
-rw-r--r--comp/lucas-standen-NEA/code/proto/ast/astg.c25
1 files changed, 16 insertions, 9 deletions
diff --git a/comp/lucas-standen-NEA/code/proto/ast/astg.c b/comp/lucas-standen-NEA/code/proto/ast/astg.c
index fc6fc8f..e96b771 100644
--- a/comp/lucas-standen-NEA/code/proto/ast/astg.c
+++ b/comp/lucas-standen-NEA/code/proto/ast/astg.c
@@ -19,11 +19,25 @@ typedef struct ast_node {
ast_node *left;
} ast_node;
+void freeAst(ast_node *head){
+ if (head->left != NULL)
+ freeAst(head->left);
+ if (head->right != NULL)
+ freeAst(head->left);
+ free(head);
+}
+
int exec(ast_node *exp){
- if (exp->left != NULL)
+ if (exp->left != NULL){
exp->realLeft = exec(exp->left);
- if (exp->right != NULL)
+ freeAst(exp->left);
+ exp->left = NULL;
+ }
+ if (exp->right != NULL){
exp->realRight = exec(exp->right);
+ freeAst(exp->right);
+ exp->right = NULL;
+ }
if (exp->operation == ADD)
return exp->realLeft+ exp->realRight;
@@ -36,10 +50,3 @@ int exec(ast_node *exp){
return 0;
}
-void freeAst(ast_node *head){
- if (head->left != NULL)
- freeAst(head->left);
- if (head->right != NULL)
- freeAst(head->left);
- free(head);
-}