Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

In this assignment you are required to write a complete code execution system for the language given below. You must follow the guidelines to the

In this assignment you are required to write a complete code execution system for the language given below. You must follow the guidelines to the letter, otherwise you may lose significant amount of points even if your program does the requested job.

Your system should have two types of statements, variable assignment and expressions. In variable assignment, you will have variable name followed by = symbol which will be followed by a standard expression.Expressions can include variables, regular arithmetic operators (+, -, *, /), power operator (^) and parenthesis. Additionally, your system should support negative operator (-), a hint will be provided at the end of the assignment to help you accomplish the task. Regular arithmetic operators are left to right while negative and power operators are right to left. To get full marks, your system should accept multi character variables, multi digit numbers and work with doubles. Thus, 2.5 + 2 should produce 4.5 correctly. No need to distinguish between integers and real numbers, treat everything as double. You can use std::stod function in C++ to convert a string to double.

Your program should read a complete line. In C++ you can usestd::getline(std::cin, line);to read the line to the string variable line. Assignment shall not produce any output (not even newline). If the statement is just an expression, you shall print the result of it. The output should only contain numbers followed by a new line. Your program should terminate if it receives ! as input.

You should use shunting yard algorithm to perform this task. You do not need to produce postfix output or AST. Simply perform the calculation. You can use any programming language that I will be able run in my system. These are C++, C, python, php (cli only), nodejs, and haskell. Any attempt at cheating will result in 0 and most likely you will fail the course. Do as much as you can, partial points will be given. Just ensure your program is compiling and running, even if it produces wrong results. You may test your application with the following input. The output you should produce is marked red. Your program should not crash during the entire run, it should keep asking for more input.

You should submit a single code file. I should be able to compile and run this single file by itself. If moodle does not allow your program extension, save it as text file and upload.

2+2

4

2+3*2

8

2+2*(3+2)+2

14

14-2^2

10

2^3^2

512

5 + 9

14

8 *-4

-32

x=4

x+5

9

y = x + 2*x

y

12

my = x+y/2

my^2

100

!

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Students also viewed these Programming questions