-
June 2nd, 2010, 04:05 PM
#1
Custom expression evaluator in C++
I am trying to make something which can load an expression with custom definitions to functions. An example what I would like:
Mouse.x() * 5
or
2+(Keyboard.A() * Object.Val(0))
mouse is an object and x is a function in that object to call. Functions may also have parameters of varying types and quantities.
I wish to run through the events frequently, so what I am looking for is a way to decode the expressions at run time and store it in a way that allows me to process them faster, without the need to parse each expression every time. Perhaps by somehow storing pointers to functions once they have been decoded?
I am finding this problem quite hard to resolve so help would be much appreciated
-
June 2nd, 2010, 04:41 PM
#2
Re: Custom expression evaluator in C++
Originally Posted by benb7760
I am trying to make something which can load an expression with custom definitions to functions. An example what I would like:
Mouse.x() * 5
or
2+(Keyboard.A() * Object.Val(0))
mouse is an object and x is a function in that object to call. Functions may also have parameters of varying types and quantities.
I wish to run through the events frequently, so what I am looking for is a way to decode the expressions at run time and store it in a way that allows me to process them faster, without the need to parse each expression every time. Perhaps by somehow storing pointers to functions once they have been decoded?
I am finding this problem quite hard to resolve so help would be much appreciated
I'm not sure I understand the problem. Is "Mouse.x() * 5" inside your code, or is it a string you would like to decode, as in "Hum, after parsing this string, it appears I need to calculate the value of 5 times the value of Mouse's function x"?
If it is the latter, well... This is a bit too open ended for me to give any real help.
I would say maybe you need to try the equivalent of stored procedures, except rather than targeting a DB, you move your mouse.
Is your question related to IO?
Read this C++ FAQ article at parashift by Marshall Cline. In particular points 1-6.
It will explain how to correctly deal with IO, how to validate input, and why you shouldn't count on "while(!in.eof())". And it always makes for excellent reading.
-
June 2nd, 2010, 06:19 PM
#3
Re: Custom expression evaluator in C++
Originally Posted by benb7760
I am finding this problem quite hard to resolve so help would be much appreciated
You're in the realms of compiler technology.
There are languages already which does what you want to do, like Ruby and Phyton. They're called scripting languages.
If you want to offer scripting capabilities in a C++ application of your own I suggest you look for some third party package. As you've already noticed it quite quickly gets exceedingly hard to implement it yourself.
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|