Top Description Fields Constructors Methods
org.antlr.analysis

public Class Label

extends Object
implements Comparable<Label>, Cloneable
Class Inheritance
All Implemented Interfaces
java.lang.Cloneable, java.lang.Comparable
Known Direct Subclasses
org.antlr.analysis.PredicateLabel, org.antlr.analysis.ActionLabel
Imports
org.antlr.misc.IntSet, .IntervalSet, org.antlr.tool.Grammar

A state machine transition label. A label can be either a simple label such as a token or character. A label can be a set of char or tokens. It can be an epsilon transition. It can be a semantic predicate (which assumes an epsilon transition) or a tree of predicates (in a DFA). Special label types have to be < 0 to avoid conflict with char.

Field Summary

Modifier and TypeField and Description
public static final int
public static final int
public static final int
public static final int
EOR_TOKEN_TYPE

End of rule token type; imaginary token type used only for local, partial FOLLOW sets to indicate that the local FOLLOW hit the end of rule.

public static final int
EOT

End of Token is like EOF for lexer rules.

public static final int
public static final String
public static final int
protected int
label

The token type or character value; or, signifies special label.

protected IntSet
labelSet

A set of token types or character codes if label==SET

public static final int
public static final int
MIN_ATOM_VALUE

Anything at this value or larger can be considered a simple atom int for easy comparison during analysis only; faux labels are not used during parse time for real token types or char values.

public static final int
public static final int
MIN_TOKEN_TYPE

tokens and char range overlap; tokens are MIN_TOKEN_TYPE..n

public static final int
NUM_FAUX_LABELS

We have labels like EPSILON that are below 0; it's hard to store them in an array with negative index so use this constant as an index shift when accessing arrays based upon token type.

public static final int
SEMPRED

label is a semantic predicate; implies label is epsilon also

public static final int
SET

label is a set of tokens or char

public static final int

Constructor Summary

AccessConstructor and Description
public
Label(int label)

public
Label(IntSet labelSet)

Make a set label

Method Summary

Modifier and TypeMethod and Description
public void
public Object
clone()

Overrides java.lang.Object.clone.

Creates and returns a copy of this object.
public int
compareTo(Label
the object to be compared.
o
)

Implements java.lang.Comparable.compareTo.

Compares this object with the specified object for order.
public boolean
equals(Object
the reference object with which to compare.
o
)

Overrides java.lang.Object.equals.

Indicates whether some other object is "equal to" this one.
public int
getAtom()

return the single atom label or INVALID if not a single atom

public SemanticContext
public IntSet
public int
hashCode()

Overrides java.lang.Object.hashCode.

Returns a hash code value for this object.
public static boolean
intersect(Label label, Label edgeLabel)

public boolean
public boolean
public boolean
public boolean
public boolean
public boolean
matches(int atom)

public boolean
public boolean
matches(Label other)

public void
public String
toString()

Overrides java.lang.Object.toString.

Predicates are lists of AST nodes from the NFA created from the grammar, but the same predicate could be cut/paste into multiple places in the grammar.
public String
Inherited from java.lang.Object:
finalizegetClassnotifynotifyAllwaitwaitwait

Field Detail

ACTIONback to summary
public static final int ACTION
DOWNback to summary
public static final int DOWN
EOFback to summary
public static final int EOF
EOR_TOKEN_TYPEback to summary
public static final int EOR_TOKEN_TYPE

End of rule token type; imaginary token type used only for local, partial FOLLOW sets to indicate that the local FOLLOW hit the end of rule. During error recovery, the local FOLLOW of a token reference may go beyond the end of the rule and have to use FOLLOW(rule). I have to just shift the token types to 2..n rather than 1..n to accommodate this imaginary token in my bitsets. If I didn't use a bitset implementation for runtime sets, I wouldn't need this. EOF is another candidate for a run time token type for parsers. Follow sets are not computed for lexers so we do not have this issue.

EOTback to summary
public static final int EOT

End of Token is like EOF for lexer rules. It implies that no more characters are available and that NFA conversion should terminate for this path. For example A : 'a' 'b' | 'a' ; yields a DFA predictor: o-a->o-b->1 predict alt 1 | |-EOT->o predict alt 2 To generate code for EOT, treat it as the "default" path, which implies there is no way to mismatch a char for the state from which the EOT emanates.

EPSILONback to summary
public static final int EPSILON
EPSILON_STRback to summary
public static final String EPSILON_STR
INVALIDback to summary
public static final int INVALID
labelback to summary
protected int label

The token type or character value; or, signifies special label.

labelSetback to summary
protected IntSet labelSet

A set of token types or character codes if label==SET

MAX_CHAR_VALUEback to summary
public static final int MAX_CHAR_VALUE
MIN_ATOM_VALUEback to summary
public static final int MIN_ATOM_VALUE

Anything at this value or larger can be considered a simple atom int for easy comparison during analysis only; faux labels are not used during parse time for real token types or char values.

MIN_CHAR_VALUEback to summary
public static final int MIN_CHAR_VALUE
MIN_TOKEN_TYPEback to summary
public static final int MIN_TOKEN_TYPE

tokens and char range overlap; tokens are MIN_TOKEN_TYPE..n

NUM_FAUX_LABELSback to summary
public static final int NUM_FAUX_LABELS

We have labels like EPSILON that are below 0; it's hard to store them in an array with negative index so use this constant as an index shift when accessing arrays based upon token type. If real token type is i, then array index would be NUM_FAUX_LABELS + i.

SEMPREDback to summary
public static final int SEMPRED

label is a semantic predicate; implies label is epsilon also

SETback to summary
public static final int SET

label is a set of tokens or char

UPback to summary
public static final int UP

Constructor Detail

Labelback to summary
public Label(int label)
Labelback to summary
public Label(IntSet labelSet)

Make a set label

Method Detail

addback to summary
public void add(Label a)
cloneback to summary
public Object clone()

Overrides java.lang.Object.clone.

Doc from java.lang.Object.clone.

Creates and returns a copy of this object. The precise meaning of "copy" may depend on the class of the object. The general intent is that, for any object x, the expression:

x.clone() != x
will be true, and that the expression:
x.clone().getClass() == x.getClass()
will be true, but these are not absolute requirements. While it is typically the case that:
x.clone().equals(x)
will be true, this is not an absolute requirement.

By convention, the returned object should be obtained by calling super.clone. If a class and all of its superclasses (except Object) obey this convention, it will be the case that x.clone().getClass() == x.getClass().

By convention, the object returned by this method should be independent of this object (which is being cloned). To achieve this independence, it may be necessary to modify one or more fields of the object returned by super.clone before returning it. Typically, this means copying any mutable objects that comprise the internal "deep structure" of the object being cloned and replacing the references to these objects with references to the copies. If a class contains only primitive fields or references to immutable objects, then it is usually the case that no fields in the object returned by super.clone need to be modified.

Returns:Object

a clone of this instance.

Annotations
@Override
compareToback to summary
public int compareTo(Label o)

Implements java.lang.Comparable.compareTo.

Doc from java.lang.Comparable.compareTo.

Compares this object with the specified object for order. Returns a negative integer, zero, or a positive integer as this object is less than, equal to, or greater than the specified object.

The implementor must ensure signum(x.compareTo(y)) == -signum(y.compareTo(x)) for all x and y. (This implies that x.compareTo(y) must throw an exception if and only if y.compareTo(x) throws an exception.)

The implementor must also ensure that the relation is transitive: (x.compareTo(y) > 0 && y.compareTo(z) > 0) implies x.compareTo(z) > 0.

Finally, the implementor must ensure that x.compareTo(y)==0 implies that signum(x.compareTo(z)) == signum(y.compareTo(z)), for all z.

Parameters
o:Label

the object to be compared.

Returns:int

a negative integer, zero, or a positive integer as this object is less than, equal to, or greater than the specified object.

Annotations
@Override
equalsback to summary
public boolean equals(Object o)

Overrides java.lang.Object.equals.

Doc from java.lang.Object.equals.

Indicates whether some other object is "equal to" this one.

The equals method implements an equivalence relation on non-null object references:

  • It is reflexive: for any non-null reference value x, x.equals(x) should return true.
  • It is symmetric: for any non-null reference values x and y, x.equals(y) should return true if and only if y.equals(x) returns true.
  • It is transitive: for any non-null reference values x, y, and z, if x.equals(y) returns true and y.equals(z) returns true, then x.equals(z) should return true.
  • It is consistent: for any non-null reference values x and y, multiple invocations of x.equals(y) consistently return true or consistently return false, provided no information used in equals comparisons on the objects is modified.
  • For any non-null reference value x, x.equals(null) should return false.

An equivalence relation partitions the elements it operates on into equivalence classes; all the members of an equivalence class are equal to each other. Members of an equivalence class are substitutable for each other, at least for some purposes.

Parameters
o:Object

the reference object with which to compare.

Returns:boolean

true if this object is the same as the obj argument; false otherwise.

Annotations
@Override
getAtomback to summary
public int getAtom()

return the single atom label or INVALID if not a single atom

getSemanticContextback to summary
public SemanticContext getSemanticContext()
getSetback to summary
public IntSet getSet()
hashCodeback to summary
public int hashCode()

Overrides java.lang.Object.hashCode.

Doc from java.lang.Object.hashCode.

Returns a hash code value for this object. This method is supported for the benefit of hash tables such as those provided by java.util.HashMap.

The general contract of hashCode is:

  • Whenever it is invoked on the same object more than once during an execution of a Java application, the hashCode method must consistently return the same integer, provided no information used in equals comparisons on the object is modified. This integer need not remain consistent from one execution of an application to another execution of the same application.
  • If two objects are equal according to the equals method, then calling the hashCode method on each of the two objects must produce the same integer result.
  • It is not required that if two objects are unequal according to the equals method, then calling the hashCode method on each of the two objects must produce distinct integer results. However, the programmer should be aware that producing distinct integer results for unequal objects may improve the performance of hash tables.
Returns:int

a hash code value for this object

Annotations
@Override
intersectback to summary
public static boolean intersect(Label label, Label edgeLabel)
isActionback to summary
public boolean isAction()
isAtomback to summary
public boolean isAtom()
isEpsilonback to summary
public boolean isEpsilon()
isSemanticPredicateback to summary
public boolean isSemanticPredicate()
isSetback to summary
public boolean isSet()
matchesback to summary
public boolean matches(int atom)
matchesback to summary
public boolean matches(IntSet set)
matchesback to summary
public boolean matches(Label other)
setSetback to summary
public void setSet(IntSet set)
toStringback to summary
public String toString()

Overrides java.lang.Object.toString.

Predicates are lists of AST nodes from the NFA created from the grammar, but the same predicate could be cut/paste into multiple places in the grammar. I must compare the text of all the predicates to truly answer whether {p1,p2} .equals {p1,p2}. Unfortunately, I cannot rely on the AST.equals() to work properly so I must do a brute force O(n^2) nested traversal of the Set doing a String compare. At this point, Labels are not compared for equals when they are predicates, but here's the code for future use.

Returns:String

Doc from java.lang.Object.toString.

a string representation of the object

Annotations
@Override
toStringback to summary
public String toString(Grammar g)