Check the bsh.Interpreter class. The methods set(), unset() and eval() may help you.

2008/6/22 Brent Easton <>:

I am trying to work out the best way to integrate Beanshell into my application. I want to use Beanshell to add the ability to parse and evaluate arbitrarily complex expressions typed in by users.

For example

 20 * xpos + ypos/2

The expressions are entered and validated at one point of time, but are evaluated much later, in a different phase of operation of the program when xpos and ypos will have determinable values.

I have successfully used the Parser to parse and validate the structure of expression.

My problem is determining and binding values to the variables in the expression at runtime. The variables 'xpos' and 'ypos' (plus a host of other 'variables') are not predetermined at the time the expression is created.

At evaluation time, I need to determine what variables are used in the expression are undefined, then bind them to values from my application, evaluate the expression and then return the result to my application.

Any pointers would be appreciated.


Check out the new Marketplace.
It's the best place to buy or sell services for
just about anything Open Source.
Beanshell-users mailing list