示例#1
0
文件: Lexer.cs 项目: xxy1991/cozy
        public static int FindIndexOfOpeningToken(Token[] tokens, int startIndex, TokenType openingType)
        {
            var closingType = tokens[startIndex].Type;
            int nestCount = 0;

            for (int i = startIndex; i >= 0; i--)
            {
                if (tokens[i].Type == closingType)
                {
                    ++nestCount;
                }
                else if (tokens[i].Type == openingType)
                {
                    --nestCount;
                }
                if (nestCount == 0)
                {
                    return i;
                }
            }

            return -1;
        }
示例#2
0
 public bool TryGetToken(char ch, out Token token)
 {
     return Tokens.TryGetValue(ch, out token);
 }