Ejemplo n.º 1
0
        /// <summary>
        /// Appends the specified operator to the expression by first
        /// reducing the operator stack and then pushing the new
        /// operator on the stack.
        /// </summary>
        /// <param name="op">The operator to push.</param>
        public void Append(ConstraintOperator op)
        {
            op.LeftContext = lastPushed;
            if (lastPushed is ConstraintOperator)
            {
                SetTopOperatorRightContext(op);
            }

            // Reduce any lower precedence operators
            ReduceOperatorStack(op.LeftPrecedence);

            ops.Push(op);
            lastPushed = op;
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Resolves this instance, returning a Constraint. If the builder
        /// is not currently in a resolvable state, an exception is thrown.
        /// </summary>
        /// <returns>The resolved constraint</returns>
        public IConstraint Resolve()
        {
            if (!IsResolvable)
            {
                throw new InvalidOperationException("A partial expression may not be resolved");
            }

            while (!ops.Empty)
            {
                ConstraintOperator op = ops.Pop();
                op.Reduce(constraints);
            }

            return(constraints.Pop());
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Sets the top operator right context.
        /// </summary>
        /// <param name="rightContext">The right context.</param>
        private void SetTopOperatorRightContext(object rightContext)
        {
            // Some operators change their precedence based on
            // the right context - save current precedence.
            int oldPrecedence = ops.Top.LeftPrecedence;

            ops.Top.RightContext = rightContext;

            // If the precedence increased, we may be able to
            // reduce the region of the stack below the operator
            if (ops.Top.LeftPrecedence > oldPrecedence)
            {
                ConstraintOperator changedOp = ops.Pop();
                ReduceOperatorStack(changedOp.LeftPrecedence);
                ops.Push(changedOp);
            }
        }
Ejemplo n.º 4
0
 /// <summary>
 /// Appends an operator to the expression and returns the
 /// resulting expression itself.
 /// </summary>
 public ConstraintExpression Append(ConstraintOperator op)
 {
     Builder.Append(op);
     return(this);
 }
Ejemplo n.º 5
0
 /// <summary>
 /// Pushes the specified operator onto the stack.
 /// </summary>
 /// <param name="op">The op.</param>
 public void Push(ConstraintOperator op) => _stack.Push(op);