494
|
1 // Tree classes. -*- C++ -*- |
|
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 |
|
31 class tree_expression; |
|
32 class tree_index_expression; |
|
33 class tree_constant; |
|
34 class symbol_record; |
|
35 |
|
36 class tree_command; |
|
37 class tree_command_list; |
|
38 class tree_global_command; |
|
39 class tree_while_command; |
|
40 class tree_for_command; |
|
41 class tree_if_command; |
|
42 class tree_break_command; |
|
43 class tree_continue_command; |
|
44 class tree_return_command; |
|
45 |
|
46 /* |
|
47 * A base class for commands. |
|
48 */ |
|
49 class |
|
50 tree_command : public tree |
|
51 { |
|
52 }; |
|
53 |
|
54 /* |
|
55 * A command or two to be executed. |
|
56 */ |
|
57 class |
|
58 tree_command_list : public tree_command |
|
59 { |
|
60 public: |
|
61 tree_command_list (void); |
|
62 tree_command_list (tree *t); |
|
63 |
|
64 ~tree_command_list (void); |
|
65 |
|
66 tree_command_list *chain (tree *t); |
|
67 tree_command_list *reverse (void); |
|
68 |
|
69 void set_print_flag (int print); |
|
70 |
|
71 tree_constant eval (int print); |
|
72 |
|
73 private: |
|
74 tree *command; // Command to execute. |
|
75 int print_flag; // Print result of eval for this command? |
|
76 tree_command_list *next; // Next command in list. |
|
77 }; |
|
78 |
|
79 /* |
|
80 * Global. |
|
81 */ |
|
82 class |
|
83 tree_global_command : public tree_command |
|
84 { |
|
85 public: |
|
86 tree_global_command (int l = -1, int c = -1); |
|
87 tree_global_command (symbol_record *s, int l = -1, int c = -1); |
|
88 tree_global_command (symbol_record *s, tree_expression *e, |
|
89 int l = -1, int c = -1); |
|
90 |
|
91 ~tree_global_command (void); |
|
92 |
|
93 tree_global_command *chain (symbol_record *s, int l = -1, int c = -1); |
|
94 tree_global_command *chain (symbol_record *s, tree_expression *e, |
|
95 int l = -1, int c = -1); |
|
96 tree_global_command *reverse (void); |
|
97 |
|
98 tree_constant eval (int print); |
|
99 |
|
100 void eval_error (void); |
|
101 |
|
102 private: |
|
103 symbol_record *sr; // Symbol record from local symbol table. |
|
104 tree_expression *rhs; // RHS of assignment. |
|
105 tree_global_command *next; // Next global command. |
|
106 }; |
|
107 |
|
108 /* |
|
109 * While. |
|
110 */ |
|
111 class |
|
112 tree_while_command : public tree_command |
|
113 { |
|
114 public: |
|
115 tree_while_command (int l = -1, int c = -1); |
|
116 tree_while_command (tree_expression *e, int l = -1, int c = -1); |
|
117 tree_while_command (tree_expression *e, tree *lst, int l = -1, int c = -1); |
|
118 |
|
119 ~tree_while_command (void); |
|
120 |
|
121 tree_constant eval (int print); |
|
122 |
|
123 void eval_error (void); |
|
124 |
|
125 private: |
|
126 tree_expression *expr; // Expression to test. |
|
127 tree *list; // List of commands to execute. |
|
128 }; |
|
129 |
|
130 /* |
|
131 * For. |
|
132 */ |
|
133 class |
|
134 tree_for_command : public tree_command |
|
135 { |
|
136 public: |
|
137 tree_for_command (int l = -1, int c = -1); |
|
138 tree_for_command (tree_index_expression *id, tree_expression *e, tree *lst, |
|
139 int l = -1, int c = -1); |
|
140 |
|
141 ~tree_for_command (void); |
|
142 |
|
143 tree_constant eval (int print); |
|
144 |
|
145 void eval_error (void); |
|
146 |
|
147 private: |
|
148 tree_constant do_for_loop_once (tree_constant *rhs, int& quit); |
|
149 |
|
150 tree_index_expression *id; // Identifier to modify. |
|
151 tree_expression *expr; // Expression to evaluate. |
|
152 tree *list; // List of commands to execute. |
|
153 }; |
|
154 |
|
155 /* |
|
156 * Simple if. |
|
157 */ |
|
158 class |
|
159 tree_if_command : public tree_command |
|
160 { |
|
161 public: |
|
162 tree_if_command (int l = -1, int c = -1); |
|
163 tree_if_command (tree *lst, int l = -1, int c = -1); |
|
164 tree_if_command (tree_expression *e, tree *lst, int l = -1, int c = -1); |
|
165 |
|
166 ~tree_if_command (void); |
|
167 |
|
168 tree_if_command *chain (tree *lst, int l = -1, int c = -1); |
|
169 tree_if_command *chain (tree_expression *e, tree *lst, int l = -1, |
|
170 int c = -1); |
|
171 tree_if_command *reverse (void); |
|
172 |
|
173 tree_constant eval (int print); |
|
174 |
|
175 void eval_error (void); |
|
176 |
|
177 private: |
|
178 tree_expression *expr; // Expression to test. |
|
179 tree *list; // Commands to execute. |
|
180 tree_if_command *next; // Next if command. |
|
181 }; |
|
182 |
|
183 /* |
|
184 * Break. |
|
185 */ |
|
186 class |
|
187 tree_break_command : public tree_command |
|
188 { |
|
189 public: |
|
190 tree_break_command (int l = -1, int c = -1); |
|
191 |
|
192 ~tree_break_command (void); |
|
193 |
|
194 tree_constant eval (int print); |
|
195 }; |
|
196 |
|
197 /* |
|
198 * Continue. |
|
199 */ |
|
200 class |
|
201 tree_continue_command : public tree_command |
|
202 { |
|
203 public: |
|
204 tree_continue_command (int l = -1, int c = -1); |
|
205 |
|
206 ~tree_continue_command (void); |
|
207 |
|
208 tree_constant eval (int print); |
|
209 }; |
|
210 |
|
211 /* |
|
212 * Return. |
|
213 */ |
|
214 class |
|
215 tree_return_command : public tree_command |
|
216 { |
|
217 public: |
|
218 tree_return_command (int l = -1, int c = -1); |
|
219 |
|
220 ~tree_return_command (void); |
|
221 |
|
222 tree_constant eval (int print); |
|
223 }; |
|
224 |
|
225 #endif |
|
226 |
|
227 /* |
|
228 ;;; Local Variables: *** |
|
229 ;;; mode: C++ *** |
|
230 ;;; page-delimiter: "^/\\*" *** |
|
231 ;;; End: *** |
|
232 */ |