Beispiel #1
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);
    }
Beispiel #2
0
    int ExecuteLine(string LineToExecute, int Value)
    {
        string FindVariable = LineToExecute;

        //MAY CAUSE FATAL ERROR v (but also, it can break game if remove)
        bool quit    = false;
        int  blocker = 0;

        while (FindVariable.Contains("Input."))
        {
            int ind = FindVariable.IndexOf("Input.") + 6;
            //Debug.Log("ind: " + ind);
            int    e     = 0;
            string comp  = "Input.";
            string value = "error";
            for (int d = 0; d < 256; d++)
            {
                //Debug.Log(FindVariable[ind+d]);
                if (char.IsLetterOrDigit(FindVariable[ind + d]))
                {
                    comp += FindVariable[ind + d].ToString();
                }
                else
                {
                    break;
                }
            }
            e = ind - 6 + comp.Length;
            //Debug.Log("comp: " + comp);
            //Debug.Log("e: " + e);
            for (int inp = 0; inp < InputI.DataId.Length; inp++)
            {
                if (comp == InputI.DataId[inp])
                {
                    value = InputI.Data[inp];
                }
            }
            if (value == "error")
            {
                quit = true;
            }
            FindVariable = FindVariable.Remove(ind - 6, e - ind + 6);
            FindVariable = FindVariable.Insert(ind - 6, value);
            //Debug.Log(FindVariable.Substring(ind-6, e-ind+6));
            //Debug.Log("FindVariable: " + FindVariable);
            if (quit || blocker >= 64)
            {
                break;
            }
            blocker++;
        }

        foreach (string FunctionRead in FunctionNames)
        {
            if (LineToExecute.Replace("\t", string.Empty).StartsWith(FunctionRead) || LineToExecute.Replace("\t", string.Empty).StartsWith(FunctionRead.Replace(" ", string.Empty)))
            {
                ReadFunction(FunctionRead.Replace("()", string.Empty).Replace(" ", string.Empty));
            }
        }
        if (LineToExecute.Replace("\t", string.Empty).StartsWith("print") || LineToExecute.Replace("\t", string.Empty).StartsWith("Debug.Log") && LineToExecute.EndsWith(";"))
        {
            Debug.Log(SearchInString("(\"", "\")", LineToExecute.Replace("\t", string.Empty)).Replace("\"", string.Empty));
        }
        else if (LineToExecute.Replace("\t", string.Empty).StartsWith("if") && LineToExecute.EndsWith("{"))
        {
            if (CompileClass.ReadBoolean(SearchInString("(", ")", FindVariable)) == "true")
            {
                int TabsCount = 0;
                foreach (char c in LineToExecute)
                {
                    if (c == '\t')
                    {
                        TabsCount++;
                    }
                }
                for (int l = Value + 1; l < Lines.Length; l++)
                {
                    int CLTabsCount = 0;
                    foreach (char c in Lines[l])
                    {
                        if (c == '\t')
                        {
                            CLTabsCount++;
                        }
                    }
                    if (Lines[l].EndsWith("}") && CLTabsCount == TabsCount)
                    {
                        break;
                    }
                    else if (Lines[l].EndsWith("{"))
                    {
                        for (int LineScanner = l; Lines[LineScanner].EndsWith("}"); LineScanner++)
                        {
                            l = LineScanner;
                        }
                        l++;
                    }
                    else
                    {
                        ExecuteLine(Lines[l], l);
                    }
                }
            }
            else
            {
                /*int SCount = 0;
                 * //Else/ElseIf
                 * int TabsCount = 0;
                 * foreach(char c in LineToExecute) {
                 *      if(c == '\t') TabsCount++;
                 * }
                 * for(int l = Value + 1; l < Lines.Length; l++) {
                 *      int CLTabsCount = 0;
                 *      foreach(char c in Lines[l]) {
                 *              if(c == '\t') CLTabsCount++;
                 *      }
                 *      if(Lines[l].EndsWith("}") && CLTabsCount == TabsCount) {
                 *              break;
                 *      } else if(Lines[l].EndsWith("{")) {
                 *              for(int LineScanner = l; Lines[LineScanner].EndsWith("}"); LineScanner++) {
                 *                      l = LineScanner;
                 *              }
                 *              l++;
                 *      } else {
                 *              SCount++;
                 *      }
                 * }*/
            }
        }
        else if (LineToExecute.Replace("\t", string.Empty).StartsWith("Output.Send") && LineToExecute.EndsWith(");"))
        {
            //All Output witch contains var: Var's name will be replace with value

            string IncludeVar = LineToExecute;

            //MAY CAUSE FATAL ERROR v (but also, it can break game if remove)
            bool quit2    = false;
            int  blocker2 = 0;
            while (IncludeVar.Contains("Input."))
            {
                int ind = IncludeVar.IndexOf("Input.") + 6;
                //Debug.Log("ind: " + ind);
                int    e     = 0;
                string comp  = "Input.";
                string value = "error";
                for (int d = 0; d < 256; d++)
                {
                    //Debug.Log(FindVariable[ind+d]);
                    if (char.IsLetterOrDigit(IncludeVar[ind + d]))
                    {
                        comp += IncludeVar[ind + d].ToString();
                    }
                    else
                    {
                        break;
                    }
                }
                e = ind - 6 + comp.Length;
                //Debug.Log("comp: " + comp);
                //Debug.Log("e: " + e);
                for (int inp = 0; inp < InputI.DataId.Length; inp++)
                {
                    if (comp == InputI.DataId[inp])
                    {
                        value = InputI.Data[inp];
                    }
                }
                if (value == "error")
                {
                    quit2 = true;
                }
                IncludeVar = IncludeVar.Remove(ind - 6, e - ind + 6);
                IncludeVar = IncludeVar.Insert(ind - 6, value);
                //Debug.Log(FindVariable.Substring(ind-6, e-ind+6));
                //Debug.Log("FindVariable: " + FindVariable);
                if (quit2 || blocker2 >= 64)
                {
                    break;
                }
                blocker2++;
            }



            if (IncludeVar.Replace("\t", string.Empty) == "Output.SendMail();")
            {
                SendAllMail();
            }
            else if (IncludeVar.Replace("\t", string.Empty).StartsWith("Output.SendColor") && NumberFree(SearchInString("(", ")", IncludeVar).Split(',')[1].Replace(" ", string.Empty)))
            {
                SendingMessage(SearchInString("(", ")", IncludeVar).Split(',')[1].Replace(" ", string.Empty), IncludeVar);
            }
            else if (IncludeVar.Replace("\t", string.Empty).StartsWith("Output.SendFloat") && MadeForFloat(SearchInString("(", ")", IncludeVar).Split(',')[1].Replace(" ", string.Empty)))
            {
                SendingMessage(CompileClass.ReadFloat(SearchInString("(", ")", IncludeVar).Split(',')[1].Replace(" ", string.Empty)).ToString(), IncludeVar);
            }
            else if (IncludeVar.Replace("\t", string.Empty).StartsWith("Output.SendInt") && MadeForInt(SearchInString("(", ")", IncludeVar).Split(',')[1].Replace(" ", string.Empty)))
            {
                SendingMessage(CompileClass.ReadIntegrer(SearchInString("(", ")", IncludeVar).Split(',')[1].Replace(" ", string.Empty)).ToString(), IncludeVar);
            }
            else if ((IncludeVar.Replace("\t", string.Empty).StartsWith("Output.SendFunc") || IncludeVar.Replace("\t", string.Empty).StartsWith("Output.SendString")))
            {
                SendingMessage(SearchInString("(", ")", IncludeVar).Split(',')[1].Replace(" ", string.Empty), IncludeVar);
            }
            else if (IncludeVar.Replace("\t", string.Empty).StartsWith("Output.SendBoolean"))
            {
                if (SearchInString("(", ")", IncludeVar).Split(',')[1].Replace(" ", string.Empty) == "true" || SearchInString("(", ")", IncludeVar).Split(',')[1].Replace(" ", string.Empty) == "false")
                {
                    SendingMessage(SearchInString("(", ")", IncludeVar).Split(',')[1].Replace(" ", string.Empty), IncludeVar);
                }
            }
            else if (IncludeVar.Replace("\t", string.Empty).StartsWith("Output.SendController"))
            {
                string Type;                 //Mail or Save
                string Port;                 //1 or 2 TODO: 1/2/1/2
                string Action;               //Output.
                string Data;                 //Value
                IncludeVar = SearchInString("(", ")", IncludeVar).Replace(" ", string.Empty);
                if (IncludeVar.Split(',').Length == 4)
                {
                    Type = IncludeVar.Split(',')[1];
                    //Debug.Log(IncludeVar.Split(',')[0]);
                    Port   = IncludeVar.Split(',')[0];
                    Action = IncludeVar.Split(',')[2];
                    Data   = IncludeVar.Split(',')[3];
                    //Debug.Log("I'm preparing myself to send a new mail! Here's the data:("+Port+","+Type+","+Action+","+Data+")");
                    SendingMessage(Data, Port + "," + Type + "," + Action, true);                     //"Port,Type,Action","Value"
                }
            }
        }
        else if (LineToExecute.Replace("\t", string.Empty).StartsWith("Input.Clear();"))
        {
            InputI.Data.ToList().Clear();
            InputI.DataId.ToList().Clear();
            InputI.SendFunctionMailNameI.Clear();
            InputI.SendFunctionMailValueI.Clear();
        }
        else if (LineToExecute.Replace("\t", string.Empty).StartsWith("Output.Clear();"))
        {
            OutputO.Data.ToList().Clear();
            OutputO.DataId.ToList().Clear();
            OutputO.SendFunctionMailNameI.Clear();
            OutputO.SendFunctionMailValueI.Clear();
        }
        else
        {
            if (LineToExecute.EndsWith(";") && LineToExecute.Contains(" = "))
            {
                string[] parts = LineToExecute.Replace("\t", string.Empty).Replace(";", string.Empty).Replace(" = ", "\t").Split('\t');
                //OutputO.Data[OutputO.DataId.ToList().IndexOf(parts[0])] = parts[1];
                if (OutputO.DataId.ToList().Contains(parts[0]))
                {
                    OutputO.Data[OutputO.DataId.ToList().IndexOf(parts[0])] = parts[1];
                }
                else
                {
                    Debug.Log("Fail: " + parts[0]);
                }
            }
        }
        return(0);
    }