1829
|
1 /* |
1
|
2 |
2847
|
3 Copyright (C) 1996, 1997 John W. Eaton |
1
|
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 |
1315
|
19 Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
1
|
20 |
|
21 */ |
|
22 |
|
23 // Parser for Octave. |
|
24 |
767
|
25 // C decarations. |
|
26 |
1
|
27 %{ |
|
28 #define YYDEBUG 1 |
|
29 |
240
|
30 #ifdef HAVE_CONFIG_H |
1229
|
31 #include <config.h> |
240
|
32 #endif |
|
33 |
3178
|
34 #include <cassert> |
3156
|
35 #include <cstdio> |
|
36 |
2427
|
37 #ifdef YYBYACC |
|
38 #include <cstdlib> |
|
39 #endif |
|
40 |
3928
|
41 #include "Cell.h" |
1
|
42 #include "Matrix.h" |
3021
|
43 #include "cmd-edit.h" |
|
44 #include "cmd-hist.h" |
|
45 #include "file-ops.h" |
|
46 #include "file-stat.h" |
3712
|
47 #include "oct-time.h" |
4051
|
48 #include "lo-sstream.h" |
1
|
49 |
3665
|
50 #include "comment-list.h" |
2166
|
51 #include "defun.h" |
3021
|
52 #include "dynamic-ld.h" |
1351
|
53 #include "error.h" |
|
54 #include "input.h" |
|
55 #include "lex.h" |
1743
|
56 #include "oct-hist.h" |
2970
|
57 #include "ov-usr-fcn.h" |
1670
|
58 #include "toplev.h" |
1351
|
59 #include "pager.h" |
|
60 #include "parse.h" |
2987
|
61 #include "pt-all.h" |
1351
|
62 #include "symtab.h" |
|
63 #include "token.h" |
3021
|
64 #include "unwind-prot.h" |
1
|
65 #include "utils.h" |
1351
|
66 #include "variables.h" |
1
|
67 |
3021
|
68 // TRUE means we print |
|
69 static bool Vdefault_eval_print_flag = true; |
|
70 |
2166
|
71 // If TRUE, generate a warning for the assignment in things like |
|
72 // |
|
73 // octave> if (a = 2 < n) |
|
74 // |
|
75 // but not |
|
76 // |
|
77 // octave> if ((a = 2) < n) |
|
78 // |
|
79 static bool Vwarn_assign_as_truth_value; |
|
80 |
2764
|
81 // If TRUE, generate a warning for variable swich labels. |
|
82 static bool Vwarn_variable_switch_label; |
|
83 |
2166
|
84 // If TRUE, generate warning if declared function name disagrees with |
|
85 // the name of the file in which it is defined. |
|
86 static bool Vwarn_function_name_clash; |
|
87 |
3162
|
88 // TRUE means warn about function files that have time stamps in the future. |
|
89 bool Vwarn_future_time_stamp; |
|
90 |
2166
|
91 // If TRUE, generate warning if a statement in a function is not |
|
92 // terminated with a semicolon. Useful for checking functions that |
|
93 // should only produce output using explicit printing statements. |
|
94 static bool Vwarn_missing_semicolon; |
|
95 |
4023
|
96 // If TRUE, generate warning about the meaning of code changing due to |
|
97 // changes in precedence levels for various ops (typically for Matlab |
|
98 // compatibility). |
|
99 static bool Vwarn_precedence_change; |
|
100 |
1
|
101 // Temporary symbol table pointer used to cope with bogus function syntax. |
522
|
102 symbol_table *tmp_local_sym_tab = 0; |
1
|
103 |
|
104 // The current input line number. |
|
105 int input_line_number = 0; |
|
106 |
|
107 // The column of the current token. |
143
|
108 int current_input_column = 1; |
1
|
109 |
338
|
110 // Buffer for help text snagged from function files. |
3523
|
111 std::string help_buf; |
1
|
112 |
3665
|
113 // Buffer for comments appearing before a function statement. |
|
114 static std::string fcn_comment_header; |
|
115 |
3021
|
116 // TRUE means we are using readline. |
|
117 // (--no-line-editing) |
|
118 bool line_editing = true; |
|
119 |
|
120 // TRUE means we printed messages about reading startup files. |
|
121 bool reading_startup_message_printed = false; |
|
122 |
|
123 // TRUE means input is coming from startup file. |
|
124 bool input_from_startup_file = false; |
|
125 |
|
126 // TRUE means that input is coming from a file that was named on |
|
127 // the command line. |
|
128 bool input_from_command_line_file = true; |
|
129 |
3489
|
130 // TRUE means that we are in the process of evaluating a function |
|
131 // body. The parser might be called in that case if we are looking at |
|
132 // an eval() statement. |
|
133 bool evaluating_function_body = false; |
|
134 |
3903
|
135 // Keep track of symbol table information when parsing functions. |
|
136 static symbol_table *symtab_context = 0; |
|
137 |
496
|
138 // Forward declarations for some functions defined at the bottom of |
|
139 // the file. |
|
140 |
|
141 // Generic error messages. |
2970
|
142 static void |
|
143 yyerror (const char *s); |
1
|
144 |
578
|
145 // Error mesages for mismatched end tokens. |
2970
|
146 static void |
|
147 end_error (const char *type, token::end_tok_type ettype, int l, int c); |
1
|
148 |
578
|
149 // Check to see that end tokens are properly matched. |
2970
|
150 static bool |
|
151 end_token_ok (token *tok, token::end_tok_type expected); |
496
|
152 |
|
153 // Maybe print a warning if an assignment expression is used as the |
|
154 // test in a logical expression. |
2970
|
155 static void |
|
156 maybe_warn_assign_as_truth_value (tree_expression *expr); |
1
|
157 |
2764
|
158 // Maybe print a warning about switch labels that aren't constants. |
2970
|
159 static void |
|
160 maybe_warn_variable_switch_label (tree_expression *expr); |
2764
|
161 |
1623
|
162 // Create a plot command. |
2970
|
163 static tree_plot_command * |
|
164 make_plot_command (token *tok, plot_limits *range, subplot_list *list); |
1623
|
165 |
|
166 // Finish building a range. |
2970
|
167 static tree_expression * |
|
168 finish_colon_expression (tree_colon_expression *e); |
1623
|
169 |
1607
|
170 // Build a constant. |
2970
|
171 static tree_constant * |
|
172 make_constant (int op, token *tok_val); |
1607
|
173 |
578
|
174 // Build a binary expression. |
2970
|
175 static tree_expression * |
|
176 make_binary_op (int op, tree_expression *op1, token *tok_val, |
|
177 tree_expression *op2); |
578
|
178 |
2375
|
179 // Build a boolean expression. |
2970
|
180 static tree_expression * |
|
181 make_boolean_op (int op, tree_expression *op1, token *tok_val, |
|
182 tree_expression *op2); |
2375
|
183 |
578
|
184 // Build a prefix expression. |
2970
|
185 static tree_expression * |
|
186 make_prefix_op (int op, tree_expression *op1, token *tok_val); |
578
|
187 |
|
188 // Build a postfix expression. |
2970
|
189 static tree_expression * |
|
190 make_postfix_op (int op, tree_expression *op1, token *tok_val); |
578
|
191 |
1623
|
192 // Build an unwind-protect command. |
2970
|
193 static tree_command * |
|
194 make_unwind_command (token *unwind_tok, tree_statement_list *body, |
3665
|
195 tree_statement_list *cleanup, token *end_tok, |
|
196 octave_comment_list *lc, octave_comment_list *mc); |
1623
|
197 |
|
198 // Build a try-catch command. |
2970
|
199 static tree_command * |
|
200 make_try_command (token *try_tok, tree_statement_list *body, |
3665
|
201 tree_statement_list *cleanup, token *end_tok, |
|
202 octave_comment_list *lc, octave_comment_list *mc); |
1623
|
203 |
|
204 // Build a while command. |
2970
|
205 static tree_command * |
|
206 make_while_command (token *while_tok, tree_expression *expr, |
3665
|
207 tree_statement_list *body, token *end_tok, |
|
208 octave_comment_list *lc); |
1623
|
209 |
3484
|
210 // Build a do-until command. |
|
211 static tree_command * |
|
212 make_do_until_command (token *do_tok, tree_statement_list *body, |
3665
|
213 tree_expression *expr, octave_comment_list *lc); |
3484
|
214 |
1623
|
215 // Build a for command. |
2970
|
216 static tree_command * |
|
217 make_for_command (token *for_tok, tree_argument_list *lhs, |
|
218 tree_expression *expr, tree_statement_list *body, |
3665
|
219 token *end_tok, octave_comment_list *lc); |
1623
|
220 |
|
221 // Build a break command. |
2970
|
222 static tree_command * |
|
223 make_break_command (token *break_tok); |
1623
|
224 |
|
225 // Build a continue command. |
2970
|
226 static tree_command * |
|
227 make_continue_command (token *continue_tok); |
1623
|
228 |
|
229 // Build a return command. |
2970
|
230 static tree_command * |
|
231 make_return_command (token *return_tok); |
1623
|
232 |
|
233 // Start an if command. |
2970
|
234 static tree_if_command_list * |
|
235 start_if_command (tree_expression *expr, tree_statement_list *list); |
1623
|
236 |
|
237 // Finish an if command. |
2970
|
238 static tree_if_command * |
3665
|
239 finish_if_command (token *if_tok, tree_if_command_list *list, |
|
240 token *end_tok, octave_comment_list *lc); |
1623
|
241 |
|
242 // Build an elseif clause. |
2970
|
243 static tree_if_clause * |
3665
|
244 make_elseif_clause (tree_expression *expr, tree_statement_list *list, |
|
245 octave_comment_list *lc); |
1623
|
246 |
2764
|
247 // Finish a switch command. |
2970
|
248 static tree_switch_command * |
|
249 finish_switch_command (token *switch_tok, tree_expression *expr, |
3665
|
250 tree_switch_case_list *list, token *end_tok, |
|
251 octave_comment_list *lc); |
2764
|
252 |
|
253 // Build a switch case. |
2970
|
254 static tree_switch_case * |
3665
|
255 make_switch_case (tree_expression *expr, tree_statement_list *list, |
|
256 octave_comment_list *lc); |
2764
|
257 |
1623
|
258 // Build an assignment to a variable. |
2970
|
259 static tree_expression * |
|
260 make_assign_op (int op, tree_argument_list *lhs, token *eq_tok, |
|
261 tree_expression *rhs); |
1623
|
262 |
|
263 // Begin defining a function. |
2970
|
264 static octave_user_function * |
|
265 start_function (tree_parameter_list *param_list, tree_statement_list *body); |
1623
|
266 |
|
267 // Do most of the work for defining a function. |
2970
|
268 static octave_user_function * |
|
269 frob_function (tree_identifier *id, octave_user_function *fcn); |
1623
|
270 |
|
271 // Finish defining a function. |
2970
|
272 static octave_user_function * |
3665
|
273 finish_function (tree_identifier *id, octave_user_function *fcn, |
|
274 octave_comment_list *lc); |
1623
|
275 |
|
276 // Finish defining a function a different way. |
2970
|
277 static octave_user_function * |
3665
|
278 finish_function (tree_parameter_list *ret_list, |
|
279 octave_user_function *fcn, octave_comment_list *lc); |
751
|
280 |
2883
|
281 // Reset state after parsing function. |
2970
|
282 static void |
|
283 recover_from_parsing_function (void); |
2883
|
284 |
751
|
285 // Make an index expression. |
2970
|
286 static tree_index_expression * |
3933
|
287 make_index_expression (tree_expression *expr, |
|
288 tree_argument_list *args, char type); |
2970
|
289 |
|
290 // Make an indirect reference expression. |
3930
|
291 static tree_index_expression * |
3523
|
292 make_indirect_ref (tree_expression *expr, const std::string&); |
666
|
293 |
4131
|
294 // Make an indirect reference expression with dynamic field name. |
|
295 static tree_index_expression * |
|
296 make_indirect_ref (tree_expression *expr, tree_expression *field); |
|
297 |
2846
|
298 // Make a declaration command. |
2970
|
299 static tree_decl_command * |
|
300 make_decl_command (int tok, token *tok_val, tree_decl_init_list *lst); |
2846
|
301 |
1623
|
302 // Finish building a matrix list. |
2970
|
303 static tree_expression * |
|
304 finish_matrix (tree_matrix *m); |
1623
|
305 |
3351
|
306 // Finish building a cell list. |
|
307 static tree_expression * |
|
308 finish_cell (tree_cell *c); |
|
309 |
1511
|
310 // Maybe print a warning. Duh. |
2970
|
311 static void |
|
312 maybe_warn_missing_semi (tree_statement_list *); |
1511
|
313 |
2525
|
314 // Set the print flag for a statement based on the separator type. |
2970
|
315 static void |
|
316 set_stmt_print_flag (tree_statement_list *, char, bool); |
2525
|
317 |
1
|
318 #define ABORT_PARSE \ |
|
319 do \ |
|
320 { \ |
522
|
321 global_command = 0; \ |
1
|
322 yyerrok; \ |
3929
|
323 if (symtab_context) \ |
|
324 { \ |
|
325 curr_sym_tab = symtab_context; \ |
|
326 symtab_context = 0; \ |
|
327 } \ |
2865
|
328 if (interactive || forced_interactive) \ |
1
|
329 YYACCEPT; \ |
|
330 else \ |
|
331 YYABORT; \ |
|
332 } \ |
|
333 while (0) |
|
334 |
|
335 %} |
|
336 |
666
|
337 // Bison declarations. |
|
338 |
1
|
339 %union |
|
340 { |
2891
|
341 // The type of the basic tokens returned by the lexer. |
143
|
342 token *tok_val; |
|
343 |
3665
|
344 // Comment strings that we need to deal with mid-rule. |
|
345 octave_comment_list *comment_type; |
|
346 |
2891
|
347 // Types for the nonterminals we generate. |
2525
|
348 char sep_type; |
1
|
349 tree *tree_type; |
1829
|
350 tree_matrix *tree_matrix_type; |
3351
|
351 tree_cell *tree_cell_type; |
496
|
352 tree_expression *tree_expression_type; |
2375
|
353 tree_constant *tree_constant_type; |
1
|
354 tree_identifier *tree_identifier_type; |
|
355 tree_index_expression *tree_index_expression_type; |
|
356 tree_colon_expression *tree_colon_expression_type; |
|
357 tree_argument_list *tree_argument_list_type; |
|
358 tree_parameter_list *tree_parameter_list_type; |
|
359 tree_command *tree_command_type; |
|
360 tree_if_command *tree_if_command_type; |
578
|
361 tree_if_clause *tree_if_clause_type; |
|
362 tree_if_command_list *tree_if_command_list_type; |
2764
|
363 tree_switch_command *tree_switch_command_type; |
|
364 tree_switch_case *tree_switch_case_type; |
|
365 tree_switch_case_list *tree_switch_case_list_type; |
2846
|
366 tree_decl_elt *tree_decl_elt_type; |
|
367 tree_decl_init_list *tree_decl_init_list_type; |
|
368 tree_decl_command *tree_decl_command_type; |
578
|
369 tree_statement *tree_statement_type; |
|
370 tree_statement_list *tree_statement_list_type; |
1
|
371 tree_plot_command *tree_plot_command_type; |
578
|
372 subplot *subplot_type; |
|
373 subplot_list *subplot_list_type; |
|
374 plot_limits *plot_limits_type; |
|
375 plot_range *plot_range_type; |
|
376 subplot_using *subplot_using_type; |
|
377 subplot_style *subplot_style_type; |
3165
|
378 subplot_axes *subplot_axes_type; |
2891
|
379 octave_user_function *octave_user_function_type; |
1
|
380 } |
|
381 |
143
|
382 // Tokens with line and column information. |
|
383 %token <tok_val> '=' ':' '-' '+' '*' '/' |
4018
|
384 %token <tok_val> ADD_EQ SUB_EQ MUL_EQ DIV_EQ LEFTDIV_EQ POW_EQ |
|
385 %token <tok_val> EMUL_EQ EDIV_EQ ELEFTDIV_EQ EPOW_EQ AND_EQ OR_EQ |
2899
|
386 %token <tok_val> LSHIFT_EQ RSHIFT_EQ LSHIFT RSHIFT |
428
|
387 %token <tok_val> EXPR_AND_AND EXPR_OR_OR |
143
|
388 %token <tok_val> EXPR_AND EXPR_OR EXPR_NOT |
|
389 %token <tok_val> EXPR_LT EXPR_LE EXPR_EQ EXPR_NE EXPR_GE EXPR_GT |
1276
|
390 %token <tok_val> LEFTDIV EMUL EDIV ELEFTDIV EPLUS EMINUS |
|
391 %token <tok_val> QUOTE TRANSPOSE |
143
|
392 %token <tok_val> PLUS_PLUS MINUS_MINUS POW EPOW |
|
393 %token <tok_val> NUM IMAG_NUM |
2970
|
394 %token <tok_val> STRUCT_ELT |
2883
|
395 %token <tok_val> NAME |
143
|
396 %token <tok_val> END |
|
397 %token <tok_val> PLOT |
4064
|
398 %token <tok_val> STRING STYLE AXES_TAG |
3484
|
399 %token <tok_val> FOR WHILE DO UNTIL |
1491
|
400 %token <tok_val> IF ELSEIF ELSE |
2764
|
401 %token <tok_val> SWITCH CASE OTHERWISE |
1491
|
402 %token <tok_val> BREAK CONTINUE FUNC_RET |
924
|
403 %token <tok_val> UNWIND CLEANUP |
1489
|
404 %token <tok_val> TRY CATCH |
2846
|
405 %token <tok_val> GLOBAL STATIC |
1
|
406 |
143
|
407 // Other tokens. |
2970
|
408 %token END_OF_INPUT LEXICAL_ERROR |
3973
|
409 %token FCN VARARGIN VARARGOUT ALL_VA_ARGS |
3165
|
410 %token USING TITLE WITH AXES COLON OPEN_BRACE CLOSE_BRACE CLEAR |
1
|
411 |
143
|
412 // Nonterminals we construct. |
3665
|
413 %type <comment_type> stash_comment function_beg |
2525
|
414 %type <sep_type> sep_no_nl opt_sep_no_nl sep opt_sep |
578
|
415 %type <tree_type> input |
2960
|
416 %type <tree_constant_type> constant magic_colon |
3351
|
417 %type <tree_matrix_type> matrix_rows matrix_rows1 |
|
418 %type <tree_cell_type> cell_rows cell_rows1 |
|
419 %type <tree_expression_type> title matrix cell |
2970
|
420 %type <tree_expression_type> primary_expr postfix_expr prefix_expr binary_expr |
|
421 %type <tree_expression_type> simple_expr colon_expr assign_expr expression |
1
|
422 %type <tree_identifier_type> identifier |
2891
|
423 %type <octave_user_function_type> function1 function2 function3 |
2970
|
424 %type <tree_index_expression_type> word_list_cmd |
|
425 %type <tree_colon_expression_type> colon_expr1 |
3351
|
426 %type <tree_argument_list_type> arg_list word_list assign_lhs |
|
427 %type <tree_argument_list_type> cell_or_matrix_row |
723
|
428 %type <tree_parameter_list_type> param_list param_list1 |
|
429 %type <tree_parameter_list_type> return_list return_list1 |
2970
|
430 %type <tree_command_type> command select_command loop_command |
|
431 %type <tree_command_type> jump_command except_command function |
578
|
432 %type <tree_if_command_type> if_command |
|
433 %type <tree_if_clause_type> elseif_clause else_clause |
|
434 %type <tree_if_command_list_type> if_cmd_list1 if_cmd_list |
2764
|
435 %type <tree_switch_command_type> switch_command |
|
436 %type <tree_switch_case_type> switch_case default_case |
|
437 %type <tree_switch_case_list_type> case_list1 case_list |
2846
|
438 %type <tree_decl_elt_type> decl2 |
|
439 %type <tree_decl_init_list_type> decl1 |
|
440 %type <tree_decl_command_type> declaration |
578
|
441 %type <tree_statement_type> statement |
627
|
442 %type <tree_statement_list_type> simple_list simple_list1 list list1 |
2891
|
443 %type <tree_statement_list_type> opt_list input1 function4 |
1
|
444 %type <tree_plot_command_type> plot_command |
578
|
445 %type <subplot_type> plot_command2 plot_options |
|
446 %type <subplot_list_type> plot_command1 |
|
447 %type <plot_limits_type> ranges |
|
448 %type <plot_range_type> ranges1 |
|
449 %type <subplot_using_type> using using1 |
|
450 %type <subplot_style_type> style |
3165
|
451 %type <subplot_axes_type> axes |
1
|
452 |
143
|
453 // Precedence and associativity. |
1
|
454 %left ';' ',' '\n' |
4018
|
455 %right '=' ADD_EQ SUB_EQ MUL_EQ DIV_EQ LEFTDIV_EQ POW_EQ EMUL_EQ EDIV_EQ ELEFTDIV_EQ EPOW_EQ OR_EQ AND_EQ LSHIFT_EQ RSHIFT_EQ |
4023
|
456 %left EXPR_OR_OR |
|
457 %left EXPR_AND_AND |
|
458 %left EXPR_OR |
|
459 %left EXPR_AND |
1
|
460 %left EXPR_LT EXPR_LE EXPR_EQ EXPR_NE EXPR_GE EXPR_GT |
2899
|
461 %left LSHIFT RSHIFT |
1
|
462 %left ':' |
1276
|
463 %left '-' '+' EPLUS EMINUS |
1
|
464 %left '*' '/' LEFTDIV EMUL EDIV ELEFTDIV |
|
465 %left QUOTE TRANSPOSE |
|
466 %left UNARY PLUS_PLUS MINUS_MINUS EXPR_NOT |
|
467 %right POW EPOW |
3351
|
468 %left '(' '.' '{' |
1
|
469 |
143
|
470 // Where to start. |
1
|
471 %start input |
|
472 |
|
473 %% |
|
474 |
2970
|
475 // ============================== |
|
476 // Statements and statement lists |
|
477 // ============================== |
|
478 |
627
|
479 input : input1 |
1
|
480 { |
627
|
481 global_command = $1; |
1
|
482 promptflag = 1; |
|
483 YYACCEPT; |
|
484 } |
627
|
485 | simple_list parse_error |
1091
|
486 { ABORT_PARSE; } |
627
|
487 | parse_error |
1091
|
488 { ABORT_PARSE; } |
627
|
489 ; |
|
490 |
|
491 input1 : '\n' |
|
492 { $$ = 0; } |
3883
|
493 | END_OF_INPUT |
|
494 { |
|
495 parser_end_of_input = 1; |
|
496 $$ = 0; |
|
497 } |
327
|
498 | simple_list |
627
|
499 { $$ = $1; } |
1
|
500 | simple_list '\n' |
627
|
501 { $$ = $1; } |
1
|
502 | simple_list END_OF_INPUT |
627
|
503 { $$ = $1; } |
|
504 ; |
|
505 |
2525
|
506 simple_list : simple_list1 opt_sep_no_nl |
1
|
507 { |
2525
|
508 set_stmt_print_flag ($1, $2, false); |
1511
|
509 $$ = $1; |
1
|
510 } |
|
511 ; |
|
512 |
578
|
513 simple_list1 : statement |
|
514 { $$ = new tree_statement_list ($1); } |
2525
|
515 | simple_list1 sep_no_nl statement |
1
|
516 { |
2525
|
517 set_stmt_print_flag ($1, $2, false); |
578
|
518 $1->append ($3); |
1511
|
519 $$ = $1; |
1
|
520 } |
|
521 ; |
|
522 |
|
523 opt_list : // empty |
578
|
524 { $$ = new tree_statement_list (); } |
1
|
525 | list |
|
526 { $$ = $1; } |
496
|
527 ; |
1
|
528 |
2525
|
529 list : list1 opt_sep |
1511
|
530 { |
2525
|
531 set_stmt_print_flag ($1, $2, true); |
1829
|
532 $$ = $1; |
1
|
533 } |
|
534 ; |
|
535 |
578
|
536 list1 : statement |
440
|
537 { |
2857
|
538 lexer_flags.beginning_of_function = false; |
578
|
539 $$ = new tree_statement_list ($1); |
440
|
540 } |
2525
|
541 | list1 sep statement |
1511
|
542 { |
2525
|
543 set_stmt_print_flag ($1, $2, true); |
578
|
544 $1->append ($3); |
1511
|
545 $$ = $1; |
1
|
546 } |
|
547 ; |
|
548 |
2970
|
549 statement : expression |
3665
|
550 { |
|
551 octave_comment_list *comment |
|
552 = octave_comment_buffer::get_comment (); |
|
553 |
|
554 $$ = new tree_statement ($1, comment); |
|
555 } |
2970
|
556 | command |
3665
|
557 { |
|
558 octave_comment_list *comment |
|
559 = octave_comment_buffer::get_comment (); |
|
560 |
|
561 $$ = new tree_statement ($1, comment); |
|
562 } |
883
|
563 | PLOT CLEAR |
|
564 { |
|
565 symbol_record *sr = lookup_by_name ("clearplot", 0); |
|
566 tree_identifier *id = new tree_identifier (sr); |
3665
|
567 |
|
568 octave_comment_list *comment |
|
569 = octave_comment_buffer::get_comment (); |
|
570 |
|
571 $$ = new tree_statement (id, comment); |
883
|
572 } |
1
|
573 ; |
|
574 |
2970
|
575 // =========== |
|
576 // Expressions |
|
577 // =========== |
|
578 |
|
579 identifier : NAME |
|
580 { |
|
581 $$ = new tree_identifier |
|
582 ($1->sym_rec (), $1->line (), $1->column ()); |
|
583 } |
|
584 ; |
|
585 |
|
586 constant : NUM |
|
587 { $$ = make_constant (NUM, $1); } |
|
588 | IMAG_NUM |
|
589 { $$ = make_constant (IMAG_NUM, $1); } |
4064
|
590 | STRING |
|
591 { $$ = make_constant (STRING, $1); } |
2970
|
592 ; |
|
593 |
3189
|
594 in_matrix_or_assign_lhs |
|
595 : // empty |
|
596 { lexer_flags.looking_at_matrix_or_assign_lhs = true; } |
|
597 ; |
|
598 |
2970
|
599 matrix : '[' ']' |
|
600 { $$ = new tree_constant (octave_value (Matrix ())); } |
|
601 | '[' ';' ']' |
|
602 { $$ = new tree_constant (octave_value (Matrix ())); } |
3351
|
603 | '[' in_matrix_or_assign_lhs matrix_rows ']' |
3203
|
604 { |
|
605 $$ = finish_matrix ($3); |
|
606 lexer_flags.looking_at_matrix_or_assign_lhs = false; |
|
607 } |
2970
|
608 ; |
|
609 |
3351
|
610 matrix_rows : matrix_rows1 |
2970
|
611 { $$ = $1; } |
3351
|
612 | matrix_rows1 ';' // Ignore trailing semicolon. |
2970
|
613 { $$ = $1; } |
|
614 ; |
|
615 |
3351
|
616 matrix_rows1 : cell_or_matrix_row |
2970
|
617 { $$ = new tree_matrix ($1); } |
3351
|
618 | matrix_rows1 ';' cell_or_matrix_row |
2970
|
619 { |
|
620 $1->append ($3); |
|
621 $$ = $1; |
|
622 } |
|
623 ; |
|
624 |
3351
|
625 cell : '{' '}' |
3928
|
626 { $$ = new tree_constant (octave_value (Cell ())); } |
3351
|
627 | '{' ';' '}' |
3928
|
628 { $$ = new tree_constant (octave_value (Cell ())); } |
3351
|
629 | '{' cell_rows '}' |
|
630 { $$ = finish_cell ($2); } |
|
631 ; |
|
632 |
|
633 cell_rows : cell_rows1 |
|
634 { $$ = $1; } |
|
635 | cell_rows1 ';' // Ignore trailing semicolon. |
|
636 { $$ = $1; } |
|
637 ; |
|
638 |
|
639 cell_rows1 : cell_or_matrix_row |
|
640 { $$ = new tree_cell ($1); } |
|
641 | cell_rows1 ';' cell_or_matrix_row |
|
642 { |
|
643 $1->append ($3); |
|
644 $$ = $1; |
|
645 } |
|
646 ; |
|
647 |
|
648 cell_or_matrix_row |
|
649 : arg_list |
2970
|
650 { $$ = $1; } |
|
651 | arg_list ',' // Ignore trailing comma. |
|
652 { $$ = $1; } |
|
653 ; |
|
654 |
|
655 primary_expr : identifier |
|
656 { $$ = $1; } |
|
657 | constant |
|
658 { $$ = $1; } |
|
659 | matrix |
|
660 { $$ = $1; } |
3351
|
661 | cell |
|
662 { $$ = $1; } |
2970
|
663 | '(' expression ')' |
|
664 { $$ = $2->mark_in_parens (); } |
|
665 ; |
|
666 |
|
667 magic_colon : ':' |
|
668 { |
|
669 octave_value tmp (octave_value::magic_colon_t); |
|
670 $$ = new tree_constant (tmp); |
|
671 } |
|
672 ; |
|
673 |
|
674 arg_list : expression |
|
675 { $$ = new tree_argument_list ($1); } |
|
676 | magic_colon |
|
677 { $$ = new tree_argument_list ($1); } |
|
678 | ALL_VA_ARGS |
|
679 { |
|
680 octave_value tmp (octave_value::all_va_args_t); |
|
681 tree_constant *all_va_args = new tree_constant (tmp); |
|
682 $$ = new tree_argument_list (all_va_args); |
|
683 } |
|
684 | arg_list ',' magic_colon |
|
685 { |
|
686 $1->append ($3); |
|
687 $$ = $1; |
|
688 } |
|
689 | arg_list ',' expression |
|
690 { |
|
691 $1->append ($3); |
|
692 $$ = $1; |
|
693 } |
|
694 | arg_list ',' ALL_VA_ARGS |
|
695 { |
|
696 octave_value tmp (octave_value::all_va_args_t); |
|
697 tree_constant *all_va_args = new tree_constant (tmp); |
|
698 $1->append (all_va_args); |
|
699 $$ = $1; |
|
700 } |
|
701 ; |
|
702 |
4131
|
703 indirect_ref_op : '.' |
2970
|
704 { lexer_flags.looking_at_indirect_ref = true; } |
|
705 ; |
|
706 |
|
707 postfix_expr : primary_expr |
|
708 { $$ = $1; } |
|
709 | postfix_expr '(' ')' |
3933
|
710 { $$ = make_index_expression ($1, 0, '('); } |
2970
|
711 | postfix_expr '(' arg_list ')' |
3933
|
712 { $$ = make_index_expression ($1, $3, '('); } |
3929
|
713 | postfix_expr '{' '}' |
3933
|
714 { $$ = make_index_expression ($1, 0, '{'); } |
3351
|
715 | postfix_expr '{' arg_list '}' |
3933
|
716 { $$ = make_index_expression ($1, $3, '{'); } |
2970
|
717 | postfix_expr PLUS_PLUS |
|
718 { $$ = make_postfix_op (PLUS_PLUS, $1, $2); } |
|
719 | postfix_expr MINUS_MINUS |
|
720 { $$ = make_postfix_op (MINUS_MINUS, $1, $2); } |
|
721 | postfix_expr QUOTE |
|
722 { $$ = make_postfix_op (QUOTE, $1, $2); } |
|
723 | postfix_expr TRANSPOSE |
|
724 { $$ = make_postfix_op (TRANSPOSE, $1, $2); } |
4131
|
725 | postfix_expr indirect_ref_op STRUCT_ELT |
|
726 { $$ = make_indirect_ref ($1, $3->text ()); } |
|
727 | postfix_expr indirect_ref_op '(' expression ')' |
|
728 { $$ = make_indirect_ref ($1, $4); } |
2970
|
729 ; |
|
730 |
|
731 prefix_expr : postfix_expr |
|
732 { $$ = $1; } |
3178
|
733 | binary_expr |
|
734 { $$ = $1; } |
2970
|
735 | PLUS_PLUS prefix_expr %prec UNARY |
|
736 { $$ = make_prefix_op (PLUS_PLUS, $2, $1); } |
|
737 | MINUS_MINUS prefix_expr %prec UNARY |
|
738 { $$ = make_prefix_op (MINUS_MINUS, $2, $1); } |
|
739 | EXPR_NOT prefix_expr %prec UNARY |
|
740 { $$ = make_prefix_op (EXPR_NOT, $2, $1); } |
|
741 | '+' prefix_expr %prec UNARY |
|
742 { $$ = $2; } |
|
743 | '-' prefix_expr %prec UNARY |
|
744 { $$ = make_prefix_op ('-', $2, $1); } |
|
745 ; |
|
746 |
3178
|
747 binary_expr : prefix_expr POW prefix_expr |
2970
|
748 { $$ = make_binary_op (POW, $1, $2, $3); } |
3178
|
749 | prefix_expr EPOW prefix_expr |
2970
|
750 { $$ = make_binary_op (EPOW, $1, $2, $3); } |
3178
|
751 | prefix_expr '+' prefix_expr |
2970
|
752 { $$ = make_binary_op ('+', $1, $2, $3); } |
3178
|
753 | prefix_expr '-' prefix_expr |
2970
|
754 { $$ = make_binary_op ('-', $1, $2, $3); } |
3178
|
755 | prefix_expr '*' prefix_expr |
2970
|
756 { $$ = make_binary_op ('*', $1, $2, $3); } |
3178
|
757 | prefix_expr '/' prefix_expr |
2970
|
758 { $$ = make_binary_op ('/', $1, $2, $3); } |
3178
|
759 | prefix_expr EPLUS prefix_expr |
2970
|
760 { $$ = make_binary_op ('+', $1, $2, $3); } |
3178
|
761 | prefix_expr EMINUS prefix_expr |
2970
|
762 { $$ = make_binary_op ('-', $1, $2, $3); } |
3178
|
763 | prefix_expr EMUL prefix_expr |
2970
|
764 { $$ = make_binary_op (EMUL, $1, $2, $3); } |
3178
|
765 | prefix_expr EDIV prefix_expr |
2970
|
766 { $$ = make_binary_op (EDIV, $1, $2, $3); } |
3178
|
767 | prefix_expr LEFTDIV prefix_expr |
2970
|
768 { $$ = make_binary_op (LEFTDIV, $1, $2, $3); } |
3178
|
769 | prefix_expr ELEFTDIV prefix_expr |
2970
|
770 { $$ = make_binary_op (ELEFTDIV, $1, $2, $3); } |
|
771 ; |
|
772 |
|
773 colon_expr : colon_expr1 |
|
774 { $$ = finish_colon_expression ($1); } |
|
775 ; |
|
776 |
3178
|
777 colon_expr1 : prefix_expr |
2970
|
778 { $$ = new tree_colon_expression ($1); } |
3178
|
779 | colon_expr1 ':' prefix_expr |
2970
|
780 { |
|
781 if (! ($$ = $1->append ($3))) |
|
782 ABORT_PARSE; |
|
783 } |
|
784 ; |
|
785 |
|
786 simple_expr : colon_expr |
|
787 { $$ = $1; } |
|
788 | simple_expr LSHIFT simple_expr |
|
789 { $$ = make_binary_op (LSHIFT, $1, $2, $3); } |
|
790 | simple_expr RSHIFT simple_expr |
|
791 { $$ = make_binary_op (RSHIFT, $1, $2, $3); } |
|
792 | simple_expr EXPR_LT simple_expr |
|
793 { $$ = make_binary_op (EXPR_LT, $1, $2, $3); } |
|
794 | simple_expr EXPR_LE simple_expr |
|
795 { $$ = make_binary_op (EXPR_LE, $1, $2, $3); } |
|
796 | simple_expr EXPR_EQ simple_expr |
|
797 { $$ = make_binary_op (EXPR_EQ, $1, $2, $3); } |
|
798 | simple_expr EXPR_GE simple_expr |
|
799 { $$ = make_binary_op (EXPR_GE, $1, $2, $3); } |
|
800 | simple_expr EXPR_GT simple_expr |
|
801 { $$ = make_binary_op (EXPR_GT, $1, $2, $3); } |
|
802 | simple_expr EXPR_NE simple_expr |
|
803 { $$ = make_binary_op (EXPR_NE, $1, $2, $3); } |
|
804 | simple_expr EXPR_AND simple_expr |
|
805 { $$ = make_binary_op (EXPR_AND, $1, $2, $3); } |
|
806 | simple_expr EXPR_OR simple_expr |
|
807 { $$ = make_binary_op (EXPR_OR, $1, $2, $3); } |
|
808 | simple_expr EXPR_AND_AND simple_expr |
|
809 { $$ = make_boolean_op (EXPR_AND_AND, $1, $2, $3); } |
|
810 | simple_expr EXPR_OR_OR simple_expr |
|
811 { $$ = make_boolean_op (EXPR_OR_OR, $1, $2, $3); } |
|
812 ; |
|
813 |
|
814 // Arrange for the lexer to return CLOSE_BRACE for `]' by looking ahead |
|
815 // one token for an assignment op. |
|
816 |
|
817 assign_lhs : simple_expr |
|
818 { $$ = new tree_argument_list ($1); } |
3189
|
819 | '[' in_matrix_or_assign_lhs arg_list CLOSE_BRACE |
|
820 { |
|
821 $$ = $3; |
|
822 lexer_flags.looking_at_matrix_or_assign_lhs = false; |
|
823 } |
2970
|
824 ; |
|
825 |
|
826 assign_expr : assign_lhs '=' expression |
|
827 { $$ = make_assign_op ('=', $1, $2, $3); } |
|
828 | assign_lhs ADD_EQ expression |
|
829 { $$ = make_assign_op (ADD_EQ, $1, $2, $3); } |
|
830 | assign_lhs SUB_EQ expression |
|
831 { $$ = make_assign_op (SUB_EQ, $1, $2, $3); } |
|
832 | assign_lhs MUL_EQ expression |
|
833 { $$ = make_assign_op (MUL_EQ, $1, $2, $3); } |
|
834 | assign_lhs DIV_EQ expression |
|
835 { $$ = make_assign_op (DIV_EQ, $1, $2, $3); } |
3204
|
836 | assign_lhs LEFTDIV_EQ expression |
|
837 { $$ = make_assign_op (LEFTDIV_EQ, $1, $2, $3); } |
4018
|
838 | assign_lhs POW_EQ expression |
|
839 { $$ = make_assign_op (POW_EQ, $1, $2, $3); } |
2970
|
840 | assign_lhs LSHIFT_EQ expression |
|
841 { $$ = make_assign_op (LSHIFT_EQ, $1, $2, $3); } |
|
842 | assign_lhs RSHIFT_EQ expression |
|
843 { $$ = make_assign_op (RSHIFT_EQ, $1, $2, $3); } |
|
844 | assign_lhs EMUL_EQ expression |
|
845 { $$ = make_assign_op (EMUL_EQ, $1, $2, $3); } |
|
846 | assign_lhs EDIV_EQ expression |
|
847 { $$ = make_assign_op (EDIV_EQ, $1, $2, $3); } |
3204
|
848 | assign_lhs ELEFTDIV_EQ expression |
|
849 { $$ = make_assign_op (ELEFTDIV_EQ, $1, $2, $3); } |
4018
|
850 | assign_lhs EPOW_EQ expression |
|
851 { $$ = make_assign_op (EPOW_EQ, $1, $2, $3); } |
2970
|
852 | assign_lhs AND_EQ expression |
|
853 { $$ = make_assign_op (AND_EQ, $1, $2, $3); } |
|
854 | assign_lhs OR_EQ expression |
|
855 { $$ = make_assign_op (OR_EQ, $1, $2, $3); } |
|
856 ; |
|
857 |
|
858 word_list_cmd : identifier word_list |
3933
|
859 { $$ = make_index_expression ($1, $2, '('); } |
2970
|
860 ; |
|
861 |
4064
|
862 word_list : STRING |
2970
|
863 { |
4064
|
864 tree_constant *tmp = make_constant (STRING, $1); |
2970
|
865 $$ = new tree_argument_list (tmp); |
|
866 } |
4064
|
867 | word_list STRING |
2970
|
868 { |
4064
|
869 tree_constant *tmp = make_constant (STRING, $2); |
2970
|
870 $1->append (tmp); |
|
871 $$ = $1; |
|
872 } |
|
873 ; |
|
874 |
|
875 expression : simple_expr |
|
876 { $$ = $1; } |
|
877 | word_list_cmd |
|
878 { $$ = $1; } |
|
879 | assign_expr |
|
880 { $$ = $1; } |
|
881 ; |
|
882 |
|
883 // ================================================ |
|
884 // Commands, declarations, and function definitions |
|
885 // ================================================ |
|
886 |
|
887 command : declaration |
|
888 { $$ = $1; } |
|
889 | select_command |
|
890 { $$ = $1; } |
|
891 | loop_command |
|
892 { $$ = $1; } |
|
893 | jump_command |
|
894 { $$ = $1; } |
|
895 | except_command |
|
896 { $$ = $1; } |
|
897 | function |
|
898 { $$ = $1; } |
|
899 | plot_command |
|
900 { $$ = $1; } |
|
901 ; |
|
902 |
|
903 // ===================== |
|
904 // Declaration statemnts |
|
905 // ===================== |
|
906 |
|
907 declaration : GLOBAL decl1 |
|
908 { $$ = make_decl_command (GLOBAL, $1, $2); } |
|
909 | STATIC decl1 |
|
910 { $$ = make_decl_command (STATIC, $1, $2); } |
|
911 ; |
|
912 |
|
913 decl1 : decl2 |
|
914 { $$ = new tree_decl_init_list ($1); } |
|
915 | decl1 decl2 |
|
916 { |
|
917 $1->append ($2); |
|
918 $$ = $1; |
|
919 } |
|
920 ; |
|
921 |
|
922 decl2 : identifier |
|
923 { $$ = new tree_decl_elt ($1); } |
|
924 | identifier '=' expression |
|
925 { $$ = new tree_decl_elt ($1, $3); } |
|
926 ; |
|
927 |
|
928 // ==================== |
|
929 // Selection statements |
|
930 // ==================== |
|
931 |
|
932 select_command : if_command |
|
933 { $$ = $1; } |
|
934 | switch_command |
|
935 { $$ = $1; } |
|
936 ; |
|
937 |
|
938 // ============ |
|
939 // If statement |
|
940 // ============ |
|
941 |
3665
|
942 if_command : IF stash_comment if_cmd_list END |
2970
|
943 { |
3665
|
944 if (! ($$ = finish_if_command ($1, $3, $4, $2))) |
2970
|
945 ABORT_PARSE; |
|
946 } |
|
947 ; |
|
948 |
|
949 if_cmd_list : if_cmd_list1 |
|
950 { $$ = $1; } |
|
951 | if_cmd_list1 else_clause |
|
952 { |
|
953 $1->append ($2); |
|
954 $$ = $1; |
|
955 } |
|
956 ; |
|
957 |
|
958 if_cmd_list1 : expression opt_sep opt_list |
|
959 { $$ = start_if_command ($1, $3); } |
|
960 | if_cmd_list1 elseif_clause |
|
961 { |
|
962 $1->append ($2); |
|
963 $$ = $1; |
|
964 } |
|
965 ; |
|
966 |
3665
|
967 elseif_clause : ELSEIF stash_comment opt_sep expression opt_sep opt_list |
|
968 { $$ = make_elseif_clause ($4, $6, $2); } |
2970
|
969 ; |
|
970 |
3665
|
971 else_clause : ELSE stash_comment opt_sep opt_list |
|
972 { |
|
973 $$ = new tree_if_clause ($4, $2); |
|
974 } |
2970
|
975 ; |
|
976 |
|
977 // ================ |
|
978 // Switch statement |
|
979 // ================ |
|
980 |
3665
|
981 switch_command : SWITCH stash_comment expression opt_sep case_list END |
2970
|
982 { |
3665
|
983 if (! ($$ = finish_switch_command ($1, $3, $5, $6, $2))) |
2970
|
984 ABORT_PARSE; |
|
985 } |
|
986 ; |
|
987 |
4044
|
988 case_list : // empty |
|
989 { $$ = new tree_switch_case_list (); } |
|
990 | case_list1 |
2970
|
991 { $$ = $1; } |
|
992 | case_list1 default_case |
|
993 { |
|
994 $1->append ($2); |
|
995 $$ = $1; |
|
996 } |
|
997 ; |
|
998 |
|
999 case_list1 : switch_case |
|
1000 { $$ = new tree_switch_case_list ($1); } |
|
1001 | case_list1 switch_case |
|
1002 { |
|
1003 $1->append ($2); |
|
1004 $$ = $1; |
|
1005 } |
|
1006 ; |
|
1007 |
4025
|
1008 switch_case : CASE stash_comment opt_sep expression opt_sep opt_list |
3665
|
1009 { $$ = make_switch_case ($4, $6, $2); } |
2970
|
1010 ; |
|
1011 |
3665
|
1012 default_case : OTHERWISE stash_comment opt_sep opt_list |
|
1013 { |
|
1014 $$ = new tree_switch_case ($4, $2); |
|
1015 } |
2970
|
1016 ; |
|
1017 |
|
1018 // ======= |
|
1019 // Looping |
|
1020 // ======= |
|
1021 |
3665
|
1022 loop_command : WHILE stash_comment expression opt_sep opt_list END |
2970
|
1023 { |
3665
|
1024 if (! ($$ = make_while_command ($1, $3, $5, $6, $2))) |
2970
|
1025 ABORT_PARSE; |
|
1026 } |
3665
|
1027 | DO stash_comment opt_sep opt_list UNTIL expression |
3484
|
1028 { |
3665
|
1029 if (! ($$ = make_do_until_command ($1, $4, $6, $2))) |
3484
|
1030 ABORT_PARSE; |
|
1031 } |
3665
|
1032 | FOR stash_comment assign_lhs '=' expression opt_sep opt_list END |
2970
|
1033 { |
3665
|
1034 if (! ($$ = make_for_command ($1, $3, $5, $7, $8, $2))) |
2970
|
1035 ABORT_PARSE; |
|
1036 } |
|
1037 ; |
|
1038 |
|
1039 // ======= |
|
1040 // Jumping |
|
1041 // ======= |
|
1042 |
|
1043 jump_command : BREAK |
|
1044 { |
|
1045 if (! ($$ = make_break_command ($1))) |
|
1046 ABORT_PARSE; |
|
1047 } |
|
1048 | CONTINUE |
|
1049 { |
|
1050 if (! ($$ = make_continue_command ($1))) |
|
1051 ABORT_PARSE; |
|
1052 } |
|
1053 | FUNC_RET |
|
1054 { |
|
1055 if (! ($$ = make_return_command ($1))) |
|
1056 ABORT_PARSE; |
|
1057 } |
|
1058 ; |
|
1059 |
|
1060 // ========== |
|
1061 // Exceptions |
|
1062 // ========== |
|
1063 |
3665
|
1064 except_command : UNWIND stash_comment opt_sep opt_list CLEANUP |
|
1065 stash_comment opt_sep opt_list END |
2970
|
1066 { |
3665
|
1067 if (! ($$ = make_unwind_command ($1, $4, $8, $9, $2, $6))) |
2970
|
1068 ABORT_PARSE; |
|
1069 } |
3665
|
1070 | TRY stash_comment opt_sep opt_list CATCH |
|
1071 stash_comment opt_sep opt_list END |
2970
|
1072 { |
3665
|
1073 if (! ($$ = make_try_command ($1, $4, $8, $9, $2, $6))) |
2970
|
1074 ABORT_PARSE; |
|
1075 } |
|
1076 ; |
|
1077 |
|
1078 // =========================================== |
|
1079 // Some `subroutines' for function definitions |
|
1080 // =========================================== |
|
1081 |
3903
|
1082 save_symtab : // empty |
|
1083 { |
|
1084 if (symtab_context) |
|
1085 panic_impossible (); |
|
1086 |
|
1087 symtab_context = curr_sym_tab; |
|
1088 } |
|
1089 ; |
|
1090 |
4009
|
1091 function_symtab : // empty |
|
1092 { curr_sym_tab = fbi_sym_tab; } |
2970
|
1093 ; |
|
1094 |
|
1095 local_symtab : // empty |
|
1096 { curr_sym_tab = tmp_local_sym_tab; } |
|
1097 ; |
|
1098 |
|
1099 in_return_list : // empty |
|
1100 { lexer_flags.looking_at_return_list = true; } |
|
1101 ; |
|
1102 |
|
1103 parsed_fcn_name : // empty |
|
1104 { lexer_flags.parsed_function_name = true; } |
|
1105 ; |
|
1106 |
|
1107 // =========================== |
|
1108 // List of function parameters |
|
1109 // =========================== |
|
1110 |
|
1111 param_list_beg : '(' |
|
1112 { lexer_flags.looking_at_parameter_list = true; } |
|
1113 ; |
|
1114 |
|
1115 param_list_end : ')' |
|
1116 { lexer_flags.looking_at_parameter_list = false; } |
|
1117 ; |
|
1118 |
|
1119 param_list : param_list_beg param_list_end |
|
1120 { |
|
1121 lexer_flags.quote_is_transpose = false; |
|
1122 $$ = 0; |
|
1123 } |
3973
|
1124 | param_list_beg VARARGIN param_list_end |
2970
|
1125 { |
|
1126 lexer_flags.quote_is_transpose = false; |
|
1127 tree_parameter_list *tmp = new tree_parameter_list (); |
|
1128 tmp->mark_varargs_only (); |
|
1129 $$ = tmp; |
|
1130 } |
|
1131 | param_list1 param_list_end |
|
1132 { |
|
1133 lexer_flags.quote_is_transpose = false; |
|
1134 $1->mark_as_formal_parameters (); |
|
1135 $$ = $1; |
|
1136 } |
3973
|
1137 | param_list1 ',' VARARGIN param_list_end |
2970
|
1138 { |
|
1139 lexer_flags.quote_is_transpose = false; |
|
1140 $1->mark_as_formal_parameters (); |
|
1141 $1->mark_varargs (); |
|
1142 $$ = $1; |
|
1143 } |
|
1144 ; |
|
1145 |
|
1146 param_list1 : param_list_beg identifier |
|
1147 { $$ = new tree_parameter_list ($2); } |
|
1148 | param_list1 ',' identifier |
|
1149 { |
|
1150 $1->append ($3); |
|
1151 $$ = $1; |
|
1152 } |
|
1153 | param_list_beg error |
|
1154 { |
|
1155 yyerror ("invalid parameter list"); |
|
1156 $$ = 0; |
|
1157 ABORT_PARSE; |
|
1158 } |
|
1159 | param_list1 ',' error |
|
1160 { |
|
1161 yyerror ("invalid parameter list"); |
|
1162 $$ = 0; |
|
1163 ABORT_PARSE; |
|
1164 } |
|
1165 ; |
|
1166 |
|
1167 // =================================== |
|
1168 // List of function return value names |
|
1169 // =================================== |
|
1170 |
3189
|
1171 return_list_beg : '[' in_return_list local_symtab |
2970
|
1172 ; |
|
1173 |
|
1174 return_list : return_list_beg return_list_end |
|
1175 { |
|
1176 lexer_flags.looking_at_return_list = false; |
|
1177 $$ = new tree_parameter_list (); |
|
1178 } |
3973
|
1179 | return_list_beg VARARGOUT return_list_end |
2970
|
1180 { |
|
1181 lexer_flags.looking_at_return_list = false; |
|
1182 tree_parameter_list *tmp = new tree_parameter_list (); |
|
1183 tmp->mark_varargs_only (); |
|
1184 $$ = tmp; |
|
1185 } |
|
1186 | return_list_beg return_list1 return_list_end |
|
1187 { |
|
1188 lexer_flags.looking_at_return_list = false; |
|
1189 $$ = $2; |
|
1190 } |
3973
|
1191 | return_list_beg return_list1 ',' VARARGOUT return_list_end |
2970
|
1192 { |
|
1193 lexer_flags.looking_at_return_list = false; |
|
1194 $2->mark_varargs (); |
|
1195 $$ = $2; |
|
1196 } |
|
1197 ; |
|
1198 |
|
1199 return_list1 : identifier |
|
1200 { $$ = new tree_parameter_list ($1); } |
|
1201 | return_list1 ',' identifier |
|
1202 { |
|
1203 $1->append ($3); |
|
1204 $$ = $1; |
|
1205 } |
|
1206 ; |
|
1207 |
4009
|
1208 return_list_end : function_symtab ']' |
2970
|
1209 ; |
|
1210 |
|
1211 // =================== |
|
1212 // Function definition |
|
1213 // =================== |
|
1214 |
4009
|
1215 function_beg : save_symtab FCN stash_comment function_symtab |
3903
|
1216 { $$ = $3; } |
2970
|
1217 ; |
|
1218 |
|
1219 function : function_beg function2 |
|
1220 { |
3665
|
1221 $2->stash_leading_comment ($1); |
2970
|
1222 recover_from_parsing_function (); |
|
1223 $$ = 0; |
|
1224 } |
|
1225 | function_beg identifier function1 |
|
1226 { |
3665
|
1227 finish_function ($2, $3, $1); |
2970
|
1228 recover_from_parsing_function (); |
|
1229 $$ = 0; |
|
1230 } |
|
1231 | function_beg return_list function1 |
|
1232 { |
3665
|
1233 finish_function ($2, $3, $1); |
2970
|
1234 recover_from_parsing_function (); |
|
1235 $$ = 0; |
|
1236 } |
|
1237 ; |
|
1238 |
4009
|
1239 function1 : function_symtab '=' function2 |
2970
|
1240 { $$ = $3; } |
|
1241 ; |
|
1242 |
|
1243 function2 : identifier local_symtab parsed_fcn_name function3 |
|
1244 { |
|
1245 if (! ($$ = frob_function ($1, $4))) |
|
1246 ABORT_PARSE; |
|
1247 } |
|
1248 ; |
|
1249 |
|
1250 function3 : param_list function4 |
|
1251 { $$ = start_function ($1, $2); } |
|
1252 | function4 |
|
1253 { $$ = start_function (0, $1); } |
|
1254 ; |
|
1255 |
|
1256 function4 : opt_sep opt_list function_end |
|
1257 { $$ = $2; } |
|
1258 ; |
|
1259 |
|
1260 function_end : END |
|
1261 { |
|
1262 if (end_token_ok ($1, token::function_end)) |
|
1263 { |
|
1264 if (reading_fcn_file) |
|
1265 check_for_garbage_after_fcn_def (); |
|
1266 } |
|
1267 else |
|
1268 ABORT_PARSE; |
|
1269 } |
|
1270 | END_OF_INPUT |
|
1271 { |
3939
|
1272 if (! (reading_fcn_file || reading_script_file |
|
1273 || get_input_from_eval_string)) |
2970
|
1274 YYABORT; |
|
1275 } |
|
1276 ; |
|
1277 |
|
1278 // ======== |
|
1279 // Plotting |
|
1280 // ======== |
|
1281 |
3180
|
1282 plot_command : PLOT |
|
1283 { |
|
1284 if (! ($$ = make_plot_command ($1, 0, 0))) |
|
1285 ABORT_PARSE; |
|
1286 } |
|
1287 | PLOT ranges |
|
1288 { |
|
1289 if (! ($$ = make_plot_command ($1, $2, 0))) |
|
1290 ABORT_PARSE; |
|
1291 } |
|
1292 | PLOT plot_command1 |
1
|
1293 { |
1623
|
1294 if (! ($$ = make_plot_command ($1, 0, $2))) |
|
1295 ABORT_PARSE; |
1
|
1296 } |
|
1297 | PLOT ranges plot_command1 |
|
1298 { |
1623
|
1299 if (! ($$ = make_plot_command ($1, $2, $3))) |
|
1300 ABORT_PARSE; |
1
|
1301 } |
|
1302 ; |
|
1303 |
|
1304 ranges : ranges1 |
578
|
1305 { $$ = new plot_limits ($1); } |
1
|
1306 | ranges1 ranges1 |
578
|
1307 { $$ = new plot_limits ($1, $2); } |
1
|
1308 | ranges1 ranges1 ranges1 |
578
|
1309 { $$ = new plot_limits ($1, $2, $3); } |
1
|
1310 ; |
|
1311 |
|
1312 ranges1 : OPEN_BRACE expression COLON expression CLOSE_BRACE |
578
|
1313 { $$ = new plot_range ($2, $4); } |
1
|
1314 | OPEN_BRACE COLON expression CLOSE_BRACE |
578
|
1315 { $$ = new plot_range (0, $3); } |
1
|
1316 | OPEN_BRACE expression COLON CLOSE_BRACE |
578
|
1317 { $$ = new plot_range ($2, 0); } |
1
|
1318 | OPEN_BRACE COLON CLOSE_BRACE |
578
|
1319 { $$ = new plot_range (); } |
1
|
1320 | OPEN_BRACE CLOSE_BRACE |
578
|
1321 { $$ = new plot_range (); } |
1
|
1322 ; |
|
1323 |
3180
|
1324 plot_command1 : plot_command2 |
578
|
1325 { $$ = new subplot_list ($1); } |
1
|
1326 | plot_command1 ',' plot_command2 |
1829
|
1327 { |
|
1328 $1->append ($3); |
|
1329 $$ = $1; |
|
1330 } |
1
|
1331 ; |
|
1332 |
|
1333 plot_command2 : expression |
578
|
1334 { $$ = new subplot ($1); } |
1
|
1335 | expression plot_options |
3165
|
1336 { $$ = $2->add_data ($1); } |
1
|
1337 ; |
|
1338 |
|
1339 plot_options : using |
3165
|
1340 { |
|
1341 subplot *tmp = new subplot (); |
|
1342 $$ = tmp->add_clause ($1); |
|
1343 } |
1
|
1344 | title |
3165
|
1345 { |
|
1346 subplot *tmp = new subplot (); |
|
1347 $$ = tmp->add_clause ($1); |
|
1348 } |
1
|
1349 | style |
3165
|
1350 { |
|
1351 subplot *tmp = new subplot (); |
|
1352 $$ = tmp->add_clause ($1); |
|
1353 } |
|
1354 | axes |
|
1355 { |
|
1356 subplot *tmp = new subplot (); |
|
1357 $$ = tmp->add_clause ($1); |
|
1358 } |
|
1359 | plot_options using |
|
1360 { |
|
1361 if (! ($$ = $1->add_clause ($2))) |
|
1362 { |
|
1363 yyerror ("only one using option may be specified"); |
|
1364 ABORT_PARSE; |
|
1365 } |
|
1366 } |
|
1367 | plot_options title |
|
1368 { |
|
1369 if (! ($$ = $1->add_clause ($2))) |
|
1370 { |
|
1371 yyerror ("only one title option my be specified"); |
|
1372 ABORT_PARSE; |
|
1373 } |
|
1374 } |
|
1375 | plot_options style |
|
1376 { |
|
1377 if (! ($$ = $1->add_clause ($2))) |
|
1378 { |
|
1379 yyerror ("only one style option my be specified"); |
|
1380 ABORT_PARSE; |
|
1381 } |
|
1382 } |
|
1383 | plot_options axes |
|
1384 { |
|
1385 if (! ($$ = $1->add_clause ($2))) |
|
1386 { |
|
1387 yyerror ("only one axes option may be specified"); |
|
1388 ABORT_PARSE; |
|
1389 } |
|
1390 } |
|
1391 ; |
|
1392 |
|
1393 axes : AXES AXES_TAG |
|
1394 { |
|
1395 lexer_flags.in_plot_axes = false; |
|
1396 $$ = new subplot_axes ($2->text ()); |
|
1397 } |
1
|
1398 ; |
|
1399 |
|
1400 using : using1 |
|
1401 { |
2857
|
1402 lexer_flags.in_plot_using = false; |
1
|
1403 $$ = $1; |
|
1404 } |
|
1405 | using1 expression |
|
1406 { |
2857
|
1407 lexer_flags.in_plot_using = false; |
1
|
1408 $$ = $1->set_format ($2); |
|
1409 } |
|
1410 ; |
|
1411 |
|
1412 using1 : USING expression |
|
1413 { |
578
|
1414 subplot_using *tmp = new subplot_using (); |
1
|
1415 $$ = tmp->add_qualifier ($2); |
|
1416 } |
|
1417 | using1 COLON expression |
|
1418 { $$ = $1->add_qualifier ($3); } |
|
1419 ; |
|
1420 |
|
1421 title : TITLE expression |
|
1422 { $$ = $2; } |
|
1423 ; |
|
1424 |
|
1425 style : WITH STYLE |
1755
|
1426 { $$ = new subplot_style ($2->text ()); } |
1
|
1427 | WITH STYLE expression |
1755
|
1428 { $$ = new subplot_style ($2->text (), $3); } |
2542
|
1429 | WITH STYLE expression expression |
|
1430 { $$ = new subplot_style ($2->text (), $3, $4); } |
1
|
1431 ; |
|
1432 |
2970
|
1433 // ============= |
|
1434 // Miscellaneous |
|
1435 // ============= |
|
1436 |
3665
|
1437 stash_comment : // empty |
|
1438 { $$ = octave_comment_buffer::get_comment (); } |
|
1439 ; |
|
1440 |
2970
|
1441 parse_error : LEXICAL_ERROR |
|
1442 { yyerror ("parse error"); } |
|
1443 | error |
1
|
1444 ; |
|
1445 |
2525
|
1446 sep_no_nl : ',' |
|
1447 { $$ = ','; } |
|
1448 | ';' |
|
1449 { $$ = ';'; } |
|
1450 | sep_no_nl ',' |
|
1451 { $$ = $1; } |
|
1452 | sep_no_nl ';' |
|
1453 { $$ = $1; } |
|
1454 ; |
|
1455 |
|
1456 opt_sep_no_nl : // empty |
|
1457 { $$ = 0; } |
|
1458 | sep_no_nl |
|
1459 { $$ = $1; } |
|
1460 ; |
|
1461 |
|
1462 sep : ',' |
|
1463 { $$ = ','; } |
|
1464 | ';' |
|
1465 { $$ = ';'; } |
|
1466 | '\n' |
|
1467 { $$ = '\n'; } |
|
1468 | sep ',' |
|
1469 { $$ = $1; } |
|
1470 | sep ';' |
|
1471 { $$ = $1; } |
|
1472 | sep '\n' |
|
1473 { $$ = $1; } |
|
1474 ; |
|
1475 |
|
1476 opt_sep : // empty |
|
1477 { $$ = 0; } |
|
1478 | sep |
|
1479 { $$ = $1; } |
|
1480 ; |
|
1481 |
1
|
1482 %% |
|
1483 |
666
|
1484 // Generic error messages. |
|
1485 |
1
|
1486 static void |
2805
|
1487 yyerror (const char *s) |
1
|
1488 { |
143
|
1489 int err_col = current_input_column - 1; |
1
|
1490 |
4051
|
1491 OSSTREAM output_buf; |
1
|
1492 |
1005
|
1493 if (reading_fcn_file || reading_script_file) |
|
1494 output_buf << "parse error near line " << input_line_number |
1607
|
1495 << " of file " << curr_fcn_file_full_name; |
1005
|
1496 else |
|
1497 output_buf << "parse error:"; |
581
|
1498 |
1005
|
1499 if (s && strcmp (s, "parse error") != 0) |
|
1500 output_buf << "\n\n " << s; |
|
1501 |
|
1502 output_buf << "\n\n"; |
1
|
1503 |
1755
|
1504 if (! current_input_line.empty ()) |
1
|
1505 { |
1755
|
1506 size_t len = current_input_line.length (); |
1060
|
1507 |
1755
|
1508 if (current_input_line[len-1] == '\n') |
|
1509 current_input_line.resize (len-1); |
1005
|
1510 |
4051
|
1511 // Print the line, maybe with a pointer near the error token. |
1005
|
1512 |
1755
|
1513 output_buf << ">>> " << current_input_line << "\n"; |
1060
|
1514 |
|
1515 if (err_col == 0) |
|
1516 err_col = len; |
|
1517 |
|
1518 for (int i = 0; i < err_col + 3; i++) |
|
1519 output_buf << " "; |
|
1520 |
|
1521 output_buf << "^"; |
1
|
1522 } |
1005
|
1523 |
4051
|
1524 output_buf << "\n" << OSSTREAM_ENDS; |
|
1525 |
|
1526 parse_error ("%s", OSSTREAM_C_STR (output_buf)); |
|
1527 |
|
1528 OSSTREAM_FREEZE (output_buf); |
1
|
1529 } |
|
1530 |
666
|
1531 // Error mesages for mismatched end tokens. |
|
1532 |
496
|
1533 static void |
2805
|
1534 end_error (const char *type, token::end_tok_type ettype, int l, int c) |
496
|
1535 { |
2805
|
1536 static const char *fmt |
|
1537 = "`%s' command matched by `%s' near line %d column %d"; |
496
|
1538 |
|
1539 switch (ettype) |
|
1540 { |
|
1541 case token::simple_end: |
|
1542 error (fmt, type, "end", l, c); |
|
1543 break; |
777
|
1544 |
496
|
1545 case token::for_end: |
|
1546 error (fmt, type, "endfor", l, c); |
|
1547 break; |
777
|
1548 |
496
|
1549 case token::function_end: |
|
1550 error (fmt, type, "endfunction", l, c); |
|
1551 break; |
777
|
1552 |
496
|
1553 case token::if_end: |
|
1554 error (fmt, type, "endif", l, c); |
|
1555 break; |
777
|
1556 |
3233
|
1557 case token::switch_end: |
|
1558 error (fmt, type, "endswitch", l, c); |
|
1559 break; |
|
1560 |
496
|
1561 case token::while_end: |
|
1562 error (fmt, type, "endwhile", l, c); |
|
1563 break; |
777
|
1564 |
1371
|
1565 case token::unwind_protect_end: |
|
1566 error (fmt, type, "end_unwind_protect", l, c); |
|
1567 break; |
|
1568 |
496
|
1569 default: |
|
1570 panic_impossible (); |
|
1571 break; |
|
1572 } |
|
1573 } |
|
1574 |
666
|
1575 // Check to see that end tokens are properly matched. |
|
1576 |
2857
|
1577 static bool |
|
1578 end_token_ok (token *tok, token::end_tok_type expected) |
143
|
1579 { |
2857
|
1580 bool retval = true; |
|
1581 |
143
|
1582 token::end_tok_type ettype = tok->ettype (); |
2857
|
1583 |
143
|
1584 if (ettype != expected && ettype != token::simple_end) |
|
1585 { |
2857
|
1586 retval = false; |
|
1587 |
143
|
1588 yyerror ("parse error"); |
|
1589 |
|
1590 int l = tok->line (); |
|
1591 int c = tok->column (); |
|
1592 |
|
1593 switch (expected) |
|
1594 { |
|
1595 case token::for_end: |
|
1596 end_error ("for", ettype, l, c); |
|
1597 break; |
777
|
1598 |
143
|
1599 case token::function_end: |
|
1600 end_error ("function", ettype, l, c); |
|
1601 break; |
777
|
1602 |
143
|
1603 case token::if_end: |
|
1604 end_error ("if", ettype, l, c); |
|
1605 break; |
777
|
1606 |
1489
|
1607 case token::try_catch_end: |
|
1608 end_error ("try", ettype, l, c); |
|
1609 break; |
|
1610 |
2764
|
1611 case token::switch_end: |
|
1612 end_error ("switch", ettype, l, c); |
|
1613 break; |
|
1614 |
1489
|
1615 case token::unwind_protect_end: |
|
1616 end_error ("unwind_protect", ettype, l, c); |
|
1617 break; |
|
1618 |
143
|
1619 case token::while_end: |
|
1620 end_error ("while", ettype, l, c); |
|
1621 break; |
777
|
1622 |
143
|
1623 default: |
|
1624 panic_impossible (); |
|
1625 break; |
|
1626 } |
|
1627 } |
2857
|
1628 |
|
1629 return retval; |
143
|
1630 } |
|
1631 |
666
|
1632 // Maybe print a warning if an assignment expression is used as the |
|
1633 // test in a logical expression. |
|
1634 |
496
|
1635 static void |
|
1636 maybe_warn_assign_as_truth_value (tree_expression *expr) |
1
|
1637 { |
2166
|
1638 if (Vwarn_assign_as_truth_value |
1
|
1639 && expr->is_assignment_expression () |
2961
|
1640 && expr->paren_count () < 2) |
1
|
1641 { |
|
1642 warning ("suggest parenthesis around assignment used as truth value"); |
|
1643 } |
|
1644 } |
578
|
1645 |
2764
|
1646 // Maybe print a warning about switch labels that aren't constants. |
|
1647 |
|
1648 static void |
|
1649 maybe_warn_variable_switch_label (tree_expression *expr) |
|
1650 { |
|
1651 if (Vwarn_variable_switch_label && ! expr->is_constant ()) |
|
1652 { |
|
1653 warning ("variable switch label"); |
|
1654 } |
|
1655 } |
|
1656 |
1623
|
1657 // Create a plot command. |
|
1658 |
|
1659 static tree_plot_command * |
|
1660 make_plot_command (token *tok, plot_limits *range, subplot_list *list) |
|
1661 { |
|
1662 if (range) |
|
1663 { |
|
1664 if (tok->pttype () == token::replot) |
|
1665 { |
|
1666 yyerror ("cannot specify new ranges with replot"); |
|
1667 return 0; |
|
1668 } |
|
1669 } |
|
1670 else if (! list && tok->pttype () != token::replot) |
|
1671 { |
|
1672 yyerror ("must have something to plot"); |
|
1673 return 0; |
|
1674 } |
|
1675 |
2857
|
1676 lexer_flags.plotting = false; |
|
1677 lexer_flags.past_plot_range = false; |
|
1678 lexer_flags.in_plot_range = false; |
|
1679 lexer_flags.in_plot_using = false; |
|
1680 lexer_flags.in_plot_style = false; |
1623
|
1681 |
|
1682 return new tree_plot_command (list, range, tok->pttype ()); |
|
1683 } |
|
1684 |
2533
|
1685 static tree_expression * |
|
1686 fold (tree_binary_expression *e) |
|
1687 { |
3110
|
1688 tree_expression *retval = e; |
|
1689 |
3292
|
1690 unwind_protect::begin_frame ("fold_binary_expression"); |
3110
|
1691 |
|
1692 unwind_protect_int (error_state); |
|
1693 |
3815
|
1694 unwind_protect_bool (discard_error_messages); |
|
1695 discard_error_messages = true; |
2533
|
1696 |
|
1697 tree_expression *op1 = e->lhs (); |
|
1698 tree_expression *op2 = e->rhs (); |
|
1699 |
|
1700 if (op1->is_constant () && op2->is_constant ()) |
|
1701 { |
2970
|
1702 octave_value tmp = e->rvalue (); |
2533
|
1703 |
3489
|
1704 if (! (error_state || warning_state)) |
2533
|
1705 { |
|
1706 tree_constant *tc_retval = new tree_constant (tmp); |
|
1707 |
4051
|
1708 OSSTREAM buf; |
2533
|
1709 |
|
1710 tree_print_code tpc (buf); |
|
1711 |
|
1712 e->accept (tpc); |
|
1713 |
4051
|
1714 buf << OSSTREAM_ENDS; |
|
1715 |
|
1716 tc_retval->stash_original_text (OSSTREAM_STR (buf)); |
|
1717 |
|
1718 OSSTREAM_FREEZE (buf); |
2533
|
1719 |
|
1720 delete e; |
|
1721 |
|
1722 retval = tc_retval; |
|
1723 } |
|
1724 } |
3110
|
1725 |
3292
|
1726 unwind_protect::run_frame ("fold_binary_expression"); |
|
1727 |
|
1728 return retval; |
|
1729 } |
|
1730 |
|
1731 static tree_expression * |
|
1732 fold (tree_unary_expression *e) |
|
1733 { |
|
1734 tree_expression *retval = e; |
|
1735 |
|
1736 unwind_protect::begin_frame ("fold_unary_expression"); |
|
1737 |
|
1738 unwind_protect_int (error_state); |
|
1739 |
3815
|
1740 unwind_protect_bool (discard_error_messages); |
|
1741 discard_error_messages = true; |
3292
|
1742 |
|
1743 tree_expression *op = e->operand (); |
|
1744 |
|
1745 if (op->is_constant ()) |
|
1746 { |
|
1747 octave_value tmp = e->rvalue (); |
|
1748 |
3489
|
1749 if (! (error_state || warning_state)) |
3292
|
1750 { |
|
1751 tree_constant *tc_retval = new tree_constant (tmp); |
|
1752 |
4051
|
1753 OSSTREAM buf; |
3292
|
1754 |
|
1755 tree_print_code tpc (buf); |
|
1756 |
|
1757 e->accept (tpc); |
|
1758 |
4051
|
1759 buf << OSSTREAM_ENDS; |
|
1760 |
|
1761 tc_retval->stash_original_text (OSSTREAM_STR (buf)); |
|
1762 |
|
1763 OSSTREAM_FREEZE (buf); |
3292
|
1764 |
|
1765 delete e; |
|
1766 |
|
1767 retval = tc_retval; |
|
1768 } |
|
1769 } |
|
1770 |
|
1771 unwind_protect::run_frame ("fold_unary_expression"); |
2533
|
1772 |
|
1773 return retval; |
|
1774 } |
|
1775 |
1623
|
1776 // Finish building a range. |
|
1777 |
|
1778 static tree_expression * |
|
1779 finish_colon_expression (tree_colon_expression *e) |
|
1780 { |
3110
|
1781 tree_expression *retval = e; |
|
1782 |
|
1783 unwind_protect::begin_frame ("finish_colon_expression"); |
|
1784 |
|
1785 unwind_protect_int (error_state); |
|
1786 |
3815
|
1787 unwind_protect_bool (discard_error_messages); |
|
1788 discard_error_messages = true; |
1623
|
1789 |
2533
|
1790 tree_expression *base = e->base (); |
|
1791 tree_expression *limit = e->limit (); |
|
1792 tree_expression *incr = e->increment (); |
|
1793 |
2970
|
1794 if (base) |
1623
|
1795 { |
2970
|
1796 if (limit) |
2533
|
1797 { |
2970
|
1798 if (base->is_constant () && limit->is_constant () |
|
1799 && (! incr || (incr && incr->is_constant ()))) |
|
1800 { |
|
1801 octave_value tmp = e->rvalue (); |
|
1802 |
3489
|
1803 if (! (error_state || warning_state)) |
2970
|
1804 { |
|
1805 tree_constant *tc_retval = new tree_constant (tmp); |
|
1806 |
4051
|
1807 OSSTREAM buf; |
2970
|
1808 |
|
1809 tree_print_code tpc (buf); |
|
1810 |
|
1811 e->accept (tpc); |
|
1812 |
4051
|
1813 buf << OSSTREAM_ENDS; |
|
1814 |
|
1815 tc_retval->stash_original_text (OSSTREAM_STR (buf)); |
|
1816 |
|
1817 OSSTREAM_FREEZE (buf); |
2970
|
1818 |
|
1819 delete e; |
|
1820 |
|
1821 retval = tc_retval; |
|
1822 } |
|
1823 } |
2533
|
1824 } |
|
1825 else |
2970
|
1826 { |
2990
|
1827 e->preserve_base (); |
|
1828 delete e; |
2970
|
1829 |
|
1830 // XXX FIXME XXX -- need to attempt constant folding here |
|
1831 // too (we need a generic way to do that). |
|
1832 retval = base; |
|
1833 } |
1623
|
1834 } |
|
1835 |
3110
|
1836 unwind_protect::run_frame ("finish_colon_expression"); |
|
1837 |
1623
|
1838 return retval; |
|
1839 } |
|
1840 |
1607
|
1841 // Make a constant. |
|
1842 |
2375
|
1843 static tree_constant * |
1607
|
1844 make_constant (int op, token *tok_val) |
|
1845 { |
|
1846 int l = tok_val->line (); |
|
1847 int c = tok_val->column (); |
|
1848 |
3216
|
1849 tree_constant *retval = 0; |
1607
|
1850 |
|
1851 switch (op) |
|
1852 { |
|
1853 case NUM: |
2533
|
1854 { |
2883
|
1855 octave_value tmp (tok_val->number ()); |
|
1856 retval = new tree_constant (tmp, l, c); |
2533
|
1857 retval->stash_original_text (tok_val->text_rep ()); |
|
1858 } |
1607
|
1859 break; |
|
1860 |
|
1861 case IMAG_NUM: |
|
1862 { |
2883
|
1863 octave_value tmp (Complex (0.0, tok_val->number ())); |
|
1864 retval = new tree_constant (tmp, l, c); |
1607
|
1865 retval->stash_original_text (tok_val->text_rep ()); |
|
1866 } |
|
1867 break; |
|
1868 |
4064
|
1869 case STRING: |
2883
|
1870 { |
|
1871 octave_value tmp (tok_val->text ()); |
|
1872 retval = new tree_constant (tmp, l, c); |
|
1873 } |
1607
|
1874 break; |
|
1875 |
|
1876 default: |
|
1877 panic_impossible (); |
|
1878 break; |
|
1879 } |
|
1880 |
|
1881 return retval; |
|
1882 } |
|
1883 |
666
|
1884 // Build a binary expression. |
|
1885 |
578
|
1886 static tree_expression * |
|
1887 make_binary_op (int op, tree_expression *op1, token *tok_val, |
|
1888 tree_expression *op2) |
|
1889 { |
2883
|
1890 octave_value::binary_op t = octave_value::unknown_binary_op; |
1623
|
1891 |
578
|
1892 switch (op) |
|
1893 { |
|
1894 case POW: |
3525
|
1895 t = octave_value::op_pow; |
578
|
1896 break; |
777
|
1897 |
578
|
1898 case EPOW: |
3525
|
1899 t = octave_value::op_el_pow; |
578
|
1900 break; |
777
|
1901 |
578
|
1902 case '+': |
3525
|
1903 t = octave_value::op_add; |
578
|
1904 break; |
777
|
1905 |
578
|
1906 case '-': |
3525
|
1907 t = octave_value::op_sub; |
578
|
1908 break; |
777
|
1909 |
578
|
1910 case '*': |
3525
|
1911 t = octave_value::op_mul; |
578
|
1912 break; |
777
|
1913 |
578
|
1914 case '/': |
3525
|
1915 t = octave_value::op_div; |
578
|
1916 break; |
777
|
1917 |
578
|
1918 case EMUL: |
3525
|
1919 t = octave_value::op_el_mul; |
578
|
1920 break; |
777
|
1921 |
578
|
1922 case EDIV: |
3525
|
1923 t = octave_value::op_el_div; |
578
|
1924 break; |
777
|
1925 |
578
|
1926 case LEFTDIV: |
3525
|
1927 t = octave_value::op_ldiv; |
578
|
1928 break; |
777
|
1929 |
578
|
1930 case ELEFTDIV: |
3525
|
1931 t = octave_value::op_el_ldiv; |
578
|
1932 break; |
777
|
1933 |
2899
|
1934 case LSHIFT: |
3525
|
1935 t = octave_value::op_lshift; |
2899
|
1936 break; |
|
1937 |
|
1938 case RSHIFT: |
3525
|
1939 t = octave_value::op_rshift; |
2899
|
1940 break; |
|
1941 |
578
|
1942 case EXPR_LT: |
3525
|
1943 t = octave_value::op_lt; |
578
|
1944 break; |
777
|
1945 |
578
|
1946 case EXPR_LE: |
3525
|
1947 t = octave_value::op_le; |
578
|
1948 break; |
777
|
1949 |
578
|
1950 case EXPR_EQ: |
3525
|
1951 t = octave_value::op_eq; |
578
|
1952 break; |
777
|
1953 |
578
|
1954 case EXPR_GE: |
3525
|
1955 t = octave_value::op_ge; |
578
|
1956 break; |
777
|
1957 |
578
|
1958 case EXPR_GT: |
3525
|
1959 t = octave_value::op_gt; |
578
|
1960 break; |
777
|
1961 |
578
|
1962 case EXPR_NE: |
3525
|
1963 t = octave_value::op_ne; |
578
|
1964 break; |
777
|
1965 |
578
|
1966 case EXPR_AND: |
3525
|
1967 t = octave_value::op_el_and; |
578
|
1968 break; |
777
|
1969 |
578
|
1970 case EXPR_OR: |
3525
|
1971 t = octave_value::op_el_or; |
4023
|
1972 if (Vwarn_precedence_change |
4024
|
1973 && op2->paren_count () == 0 && op2->is_binary_expression ()) |
4023
|
1974 { |
|
1975 tree_binary_expression *e |
|
1976 = dynamic_cast<tree_binary_expression *> (op2); |
|
1977 |
|
1978 if (e->op_type () == octave_value::op_el_and) |
|
1979 warning ("meaning may have changed due to change in precedence for & and | operators"); |
|
1980 } |
578
|
1981 break; |
777
|
1982 |
578
|
1983 default: |
|
1984 panic_impossible (); |
|
1985 break; |
|
1986 } |
|
1987 |
|
1988 int l = tok_val->line (); |
|
1989 int c = tok_val->column (); |
|
1990 |
2533
|
1991 tree_binary_expression *e |
|
1992 = new tree_binary_expression (op1, op2, l, c, t); |
1623
|
1993 |
2533
|
1994 return fold (e); |
578
|
1995 } |
|
1996 |
2375
|
1997 // Build a boolean expression. |
666
|
1998 |
578
|
1999 static tree_expression * |
2375
|
2000 make_boolean_op (int op, tree_expression *op1, token *tok_val, |
|
2001 tree_expression *op2) |
578
|
2002 { |
2375
|
2003 tree_boolean_expression::type t; |
|
2004 |
578
|
2005 switch (op) |
|
2006 { |
2375
|
2007 case EXPR_AND_AND: |
2805
|
2008 t = tree_boolean_expression::bool_and; |
578
|
2009 break; |
777
|
2010 |
2375
|
2011 case EXPR_OR_OR: |
2805
|
2012 t = tree_boolean_expression::bool_or; |
4023
|
2013 if (Vwarn_precedence_change |
4024
|
2014 && op2->paren_count () == 0 && op2->is_boolean_expression ()) |
4023
|
2015 { |
|
2016 tree_boolean_expression *e |
|
2017 = dynamic_cast<tree_boolean_expression *> (op2); |
|
2018 |
|
2019 if (e->op_type () == tree_boolean_expression::bool_and) |
|
2020 warning ("meaning may have changed due to change in precedence for && and || operators"); |
|
2021 } |
578
|
2022 break; |
777
|
2023 |
578
|
2024 default: |
|
2025 panic_impossible (); |
|
2026 break; |
|
2027 } |
|
2028 |
|
2029 int l = tok_val->line (); |
|
2030 int c = tok_val->column (); |
|
2031 |
2533
|
2032 tree_boolean_expression *e |
|
2033 = new tree_boolean_expression (op1, op2, l, c, t); |
2375
|
2034 |
2533
|
2035 return fold (e); |
578
|
2036 } |
|
2037 |
2375
|
2038 // Build a prefix expression. |
666
|
2039 |
578
|
2040 static tree_expression * |
2960
|
2041 make_prefix_op (int op, tree_expression *op1, token *tok_val) |
578
|
2042 { |
3203
|
2043 octave_value::unary_op t = octave_value::unknown_unary_op; |
2375
|
2044 |
578
|
2045 switch (op) |
|
2046 { |
2960
|
2047 case EXPR_NOT: |
3525
|
2048 t = octave_value::op_not; |
2960
|
2049 break; |
|
2050 |
|
2051 case '-': |
3525
|
2052 t = octave_value::op_uminus; |
2960
|
2053 break; |
|
2054 |
578
|
2055 case PLUS_PLUS: |
3525
|
2056 t = octave_value::op_incr; |
578
|
2057 break; |
777
|
2058 |
578
|
2059 case MINUS_MINUS: |
3525
|
2060 t = octave_value::op_decr; |
578
|
2061 break; |
777
|
2062 |
578
|
2063 default: |
|
2064 panic_impossible (); |
|
2065 break; |
|
2066 } |
|
2067 |
|
2068 int l = tok_val->line (); |
|
2069 int c = tok_val->column (); |
|
2070 |
3292
|
2071 tree_prefix_expression *e |
|
2072 = new tree_prefix_expression (op1, l, c, t); |
|
2073 |
|
2074 return fold (e); |
578
|
2075 } |
|
2076 |
2375
|
2077 // Build a postfix expression. |
666
|
2078 |
578
|
2079 static tree_expression * |
2960
|
2080 make_postfix_op (int op, tree_expression *op1, token *tok_val) |
578
|
2081 { |
3203
|
2082 octave_value::unary_op t = octave_value::unknown_unary_op; |
1623
|
2083 |
578
|
2084 switch (op) |
|
2085 { |
2960
|
2086 case QUOTE: |
3525
|
2087 t = octave_value::op_hermitian; |
2960
|
2088 break; |
|
2089 |
|
2090 case TRANSPOSE: |
3525
|
2091 t = octave_value::op_transpose; |
2960
|
2092 break; |
|
2093 |
2375
|
2094 case PLUS_PLUS: |
3525
|
2095 t = octave_value::op_incr; |
578
|
2096 break; |
777
|
2097 |
2375
|
2098 case MINUS_MINUS: |
3525
|
2099 t = octave_value::op_decr; |
578
|
2100 break; |
777
|
2101 |
578
|
2102 default: |
|
2103 panic_impossible (); |
|
2104 break; |
|
2105 } |
|
2106 |
|
2107 int l = tok_val->line (); |
|
2108 int c = tok_val->column (); |
|
2109 |
3292
|
2110 tree_postfix_expression *e |
|
2111 = new tree_postfix_expression (op1, l, c, t); |
|
2112 |
|
2113 return fold (e); |
1623
|
2114 } |
|
2115 |
|
2116 // Build an unwind-protect command. |
|
2117 |
|
2118 static tree_command * |
|
2119 make_unwind_command (token *unwind_tok, tree_statement_list *body, |
3665
|
2120 tree_statement_list *cleanup, token *end_tok, |
|
2121 octave_comment_list *lc, octave_comment_list *mc) |
1623
|
2122 { |
|
2123 tree_command *retval = 0; |
|
2124 |
2857
|
2125 if (end_token_ok (end_tok, token::unwind_protect_end)) |
1623
|
2126 { |
3665
|
2127 octave_comment_list *tc = octave_comment_buffer::get_comment (); |
|
2128 |
1623
|
2129 int l = unwind_tok->line (); |
|
2130 int c = unwind_tok->column (); |
|
2131 |
3665
|
2132 retval = new tree_unwind_protect_command (body, cleanup, |
|
2133 lc, mc, tc, l, c); |
1623
|
2134 } |
|
2135 |
|
2136 return retval; |
|
2137 } |
|
2138 |
|
2139 // Build a try-catch command. |
|
2140 |
|
2141 static tree_command * |
|
2142 make_try_command (token *try_tok, tree_statement_list *body, |
3665
|
2143 tree_statement_list *cleanup, token *end_tok, |
|
2144 octave_comment_list *lc, octave_comment_list *mc) |
1623
|
2145 { |
|
2146 tree_command *retval = 0; |
|
2147 |
2857
|
2148 if (end_token_ok (end_tok, token::try_catch_end)) |
1623
|
2149 { |
3665
|
2150 octave_comment_list *tc = octave_comment_buffer::get_comment (); |
|
2151 |
1623
|
2152 int l = try_tok->line (); |
|
2153 int c = try_tok->column (); |
|
2154 |
3665
|
2155 retval = new tree_try_catch_command (body, cleanup, |
|
2156 lc, mc, tc, l, c); |
1623
|
2157 } |
|
2158 |
|
2159 return retval; |
|
2160 } |
|
2161 |
|
2162 // Build a while command. |
|
2163 |
|
2164 static tree_command * |
|
2165 make_while_command (token *while_tok, tree_expression *expr, |
3665
|
2166 tree_statement_list *body, token *end_tok, |
|
2167 octave_comment_list *lc) |
1623
|
2168 { |
|
2169 tree_command *retval = 0; |
|
2170 |
|
2171 maybe_warn_assign_as_truth_value (expr); |
|
2172 |
2857
|
2173 if (end_token_ok (end_tok, token::while_end)) |
1623
|
2174 { |
3665
|
2175 octave_comment_list *tc = octave_comment_buffer::get_comment (); |
|
2176 |
1826
|
2177 lexer_flags.looping--; |
1623
|
2178 |
|
2179 int l = while_tok->line (); |
|
2180 int c = while_tok->column (); |
|
2181 |
3665
|
2182 retval = new tree_while_command (expr, body, lc, tc, l, c); |
1623
|
2183 } |
|
2184 |
|
2185 return retval; |
|
2186 } |
|
2187 |
3484
|
2188 // Build a do-until command. |
|
2189 |
|
2190 static tree_command * |
|
2191 make_do_until_command (token *do_tok, tree_statement_list *body, |
3665
|
2192 tree_expression *expr, octave_comment_list *lc) |
3484
|
2193 { |
|
2194 tree_command *retval = 0; |
|
2195 |
|
2196 maybe_warn_assign_as_truth_value (expr); |
|
2197 |
3665
|
2198 octave_comment_list *tc = octave_comment_buffer::get_comment (); |
|
2199 |
3484
|
2200 lexer_flags.looping--; |
|
2201 |
|
2202 int l = do_tok->line (); |
|
2203 int c = do_tok->column (); |
|
2204 |
3665
|
2205 retval = new tree_do_until_command (expr, body, lc, tc, l, c); |
3484
|
2206 |
|
2207 return retval; |
|
2208 } |
|
2209 |
1623
|
2210 // Build a for command. |
|
2211 |
|
2212 static tree_command * |
2970
|
2213 make_for_command (token *for_tok, tree_argument_list *lhs, |
1623
|
2214 tree_expression *expr, tree_statement_list *body, |
3665
|
2215 token *end_tok, octave_comment_list *lc) |
1623
|
2216 { |
|
2217 tree_command *retval = 0; |
|
2218 |
2857
|
2219 if (end_token_ok (end_tok, token::for_end)) |
1623
|
2220 { |
3665
|
2221 octave_comment_list *tc = octave_comment_buffer::get_comment (); |
|
2222 |
1826
|
2223 lexer_flags.looping--; |
1623
|
2224 |
|
2225 int l = for_tok->line (); |
|
2226 int c = for_tok->column (); |
|
2227 |
2970
|
2228 if (lhs->length () == 1) |
|
2229 { |
|
2230 tree_expression *tmp = lhs->remove_front (); |
|
2231 |
3665
|
2232 retval = new tree_simple_for_command (tmp, expr, body, |
|
2233 lc, tc, l, c); |
2970
|
2234 |
|
2235 delete lhs; |
|
2236 } |
|
2237 else |
3665
|
2238 retval = new tree_complex_for_command (lhs, expr, body, |
|
2239 lc, tc, l, c); |
1623
|
2240 } |
|
2241 |
|
2242 return retval; |
|
2243 } |
|
2244 |
|
2245 // Build a break command. |
|
2246 |
|
2247 static tree_command * |
|
2248 make_break_command (token *break_tok) |
|
2249 { |
|
2250 tree_command *retval = 0; |
|
2251 |
2620
|
2252 int l = break_tok->line (); |
|
2253 int c = break_tok->column (); |
|
2254 |
3489
|
2255 if (lexer_flags.looping || lexer_flags.defining_func |
3877
|
2256 || reading_script_file || evaluating_function_body |
|
2257 || evaluating_looping_command) |
2620
|
2258 retval = new tree_break_command (l, c); |
1623
|
2259 else |
2620
|
2260 retval = new tree_no_op_command ("break", l, c); |
1623
|
2261 |
|
2262 return retval; |
|
2263 } |
|
2264 |
|
2265 // Build a continue command. |
|
2266 |
|
2267 static tree_command * |
|
2268 make_continue_command (token *continue_tok) |
|
2269 { |
|
2270 tree_command *retval = 0; |
|
2271 |
2620
|
2272 int l = continue_tok->line (); |
|
2273 int c = continue_tok->column (); |
|
2274 |
3877
|
2275 if (lexer_flags.looping || evaluating_looping_command) |
2620
|
2276 retval = new tree_continue_command (l, c); |
1623
|
2277 else |
2620
|
2278 retval = new tree_no_op_command ("continue", l, c); |
1623
|
2279 |
|
2280 return retval; |
|
2281 } |
|
2282 |
|
2283 // Build a return command. |
|
2284 |
|
2285 static tree_command * |
|
2286 make_return_command (token *return_tok) |
|
2287 { |
|
2288 tree_command *retval = 0; |
|
2289 |
2620
|
2290 int l = return_tok->line (); |
|
2291 int c = return_tok->column (); |
|
2292 |
3489
|
2293 if (lexer_flags.defining_func || reading_script_file |
|
2294 || evaluating_function_body) |
2620
|
2295 retval = new tree_return_command (l, c); |
1623
|
2296 else |
2620
|
2297 retval = new tree_no_op_command ("return", l, c); |
1623
|
2298 |
|
2299 return retval; |
|
2300 } |
|
2301 |
|
2302 // Start an if command. |
|
2303 |
|
2304 static tree_if_command_list * |
|
2305 start_if_command (tree_expression *expr, tree_statement_list *list) |
|
2306 { |
|
2307 maybe_warn_assign_as_truth_value (expr); |
|
2308 |
|
2309 tree_if_clause *t = new tree_if_clause (expr, list); |
|
2310 |
|
2311 return new tree_if_command_list (t); |
|
2312 } |
|
2313 |
|
2314 // Finish an if command. |
|
2315 |
|
2316 static tree_if_command * |
|
2317 finish_if_command (token *if_tok, tree_if_command_list *list, |
3665
|
2318 token *end_tok, octave_comment_list *lc) |
1623
|
2319 { |
|
2320 tree_if_command *retval = 0; |
|
2321 |
2857
|
2322 if (end_token_ok (end_tok, token::if_end)) |
1623
|
2323 { |
3665
|
2324 octave_comment_list *tc = octave_comment_buffer::get_comment (); |
|
2325 |
1623
|
2326 int l = if_tok->line (); |
|
2327 int c = if_tok->column (); |
|
2328 |
3665
|
2329 retval = new tree_if_command (list, lc, tc, l, c); |
1623
|
2330 } |
|
2331 |
|
2332 return retval; |
|
2333 } |
|
2334 |
|
2335 // Build an elseif clause. |
|
2336 |
|
2337 static tree_if_clause * |
3665
|
2338 make_elseif_clause (tree_expression *expr, tree_statement_list *list, |
|
2339 octave_comment_list *lc) |
1623
|
2340 { |
|
2341 maybe_warn_assign_as_truth_value (expr); |
|
2342 |
3665
|
2343 return new tree_if_clause (expr, list, lc); |
1623
|
2344 } |
|
2345 |
2764
|
2346 // Finish a switch command. |
|
2347 |
|
2348 static tree_switch_command * |
|
2349 finish_switch_command (token *switch_tok, tree_expression *expr, |
3665
|
2350 tree_switch_case_list *list, token *end_tok, |
|
2351 octave_comment_list *lc) |
2764
|
2352 { |
|
2353 tree_switch_command *retval = 0; |
|
2354 |
2857
|
2355 if (end_token_ok (end_tok, token::switch_end)) |
2764
|
2356 { |
3665
|
2357 octave_comment_list *tc = octave_comment_buffer::get_comment (); |
|
2358 |
2764
|
2359 int l = switch_tok->line (); |
|
2360 int c = switch_tok->column (); |
|
2361 |
3665
|
2362 retval = new tree_switch_command (expr, list, lc, tc, l, c); |
2764
|
2363 } |
|
2364 |
|
2365 return retval; |
|
2366 } |
|
2367 |
|
2368 // Build a switch case. |
|
2369 |
|
2370 static tree_switch_case * |
3665
|
2371 make_switch_case (tree_expression *expr, tree_statement_list *list, |
|
2372 octave_comment_list *lc) |
2764
|
2373 { |
|
2374 maybe_warn_variable_switch_label (expr); |
|
2375 |
3665
|
2376 return new tree_switch_case (expr, list, lc); |
2764
|
2377 } |
|
2378 |
1623
|
2379 // Build an assignment to a variable. |
|
2380 |
|
2381 static tree_expression * |
2970
|
2382 make_assign_op (int op, tree_argument_list *lhs, token *eq_tok, |
|
2383 tree_expression *rhs) |
1623
|
2384 { |
2970
|
2385 tree_expression *retval = 0; |
|
2386 |
2883
|
2387 octave_value::assign_op t = octave_value::unknown_assign_op; |
|
2388 |
|
2389 switch (op) |
|
2390 { |
|
2391 case '=': |
3525
|
2392 t = octave_value::op_asn_eq; |
2883
|
2393 break; |
|
2394 |
|
2395 case ADD_EQ: |
3525
|
2396 t = octave_value::op_add_eq; |
2883
|
2397 break; |
|
2398 |
|
2399 case SUB_EQ: |
3525
|
2400 t = octave_value::op_sub_eq; |
2883
|
2401 break; |
|
2402 |
|
2403 case MUL_EQ: |
3525
|
2404 t = octave_value::op_mul_eq; |
2883
|
2405 break; |
|
2406 |
|
2407 case DIV_EQ: |
3525
|
2408 t = octave_value::op_div_eq; |
2883
|
2409 break; |
|
2410 |
3204
|
2411 case LEFTDIV_EQ: |
3525
|
2412 t = octave_value::op_ldiv_eq; |
3204
|
2413 break; |
|
2414 |
4018
|
2415 case POW_EQ: |
|
2416 t = octave_value::op_pow_eq; |
|
2417 break; |
|
2418 |
2899
|
2419 case LSHIFT_EQ: |
3525
|
2420 t = octave_value::op_lshift_eq; |
2899
|
2421 break; |
|
2422 |
|
2423 case RSHIFT_EQ: |
3525
|
2424 t = octave_value::op_rshift_eq; |
2899
|
2425 break; |
|
2426 |
2883
|
2427 case EMUL_EQ: |
3525
|
2428 t = octave_value::op_el_mul_eq; |
2883
|
2429 break; |
|
2430 |
|
2431 case EDIV_EQ: |
3525
|
2432 t = octave_value::op_el_div_eq; |
2883
|
2433 break; |
|
2434 |
3204
|
2435 case ELEFTDIV_EQ: |
3525
|
2436 t = octave_value::op_el_ldiv_eq; |
3204
|
2437 break; |
|
2438 |
4018
|
2439 case EPOW_EQ: |
|
2440 t = octave_value::op_el_pow_eq; |
|
2441 break; |
|
2442 |
2883
|
2443 case AND_EQ: |
3525
|
2444 t = octave_value::op_el_and_eq; |
2883
|
2445 break; |
|
2446 |
|
2447 case OR_EQ: |
3525
|
2448 t = octave_value::op_el_or_eq; |
2883
|
2449 break; |
|
2450 |
|
2451 default: |
|
2452 panic_impossible (); |
|
2453 break; |
|
2454 } |
|
2455 |
1623
|
2456 int l = eq_tok->line (); |
|
2457 int c = eq_tok->column (); |
|
2458 |
2970
|
2459 if (lhs->length () == 1) |
666
|
2460 { |
2970
|
2461 tree_expression *tmp = lhs->remove_front (); |
|
2462 |
|
2463 retval = new tree_simple_assignment (tmp, rhs, false, l, c, t); |
|
2464 |
|
2465 delete lhs; |
666
|
2466 } |
|
2467 else |
3208
|
2468 return new tree_multi_assignment (lhs, rhs, false, l, c, t); |
666
|
2469 |
|
2470 return retval; |
|
2471 } |
751
|
2472 |
1623
|
2473 // Begin defining a function. |
|
2474 |
2891
|
2475 static octave_user_function * |
|
2476 start_function (tree_parameter_list *param_list, tree_statement_list *body) |
1623
|
2477 { |
|
2478 body->mark_as_function_body (); |
|
2479 |
2891
|
2480 // We'll fill in the return list later. |
|
2481 |
|
2482 octave_user_function *fcn |
|
2483 = new octave_user_function (param_list, 0, body, curr_sym_tab); |
1623
|
2484 |
3665
|
2485 if (fcn) |
|
2486 { |
|
2487 octave_comment_list *tc = octave_comment_buffer::get_comment (); |
|
2488 |
|
2489 fcn->stash_trailing_comment (tc); |
|
2490 } |
|
2491 |
1623
|
2492 return fcn; |
|
2493 } |
|
2494 |
|
2495 // Do most of the work for defining a function. |
|
2496 |
2891
|
2497 static octave_user_function * |
|
2498 frob_function (tree_identifier *id, octave_user_function *fcn) |
1623
|
2499 { |
3523
|
2500 std::string id_name = id->name (); |
1623
|
2501 |
|
2502 // If input is coming from a file, issue a warning if the name of |
|
2503 // the file does not match the name of the function stated in the |
|
2504 // file. Matlab doesn't provide a diagnostic (it ignores the stated |
|
2505 // name). |
|
2506 |
|
2507 fcn->stash_function_name (id_name); |
|
2508 |
|
2509 if (reading_fcn_file) |
|
2510 { |
1755
|
2511 if (curr_fcn_file_name != id_name) |
1623
|
2512 { |
2166
|
2513 if (Vwarn_function_name_clash) |
1623
|
2514 warning ("function name `%s' does not agree with function\ |
1755
|
2515 file name `%s'", id_name.c_str (), curr_fcn_file_full_name.c_str ()); |
1623
|
2516 |
4009
|
2517 fbi_sym_tab->rename (id_name, curr_fcn_file_name); |
1623
|
2518 |
|
2519 if (error_state) |
|
2520 return 0; |
|
2521 |
|
2522 id_name = id->name (); |
|
2523 } |
|
2524 |
3712
|
2525 octave_time now; |
3162
|
2526 |
1623
|
2527 fcn->stash_function_name (id_name); |
|
2528 fcn->stash_fcn_file_name (); |
3162
|
2529 fcn->stash_fcn_file_time (now); |
1623
|
2530 fcn->mark_as_system_fcn_file (); |
3162
|
2531 |
|
2532 if (Vwarn_future_time_stamp) |
|
2533 { |
3523
|
2534 std::string nm = fcn->fcn_file_name (); |
3162
|
2535 |
|
2536 file_stat fs (nm); |
|
2537 |
|
2538 if (fs && fs.is_newer (now)) |
|
2539 warning ("time stamp for `%s' is in the future", nm.c_str ()); |
|
2540 } |
1623
|
2541 } |
|
2542 else if (! (input_from_tmp_history_file || input_from_startup_file) |
|
2543 && reading_script_file |
1755
|
2544 && curr_fcn_file_name == id_name) |
1623
|
2545 { |
|
2546 warning ("function `%s' defined within script file `%s'", |
1755
|
2547 id_name.c_str (), curr_fcn_file_full_name.c_str ()); |
1623
|
2548 } |
|
2549 |
|
2550 top_level_sym_tab->clear (id_name); |
|
2551 |
4009
|
2552 symbol_record *sr = fbi_sym_tab->lookup (id_name); |
2791
|
2553 |
|
2554 if (sr) |
|
2555 fcn->stash_symtab_ptr (sr); |
|
2556 else |
|
2557 panic_impossible (); |
|
2558 |
3016
|
2559 id->define (fcn, symbol_record::USER_FUNCTION); |
1755
|
2560 |
1623
|
2561 id->document (help_buf); |
|
2562 |
3844
|
2563 help_buf.resize (0); |
|
2564 |
1623
|
2565 return fcn; |
|
2566 } |
|
2567 |
|
2568 // Finish defining a function. |
|
2569 |
2891
|
2570 static octave_user_function * |
3665
|
2571 finish_function (tree_identifier *id, octave_user_function *fcn, |
|
2572 octave_comment_list *lc) |
1623
|
2573 { |
2883
|
2574 tree_parameter_list *tpl = new tree_parameter_list (id); |
1623
|
2575 |
|
2576 tpl->mark_as_formal_parameters (); |
|
2577 |
3665
|
2578 fcn->stash_leading_comment (lc); |
|
2579 |
1623
|
2580 return fcn->define_ret_list (tpl); |
|
2581 } |
|
2582 |
|
2583 // Finish defining a function a different way. |
|
2584 |
2891
|
2585 static octave_user_function * |
3665
|
2586 finish_function (tree_parameter_list *ret_list, |
|
2587 octave_user_function *fcn, octave_comment_list *lc) |
1623
|
2588 { |
|
2589 ret_list->mark_as_formal_parameters (); |
|
2590 |
3665
|
2591 fcn->stash_leading_comment (lc); |
|
2592 |
1623
|
2593 return fcn->define_ret_list (ret_list); |
|
2594 } |
|
2595 |
2883
|
2596 static void |
|
2597 recover_from_parsing_function (void) |
|
2598 { |
3903
|
2599 if (! symtab_context) |
|
2600 panic_impossible (); |
|
2601 |
|
2602 curr_sym_tab = symtab_context; |
|
2603 symtab_context = 0; |
2883
|
2604 |
|
2605 lexer_flags.defining_func = false; |
|
2606 lexer_flags.beginning_of_function = false; |
|
2607 lexer_flags.parsed_function_name = false; |
|
2608 lexer_flags.looking_at_return_list = false; |
|
2609 lexer_flags.looking_at_parameter_list = false; |
|
2610 } |
|
2611 |
2846
|
2612 // Make an index expression. |
|
2613 |
751
|
2614 static tree_index_expression * |
3929
|
2615 make_index_expression (tree_expression *expr, tree_argument_list *args, |
3933
|
2616 char type) |
751
|
2617 { |
|
2618 tree_index_expression *retval = 0; |
|
2619 |
2970
|
2620 int l = expr->line (); |
|
2621 int c = expr->column (); |
|
2622 |
|
2623 expr->mark_postfix_indexed (); |
|
2624 |
3933
|
2625 if (expr->is_index_expression ()) |
|
2626 { |
|
2627 tree_index_expression *tmp = static_cast<tree_index_expression *> (expr); |
|
2628 |
|
2629 tmp->append (args, type); |
|
2630 |
|
2631 retval = tmp; |
|
2632 } |
|
2633 else |
|
2634 retval = new tree_index_expression (expr, args, l, c, type); |
2970
|
2635 |
|
2636 return retval; |
|
2637 } |
|
2638 |
|
2639 // Make an indirect reference expression. |
|
2640 |
3930
|
2641 static tree_index_expression * |
3523
|
2642 make_indirect_ref (tree_expression *expr, const std::string& elt) |
2970
|
2643 { |
3930
|
2644 tree_index_expression *retval = 0; |
2970
|
2645 |
|
2646 int l = expr->line (); |
|
2647 int c = expr->column (); |
|
2648 |
3933
|
2649 if (expr->is_index_expression ()) |
|
2650 { |
|
2651 tree_index_expression *tmp = static_cast<tree_index_expression *> (expr); |
|
2652 |
|
2653 tmp->append (elt); |
|
2654 |
|
2655 retval = tmp; |
|
2656 } |
|
2657 else |
|
2658 retval = new tree_index_expression (expr, elt, l, c); |
2970
|
2659 |
|
2660 lexer_flags.looking_at_indirect_ref = false; |
751
|
2661 |
|
2662 return retval; |
|
2663 } |
1511
|
2664 |
4131
|
2665 // Make an indirect reference expression with dynamic field name. |
|
2666 |
|
2667 static tree_index_expression * |
|
2668 make_indirect_ref (tree_expression *expr, tree_expression *elt) |
|
2669 { |
|
2670 tree_index_expression *retval = 0; |
|
2671 |
|
2672 int l = expr->line (); |
|
2673 int c = expr->column (); |
|
2674 |
|
2675 if (expr->is_index_expression ()) |
|
2676 { |
|
2677 tree_index_expression *tmp = static_cast<tree_index_expression *> (expr); |
|
2678 |
|
2679 tmp->append (elt); |
|
2680 |
|
2681 retval = tmp; |
|
2682 } |
|
2683 else |
|
2684 retval = new tree_index_expression (expr, elt, l, c); |
|
2685 |
|
2686 lexer_flags.looking_at_indirect_ref = false; |
|
2687 |
|
2688 return retval; |
|
2689 } |
|
2690 |
2846
|
2691 // Make a declaration command. |
|
2692 |
|
2693 static tree_decl_command * |
|
2694 make_decl_command (int tok, token *tok_val, tree_decl_init_list *lst) |
|
2695 { |
|
2696 tree_decl_command *retval = 0; |
|
2697 |
|
2698 int l = tok_val->line (); |
|
2699 int c = tok_val->column (); |
|
2700 |
|
2701 switch (tok) |
|
2702 { |
|
2703 case GLOBAL: |
|
2704 retval = new tree_global_command (lst, l, c); |
|
2705 break; |
|
2706 |
|
2707 case STATIC: |
|
2708 if (lexer_flags.defining_func) |
|
2709 retval = new tree_static_command (lst, l, c); |
|
2710 else |
|
2711 { |
|
2712 if (reading_script_file) |
|
2713 warning ("ignoring static declaration near line %d of file `%s'", |
|
2714 l, curr_fcn_file_full_name.c_str ()); |
|
2715 else |
|
2716 warning ("ignoring static declaration near line %d", l); |
|
2717 } |
|
2718 break; |
|
2719 |
|
2720 default: |
|
2721 panic_impossible (); |
|
2722 break; |
|
2723 } |
|
2724 |
|
2725 return retval; |
|
2726 } |
|
2727 |
1623
|
2728 // Finish building a matrix list. |
|
2729 |
|
2730 static tree_expression * |
1829
|
2731 finish_matrix (tree_matrix *m) |
1623
|
2732 { |
3110
|
2733 tree_expression *retval = m; |
|
2734 |
|
2735 unwind_protect::begin_frame ("finish_matrix"); |
|
2736 |
|
2737 unwind_protect_int (error_state); |
|
2738 |
3815
|
2739 unwind_protect_bool (discard_error_messages); |
|
2740 discard_error_messages = true; |
1623
|
2741 |
2533
|
2742 if (m->all_elements_are_constant ()) |
1829
|
2743 { |
2970
|
2744 octave_value tmp = m->rvalue (); |
1623
|
2745 |
3489
|
2746 if (! (error_state || warning_state)) |
2533
|
2747 { |
|
2748 tree_constant *tc_retval = new tree_constant (tmp); |
|
2749 |
4051
|
2750 OSSTREAM buf; |
2533
|
2751 |
|
2752 tree_print_code tpc (buf); |
|
2753 |
|
2754 m->accept (tpc); |
|
2755 |
4051
|
2756 buf << OSSTREAM_ENDS; |
|
2757 |
|
2758 tc_retval->stash_original_text (OSSTREAM_STR (buf)); |
|
2759 |
|
2760 OSSTREAM_FREEZE (buf); |
2533
|
2761 |
|
2762 delete m; |
|
2763 |
|
2764 retval = tc_retval; |
|
2765 } |
1623
|
2766 } |
3110
|
2767 |
|
2768 unwind_protect::run_frame ("finish_matrix"); |
1623
|
2769 |
|
2770 return retval; |
|
2771 } |
|
2772 |
3351
|
2773 // Finish building a cell list. |
|
2774 |
|
2775 static tree_expression * |
|
2776 finish_cell (tree_cell *c) |
|
2777 { |
|
2778 // For now, this doesn't do anything. |
|
2779 |
|
2780 return c; |
|
2781 } |
|
2782 |
1511
|
2783 static void |
|
2784 maybe_warn_missing_semi (tree_statement_list *t) |
|
2785 { |
2166
|
2786 if (lexer_flags.defining_func && Vwarn_missing_semicolon) |
1511
|
2787 { |
|
2788 tree_statement *tmp = t->rear(); |
1607
|
2789 |
1511
|
2790 if (tmp->is_expression ()) |
1607
|
2791 warning ("missing semicolon near line %d, column %d in file `%s'", |
1755
|
2792 tmp->line (), tmp->column (), |
|
2793 curr_fcn_file_full_name.c_str ()); |
1511
|
2794 } |
|
2795 } |
1994
|
2796 |
2525
|
2797 static void |
|
2798 set_stmt_print_flag (tree_statement_list *list, char sep, |
|
2799 bool warn_missing_semi) |
|
2800 { |
|
2801 switch (sep) |
|
2802 { |
|
2803 case ';': |
|
2804 { |
|
2805 tree_statement *tmp = list->rear (); |
|
2806 tmp->set_print_flag (0); |
|
2807 } |
|
2808 break; |
|
2809 |
|
2810 case 0: |
|
2811 case ',': |
|
2812 case '\n': |
|
2813 if (warn_missing_semi) |
|
2814 maybe_warn_missing_semi (list); |
|
2815 break; |
|
2816 |
|
2817 default: |
|
2818 warning ("unrecognized separator type!"); |
|
2819 break; |
|
2820 } |
|
2821 } |
|
2822 |
3021
|
2823 void |
|
2824 parse_and_execute (FILE *f) |
|
2825 { |
|
2826 unwind_protect::begin_frame ("parse_and_execute"); |
3880
|
2827 |
3021
|
2828 YY_BUFFER_STATE old_buf = current_buffer (); |
|
2829 YY_BUFFER_STATE new_buf = create_buffer (f); |
|
2830 |
|
2831 unwind_protect::add (restore_input_buffer, old_buf); |
|
2832 unwind_protect::add (delete_input_buffer, new_buf); |
|
2833 |
|
2834 switch_to_buffer (new_buf); |
|
2835 |
|
2836 unwind_protect_bool (line_editing); |
|
2837 unwind_protect_bool (input_from_command_line_file); |
3880
|
2838 unwind_protect_bool (get_input_from_eval_string); |
3883
|
2839 unwind_protect_bool (parser_end_of_input); |
3021
|
2840 |
|
2841 line_editing = false; |
|
2842 input_from_command_line_file = false; |
3880
|
2843 get_input_from_eval_string = false; |
3883
|
2844 parser_end_of_input = false; |
3021
|
2845 |
|
2846 unwind_protect_ptr (curr_sym_tab); |
|
2847 |
|
2848 int retval; |
|
2849 do |
|
2850 { |
|
2851 reset_parser (); |
|
2852 |
|
2853 retval = yyparse (); |
|
2854 |
3883
|
2855 if (retval == 0) |
|
2856 { |
|
2857 if (global_command) |
3021
|
2858 { |
3883
|
2859 global_command->eval (); |
|
2860 |
|
2861 delete global_command; |
|
2862 |
|
2863 global_command = 0; |
|
2864 |
|
2865 bool quit = (tree_return_command::returning |
|
2866 || tree_break_command::breaking); |
|
2867 |
|
2868 if (tree_return_command::returning) |
|
2869 tree_return_command::returning = 0; |
|
2870 |
|
2871 if (tree_break_command::breaking) |
|
2872 tree_break_command::breaking--; |
|
2873 |
|
2874 if (error_state) |
|
2875 { |
|
2876 error ("near line %d of file `%s'", input_line_number, |
|
2877 curr_fcn_file_full_name.c_str ()); |
|
2878 |
|
2879 break; |
|
2880 } |
|
2881 |
|
2882 if (quit) |
|
2883 break; |
3021
|
2884 } |
3883
|
2885 else if (parser_end_of_input) |
3021
|
2886 break; |
3883
|
2887 } |
3021
|
2888 } |
|
2889 while (retval == 0); |
|
2890 |
|
2891 unwind_protect::run_frame ("parse_and_execute"); |
|
2892 } |
|
2893 |
|
2894 static void |
|
2895 safe_fclose (void *f) |
|
2896 { |
3765
|
2897 // XXX FIXME XXX -- comments at the end of an input file are |
|
2898 // discarded (otherwise, they would be appended to the next |
|
2899 // statement, possibly from the command line or another file, which |
|
2900 // can be quite confusing). |
|
2901 |
|
2902 octave_comment_buffer::get_comment (); |
|
2903 |
3021
|
2904 if (f) |
|
2905 fclose (static_cast<FILE *> (f)); |
|
2906 } |
|
2907 |
|
2908 void |
3523
|
2909 parse_and_execute (const std::string& s, bool verbose, const char *warn_for) |
3021
|
2910 { |
|
2911 unwind_protect::begin_frame ("parse_and_execute_2"); |
|
2912 |
|
2913 unwind_protect_bool (reading_script_file); |
|
2914 unwind_protect_str (curr_fcn_file_full_name); |
|
2915 |
|
2916 reading_script_file = true; |
|
2917 curr_fcn_file_full_name = s; |
|
2918 |
|
2919 FILE *f = get_input_from_file (s, 0); |
|
2920 |
|
2921 if (f) |
|
2922 { |
|
2923 unwind_protect::add (safe_fclose, f); |
|
2924 |
|
2925 unwind_protect_int (input_line_number); |
|
2926 unwind_protect_int (current_input_column); |
|
2927 |
|
2928 input_line_number = 0; |
|
2929 current_input_column = 1; |
|
2930 |
|
2931 if (verbose) |
|
2932 { |
3531
|
2933 std::cout << "reading commands from " << s << " ... "; |
3021
|
2934 reading_startup_message_printed = true; |
3531
|
2935 std::cout.flush (); |
3021
|
2936 } |
|
2937 |
|
2938 parse_and_execute (f); |
|
2939 |
|
2940 if (verbose) |
3538
|
2941 std::cout << "done." << std::endl; |
3021
|
2942 } |
|
2943 else if (warn_for) |
|
2944 error ("%s: unable to open file `%s'", warn_for, s.c_str ()); |
|
2945 |
|
2946 unwind_protect::run_frame ("parse_and_execute_2"); |
|
2947 } |
|
2948 |
|
2949 static bool |
3523
|
2950 looks_like_octave_copyright (const std::string& s) |
3021
|
2951 { |
|
2952 bool retval = false; |
|
2953 |
3523
|
2954 std::string t = s.substr (0, 14); |
3427
|
2955 |
|
2956 if (t == "Copyright (C) ") |
3021
|
2957 { |
|
2958 size_t pos = s.find ('\n'); |
|
2959 |
|
2960 if (pos != NPOS) |
|
2961 { |
|
2962 pos = s.find ('\n', pos + 1); |
|
2963 |
|
2964 if (pos != NPOS) |
|
2965 { |
|
2966 pos++; |
|
2967 |
3427
|
2968 t = s.substr (pos, 28); |
|
2969 |
|
2970 if (t == "This file is part of Octave." |
|
2971 || t == "This program is free softwar") |
3021
|
2972 retval = true; |
|
2973 } |
|
2974 } |
|
2975 } |
|
2976 |
|
2977 return retval; |
|
2978 } |
|
2979 |
|
2980 // Eat whitespace and comments from FFILE, returning the text of the |
|
2981 // comments read if it doesn't look like a copyright notice. If |
|
2982 // IN_PARTS, consider each block of comments separately; otherwise, |
|
2983 // grab them all at once. If UPDATE_POS is TRUE, line and column |
3665
|
2984 // number information is updated. If SAVE_COPYRIGHT is TRUE, then |
|
2985 // comments that are recognized as a copyright notice are saved in the |
|
2986 // comment buffer. |
3021
|
2987 |
|
2988 // XXX FIXME XXX -- grab_help_text() in lex.l duplicates some of this |
|
2989 // code! |
|
2990 |
3536
|
2991 static std::string |
3665
|
2992 gobble_leading_white_space (FILE *ffile, bool in_parts, |
|
2993 bool update_pos, bool save_copyright) |
3021
|
2994 { |
3523
|
2995 std::string help_txt; |
3021
|
2996 |
3802
|
2997 // TRUE means we have already seen the first block of comments. |
3021
|
2998 bool first_comments_seen = false; |
3802
|
2999 |
|
3000 // TRUE means we are at the beginning of a comment block. |
3021
|
3001 bool begin_comment = false; |
3802
|
3002 |
|
3003 // TRUE means we have already cached the help text. |
3021
|
3004 bool have_help_text = false; |
3802
|
3005 |
|
3006 // TRUE means we are currently reading a comment block. |
3021
|
3007 bool in_comment = false; |
3802
|
3008 |
|
3009 // TRUE means we should discard the first space from the input |
|
3010 // (used to strip leading spaces from the help text). |
3427
|
3011 bool discard_space = true; |
3802
|
3012 |
3021
|
3013 int c; |
|
3014 |
|
3015 while ((c = getc (ffile)) != EOF) |
|
3016 { |
|
3017 if (update_pos) |
|
3018 current_input_column++; |
|
3019 |
|
3020 if (begin_comment) |
|
3021 { |
|
3022 if (c == '%' || c == '#') |
|
3023 continue; |
3427
|
3024 else if (discard_space && c == ' ') |
|
3025 { |
|
3026 discard_space = false; |
|
3027 continue; |
|
3028 } |
3021
|
3029 else |
|
3030 begin_comment = false; |
|
3031 } |
|
3032 |
|
3033 if (in_comment) |
|
3034 { |
|
3035 if (! have_help_text) |
|
3036 { |
|
3037 first_comments_seen = true; |
|
3038 help_txt += (char) c; |
|
3039 } |
|
3040 |
|
3041 if (c == '\n') |
|
3042 { |
|
3043 if (update_pos) |
|
3044 { |
|
3045 input_line_number++; |
|
3046 current_input_column = 0; |
|
3047 } |
3427
|
3048 |
3021
|
3049 in_comment = false; |
3427
|
3050 discard_space = true; |
3021
|
3051 |
|
3052 if (in_parts) |
|
3053 { |
|
3054 if ((c = getc (ffile)) != EOF) |
|
3055 { |
|
3056 if (update_pos) |
|
3057 current_input_column--; |
|
3058 ungetc (c, ffile); |
|
3059 if (c == '\n') |
|
3060 break; |
|
3061 } |
|
3062 else |
|
3063 break; |
|
3064 } |
|
3065 } |
|
3066 } |
|
3067 else |
|
3068 { |
|
3069 switch (c) |
|
3070 { |
|
3071 case ' ': |
|
3072 case '\t': |
|
3073 if (first_comments_seen) |
|
3074 have_help_text = true; |
|
3075 break; |
|
3076 |
3802
|
3077 case '%': |
|
3078 case '#': |
|
3079 begin_comment = true; |
|
3080 in_comment = true; |
|
3081 break; |
|
3082 |
3021
|
3083 case '\n': |
|
3084 if (first_comments_seen) |
|
3085 have_help_text = true; |
|
3086 if (update_pos) |
|
3087 { |
|
3088 input_line_number++; |
|
3089 current_input_column = 0; |
|
3090 } |
|
3091 continue; |
|
3092 |
3802
|
3093 case '\r': |
|
3094 c = getc (ffile); |
|
3095 if (update_pos) |
|
3096 current_input_column++; |
|
3097 if (c == EOF) |
|
3098 goto done; |
|
3099 else if (c == '\n') |
|
3100 { |
|
3101 if (first_comments_seen) |
|
3102 have_help_text = true; |
|
3103 if (update_pos) |
|
3104 { |
|
3105 input_line_number++; |
|
3106 current_input_column = 0; |
|
3107 } |
|
3108 continue; |
|
3109 } |
|
3110 |
|
3111 // Fall through... |
3021
|
3112 |
|
3113 default: |
|
3114 if (update_pos) |
|
3115 current_input_column--; |
|
3116 ungetc (c, ffile); |
|
3117 goto done; |
|
3118 } |
|
3119 } |
|
3120 } |
|
3121 |
|
3122 done: |
|
3123 |
|
3124 if (! help_txt.empty ()) |
|
3125 { |
3665
|
3126 if (looks_like_octave_copyright (help_txt)) |
|
3127 { |
|
3128 if (save_copyright) |
|
3129 octave_comment_buffer::append (help_txt); |
|
3130 |
|
3131 help_txt.resize (0); |
|
3132 } |
3021
|
3133 |
|
3134 if (in_parts && help_txt.empty ()) |
3665
|
3135 help_txt = gobble_leading_white_space (ffile, in_parts, |
|
3136 update_pos, false); |
3021
|
3137 } |
|
3138 |
|
3139 return help_txt; |
|
3140 } |
|
3141 |
3536
|
3142 std::string |
3523
|
3143 get_help_from_file (const std::string& path) |
3021
|
3144 { |
3523
|
3145 std::string retval; |
3021
|
3146 |
|
3147 if (! path.empty ()) |
|
3148 { |
|
3149 FILE *fptr = fopen (path.c_str (), "r"); |
|
3150 |
|
3151 if (fptr) |
|
3152 { |
|
3153 unwind_protect::add (safe_fclose, (void *) fptr); |
|
3154 |
3665
|
3155 retval = gobble_leading_white_space (fptr, true, true, false); |
3021
|
3156 |
|
3157 unwind_protect::run (); |
|
3158 } |
|
3159 } |
|
3160 |
|
3161 return retval; |
|
3162 } |
|
3163 |
|
3164 static int |
|
3165 is_function_file (FILE *ffile) |
|
3166 { |
|
3167 int status = 0; |
|
3168 |
|
3169 long pos = ftell (ffile); |
|
3170 |
3665
|
3171 gobble_leading_white_space (ffile, false, false, false); |
3021
|
3172 |
|
3173 char buf [10]; |
|
3174 fgets (buf, 10, ffile); |
|
3175 int len = strlen (buf); |
|
3176 if (len > 8 && strncmp (buf, "function", 8) == 0 |
|
3177 && ! (isalnum (buf[8]) || buf[8] == '_')) |
|
3178 status = 1; |
|
3179 |
|
3180 fseek (ffile, pos, SEEK_SET); |
|
3181 |
|
3182 return status; |
|
3183 } |
|
3184 |
|
3185 static void |
|
3186 restore_command_history (void *) |
|
3187 { |
|
3188 command_history::ignore_entries (! Vsaving_history); |
|
3189 } |
|
3190 |
|
3191 static void |
|
3192 restore_input_stream (void *f) |
|
3193 { |
|
3194 command_editor::set_input_stream (static_cast<FILE *> (f)); |
|
3195 } |
|
3196 |
3180
|
3197 static void |
|
3198 clear_current_script_file_name (void *) |
|
3199 { |
|
3200 bind_builtin_variable ("current_script_file_name", octave_value ()); |
|
3201 } |
|
3202 |
3021
|
3203 static bool |
3523
|
3204 parse_fcn_file (const std::string& ff, bool exec_script, bool force_script = false) |
3021
|
3205 { |
|
3206 unwind_protect::begin_frame ("parse_fcn_file"); |
|
3207 |
|
3208 int script_file_executed = false; |
|
3209 |
|
3210 // Open function file and parse. |
|
3211 |
|
3212 bool old_reading_fcn_file_state = reading_fcn_file; |
|
3213 |
|
3214 FILE *in_stream = command_editor::get_input_stream (); |
|
3215 |
|
3216 unwind_protect::add (restore_input_stream, in_stream); |
|
3217 |
|
3218 unwind_protect_ptr (ff_instream); |
|
3219 |
|
3220 unwind_protect_int (input_line_number); |
|
3221 unwind_protect_int (current_input_column); |
|
3222 unwind_protect_bool (reading_fcn_file); |
|
3223 unwind_protect_bool (line_editing); |
|
3224 |
|
3225 input_line_number = 0; |
|
3226 current_input_column = 1; |
|
3227 reading_fcn_file = true; |
|
3228 line_editing = false; |
|
3229 |
|
3230 FILE *ffile = get_input_from_file (ff, 0); |
|
3231 |
|
3232 unwind_protect::add (safe_fclose, ffile); |
|
3233 |
|
3234 if (ffile) |
|
3235 { |
|
3236 // Check to see if this file defines a function or is just a |
|
3237 // list of commands. |
|
3238 |
3165
|
3239 if (! force_script && is_function_file (ffile)) |
3021
|
3240 { |
|
3241 // XXX FIXME XXX -- we shouldn't need both the |
|
3242 // command_history object and the |
|
3243 // Vsaving_history variable... |
|
3244 command_history::ignore_entries (); |
|
3245 |
|
3246 unwind_protect::add (restore_command_history, 0); |
|
3247 |
|
3248 unwind_protect_int (Vecho_executing_commands); |
|
3249 unwind_protect_bool (Vsaving_history); |
|
3250 unwind_protect_bool (reading_fcn_file); |
|
3251 unwind_protect_bool (input_from_command_line_file); |
3877
|
3252 unwind_protect_bool (get_input_from_eval_string); |
3883
|
3253 unwind_protect_bool (parser_end_of_input); |
3021
|
3254 |
|
3255 Vecho_executing_commands = ECHO_OFF; |
|
3256 Vsaving_history = false; |
|
3257 reading_fcn_file = true; |
|
3258 input_from_command_line_file = false; |
3877
|
3259 get_input_from_eval_string = false; |
3883
|
3260 parser_end_of_input = false; |
3021
|
3261 |
|
3262 YY_BUFFER_STATE old_buf = current_buffer (); |
|
3263 YY_BUFFER_STATE new_buf = create_buffer (ffile); |
|
3264 |
|
3265 unwind_protect::add (restore_input_buffer, (void *) old_buf); |
|
3266 unwind_protect::add (delete_input_buffer, (void *) new_buf); |
|
3267 |
|
3268 switch_to_buffer (new_buf); |
|
3269 |
|
3270 unwind_protect_ptr (curr_sym_tab); |
|
3271 |
|
3272 reset_parser (); |
|
3273 |
3665
|
3274 help_buf = gobble_leading_white_space (ffile, true, true, true); |
|
3275 |
|
3276 octave_comment_buffer::append (help_buf); |
3021
|
3277 |
|
3278 // XXX FIXME XXX -- this should not be necessary. |
3665
|
3279 gobble_leading_white_space (ffile, false, true, false); |
3021
|
3280 |
|
3281 int status = yyparse (); |
|
3282 |
|
3283 if (status != 0) |
|
3284 { |
|
3285 error ("parse error while reading function file %s", |
|
3286 ff.c_str ()); |
4009
|
3287 fbi_sym_tab->clear (curr_fcn_file_name); |
3021
|
3288 } |
|
3289 } |
|
3290 else if (exec_script) |
|
3291 { |
|
3292 // The value of `reading_fcn_file' will be restored to the |
|
3293 // proper value when we unwind from this frame. |
|
3294 reading_fcn_file = old_reading_fcn_file_state; |
|
3295 |
|
3296 // XXX FIXME XXX -- we shouldn't need both the |
|
3297 // command_history object and the |
|
3298 // Vsaving_history variable... |
|
3299 command_history::ignore_entries (); |
|
3300 |
|
3301 unwind_protect::add (restore_command_history, 0); |
|
3302 |
|
3303 unwind_protect_bool (Vsaving_history); |
|
3304 unwind_protect_bool (reading_script_file); |
|
3305 |
|
3306 Vsaving_history = false; |
|
3307 reading_script_file = true; |
|
3308 |
3180
|
3309 unwind_protect::add (clear_current_script_file_name, 0); |
|
3310 |
|
3311 bind_builtin_variable ("current_script_file_name", ff); |
|
3312 |
3021
|
3313 parse_and_execute (ffile); |
|
3314 |
|
3315 script_file_executed = true; |
|
3316 } |
|
3317 } |
3880
|
3318 else |
|
3319 error ("no such file, `%s'", ff.c_str ()); |
3021
|
3320 |
|
3321 unwind_protect::run_frame ("parse_fcn_file"); |
|
3322 |
|
3323 return script_file_executed; |
|
3324 } |
|
3325 |
|
3326 bool |
|
3327 load_fcn_from_file (symbol_record *sym_rec, bool exec_script) |
|
3328 { |
|
3329 bool script_file_executed = false; |
|
3330 |
3523
|
3331 std::string nm = sym_rec->name (); |
3021
|
3332 |
3325
|
3333 if (octave_dynamic_loader::load (nm)) |
3021
|
3334 { |
|
3335 force_link_to_function (nm); |
|
3336 } |
|
3337 else |
|
3338 { |
3523
|
3339 std::string ff = fcn_file_in_path (nm); |
3021
|
3340 |
|
3341 // These are needed by yyparse. |
|
3342 |
|
3343 unwind_protect::begin_frame ("load_fcn_from_file"); |
|
3344 |
|
3345 unwind_protect_str (curr_fcn_file_name); |
|
3346 unwind_protect_str (curr_fcn_file_full_name); |
|
3347 |
|
3348 curr_fcn_file_name = nm; |
|
3349 curr_fcn_file_full_name = ff; |
|
3350 |
|
3351 if (ff.length () > 0) |
3165
|
3352 script_file_executed = parse_fcn_file (ff, exec_script); |
3021
|
3353 |
|
3354 if (! (error_state || script_file_executed)) |
|
3355 force_link_to_function (nm); |
|
3356 |
|
3357 unwind_protect::run_frame ("load_fcn_from_file"); |
|
3358 } |
|
3359 |
|
3360 return script_file_executed; |
|
3361 } |
|
3362 |
|
3363 DEFUN (source, args, , |
3371
|
3364 "-*- texinfo -*-\n\ |
|
3365 @deftypefn {Built-in Function} {} source (@var{file})\n\ |
|
3366 Parse and execute the contents of @var{file}. This is equivalent to\n\ |
|
3367 executing commands from a script file, but without requiring the file to\n\ |
|
3368 be named @file{@var{file}.m}.\n\ |
|
3369 @end deftypefn") |
3021
|
3370 { |
|
3371 octave_value_list retval; |
|
3372 |
|
3373 int nargin = args.length (); |
|
3374 |
|
3375 if (nargin == 1) |
|
3376 { |
3523
|
3377 std::string file_name = args(0).string_value (); |
3021
|
3378 |
|
3379 if (! error_state) |
|
3380 { |
3523
|
3381 std::string file_full_name = file_ops::tilde_expand (file_name); |
3388
|
3382 |
|
3383 unwind_protect::begin_frame ("Fsource"); |
|
3384 |
|
3385 unwind_protect_str (curr_fcn_file_name); |
|
3386 unwind_protect_str (curr_fcn_file_full_name); |
|
3387 |
|
3388 curr_fcn_file_name = file_name; |
|
3389 curr_fcn_file_full_name = file_full_name; |
|
3390 |
|
3391 parse_fcn_file (file_full_name, true, true); |
3021
|
3392 |
|
3393 if (error_state) |
3388
|
3394 error ("source: error sourcing file `%s'", |
|
3395 file_full_name.c_str ()); |
|
3396 |
|
3397 unwind_protect::run_frame ("Fsource"); |
3021
|
3398 } |
|
3399 else |
|
3400 error ("source: expecting file name as argument"); |
|
3401 } |
|
3402 else |
|
3403 print_usage ("source"); |
|
3404 |
|
3405 return retval; |
|
3406 } |
|
3407 |
3726
|
3408 // Evaluate an Octave function (built-in or interpreted) and return |
3844
|
3409 // the list of result values. NAME is the name of the function to |
|
3410 // call. ARGS are the arguments to the function. NARGOUT is the |
|
3411 // number of output arguments expected. |
3726
|
3412 |
3021
|
3413 octave_value_list |
3523
|
3414 feval (const std::string& name, const octave_value_list& args, int nargout) |
3156
|
3415 { |
|
3416 octave_value_list retval; |
|
3417 |
|
3418 octave_function *fcn = is_valid_function (name, "feval", 1); |
|
3419 |
|
3420 if (fcn) |
3544
|
3421 retval = fcn->do_multi_index_op (nargout, args); |
3156
|
3422 |
|
3423 return retval; |
|
3424 } |
|
3425 |
3726
|
3426 // Evaluate an Octave function (built-in or interpreted) and return |
|
3427 // the list of result values. The first element of ARGS should be a |
|
3428 // string containing the name of the function to call, then the rest |
|
3429 // are the actual arguments to the function. NARGOUT is the number of |
|
3430 // output arguments expected. |
|
3431 |
3156
|
3432 octave_value_list |
3021
|
3433 feval (const octave_value_list& args, int nargout) |
|
3434 { |
|
3435 octave_value_list retval; |
|
3436 |
3156
|
3437 if (args.length () > 0) |
3021
|
3438 { |
3523
|
3439 std::string name = args(0).string_value (); |
3156
|
3440 |
|
3441 if (! error_state) |
3021
|
3442 { |
3156
|
3443 int tmp_nargin = args.length () - 1; |
|
3444 |
|
3445 octave_value_list tmp_args (tmp_nargin, octave_value ()); |
|
3446 |
|
3447 for (int i = 0; i < tmp_nargin; i++) |
3178
|
3448 tmp_args(i) = args(i+1); |
|
3449 |
|
3450 string_vector arg_names = args.name_tags (); |
|
3451 |
|
3452 if (! arg_names.empty ()) |
3156
|
3453 { |
3726
|
3454 // tmp_nargin and arg_names.length () - 1 may differ if |
|
3455 // we are passed all_va_args. |
|
3456 |
|
3457 int n = arg_names.length () - 1; |
|
3458 |
|
3459 int len = n > tmp_nargin ? tmp_nargin : n; |
|
3460 |
|
3461 string_vector tmp_arg_names (len); |
|
3462 |
|
3463 for (int i = 0; i < len; i++) |
3178
|
3464 tmp_arg_names(i) = arg_names(i+1); |
|
3465 |
|
3466 tmp_args.stash_name_tags (tmp_arg_names); |
3156
|
3467 } |
|
3468 |
|
3469 retval = feval (name, tmp_args, nargout); |
3021
|
3470 } |
|
3471 } |
|
3472 |
|
3473 return retval; |
|
3474 } |
|
3475 |
|
3476 DEFUN (feval, args, nargout, |
3371
|
3477 "-*- texinfo -*-\n\ |
|
3478 @deftypefn {Built-in Function} {} feval (@var{name}, @dots{})\n\ |
|
3479 Evaluate the function named @var{name}. Any arguments after the first\n\ |
|
3480 are passed on to the named function. For example,\n\ |
|
3481 \n\ |
|
3482 @example\n\ |
|
3483 feval (\"acos\", -1)\n\ |
|
3484 @result{} 3.1416\n\ |
|
3485 @end example\n\ |
3021
|
3486 \n\ |
3371
|
3487 @noindent\n\ |
|
3488 calls the function @code{acos} with the argument @samp{-1}.\n\ |
|
3489 \n\ |
|
3490 The function @code{feval} is necessary in order to be able to write\n\ |
|
3491 functions that call user-supplied functions, because Octave does not\n\ |
|
3492 have a way to declare a pointer to a function (like C) or to declare a\n\ |
|
3493 special kind of variable that can be used to hold the name of a function\n\ |
|
3494 (like @code{EXTERNAL} in Fortran). Instead, you must refer to functions\n\ |
|
3495 by name, and use @code{feval} to call them.\n\ |
|
3496 @end deftypefn") |
3021
|
3497 { |
|
3498 octave_value_list retval; |
|
3499 |
|
3500 int nargin = args.length (); |
|
3501 |
|
3502 if (nargin > 0) |
|
3503 retval = feval (args, nargout); |
|
3504 else |
|
3505 print_usage ("feval"); |
|
3506 |
|
3507 return retval; |
|
3508 } |
|
3509 |
3099
|
3510 octave_value_list |
3523
|
3511 eval_string (const std::string& s, bool silent, int& parse_status, int nargout) |
3021
|
3512 { |
3877
|
3513 octave_value_list retval; |
|
3514 |
3021
|
3515 unwind_protect::begin_frame ("eval_string"); |
|
3516 |
|
3517 unwind_protect_bool (get_input_from_eval_string); |
3877
|
3518 unwind_protect_bool (input_from_eval_string_pending); |
3021
|
3519 unwind_protect_bool (input_from_command_line_file); |
3883
|
3520 unwind_protect_bool (parser_end_of_input); |
3021
|
3521 unwind_protect_str (current_eval_string); |
|
3522 |
|
3523 get_input_from_eval_string = true; |
3877
|
3524 input_from_eval_string_pending = true; |
3021
|
3525 input_from_command_line_file = false; |
3883
|
3526 parser_end_of_input = false; |
3021
|
3527 current_eval_string = s; |
|
3528 |
3877
|
3529 unwind_protect_ptr (global_command); |
|
3530 |
3021
|
3531 YY_BUFFER_STATE old_buf = current_buffer (); |
|
3532 YY_BUFFER_STATE new_buf = create_buffer (0); |
|
3533 |
|
3534 unwind_protect::add (restore_input_buffer, old_buf); |
|
3535 unwind_protect::add (delete_input_buffer, new_buf); |
|
3536 |
|
3537 switch_to_buffer (new_buf); |
|
3538 |
|
3539 unwind_protect_ptr (curr_sym_tab); |
|
3540 |
3877
|
3541 do |
|
3542 { |
|
3543 parse_status = yyparse (); |
|
3544 |
|
3545 tree_statement_list *command = global_command; |
|
3546 |
3883
|
3547 if (parse_status == 0) |
3877
|
3548 { |
3883
|
3549 if (command) |
|
3550 { |
|
3551 retval = command->eval (silent, nargout); |
|
3552 |
|
3553 delete command; |
|
3554 |
|
3555 command = 0; |
|
3556 |
|
3557 if (error_state |
|
3558 || tree_return_command::returning |
|
3559 || tree_break_command::breaking |
|
3560 || tree_continue_command::continuing) |
|
3561 break; |
|
3562 } |
|
3563 else if (parser_end_of_input) |
3877
|
3564 break; |
3883
|
3565 } |
3877
|
3566 } |
|
3567 while (parse_status == 0); |
3021
|
3568 |
|
3569 unwind_protect::run_frame ("eval_string"); |
|
3570 |
|
3571 return retval; |
|
3572 } |
|
3573 |
|
3574 octave_value |
3523
|
3575 eval_string (const std::string& s, bool silent, int& parse_status) |
3021
|
3576 { |
|
3577 octave_value retval; |
|
3578 |
|
3579 octave_value_list tmp = eval_string (s, silent, parse_status, 1); |
|
3580 |
|
3581 if (! tmp.empty ()) |
|
3582 retval = tmp(0); |
|
3583 |
|
3584 return retval; |
|
3585 } |
|
3586 |
|
3587 static octave_value_list |
|
3588 eval_string (const octave_value& arg, bool silent, int& parse_status, |
|
3589 int nargout) |
|
3590 { |
3523
|
3591 std::string s = arg.string_value (); |
3021
|
3592 |
|
3593 if (error_state) |
|
3594 { |
3523
|
3595 error ("eval: expecting std::string argument"); |
3021
|
3596 return -1.0; |
|
3597 } |
|
3598 |
|
3599 return eval_string (s, silent, parse_status, nargout); |
|
3600 } |
|
3601 |
|
3602 DEFUN (eval, args, nargout, |
3371
|
3603 "-*- texinfo -*-\n\ |
|
3604 @deftypefn {Built-in Function} {} eval (@var{try}, @var{catch})\n\ |
|
3605 Parse the string @var{try} and evaluate it as if it were an Octave\n\ |
|
3606 program, returning the last value computed. If that fails, evaluate\n\ |
|
3607 the string @var{catch}. The string @var{try} is evaluated in the\n\ |
|
3608 current context, so any results remain available after @code{eval}\n\ |
|
3609 returns. For example,\n\ |
|
3610 \n\ |
|
3611 @example\n\ |
|
3612 @group\n\ |
|
3613 eval (\"a = 13\")\n\ |
|
3614 @print{} a = 13\n\ |
|
3615 @result{} 13\n\ |
|
3616 @end group\n\ |
|
3617 @end example\n\ |
3021
|
3618 \n\ |
3371
|
3619 In this case, the value of the evaluated expression is printed and it is\n\ |
|
3620 also returned returned from @code{eval}. Just as with any other\n\ |
|
3621 expression, you can turn printing off by ending the expression in a\n\ |
|
3622 semicolon. For example,\n\ |
|
3623 \n\ |
|
3624 @example\n\ |
|
3625 eval (\"a = 13;\")\n\ |
|
3626 @result{} 13\n\ |
|
3627 @end example\n\ |
|
3628 \n\ |
|
3629 In this example, the variable @code{a} has been given the value 13, but\n\ |
|
3630 the value of the expression is not printed. You can also turn off\n\ |
|
3631 automatic printing for all expressions executed by @code{eval} using the\n\ |
|
3632 variable @code{default_eval_print_flag}.\n\ |
|
3633 @end deftypefn") |
3021
|
3634 { |
|
3635 octave_value_list retval; |
|
3636 |
|
3637 int nargin = args.length (); |
|
3638 |
|
3639 if (nargin > 0) |
|
3640 { |
|
3641 unwind_protect::begin_frame ("Feval"); |
|
3642 |
|
3643 if (nargin > 1) |
|
3644 { |
|
3645 unwind_protect_bool (buffer_error_messages); |
|
3646 buffer_error_messages = true; |
|
3647 } |
|
3648 |
|
3649 int parse_status = 0; |
|
3650 |
|
3651 retval = eval_string (args(0), ! Vdefault_eval_print_flag, |
|
3652 parse_status, nargout); |
|
3653 |
|
3654 if (nargin > 1 && (parse_status != 0 || error_state)) |
|
3655 { |
|
3656 error_state = 0; |
|
3657 |
|
3658 // Set up for letting the user print any messages from |
|
3659 // errors that occurred in the first part of this eval(). |
|
3660 |
|
3661 buffer_error_messages = false; |
3815
|
3662 |
3021
|
3663 bind_global_error_variable (); |
3815
|
3664 |
3021
|
3665 unwind_protect::add (clear_global_error_variable, 0); |
|
3666 |
|
3667 eval_string (args(1), 0, parse_status, nargout); |
|
3668 |
|
3669 retval = octave_value_list (); |
|
3670 } |
|
3671 |
|
3672 unwind_protect::run_frame ("Feval"); |
|
3673 } |
|
3674 else |
|
3675 print_usage ("eval"); |
|
3676 |
|
3677 return retval; |
|
3678 } |
|
3679 |
|
3680 static int |
|
3681 default_eval_print_flag (void) |
|
3682 { |
|
3683 Vdefault_eval_print_flag = check_preference ("default_eval_print_flag"); |
|
3684 |
|
3685 return 0; |
|
3686 } |
|
3687 |
2166
|
3688 static int |
|
3689 warn_assign_as_truth_value (void) |
|
3690 { |
|
3691 Vwarn_assign_as_truth_value |
|
3692 = check_preference ("warn_assign_as_truth_value"); |
|
3693 |
|
3694 return 0; |
|
3695 } |
|
3696 |
|
3697 static int |
|
3698 warn_function_name_clash (void) |
|
3699 { |
|
3700 Vwarn_function_name_clash = check_preference ("warn_function_name_clash"); |
|
3701 |
|
3702 return 0; |
|
3703 } |
|
3704 |
|
3705 static int |
3162
|
3706 warn_future_time_stamp (void) |
|
3707 { |
|
3708 Vwarn_future_time_stamp = check_preference ("warn_future_time_stamp"); |
|
3709 |
|
3710 return 0; |
|
3711 } |
|
3712 |
|
3713 static int |
2166
|
3714 warn_missing_semicolon (void) |
|
3715 { |
|
3716 Vwarn_missing_semicolon = check_preference ("warn_missing_semicolon"); |
|
3717 |
|
3718 return 0; |
|
3719 } |
|
3720 |
2764
|
3721 static int |
4023
|
3722 warn_precedence_change (void) |
|
3723 { |
|
3724 Vwarn_precedence_change = check_preference ("warn_precedence_change"); |
|
3725 |
|
3726 return 0; |
|
3727 } |
|
3728 |
|
3729 static int |
2764
|
3730 warn_variable_switch_label (void) |
|
3731 { |
|
3732 Vwarn_variable_switch_label |
|
3733 = check_preference ("warn_variable_switch_label"); |
|
3734 |
|
3735 return 0; |
|
3736 } |
|
3737 |
2166
|
3738 void |
|
3739 symbols_of_parse (void) |
|
3740 { |
3258
|
3741 DEFVAR (default_eval_print_flag, 1.0, default_eval_print_flag, |
3371
|
3742 "-*- texinfo -*-\n\ |
|
3743 @defvr {Built-in Variable} default_eval_print_flag\n\ |
|
3744 If the value of this variable is nonzero, Octave prints the results of\n\ |
|
3745 commands executed by @code{eval} that do not end with semicolons. If it\n\ |
|
3746 is zero, automatic printing is suppressed. The default value is 1.\n\ |
|
3747 @end defvr"); |
3021
|
3748 |
3258
|
3749 DEFVAR (warn_assign_as_truth_value, 1.0, warn_assign_as_truth_value, |
3366
|
3750 "-*- texinfo -*-\n\ |
|
3751 @defvr {Built-in Variable} warn_assign_as_truth_value\n\ |
|
3752 If the value of @code{warn_assign_as_truth_value} is nonzero, a\n\ |
|
3753 warning is issued for statements like\n\ |
|
3754 \n\ |
|
3755 @example\n\ |
|
3756 if (s = t)\n\ |
|
3757 ...\n\ |
|
3758 @end example\n\ |
|
3759 \n\ |
|
3760 @noindent\n\ |
|
3761 since such statements are not common, and it is likely that the intent\n\ |
|
3762 was to write\n\ |
|
3763 \n\ |
|
3764 @example\n\ |
|
3765 if (s == t)\n\ |
|
3766 ...\n\ |
|
3767 @end example\n\ |
|
3768 \n\ |
|
3769 @noindent\n\ |
|
3770 instead.\n\ |
|
3771 \n\ |
|
3772 There are times when it is useful to write code that contains\n\ |
|
3773 assignments within the condition of a @code{while} or @code{if}\n\ |
|
3774 statement. For example, statements like\n\ |
|
3775 \n\ |
|
3776 @example\n\ |
|
3777 while (c = getc())\n\ |
|
3778 ...\n\ |
|
3779 @end example\n\ |
|
3780 \n\ |
|
3781 @noindent\n\ |
|
3782 are common in C programming.\n\ |
|
3783 \n\ |
|
3784 It is possible to avoid all warnings about such statements by setting\n\ |
|
3785 @code{warn_assign_as_truth_value} to 0, but that may also\n\ |
|
3786 let real errors like\n\ |
|
3787 \n\ |
|
3788 @example\n\ |
|
3789 if (x = 1) # intended to test (x == 1)!\n\ |
|
3790 ...\n\ |
|
3791 @end example\n\ |
|
3792 \n\ |
|
3793 @noindent\n\ |
|
3794 slip by.\n\ |
|
3795 \n\ |
|
3796 In such cases, it is possible suppress errors for specific statements by\n\ |
|
3797 writing them with an extra set of parentheses. For example, writing the\n\ |
|
3798 previous example as\n\ |
|
3799 \n\ |
|
3800 @example\n\ |
|
3801 while ((c = getc()))\n\ |
|
3802 ...\n\ |
|
3803 @end example\n\ |
|
3804 \n\ |
|
3805 @noindent\n\ |
|
3806 will prevent the warning from being printed for this statement, while\n\ |
|
3807 allowing Octave to warn about other assignments used in conditional\n\ |
|
3808 contexts.\n\ |
|
3809 \n\ |
|
3810 The default value of @code{warn_assign_as_truth_value} is 1.\n\ |
|
3811 @end defvr"); |
2166
|
3812 |
3258
|
3813 DEFVAR (warn_function_name_clash, 1.0, warn_function_name_clash, |
3371
|
3814 "-*- texinfo -*-\n\ |
|
3815 @defvr {Built-in Variable} warn_function_name_clash\n\ |
|
3816 If the value of @code{warn_function_name_clash} is nonzero, a warning is\n\ |
|
3817 issued when Octave finds that the name of a function defined in a\n\ |
|
3818 function file differs from the name of the file. (If the names\n\ |
|
3819 disagree, the name declared inside the file is ignored.) If the value\n\ |
|
3820 is 0, the warning is omitted. The default value is 1.\n\ |
|
3821 @end defvr"); |
2166
|
3822 |
3258
|
3823 DEFVAR (warn_future_time_stamp, 1.0, warn_future_time_stamp, |
3446
|
3824 "-*- texinfo -*-\n\ |
|
3825 @defvr {Built-in Variable} warn_future_time_stamp\n\ |
|
3826 If the value of this variable is nonzero, Octave will print a warning\n\ |
|
3827 if it finds a function file with a time stamp that is in the future.\n\ |
|
3828 @end defvr"); |
3162
|
3829 |
3258
|
3830 DEFVAR (warn_missing_semicolon, 0.0, warn_missing_semicolon, |
3371
|
3831 "-*- texinfo -*-\n\ |
|
3832 @defvr {Built-in Variable} warn_missing_semicolon\n\ |
|
3833 If the value of this variable is nonzero, Octave will warn when\n\ |
|
3834 statements in function definitions don't end in semicolons. The default\n\ |
|
3835 value is 0.\n\ |
|
3836 @end defvr"); |
2764
|
3837 |
4023
|
3838 DEFVAR (warn_precedence_change, 1.0, warn_precedence_change, |
|
3839 "-*- texinfo -*-\n\ |
|
3840 @defvr {Built-in Variable} warn_precedence_change\n\ |
|
3841 If the value of this variable is nonzero, Octave will warn about\n\ |
|
3842 possible changes in the meaning of some code due to changes in\n\ |
|
3843 precedence for some operators. Precedence changes have typically\n\ |
|
3844 been made for Matlab compatibility. The default value is 1.\n\ |
|
3845 @end defvr"); |
|
3846 |
3258
|
3847 DEFVAR (warn_variable_switch_label, 0.0, warn_variable_switch_label, |
3366
|
3848 "-*- texinfo -*-\n\ |
|
3849 @defvr {Built-in Variable} warn_variable_switch_label\n\ |
|
3850 If the value of this variable is nonzero, Octave will print a warning if\n\ |
|
3851 a switch label is not a constant or constant expression\n\ |
|
3852 @end defvr"); |
3347
|
3853 |
2166
|
3854 } |
|
3855 |
1994
|
3856 /* |
|
3857 ;;; Local Variables: *** |
|
3858 ;;; mode: text *** |
|
3859 ;;; End: *** |
|
3860 */ |