So, if you have log max(1, 2, 3, 4, 5) , you will do:
log => push sin to stack max => push max to stack ( => push ( to stack 1 => push 1 to stack , => pop top of stack to output => pop 1 to output 2 => push 2 to stack , => pop 2 to output ... => end result: 1 2 3 4 5 max log
The problem is that you do not know how many arguments max belongs to and how many - log (the logarithm may or may not accept the base as an argument).
Using the wikipedia description, it should be possible to read each function argument separator (comma): if you have k function separators, then you have k + 1 arguments, so you can print 1 2 3 4 5 max_5 log above. Be careful to have different values ββin case of nested functions:
max(1, 2, log(3, 4), 5) => 1 2 3 4 log_2 5 max_4 --------- max has 4 arguments after evaluating log_2(3, 4)
You have one account for the max token, and another for the log function. You need to keep track of the counter for the highest function token in your stack, but also for all the other function tokens in your stack, as you can eventually resume them.
Ivlad source share