Arithmetic evaluation: Difference between revisions

m
→‎{{header|Phix}}: simplified popfactor
(→‎{{header|Tailspin}}: add directly calculated solution)
m (→‎{{header|Phix}}: simplified popfactor)
Line 4,520:
 
procedure PopFactor()
object p1, p2 = opstack[$]
if op="u-" then
endp1 if= 0
if op_p_p=1 then -- op_p_p
opstack[$] = {op,0,p2}
elsif op_p_p=0 then -- p_op_p
opstack[$] = {0,op,p2}
else -- -1 -- p_p_op
opstack[$] = {0,p2,op}
end if
else
opstack = opstack[1..$-1]
p1 = opstack[$] = {op,0,p2}
if op_p_p=1 then -- op_p_p
end if
opstack[$] = {op,opstack[$],p2}
elsifif op_p_p=01 then -- p_op_p
opstack[$] = {opstack[$],op,p1,p2} -- op_p_p
elsif op_p_p=0 then -- p_op_p
else -- -1 -- p_p_op
opstack[$] = {opstack[$]p1,op,p2,op} -- p_op_p
else -- end if-1
opstack[$] = {0p1,p2,op,p2} -- p_p_op
end if
op = 0
Line 4,665 ⟶ 4,660:
I added a flag (for this task) to store the ast nodes as op_p_p, p_op_p, or p_p_op, whichever you prefer.
{{out}}
For "3+4+5+6*7/1*5^2^3", the fully parenthesised Phix equivalent being ((3+4)+5)+(((6*7)/1)*power(5,power(2,3)))
<pre>
with op_p_p:
7,796

edits