public void Append(ConstraintOperator op)
 {
     op.LeftContext = lastPushed;
     if (lastPushed is ConstraintOperator)
     {
         SetTopOperatorRightContext(op);
     }
     ReduceOperatorStack(op.LeftPrecedence);
     ops.Push(op);
     lastPushed = op;
 }
        private void SetTopOperatorRightContext(object rightContext)
        {
            int leftPrecedence = ops.Top.LeftPrecedence;

            ops.Top.RightContext = rightContext;
            if (ops.Top.LeftPrecedence > leftPrecedence)
            {
                ConstraintOperator constraintOperator = ops.Pop();
                ReduceOperatorStack(constraintOperator.LeftPrecedence);
                ops.Push(constraintOperator);
            }
        }
        /// <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;
        }
 public Constraint Resolve()
 {
     if (!IsResolvable)
     {
         throw new InvalidOperationException("A partial expression may not be resolved");
     }
     while (!ops.Empty)
     {
         ConstraintOperator constraintOperator = ops.Pop();
         constraintOperator.Reduce(constraints);
     }
     return(constraints.Pop());
 }
Exemple #5
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);
            }
        }
 /// <summary>
 /// Appends an operator to the expression and returns the
 /// resulting expression itself.
 /// </summary>
 public ConstraintExpression Append(ConstraintOperator op)
 {
     builder.Append(op);
     return(this);
 }
Exemple #7
0
 /// <summary>
 /// Pushes the specified operator onto the stack.
 /// </summary>
 /// <param name="op">The op.</param>
 public void Push(ConstraintOperator op)
 {
     stack.Push(op);
 }
 /// <summary>
 /// Appends an operator to the expression and returns the
 /// resulting expression itself.
 /// </summary>
 public ConstraintExpression Append(ConstraintOperator op)
 {
     builder.Append(op);
     return (ConstraintExpression)this;
 }
 /// <summary>
 /// Pushes the specified operator onto the stack.
 /// </summary>
 /// <param name="op">The op.</param>
 public void Push(ConstraintOperator op)
 {
     stack.Push(op);
 }