ProfilingATNSimulator

TODO add class description

Constructors

this
this(Parser parser)
Undocumented in source.

Members

Functions

adaptivePredict
int adaptivePredict(TokenStream input, int decision, ParserRuleContext outerContext)

@uml @override

computeReachSet
ATNConfigSet computeReachSet(ATNConfigSet closure, int t, bool fullCtx)

@uml @override

computeTargetState
DFAState computeTargetState(DFA dfa, DFAState previousD, int t)

@uml @override

evalSemanticContext
bool evalSemanticContext(SemanticContext pred, ParserRuleContext parserCallStack, int alt, bool fullCtx)

@uml @override

getDecisionInfo
DecisionInfo[] getDecisionInfo()
Undocumented in source. Be warned that the author may not have intended to support it.
getExistingTargetState
DFAState getExistingTargetState(DFAState previousD, int t)

@uml @override

Variables

_llStopIndex
int _llStopIndex;
Undocumented in source.
_sllStopIndex
int _sllStopIndex;
Undocumented in source.
conflictingAltResolvedBySLL
int conflictingAltResolvedBySLL;

we can determine whether or not a decision / input pair is context-sensitive. If LL gives a different result than SLL's predicted alternative, we have a context sensitivity for sure. The converse is not necessarily true, however. It's possible that after conflict resolution chooses minimum alternatives, SLL could get the same answer as LL. Regardless of whether or not the result indicates an ambiguity, it is not treated as a context sensitivity because LL prediction was not required in order to produce a correct prediction for this decision and input sequence. It may in fact still be a context sensitivity but we don't know by looking at the minimum alternatives for the current input.

currentDecision
int currentDecision;
Undocumented in source.
currentState
DFAState currentState;
Undocumented in source.
decisions
DecisionInfo[] decisions;
Undocumented in source.
numDecisions
int numDecisions;
Undocumented in source.

Inherited Members

From ParserATNSimulator

parser
Parser parser;
Undocumented in source.
decisionToDFA
DFA[] decisionToDFA;
Undocumented in source.
mode
PredictionModeConst mode;
Undocumented in source.
mergeCache
DoubleKeyMap!(PredictionContext, PredictionContext, PredictionContext) mergeCache;

Each prediction operation uses a cache for merge of prediction contexts. Don't keep around as it wastes huge amounts of memory. DoubleKeyMap isn't synchronized but we're ok since two threads shouldn't reuse same parser/atnsim object because it can only handle one input at a time. This maps graphs a and b to merged result c. (a,b)→c. We can avoid the merge if we ever see a and b again. Note that (b,a)→c should also be examined during cache lookup. @uml @__gshared

_dfa
DFA _dfa;
Undocumented in source.
_input
TokenStream _input;
Undocumented in source.
_startIndex
int _startIndex;
Undocumented in source.
_outerContext
ParserRuleContext _outerContext;
Undocumented in source.
reset
void reset()

@uml @override

clearDFA
void clearDFA()

@uml @override

adaptivePredict
int adaptivePredict(TokenStream input, int decision, ParserRuleContext outerContext)
Undocumented in source. Be warned that the author may not have intended to support it.
execATN
int execATN(DFA dfa, DFAState s0, TokenStream input, int startIndex, ParserRuleContext outerContext)

There are some key conditions we're looking for after computing a new set of ATN configs (proposed DFA state): <br>- if the set is empty, there is no viable alternative for current symbol <br>- does the state uniquely predict an alternative? <br>- does the state have a conflict that would prevent us from putting it on the work list? <br><br>We also have some key operations to do: <br>- add an edge from previous DFA state to potentially new DFA state, D, upon current symbol but only if adding to work list, which means in all cases except no viable alternative (and possibly non-greedy decisions?) <br>- collecting predicates and adding semantic context to DFA accept states <br>- adding rule context to context-sensitive DFA accept states <br>- consuming an input symbol <br>- reporting a conflict <br>- reporting an ambiguity <br>- reporting a context sensitivity <br>- reporting insufficient predicates <br><br>cover these cases: <br>- dead end <br>- single alt <br>- single alt + preds <br>- conflict <br>- conflict + preds

getExistingTargetState
DFAState getExistingTargetState(DFAState previousD, int t)

Get an existing target state for an edge in the DFA. If the target state for the edge has not yet been computed or is otherwise not available, this method returns {@code null}.

computeTargetState
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.

predicateDFAState
void predicateDFAState(DFAState dfaState, DecisionState decisionState)
Undocumented in source. Be warned that the author may not have intended to support it.
execATNWithFullContext
int execATNWithFullContext(DFA dfa, DFAState D, ATNConfigSet s0, TokenStream input, int startIndex, ParserRuleContext outerContext)

@uml comes back with reach.uniqueAlt set to a valid alt

computeReachSet
ATNConfigSet computeReachSet(ATNConfigSet closure, int t, bool fullCtx)
Undocumented in source. Be warned that the author may not have intended to support it.
removeAllConfigsNotInRuleStopState
ATNConfigSet removeAllConfigsNotInRuleStopState(ATNConfigSet configs, bool lookToEndOfRule)

Return a configuration set containing only the configurations from {@code configs} which are in a {@link RuleStopState}. If all configurations in {@code configs} are already in a rule stop state, this method simply returns {@code configs}.

computeStartState
ATNConfigSet computeStartState(ATNState p, RuleContext ctx, bool fullCtx)
Undocumented in source. Be warned that the author may not have intended to support it.
applyPrecedenceFilter
ATNConfigSet applyPrecedenceFilter(ATNConfigSet configs)
Undocumented in source. Be warned that the author may not have intended to support it.
getReachableTarget
ATNState getReachableTarget(Transition trans, int ttype)
Undocumented in source. Be warned that the author may not have intended to support it.
getPredsForAmbigAlts
SemanticContext[] getPredsForAmbigAlts(BitSet ambigAlts, ATNConfigSet configs, int nalts)
Undocumented in source. Be warned that the author may not have intended to support it.
getPredicatePredictions
PredPrediction[] getPredicatePredictions(BitSet ambigAlts, SemanticContext[] altToPred)
Undocumented in source. Be warned that the author may not have intended to support it.
getAltThatFinishedDecisionEntryRule
int getAltThatFinishedDecisionEntryRule(ATNConfigSet configs)
Undocumented in source. Be warned that the author may not have intended to support it.
getSynValidOrSemInvalidAltThatFinishedDecisionEntryRule
int getSynValidOrSemInvalidAltThatFinishedDecisionEntryRule(ATNConfigSet configs, ParserRuleContext outerContext)

This method is used to improve the localization of error messages by choosing an alternative rather than throwing a {@link NoViableAltException} in particular prediction scenarios where the {@link #ERROR} state was reached during ATN simulation.

splitAccordingToSemanticValidity
ATNConfigSetATNConfigSetPair splitAccordingToSemanticValidity(ATNConfigSet configs, ParserRuleContext outerContext)
Undocumented in source. Be warned that the author may not have intended to support it.
evalSemanticContext
BitSet evalSemanticContext(PredPrediction[] predPredictions, ParserRuleContext outerContext, bool complete)

Look through a list of predicate/alt pairs, returning alts for the pairs that win. A {@code 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.

evalSemanticContext
bool evalSemanticContext(SemanticContext pred, ParserRuleContext parserCallStack, int alt, bool fullCtx)
Undocumented in source. Be warned that the author may not have intended to support it.
closureATN
void closureATN(ATNConfig config, ATNConfigSet configs, ATNConfig[] closureBusy, bool collectPredicates, bool fullCtx, bool treatEofAsEpsilon)
Undocumented in source. Be warned that the author may not have intended to support it.
closureCheckingStopState
void closureCheckingStopState(ATNConfig config, ATNConfigSet configs, ATNConfig[] closureBusy, bool collectPredicates, bool fullCtx, int depth, bool treatEofAsEpsilon)
Undocumented in source. Be warned that the author may not have intended to support it.
closure_
void closure_(ATNConfig config, ATNConfigSet configs, ATNConfig[] closureBusy, bool collectPredicates, bool fullCtx, int depth, bool treatEofAsEpsilon)

Do the actual work of walking epsilon edges

getRuleName
string getRuleName(int index)
Undocumented in source. Be warned that the author may not have intended to support it.
getEpsilonTarget
ATNConfig getEpsilonTarget(ATNConfig config, Transition t, bool collectPredicates, bool inContext, bool fullCtx, bool treatEofAsEpsilon)
Undocumented in source. Be warned that the author may not have intended to support it.
actionTransition
ATNConfig actionTransition(ATNConfig config, ActionTransition t)
Undocumented in source. Be warned that the author may not have intended to support it.
precedenceTransition
ATNConfig precedenceTransition(ATNConfig config, PrecedencePredicateTransition pt, bool collectPredicates, bool inContext, bool fullCtx)
Undocumented in source. Be warned that the author may not have intended to support it.
predTransition
ATNConfig predTransition(ATNConfig config, PredicateTransition pt, bool collectPredicates, bool inContext, bool fullCtx)
Undocumented in source. Be warned that the author may not have intended to support it.
ruleTransition
ATNConfig ruleTransition(ATNConfig config, RuleTransition t)
Undocumented in source. Be warned that the author may not have intended to support it.
getConflictingAlts
BitSet getConflictingAlts(ATNConfigSet configs)

Gets a {@link BitSet} containing the alternatives in {@code configs} which are part of one or more conflicting alternative subsets.

getConflictingAltsOrUniqueAlt
BitSet getConflictingAltsOrUniqueAlt(ATNConfigSet configs)

Sam pointed out a problem with the previous definition, v3, of ambiguous states. If we have another state associated with conflicting alternatives, we should keep going. For example, the following grammar

getTokenName
string getTokenName(int t)
Undocumented in source. Be warned that the author may not have intended to support it.
getLookaheadName
string getLookaheadName(TokenStream input)
Undocumented in source. Be warned that the author may not have intended to support it.
dumpDeadEndConfigs
void dumpDeadEndConfigs(NoViableAltException nvae)

Used for debugging in adaptivePredict around execATN but I cut it out for clarity now that alg. works well. We can leave this "dead" code for a bit.

noViableAlt
NoViableAltException noViableAlt(TokenStream input, ParserRuleContext outerContext, ATNConfigSet configs, int startIndex)
Undocumented in source. Be warned that the author may not have intended to support it.
getUniqueAlt
int getUniqueAlt(ATNConfigSet configs)
Undocumented in source. Be warned that the author may not have intended to support it.
addDFAEdge
DFAState addDFAEdge(DFA dfa, DFAState from, int t, DFAState to)

Add an edge to the DFA, if possible. This method calls {@link #addDFAState} to ensure the {@code to} state is present in the DFA. If {@code from} is {@code null}, or if {@code 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.

addDFAState
DFAState addDFAState(DFA dfa, DFAState D)

Add state {@code D} to the DFA if it is not already present, and return the actual instance stored in the DFA. If a state equivalent to {@code D} is already in the DFA, the existing state is returned. Otherwise this method returns {@code D} after adding it to the DFA.

reportAttemptingFullContext
void reportAttemptingFullContext(DFA dfa, BitSet conflictingAlts, ATNConfigSet configs, int startIndex, int stopIndex)
Undocumented in source. Be warned that the author may not have intended to support it.
reportContextSensitivity
void reportContextSensitivity(DFA dfa, int prediction, ATNConfigSet configs, int startIndex, int stopIndex)
Undocumented in source. Be warned that the author may not have intended to support it.
reportAmbiguity
void reportAmbiguity(DFA dfa, DFAState D, int startIndex, int stopIndex, bool exact, BitSet ambigAlts, ATNConfigSet configs)
Undocumented in source. Be warned that the author may not have intended to support it.
setPredictionMode
void setPredictionMode(PredictionModeConst mode)
Undocumented in source. Be warned that the author may not have intended to support it.
getPredictionMode
PredictionModeConst getPredictionMode()
Undocumented in source. Be warned that the author may not have intended to support it.
getParser
Parser getParser()
Undocumented in source. Be warned that the author may not have intended to support it.
canDropLoopEntryEdgeInLeftRecursiveRule
bool canDropLoopEntryEdgeInLeftRecursiveRule(ATNConfig config)
Undocumented in source. Be warned that the author may not have intended to support it.

Meta