public VirtualForestNode( int location, ITransitionState transitionState, IForestNode completedParseNode) : this(location, transitionState, completedParseNode, transitionState.GetTargetState()) { }
protected VirtualForestNode( int location, ITransitionState transitionState, IForestNode completedParseNode, IState targetState) : base(targetState.Origin, location) { _paths = new List<VirtualForestNodePath>(); Symbol = targetState.Production.LeftHandSide; _hashCode = ComputeHashCode(); var path = new VirtualForestNodePath(transitionState, completedParseNode); AddUniquePath(path); }
private static bool IsMatchedSubTree(IForestNode firstChild, IForestNode secondChild, IAndForestNode andNode) { var firstCompareNode = andNode.Children[0]; // if first child matches the compare node, continue // otherwise return false if (!firstChild.Equals(firstCompareNode)) return false; if (secondChild == null) return true; var secondCompareNode = andNode.Children[1]; // return true if the second child matches // otherwise return false return secondChild.Equals(secondCompareNode); }
private static bool IsMatchedSubTree(IForestNode firstChild, IForestNode secondChild, IAndForestNode andNode) { var firstCompareNode = andNode.Children[0]; // if first child matches the compare node, continue // otherwise return false if (!firstChild.Equals(firstCompareNode)) { return(false); } if (secondChild == null) { return(true); } var secondCompareNode = andNode.Children[1]; // return true if the second child matches // otherwise return false return(secondChild.Equals(secondCompareNode)); }
private void AddUniqueAndNode(IForestNode first, IForestNode second = null) { var childCount = 1 + (second == null ? 0 : 1); foreach (var andNode in this.children) { if (andNode.Children.Count != childCount) { continue; } if (IsMatchedSubTree(andNode, first, second)) { return; } } // not found so add new and node var newAndNode = AndForestNode.Make(first, second); Debug.Assert(!(this is IntermediateForestNode) || this.children.Count == 0); this.children.Add(newAndNode); }
private void AddUniqueAndNode(IForestNode firstChild, IForestNode secondChild) { var childCount = 1 + ((secondChild == null) ? 0 : 1); for (var c = 0; c < _children.Count; c++) { var andNode = _children[c]; if (andNode.Children.Count != childCount) continue; if (IsMatchedSubTree(firstChild, secondChild, andNode)) return; } // not found so return new and node var newAndNode = new AndForestNode(); newAndNode.AddChild(firstChild); if (childCount > 1) newAndNode.AddChild(secondChild); _children.Add(newAndNode); }
private static bool IsMatchedSubTree(AndForestNode andNode, IForestNode first, IForestNode second) { return(first.Equals(andNode.First) && (second == null || second.Equals(andNode.Second))); }
public void AddUniqueFamily(IForestNode trigger) { AddUniqueAndNode(trigger); }
public VirtualForestNodePath(ITransitionState transitionState, IForestNode forestNode) { TransitionState = transitionState; ForestNode = forestNode; _hashCode = ComputeHashCode(TransitionState, ForestNode); }
public void AddUniqueFamily(IForestNode source, IForestNode trigger) { throw new NotImplementedException(); }
static void AssertForestsAreEqual(IForestNode expected, IForestNode actual) { var comparer = new StatefulForestNodeComparer(); Assert.IsTrue(comparer.Equals(expected, actual)); }
public void Add(IForestNode child) { _children.Add(child); }
public void AddChild(IForestNode orNode) { _children.Add(orNode); }
public CompletedState(DottedRule dottedRule, int origin, IForestNode parseNode) : base(dottedRule, origin, parseNode) { }
public void SetParseNode(IForestNode parseNode) { ParseNode = parseNode; }
private IForestNode CreateParseNode( IState nextState, IForestNode w, IForestNode v, int location) { Assert.IsNotNull(v, nameof(v)); var anyPreDotRuleNull = true; if (nextState.Position > 1) { var predotPrecursorSymbol = nextState .Production .RightHandSide[nextState.Position - 2]; anyPreDotRuleNull = IsSymbolNullable(predotPrecursorSymbol); } var anyPostDotRuleNull = IsSymbolNullable(nextState.PostDotSymbol); if (anyPreDotRuleNull && !anyPostDotRuleNull) return v; IInternalForestNode internalNode = null; if (anyPostDotRuleNull) { internalNode = _nodeSet .AddOrGetExistingSymbolNode( nextState.Production.LeftHandSide, nextState.Origin, location); } else { internalNode = _nodeSet .AddOrGetExistingIntermediateNode( nextState, nextState.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(w, v); return internalNode; }
public PredictionState(DottedRule dottedRule, int origin, IForestNode parseNode) : base(dottedRule, origin, parseNode) { }
private static int ComputeHashCode(ITransitionState transitionState, IForestNode forestNode) { return(HashCode.Compute( transitionState.GetHashCode(), forestNode.GetHashCode())); }
public void AddUniqueFamily(IForestNode source, IForestNode trigger) { if(source == this) source = Children[0].Children[0]; AddUniqueAndNode(source, trigger); }
public IState NewState(IDottedRule dottedRule, int origin, IForestNode forestNode = null) { return(forestNode is null ? new NormalState(dottedRule, origin) : new NormalState(dottedRule, origin, forestNode)); }
private void AddUniqueAndNode(IForestNode child) { AddUniqueAndNode(child, null); }
public NormalState(IDottedRule dottedRule, int origin, IForestNode parseNode) : this(dottedRule, origin) { ParseNode = parseNode; }
public void AddUniqueFamily(IForestNode trigger) { Debug.Assert(!(this is IntermediateForestNode) || Children.Count == 0); AddUniqueAndNode(trigger); }
private static int ComputeHashCode(ITransitionState transitionState, IForestNode forestNode) { return HashCode.Compute( transitionState.GetHashCode(), forestNode.GetHashCode()); }