refactor away local result variable

This commit is contained in:
2025-09-18 06:25:01 +02:00
parent 08fb5daf0d
commit 234cd321ea

View File

@@ -27,24 +27,23 @@ local
[] number(N)|Tail then
{InterpretAux Tail N|Stack}
[] operator(type:Op)|Tail then
case Stack of
Y|X|StackTail then
local Result in case Op
of plus then Result = X + Y
[] minus then Result = X - Y
[] multiply then Result = X * Y
[] divide then Result = X div Y
else raise unexpectedOperator end end
{InterpretAux Tail Result|StackTail}
end
else raise stackUnderflow end end
case Stack of Y|X|StackTail then
{InterpretAux Tail (case Op
of plus then X + Y
[] minus then X - Y
[] multiply then X * Y
[] divide then X div Y
else raise unexpectedOperator end end
)|StackTail}
else raise stackUnderflow end end
[] unary(type:Op)|Tail then
case Stack of
X|StackTail then case Op
of duplicate then {InterpretAux Tail X|Stack}
[] negate then {InterpretAux Tail (~X)|StackTail}
else raise unexpectedOperator end end
else raise stackUnderflow end end
case Stack of X|StackTail then
{InterpretAux Tail (case Op
of duplicate then X|Stack
[] negate then (~X)|StackTail
else raise unexpectedOperator end end
)}
else raise stackUnderflow end end
[] command(print)|Tail then
{Show Stack}
{InterpretAux Tail Stack}
@@ -56,5 +55,5 @@ local
fun {Interpret Tokens}
{InterpretAux Tokens nil}
end
{Show {Interpret {Tokenize {Lex "4 d * i c"}}}}
{Show {Interpret {Tokenize {Lex "4 2 /"}}}}
end