public virtual Antlr4.Runtime.Atn.ATNConfig AppendContext(int context, PredictionContextCache contextCache) { PredictionContext appendedContext = Context.AppendContext(context, contextCache); Antlr4.Runtime.Atn.ATNConfig result = Transform(State, appendedContext, false); return(result); }
public virtual bool Add(ATNConfig e, PredictionContextCache contextCache) { EnsureWritable(); System.Diagnostics.Debug.Assert(!outermostConfigSet || !e.ReachesIntoOuterContext); System.Diagnostics.Debug.Assert(!e.IsHidden); if (contextCache == null) { contextCache = PredictionContextCache.Uncached; } bool addKey; long key = GetKey(e); ATNConfig mergedConfig; addKey = !mergedConfigs.TryGetValue(key, out mergedConfig); if (mergedConfig != null && CanMerge(e, key, mergedConfig)) { mergedConfig.OuterContextDepth = Math.Max(mergedConfig.OuterContextDepth, e.OuterContextDepth); PredictionContext joined = PredictionContext.Join(mergedConfig.Context, e.Context, contextCache); UpdatePropertiesForMergedConfig(e); if (mergedConfig.Context == joined) { return(false); } mergedConfig.Context = joined; return(true); } for (int i = 0; i < unmerged.Count; i++) { ATNConfig unmergedConfig = unmerged[i]; if (CanMerge(e, key, unmergedConfig)) { unmergedConfig.OuterContextDepth = Math.Max(unmergedConfig.OuterContextDepth, e.OuterContextDepth); PredictionContext joined = PredictionContext.Join(unmergedConfig.Context, e.Context, contextCache); UpdatePropertiesForMergedConfig(e); if (unmergedConfig.Context == joined) { return(false); } unmergedConfig.Context = joined; if (addKey) { mergedConfigs[key] = unmergedConfig; unmerged.RemoveAt(i); } return(true); } } configs.Add(e); if (addKey) { mergedConfigs[key] = e; } else { unmerged.Add(e); } UpdatePropertiesForAddedConfig(e); return(true); }
public LexerATNSimulator(Lexer recog, ATN atn, DFA[] decisionToDFA, PredictionContextCache sharedContextCache) : base(atn, sharedContextCache) { this.decisionToDFA = decisionToDFA; this.recog = recog; }
public virtual bool AddAll(IEnumerable <ATNConfig> c, PredictionContextCache contextCache) { EnsureWritable(); bool changed = false; foreach (ATNConfig group in c) { changed |= Add(group, contextCache); } return(changed); }
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); }
protected internal override Tuple <DFAState, ParserRuleContext> ComputeTargetState(DFA dfa, DFAState s, ParserRuleContext remainingGlobalContext, int t, bool useContext, PredictionContextCache contextCache) { Tuple <DFAState, ParserRuleContext> targetState = base.ComputeTargetState(dfa, s, remainingGlobalContext, t, useContext, contextCache); if (useContext) { decisions[currentDecision].LL_ATNTransitions++; } else { decisions[currentDecision].SLL_ATNTransitions++; } return(targetState); }
public virtual Antlr4.Runtime.Atn.ATNConfig AppendContext(PredictionContext context, PredictionContextCache contextCache) { PredictionContext appendedContext = Context.AppendContext(context, contextCache); Antlr4.Runtime.Atn.ATNConfig result = Transform(State, appendedContext, false); return result; }
public override PredictionContext AppendContext(PredictionContext suffix, PredictionContextCache contextCache) { return contextCache.GetChild(parent.AppendContext(suffix, contextCache), returnState ); }
public override PredictionContext AppendContext(PredictionContext suffix, PredictionContextCache contextCache) { return(suffix); }
public LexerATNSimulator(ATN atn, DFA[] decisionToDFA, PredictionContextCache sharedContextCache) : this(null, atn, decisionToDFA, sharedContextCache) { }
protected internal override Tuple<DFAState, ParserRuleContext> ComputeTargetState(DFA dfa, DFAState s, ParserRuleContext remainingGlobalContext, int t, bool useContext, PredictionContextCache contextCache) { Tuple<DFAState, ParserRuleContext> targetState = base.ComputeTargetState(dfa, s, remainingGlobalContext, t, useContext, contextCache); if (useContext) { decisions[currentDecision].LL_ATNTransitions++; } else { decisions[currentDecision].SLL_ATNTransitions++; } return targetState; }
public abstract Antlr4.Runtime.Atn.PredictionContext AppendContext(Antlr4.Runtime.Atn.PredictionContext suffix, PredictionContextCache contextCache);
/** Testing only! */ public ParserATNSimulator(ATN atn, DFA[] decisionToDFA, PredictionContextCache sharedContextCache) : this(null, atn, decisionToDFA, sharedContextCache) { }
public ParserATNSimulator(Parser parser, ATN atn, DFA[] decisionToDFA, PredictionContextCache sharedContextCache) : base(atn, sharedContextCache) { this.parser = parser; this.decisionToDFA = decisionToDFA; // DOTGenerator dot = new DOTGenerator(null); // Console.WriteLine(dot.getDOT(atn.rules.get(0), parser.getRuleNames())); // Console.WriteLine(dot.getDOT(atn.rules.get(1), parser.getRuleNames())); }
public override PredictionContext AppendContext(PredictionContext suffix, PredictionContextCache contextCache) { return suffix; }
public override PredictionContext AppendContext(int returnContext, PredictionContextCache contextCache) { return contextCache.GetChild(this, returnContext); }
public static PredictionContext GetCachedContext(PredictionContext context, PredictionContextCache contextCache, PredictionContext.IdentityHashMap visited) { if (context.IsEmpty) { return(context); } PredictionContext existing = visited.Get(context); if (existing != null) { return(existing); } existing = contextCache.Get(context); if (existing != null) { visited.Put(context, existing); return(existing); } bool changed = false; PredictionContext[] parents = new PredictionContext[context.Size]; for (int i = 0; i < parents.Length; i++) { PredictionContext parent = GetCachedContext(context.GetParent(i), contextCache, visited); if (changed || parent != context.GetParent(i)) { if (!changed) { parents = new PredictionContext[context.Size]; for (int j = 0; j < context.Size; j++) { parents[j] = context.GetParent(j); } changed = true; } parents[i] = parent; } } if (!changed) { contextCache.Add(context); visited.Put(context, context); return(context); } PredictionContext updated; if (parents.Length == 0) { updated = EMPTY; } else if (parents.Length == 1) { updated = SingletonPredictionContext.Create(parents[0], context.GetReturnState(0)); } else { ArrayPredictionContext arrayPredictionContext = (ArrayPredictionContext)context; updated = new ArrayPredictionContext(parents, arrayPredictionContext.returnStates); } contextCache.Add(updated); visited.Put(updated, updated); visited.Put(context, updated); return(updated); }
internal static Antlr4.Runtime.Atn.PredictionContext Join(Antlr4.Runtime.Atn.PredictionContext context0, Antlr4.Runtime.Atn.PredictionContext context1, PredictionContextCache contextCache) { if (context0 == context1) { return(context0); } if (context0.IsEmpty) { return(IsEmptyLocal(context0) ? context0 : AddEmptyContext(context1)); } else { if (context1.IsEmpty) { return(IsEmptyLocal(context1) ? context1 : AddEmptyContext(context0)); } } int context0size = context0.Size; int context1size = context1.Size; if (context0size == 1 && context1size == 1 && context0.GetReturnState(0) == context1 .GetReturnState(0)) { Antlr4.Runtime.Atn.PredictionContext merged = contextCache.Join(context0.GetParent (0), context1.GetParent(0)); if (merged == context0.GetParent(0)) { return(context0); } else { if (merged == context1.GetParent(0)) { return(context1); } else { return(merged.GetChild(context0.GetReturnState(0))); } } } int count = 0; Antlr4.Runtime.Atn.PredictionContext[] parentsList = new Antlr4.Runtime.Atn.PredictionContext [context0size + context1size]; int[] returnStatesList = new int[parentsList.Length]; int leftIndex = 0; int rightIndex = 0; bool canReturnLeft = true; bool canReturnRight = true; while (leftIndex < context0size && rightIndex < context1size) { if (context0.GetReturnState(leftIndex) == context1.GetReturnState(rightIndex)) { parentsList[count] = contextCache.Join(context0.GetParent(leftIndex), context1.GetParent (rightIndex)); returnStatesList[count] = context0.GetReturnState(leftIndex); canReturnLeft = canReturnLeft && parentsList[count] == context0.GetParent(leftIndex ); canReturnRight = canReturnRight && parentsList[count] == context1.GetParent(rightIndex ); leftIndex++; rightIndex++; } else { if (context0.GetReturnState(leftIndex) < context1.GetReturnState(rightIndex)) { parentsList[count] = context0.GetParent(leftIndex); returnStatesList[count] = context0.GetReturnState(leftIndex); canReturnRight = false; leftIndex++; } else { System.Diagnostics.Debug.Assert(context1.GetReturnState(rightIndex) < context0.GetReturnState (leftIndex)); parentsList[count] = context1.GetParent(rightIndex); returnStatesList[count] = context1.GetReturnState(rightIndex); canReturnLeft = false; rightIndex++; } } count++; } while (leftIndex < context0size) { parentsList[count] = context0.GetParent(leftIndex); returnStatesList[count] = context0.GetReturnState(leftIndex); leftIndex++; canReturnRight = false; count++; } while (rightIndex < context1size) { parentsList[count] = context1.GetParent(rightIndex); returnStatesList[count] = context1.GetReturnState(rightIndex); rightIndex++; canReturnLeft = false; count++; } if (canReturnLeft) { return(context0); } else { if (canReturnRight) { return(context1); } } if (count < parentsList.Length) { parentsList = Arrays.CopyOf(parentsList, count); returnStatesList = Arrays.CopyOf(returnStatesList, count); } if (parentsList.Length == 0) { // if one of them was EMPTY_LOCAL, it would be empty and handled at the beginning of the method return(EmptyFull); } else { if (parentsList.Length == 1) { return(new SingletonPredictionContext(parentsList[0], returnStatesList[0])); } else { return(new ArrayPredictionContext(parentsList, returnStatesList)); } } }
public override PredictionContext AppendContext(PredictionContext suffix, PredictionContextCache contextCache) { return AppendContext(this, suffix, new PredictionContext.IdentityHashMap()); }
public virtual Antlr4.Runtime.Atn.PredictionContext AppendContext(int returnContext , PredictionContextCache contextCache) { return(AppendContext(Antlr4.Runtime.Atn.PredictionContext.EmptyFull.GetChild(returnContext ), contextCache)); }
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; }
public override PredictionContext AppendContext(PredictionContext suffix, PredictionContextCache contextCache) { return(contextCache.GetChild(parent.AppendContext(suffix, contextCache), returnState)); }
public override PredictionContext AppendContext(int returnContext, PredictionContextCache contextCache) { return(contextCache.GetChild(this, returnContext)); }
public override PredictionContext AppendContext(PredictionContext suffix, PredictionContextCache contextCache) { return(AppendContext(this, suffix, new PredictionContext.IdentityHashMap())); }
public void ClosureHelper(ATNConfigSet sourceConfigs, ATNConfigSet configs, bool collectPredicates, bool hasMoreContext, PredictionContextCache contextCache, bool treatEofAsEpsilon) { Closure(sourceConfigs, configs, collectPredicates, hasMoreContext, contextCache, treatEofAsEpsilon); }
public ATNSimulator(ATN atn, PredictionContextCache sharedContextCache) { this.atn = atn; this.sharedContextCache = sharedContextCache; }