示例#1
0
        public SyntaxBlock Simplify()
        {
            A = A.Simplify();
            B = B.Simplify();


            var a = A as NumericConstant;
            var b = B as NumericConstant;

            if (a == null && b == null) //Neither A nor B are numeric constants, return this sum in its existing state.
            {
                return(this);
            }

            if (a != null && b != null) //Both A and B are numeric constants, return new numeric constant that is the sum of both.
            {
                return(new NumericConstant(a.value + b.value));
            }

            if (a?.value == 0)  //if a is zero, return B;
            {
                return(B);
            }

            if (b?.value == 0)  //if b is zero, return A;
            {
                return(A);
            }

            return(this); //No simplification possible, return this sum in its existing state.
        }
        public SyntaxBlock Simplify()
        {
            A = A.Simplify();
            B = B.Simplify();

            var a = A as NumericConstant;
            var b = B as NumericConstant;

            if (a == null && b == null) //Neither A nor B are numeric constants, return this quotient in its existing state.
            {
                return(this);
            }

            if (a != null && b != null) //Both A and B are numeric constants, return new numeric constant that is the quotient of both.
            {
                return(new NumericConstant(a.value / b.value));
            }

            if (a?.value == 0)
            {
                return(new NumericConstant(0));
            }

            if (b?.value == 1)
            {
                return(A);
            }
            else if (b?.value == 0)
            {
                throw new DivideByZeroException("Can't devide by zero!");
            }
            return(this); //No simplification possible, return this quotient in its existing state.
        }
 public SyntaxBlock Simplify()
 {
     A = A.Simplify();
     B = B.Simplify();
     return(SimplifySelf());
 }