KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > ASTReadStatement


1
2 /*
3  * Copyright © 2002 Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
4  * California 95054, U.S.A. All rights reserved. Sun Microsystems, Inc. has
5  * intellectual property rights relating to technology embodied in the product
6  * that is described in this document. In particular, and without limitation,
7  * these intellectual property rights may include one or more of the U.S.
8  * patents listed at http://www.sun.com/patents and one or more additional
9  * patents or pending patent applications in the U.S. and in other countries.
10  * U.S. Government Rights - Commercial software. Government users are subject
11  * to the Sun Microsystems, Inc. standard license agreement and applicable
12  * provisions of the FAR and its supplements. Use is subject to license terms.
13  * Sun, Sun Microsystems, the Sun logo and Java are trademarks or registered
14  * trademarks of Sun Microsystems, Inc. in the U.S. and other countries. This
15  * product is covered and controlled by U.S. Export Control laws and may be
16  * subject to the export or import laws in other countries. Nuclear, missile,
17  * chemical biological weapons or nuclear maritime end uses or end users,
18  * whether direct or indirect, are strictly prohibited. Export or reexport
19  * to countries subject to U.S. embargo or to entities identified on U.S.
20  * export exclusion lists, including, but not limited to, the denied persons
21  * and specially designated nationals lists is strictly prohibited.
22  */

23
24
25 /* JJT: 0.2.2 */
26
27
28
29
30 public class ASTReadStatement extends SimpleNode {
31   String JavaDoc name;
32
33   ASTReadStatement(int id) {
34     super(id);
35   }
36
37
38   public void interpret()
39   {
40      Object JavaDoc o;
41      byte[] b = new byte[64];
42      int i;
43
44      if ((o = symtab.get(name)) == null)
45         System.err.println("Undefined variable : " + name);
46
47      if (o instanceof Boolean JavaDoc)
48      {
49         System.out.print("Enter a value for \'" + name + "\' (boolean) : ");
50         System.out.flush();
51         try
52         {
53            i = System.in.read(b);
54            symtab.put(name, new Boolean JavaDoc((new String JavaDoc(b, 0, 0, i - 1)).trim()));
55         } catch(Exception JavaDoc e) { System.exit(1); }
56      }
57      else if (o instanceof Integer JavaDoc)
58      {
59         System.out.print("Enter a value for \'" + name + "\' (int) : ");
60         System.out.flush();
61         try
62         {
63            i = System.in.read(b);
64            symtab.put(name, new Integer JavaDoc((new String JavaDoc(b, 0, 0, i - 1)).trim()));
65         } catch(Exception JavaDoc e) {
66            System.out.println("Exceptio : " + e.getClass().getName());
67            System.exit(1);
68         }
69      }
70   }
71 }
72
Popular Tags