コード例 #1
0
 public Token Read()
 {
     if (Index >= Tokens.Count - 1)
     {
         throw ScriptError.UnexpectedEOF(null);
     }
     return(Tokens[Index++]);
 }
コード例 #2
0
 public bool Match(params TokenType[] types)
 {
     if (Index >= Tokens.Count)
     {
         throw ScriptError.UnexpectedEOF(null);
     }
     foreach (var type in types)
     {
         if (Tokens[Index].Type == type)
         {
             return(true);
         }
     }
     return(false);
 }
コード例 #3
0
        public Token Expect(params TokenType[] types)
        {
            if (Index >= Tokens.Count)
            {
                throw ScriptError.UnexpectedEOF(null);
            }

            foreach (var type in types)
            {
                if (Tokens[Index].Type == type)
                {
                    var token = Tokens[Index];
                    Index++;
                    return(token);
                }
            }
            throw ScriptError.UnexpectedToken(Tokens[Index], Tokens[Index].Contents);
        }