public OperNode(string operType, int operWeight, ValueNode leftVal, OperNode prevOper) { OperType = operType; OperVeight = operWeight; LeftVal = leftVal; RightVal = null; PrevOper = prevOper; NextOper = null; }
/// <summary> /// Adds a <see cref="OperNode"/> to the expression tree. /// </summary> /// <param name="node">The <see cref="OperNode"/> to add to the expression tree.</param> public void AddNode(OperNode node) { bool insert = !(node is UOperNode); if (_activeNode == null) { // This is the first Branch Node if (Root != null) { // The first node is often a ValueNode // That is the only time a ValueNode will be the active or root node // Makes node the new active_node node.AddChild(Root); } Root = node; _activeNode = node; return; } FindInsertionNode(node); if (node.Priority > _activeNode.Priority) { // The new node is a lower priority than any node so far // or a parenthesis/function was hit // Add new node to top if (_activeNode.Priority == Priority.OVERRIDE) { InsertOperNode(node, insert); } else if (Root == _activeNode) { // node is new root node.AddChild(Root); Root = node; } } else if (node.Priority == _activeNode.Priority && (node is NOperNode)) { for (int i = 0; i < node.ChildCount; i++) { _activeNode.AddChild(node); } return; } else { InsertOperNode(node, insert); } _activeNode = node; }
/// <summary> /// Executes operation on an <see cref="OperNode"/>. /// </summary> /// <param name="node">The <see cref="OperNode"/> to execute operation on.</param> /// <returns>The result of the operation on an <see cref="OperNode"/>.</returns> public virtual ExpNode Execute(OperNode node) => Execute((BranchNode)node);
/// <summary> /// Initializes a new instance of the <see cref="CannotMultiplyTensors"/> class. /// </summary> /// <param name="simplifier">The simplified that threw.</param> /// <param name="context">The <see cref="OperNode"/> that it threw simplifying.</param> /// <param name="message">The <see cref="Exception"/> message.</param> public CannotMultiplyTensors(Simplifier simplifier, OperNode context, string message = "") : base(simplifier, context, message) { }
/// <summary> /// Prints an <see cref="OperNode"/>. /// </summary> /// <param name="node">The <see cref="OperNode"/> to print.</param> /// <returns>The <see cref="OperNode"/> printed to a string.</returns> public virtual string Print(OperNode node) => Print((BranchNode)node);