Package org.oristool.lello.ast
Class UnaryExpression
java.lang.Object
org.oristool.lello.ast.Expression
org.oristool.lello.ast.UnaryExpression
Represents a unary expression. Any string may serve as operator.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic enumRepresents which version of the operator is being used, either prefix or suffix. -
Field Summary
Fields inherited from class org.oristool.lello.ast.Expression
EPSILON -
Constructor Summary
ConstructorsConstructorDescriptionUnaryExpression(UnaryExpression.UnaryOperationType type, String op, Expression expr) Initializes a new unary expression. -
Method Summary
Modifier and TypeMethodDescriptioncopy()Creates a copy of this object.Evaluates this expression using the specified variable bindings.format(FormatVisitor visitor) Formats this expression.getExpr()Retrieves the operand expression.getOp()Retrieves the unary operator.getType()Retrieves the operator version.isOne()Checks whether this expression is equal to 1 (with respect to the EPSILON tolerance).isZero()Checks whether this expression is equal to 0 (with respect to the EPSILON tolerance).simplify(Bindings bindings, SymbolicVisitor visitor) Tries to simplify this expression.toString()Retrieves the names of all the variables appearing in this expression.Methods inherited from class org.oristool.lello.ast.Expression
isOneNumber, isOneNumber, isZeroNumber, isZeroNumber
-
Constructor Details
-
UnaryExpression
Initializes a new unary expression.- Parameters:
type- The operator version.op- The unary operator.expr- The operand expression.
-
-
Method Details
-
getType
Retrieves the operator version.- Returns:
- The operator version.
-
getOp
Retrieves the unary operator.- Returns:
- The unary operator.
-
getExpr
Retrieves the operand expression.- Returns:
- The operand expression.
-
eval
Description copied from class:ExpressionEvaluates this expression using the specified variable bindings. Calling this method does not alter this expression.It is important to note that this method will not attempt any kind of simplification on the expression, which means that all the variables appearing in it must be either bound or correspond to Java static fields defined somewhere; if this is not the case an exception will be thrown.
- Specified by:
evalin classExpression- Parameters:
bindings- Variable bindings.- Returns:
- The value of the expression.
-
simplify
Description copied from class:ExpressionTries to simplify this expression. Calling this method does not alter this expression.This method will not throw an exception if some variables appearing in the expression are not bound. However it may still be able to cancel a variable, if an appropriate rule is found.
- Specified by:
simplifyin classExpression- Parameters:
bindings- Variable bindings.visitor- The visitor implementing the simplification rules.- Returns:
- A simplified expression if an appropriate rule was found, the same expression otherwise.
-
isZero
Description copied from class:ExpressionChecks whether this expression is equal to 0 (with respect to the EPSILON tolerance).To decrease the probability that this method will return DONTKNOW, simplify or eval should be preventively called on this expression.
- Specified by:
isZeroin classExpression- Returns:
- YES if this expression is equal to 0, NO if it is not, DONTKNOW if it is not known.
-
isOne
Description copied from class:ExpressionChecks whether this expression is equal to 1 (with respect to the EPSILON tolerance).To decrease the probability that this method will return DONTKNOW, simplify or eval should be preventively called on this expression.
- Specified by:
isOnein classExpression- Returns:
- YES if this expression is equal to 1, NO if it is not, DONTKNOW if it is not known.
-
variables
Description copied from class:ExpressionRetrieves the names of all the variables appearing in this expression.- Specified by:
variablesin classExpression- Returns:
- set of variables
-
copy
Creates a copy of this object.- Specified by:
copyin classExpression- Returns:
- a copy
-
format
Description copied from class:ExpressionFormats this expression.- Overrides:
formatin classExpression- Parameters:
visitor- The visitor implementing the formatting rules.- Returns:
- The formatted string.
-
toString
- Overrides:
toStringin classExpression
-