Package com.tonic.analysis.source.parser
Enum Precedence
- java.lang.Object
-
- java.lang.Enum<Precedence>
-
- com.tonic.analysis.source.parser.Precedence
-
- All Implemented Interfaces:
Serializable,Comparable<Precedence>
public enum Precedence extends Enum<Precedence>
Java operator binding strengths, ordered from loosest (NONE) to tightest (PRIMARY).
-
-
Enum Constant Summary
Enum Constants Enum Constant Description ADDITIVEThe level of binary+and-.ANDThe level of the short-circuiting&&, binding tighter than||.ASSIGNMENTThe loosest operator level, covering plain assignment and every compound assignment; right-associative.BIT_ANDThe level of the single&, the tightest of the three bitwise levels.BIT_ORThe level of the single|, the loosest of the three bitwise levels.BIT_XORThe level of^, between bitwise or and bitwise and.COMPARISONThe relational level, covering the four ordering operators andinstanceof.EQUALITYThe level of==and!=, binding looser than the ordering comparisons.MULTIPLICATIVEThe level of*,/, and%.NONENo binding at all; the level reported for a token that is not an operator, which stops the parser from extending an expression.ORThe level of the short-circuiting||, the loosest binary operator.POSTFIXThe postfix level, covering++and--as well as member access, array indexing, and call parentheses.PRIMARYThe tightest level, above every operator; literals, names, and parenthesized expressions sit here.SHIFTThe level of the three shift operators.TERNARYThe conditional?:level, reached from the?token and right-associative like assignment.UNARYThe prefix operator level, covering negation, complement, prefix increment and decrement, and casts.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description intgetLevel()booleanisRightAssociative()static Precedenceof(TokenType type)Maps an operator token to the precedence at which it binds.static PrecedencevalueOf(String name)Returns the enum constant of this type with the specified name.static Precedence[]values()Returns an array containing the constants of this enum type, in the order they are declared.
-
-
-
Enum Constant Detail
-
NONE
public static final Precedence NONE
No binding at all; the level reported for a token that is not an operator, which stops the parser from extending an expression.
-
ASSIGNMENT
public static final Precedence ASSIGNMENT
The loosest operator level, covering plain assignment and every compound assignment; right-associative.
-
TERNARY
public static final Precedence TERNARY
The conditional?:level, reached from the?token and right-associative like assignment.
-
OR
public static final Precedence OR
The level of the short-circuiting||, the loosest binary operator.
-
AND
public static final Precedence AND
The level of the short-circuiting&&, binding tighter than||.
-
BIT_OR
public static final Precedence BIT_OR
The level of the single|, the loosest of the three bitwise levels.
-
BIT_XOR
public static final Precedence BIT_XOR
The level of^, between bitwise or and bitwise and.
-
BIT_AND
public static final Precedence BIT_AND
The level of the single&, the tightest of the three bitwise levels.
-
EQUALITY
public static final Precedence EQUALITY
The level of==and!=, binding looser than the ordering comparisons.
-
COMPARISON
public static final Precedence COMPARISON
The relational level, covering the four ordering operators andinstanceof.
-
SHIFT
public static final Precedence SHIFT
The level of the three shift operators.
-
ADDITIVE
public static final Precedence ADDITIVE
The level of binary+and-.
-
MULTIPLICATIVE
public static final Precedence MULTIPLICATIVE
The level of*,/, and%.
-
UNARY
public static final Precedence UNARY
The prefix operator level, covering negation, complement, prefix increment and decrement, and casts.
-
POSTFIX
public static final Precedence POSTFIX
The postfix level, covering++and--as well as member access, array indexing, and call parentheses.
-
PRIMARY
public static final Precedence PRIMARY
The tightest level, above every operator; literals, names, and parenthesized expressions sit here.
-
-
Method Detail
-
values
public static Precedence[] values()
Returns an array containing the constants of this enum type, in the order they are declared. This method may be used to iterate over the constants as follows:for (Precedence c : Precedence.values()) System.out.println(c);
- Returns:
- an array containing the constants of this enum type, in the order they are declared
-
valueOf
public static Precedence valueOf(String name)
Returns the enum constant of this type with the specified name. The string must match exactly an identifier used to declare an enum constant in this type. (Extraneous whitespace characters are not permitted.)- Parameters:
name- the name of the enum constant to be returned.- Returns:
- the enum constant with the specified name
- Throws:
IllegalArgumentException- if this enum type has no constant with the specified nameNullPointerException- if the argument is null
-
getLevel
public int getLevel()
- Returns:
- the level
-
of
public static Precedence of(TokenType type)
Maps an operator token to the precedence at which it binds.- Parameters:
type- the token to classify- Returns:
- the matching precedence, or NONE when the token is not an operator
-
isRightAssociative
public boolean isRightAssociative()
- Returns:
- true for assignment and ternary, the two right-associative levels
-
-