Esempio n. 1
0
        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;
        }
Esempio n. 2
0
 public bool TryGetToken(char ch, out Token token)
 {
     return Tokens.TryGetValue(ch, out token);
 }