1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29 package fr.ove.openmath.jome.ctrl.linear.events;
30
31 import java.util.EventObject;
32
33 /***
34 * The event sent during the parsing of a linear form of an expression.<BR>
35 * Each event sent corresponds to token in the expression parsed. The tokens are the following :
36 * <UL>
37 * <LI> VARIABLE when a variable is encountered in the expression </LI>
38 * <LI> INTEGER when an integer is encountered in the expression </LI>
39 * <LI> FLOAT when a real number is encountered in the expression </LI>
40 * <LI> ADDITION when the + operator is encountered in the expression </LI>
41 * <LI> SUBSTRACTION when the - operator is encountered in the expression </LI>
42 * <LI> MULTIPLICATION when the * operator is encountered in the expression </LI>
43 * <LI> DIVISION when the / operator is encountered in the expression </LI>
44 * <LI> POWER when the ^ operator is encountered in the expression </LI>
45 * <LI> EQUAL when the = operator is encountered in the expression </LI>
46 * <LI> UNEQUAL when the <> operator is encountered in the expression </LI>
47 * <LI> LESS when the < operator is encountered in the expression </LI>
48 * <LI> LESSEQUAL when the <= operator is encountered in the expression </LI>
49 * <LI> GREATER when the > operator is encountered in the expression </LI>
50 * <LI> GREATEREQUAL when the >= operator is encountered in the expression </LI>
51 * <LI> FUNCTION when a name of a function (an function is expected to be an identificator immediately followed
52 * by an opening parenthesis) is encountered in the expression </LI>
53 * <LI> SEPARATOR when a separator (, or ;) is encountered in the expression </LI>
54 * <LI> OPEN_PAREN when an opening paranthesis is encountered in the expression </LI>
55 * <LI> CLOSE_PAREN when a closing paranthesis is encountered in the expression </LI>
56 * <LI> OPEN_BRACKET when an opening bracket is encountered in the expression </LI>
57 * <LI> CLOSE_BRACKET when a closing bracket is encountered in the expression </LI>
58 * <LI> OPEN_CURLY when an opening curly brace is encountered in the expression </LI>
59 * <LI> CLOSE_CURLY when a closing curly brace is encountered in the expression </LI>
60 * <LI> UNDERSCRIPT when the underscript (_) operator is encountered in the expression </LI>
61 * </UL>
62 *
63 * There exists other token identifiers :
64 * <UL>
65 * <LI> RESERVED when a specific keyword (define in the property file of the parser) is encountered
66 * in the expression </LI>
67 * <LI> SPECIALIZED when a specialized operator is encountered in the expression.<BR>
68 * (not really clearly defined :o( )</LI>
69 * </UL>
70 *
71 * Finally, 2 other token identifiers dealing with the parsing itself.
72 * <UL>
73 * <LI> START_EXPRESSION when the parsing of the expression starts </LI>
74 * <LI> END_EXPRESSION when the parsing of the expression ends </LI>
75 * </UL>
76 *
77 * @author © 1999 DIRAT Laurent
78 * @version 1.0 27/09/1999
79 */
80 public class LinearParserEvent extends EventObject {
81 /***
82 * The token identifier.
83 */
84 private int identifier;
85
86 /***
87 * The token value.
88 */
89 private String value;
90
91 /***
92 * The constructor.
93 * @param src the object which produces this event.
94 */
95 public LinearParserEvent(Object src) {
96 super(src);
97 }
98
99 /***
100 * Sets the identifier of the token and its value, if needed.
101 * @param identifier the token identifier.
102 * @param value the token value.
103 */
104 public void setToken(int identifier, String value) {
105 this.identifier = identifier;
106 this.value = value;
107 }
108
109 /***
110 * Returns the identifier of the token wrapped into the event.
111 */
112 public int getIdentifier() {
113 return identifier;
114 }
115
116 /***
117 * Returns the identifier of the token wrapped into the event, as a string
118 */
119 public String getIdentifierAsString() {
120 String str = "";
121
122 switch (identifier) {
123 case VARIABLE : str += "VARIABLE"; break;
124 case INTEGER : str += "INTEGER"; break;
125 case FLOAT : str += "FLOAT"; break;
126 case ADDITION : str += "ADDITION"; break;
127 case SUBSTRACTION : str += "SUBSTRACTION"; break;
128 case MULTIPLICATION: str += "MULTIPLICATION"; break;
129 case DIVISION : str += "DIVISION"; break;
130 case POWER : str += "POWER"; break;
131 case EQUAL : str += "EQUAL"; break;
132 case UNEQUAL : str += "UNEQUAL"; break;
133 case LESS : str += "LESS"; break;
134 case LESSEQUAL : str += "LESSEQUAL"; break;
135 case GREATER : str += "GREATER"; break;
136 case GREATEREQUAL : str += "GREATEREQUAL"; break;
137 case FUNCTION : str += "FUNCTION"; break;
138 case FUNCTION2 : str += "FUNCTION2"; break;
139 case SEPARATOR : str += "SEPARATOR"; break;
140 case OPEN_PAREN : str += "OPEN_PAREN"; break;
141 case CLOSE_PAREN : str += "CLOSE_PAREN"; break;
142 case OPEN_BRACKET : str += "OPEN_BRACKET"; break;
143 case CLOSE_BRACKET : str += "CLOSE_BRACKET"; break;
144 case OPEN_CURLY : str += "OPEN_CURLY"; break;
145 case CLOSE_CURLY : str += "CLOSE_CURLY"; break;
146 case UNDERSCRIPT : str += "UNDERSCRIPT"; break;
147 case RESERVED : str += "RESERVED"; break;
148 case SPECIALIZED : str += "SPECIALIZED"; break;
149 case START_EXPRESSION : str += "START_EXPRESSION"; break;
150 case END_EXPRESSION : str += "END_EXPRESSION"; break;
151 case SYMBOL : str += "symbol"; break;
152 case GROUP_START : str += "GROUP_START"; break;
153 case GROUP_END : str += "GROUP_END"; break;
154 }
155
156 return str;
157 }
158
159 /***
160 * Returns the int value of the specified identifier string representation .
161 */
162 public static int getStringIdentifierAsInt(String identifier) {
163 int value = 0;
164
165 if (identifier.equals("VARIABLE"))
166 value = 1;
167 else if (identifier.equals("INTEGER"))
168 value = 2;
169 else if (identifier.equals("FLOAT"))
170 value = 3;
171 else if (identifier.equals("ADDITION"))
172 value = 4;
173 else if (identifier.equals("SUBSTRACTION"))
174 value = 5;
175 else if (identifier.equals("MULTIPLICATION"))
176 value = 6;
177 else if (identifier.equals("DIVISION"))
178 value = 7;
179 else if (identifier.equals("POWER"))
180 value = 8;
181 else if (identifier.equals("EQUAL"))
182 value = 9;
183 else if (identifier.equals("UNEQUAL"))
184 value = 10;
185 else if (identifier.equals("LESS"))
186 value = 11;
187 else if (identifier.equals("LESSEQUAL"))
188 value = 12;
189 else if (identifier.equals("GREATER"))
190 value = 13;
191 else if (identifier.equals("GREATEREQUAL"))
192 value = 14;
193 else if (identifier.equals("FUNCTION"))
194 value = 15;
195 else if (identifier.equals("FUNCTION2"))
196 value = 31;
197 else if (identifier.equals("SEPARATOR"))
198 value = 16;
199 else if (identifier.equals("OPEN_PAREN"))
200 value = 17;
201 else if (identifier.equals("CLOSE_PAREN"))
202 value = 18;
203 else if (identifier.equals("OPEN_BRACKET"))
204 value = 19;
205 else if (identifier.equals("CLOSE_BRACKET"))
206 value = 20;
207 else if (identifier.equals("OPEN_CURLY"))
208 value = 21;
209 else if (identifier.equals("CLOSE_CURLY"))
210 value = 22;
211 else if (identifier.equals("RESERVED"))
212 value = 23;
213 else if (identifier.equals("UNDERSCRIPT"))
214 value = 24;
215 else if (identifier.equals("SPECIALIZED"))
216 value = 25;
217 else if (identifier.equals("START_EXPRESSION"))
218 value = 26;
219 else if (identifier.equals("END_EXPRESSION"))
220 value = 27;
221 else if (identifier.equals("GROUP_START"))
222 value = 29;
223 else if (identifier.equals("GROUP_END"))
224 value = 30;
225
226 return value;
227 }
228
229 /***
230 * Returns the value of the identifier.
231 */
232 public String getValue() {
233 return value;
234 }
235
236 /***
237 * Returns a @see String representation of the instance.<BR>
238 * Mainly for debugg.
239 */
240 public String toString() {
241 return getIdentifierAsString() + "\t" + value;
242 }
243
244 /***
245 * The different command tokens.
246 */
247
248
249 public static final int VARIABLE = 1;
250 public static final int INTEGER = 2;
251 public static final int FLOAT = 3;
252
253
254 public static final int ADDITION = 4;
255 public static final int SUBSTRACTION = 5;
256 public static final int MULTIPLICATION = 6;
257 public static final int DIVISION = 7;
258 public static final int POWER = 8;
259
260
261 public static final int EQUAL = 9;
262 public static final int UNEQUAL = 10;
263 public static final int LESS = 11;
264 public static final int LESSEQUAL = 12;
265 public static final int GREATER = 13;
266 public static final int GREATEREQUAL = 14;
267
268
269 public static final int FUNCTION = 15;
270 public static final int SEPARATOR = 16;
271
272
273 public static final int OPEN_PAREN = 17;
274 public static final int CLOSE_PAREN = 18;
275 public static final int OPEN_BRACKET = 19;
276 public static final int CLOSE_BRACKET = 20;
277 public static final int OPEN_CURLY = 21;
278 public static final int CLOSE_CURLY = 22;
279
280
281 public static final int RESERVED = 23;
282
283
284 public static final int UNDERSCRIPT = 24;
285 public static final int SPECIALIZED = 25;
286
287
288 public static final int START_EXPRESSION = 26;
289 public static final int END_EXPRESSION = 27;
290 public static final int SYMBOL = 28;
291
292 public static final int GROUP_START = 29;
293 public static final int GROUP_END = 30;
294 public static final int FUNCTION2 = 31;
295 }