2982
|
1 /* |
|
2 |
|
3 Copyright (C) 1996, 1997 John W. Eaton |
|
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_loop_h) |
|
24 #define octave_tree_loop_h 1 |
|
25 |
4066
|
26 #if defined (__GNUG__) && ! defined (NO_PRAGMA_INTERFACE_IMPLEMENTATION) |
2982
|
27 #pragma interface |
|
28 #endif |
|
29 |
|
30 class octave_value; |
|
31 class octave_lvalue; |
|
32 |
|
33 class tree_argument_list; |
|
34 class tree_expression; |
|
35 class tree_statement_list; |
|
36 |
|
37 class tree_walker; |
|
38 |
3665
|
39 #include "comment-list.h" |
2982
|
40 #include "pt-cmd.h" |
|
41 |
3877
|
42 // TRUE means we are evaluating some kind of looping construct. |
|
43 extern bool evaluating_looping_command; |
|
44 |
2982
|
45 // While. |
|
46 |
|
47 class |
|
48 tree_while_command : public tree_command |
|
49 { |
|
50 public: |
|
51 |
|
52 tree_while_command (int l = -1, int c = -1) |
3665
|
53 : tree_command (l, c), expr (0), list (0), lead_comm (0), |
|
54 trail_comm (0) { } |
2982
|
55 |
3665
|
56 tree_while_command (tree_expression *e, |
|
57 octave_comment_list *lc = 0, |
|
58 octave_comment_list *tc = 0, |
|
59 int l = -1, int c = -1) |
|
60 : tree_command (l, c), expr (e), list (0), lead_comm (lc), |
|
61 trail_comm (tc) { } |
2982
|
62 |
|
63 tree_while_command (tree_expression *e, tree_statement_list *lst, |
3665
|
64 octave_comment_list *lc = 0, |
|
65 octave_comment_list *tc = 0, |
2982
|
66 int l = -1, int c = -1) |
3665
|
67 : tree_command (l, c), expr (e), list (lst), lead_comm (lc), |
|
68 trail_comm (tc) { } |
2982
|
69 |
|
70 ~tree_while_command (void); |
|
71 |
|
72 void eval (void); |
|
73 |
|
74 void eval_error (void); |
|
75 |
|
76 tree_expression *condition (void) { return expr; } |
|
77 |
|
78 tree_statement_list *body (void) { return list; } |
|
79 |
3665
|
80 octave_comment_list *leading_comment (void) { return lead_comm; } |
|
81 |
|
82 octave_comment_list *trailing_comment (void) { return trail_comm; } |
|
83 |
2982
|
84 void accept (tree_walker& tw); |
|
85 |
3484
|
86 protected: |
2982
|
87 |
|
88 // Expression to test. |
|
89 tree_expression *expr; |
|
90 |
|
91 // List of commands to execute. |
|
92 tree_statement_list *list; |
2988
|
93 |
3665
|
94 // Comment preceding WHILE token. |
|
95 octave_comment_list *lead_comm; |
|
96 |
|
97 // Comment preceding ENDWHILE token. |
|
98 octave_comment_list *trail_comm; |
|
99 |
3484
|
100 private: |
|
101 |
2988
|
102 // No copying! |
|
103 |
|
104 tree_while_command (const tree_while_command&); |
|
105 |
|
106 tree_while_command& operator = (const tree_while_command&); |
2982
|
107 }; |
|
108 |
3484
|
109 // Do-Until. |
|
110 |
|
111 class |
|
112 tree_do_until_command : public tree_while_command |
|
113 { |
|
114 public: |
|
115 |
|
116 tree_do_until_command (int l = -1, int c = -1) |
|
117 : tree_while_command (l, c) { } |
|
118 |
3665
|
119 tree_do_until_command (tree_expression *e, |
|
120 octave_comment_list *lc = 0, |
|
121 octave_comment_list *tc = 0, |
|
122 int l = -1, int c = -1) |
|
123 : tree_while_command (e, lc, tc, l, c) { } |
3484
|
124 |
|
125 tree_do_until_command (tree_expression *e, tree_statement_list *lst, |
3665
|
126 octave_comment_list *lc = 0, |
|
127 octave_comment_list *tc = 0, |
|
128 int l = -1, int c = -1) |
|
129 : tree_while_command (e, lst, lc, tc, l, c) { } |
3484
|
130 |
|
131 ~tree_do_until_command (void) { } |
|
132 |
|
133 void eval (void); |
|
134 |
|
135 void eval_error (void); |
|
136 |
|
137 void accept (tree_walker& tw); |
|
138 |
|
139 private: |
|
140 |
|
141 // No copying! |
|
142 |
|
143 tree_do_until_command (const tree_do_until_command&); |
|
144 |
|
145 tree_do_until_command& operator = (const tree_do_until_command&); |
|
146 }; |
|
147 |
2982
|
148 // For. |
|
149 |
|
150 class |
|
151 tree_simple_for_command : public tree_command |
|
152 { |
|
153 public: |
|
154 |
|
155 tree_simple_for_command (int l = -1, int c = -1) |
3665
|
156 : tree_command (l, c), lhs (0), expr (0), list (0), lead_comm (0), |
|
157 trail_comm (0) { } |
2982
|
158 |
|
159 tree_simple_for_command (tree_expression *le, tree_expression *re, |
3665
|
160 tree_statement_list *lst, |
|
161 octave_comment_list *lc = 0, |
|
162 octave_comment_list *tc = 0, |
|
163 int l = -1, int c = -1) |
|
164 : tree_command (l, c), lhs (le), expr (re), list (lst), |
|
165 lead_comm (lc), trail_comm (tc) { } |
2982
|
166 |
|
167 ~tree_simple_for_command (void); |
|
168 |
|
169 void eval (void); |
|
170 |
|
171 void eval_error (void); |
|
172 |
|
173 tree_expression *left_hand_side (void) { return lhs; } |
|
174 |
|
175 tree_expression *control_expr (void) { return expr; } |
|
176 |
|
177 tree_statement_list *body (void) { return list; } |
|
178 |
3665
|
179 octave_comment_list *leading_comment (void) { return lead_comm; } |
|
180 |
|
181 octave_comment_list *trailing_comment (void) { return trail_comm; } |
|
182 |
2982
|
183 void accept (tree_walker& tw); |
|
184 |
|
185 private: |
|
186 |
|
187 // Expression to modify. |
|
188 tree_expression *lhs; |
|
189 |
|
190 // Expression to evaluate. |
|
191 tree_expression *expr; |
|
192 |
|
193 // List of commands to execute. |
|
194 tree_statement_list *list; |
|
195 |
3665
|
196 // Comment preceding FOR token. |
|
197 octave_comment_list *lead_comm; |
|
198 |
|
199 // Comment preceding ENDFOR token. |
|
200 octave_comment_list *trail_comm; |
|
201 |
2982
|
202 void do_for_loop_once (octave_lvalue &ult, const octave_value& rhs, |
|
203 bool& quit); |
2988
|
204 |
|
205 // No copying! |
|
206 |
|
207 tree_simple_for_command (const tree_simple_for_command&); |
|
208 |
|
209 tree_simple_for_command& operator = (const tree_simple_for_command&); |
2982
|
210 }; |
|
211 |
|
212 class |
|
213 tree_complex_for_command : public tree_command |
|
214 { |
|
215 public: |
|
216 |
|
217 tree_complex_for_command (int l = -1, int c = -1) |
3665
|
218 : tree_command (l, c), lhs (0), expr (0), list (0), lead_comm (0), |
|
219 trail_comm (0) { } |
2982
|
220 |
|
221 tree_complex_for_command (tree_argument_list *le, tree_expression *re, |
3665
|
222 tree_statement_list *lst, |
|
223 octave_comment_list *lc = 0, |
|
224 octave_comment_list *tc = 0, |
|
225 int l = -1, int c = -1) |
|
226 : tree_command (l, c), lhs (le), expr (re), list (lst), |
|
227 lead_comm (lc), trail_comm (tc) { } |
2982
|
228 |
|
229 ~tree_complex_for_command (void); |
|
230 |
|
231 void eval (void); |
|
232 |
|
233 void eval_error (void); |
|
234 |
|
235 tree_argument_list *left_hand_side (void) { return lhs; } |
|
236 |
|
237 tree_expression *control_expr (void) { return expr; } |
|
238 |
|
239 tree_statement_list *body (void) { return list; } |
|
240 |
3665
|
241 octave_comment_list *leading_comment (void) { return lead_comm; } |
|
242 |
|
243 octave_comment_list *trailing_comment (void) { return trail_comm; } |
|
244 |
2982
|
245 void accept (tree_walker& tw); |
|
246 |
|
247 private: |
|
248 |
|
249 // Expression to modify. |
|
250 tree_argument_list *lhs; |
|
251 |
|
252 // Expression to evaluate. |
|
253 tree_expression *expr; |
|
254 |
|
255 // List of commands to execute. |
|
256 tree_statement_list *list; |
|
257 |
3665
|
258 // Comment preceding FOR token. |
|
259 octave_comment_list *lead_comm; |
|
260 |
|
261 // Comment preceding ENDFOR token. |
|
262 octave_comment_list *trail_comm; |
|
263 |
2982
|
264 void do_for_loop_once (octave_lvalue &val_ref, octave_lvalue &key_ref, |
|
265 const octave_value& val, const octave_value& key, |
|
266 bool& quit); |
2988
|
267 |
|
268 // No copying! |
|
269 |
|
270 tree_complex_for_command (const tree_complex_for_command&); |
|
271 |
|
272 tree_complex_for_command& operator = (const tree_complex_for_command&); |
2982
|
273 }; |
|
274 |
|
275 #endif |
|
276 |
|
277 /* |
|
278 ;;; Local Variables: *** |
|
279 ;;; mode: C++ *** |
|
280 ;;; End: *** |
|
281 */ |