Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Write a program using the language Rust, not in any other language. Please use the public api as well. ## Description Write a [postfix](https://en.wikipedia.org/wiki/Reverse_Polish_notation) expression

Write a program using the language Rust, not in any other language. Please use the public api as well.

## Description Write a [postfix](https://en.wikipedia.org/wiki/Reverse_Polish_notation) expression evaluator. An expression consists of operands and operators. An operand is a signed integer (`isize`). An operator is `+`, `-`, or `*` with their common semantics. An expression is valid if it can be evaluated to a signed integer. For example, the following are valid expressions: ``` -100 1 2 + 1 2 3 + * ``` The following expressions are invalid: ``` // empty expression -1 -2 1 2 + * ``` ## Public API Your program must provide the following public API. ``` pub enum Operator { // `+` Add, // `-` Sub, // `*` Mul, } pub enum Token { Operator(Operator), Operand(isize), } /// Evaluates the postix expression. /// /// Input: a postfix expression, where each element contains an operator or operand. /// Returns: if the postfix expression is valid, returns `Some(value)`; /// otherwise, returns `None`. pub fn eval(tokens: &[Token]) -> Option { // TODO unimplemented!(); } 

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

Recommended Textbook for

Database Concepts

Authors: David Kroenke, David Auer, Scott Vandenberg, Robert Yoder

8th Edition

013460153X, 978-0134601533

More Books

Students also viewed these Databases questions

Question

If you were Akio, what would you do now?

Answered: 1 week ago

Question

What is management growth? What are its factors

Answered: 1 week ago

Question

LO1 Explain how the workforce is changing in unpredicted ways.

Answered: 1 week ago