This is a read-only archive of lispforum.com. The forum was locked to new users and posts and is preserved here as static HTML from a database snapshot taken on 2019-09-07.

HELP HELP postfix calculator that takes postfix expressions

2 posts · 1561 views

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

Re: HELP HELP postfix calculator that takes postfix expressions

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.