A Powerful Function Parser

CodeGuru content and product recommendations are editorially independent. We may make money when you click on links to our partners. Learn More.


The inspiration to write this code was to have an
easy-to-use parser for functions given as string. You have a string like


and you want to compute some values, maybe for displaying
the graph of the function. You can write code like this:

CFunction<long double>* fkt =
CFunction<long double>::Parse(“cos(x)-7*x/(1+x)”);

long double y = fkt->Execute(1.5);

There are lots of definitions in the background, but the
result is easy and fast! There is a one-time pasing step to construct the
function tree, and function evaluations are only calls of standard math
functions like sin, +, *, sqrt. When you want to know details about the
implementaion, you should look into the source code. It would be too complex to
describe the parsing algorithm here.


Download demo source – 50 Kb
Download demo application – 32 Kb

More by Author

Get the Free Newsletter!

Subscribe to Developer Insider for top news, trends & analysis

Must Read