CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 3 of 3
  1. #1
    Join Date
    Nov 2010
    Posts
    105

    Question Existing code for String to Expression?

    I would like to get hold of the code for a function that takes a string as input argument and returns a numerical value, either integer or double, according to the the expression represented by the string. For example the string may look like this:
    Code:
    "(256 * d3 + d4) * factor - offset"
    then the function would calculate the value of
    Code:
    (256 * d[3] + d[4]) * factor - offset
    where d is an integer array, factor and offset are double or int variables or constants. For my application the name for the array can be fixed to be "d", and the names for other variables and constants are known. The closest thing I could find on-line is this:
    http://www.physicsforums.com/showpos...2&postcount=11
    which only does literal integer calculations, no double, no variables or constants. Are there existing code that does what I need or do I have to write my own? Thanks!

  2. #2
    Join Date
    Mar 2004
    Location
    Central Florida
    Posts
    293

    Re: Existing code for String to Expression?

    This is probably what you are looking for.

    http://www.codeproject.com/Articles/...Formula-Parser
    "Effective teaching is the essence of leadership..."

    "There is no substitute for a carefully thought-out design."

    If you have found this post to be useful, please Rate it.

  3. #3
    Join Date
    Nov 2010
    Posts
    105

    Re: Existing code for String to Expression?

    Quote Originally Posted by mlgoff View Post
    This is probably what you are looking for.

    http://www.codeproject.com/Articles/...Formula-Parser
    Thanks for the quick reply but the link is for C#, not C++?

    Edit: I found this:
    http://www.codeproject.com/Articles/...essions-Parser

    Thanks again!

    Edit: and this:
    http://code.google.com/p/muparserx/
    Last edited by acppdummy; April 17th, 2012 at 11:02 AM.

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