A Powerful Function Parser
Posted
by Andreas Jdger
on March 1st, 2000
The inspiration to write this code was to have an easy-to-use parser for functions given as string. You have a string like
"cos(x)-7*x/(1+x)"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.
Downloads
Download demo source - 50 KbDownload demo application - 32 Kb

Comments
Just OK
Posted by Legacy on 01/14/2004 12:00amOriginally posted by: Gerhalt
very ok!
ReplyVery good, but ...
Posted by Legacy on 10/16/2003 12:00amOriginally posted by: Alexander Magola
My english is not good, but i want to say that this code is very good. I like idea of this author, but this code is not very fast. My own similar code is faster three times more than it. Although, my code is not fastest. ;)
ReplyBest regards.
How about adding new functions to this as plug-ins
Posted by Legacy on 07/03/2003 12:00amOriginally posted by: Harshdeep Singh
Great Job
ReplyI was thinking about giving option of adding new functions as plug-ins (dll?)
That would make it cooler.
And I would love to see an explanation of the code.
Harshdeep
Vergleich Fl�chenberechnungen
Posted by Legacy on 03/15/2003 12:00amOriginally posted by: Oswald Ruckriegel
Zun�chst: ein Spitzenprogramm. Meine Gratulation
Habe es in mein Programm (VC++5.0) eingebaut.
Stelle fest: am genauesten rechnet
1. Mittelpunktsregel
2. Integration mit Trapezregel
3. Simpson ( hier Abweichungen von 1) bis zu 10 %.
Beispiel: sin(x)/x ( f�r x= 0 bis x = 3)
nur 1) berechnet richtig, 2) und 3) keine Berechnung m�glich.
Warum ?
ReplyThe console app closes immediately
Posted by Legacy on 11/13/2002 12:00amOriginally posted by: The Big Cat
ReplyError using sqrt
Posted by Legacy on 09/04/2002 12:00amOriginally posted by: Holger
ReplyFound an error
Posted by Legacy on 08/20/2002 12:00amOriginally posted by: Lee
The expression: x^2+3x-5
was parsed to: x^2+3-5
Replyfew
Posted by Legacy on 07/10/2002 12:00amOriginally posted by: few
So fucking cool thing!
ReplyA Powerful Function Parser
Posted by Legacy on 04/10/2002 12:00amOriginally posted by: Nikhil
Impressive....but comments are not clear
Replyand extensive....Comments in English would be a definite help!!!
Very interesting
Posted by Legacy on 11/27/2001 12:00amOriginally posted by: Philippe Boucher
This is very interesting!
ReplyLoading, Please Wait ...