Question: Using c++ programming skills and expression trees, which are special cases of parse trees or grammar trees. Binary Expression Trees. Implement a program that takes
Using c++ programming skills and expression trees, which are special cases of parse trees or grammar trees.
Binary Expression Trees.
Implement a program that takes a binary arithmetic expression as input, builds a binary expression tree for the input and then calculates the value of the input. A binary expression is composed of double type operands, binary arithmetic operators +, -, *, and /, and parentheses ( and ). Your program shall detect whether there are any syntactic errors in the input expression. Once the binary expression tree is built for the input expression that has no syntactic errors, your program shall print prefix and postfix expressions of the input expression. You shall use stack data structures to help build the binary expression tree.
Your program shall read input expressions from a text file. Use the following examples to test your program:
(10.24 + 5.4 * 2.5) / 6.7 + (12.5 * 20.67 + 10) * 25
(10.24 + 5.4 * 2.5) / 6.7 + (12.5 * 20.67 + 10) * 25)
(10.24 + 5.4 * 2.5) / 6.7 + (12.5 * 20.67 + ) * 25
Note: o Expression 1 has no syntactic errors. o Expressions 2 and 3 have one error each.
Appreciate if you could include comments so they help improve understanding every main step of the program.
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
