CSLE.CLS_Expression_Compiler.FindCodeBlock C# (CSharp) Метод

FindCodeBlock() приватный Метод

private FindCodeBlock ( IList tokens, int pos ) : int
tokens IList
pos int
Результат int
        int FindCodeBlock(IList<Token> tokens, int pos)
        {
            int dep = 0;
            for (int i = pos; i < tokens.Count; i++)
            {

                if (tokens[i].type == TokenType.PUNCTUATION)
                {
                    if (tokens[i].text == "{")
                    {
                        dep++;
                    }
                    if (tokens[i].text == "}")
                    {
                        dep--;
                        if (dep < 0)
                            return i - 1;
                    }
                }
            }
            if (dep != 0)
                return -1;
            else
                return tokens.Count - 1;
        }