
A Simple Translator 37
and confirmed. We shall see in Chapter 4 why we need to
do this look-ahead. We cannot get the nextsymbol by
requesting Scanner(), as the meaning of a look-ahead
is that we peep at the next symbol, but without processing
it. Thus, we have a two-position “shifter” coded, which is
initially empty (see Fig. 2.2).
For each call to symbol(), a request goes to the
Scanner to supply the next token and the shifter is shifted
to the left. The very first call to symbol() results in two
calls to the Scanner. A call to nextsymbol() does not
result in a call to the Scanner, it simply allows a peep to
the nxtsym in the shifter.
The algorithms ...