Beispiel #1
0
        public void Visit(PowExpr powExpr, object[] args)
        {
            powExpr.FirstOp.Accept(this);
            powExpr.SecondOp.Accept(this);

            RightValue v1 = readRightValue(powExpr.FirstOp);
            RightValue v2 = readRightValue(powExpr.SecondOp);


            DataType resultType = readAlgoOperand(v1, v2, powExpr.Location);

            if (resultType == DataType.Int)
            {
                IntConst result = new IntConst();
                result.Value       = (int)Math.Pow(Convert.ToInt32(v1.GetValueObject()), Convert.ToInt32(v2.GetValueObject()));
                powExpr.RightValue = result;
                //powExpr.DataType = DataType.Int;
            }
            else if (resultType == DataType.Float)
            {
                FloatConst result = new FloatConst();
                result.Value       = Math.Pow(Convert.ToDouble(v1.GetValueObject()), Convert.ToDouble(v2.GetValueObject()));
                powExpr.RightValue = result;
                //powExpr.DataType = DataType.Float;
            }
            else
            {
                throw new Exception();
            }
        }
Beispiel #2
0
 public Value Visit(PowExpr expr, Scope scope)
 {
     return(PerformOperation(expr.Left.Accept(this, scope),
                             expr.Right.Accept(this, scope),
                             (a, b) => Math.Pow(a, b),
                             (a, b) => Math.Pow(a, b),
                             (a, b) => { throw new InvalidOperationException(); },
                             (a, b) => { throw new InvalidOperationException(); }));
 }
Beispiel #3
0
 public string Visit(PowExpr expr, Scope scope)
 {
     return(expr.Left.Accept(this, scope) + "^" + expr.Right.Accept(this, scope));
 }
Beispiel #4
0
 public ValueType Visit(PowExpr expr, Scope scope)
 {
     return(BinaryOperatorTypeCheck(expr, scope, numericTypesOnly: true));
 }