public ParseTreeEnumerator( IInternalForestNode forestRoot) { _forestRoot = forestRoot; _status = ParseTreeEnumeratorState.New; _visitor = new ForestNodeVisitorImpl(); }
private int GetOrSetChildIndex(IInternalForestNode symbolNode) { if (!_paths.TryGetValue(symbolNode, out int childIndex)) { _paths.Add(symbolNode, 0); return(childIndex); } var isLocked = _lock is object; if (!isLocked) { _lock = symbolNode; } var isCurrentNodeLocked = ReferenceEquals(_lock, symbolNode); if (!isCurrentNodeLocked) { return(childIndex); } childIndex++; if (childIndex >= symbolNode.Children.Count) { _lock = null; _paths[symbolNode] = 0; return(0); } _paths[symbolNode] = childIndex; return(childIndex); }
private int GetOrSetChildIndex(IInternalForestNode symbolNode) { if (!this.paths.TryGetValue(symbolNode, out var childIndex)) { this.paths.Add(symbolNode, 0); return(0); } var isLocked = !ReferenceEquals(null, this._lock); if (!isLocked) { this._lock = symbolNode; } var isCurrentNodeLocked = ReferenceEquals(this._lock, symbolNode); if (!isCurrentNodeLocked) { return(childIndex); } childIndex++; if (childIndex >= symbolNode.Children.Count) { this._lock = null; this.paths[symbolNode] = 0; return(0); } this.paths[symbolNode] = childIndex; return(childIndex); }
public void Reset() { _paths.Clear(); _nodeStack.Clear(); _visited.Clear(); _count = 0; _lock = null; }
private IForestNode CreateParseNode( IState nextState, IForestNode w, IForestNode v, int location) { Assert.IsNotNull(v, nameof(v)); var anyPreDotRuleNull = true; if (nextState.DottedRule.Position > 1) { var predotPrecursorSymbol = nextState .DottedRule .Production .RightHandSide[nextState.DottedRule.Position - 2]; anyPreDotRuleNull = IsSymbolNullable(predotPrecursorSymbol); } var anyPostDotRuleNull = IsSymbolNullable(nextState.PostDotSymbol); if (anyPreDotRuleNull && !anyPostDotRuleNull) { return(v); } IInternalForestNode internalNode = null; if (anyPostDotRuleNull) { internalNode = _nodeSet .AddOrGetExistingSymbolNode( nextState.DottedRule.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 InternalTreeNode( IInternalForestNode internalNode, IForestDisambiguationAlgorithm stateManager) { _disambiguationAlgorithm = stateManager; _internalNode = internalNode; _children = new List <ITreeNode>(); SetSymbol(_internalNode); }
public InternalTreeNode( IInternalForestNode internalNode, IForestDisambiguationAlgorithm stateManager) { _disambiguationAlgorithm = stateManager; _internalNode = internalNode; _children = new ReadWriteList<ITreeNode>(); SetSymbol(_internalNode); }
private static T GetAndCastChildAtIndex <T>(IInternalForestNode node, int index) where T : class, IForestNode { var firstAndNode = node.Children[0]; Assert.IsNotNull(firstAndNode); Assert.IsFalse(index > firstAndNode.Children.Count); var child = firstAndNode.Children[index] as T; Assert.IsNotNull(child); return(child); }
private void SetSymbol(IInternalForestNode node) { switch (node.NodeType) { case Forest.ForestNodeType.Symbol: Symbol = (node as ISymbolForestNode).Symbol as INonTerminal; break; case Forest.ForestNodeType.Intermediate: Symbol = (node as IIntermediateForestNode).State.DottedRule.Production.LeftHandSide; break; } }
private void SetSymbol(IInternalForestNode node) { switch (node) { case ISymbolForestNode symbol: Symbol = symbol.Symbol as NonTerminal; break; case IIntermediateForestNode intermediate: Symbol = intermediate.DottedRule.Production.LeftHandSide; break; } }
private void CloneUniqueChildSubTree(IInternalForestNode internalCompletedParseNode) { for (var a = 0; a < internalCompletedParseNode.Children.Count; a++) { var andNode = internalCompletedParseNode.Children[a]; var newAndNode = new AndForestNode(); for (var c = 0; c < andNode.Children.Count; c++) { var child = andNode.Children[c]; newAndNode.AddChild(child); } _children.Add(newAndNode); } }
bool AreChildNodesEqual(IInternalForestNode firstInternalForestNode, IInternalForestNode secondInternalForestNode) { if (firstInternalForestNode.Children.Count != secondInternalForestNode.Children.Count) { return(false); } for (int i = 0; i < firstInternalForestNode.Children.Count; i++) { if (!AreAndNodesEqual( firstInternalForestNode.Children[i], secondInternalForestNode.Children[i])) { return(false); } } return(true); }
public ParseTreeEnumerable(IInternalForestNode internalForestNode) { this._internalForestNode = internalForestNode; }
public InternalTreeNode( IInternalForestNode internalNode) : this(internalNode, new SelectFirstChildDisambiguationAlgorithm()) { }
public IAndForestNode GetCurrentAndNode(IInternalForestNode internalNode) { throw new NotImplementedException(); }
public void Dispose() { _visitor = null; _forestRoot = null; }
private int GetOrSetChildIndex(IInternalForestNode symbolNode) { var childIndex = 0; if (!_paths.TryGetValue(symbolNode, out childIndex)) { _paths.Add(symbolNode, 0); return childIndex; } var isLocked = !object.ReferenceEquals(null, _lock); if (!isLocked) _lock = symbolNode; var isCurrentNodeLocked = object.ReferenceEquals(_lock, symbolNode); if(!isCurrentNodeLocked) return childIndex; childIndex++; if (childIndex >= symbolNode.Children.Count) { _lock = null; _paths[symbolNode] = 0; return 0; } _paths[symbolNode] = childIndex; return childIndex; }
public IAndForestNode GetCurrentAndNode(IInternalForestNode internalNode) { return internalNode.Children[0]; }
public AndForestNode GetCurrentAndNode(IInternalForestNode internalNode) { throw new NotImplementedException(); }
public IAndForestNode GetCurrentAndNode(IInternalForestNode internalNode) { return(internalNode.Children[0]); }
private void SetSymbol(IInternalForestNode node) { switch (node.NodeType) { case Forest.ForestNodeType.Symbol: Symbol = (node as ISymbolForestNode).Symbol as INonTerminal; break; case Forest.ForestNodeType.Intermediate: Symbol = (node as IIntermediateForestNode).State.Production.LeftHandSide; break; } }