Ejemplo n.º 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);
            }
Ejemplo n.º 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);
                }
Ejemplo n.º 3
0
                public BasicExpression Apply(BasicExpression x, BasicExpression y)
                {
                    BasicType result = this.CheckType(x, y);

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