com.rubecula.util
Interface ExpressionInterface

All Superinterfaces:
Identifiable
All Known Implementing Classes:
ExpressionParser

public interface ExpressionInterface
extends Identifiable

Interface to specify the operations relating to the parsing and evaluation of expressions. Note that his interface is independent of any particular technologies. Note too that the (opaque) object returned from parse is supposed to be provided as a parameter to the evaluate method.

Since:
V_0_1
Version:
$Revision: 1.7 $
Author:
Robin Hillyard

Method Summary
 java.lang.Double addAlgebraicVariable(java.lang.String string, double value)
          Method to add a predefined variable to the expression parser.
 Presentable evaluate(java.lang.Object parseTree)
          Method to evaluate a previously-parsed expression.
 java.util.Collection getExpressionVariables()
           
 java.lang.Object parse(java.lang.String expression)
          Method to parse an expression in the form of a String and to return a handle to the parse Tree.
 void resetAlgebraicVariables()
          Method to remove all predefined variables from the expression parser.
 void setDebug(boolean debug)
          Method to set the debug status for the expression parser.
 void setMillFactory(MillFactoryInterface millFactory)
          Method to setup the mill factory for the evaluation of expressions, in particular monadic, dyadic operations, pushing and popping of values.
 void setVariables(Lookupable variables)
          Method to setup the variables map for allowing variables to be dealt with in expressions.
 
Methods inherited from interface com.rubecula.util.Identifiable
getIdentifier
 

Method Detail

parse

public java.lang.Object parse(java.lang.String expression)
Method to parse an expression in the form of a String and to return a handle to the parse Tree.

Parameters:
expression - A mathematical expression to be parsed.
Returns:
a handle to the parse tree corresponding to expression.

evaluate

public Presentable evaluate(java.lang.Object parseTree)
                     throws PresentableException
Method to evaluate a previously-parsed expression.

Parameters:
parseTree - An object previously returned from a call to parse(String).
Returns:
a Presentable object.
Throws:
PresentableException - A problem has occurred with parsing or evaluating the expression.

setMillFactory

public void setMillFactory(MillFactoryInterface millFactory)
Method to setup the mill factory for the evaluation of expressions, in particular monadic, dyadic operations, pushing and popping of values. If this method is not invoked on an expression parser, then the native function evaluation of the expression parser will be used instead.

Parameters:
millFactory - a factory for creating mills with which to evaluate expressions.

setVariables

public void setVariables(Lookupable variables)
Method to setup the variables map for allowing variables to be dealt with in expressions. If this method is not invoked on an expression parser, then variables must be predefined before they can be encountered in an expression.

Parameters:
variables - a map of variables, so that they can be looked up (may be null, in which case undeclared variables are not enabled for this expression parser).

addAlgebraicVariable

public java.lang.Double addAlgebraicVariable(java.lang.String string,
                                             double value)
Method to add a predefined variable to the expression parser. Note that the name "addAlgebraicVariable" may not be 100% appropriate, but it does seem to distinguish it tolerably well from the other types of variables defined through setVariables(com.rubecula.util.Lookupable).

Parameters:
string - the name of the variable
value - the desired value of the variable.
Returns:
the result of calling adding the variable.

resetAlgebraicVariables

public void resetAlgebraicVariables()
Method to remove all predefined variables from the expression parser.


setDebug

public void setDebug(boolean debug)
Method to set the debug status for the expression parser.

Parameters:
debug - true or false.

getExpressionVariables

public java.util.Collection getExpressionVariables()