Department of Electrical and Computer Engineering
University of Texas at Austin
EE 379K, Fall 2000
Y. N. Patt, Instructor
TAs: Kathy Buchheit, Laura Funderburg, Chandresh Jain, Onur Mutlu,
Danny Nold, Kameswar Subramanian, Francis Tseng, Brian Ward
Programming Assignment 5
Due: December 3, 2000 11:59 PM
Infix Calculator
Problem Statement
In this program, we ask you to design an infix calculator. The program
should start by displaying a prompt for the user Input>. The user
will then enter an arbitrary arithmetic expression, using only the operator
+ (denoting the binary operation of addition), the operator - (denoting
the binary operation of subtraction), the left parenthesis, the right parenthesis,
together with decimal valued integer operands. This expression should be
entered using an infix notation (explained below). As this expression is
entered, the program can begin evaluating the expression. Once entry of
the expression is complete (i.e., after the user hits the "ENTER" key),
the program should display the results of calculating the arithmetic expression
entered, followed by a new prompt for further user input. When the user
types "x" in response to the prompt for further input, the program
should display "Have a nice day!" and terminate.
Infix Notation
Most people are accustomed to writing arithmetic expressions in INFIX
notation, in which case an operator that denotes a binary operation appears
BETWEEN the two operands, as in
( 2 + 3 )
Using nested parentheses, we can represent more complex expressions such
as
( 11 + ( ( 19 + 23 ) - ( 4 + 10 ) ) )
Program Details
-
You may assume that only valid input expressions are entered.
-
The numbers and symbols must be separated by exactly one space.
-
The numbers in the input expression are positive integers up to three decimal
digits.
-
The input expression is fully parenthesized. Examples of expressions
that are NOT fully parenthesized are
1 + 2
and
( 2 + ( 15 - 12 ) + 5 )
-
There must be an operator for every pair of parentheses. For example, the
following will not be considered as valid input expressions.
( 5 )
and
( ( 5 ) - ( 4 + 3 ) )
-
Your result should be output to the screen using a plus or minus sign followed
by three deciaml digits.
-
When the result of an expression is zero, you should output +000.
-
You are strongly encouraged to use a stack in the implementation of your
design. You should allocate a block of 50 entries for the stack in your
program.
-
You are also encouraged to use subroutines to make your program easier
to work with.
-
You are free to use any example program in the textbook.
Sample Input/Output
Input> ( 101 - ( ( 23 + 31 ) + 74 ) )
-027
Input> ( 150 - ( 1 + 2 ) )
+147
Input> ( 1 - 1 )
+000
Input> ( ( 200 - ( ( ( ( ( 5 - 3 ) - 75 ) - 18 ) + 5 ) - 7 ) ) + 2
)
+295
Input> x
Have a nice day!
Writing and submitting your program
-
Your code should have a comment block at the beginning of the file.
Include in this comment block, your name, your ECE login name, student
number, and a brief description of the program. Your description should
serve as a general summary of your program's approach to the problem and
will aid in grading. It will also serve as a guideline for assigning partial
credit. It is in your best interest to make all of your ideas clear through
this summary and through commenting within your code.
-
We request you place your program starting at memory location x3000.
-
Think carefully about the design of your program before you start writing
your code. Make a flowchart before you start writing code.
-
Submit your assembly file using the submit program or the submit script.
The program number is 5.
-
Check your ECE email to verify that you have submitted your program
correctly. If you don't get a confirmation, we might not see your submission.