Class ATNConfig
- Direct Known Subclasses:
ATNConfig.ActionATNConfig,ATNConfig.SemanticContextATNConfig
- The current ATN state
- The predicted alternative
- The semantic context which must be true for this configuration to be enabled
- The syntactic context, which is represented as a graph-structured stack whose path(s) lead to the root of the rule invocations leading to this state.
In addition to these values, ATNConfig stores several properties
about paths taken to get to the location which were added over time to help
with performance, correctness, and/or debugging.
getReachesIntoOuterContext(): Used to ensure semantic predicates are not evaluated in the wrong context.hasPassedThroughNonGreedyDecision(): Used for enabling first-match-wins instead of longest-match-wins after crossing a non-greedy decision.getLexerActionExecutor(): Used for tracking the lexer action(s) to execute should this instance be selected during lexing.isPrecedenceFilterSuppressed(): A state variable for one of the dynamic disambiguation strategies employed byParserATNSimulator.applyPrecedenceFilter(org.antlr.v4.runtime.atn.ATNConfigSet, org.antlr.v4.runtime.ParserRuleContext, org.antlr.v4.runtime.atn.PredictionContextCache).
Due to the use of a graph-structured stack, a single ATNConfig is
capable of representing many individual ATN configurations which reached the
same location in an ATN by following different paths.
PERF: To conserve memory, ATNConfig is split into several
different concrete types. ATNConfig itself stores the minimum amount
of information typically used to define an ATNConfig instance.
Various derived types provide additional storage space for cases where a
non-default value is used for some of the object properties. The
create(org.antlr.v4.runtime.atn.ATNState, int, org.antlr.v4.runtime.atn.PredictionContext) and transform(org.antlr.v4.runtime.atn.ATNState, boolean) methods
automatically select the smallest concrete type capable of representing the
unique information for any given ATNConfig.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionprivate static classThis class was derived fromATNConfigpurely as a memory optimization.private static classThis class was derived fromATNConfig.SemanticContextATNConfigpurely as a memory optimization.private static classThis class was derived fromATNConfigpurely as a memory optimization. -
Field Summary
FieldsModifier and TypeFieldDescriptionprivate intThis is a bit-field currently containing the following values.private intLazily cachedhashCode()result.private PredictionContextThe stack of invoking states leading to the rule/states associated with this config.private final ATNStateThe ATN state associated with this configurationprivate static final intThis field stores the bit mask for implementing theisPrecedenceFilterSuppressed()property as a bit within the existingaltAndOuterContextDepthfield. -
Constructor Summary
ConstructorsModifierConstructorDescriptionprotectedATNConfig(ATNConfig c, ATNState state, PredictionContext context) protectedATNConfig(ATNState state, int alt, PredictionContext context) -
Method Summary
Modifier and TypeMethodDescriptionappendContext(int context, PredictionContextCache contextCache) appendContext(PredictionContext context, PredictionContextCache contextCache) private static booleancheckNonGreedyDecision(ATNConfig source, ATNState target) final ATNConfigclone()booleanstatic ATNConfigcreate(ATNState state, int alt, PredictionContext context) static ATNConfigcreate(ATNState state, int alt, PredictionContext context, SemanticContext semanticContext) static ATNConfigcreate(ATNState state, int alt, PredictionContext context, SemanticContext semanticContext, LexerActionExecutor lexerActionExecutor) booleanAn ATN configuration is equal to another if both have the same state, they predict the same alternative, and syntactic/semantic contexts are the same.booleanfinal intgetAlt()What alt (or lexer rule) is predicted by this configurationfinal PredictionContextfinal intWe cannot execute predicates dependent upon local context unless we know for sure we are in the correct context.final booleanfinal ATNStategetState()Gets the ATN state associated with this configurationinthashCode()booleanfinal booleanvoidsetContext(PredictionContext context) voidsetOuterContextDepth(int outerContextDepth) final voidsetPrecedenceFilterSuppressed(boolean value) Returns a graphical representation of the currentATNConfigin Graphviz format.toString()toString(Recognizer<?, ?> recog, boolean showAlt) toString(Recognizer<?, ?> recog, boolean showAlt, boolean showContext) final ATNConfigfinal ATNConfigtransform(ATNState state, LexerActionExecutor lexerActionExecutor, boolean checkNonGreedy) final ATNConfigtransform(ATNState state, PredictionContext context, boolean checkNonGreedy) private ATNConfigtransform(ATNState state, PredictionContext context, SemanticContext semanticContext, boolean checkNonGreedy, LexerActionExecutor lexerActionExecutor) final ATNConfigtransform(ATNState state, SemanticContext semanticContext, boolean checkNonGreedy)
-
Field Details
-
SUPPRESS_PRECEDENCE_FILTER
private static final int SUPPRESS_PRECEDENCE_FILTERThis field stores the bit mask for implementing theisPrecedenceFilterSuppressed()property as a bit within the existingaltAndOuterContextDepthfield.- See Also:
-
state
The ATN state associated with this configuration -
altAndOuterContextDepth
private int altAndOuterContextDepthThis is a bit-field currently containing the following values.- 0x00FFFFFF: Alternative
- 0x7F000000: Outer context depth
- 0x80000000: Suppress precedence filter
-
context
The stack of invoking states leading to the rule/states associated with this config. We track only those contexts pushed during execution of the ATN simulator. -
cachedHashCode
private int cachedHashCodeLazily cachedhashCode()result. Zero means "not yet computed" (or invalidated after a mutable field change). The hash algorithm is biased away from zero when the raw MurmurHash finishes at zero so a legitimate hash of zero cannot thrash the cache sentinel.PERF: Lexer
OrderedATNConfigSetkeys configs byhashCode(), parser epsilon-closure busy sets hash configs on every right-recursion / EOF* guard, and DFA state lookup hashes entire config sets. Caching avoids repeating MurmurHash over the same immutable-after-first-use field set on these hot paths.
-
-
Constructor Details
-
ATNConfig
-
ATNConfig
-
-
Method Details
-
create
public static ATNConfig create(@NotNull ATNState state, int alt, @Nullable PredictionContext context) -
create
public static ATNConfig create(@NotNull ATNState state, int alt, @Nullable PredictionContext context, @NotNull SemanticContext semanticContext) -
create
public static ATNConfig create(@NotNull ATNState state, int alt, @Nullable PredictionContext context, @NotNull SemanticContext semanticContext, LexerActionExecutor lexerActionExecutor) -
getState
Gets the ATN state associated with this configuration -
getAlt
public final int getAlt()What alt (or lexer rule) is predicted by this configuration -
getContext
-
setContext
-
getReachesIntoOuterContext
public final boolean getReachesIntoOuterContext() -
getOuterContextDepth
public final int getOuterContextDepth()We cannot execute predicates dependent upon local context unless we know for sure we are in the correct context. Because there is no way to do this efficiently, we simply cannot evaluate dependent predicates unless we are in the rule that initially invokes the ATN simulator.closure() tracks the depth of how far we dip into the outer context: depth > 0. Note that it may not be totally accurate depth since I don't ever decrement. TODO: make it a boolean then
-
setOuterContextDepth
public void setOuterContextDepth(int outerContextDepth) -
getLexerActionExecutor
-
getSemanticContext
-
hasPassedThroughNonGreedyDecision
public boolean hasPassedThroughNonGreedyDecision() -
clone
-
transform
-
transform
public final ATNConfig transform(@NotNull ATNState state, @NotNull SemanticContext semanticContext, boolean checkNonGreedy) -
transform
public final ATNConfig transform(@NotNull ATNState state, @Nullable PredictionContext context, boolean checkNonGreedy) -
transform
public final ATNConfig transform(@NotNull ATNState state, LexerActionExecutor lexerActionExecutor, boolean checkNonGreedy) -
transform
private ATNConfig transform(@NotNull ATNState state, @Nullable PredictionContext context, @NotNull SemanticContext semanticContext, boolean checkNonGreedy, LexerActionExecutor lexerActionExecutor) -
checkNonGreedyDecision
-
appendContext
-
appendContext
-
contains
Determines if thisATNConfigfully contains anotherATNConfig.An ATN configuration represents a position (including context) in an ATN during parsing. Since
ATNConfigstores the context as a graph, a singleATNConfiginstance is capable of representing many ATN configurations which are all in the same "location" but have different contexts. TheseATNConfiginstances are again merged when they are added to anATNConfigSet. This method supportsATNConfigSet.contains(java.lang.Object)by evaluating whether a particularATNConfigcontains all of the ATN configurations represented by anotherATNConfig.An
ATNConfiga contains anotherATNConfigb if all of the following conditions are met:- The configurations are in the same state (
getState()) - The configurations predict the same alternative
(
getAlt()) - The semantic context of a implies the semantic context of b (this method performs a weaker equality check)
- Joining the prediction contexts of a and b results in the prediction context of a
This method implements a conservative approximation of containment. As a result, when this method returns {code true} it is known that parsing from
subconfigcan only recognize a subset of the inputs which can be recognized starting at the currentATNConfig. However, due to the imprecise evaluation of implication for the semantic contexts, no assumptions can be made about the relationship between the configurations when this method returnsfalse.- Parameters:
subconfig- The sub configuration.- Returns:
trueif this configuration containssubconfig; otherwise,false.
- The configurations are in the same state (
-
isPrecedenceFilterSuppressed
public final boolean isPrecedenceFilterSuppressed() -
setPrecedenceFilterSuppressed
public final void setPrecedenceFilterSuppressed(boolean value) -
equals
An ATN configuration is equal to another if both have the same state, they predict the same alternative, and syntactic/semantic contexts are the same. -
equals
-
hashCode
public int hashCode() -
toDotString
Returns a graphical representation of the currentATNConfigin Graphviz format. The graph can be stored to a .dot file and then rendered to an image using Graphviz.- Returns:
- A Graphviz graph representing the current
ATNConfig.
-
toString
-
toString
-
toString
-