RosettaCodeData/Task/Parsing-RPN-calculator-algorithm/MiniScript/parsing-rpn-calculator-algorithm.mini
2023-07-01 13:44:08 -04:00

22 lines
633 B
Text

RPN = function(inputText)
tokens = inputText.split
stack = []
while tokens
tok = tokens.pull
if "+-*/^".indexOf(tok) != null then
b = stack.pop
a = stack.pop
if tok == "+" then stack.push a + b
if tok == "-" then stack.push a - b
if tok == "*" then stack.push a * b
if tok == "/" then stack.push a / b
if tok == "^" then stack.push a ^ b
else
stack.push val(tok)
end if
print tok + " --> " + stack
end while
return stack[0]
end function
print RPN("3 4 2 * 1 5 - 2 3 ^ ^ / +")