Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

Welcome to the new platform of Programmer's Heaven! We apologize for the inconvenience caused, if you visited us from a broken link of the previous version. The main reason to move to a new platform is to provide more effective and collaborative experience to you all. Please feel free to experience the new platform and use its exciting features. Contact us for any issue that you need to get clarified. We are more than happy to help you.

Arrays of Pointers to Functions & Math

evdoxosevdoxos Posts: 1Member
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]

Comments

  • Malcolm_McLeanMalcolm_McLean Posts: 248Member ✭✭
    : 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]
    :
    :

Sign In or Register to comment.