CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 5 of 5
  1. #1
    Join Date
    Mar 2012
    Posts
    2

    How can an application execute a mathematical formula edited in an Edit

    Hello every one
    I am so tired about this problem. Please can someone help me.
    In my application I need perform a procedure which can read a mathematical formula form an Edit and execute it. The problem is how can I convert this string to a real function
    Thank you

  2. #2
    Join Date
    Jul 2005
    Location
    Netherlands
    Posts
    2,042

    Re: How can an application execute a mathematical formula edited in an Edit

    Quote Originally Posted by nunca View Post
    In my application I need perform a procedure which can read a mathematical formula form an Edit and execute it. The problem is how can I convert this string to a real function
    You cannot convert it to a C++ function, because those only exist at compile time, not in run-time.
    What you can do is implement a parser that can interpret the formula and either calculate the result directly or produce a bunch of objects that can calculate the result. Read up on recursive descent parsers to learn more. You could also try to use a library such as Boost Spirit to build the parser.
    Cheers, D Drmmr

    Please put [code][/code] tags around your code to preserve indentation and make it more readable.

    As long as man ascribes to himself what is merely a posibility, he will not work for the attainment of it. - P. D. Ouspensky

  3. #3
    Join Date
    Nov 2002
    Location
    California
    Posts
    4,556

    Re: How can an application execute a mathematical formula edited in an Edit

    For parsing a string in an attempt to interpret it as a function, the following article might give you some ideas: "Symbolic Differentiation" By Hatem Mostafa at http://www.codeproject.com/Articles/...ifferentiation

    It's not easy to do.

    Mike

  4. #4
    Join Date
    May 2002
    Posts
    1,798

    Re: How can an application execute a mathematical formula edited in an Edit

    Check this out.

    http://www.codeproject.com/Articles/...essions-Parser

    I've used it and it is quite useful for the purpose that you have stated.
    mpliam

  5. #5
    Join Date
    Nov 2002
    Location
    California
    Posts
    4,556

    Re: How can an application execute a mathematical formula edited in an Edit

    @Mike, nice find.

    @OP, here is another one at that site: "An extensible math expression parser with plug-ins" by Mathieu Jacques at http://www.codeproject.com/Articles/...-with-plug-ins

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured