Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Can you please be quick and do part A and B only and report also Project Definition: In this project, you will implement common data
Can you please be quick and do part A and B only and report also
Project Definition: In this project, you will implement common data structures such as vector and stack to EREF. Please, read each part carefully, and pay attention to Assumptions and Constraints section. Part A. In this part, you will add vector to EREF. Introduce new operators newvector, updatevector, read-vector, length-vector, and swap-vector with the following definitions: (50 pts) newvector: ExpVal x ExpVal VecVal update-vector: VecVal ExpVal ExpVal Unspecified read-vector: VecVal x ExpVal ExpVal length-vector: VecVal ExpVal swap-vector: VecVal x ExpVal x ExpVal-> Unspeciffed copy-vector: Vecval Vecval This leads us to define value types of EREF as: VecVal =(Ref(ExpVal)) ExpVal = Int + Bool + Proc + VecVal + Ref ( ExpVal ) DenVal = ExpVal Operators of vectors is defined as follows; newvector (length, value) initializes a vector of size length with the value value. update-vector (vec, index, value) updates the value of the vector vec at index index by value value. read-vector (vec, index) returns the element of the vector vec at index index. length-vector (vec) returns the length of the vector vec. swap-vector (vec, index, index) swaps the values of the indexes in the vector vec, copy-vector (vec) initializes an new vector with the same values of the given vector vec. (Creates a deep copy of the given vector.) Part B. In this part, you will implement a Stack using vectors that you implemented in Part A. Stack is a linear type of data structure that follows the LIFO (Last-In-First-Out) principle and allows insertion and deletion operations from one end of the stack data structure, that is top. In other words, whenever pop is called, the element that is added latest is removed and returned from the stack. You will implement the following operators of Stack with the given gramman: newstack (L) returns an empty stack with max-size L. push (s, val) adds the element val to the stack s. If the stack is full it throws a stack overflow error. pop (s) removes the last element of the stack s and returns its value. stack-size(s) returns the number of elements in the s. peek (s) returns the value of the last element in the stack s without removal. empty-stack? (s) returns true if there is no element inside the stack s and false otherwise. print-stack (s) prints the elements in the stack s. Part C (bonus). In this part, you will implement multiplication function for vectors, in order to support interpreter level vector multiplication, which is more efficient: vec-mult talos two vectors, calculates their pairwise multiplication and outputs a new vetor. If the sizes of the vectors are not equal, it throws an error Expression:=vec-mult(Expression,Expression)vec-mult-exp(vecl,vecl) Example: Figure 1. Syntax for wer-mult Expression Report. Your report should include the following: (1) Workload distribution of group members. (2) Parts that work properly, and that do not work properly. (3) Your approach to implementationas: How does your stack work?, How did you implement vec-mult? ete. Include your report as PDF format in your sabanission folder. Assumptions and Constraints. Read the followitg assumptions and constraints carefully: You may not consider the edge cases related to the assumptions. (1) For stack, you may assume print-stack will only be used for stacks of integers. (2) Stack does not have to be new defined data types, you can utilize the vector implenentation frotn Part A. (3) It is guaranteed that the correct type of parameters will be passed to the operators. For example, in pop(s), s always be a strek. (4) If stack is empty, pop operation must retarn 1, (5) You CANNOT define global variables to keep trark of the size or top eleanent of a stack. The reason is we may create multiple stacks and euch of them may have different sizes and froat elements. (6) If you consider using list of references for vector and stack, find an efficient way to reach to an elements, you are NOT allowed to iterate over list, (7) Please consider that we will test yout code with sotne additional test cases, which will not be shared publicly. Thus passing all tests does not guarantee full points Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started