Package org.scijava.parsington
Class Operator
java.lang.Object
org.scijava.parsington.Token
org.scijava.parsington.Operator
- All Implemented Interfaces:
Comparable<Operator>
A mathematical operator is a special symbol or "verb" which defines a
relation between "nouns" (i.e.: literals and variables). For binary
operators, it is infix (between the nouns); for unary operators, it is either
prefix (preceding the noun) or postfix (following the noun).
- Author:
- Curtis Rueden
-
Nested Class Summary
Nested Classes -
Constructor Summary
ConstructorsConstructorDescriptionOperator
(String symbol, int arity, Operator.Associativity associativity, double precedence) -
Method Summary
Modifier and TypeMethodDescriptionint
int
getArity()
Gets the operator's arity.Gets the operator's associativity.double
Gets the operator precedence.instance()
Gets an instance of the operator, using this one as a template.boolean
isInfix()
Gets whether the operator is an infix operator (e.g.,a-b
).boolean
Gets whether the operator is left associative.boolean
Gets whether the operator is a postfix operator (e.g.,a'
).boolean
isPrefix()
Gets whether the operator is a prefix operator (e.g.,-a
).boolean
Gets whether the operator is right associative.
-
Constructor Details
-
Operator
-
-
Method Details
-
getArity
public int getArity()Gets the operator's arity.- Returns:
- The arity of the operator: 1 for unary, 2 for binary, etc.
-
getAssociativity
Gets the operator's associativity. -
isLeftAssociative
public boolean isLeftAssociative()Gets whether the operator is left associative.- Returns:
- True iff the operator's associativity is
Operator.Associativity.LEFT
orOperator.Associativity.EITHER
.
-
isRightAssociative
public boolean isRightAssociative()Gets whether the operator is right associative.- Returns:
- True iff the operator's associativity is
Operator.Associativity.RIGHT
orOperator.Associativity.EITHER
.
-
isInfix
public boolean isInfix()Gets whether the operator is an infix operator (e.g.,a-b
).- Returns:
- True iff the operator is an infix operator.
-
isPrefix
public boolean isPrefix()Gets whether the operator is a prefix operator (e.g.,-a
).- Returns:
- True iff the operator is a prefix operator.
-
isPostfix
public boolean isPostfix()Gets whether the operator is a postfix operator (e.g.,a'
).- Returns:
- True iff the operator is a postfix operator.
-
getPrecedence
public double getPrecedence()Gets the operator precedence. Larger is higher.- Returns:
- The operator precedence.
-
instance
Gets an instance of the operator, using this one as a template.For stateless operators, no copy will be made. But for operators with state (e.g.
Group
), a new instance will be returned.- Returns:
this
or a new instance, depending on the type of operator.
-
compareTo
- Specified by:
compareTo
in interfaceComparable<Operator>
-