Here's a somewhat cleaned up and somewhat better tested version that handles infinite nesting, four levels of presecence etc.
It also has a rpn2exp() routine that reverses the process that adds full parenthesis to show the effect of the precedence.
Tests
P:\test>423305
Func_1(1,Func_2(Func3(1+2*3)*aFunc(3))+FuNc(4,5,6),-2,e,-10,2e10)+1
1, 1, 2, 3, *, +, 1, Func3(), 3, 1, aFunc(), *, 1, Func_2(), 4, 5, 6,
+3, FuNc(), +, -2, e, -10, 2e10, 6, Func_1(), 1, +
( Func_1( 1, ( Func_2( ( Func3( ( 1 + ( 2 * 3 ) ) ) * aFunc( 3 ) ) ) +
+ FuNc( 4, 5, 6 ) ), -2, e, -10, 2e10 ) + 1 )
func(1,2+3*4/5**6,7/8)
1, 2, 3, 4, *, 5, 6, **, /, +, 7, 8, /, 3, func()
func( 1, ( 2 + ( ( 3 * 4 ) / ( 5 ** 6 ) ) ), ( 7 / 8 ) )
a+b*c/2
a, b, c, *, 2, /, +
( a + ( ( b * c ) / 2 ) )
abc+def+Efg_hij
abc, def, +, Efg_hij, +
( ( abc + def ) + Efg_hij )
2.0+1e-2/0.01E-21
2.0, 1e-2, 0.01E-21, /, +
( 2.0 + ( 1e-2 / 0.01E-21 ) )
max(a,b,c,d)*atan(pi*4,-1)
a, b, c, d, 4, max(), pi, 4, *, -1, 2, atan(), *
( max( a, b, c, d ) * atan( ( pi * 4 ), -1 ) )
sin(cos(x)-tan(y))+f(g(z))
x, 1, cos(), y, 1, tan(), -, 1, sin(), z, 1, g(), 1, f(), +
( sin( ( cos( x ) - tan( y ) ) ) + f( g( z ) ) )
2*(somevar+other)+max(this,that)
2, somevar, other, +, *, this, that, 2, max(), +
( ( 2 * ( somevar + other ) ) + max( this, that ) )
A+(B*C-D)/E
A, B, C, *, D, -, E, /, +
( A + ( ( ( B * C ) - D ) / E ) )
(a*(b)-c**(3.4e-2))
a, b, *, c, 3.4e-2, **, -
( ( a * b ) - ( c ** 3.4e-2 ) )
5**((-2e-3+x)*sin(p+4.0)/fred)
5, -2e-3, x, +, p, 4.0, +, 1, sin(), *, fred, /, **
( 5 ** ( ( ( -2e-3 + x ) * sin( ( p + 4.0 ) ) ) / fred ) )
sin(a)+sin(ab)+sin(a,b)
a, 1, sin(), ab, 1, sin(), +, a, b, 2, sin(), +
( ( sin( a ) + sin( ab ) ) + sin( a, b ) )
Func_2(Func3(1*2*3)*aFunc(3))+FuNc(4,5,6)
1, 2, *, 3, *, 1, Func3(), 3, 1, aFunc(), *, 1, Func_2(), 4, 5, 6, 3,
+FuNc(), +
( Func_2( ( Func3( ( ( 1 * 2 ) * 3 ) ) * aFunc( 3 ) ) ) + FuNc( 4, 5,
+6 ) )
func(1,2+3*4/5**6,7/8)
1, 2, 3, 4, *, 5, 6, **, /, +, 7, 8, /, 3, func()
func( 1, ( 2 + ( ( 3 * 4 ) / ( 5 ** 6 ) ) ), ( 7 / 8 ) )
Func_1(1,xx,-2,e,-10,-2e-10)+1
1, xx, -2, e, -10, -2e-10, 6, Func_1(), 1, +
( Func_1( 1, xx, -2, e, -10, -2e-10 ) + 1 )
Examine what is said, not who speaks.
Silence betokens consent.
Love the truth but pardon error.
|