Example #1
0
        void PlusMinusTerm(out Expression aexp)
        {
            ArithmeticBinOp op; Expression right = null, left = null;

            UnaryMinusTerm(out left);
            aexp = left;
            while (la.kind == 22 || la.kind == 37 || la.kind == 38)
            {
                if (la.kind == 37)
                {
                    Get();
                    op = ArithmeticBinOp.Multiply;
                }
                else if (la.kind == 22)
                {
                    Get();
                    op = ArithmeticBinOp.Divide;
                }
                else
                {
                    Get();
                    op = ArithmeticBinOp.Modulo;
                }
                UnaryMinusTerm(out right);
                aexp = new ArithmeticBinOpExpression(aexp, right, op); CopyPos(aexp, ((ArithmeticBinOpExpression)aexp).Left, t);
            }
        }
        public override void Visit(ArithmeticBinOpExpression exp)
        {
            if (exp.Left is Number && exp.Right is Number)
            {
                int result = 0, leftVal, rightVal;
                leftVal  = ((Number)exp.Left).Value;
                rightVal = ((Number)exp.Right).Value;

                if (exp.Op == ArithmeticBinOp.Plus)
                {
                    result = rightVal + leftVal;
                }
                else if (exp.Op == ArithmeticBinOp.Minus)
                {
                    result = leftVal - rightVal;
                }
                else if (exp.Op == ArithmeticBinOp.Multiply)
                {
                    result = leftVal * rightVal;
                }
                else if (exp.Op == ArithmeticBinOp.Divide)
                {
                    result = leftVal / rightVal;
                }
                exp.Parent.Replace(exp, new Number(result));
            }
        }
Example #3
0
        public virtual string Format(ArithmeticBinOpExpression exp)
        {
            char op = 'E';

            if (exp.Op == ArithmeticBinOp.Divide)
            {
                op = '/';
            }
            else if (exp.Op == ArithmeticBinOp.Minus)
            {
                op = '-';
            }
            else if (exp.Op == ArithmeticBinOp.Modulo)
            {
                op = '%';
            }
            else if (exp.Op == ArithmeticBinOp.Multiply)
            {
                op = '*';
            }
            else if (exp.Op == ArithmeticBinOp.Plus)
            {
                op = '+';
            }
            return(SurroundWithParens(Format(exp.Left) + op + Format(exp.Right), exp.ParenCount));
        }
        //Expressions
        public override void Visit(ArithmeticBinOpExpression node)
        {
            string op = "";

            if (node.Op == ArithmeticBinOp.Divide)
            {
                op = "/";
            }
            else if (node.Op == ArithmeticBinOp.Minus)
            {
                op = "-";
            }
            else if (node.Op == ArithmeticBinOp.Plus)
            {
                op = "+";
            }
            else if (node.Op == ArithmeticBinOp.Modulo)
            {
                op = "%";
            }
            else if (node.Op == ArithmeticBinOp.Multiply)
            {
                op = "*";
            }
            List <string> children = PopChildren();

            Return(SurroundWithParens(children[0] + op + children[1], node.ParenCount));
        }
Example #5
0
        void ArithmeticExpression(out Expression aexp)
        {
            ArithmeticBinOp op; Expression right = null, left = null;

            PlusMinusTerm(out left);
            aexp = left;
            while (la.kind == 14 || la.kind == 36)
            {
                if (la.kind == 14)
                {
                    Get();
                    op = ArithmeticBinOp.Plus;
                }
                else
                {
                    Get();
                    op = ArithmeticBinOp.Minus;
                }
                PlusMinusTerm(out right);
                aexp = new ArithmeticBinOpExpression(aexp, right, op); CopyPos(aexp, ((ArithmeticBinOpExpression)aexp).Left, t);
            }
        }
 //Expressions
 public virtual void Visit(ArithmeticBinOpExpression node)
 {
 }