Question: Please write a code using the stack functions to make a Reverse Polish Notation calculator in the language Rust. Implement a calculator for arithmetic programs

Please write a code using the stack functions to make a Reverse Polish Notation calculator in the language Rust.

Implement a calculator for arithmetic programs written in RPN style, as specified by the following grammar:

Binary Operators b ::= + | - | * | / Terms t ::= n //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_0 t_1 ... t_n done

Example of the run

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

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

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

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!