public DefaultVisitor(ForestInternal root) { if (root == null) { throw new ArgumentNullException(); } _root = root; }
public virtual bool Visit(ForestInternal node) { foreach (var option in node.Options) { foreach (var children in option.Children()) { foreach (var child in children) { child.Accept(this); } } } return true; }
public virtual bool Visit(ForestInternal node) { foreach (var option in node.Options) { foreach (var children in option.Children()) { foreach (var child in children) { child.Accept(this); } } } return(true); }
public override bool Visit(ForestInternal node) { if (_visited.Contains(node.InternalNode)) { return(true); } _visited.Add(node.InternalNode); var currentNode = _currentNode; for (int i = 0; i < node.Options.Count; i++) { var option = node.Options[i]; string optionId = _ids[node.InternalNode] + "-" + i; var optionNode = new ChildNode(option.Production.Rhs, node.StartPosition, node.EndPosition, optionId, currentNode.Rank + 1); _graph.AddEdge(currentNode, optionNode, option.Production); foreach (var children in option.Children()) { foreach (var child in children) { int childSeenId; if (child is ForestLeaf) { childSeenId = _id++; } else { var internalChild = (ForestInternal)child; if (!_ids.TryGetValue(internalChild.InternalNode, out childSeenId)) { childSeenId = _id++; _ids[internalChild.InternalNode] = childSeenId; } } string childId = "" + childSeenId; var childNode = new ForestNodeNode(child, childId, optionNode.Rank + 1); _graph.AddEdge(optionNode, childNode); _currentNode = childNode; child.Accept(this); // child.GetGraphHelper(g, childNode, visited, ids, ref id); } } } return(true); }
public override bool Visit(ForestInternal node) { if (_visited.Contains(node.InternalNode)) { return true; } _visited.Add(node.InternalNode); var currentNode = _currentNode; for (int i = 0; i < node.Options.Count; i++) { var option = node.Options[i]; string optionId = _ids[node.InternalNode] + "-" + i; var optionNode = new ChildNode(option.Production.Rhs, node.StartPosition, node.EndPosition, optionId, currentNode.Rank + 1); _graph.AddEdge(currentNode, optionNode, option.Production); foreach (var children in option.Children()) { foreach (var child in children) { int childSeenId; if (child is ForestLeaf) { childSeenId = _id++; } else { var internalChild = (ForestInternal)child; if (!_ids.TryGetValue(internalChild.InternalNode, out childSeenId)) { childSeenId = _id++; _ids[internalChild.InternalNode] = childSeenId; } } string childId = "" + childSeenId; var childNode = new ForestNodeNode(child, childId, optionNode.Rank + 1); _graph.AddEdge(optionNode, childNode); _currentNode = childNode; child.Accept(this); // child.GetGraphHelper(g, childNode, visited, ids, ref id); } } } return true; }
public GraphVisitor(ForestInternal root) : base(root) { }