Beispiel #1
0
            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);
            }
Beispiel #2
0
                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);
                }
Beispiel #3
0
                public BasicExpression Apply(BasicExpression x, BasicExpression y)
                {
                    BasicType result = this.CheckType(x, y);

                    return(BasicOperator.Binary(this.name, result, x, y));
                }
Beispiel #4
0
 public static BasicExpression Apply(IOperator op, BasicExpression x, BasicExpression y)
 {
     return(op.Apply(x, y));
 }
Beispiel #5
0
 public static BasicExpression Num(BasicExpression x) => Type(x, BasicType.Num);
Beispiel #6
0
 public static BasicExpression Str(BasicExpression x) => Type(x, BasicType.Str);