#ifndef TREE_H #define TREE_H #include #include #include "lextypes.h" #include "nt.h" using std::string; class TreeNode { public: TreeNode* left; TreeNode* right; TreeNode* parent; int nodeType; int intValue; double doubleValue; string stringValue; // Used also for name of variable, array, function // Node types enum { node_type_undefined = (-1), int_const = 0, double_const, string_const, name, name_ref, // used for reference parameters of functions list, array_element, function_call, empty_array, array_append, plus, minus, mul, div, mod, power, assign, uminus, lor, land, lnot, relop, // Comparing (relation operation) typecast }; TreeNode(): left(0), right(0), parent(0), nodeType(node_type_undefined), intValue(0), doubleValue(0), stringValue() {} void addLeftSon(TreeNode* t) { assert(t != 0); left = t; t->parent = this; } void addRightSon(TreeNode* t) { assert(t != 0); right = t; t->parent = this; } void printSubtree(int level = 0) const; void print() const { printSubtree(0); } static void release(TreeNode* t); // Delete tree static int height(const TreeNode* t); }; typedef TreeNode* TreeNodePtr; class Tree { public: TreeNode header; Tree(): header() {} ~Tree() { release(); } TreeNode* root() { return header.left; } const TreeNode* root() const { return header.left; } void release() { TreeNode::release(header.left); header.left = 0; } void clear() { release(); } void print() const; }; #endif