The code needs to be in C++. DO NOT JUST COPY THE PROVIDED CODE AS YOUR FINAL ANSWER THAT IS INCORRECT. Your problem is to

Answered step by step
Verified Expert Solution
Question
21 users unlocked this solution today!

The code needs to be in C++. DO NOT JUST COPY THE PROVIDED CODE AS YOUR FINAL ANSWER THAT IS INCORRECT. Your problem is to convert a given infix expression into a sequence of assembly instructions that evaluates the expression and leaves the result in the register. You will do this by using postfix expressions. First, you will convert a given infix expression into the corresponding postfix expression. In the second step, you will convert postfix to the required sequence of assembly instructions. You will read the infix expression from a file, and write the result to another file.

You must implement a destructor, copy constructor, constant time swap, and assignment. For example, given the following infix expression: ( ( A + ( B * C ) ) / ( D - E ) ) we get the postfix expression: A B C * + D E - / This results in an assembly program that looks like:

Opcode Operand Comment
LOAD B Load in B.
MULR C B * C.
STOR TMP1 Save results of B * C.
LOAD A Load A.
ADDR TMP1 Add A to B * C.
STOR TMP2 Save result.
LOAD D Load D.
SUBR E D - E.
STOR TMP3 Save result.
LOAD TMP2 Get A + B * C.
DIVR TMP3 Divide it by D - E.
STOR TMP4 Save result, also still in register.

Your program output should be:

 Infix Expression: ( ( AX + ( BY * C ) ) / ( D4 - E ) ) Postfix Expression: AX BY C * + D4 E - / LOAD BY MULR C STOR TMP1 LOAD AX ADDR TMP1 STOR TMP2 LOAD D4 SUBR E STOR TMP3 LOAD TMP2 DIVR TMP3 STOR TMP4 

Requirements:

You CANNOT use std::string and must construct your stack using a linked list you build.

Implementation:

Create a generic (template) ADT stack class.

1) Implement using a linked list.

2) You must implement a destructor, copy constructor, constant time swap, and assignment.

3) You will need to have a stack of strings.

Use the following files as a starting point:

-----------------------------------------------------------------------

stack.hpp

-----------------------------------------------------------------------

#ifndef STACK_HPP #define STACK_HPP #include const int MAX_VALUES = 256; template class stack { private: int tos; type values[MAX_VALUES]; public: stack() : tos(-1) {} /** @pre non-full stack */ void push(const type & object) { assert(!full()); ++tos; values[tos] = object; } /** @pre non-empty stack */ void pop() { assert(!empty()); --tos; } /** @pre non-empty stack */ type top() const { assert(!empty()); return values[tos]; } /** @pre non-empty stack */ type & top() { assert(!empty()); return values[tos]; } bool empty() const { return tos == -1; } bool full() const { return tos == (MAX_VALUES - 1); } }; #endif 

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Link Copied!

Step: 1

blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

100% Satisfaction Guaranteed-or Get a Refund!

Step: 2Unlock detailed examples and clear explanations to master concepts

blur-text-image_2

Step: 3Unlock to practice, ask and learn with real-world examples

blur-text-image_3

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

  • tick Icon Access 30 Million+ textbook solutions.
  • tick Icon Ask unlimited questions from AI Tutors.
  • tick Icon Order free textbooks.
  • tick Icon 100% Satisfaction Guaranteed-or Get a Refund!

Claim Your Hoodie Now!

Recommended Textbook for

Inductive Databases And Constraint Based Data Mining

Authors: Saso Dzeroski ,Bart Goethals ,Pance Panov

2010th Edition

1489982175, 978-1489982179

More Books
flashcard-anime

Study Smart with AI Flashcards

Access a vast library of flashcards, create your own, and experience a game-changing transformation in how you learn and retain knowledge

Explore Flashcards

Students Have Also Explored These Related Databases Questions!