Package org.qdl_lang.evaluate
Class OpEvaluator
- java.lang.Object
-
- org.qdl_lang.evaluate.AbstractEvaluator
-
- org.qdl_lang.evaluate.OpEvaluator
-
- All Implemented Interfaces:
Serializable
,EvaluatorInterface
public class OpEvaluator extends AbstractEvaluator
Class charged with evaluating algebraic expressions.Created by Jeff Gaynor
on 1/13/20 at 3:20 PM- See Also:
- Serialized Form
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from class org.qdl_lang.evaluate.AbstractEvaluator
AbstractEvaluator.CommonKeyIterator, AbstractEvaluator.fPointer, AbstractEvaluator.fpResult
-
-
Field Summary
-
Fields inherited from class org.qdl_lang.evaluate.AbstractEvaluator
bigArgList, bigArgList0, FILE_OP_AUTO, FILE_OP_BINARY, FILE_OP_INPUT_STREAM, FILE_OP_TEXT_INI, FILE_OP_TEXT_STEM, FILE_OP_TEXT_STRING, FILE_OP_TEXT_WITHOUT_LIST_INI, fNames, MAX_ARG_COUNT
-
Fields inherited from interface org.qdl_lang.evaluate.EvaluatorInterface
UNKNOWN_VALUE
-
-
Constructor Summary
Constructors Constructor Description OpEvaluator()
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description protected QDLSet
applyToSet(QDLStem lArg, QDLSet rArg, Object defaultValue, State state, Dyad dyad)
protected QDLStem
applyToStem(QDLStem lArg, QDLStem rArg, Object defaultValue, State state, Dyad dyad)
boolean
dispatch(Polyad polyad, State state)
Does the actual evaluation of thePolyad
.protected void
doContainsKey(Dyad dyad, State state, boolean containsKey)
protected void
doDyadComparisonOperator(Dyad dyad, State state)
protected void
doDyadEqualsOperator(Dyad dyad, State state)
protected void
doDyadIntegerDivide(Dyad dyad, State state)
protected void
doDyadLogicalOperator(Dyad dyad, State state)
protected void
doDyadMinus(Dyad dyad, State state)
protected void
doDyadPlus(Dyad dyad, State state)
For dyadic plus.protected void
doDyadTimesOrDivide(Dyad dyad, State state, boolean doTimes)
protected void
doIsDefinedDyad(Dyad dyad, State state, boolean isDefined)
protected void
doMonadicTilde(Monad monad, State state, boolean isStile)
protected void
doMonadIncOrDec(Monad monad, State state, boolean isPlusPlus)
NOTE that at this point this only works for single variables -- you can't apply this to a stem.protected void
doMonadMinus(Monad monad, State state)
protected void
doMonadNot(Monad monad, State state)
protected void
doMonadPlus(Monad monad, State state)
protected void
doRegexMatch(Dyad dyad, State state)
Contract is expression regex ≈ expression returns true if it matches expression as a string.protected void
doSetUnionOrInteresection(Dyad dyad, State state)
protected Object
doSingleApply(Object lArg, DyadicFunctionReferenceNode fNode, Object defaultValue, State state, Dyad dyad)
protected Object
doSingleApply(Object lArg, FunctionReferenceNode fNode, Object defaultValue, State state, Dyad dyad)
apply the argument to a single function.protected Object
doSingleApply(Object lArg, FunctionReferenceNode fNode, State actualState)
protected void
doTilde(Dyad dyad, State state)
protected void
doUnaryPlusMinus(Monad monad, State state, Long sign)
This will evaluate the expression and take its opposite.void
evaluate(Dyad dyad, State state)
void
evaluate(Monad monad, State state)
void
evaluate(Nilad nilad, State state)
boolean
evaluate(Polyad polyad, State state)
Decides if aPolyad
is evaluated by this evaluator and if not, returns false, if so, it evaluates it and returns true.void
evaluate2(Dyad dyad, State state)
void
evaluate2(Monad monad, State state)
protected Object
evaluateNextArgForApplies(Object lArg, Object rArg, Object defaultValue, State state, Dyad dyad)
int[]
getArgCount(String name)
Return the arg counts for an operator.int[]
getArgCount(Dyad dyad)
int[]
getArgCount(Monad monad)
String[]
getFunctionNames()
static MathContext
getMathContext()
String
getNamespace()
static int
getNumericDigits()
int
getType(String oo)
Given an operator, this will return the integer value associated with it for lookups later.boolean
isMathOperator(String x)
TreeSet<String>
listFunctions(boolean listFQ)
No listing for these yet since they are not the standard func() pattern, e.g.static void
setNumericDigits(int newNumericDigits)
-
Methods inherited from class org.qdl_lang.evaluate.AbstractEvaluator
areAllBigDecimals, areAllBoolean, areAllLongs, areAllNumbers, areAllSets, areAllStems, areAllStrings, areAnyBigDecimals, areNoneStems, bdEquals, checkNull, checkNull, convertArgsToStem, evaluate, finishExpr, getBigArgList, getBigArgList0, getCommonKeys, getFQFunctionNames, getFunctionReferenceNode, getFunctionReferenceNode, getOperator, getOrCreateStem, isBigDecimal, isBoolean, isBuiltInFunction, isFunctionRef, isLong, isNumber, isScalar, isSet, isStem, isStemList, isString, process1, process2, process2, process3, processSet1, processSet2, processSet2, processStem1, processStem2, processStem3, resolveResourceToFile, tempFname, toBD, toConstants, toStem
-
-
-
-
Field Detail
-
AND
public static final String AND
- See Also:
- Constant Field Values
-
AND2
public static final String AND2
- See Also:
- Constant Field Values
-
ASSIGNMENT
public static final String ASSIGNMENT
- See Also:
- Constant Field Values
-
CEILING
public static final String CEILING
- See Also:
- Constant Field Values
-
DIVIDE
public static final String DIVIDE
- See Also:
- Constant Field Values
-
DIVIDE2
public static final String DIVIDE2
- See Also:
- Constant Field Values
-
EQUALS
public static final String EQUALS
- See Also:
- Constant Field Values
-
EQUALS2
public static final String EQUALS2
- See Also:
- Constant Field Values
-
FLOOR
public static final String FLOOR
- See Also:
- Constant Field Values
-
INTEGER_DIVIDE
public static final String INTEGER_DIVIDE
- See Also:
- Constant Field Values
-
SYMMETRIC_DIFFERENCE
public static final String SYMMETRIC_DIFFERENCE
- See Also:
- Constant Field Values
-
LESS_THAN
public static final String LESS_THAN
- See Also:
- Constant Field Values
-
LESS_THAN_EQUAL
public static final String LESS_THAN_EQUAL
- See Also:
- Constant Field Values
-
LESS_THAN_EQUAL2
public static final String LESS_THAN_EQUAL2
- See Also:
- Constant Field Values
-
LESS_THAN_EQUAL3
public static final String LESS_THAN_EQUAL3
- See Also:
- Constant Field Values
-
MINUS
public static final String MINUS
- See Also:
- Constant Field Values
-
MINUS2
public static final String MINUS2
- See Also:
- Constant Field Values
-
MINUS_MINUS
public static final String MINUS_MINUS
- See Also:
- Constant Field Values
-
MORE_THAN
public static final String MORE_THAN
- See Also:
- Constant Field Values
-
MORE_THAN_EQUAL
public static final String MORE_THAN_EQUAL
- See Also:
- Constant Field Values
-
MORE_THAN_EQUAL2
public static final String MORE_THAN_EQUAL2
- See Also:
- Constant Field Values
-
MORE_THAN_EQUAL3
public static final String MORE_THAN_EQUAL3
- See Also:
- Constant Field Values
-
NOT
public static final String NOT
- See Also:
- Constant Field Values
-
NOT2
public static final String NOT2
- See Also:
- Constant Field Values
-
NOT_EQUAL
public static final String NOT_EQUAL
- See Also:
- Constant Field Values
-
NOT_EQUAL2
public static final String NOT_EQUAL2
- See Also:
- Constant Field Values
-
OR
public static final String OR
- See Also:
- Constant Field Values
-
OR2
public static final String OR2
- See Also:
- Constant Field Values
-
PLUS
public static final String PLUS
- See Also:
- Constant Field Values
-
PLUS2
public static final String PLUS2
- See Also:
- Constant Field Values
-
PLUS_PLUS
public static final String PLUS_PLUS
- See Also:
- Constant Field Values
-
POWER
public static final String POWER
- See Also:
- Constant Field Values
-
UNION
public static final String UNION
- See Also:
- Constant Field Values
-
UNION_2
public static final String UNION_2
- See Also:
- Constant Field Values
-
INTERSECTION
public static final String INTERSECTION
- See Also:
- Constant Field Values
-
INTERSECTION_2
public static final String INTERSECTION_2
- See Also:
- Constant Field Values
-
TILDE
public static final String TILDE
- See Also:
- Constant Field Values
-
TILDE_STILE
public static final String TILDE_STILE
- See Also:
- Constant Field Values
-
TILDE_STILE2
public static final String TILDE_STILE2
- See Also:
- Constant Field Values
-
TIMES
public static final String TIMES
- See Also:
- Constant Field Values
-
TIMES2
public static final String TIMES2
- See Also:
- Constant Field Values
-
DOT
public static final String DOT
- See Also:
- Constant Field Values
-
REGEX_MATCH
public static final String REGEX_MATCH
- See Also:
- Constant Field Values
-
REGEX_MATCH2
public static final String REGEX_MATCH2
- See Also:
- Constant Field Values
-
TO_SET
public static final String TO_SET
- See Also:
- Constant Field Values
-
TO_SET2
public static final String TO_SET2
- See Also:
- Constant Field Values
-
EPSILON
public static final String EPSILON
- See Also:
- Constant Field Values
-
EPSILON_NOT
public static final String EPSILON_NOT
- See Also:
- Constant Field Values
-
IS_A
public static final String IS_A
- See Also:
- Constant Field Values
-
IS_DEFINED
public static final String IS_DEFINED
- See Also:
- Constant Field Values
-
IS_NOT_DEFINED
public static final String IS_NOT_DEFINED
- See Also:
- Constant Field Values
-
CONTAINS_KEY
public static final String CONTAINS_KEY
- See Also:
- Constant Field Values
-
NOT_CONTAINS_KEY
public static final String NOT_CONTAINS_KEY
- See Also:
- Constant Field Values
-
FOR_ALL_KEY
public static final String FOR_ALL_KEY
- See Also:
- Constant Field Values
-
MASK_OP_KEY
public static final String MASK_OP_KEY
- See Also:
- Constant Field Values
-
TRANSPOSE_OP_KEY
public static final String TRANSPOSE_OP_KEY
- See Also:
- Constant Field Values
-
REDUCE_OP_KEY
public static final String REDUCE_OP_KEY
- See Also:
- Constant Field Values
-
EXPAND_OP_KEY
public static final String EXPAND_OP_KEY
- See Also:
- Constant Field Values
-
APPLY_OP_KEY
public static final String APPLY_OP_KEY
- See Also:
- Constant Field Values
-
ASSIGNMENT_VALUE
public static final int ASSIGNMENT_VALUE
- See Also:
- Constant Field Values
-
PLUS_VALUE
public static final int PLUS_VALUE
- See Also:
- Constant Field Values
-
MINUS_VALUE
public static final int MINUS_VALUE
- See Also:
- Constant Field Values
-
PLUS_PLUS_VALUE
public static final int PLUS_PLUS_VALUE
- See Also:
- Constant Field Values
-
MINUS_MINUS_VALUE
public static final int MINUS_MINUS_VALUE
- See Also:
- Constant Field Values
-
AND_VALUE
public static final int AND_VALUE
- See Also:
- Constant Field Values
-
OR_VALUE
public static final int OR_VALUE
- See Also:
- Constant Field Values
-
EQUALS_VALUE
public static final int EQUALS_VALUE
- See Also:
- Constant Field Values
-
NOT_EQUAL_VALUE
public static final int NOT_EQUAL_VALUE
- See Also:
- Constant Field Values
-
LESS_THAN_VALUE
public static final int LESS_THAN_VALUE
- See Also:
- Constant Field Values
-
LESS_THAN_EQUAL_VALUE
public static final int LESS_THAN_EQUAL_VALUE
- See Also:
- Constant Field Values
-
MORE_THAN_VALUE
public static final int MORE_THAN_VALUE
- See Also:
- Constant Field Values
-
MORE_THAN_EQUAL_VALUE
public static final int MORE_THAN_EQUAL_VALUE
- See Also:
- Constant Field Values
-
NOT_VALUE
public static final int NOT_VALUE
- See Also:
- Constant Field Values
-
TIMES_VALUE
public static final int TIMES_VALUE
- See Also:
- Constant Field Values
-
DIVIDE_VALUE
public static final int DIVIDE_VALUE
- See Also:
- Constant Field Values
-
POWER_VALUE
public static final int POWER_VALUE
- See Also:
- Constant Field Values
-
INTEGER_DIVIDE_VALUE
public static final int INTEGER_DIVIDE_VALUE
- See Also:
- Constant Field Values
-
TILDE_VALUE
public static final int TILDE_VALUE
- See Also:
- Constant Field Values
-
DOT_VALUE
public static final int DOT_VALUE
- See Also:
- Constant Field Values
-
TILDE_STILE_VALUE
public static final int TILDE_STILE_VALUE
- See Also:
- Constant Field Values
-
REGEX_MATCH_VALUE
public static final int REGEX_MATCH_VALUE
- See Also:
- Constant Field Values
-
UNION_VALUE
public static final int UNION_VALUE
- See Also:
- Constant Field Values
-
INTERSECTION_VALUE
public static final int INTERSECTION_VALUE
- See Also:
- Constant Field Values
-
FLOOR_VALUE
public static final int FLOOR_VALUE
- See Also:
- Constant Field Values
-
CEILING_VALUE
public static final int CEILING_VALUE
- See Also:
- Constant Field Values
-
TO_SET_VALUE
public static final int TO_SET_VALUE
- See Also:
- Constant Field Values
-
EPSILON_VALUE
public static final int EPSILON_VALUE
- See Also:
- Constant Field Values
-
EPSILON_NOT_VALUE
public static final int EPSILON_NOT_VALUE
- See Also:
- Constant Field Values
-
IS_A_VALUE
public static final int IS_A_VALUE
- See Also:
- Constant Field Values
-
IS_DEFINED_VALUE
public static final int IS_DEFINED_VALUE
- See Also:
- Constant Field Values
-
IS_NOT_DEFINED_VALUE
public static final int IS_NOT_DEFINED_VALUE
- See Also:
- Constant Field Values
-
CONTAINS_KEY_VALUE
public static final int CONTAINS_KEY_VALUE
- See Also:
- Constant Field Values
-
NOT_CONTAINS_KEY_VALUE
public static final int NOT_CONTAINS_KEY_VALUE
- See Also:
- Constant Field Values
-
FOR_ALL_KEY_VALUE
public static final int FOR_ALL_KEY_VALUE
- See Also:
- Constant Field Values
-
MASK_OP_VALUE
public static final int MASK_OP_VALUE
- See Also:
- Constant Field Values
-
TRANSPOSE_OP_VALUE
public static final int TRANSPOSE_OP_VALUE
- See Also:
- Constant Field Values
-
REDUCE_OP_VALUE
public static final int REDUCE_OP_VALUE
- See Also:
- Constant Field Values
-
EXPAND_OP_VALUE
public static final int EXPAND_OP_VALUE
- See Also:
- Constant Field Values
-
APPLY_OP_VALUE
public static final int APPLY_OP_VALUE
- See Also:
- Constant Field Values
-
OTHER_MATH_OPS
public static String[] OTHER_MATH_OPS
This is for operators that are in the parser and never are created directly, e.g. → or #. "->"
-
ALL_MATH_OPS
public static String[] ALL_MATH_OPS
All Math operators. These are used in function references.
-
numericDigits
public static int numericDigits
-
-
Method Detail
-
getArgCount
public int[] getArgCount(String name)
Return the arg counts for an operator.- Parameters:
name
-- Returns:
-
getNamespace
public String getNamespace()
-
isMathOperator
public boolean isMathOperator(String x)
-
getFunctionNames
public String[] getFunctionNames()
- Specified by:
getFunctionNames
in classAbstractEvaluator
-
getMathContext
public static MathContext getMathContext()
-
getNumericDigits
public static int getNumericDigits()
-
setNumericDigits
public static void setNumericDigits(int newNumericDigits)
-
listFunctions
public TreeSet<String> listFunctions(boolean listFQ)
No listing for these yet since they are not the standard func() pattern, e.g. a < b.- Specified by:
listFunctions
in interfaceEvaluatorInterface
- Overrides:
listFunctions
in classAbstractEvaluator
- Returns:
-
getType
public int getType(String oo)
Given an operator, this will return the integer value associated with it for lookups later.ExpressionNode
s store the value, not the operator.- Parameters:
oo
-- Returns:
-
applyToSet
protected QDLSet applyToSet(QDLStem lArg, QDLSet rArg, Object defaultValue, State state, Dyad dyad)
-
evaluateNextArgForApplies
protected Object evaluateNextArgForApplies(Object lArg, Object rArg, Object defaultValue, State state, Dyad dyad)
-
applyToStem
protected QDLStem applyToStem(QDLStem lArg, QDLStem rArg, Object defaultValue, State state, Dyad dyad)
-
doSingleApply
protected Object doSingleApply(Object lArg, DyadicFunctionReferenceNode fNode, Object defaultValue, State state, Dyad dyad)
-
doSingleApply
protected Object doSingleApply(Object lArg, FunctionReferenceNode fNode, Object defaultValue, State state, Dyad dyad)
apply the argument to a single function. Note that the dyad here is passed along to make error messages only.- Parameters:
fNode
-dyad
-- Returns:
-
doSingleApply
protected Object doSingleApply(Object lArg, FunctionReferenceNode fNode, State actualState)
-
doRegexMatch
protected void doRegexMatch(Dyad dyad, State state)
Contract is expression regex ≈ expression returns true if it matches expression as a string.- Parameters:
dyad
-state
-
-
doDyadPlus
protected void doDyadPlus(Dyad dyad, State state)
For dyadic plus.- Parameters:
dyad
-state
-
-
doMonadIncOrDec
protected void doMonadIncOrDec(Monad monad, State state, boolean isPlusPlus)
NOTE that at this point this only works for single variables -- you can't apply this to a stem.- Parameters:
monad
-state
-isPlusPlus
-
-
doUnaryPlusMinus
protected void doUnaryPlusMinus(Monad monad, State state, Long sign)
This will evaluate the expression and take its opposite. This is because the parser does not differentiate between -3^4 and (-3)^4, turing the first of each into a single monad. It works right if there are parentheses, but this is possible a thronier issue to fix than we want now. Best to ket it do this since algebraic operations work as expected.- Parameters:
monad
-state
-sign
-
-
evaluate
public boolean evaluate(Polyad polyad, State state)
Description copied from class:AbstractEvaluator
Decides if aPolyad
is evaluated by this evaluator and if not, returns false, if so, it evaluates it and returns true. This function actually just dispatches it toAbstractEvaluator.dispatch(Polyad, State)
where the work is done and manages putting better trace information in if there is a failure.- Overrides:
evaluate
in classAbstractEvaluator
- Returns:
-
dispatch
public boolean dispatch(Polyad polyad, State state)
Description copied from class:AbstractEvaluator
Does the actual evaluation of thePolyad
.- Specified by:
dispatch
in classAbstractEvaluator
- Returns:
-
getArgCount
public int[] getArgCount(Monad monad)
-
getArgCount
public int[] getArgCount(Dyad dyad)
-
-