Class OverloadedOperator
- All Implemented Interfaces:
Serializable
OverloadResolver
will substitute the appropriate one when it visits the node.- See Also:
-
Field Summary
Fields inherited from class com.singularsys.jep.Operator
ASSOCIATIVE, BINARY, COMMUTATIVE, COMPOSITE, EQUIVALENCE, flags, key, LEFT, name, NARY, NO_ARGS, NOT_IN_PARSER, pfmc, precedence, PREFIX, printSymbol, REFLEXIVE, RIGHT, SELF_INVERSE, SUFFIX, symbol, SYMMETRIC, TERNARY, TRANSITIVE, UNARY, USE_BINDING_FOR_PRINT -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic voidapplyPrintRules(OverloadedOperator op, Jep jep) Apply thePrintVisitor.PrintRulesIto an operators created usingextendOperator(OperatorTable2, PostfixMathCommandI, Operator, Predicate, OperatorKey, OperatorKey, OperatorKey).static OverloadedOperatorextendOperator(Jep jep, PostfixMathCommandI fun1, Operator originalOp, Predicate<Node> pred, EmptyOperatorTable.OperatorKey overKey, EmptyOperatorTable.OperatorKey altKey, EmptyOperatorTable.OperatorKey origKey) Extends an existing operator to form an overloaded operator, using a additional function and predicate, and add them to the Jep instance.static OverloadedOperatorextendOperator(OperatorTable2 ot, PostfixMathCommandI fun1, Operator originalOp, Predicate<Node> pred, EmptyOperatorTable.OperatorKey overKey, EmptyOperatorTable.OperatorKey altKey, EmptyOperatorTable.OperatorKey originalKey) Extends an existing operator to form an overloaded operator, using a additional function and predicate, and add them to the OperatorTable, does not set the PrintRules.getOp1()getOp2()Run the predicate against a node, returning the corresponding operator.Methods inherited from class com.singularsys.jep.Operator
addAltSymbol, duplicate, getAltSymbols, getBinaryInverseOp, getBinding, getFlags, getInverseOp, getKey, getName, getPFMC, getPrecedence, getPrintSymbol, getRootOp, getSymbol, isAssociative, isBinary, isCommutative, isComposite, isDistributiveOver, isEquivalence, isLeftBinding, isNary, isPrefix, isReflexive, isRightBinding, isSelfInverse, isSuffix, isSymmetric, isTernary, isTransitive, isUnary, notInParser, numArgs, setBinaryInverseOp, setDistributiveOver, setFlag, setInverseOp, setKey, setPFMC, setPrecedence, setPrintSymbol, setRootOp, setSymbol, toFullString, toString, useBindingForPrint
-
Constructor Details
-
OverloadedOperator
public OverloadedOperator(String name, String symbol, Operator op1, Operator op2, Predicate<Node> pred, int flags, int prec) Constructor. The two component operators should both have the same symbol and precedence. The flags for all three operators should be the same, apart from the NOT_IN_PARSER flag which should be set for the two component operators, and unset for the overloaded operator. All three operators should be added to the operator table.- Parameters:
name- unique name of the operatorsymbol- the symbol for the operatorop1- the first operator, used if the predicate returns trueop2- the second operator, used if the predicate returns falsepred- a predicate that tests the structure of the parse treeflags- the flags for the operator, seeOperatorprec- the precedence of the operator
-
-
Method Details
-
getOp1
-
getOp2
-
getPredicate
-
getOpFor
Run the predicate against a node, returning the corresponding operator.- Parameters:
n- node to test- Returns:
- the selected operator
-
extendOperator
public static OverloadedOperator extendOperator(Jep jep, PostfixMathCommandI fun1, Operator originalOp, Predicate<Node> pred, EmptyOperatorTable.OperatorKey overKey, EmptyOperatorTable.OperatorKey altKey, EmptyOperatorTable.OperatorKey origKey) Extends an existing operator to form an overloaded operator, using a additional function and predicate, and add them to the Jep instance.This method creates three operators:
- The original operator that will be used when the predicate returns false.
- An alternate operator that will be used when the predicate returns true. This uses the supplied PostfixMathCommand.
- An OverloadedOperator that will be used in parsing.
The three operators share the same, precedence, symbol and flags but the first two have the NO_IN_PARSER flag set. All three operators are added to the operator table. If the PrintVisitor has a special rule for the original operator then rules are also added for the alternate operator and overloaded operator. Names for alternate operator and overloaded operator are constructed using message properties.
- Parameters:
jep- Jep instancefun1- pfmc used by first operatororiginalOp- existing operatorpred- predicate used to test the nodeoverKey- key for the overloaded operatoraltKey- key for the alternate operatororigKey- key for the original operator- Returns:
- a new OverloadedOperator
-
applyPrintRules
Apply thePrintVisitor.PrintRulesIto an operators created usingextendOperator(OperatorTable2, PostfixMathCommandI, Operator, Predicate, OperatorKey, OperatorKey, OperatorKey). This method takes the rule, if specified, for the second operator and applies it to the root operator and the second operator.- Parameters:
op-jep-
-
extendOperator
public static OverloadedOperator extendOperator(OperatorTable2 ot, PostfixMathCommandI fun1, Operator originalOp, Predicate<Node> pred, EmptyOperatorTable.OperatorKey overKey, EmptyOperatorTable.OperatorKey altKey, EmptyOperatorTable.OperatorKey originalKey) Extends an existing operator to form an overloaded operator, using a additional function and predicate, and add them to the OperatorTable, does not set the PrintRules.This method creates three operators:
- The original operator that will be used when the predicate returns false.
- An alternate operator that will be used when the predicate returns true. This uses the supplied PostfixMathCommand.
- An OverloadedOperator that will be used in parsing.
The three operators share the same, precedence, symbol and flags but the first two have the NO_IN_PARSER flag set. All three operators are added to the operator table. Names for alternate operator and overloaded operator are constructed using message properties.
If the
PrintVisitor.PrintRulesIof the operators need to be set callapplyPrintRules(OverloadedOperator, Jep)when the Jep instance is available.- Parameters:
ot- the operator table to which the operators should be addedfun1- pfmc used by first operatororiginalOp- existing operatorpred- predicate used to test the nodeoverKey- key for the overloaded operatoraltKey- key for the alternate operatororiginalKey- key for the original operator- Returns:
- a new OverloadedOperator
-