In my programming languages class we are working on a parser project that generates a parse tree and evaluates mathematical expressions based on the trees generated.
I have completed the first part, and the correct parse trees are generated according to the given mathematical expressions.
I am having trouble getting started on the second part, in which the interpreter does a tree walk and calculates a result based on the characteristics of the parse tree.
I only need to create one method to do this, everything else has been included in the assignment.
Here is my working method for addition and subtraction in my parser class:
What I need to do now is include a method in my interpreter class that can evaluate the expression "a=2+3" if I can figure that part out I can probably get the rest, but
as for now I have no idea what to do.
This is what the given evaluate method in my interpreter class looks like:
These are the specific assignment instructions:
You will be completing the method evaluate(TreeNode t) contained in the TestInterpreter class so that it correctly evaluates the parse tree (by doing a tree walk) for arithmetic expressions passed to it as the parameter t, and returns the result of the evaluation. Here are the meanings (interpretations) of the operations associated with the operators, all with respect to real operands:
+ addition
- subtraction
Any help is appreciated. Thanks!