TokenStream stream = new TokenStream(); while (stream.HasNext()) { Token currentToken = stream.NextToken(); if (currentToken.Type == TokenType.Number) { // Do something with currentToken } }
TokenStream stream = new TokenStream(); stream.AddToken(new Token(TokenType.Identifier, "foo")); stream.AddToken(new Token(TokenType.Operator, "+")); stream.AddToken(new Token(TokenType.Number, "42")); stream.Accept(TokenType.Identifier); stream.Accept(TokenType.Operator); stream.Accept(TokenType.Number);In this example, we create a TokenStream object and add three tokens to it. We then call `Accept()` three times with the expected token types as arguments. If the next token in the stream matches the expected type, it is consumed and the method returns true. If it doesn't match, the method returns false. It's difficult to determine the package or library associated with TokenStream Accept, as it could be part of a larger project or used independently. However, it's likely used in a parser or some form of code analysis tool.