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