Пример #1
0
        private Expression CompileBinaryExpression(int baseLevel, int lambdaLevel)
        {
            Expression current = CompileUnaryExpression(lambdaLevel);

            PushPosition();


            while (!End)
            {
                BinaryOperator op = ExpressionSnippets.GetBinaryOperator(GetPunctuation());

                if (op == BinaryOperator.None)
                {
                    break;
                }


                if (ExpressionSnippets.GetOperatorLevel(op) <= baseLevel)
                {
                    break;
                }
                else
                {
                    Move();

                    int fromPos = PeekPos();
                    int toPos   = Pos;

                    current = new BinaryExpression(op, current, CompileBinaryExpression(ExpressionSnippets.GetOperatorLevel(op), lambdaLevel), fromPos, toPos);
                }
            }

            PopPosition();
            return(current);
        }
Пример #2
0
        public override Expression Reduce(Expression root, ExpressionReductor reductor)
        {
            if (root is BinaryExpression)
            {
                Expression left  = reductor.Reduce((root as BinaryExpression).Left);
                Expression right = reductor.Reduce((root as BinaryExpression).Right);
                if (left is BinaryExpression && ExpressionSnippets.GetOperatorLevel((left as BinaryExpression).Operator) == ExpressionSnippets.GetOperatorLevel((root as BinaryExpression).Operator))
                {
                    Expression ll = reductor.Reduce((left as BinaryExpression).Left);
                    Expression lr = reductor.Reduce((left as BinaryExpression).Right);

                    if (lr.IsConstantExpression())
                    {
                        return(BinaryExpression.Create((left as BinaryExpression).Operator, ll, BinaryExpression.Create((root as BinaryExpression).Operator, lr, right)));
                    }
                }
            }


            return(root);
        }