EE 100 Homework 1: Postfix Calculator

Hand out

Policy on plagiarism

This is an individual homework. While you may discuss the ideas and algorithms of this homework with others, at no time should you read the source code or possess the source files of any other person, including people outside this course. We will detect plagiarism using automated tools and will prosecute all violations to the fullest extent of the university regulations, including failing this course, academic probation, and expulsion from the university.

Description

Create a simple postfix calculator.

A postfix calculator reads its input in postfix notation. You may be familiar with infix notation, where the operator is placed between the operands. (e.g., 1 * 2 + 3). Postfix notation places the operator after the operands (e.g., 1 2 * 3 +). Postfix notation removes the need for parentheses or operator priorities, which is an advantage over infix notation. A postfix calculator reads operands and operators from left to right in a postfix expression and uses a stack to evaluate the expression:

Your program reads its input, a postfix expression, from stdin, evaluates the expression, and prints the result to stdout.

The input consists of a sequence of numbers and operators separated by one or more whitespace. Read the input until EOF, as the input may span multiple lines.

We will test your program with only valid postfix expressions, which contain valid numbers, operators, and whitespace defined above. Your prgram need not handle integer overflow or division by 0.

Output the decimal signed integer result of the calculation, followed by a newline '\n'. Your output should exactly match the output of the reference program. In other words, given the same input, the output of your program must be identical to that of the reference program. If you run the Linux command diff on the two outputs, diff must report nothing. However, if you think that the reference program does not behave as specified, please report the bug.

Gradebot instructions

Exit status

Your program must not exit with a non-zero status. This means that if your program calls exit(), the argument must be zero.