I'm reading "Principles and Practice Using C++" chapter 6, it's about using Tokens and as if the concept of Tokens were not already confusing the whole chapter is just a mess and gives me the impression that Bjarne was just not in the mood when writing this chapter....
Can you guys suggest any book that also covers Tokens(to complete beginners)?
I can't find anything good on the internet....
I'm not sure if I'd classify understanding tokens as a beginner topic. Tokens are simply the smallest sub-strings of a program that need to be read together to have meaning. For example: int x = 501; In that code the five tokens (in order) are: int
x
=
501
;
The characters i and 5 are not a tokens however, because it they are part of the tokens int and 501 (respectively).
get_token() in your example has to return a value of type Token, which consists of the two attributes kind and name. Depending on the input stream a simple tokenizer could be written as:
You may also find tokens in communication systems like a real time bus, a so called token-bus. There are several potentiell communication participants, but only one at a time is allowed to send messages. This one is called the token holder. If ready or its maximum sending time is reached, it will forward the token, say the right to send, to another participant.