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