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