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