Algorithm to evaluate expressions using prefix notation

Assignment Help Data Structure & Algorithms
Reference no: EM131052566

Algorithm To Evaluate Expressions Using Prefix Notation.

Initialization:

1. Read a token from the input stream.

a. If it is an operand, push it into the operand stack.

b. If it is an operator, push a marker onto operand stack and push the actual operator onto operator stack.

Loop While (there are more input tokens):

1. Read a token.

2. If token is an operator, push operator onto operator stack and push the marker onto operand stack.

3. Else if, the token is an operand, check the top of the operand stack for a marker.

a. If the marker is on top of the stack, push the read operand onto the operand stack.

b. Else If - the top of the operand stack contains another operand:

Loop While (the top of the stack is an operand):

1. Pop operand from operand stack.

2. Pop marker from operand stack and the corresponding operator from the operator stack.

3. Apply the operation on the read token and popped operand and obtain result.

4. 1 If the top of the stack is another operand, continue Looping (as stated above in Loop While constraint).

4.2 Else if the top of the stack is an operator or the operand stack is empty, push the result and exit the loop.

4. Go back to step 1 (loop)

Loop is finished:

When the loop is finished (all of the input has been read), the value on top of the operand stack is the result of evaluating an expression using the prefix notation.

Some possible errors:

The operand stack was not empty at the end of algorithm.

The operator stack was not empty at the end of algorithm.

An operator is the last token in the input.

Reading illegal token from the input.

Reference no: EM131052566

Questions Cloud

Depreciation for income tax purposes : To determine the amount to be used for depreciation for income tax purposes the owner used the assessment figures as a basis for his calculations. Which of the following most nearly reflects the depreciable amount? Show your work.
Income statement that reduces equity via retained earnings : Why do capital expenditures increase assets while other cash outflows, like paying salary, taxes, etc., do not create any asset, and instead instantly create an expense on the income statement that reduces equity via retained earnings? Explain in ..
Expense-liabilities-revenue-net assets and assets : Transactions and financial statements (accrual basis) for the month of December 2014. Using only five accounts – Expense, Liabilities, Revenue, Net assets and Assets – record the following transactions and prepare a balance sheet and statement of ope..
How nats rebellion affect relation between north and south : How did Nat's rebellion affect the relationship between the North and South? Think about what happened to the trust between them.
Algorithm to evaluate expressions using prefix notation : Algorithm To Evaluate Expressions Using Prefix Notation. Initialization: Read a token from the input stream. If it is an operand, push it into the operand stack. If it is an operator, push a marker onto operand stack and push the actual operator onto..
Describe the economy of your state : What explanations have been offered in the press? How accurate are they?
German stock traded on the frankfurt exchange : Erin McQueen purchased 50 shares of BMW, a German stock traded on the Frankfurt Exchange, for 64.5 euros (€) per share exactly 1 year ago when the exchange rate was 0.67 €/US$. Today the stock is trading at 71.8 (€) per share, and the exchange rate i..
Infrastructure overhead of implementing strategy process : Why do many organizations choose not implement this process? Do you believe the cost and infrastructure overhead of implementing the Orion Strategy Process is worth the benefits? Why or why not? Without performing all of the steps within the Orion St..
Requirements of the hazard communication standard : List and briefly discuss four exceptions to the Safety Data Sheet (SDS) requirements of the Hazard Communication Standard (HCS).

Reviews

Write a Review

Data Structure & Algorithms Questions & Answers

  Implement an open hash table

In this programming assignment you will implement an open hash table and compare the performance of four hash functions using various prime table sizes.

  Use a search tree to find the solution

Explain how will use a search tree to find the solution.

  How to access virtualised applications through unicore

How to access virtualised applications through UNICORE

  Recursive tree algorithms

Write a recursive function to determine if a binary tree is a binary search tree.

  Determine the mean salary as well as the number of salaries

Determine the mean salary as well as the number of salaries.

  Currency conversion development

Currency Conversion Development

  Cloud computing assignment

WSDL service that receives a request for a stock market quote and returns the quote

  Design a gui and implement tic tac toe game in java

Design a GUI and implement Tic Tac Toe game in java

  Recursive implementation of euclids algorithm

Write a recursive implementation of Euclid's algorithm for finding the greatest common divisor (GCD) of two integers

  Data structures for a single algorithm

Data structures for a single algorithm

  Write the selection sort algorithm

Write the selection sort algorithm

  Design of sample and hold amplifiers for 100 msps by using n

The report is divided into four main parts. The introduction about sample, hold amplifier and design, bootstrap switch design followed by simulation results.

Free Assignment Quote

Assured A++ Grade

Get guaranteed satisfaction & time on delivery in every assignment order you paid with us! We ensure premium quality solution document along with free turntin report!

All rights reserved! Copyrights ©2019-2020 ExpertsMind IT Educational Pvt Ltd