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}{

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!