Java Reference
In-Depth Information
In the code above, TokenInfo is the type of an object that encapsulates a represen-
tation of the token found, its image (if any), and the number of the line on which it was
found.
Reserved Words
There are two ways of recognizing reserved words. In the first, we complicate the state tran-
sition diagram for recognizing reserved words and distinguishing them from (non-reserved)
identifiers. For example, the state transition diagram fragment in Figure 2.2 recognizes
reserved words (and identiers) beginning with the letter `i' or the letter `n'.
FIGURE 2.2 A state transition diagram that distinguishes reserved words from identifiers.
The code corresponding to this might look something like
...
elseif(ch=='n'){
buffer.append(ch);
nextCh();
if(ch=='e'){
buffer.append(ch);
nextCh();
if(ch=='w'){
buffer.append(ch);
nextCh();
if(!isLetter(ch)&&!isDigit(ch)&&
ch!='_'&&ch!= '$'){
 
Search WWH ::




Custom Search