1739
|
1 /* |
|
2 |
2847
|
3 Copyright (C) 1996, 1997 John W. Eaton |
1739
|
4 |
|
5 This file is part of Octave. |
|
6 |
|
7 Octave is free software; you can redistribute it and/or modify it |
|
8 under the terms of the GNU General Public License as published by the |
|
9 Free Software Foundation; either version 2, or (at your option) any |
|
10 later version. |
|
11 |
|
12 Octave is distributed in the hope that it will be useful, but WITHOUT |
|
13 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
|
14 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
|
15 for more details. |
|
16 |
|
17 You should have received a copy of the GNU General Public License |
|
18 along with Octave; see the file COPYING. If not, write to the Free |
|
19 Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
|
20 |
|
21 */ |
|
22 |
|
23 #if !defined (octave_tree_expr2_h) |
|
24 #define octave_tree_expr2_h 1 |
|
25 |
|
26 #if defined (__GNUG__) |
|
27 #pragma interface |
|
28 #endif |
|
29 |
|
30 class ostream; |
|
31 |
|
32 class tree_identifier; |
|
33 class tree_index_expression; |
|
34 class tree_indirect_ref; |
|
35 class tree_argument_list; |
|
36 |
2124
|
37 class tree_walker; |
|
38 |
1739
|
39 #include "pt-exp-base.h" |
|
40 |
|
41 // Prefix expressions. |
|
42 |
|
43 class |
|
44 tree_prefix_expression : public tree_expression |
|
45 { |
2124
|
46 public: |
|
47 |
2388
|
48 enum type |
|
49 { |
|
50 unknown, |
|
51 increment, |
|
52 decrement |
|
53 }; |
1739
|
54 |
2388
|
55 tree_prefix_expression (int l = -1, int c = -1, type t = unknown) |
|
56 : tree_expression (l, c), id (0), etype (t) { } |
|
57 |
|
58 tree_prefix_expression (tree_identifier *i, int l = -1, int c = -1, |
|
59 type t = unknown) |
|
60 : tree_expression (l, c), id (i), etype (t) { } |
1739
|
61 |
|
62 ~tree_prefix_expression (void); |
|
63 |
2086
|
64 octave_value eval (bool print); |
1739
|
65 |
|
66 void eval_error (void); |
|
67 |
1827
|
68 bool is_prefix_expression (void) const |
|
69 { return true; } |
1739
|
70 |
2805
|
71 const char *oper (void) const; |
1739
|
72 |
2124
|
73 tree_identifier *ident (void) { return id; } |
|
74 |
|
75 void accept (tree_walker& tw); |
1739
|
76 |
2124
|
77 private: |
|
78 |
|
79 // Currently, a prefix expression can only apply to an identifier. |
1739
|
80 tree_identifier *id; |
2388
|
81 |
|
82 // The type of the expression. |
|
83 type etype; |
1739
|
84 }; |
|
85 |
|
86 // Postfix expressions. |
|
87 |
|
88 class |
|
89 tree_postfix_expression : public tree_expression |
|
90 { |
2124
|
91 public: |
|
92 |
2388
|
93 enum type |
|
94 { |
|
95 unknown, |
|
96 increment, |
|
97 decrement |
|
98 }; |
1739
|
99 |
2388
|
100 tree_postfix_expression (int l = -1, int c = -1, type t = unknown) |
|
101 : tree_expression (l, c), id (0), etype (t) { } |
|
102 |
|
103 tree_postfix_expression (tree_identifier *i, int l = -1, int c = -1, |
|
104 type t = unknown) |
|
105 : tree_expression (l, c), id (i), etype (t) { } |
1739
|
106 |
|
107 ~tree_postfix_expression (void); |
|
108 |
2086
|
109 octave_value eval (bool print); |
1739
|
110 |
|
111 void eval_error (void); |
|
112 |
2805
|
113 const char *oper (void) const; |
1739
|
114 |
2124
|
115 tree_identifier *ident (void) { return id; } |
|
116 |
|
117 void accept (tree_walker& tw); |
1739
|
118 |
2124
|
119 private: |
|
120 |
|
121 // Currently, a prefix expression can only apply to an identifier. |
1739
|
122 tree_identifier *id; |
2388
|
123 |
|
124 // The type of the expression. |
|
125 type etype; |
1739
|
126 }; |
|
127 |
|
128 // Unary expressions. |
|
129 |
|
130 class |
|
131 tree_unary_expression : public tree_expression |
|
132 { |
2124
|
133 public: |
|
134 |
2388
|
135 enum type |
|
136 { |
|
137 unknown, |
|
138 unot, |
|
139 uminus, |
|
140 hermitian, |
|
141 transpose |
|
142 }; |
1739
|
143 |
2388
|
144 tree_unary_expression (int l = -1, int c = -1, type t = unknown) |
|
145 : tree_expression (l, c), op (0), etype (t) { } |
|
146 |
|
147 tree_unary_expression (tree_expression *a, int l = -1, int c = -1, |
|
148 type t = unknown) |
|
149 : tree_expression (l, c), op (a), etype (t) { } |
1739
|
150 |
|
151 ~tree_unary_expression (void) |
|
152 { delete op; } |
|
153 |
2086
|
154 octave_value eval (bool print); |
1739
|
155 |
|
156 void eval_error (void); |
|
157 |
2805
|
158 const char *oper (void) const; |
1739
|
159 |
2805
|
160 bool is_prefix_op (void) { return (etype == unot || etype == uminus); } |
2388
|
161 |
2124
|
162 tree_expression *operand (void) { return op; } |
|
163 |
|
164 void accept (tree_walker& tw); |
1739
|
165 |
2124
|
166 private: |
|
167 |
|
168 // The operand for the expression. |
1739
|
169 tree_expression *op; |
2388
|
170 |
|
171 // The type of the expression. |
|
172 type etype; |
1739
|
173 }; |
|
174 |
|
175 // Binary expressions. |
|
176 |
|
177 class |
|
178 tree_binary_expression : public tree_expression |
|
179 { |
2124
|
180 public: |
|
181 |
2388
|
182 enum type |
|
183 { |
|
184 unknown, |
|
185 add, |
|
186 subtract, |
|
187 multiply, |
|
188 el_mul, |
|
189 divide, |
|
190 el_div, |
|
191 leftdiv, |
|
192 el_leftdiv, |
|
193 power, |
|
194 elem_pow, |
|
195 cmp_lt, |
|
196 cmp_le, |
|
197 cmp_eq, |
|
198 cmp_ge, |
|
199 cmp_gt, |
|
200 cmp_ne, |
2805
|
201 el_and, |
|
202 el_or |
2388
|
203 }; |
|
204 |
|
205 tree_binary_expression (int l = -1, int c = -1, type t = unknown) |
|
206 : tree_expression (l, c), op_lhs (0), op_rhs (0), etype (t) { } |
1739
|
207 |
|
208 tree_binary_expression (tree_expression *a, tree_expression *b, |
2388
|
209 int l = -1, int c = -1, type t = unknown) |
|
210 : tree_expression (l, c), op_lhs (a), op_rhs (b), etype (t) { } |
1739
|
211 |
|
212 ~tree_binary_expression (void) |
|
213 { |
2124
|
214 delete op_lhs; |
|
215 delete op_rhs; |
1739
|
216 } |
|
217 |
2086
|
218 octave_value eval (bool print); |
1739
|
219 |
|
220 void eval_error (void); |
|
221 |
2805
|
222 const char *oper (void) const; |
1739
|
223 |
2124
|
224 tree_expression *lhs (void) { return op_lhs; } |
|
225 tree_expression *rhs (void) { return op_rhs; } |
|
226 |
|
227 void accept (tree_walker& tw); |
1739
|
228 |
2388
|
229 protected: |
2124
|
230 |
|
231 // The operands for the expression. |
|
232 tree_expression *op_lhs; |
|
233 tree_expression *op_rhs; |
2388
|
234 |
|
235 private: |
|
236 |
|
237 // The type of the expression. |
|
238 type etype; |
|
239 }; |
|
240 |
|
241 // Boolean expressions. |
|
242 |
|
243 class |
|
244 tree_boolean_expression : public tree_binary_expression |
|
245 { |
|
246 public: |
|
247 |
|
248 enum type |
|
249 { |
|
250 unknown, |
2805
|
251 bool_and, |
|
252 bool_or |
2388
|
253 }; |
|
254 |
|
255 tree_boolean_expression (int l = -1, int c = -1, type t) |
|
256 : tree_binary_expression (l, c), etype (t) { } |
|
257 |
|
258 tree_boolean_expression (tree_expression *a, tree_expression *b, |
|
259 int l = -1, int c = -1, type t = unknown) |
|
260 : tree_binary_expression (a, b, l, c), etype (t) { } |
|
261 |
|
262 ~tree_boolean_expression (void) { } |
|
263 |
|
264 octave_value eval (bool print); |
|
265 |
2805
|
266 const char *oper (void) const; |
2388
|
267 |
|
268 private: |
|
269 |
|
270 // The type of the expression. |
|
271 type etype; |
1739
|
272 }; |
|
273 |
|
274 // Simple assignment expressions. |
|
275 |
|
276 class |
|
277 tree_simple_assignment_expression : public tree_expression |
|
278 { |
2124
|
279 public: |
1739
|
280 |
1827
|
281 tree_simple_assignment_expression (bool plhs = false, |
|
282 bool ans_assign = false, |
1739
|
283 int l = -1, int c = -1) |
|
284 : tree_expression (l, c) |
|
285 { init (plhs, ans_assign); } |
|
286 |
|
287 tree_simple_assignment_expression (tree_identifier *i, |
|
288 tree_expression *r, |
1827
|
289 bool plhs = false, |
|
290 bool ans_assign = false, |
1739
|
291 int l = -1, int c = -1); |
|
292 |
|
293 tree_simple_assignment_expression (tree_indirect_ref *i, |
|
294 tree_expression *r, |
1827
|
295 bool plhs = false, |
|
296 bool ans_assign = false, |
1739
|
297 int l = -1, int c = -1) |
|
298 : tree_expression (l, c) |
|
299 { |
|
300 init (plhs, ans_assign); |
|
301 lhs = i; |
|
302 rhs = r; |
|
303 } |
|
304 |
|
305 tree_simple_assignment_expression (tree_index_expression *idx_expr, |
|
306 tree_expression *r, |
1827
|
307 bool plhs = false, |
|
308 bool ans_assign = false, |
1739
|
309 int l = -1, int c = -1); |
|
310 |
|
311 ~tree_simple_assignment_expression (void); |
|
312 |
1827
|
313 bool left_hand_side_is_identifier_only (void); |
1739
|
314 |
|
315 tree_identifier *left_hand_side_id (void); |
|
316 |
1827
|
317 bool is_ans_assign (void) |
1739
|
318 { return ans_ass; } |
|
319 |
2086
|
320 octave_value eval (bool print); |
1739
|
321 |
1827
|
322 bool is_assignment_expression (void) const |
|
323 { return true; } |
1739
|
324 |
|
325 void eval_error (void); |
|
326 |
2124
|
327 tree_indirect_ref *left_hand_side (void) { return lhs; } |
|
328 |
|
329 tree_argument_list *lhs_index (void) { return index; } |
|
330 |
|
331 tree_expression *right_hand_side (void) { return rhs; } |
|
332 |
|
333 void accept (tree_walker& tw); |
1739
|
334 |
2124
|
335 private: |
|
336 |
|
337 // The left hand side of the assignment, as an index expression. If |
|
338 // the assignment is constructed from an index expression, the index |
|
339 // expression is split into the its components in the constructor. |
1739
|
340 tree_index_expression *lhs_idx_expr; |
2124
|
341 |
|
342 // The indirect reference (id or structure reference) on the left |
|
343 // hand side of the assignemnt. |
1739
|
344 tree_indirect_ref *lhs; |
2124
|
345 |
|
346 // The index of the left hand side of the assignment, if any. |
1739
|
347 tree_argument_list *index; |
2124
|
348 |
|
349 // The right hand side of the assignment. |
1739
|
350 tree_expression *rhs; |
2124
|
351 |
|
352 // True if we should not delete the lhs. |
1827
|
353 bool preserve; |
2124
|
354 |
|
355 // True if this is an assignment to the built-in variable ans. |
1827
|
356 bool ans_ass; |
2124
|
357 |
|
358 void init (bool plhs, bool ans_assign) |
|
359 { |
|
360 etype = tree_expression::assignment; |
|
361 lhs_idx_expr = 0; |
|
362 lhs = 0; |
|
363 index = 0; |
|
364 rhs = 0; |
|
365 preserve = plhs; |
|
366 ans_ass = ans_assign; |
|
367 } |
1739
|
368 }; |
|
369 |
|
370 // Colon expressions. |
|
371 |
|
372 class |
|
373 tree_colon_expression : public tree_expression |
|
374 { |
2124
|
375 public: |
|
376 |
1739
|
377 tree_colon_expression (int l = -1, int c = -1) |
|
378 : tree_expression (l, c, tree_expression::colon), |
2124
|
379 op_base (0), op_limit (0), op_increment (0) { } |
1739
|
380 |
|
381 tree_colon_expression (tree_expression *a, tree_expression *b, |
|
382 int l = -1, int c = -1) |
|
383 : tree_expression (l, c, tree_expression::colon), |
2124
|
384 op_base (a), op_limit (b), op_increment (0) { } |
1739
|
385 |
|
386 ~tree_colon_expression (void) |
|
387 { |
2124
|
388 delete op_base; |
|
389 delete op_limit; |
|
390 delete op_increment; |
1739
|
391 } |
|
392 |
|
393 tree_colon_expression *chain (tree_expression *t); |
|
394 |
2086
|
395 octave_value eval (bool print); |
1739
|
396 |
|
397 void eval_error (const char *s); |
|
398 |
2124
|
399 tree_expression *base (void) { return op_base; } |
|
400 tree_expression *limit (void) { return op_limit; } |
|
401 tree_expression *increment (void) { return op_increment; } |
|
402 |
|
403 void accept (tree_walker& tw); |
1739
|
404 |
2124
|
405 private: |
|
406 |
|
407 // The components of the expression. |
|
408 tree_expression *op_base; |
|
409 tree_expression *op_limit; |
|
410 tree_expression *op_increment; |
1739
|
411 }; |
|
412 |
|
413 #endif |
|
414 |
|
415 /* |
|
416 ;;; Local Variables: *** |
|
417 ;;; mode: C++ *** |
|
418 ;;; End: *** |
|
419 */ |