# Arrays of Pointers to Functions & Math

Let's say we have:

some functions f1, f2, ..., fn (like sin, cos, tan etc.)

a number like 5 (or a variable like x).

and the array char* a[] = { 'f1', '(', 'f2', '(', ..., '(', 'fn', '(', '5', ')', ')', ..., ')', ')' } .

I want to calculate the f1(f2(...(fn(5))...)) .

I know how to do this with RPN and stacks (even using arrays of pointers to functions), but I'm looking for the fastest way (and I believe this is using arrays of pointers to functions and WITHOUT using RPN and stacks)
[italic](I have the ability to include brackets [] where needed in the array)[/italic]

• : Let's say we have:
:
: some functions f1, f2, ..., fn (like sin, cos, tan etc.)
:
: a number like 5 (or a variable like x).
:
: and the array char* a[] = { 'f1', '(', 'f2', '(', ..., '(', 'fn',
: '(', '5', ')', ')', ..., ')', ')' } .
:
: I want to calculate the f1(f2(...(fn(5))...)) .
:
: I know how to do this with RPN and stacks (even using arrays of
: pointers to functions), but I'm looking for the fastest way (and I
: believe this is using arrays of pointers to functions and WITHOUT
: using RPN and stacks)
:
Check the MiniBasic section of my website for information on how to write a recursive descent parser. There's also a printed book.

As for the question itself, it's not easy to answer. Lots of work has been done on optimising compilers, but mainly the focus is in optimising the output rather than the parse speed. If you know that your input has certain characteristics, like being simply nested, you can take shortcuts to speed things up, but it is questionable how worthwhile these will be.

: [italic](I have the ability to include brackets [] where needed in
: the array)[/italic]
:
: