#ifndef EXPRESSION_TREE_H #define EXPRESSION_TREE_H #include #include "Token.h" #include "BinaryTree.h" class ExpressionTree : public BinaryTree { public: /* * Default constructor (for convenience). No need to implement. */ ExpressionTree() {}; /* * Constructor to build an Expression Tree based upon an array of * 'tokens' */ ExpressionTree(int numTokens, const Token tokens[]); /* * Evaluate the underlying expression, returning the result of that evaluation. */ int evaluate() const; /* * EXTRA CREDIT version of constructor to build an Expression Tree * based upon an array of 'tokens'. * * This version handles more general syntax which may not be fully * parenthesized or which may include unary negation. * * Furthermore, it throws and InvalidExpressionException in the * case where the input has invalid syntax. */ ExpressionTree(const Token tokens[], int numTokens); /* * You will likely need to define your own recursive functions. * You can decide whether the design makes sense to have each as * public or private. */ }; /* * Overloaded output operator should result in echoing the underlying * arithemtic expression in fully-parenthesized form. */ std::ostream& operator<<(std::ostream& out, const ExpressionTree& T); #endif