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
opstack[$] = {op,0,p2}▼
elsif op_p_p=0 then -- p_op_p▼
opstack[$] = {0,op,p2}▼
▲ end if
else
opstack = opstack[1..$-1]
end if
else --
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:
|