Exemplo n.º 1
0
        /// <summary>
        /// Recognizes an addition or a subtraction.
        /// </summary>
        /// <returns>A <see cref="BinaryExpression"/></returns>
        protected Expression Term()
        {
            Expression expr = Factor();

            if (expr == null)
            {
                return(null);
            }

            var parts = new Queue <BinaryExpressionPart>();

            while (TryMatchAny(TokenID.Plus, TokenID.Minus))
            {
                BinaryOperator oper = token.ToBinaryOperator();
                Consume(1);
                var factor = Required <Expression>(Factor, Resources.ExpressionRequired);
                parts.Enqueue(new BinaryExpressionPart(oper, factor));
            }

            while (parts.Count > 0)
            {
                BinaryExpressionPart part = parts.Dequeue();
                expr = new BinaryExpression(part.Operator, expr, part.Operand);
            }

            return(expr);
        }
Exemplo n.º 2
0
        /// <summary>
        /// Recognizes a multiplication, a divison, a modulo or a shift.
        /// </summary>
        /// <returns>A <see cref="BinaryExpression"/></returns>
        protected Expression Factor()
        {
            Expression expr = Exponentiation();

            if (expr == null)
            {
                return(null);
            }

            var parts = new Queue <BinaryExpressionPart>();

            while (TryMatchAny(TokenID.Asterisk, TokenID.Slash, TokenID.Percent,
                               TokenID.DoubleLessThan, TokenID.DoubleGreaterThan))
            {
                BinaryOperator oper = token.ToBinaryOperator();
                Consume(1);
                var expon = Required <Expression>(Exponentiation, Resources.ExpressionRequired);
                parts.Enqueue(new BinaryExpressionPart(oper, expon));
            }

            while (parts.Count > 0)
            {
                BinaryExpressionPart part = parts.Dequeue();
                expr = new BinaryExpression(part.Operator, expr, part.Operand);
            }

            return(expr);
        }
Exemplo n.º 3
0
        /// <summary>
        /// Recognizes a logical expression.
        /// </summary>
        /// <returns>A <see cref="BinaryExpression"/></returns>
        protected Expression Condition()
        {
            Expression expr = Relation();

            if (expr == null)
            {
                return(null);
            }

            var parts = new Queue <BinaryExpressionPart>();

            while (TryMatchAny(TokenID.Ampersand, TokenID.DoubleAmpersand,
                               TokenID.VerticalBar, TokenID.DoubleVerticalBar,
                               TokenID.Circumflex))
            {
                BinaryOperator oper = token.ToBinaryOperator();
                Consume(1);
                var relation = Required <Expression>(Relation, Resources.ExpressionRequired);
                parts.Enqueue(new BinaryExpressionPart(oper, relation));
            }

            while (parts.Count > 0)
            {
                BinaryExpressionPart part = parts.Dequeue();
                expr = new BinaryExpression(part.Operator, expr, part.Operand);
            }

            return(expr);
        }