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 |
3233
|
1426 case token::switch_end: |
|
1427 error (fmt, type, "endswitch", l, c); |
|
1428 break; |
|
1429 |
496
|
1430 case token::while_end: |
|
1431 error (fmt, type, "endwhile", l, c); |
|
1432 break; |
777
|
1433 |
1371
|
1434 case token::unwind_protect_end: |
|
1435 error (fmt, type, "end_unwind_protect", l, c); |
|
1436 break; |
|
1437 |
496
|
1438 default: |
|
1439 panic_impossible (); |
|
1440 break; |
|
1441 } |
|
1442 } |
|
1443 |
666
|
1444 // Check to see that end tokens are properly matched. |
|
1445 |
2857
|
1446 static bool |
|
1447 end_token_ok (token *tok, token::end_tok_type expected) |
143
|
1448 { |
2857
|
1449 bool retval = true; |
|
1450 |
143
|
1451 token::end_tok_type ettype = tok->ettype (); |
2857
|
1452 |
143
|
1453 if (ettype != expected && ettype != token::simple_end) |
|
1454 { |
2857
|
1455 retval = false; |
|
1456 |
143
|
1457 yyerror ("parse error"); |
|
1458 |
|
1459 int l = tok->line (); |
|
1460 int c = tok->column (); |
|
1461 |
|
1462 switch (expected) |
|
1463 { |
|
1464 case token::for_end: |
|
1465 end_error ("for", ettype, l, c); |
|
1466 break; |
777
|
1467 |
143
|
1468 case token::function_end: |
|
1469 end_error ("function", ettype, l, c); |
|
1470 break; |
777
|
1471 |
143
|
1472 case token::if_end: |
|
1473 end_error ("if", ettype, l, c); |
|
1474 break; |
777
|
1475 |
1489
|
1476 case token::try_catch_end: |
|
1477 end_error ("try", ettype, l, c); |
|
1478 break; |
|
1479 |
2764
|
1480 case token::switch_end: |
|
1481 end_error ("switch", ettype, l, c); |
|
1482 break; |
|
1483 |
1489
|
1484 case token::unwind_protect_end: |
|
1485 end_error ("unwind_protect", ettype, l, c); |
|
1486 break; |
|
1487 |
143
|
1488 case token::while_end: |
|
1489 end_error ("while", ettype, l, c); |
|
1490 break; |
777
|
1491 |
143
|
1492 default: |
|
1493 panic_impossible (); |
|
1494 break; |
|
1495 } |
|
1496 } |
2857
|
1497 |
|
1498 return retval; |
143
|
1499 } |
|
1500 |
666
|
1501 // Maybe print a warning if an assignment expression is used as the |
|
1502 // test in a logical expression. |
|
1503 |
496
|
1504 static void |
|
1505 maybe_warn_assign_as_truth_value (tree_expression *expr) |
1
|
1506 { |
2166
|
1507 if (Vwarn_assign_as_truth_value |
1
|
1508 && expr->is_assignment_expression () |
2961
|
1509 && expr->paren_count () < 2) |
1
|
1510 { |
|
1511 warning ("suggest parenthesis around assignment used as truth value"); |
|
1512 } |
|
1513 } |
578
|
1514 |
2764
|
1515 // Maybe print a warning about switch labels that aren't constants. |
|
1516 |
|
1517 static void |
|
1518 maybe_warn_variable_switch_label (tree_expression *expr) |
|
1519 { |
|
1520 if (Vwarn_variable_switch_label && ! expr->is_constant ()) |
|
1521 { |
|
1522 warning ("variable switch label"); |
|
1523 } |
|
1524 } |
|
1525 |
1623
|
1526 // Create a plot command. |
|
1527 |
|
1528 static tree_plot_command * |
|
1529 make_plot_command (token *tok, plot_limits *range, subplot_list *list) |
|
1530 { |
|
1531 if (range) |
|
1532 { |
|
1533 if (tok->pttype () == token::replot) |
|
1534 { |
|
1535 yyerror ("cannot specify new ranges with replot"); |
|
1536 return 0; |
|
1537 } |
|
1538 } |
|
1539 else if (! list && tok->pttype () != token::replot) |
|
1540 { |
|
1541 yyerror ("must have something to plot"); |
|
1542 return 0; |
|
1543 } |
|
1544 |
2857
|
1545 lexer_flags.plotting = false; |
|
1546 lexer_flags.past_plot_range = false; |
|
1547 lexer_flags.in_plot_range = false; |
|
1548 lexer_flags.in_plot_using = false; |
|
1549 lexer_flags.in_plot_style = false; |
1623
|
1550 |
|
1551 return new tree_plot_command (list, range, tok->pttype ()); |
|
1552 } |
|
1553 |
2533
|
1554 static tree_expression * |
|
1555 fold (tree_binary_expression *e) |
|
1556 { |
3110
|
1557 tree_expression *retval = e; |
|
1558 |
|
1559 unwind_protect::begin_frame ("fold"); |
|
1560 |
|
1561 unwind_protect_int (error_state); |
|
1562 |
|
1563 unwind_protect_bool (buffer_error_messages); |
|
1564 buffer_error_messages = true; |
|
1565 |
|
1566 unwind_protect::add (clear_global_error_variable, 0); |
2533
|
1567 |
|
1568 tree_expression *op1 = e->lhs (); |
|
1569 tree_expression *op2 = e->rhs (); |
|
1570 |
|
1571 if (op1->is_constant () && op2->is_constant ()) |
|
1572 { |
2970
|
1573 octave_value tmp = e->rvalue (); |
2533
|
1574 |
|
1575 if (! error_state) |
|
1576 { |
|
1577 tree_constant *tc_retval = new tree_constant (tmp); |
|
1578 |
|
1579 ostrstream buf; |
|
1580 |
|
1581 tree_print_code tpc (buf); |
|
1582 |
|
1583 e->accept (tpc); |
|
1584 |
|
1585 buf << ends; |
|
1586 |
|
1587 char *s = buf.str (); |
|
1588 |
|
1589 tc_retval->stash_original_text (s); |
|
1590 |
|
1591 delete [] s; |
|
1592 |
|
1593 delete e; |
|
1594 |
|
1595 retval = tc_retval; |
|
1596 } |
|
1597 } |
3110
|
1598 |
|
1599 unwind_protect::run_frame ("fold"); |
2533
|
1600 |
|
1601 return retval; |
|
1602 } |
|
1603 |
1623
|
1604 // Finish building a range. |
|
1605 |
|
1606 static tree_expression * |
|
1607 finish_colon_expression (tree_colon_expression *e) |
|
1608 { |
3110
|
1609 tree_expression *retval = e; |
|
1610 |
|
1611 unwind_protect::begin_frame ("finish_colon_expression"); |
|
1612 |
|
1613 unwind_protect_int (error_state); |
|
1614 |
|
1615 unwind_protect_bool (buffer_error_messages); |
|
1616 buffer_error_messages = true; |
|
1617 |
|
1618 unwind_protect::add (clear_global_error_variable, 0); |
1623
|
1619 |
2533
|
1620 tree_expression *base = e->base (); |
|
1621 tree_expression *limit = e->limit (); |
|
1622 tree_expression *incr = e->increment (); |
|
1623 |
2970
|
1624 if (base) |
1623
|
1625 { |
2970
|
1626 if (limit) |
2533
|
1627 { |
2970
|
1628 if (base->is_constant () && limit->is_constant () |
|
1629 && (! incr || (incr && incr->is_constant ()))) |
|
1630 { |
|
1631 octave_value tmp = e->rvalue (); |
|
1632 |
|
1633 if (! error_state) |
|
1634 { |
|
1635 tree_constant *tc_retval = new tree_constant (tmp); |
|
1636 |
|
1637 ostrstream buf; |
|
1638 |
|
1639 tree_print_code tpc (buf); |
|
1640 |
|
1641 e->accept (tpc); |
|
1642 |
|
1643 buf << ends; |
|
1644 |
|
1645 char *s = buf.str (); |
|
1646 |
|
1647 tc_retval->stash_original_text (s); |
|
1648 |
|
1649 delete [] s; |
|
1650 |
|
1651 delete e; |
|
1652 |
|
1653 retval = tc_retval; |
|
1654 } |
|
1655 } |
2533
|
1656 } |
|
1657 else |
2970
|
1658 { |
2990
|
1659 e->preserve_base (); |
|
1660 delete e; |
2970
|
1661 |
|
1662 // XXX FIXME XXX -- need to attempt constant folding here |
|
1663 // too (we need a generic way to do that). |
|
1664 retval = base; |
|
1665 } |
1623
|
1666 } |
|
1667 |
3110
|
1668 unwind_protect::run_frame ("finish_colon_expression"); |
|
1669 |
1623
|
1670 return retval; |
|
1671 } |
|
1672 |
1607
|
1673 // Make a constant. |
|
1674 |
2375
|
1675 static tree_constant * |
1607
|
1676 make_constant (int op, token *tok_val) |
|
1677 { |
|
1678 int l = tok_val->line (); |
|
1679 int c = tok_val->column (); |
|
1680 |
3216
|
1681 tree_constant *retval = 0; |
1607
|
1682 |
|
1683 switch (op) |
|
1684 { |
|
1685 case NUM: |
2533
|
1686 { |
2883
|
1687 octave_value tmp (tok_val->number ()); |
|
1688 retval = new tree_constant (tmp, l, c); |
2533
|
1689 retval->stash_original_text (tok_val->text_rep ()); |
|
1690 } |
1607
|
1691 break; |
|
1692 |
|
1693 case IMAG_NUM: |
|
1694 { |
2883
|
1695 octave_value tmp (Complex (0.0, tok_val->number ())); |
|
1696 retval = new tree_constant (tmp, l, c); |
1607
|
1697 retval->stash_original_text (tok_val->text_rep ()); |
|
1698 } |
|
1699 break; |
|
1700 |
|
1701 case TEXT: |
2883
|
1702 { |
|
1703 octave_value tmp (tok_val->text ()); |
|
1704 retval = new tree_constant (tmp, l, c); |
|
1705 } |
1607
|
1706 break; |
|
1707 |
|
1708 default: |
|
1709 panic_impossible (); |
|
1710 break; |
|
1711 } |
|
1712 |
|
1713 return retval; |
|
1714 } |
|
1715 |
666
|
1716 // Build a binary expression. |
|
1717 |
578
|
1718 static tree_expression * |
|
1719 make_binary_op (int op, tree_expression *op1, token *tok_val, |
|
1720 tree_expression *op2) |
|
1721 { |
2883
|
1722 octave_value::binary_op t = octave_value::unknown_binary_op; |
1623
|
1723 |
578
|
1724 switch (op) |
|
1725 { |
|
1726 case POW: |
2883
|
1727 t = octave_value::pow; |
578
|
1728 break; |
777
|
1729 |
578
|
1730 case EPOW: |
2883
|
1731 t = octave_value::el_pow; |
578
|
1732 break; |
777
|
1733 |
578
|
1734 case '+': |
2883
|
1735 t = octave_value::add; |
578
|
1736 break; |
777
|
1737 |
578
|
1738 case '-': |
2883
|
1739 t = octave_value::sub; |
578
|
1740 break; |
777
|
1741 |
578
|
1742 case '*': |
2883
|
1743 t = octave_value::mul; |
578
|
1744 break; |
777
|
1745 |
578
|
1746 case '/': |
2883
|
1747 t = octave_value::div; |
578
|
1748 break; |
777
|
1749 |
578
|
1750 case EMUL: |
2883
|
1751 t = octave_value::el_mul; |
578
|
1752 break; |
777
|
1753 |
578
|
1754 case EDIV: |
2883
|
1755 t = octave_value::el_div; |
578
|
1756 break; |
777
|
1757 |
578
|
1758 case LEFTDIV: |
2883
|
1759 t = octave_value::ldiv; |
578
|
1760 break; |
777
|
1761 |
578
|
1762 case ELEFTDIV: |
2883
|
1763 t = octave_value::el_ldiv; |
578
|
1764 break; |
777
|
1765 |
2899
|
1766 case LSHIFT: |
|
1767 t = octave_value::lshift; |
|
1768 break; |
|
1769 |
|
1770 case RSHIFT: |
|
1771 t = octave_value::rshift; |
|
1772 break; |
|
1773 |
578
|
1774 case EXPR_LT: |
2883
|
1775 t = octave_value::lt; |
578
|
1776 break; |
777
|
1777 |
578
|
1778 case EXPR_LE: |
2883
|
1779 t = octave_value::le; |
578
|
1780 break; |
777
|
1781 |
578
|
1782 case EXPR_EQ: |
2883
|
1783 t = octave_value::eq; |
578
|
1784 break; |
777
|
1785 |
578
|
1786 case EXPR_GE: |
2883
|
1787 t = octave_value::ge; |
578
|
1788 break; |
777
|
1789 |
578
|
1790 case EXPR_GT: |
2883
|
1791 t = octave_value::gt; |
578
|
1792 break; |
777
|
1793 |
578
|
1794 case EXPR_NE: |
2883
|
1795 t = octave_value::ne; |
578
|
1796 break; |
777
|
1797 |
578
|
1798 case EXPR_AND: |
2883
|
1799 t = octave_value::el_and; |
578
|
1800 break; |
777
|
1801 |
578
|
1802 case EXPR_OR: |
2883
|
1803 t = octave_value::el_or; |
578
|
1804 break; |
777
|
1805 |
578
|
1806 default: |
|
1807 panic_impossible (); |
|
1808 break; |
|
1809 } |
|
1810 |
|
1811 int l = tok_val->line (); |
|
1812 int c = tok_val->column (); |
|
1813 |
2533
|
1814 tree_binary_expression *e |
|
1815 = new tree_binary_expression (op1, op2, l, c, t); |
1623
|
1816 |
2533
|
1817 return fold (e); |
578
|
1818 } |
|
1819 |
2375
|
1820 // Build a boolean expression. |
666
|
1821 |
578
|
1822 static tree_expression * |
2375
|
1823 make_boolean_op (int op, tree_expression *op1, token *tok_val, |
|
1824 tree_expression *op2) |
578
|
1825 { |
2375
|
1826 tree_boolean_expression::type t; |
|
1827 |
578
|
1828 switch (op) |
|
1829 { |
2375
|
1830 case EXPR_AND_AND: |
2805
|
1831 t = tree_boolean_expression::bool_and; |
578
|
1832 break; |
777
|
1833 |
2375
|
1834 case EXPR_OR_OR: |
2805
|
1835 t = tree_boolean_expression::bool_or; |
578
|
1836 break; |
777
|
1837 |
578
|
1838 default: |
|
1839 panic_impossible (); |
|
1840 break; |
|
1841 } |
|
1842 |
|
1843 int l = tok_val->line (); |
|
1844 int c = tok_val->column (); |
|
1845 |
2533
|
1846 tree_boolean_expression *e |
|
1847 = new tree_boolean_expression (op1, op2, l, c, t); |
2375
|
1848 |
2533
|
1849 return fold (e); |
578
|
1850 } |
|
1851 |
2375
|
1852 // Build a prefix expression. |
666
|
1853 |
578
|
1854 static tree_expression * |
2960
|
1855 make_prefix_op (int op, tree_expression *op1, token *tok_val) |
578
|
1856 { |
3203
|
1857 octave_value::unary_op t = octave_value::unknown_unary_op; |
2375
|
1858 |
578
|
1859 switch (op) |
|
1860 { |
2960
|
1861 case EXPR_NOT: |
3203
|
1862 t = octave_value::not; |
2960
|
1863 break; |
|
1864 |
|
1865 case '-': |
3203
|
1866 t = octave_value::uminus; |
2960
|
1867 break; |
|
1868 |
578
|
1869 case PLUS_PLUS: |
3203
|
1870 t = octave_value::incr; |
578
|
1871 break; |
777
|
1872 |
578
|
1873 case MINUS_MINUS: |
3203
|
1874 t = octave_value::decr; |
578
|
1875 break; |
777
|
1876 |
578
|
1877 default: |
|
1878 panic_impossible (); |
|
1879 break; |
|
1880 } |
|
1881 |
|
1882 int l = tok_val->line (); |
|
1883 int c = tok_val->column (); |
|
1884 |
3110
|
1885 // XXX FIXME XXX -- what about constant folding here? |
|
1886 |
3195
|
1887 return new tree_prefix_expression (op1, l, c, t); |
578
|
1888 } |
|
1889 |
2375
|
1890 // Build a postfix expression. |
666
|
1891 |
578
|
1892 static tree_expression * |
2960
|
1893 make_postfix_op (int op, tree_expression *op1, token *tok_val) |
578
|
1894 { |
3203
|
1895 octave_value::unary_op t = octave_value::unknown_unary_op; |
1623
|
1896 |
578
|
1897 switch (op) |
|
1898 { |
2960
|
1899 case QUOTE: |
3203
|
1900 t = octave_value::hermitian; |
2960
|
1901 break; |
|
1902 |
|
1903 case TRANSPOSE: |
3203
|
1904 t = octave_value::transpose; |
2960
|
1905 break; |
|
1906 |
2375
|
1907 case PLUS_PLUS: |
3203
|
1908 t = octave_value::incr; |
578
|
1909 break; |
777
|
1910 |
2375
|
1911 case MINUS_MINUS: |
3203
|
1912 t = octave_value::decr; |
578
|
1913 break; |
777
|
1914 |
578
|
1915 default: |
|
1916 panic_impossible (); |
|
1917 break; |
|
1918 } |
|
1919 |
|
1920 int l = tok_val->line (); |
|
1921 int c = tok_val->column (); |
|
1922 |
3110
|
1923 // XXX FIXME XXX -- what about constant folding here? |
|
1924 |
3195
|
1925 return new tree_postfix_expression (op1, l, c, t); |
1623
|
1926 } |
|
1927 |
|
1928 // Build an unwind-protect command. |
|
1929 |
|
1930 static tree_command * |
|
1931 make_unwind_command (token *unwind_tok, tree_statement_list *body, |
|
1932 tree_statement_list *cleanup, token *end_tok) |
|
1933 { |
|
1934 tree_command *retval = 0; |
|
1935 |
2857
|
1936 if (end_token_ok (end_tok, token::unwind_protect_end)) |
1623
|
1937 { |
|
1938 int l = unwind_tok->line (); |
|
1939 int c = unwind_tok->column (); |
|
1940 |
|
1941 retval = new tree_unwind_protect_command (body, cleanup, l, c); |
|
1942 } |
|
1943 |
|
1944 return retval; |
|
1945 } |
|
1946 |
|
1947 // Build a try-catch command. |
|
1948 |
|
1949 static tree_command * |
|
1950 make_try_command (token *try_tok, tree_statement_list *body, |
|
1951 tree_statement_list *cleanup, token *end_tok) |
|
1952 { |
|
1953 tree_command *retval = 0; |
|
1954 |
2857
|
1955 if (end_token_ok (end_tok, token::try_catch_end)) |
1623
|
1956 { |
|
1957 int l = try_tok->line (); |
|
1958 int c = try_tok->column (); |
|
1959 |
|
1960 retval = new tree_try_catch_command (body, cleanup, l, c); |
|
1961 } |
|
1962 |
|
1963 return retval; |
|
1964 } |
|
1965 |
|
1966 // Build a while command. |
|
1967 |
|
1968 static tree_command * |
|
1969 make_while_command (token *while_tok, tree_expression *expr, |
|
1970 tree_statement_list *body, token *end_tok) |
|
1971 { |
|
1972 tree_command *retval = 0; |
|
1973 |
|
1974 maybe_warn_assign_as_truth_value (expr); |
|
1975 |
2857
|
1976 if (end_token_ok (end_tok, token::while_end)) |
1623
|
1977 { |
1826
|
1978 lexer_flags.looping--; |
1623
|
1979 |
|
1980 int l = while_tok->line (); |
|
1981 int c = while_tok->column (); |
|
1982 |
|
1983 retval = new tree_while_command (expr, body, l, c); |
|
1984 } |
|
1985 |
|
1986 return retval; |
|
1987 } |
|
1988 |
|
1989 // Build a for command. |
|
1990 |
|
1991 static tree_command * |
2970
|
1992 make_for_command (token *for_tok, tree_argument_list *lhs, |
1623
|
1993 tree_expression *expr, tree_statement_list *body, |
|
1994 token *end_tok) |
|
1995 { |
|
1996 tree_command *retval = 0; |
|
1997 |
2857
|
1998 if (end_token_ok (end_tok, token::for_end)) |
1623
|
1999 { |
1826
|
2000 lexer_flags.looping--; |
1623
|
2001 |
|
2002 int l = for_tok->line (); |
|
2003 int c = for_tok->column (); |
|
2004 |
2970
|
2005 if (lhs->length () == 1) |
|
2006 { |
|
2007 tree_expression *tmp = lhs->remove_front (); |
|
2008 |
|
2009 retval = new tree_simple_for_command (tmp, expr, body, l, c); |
|
2010 |
|
2011 delete lhs; |
|
2012 } |
|
2013 else |
|
2014 retval = new tree_complex_for_command (lhs, expr, body, l, c); |
1623
|
2015 } |
|
2016 |
|
2017 return retval; |
|
2018 } |
|
2019 |
|
2020 // Build a break command. |
|
2021 |
|
2022 static tree_command * |
|
2023 make_break_command (token *break_tok) |
|
2024 { |
|
2025 tree_command *retval = 0; |
|
2026 |
2620
|
2027 int l = break_tok->line (); |
|
2028 int c = break_tok->column (); |
|
2029 |
|
2030 if (lexer_flags.looping || lexer_flags.defining_func || reading_script_file) |
|
2031 retval = new tree_break_command (l, c); |
1623
|
2032 else |
2620
|
2033 retval = new tree_no_op_command ("break", l, c); |
1623
|
2034 |
|
2035 return retval; |
|
2036 } |
|
2037 |
|
2038 // Build a continue command. |
|
2039 |
|
2040 static tree_command * |
|
2041 make_continue_command (token *continue_tok) |
|
2042 { |
|
2043 tree_command *retval = 0; |
|
2044 |
2620
|
2045 int l = continue_tok->line (); |
|
2046 int c = continue_tok->column (); |
|
2047 |
|
2048 if (lexer_flags.looping) |
|
2049 retval = new tree_continue_command (l, c); |
1623
|
2050 else |
2620
|
2051 retval = new tree_no_op_command ("continue", l, c); |
1623
|
2052 |
|
2053 return retval; |
|
2054 } |
|
2055 |
|
2056 // Build a return command. |
|
2057 |
|
2058 static tree_command * |
|
2059 make_return_command (token *return_tok) |
|
2060 { |
|
2061 tree_command *retval = 0; |
|
2062 |
2620
|
2063 int l = return_tok->line (); |
|
2064 int c = return_tok->column (); |
|
2065 |
|
2066 if (lexer_flags.defining_func || reading_script_file) |
|
2067 retval = new tree_return_command (l, c); |
1623
|
2068 else |
2620
|
2069 retval = new tree_no_op_command ("return", l, c); |
1623
|
2070 |
|
2071 return retval; |
|
2072 } |
|
2073 |
|
2074 // Start an if command. |
|
2075 |
|
2076 static tree_if_command_list * |
|
2077 start_if_command (tree_expression *expr, tree_statement_list *list) |
|
2078 { |
|
2079 maybe_warn_assign_as_truth_value (expr); |
|
2080 |
|
2081 tree_if_clause *t = new tree_if_clause (expr, list); |
|
2082 |
|
2083 return new tree_if_command_list (t); |
|
2084 } |
|
2085 |
|
2086 // Finish an if command. |
|
2087 |
|
2088 static tree_if_command * |
|
2089 finish_if_command (token *if_tok, tree_if_command_list *list, |
|
2090 token *end_tok) |
|
2091 { |
|
2092 tree_if_command *retval = 0; |
|
2093 |
2857
|
2094 if (end_token_ok (end_tok, token::if_end)) |
1623
|
2095 { |
|
2096 int l = if_tok->line (); |
|
2097 int c = if_tok->column (); |
|
2098 |
|
2099 retval = new tree_if_command (list, l, c); |
|
2100 } |
|
2101 |
|
2102 return retval; |
|
2103 } |
|
2104 |
|
2105 // Build an elseif clause. |
|
2106 |
|
2107 static tree_if_clause * |
|
2108 make_elseif_clause (tree_expression *expr, tree_statement_list *list) |
|
2109 { |
|
2110 maybe_warn_assign_as_truth_value (expr); |
|
2111 |
|
2112 return new tree_if_clause (expr, list); |
|
2113 } |
|
2114 |
2764
|
2115 // Finish a switch command. |
|
2116 |
|
2117 static tree_switch_command * |
|
2118 finish_switch_command (token *switch_tok, tree_expression *expr, |
|
2119 tree_switch_case_list *list, token *end_tok) |
|
2120 { |
|
2121 tree_switch_command *retval = 0; |
|
2122 |
2857
|
2123 if (end_token_ok (end_tok, token::switch_end)) |
2764
|
2124 { |
|
2125 int l = switch_tok->line (); |
|
2126 int c = switch_tok->column (); |
|
2127 |
|
2128 retval = new tree_switch_command (expr, list, l, c); |
|
2129 } |
|
2130 |
|
2131 return retval; |
|
2132 } |
|
2133 |
|
2134 // Build a switch case. |
|
2135 |
|
2136 static tree_switch_case * |
|
2137 make_switch_case (tree_expression *expr, tree_statement_list *list) |
|
2138 { |
|
2139 maybe_warn_variable_switch_label (expr); |
|
2140 |
|
2141 return new tree_switch_case (expr, list); |
|
2142 } |
|
2143 |
1623
|
2144 // Build an assignment to a variable. |
|
2145 |
|
2146 static tree_expression * |
2970
|
2147 make_assign_op (int op, tree_argument_list *lhs, token *eq_tok, |
|
2148 tree_expression *rhs) |
1623
|
2149 { |
2970
|
2150 tree_expression *retval = 0; |
|
2151 |
2883
|
2152 octave_value::assign_op t = octave_value::unknown_assign_op; |
|
2153 |
|
2154 switch (op) |
|
2155 { |
|
2156 case '=': |
|
2157 t = octave_value::asn_eq; |
|
2158 break; |
|
2159 |
|
2160 case ADD_EQ: |
|
2161 t = octave_value::add_eq; |
|
2162 break; |
|
2163 |
|
2164 case SUB_EQ: |
|
2165 t = octave_value::sub_eq; |
|
2166 break; |
|
2167 |
|
2168 case MUL_EQ: |
|
2169 t = octave_value::mul_eq; |
|
2170 break; |
|
2171 |
|
2172 case DIV_EQ: |
|
2173 t = octave_value::div_eq; |
|
2174 break; |
|
2175 |
3204
|
2176 case LEFTDIV_EQ: |
|
2177 t = octave_value::ldiv_eq; |
|
2178 break; |
|
2179 |
2899
|
2180 case LSHIFT_EQ: |
|
2181 t = octave_value::lshift_eq; |
|
2182 break; |
|
2183 |
|
2184 case RSHIFT_EQ: |
|
2185 t = octave_value::rshift_eq; |
|
2186 break; |
|
2187 |
2883
|
2188 case EMUL_EQ: |
|
2189 t = octave_value::el_mul_eq; |
|
2190 break; |
|
2191 |
|
2192 case EDIV_EQ: |
|
2193 t = octave_value::el_div_eq; |
|
2194 break; |
|
2195 |
3204
|
2196 case ELEFTDIV_EQ: |
|
2197 t = octave_value::el_ldiv_eq; |
|
2198 break; |
|
2199 |
2883
|
2200 case AND_EQ: |
|
2201 t = octave_value::el_and_eq; |
|
2202 break; |
|
2203 |
|
2204 case OR_EQ: |
|
2205 t = octave_value::el_or_eq; |
|
2206 break; |
|
2207 |
|
2208 default: |
|
2209 panic_impossible (); |
|
2210 break; |
|
2211 } |
|
2212 |
1623
|
2213 int l = eq_tok->line (); |
|
2214 int c = eq_tok->column (); |
|
2215 |
2970
|
2216 if (lhs->length () == 1) |
666
|
2217 { |
2970
|
2218 tree_expression *tmp = lhs->remove_front (); |
|
2219 |
|
2220 retval = new tree_simple_assignment (tmp, rhs, false, l, c, t); |
|
2221 |
|
2222 delete lhs; |
666
|
2223 } |
|
2224 else |
3208
|
2225 return new tree_multi_assignment (lhs, rhs, false, l, c, t); |
666
|
2226 |
|
2227 return retval; |
|
2228 } |
751
|
2229 |
1623
|
2230 // Begin defining a function. |
|
2231 |
2891
|
2232 static octave_user_function * |
|
2233 start_function (tree_parameter_list *param_list, tree_statement_list *body) |
1623
|
2234 { |
|
2235 body->mark_as_function_body (); |
|
2236 |
2891
|
2237 // We'll fill in the return list later. |
|
2238 |
|
2239 octave_user_function *fcn |
|
2240 = new octave_user_function (param_list, 0, body, curr_sym_tab); |
1623
|
2241 |
|
2242 return fcn; |
|
2243 } |
|
2244 |
|
2245 // Do most of the work for defining a function. |
|
2246 |
2891
|
2247 static octave_user_function * |
|
2248 frob_function (tree_identifier *id, octave_user_function *fcn) |
1623
|
2249 { |
1755
|
2250 string id_name = id->name (); |
1623
|
2251 |
|
2252 // If input is coming from a file, issue a warning if the name of |
|
2253 // the file does not match the name of the function stated in the |
|
2254 // file. Matlab doesn't provide a diagnostic (it ignores the stated |
|
2255 // name). |
|
2256 |
|
2257 fcn->stash_function_name (id_name); |
|
2258 |
|
2259 if (reading_fcn_file) |
|
2260 { |
1755
|
2261 if (curr_fcn_file_name != id_name) |
1623
|
2262 { |
2166
|
2263 if (Vwarn_function_name_clash) |
1623
|
2264 warning ("function name `%s' does not agree with function\ |
1755
|
2265 file name `%s'", id_name.c_str (), curr_fcn_file_full_name.c_str ()); |
1623
|
2266 |
|
2267 global_sym_tab->rename (id_name, curr_fcn_file_name); |
|
2268 |
|
2269 if (error_state) |
|
2270 return 0; |
|
2271 |
|
2272 id_name = id->name (); |
|
2273 } |
|
2274 |
3162
|
2275 time_t now = time (0); |
|
2276 |
1623
|
2277 fcn->stash_function_name (id_name); |
|
2278 fcn->stash_fcn_file_name (); |
3162
|
2279 fcn->stash_fcn_file_time (now); |
1623
|
2280 fcn->mark_as_system_fcn_file (); |
3162
|
2281 |
|
2282 if (Vwarn_future_time_stamp) |
|
2283 { |
|
2284 string nm = fcn->fcn_file_name (); |
|
2285 |
|
2286 file_stat fs (nm); |
|
2287 |
|
2288 if (fs && fs.is_newer (now)) |
|
2289 warning ("time stamp for `%s' is in the future", nm.c_str ()); |
|
2290 } |
1623
|
2291 } |
|
2292 else if (! (input_from_tmp_history_file || input_from_startup_file) |
|
2293 && reading_script_file |
1755
|
2294 && curr_fcn_file_name == id_name) |
1623
|
2295 { |
|
2296 warning ("function `%s' defined within script file `%s'", |
1755
|
2297 id_name.c_str (), curr_fcn_file_full_name.c_str ()); |
1623
|
2298 } |
|
2299 |
|
2300 top_level_sym_tab->clear (id_name); |
|
2301 |
2856
|
2302 symbol_record *sr = global_sym_tab->lookup (id_name); |
2791
|
2303 |
|
2304 if (sr) |
|
2305 fcn->stash_symtab_ptr (sr); |
|
2306 else |
|
2307 panic_impossible (); |
|
2308 |
3016
|
2309 id->define (fcn, symbol_record::USER_FUNCTION); |
1755
|
2310 |
1623
|
2311 id->document (help_buf); |
|
2312 |
|
2313 return fcn; |
|
2314 } |
|
2315 |
|
2316 // Finish defining a function. |
|
2317 |
2891
|
2318 static octave_user_function * |
|
2319 finish_function (tree_identifier *id, octave_user_function *fcn) |
1623
|
2320 { |
2883
|
2321 tree_parameter_list *tpl = new tree_parameter_list (id); |
1623
|
2322 |
|
2323 tpl->mark_as_formal_parameters (); |
|
2324 |
|
2325 return fcn->define_ret_list (tpl); |
|
2326 } |
|
2327 |
|
2328 // Finish defining a function a different way. |
|
2329 |
2891
|
2330 static octave_user_function * |
|
2331 finish_function (tree_parameter_list *ret_list, octave_user_function *fcn) |
1623
|
2332 { |
|
2333 ret_list->mark_as_formal_parameters (); |
|
2334 |
|
2335 return fcn->define_ret_list (ret_list); |
|
2336 } |
|
2337 |
2883
|
2338 static void |
|
2339 recover_from_parsing_function (void) |
|
2340 { |
|
2341 curr_sym_tab = top_level_sym_tab; |
|
2342 |
|
2343 lexer_flags.defining_func = false; |
|
2344 lexer_flags.beginning_of_function = false; |
|
2345 lexer_flags.parsed_function_name = false; |
|
2346 lexer_flags.looking_at_return_list = false; |
|
2347 lexer_flags.looking_at_parameter_list = false; |
|
2348 } |
|
2349 |
2846
|
2350 // Make an index expression. |
|
2351 |
751
|
2352 static tree_index_expression * |
2970
|
2353 make_index_expression (tree_expression *expr, tree_argument_list *args) |
751
|
2354 { |
|
2355 tree_index_expression *retval = 0; |
|
2356 |
2970
|
2357 int l = expr->line (); |
|
2358 int c = expr->column (); |
|
2359 |
|
2360 expr->mark_postfix_indexed (); |
|
2361 |
|
2362 retval = new tree_index_expression (expr, args, l, c); |
|
2363 |
|
2364 return retval; |
|
2365 } |
|
2366 |
|
2367 // Make an indirect reference expression. |
|
2368 |
|
2369 static tree_indirect_ref * |
|
2370 make_indirect_ref (tree_expression *expr, const string& elt) |
|
2371 { |
|
2372 tree_indirect_ref *retval = 0; |
|
2373 |
|
2374 int l = expr->line (); |
|
2375 int c = expr->column (); |
|
2376 |
|
2377 retval = new tree_indirect_ref (expr, elt, l, c); |
|
2378 |
|
2379 lexer_flags.looking_at_indirect_ref = false; |
751
|
2380 |
|
2381 return retval; |
|
2382 } |
1511
|
2383 |
2846
|
2384 // Make a declaration command. |
|
2385 |
|
2386 static tree_decl_command * |
|
2387 make_decl_command (int tok, token *tok_val, tree_decl_init_list *lst) |
|
2388 { |
|
2389 tree_decl_command *retval = 0; |
|
2390 |
|
2391 int l = tok_val->line (); |
|
2392 int c = tok_val->column (); |
|
2393 |
|
2394 switch (tok) |
|
2395 { |
|
2396 case GLOBAL: |
|
2397 retval = new tree_global_command (lst, l, c); |
|
2398 break; |
|
2399 |
|
2400 case STATIC: |
|
2401 if (lexer_flags.defining_func) |
|
2402 retval = new tree_static_command (lst, l, c); |
|
2403 else |
|
2404 { |
|
2405 if (reading_script_file) |
|
2406 warning ("ignoring static declaration near line %d of file `%s'", |
|
2407 l, curr_fcn_file_full_name.c_str ()); |
|
2408 else |
|
2409 warning ("ignoring static declaration near line %d", l); |
|
2410 } |
|
2411 break; |
|
2412 |
|
2413 default: |
|
2414 panic_impossible (); |
|
2415 break; |
|
2416 } |
|
2417 |
|
2418 return retval; |
|
2419 } |
|
2420 |
1623
|
2421 // Finish building a matrix list. |
|
2422 |
|
2423 static tree_expression * |
1829
|
2424 finish_matrix (tree_matrix *m) |
1623
|
2425 { |
3110
|
2426 tree_expression *retval = m; |
|
2427 |
|
2428 unwind_protect::begin_frame ("finish_matrix"); |
|
2429 |
|
2430 unwind_protect_int (error_state); |
|
2431 |
|
2432 unwind_protect_bool (buffer_error_messages); |
|
2433 buffer_error_messages = true; |
|
2434 |
|
2435 unwind_protect::add (clear_global_error_variable, 0); |
1623
|
2436 |
2533
|
2437 if (m->all_elements_are_constant ()) |
1829
|
2438 { |
2970
|
2439 octave_value tmp = m->rvalue (); |
1623
|
2440 |
2533
|
2441 if (! error_state) |
|
2442 { |
|
2443 tree_constant *tc_retval = new tree_constant (tmp); |
|
2444 |
|
2445 ostrstream buf; |
|
2446 |
|
2447 tree_print_code tpc (buf); |
|
2448 |
|
2449 m->accept (tpc); |
|
2450 |
|
2451 buf << ends; |
1623
|
2452 |
2533
|
2453 char *s = buf.str (); |
|
2454 |
|
2455 tc_retval->stash_original_text (s); |
|
2456 |
|
2457 delete [] s; |
|
2458 |
|
2459 delete m; |
|
2460 |
|
2461 retval = tc_retval; |
|
2462 } |
1623
|
2463 } |
3110
|
2464 |
|
2465 unwind_protect::run_frame ("finish_matrix"); |
1623
|
2466 |
|
2467 return retval; |
|
2468 } |
|
2469 |
1511
|
2470 static void |
|
2471 maybe_warn_missing_semi (tree_statement_list *t) |
|
2472 { |
2166
|
2473 if (lexer_flags.defining_func && Vwarn_missing_semicolon) |
1511
|
2474 { |
|
2475 tree_statement *tmp = t->rear(); |
1607
|
2476 |
1511
|
2477 if (tmp->is_expression ()) |
1607
|
2478 warning ("missing semicolon near line %d, column %d in file `%s'", |
1755
|
2479 tmp->line (), tmp->column (), |
|
2480 curr_fcn_file_full_name.c_str ()); |
1511
|
2481 } |
|
2482 } |
1994
|
2483 |
2525
|
2484 static void |
|
2485 set_stmt_print_flag (tree_statement_list *list, char sep, |
|
2486 bool warn_missing_semi) |
|
2487 { |
|
2488 switch (sep) |
|
2489 { |
|
2490 case ';': |
|
2491 { |
|
2492 tree_statement *tmp = list->rear (); |
|
2493 tmp->set_print_flag (0); |
|
2494 } |
|
2495 break; |
|
2496 |
|
2497 case 0: |
|
2498 case ',': |
|
2499 case '\n': |
|
2500 if (warn_missing_semi) |
|
2501 maybe_warn_missing_semi (list); |
|
2502 break; |
|
2503 |
|
2504 default: |
|
2505 warning ("unrecognized separator type!"); |
|
2506 break; |
|
2507 } |
|
2508 } |
|
2509 |
3021
|
2510 void |
|
2511 parse_and_execute (FILE *f) |
|
2512 { |
|
2513 unwind_protect::begin_frame ("parse_and_execute"); |
|
2514 |
|
2515 YY_BUFFER_STATE old_buf = current_buffer (); |
|
2516 YY_BUFFER_STATE new_buf = create_buffer (f); |
|
2517 |
|
2518 unwind_protect::add (restore_input_buffer, old_buf); |
|
2519 unwind_protect::add (delete_input_buffer, new_buf); |
|
2520 |
|
2521 switch_to_buffer (new_buf); |
|
2522 |
|
2523 unwind_protect_bool (line_editing); |
|
2524 unwind_protect_bool (input_from_command_line_file); |
|
2525 |
|
2526 line_editing = false; |
|
2527 input_from_command_line_file = false; |
|
2528 |
|
2529 unwind_protect_ptr (curr_sym_tab); |
|
2530 |
|
2531 int retval; |
|
2532 do |
|
2533 { |
|
2534 reset_parser (); |
|
2535 |
|
2536 retval = yyparse (); |
|
2537 |
|
2538 if (retval == 0 && global_command) |
|
2539 { |
|
2540 global_command->eval (); |
|
2541 |
|
2542 delete global_command; |
|
2543 |
|
2544 global_command = 0; |
|
2545 |
|
2546 bool quit = (tree_return_command::returning |
|
2547 || tree_break_command::breaking); |
|
2548 |
|
2549 if (tree_return_command::returning) |
|
2550 tree_return_command::returning = 0; |
|
2551 |
|
2552 if (tree_break_command::breaking) |
|
2553 tree_break_command::breaking--; |
|
2554 |
|
2555 if (error_state) |
|
2556 { |
|
2557 error ("near line %d of file `%s'", input_line_number, |
|
2558 curr_fcn_file_full_name.c_str ()); |
|
2559 |
|
2560 break; |
|
2561 } |
|
2562 |
|
2563 if (quit) |
|
2564 break; |
|
2565 } |
|
2566 } |
|
2567 while (retval == 0); |
|
2568 |
|
2569 unwind_protect::run_frame ("parse_and_execute"); |
|
2570 } |
|
2571 |
|
2572 static void |
|
2573 safe_fclose (void *f) |
|
2574 { |
|
2575 if (f) |
|
2576 fclose (static_cast<FILE *> (f)); |
|
2577 } |
|
2578 |
|
2579 void |
|
2580 parse_and_execute (const string& s, bool verbose, const char *warn_for) |
|
2581 { |
|
2582 unwind_protect::begin_frame ("parse_and_execute_2"); |
|
2583 |
|
2584 unwind_protect_bool (reading_script_file); |
|
2585 unwind_protect_str (curr_fcn_file_full_name); |
|
2586 |
|
2587 reading_script_file = true; |
|
2588 curr_fcn_file_full_name = s; |
|
2589 |
|
2590 FILE *f = get_input_from_file (s, 0); |
|
2591 |
|
2592 if (f) |
|
2593 { |
|
2594 unwind_protect::add (safe_fclose, f); |
|
2595 |
|
2596 unwind_protect_int (input_line_number); |
|
2597 unwind_protect_int (current_input_column); |
|
2598 |
|
2599 input_line_number = 0; |
|
2600 current_input_column = 1; |
|
2601 |
|
2602 if (verbose) |
|
2603 { |
|
2604 cout << "reading commands from " << s << " ... "; |
|
2605 reading_startup_message_printed = true; |
|
2606 cout.flush (); |
|
2607 } |
|
2608 |
|
2609 parse_and_execute (f); |
|
2610 |
|
2611 if (verbose) |
|
2612 cout << "done." << endl; |
|
2613 } |
|
2614 else if (warn_for) |
|
2615 error ("%s: unable to open file `%s'", warn_for, s.c_str ()); |
|
2616 |
|
2617 unwind_protect::run_frame ("parse_and_execute_2"); |
|
2618 } |
|
2619 |
|
2620 static bool |
|
2621 looks_like_octave_copyright (const string& s) |
|
2622 { |
|
2623 bool retval = false; |
|
2624 |
|
2625 string t = s.substr (0, 15); |
|
2626 |
|
2627 if (t == " Copyright (C) ") |
|
2628 { |
|
2629 size_t pos = s.find ('\n'); |
|
2630 |
|
2631 if (pos != NPOS) |
|
2632 { |
|
2633 pos = s.find ('\n', pos + 1); |
|
2634 |
|
2635 if (pos != NPOS) |
|
2636 { |
|
2637 pos++; |
|
2638 |
|
2639 t = s.substr (pos, 29); |
|
2640 |
|
2641 if (t == " This file is part of Octave." |
|
2642 || t == " This program is free softwar") |
|
2643 retval = true; |
|
2644 } |
|
2645 } |
|
2646 } |
|
2647 |
|
2648 return retval; |
|
2649 } |
|
2650 |
|
2651 // Eat whitespace and comments from FFILE, returning the text of the |
|
2652 // comments read if it doesn't look like a copyright notice. If |
|
2653 // IN_PARTS, consider each block of comments separately; otherwise, |
|
2654 // grab them all at once. If UPDATE_POS is TRUE, line and column |
|
2655 // number information is updated. |
|
2656 |
|
2657 // XXX FIXME XXX -- grab_help_text() in lex.l duplicates some of this |
|
2658 // code! |
|
2659 |
|
2660 static string |
|
2661 gobble_leading_white_space (FILE *ffile, bool in_parts, bool update_pos) |
|
2662 { |
|
2663 string help_txt; |
|
2664 |
|
2665 bool first_comments_seen = false; |
|
2666 bool begin_comment = false; |
|
2667 bool have_help_text = false; |
|
2668 bool in_comment = false; |
|
2669 int c; |
|
2670 |
|
2671 while ((c = getc (ffile)) != EOF) |
|
2672 { |
|
2673 if (update_pos) |
|
2674 current_input_column++; |
|
2675 |
|
2676 if (begin_comment) |
|
2677 { |
|
2678 if (c == '%' || c == '#') |
|
2679 continue; |
|
2680 else |
|
2681 begin_comment = false; |
|
2682 } |
|
2683 |
|
2684 if (in_comment) |
|
2685 { |
|
2686 if (! have_help_text) |
|
2687 { |
|
2688 first_comments_seen = true; |
|
2689 help_txt += (char) c; |
|
2690 } |
|
2691 |
|
2692 if (c == '\n') |
|
2693 { |
|
2694 if (update_pos) |
|
2695 { |
|
2696 input_line_number++; |
|
2697 current_input_column = 0; |
|
2698 } |
|
2699 in_comment = false; |
|
2700 |
|
2701 if (in_parts) |
|
2702 { |
|
2703 if ((c = getc (ffile)) != EOF) |
|
2704 { |
|
2705 if (update_pos) |
|
2706 current_input_column--; |
|
2707 ungetc (c, ffile); |
|
2708 if (c == '\n') |
|
2709 break; |
|
2710 } |
|
2711 else |
|
2712 break; |
|
2713 } |
|
2714 } |
|
2715 } |
|
2716 else |
|
2717 { |
|
2718 switch (c) |
|
2719 { |
|
2720 case ' ': |
|
2721 case '\t': |
|
2722 if (first_comments_seen) |
|
2723 have_help_text = true; |
|
2724 break; |
|
2725 |
|
2726 case '\n': |
|
2727 if (first_comments_seen) |
|
2728 have_help_text = true; |
|
2729 if (update_pos) |
|
2730 { |
|
2731 input_line_number++; |
|
2732 current_input_column = 0; |
|
2733 } |
|
2734 continue; |
|
2735 |
|
2736 case '%': |
|
2737 case '#': |
|
2738 begin_comment = true; |
|
2739 in_comment = true; |
|
2740 break; |
|
2741 |
|
2742 default: |
|
2743 if (update_pos) |
|
2744 current_input_column--; |
|
2745 ungetc (c, ffile); |
|
2746 goto done; |
|
2747 } |
|
2748 } |
|
2749 } |
|
2750 |
|
2751 done: |
|
2752 |
|
2753 if (! help_txt.empty ()) |
|
2754 { |
|
2755 if (looks_like_octave_copyright (help_txt)) |
|
2756 help_txt.resize (0); |
|
2757 |
|
2758 if (in_parts && help_txt.empty ()) |
|
2759 help_txt = gobble_leading_white_space (ffile, in_parts, update_pos); |
|
2760 } |
|
2761 |
|
2762 return help_txt; |
|
2763 } |
|
2764 |
|
2765 string |
|
2766 get_help_from_file (const string& path) |
|
2767 { |
|
2768 string retval; |
|
2769 |
|
2770 if (! path.empty ()) |
|
2771 { |
|
2772 FILE *fptr = fopen (path.c_str (), "r"); |
|
2773 |
|
2774 if (fptr) |
|
2775 { |
|
2776 unwind_protect::add (safe_fclose, (void *) fptr); |
|
2777 |
|
2778 retval = gobble_leading_white_space (fptr, true, true); |
|
2779 |
|
2780 unwind_protect::run (); |
|
2781 } |
|
2782 } |
|
2783 |
|
2784 return retval; |
|
2785 } |
|
2786 |
|
2787 static int |
|
2788 is_function_file (FILE *ffile) |
|
2789 { |
|
2790 int status = 0; |
|
2791 |
|
2792 long pos = ftell (ffile); |
|
2793 |
|
2794 gobble_leading_white_space (ffile, false, false); |
|
2795 |
|
2796 char buf [10]; |
|
2797 fgets (buf, 10, ffile); |
|
2798 int len = strlen (buf); |
|
2799 if (len > 8 && strncmp (buf, "function", 8) == 0 |
|
2800 && ! (isalnum (buf[8]) || buf[8] == '_')) |
|
2801 status = 1; |
|
2802 |
|
2803 fseek (ffile, pos, SEEK_SET); |
|
2804 |
|
2805 return status; |
|
2806 } |
|
2807 |
|
2808 static void |
|
2809 restore_command_history (void *) |
|
2810 { |
|
2811 command_history::ignore_entries (! Vsaving_history); |
|
2812 } |
|
2813 |
|
2814 static void |
|
2815 restore_input_stream (void *f) |
|
2816 { |
|
2817 command_editor::set_input_stream (static_cast<FILE *> (f)); |
|
2818 } |
|
2819 |
3180
|
2820 static void |
|
2821 clear_current_script_file_name (void *) |
|
2822 { |
|
2823 bind_builtin_variable ("current_script_file_name", octave_value ()); |
|
2824 } |
|
2825 |
3021
|
2826 static bool |
3165
|
2827 parse_fcn_file (const string& ff, bool exec_script, bool force_script = false) |
3021
|
2828 { |
|
2829 unwind_protect::begin_frame ("parse_fcn_file"); |
|
2830 |
|
2831 int script_file_executed = false; |
|
2832 |
|
2833 // Open function file and parse. |
|
2834 |
|
2835 bool old_reading_fcn_file_state = reading_fcn_file; |
|
2836 |
|
2837 FILE *in_stream = command_editor::get_input_stream (); |
|
2838 |
|
2839 unwind_protect::add (restore_input_stream, in_stream); |
|
2840 |
|
2841 unwind_protect_ptr (ff_instream); |
|
2842 |
|
2843 unwind_protect_int (input_line_number); |
|
2844 unwind_protect_int (current_input_column); |
|
2845 unwind_protect_bool (reading_fcn_file); |
|
2846 unwind_protect_bool (line_editing); |
|
2847 |
|
2848 input_line_number = 0; |
|
2849 current_input_column = 1; |
|
2850 reading_fcn_file = true; |
|
2851 line_editing = false; |
|
2852 |
|
2853 FILE *ffile = get_input_from_file (ff, 0); |
|
2854 |
|
2855 unwind_protect::add (safe_fclose, ffile); |
|
2856 |
|
2857 if (ffile) |
|
2858 { |
|
2859 // Check to see if this file defines a function or is just a |
|
2860 // list of commands. |
|
2861 |
3165
|
2862 if (! force_script && is_function_file (ffile)) |
3021
|
2863 { |
|
2864 // XXX FIXME XXX -- we shouldn't need both the |
|
2865 // command_history object and the |
|
2866 // Vsaving_history variable... |
|
2867 command_history::ignore_entries (); |
|
2868 |
|
2869 unwind_protect::add (restore_command_history, 0); |
|
2870 |
|
2871 unwind_protect_int (Vecho_executing_commands); |
|
2872 unwind_protect_bool (Vsaving_history); |
|
2873 unwind_protect_bool (reading_fcn_file); |
|
2874 unwind_protect_bool (input_from_command_line_file); |
|
2875 |
|
2876 Vecho_executing_commands = ECHO_OFF; |
|
2877 Vsaving_history = false; |
|
2878 reading_fcn_file = true; |
|
2879 input_from_command_line_file = false; |
|
2880 |
|
2881 YY_BUFFER_STATE old_buf = current_buffer (); |
|
2882 YY_BUFFER_STATE new_buf = create_buffer (ffile); |
|
2883 |
|
2884 unwind_protect::add (restore_input_buffer, (void *) old_buf); |
|
2885 unwind_protect::add (delete_input_buffer, (void *) new_buf); |
|
2886 |
|
2887 switch_to_buffer (new_buf); |
|
2888 |
|
2889 unwind_protect_ptr (curr_sym_tab); |
|
2890 |
|
2891 reset_parser (); |
|
2892 |
|
2893 help_buf = gobble_leading_white_space (ffile, true, true); |
|
2894 |
|
2895 // XXX FIXME XXX -- this should not be necessary. |
|
2896 gobble_leading_white_space (ffile, false, true); |
|
2897 |
|
2898 int status = yyparse (); |
|
2899 |
|
2900 if (status != 0) |
|
2901 { |
|
2902 error ("parse error while reading function file %s", |
|
2903 ff.c_str ()); |
|
2904 global_sym_tab->clear (curr_fcn_file_name); |
|
2905 } |
|
2906 } |
|
2907 else if (exec_script) |
|
2908 { |
|
2909 // The value of `reading_fcn_file' will be restored to the |
|
2910 // proper value when we unwind from this frame. |
|
2911 reading_fcn_file = old_reading_fcn_file_state; |
|
2912 |
|
2913 // XXX FIXME XXX -- we shouldn't need both the |
|
2914 // command_history object and the |
|
2915 // Vsaving_history variable... |
|
2916 command_history::ignore_entries (); |
|
2917 |
|
2918 unwind_protect::add (restore_command_history, 0); |
|
2919 |
|
2920 unwind_protect_bool (Vsaving_history); |
|
2921 unwind_protect_bool (reading_script_file); |
|
2922 |
|
2923 Vsaving_history = false; |
|
2924 reading_script_file = true; |
|
2925 |
3180
|
2926 unwind_protect::add (clear_current_script_file_name, 0); |
|
2927 |
|
2928 bind_builtin_variable ("current_script_file_name", ff); |
|
2929 |
3021
|
2930 parse_and_execute (ffile); |
|
2931 |
|
2932 script_file_executed = true; |
|
2933 } |
|
2934 } |
|
2935 |
|
2936 unwind_protect::run_frame ("parse_fcn_file"); |
|
2937 |
|
2938 return script_file_executed; |
|
2939 } |
|
2940 |
|
2941 bool |
|
2942 load_fcn_from_file (symbol_record *sym_rec, bool exec_script) |
|
2943 { |
|
2944 bool script_file_executed = false; |
|
2945 |
|
2946 string nm = sym_rec->name (); |
|
2947 |
|
2948 if (octave_dynamic_loader::load_fcn_from_dot_oct_file (nm)) |
|
2949 { |
|
2950 force_link_to_function (nm); |
|
2951 } |
|
2952 else |
|
2953 { |
|
2954 string ff = fcn_file_in_path (nm); |
|
2955 |
|
2956 // These are needed by yyparse. |
|
2957 |
|
2958 unwind_protect::begin_frame ("load_fcn_from_file"); |
|
2959 |
|
2960 unwind_protect_str (curr_fcn_file_name); |
|
2961 unwind_protect_str (curr_fcn_file_full_name); |
|
2962 |
|
2963 curr_fcn_file_name = nm; |
|
2964 curr_fcn_file_full_name = ff; |
|
2965 |
|
2966 if (ff.length () > 0) |
3165
|
2967 script_file_executed = parse_fcn_file (ff, exec_script); |
3021
|
2968 |
|
2969 if (! (error_state || script_file_executed)) |
|
2970 force_link_to_function (nm); |
|
2971 |
|
2972 unwind_protect::run_frame ("load_fcn_from_file"); |
|
2973 } |
|
2974 |
|
2975 return script_file_executed; |
|
2976 } |
|
2977 |
|
2978 DEFUN (source, args, , |
|
2979 "source (FILE)\n\ |
|
2980 \n\ |
|
2981 Parse and execute the contents of FILE. Like executing commands in a\n\ |
|
2982 script file but without requiring the file to be named `FILE.m'.") |
|
2983 { |
|
2984 octave_value_list retval; |
|
2985 |
|
2986 int nargin = args.length (); |
|
2987 |
|
2988 if (nargin == 1) |
|
2989 { |
|
2990 string file = args(0).string_value (); |
|
2991 |
|
2992 if (! error_state) |
|
2993 { |
|
2994 file = file_ops::tilde_expand (file); |
|
2995 |
3165
|
2996 parse_fcn_file (file, true, true); |
3021
|
2997 |
|
2998 if (error_state) |
|
2999 error ("source: error sourcing file `%s'", file.c_str ()); |
|
3000 } |
|
3001 else |
|
3002 error ("source: expecting file name as argument"); |
|
3003 } |
|
3004 else |
|
3005 print_usage ("source"); |
|
3006 |
|
3007 return retval; |
|
3008 } |
|
3009 |
|
3010 octave_value_list |
3156
|
3011 feval (const string& name, const octave_value_list& args, int nargout) |
|
3012 { |
|
3013 octave_value_list retval; |
|
3014 |
|
3015 octave_function *fcn = is_valid_function (name, "feval", 1); |
|
3016 |
|
3017 if (fcn) |
|
3018 retval = fcn->do_index_op (nargout, args); |
|
3019 |
|
3020 return retval; |
|
3021 } |
|
3022 |
|
3023 octave_value_list |
3021
|
3024 feval (const octave_value_list& args, int nargout) |
|
3025 { |
|
3026 octave_value_list retval; |
|
3027 |
3156
|
3028 if (args.length () > 0) |
3021
|
3029 { |
3156
|
3030 string name = args(0).string_value (); |
|
3031 |
|
3032 if (! error_state) |
3021
|
3033 { |
3156
|
3034 int tmp_nargin = args.length () - 1; |
|
3035 |
|
3036 octave_value_list tmp_args (tmp_nargin, octave_value ()); |
|
3037 |
|
3038 for (int i = 0; i < tmp_nargin; i++) |
3178
|
3039 tmp_args(i) = args(i+1); |
|
3040 |
|
3041 string_vector arg_names = args.name_tags (); |
|
3042 |
|
3043 if (! arg_names.empty ()) |
3156
|
3044 { |
3178
|
3045 assert (arg_names.length () == tmp_nargin + 1); |
|
3046 |
|
3047 string_vector tmp_arg_names (tmp_nargin); |
|
3048 |
|
3049 for (int i = 0; i < tmp_nargin; i++) |
|
3050 tmp_arg_names(i) = arg_names(i+1); |
|
3051 |
|
3052 tmp_args.stash_name_tags (tmp_arg_names); |
3156
|
3053 } |
|
3054 |
|
3055 retval = feval (name, tmp_args, nargout); |
3021
|
3056 } |
|
3057 } |
|
3058 |
|
3059 return retval; |
|
3060 } |
|
3061 |
|
3062 DEFUN (feval, args, nargout, |
|
3063 "feval (NAME, ARGS, ...)\n\ |
|
3064 \n\ |
|
3065 evaluate NAME as a function, passing ARGS as its arguments") |
|
3066 { |
|
3067 octave_value_list retval; |
|
3068 |
|
3069 int nargin = args.length (); |
|
3070 |
|
3071 if (nargin > 0) |
|
3072 retval = feval (args, nargout); |
|
3073 else |
|
3074 print_usage ("feval"); |
|
3075 |
|
3076 return retval; |
|
3077 } |
|
3078 |
3099
|
3079 octave_value_list |
3021
|
3080 eval_string (const string& s, bool silent, int& parse_status, int nargout) |
|
3081 { |
|
3082 unwind_protect::begin_frame ("eval_string"); |
|
3083 |
|
3084 unwind_protect_bool (get_input_from_eval_string); |
|
3085 unwind_protect_bool (input_from_command_line_file); |
|
3086 unwind_protect_ptr (global_command); |
|
3087 unwind_protect_str (current_eval_string); |
|
3088 |
|
3089 get_input_from_eval_string = true; |
|
3090 input_from_command_line_file = false; |
|
3091 current_eval_string = s; |
|
3092 |
|
3093 YY_BUFFER_STATE old_buf = current_buffer (); |
|
3094 YY_BUFFER_STATE new_buf = create_buffer (0); |
|
3095 |
|
3096 unwind_protect::add (restore_input_buffer, old_buf); |
|
3097 unwind_protect::add (delete_input_buffer, new_buf); |
|
3098 |
|
3099 switch_to_buffer (new_buf); |
|
3100 |
|
3101 unwind_protect_ptr (curr_sym_tab); |
|
3102 |
|
3103 reset_parser (); |
|
3104 |
|
3105 parse_status = yyparse (); |
|
3106 |
|
3107 // Important to reset the idea of where input is coming from before |
|
3108 // trying to eval the command we just parsed -- it might contain the |
|
3109 // name of an function file that still needs to be parsed! |
|
3110 |
|
3111 tree_statement_list *command = global_command; |
|
3112 |
|
3113 unwind_protect::run_frame ("eval_string"); |
|
3114 |
|
3115 octave_value_list retval; |
|
3116 |
|
3117 if (parse_status == 0 && command) |
|
3118 { |
|
3119 retval = command->eval (silent, nargout); |
|
3120 delete command; |
|
3121 } |
|
3122 |
|
3123 return retval; |
|
3124 } |
|
3125 |
|
3126 octave_value |
|
3127 eval_string (const string& s, bool silent, int& parse_status) |
|
3128 { |
|
3129 octave_value retval; |
|
3130 |
|
3131 octave_value_list tmp = eval_string (s, silent, parse_status, 1); |
|
3132 |
|
3133 if (! tmp.empty ()) |
|
3134 retval = tmp(0); |
|
3135 |
|
3136 return retval; |
|
3137 } |
|
3138 |
|
3139 static octave_value_list |
|
3140 eval_string (const octave_value& arg, bool silent, int& parse_status, |
|
3141 int nargout) |
|
3142 { |
|
3143 string s = arg.string_value (); |
|
3144 |
|
3145 if (error_state) |
|
3146 { |
|
3147 error ("eval: expecting string argument"); |
|
3148 return -1.0; |
|
3149 } |
|
3150 |
|
3151 return eval_string (s, silent, parse_status, nargout); |
|
3152 } |
|
3153 |
|
3154 DEFUN (eval, args, nargout, |
|
3155 "eval (TRY, CATCH)\n\ |
|
3156 \n\ |
|
3157 Evaluate the string TRY as octave code. If that fails, evaluate the\n\ |
|
3158 string CATCH.") |
|
3159 { |
|
3160 octave_value_list retval; |
|
3161 |
|
3162 int nargin = args.length (); |
|
3163 |
|
3164 if (nargin > 0) |
|
3165 { |
|
3166 unwind_protect::begin_frame ("Feval"); |
|
3167 |
|
3168 if (nargin > 1) |
|
3169 { |
|
3170 unwind_protect_bool (buffer_error_messages); |
|
3171 buffer_error_messages = true; |
|
3172 } |
|
3173 |
|
3174 int parse_status = 0; |
|
3175 |
|
3176 retval = eval_string (args(0), ! Vdefault_eval_print_flag, |
|
3177 parse_status, nargout); |
|
3178 |
|
3179 if (nargin > 1 && (parse_status != 0 || error_state)) |
|
3180 { |
|
3181 error_state = 0; |
|
3182 |
|
3183 // Set up for letting the user print any messages from |
|
3184 // errors that occurred in the first part of this eval(). |
|
3185 |
|
3186 buffer_error_messages = false; |
|
3187 bind_global_error_variable (); |
|
3188 unwind_protect::add (clear_global_error_variable, 0); |
|
3189 |
|
3190 eval_string (args(1), 0, parse_status, nargout); |
|
3191 |
|
3192 retval = octave_value_list (); |
|
3193 } |
|
3194 |
|
3195 unwind_protect::run_frame ("Feval"); |
|
3196 } |
|
3197 else |
|
3198 print_usage ("eval"); |
|
3199 |
|
3200 return retval; |
|
3201 } |
|
3202 |
|
3203 static int |
|
3204 default_eval_print_flag (void) |
|
3205 { |
|
3206 Vdefault_eval_print_flag = check_preference ("default_eval_print_flag"); |
|
3207 |
|
3208 return 0; |
|
3209 } |
|
3210 |
2166
|
3211 static int |
|
3212 warn_assign_as_truth_value (void) |
|
3213 { |
|
3214 Vwarn_assign_as_truth_value |
|
3215 = check_preference ("warn_assign_as_truth_value"); |
|
3216 |
|
3217 return 0; |
|
3218 } |
|
3219 |
|
3220 static int |
|
3221 warn_function_name_clash (void) |
|
3222 { |
|
3223 Vwarn_function_name_clash = check_preference ("warn_function_name_clash"); |
|
3224 |
|
3225 return 0; |
|
3226 } |
|
3227 |
|
3228 static int |
3162
|
3229 warn_future_time_stamp (void) |
|
3230 { |
|
3231 Vwarn_future_time_stamp = check_preference ("warn_future_time_stamp"); |
|
3232 |
|
3233 return 0; |
|
3234 } |
|
3235 |
|
3236 static int |
2166
|
3237 warn_missing_semicolon (void) |
|
3238 { |
|
3239 Vwarn_missing_semicolon = check_preference ("warn_missing_semicolon"); |
|
3240 |
|
3241 return 0; |
|
3242 } |
|
3243 |
2764
|
3244 static int |
|
3245 warn_variable_switch_label (void) |
|
3246 { |
|
3247 Vwarn_variable_switch_label |
|
3248 = check_preference ("warn_variable_switch_label"); |
|
3249 |
|
3250 return 0; |
|
3251 } |
|
3252 |
2166
|
3253 void |
|
3254 symbols_of_parse (void) |
|
3255 { |
3021
|
3256 DEFVAR (default_eval_print_flag, 1.0, 0, default_eval_print_flag, |
|
3257 "If the value of this variable is nonzero, Octave will print the\n\ |
|
3258 results of commands executed by eval() that do not end with semicolons."); |
|
3259 |
2166
|
3260 DEFVAR (warn_assign_as_truth_value, 1.0, 0, warn_assign_as_truth_value, |
|
3261 "produce warning for assignments used as truth values"); |
|
3262 |
|
3263 DEFVAR (warn_function_name_clash, 1.0, 0, warn_function_name_clash, |
|
3264 "produce warning if function name conflicts with file name"); |
|
3265 |
3162
|
3266 DEFVAR (warn_future_time_stamp, 1.0, 0, warn_future_time_stamp, |
|
3267 "warn if a function file has a time stamp that is in the future"); |
|
3268 |
2166
|
3269 DEFVAR (warn_missing_semicolon, 0.0, 0, warn_missing_semicolon, |
2764
|
3270 "produce a warning if a statement in a function file is not\n\ |
2166
|
3271 terminated with a semicolon"); |
2764
|
3272 |
|
3273 DEFVAR (warn_variable_switch_label, 0.0, 0, warn_variable_switch_label, |
|
3274 "produce warning for variables used as switch labels"); |
2166
|
3275 } |
|
3276 |
1994
|
3277 /* |
|
3278 ;;; Local Variables: *** |
|
3279 ;;; mode: text *** |
|
3280 ;;; End: *** |
|
3281 */ |