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