I'm currently working on a math evaluator, which works by converting the infix notation to postfix notation and then evaluating the postfix expression. It was going pretty good, until I ran into the problem of unary operations and having functions accepting an infinite amount of parameters.
Say (infix notation): $$1+2*3$$
Which of course would be (postfix notation): $$1\enspace 2\enspace 3 * +$$
But how would we go about representing unary operations. Like $$4!$$ or $$-4$$ or $$not\enspace true$$
Further what about functions $sqrt(9)$ would be easy, as we know $sqrt$ only needs a single parameter. But what if the function accepts an arbitrary amount of parameters.
Thereby both (infix notation): $$f(1, 2) + 3$$ and $$1 * f(2) + 3$$
Would result in (postfix notation):
$$1\enspace 2\enspace f\enspace 3\enspace+$$
$$1\enspace 2\enspace f\enspace *\enspace 3\enspace +$$
My previous assumption here being that the function could just eat all the previous numbers, but that clearly isn't going to work...
One way to handle functions which take an arbitrary number of parameters is to introduce an additional "wall" token, such as "|". The wall would be entered to the left of the leftmost parameter of the function. When the function is encountered, it consumes all the parameters back to the wall. Later operators would consume any parameters before the wall. For example,
$$f(1,2) + 3 \longrightarrow |\ 1\ 2\ f\ 3\ +$$ $$1*f(2)+3 \longrightarrow 1\ |\ 2\ f\ *\ 3\ +$$ $$6 * (5 - f(4,3,2))+1 \longrightarrow 6\ 5\ |\ 4\ 3\ 2\ f\ -\ *\ 1\ +$$
If you don't want to denote unary negation by a different token than subtraction, then you could consider "$-$" to be a function that takes one or two parameters, and therefore needs a wall to differentiate:
$$1+2-(-3) \longrightarrow 1\ |\ 2\ |\ 3\ -\ -\ +$$
An alternate approach would be to preceed the function with an additional parameter, which would be the count of how many other parameters are consumed by the function:
$$f(1,2) + 3 \longrightarrow 1\ 2\ 2\ f\ 3\ +$$ $$1*f(2)+3 \longrightarrow 1\ 2\ 1\ f\ *\ 3\ +$$ $$6 * (5 - f(4,3,2))+1 \longrightarrow 6\ 5\ 4\ 3\ 2\ 3\ f\ -\ *\ 1\ +$$
$$1+2-(-3) \longrightarrow 1\ 2\ 3\ 1\ -\ 2\ -\ +$$