KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > lib > terminalemulator > AbstractInterp


1 /*
2  * The contents of this file are subject to the terms of the Common Development
3  * and Distribution License (the License). You may not use this file except in
4  * compliance with the License.
5  *
6  * You can obtain a copy of the License at http://www.netbeans.org/cddl.html
7  * or http://www.netbeans.org/cddl.txt.
8  *
9  * When distributing Covered Code, include this CDDL Header Notice in each file
10  * and include the License file at http://www.netbeans.org/cddl.txt.
11  * If applicable, add the following below the CDDL Header, with the fields
12  * enclosed by brackets [] replaced by your own identifying information:
13  * "Portions Copyrighted [year] [name of copyright owner]"
14  *
15  * The Original Software is Terminal Emulator.
16  * The Initial Developer of the Original Software is Sun Microsystems, Inc..
17  * Portions created by Sun Microsystems, Inc. are Copyright (C) 2001-2004.
18  * All Rights Reserved.
19  *
20  * Contributor(s): Ivan Soleimanipour.
21  */

22
23 package org.netbeans.lib.terminalemulator;
24
25 public abstract class AbstractInterp implements Interp {
26
27     protected interface Actor {
28     public String JavaDoc action(AbstractInterp interp, char c);
29     }
30
31     protected static class State {
32
33     // some generic actors
34
Actor act_error = new Actor() {
35         public String JavaDoc action(AbstractInterp ai, char c) {
36         return "generic error"; // NOI18N
37
}
38     };
39
40     public String JavaDoc name() {
41         return name;
42     }
43     private String JavaDoc name;
44
45
46     class Action {
47         public State new_state = null;
48         public Actor actor = act_error;
49     };
50
51     private Action action[] = new Action[128];
52     private Action action_regular = new Action();
53
54     public State(String JavaDoc name) {
55         this.name = name;
56         for (int i = 0; i < action.length; i++)
57         action[i] = new Action();
58         action_regular.actor = null;
59         action_regular.new_state = null;
60     }
61
62     /*
63      * Specify the state action_regular will transition to.
64      */

65     public void setRegular(State new_state, Actor actor) {
66         action_regular.actor = actor;
67         action_regular.new_state = new_state;
68     }
69
70     public void setAction(char c, State new_state, Actor actor) {
71         if ((int) c > 127)
72         return;
73         action[c].actor = actor;
74         action[c].new_state = new_state;
75     }
76
77     public Action getAction(char c) {
78         if ((int) c > 127)
79         return action_regular;
80         return action[c];
81     }
82     };
83
84     // Why make these be public and not protected?
85
// Someone might inherit from us in a package other than org.netbeans
86
// and while the inherited Interp will see these if they are protected,
87
// the corresponding InterpType won't.
88

89     /*
90     */

91     public Ops ops;
92     public State state; // current state
93

94     /*
95     protected Ops ops;
96     protected State state; // current state
97     */

98
99     protected AbstractInterp(Ops ops) {
100     this.ops = ops;
101     }
102
103     public void reset() {
104     ;
105     }
106
107     /*
108      * Management of number parsing
109      */

110
111     private static final int max_numbers = 5;
112     private int numberx = 0;
113     private String JavaDoc number[] = new String JavaDoc[max_numbers];
114
115     protected void resetNumber() {
116     for (int x = 0; x < max_numbers; x++) {
117         number[x] = "";
118     }
119     numberx = 0;
120     }
121     protected void remember_digit(char c) {
122     number[numberx] += c;
123     }
124     protected boolean pushNumber() {
125     numberx++;
126     return (numberx < max_numbers);
127     }
128     protected boolean noNumber() {
129     return number[0].equals(""); // NOI18N
130
}
131     protected int numberAt(int position) {
132     if (position > numberx) {
133         return 1;
134     }
135     return Integer.parseInt(number[position]);
136     }
137     protected int nNumbers() {
138     return numberx;
139     }
140
141
142 }
143
Popular Tags