The Wayback Machine - https://web.archive.org/web/20091009185744/http://www.codeguru.com:80/cpp/cpp/cpp_mfc/article.php/c4073

CodeGuru
Earthweb Search
Login Forums Wireless Jars Gamelan Developer.com
CodeGuru Navigation
RSS Feeds

RSSAll

RSSVC++/C++

RSS.NET/C#

RSSVB

See more EarthWeb Network feeds

follow us on Twitter

Member Sign In
User ID:
Password:
Remember Me:
Forgot Password?
Not a member?
Click here for more information and to register.

jobs.internet.com

internet.commerce
Partners & Affiliates
















Home >> Visual C++ / C++ >> C++ >> C++ & MFC


A Powerful Function Parser
Rating:

Andreas Jdger (view profile)
March 1, 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 Kb
Download demo application - 32 Kb

Tools:
Add www.codeguru.com to your favorites
Add www.codeguru.com to your browser search box
IE 7 | Firefox 2.0 | Firefox 1.5.x
Receive news via our XML/RSS feed







RATE THIS ARTICLE:   Excellent  Very Good  Average  Below Average  Poor  

(You must be signed in to rank an article. Not a member? Click here to register)

Latest Comments:
Just OK - Legacy CodeGuru (01/14/2004)
Very good, but ... - Legacy CodeGuru (10/16/2003)
How about adding new functions to this as plug-ins - Legacy CodeGuru (07/03/2003)
Vergleich Flachenberechnungen - Legacy CodeGuru (03/15/2003)
The console app closes immediately - Legacy CodeGuru (11/13/2002)

View All Comments
Add a Comment:
Title:
Comment:
Pre-Formatted: Check this if you want the text to display with the formatting as typed (good for source code)



(You must be signed in to comment on an article. Not a member? Click here to register)

internet.commediabistro.comJusttechjobs.comGraphics.com

WebMediaBrands Corporate Info

Legal Notices, Licensing, Reprints, Permissions, Privacy Policy.
Advertise | Newsletters | Shopping | E-mail Offers | Freelance Jobs