Click here to Skip to main content
12,820,521 members (30,238 online)
Click here to Skip to main content
Add your own
alternative version

Stats

127.3K views
2K downloads
59 bookmarked
Posted 22 Feb 2000

A powerful function parser

, 22 Feb 2000
Rate this:
Please Sign up or sign in to vote.
A simple yet powerful function parser that parses and evaluates standard mathematical functions
  • Download source files - 82 Kb
  • 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.

    License

    This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

    A list of licenses authors might use can be found here

    Share

    About the Author

    Andreas Jäger
    Web Developer
    Germany Germany
    No Biography provided

    You may also be interested in...

    Comments and Discussions

     
    GeneralMFC compile Pin
    Luke Murphey6-Jul-02 10:28
    memberLuke Murphey6-Jul-02 10:28 
    GeneralRe: MFC compile Pin
    lLukeMurphey8-Jul-02 7:56
    memberlLukeMurphey8-Jul-02 7:56 
    GeneralA version without MFC / MS dependencies Pin
    JochenKa14-Feb-02 21:23
    memberJochenKa14-Feb-02 21:23 
    GeneralRe: A version without MFC / MS dependencies Pin
    jean-luc adam19-Feb-02 2:50
    memberjean-luc adam19-Feb-02 2:50 
    GeneralRe: A version without MFC / MS dependencies Pin
    Jochen Kalmbach29-Jan-04 20:31
    memberJochen Kalmbach29-Jan-04 20:31 
    GeneralRe: A version without MFC / MS dependencies Pin
    Philippe Lhoste4-Dec-04 3:25
    memberPhilippe Lhoste4-Dec-04 3:25 
    GeneralRe: A version without MFC / MS dependencies Pin
    Jochen Kalmbach [MVP VC++]1-Jan-06 20:58
    memberJochen Kalmbach [MVP VC++]1-Jan-06 20:58 
    GeneralRe: A version without MFC / MS dependencies Pin
    Member 190613125-Jul-13 14:18
    memberMember 190613125-Jul-13 14:18 
    Generalmore General expression Pin
    Jie Luo16-Jan-02 2:56
    memberJie Luo16-Jan-02 2:56 
    GeneralWorld peace Pin
    Bartosz Bien14-Dec-01 14:14
    memberBartosz Bien14-Dec-01 14:14 
    GeneralTo B.Starks, W.Dean, & J.Andreas Pin
    Amit Gefen8-Nov-01 13:43
    memberAmit Gefen8-Nov-01 13:43 
    GeneralOperators/precedence/types etc Pin
    Andrew Phillips26-Sep-01 19:04
    memberAndrew Phillips26-Sep-01 19:04 
    GeneralVery good success with this Pin
    Jeff12-May-01 9:59
    memberJeff12-May-01 9:59 
    GeneralYou must read jeff's reply..!! then you will success Pin
    JsSong25-Mar-02 15:47
    memberJsSong25-Mar-02 15:47 
    GeneralBugs etc below should be renamed to Dean Wyant knows little about programming. Pin
    B. Starks13-Apr-01 8:36
    memberB. Starks13-Apr-01 8:36 
    GeneralRe: Bugs etc below should be renamed to Dean Wyant knows little about programming. Pin
    Dean Wyant30-Apr-04 11:11
    memberDean Wyant30-Apr-04 11:11 
    I'm sorry. No one bothered to reply to my message, including you. You created a new message so I was never informed of your reply. Just like an idiot... flame away clown boy..... Perhaps my programming standards are higher than yours.
    My opinion remains = There is no support for the issues in using this parser - even you would not directly reply to a posted message here. It does not handle parens properly, decimals, and several other issues. You are correct about the locale and partially correct about the std:cin. The part about me was way off base.
    As I stated in my message - my message was not meant to be mean or degrading. Obviously, it came across to you as "railing" the author.

    Yes, I was ignorant for not noticing the , problem was a locale issue. And, my message could have been written as questions instead of statements about how it did not work. I am glad that some people are willing to share anything at all. My bad.

    Hmm, what has B. Stark shared?

    Perhaps this code is wonderful? How about an update from you or the author or anyone to show how wonderful it is. I am sure that a decent test interface that will accept string input properly, some bug fixes, and a little documentation would be very helpful. I could care less, I am too busy making money using my programming skills to mess with this code.

    D'Oh! | :doh:
    GeneralA good Parser Pin
    stocklab18-Jan-01 18:57
    memberstocklab18-Jan-01 18:57 
    GeneralRe: A good Parser Pin
    Ping He10-May-01 0:36
    memberPing He10-May-01 0:36 
    GeneralRe: A good Parser Pin
    MathePeter3-Jul-07 4:22
    memberMathePeter3-Jul-07 4:22 
    GeneralDoes not understand decimals Pin
    Anonymous3-Nov-00 5:55
    sussAnonymous3-Nov-00 5:55 
    QuestionBugs etc. - How does it deserve such high ratings? Pin
    Dean Wyant23-May-00 14:59
    sussDean Wyant23-May-00 14:59 
    QuestionEnglish translation of comments? Pin
    Peter Helmers10-Apr-00 5:03
    sussPeter Helmers10-Apr-00 5:03 
    GeneralFunctionParser Pin
    Armin Zürcher12-Mar-00 2:57
    sussArmin Zürcher12-Mar-00 2:57 

    General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

    Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

    Permalink | Advertise | Privacy | Terms of Use | Mobile
    Web01 | 2.8.170308.1 | Last Updated 23 Feb 2000
    Article Copyright 2000 by Andreas Jäger
    Everything else Copyright © CodeProject, 1999-2017
    Layout: fixed | fluid