/* These are the functions to manipulate logic expressions. */ #include #include #include #include "glob.h" lox *NewLox(int kind) { lox *t; t = (lox *)malloc(sizeof(lox)); if (t==NULL) eprintf("Allocation error in new-lox.",0,0,0); t->type = kind; t->id = 0; t->vc = 0; t->a = t->b = NULL; dprintf(" new lox %p",t); return t; } int FreeLox(lox *t) { lox *u,*v; dprintf("free lox %p",t); if (t==NULL) return 1; u = t->a; v = t->b; t->a = t->b = NULL; /* prevents infinite recursion */ free(t); t = NULL; FreeLox(u); FreeLox(v); return 0; } lox *DeepCopyLox(lox *t) /* returns a deep copy of t */ { lox *u; if (t == NULL) return NULL; u = NewLox(t->type); memcpy(u,t,sizeof(*u)); u->a = DeepCopyLox(t->a); u->b = DeepCopyLox(t->b); return u; } /*--------------------------------------------------------------------------- This returns a shallow copy of t. All logical connectives and quantifiers are copied, but the predicates and below are not. */ lox *CopyLox(lox *t) { lox *u; if (t == NULL) return NULL; if (t->type <= TERM) return t; u = NewLox(t->type); memcpy(u,t,sizeof(*u)); u->a = CopyLox(t->a); u->b = CopyLox(t->b); return u; }