Answered step by step
Verified Expert Solution
Question
1 Approved Answer
This is a RUST program, I need it by today midnight, please help! Implement a calculator for arithmetic programs written in RPN style, as specified
This is a RUST program, I need it by today midnight, please help!
Implement a calculator for arithmetic programs written in RPN style, as specified by the following grammar: Binary Operators b ::= + | - | */ Terms t := n 1/ 32-bit signed integers, e.g., -1, 2, 256, 0, ... | b // Binary operator save // Pop from the main stack, pushing the value onto an auxiliary stack | restore // Pop from the auxiliary stack, pushing the value onto the main stack RPN Programs p ::= t_ t_1 ... t_n done That is, a valid RPN program is a series of n terms, to t_1 ... t_n, followed by the keyword done. Both the example programs given above are valid according to this grammar. The special commands save and restore allow the programmer to save values from the calculator's main stack onto an auxiliary stack for later computation. Here's a program that calculates the sum of two numbers, then uses save and restore to subtract the result from 0. 7 8 + save o restore - done with stack trace: Operation Main Stack Auxiliary Stack push 7 [7] push 8 [7; 8] op + [15] save 15 0) [15] push 0 [0] [15] restore 15 [0, 15] [ op - [-15] 0 The special term done must appear at the end of every valid RPN program, and has the effect of printing out the top value on the main stack (if any), then terminating the program. It's an error if done is encountered with no values on the stack. Examples Program Result 1 2 3 done 3 1 2 + 3 + 4 + 5 + done 15 1 2 3 4 5 + + + + done 15 1 2 + save 3 restore + done 6 1 2 + done 3 4 5 done 3 10 2 / save 7 restore - done 2 Specifics 1. Write a program,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