public class ParserATNSimulator extends ATNSimulator
Modifier and Type | Field and Description |
---|---|
protected TokenStream |
_input |
protected ParserRuleContext |
_outerContext |
protected int |
_startIndex |
static boolean |
debug |
static boolean |
debug_list_atn_decisions |
DFA[] |
decisionToDFA |
static boolean |
dfa_debug |
protected DoubleKeyMap<PredictionContext,PredictionContext,PredictionContext> |
mergeCache
Each prediction operation uses a cache for merge of prediction contexts.
|
protected Parser |
parser |
static boolean |
retry_debug |
atn, ERROR, SERIALIZED_UUID, SERIALIZED_VERSION, sharedContextCache
Constructor and Description |
---|
ParserATNSimulator(ATN atn,
DFA[] decisionToDFA,
PredictionContextCache sharedContextCache)
Testing only!
|
ParserATNSimulator(Parser parser,
ATN atn,
DFA[] decisionToDFA,
PredictionContextCache sharedContextCache) |
Modifier and Type | Method and Description |
---|---|
protected ATNConfig |
actionTransition(ATNConfig config,
ActionTransition t) |
int |
adaptivePredict(TokenStream input,
int decision,
ParserRuleContext outerContext) |
protected DFAState |
addDFAEdge(DFA dfa,
DFAState from,
int t,
DFAState to)
Add an edge to the DFA, if possible.
|
protected DFAState |
addDFAState(DFA dfa,
DFAState D)
Add state
D to the DFA if it is not already present, and return
the actual instance stored in the DFA. |
protected void |
closure_(ATNConfig config,
ATNConfigSet configs,
Set<ATNConfig> closureBusy,
boolean collectPredicates,
boolean fullCtx,
int depth)
Do the actual work of walking epsilon edges
|
protected void |
closure(ATNConfig config,
ATNConfigSet configs,
Set<ATNConfig> closureBusy,
boolean collectPredicates,
boolean fullCtx) |
protected void |
closureCheckingStopState(ATNConfig config,
ATNConfigSet configs,
Set<ATNConfig> closureBusy,
boolean collectPredicates,
boolean fullCtx,
int depth) |
protected ATNConfigSet |
computeReachSet(ATNConfigSet closure,
int t,
boolean fullCtx) |
protected ATNConfigSet |
computeStartState(ATNState p,
RuleContext ctx,
boolean fullCtx) |
protected DFAState |
computeTargetState(DFA dfa,
DFAState previousD,
int t)
Compute a target state for an edge in the DFA, and attempt to add the
computed state and corresponding edge to the DFA.
|
void |
dumpDeadEndConfigs(NoViableAltException nvae)
Used for debugging in adaptivePredict around execATN but I cut
it out for clarity now that alg.
|
protected BitSet |
evalSemanticContext(DFAState.PredPrediction[] predPredictions,
ParserRuleContext outerContext,
boolean complete)
Look through a list of predicate/alt pairs, returning alts for the
pairs that win.
|
protected int |
execATN(DFA dfa,
DFAState s0,
TokenStream input,
int startIndex,
ParserRuleContext outerContext)
Performs ATN simulation to compute a predicted alternative based
upon the remaining input, but also updates the DFA cache to avoid
having to traverse the ATN again for the same input sequence.
|
protected int |
execATNWithFullContext(DFA dfa,
DFAState D,
ATNConfigSet s0,
TokenStream input,
int startIndex,
ParserRuleContext outerContext) |
protected int |
getAltThatFinishedDecisionEntryRule(ATNConfigSet configs) |
protected BitSet |
getConflictingAlts(ATNConfigSet configs) |
protected BitSet |
getConflictingAltsOrUniqueAlt(ATNConfigSet configs)
Sam pointed out a problem with the previous definition, v3, of
ambiguous states.
|
protected ATNConfig |
getEpsilonTarget(ATNConfig config,
Transition t,
boolean collectPredicates,
boolean inContext,
boolean fullCtx) |
protected DFAState |
getExistingTargetState(DFAState previousD,
int t)
Get an existing target state for an edge in the DFA.
|
String |
getLookaheadName(TokenStream input) |
protected DFAState.PredPrediction[] |
getPredicatePredictions(BitSet ambigAlts,
SemanticContext[] altToPred) |
PredictionMode |
getPredictionMode() |
protected SemanticContext[] |
getPredsForAmbigAlts(BitSet ambigAlts,
ATNConfigSet configs,
int nalts) |
protected ATNState |
getReachableTarget(Transition trans,
int ttype) |
String |
getRuleName(int index) |
String |
getTokenName(int t) |
protected static int |
getUniqueAlt(ATNConfigSet configs) |
protected NoViableAltException |
noViableAlt(TokenStream input,
ParserRuleContext outerContext,
ATNConfigSet configs,
int startIndex) |
protected void |
predicateDFAState(DFAState dfaState,
DecisionState decisionState) |
protected ATNConfig |
predTransition(ATNConfig config,
PredicateTransition pt,
boolean collectPredicates,
boolean inContext,
boolean fullCtx) |
protected ATNConfigSet |
removeAllConfigsNotInRuleStopState(ATNConfigSet configs,
boolean lookToEndOfRule)
Return a configuration set containing only the configurations from
configs which are in a RuleStopState . |
protected void |
reportAmbiguity(DFA dfa,
DFAState D,
int startIndex,
int stopIndex,
boolean exact,
BitSet ambigAlts,
ATNConfigSet configs)
If context sensitive parsing, we know it's ambiguity not conflict
|
protected void |
reportAttemptingFullContext(DFA dfa,
BitSet conflictingAlts,
ATNConfigSet configs,
int startIndex,
int stopIndex) |
protected void |
reportContextSensitivity(DFA dfa,
int prediction,
ATNConfigSet configs,
int startIndex,
int stopIndex) |
void |
reset() |
protected ATNConfig |
ruleTransition(ATNConfig config,
RuleTransition t) |
void |
setPredictionMode(PredictionMode mode) |
checkCondition, checkCondition, deserialize, edgeFactory, getCachedContext, getSharedContextCache, stateFactory, toInt, toInt32, toLong, toUUID
public static final boolean debug
public static final boolean debug_list_atn_decisions
public static final boolean dfa_debug
public static final boolean retry_debug
protected DoubleKeyMap<PredictionContext,PredictionContext,PredictionContext> mergeCache
protected TokenStream _input
protected int _startIndex
protected ParserRuleContext _outerContext
public ParserATNSimulator(@NotNull ATN atn, @NotNull DFA[] decisionToDFA, @NotNull PredictionContextCache sharedContextCache)
public void reset()
reset
in class ATNSimulator
public int adaptivePredict(@NotNull TokenStream input, int decision, @Nullable ParserRuleContext outerContext)
protected int execATN(@NotNull DFA dfa, @NotNull DFAState s0, @NotNull TokenStream input, int startIndex, ParserRuleContext outerContext)
@Nullable protected DFAState getExistingTargetState(@NotNull DFAState previousD, int t)
null
.previousD
- The current DFA statet
- The next input symbolt
, or null
if the target state for this edge is not
already cached@NotNull protected DFAState computeTargetState(@NotNull DFA dfa, @NotNull DFAState previousD, int t)
dfa
- The DFApreviousD
- The current DFA statet
- The next input symbolt
. If t
does not lead to a valid DFA state, this method
returns ATNSimulator.ERROR
.protected void predicateDFAState(DFAState dfaState, DecisionState decisionState)
protected int execATNWithFullContext(DFA dfa, DFAState D, @NotNull ATNConfigSet s0, @NotNull TokenStream input, int startIndex, ParserRuleContext outerContext)
protected ATNConfigSet computeReachSet(ATNConfigSet closure, int t, boolean fullCtx)
@NotNull protected ATNConfigSet removeAllConfigsNotInRuleStopState(@NotNull ATNConfigSet configs, boolean lookToEndOfRule)
configs
which are in a RuleStopState
. If all
configurations in configs
are already in a rule stop state, this
method simply returns configs
.
When lookToEndOfRule
is true, this method uses
ATN.nextTokens(org.antlr.v4.runtime.atn.ATNState, org.antlr.v4.runtime.RuleContext)
for each configuration in configs
which is
not already in a rule stop state to see if a rule stop state is reachable
from the configuration via epsilon-only transitions.configs
- the configuration set to updatelookToEndOfRule
- when true, this method checks for rule stop states
reachable by epsilon-only transitions from each configuration in
configs
.configs
if all configurations in configs
are in a
rule stop state, otherwise return a new configuration set containing only
the configurations from configs
which are in a rule stop state@NotNull protected ATNConfigSet computeStartState(@NotNull ATNState p, @Nullable RuleContext ctx, boolean fullCtx)
@Nullable protected ATNState getReachableTarget(@NotNull Transition trans, int ttype)
protected SemanticContext[] getPredsForAmbigAlts(@NotNull BitSet ambigAlts, @NotNull ATNConfigSet configs, int nalts)
protected DFAState.PredPrediction[] getPredicatePredictions(BitSet ambigAlts, SemanticContext[] altToPred)
protected int getAltThatFinishedDecisionEntryRule(ATNConfigSet configs)
protected BitSet evalSemanticContext(@NotNull DFAState.PredPrediction[] predPredictions, ParserRuleContext outerContext, boolean complete)
NONE
predicate indicates an alt containing an
unpredicated config which behaves as "always true." If !complete
then we stop at the first predicate that evaluates to true. This
includes pairs with null predicates.protected void closure(@NotNull ATNConfig config, @NotNull ATNConfigSet configs, @NotNull Set<ATNConfig> closureBusy, boolean collectPredicates, boolean fullCtx)
protected void closureCheckingStopState(@NotNull ATNConfig config, @NotNull ATNConfigSet configs, @NotNull Set<ATNConfig> closureBusy, boolean collectPredicates, boolean fullCtx, int depth)
protected void closure_(@NotNull ATNConfig config, @NotNull ATNConfigSet configs, @NotNull Set<ATNConfig> closureBusy, boolean collectPredicates, boolean fullCtx, int depth)
@Nullable protected ATNConfig getEpsilonTarget(@NotNull ATNConfig config, @NotNull Transition t, boolean collectPredicates, boolean inContext, boolean fullCtx)
@NotNull protected ATNConfig actionTransition(@NotNull ATNConfig config, @NotNull ActionTransition t)
@Nullable protected ATNConfig predTransition(@NotNull ATNConfig config, @NotNull PredicateTransition pt, boolean collectPredicates, boolean inContext, boolean fullCtx)
@NotNull protected ATNConfig ruleTransition(@NotNull ATNConfig config, @NotNull RuleTransition t)
protected BitSet getConflictingAlts(ATNConfigSet configs)
protected BitSet getConflictingAltsOrUniqueAlt(ATNConfigSet configs)
public String getLookaheadName(TokenStream input)
public void dumpDeadEndConfigs(@NotNull NoViableAltException nvae)
@NotNull protected NoViableAltException noViableAlt(@NotNull TokenStream input, @NotNull ParserRuleContext outerContext, @NotNull ATNConfigSet configs, int startIndex)
protected static int getUniqueAlt(@NotNull ATNConfigSet configs)
protected DFAState addDFAEdge(@NotNull DFA dfa, @Nullable DFAState from, int t, @Nullable DFAState to)
addDFAState(org.antlr.v4.runtime.dfa.DFA, org.antlr.v4.runtime.dfa.DFAState)
to ensure the to
state is present in the
DFA. If from
is null
, or if t
is outside the
range of edges that can be represented in the DFA tables, this method
returns without adding the edge to the DFA.
If to
is null
, this method returns null
.
Otherwise, this method returns the DFAState
returned by calling
addDFAState(org.antlr.v4.runtime.dfa.DFA, org.antlr.v4.runtime.dfa.DFAState)
for the to
state.dfa
- The DFAfrom
- The source state for the edget
- The input symbolto
- The target state for the edgeto
is null
, this method returns null
;
otherwise this method returns the result of calling addDFAState(org.antlr.v4.runtime.dfa.DFA, org.antlr.v4.runtime.dfa.DFAState)
on to
@NotNull protected DFAState addDFAState(@NotNull DFA dfa, @NotNull DFAState D)
D
to the DFA if it is not already present, and return
the actual instance stored in the DFA. If a state equivalent to D
is already in the DFA, the existing state is returned. Otherwise this
method returns D
after adding it to the DFA.
If D
is ATNSimulator.ERROR
, this method returns ATNSimulator.ERROR
and
does not change the DFA.dfa
- The dfaD
- The DFA state to addD
is already in the DFA, or D
itself if the
state was not already present.protected void reportAttemptingFullContext(DFA dfa, @Nullable BitSet conflictingAlts, @NotNull ATNConfigSet configs, int startIndex, int stopIndex)
protected void reportContextSensitivity(DFA dfa, int prediction, @NotNull ATNConfigSet configs, int startIndex, int stopIndex)
protected void reportAmbiguity(@NotNull DFA dfa, DFAState D, int startIndex, int stopIndex, boolean exact, @Nullable BitSet ambigAlts, @NotNull ATNConfigSet configs)
public final void setPredictionMode(@NotNull PredictionMode mode)
@NotNull public final PredictionMode getPredictionMode()
Copyright © 1992-2013 ANTLR. All Rights Reserved.