23 lines
633 B
Plaintext
23 lines
633 B
Plaintext
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 ^ ^ / +")
|