Evaluating code passed by argument?
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 3 of 3

Thread: Evaluating code passed by argument?

  1. #1
    Join Date
    Jul 2009
    Posts
    1

    Exclamation Evaluating code passed by argument?

    In a small DLL I'm working on, I need a way for the user to enter a functional definition, which is then passed to my function as an argument (PCHAR), and have this evaluated.

    For example, if my function is defined thus:

    double eval(PCHAR func,PCHAR vari,double val) { }

    And the user calls it thus:

    eval("3x+5","x",5)

    It will return 20, as 3x+5=20 when x=5.

    This is similar to Javascript's eval() function, but as C++ is nothing like Javascript, I doubt it'll be so easy.

    Is there any way to do this? I need the user to be able to pass their custom functions to the DLL for evaluation.

    If it matters, due to compatibility constraints, only PCHARs and doubles may be passed as arguments or returned, though anything goes within a function.

    -IMP

  2. #2
    Join Date
    May 2007
    Location
    Scotland
    Posts
    1,121

    Re: Evaluating code passed by argument?

    It can be done, but you will need to write code to interpret the data (I would look at using stringstream to do the coversions from string to double.

  3. #3
    Join Date
    Oct 2006
    Posts
    616

    Re: Evaluating code passed by argument?

    You can have a look at this example for math parser.
    It's not C++, but you can easily rewrite it in C++.

    Regards,
    Zachm

Tags for this Thread

Posting Permissions

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


Azure Activities Information Page

Windows Mobile Development Center


Click Here to Expand Forum to Full Width

This is a CodeGuru survey question.


Featured


HTML5 Development Center