Пример #1
0
 private static Token Accept(Token.TokenTypes type, List <Token> tokens, ref int idx)
 {
     if (idx < tokens.Count)
     {
         var tk = tokens[idx];
         if (tk.Type == type)
         {
             idx++;
             return(tk);
         }
     }
     return(null);
 }
Пример #2
0
        private static Token Expect(Token.TokenTypes type, List <Token> tokens, ref int idx)
        {
            if (idx >= tokens.Count && idx > 0)
            {
                throw new ArgumentException(string.Format("Expected token {0} at line:{1}", type, tokens[idx - 1].Line));
            }
            var tk = tokens[idx];

            if (tk.Type == type)
            {
                idx++;
                return(tk);
            }
            throw new ArgumentException(string.Format("Unexpected token: '{0}' at line:{1}, expected {2}", tk.StringValue, tk.Line, type));
        }