How to execute / evaluate a string expression? (from newbie)

M

Marco Traverso

Hi all,

Is there a function to evaluate a string expression?
InVisual Basic and VbScript there is the Execute command that does this job.

For example:

Dim a,x
a=100
Execute "x = a/2"

Now the x value is 50...

Is there anything of this kind in C++/Visual C++ ?
Or do I need an external math parser or function?

Thank you in advance,

Marco
 
G

Grant Austin

Dim a,x
a=100
Execute "x = a/2"

Now the x value is 50...

Is there anything of this kind in C++/Visual C++ ?
Or do I need an external math parser or function?

I don't believe there is a way to execute strings unless someone has
developed an additional library to do such. I suppose you could always
write/use a lexical analyzer or a lot of string functions to do the parsing.

Unless you're expecting the user to type in expressions, the 'normal' way
is to do something like this:

void somefun(){
...
...
...
int a,x;
a = 100;
x = a/2;
/*
if you have stdio or iostream #include'd output by
printf("x = %d",x); or cout << "x = " << x; respectively
*/
}

I hope that helps,
Grant
 
M

Marco Traverso

Hi Grant,
Unless you're expecting the user to type in expressions, the 'normal' way
is to do something like this:

Unfortunately I need just that! Anyway, since I'm writing a plug-in for an
app that includes vbscript, I will launch a little script with the execute
command and then take back the result into C++.

Thank you for the clarification! :)

Regards,

Marco
 
G

Grant Austin

A possible solution occurred to me. You can embed TCL into any c/c++
program. This might allow you to evaluate the expressions you need.

There might be other scripting languages in that direction as well.

-Grant
 
M

Marco Traverso

Hi Grant,

Even if it is not so clear to me (I'm a VC++ newvie, see subject ;-)),
anyway I'll go through that!

Thanks again!

Marco
 
G

Gianni Mariani

Marco said:
Hi Grant,

Even if it is not so clear to me (I'm a VC++ newvie, see subject ;-)),
anyway I'll go through that!

There exist a number of interpreters that are embeddable in C++.

TCL is but one.
 
L

lallous

Marco Traverso said:
Hi Grant,

Even if it is not so clear to me (I'm a VC++ newvie, see subject ;-)),
anyway I'll go through that!

Thanks again!

Marco

Guess you can use VBScript/Scripting engine from your win32 app.
Try asking your question in one of Microsoft's programming / scripting
newsgroup.

Regards,
Elias
 
M

Marco Traverso

Thany you all!

I think I've found a solution with the winapp vbscript engine!

Regards,

Marco
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,755
Messages
2,569,534
Members
45,007
Latest member
obedient dusk

Latest Threads

Top