Program trees are built from nodes; trees are referenced by their root node. The Node class itself is a virtual base class; its definition follows:
// base class for the 4 types of nodes
class Node {
protected:
Node *parent; // the parent node
int n_children; // number of child nodes
int n_valid; // validity flag for above
public:
Node(void); // constructor
~Node(void); // destructor will reset the parent's
// pointer to this node
int type; // indicates the type of node
void invalidate_count(void); // called when the number of children
// of this node has changed
virtual Val value(void) = 0; // this is the function that takes care
// of everything needed to assign a
// value to this node
virtual int count(void) = 0; // returns the number of children
virtual Node *find(int) = 0; // used to return a particular node
virtual char *print(void) = 0; // prints the subtree's expression to a
// string
// resets the parent node
void set_parent(Node *n) {parent = n;};
// accesses the parent node
Node *get_parent(void) {return parent;};
};
Some items of interest: