Click here to Skip to main content
Licence 
First Posted 22 Feb 2000
Views 110,403
Bookmarked 52 times

A powerful function parser

By | 22 Feb 2000 | Article
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

    About the Author

    Andreas Jäger

    Web Developer

    Germany Germany

    Member



    Sign Up to vote   Poor Excellent
    Add a reason or comment to your vote: x
    Votes of 3 or less require a comment

    Comments and Discussions

     
    You must Sign In to use this message board. (secure sign-in)
     
    Search this forum  
     FAQ
        Noise  Layout  Per page   
      Refresh
    GeneralMFC compile PinmemberLuke Murphey9:28 6 Jul '02  
    GeneralRe: MFC compile PinmemberlLukeMurphey6:56 8 Jul '02  
    GeneralA version without MFC / MS dependencies PinmemberJochenKa20:23 14 Feb '02  
    GeneralRe: A version without MFC / MS dependencies Pinmemberjean-luc adam1:50 19 Feb '02  
    GeneralRe: A version without MFC / MS dependencies PinmemberJochen Kalmbach19:31 29 Jan '04  
    GeneralRe: A version without MFC / MS dependencies PinmemberPhilippe Lhoste2:25 4 Dec '04  
    GeneralRe: A version without MFC / MS dependencies PinmemberJochen Kalmbach [MVP VC++]19:58 1 Jan '06  
    Generalmore General expression PinmemberJie Luo1:56 16 Jan '02  
    GeneralWorld peace PinmemberBartosz Bien13:14 14 Dec '01  
    GeneralTo B.Starks, W.Dean, & J.Andreas PinmemberAmit Gefen12:43 8 Nov '01  
    GeneralOperators/precedence/types etc PinmemberAndrew Phillips18:04 26 Sep '01  
    GeneralVery good success with this PinmemberJeff8:59 12 May '01  
    GeneralYou must read jeff's reply..!! then you will success PinmemberJsSong14:47 25 Mar '02  
    GeneralBugs etc below should be renamed to Dean Wyant knows little about programming. PinmemberB. Starks7:36 13 Apr '01  
    GeneralRe: Bugs etc below should be renamed to Dean Wyant knows little about programming. PinmemberDean Wyant10:11 30 Apr '04  
    GeneralA good Parser Pinmemberstocklab17:57 18 Jan '01  
    GeneralRe: A good Parser PinmemberPing He23:36 9 May '01  
    GeneralRe: A good Parser PinmemberMathePeter3:22 3 Jul '07  
    GeneralDoes not understand decimals PinsussAnonymous4:55 3 Nov '00  
    QuestionBugs etc. - How does it deserve such high ratings? PinsussDean Wyant13:59 23 May '00  
    QuestionEnglish translation of comments? PinsussPeter Helmers4:03 10 Apr '00  
    GeneralFunctionParser PinsussArmin Zürcher1:57 12 Mar '00  

    General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    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 | Mobile
    Web04 | 2.5.120517.1 | Last Updated 23 Feb 2000
    Article Copyright 2000 by Andreas Jäger
    Everything else Copyright © CodeProject, 1999-2012
    Terms of Use
    Layout: fixed | fluid