2980
|
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 |
4192
|
23 #if defined (__GNUG__) && defined (USE_PRAGMA_INTERFACE_IMPLEMENTATION) |
2980
|
24 #pragma implementation |
|
25 #endif |
|
26 |
|
27 #ifdef HAVE_CONFIG_H |
|
28 #include <config.h> |
|
29 #endif |
|
30 |
|
31 #include "error.h" |
|
32 #include "oct-obj.h" |
|
33 #include "pager.h" |
|
34 #include "ov.h" |
3770
|
35 #include "pt-bp.h" |
2980
|
36 #include "pt-colon.h" |
|
37 #include "pt-walk.h" |
|
38 |
|
39 // Colon expressions. |
|
40 |
|
41 tree_colon_expression * |
|
42 tree_colon_expression::append (tree_expression *t) |
|
43 { |
|
44 tree_colon_expression *retval = 0; |
|
45 |
|
46 if (op_base) |
|
47 { |
|
48 if (op_limit) |
|
49 { |
|
50 if (op_increment) |
|
51 ::error ("invalid colon expression"); |
|
52 else |
|
53 { |
|
54 // Stupid syntax: |
|
55 // |
|
56 // base : limit |
|
57 // base : increment : limit |
|
58 |
|
59 op_increment = op_limit; |
|
60 op_limit = t; |
|
61 } |
|
62 } |
|
63 else |
|
64 op_limit = t; |
|
65 |
|
66 retval = this; |
|
67 } |
|
68 else |
|
69 ::error ("invalid colon expression"); |
|
70 |
|
71 return retval; |
|
72 } |
|
73 |
|
74 octave_value_list |
|
75 tree_colon_expression::rvalue (int nargout) |
|
76 { |
|
77 octave_value_list retval; |
|
78 |
|
79 if (nargout > 1) |
|
80 error ("invalid number of output arguments for colon expression"); |
|
81 else |
|
82 retval = rvalue (); |
|
83 |
|
84 return retval; |
|
85 } |
|
86 |
|
87 octave_value |
|
88 tree_colon_expression::rvalue (void) |
|
89 { |
|
90 octave_value retval; |
|
91 |
3770
|
92 MAYBE_DO_BREAKPOINT; |
|
93 |
2980
|
94 if (error_state || ! op_base || ! op_limit) |
|
95 return retval; |
|
96 |
|
97 octave_value tmp = op_base->rvalue (); |
|
98 |
4876
|
99 if (error_state || tmp.is_undefined ()) |
2980
|
100 { |
4876
|
101 eval_error ("invalid value in colon expression"); |
2980
|
102 return retval; |
|
103 } |
|
104 |
|
105 double xbase = tmp.double_value (); |
|
106 |
|
107 if (error_state) |
|
108 { |
|
109 eval_error ("colon expression elements must be scalars"); |
|
110 return retval; |
|
111 } |
|
112 |
|
113 tmp = op_limit->rvalue (); |
|
114 |
4876
|
115 if (error_state || tmp.is_undefined ()) |
2980
|
116 { |
4876
|
117 eval_error ("invalid value in colon expression"); |
2980
|
118 return retval; |
|
119 } |
|
120 |
|
121 double xlimit = tmp.double_value (); |
|
122 |
|
123 if (error_state) |
|
124 { |
|
125 eval_error ("colon expression elements must be scalars"); |
|
126 return retval; |
|
127 } |
|
128 |
|
129 double xinc = 1.0; |
|
130 |
|
131 if (op_increment) |
|
132 { |
|
133 tmp = op_increment->rvalue (); |
|
134 |
4876
|
135 if (error_state || tmp.is_undefined ()) |
2980
|
136 { |
4876
|
137 eval_error ("invalid value in colon expression"); |
2980
|
138 return retval; |
|
139 } |
|
140 |
|
141 xinc = tmp.double_value (); |
|
142 |
|
143 if (error_state) |
|
144 { |
|
145 eval_error ("colon expression elements must be scalars"); |
|
146 return retval; |
|
147 } |
|
148 } |
|
149 |
|
150 retval = octave_value (xbase, xlimit, xinc); |
|
151 |
|
152 if (error_state) |
|
153 { |
3965
|
154 retval = octave_value (); |
|
155 eval_error (); |
2980
|
156 } |
|
157 |
|
158 return retval; |
|
159 } |
|
160 |
|
161 void |
3523
|
162 tree_colon_expression::eval_error (const std::string& s) |
2980
|
163 { |
3965
|
164 if (! s.empty ()) |
|
165 ::error ("%s", s.c_str ()); |
2980
|
166 |
3965
|
167 ::error ("evaluating colon expression near line %d column %d", |
|
168 line (), column ()); |
2980
|
169 } |
|
170 |
|
171 void |
|
172 tree_colon_expression::accept (tree_walker& tw) |
|
173 { |
|
174 tw.visit_colon_expression (*this); |
|
175 } |
|
176 |
|
177 /* |
|
178 ;;; Local Variables: *** |
|
179 ;;; mode: C++ *** |
|
180 ;;; End: *** |
|
181 */ |