Package com.ezylang.evalex.operators
Interface OperatorIfc
-
- All Known Implementing Classes:
AbstractOperator,InfixAndOperator,InfixDivisionOperator,InfixEqualsOperator,InfixGreaterEqualsOperator,InfixGreaterOperator,InfixLessEqualsOperator,InfixLessOperator,InfixMinusOperator,InfixModuloOperator,InfixMultiplicationOperator,InfixNotEqualsOperator,InfixOrOperator,InfixPlusOperator,InfixPowerOfOperator,PrefixMinusOperator,PrefixNotOperator,PrefixPlusOperator
public interface OperatorIfcInterface that is required for all operators in an operator dictionary for evaluation of expressions. There are three operator type: prefix, postfix and infix. Every operator has a precedence, which defines the order of operator evaluation. The associativity of an operator is a property that determines how operators of the same precedence are grouped in the absence of parentheses.
-
-
Nested Class Summary
Nested Classes Modifier and Type Interface Description static classOperatorIfc.OperatorTypeThe operator type.
-
Field Summary
Fields Modifier and Type Field Description static intOPERATOR_PRECEDENCE_ADDITIVEAdditive operators precedence: + and -static intOPERATOR_PRECEDENCE_ANDAnd operator precedence: &&static intOPERATOR_PRECEDENCE_COMPARISONComparative operators precedence: <, >, <=, >=static intOPERATOR_PRECEDENCE_EQUALITYEquality operators precedence: =, ==, !=, <>static intOPERATOR_PRECEDENCE_MULTIPLICATIVEMultiplicative operators precedence: *, /, %static intOPERATOR_PRECEDENCE_OROr operator precedence: ||static intOPERATOR_PRECEDENCE_POWERPower operator precedence: ^static intOPERATOR_PRECEDENCE_POWER_HIGHERAn optional higher power operator precedence, higher than the unary prefix, e.g.static intOPERATOR_PRECEDENCE_UNARYUnary operators precedence: + and - as prefix
-
Method Summary
All Methods Instance Methods Abstract Methods Modifier and Type Method Description EvaluationValueevaluate(Expression expression, Token operatorToken, EvaluationValue... operands)Performs the operator logic and returns an evaluation result.intgetPrecedence()intgetPrecedence(ExpressionConfiguration configuration)Called during parsing, can be implemented to return a customized precedence.booleanisInfix()If it is an infix operator.booleanisLeftAssociative()If operators with same precedence are evaluated from left to right.booleanisOperandLazy()Checks if the operand is lazy.booleanisPostfix()If it is a postfix operator.booleanisPrefix()If it is a prefix operator.
-
-
-
Field Detail
-
OPERATOR_PRECEDENCE_OR
static final int OPERATOR_PRECEDENCE_OR
Or operator precedence: ||- See Also:
- Constant Field Values
-
OPERATOR_PRECEDENCE_AND
static final int OPERATOR_PRECEDENCE_AND
And operator precedence: &&- See Also:
- Constant Field Values
-
OPERATOR_PRECEDENCE_EQUALITY
static final int OPERATOR_PRECEDENCE_EQUALITY
Equality operators precedence: =, ==, !=, <>- See Also:
- Constant Field Values
-
OPERATOR_PRECEDENCE_COMPARISON
static final int OPERATOR_PRECEDENCE_COMPARISON
Comparative operators precedence: <, >, <=, >=- See Also:
- Constant Field Values
-
OPERATOR_PRECEDENCE_ADDITIVE
static final int OPERATOR_PRECEDENCE_ADDITIVE
Additive operators precedence: + and -- See Also:
- Constant Field Values
-
OPERATOR_PRECEDENCE_MULTIPLICATIVE
static final int OPERATOR_PRECEDENCE_MULTIPLICATIVE
Multiplicative operators precedence: *, /, %- See Also:
- Constant Field Values
-
OPERATOR_PRECEDENCE_POWER
static final int OPERATOR_PRECEDENCE_POWER
Power operator precedence: ^- See Also:
- Constant Field Values
-
OPERATOR_PRECEDENCE_UNARY
static final int OPERATOR_PRECEDENCE_UNARY
Unary operators precedence: + and - as prefix- See Also:
- Constant Field Values
-
OPERATOR_PRECEDENCE_POWER_HIGHER
static final int OPERATOR_PRECEDENCE_POWER_HIGHER
An optional higher power operator precedence, higher than the unary prefix, e.g. -2^2 equals to 4 or -4, depending on precedence configuration.- See Also:
- Constant Field Values
-
-
Method Detail
-
getPrecedence
int getPrecedence()
- Returns:
- The operator's precedence.
-
isLeftAssociative
boolean isLeftAssociative()
If operators with same precedence are evaluated from left to right.- Returns:
- The associativity.
-
isPrefix
boolean isPrefix()
If it is a prefix operator.- Returns:
trueif it is a prefix operator.
-
isPostfix
boolean isPostfix()
If it is a postfix operator.- Returns:
trueif it is a postfix operator.
-
isInfix
boolean isInfix()
If it is an infix operator.- Returns:
trueif it is an infix operator.
-
getPrecedence
int getPrecedence(ExpressionConfiguration configuration)
Called during parsing, can be implemented to return a customized precedence.- Parameters:
configuration- The expression configuration.- Returns:
- The default precedence from the operator annotation, or a customized value.
-
isOperandLazy
boolean isOperandLazy()
Checks if the operand is lazy.- Returns:
trueif operands are defined as lazy.
-
evaluate
EvaluationValue evaluate(Expression expression, Token operatorToken, EvaluationValue... operands) throws EvaluationException
Performs the operator logic and returns an evaluation result.- Parameters:
expression- The expression, where this function is executed. Can be used to access the expression configuration.operatorToken- The operator token from the parsed expression.operands- The operands, one for prefix and postfix operators, two for infix operators.- Returns:
- The evaluation result in form of a
EvaluationValue. - Throws:
EvaluationException- In case there were problems during evaluation.
-
-