HELP HELP postfix calculator that takes postfix expressions

Discussion of Common Lisp
Post Reply
mikede

HELP HELP postfix calculator that takes postfix expressions

Post by mikede » Tue May 12, 2009 12:56 pm

greetings everyone ,

i have a big problem with this lisp programming , so , badly i need you all your help since i have hand this over in 7 hrs from now , i cant really do it , i tried but still with no hope . the question is

****************************************************************************************************************************
Write in Lisp a postfix calculator that takes postfix expressions involving
the +,-, and * binary operators. Fix the calculator to accept only 5 elements
(2 functions and 3 operands) with fixed position: (first, second and fifth element are
numbers, third and fifth are functions). For example.
(2 3 + 4 -) evaluates to 1

must generate either the infix or prefix translated string, with parentheses.


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.

****************************************************************************************************************************

i really tried to do my best but i don't have a great knowledge about it ..

i would greatly appreciate your help...


thank you soo much

regards ,
mike

qbg
Posts: 64
Joined: Mon Jun 30, 2008 1:05 pm
Location: Minnesota

Re: HELP HELP postfix calculator that takes postfix expressions

Post by qbg » Wed May 13, 2009 9:40 am

For the calculations, implement at stack machine. Numbers are pushed on the stack, operations pop their arguments and push their result.

For the translation, do the same thing but make the operators push the resulting list instead.

Post Reply