CS 451 Programming Paradigms
LISP Assignment One: RPN Calculator

Your assignment is to write in Lisp a postfix calculator that takes postfix expressions involving the +,-, and * binary operators. For example,

(2 3 + 4 -)

evaluates to 1.

You also must generate either the infix or prefix translated string, with parentheses. If you understand how to do the calculation this should be easy.
The infix version of the above is ((2+3)-4).
The prefix version of the above is (- (+ 2 3) 4)

Note that this implies that you apply an operator to the two operands preceding it (either or both of which may be the result of other operations) in the order they appear. The ( 2 3 + 4 -) becomes (5 4 -) after the first operator is applied. Then the - operator is applied between 5 and 4 in the order they appear, resulting in 1.

You will probably want to use a stack structure, and you are welcome to use existing functions (push, pop) to do this. You should turn in your code and the results of a few tests ON PAPER. The assignment is quite easy (less than a page) so don't make it harder than it is. You should make your program graceful (errors handled in a reasonable way) and you can include division if you wish (but handle the special cases!). Your code must work to get points for the assignment-- what you do beyond that (thoroughness in coding and testing, presentation) determines how good your grade will be.


[ Back to CS451: Assigments ]