Java Reference
In-Depth Information
1 import java.io.Reader;
2 import java.io.FileReader;
3 import java.io.IOException;
4 import java.io.InputStreamReader;
5
6 import java.util.Stack;
7
8
9 // Balance class: check for balanced symbols
10 //
11 // CONSTRUCTION: with a Reader object
12 // ******************PUBLIC OPERATIONS***********************
13 // int checkBalance( ) --> Print mismatches
14 // return number of errors
15 // ******************ERRORS**********************************
16 // Error checking on comments and quotes is performed
17 // main checks for balanced symbols.
18
19 public class Balance
20 {
21 public Balance( Reader inStream )
22 { errors = 0; tok = new Tokenizer( inStream ); }
23
24 public int checkBalance( )
25 { /* Figure 11.8 */ }
26
27 private Tokenizer tok;
28 private int errors;
29
30 /**
31 * Symbol nested class;
32 * represents what will be placed on the stack.
33 */
34 private static class Symbol
35 {
36 public char token;
37 public int theLine;
38
39 public Symbol( char tok, int line )
40 {
41 token = tok;
42 theLine = line;
43 }
44 }
45
46 private void checkMatch( Symbol opSym, Symbol clSym )
47 { /* Figure 11.9 */ }
48 }
figure 11.3
Class skeleton
for a balanced-
symbol program
Search WWH ::




Custom Search