Question: Given an expression tree, write a method to evaluate it and return its value. Assume that the Token class has a member function long getValue()

Given an expression tree, write a method to evaluate it and return its value. Assume that the Token class has a member function "long getValue()" that returns the value of a token that is an operand. Token class has a field "Token Type token" which takes one of the following four values when the token is an operator: {PLUS, MINUS, TIMES, DIV}, corresponding to the operators [+, -, *, }. In expression trees, internal nodes are operator nodes and leaf nodes are operands. Make additional assumptions as needed as in Project 1. class Expression {Token toke; Expression left, right;} long evaluateExpTree (Expression tree) { Given an expression tree, write a method to evaluate it and return its value. Assume that the Token class has a member function "long getValue()" that returns the value of a token that is an operand. Token class has a field "Token Type token" which takes one of the following four values when the token is an operator: {PLUS, MINUS, TIMES, DIV}, corresponding to the operators [+, -, *, }. In expression trees, internal nodes are operator nodes and leaf nodes are operands. Make additional assumptions as needed as in Project 1. class Expression {Token toke; Expression left, right;} long evaluateExpTree (Expression tree) {
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
