Browse Source

Added UP_freeTree & free'd the AST after use in main.c

remotes/origin/HEAD
Seth Stubbs 6 months ago
parent
commit
f29e4a9831
  1. 2
      src/main.c
  2. 9
      src/uparse.c
  3. 2
      src/uparse.h

2
src/main.c

@ -5,5 +5,7 @@ int main() {
UASTNode *tree = UP_parseSource("6 + 2 * 21 + 3 * 6");
UA_genTal(tree, fopen("out.tal", "w"));
/* clean up */
UP_freeTree(tree);
return 0;
}

9
src/uparse.c

@ -210,4 +210,13 @@ UASTNode *UP_parseSource(const char *src) {
printTree(tree, 16);
return tree;
}
void UP_freeTree(UASTNode *tree) {
if (tree->left)
UP_freeTree(tree->left);
if (tree->right)
UP_freeTree(tree->right);
UM_free(tree);
}

2
src/uparse.h

@ -29,4 +29,6 @@ typedef struct {
/* returns the base AST node, or NULL if a syntax error occurred */
UASTNode *UP_parseSource(const char *src);
void UP_freeTree(UASTNode *tree);
#endif
Loading…
Cancel
Save