    All Packages  Class Hierarchy  This Package  Previous  Next  Index

# Class gnu.jel.Evaluator

    java.lang.Object
       |
       +----gnu.jel.Evaluator

public class Evaluator
extends Object

This is the main front end to JEL.

It is intended for compilation of algebraic expressions, involving functions.

Syntax supports variables, which are, in fact, functions with no arguments. If You define such function in the static library -- it is a constant (and will be substituted into expression at compile time). If you define the method , such as "`double x() {}`;" in the dynamic library class the expression "`sin(x)`" will call the method "`x()`" ( and function `Math.sin()` ) each time it is evaluated.

It is possible to have any type of intermediate object throughout the calculation as long as types of the function return values and parameters stay compatible.

The variant of the "compile" function with three arguments allows to fix the type of the expression result. For example :

     CompiledExpression expression=compile("2*6+6",lib,Double.TYPE);

will produce compiled expression, whose return type is always `double`. For additional information on how to use this feature to eliminate object allocation overhead see `gnu.jel.CompiledExpression` documentation.

Care should be taken during the assembly of static and dynamic libraries to avoid conflicts and unsupported return types.

(c) 1998, by Konstantin Metlov
Prague, CZ

See Also:
  CompiledExpression

##

Evaluator()

##

compile(String, Library)
  Compiles expression, resolving the function names in the library.
compile(String, Library, Class)
  Compiles expression, resolving the function names in the library.
compileBits(String, Library)
  Compiles expression, resolving the function names in the library.
compileBits(String, Library, Class)
  Compiles expression, resolving the function names in the library.

##

Evaluator

     public Evaluator()

##

compile

     public static CompiledExpression compile(String expression,
                                              Library lib,
                                              Class resultType) throws CompilationException

  Compiles expression, resolving the function names in the library.

  Parameters:
    expression - is the expression to compile. i.e. "sin(666)" .
    lib - Library of functions exported for use in expression.
    resultType - identifies the type result should be converted to. Can be null, in this case the result type is not fixed.
  Returns:
    Instance of the CompiledExpression subclass, implementing the specified expression evaluation.
  Throws: CompilationException
    if the expression is not syntactically or semantically correct.
  See Also:
    evaluate

compileBits

     public static ExpressionBits compileBits(String expression,
                                              Library lib,
                                              Class resultType) throws CompilationException

  Compiles expression, resolving the function names in the library.

  This variant of compile allows to store expressions in a `java.io.OutputStream` using Java serialization mechanism.

  Parameters:
    expression - is the expression to compile. i.e. "sin(666)" .
    lib - Library of functions exported for use in expression.
    resultType - identifies the type result should be converted to. Can be null, in this case the result type is not fixed.
  Returns:
    Instance of the ExpressionBits class, allowing to store and/or instantiate compiled expression.
  Throws: CompilationException
    if the expression is not syntactically or semantically correct.
  See Also:
    evaluate

compile

     public static CompiledExpression compile(String expression,
                                              Library lib) throws CompilationException

  Compiles expression, resolving the function names in the library.

  Parameters:
    expression - is the expression to compile. i.e. "sin(666)" .
    lib - Library of functions exported for use in expression.
  Returns:
    Instance of the CompiledExpression subclass, implementing the specified expression evaluation.
  Throws: CompilationException
    if the expression is not syntactically or semantically correct.
  See Also:
    evaluate

compileBits

     public static ExpressionBits compileBits(String expression,
                                              Library lib) throws CompilationException

  Compiles expression, resolving the function names in the library.

  This variant of compile allows to store expressions in a `java.io.OutputStream` using Java serialization mechanism.

  Parameters:
    expression - is the expression to compile. i.e. "sin(666)" .
    lib - Library of functions exported for use in expression.
  Returns:
    Instance of the ExpressionBits class, allowing to store and/or instantiate compiled expression.
  Throws: CompilationException
    if the expression is not syntactically or semantically correct.
  See Also:
    evaluate

    All Packages  Class Hierarchy  This Package  Previous  Next  Index