Java Reference
In-Depth Information
1 import java.io.Reader;
2 import java.io.PushbackReader;
3 import java.io.IOException;
4
5 // Tokenizer class.
6 //
7 // CONSTRUCTION: with a Reader object
8 // ******************PUBLIC OPERATIONS***********************
9 // char getNextOpenClose( ) --> Get next opening/closing symbol
10 // int getLineNumber( ) --> Return current line number
11 // int getErrorCount( ) --> Return number of parsing errors
12 // String getNextID( ) --> Get next Java identifier
13 // (see Section 12.2)
14 // ******************ERRORS**********************************
15 // Error checking on comments and quotes is performed
16
17 public class Tokenizer
18 {
19 public Tokenizer( Reader inStream )
20 { errors = 0; ch = '\0'; currentLine = 1;
21 in = new PushbackReader( inStream ); }
22
23 public static final int SLASH_SLASH = 0;
24 public static final int SLASH_STAR = 1;
25
26 public int getLineNumber( )
27 { return currentLine; }
28 public int getErrorCount( )
29 { return errors; }
30 public char getNextOpenClose( )
31 { /* Figure 11.7 */ }
32 public char getNextID( )
33 { /* Figure 12.29 */ }
34
35 private boolean nextChar( )
36 { /* Figure 11.4 */ }
37 private void putBackChar( )
38 { /* Figure 11.4 */ }
39 private void skipComment( int start )
40 { /* Figure 11.5 */ }
41 private void skipQuote( char quoteType )
42 { /* Figure 11.6 */ }
43 private void processSlash( )
44 { /* Figure 11.7 */ }
45 private static final boolean isIdChar( char ch )
46 { /* Figure 12.27 */ }
47 private String getRemainingString( )
48 { /* Figure 12.28 */ }
49
50 private PushbackReader in; // The input stream
51 private char ch; // Current character
52 private int currentLine; // Current line
53 private int errors; // Number of errors seen
54 }
figure 11.2
The Tokenizer class
skeleton, used to
retrieve tokens from
an input stream
 
Search WWH ::




Custom Search