Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

In Java write a program that will recognize and evaluate prefix expressions. First design and implement a class of prefix expressions. This class should contain

In Java write a program that will recognize and evaluate prefix expressions. First design and implement a class of prefix expressions. This class should contain methods to recognize and evaluate prefix expressions. I need help creating this program with the given algorthms I have from the book.

isPre()

size = length of expression strExp

lastChar = endPre(0, size 1)

if (lastChar >= 0 and lastChar == size-1 {

return true

}

else {

return false

}

evaluatePrefix(strExp)

ch = first character of expression strExp

Delete first character from strExp

if (ch is an identifier) {

return value of the identifier

}

else if (ch is an operator named op) {

operand1 = evaluatePrefix(strExp)

operand2 = evaluatePrefix(strExp)

return operand1 op operand2

}

endPre( in first:integer, in second:integer):integer

if (first < 0 || first > last )

{

return -1

}

ch = character at position first of strExp

if ( ch is an identifier)

{

//index of last character in simple prefix expression

return first;

}

else if(ch is an operator )

{

//find the end of the first prefix expression

firstEnd = endPre (first +1, last)

//If the end of the first expression was found

//If the end of the second prefix expression

if(firstEnd > -1)

{

return endPre(firstEnd +1, last)

}

else

{

return -1

}

else

{

return -1

}

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

Database Management With Website Development Applications

Authors: Greg Riccardi

1st Edition

0201743876, 978-0201743876

More Books

Students also viewed these Databases questions

Question

4. Explain why the long-run aggregate-supply curve is vertical.

Answered: 1 week ago

Question

=+ Why have these changes occurred?

Answered: 1 week ago

Question

=+90 percent of all oil refineries) into several smaller companies

Answered: 1 week ago