529
|
1 // tree-cmd.h -*- C++ -*- |
494
|
2 /* |
|
3 |
|
4 Copyright (C) 1992, 1993, 1994 John W. Eaton |
|
5 |
|
6 This file is part of Octave. |
|
7 |
|
8 Octave is free software; you can redistribute it and/or modify it |
|
9 under the terms of the GNU General Public License as published by the |
|
10 Free Software Foundation; either version 2, or (at your option) any |
|
11 later version. |
|
12 |
|
13 Octave is distributed in the hope that it will be useful, but WITHOUT |
|
14 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
|
15 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
|
16 for more details. |
|
17 |
|
18 You should have received a copy of the GNU General Public License |
|
19 along with Octave; see the file COPYING. If not, write to the Free |
|
20 Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. |
|
21 |
|
22 */ |
|
23 |
|
24 #if !defined (octave_tree_cmd_h) |
|
25 #define octave_tree_cmd_h 1 |
|
26 |
|
27 #if defined (__GNUG__) |
|
28 #pragma interface |
|
29 #endif |
|
30 |
578
|
31 class tree_statement_list; |
|
32 class tree_global_init_list; |
|
33 class tree_if_command_list; |
494
|
34 class tree_expression; |
|
35 class tree_index_expression; |
|
36 class tree_constant; |
|
37 class symbol_record; |
|
38 |
|
39 class tree_command; |
|
40 class tree_global_command; |
|
41 class tree_while_command; |
|
42 class tree_for_command; |
|
43 class tree_if_command; |
|
44 class tree_break_command; |
|
45 class tree_continue_command; |
|
46 class tree_return_command; |
|
47 |
578
|
48 #include "tree-base.h" |
|
49 |
|
50 // A base class for commands. |
|
51 |
494
|
52 class |
|
53 tree_command : public tree |
|
54 { |
578
|
55 public: |
|
56 tree_command (int l = -1, int c = -1) : tree (l, c) { } |
|
57 |
|
58 virtual void eval (void) = 0; |
494
|
59 }; |
|
60 |
|
61 class |
|
62 tree_global_command : public tree_command |
|
63 { |
|
64 public: |
578
|
65 tree_global_command (int l = -1, int c = -1) : tree_command (l, c) |
|
66 { init_list = 0; } |
|
67 |
|
68 tree_global_command (tree_global_init_list *t, int l = -1, int c = -1) |
|
69 : tree_command (l, c) |
|
70 { init_list = t; } |
494
|
71 |
|
72 ~tree_global_command (void); |
|
73 |
578
|
74 void eval (void); |
494
|
75 |
578
|
76 private: |
|
77 tree_global_init_list *init_list; |
494
|
78 }; |
|
79 |
578
|
80 // While. |
|
81 |
494
|
82 class |
|
83 tree_while_command : public tree_command |
|
84 { |
|
85 public: |
578
|
86 tree_while_command (int l = -1, int c = -1) : tree_command (l, c) |
|
87 { |
|
88 expr = 0; |
|
89 list = 0; |
|
90 } |
|
91 |
|
92 tree_while_command (tree_expression *e, int l = -1, int c = -1) |
|
93 : tree_command (l, c) |
|
94 { |
|
95 expr = e; |
|
96 list = 0; |
|
97 } |
|
98 |
|
99 tree_while_command (tree_expression *e, tree_statement_list *lst, |
|
100 int l = -1, int c = -1) |
|
101 : tree_command (l, c) |
|
102 { |
|
103 expr = e; |
|
104 list = lst; |
|
105 } |
494
|
106 |
|
107 ~tree_while_command (void); |
|
108 |
578
|
109 void eval (void); |
494
|
110 |
|
111 void eval_error (void); |
|
112 |
|
113 private: |
|
114 tree_expression *expr; // Expression to test. |
578
|
115 tree_statement_list *list; // List of commands to execute. |
494
|
116 }; |
|
117 |
578
|
118 // For. |
|
119 |
494
|
120 class |
|
121 tree_for_command : public tree_command |
|
122 { |
|
123 public: |
578
|
124 tree_for_command (int l = -1, int c = -1) : tree_command (l, c) |
|
125 { |
|
126 id = 0; |
|
127 expr = 0; |
|
128 list = 0; |
|
129 } |
|
130 |
|
131 tree_for_command (tree_index_expression *ident, tree_expression *e, |
|
132 tree_statement_list *lst, int l = -1, int c = -1) |
|
133 : tree_command (l, c) |
|
134 { |
|
135 id = ident; |
|
136 expr = e; |
|
137 list = lst; |
|
138 } |
494
|
139 |
|
140 ~tree_for_command (void); |
|
141 |
578
|
142 void eval (void); |
494
|
143 |
|
144 void eval_error (void); |
|
145 |
|
146 private: |
578
|
147 void do_for_loop_once (tree_constant *rhs, int& quit); |
494
|
148 |
|
149 tree_index_expression *id; // Identifier to modify. |
|
150 tree_expression *expr; // Expression to evaluate. |
578
|
151 tree_statement_list *list; // List of commands to execute. |
494
|
152 }; |
|
153 |
578
|
154 // If. |
|
155 |
494
|
156 class |
|
157 tree_if_command : public tree_command |
|
158 { |
|
159 public: |
578
|
160 tree_if_command (int l = -1, int c = -1) : tree_command (l, c) |
|
161 { list = 0; } |
|
162 |
|
163 tree_if_command (tree_if_command_list *lst, int l = -1, int c = -1) |
|
164 : tree_command (l, c) |
|
165 { list = lst; } |
494
|
166 |
|
167 ~tree_if_command (void); |
|
168 |
578
|
169 void eval (void); |
494
|
170 |
|
171 void eval_error (void); |
|
172 |
|
173 private: |
578
|
174 tree_if_command_list *list; |
494
|
175 }; |
|
176 |
578
|
177 // Break. |
|
178 |
494
|
179 class |
|
180 tree_break_command : public tree_command |
|
181 { |
|
182 public: |
578
|
183 tree_break_command (int l = -1, int c = -1) : tree_command (l, c) { } |
494
|
184 |
578
|
185 ~tree_break_command (void) { } |
494
|
186 |
578
|
187 void eval (void); |
494
|
188 }; |
|
189 |
578
|
190 // Continue. |
|
191 |
494
|
192 class |
|
193 tree_continue_command : public tree_command |
|
194 { |
|
195 public: |
578
|
196 tree_continue_command (int l = -1, int c = -1) : tree_command (l, c) { } |
494
|
197 |
578
|
198 ~tree_continue_command (void) { } |
494
|
199 |
578
|
200 void eval (void); |
494
|
201 }; |
|
202 |
578
|
203 // Return. |
|
204 |
494
|
205 class |
|
206 tree_return_command : public tree_command |
|
207 { |
578
|
208 public: |
|
209 tree_return_command (int l = -1, int c = -1) : tree_command (l, c) { } |
494
|
210 |
578
|
211 ~tree_return_command (void) { } |
494
|
212 |
578
|
213 void eval (void); |
494
|
214 }; |
|
215 |
|
216 #endif |
|
217 |
|
218 /* |
|
219 ;;; Local Variables: *** |
|
220 ;;; mode: C++ *** |
|
221 ;;; page-delimiter: "^/\\*" *** |
|
222 ;;; End: *** |
|
223 */ |