Ejemplo n.º 1
0
        // If we find an operator on the right, we produce a new operation node, otherwise, the primitive will be returned
        private AbstractExpressionNode ExecuteIfOperator(AbstractExpressionNode prime, Func <AbstractExpressionNode> operation, IEnumerable <OperatorType> operators)
        {
            var op = operators.FirstOrDefault(IsOperator);

            if (op != OperatorType.None)
            {
                return(new OperationNode(op, prime, operation()));
            }
            return(prime);
        }
 public override void OptimizeChilds()
 {
     Expression.OptimizeChilds();
     Expression = Expression.Optimize();
 }
Ejemplo n.º 3
0
        private AbstractExpressionNode AbstractAssign(AbstractExpressionNode left)
        {
            var assignationOperators = new[]
            {
                OperatorType.Assign,
                OperatorType.AddAssign,
                OperatorType.SubAssign,
                OperatorType.MulAssign,
                OperatorType.PowAssign,
                OperatorType.EuclidianDivAssign,
                OperatorType.DivAssign,
                OperatorType.ModAssign,
                OperatorType.Increment,
                OperatorType.Decrement,
            };
            var op = assignationOperators.FirstOrDefault(IsOperator);

            if (op == OperatorType.None)
            {
                throw new InvalidOperationException($"wrong assignation operator {PeekToken()}");
            }
            AbstractExpressionNode expression = null;

            switch (op)
            {
            case OperatorType.Assign:
                expression = ArithmeticExpression();
                break;

            case OperatorType.AddAssign:
                expression = new OperationNode(OperatorType.Add, left, ArithmeticExpression());
                break;

            case OperatorType.SubAssign:
                expression = new OperationNode(OperatorType.Sub, left, ArithmeticExpression());
                break;

            case OperatorType.MulAssign:
                expression = new OperationNode(OperatorType.Mul, left, ArithmeticExpression());
                break;

            case OperatorType.DivAssign:
                expression = new OperationNode(OperatorType.Div, left, ArithmeticExpression());
                break;

            case OperatorType.ModAssign:
                expression = new OperationNode(OperatorType.Mod, left, ArithmeticExpression());
                break;

            case OperatorType.PowAssign:
                expression = new OperationNode(OperatorType.Pow, left, ArithmeticExpression());
                break;

            case OperatorType.EuclidianDivAssign:
                expression = new OperationNode(OperatorType.EuclidianDiv, left, ArithmeticExpression());
                break;

            case OperatorType.Increment:
                expression = OperationNode.Increment(left);
                break;

            case OperatorType.Decrement:
                expression = OperationNode.Decrement(left);
                break;
            }
            return(expression);
        }
 public AbstractDeclarationNode(AbstractExpressionNode expression) : base(NodeType.Declaration)
 {
     Expression = expression;
 }