You are right dear Salvador if I want to access local variables but what I meant by this question a source code that simply can parse a string of function(s), operator(s) and constant(s) and then evaluate them
Mohamed, it depends on what you mean by "parse".. if you are into a compiled language then you can probably parse a C code but not to execute it, since you would need to compile that piece of code just "parsed" first. Think about a compiler program, for example GCC. If you look at the compiler source code you will find out that there is a parsing of the C code but of course it is not executed, but transformed into the binary format of the underlying operating system (i.e. it gets compiled). Only then, the code can be run, but that is another process.
Have a look at the Boost libraries, especially the Proto part: http://www.boost.org/doc/libs/1_64_0/doc/html/proto.html. It has an expression evaluator function eval().
Very interesting recommendations I have read on this thread. That of Petr points to interpret C++ on runtime, while that from Jan to a library for constructing your own interpreted language within a C++ program itself. After thinking on these solutions and the original question one might wonder then why the original program was written in C++. In my humble opinion something is wrong here, for if you are going to follow any of those paths you better rethink the original program and rewrite it on an interpreted language instead, in which native interpretation is natural with typical eval() functions implemented in those frameworks.
I agree with Salvador. But I have a system that already developed in C/C++ and I want to add a new module only to evaluate mathematical and logical expressions.
Mohamed, perhaps you should have told us before that you were going to evaluate mathematical expressions because when you mentioned an eval() like function one understand that you wanted a function for evaluating code in the same programming language. I don't know if you are aware of that.. eval() always evaluate code in the same programming language, and never something like a general math expression, even when some pieces of a programming language code might look like a math expression. for example, eval() in PHP cannot evaluate code in Perl, so to speak.. even less a general math expression.
However, if your expressions are limited to simple arithmetics and trigonometry, then you can try some simple solutions that are available for C++. For example this one:
http://partow.net/programming/exprtk/index.html
It's very simple to use since you only have to include a .h file and recompile your app.
EDITED: The latest version of this library allows even numeric integration! so it's not so basic at all, and most likely will cover all your needs.
For such evaluation, it seems usually better to write your own module rather than study why the one downloaded is not perfect and if possible, to work on overcoming the bugs. I assume it is your work, you know what you need so you know what and how to evaluate particular (those of your interest) mathematical models.