The George Washington University
School of Engineering and Applied Science
Department of Electrical Engineering and Computer Science

CSci 131 - Data Structures
Programming Project #4

Due Date: April 10, 1997

The fourth project involves writing a program to evaluate a postfix expression using a generic stack package. The evaluation of the postfix expression is to be done using the generic stack package begun in Program 7.3, using an unbounded implementation as suggested in Sect. 9.3. The pseudocode for evaluating postfix expressions (a modification of the algorithm in Program 7.4) is given below:

WHILE NOT End of expression LOOP
  CASE Next character of expression IS
    WHEN Space =>
      Skip it;
    WHEN Numeric digits =>
      Convert from ASCII to floating point;
      Push value onto the stack;
    WHEN Operator =>
      Pop two values off the stack;
      Perform the operation;
      Push the result onto the stack;
    END CASE;
END LOOP;
Pop the final result off the stack;

The numeric values will be floating point numbers. Note that converting a floating-point constant from ASCII to Float is quite easy using the version of Ada.Float_Text_IO.Get that reads from a string. See Appendix D.