Integer expression evaluator this program must use stacks

Assignment Help Basic Computer Science
Reference no: EM13630554

This program must use stacks in order to evaluate integer expressions. Your program need only implement the following binary operators: <br/> <br/>+ … addition <br/>- … subtraction <br/>* … multiplication <br/>/ … integer division <br/>< … minimum (e.g. 3 < 2 yields 2) <br/>> … maximum (e.g. 3 > 2 yields 3) <br/> <br/>To keep the assignment somewhat more manageable you may assume that all input integers are unsigned single decimal digits (0-9). However, your evaluation may result in larger and/or negative integers. <br/>The evaluation of expressions must recognize the standard precedence: <br/>< and > have the highest precedence <br/>* and / have the middle precedence <br/>+ and - have lowest precedence <br/>Expressions must also permit the usual use of parentheses (...) to override precedence. <br/>Below are several examples of proper expressions: <br/> <br/>1+2*3>4 <br/>(24-7)/2+6<3*(31-299) <br/>2*3*4*5*6 <br/>10>9*8+7+2 <br/> <br/>Your program must read input expressions from a text file and allow the user to select which text file to process using a JFileChooser. You may assume that each line of the text file is a separate integer expression and that there are no blanks or other invalid characters in the file. <br/>For each input expression your program should output (using System.out.println) the input line followed by "==" then followed by the numeric value of the resulting expressions evaluation. <br/>You must implement a generic Stack class like the one given in lecture. <br/>The standard algorithm for evaluating expressions of this style is to use two stacks - one <br/>stack for operators (the operator stack) and the other for operands/subexpression values <br/>(the operand stack). An expression is processed left to right as follows: <br/>• Each operand encountered is pushed upon the operand stack. <br/>• Each left paren encountered is pushed upon the operator stack. <br/>• Each right paren causes operators to be popped from the operator stack and the associated subexpressions evaluated until a left paren is found in the operator stack. The left paren is then popped. <br/>• Each operator has its precedence compared to the precedence of the operator atop the operator stack. Operators are popped off the operator stack and their corresponding subexpressions evaluated until the top of the operator stack is <br/>either a left paren or has a precedence less than the new operator. After evaluating subexpressions, the new operator is pushed onto the operator stack. <br/>• At the end of the expression all operators on the operator stack must be popped and their corresponding subexpressions evaluated. The value of the expression should be the single remaining value atop the operand stack. When the prior explanations refer to “popping an operator and evaluating the <br/>corresponding subexpression” this means that the operand stack should be popped <br/>twice, and the two popped operands are evaluated using the popped operator with the <br/>resulting value pushed on the operand stack. For example, if the top of the operand <br/>stack is a 7 and the second operand in the operand stack is a 3 and the operator is a “-“, <br/>then all three of these are popped and the result of the subexpression 3-7 (i.e., the value -4) is pushed on the operand stack.

Reference no: EM13630554

Questions Cloud

For a brief time the formula 1 championship held one of the : race cars often use wings in an effort to increase cornering speeds. the wings provide an extra downward force that
Air as an idea gas is compressed from a state where the : air as an idea gas is compressed from a state where the pressure is 0.1 mpa and the temperature is 27oc to a state
Water at 25 degrees c enters a heat exchanger at 01 kgs and : water at 25 degrees c enters a heat exchanger at 0.1 kgs and exits at 50 degrees c. kerosene enters the other side of
Geography 4 assignments coastal geography that go along : 4 assignments coastal geography that go along with spreadsheet ltbrgt ltbrgtthese are the first 2 assignments it would
Integer expression evaluator this program must use stacks : this program must use stacks in order to evaluate integer expressions. your program need only implement the following
Project i have a project and i really need help with it its : i have a project and i really need help with it its in fact 8 of them. the book is fundamentals of differential
Family health assessment select a family to complete a : select a family to complete a family health assessment. the family cannot be your own. ltbrgt ltbrgtbefore interviewing
Okuns law the natural unemployment rate is 4 percent and : the natural unemployment rate is 4 percent and the actual unemployment rate is 7 percent. describe okun3939s law and
Computer micro code etc need this in a hurry will pay : need this in a hurry will pay whatever.its due by the end of today and just curious if you guys could do it that

Reviews

Write a Review

Basic Computer Science Questions & Answers

  Trust and deception

Trust and Deception

  Turing machine that decreases positive binary number by one

Write a Turing machine that decreases a positive binary number by one? By writing turing machine an instruction set in the form of (w,x,y,z,a) where w is current state,

  Discuss benefits of working with shell scripts

Discuss the benefits and provide examples of working with shell scripts.

  Cell e2 that will calculate gross pay.

Part 1: Write a formula as if it were in Cell E2 that will calculate gross pay. Write the formula so that it may be copied to the other employees without modification.

  How many different seven-digit phone numbers can be formed

How many different seven-digit phone numbers (ignoring area code) can be formed? Can city of 2 million people be served by single area code? Describe.

  Can the capability also be used to install windows 7

What Windows Server 2008 capability enables them to do the mass installation quickly and efficiently? What general steps are involved in setting up this capability? Can the capability also be used to install Windows 7 on the 24 new client workstat..

  Write select statement create this column and format columns

Write a Select statement that returns one column from the Vendors table named Full Name.

  Determine gradient magnitude and gradient direction of image

Consider the sub-image. Determine gradient magnitude and gradient direction at center entry using following operators.

  Write a basic java program called that simulates a lottery

Your program will generate a 5-digit lottery number, and then it will prompt the user to enter a guess in the form of a 5-digit number. Your program should then determine how many numbers.

  Distance between nodes u and v

The distance between nodes u and v in graph is the length of the shortest path from u to v. Given a d-dimensional hypercube and a designated source node s, how many nodes are distance i from s, where 0

  Write a program in python shell

Write a program in python shell. Convert inches into yards, feet, and inches. This time, use a variable to store the number of inches. You may use more than one variable.

  The wireless technology company

The Wireless Technology Company

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