private ResultNode SolveNode(AbstractParseNode node) { if (node is FunctionNode) { for (int i = 0; i < node.Children.Count; i++) node.Children[i] = SolveNode(node.Children[i]); return SolveFunctionNode((FunctionNode)node); } else if (node is ValueNode) { return GetResultNode((ValueNode)node); } else if (node is RootNode) { var firstChild = node.Children.FirstOrDefault(); if (firstChild == null) throw new ExecutorException("Asked to solve an empty tree!"); return SolveNode(firstChild); } throw new ExecutorException("Unrecognized node type!"); }
public ParseTree() { _root = new RootNode(); }
public override void AddChild(AbstractParseNode child) { throw new InvalidOperationException("Cannot all child nodes to values"); }
public virtual void AddChild(AbstractParseNode child) { child._parent = this; _nodes.Add(child); }
public void DepthFirstTraversalFrom(Action<AbstractParseNode> action, AbstractParseNode fromNode) { if (fromNode.GetType() != typeof(RootNode)) action.Invoke(fromNode); foreach (var childNode in fromNode.Children) DepthFirstTraversalFrom(action, childNode); }