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