| java.lang.Object org.antlr.analysis.Label
Label | public class Label implements Comparable,Cloneable(Code) | | 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).
|
Field Summary | |
final public static int | DOWN | final public static int | EOF | final public static 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. | final public static int | EOT End of Token is like EOF for lexer rules. | final public static int | EPSILON | final public static String | EPSILON_STR | final public static int | INVALID | final public static int | MAX_CHAR_VALUE | final public static 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. | final public static int | MIN_CHAR_VALUE | final public static int | MIN_TOKEN_TYPE | final public static 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. | final public static int | SEMPRED | final public static int | SET | final public static int | UP | protected int | label The token type or character value; or, signifies special label. | protected IntSet | labelSet | protected SemanticContext | semanticContext A tree of semantic predicates from the grammar AST if label==SEMPRED. |
DOWN | final public static int DOWN(Code) | | |
EOF | final public static int EOF(Code) | | |
EOR_TOKEN_TYPE | final public static int EOR_TOKEN_TYPE(Code) | | 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.
|
EOT | final public static int EOT(Code) | | 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.
|
EPSILON | final public static int EPSILON(Code) | | |
INVALID | final public static int INVALID(Code) | | |
MAX_CHAR_VALUE | final public static int MAX_CHAR_VALUE(Code) | | |
MIN_ATOM_VALUE | final public static int MIN_ATOM_VALUE(Code) | | 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_VALUE | final public static int MIN_CHAR_VALUE(Code) | | |
MIN_TOKEN_TYPE | final public static int MIN_TOKEN_TYPE(Code) | | tokens and char range overlap; tokens are MIN_TOKEN_TYPE..n
|
NUM_FAUX_LABELS | final public static int NUM_FAUX_LABELS(Code) | | 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.
|
SEMPRED | final public static int SEMPRED(Code) | | label is a semantic predicate; implies label is epsilon also
|
SET | final public static int SET(Code) | | label is a set of tokens or char
|
UP | final public static int UP(Code) | | |
label | protected int label(Code) | | The token type or character value; or, signifies special label.
|
labelSet | protected IntSet labelSet(Code) | | A set of token types or character codes if label==SET
|
semanticContext | protected SemanticContext semanticContext(Code) | | A tree of semantic predicates from the grammar AST if label==SEMPRED.
In the NFA, labels will always be exactly one predicate, but the DFA
may have to combine a bunch of them as it collects predicates from
multiple NFA configurations into a single DFA state.
|
Label | public Label(int label)(Code) | | |
Label | public Label(GrammarAST predicateASTNode)(Code) | | Make a semantic predicate label
|
getAtom | public int getAtom()(Code) | | return the single atom label or INVALID if not a single atom
|
hashCode | public int hashCode()(Code) | | |
isAtom | public boolean isAtom()(Code) | | |
isEpsilon | public boolean isEpsilon()(Code) | | |
isSemanticPredicate | public boolean isSemanticPredicate()(Code) | | |
isSet | public boolean isSet()(Code) | | |
matches | public boolean matches(int atom)(Code) | | |
toString | public String toString()(Code) | | 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.
|
|
|