Ejemplo n.º 1
0
 public OperNode(string operType, int operWeight, ValueNode leftVal, OperNode prevOper)
 {
     OperType   = operType;
     OperVeight = operWeight;
     LeftVal    = leftVal;
     RightVal   = null;
     PrevOper   = prevOper;
     NextOper   = null;
 }
Ejemplo n.º 2
0
        /// <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;
        }
Ejemplo n.º 3
0
 /// <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);
Ejemplo n.º 4
0
 /// <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)
 {
 }
Ejemplo n.º 5
0
 /// <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);