// grammar: // ::= a | b | ... | z | A | B | ... | Z // ::= { }+ // ::+ 0 | 1 | ... | 9 // ::= { }+ // ::= [ ] | // ::= | [ ] class VarTreeNode{ public: // kinds of nodes which can occur. the net effect of // this declaration is to define a bunch of constants. enum nodeType { SUBSCRIPT = 0, NAME = 1, NUMBER = 2, UNDEFINED = 3 }; nodeType type; int value; // only used when "type" == NUMBER String2002 varname; // only used when "type" == NAME VarTreeNode *left, *right; // note: the second and third arguments are optional VarTreeNode (nodeType type, int value = 1, String2002 varname = "") { VarTreeNode::type = type; VarTreeNode::value = value; // harmless at worst VarTreeNode::varname = varname; // harmless at worst left = right = NULL; // guarantee reasonable values } }; void deleteVarTree(VarTreeNode *root); void outputVariable (VarTreeNode *root); // outputs an error message and returns null if the string // is not a valid expression VarTreeNode *createVarTree (String2002 str);