/// <summary> /// Constructs a new instance of the /// <see cref="PredicateEvalInfo"/> /// class with the /// specified detailed predicate evaluation information. /// </summary> /// <param name="state">The simulator state</param> /// <param name="decision">The decision number</param> /// <param name="input">The input token stream</param> /// <param name="startIndex">The start index for the current prediction</param> /// <param name="stopIndex"> /// The index at which the predicate evaluation was /// triggered. Note that the input stream may be reset to other positions for /// the actual evaluation of individual predicates. /// </param> /// <param name="semctx">The semantic context which was evaluated</param> /// <param name="evalResult">The results of evaluating the semantic context</param> /// <param name="predictedAlt"> /// The alternative number for the decision which is /// guarded by the semantic context /// <paramref name="semctx"/> /// . See /// <see cref="predictedAlt"/> /// for more information. /// </param> /// <seealso cref="ParserATNSimulator.EvalSemanticContext(SemanticContext, ParserRuleContext, int)"/> /// <seealso cref="SemanticContext.Eval"/> public PredicateEvalInfo(SimulatorState state, int decision, ITokenStream input, int startIndex, int stopIndex, SemanticContext semctx, bool evalResult, int predictedAlt) : base(decision, state, input, startIndex, stopIndex, state.useContext) { this.semctx = semctx; this.evalResult = evalResult; this.predictedAlt = predictedAlt; }
public override void ReportContextSensitivity(Parser recognizer, DFA dfa, int startIndex , int stopIndex, SimulatorState acceptState) { string format = "reportContextSensitivity d={0}, input='{1}'"; recognizer.NotifyErrorListeners(string.Format(format, GetDecisionDescription(recognizer , dfa.decision), ((ITokenStream)recognizer.InputStream).GetText(Interval.Of(startIndex , stopIndex)))); }
public override void ReportAttemptingFullContext(Parser recognizer, DFA dfa, int startIndex, int stopIndex, BitSet conflictingAlts, SimulatorState conflictState) { string format = "reportAttemptingFullContext d={0}, input='{1}'"; string decision = GetDecisionDescription(recognizer, dfa); string text = ((ITokenStream)recognizer.InputStream).GetText(Interval.Of(startIndex, stopIndex)); string message = string.Format(format, decision, text); recognizer.NotifyErrorListeners(message); }
public DecisionEventInfo(int decision, SimulatorState state, ITokenStream input, int startIndex, int stopIndex, bool fullCtx) { this.decision = decision; this.fullCtx = fullCtx; this.stopIndex = stopIndex; this.input = input; this.startIndex = startIndex; this.state = state; }
public override int AdaptivePredict(ITokenStream input, int decision, ParserRuleContext outerContext) { try { this._input = input; this._startIndex = input.Index; // it's possible for SLL to reach a conflict state without consuming any input this._sllStopIndex = _startIndex - 1; this._llStopIndex = -1; this.currentDecision = decision; this.currentState = null; this.conflictingAltResolvedBySLL = ATN.InvalidAltNumber; #if !PORTABLE || NET45PLUS Stopwatch stopwatch = Stopwatch.StartNew(); #endif // expensive but useful info int alt = base.AdaptivePredict(input, decision, outerContext); #if !PORTABLE || NET45PLUS decisions[decision].timeInPrediction += stopwatch.ElapsedTicks * 100; #endif decisions[decision].invocations++; int SLL_k = _sllStopIndex - _startIndex + 1; decisions[decision].SLL_TotalLook += SLL_k; decisions[decision].SLL_MinLook = decisions[decision].SLL_MinLook == 0 ? SLL_k : Math.Min(decisions[decision].SLL_MinLook, SLL_k); if (SLL_k > decisions[decision].SLL_MaxLook) { decisions[decision].SLL_MaxLook = SLL_k; decisions[decision].SLL_MaxLookEvent = new LookaheadEventInfo(decision, null, alt, input, _startIndex, _sllStopIndex, false); } if (_llStopIndex >= 0) { int LL_k = _llStopIndex - _startIndex + 1; decisions[decision].LL_TotalLook += LL_k; decisions[decision].LL_MinLook = decisions[decision].LL_MinLook == 0 ? LL_k : Math.Min(decisions[decision].LL_MinLook, LL_k); if (LL_k > decisions[decision].LL_MaxLook) { decisions[decision].LL_MaxLook = LL_k; decisions[decision].LL_MaxLookEvent = new LookaheadEventInfo(decision, null, alt, input, _startIndex, _llStopIndex, true); } } return alt; } finally { this._input = null; this.currentDecision = -1; } }
public override void ReportContextSensitivity(Parser recognizer, Antlr4.Runtime.Dfa.DFA dfa, int startIndex, int stopIndex, int prediction, Antlr4.Runtime.Atn.SimulatorState acceptState) { if (_captureDiagnostics) { _warningMessages.Add(string.Format("reportContextSensitivity d={0}, input='{1}'", GetDecisionDescription(recognizer, dfa), ((ITokenStream)recognizer.InputStream).GetText(Interval.Of(startIndex, stopIndex)))); Debug.Log(string.Format("reportContextSensitivity d={0}, input='{1}'", GetDecisionDescription(recognizer, dfa), ((ITokenStream)recognizer.InputStream).GetText(Interval.Of(startIndex, stopIndex)))); MyConsole.main.AppendText(string.Format("reportContextSensitivity d={0}, input='{1}'", GetDecisionDescription(recognizer, dfa), ((ITokenStream)recognizer.InputStream).GetText(Interval.Of(startIndex, stopIndex)))); } }
protected internal override void ReportAttemptingFullContext(DFA dfa, BitSet conflictingAlts, SimulatorState conflictState, int startIndex, int stopIndex) { if (conflictingAlts != null) { conflictingAltResolvedBySLL = conflictingAlts.NextSetBit(0); } else { conflictingAltResolvedBySLL = conflictState.s0.configs.RepresentedAlternatives.NextSetBit(0); } decisions[currentDecision].LL_Fallback++; base.ReportAttemptingFullContext(dfa, conflictingAlts, conflictState, startIndex, stopIndex); }
protected internal override DFAState GetExistingTargetState(DFAState previousD, int t) { // this method is called after each time the input position advances if (currentState.useContext) { _llStopIndex = _input.Index; } else { _sllStopIndex = _input.Index; } DFAState existingTargetState = base.GetExistingTargetState(previousD, t); if (existingTargetState != null) { // this method is directly called by execDFA; must construct a SimulatorState // to represent the current state for this case currentState = new SimulatorState(currentState.outerContext, existingTargetState, currentState.useContext, currentState.remainingOuterContext); if (currentState.useContext) { decisions[currentDecision].LL_DFATransitions++; } else { decisions[currentDecision].SLL_DFATransitions++; } // count only if we transition over a DFA state if (existingTargetState == Error) { SimulatorState state = new SimulatorState(currentState.outerContext, previousD, currentState.useContext, currentState.remainingOuterContext); decisions[currentDecision].errors.Add(new ErrorInfo(currentDecision, state, _input, _startIndex, _input.Index)); } } return existingTargetState; }
protected internal override void ReportContextSensitivity(DFA dfa, int prediction, SimulatorState acceptState, int startIndex, int stopIndex) { if (prediction != conflictingAltResolvedBySLL) { decisions[currentDecision].contextSensitivities.Add(new ContextSensitivityInfo(currentDecision, acceptState, _input, startIndex, stopIndex)); } base.ReportContextSensitivity(dfa, prediction, acceptState, startIndex, stopIndex); }
protected internal override SimulatorState ComputeReachSet(DFA dfa, SimulatorState previous, int t, PredictionContextCache contextCache) { SimulatorState reachState = base.ComputeReachSet(dfa, previous, t, contextCache); if (reachState == null) { // no reach on current lookahead symbol. ERROR. decisions[currentDecision].errors.Add(new ErrorInfo(currentDecision, previous, _input, _startIndex, _input.Index)); } currentState = reachState; return reachState; }
/// <summary> /// Constructs a new instance of the /// <see cref="ContextSensitivityInfo"/> /// class /// with the specified detailed context sensitivity information. /// </summary> /// <param name="decision">The decision number</param> /// <param name="state"> /// The final simulator state containing the unique /// alternative identified by full-context prediction /// </param> /// <param name="input">The input token stream</param> /// <param name="startIndex">The start index for the current prediction</param> /// <param name="stopIndex"> /// The index at which the context sensitivity was /// identified during full-context prediction /// </param> public ContextSensitivityInfo(int decision, SimulatorState state, ITokenStream input, int startIndex, int stopIndex) : base(decision, state, input, startIndex, stopIndex, true) { }
public virtual void ReportAttemptingFullContext(Parser recognizer, DFA dfa, int startIndex , int stopIndex, SimulatorState initialState) { }
/// <summary> /// Constructs a new instance of the /// <see cref="ErrorInfo"/> /// class with the /// specified detailed syntax error information. /// </summary> /// <param name="decision">The decision number</param> /// <param name="state"> /// The final simulator state reached during prediction /// prior to reaching the /// <see cref="ATNSimulator.Error"/> /// state /// </param> /// <param name="input">The input token stream</param> /// <param name="startIndex">The start index for the current prediction</param> /// <param name="stopIndex">The index at which the syntax error was identified</param> public ErrorInfo(int decision, SimulatorState state, ITokenStream input, int startIndex, int stopIndex) : base(decision, state, input, startIndex, stopIndex, state.useContext) { }
public virtual void ReportAttemptingFullContext(Parser recognizer, DFA dfa, int startIndex , int stopIndex, BitSet conflictingAlts, SimulatorState conflictState) { }
public override void ReportContextSensitivity(Parser recognizer, DFA dfa, int startIndex, int stopIndex, int prediction, SimulatorState acceptState) { }
/// <summary> /// Constructs a new instance of the /// <see cref="LookaheadEventInfo"/> /// class with /// the specified detailed lookahead information. /// </summary> /// <param name="decision">The decision number</param> /// <param name="state"> /// The final simulator state containing the necessary /// information to determine the result of a prediction, or /// <see langword="null"/> /// if /// the final state is not available /// </param> /// <param name="input">The input token stream</param> /// <param name="startIndex">The start index for the current prediction</param> /// <param name="stopIndex">The index at which the prediction was finally made</param> /// <param name="fullCtx"> /// /// <see langword="true"/> /// if the current lookahead is part of an LL /// prediction; otherwise, /// <see langword="false"/> /// if the current lookahead is part of /// an SLL prediction /// </param> public LookaheadEventInfo(int decision, SimulatorState state, ITokenStream input, int startIndex, int stopIndex, bool fullCtx) : base(decision, state, input, startIndex, stopIndex, fullCtx) { }
public override void ReportAttemptingFullContext(Parser recognizer, DFA dfa, int startIndex, int stopIndex, SimulatorState initialState) { if (!REPORT_FULL_CONTEXT) { return; } base.ReportAttemptingFullContext(recognizer, dfa, startIndex, stopIndex, initialState); }
public override void ReportContextSensitivity(Parser recognizer, DFA dfa, int startIndex, int stopIndex, SimulatorState acceptState) { if (!REPORT_CONTEXT_SENSITIVITY) { return; } base.ReportContextSensitivity(recognizer, dfa, startIndex, stopIndex, acceptState); }
/// <summary> /// Constructs a new instance of the /// <see cref="AmbiguityInfo"/> /// class with the /// specified detailed ambiguity information. /// </summary> /// <param name="decision">The decision number</param> /// <param name="state"> /// The final simulator state identifying the ambiguous /// alternatives for the current input /// </param> /// <param name="ambigAlts">The set of alternatives in the decision that lead to a valid parse.</param> /// <param name="input">The input token stream</param> /// <param name="startIndex">The start index for the current prediction</param> /// <param name="stopIndex"> /// The index at which the ambiguity was identified during /// prediction /// </param> public AmbiguityInfo(int decision, SimulatorState state, BitSet ambigAlts, ITokenStream input, int startIndex, int stopIndex) : base(decision, state, input, startIndex, stopIndex, state.useContext) { this.ambigAlts = ambigAlts; }
protected internal override SimulatorState GetStartState(DFA dfa, ITokenStream input, ParserRuleContext outerContext, bool useContext) { SimulatorState state = base.GetStartState(dfa, input, outerContext, useContext); currentState = state; return state; }
/// <summary> /// Constructs a new instance of the /// <see cref="AmbiguityInfo"/> /// class with the /// specified detailed ambiguity information. /// </summary> /// <param name="decision">The decision number</param> /// <param name="state"> /// The final simulator state identifying the ambiguous /// alternatives for the current input /// </param> /// <param name="input">The input token stream</param> /// <param name="startIndex">The start index for the current prediction</param> /// <param name="stopIndex"> /// The index at which the ambiguity was identified during /// prediction /// </param> public AmbiguityInfo(int decision, SimulatorState state, ITokenStream input, int startIndex, int stopIndex) : base(decision, state, input, startIndex, stopIndex, state.useContext) { }
protected internal override SimulatorState ComputeStartState(DFA dfa, ParserRuleContext globalContext, bool useContext) { SimulatorState state = base.ComputeStartState(dfa, globalContext, useContext); currentState = state; return state; }
public virtual void ReportContextSensitivity(Parser recognizer, DFA dfa, int startIndex , int stopIndex, SimulatorState acceptState) { }