Ask Question, Ask an Expert

+61-413 786 465

info@mywordsolution.com

Ask Computer Engineering Expert

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.

Computer Engineering, Engineering

  • Category:- Computer Engineering
  • Reference No.:- M91776983
  • Price:- $60

Guranteed 36 Hours Delivery, In Price:- $60

Have any Question?


Related Questions in Computer Engineering

Solve the problem by implementing the whole class with main

Solve the problem by implementing the whole class with main() function and demonstrate that your Java code can pass several appropriate test cases successfully in your main() function? Write a short recursive Java method ...

A string in c is simply an array of characters with the

A string in C++ is simply an array of characters with the null character(\0) used to mark the end of the string. C++ provides a set of string handling function in as well as I/O functions in . With the addition of the ST ...

Use the normal model n110756 for the weights of steersa

Use the Normal model ?N(1107?,56) for the weights of steers. A) What weight represents the 49th Percentile? B) What weight represents the 99th Percentile? C) What's the IQR of the weights of these steers?

The literature on honeypots or so called fake networks to

The literature on honeypots or so called "fake networks" to attract hackers and attackers frequently mentions "entrapment" as one of the legal issues that must be considered. How of a concern is entrapment? What are some ...

Subject digital securitybesides legal factors what are

Subject : Digital Security Besides legal factors, what are some of other important factors that need to be seriously considered when the cloud computing and service company(assuming) you work for decides to extend busine ...

Question there are a number of key steps necessary to

Question: There are a number of key steps necessary to effectively handle an incident. Please briefly describe the basic activities in the incident response procedure . Choose two activities in the basic activities in th ...

Make a function first-char that consumes a nonempty string

Make a function first-char that consumes a nonempty string and produces a string consisting of the first character in the original string. Do not use string-ref.

What are some topics that must be covered in a business

What are some topics that must be covered in a business case presented to management?

Current system analysis and modelling assignment 1

Current System Analysis and Modelling Assignment 1 - Assignment overview - This assignment aims to produce a requirements document that captures the functional requirements for an information system that supports the cur ...

Question having separate level 1 caches for instructions

Question : Having separate level 1 caches for instructions and data is a popular technique. Describe how this might pay off if a short loop of code that is operating on a giant array. Imagine that instructions and data e ...

  • 4,153,160 Questions Asked
  • 13,132 Experts
  • 2,558,936 Questions Answered

Ask Experts for help!!

Looking for Assignment Help?

Start excelling in your Courses, Get help with Assignment

Write us your full requirement for evaluation and you will receive response within 20 minutes turnaround time.

Ask Now Help with Problems, Get a Best Answer

Why might a bank avoid the use of interest rate swaps even

Why might a bank avoid the use of interest rate swaps, even when the institution is exposed to significant interest rate

Describe the difference between zero coupon bonds and

Describe the difference between zero coupon bonds and coupon bonds. Under what conditions will a coupon bond sell at a p

Compute the present value of an annuity of 880 per year

Compute the present value of an annuity of $ 880 per year for 16 years, given a discount rate of 6 percent per annum. As

Compute the present value of an 1150 payment made in ten

Compute the present value of an $1,150 payment made in ten years when the discount rate is 12 percent. (Do not round int

Compute the present value of an annuity of 699 per year

Compute the present value of an annuity of $ 699 per year for 19 years, given a discount rate of 6 percent per annum. As