Re: Using Beanshell as an expression evaluator
Alexey Zinger <inline_four-/[email protected]> Mon, 23 Jun 2008 09:56:22 -0700 (PDT)
| Newsgroups | gmane.comp.java.beanshell.user |
|---|---|
| Message-ID | <[email protected]> |
Is there a reason you couldn't use your extended NameSpace object at runtime to check for any unretrieved variables? I'm not familiar with your project's specifics, but I can't imagine any reason you couldn't do this. Is there something your application knows at expression "compile" time it doesn't know at "run" time? Alexey 2001 Honda CBR600F4i (CCS) 1992 Kawasaki EX500 http://azinger.blogspot.com http://bsheet.sourceforge.net http://wcollage.sourceforge.net --- On Mon, 6/23/08, Brent Easton <[email protected]> wrote: > From: Brent Easton <[email protected]> > Subject: Re: [Beanshell-users] Using Beanshell as an expression evaluator > To: "Stewart Cambridge" <[email protected]> > Cc: beanshell-users-5NWGOfrQmneRv+LV9MX5uipxlwaOVQ5f@public.gmane.org > Date: Monday, June 23, 2008, 6:34 AM > Thanks Stewart, > > I was aware of those, but the problem is how do you find > out which variables are undefined and need to be set? The > set of variables available is not canonical. > > I have got something working by subclassing NameSpace with > a custom getVariableImpl implementation that builds a list > of undefined variables. When an expression is created, I do > a test evaluation and record the list of undefined > variables. When the expression is to be evaluated for real, > I use bind the known undefined variables to the current > property values. > This seems to be working fine for the limited use of > evaluating a single expression. My next task is to > implement a more general script object. What I really need > to work out is how to dynamically reference property values > in my main application from within beanscript. Slowly > getting there. > Regards, > Brent. > > *********** REPLY SEPARATOR *********** > > On 23/06/2008 at 11:21 AM Stewart Cambridge wrote: > > Check the bsh.Interpreter class. The methods set(), unset() > and eval() may help you. > > > > 2008/6/22 Brent Easton <[email protected]>: > > > 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. > > Regards, > Brent. > > > > > > > > ------------------------------------------------------------------------- > Check out the new SourceForge.net Marketplace. > It's the best place to buy or sell services for > just about anything Open Source. > http://sourceforge.net/services/buy/index.php > _______________________________________________ > Beanshell-users mailing list > Beanshell-users-5NWGOfrQmneRv+LV9MX5uipxlwaOVQ5f@public.gmane.org > https://lists.sourceforge.net/lists/listinfo/beanshell-users > ____________________________________________________________ > Brent Easton > Analyst/Programmer > University of Western Sydney > Email: > b.easton-w6+s2I0VQzVMskiN7EVSyPj1EjU76Jnw+PUSNTvomfD49RI1O+iZ8Pj1EjU76Jnw+PUSNTvomfD49RI1O+iZ8Pj1EjU76Jnw+PUSNTvomfCeHx0PihYX5Q==@public.gmane.org > Check out the new SourceForge.net Marketplace. > It's the best place to buy or sell services for > just about anything Open Source. > http://sourceforge.net/services/buy/index.php_______________________________________________ > Beanshell-users mailing list > Beanshell-users-5NWGOfrQmneRv+LV9MX5uipxlwaOVQ5f@public.gmane.org > https://lists.sourceforge.net/lists/listinfo/beanshell-users ------------------------------------------------------------------------- Check out the new SourceForge.net Marketplace. It's the best place to buy or sell services for just about anything Open Source. http://sourceforge.net/services/buy/index.php