Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

IN JAVA: For this lab we will be building an expression translator to convert infix notation to postfix notation . Typical expressions to be evaluated

IN JAVA:

For this lab we will be building an expression translator to convert infix notation to postfix notation. Typical expressions to be evaluated are as follows:

 
infix expression postfix expression
a + b - c a b + c -
a - b + c * d a b - c d * +
a + c - h / b * r a c + h b / r * -
a + ( c - h ) / ( b * r ) a c h - b r * / +
 

An algorithm to accomplish the transformation is:

R1: Initially the operatorStack is empty

R2: For each operator of the infix string loop until the operator has been pushed onto the operatorStack:

If the operatorStack is empty or the operator has a higher precedence than the operator on the top of the operatorStack then push the operator onto the operatorStack

else pop the operatorStack and append that popped operator to the postfix string

R3: Once the end ot the input string is encountered

loop until the operatorStack is empty: Pop the operatorStack and append that popped operator to the postfix string

infix expression: a + b - h / b * r
infix operatorStack postfix
a empty a
+ + a
c + a c
- - a c +
h - a c + h
/ -/ a c + h
b -/ a c + h b
* -* a c + h b /
r -* a c + h b / r
- a c + h b / r *
empty a c + h b / r * -

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

Step: 3

blur-text-image

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

Records And Database Management

Authors: Jeffrey R Stewart Ed D, Judith S Greene, Judith A Hickey

4th Edition

0070614741, 9780070614741

More Books

Students also viewed these Databases questions

Question

2. How were various roles filled?

Answered: 1 week ago