Add function to free an entire parse tree.

This commit is contained in:
Guido van Rossum 1990-11-18 17:37:06 +00:00
parent eb38d2411c
commit 03a24cd47b
1 changed files with 23 additions and 0 deletions

View File

@ -45,3 +45,26 @@ addchild(n1, type, str)
n->n_child = NULL;
return n;
}
static void
freechildren(n)
node *n;
{
int i;
for (i = NCH(n); --i >= 0; )
freechildren(CHILD(n, i));
if (n->n_child != NULL)
DEL(n->n_child);
if (STR(n) != NULL)
DEL(STR(n));
}
void
freenode(n)
node *n;
{
if (n != NULL) {
freechildren(n);
DEL(n);
}
}