Please complete this assignment and submit in a python file, name it p5.py and implement expression evaluator using Python. The input text files t5*.dat should be at the same directory with your p5.py...

Please complete this assignment and submit in a python file, name it p5.py and implement expression evaluator using Python. The input text files t5*.dat should be at the same directory with your p5.py file. Each input file has only one expression consists of positive integers, whitespaces like space (‘ ‘) or tab, add (‘+’), multiply (‘*’), open parenthesis (‘(‘), and close parenthesis (‘)’). If input contains any other characters or imbalanced open and close parenthesis, your p5 should report error and handle the next input file if there is one. The parenthesis has the highest precedence, the * is second highest, and + is the lowest. Since you read input as a character string, you need to convert numbers to integer by int(). If the input is a legal expression, your p5 should output correct answer for the expression.


Example input and output:


t50.dat:


2*(5+3*3)


The output for t50.dat should be 28


t51.dat:


(1 + 2 * (51              + 3 * 3)) * 12 + 110


The output for t51 should be 1562


t59.dat:


(1+a)) + 1 * ((2)


Your p5 should report error and handle next input file.







May 18, 2022
SOLUTION.PDF

Get Answer To This Question

Submit New Assignment

Copy and Paste Your Assignment Here