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
Re: Custom expression evaluator in C++
Quote:
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.
Re: Custom expression evaluator in C++
Quote:
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.