IUP Computer Science
CO 310 Fall 1983

Assignment #4



    Write a program that will evaluate postfix expressions.   These expressions will consist of positive numbers and operators (+, -, *, /) separated by spaces.  For example:
          23 5 10 7 - * 11 - +

This is equivalent to 23 + (5 * (10 - 7) - 11) which has a value of 27.
    There is one space between each two operands and operators.   The numbers are never more than four  digits long.  The whole expression takes no more than 80 characters.

    Your program should do the following.

1.  Read each of the postfix expressions in the file 310EVAL.COMPSCI.  There is one expression in each record.

2.  For each valid expression, print out the expression and the evaluation of it.

3.  For each invalid expression, print out the expression and an appropriate error message.

          Hints

1.   Read each  expression as a string of characters and use the built in subroutines (INDEX to find the spaces, SUBSTR to extract the operands, and CHARBIN to convert the operands to their numeric equivalent).  Note: CHARBIN converts trailing spaces to zeros.

2.   Expand on the EVAL and DOIT procedures described in class to do the postfix evaluation.