Ejemplo n.º 1
0
        private static int Find_DEFAULT_EndLine(int startLine)
        {
            int?skipCounter = null;

            for (int i = startLine + 1; i < Data.Code.Lines.Length; i++)
            {
                if (Word.Contains(Data.Code[i], '{'))
                {
                    if (skipCounter.HasValue)
                    {
                        skipCounter++;
                    }
                    else
                    {
                        skipCounter = 1;
                    }
                }
                if (Word.Contains(Data.Code[i], '}'))
                {
                    if (!skipCounter.HasValue || skipCounter.Value == 0)
                    {
                        return(i - 1);
                    }
                    else
                    {
                        skipCounter--;
                    }
                }
            }
            Data.ThrowError("Не удалось найти конец ветви \'default\' в строке " + (startLine + 1).ToString());
            return(0);
        }
Ejemplo n.º 2
0
 private static void SearchForLinesWithConditionalOperators()
 {
     ClearLists();
     for (int i = 0; i < Data.Code.Lines.Length; i++)
     {
         Word[] words = Data.Code[i];
         if (words.Length == 0)
         {
             continue;
         }
         string first = words[0].Text;
         if (first == Data.IF.Text)
         {
             LinesWith[(int)O.IF].Add(i);
         }
         else if (first == Data.ELSEIF.Text)
         {
             LinesWith[(int)O.ELSEIF].Add(i);
         }
         else if (first == Data.ELSE.Text)
         {
             LinesWith[(int)O.ELSE].Add(i);
         }
         else if (first == Data.SWITCH.Text)
         {
             LinesWith[(int)O.SWITCH].Add(i);
         }
         else if (first == Data.FOR.Text)
         {
             LinesWith[(int)O.FOR].Add(i);
         }
         else if (first == Data.WHILE.Text && !Word.Contains(words, Data.SEMICOLON))
         {
             LinesWith[(int)O.WHILE].Add(i);
         }
         else if (first == Data.DO.Text)
         {
             LinesWith[(int)O.DO_WHILE].Add(i);
         }
         else if (first == Data.CASE.Text)
         {
             LinesWith[(int)O.CASE].Add(i);
         }
         else if (first == Data.DEFAULT.Text)
         {
             LinesWith[(int)O.DEFAULT].Add(i);
         }
         else if (Word.Contains(words, Data.QUESTION_MARK) && Word.Contains(words, Data.COLON))
         {
             LinesWith[(int)O.TERNARY].Add(i);
         }
     }
 }
Ejemplo n.º 3
0
 private bool Contains_RETURN()
 {
     for (int i = End; i >= Start; i--)
     {
         Word[] words = Data.Code[i];
         if (Word.Contains(words, Data.RETURN))
         {
             return(true);
         }
     }
     return(false);
 }
Ejemplo n.º 4
0
        private static CodeBlock GetFramingBlockForUsualBlock(CodeBlock block)
        {
            int?skipCounter = null;

            for (int i = block.StartLine - 1; i >= 0; i--)
            {
                Word[] words = Data.Code[i];
                if (words.Length == 0)
                {
                    continue;
                }
                if (words[0].Text == "}")
                {
                    if (skipCounter.HasValue)
                    {
                        skipCounter++;
                    }
                    else
                    {
                        skipCounter = 1;
                    }
                }
                if (words[0].Text == "{")
                {
                    if (!skipCounter.HasValue || skipCounter.Value == 0)
                    {
                        Word[] definition = Data.Code[i - 1];
                        if (Word.Contains(definition, Data.FUNCTION))
                        {
                            return(null);
                        }
                        else
                        {
                            return(GetBlockByStartLine(i - 1));
                        }
                    }
                    else
                    {
                        skipCounter--;
                    }
                }
                if (words[0].Text == Data.CASE.Text && (!skipCounter.HasValue || skipCounter.Value == 0))
                {
                    return(GetBlockByStartLine(i));
                }
            }
            return(null);
        }
Ejemplo n.º 5
0
        private static void CreateFunctions()
        {
            Functions    = new List <Function>();
            Constants    = new List <Constant>();
            MainFunction = new MainFunction();
            for (int i = 0; i < Data.Code.Lines.Length; i++)
            {
                Word[] words = Data.Code[i];
                if (words.Length == 0)
                {
                    continue;
                }
                if (Split.IsTag(words[0].Text))
                {
                    continue;
                }
                if (words[0].Text == "")
                {
                    continue;
                }
                if (Word.Contains(words, Data.FUNCTION))
                {
                    int end = Brackets.GetCloseCurveBracketIndex(Data.Code.Lines, i + 1);
                    Functions.Add(new Function(i, end, words));
                    i = end;
                }
                else
                {
                    int end = MainFunctionEnd(i);
                    MainFunction.AddLines(i, end);
                    i = end;
                }
            }

            List <Function> onlyOutputtingFunctions = GetFunctionsThatAreOnlyForOutput();

            foreach (Function function in Functions)
            {
                function.DefineIsOnlyForOutputting(ref onlyOutputtingFunctions);
            }
        }
Ejemplo n.º 6
0
        private static void MakeGapsAfterWords(Word[] words)
        {
            for (int i = 1; i < words.Length; i++)
            {
                switch (words[i].Text)
                {
                case "(":
                    words[i].IsSpaceAfter = false;
                    if (Word.Contains(Data.BLOCK_Operators, words[i - 1]))
                    {
                        words[i - 1].IsSpaceAfter = true;
                    }
                    else
                    {
                        words[i - 1].IsSpaceAfter = false;
                    }
                    break;

                case "[":
                    words[i].IsSpaceAfter     = false;
                    words[i - 1].IsSpaceAfter = false;
                    break;

                case ")":
                case "]":
                    words[i - 1].IsSpaceAfter = false;
                    if (i + 1 == words.Length)
                    {
                        break;
                    }
                    if (words[i + 1].Text == Data.SEMICOLON.Text)
                    {
                        words[i].IsSpaceAfter = false;
                    }
                    else
                    {
                        words[i].IsSpaceAfter = true;
                    }
                    break;

                case "\"":
                    words[i - 1].IsSpaceAfter = true;
                    words[i].IsSpaceAfter     = false;
                    break;

                case "&":
                case "!":
                    words[i].IsSpaceAfter = false;
                    break;

                case "return":
                    words[i].IsSpaceAfter = true;
                    break;

                case "++":
                case "--":
                    if (i + 1 == words.Length)
                    {
                        words[i - 1].IsSpaceAfter = false;
                        break;
                    }
                    if (words[i + 1].Text[0] == '$')
                    {
                        words[i].IsSpaceAfter = false;
                    }
                    else
                    {
                        words[i - 1].IsSpaceAfter = false;
                    }
                    break;

                case ",":
                case ";":
                    words[i - 1].IsSpaceAfter = false;
                    break;
                }
            }
        }
Ejemplo n.º 7
0
        private void CarryFromConditionToNewLine()
        {
            for (int i = 0; i < lines.Length; i++)
            {
                string offset = "";
                if (i != 0)
                {
                    offset = Line.GetOffset(lines[i - 1]);
                }

                Word[] words = Split.SeparateLine(Line.TrimmedLine(lines[i]));
                Word.TrimWords(ref words);
                if (words.Length == 0)
                {
                    continue;
                }
                if (Word.Contains(words, Data.DO))
                {
                    string[] parts       = new string[2];
                    int      DO_Position = Word.IndexOfFirst(words, Data.DO);
                    parts[0] = offset + Word.ToLine(words, 0, DO_Position);
                    parts[1] = Word.ToLine(words, DO_Position + 1);
                    if (Line.TrimmedLine(parts[1]) == "")
                    {
                        Array.Resize(ref parts, 1);
                    }
                    Split.InsertInsteadOf(i, ref lines, parts);
                }
                else if (Word.ContainsBlockOperator(words))
                {
                    if (words[0].Text == Data.WHILE.Text)
                    {
                        int closeRoundBracket = Brackets.GetCloseBracketPosition(words, '(');
                        if (closeRoundBracket != words.Length - 1 && words[closeRoundBracket + 1].Text == ";")
                        {
                            continue;
                        }
                    }
                    int      closeBracketPosition = Brackets.GetCloseBracketPosition(words, '(');
                    string[] parts = new string[2];
                    parts[0] = offset + Word.ToLine(words, 0, closeBracketPosition);
                    parts[1] = offset + "\t" + Word.ToLine(words, closeBracketPosition + 1);
                    if (Line.TrimmedLine(parts[1]) == "")
                    {
                        continue;
                    }
                    Split.InsertInsteadOf(i, ref lines, parts);
                }
                else if (words[0].Text == Data.ELSE.Text)
                {
                    string[] parts = new string[2];
                    parts[0] = offset + Data.ELSE.Text;
                    parts[1] = offset + "\t" + Word.ToLine(words, 1);
                    if (Line.TrimmedLine(parts[1]) == "")
                    {
                        continue;
                    }
                    Split.InsertInsteadOf(i, ref lines, parts);
                }
            }
        }