Beispiel #1
0
        private TinyValue Add(TinyUnityParser.AddExpressionContext context)
        {
            TinyValue lhs = this.Visit(context.expression(0));
            TinyValue rhs = this.Visit(context.expression(1));

            if (lhs == null || rhs == null)
            {
                throw new EvalException("Null operators: " + context.op.Type, context);
            }

            if (lhs.value is float && rhs.value is float)
            {
                return(new TinyValue((float)lhs.value + (float)rhs.value));
            }

            if (lhs.isList())
            {
                List <TinyValue> nlst = lhs.asList();
                nlst.Add(rhs);
                return(new TinyValue(nlst));
            }

            if (lhs.isString())
            {
                return(new TinyValue(lhs.asString() + rhs.value.ToString()));
            }

            if (rhs.isString())
            {
                return(new TinyValue(lhs.value.ToString() + rhs.asString()));
            }

            return(new TinyValue(lhs.value.ToString() + rhs.value.ToString()));
        }
Beispiel #2
0
        private TinyValue Subtract(TinyUnityParser.AddExpressionContext context)
        {
            TinyValue lhs = this.Visit(context.expression(0));
            TinyValue rhs = this.Visit(context.expression(1));

            if (lhs == null || rhs == null)
            {
                throw new EvalException("Null operators: " + context.op.Type, context);
            }

            if (lhs.value is float && rhs.value is float)
            {
                return(new TinyValue((float)lhs.value - (float)rhs.value));
            }

            if (lhs.isList())
            {
                List <TinyValue> nlst = lhs.asList();
                nlst.Remove(rhs);
                return(new TinyValue(nlst));
            }

            throw new EvalException("Bad operators: " + context.op.Type, context);
        }