protected override string CalculateValue() { string valueString = ParentExpression.ToString(); if (ParentExpression.IsNumericLiteral()) { return(SmallBasicExtensions.FormatFloat(valueString)); } else { return(valueString.Replace('"', '\'')); } }
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); }
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); }
protected string CompileWithConvert(TextWriter writer, IExpressionCompiler compiler, EV3Type resultType, EV3Variables.TempVariableCreator tempVariables) { string value = compiler.Compile(writer, tempVariables.CreateVariable(compiler.Type)); if (compiler.Type.BaseType().IsNumber() && resultType.BaseType() == EV3Type.String) { if (compiler.IsLiteral) { return("'" + SmallBasicExtensions.FormatFloat(value) + "'"); } else { IEV3Variable outputVariable = tempVariables.CreateVariable(EV3Type.String); writer.WriteLine($" STRINGS VALUE_FORMATTED {value} '%g' 99 {outputVariable.Ev3Name}"); return(outputVariable.Ev3Name); } } else { return(value); } }