On 18 Jul 2004 14:40:42 -0700,
kantas@ceid.upatras.gr (spiros) wrote:
[color=blue]
>Hi,
>
>suppose you have the class Class1 and the main program:
>
>class Class1
>{
>public:
> Class1();
> ~Class1();
>
>private:
> int a;
> int b;
>}
>
>void main()
>{
> Class1 cl = Class1();
>
> cl.a = 4;
> cl.b = 6;
>
> char str[] = "a>0 && b<5"
>}
>
>I want to check if the expression which is contained to the str[] is
>true or false.
>With other word i want to check the following:
>
>if (a>0 && b<5)
>{
> // do something
>}
>else
>{
> // do something else
>}
>
>the problem is that i have the expression in a string, how can i
>convert the content od the string to a expression and check if the
>expression is TRUE or FALSE?[/color]
If you need to evaluate the expressions at runtime, you'll have to
write a parser, which for full C++ functionality will require many
thousands of lines of code (or you could use a library like
boost.Spirit to reduce this substantially). A far better solution is
to use a scripting language that supports this kind of thing - I think
Python is a popular choice. Python and C++ play together quite well,
see
http://www.boost.org/libs/python/doc/index.html
Tom