Exemplo n.º 1
0
 public static EV3Type ConvertToArray(this EV3Type type)
 {
     if (!type.IsArray())
     {
         return((EV3Type)((int)type + ARRAY_OFFSET));
     }
     else
     {
         return(type);
     }
 }
Exemplo n.º 2
0
 public static EV3Type BaseType(this EV3Type type)
 {
     if (type.IsArray())
     {
         return((EV3Type)((int)type - ARRAY_OFFSET));
     }
     else
     {
         return(type);
     }
 }
Exemplo n.º 3
0
        protected override string CalculateValue()
        {
            if (LeftCompiler.IsLiteral && RightCompiler.IsLiteral)
            {
                EV3Type commonType = CalculateCommonType(LeftCompiler.Type, RightCompiler.Type);

                if (commonType.IsArray() || commonType == EV3Type.Unknown)
                {
                    return(null);
                }

                if (commonType.IsNumber())
                {
                    float leftValue  = SmallBasicExtensions.ParseFloat(LeftCompiler.Value);
                    float rightValue = SmallBasicExtensions.ParseFloat(RightCompiler.Value);
                    switch (ParentExpression.Operator.Token)
                    {
                    case Token.Addition:
                        return(SmallBasicExtensions.FormatFloat(leftValue + rightValue));

                    case Token.Subtraction:
                        return(SmallBasicExtensions.FormatFloat(leftValue - rightValue));

                    case Token.Division:
                        return(SmallBasicExtensions.FormatFloat(leftValue / rightValue));

                    case Token.Multiplication:
                        return(SmallBasicExtensions.FormatFloat(leftValue * rightValue));
                    }
                }
                else
                {
                    if (ParentExpression.Operator.Token == Token.Addition)
                    {
                        string leftValue = LeftCompiler.Value.Trim('\'');
                        if (LeftCompiler.Type.IsNumber())
                        {
                            leftValue = SmallBasicExtensions.FormatFloat(leftValue);
                        }
                        string rightValue = RightCompiler.Value.Trim('\'');
                        if (RightCompiler.Type.IsNumber())
                        {
                            rightValue = SmallBasicExtensions.FormatFloat(rightValue);
                        }

                        return('\'' + leftValue + rightValue + '\'');
                    }
                }
            }
            return(null);
        }
Exemplo n.º 4
0
        protected EV3Type CalculateCommonType(EV3Type type1, EV3Type type2)
        {
            if (type1.BaseType() == type2.BaseType())
            {
                if (type1.IsArray())
                {
                    return(type1);
                }
                return(type2);
            }
            if (type1.BaseType().IsNumber() && type2.BaseType().IsNumber())
            {
                return(EV3Type.Float);
            }
            if ((type1.BaseType().IsNumber() && type2.BaseType() == EV3Type.String) || (type1.BaseType() == EV3Type.String && type2.BaseType().IsNumber()))
            {
                return(EV3Type.String);
            }

            return(EV3Type.Unknown);
        }
Exemplo n.º 5
0
 public static bool IsArrayOf(this EV3Type type, EV3Type baseType)
 {
     return(type.IsArray() && type.BaseType() == baseType);
 }