|
http://www.eteks.com | ||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
Runtime interpreter. This interface specifies the set of methods that computes the value
of the different literals, constants, operators and functions available in the Syntax
interface.
Once a string is parsed by one of the parsers, these methods are called at time of interpretation to
evaluate the result of a function or an expression according to the value of its parameters.
The values managed at runtime by the methods are of type Object
: This allows to
apply computations on a wide range of parameter types, from number types (with the classes Long
,
Double
,...) to strings (instances of String
) and also booleans
(Boolean
). Other classes like java.math.BigDecimal
or javax.vecmath.GVector
and
javax.vecmath.GMatrix
can be also used.
Depending on some implementations of this interface, these methods may throw a runtime exception
(generally an instance of IllegalArgumentException
) if they consider
that their parameters have a wrong type to perform the resquested operation or if the key of
a constant, operator or function of a given syntax isn't implemented.
Note that an Interpreter
implementation isn't obliged to implement all the default
keys listed in Syntax
. For example, the com.eteks.tools.calculator.JeksCalculator
class implements the Syntax
interface to recognize only the operators and common functions
available in the calculator and uses its own keys. On the other side, its implementation
of Interpreter
is able to compute only these operators and common functions
according to these keys.
Syntax
,
DoubleInterpreter
,
com.eteks.tools.calculator.JeksCalculator
Method Summary | |
java.lang.Object |
getBinaryOperatorValue(java.lang.Object binaryOperatorKey,
java.lang.Object operand1,
java.lang.Object operand2)
Returns the value of the operation of the binary operator binaryOperatorKey applied on
the two operands operand1 and operand2 . |
java.lang.Object |
getCommonFunctionValue(java.lang.Object commonFunctionKey,
java.lang.Object param)
Returns the value of the common function commonFunctionKey with
the parameter param . |
java.lang.Object |
getConditionValue(java.lang.Object paramIf,
java.lang.Object paramThen,
java.lang.Object paramElse)
Returns the value paramThen or paramElse depending on
whether the condition paramIf being true or false.
|
java.lang.Object |
getConstantValue(java.lang.Object constantKey)
Returns the value of the constant constantKey . |
java.lang.Object |
getFunctionValue(Function function,
java.lang.Object[] parametersValue,
boolean recursiveCall)
Returns the value of the function function with its parameters parametersValue .
|
java.lang.Object |
getLiteralValue(java.lang.Object literal)
Returns the value of the literal literal . |
java.lang.Object |
getParameterValue(java.lang.Object parameter)
Returns the value of the parameter parameter . |
java.lang.Object |
getUnaryOperatorValue(java.lang.Object unaryOperatorKey,
java.lang.Object operand)
Returns the value of the operation of the unary operator unaryOperatorKey applied on
the operand operand . |
boolean |
isTrue(java.lang.Object condition)
Returns true or false according to the value of condition .
|
boolean |
supportsRecursiveCall()
Returns true if the isTrue () method is able to evaluate its parameter.
|
Method Detail |
public java.lang.Object getLiteralValue(java.lang.Object literal)
literal
. literal
may be an instance of Number
, String
or another class
matching the literal recognized by the syntax. This method
may throw an exception if the interpreter doesn't accept one of these types.literal
- a literal.public java.lang.Object getParameterValue(java.lang.Object parameter)
parameter
. parameter
is one of the values passed to the computeFunction ()
method of
Function
to compute the value of a function or the value returned by the
getParameterValue ()
method of ExpressionParameter
to compute
the value of an expression.parameter
.parameter
- a paramater.Function.computeFunction(com.eteks.parser.Interpreter, java.lang.Object[])
,
ExpressionParameter.getParameterValue(java.lang.Object)
public java.lang.Object getConstantValue(java.lang.Object constantKey)
constantKey
. constantKey
may be the key of a constant of Syntax
(one of CONSTANT_PI
,
CONSTANT_E
, CONSTANT_FALSE
, CONSTANT_TRUE
or an other user defined key).constantKey
- the key of a constant of Syntax
.public java.lang.Object getUnaryOperatorValue(java.lang.Object unaryOperatorKey, java.lang.Object operand)
unaryOperatorKey
applied on
the operand operand
. unaryOperatorKey
is the key of an unary operator
of Syntax
(one of OPERATOR_POSITIVE
,OPERATOR_OPPOSITE
,
OPERATOR_LOGICAL_NOT
, OPERATOR_BITWISE_NOT
or
an other user defined key).unaryOperatorKey
- the key of an unary operator of Syntax
.operand
- the operand (already evaluated if it's an expression).public java.lang.Object getBinaryOperatorValue(java.lang.Object binaryOperatorKey, java.lang.Object operand1, java.lang.Object operand2)
binaryOperatorKey
applied on
the two operands operand1
and operand2
. binaryOperatorKey
is the key of a binary operator of Syntax
(one of OPERATOR_ADD
,
OPERATOR_SUBSTRACT
, OPERATOR_MULTIPLY
, OPERATOR_DIVIDE
,...
or an other user defined key).binaryOperatorKey
- the key of a binary operator of Syntax
.operand1
- the first operand (already evaluated if it's an expression).operand2
- the second operand (already evaluated if it's an expression).public java.lang.Object getCommonFunctionValue(java.lang.Object commonFunctionKey, java.lang.Object param)
commonFunctionKey
with
the parameter param
. commonFunctionKey
is the key of
a commomon function of Syntax
(one of FUNCTION_LN
,
FUNCTION_LOG
, FUNCTION_EXP
, FUNCTION_SQR
,...
or an other user defined key).commonFunctionKey
- the key of a common function of Syntax
.param
- the parameter of the function (already evaluated if it's an expression).public java.lang.Object getConditionValue(java.lang.Object paramIf, java.lang.Object paramThen, java.lang.Object paramElse)
paramThen
or paramElse
depending on
whether the condition paramIf
being true or false.
As paramIf
, paramThen
and paramElse
are already evaluated before the call to this method, note that this method will
be called to get the result of a condition only if supportsRecursiveCall ()
returns false
(otherwise recursive calls would never end).
If supportsRecursiveCall ()
returns true
, only paramThen
or paramElse
is evaluated depending on whether isTrue (paramIf)
returning true
or false
.paramIf
- the condition.paramThen
- the true condition value.paramElse
- the false condition value.supportsRecursiveCall()
public boolean isTrue(java.lang.Object condition)
true
or false
according to the value of condition
.
This method is called internally if supportsRecursiveCall ()
returns
true
. It may also be used in other methods of Interpreter
to test the boolean
value of its operands.condition
- the value to test (already evaluated if it's an expression).true
or false
.getConditionValue(java.lang.Object, java.lang.Object, java.lang.Object)
public boolean supportsRecursiveCall()
true
if the isTrue ()
method is able to evaluate its parameter.
isTrue ()
must be able to evaluate a boolean condition to stop the recursive
calls when the stop condition is met during interpretation.true
or false
.isTrue(java.lang.Object)
,
getConditionValue(java.lang.Object, java.lang.Object, java.lang.Object)
public java.lang.Object getFunctionValue(Function function, java.lang.Object[] parametersValue, boolean recursiveCall)
function
with its parameters parametersValue
.
This method can evaluate the value of the function call symply by computing function.computeFunction (this, parametersValue)
.function
- the function to compute.parametersValue
- the value of function's parameters (already evaluated if they are expressions).recursiveCall
- true
if the call to this function is a recursive call, meaning that
the current evaluated function calls itself.
|
|
||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |