private static BasicExpression Type(BasicExpression x, BasicType expected) { if (x.Type != expected) { string error = string.Format( CultureInfo.InvariantCulture, "Type mismatch; expected [{0}] to be of type {1} but was of type {2}.", x, expected, x.Type); throw new ParseException(error); } return(x); }
private BasicType CheckType(BasicExpression x, BasicExpression y) { if (x.Type != y.Type) { string error = string.Format( CultureInfo.InvariantCulture, "Type mismatch for operator '{0}'; Type of [{1}] is {2} while type of [{3}] is {4}.", this.name, x, x.Type, y, y.Type); throw new ParseException(error); } BasicType result = this.type; if (result == BasicType.None) { result = x.Type; } return(result); }
public BasicExpression Apply(BasicExpression x, BasicExpression y) { BasicType result = this.CheckType(x, y); return(BasicOperator.Binary(this.name, result, x, y)); }
public static BasicExpression Apply(IOperator op, BasicExpression x, BasicExpression y) { return(op.Apply(x, y)); }
public static BasicExpression Num(BasicExpression x) => Type(x, BasicType.Num);
public static BasicExpression Str(BasicExpression x) => Type(x, BasicType.Str);