예제 #1
0
        public static int GetOperatorPrecedence(ETypeExpr op)
        {
            switch (op)
            {
            case ETypeExpr.Number:
            case ETypeExpr.Literal:
                return(6);

            case ETypeExpr.Power:
                return(5);

            case ETypeExpr.Negate:
                return(4);

            case ETypeExpr.Multiply:
            case ETypeExpr.Divide:
                return(3);

            case ETypeExpr.Add:
            case ETypeExpr.Subtract:
                return(2);

            case ETypeExpr.Equal:
                return(1);

            default:
                return(0);
            }
        }
예제 #2
0
파일: UnaryExpr.cs 프로젝트: bugbit/algebra
        public UnaryExpr(ETypeExpr op, Expr operand) : base(op)
        {
            switch (op)
            {
            case ETypeExpr.Negate:
                Operand = operand ?? Null;
                break;

            default:
                throw new ArgumentException($"{op} not unary operator");
            }
        }
예제 #3
0
        public FunctionExpr(ETypeExpr argFunc, Expr argArg) : base(argFunc)
        {
            switch (argFunc)
            {
            case ETypeExpr.Sin:
            case ETypeExpr.Cos:
                Argument = argArg ?? Null;
                break;

            default:
                throw new ArgumentException($"{argFunc} not function operator");
            }
        }
예제 #4
0
        public static Expr Unary(ETypeExpr op, Expr operand)
        {
            if (op == ETypeExpr.Negate)
            {
                if (operand is NumberExpr n)
                {
                    return(new NumberExpr(-n.Value));
                }

                if (operand is UnaryExpr u && u.TypeExpr == ETypeExpr.Negate)
                {
                    return(u.Operand);
                }
            }

            return(new UnaryExpr(op, operand));
        }
예제 #5
0
        public BinaryExpr(ETypeExpr op, Expr left, Expr right) : base(op)
        {
            switch (op)
            {
            case ETypeExpr.Add:
            case ETypeExpr.Divide:
            case ETypeExpr.Multiply:
            case ETypeExpr.Subtract:
            case ETypeExpr.Power:
            case ETypeExpr.Equal:
                Left  = left ?? Null;
                Right = right ?? Null;
                break;

            default:
                throw new ArgumentException($"{op} not binary operator");
            }
        }
예제 #6
0
파일: Expr.cs 프로젝트: bugbit/CASSharp
 protected Expr(ETypeExpr argTypeExpr)
 {
     TypeExpr = argTypeExpr;
 }
예제 #7
0
 public Cell(Expr e, ETypeExpr op = ETypeExpr.Null)
 {
     Expr   = e;
     TypeOp = op;
 }
예제 #8
0
 public WordExpr(ETypeExpr argTypeExpr, string argWord) : base(argTypeExpr)
 {
     Word = argWord;
 }
예제 #9
0
 public CteExpr(ETypeExpr argTypeExpr, T argCte) : base(argTypeExpr)
 {
     Constant = argCte;
 }
예제 #10
0
 public CteExpr(ETypeExpr argTypeExpr, T argCte) : base(ETypeExpr.Constant | (argTypeExpr & ETypeExpr.Flags))
 {
     Constant = argCte;
 }
예제 #11
0
 public static FunctionExpr Function(ETypeExpr fn, Expr argArg) => new FunctionExpr(fn, argArg);
예제 #12
0
 public static BinaryExpr Binary(ETypeExpr op, Expr l, Expr r) => new BinaryExpr(op, l, r);
예제 #13
0
 public Expr(ETypeExpr argType)
 {
     TypeExpr = argType;
 }