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); } }
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"); } }
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"); } }
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)); }
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"); } }
protected Expr(ETypeExpr argTypeExpr) { TypeExpr = argTypeExpr; }
public Cell(Expr e, ETypeExpr op = ETypeExpr.Null) { Expr = e; TypeOp = op; }
public WordExpr(ETypeExpr argTypeExpr, string argWord) : base(argTypeExpr) { Word = argWord; }
public CteExpr(ETypeExpr argTypeExpr, T argCte) : base(argTypeExpr) { Constant = argCte; }
public CteExpr(ETypeExpr argTypeExpr, T argCte) : base(ETypeExpr.Constant | (argTypeExpr & ETypeExpr.Flags)) { Constant = argCte; }
public static FunctionExpr Function(ETypeExpr fn, Expr argArg) => new FunctionExpr(fn, argArg);
public static BinaryExpr Binary(ETypeExpr op, Expr l, Expr r) => new BinaryExpr(op, l, r);
public Expr(ETypeExpr argType) { TypeExpr = argType; }