Question: C++ Using stacks, write an infix expression parser. Here are a few examples of expressions your program should parse and evaluate Result Expression 1+2 3
C++
Using stacks, write an infix expression parser. Here are a few examples of expressions your program should parse and evaluate Result Expression 1+2 3 2+2 2 3 14 0 /or false if the t 1/ or true if the t 0 //or false if the t is bool is bool is bool 1+3>2 +2-5 (3 2) Technical Requirements Your parser should parse an infix expression that supports the following arithmetic and logical operators with the specified precedencies Precedence Example ! 1 // - 0 (false Operaton ! //logical not ++//prefix increment .. //prefix decrement negative /power 2 3 /8 62//4 6!-5 / 1 (true) /.% //arithmetic //arithmetic 1 true -,-//equality &//logical and arison3 6>5 && 4>5 /0 (false) l //logical OR 11 0 111 (true) (Weight: 3096) Parse an expression given in a string format. Your program should be flexible with the given expressions. For instance, 1+2 is the same as 12. The user should not worry about writing the spaces between operands and operators. (Weight: 2096) Your program should check for invalid expressions, and produce meaningful error messages when necessary. Further, the error message should indicate whether the error happened (Only report the first error the program encounters and exits the program) Here are a few examples What the user enters Error message Expression can't start with a closing parenthesis char: 0 Expression can't start with a binary operator char: 0 Two binary operators in a row @ char 3 Two operands in a row char 5 A unary operand can't be followed by a binary operator char 6 Division by zero char 2
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
