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