public BinaryExpression(int bits, Expression left, Expression right)
        {
            if (left == null)
            {
                throw new ArgumentNullException(nameof(left));
            }

            if (right == null)
            {
                throw new ArgumentNullException(nameof(right));
            }

            if (bits <= 0 || bits > 32)
            {
                throw new ArgumentOutOfRangeException(nameof(bits), bits, "invalid value");
            }

            LeftOperand = left;
            RightOperand = right;
            int mask = 0;
            for (int n = 0; n < bits; n++)
            {
                mask <<= 1;
                mask |= 1;
            }
            Mask = mask;
        }
Esempio n. 2
0
        public AssignStatement(Expression expression, VariableExpression variable)
        {
            if (expression == null)
            {
                throw new ArgumentNullException(nameof(expression));
            }

            if (variable == null)
            {
                throw new ArgumentNullException(nameof(variable));
            }

            Value = expression;
            Variable = variable;
        }
Esempio n. 3
0
        public NotExpression(int bits, Expression expression)
        {
            if (expression == null)
            {
                throw new ArgumentNullException(nameof(expression));
            }

            Operand = expression;

            if (bits <= 0 || bits > 32)
            {
                throw new ArgumentOutOfRangeException(nameof(bits), bits, "invalid value");
            }

            int mask = 0;
            for (int n = 0; n < bits; n++)
            {
                mask <<= 1;
                mask |= 1;
            }
            Mask = mask;
        }
 public RightShiftExpression(int bits, Expression left, Expression right) : base(bits, left, right)
 {
 }
        public static Expression CreateBinaryExpression(int bits, Expression left, ITokenConsumeScope scope)
        {
            using (var local = scope.Begin())
            {
                string literal;
                if (left != null && local.EatLiteral(out literal).Ok())
                {
                    var right = CreateExpression(local);
                    if (right == null)
                    {
                        return null;
                    }
                    switch (literal)
                    {
                        case "LSHIFT":
                            local.Commit();
                            return new LeftShiftExpression(bits, left, right);

                        case "AND":
                            local.Commit();
                            return new AndExpression(bits, left, right);

                        case "OR":
                            local.Commit();
                            return new OrOperation(bits, left, right);

                        case "RSHIFT":
                            local.Commit();
                            return new RightShiftExpression(bits, left, right);
                    }
                }

                return null;
            }
        }
Esempio n. 6
0
 public OrOperation(int bits, Expression left, Expression right) : base(bits, left, right)
 {
 }
Esempio n. 7
0
 public AndExpression(int bits, Expression left, Expression right) : base(bits, left, right)
 {
 }