private int ComputeHashCode() { return(HashCode.Compute( ((int)NodeType).GetHashCode(), Location.GetHashCode(), Origin.GetHashCode(), DottedRule.GetHashCode())); }
public IIntermediateForestNode AddOrGetExistingIntermediateNode(DottedRule dottedRule, int origin, int location) { var key = (dottedRule, origin, location); if (this._intermediateNodes.TryGetValue(key, out var intermediateNode)) { return(intermediateNode); } intermediateNode = new IntermediateForestNode(dottedRule, origin, location); this._intermediateNodes.Add(key, intermediateNode); return(intermediateNode); }
private IForestNode CreateParseNode( DottedRule nextDottedRule, int origin, IForestNode w, IForestNode v, int location) { Assert.IsNotNull(v, nameof(v)); var anyPreDotRuleNull = true; if (nextDottedRule.Dot > 1) { var preDotPrecursorSymbol = nextDottedRule.Production[nextDottedRule.Dot - 2]; anyPreDotRuleNull = IsSymbolTransitiveNullable(preDotPrecursorSymbol); } var anyPostDotRuleNull = IsSymbolTransitiveNullable(nextDottedRule.PostDotSymbol); if (anyPreDotRuleNull && !anyPostDotRuleNull) { return(v); } IInternalForestNode internalNode; if (anyPostDotRuleNull) { internalNode = NodeSet.AddOrGetExistingSymbolNode(nextDottedRule.Production.LeftHandSide, origin, location); } else { internalNode = NodeSet.AddOrGetExistingIntermediateNode(nextDottedRule, origin, location); } // if w = null and y doesn't have a family of children (v) if (w == null) { internalNode.AddUniqueFamily(v); } // if w != null and y doesn't have a family of children (w, v) else { internalNode.AddUniqueFamily(v, w); } return(internalNode); }
public void ChartEnqueShouldAvoidDuplication() { ProductionExpression L = "L"; var aToZ = new RangeTerminal('a', 'z'); L.Rule = L + aToZ | aToZ; var grammar = new GrammarExpression(L, new[] { L }).ToGrammar(); var chart = new Chart(); var dottedRule = new DottedRule(grammar.Productions[0], 0); var firstState = new NormalState(dottedRule, 1); var secondState = new NormalState(dottedRule, 1); chart.Enqueue(0, firstState); chart.Enqueue(0, secondState); Assert.AreEqual(1, chart.EarleySets[0].Predictions.Count); }
public override bool Equals(object obj) { if (obj is null) { return(false); } if (!(obj is IIntermediateForestNode intermediateNode)) { return(false); } return(Location == intermediateNode.Location && Origin == intermediateNode.Origin && NodeType == intermediateNode.NodeType && DottedRule.Equals(intermediateNode.DottedRule)); }
public IntermediateForestNode(DottedRule dottedRule, int origin, int location) : base(origin, location) { DottedRule = dottedRule; this.hashCode = (DottedRule, Origin, Location).GetHashCode(); }
private static bool IsComplete(DottedRule preComputedState) { return(preComputedState.Position == preComputedState.Production.RightHandSide.Count); }
private bool IsStartState(DottedRule state) { var start = _preComputedGrammar.Grammar.Start; return(state.Production.LeftHandSide.Equals(start)); }
private static ISymbol GetPostDotSymbol(DottedRule preComputedState) { return(preComputedState.Production.RightHandSide[preComputedState.Position]); }
private static bool IsCompleted(DottedRule dottedRule) { return(dottedRule.Production.RightHandSide.Count == dottedRule.Position); }