[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: BeanShell : Separating parsing from evaluation



On Mon, Nov 15, 1999 at 11:52:19AM +0100, Rémi Bastide wrote:
> Hi Pat,
> 
> Thanks for your continuous improvement of BeanShell, which has become a very
> important piece of our research product.
> 
> I wonder of difficult it would be to separate in BeanShell the parsing of an
> expression from its evaluation. This would be very valuable in our app,
> where an expression is entered once by the user, and then evaluated a number
> of times.
> 
> I dream to be able to do this :
> 
> bsh.Interpreter i = ...
> String anExpression = ...
> ParsedExpression e; // Opaque class to represent an evaluable expression
> pre-parsed by BeanShell
> 
> try {
> 	e = i.parse(anExpression);
> } catch (bsh.ParseError e) {
> 	// The expression is syntaxically incorrect
> 	return false;
> }

I believe this is exactly what is accomplished by evaluating the method
delcaration in the interpreter.. and then later using that interpreter to
invoke the method with arguments...

e.g.
    interpreter.eval("foo(a,b) { ... } ");
    // later
    interpreter.eval("foo(1,2)");

The internal form of the parsed method is a BSHMethodDeclaration node, not
the original text.

Variable resolution from the enclosing context (probably the root interpreter
context in your case) will happen at invocation time.

Does this make sense?  Or am I missing your point.


Pat