As the token machine moves down a stream of tokens, eventually it reaches
the end of the token stream. At that point, the nextToken
method
returns a special value, which is the same as the value assigned to the
TT_EOF
instance variable of the tokenizer, where TT
is an
acronym for token type.
Thus, when nextToken
returns a value equal to the value of the
TT_EOF
instance variable, there are no more tokens to be read.
Accordingly, you can read and process all the integer tokens in a token
stream with a while
loop:
while (tokens.nextToken() != tokens.TT_EOF) { ... ... (int) tokens.nval ... ... }