void PlusMinusTerm(out Expression aexp)
 {
     ArithmeticBinOp op; Expression right = null, left = null;
     UnaryMinusTerm(out left);
     aexp = left;
     while (la.kind == 10 || la.kind == 22 || la.kind == 23) {
     if (la.kind == 10) {
         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(((ArithmeticBinOpExpression)aexp).Left,aexp,t);
     }
 }
 void Expression(out Expression aexp)
 {
     ArithmeticBinOp op; Expression right = null, left = null;
     PlusMinusTerm(out left);
     aexp = left;
     while (la.kind == 11 || la.kind == 21) {
     if (la.kind == 11) {
         Get();
         op = ArithmeticBinOp.Plus;
     } else {
         Get();
         op = ArithmeticBinOp.Minus;
     }
     PlusMinusTerm(out right);
     aexp = new ArithmeticBinOpExpression(aexp, right, op); CopyPos(((ArithmeticBinOpExpression)aexp).Left,aexp,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));
            }
        }
 //Expressions
 public virtual void Visit(ArithmeticBinOpExpression node)
 {
 }
 //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));
 }
 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);
 }