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);
        }
示例#2
0
        protected override string CalculateValue()
        {
            if (Type != EV3Type.Boolean)
            {
                return(null);
            }

            if (LeftCompiler.IsLiteral && RightCompiler.IsLiteral)
            {
                if (LeftCompiler.Type.IsNumber())
                {
                    float leftValue  = SmallBasicExtensions.ParseFloat(LeftCompiler.Value);
                    float rightValue = SmallBasicExtensions.ParseFloat(RightCompiler.Value);

                    switch (ParentExpression.Operator.Token)
                    {
                    case Token.Equals:
                        return(SmallBasicExtensions.FormatBoolean(leftValue == rightValue));

                    case Token.NotEqualTo:
                        return(SmallBasicExtensions.FormatBoolean(leftValue != rightValue));

                    case Token.LessThan:
                        return(SmallBasicExtensions.FormatBoolean(leftValue < rightValue));

                    case Token.LessThanEqualTo:
                        return(SmallBasicExtensions.FormatBoolean(leftValue <= rightValue));

                    case Token.GreaterThan:
                        return(SmallBasicExtensions.FormatBoolean(leftValue > rightValue));

                    case Token.GreaterThanEqualTo:
                        return(SmallBasicExtensions.FormatBoolean(leftValue >= rightValue));
                    }
                }
                else
                {
                    switch (ParentExpression.Operator.Token)
                    {
                    case Token.Equals:
                        return(SmallBasicExtensions.FormatBoolean(LeftCompiler.Value == RightCompiler.Value));

                    case Token.NotEqualTo:
                        return(SmallBasicExtensions.FormatBoolean(LeftCompiler.Value != RightCompiler.Value));
                    }
                }
            }
            return(null);
        }
示例#3
0
 protected override string CalculateValue()
 {
     if (Type.IsNumber())
     {
         if (IsLiteral)
         {
             return(SmallBasicExtensions.FormatFloat(-SmallBasicExtensions.ParseFloat(ParentExpression.Expression.Compiler().Value)));
         }
     }
     else
     {
         AddError("Need number after minus");
     }
     return(null);
 }