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.AbstractEvaluatorAbstractEvaluator.CommonKeyIterator, AbstractEvaluator.fPointer, AbstractEvaluator.fpResult
 
- 
 - 
Field Summary- 
Fields inherited from class org.qdl_lang.evaluate.AbstractEvaluatorbigArgList, 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.EvaluatorInterfaceUNKNOWN_VALUE
 
- 
 - 
Constructor SummaryConstructors Constructor Description OpEvaluator()
 - 
Method SummaryAll Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description protected QDLSetapplyToSet(QDLStem lArg, QDLSet rArg, QDLValue defaultValue, State state, Dyad dyad)protected QDLStemapplyToStem(QDLStem lArg, QDLStem rArg, QDLValue defaultValue, State state, Dyad dyad)booleandispatch(Polyad polyad, State state)Does the actual evaluation of thePolyad.protected voiddoContainsKey(Dyad dyad, State state, boolean containsKey)protected voiddoDyadComparisonOperator(Dyad dyad, State state)protected voiddoDyadEqualsOperator(Dyad dyad, State state)protected voiddoDyadIntegerDivide(Dyad dyad, State state)protected voiddoDyadLogicalOperator(Dyad dyad, State state)protected voiddoDyadMinus(Dyad dyad, State state)protected voiddoDyadPlus(Dyad dyad, State state)For dyadic plus.protected voiddoDyadTimesOrDivide(Dyad dyad, State state, boolean doTimes)protected voiddoIsDefinedDyad(Dyad dyad, State state, boolean isDefined)protected voiddoMonadicTilde(Monad monad, State state, boolean isStile)protected voiddoMonadIncOrDec(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 voiddoMonadMinus(Monad monad, State state)protected voiddoMonadNot(Monad monad, State state)protected voiddoMonadPlus(Monad monad, State state)protected voiddoRegexMatch(Dyad dyad, State state)Contract is expression regex ≈ expression returns true if it matches expression as a string.protected voiddoSetUnionOrInteresection(Dyad dyad, State state)protected ObjectdoSingleApply(QDLValue lArg, DyadicFunctionReferenceNode fNode, QDLValue defaultValue, State state, Dyad dyad)protected QDLValuedoSingleApply(QDLValue lArg, FunctionReferenceNode fNode, State actualState)protected ObjectdoSingleApply(QDLValue lArg, FunctionReferenceNode fNode, QDLValue defaultValue, State state, Dyad dyad)apply the argument to a single function.protected voiddoTilde(Dyad dyad, State state)protected voiddoUnaryPlusMinus(Monad monad, State state, Long sign)This will evaluate the expression and take its opposite.voidevaluate(Dyad dyad, State state)voidevaluate(Monad monad, State state)voidevaluate(Nilad nilad, State state)booleanevaluate(Polyad polyad, State state)Decides if aPolyadis evaluated by this evaluator and if not, returns false, if so, it evaluates it and returns true.voidevaluate2(Dyad dyad, State state)voidevaluate2(Monad monad, State state)protected ObjectevaluateNextArgForApplies(QDLValue lArg, Object rArg, QDLValue defaultValue, State state, Dyad dyad)int[]getArgCount(String name)Return the arg counts for an operator.String[]getFunctionNames()static MathContextgetMathContext()StringgetNamespace()static intgetNumericDigits()intgetType(String oo)Given an operator, this will return the integer value associated with it for lookups later.booleanisMathOperator(String x)TreeSet<String>listFunctions(boolean listFQ)No listing for these yet since they are not the standard func() pattern, e.g.static voidsetNumericDigits(int newNumericDigits)- 
Methods inherited from class org.qdl_lang.evaluate.AbstractEvaluatorareAllBigDecimals, 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, NEWgetOperator, OLDgetOperator, process1, process2, process2, process3, processSet1, processSet2, processSet2, processStem1, processStem2, processStem3, resolveResourceToFile, tempFname, toBD, toConstants, toStem
 
- 
 
- 
- 
- 
Field Detail- 
ANDpublic static final String AND - See Also:
- Constant Field Values
 
 - 
AND2public static final String AND2 - See Also:
- Constant Field Values
 
 - 
ASSIGNMENTpublic static final String ASSIGNMENT - See Also:
- Constant Field Values
 
 - 
CEILINGpublic static final String CEILING - See Also:
- Constant Field Values
 
 - 
DIVIDEpublic static final String DIVIDE - See Also:
- Constant Field Values
 
 - 
DIVIDE2public static final String DIVIDE2 - See Also:
- Constant Field Values
 
 - 
EQUALSpublic static final String EQUALS - See Also:
- Constant Field Values
 
 - 
EQUALS2public static final String EQUALS2 - See Also:
- Constant Field Values
 
 - 
EXCISEpublic static final String EXCISE - See Also:
- Constant Field Values
 
 - 
FLOORpublic static final String FLOOR - See Also:
- Constant Field Values
 
 - 
INTEGER_DIVIDEpublic static final String INTEGER_DIVIDE - See Also:
- Constant Field Values
 
 - 
SYMMETRIC_DIFFERENCEpublic static final String SYMMETRIC_DIFFERENCE - See Also:
- Constant Field Values
 
 - 
LESS_THANpublic static final String LESS_THAN - See Also:
- Constant Field Values
 
 - 
LESS_THAN_EQUALpublic static final String LESS_THAN_EQUAL - See Also:
- Constant Field Values
 
 - 
LESS_THAN_EQUAL2public static final String LESS_THAN_EQUAL2 - See Also:
- Constant Field Values
 
 - 
LESS_THAN_EQUAL3public static final String LESS_THAN_EQUAL3 - See Also:
- Constant Field Values
 
 - 
MINUSpublic static final String MINUS - See Also:
- Constant Field Values
 
 - 
MINUS2public static final String MINUS2 - See Also:
- Constant Field Values
 
 - 
MINUS_MINUSpublic static final String MINUS_MINUS - See Also:
- Constant Field Values
 
 - 
MORE_THANpublic static final String MORE_THAN - See Also:
- Constant Field Values
 
 - 
MORE_THAN_EQUALpublic static final String MORE_THAN_EQUAL - See Also:
- Constant Field Values
 
 - 
MORE_THAN_EQUAL2public static final String MORE_THAN_EQUAL2 - See Also:
- Constant Field Values
 
 - 
MORE_THAN_EQUAL3public static final String MORE_THAN_EQUAL3 - See Also:
- Constant Field Values
 
 - 
NOTpublic static final String NOT - See Also:
- Constant Field Values
 
 - 
NOT2public static final String NOT2 - See Also:
- Constant Field Values
 
 - 
NOT_EQUALpublic static final String NOT_EQUAL - See Also:
- Constant Field Values
 
 - 
NOT_EQUAL2public static final String NOT_EQUAL2 - See Also:
- Constant Field Values
 
 - 
ORpublic static final String OR - See Also:
- Constant Field Values
 
 - 
OR2public static final String OR2 - See Also:
- Constant Field Values
 
 - 
PLUSpublic static final String PLUS - See Also:
- Constant Field Values
 
 - 
PLUS2public static final String PLUS2 - See Also:
- Constant Field Values
 
 - 
PLUS_PLUSpublic static final String PLUS_PLUS - See Also:
- Constant Field Values
 
 - 
POWERpublic static final String POWER - See Also:
- Constant Field Values
 
 - 
NROOTpublic static final String NROOT - See Also:
- Constant Field Values
 
 - 
UNIONpublic static final String UNION - See Also:
- Constant Field Values
 
 - 
UNION_2public static final String UNION_2 - See Also:
- Constant Field Values
 
 - 
INTERSECTIONpublic static final String INTERSECTION - See Also:
- Constant Field Values
 
 - 
INTERSECTION_2public static final String INTERSECTION_2 - See Also:
- Constant Field Values
 
 - 
TILDEpublic static final String TILDE - See Also:
- Constant Field Values
 
 - 
TILDE_STILEpublic static final String TILDE_STILE - See Also:
- Constant Field Values
 
 - 
TILDE_STILE2public static final String TILDE_STILE2 - See Also:
- Constant Field Values
 
 - 
TIMESpublic static final String TIMES - See Also:
- Constant Field Values
 
 - 
TIMES2public static final String TIMES2 - See Also:
- Constant Field Values
 
 - 
DOTpublic static final String DOT - See Also:
- Constant Field Values
 
 - 
REGEX_MATCHpublic static final String REGEX_MATCH - See Also:
- Constant Field Values
 
 - 
REGEX_MATCH2public static final String REGEX_MATCH2 - See Also:
- Constant Field Values
 
 - 
TO_SETpublic static final String TO_SET - See Also:
- Constant Field Values
 
 - 
TO_SET2public static final String TO_SET2 - See Also:
- Constant Field Values
 
 - 
EPSILONpublic static final String EPSILON - See Also:
- Constant Field Values
 
 - 
EPSILON_NOTpublic static final String EPSILON_NOT - See Also:
- Constant Field Values
 
 - 
IS_Apublic static final String IS_A - See Also:
- Constant Field Values
 
 - 
IS_DEFINEDpublic static final String IS_DEFINED - See Also:
- Constant Field Values
 
 - 
IS_NOT_DEFINEDpublic static final String IS_NOT_DEFINED - See Also:
- Constant Field Values
 
 - 
CONTAINS_KEYpublic static final String CONTAINS_KEY - See Also:
- Constant Field Values
 
 - 
NOT_CONTAINS_KEYpublic static final String NOT_CONTAINS_KEY - See Also:
- Constant Field Values
 
 - 
FOR_ALL_KEYpublic static final String FOR_ALL_KEY - See Also:
- Constant Field Values
 
 - 
MASK_OP_KEYpublic static final String MASK_OP_KEY - See Also:
- Constant Field Values
 
 - 
TRANSPOSE_OP_KEYpublic static final String TRANSPOSE_OP_KEY - See Also:
- Constant Field Values
 
 - 
REDUCE_OP_KEYpublic static final String REDUCE_OP_KEY - See Also:
- Constant Field Values
 
 - 
EXPAND_OP_KEYpublic static final String EXPAND_OP_KEY - See Also:
- Constant Field Values
 
 - 
APPLY_OP_KEYpublic static final String APPLY_OP_KEY - See Also:
- Constant Field Values
 
 - 
ASSIGNMENT_VALUEpublic static final int ASSIGNMENT_VALUE - See Also:
- Constant Field Values
 
 - 
PLUS_VALUEpublic static final int PLUS_VALUE - See Also:
- Constant Field Values
 
 - 
MINUS_VALUEpublic static final int MINUS_VALUE - See Also:
- Constant Field Values
 
 - 
PLUS_PLUS_VALUEpublic static final int PLUS_PLUS_VALUE - See Also:
- Constant Field Values
 
 - 
MINUS_MINUS_VALUEpublic static final int MINUS_MINUS_VALUE - See Also:
- Constant Field Values
 
 - 
AND_VALUEpublic static final int AND_VALUE - See Also:
- Constant Field Values
 
 - 
OR_VALUEpublic static final int OR_VALUE - See Also:
- Constant Field Values
 
 - 
EQUALS_VALUEpublic static final int EQUALS_VALUE - See Also:
- Constant Field Values
 
 - 
NOT_EQUAL_VALUEpublic static final int NOT_EQUAL_VALUE - See Also:
- Constant Field Values
 
 - 
LESS_THAN_VALUEpublic static final int LESS_THAN_VALUE - See Also:
- Constant Field Values
 
 - 
LESS_THAN_EQUAL_VALUEpublic static final int LESS_THAN_EQUAL_VALUE - See Also:
- Constant Field Values
 
 - 
MORE_THAN_VALUEpublic static final int MORE_THAN_VALUE - See Also:
- Constant Field Values
 
 - 
MORE_THAN_EQUAL_VALUEpublic static final int MORE_THAN_EQUAL_VALUE - See Also:
- Constant Field Values
 
 - 
NOT_VALUEpublic static final int NOT_VALUE - See Also:
- Constant Field Values
 
 - 
TIMES_VALUEpublic static final int TIMES_VALUE - See Also:
- Constant Field Values
 
 - 
DIVIDE_VALUEpublic static final int DIVIDE_VALUE - See Also:
- Constant Field Values
 
 - 
POWER_VALUEpublic static final int POWER_VALUE - See Also:
- Constant Field Values
 
 - 
INTEGER_DIVIDE_VALUEpublic static final int INTEGER_DIVIDE_VALUE - See Also:
- Constant Field Values
 
 - 
TILDE_VALUEpublic static final int TILDE_VALUE - See Also:
- Constant Field Values
 
 - 
DOT_VALUEpublic static final int DOT_VALUE - See Also:
- Constant Field Values
 
 - 
TILDE_STILE_VALUEpublic static final int TILDE_STILE_VALUE - See Also:
- Constant Field Values
 
 - 
REGEX_MATCH_VALUEpublic static final int REGEX_MATCH_VALUE - See Also:
- Constant Field Values
 
 - 
UNION_VALUEpublic static final int UNION_VALUE - See Also:
- Constant Field Values
 
 - 
INTERSECTION_VALUEpublic static final int INTERSECTION_VALUE - See Also:
- Constant Field Values
 
 - 
FLOOR_VALUEpublic static final int FLOOR_VALUE - See Also:
- Constant Field Values
 
 - 
CEILING_VALUEpublic static final int CEILING_VALUE - See Also:
- Constant Field Values
 
 - 
TO_SET_VALUEpublic static final int TO_SET_VALUE - See Also:
- Constant Field Values
 
 - 
EPSILON_VALUEpublic static final int EPSILON_VALUE - See Also:
- Constant Field Values
 
 - 
EPSILON_NOT_VALUEpublic static final int EPSILON_NOT_VALUE - See Also:
- Constant Field Values
 
 - 
IS_A_VALUEpublic static final int IS_A_VALUE - See Also:
- Constant Field Values
 
 - 
IS_DEFINED_VALUEpublic static final int IS_DEFINED_VALUE - See Also:
- Constant Field Values
 
 - 
IS_NOT_DEFINED_VALUEpublic static final int IS_NOT_DEFINED_VALUE - See Also:
- Constant Field Values
 
 - 
CONTAINS_KEY_VALUEpublic static final int CONTAINS_KEY_VALUE - See Also:
- Constant Field Values
 
 - 
NOT_CONTAINS_KEY_VALUEpublic static final int NOT_CONTAINS_KEY_VALUE - See Also:
- Constant Field Values
 
 - 
FOR_ALL_KEY_VALUEpublic static final int FOR_ALL_KEY_VALUE - See Also:
- Constant Field Values
 
 - 
MASK_OP_VALUEpublic static final int MASK_OP_VALUE - See Also:
- Constant Field Values
 
 - 
TRANSPOSE_OP_VALUEpublic static final int TRANSPOSE_OP_VALUE - See Also:
- Constant Field Values
 
 - 
REDUCE_OP_VALUEpublic static final int REDUCE_OP_VALUE - See Also:
- Constant Field Values
 
 - 
EXPAND_OP_VALUEpublic static final int EXPAND_OP_VALUE - See Also:
- Constant Field Values
 
 - 
APPLY_OP_VALUEpublic static final int APPLY_OP_VALUE - See Also:
- Constant Field Values
 
 - 
NROOT_VALUEpublic static final int NROOT_VALUE - See Also:
- Constant Field Values
 
 - 
EXCISE_VALUEpublic static final int EXCISE_VALUE - See Also:
- Constant Field Values
 
 - 
OTHER_MATH_OPSpublic static String[] OTHER_MATH_OPS This is for operators that are in the parser and never are created directly, e.g. → or #. "->"
 - 
ALL_MATH_OPSpublic static String[] ALL_MATH_OPS All Math operators. These are used in function references.
 - 
numericDigitspublic static int numericDigits 
 
- 
 - 
Method Detail- 
getArgCountpublic int[] getArgCount(String name) Return the arg counts for an operator.- Parameters:
- name-
- Returns:
 
 - 
getNamespacepublic String getNamespace() 
 - 
isMathOperatorpublic boolean isMathOperator(String x) 
 - 
getFunctionNamespublic String[] getFunctionNames() - Specified by:
- getFunctionNamesin class- AbstractEvaluator
 
 - 
getMathContextpublic static MathContext getMathContext() 
 - 
getNumericDigitspublic static int getNumericDigits() 
 - 
setNumericDigitspublic static void setNumericDigits(int newNumericDigits) 
 - 
listFunctionspublic TreeSet<String> listFunctions(boolean listFQ) No listing for these yet since they are not the standard func() pattern, e.g. a < b.- Specified by:
- listFunctionsin interface- EvaluatorInterface
- Overrides:
- listFunctionsin class- AbstractEvaluator
- Returns:
 
 - 
getTypepublic int getType(String oo) Given an operator, this will return the integer value associated with it for lookups later.ExpressionNodes store the value, not the operator.- Parameters:
- oo-
- Returns:
 
 - 
applyToSetprotected QDLSet applyToSet(QDLStem lArg, QDLSet rArg, QDLValue defaultValue, State state, Dyad dyad) 
 - 
evaluateNextArgForAppliesprotected Object evaluateNextArgForApplies(QDLValue lArg, Object rArg, QDLValue defaultValue, State state, Dyad dyad) 
 - 
applyToStemprotected QDLStem applyToStem(QDLStem lArg, QDLStem rArg, QDLValue defaultValue, State state, Dyad dyad) 
 - 
doSingleApplyprotected Object doSingleApply(QDLValue lArg, DyadicFunctionReferenceNode fNode, QDLValue defaultValue, State state, Dyad dyad) 
 - 
doSingleApplyprotected Object doSingleApply(QDLValue lArg, FunctionReferenceNode fNode, QDLValue 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:
 
 - 
doSingleApplyprotected QDLValue doSingleApply(QDLValue lArg, FunctionReferenceNode fNode, State actualState) 
 - 
doRegexMatchprotected void doRegexMatch(Dyad dyad, State state) Contract is expression regex ≈ expression returns true if it matches expression as a string.- Parameters:
- dyad-
- state-
 
 - 
doDyadPlusprotected void doDyadPlus(Dyad dyad, State state) For dyadic plus.- Parameters:
- dyad-
- state-
 
 - 
doMonadIncOrDecprotected 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-
 
 - 
doUnaryPlusMinusprotected 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-
 
 - 
evaluatepublic boolean evaluate(Polyad polyad, State state) Description copied from class:AbstractEvaluatorDecides if aPolyadis 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:
- evaluatein class- AbstractEvaluator
- Returns:
 
 - 
dispatchpublic boolean dispatch(Polyad polyad, State state) Description copied from class:AbstractEvaluatorDoes the actual evaluation of thePolyad.- Specified by:
- dispatchin class- AbstractEvaluator
- Returns:
 
 
- 
 
-