Esempio n. 1
0
    public static float ReadFloat(string Operation)
    {
        string Line = Operation;

        if (Line.StartsWith(" "))
        {
            Line.Remove(0);
        }
        Line = Line.Replace(" ", "");
        //Line = Line.Replace("f", "");
        Line = Line.Replace("+", " + ");
        Line = Line.Replace("-", " - ");
        Line = Line.Replace("*", " * ");
        Line = Line.Replace("/", " / ");
        Line = Line.Replace("^", " ^ ");
        Line = Line.Replace("(", "( ");
        Line = Line.Replace(")", " )");
        int PairStarting = Line.Split('(').Length - 1;
        int PairEnding   = Line.Split(')').Length - 1;

        if (PairStarting == PairEnding)
        {
            if (Line.Contains("(") && Line.Contains(")"))
            {
                int RepeatCount = PairStarting;
                for (int i = 0; i < RepeatCount; i++)
                {
                    Line = Line.Replace(CompileClass.ParenthesesReader(Line, true), CompileClass.ReadFloat(CompileClass.ParenthesesReader(Line, false)).ToString());
                }
            }
        }
        else
        {
            return(0.0f);
        }
        Line = CompileClass.FixMinusNumbers(Line);
        string[] LineParts = Line.Split(' ');
        for (int i = 0; i < LineParts.Length; i++)
        {
            if (LineParts[i] == "^")
            {
                if (i - 1 >= 0 && i + 1 < LineParts.Length)
                {
                    Line = Line.Replace((LineParts[i - 1] + " ^ " + LineParts[i + 1]).ToString(), (Mathf.Pow(float.Parse(LineParts[i - 1]), float.Parse(LineParts[i + 1]))).ToString());
                }
            }
        }
        Line      = CompileClass.FixMinusNumbers(Line);
        LineParts = Line.Split(' ');
        for (int i = 0; i < LineParts.Length; i++)
        {
            if (LineParts[i] == "/")
            {
                if (i - 1 >= 0 && i + 1 < LineParts.Length)
                {
                    Line = Line.Replace((LineParts[i - 1] + " / " + LineParts[i + 1]).ToString(), (float.Parse(LineParts[i - 1]) / float.Parse(LineParts[i + 1])).ToString());
                }
            }
            if (LineParts[i] == "*")
            {
                if (i - 1 >= 0 && i + 1 < LineParts.Length)
                {
                    Line = Line.Replace((LineParts[i - 1] + " * " + LineParts[i + 1]).ToString(), (float.Parse(LineParts[i - 1]) * float.Parse(LineParts[i + 1])).ToString());
                }
            }
        }
        Line      = CompileClass.FixMinusNumbers(Line);
        LineParts = Line.Split(' ');
        for (int i = 0; i < LineParts.Length; i++)
        {
            if (LineParts[i] == "+")
            {
                if (i - 1 >= 0 && i + 1 < LineParts.Length)
                {
                    //BUG ICI
                    //Debug.Log("Parse1: " + LineParts[i - 1]);
                    //Debug.Log("Parse2: " + LineParts[i + 1]);
                    Line = Line.Replace((LineParts[i - 1] + " + " + LineParts[i + 1]).ToString(), (float.Parse(LineParts[i - 1]) + float.Parse(LineParts[i + 1])).ToString());
                }
            }
            if (LineParts[i] == "-")
            {
                if (i - 1 >= 0 && i + 1 < LineParts.Length)
                {
                    Line = Line.Replace((LineParts[i - 1] + " - " + LineParts[i + 1]).ToString(), (float.Parse(LineParts[i - 1]) - float.Parse(LineParts[i + 1])).ToString());
                }
            }
        }
        Line = CompileClass.FixMinusNumbers(Line);
        return(float.Parse(Line));
    }
Esempio n. 2
0
    public static string ReadBoolean(string Operation)
    {
        string Line = Operation;

        Line = Line.Replace("!true", "false");
        Line = Line.Replace("!false", "true");
        Line = Line.Replace(" ", string.Empty);
        //Line = Line.Replace("f", string.Empty);
        //Line = Line.Replace("alse", "false");
        Line = Line.Replace("+", " + ");
        Line = Line.Replace("-", " - ");
        Line = Line.Replace(">", " > ");
        Line = Line.Replace("<", " < ");
        Line = Line.Replace(">=", " >= ");
        Line = Line.Replace("<=", " <= ");
        Line = Line.Replace("==", " == ");
        Line = Line.Replace("!=", " != ");
        Line = Line.Replace("*", " * ");
        Line = Line.Replace("/", " / ");
        Line = Line.Replace("^", " ^ ");
        Line = Line.Replace("(", "( ");
        Line = Line.Replace(")", " )");
        Line = Line.Replace("&&", " && ");
        Line = Line.Replace("||", " || ");
        Line = Line.Replace("True", "true").Replace("False", "false");
        int PairStarting = Line.Split('(').Length - 1;
        int PairEnding   = Line.Split(')').Length - 1;

        Line = CompileClass.FixMinusNumbers(Line);
        if (PairStarting == PairEnding)
        {
            if (Line.Contains("(") && Line.Contains(")"))
            {
                int RepeatCount = PairStarting;
                for (int i = 0; i < RepeatCount; i++)
                {
                    Line = Line.Replace(CompileClass.ParenthesesReader(Line, true), CompileClass.ReadBoolean(CompileClass.ParenthesesReader(Line, false)).ToString());
                }
            }
        }
        else
        {
            return("false");
        }
        string[] LineParts = Line.Split(' ');
        for (int i = 0; i < LineParts.Length; i++)
        {
            if (LineParts[i] == "^")
            {
                if (i - 1 >= 0 && i + 1 < LineParts.Length)
                {
                    Line = Line.Replace((LineParts[i - 1] + " ^ " + LineParts[i + 1]).ToString(), Mathf.Pow(float.Parse(LineParts[i - 1]), float.Parse(LineParts[i + 1])).ToString());
                }
            }
        }
        Line      = CompileClass.FixMinusNumbers(Line);
        LineParts = Line.Split(' ');
        for (int i = 0; i < LineParts.Length; i++)
        {
            if (LineParts[i] == "/")
            {
                if (i - 1 >= 0 && i + 1 < LineParts.Length)
                {
                    Line = Line.Replace((LineParts[i - 1] + " / " + LineParts[i + 1]).ToString(), (float.Parse(LineParts[i - 1]) / float.Parse(LineParts[i + 1])).ToString());
                }
            }
            if (LineParts[i] == "*")
            {
                if (i - 1 >= 0 && i + 1 < LineParts.Length)
                {
                    Line = Line.Replace((LineParts[i - 1] + " * " + LineParts[i + 1]).ToString(), (float.Parse(LineParts[i - 1]) * float.Parse(LineParts[i + 1])).ToString());
                }
            }
        }
        Line      = CompileClass.FixMinusNumbers(Line);
        LineParts = Line.Split(' ');
        for (int i = 0; i < LineParts.Length; i++)
        {
            if (LineParts[i] == "+")
            {
                if (i - 1 >= 0 && i + 1 < LineParts.Length)
                {
                    Line = Line.Replace((LineParts[i - 1] + " + " + LineParts[i + 1]).ToString(), (float.Parse(LineParts[i - 1]) + float.Parse(LineParts[i + 1])).ToString());
                }
            }
            if (LineParts[i] == "-")
            {
                if (i - 1 >= 0 && i + 1 < LineParts.Length)
                {
                    Line = Line.Replace((LineParts[i - 1] + " - " + LineParts[i + 1]).ToString(), (float.Parse(LineParts[i - 1]) - float.Parse(LineParts[i + 1])).ToString());
                }
            }
        }
        Line      = CompileClass.FixMinusNumbers(Line);
        LineParts = Line.Split(' ');
        for (int i = 0; i < LineParts.Length; i++)
        {
            if (LineParts[i] == ">")
            {
                if (i - 1 >= 0 && i + 1 < LineParts.Length)
                {
                    Line = Line.Replace((LineParts[i - 1] + " > " + LineParts[i + 1]).ToString(), (float.Parse(LineParts[i - 1]) > float.Parse(LineParts[i + 1])).ToString());
                }
            }
            if (LineParts[i] == "<")
            {
                if (i - 1 >= 0 && i + 1 < LineParts.Length)
                {
                    Line = Line.Replace((LineParts[i - 1] + " < " + LineParts[i + 1]).ToString(), (float.Parse(LineParts[i - 1]) < float.Parse(LineParts[i + 1])).ToString());
                }
            }
            if (LineParts[i] == ">=")
            {
                if (i - 1 >= 0 && i + 1 < LineParts.Length)
                {
                    Line = Line.Replace((LineParts[i - 1] + " >= " + LineParts[i + 1]).ToString(), (float.Parse(LineParts[i - 1]) >= float.Parse(LineParts[i + 1])).ToString());
                }
            }
            if (LineParts[i] == "<=")
            {
                if (i - 1 >= 0 && i + 1 < LineParts.Length)
                {
                    Line = Line.Replace((LineParts[i - 1] + " <= " + LineParts[i + 1]).ToString(), (float.Parse(LineParts[i - 1]) <= float.Parse(LineParts[i + 1])).ToString());
                }
            }
        }
        Line      = Line.Replace("True", "true").Replace("False", "false");
        LineParts = Line.Split(' ');
        for (int i = 0; i < LineParts.Length; i++)
        {
            if (LineParts[i] == "==")
            {
                if (i - 1 >= 0 && i + 1 < LineParts.Length)
                {
                    Line = Line.Replace((LineParts[i - 1] + " == " + LineParts[i + 1]).ToString(), (LineParts[i - 1] == LineParts[i + 1]).ToString());
                }
            }
            if (LineParts[i] == "!=")
            {
                if (i - 1 >= 0 && i + 1 < LineParts.Length)
                {
                    Line = Line.Replace((LineParts[i - 1] + " != " + LineParts[i + 1]).ToString(), (LineParts[i - 1] != LineParts[i + 1]).ToString());
                }
            }
        }
        Line      = Line.Replace("True", "true").Replace("False", "false");
        LineParts = Line.Split(' ');
        for (int i = 0; i < LineParts.Length; i++)
        {
            if (LineParts[i] == "&&")
            {
                if (i - 1 >= 0 && i + 1 < LineParts.Length)
                {
                    Line = Line.Replace((LineParts[i - 1].ToString().ToLower() + " && " + LineParts[i + 1].ToString().ToLower()), ((LineParts[i - 1].ToString() == "true") && (LineParts[i + 1].ToString() == "true")).ToString().ToLower());
                }
            }
        }
        Line      = Line.Replace("True", "true").Replace("False", "false");
        LineParts = Line.Split(' ');
        for (int i = 0; i < LineParts.Length; i++)
        {
            if (LineParts[i] == "||")
            {
                if (i - 1 >= 0 && i + 1 < LineParts.Length)
                {
                    Line = Line.Replace((LineParts[i - 1].ToString().ToLower() + " || " + LineParts[i + 1].ToString().ToLower()), ((LineParts[i - 1].ToString() == "true") || (LineParts[i + 1].ToString() == "true")).ToString().ToLower());
                }
            }
        }
        Line = Line.Replace("True", "true").Replace("False", "false");
        return(Line);
    }