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_stmt_h) |
|
24 #define octave_tree_stmt_h 1 |
|
25 |
|
26 #if defined (__GNUG__) |
|
27 #pragma interface |
|
28 #endif |
|
29 |
|
30 #include <SLList.h> |
|
31 |
|
32 class octave_value_list; |
|
33 |
|
34 class tree_command; |
|
35 class tree_expression; |
|
36 |
|
37 class tree_walker; |
|
38 |
|
39 // A statement is either a command to execute or an expression to |
|
40 // evaluate. |
|
41 |
|
42 class |
|
43 tree_statement |
|
44 { |
|
45 public: |
|
46 |
|
47 tree_statement (void) |
|
48 : cmd (0), expr (0), print_flag (true) { } |
|
49 |
|
50 tree_statement (tree_command *c) |
|
51 : cmd (c), expr (0), print_flag (true) { } |
|
52 |
|
53 tree_statement (tree_expression *e) |
|
54 : cmd (0), expr (e), print_flag (true) { } |
|
55 |
|
56 ~tree_statement (void); |
|
57 |
|
58 void set_print_flag (bool print) |
|
59 { print_flag = print; } |
|
60 |
|
61 bool is_command (void) |
|
62 { return cmd != 0; } |
|
63 |
|
64 bool is_expression (void) |
|
65 { return expr != 0; } |
|
66 |
|
67 int line (void); |
|
68 int column (void); |
|
69 |
|
70 void maybe_echo_code (bool in_function_body); |
|
71 |
|
72 bool print_result (void) { return print_flag; } |
|
73 |
|
74 tree_command *command (void) { return cmd; } |
|
75 |
|
76 octave_value_list eval (bool silent, int nargout, bool in_function_body); |
|
77 |
|
78 tree_expression *expression (void) { return expr; } |
|
79 |
|
80 void accept (tree_walker& tw); |
|
81 |
|
82 private: |
|
83 |
|
84 // Only one of cmd or expr can be valid at once. |
|
85 |
|
86 // Command to execute. |
|
87 tree_command *cmd; |
|
88 |
|
89 // Expression to evaluate. |
|
90 tree_expression *expr; |
|
91 |
|
92 // Print result of eval for this command? |
|
93 bool print_flag; |
|
94 }; |
|
95 |
|
96 // A list of statements to evaluate. |
|
97 |
|
98 class |
|
99 tree_statement_list : public SLList<tree_statement *> |
|
100 { |
|
101 public: |
|
102 |
|
103 tree_statement_list (void) |
|
104 : SLList<tree_statement *> (), function_body (false) { } |
|
105 |
|
106 tree_statement_list (tree_statement *s) |
|
107 : SLList<tree_statement *> (), function_body (false) { append (s); } |
|
108 |
|
109 ~tree_statement_list (void) |
|
110 { |
|
111 while (! empty ()) |
|
112 { |
|
113 tree_statement *t = remove_front (); |
|
114 delete t; |
|
115 } |
|
116 } |
|
117 |
|
118 void mark_as_function_body (void) { function_body = true; } |
|
119 |
|
120 octave_value_list eval (bool silent = false, int nargout = 0); |
|
121 |
|
122 void accept (tree_walker& tw); |
|
123 |
|
124 private: |
|
125 |
|
126 // Does this list of statements make up the body of a function? |
|
127 bool function_body; |
|
128 }; |
|
129 |
|
130 #endif |
|
131 |
|
132 /* |
|
133 ;;; Local Variables: *** |
|
134 ;;; mode: C++ *** |
|
135 ;;; End: *** |
|
136 */ |