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