Exemple #1
0
        public override double generate(SymbolTable table)
        {
            double l = left.generate(table);
            double r = right.generate(table);

            switch (ope)
            {
            case Exp_Operator.DIVI:
                if (r == 0)
                {
                    return(0);
                }
                return(l / r);

            case Exp_Operator.MINU:
                return(l - r);

            case Exp_Operator.MULT:
                return(l * r);

            case Exp_Operator.PLUS:
                return(l + r);

            case Exp_Operator.EQUAL:
                table.set(left.getID(), r);
                return(r);

            case Exp_Operator.LESS_THAN:
                return(l < r ? 1 : 0);

            case Exp_Operator.GREATER_THAN:
                return(l > r ? 1 : 0);

            case Exp_Operator.IF_EQUAL:
                return(l == r ? 1 : 0);

            case Exp_Operator.NOT_EQUAL:
                return(l != r ? 1 : 0);

            case Exp_Operator.LESS_EQUAL_THAN:
                return(l <= r ? 1 : 0);

            case Exp_Operator.GREATER_EQUAL_THAN:
                return(l >= r ? 1 : 0);

            default:
                LogWriter.WriteErrText("Unknown double operator " + ope.ToString());
                break;
            }
            return(0);
        }
Exemple #2
0
        public override double generate(SymbolTable table)
        {
            double d = expression.generate(table);

            switch (ope)
            {
            case Exp_Operator.ABS:
                return(Math.Abs(d));

            case Exp_Operator.ACOS:
                return(scale * Math.Acos(d));

            case Exp_Operator.ASIN:
                return(scale * Math.Asin(d));

            case Exp_Operator.ATAN:
                return(scale * Math.Atan(d));

            case Exp_Operator.COS:
                return(Math.Cos(d / scale));

            case Exp_Operator.EXP:
                return(Math.Exp(d));

            case Exp_Operator.LOG:
                return(Math.Log(d));

            case Exp_Operator.SIN:
                return(Math.Sin(d / scale));

            case Exp_Operator.SQRT:
                return(Math.Sqrt(d));

            case Exp_Operator.TAN:
                return(Math.Tan(d / scale));

            case Exp_Operator.MINU:
                return(-d);

            case Exp_Operator.NONE:
                return(d);

            default:
                LogWriter.WriteErrText("Unkown single operator " + ope.ToString());
                break;
            }
            return(0);
        }