Mercurial > octave-antonio
annotate src/parse.y @ 8745:6dc61981d18b
better handling of object indexing in lexer
author | John W. Eaton <jwe@octave.org> |
---|---|
date | Sun, 15 Feb 2009 16:31:16 -0500 |
parents | 1652e39b934e |
children | 5dd06f19e9be |
rev | line source |
---|---|
1829 | 1 /* |
1 | 2 |
7017 | 3 Copyright (C) 1993, 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001, |
7351 | 4 2002, 2003, 2004, 2005, 2006, 2007, 2008 John W. Eaton |
1 | 5 |
6 This file is part of Octave. | |
7 | |
8 Octave is free software; you can redistribute it and/or modify it | |
9 under the terms of the GNU General Public License as published by the | |
7016 | 10 Free Software Foundation; either version 3 of the License, or (at your |
11 option) any later version. | |
1 | 12 |
13 Octave is distributed in the hope that it will be useful, but WITHOUT | |
14 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | |
15 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License | |
16 for more details. | |
17 | |
18 You should have received a copy of the GNU General Public License | |
7016 | 19 along with Octave; see the file COPYING. If not, see |
20 <http://www.gnu.org/licenses/>. | |
1 | 21 |
22 */ | |
23 | |
24 // Parser for Octave. | |
25 | |
767 | 26 // C decarations. |
27 | |
1 | 28 %{ |
29 #define YYDEBUG 1 | |
30 | |
240 | 31 #ifdef HAVE_CONFIG_H |
1229 | 32 #include <config.h> |
240 | 33 #endif |
34 | |
3178 | 35 #include <cassert> |
3156 | 36 #include <cstdio> |
37 | |
2427 | 38 #ifdef YYBYACC |
39 #include <cstdlib> | |
40 #endif | |
41 | |
5484 | 42 #include <map> |
5765 | 43 #include <sstream> |
5484 | 44 |
3928 | 45 #include "Cell.h" |
1 | 46 #include "Matrix.h" |
3021 | 47 #include "cmd-edit.h" |
48 #include "cmd-hist.h" | |
49 #include "file-ops.h" | |
50 #include "file-stat.h" | |
4243 | 51 #include "oct-env.h" |
3712 | 52 #include "oct-time.h" |
4171 | 53 #include "quit.h" |
1 | 54 |
3665 | 55 #include "comment-list.h" |
4243 | 56 #include "defaults.h" |
2166 | 57 #include "defun.h" |
4243 | 58 #include "dirfns.h" |
3021 | 59 #include "dynamic-ld.h" |
1351 | 60 #include "error.h" |
61 #include "input.h" | |
62 #include "lex.h" | |
5832 | 63 #include "load-path.h" |
1743 | 64 #include "oct-hist.h" |
5626 | 65 #include "oct-map.h" |
4935 | 66 #include "ov-fcn-handle.h" |
2970 | 67 #include "ov-usr-fcn.h" |
8150
283989f2da9b
make null assignment matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
8064
diff
changeset
|
68 #include "ov-null-mat.h" |
1670 | 69 #include "toplev.h" |
1351 | 70 #include "pager.h" |
71 #include "parse.h" | |
2987 | 72 #include "pt-all.h" |
8658
73c4516fae10
New evaluator and debugger derived from tree-walker class
John W. Eaton <jwe@octave.org>
parents:
8471
diff
changeset
|
73 #include "pt-eval.h" |
1351 | 74 #include "symtab.h" |
75 #include "token.h" | |
3021 | 76 #include "unwind-prot.h" |
1 | 77 #include "utils.h" |
1351 | 78 #include "variables.h" |
1 | 79 |
80 // The current input line number. | |
8447
adab48231a03
make input_line_number work again
John W. Eaton <jwe@octave.org>
parents:
8311
diff
changeset
|
81 int input_line_number = 1; |
1 | 82 |
83 // The column of the current token. | |
143 | 84 int current_input_column = 1; |
1 | 85 |
338 | 86 // Buffer for help text snagged from function files. |
4426 | 87 std::stack<std::string> help_buf; |
1 | 88 |
3665 | 89 // Buffer for comments appearing before a function statement. |
90 static std::string fcn_comment_header; | |
91 | |
3021 | 92 // TRUE means we are using readline. |
93 // (--no-line-editing) | |
94 bool line_editing = true; | |
95 | |
96 // TRUE means we printed messages about reading startup files. | |
97 bool reading_startup_message_printed = false; | |
98 | |
99 // TRUE means input is coming from startup file. | |
100 bool input_from_startup_file = false; | |
101 | |
4238 | 102 // Keep a count of how many END tokens we expect. |
103 int end_tokens_expected = 0; | |
104 | |
3903 | 105 // Keep track of symbol table information when parsing functions. |
7336 | 106 std::stack<symbol_table::scope_id> symtab_context; |
4238 | 107 |
108 // Name of parent function when parsing function files that might | |
109 // contain nested functions. | |
110 std::string parent_function_name; | |
3903 | 111 |
7336 | 112 // Name of the current class when we are parsing class methods or |
113 // constructors. | |
114 std::string current_class_name; | |
115 | |
5484 | 116 // TRUE means we are in the process of autoloading a function. |
117 static bool autoloading = false; | |
118 | |
6323 | 119 // TRUE means the current function file was found in a relative path |
120 // element. | |
121 static bool fcn_file_from_relative_lookup = false; | |
122 | |
7336 | 123 // If nonzero, this is a pointer to the function we just finished |
124 // parsing. | |
125 static octave_function *curr_fcn_ptr = 0; | |
126 | |
5484 | 127 // List of autoloads (function -> file mapping). |
128 static std::map<std::string, std::string> autoload_map; | |
129 | |
496 | 130 // Forward declarations for some functions defined at the bottom of |
131 // the file. | |
132 | |
133 // Generic error messages. | |
2970 | 134 static void |
135 yyerror (const char *s); | |
1 | 136 |
578 | 137 // Error mesages for mismatched end tokens. |
2970 | 138 static void |
139 end_error (const char *type, token::end_tok_type ettype, int l, int c); | |
1 | 140 |
578 | 141 // Check to see that end tokens are properly matched. |
2970 | 142 static bool |
143 end_token_ok (token *tok, token::end_tok_type expected); | |
496 | 144 |
145 // Maybe print a warning if an assignment expression is used as the | |
146 // test in a logical expression. | |
2970 | 147 static void |
148 maybe_warn_assign_as_truth_value (tree_expression *expr); | |
1 | 149 |
2764 | 150 // Maybe print a warning about switch labels that aren't constants. |
2970 | 151 static void |
152 maybe_warn_variable_switch_label (tree_expression *expr); | |
2764 | 153 |
1623 | 154 // Finish building a range. |
2970 | 155 static tree_expression * |
156 finish_colon_expression (tree_colon_expression *e); | |
1623 | 157 |
1607 | 158 // Build a constant. |
2970 | 159 static tree_constant * |
160 make_constant (int op, token *tok_val); | |
1607 | 161 |
4342 | 162 // Build a function handle. |
163 static tree_fcn_handle * | |
164 make_fcn_handle (token *tok_val); | |
165 | |
4935 | 166 // Build an anonymous function handle. |
5861 | 167 static tree_anon_fcn_handle * |
4935 | 168 make_anon_fcn_handle (tree_parameter_list *param_list, tree_statement *stmt); |
169 | |
578 | 170 // Build a binary expression. |
2970 | 171 static tree_expression * |
172 make_binary_op (int op, tree_expression *op1, token *tok_val, | |
173 tree_expression *op2); | |
578 | 174 |
2375 | 175 // Build a boolean expression. |
2970 | 176 static tree_expression * |
177 make_boolean_op (int op, tree_expression *op1, token *tok_val, | |
178 tree_expression *op2); | |
2375 | 179 |
578 | 180 // Build a prefix expression. |
2970 | 181 static tree_expression * |
182 make_prefix_op (int op, tree_expression *op1, token *tok_val); | |
578 | 183 |
184 // Build a postfix expression. | |
2970 | 185 static tree_expression * |
186 make_postfix_op (int op, tree_expression *op1, token *tok_val); | |
578 | 187 |
1623 | 188 // Build an unwind-protect command. |
2970 | 189 static tree_command * |
190 make_unwind_command (token *unwind_tok, tree_statement_list *body, | |
3665 | 191 tree_statement_list *cleanup, token *end_tok, |
192 octave_comment_list *lc, octave_comment_list *mc); | |
1623 | 193 |
194 // Build a try-catch command. | |
2970 | 195 static tree_command * |
196 make_try_command (token *try_tok, tree_statement_list *body, | |
3665 | 197 tree_statement_list *cleanup, token *end_tok, |
198 octave_comment_list *lc, octave_comment_list *mc); | |
1623 | 199 |
200 // Build a while command. | |
2970 | 201 static tree_command * |
202 make_while_command (token *while_tok, tree_expression *expr, | |
3665 | 203 tree_statement_list *body, token *end_tok, |
204 octave_comment_list *lc); | |
1623 | 205 |
3484 | 206 // Build a do-until command. |
207 static tree_command * | |
8658
73c4516fae10
New evaluator and debugger derived from tree-walker class
John W. Eaton <jwe@octave.org>
parents:
8471
diff
changeset
|
208 make_do_until_command (token *until_tok, tree_statement_list *body, |
3665 | 209 tree_expression *expr, octave_comment_list *lc); |
3484 | 210 |
1623 | 211 // Build a for command. |
2970 | 212 static tree_command * |
213 make_for_command (token *for_tok, tree_argument_list *lhs, | |
214 tree_expression *expr, tree_statement_list *body, | |
3665 | 215 token *end_tok, octave_comment_list *lc); |
1623 | 216 |
4207 | 217 // Build a break command. |
218 static tree_command * | |
219 make_break_command (token *break_tok); | |
220 | |
221 // Build a continue command. | |
222 static tree_command * | |
223 make_continue_command (token *continue_tok); | |
224 | |
225 // Build a return command. | |
226 static tree_command * | |
227 make_return_command (token *return_tok); | |
1623 | 228 |
229 // Start an if command. | |
2970 | 230 static tree_if_command_list * |
231 start_if_command (tree_expression *expr, tree_statement_list *list); | |
1623 | 232 |
233 // Finish an if command. | |
2970 | 234 static tree_if_command * |
3665 | 235 finish_if_command (token *if_tok, tree_if_command_list *list, |
236 token *end_tok, octave_comment_list *lc); | |
1623 | 237 |
238 // Build an elseif clause. | |
2970 | 239 static tree_if_clause * |
8658
73c4516fae10
New evaluator and debugger derived from tree-walker class
John W. Eaton <jwe@octave.org>
parents:
8471
diff
changeset
|
240 make_elseif_clause (token *elseif_tok, tree_expression *expr, |
73c4516fae10
New evaluator and debugger derived from tree-walker class
John W. Eaton <jwe@octave.org>
parents:
8471
diff
changeset
|
241 tree_statement_list *list, octave_comment_list *lc); |
1623 | 242 |
2764 | 243 // Finish a switch command. |
2970 | 244 static tree_switch_command * |
245 finish_switch_command (token *switch_tok, tree_expression *expr, | |
3665 | 246 tree_switch_case_list *list, token *end_tok, |
247 octave_comment_list *lc); | |
2764 | 248 |
249 // Build a switch case. | |
2970 | 250 static tree_switch_case * |
8658
73c4516fae10
New evaluator and debugger derived from tree-walker class
John W. Eaton <jwe@octave.org>
parents:
8471
diff
changeset
|
251 make_switch_case (token *case_tok, tree_expression *expr, |
73c4516fae10
New evaluator and debugger derived from tree-walker class
John W. Eaton <jwe@octave.org>
parents:
8471
diff
changeset
|
252 tree_statement_list *list, octave_comment_list *lc); |
2764 | 253 |
1623 | 254 // Build an assignment to a variable. |
2970 | 255 static tree_expression * |
256 make_assign_op (int op, tree_argument_list *lhs, token *eq_tok, | |
257 tree_expression *rhs); | |
1623 | 258 |
7715
5b4d278ec828
parse scripts completely before executing
John W. Eaton <jwe@octave.org>
parents:
7699
diff
changeset
|
259 // Define a script. |
5b4d278ec828
parse scripts completely before executing
John W. Eaton <jwe@octave.org>
parents:
7699
diff
changeset
|
260 static void |
8658
73c4516fae10
New evaluator and debugger derived from tree-walker class
John W. Eaton <jwe@octave.org>
parents:
8471
diff
changeset
|
261 make_script (tree_statement_list *cmds, tree_statement *end_script); |
7715
5b4d278ec828
parse scripts completely before executing
John W. Eaton <jwe@octave.org>
parents:
7699
diff
changeset
|
262 |
1623 | 263 // Begin defining a function. |
2970 | 264 static octave_user_function * |
8658
73c4516fae10
New evaluator and debugger derived from tree-walker class
John W. Eaton <jwe@octave.org>
parents:
8471
diff
changeset
|
265 start_function (tree_parameter_list *param_list, tree_statement_list *body, |
73c4516fae10
New evaluator and debugger derived from tree-walker class
John W. Eaton <jwe@octave.org>
parents:
8471
diff
changeset
|
266 tree_statement *end_function); |
73c4516fae10
New evaluator and debugger derived from tree-walker class
John W. Eaton <jwe@octave.org>
parents:
8471
diff
changeset
|
267 |
73c4516fae10
New evaluator and debugger derived from tree-walker class
John W. Eaton <jwe@octave.org>
parents:
8471
diff
changeset
|
268 // Create a no-op statement for end_function. |
73c4516fae10
New evaluator and debugger derived from tree-walker class
John W. Eaton <jwe@octave.org>
parents:
8471
diff
changeset
|
269 static tree_statement * |
73c4516fae10
New evaluator and debugger derived from tree-walker class
John W. Eaton <jwe@octave.org>
parents:
8471
diff
changeset
|
270 make_end (const std::string& type, int l, int c); |
1623 | 271 |
272 // Do most of the work for defining a function. | |
2970 | 273 static octave_user_function * |
4872 | 274 frob_function (const std::string& fname, octave_user_function *fcn); |
1623 | 275 |
276 // Finish defining a function. | |
7715
5b4d278ec828
parse scripts completely before executing
John W. Eaton <jwe@octave.org>
parents:
7699
diff
changeset
|
277 static tree_function_def * |
3665 | 278 finish_function (tree_parameter_list *ret_list, |
279 octave_user_function *fcn, octave_comment_list *lc); | |
751 | 280 |
2883 | 281 // Reset state after parsing function. |
2970 | 282 static void |
283 recover_from_parsing_function (void); | |
2883 | 284 |
751 | 285 // Make an index expression. |
2970 | 286 static tree_index_expression * |
3933 | 287 make_index_expression (tree_expression *expr, |
288 tree_argument_list *args, char type); | |
2970 | 289 |
290 // Make an indirect reference expression. | |
3930 | 291 static tree_index_expression * |
3523 | 292 make_indirect_ref (tree_expression *expr, const std::string&); |
666 | 293 |
4131 | 294 // Make an indirect reference expression with dynamic field name. |
295 static tree_index_expression * | |
296 make_indirect_ref (tree_expression *expr, tree_expression *field); | |
297 | |
2846 | 298 // Make a declaration command. |
2970 | 299 static tree_decl_command * |
300 make_decl_command (int tok, token *tok_val, tree_decl_init_list *lst); | |
2846 | 301 |
1623 | 302 // Finish building a matrix list. |
2970 | 303 static tree_expression * |
304 finish_matrix (tree_matrix *m); | |
1623 | 305 |
3351 | 306 // Finish building a cell list. |
307 static tree_expression * | |
308 finish_cell (tree_cell *c); | |
309 | |
1511 | 310 // Maybe print a warning. Duh. |
2970 | 311 static void |
312 maybe_warn_missing_semi (tree_statement_list *); | |
1511 | 313 |
2525 | 314 // Set the print flag for a statement based on the separator type. |
8471
02de6775f1fe
parse.y: always append statements to list, but remove null statements after seeing separator
John W. Eaton <jwe@octave.org>
parents:
8448
diff
changeset
|
315 static tree_statement_list * |
2970 | 316 set_stmt_print_flag (tree_statement_list *, char, bool); |
2525 | 317 |
8448
d6c0d5f208de
parse.y: avoid storing null statements in statement lists
John W. Eaton <jwe@octave.org>
parents:
8447
diff
changeset
|
318 // Create a statement list. |
d6c0d5f208de
parse.y: avoid storing null statements in statement lists
John W. Eaton <jwe@octave.org>
parents:
8447
diff
changeset
|
319 static tree_statement_list *make_statement_list (tree_statement *stmt); |
d6c0d5f208de
parse.y: avoid storing null statements in statement lists
John W. Eaton <jwe@octave.org>
parents:
8447
diff
changeset
|
320 |
d6c0d5f208de
parse.y: avoid storing null statements in statement lists
John W. Eaton <jwe@octave.org>
parents:
8447
diff
changeset
|
321 // Append a statement to an existing statement list. |
d6c0d5f208de
parse.y: avoid storing null statements in statement lists
John W. Eaton <jwe@octave.org>
parents:
8447
diff
changeset
|
322 static tree_statement_list * |
d6c0d5f208de
parse.y: avoid storing null statements in statement lists
John W. Eaton <jwe@octave.org>
parents:
8447
diff
changeset
|
323 append_statement_list (tree_statement_list *list, char sep, |
d6c0d5f208de
parse.y: avoid storing null statements in statement lists
John W. Eaton <jwe@octave.org>
parents:
8447
diff
changeset
|
324 tree_statement *stmt, bool warn_missing_semi); |
d6c0d5f208de
parse.y: avoid storing null statements in statement lists
John W. Eaton <jwe@octave.org>
parents:
8447
diff
changeset
|
325 |
d6c0d5f208de
parse.y: avoid storing null statements in statement lists
John W. Eaton <jwe@octave.org>
parents:
8447
diff
changeset
|
326 // Finish building a statement. |
d6c0d5f208de
parse.y: avoid storing null statements in statement lists
John W. Eaton <jwe@octave.org>
parents:
8447
diff
changeset
|
327 template <class T> |
d6c0d5f208de
parse.y: avoid storing null statements in statement lists
John W. Eaton <jwe@octave.org>
parents:
8447
diff
changeset
|
328 static tree_statement * |
d6c0d5f208de
parse.y: avoid storing null statements in statement lists
John W. Eaton <jwe@octave.org>
parents:
8447
diff
changeset
|
329 make_statement (T *arg) |
d6c0d5f208de
parse.y: avoid storing null statements in statement lists
John W. Eaton <jwe@octave.org>
parents:
8447
diff
changeset
|
330 { |
8471
02de6775f1fe
parse.y: always append statements to list, but remove null statements after seeing separator
John W. Eaton <jwe@octave.org>
parents:
8448
diff
changeset
|
331 octave_comment_list *comment = octave_comment_buffer::get_comment (); |
02de6775f1fe
parse.y: always append statements to list, but remove null statements after seeing separator
John W. Eaton <jwe@octave.org>
parents:
8448
diff
changeset
|
332 |
02de6775f1fe
parse.y: always append statements to list, but remove null statements after seeing separator
John W. Eaton <jwe@octave.org>
parents:
8448
diff
changeset
|
333 return new tree_statement (arg, comment); |
8448
d6c0d5f208de
parse.y: avoid storing null statements in statement lists
John W. Eaton <jwe@octave.org>
parents:
8447
diff
changeset
|
334 } |
d6c0d5f208de
parse.y: avoid storing null statements in statement lists
John W. Eaton <jwe@octave.org>
parents:
8447
diff
changeset
|
335 |
1 | 336 #define ABORT_PARSE \ |
337 do \ | |
338 { \ | |
522 | 339 global_command = 0; \ |
1 | 340 yyerrok; \ |
4238 | 341 if (! symtab_context.empty ()) \ |
3929 | 342 { \ |
7336 | 343 symbol_table::set_scope (symtab_context.top ()); \ |
4238 | 344 symtab_context.pop (); \ |
3929 | 345 } \ |
2865 | 346 if (interactive || forced_interactive) \ |
1 | 347 YYACCEPT; \ |
348 else \ | |
349 YYABORT; \ | |
350 } \ | |
351 while (0) | |
352 | |
353 %} | |
354 | |
666 | 355 // Bison declarations. |
356 | |
4813 | 357 // Don't add spaces around the = here; it causes some versions of |
358 // bison to fail to properly recognize the directive. | |
359 | |
360 %name-prefix="octave_" | |
4753 | 361 |
1 | 362 %union |
363 { | |
2891 | 364 // The type of the basic tokens returned by the lexer. |
143 | 365 token *tok_val; |
366 | |
3665 | 367 // Comment strings that we need to deal with mid-rule. |
368 octave_comment_list *comment_type; | |
369 | |
2891 | 370 // Types for the nonterminals we generate. |
2525 | 371 char sep_type; |
1 | 372 tree *tree_type; |
1829 | 373 tree_matrix *tree_matrix_type; |
3351 | 374 tree_cell *tree_cell_type; |
496 | 375 tree_expression *tree_expression_type; |
2375 | 376 tree_constant *tree_constant_type; |
4342 | 377 tree_fcn_handle *tree_fcn_handle_type; |
5861 | 378 tree_anon_fcn_handle *tree_anon_fcn_handle_type; |
1 | 379 tree_identifier *tree_identifier_type; |
380 tree_index_expression *tree_index_expression_type; | |
381 tree_colon_expression *tree_colon_expression_type; | |
382 tree_argument_list *tree_argument_list_type; | |
383 tree_parameter_list *tree_parameter_list_type; | |
384 tree_command *tree_command_type; | |
385 tree_if_command *tree_if_command_type; | |
578 | 386 tree_if_clause *tree_if_clause_type; |
387 tree_if_command_list *tree_if_command_list_type; | |
2764 | 388 tree_switch_command *tree_switch_command_type; |
389 tree_switch_case *tree_switch_case_type; | |
390 tree_switch_case_list *tree_switch_case_list_type; | |
2846 | 391 tree_decl_elt *tree_decl_elt_type; |
392 tree_decl_init_list *tree_decl_init_list_type; | |
393 tree_decl_command *tree_decl_command_type; | |
578 | 394 tree_statement *tree_statement_type; |
395 tree_statement_list *tree_statement_list_type; | |
2891 | 396 octave_user_function *octave_user_function_type; |
1 | 397 } |
398 | |
143 | 399 // Tokens with line and column information. |
400 %token <tok_val> '=' ':' '-' '+' '*' '/' | |
4018 | 401 %token <tok_val> ADD_EQ SUB_EQ MUL_EQ DIV_EQ LEFTDIV_EQ POW_EQ |
402 %token <tok_val> EMUL_EQ EDIV_EQ ELEFTDIV_EQ EPOW_EQ AND_EQ OR_EQ | |
2899 | 403 %token <tok_val> LSHIFT_EQ RSHIFT_EQ LSHIFT RSHIFT |
428 | 404 %token <tok_val> EXPR_AND_AND EXPR_OR_OR |
143 | 405 %token <tok_val> EXPR_AND EXPR_OR EXPR_NOT |
406 %token <tok_val> EXPR_LT EXPR_LE EXPR_EQ EXPR_NE EXPR_GE EXPR_GT | |
1276 | 407 %token <tok_val> LEFTDIV EMUL EDIV ELEFTDIV EPLUS EMINUS |
408 %token <tok_val> QUOTE TRANSPOSE | |
143 | 409 %token <tok_val> PLUS_PLUS MINUS_MINUS POW EPOW |
410 %token <tok_val> NUM IMAG_NUM | |
2970 | 411 %token <tok_val> STRUCT_ELT |
2883 | 412 %token <tok_val> NAME |
143 | 413 %token <tok_val> END |
5279 | 414 %token <tok_val> DQ_STRING SQ_STRING |
3484 | 415 %token <tok_val> FOR WHILE DO UNTIL |
1491 | 416 %token <tok_val> IF ELSEIF ELSE |
2764 | 417 %token <tok_val> SWITCH CASE OTHERWISE |
1491 | 418 %token <tok_val> BREAK CONTINUE FUNC_RET |
924 | 419 %token <tok_val> UNWIND CLEANUP |
1489 | 420 %token <tok_val> TRY CATCH |
2846 | 421 %token <tok_val> GLOBAL STATIC |
4342 | 422 %token <tok_val> FCN_HANDLE |
1 | 423 |
143 | 424 // Other tokens. |
2970 | 425 %token END_OF_INPUT LEXICAL_ERROR |
7715
5b4d278ec828
parse scripts completely before executing
John W. Eaton <jwe@octave.org>
parents:
7699
diff
changeset
|
426 %token FCN SCRIPT |
7587
1f662945c2be
handle varargin and varargout without keywords
John W. Eaton <jwe@octave.org>
parents:
7562
diff
changeset
|
427 // %token VARARGIN VARARGOUT |
5296 | 428 %token CLOSE_BRACE |
1 | 429 |
143 | 430 // Nonterminals we construct. |
3665 | 431 %type <comment_type> stash_comment function_beg |
2525 | 432 %type <sep_type> sep_no_nl opt_sep_no_nl sep opt_sep |
578 | 433 %type <tree_type> input |
5861 | 434 %type <tree_constant_type> string constant magic_colon |
435 %type <tree_anon_fcn_handle_type> anon_fcn_handle | |
4342 | 436 %type <tree_fcn_handle_type> fcn_handle |
3351 | 437 %type <tree_matrix_type> matrix_rows matrix_rows1 |
438 %type <tree_cell_type> cell_rows cell_rows1 | |
5102 | 439 %type <tree_expression_type> matrix cell |
4207 | 440 %type <tree_expression_type> primary_expr postfix_expr prefix_expr binary_expr |
441 %type <tree_expression_type> simple_expr colon_expr assign_expr expression | |
4238 | 442 %type <tree_identifier_type> identifier fcn_name |
7336 | 443 %type <octave_user_function_type> function1 function2 |
2970 | 444 %type <tree_index_expression_type> word_list_cmd |
445 %type <tree_colon_expression_type> colon_expr1 | |
3351 | 446 %type <tree_argument_list_type> arg_list word_list assign_lhs |
447 %type <tree_argument_list_type> cell_or_matrix_row | |
4935 | 448 %type <tree_parameter_list_type> param_list param_list1 param_list2 |
723 | 449 %type <tree_parameter_list_type> return_list return_list1 |
2970 | 450 %type <tree_command_type> command select_command loop_command |
7715
5b4d278ec828
parse scripts completely before executing
John W. Eaton <jwe@octave.org>
parents:
7699
diff
changeset
|
451 %type <tree_command_type> jump_command except_command function script |
578 | 452 %type <tree_if_command_type> if_command |
453 %type <tree_if_clause_type> elseif_clause else_clause | |
454 %type <tree_if_command_list_type> if_cmd_list1 if_cmd_list | |
2764 | 455 %type <tree_switch_command_type> switch_command |
456 %type <tree_switch_case_type> switch_case default_case | |
457 %type <tree_switch_case_list_type> case_list1 case_list | |
2846 | 458 %type <tree_decl_elt_type> decl2 |
459 %type <tree_decl_init_list_type> decl1 | |
460 %type <tree_decl_command_type> declaration | |
8658
73c4516fae10
New evaluator and debugger derived from tree-walker class
John W. Eaton <jwe@octave.org>
parents:
8471
diff
changeset
|
461 %type <tree_statement_type> statement function_end |
627 | 462 %type <tree_statement_list_type> simple_list simple_list1 list list1 |
7336 | 463 %type <tree_statement_list_type> opt_list input1 |
1 | 464 |
143 | 465 // Precedence and associativity. |
1 | 466 %left ';' ',' '\n' |
4018 | 467 %right '=' ADD_EQ SUB_EQ MUL_EQ DIV_EQ LEFTDIV_EQ POW_EQ EMUL_EQ EDIV_EQ ELEFTDIV_EQ EPOW_EQ OR_EQ AND_EQ LSHIFT_EQ RSHIFT_EQ |
4023 | 468 %left EXPR_OR_OR |
469 %left EXPR_AND_AND | |
470 %left EXPR_OR | |
471 %left EXPR_AND | |
1 | 472 %left EXPR_LT EXPR_LE EXPR_EQ EXPR_NE EXPR_GE EXPR_GT |
2899 | 473 %left LSHIFT RSHIFT |
1 | 474 %left ':' |
1276 | 475 %left '-' '+' EPLUS EMINUS |
1 | 476 %left '*' '/' LEFTDIV EMUL EDIV ELEFTDIV |
477 %left UNARY PLUS_PLUS MINUS_MINUS EXPR_NOT | |
5667 | 478 %left POW EPOW QUOTE TRANSPOSE |
3351 | 479 %left '(' '.' '{' |
1 | 480 |
143 | 481 // Where to start. |
1 | 482 %start input |
483 | |
484 %% | |
485 | |
2970 | 486 // ============================== |
487 // Statements and statement lists | |
488 // ============================== | |
489 | |
627 | 490 input : input1 |
1 | 491 { |
627 | 492 global_command = $1; |
1 | 493 promptflag = 1; |
494 YYACCEPT; | |
495 } | |
627 | 496 | simple_list parse_error |
1091 | 497 { ABORT_PARSE; } |
627 | 498 | parse_error |
1091 | 499 { ABORT_PARSE; } |
627 | 500 ; |
501 | |
502 input1 : '\n' | |
503 { $$ = 0; } | |
3883 | 504 | END_OF_INPUT |
505 { | |
506 parser_end_of_input = 1; | |
507 $$ = 0; | |
508 } | |
327 | 509 | simple_list |
627 | 510 { $$ = $1; } |
1 | 511 | simple_list '\n' |
627 | 512 { $$ = $1; } |
1 | 513 | simple_list END_OF_INPUT |
627 | 514 { $$ = $1; } |
515 ; | |
516 | |
2525 | 517 simple_list : simple_list1 opt_sep_no_nl |
8471
02de6775f1fe
parse.y: always append statements to list, but remove null statements after seeing separator
John W. Eaton <jwe@octave.org>
parents:
8448
diff
changeset
|
518 { $$ = set_stmt_print_flag ($1, $2, false); } |
1 | 519 ; |
520 | |
578 | 521 simple_list1 : statement |
8448
d6c0d5f208de
parse.y: avoid storing null statements in statement lists
John W. Eaton <jwe@octave.org>
parents:
8447
diff
changeset
|
522 { $$ = make_statement_list ($1); } |
2525 | 523 | simple_list1 sep_no_nl statement |
8448
d6c0d5f208de
parse.y: avoid storing null statements in statement lists
John W. Eaton <jwe@octave.org>
parents:
8447
diff
changeset
|
524 { $$ = append_statement_list ($1, $2, $3, false); } |
1 | 525 ; |
526 | |
527 opt_list : // empty | |
578 | 528 { $$ = new tree_statement_list (); } |
1 | 529 | list |
530 { $$ = $1; } | |
496 | 531 ; |
1 | 532 |
2525 | 533 list : list1 opt_sep |
8471
02de6775f1fe
parse.y: always append statements to list, but remove null statements after seeing separator
John W. Eaton <jwe@octave.org>
parents:
8448
diff
changeset
|
534 { $$ = set_stmt_print_flag ($1, $2, true); } |
1 | 535 ; |
536 | |
578 | 537 list1 : statement |
8448
d6c0d5f208de
parse.y: avoid storing null statements in statement lists
John W. Eaton <jwe@octave.org>
parents:
8447
diff
changeset
|
538 { $$ = make_statement_list ($1); } |
2525 | 539 | list1 sep statement |
8448
d6c0d5f208de
parse.y: avoid storing null statements in statement lists
John W. Eaton <jwe@octave.org>
parents:
8447
diff
changeset
|
540 { $$ = append_statement_list ($1, $2, $3, true); } |
1 | 541 ; |
542 | |
2970 | 543 statement : expression |
8448
d6c0d5f208de
parse.y: avoid storing null statements in statement lists
John W. Eaton <jwe@octave.org>
parents:
8447
diff
changeset
|
544 { $$ = make_statement ($1); } |
2970 | 545 | command |
8448
d6c0d5f208de
parse.y: avoid storing null statements in statement lists
John W. Eaton <jwe@octave.org>
parents:
8447
diff
changeset
|
546 { $$ = make_statement ($1); } |
1 | 547 ; |
548 | |
2970 | 549 // =========== |
550 // Expressions | |
551 // =========== | |
552 | |
553 identifier : NAME | |
554 { | |
7336 | 555 symbol_table::symbol_record *sr = $1->sym_rec (); |
556 $$ = new tree_identifier (*sr, $1->line (), $1->column ()); | |
2970 | 557 } |
558 ; | |
559 | |
5279 | 560 string : DQ_STRING |
561 { $$ = make_constant (DQ_STRING, $1); } | |
562 | SQ_STRING | |
563 { $$ = make_constant (SQ_STRING, $1); } | |
564 ; | |
565 | |
2970 | 566 constant : NUM |
567 { $$ = make_constant (NUM, $1); } | |
568 | IMAG_NUM | |
569 { $$ = make_constant (IMAG_NUM, $1); } | |
5279 | 570 | string |
571 { $$ = $1; } | |
2970 | 572 ; |
573 | |
574 matrix : '[' ']' | |
5615 | 575 { |
8150
283989f2da9b
make null assignment matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
8064
diff
changeset
|
576 $$ = new tree_constant (octave_null_matrix::instance); |
5615 | 577 lexer_flags.looking_at_matrix_or_assign_lhs = false; |
8001
ff9e7873f8ea
improve handling of command-style names in matrix_or_assign_lhs context
John W. Eaton <jwe@octave.org>
parents:
7968
diff
changeset
|
578 lexer_flags.pending_local_variables.clear (); |
5615 | 579 } |
2970 | 580 | '[' ';' ']' |
3203 | 581 { |
8150
283989f2da9b
make null assignment matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
8064
diff
changeset
|
582 $$ = new tree_constant (octave_null_matrix::instance); |
283989f2da9b
make null assignment matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
8064
diff
changeset
|
583 lexer_flags.looking_at_matrix_or_assign_lhs = false; |
283989f2da9b
make null assignment matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
8064
diff
changeset
|
584 lexer_flags.pending_local_variables.clear (); |
283989f2da9b
make null assignment matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
8064
diff
changeset
|
585 } |
283989f2da9b
make null assignment matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
8064
diff
changeset
|
586 | '[' ',' ']' |
283989f2da9b
make null assignment matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
8064
diff
changeset
|
587 { |
283989f2da9b
make null assignment matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
8064
diff
changeset
|
588 $$ = new tree_constant (octave_null_matrix::instance); |
5615 | 589 lexer_flags.looking_at_matrix_or_assign_lhs = false; |
8001
ff9e7873f8ea
improve handling of command-style names in matrix_or_assign_lhs context
John W. Eaton <jwe@octave.org>
parents:
7968
diff
changeset
|
590 lexer_flags.pending_local_variables.clear (); |
5615 | 591 } |
592 | '[' matrix_rows ']' | |
593 { | |
594 $$ = finish_matrix ($2); | |
3203 | 595 lexer_flags.looking_at_matrix_or_assign_lhs = false; |
8001
ff9e7873f8ea
improve handling of command-style names in matrix_or_assign_lhs context
John W. Eaton <jwe@octave.org>
parents:
7968
diff
changeset
|
596 lexer_flags.pending_local_variables.clear (); |
3203 | 597 } |
2970 | 598 ; |
599 | |
3351 | 600 matrix_rows : matrix_rows1 |
2970 | 601 { $$ = $1; } |
3351 | 602 | matrix_rows1 ';' // Ignore trailing semicolon. |
2970 | 603 { $$ = $1; } |
604 ; | |
605 | |
3351 | 606 matrix_rows1 : cell_or_matrix_row |
2970 | 607 { $$ = new tree_matrix ($1); } |
3351 | 608 | matrix_rows1 ';' cell_or_matrix_row |
2970 | 609 { |
610 $1->append ($3); | |
611 $$ = $1; | |
612 } | |
613 ; | |
614 | |
3351 | 615 cell : '{' '}' |
3928 | 616 { $$ = new tree_constant (octave_value (Cell ())); } |
3351 | 617 | '{' ';' '}' |
3928 | 618 { $$ = new tree_constant (octave_value (Cell ())); } |
3351 | 619 | '{' cell_rows '}' |
620 { $$ = finish_cell ($2); } | |
621 ; | |
622 | |
623 cell_rows : cell_rows1 | |
624 { $$ = $1; } | |
625 | cell_rows1 ';' // Ignore trailing semicolon. | |
626 { $$ = $1; } | |
627 ; | |
628 | |
629 cell_rows1 : cell_or_matrix_row | |
630 { $$ = new tree_cell ($1); } | |
631 | cell_rows1 ';' cell_or_matrix_row | |
632 { | |
633 $1->append ($3); | |
634 $$ = $1; | |
635 } | |
636 ; | |
637 | |
638 cell_or_matrix_row | |
639 : arg_list | |
2970 | 640 { $$ = $1; } |
641 | arg_list ',' // Ignore trailing comma. | |
642 { $$ = $1; } | |
643 ; | |
644 | |
4930 | 645 fcn_handle : '@' FCN_HANDLE |
646 { | |
647 $$ = make_fcn_handle ($2); | |
648 lexer_flags.looking_at_function_handle--; | |
649 } | |
650 ; | |
651 | |
4935 | 652 anon_fcn_handle : '@' param_list statement |
653 { $$ = make_anon_fcn_handle ($2, $3); } | |
4342 | 654 ; |
655 | |
2970 | 656 primary_expr : identifier |
657 { $$ = $1; } | |
658 | constant | |
659 { $$ = $1; } | |
4342 | 660 | fcn_handle |
661 { $$ = $1; } | |
2970 | 662 | matrix |
663 { $$ = $1; } | |
3351 | 664 | cell |
665 { $$ = $1; } | |
2970 | 666 | '(' expression ')' |
667 { $$ = $2->mark_in_parens (); } | |
668 ; | |
669 | |
670 magic_colon : ':' | |
671 { | |
672 octave_value tmp (octave_value::magic_colon_t); | |
673 $$ = new tree_constant (tmp); | |
674 } | |
675 ; | |
676 | |
677 arg_list : expression | |
678 { $$ = new tree_argument_list ($1); } | |
679 | magic_colon | |
680 { $$ = new tree_argument_list ($1); } | |
681 | arg_list ',' magic_colon | |
682 { | |
683 $1->append ($3); | |
684 $$ = $1; | |
685 } | |
686 | arg_list ',' expression | |
687 { | |
688 $1->append ($3); | |
689 $$ = $1; | |
690 } | |
691 ; | |
692 | |
4131 | 693 indirect_ref_op : '.' |
2970 | 694 { lexer_flags.looking_at_indirect_ref = true; } |
695 ; | |
696 | |
697 postfix_expr : primary_expr | |
698 { $$ = $1; } | |
8745
6dc61981d18b
better handling of object indexing in lexer
John W. Eaton <jwe@octave.org>
parents:
8701
diff
changeset
|
699 | postfix_expr '(' ')' |
6dc61981d18b
better handling of object indexing in lexer
John W. Eaton <jwe@octave.org>
parents:
8701
diff
changeset
|
700 { $$ = make_index_expression ($1, 0, '('); } |
6dc61981d18b
better handling of object indexing in lexer
John W. Eaton <jwe@octave.org>
parents:
8701
diff
changeset
|
701 | postfix_expr '(' arg_list ')' |
6dc61981d18b
better handling of object indexing in lexer
John W. Eaton <jwe@octave.org>
parents:
8701
diff
changeset
|
702 { $$ = make_index_expression ($1, $3, '('); } |
6dc61981d18b
better handling of object indexing in lexer
John W. Eaton <jwe@octave.org>
parents:
8701
diff
changeset
|
703 | postfix_expr '{' '}' |
6dc61981d18b
better handling of object indexing in lexer
John W. Eaton <jwe@octave.org>
parents:
8701
diff
changeset
|
704 { $$ = make_index_expression ($1, 0, '{'); } |
6dc61981d18b
better handling of object indexing in lexer
John W. Eaton <jwe@octave.org>
parents:
8701
diff
changeset
|
705 | postfix_expr '{' arg_list '}' |
6dc61981d18b
better handling of object indexing in lexer
John W. Eaton <jwe@octave.org>
parents:
8701
diff
changeset
|
706 { $$ = make_index_expression ($1, $3, '{'); } |
6dc61981d18b
better handling of object indexing in lexer
John W. Eaton <jwe@octave.org>
parents:
8701
diff
changeset
|
707 | postfix_expr PLUS_PLUS |
6dc61981d18b
better handling of object indexing in lexer
John W. Eaton <jwe@octave.org>
parents:
8701
diff
changeset
|
708 { $$ = make_postfix_op (PLUS_PLUS, $1, $2); } |
6dc61981d18b
better handling of object indexing in lexer
John W. Eaton <jwe@octave.org>
parents:
8701
diff
changeset
|
709 | postfix_expr MINUS_MINUS |
6dc61981d18b
better handling of object indexing in lexer
John W. Eaton <jwe@octave.org>
parents:
8701
diff
changeset
|
710 { $$ = make_postfix_op (MINUS_MINUS, $1, $2); } |
6dc61981d18b
better handling of object indexing in lexer
John W. Eaton <jwe@octave.org>
parents:
8701
diff
changeset
|
711 | postfix_expr QUOTE |
6dc61981d18b
better handling of object indexing in lexer
John W. Eaton <jwe@octave.org>
parents:
8701
diff
changeset
|
712 { $$ = make_postfix_op (QUOTE, $1, $2); } |
6dc61981d18b
better handling of object indexing in lexer
John W. Eaton <jwe@octave.org>
parents:
8701
diff
changeset
|
713 | postfix_expr TRANSPOSE |
6dc61981d18b
better handling of object indexing in lexer
John W. Eaton <jwe@octave.org>
parents:
8701
diff
changeset
|
714 { $$ = make_postfix_op (TRANSPOSE, $1, $2); } |
6dc61981d18b
better handling of object indexing in lexer
John W. Eaton <jwe@octave.org>
parents:
8701
diff
changeset
|
715 | postfix_expr indirect_ref_op STRUCT_ELT |
6dc61981d18b
better handling of object indexing in lexer
John W. Eaton <jwe@octave.org>
parents:
8701
diff
changeset
|
716 { $$ = make_indirect_ref ($1, $3->text ()); } |
6dc61981d18b
better handling of object indexing in lexer
John W. Eaton <jwe@octave.org>
parents:
8701
diff
changeset
|
717 | postfix_expr indirect_ref_op '(' expression ')' |
6dc61981d18b
better handling of object indexing in lexer
John W. Eaton <jwe@octave.org>
parents:
8701
diff
changeset
|
718 { $$ = make_indirect_ref ($1, $4); } |
2970 | 719 ; |
720 | |
8745
6dc61981d18b
better handling of object indexing in lexer
John W. Eaton <jwe@octave.org>
parents:
8701
diff
changeset
|
721 prefix_expr : postfix_expr |
2970 | 722 { $$ = $1; } |
3178 | 723 | binary_expr |
724 { $$ = $1; } | |
2970 | 725 | PLUS_PLUS prefix_expr %prec UNARY |
726 { $$ = make_prefix_op (PLUS_PLUS, $2, $1); } | |
727 | MINUS_MINUS prefix_expr %prec UNARY | |
728 { $$ = make_prefix_op (MINUS_MINUS, $2, $1); } | |
729 | EXPR_NOT prefix_expr %prec UNARY | |
730 { $$ = make_prefix_op (EXPR_NOT, $2, $1); } | |
731 | '+' prefix_expr %prec UNARY | |
4965 | 732 { $$ = make_prefix_op ('+', $2, $1); } |
2970 | 733 | '-' prefix_expr %prec UNARY |
734 { $$ = make_prefix_op ('-', $2, $1); } | |
735 ; | |
736 | |
3178 | 737 binary_expr : prefix_expr POW prefix_expr |
2970 | 738 { $$ = make_binary_op (POW, $1, $2, $3); } |
3178 | 739 | prefix_expr EPOW prefix_expr |
2970 | 740 { $$ = make_binary_op (EPOW, $1, $2, $3); } |
3178 | 741 | prefix_expr '+' prefix_expr |
2970 | 742 { $$ = make_binary_op ('+', $1, $2, $3); } |
3178 | 743 | prefix_expr '-' prefix_expr |
2970 | 744 { $$ = make_binary_op ('-', $1, $2, $3); } |
3178 | 745 | prefix_expr '*' prefix_expr |
2970 | 746 { $$ = make_binary_op ('*', $1, $2, $3); } |
3178 | 747 | prefix_expr '/' prefix_expr |
2970 | 748 { $$ = make_binary_op ('/', $1, $2, $3); } |
3178 | 749 | prefix_expr EPLUS prefix_expr |
2970 | 750 { $$ = make_binary_op ('+', $1, $2, $3); } |
3178 | 751 | prefix_expr EMINUS prefix_expr |
2970 | 752 { $$ = make_binary_op ('-', $1, $2, $3); } |
3178 | 753 | prefix_expr EMUL prefix_expr |
2970 | 754 { $$ = make_binary_op (EMUL, $1, $2, $3); } |
3178 | 755 | prefix_expr EDIV prefix_expr |
2970 | 756 { $$ = make_binary_op (EDIV, $1, $2, $3); } |
3178 | 757 | prefix_expr LEFTDIV prefix_expr |
2970 | 758 { $$ = make_binary_op (LEFTDIV, $1, $2, $3); } |
3178 | 759 | prefix_expr ELEFTDIV prefix_expr |
2970 | 760 { $$ = make_binary_op (ELEFTDIV, $1, $2, $3); } |
761 ; | |
762 | |
763 colon_expr : colon_expr1 | |
764 { $$ = finish_colon_expression ($1); } | |
765 ; | |
766 | |
3178 | 767 colon_expr1 : prefix_expr |
2970 | 768 { $$ = new tree_colon_expression ($1); } |
3178 | 769 | colon_expr1 ':' prefix_expr |
2970 | 770 { |
771 if (! ($$ = $1->append ($3))) | |
772 ABORT_PARSE; | |
773 } | |
774 ; | |
775 | |
776 simple_expr : colon_expr | |
777 { $$ = $1; } | |
778 | simple_expr LSHIFT simple_expr | |
779 { $$ = make_binary_op (LSHIFT, $1, $2, $3); } | |
780 | simple_expr RSHIFT simple_expr | |
781 { $$ = make_binary_op (RSHIFT, $1, $2, $3); } | |
782 | simple_expr EXPR_LT simple_expr | |
783 { $$ = make_binary_op (EXPR_LT, $1, $2, $3); } | |
784 | simple_expr EXPR_LE simple_expr | |
785 { $$ = make_binary_op (EXPR_LE, $1, $2, $3); } | |
786 | simple_expr EXPR_EQ simple_expr | |
787 { $$ = make_binary_op (EXPR_EQ, $1, $2, $3); } | |
788 | simple_expr EXPR_GE simple_expr | |
789 { $$ = make_binary_op (EXPR_GE, $1, $2, $3); } | |
790 | simple_expr EXPR_GT simple_expr | |
791 { $$ = make_binary_op (EXPR_GT, $1, $2, $3); } | |
792 | simple_expr EXPR_NE simple_expr | |
793 { $$ = make_binary_op (EXPR_NE, $1, $2, $3); } | |
794 | simple_expr EXPR_AND simple_expr | |
795 { $$ = make_binary_op (EXPR_AND, $1, $2, $3); } | |
796 | simple_expr EXPR_OR simple_expr | |
797 { $$ = make_binary_op (EXPR_OR, $1, $2, $3); } | |
798 | simple_expr EXPR_AND_AND simple_expr | |
799 { $$ = make_boolean_op (EXPR_AND_AND, $1, $2, $3); } | |
800 | simple_expr EXPR_OR_OR simple_expr | |
801 { $$ = make_boolean_op (EXPR_OR_OR, $1, $2, $3); } | |
802 ; | |
803 | |
804 // Arrange for the lexer to return CLOSE_BRACE for `]' by looking ahead | |
805 // one token for an assignment op. | |
806 | |
807 assign_lhs : simple_expr | |
5841 | 808 { |
809 $$ = new tree_argument_list ($1); | |
810 $$->mark_as_simple_assign_lhs (); | |
811 } | |
5615 | 812 | '[' arg_list CLOSE_BRACE |
3189 | 813 { |
5615 | 814 $$ = $2; |
3189 | 815 lexer_flags.looking_at_matrix_or_assign_lhs = false; |
8001
ff9e7873f8ea
improve handling of command-style names in matrix_or_assign_lhs context
John W. Eaton <jwe@octave.org>
parents:
7968
diff
changeset
|
816 for (std::set<std::string>::const_iterator p = lexer_flags.pending_local_variables.begin (); |
ff9e7873f8ea
improve handling of command-style names in matrix_or_assign_lhs context
John W. Eaton <jwe@octave.org>
parents:
7968
diff
changeset
|
817 p != lexer_flags.pending_local_variables.end (); |
ff9e7873f8ea
improve handling of command-style names in matrix_or_assign_lhs context
John W. Eaton <jwe@octave.org>
parents:
7968
diff
changeset
|
818 p++) |
ff9e7873f8ea
improve handling of command-style names in matrix_or_assign_lhs context
John W. Eaton <jwe@octave.org>
parents:
7968
diff
changeset
|
819 { |
ff9e7873f8ea
improve handling of command-style names in matrix_or_assign_lhs context
John W. Eaton <jwe@octave.org>
parents:
7968
diff
changeset
|
820 force_local_variable (*p); |
ff9e7873f8ea
improve handling of command-style names in matrix_or_assign_lhs context
John W. Eaton <jwe@octave.org>
parents:
7968
diff
changeset
|
821 } |
ff9e7873f8ea
improve handling of command-style names in matrix_or_assign_lhs context
John W. Eaton <jwe@octave.org>
parents:
7968
diff
changeset
|
822 lexer_flags.pending_local_variables.clear (); |
3189 | 823 } |
2970 | 824 ; |
825 | |
826 assign_expr : assign_lhs '=' expression | |
827 { $$ = make_assign_op ('=', $1, $2, $3); } | |
828 | assign_lhs ADD_EQ expression | |
829 { $$ = make_assign_op (ADD_EQ, $1, $2, $3); } | |
830 | assign_lhs SUB_EQ expression | |
831 { $$ = make_assign_op (SUB_EQ, $1, $2, $3); } | |
832 | assign_lhs MUL_EQ expression | |
833 { $$ = make_assign_op (MUL_EQ, $1, $2, $3); } | |
834 | assign_lhs DIV_EQ expression | |
835 { $$ = make_assign_op (DIV_EQ, $1, $2, $3); } | |
3204 | 836 | assign_lhs LEFTDIV_EQ expression |
837 { $$ = make_assign_op (LEFTDIV_EQ, $1, $2, $3); } | |
4018 | 838 | assign_lhs POW_EQ expression |
839 { $$ = make_assign_op (POW_EQ, $1, $2, $3); } | |
2970 | 840 | assign_lhs LSHIFT_EQ expression |
841 { $$ = make_assign_op (LSHIFT_EQ, $1, $2, $3); } | |
842 | assign_lhs RSHIFT_EQ expression | |
843 { $$ = make_assign_op (RSHIFT_EQ, $1, $2, $3); } | |
844 | assign_lhs EMUL_EQ expression | |
845 { $$ = make_assign_op (EMUL_EQ, $1, $2, $3); } | |
846 | assign_lhs EDIV_EQ expression | |
847 { $$ = make_assign_op (EDIV_EQ, $1, $2, $3); } | |
3204 | 848 | assign_lhs ELEFTDIV_EQ expression |
849 { $$ = make_assign_op (ELEFTDIV_EQ, $1, $2, $3); } | |
4018 | 850 | assign_lhs EPOW_EQ expression |
851 { $$ = make_assign_op (EPOW_EQ, $1, $2, $3); } | |
2970 | 852 | assign_lhs AND_EQ expression |
853 { $$ = make_assign_op (AND_EQ, $1, $2, $3); } | |
854 | assign_lhs OR_EQ expression | |
855 { $$ = make_assign_op (OR_EQ, $1, $2, $3); } | |
856 ; | |
857 | |
858 word_list_cmd : identifier word_list | |
3933 | 859 { $$ = make_index_expression ($1, $2, '('); } |
2970 | 860 ; |
861 | |
5279 | 862 word_list : string |
863 { $$ = new tree_argument_list ($1); } | |
864 | word_list string | |
2970 | 865 { |
5279 | 866 $1->append ($2); |
2970 | 867 $$ = $1; |
868 } | |
869 ; | |
870 | |
871 expression : simple_expr | |
872 { $$ = $1; } | |
873 | word_list_cmd | |
874 { $$ = $1; } | |
875 | assign_expr | |
876 { $$ = $1; } | |
4935 | 877 | anon_fcn_handle |
878 { $$ = $1; } | |
2970 | 879 ; |
880 | |
881 // ================================================ | |
882 // Commands, declarations, and function definitions | |
883 // ================================================ | |
884 | |
885 command : declaration | |
886 { $$ = $1; } | |
887 | select_command | |
888 { $$ = $1; } | |
889 | loop_command | |
890 { $$ = $1; } | |
4207 | 891 | jump_command |
892 { $$ = $1; } | |
2970 | 893 | except_command |
894 { $$ = $1; } | |
895 | function | |
896 { $$ = $1; } | |
7715
5b4d278ec828
parse scripts completely before executing
John W. Eaton <jwe@octave.org>
parents:
7699
diff
changeset
|
897 | script |
5b4d278ec828
parse scripts completely before executing
John W. Eaton <jwe@octave.org>
parents:
7699
diff
changeset
|
898 { $$ = $1; } |
2970 | 899 ; |
900 | |
901 // ===================== | |
902 // Declaration statemnts | |
903 // ===================== | |
904 | |
8701
1652e39b934e
handle command names in declaration lists
John W. Eaton <jwe@octave.org>
parents:
8697
diff
changeset
|
905 parsing_decl_list |
1652e39b934e
handle command names in declaration lists
John W. Eaton <jwe@octave.org>
parents:
8697
diff
changeset
|
906 : // empty |
1652e39b934e
handle command names in declaration lists
John W. Eaton <jwe@octave.org>
parents:
8697
diff
changeset
|
907 { lexer_flags.looking_at_decl_list = true; } |
1652e39b934e
handle command names in declaration lists
John W. Eaton <jwe@octave.org>
parents:
8697
diff
changeset
|
908 |
1652e39b934e
handle command names in declaration lists
John W. Eaton <jwe@octave.org>
parents:
8697
diff
changeset
|
909 declaration : GLOBAL parsing_decl_list decl1 |
1652e39b934e
handle command names in declaration lists
John W. Eaton <jwe@octave.org>
parents:
8697
diff
changeset
|
910 { |
1652e39b934e
handle command names in declaration lists
John W. Eaton <jwe@octave.org>
parents:
8697
diff
changeset
|
911 $$ = make_decl_command (GLOBAL, $1, $3); |
1652e39b934e
handle command names in declaration lists
John W. Eaton <jwe@octave.org>
parents:
8697
diff
changeset
|
912 lexer_flags.looking_at_decl_list = false; |
1652e39b934e
handle command names in declaration lists
John W. Eaton <jwe@octave.org>
parents:
8697
diff
changeset
|
913 } |
1652e39b934e
handle command names in declaration lists
John W. Eaton <jwe@octave.org>
parents:
8697
diff
changeset
|
914 | STATIC parsing_decl_list decl1 |
1652e39b934e
handle command names in declaration lists
John W. Eaton <jwe@octave.org>
parents:
8697
diff
changeset
|
915 { |
1652e39b934e
handle command names in declaration lists
John W. Eaton <jwe@octave.org>
parents:
8697
diff
changeset
|
916 $$ = make_decl_command (STATIC, $1, $3); |
1652e39b934e
handle command names in declaration lists
John W. Eaton <jwe@octave.org>
parents:
8697
diff
changeset
|
917 lexer_flags.looking_at_decl_list = false; |
1652e39b934e
handle command names in declaration lists
John W. Eaton <jwe@octave.org>
parents:
8697
diff
changeset
|
918 } |
2970 | 919 ; |
920 | |
921 decl1 : decl2 | |
922 { $$ = new tree_decl_init_list ($1); } | |
923 | decl1 decl2 | |
924 { | |
925 $1->append ($2); | |
926 $$ = $1; | |
927 } | |
928 ; | |
929 | |
7634
ae90e05ad299
fix parameter list initializer bug
John W. Eaton <jwe@octave.org>
parents:
7587
diff
changeset
|
930 decl_param_init : // empty |
ae90e05ad299
fix parameter list initializer bug
John W. Eaton <jwe@octave.org>
parents:
7587
diff
changeset
|
931 { lexer_flags.looking_at_initializer_expression = true; } |
ae90e05ad299
fix parameter list initializer bug
John W. Eaton <jwe@octave.org>
parents:
7587
diff
changeset
|
932 |
2970 | 933 decl2 : identifier |
934 { $$ = new tree_decl_elt ($1); } | |
7634
ae90e05ad299
fix parameter list initializer bug
John W. Eaton <jwe@octave.org>
parents:
7587
diff
changeset
|
935 | identifier '=' decl_param_init expression |
ae90e05ad299
fix parameter list initializer bug
John W. Eaton <jwe@octave.org>
parents:
7587
diff
changeset
|
936 { |
ae90e05ad299
fix parameter list initializer bug
John W. Eaton <jwe@octave.org>
parents:
7587
diff
changeset
|
937 lexer_flags.looking_at_initializer_expression = false; |
ae90e05ad299
fix parameter list initializer bug
John W. Eaton <jwe@octave.org>
parents:
7587
diff
changeset
|
938 $$ = new tree_decl_elt ($1, $4); |
ae90e05ad299
fix parameter list initializer bug
John W. Eaton <jwe@octave.org>
parents:
7587
diff
changeset
|
939 } |
2970 | 940 ; |
941 | |
942 // ==================== | |
943 // Selection statements | |
944 // ==================== | |
945 | |
946 select_command : if_command | |
947 { $$ = $1; } | |
948 | switch_command | |
949 { $$ = $1; } | |
950 ; | |
951 | |
952 // ============ | |
953 // If statement | |
954 // ============ | |
955 | |
3665 | 956 if_command : IF stash_comment if_cmd_list END |
2970 | 957 { |
3665 | 958 if (! ($$ = finish_if_command ($1, $3, $4, $2))) |
2970 | 959 ABORT_PARSE; |
960 } | |
961 ; | |
962 | |
963 if_cmd_list : if_cmd_list1 | |
964 { $$ = $1; } | |
965 | if_cmd_list1 else_clause | |
966 { | |
967 $1->append ($2); | |
968 $$ = $1; | |
969 } | |
970 ; | |
971 | |
972 if_cmd_list1 : expression opt_sep opt_list | |
973 { $$ = start_if_command ($1, $3); } | |
974 | if_cmd_list1 elseif_clause | |
975 { | |
976 $1->append ($2); | |
977 $$ = $1; | |
978 } | |
979 ; | |
980 | |
3665 | 981 elseif_clause : ELSEIF stash_comment opt_sep expression opt_sep opt_list |
8658
73c4516fae10
New evaluator and debugger derived from tree-walker class
John W. Eaton <jwe@octave.org>
parents:
8471
diff
changeset
|
982 { $$ = make_elseif_clause ($1, $4, $6, $2); } |
2970 | 983 ; |
984 | |
3665 | 985 else_clause : ELSE stash_comment opt_sep opt_list |
8658
73c4516fae10
New evaluator and debugger derived from tree-walker class
John W. Eaton <jwe@octave.org>
parents:
8471
diff
changeset
|
986 { $$ = new tree_if_clause ($4, $2); } |
2970 | 987 ; |
988 | |
989 // ================ | |
990 // Switch statement | |
991 // ================ | |
992 | |
3665 | 993 switch_command : SWITCH stash_comment expression opt_sep case_list END |
2970 | 994 { |
3665 | 995 if (! ($$ = finish_switch_command ($1, $3, $5, $6, $2))) |
2970 | 996 ABORT_PARSE; |
997 } | |
998 ; | |
999 | |
4044 | 1000 case_list : // empty |
1001 { $$ = new tree_switch_case_list (); } | |
1002 | case_list1 | |
2970 | 1003 { $$ = $1; } |
1004 | case_list1 default_case | |
1005 { | |
1006 $1->append ($2); | |
1007 $$ = $1; | |
1008 } | |
1009 ; | |
1010 | |
1011 case_list1 : switch_case | |
1012 { $$ = new tree_switch_case_list ($1); } | |
1013 | case_list1 switch_case | |
1014 { | |
1015 $1->append ($2); | |
1016 $$ = $1; | |
1017 } | |
1018 ; | |
1019 | |
4025 | 1020 switch_case : CASE stash_comment opt_sep expression opt_sep opt_list |
8658
73c4516fae10
New evaluator and debugger derived from tree-walker class
John W. Eaton <jwe@octave.org>
parents:
8471
diff
changeset
|
1021 { $$ = make_switch_case ($1, $4, $6, $2); } |
2970 | 1022 ; |
1023 | |
3665 | 1024 default_case : OTHERWISE stash_comment opt_sep opt_list |
1025 { | |
1026 $$ = new tree_switch_case ($4, $2); | |
1027 } | |
2970 | 1028 ; |
1029 | |
1030 // ======= | |
1031 // Looping | |
1032 // ======= | |
1033 | |
3665 | 1034 loop_command : WHILE stash_comment expression opt_sep opt_list END |
2970 | 1035 { |
3665 | 1036 if (! ($$ = make_while_command ($1, $3, $5, $6, $2))) |
2970 | 1037 ABORT_PARSE; |
1038 } | |
3665 | 1039 | DO stash_comment opt_sep opt_list UNTIL expression |
3484 | 1040 { |
8658
73c4516fae10
New evaluator and debugger derived from tree-walker class
John W. Eaton <jwe@octave.org>
parents:
8471
diff
changeset
|
1041 if (! ($$ = make_do_until_command ($5, $4, $6, $2))) |
3484 | 1042 ABORT_PARSE; |
1043 } | |
3665 | 1044 | FOR stash_comment assign_lhs '=' expression opt_sep opt_list END |
2970 | 1045 { |
3665 | 1046 if (! ($$ = make_for_command ($1, $3, $5, $7, $8, $2))) |
2970 | 1047 ABORT_PARSE; |
1048 } | |
5127 | 1049 | FOR stash_comment '(' assign_lhs '=' expression ')' opt_sep opt_list END |
1050 { | |
1051 if (! ($$ = make_for_command ($1, $4, $6, $9, $10, $2))) | |
1052 ABORT_PARSE; | |
1053 } | |
2970 | 1054 ; |
1055 | |
1056 // ======= | |
1057 // Jumping | |
1058 // ======= | |
1059 | |
4207 | 1060 jump_command : BREAK |
2970 | 1061 { |
4207 | 1062 if (! ($$ = make_break_command ($1))) |
2970 | 1063 ABORT_PARSE; |
1064 } | |
1065 | CONTINUE | |
1066 { | |
4207 | 1067 if (! ($$ = make_continue_command ($1))) |
2970 | 1068 ABORT_PARSE; |
1069 } | |
1070 | FUNC_RET | |
1071 { | |
4207 | 1072 if (! ($$ = make_return_command ($1))) |
2970 | 1073 ABORT_PARSE; |
1074 } | |
1075 ; | |
1076 | |
1077 // ========== | |
1078 // Exceptions | |
1079 // ========== | |
1080 | |
3665 | 1081 except_command : UNWIND stash_comment opt_sep opt_list CLEANUP |
1082 stash_comment opt_sep opt_list END | |
2970 | 1083 { |
3665 | 1084 if (! ($$ = make_unwind_command ($1, $4, $8, $9, $2, $6))) |
2970 | 1085 ABORT_PARSE; |
1086 } | |
3665 | 1087 | TRY stash_comment opt_sep opt_list CATCH |
1088 stash_comment opt_sep opt_list END | |
2970 | 1089 { |
3665 | 1090 if (! ($$ = make_try_command ($1, $4, $8, $9, $2, $6))) |
2970 | 1091 ABORT_PARSE; |
1092 } | |
5344 | 1093 | TRY stash_comment opt_sep opt_list END |
1094 { | |
1095 if (! ($$ = make_try_command ($1, $4, 0, $5, $2, 0))) | |
1096 ABORT_PARSE; | |
1097 } | |
2970 | 1098 ; |
1099 | |
1100 // =========================================== | |
1101 // Some `subroutines' for function definitions | |
1102 // =========================================== | |
1103 | |
7336 | 1104 push_fcn_symtab : // empty |
1105 { | |
1106 symtab_context.push (symbol_table::current_scope ()); | |
1107 symbol_table::set_scope (symbol_table::alloc_scope ()); | |
1108 | |
1109 if (! lexer_flags.parsing_nested_function) | |
1110 symbol_table::set_parent_scope (symbol_table::current_scope ()); | |
1111 } | |
2970 | 1112 ; |
1113 | |
1114 // =========================== | |
1115 // List of function parameters | |
1116 // =========================== | |
1117 | |
1118 param_list_beg : '(' | |
4935 | 1119 { |
1120 lexer_flags.looking_at_parameter_list = true; | |
1121 | |
1122 if (lexer_flags.looking_at_function_handle) | |
1123 { | |
7336 | 1124 symtab_context.push (symbol_table::current_scope ()); |
1125 symbol_table::set_scope (symbol_table::alloc_scope ()); | |
4935 | 1126 lexer_flags.looking_at_function_handle--; |
1127 } | |
1128 } | |
2970 | 1129 ; |
1130 | |
1131 param_list_end : ')' | |
1132 { lexer_flags.looking_at_parameter_list = false; } | |
1133 ; | |
1134 | |
4935 | 1135 param_list : param_list_beg param_list1 param_list_end |
2970 | 1136 { |
1137 lexer_flags.quote_is_transpose = false; | |
4935 | 1138 $$ = $2; |
2970 | 1139 } |
1140 | param_list_beg error | |
1141 { | |
1142 yyerror ("invalid parameter list"); | |
1143 $$ = 0; | |
1144 ABORT_PARSE; | |
1145 } | |
4935 | 1146 ; |
1147 | |
1148 param_list1 : // empty | |
1149 { $$ = 0; } | |
1150 | param_list2 | |
1151 { | |
1152 $1->mark_as_formal_parameters (); | |
7587
1f662945c2be
handle varargin and varargout without keywords
John W. Eaton <jwe@octave.org>
parents:
7562
diff
changeset
|
1153 if ($1->validate (tree_parameter_list::in)) |
1f662945c2be
handle varargin and varargout without keywords
John W. Eaton <jwe@octave.org>
parents:
7562
diff
changeset
|
1154 $$ = $1; |
1f662945c2be
handle varargin and varargout without keywords
John W. Eaton <jwe@octave.org>
parents:
7562
diff
changeset
|
1155 else |
1f662945c2be
handle varargin and varargout without keywords
John W. Eaton <jwe@octave.org>
parents:
7562
diff
changeset
|
1156 ABORT_PARSE; |
4935 | 1157 } |
1158 ; | |
1159 | |
6215 | 1160 param_list2 : decl2 |
4935 | 1161 { $$ = new tree_parameter_list ($1); } |
6215 | 1162 | param_list2 ',' decl2 |
4935 | 1163 { |
1164 $1->append ($3); | |
1165 $$ = $1; | |
2970 | 1166 } |
1167 ; | |
1168 | |
1169 // =================================== | |
1170 // List of function return value names | |
1171 // =================================== | |
1172 | |
7336 | 1173 return_list : '[' ']' |
2970 | 1174 { |
1175 lexer_flags.looking_at_return_list = false; | |
1176 $$ = new tree_parameter_list (); | |
1177 } | |
7336 | 1178 | return_list1 |
1179 { | |
1180 lexer_flags.looking_at_return_list = false; | |
7587
1f662945c2be
handle varargin and varargout without keywords
John W. Eaton <jwe@octave.org>
parents:
7562
diff
changeset
|
1181 if ($1->validate (tree_parameter_list::out)) |
1f662945c2be
handle varargin and varargout without keywords
John W. Eaton <jwe@octave.org>
parents:
7562
diff
changeset
|
1182 $$ = $1; |
1f662945c2be
handle varargin and varargout without keywords
John W. Eaton <jwe@octave.org>
parents:
7562
diff
changeset
|
1183 else |
1f662945c2be
handle varargin and varargout without keywords
John W. Eaton <jwe@octave.org>
parents:
7562
diff
changeset
|
1184 ABORT_PARSE; |
7336 | 1185 } |
1186 | '[' return_list1 ']' | |
2970 | 1187 { |
1188 lexer_flags.looking_at_return_list = false; | |
7587
1f662945c2be
handle varargin and varargout without keywords
John W. Eaton <jwe@octave.org>
parents:
7562
diff
changeset
|
1189 if ($2->validate (tree_parameter_list::out)) |
1f662945c2be
handle varargin and varargout without keywords
John W. Eaton <jwe@octave.org>
parents:
7562
diff
changeset
|
1190 $$ = $2; |
1f662945c2be
handle varargin and varargout without keywords
John W. Eaton <jwe@octave.org>
parents:
7562
diff
changeset
|
1191 else |
1f662945c2be
handle varargin and varargout without keywords
John W. Eaton <jwe@octave.org>
parents:
7562
diff
changeset
|
1192 ABORT_PARSE; |
2970 | 1193 } |
1194 ; | |
1195 | |
1196 return_list1 : identifier | |
6215 | 1197 { $$ = new tree_parameter_list (new tree_decl_elt ($1)); } |
2970 | 1198 | return_list1 ',' identifier |
1199 { | |
6215 | 1200 $1->append (new tree_decl_elt ($3)); |
2970 | 1201 $$ = $1; |
1202 } | |
1203 ; | |
1204 | |
7715
5b4d278ec828
parse scripts completely before executing
John W. Eaton <jwe@octave.org>
parents:
7699
diff
changeset
|
1205 // =========== |
5b4d278ec828
parse scripts completely before executing
John W. Eaton <jwe@octave.org>
parents:
7699
diff
changeset
|
1206 // Script file |
5b4d278ec828
parse scripts completely before executing
John W. Eaton <jwe@octave.org>
parents:
7699
diff
changeset
|
1207 // =========== |
5b4d278ec828
parse scripts completely before executing
John W. Eaton <jwe@octave.org>
parents:
7699
diff
changeset
|
1208 |
5b4d278ec828
parse scripts completely before executing
John W. Eaton <jwe@octave.org>
parents:
7699
diff
changeset
|
1209 script : SCRIPT opt_list END_OF_INPUT |
5b4d278ec828
parse scripts completely before executing
John W. Eaton <jwe@octave.org>
parents:
7699
diff
changeset
|
1210 { |
8658
73c4516fae10
New evaluator and debugger derived from tree-walker class
John W. Eaton <jwe@octave.org>
parents:
8471
diff
changeset
|
1211 tree_statement *end_of_script |
73c4516fae10
New evaluator and debugger derived from tree-walker class
John W. Eaton <jwe@octave.org>
parents:
8471
diff
changeset
|
1212 = make_end ("endscript", input_line_number, |
73c4516fae10
New evaluator and debugger derived from tree-walker class
John W. Eaton <jwe@octave.org>
parents:
8471
diff
changeset
|
1213 current_input_column); |
73c4516fae10
New evaluator and debugger derived from tree-walker class
John W. Eaton <jwe@octave.org>
parents:
8471
diff
changeset
|
1214 |
73c4516fae10
New evaluator and debugger derived from tree-walker class
John W. Eaton <jwe@octave.org>
parents:
8471
diff
changeset
|
1215 make_script ($2, end_of_script); |
73c4516fae10
New evaluator and debugger derived from tree-walker class
John W. Eaton <jwe@octave.org>
parents:
8471
diff
changeset
|
1216 |
7715
5b4d278ec828
parse scripts completely before executing
John W. Eaton <jwe@octave.org>
parents:
7699
diff
changeset
|
1217 $$ = 0; |
5b4d278ec828
parse scripts completely before executing
John W. Eaton <jwe@octave.org>
parents:
7699
diff
changeset
|
1218 } |
5b4d278ec828
parse scripts completely before executing
John W. Eaton <jwe@octave.org>
parents:
7699
diff
changeset
|
1219 ; |
5b4d278ec828
parse scripts completely before executing
John W. Eaton <jwe@octave.org>
parents:
7699
diff
changeset
|
1220 |
2970 | 1221 // =================== |
1222 // Function definition | |
1223 // =================== | |
1224 | |
7336 | 1225 function_beg : push_fcn_symtab FCN stash_comment |
1226 { $$ = $3; } | |
2970 | 1227 ; |
1228 | |
7336 | 1229 function : function_beg function1 |
2970 | 1230 { |
7715
5b4d278ec828
parse scripts completely before executing
John W. Eaton <jwe@octave.org>
parents:
7699
diff
changeset
|
1231 $$ = finish_function (0, $2, $1); |
2970 | 1232 recover_from_parsing_function (); |
1233 } | |
7336 | 1234 | function_beg return_list '=' function1 |
2970 | 1235 { |
7715
5b4d278ec828
parse scripts completely before executing
John W. Eaton <jwe@octave.org>
parents:
7699
diff
changeset
|
1236 $$ = finish_function ($2, $4, $1); |
2970 | 1237 recover_from_parsing_function (); |
1238 } | |
1239 ; | |
1240 | |
7336 | 1241 fcn_name : identifier |
2970 | 1242 { |
4238 | 1243 std::string id_name = $1->name (); |
1244 | |
1245 if (reading_fcn_file | |
1246 && ! lexer_flags.parsing_nested_function) | |
1247 parent_function_name = (curr_fcn_file_name == id_name) | |
1248 ? id_name : curr_fcn_file_name; | |
1249 | |
1250 lexer_flags.parsed_function_name = true; | |
1251 | |
1252 $$ = $1; | |
1253 } | |
1254 ; | |
1255 | |
7336 | 1256 function1 : fcn_name function2 |
4238 | 1257 { |
4872 | 1258 std::string fname = $1->name (); |
1259 | |
1260 delete $1; | |
1261 | |
1262 if (! ($$ = frob_function (fname, $2))) | |
2970 | 1263 ABORT_PARSE; |
1264 } | |
1265 ; | |
1266 | |
7336 | 1267 function2 : param_list opt_sep opt_list function_end |
8658
73c4516fae10
New evaluator and debugger derived from tree-walker class
John W. Eaton <jwe@octave.org>
parents:
8471
diff
changeset
|
1268 { $$ = start_function ($1, $3, $4); } |
7336 | 1269 | opt_sep opt_list function_end |
8658
73c4516fae10
New evaluator and debugger derived from tree-walker class
John W. Eaton <jwe@octave.org>
parents:
8471
diff
changeset
|
1270 { $$ = start_function (0, $2, $3); } |
2970 | 1271 ; |
1272 | |
1273 function_end : END | |
1274 { | |
8658
73c4516fae10
New evaluator and debugger derived from tree-walker class
John W. Eaton <jwe@octave.org>
parents:
8471
diff
changeset
|
1275 if (end_token_ok ($1, token::function_end)) |
73c4516fae10
New evaluator and debugger derived from tree-walker class
John W. Eaton <jwe@octave.org>
parents:
8471
diff
changeset
|
1276 $$ = make_end ("endfunction", $1->line (), $1->column ()); |
73c4516fae10
New evaluator and debugger derived from tree-walker class
John W. Eaton <jwe@octave.org>
parents:
8471
diff
changeset
|
1277 else |
2970 | 1278 ABORT_PARSE; |
1279 } | |
1280 | END_OF_INPUT | |
1281 { | |
4240 | 1282 if (lexer_flags.parsing_nested_function) |
1283 lexer_flags.parsing_nested_function = -1; | |
4238 | 1284 |
8658
73c4516fae10
New evaluator and debugger derived from tree-walker class
John W. Eaton <jwe@octave.org>
parents:
8471
diff
changeset
|
1285 if (reading_fcn_file || reading_script_file |
73c4516fae10
New evaluator and debugger derived from tree-walker class
John W. Eaton <jwe@octave.org>
parents:
8471
diff
changeset
|
1286 || get_input_from_eval_string) |
73c4516fae10
New evaluator and debugger derived from tree-walker class
John W. Eaton <jwe@octave.org>
parents:
8471
diff
changeset
|
1287 $$ = make_end ("endfunction", input_line_number, |
73c4516fae10
New evaluator and debugger derived from tree-walker class
John W. Eaton <jwe@octave.org>
parents:
8471
diff
changeset
|
1288 current_input_column); |
73c4516fae10
New evaluator and debugger derived from tree-walker class
John W. Eaton <jwe@octave.org>
parents:
8471
diff
changeset
|
1289 else |
2970 | 1290 YYABORT; |
1291 } | |
1292 ; | |
1293 | |
1294 // ============= | |
1295 // Miscellaneous | |
1296 // ============= | |
1297 | |
3665 | 1298 stash_comment : // empty |
1299 { $$ = octave_comment_buffer::get_comment (); } | |
1300 ; | |
1301 | |
2970 | 1302 parse_error : LEXICAL_ERROR |
1303 { yyerror ("parse error"); } | |
1304 | error | |
1 | 1305 ; |
1306 | |
2525 | 1307 sep_no_nl : ',' |
1308 { $$ = ','; } | |
1309 | ';' | |
1310 { $$ = ';'; } | |
1311 | sep_no_nl ',' | |
1312 { $$ = $1; } | |
1313 | sep_no_nl ';' | |
1314 { $$ = $1; } | |
1315 ; | |
1316 | |
1317 opt_sep_no_nl : // empty | |
1318 { $$ = 0; } | |
1319 | sep_no_nl | |
1320 { $$ = $1; } | |
1321 ; | |
1322 | |
1323 sep : ',' | |
1324 { $$ = ','; } | |
1325 | ';' | |
1326 { $$ = ';'; } | |
1327 | '\n' | |
1328 { $$ = '\n'; } | |
1329 | sep ',' | |
1330 { $$ = $1; } | |
1331 | sep ';' | |
1332 { $$ = $1; } | |
1333 | sep '\n' | |
1334 { $$ = $1; } | |
1335 ; | |
1336 | |
1337 opt_sep : // empty | |
1338 { $$ = 0; } | |
1339 | sep | |
1340 { $$ = $1; } | |
1341 ; | |
1342 | |
1 | 1343 %% |
1344 | |
666 | 1345 // Generic error messages. |
1346 | |
1 | 1347 static void |
2805 | 1348 yyerror (const char *s) |
1 | 1349 { |
143 | 1350 int err_col = current_input_column - 1; |
1 | 1351 |
5765 | 1352 std::ostringstream output_buf; |
1 | 1353 |
1005 | 1354 if (reading_fcn_file || reading_script_file) |
1355 output_buf << "parse error near line " << input_line_number | |
1607 | 1356 << " of file " << curr_fcn_file_full_name; |
1005 | 1357 else |
1358 output_buf << "parse error:"; | |
581 | 1359 |
1005 | 1360 if (s && strcmp (s, "parse error") != 0) |
1361 output_buf << "\n\n " << s; | |
1362 | |
1363 output_buf << "\n\n"; | |
1 | 1364 |
1755 | 1365 if (! current_input_line.empty ()) |
1 | 1366 { |
1755 | 1367 size_t len = current_input_line.length (); |
1060 | 1368 |
1755 | 1369 if (current_input_line[len-1] == '\n') |
1370 current_input_line.resize (len-1); | |
1005 | 1371 |
4051 | 1372 // Print the line, maybe with a pointer near the error token. |
1005 | 1373 |
1755 | 1374 output_buf << ">>> " << current_input_line << "\n"; |
1060 | 1375 |
1376 if (err_col == 0) | |
1377 err_col = len; | |
1378 | |
1379 for (int i = 0; i < err_col + 3; i++) | |
1380 output_buf << " "; | |
1381 | |
1382 output_buf << "^"; | |
1 | 1383 } |
1005 | 1384 |
5765 | 1385 output_buf << "\n"; |
1386 | |
1387 std::string msg = output_buf.str (); | |
1388 | |
1389 parse_error ("%s", msg.c_str ()); | |
1 | 1390 } |
1391 | |
666 | 1392 // Error mesages for mismatched end tokens. |
1393 | |
496 | 1394 static void |
2805 | 1395 end_error (const char *type, token::end_tok_type ettype, int l, int c) |
496 | 1396 { |
2805 | 1397 static const char *fmt |
1398 = "`%s' command matched by `%s' near line %d column %d"; | |
496 | 1399 |
1400 switch (ettype) | |
1401 { | |
1402 case token::simple_end: | |
1403 error (fmt, type, "end", l, c); | |
1404 break; | |
777 | 1405 |
496 | 1406 case token::for_end: |
1407 error (fmt, type, "endfor", l, c); | |
1408 break; | |
777 | 1409 |
496 | 1410 case token::function_end: |
1411 error (fmt, type, "endfunction", l, c); | |
1412 break; | |
777 | 1413 |
496 | 1414 case token::if_end: |
1415 error (fmt, type, "endif", l, c); | |
1416 break; | |
777 | 1417 |
3233 | 1418 case token::switch_end: |
1419 error (fmt, type, "endswitch", l, c); | |
1420 break; | |
1421 | |
496 | 1422 case token::while_end: |
1423 error (fmt, type, "endwhile", l, c); | |
1424 break; | |
777 | 1425 |
5400 | 1426 case token::try_catch_end: |
1427 error (fmt, type, "end_try_catch", l, c); | |
1428 break; | |
1429 | |
1371 | 1430 case token::unwind_protect_end: |
1431 error (fmt, type, "end_unwind_protect", l, c); | |
1432 break; | |
1433 | |
496 | 1434 default: |
1435 panic_impossible (); | |
1436 break; | |
1437 } | |
1438 } | |
1439 | |
666 | 1440 // Check to see that end tokens are properly matched. |
1441 | |
2857 | 1442 static bool |
1443 end_token_ok (token *tok, token::end_tok_type expected) | |
143 | 1444 { |
2857 | 1445 bool retval = true; |
1446 | |
143 | 1447 token::end_tok_type ettype = tok->ettype (); |
2857 | 1448 |
143 | 1449 if (ettype != expected && ettype != token::simple_end) |
1450 { | |
2857 | 1451 retval = false; |
1452 | |
143 | 1453 yyerror ("parse error"); |
1454 | |
1455 int l = tok->line (); | |
1456 int c = tok->column (); | |
1457 | |
1458 switch (expected) | |
1459 { | |
1460 case token::for_end: | |
1461 end_error ("for", ettype, l, c); | |
1462 break; | |
777 | 1463 |
143 | 1464 case token::function_end: |
1465 end_error ("function", ettype, l, c); | |
1466 break; | |
777 | 1467 |
143 | 1468 case token::if_end: |
1469 end_error ("if", ettype, l, c); | |
1470 break; | |
777 | 1471 |
1489 | 1472 case token::try_catch_end: |
1473 end_error ("try", ettype, l, c); | |
1474 break; | |
1475 | |
2764 | 1476 case token::switch_end: |
1477 end_error ("switch", ettype, l, c); | |
1478 break; | |
1479 | |
1489 | 1480 case token::unwind_protect_end: |
1481 end_error ("unwind_protect", ettype, l, c); | |
1482 break; | |
1483 | |
143 | 1484 case token::while_end: |
1485 end_error ("while", ettype, l, c); | |
1486 break; | |
777 | 1487 |
143 | 1488 default: |
1489 panic_impossible (); | |
1490 break; | |
1491 } | |
1492 } | |
2857 | 1493 |
1494 return retval; | |
143 | 1495 } |
1496 | |
666 | 1497 // Maybe print a warning if an assignment expression is used as the |
1498 // test in a logical expression. | |
1499 | |
496 | 1500 static void |
1501 maybe_warn_assign_as_truth_value (tree_expression *expr) | |
1 | 1502 { |
5781 | 1503 if (expr->is_assignment_expression () |
2961 | 1504 && expr->paren_count () < 2) |
1 | 1505 { |
5781 | 1506 warning_with_id |
1507 ("Octave:assign-as-truth-value", | |
1508 "suggest parenthesis around assignment used as truth value"); | |
1 | 1509 } |
1510 } | |
578 | 1511 |
2764 | 1512 // Maybe print a warning about switch labels that aren't constants. |
1513 | |
1514 static void | |
1515 maybe_warn_variable_switch_label (tree_expression *expr) | |
1516 { | |
5781 | 1517 if (! expr->is_constant ()) |
5878 | 1518 warning_with_id ("Octave:variable-switch-label", |
5781 | 1519 "variable switch label"); |
2764 | 1520 } |
1521 | |
2533 | 1522 static tree_expression * |
1523 fold (tree_binary_expression *e) | |
1524 { | |
3110 | 1525 tree_expression *retval = e; |
1526 | |
3292 | 1527 unwind_protect::begin_frame ("fold_binary_expression"); |
3110 | 1528 |
1529 unwind_protect_int (error_state); | |
4452 | 1530 unwind_protect_int (warning_state); |
3110 | 1531 |
3815 | 1532 unwind_protect_bool (discard_error_messages); |
4452 | 1533 unwind_protect_bool (discard_warning_messages); |
1534 | |
3815 | 1535 discard_error_messages = true; |
4452 | 1536 discard_warning_messages = true; |
2533 | 1537 |
1538 tree_expression *op1 = e->lhs (); | |
1539 tree_expression *op2 = e->rhs (); | |
1540 | |
5161 | 1541 octave_value::binary_op op_type = e->op_type (); |
1542 | |
1543 if (op1->is_constant () && op2->is_constant () | |
5781 | 1544 && (! ((warning_enabled ("Octave:associativity-change") |
5161 | 1545 && (op_type == POW || op_type == EPOW)) |
5781 | 1546 || (warning_enabled ("Octave:precedence-change") |
5161 | 1547 && (op_type == EXPR_OR || op_type == EXPR_OR_OR))))) |
2533 | 1548 { |
8658
73c4516fae10
New evaluator and debugger derived from tree-walker class
John W. Eaton <jwe@octave.org>
parents:
8471
diff
changeset
|
1549 octave_value tmp = e->rvalue1 (); |
2533 | 1550 |
3489 | 1551 if (! (error_state || warning_state)) |
2533 | 1552 { |
8658
73c4516fae10
New evaluator and debugger derived from tree-walker class
John W. Eaton <jwe@octave.org>
parents:
8471
diff
changeset
|
1553 tree_constant *tc_retval |
73c4516fae10
New evaluator and debugger derived from tree-walker class
John W. Eaton <jwe@octave.org>
parents:
8471
diff
changeset
|
1554 = new tree_constant (tmp, op1->line (), op1->column ()); |
2533 | 1555 |
5765 | 1556 std::ostringstream buf; |
2533 | 1557 |
1558 tree_print_code tpc (buf); | |
1559 | |
1560 e->accept (tpc); | |
1561 | |
5765 | 1562 tc_retval->stash_original_text (buf.str ()); |
2533 | 1563 |
1564 delete e; | |
1565 | |
1566 retval = tc_retval; | |
1567 } | |
1568 } | |
3110 | 1569 |
3292 | 1570 unwind_protect::run_frame ("fold_binary_expression"); |
1571 | |
1572 return retval; | |
1573 } | |
1574 | |
1575 static tree_expression * | |
1576 fold (tree_unary_expression *e) | |
1577 { | |
1578 tree_expression *retval = e; | |
1579 | |
1580 unwind_protect::begin_frame ("fold_unary_expression"); | |
1581 | |
1582 unwind_protect_int (error_state); | |
4452 | 1583 unwind_protect_int (warning_state); |
3292 | 1584 |
3815 | 1585 unwind_protect_bool (discard_error_messages); |
4452 | 1586 unwind_protect_bool (discard_warning_messages); |
1587 | |
3815 | 1588 discard_error_messages = true; |
4452 | 1589 discard_warning_messages = true; |
3292 | 1590 |
1591 tree_expression *op = e->operand (); | |
1592 | |
1593 if (op->is_constant ()) | |
1594 { | |
8658
73c4516fae10
New evaluator and debugger derived from tree-walker class
John W. Eaton <jwe@octave.org>
parents:
8471
diff
changeset
|
1595 octave_value tmp = e->rvalue1 (); |
3292 | 1596 |
3489 | 1597 if (! (error_state || warning_state)) |
3292 | 1598 { |
8658
73c4516fae10
New evaluator and debugger derived from tree-walker class
John W. Eaton <jwe@octave.org>
parents:
8471
diff
changeset
|
1599 tree_constant *tc_retval |
73c4516fae10
New evaluator and debugger derived from tree-walker class
John W. Eaton <jwe@octave.org>
parents:
8471
diff
changeset
|
1600 = new tree_constant (tmp, op->line (), op->column ()); |
3292 | 1601 |
5765 | 1602 std::ostringstream buf; |
3292 | 1603 |
1604 tree_print_code tpc (buf); | |
1605 | |
1606 e->accept (tpc); | |
1607 | |
5765 | 1608 tc_retval->stash_original_text (buf.str ()); |
3292 | 1609 |
1610 delete e; | |
1611 | |
1612 retval = tc_retval; | |
1613 } | |
1614 } | |
1615 | |
1616 unwind_protect::run_frame ("fold_unary_expression"); | |
2533 | 1617 |
1618 return retval; | |
1619 } | |
1620 | |
1623 | 1621 // Finish building a range. |
1622 | |
1623 static tree_expression * | |
1624 finish_colon_expression (tree_colon_expression *e) | |
1625 { | |
3110 | 1626 tree_expression *retval = e; |
1627 | |
1628 unwind_protect::begin_frame ("finish_colon_expression"); | |
1629 | |
1630 unwind_protect_int (error_state); | |
4452 | 1631 unwind_protect_int (warning_state); |
3110 | 1632 |
3815 | 1633 unwind_protect_bool (discard_error_messages); |
4452 | 1634 unwind_protect_bool (discard_warning_messages); |
1635 | |
3815 | 1636 discard_error_messages = true; |
4452 | 1637 discard_warning_messages = true; |
1623 | 1638 |
2533 | 1639 tree_expression *base = e->base (); |
1640 tree_expression *limit = e->limit (); | |
1641 tree_expression *incr = e->increment (); | |
1642 | |
2970 | 1643 if (base) |
1623 | 1644 { |
2970 | 1645 if (limit) |
2533 | 1646 { |
2970 | 1647 if (base->is_constant () && limit->is_constant () |
1648 && (! incr || (incr && incr->is_constant ()))) | |
1649 { | |
8658
73c4516fae10
New evaluator and debugger derived from tree-walker class
John W. Eaton <jwe@octave.org>
parents:
8471
diff
changeset
|
1650 octave_value tmp = e->rvalue1 (); |
2970 | 1651 |
3489 | 1652 if (! (error_state || warning_state)) |
2970 | 1653 { |
8658
73c4516fae10
New evaluator and debugger derived from tree-walker class
John W. Eaton <jwe@octave.org>
parents:
8471
diff
changeset
|
1654 tree_constant *tc_retval |
73c4516fae10
New evaluator and debugger derived from tree-walker class
John W. Eaton <jwe@octave.org>
parents:
8471
diff
changeset
|
1655 = new tree_constant (tmp, base->line (), base->column ()); |
2970 | 1656 |
5765 | 1657 std::ostringstream buf; |
2970 | 1658 |
1659 tree_print_code tpc (buf); | |
1660 | |
1661 e->accept (tpc); | |
1662 | |
5765 | 1663 tc_retval->stash_original_text (buf.str ()); |
2970 | 1664 |
1665 delete e; | |
1666 | |
1667 retval = tc_retval; | |
1668 } | |
1669 } | |
2533 | 1670 } |
1671 else | |
2970 | 1672 { |
2990 | 1673 e->preserve_base (); |
1674 delete e; | |
2970 | 1675 |
5775 | 1676 // FIXME -- need to attempt constant folding here |
2970 | 1677 // too (we need a generic way to do that). |
1678 retval = base; | |
1679 } | |
1623 | 1680 } |
1681 | |
3110 | 1682 unwind_protect::run_frame ("finish_colon_expression"); |
1683 | |
1623 | 1684 return retval; |
1685 } | |
1686 | |
1607 | 1687 // Make a constant. |
1688 | |
2375 | 1689 static tree_constant * |
1607 | 1690 make_constant (int op, token *tok_val) |
1691 { | |
1692 int l = tok_val->line (); | |
1693 int c = tok_val->column (); | |
1694 | |
3216 | 1695 tree_constant *retval = 0; |
1607 | 1696 |
1697 switch (op) | |
1698 { | |
1699 case NUM: | |
2533 | 1700 { |
2883 | 1701 octave_value tmp (tok_val->number ()); |
1702 retval = new tree_constant (tmp, l, c); | |
2533 | 1703 retval->stash_original_text (tok_val->text_rep ()); |
1704 } | |
1607 | 1705 break; |
1706 | |
1707 case IMAG_NUM: | |
1708 { | |
2883 | 1709 octave_value tmp (Complex (0.0, tok_val->number ())); |
1710 retval = new tree_constant (tmp, l, c); | |
1607 | 1711 retval->stash_original_text (tok_val->text_rep ()); |
1712 } | |
1713 break; | |
1714 | |
5279 | 1715 case DQ_STRING: |
1716 case SQ_STRING: | |
2883 | 1717 { |
7699
27a5f578750c
make_constant: handle escape sequences in dq-strings
John W. Eaton <jwe@octave.org>
parents:
7690
diff
changeset
|
1718 std::string txt = tok_val->text (); |
27a5f578750c
make_constant: handle escape sequences in dq-strings
John W. Eaton <jwe@octave.org>
parents:
7690
diff
changeset
|
1719 |
8150
283989f2da9b
make null assignment matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
8064
diff
changeset
|
1720 char delim = op == DQ_STRING ? '"' : '\''; |
283989f2da9b
make null assignment matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
8064
diff
changeset
|
1721 octave_value tmp (txt, delim); |
283989f2da9b
make null assignment matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
8064
diff
changeset
|
1722 |
283989f2da9b
make null assignment matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
8064
diff
changeset
|
1723 if (txt.empty ()) |
283989f2da9b
make null assignment matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
8064
diff
changeset
|
1724 { |
283989f2da9b
make null assignment matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
8064
diff
changeset
|
1725 if (op == DQ_STRING) |
283989f2da9b
make null assignment matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
8064
diff
changeset
|
1726 tmp = octave_null_str::instance; |
283989f2da9b
make null assignment matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
8064
diff
changeset
|
1727 else |
283989f2da9b
make null assignment matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
8064
diff
changeset
|
1728 tmp = octave_null_sq_str::instance; |
283989f2da9b
make null assignment matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
8064
diff
changeset
|
1729 } |
283989f2da9b
make null assignment matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
8064
diff
changeset
|
1730 |
2883 | 1731 retval = new tree_constant (tmp, l, c); |
7699
27a5f578750c
make_constant: handle escape sequences in dq-strings
John W. Eaton <jwe@octave.org>
parents:
7690
diff
changeset
|
1732 |
27a5f578750c
make_constant: handle escape sequences in dq-strings
John W. Eaton <jwe@octave.org>
parents:
7690
diff
changeset
|
1733 if (op == DQ_STRING) |
27a5f578750c
make_constant: handle escape sequences in dq-strings
John W. Eaton <jwe@octave.org>
parents:
7690
diff
changeset
|
1734 txt = undo_string_escapes (txt); |
27a5f578750c
make_constant: handle escape sequences in dq-strings
John W. Eaton <jwe@octave.org>
parents:
7690
diff
changeset
|
1735 |
7690
97e535ec65db
make_constant: stash original text for strings
John W. Eaton <jwe@octave.org>
parents:
7634
diff
changeset
|
1736 // FIXME -- maybe this should also be handled by |
97e535ec65db
make_constant: stash original text for strings
John W. Eaton <jwe@octave.org>
parents:
7634
diff
changeset
|
1737 // tok_val->text_rep () for character strings? |
7699
27a5f578750c
make_constant: handle escape sequences in dq-strings
John W. Eaton <jwe@octave.org>
parents:
7690
diff
changeset
|
1738 retval->stash_original_text (delim + txt + delim); |
2883 | 1739 } |
1607 | 1740 break; |
1741 | |
1742 default: | |
1743 panic_impossible (); | |
1744 break; | |
1745 } | |
1746 | |
1747 return retval; | |
1748 } | |
1749 | |
4342 | 1750 // Make a function handle. |
1751 | |
1752 static tree_fcn_handle * | |
1753 make_fcn_handle (token *tok_val) | |
1754 { | |
1755 int l = tok_val->line (); | |
1756 int c = tok_val->column (); | |
1757 | |
1758 tree_fcn_handle *retval = new tree_fcn_handle (tok_val->text (), l, c); | |
1759 | |
1760 return retval; | |
1761 } | |
1762 | |
4935 | 1763 // Make an anonymous function handle. |
1764 | |
5861 | 1765 static tree_anon_fcn_handle * |
4935 | 1766 make_anon_fcn_handle (tree_parameter_list *param_list, tree_statement *stmt) |
1767 { | |
5775 | 1768 // FIXME -- need to get these from the location of the @ symbol. |
4935 | 1769 |
1770 int l = -1; | |
1771 int c = -1; | |
1772 | |
1773 tree_parameter_list *ret_list = 0; | |
1774 | |
7336 | 1775 symbol_table::scope_id fcn_scope = symbol_table::current_scope (); |
5861 | 1776 |
1777 if (symtab_context.empty ()) | |
1778 panic_impossible (); | |
1779 | |
7336 | 1780 symbol_table::set_scope (symtab_context.top ()); |
5861 | 1781 |
1782 symtab_context.pop (); | |
1783 | |
7351 | 1784 stmt->set_print_flag (false); |
4935 | 1785 |
1786 tree_statement_list *body = new tree_statement_list (stmt); | |
1787 | |
8658
73c4516fae10
New evaluator and debugger derived from tree-walker class
John W. Eaton <jwe@octave.org>
parents:
8471
diff
changeset
|
1788 body->mark_as_anon_function_body (); |
73c4516fae10
New evaluator and debugger derived from tree-walker class
John W. Eaton <jwe@octave.org>
parents:
8471
diff
changeset
|
1789 |
5861 | 1790 tree_anon_fcn_handle *retval |
7336 | 1791 = new tree_anon_fcn_handle (param_list, ret_list, body, fcn_scope, l, c); |
4935 | 1792 |
1793 return retval; | |
1794 } | |
1795 | |
5161 | 1796 static void |
1797 maybe_warn_associativity_change (tree_expression *op) | |
1798 { | |
5781 | 1799 if (op->paren_count () == 0 && op->is_binary_expression ()) |
5161 | 1800 { |
1801 tree_binary_expression *e | |
1802 = dynamic_cast<tree_binary_expression *> (op); | |
1803 | |
1804 octave_value::binary_op op_type = e->op_type (); | |
1805 | |
1806 if (op_type == octave_value::op_pow | |
1807 || op_type == octave_value::op_el_pow) | |
1808 { | |
1809 std::string op_str = octave_value::binary_op_as_string (op_type); | |
1810 | |
5781 | 1811 warning_with_id |
1812 ("Octave:associativity-change", | |
1813 "meaning may have changed due to change in associativity for %s operator", op_str.c_str ()); | |
5161 | 1814 } |
1815 } | |
1816 } | |
1817 | |
666 | 1818 // Build a binary expression. |
1819 | |
578 | 1820 static tree_expression * |
1821 make_binary_op (int op, tree_expression *op1, token *tok_val, | |
1822 tree_expression *op2) | |
1823 { | |
2883 | 1824 octave_value::binary_op t = octave_value::unknown_binary_op; |
1623 | 1825 |
578 | 1826 switch (op) |
1827 { | |
1828 case POW: | |
3525 | 1829 t = octave_value::op_pow; |
5161 | 1830 maybe_warn_associativity_change (op1); |
578 | 1831 break; |
777 | 1832 |
578 | 1833 case EPOW: |
3525 | 1834 t = octave_value::op_el_pow; |
5161 | 1835 maybe_warn_associativity_change (op1); |
578 | 1836 break; |
777 | 1837 |
578 | 1838 case '+': |
3525 | 1839 t = octave_value::op_add; |
578 | 1840 break; |
777 | 1841 |
578 | 1842 case '-': |
3525 | 1843 t = octave_value::op_sub; |
578 | 1844 break; |
777 | 1845 |
578 | 1846 case '*': |
3525 | 1847 t = octave_value::op_mul; |
578 | 1848 break; |
777 | 1849 |
578 | 1850 case '/': |
3525 | 1851 t = octave_value::op_div; |
578 | 1852 break; |
777 | 1853 |
578 | 1854 case EMUL: |
3525 | 1855 t = octave_value::op_el_mul; |
578 | 1856 break; |
777 | 1857 |
578 | 1858 case EDIV: |
3525 | 1859 t = octave_value::op_el_div; |
578 | 1860 break; |
777 | 1861 |
578 | 1862 case LEFTDIV: |
3525 | 1863 t = octave_value::op_ldiv; |
578 | 1864 break; |
777 | 1865 |
578 | 1866 case ELEFTDIV: |
3525 | 1867 t = octave_value::op_el_ldiv; |
578 | 1868 break; |
777 | 1869 |
2899 | 1870 case LSHIFT: |
3525 | 1871 t = octave_value::op_lshift; |
2899 | 1872 break; |
1873 | |
1874 case RSHIFT: | |
3525 | 1875 t = octave_value::op_rshift; |
2899 | 1876 break; |
1877 | |
578 | 1878 case EXPR_LT: |
3525 | 1879 t = octave_value::op_lt; |
578 | 1880 break; |
777 | 1881 |
578 | 1882 case EXPR_LE: |
3525 | 1883 t = octave_value::op_le; |
578 | 1884 break; |
777 | 1885 |
578 | 1886 case EXPR_EQ: |
3525 | 1887 t = octave_value::op_eq; |
578 | 1888 break; |
777 | 1889 |
578 | 1890 case EXPR_GE: |
3525 | 1891 t = octave_value::op_ge; |
578 | 1892 break; |
777 | 1893 |
578 | 1894 case EXPR_GT: |
3525 | 1895 t = octave_value::op_gt; |
578 | 1896 break; |
777 | 1897 |
578 | 1898 case EXPR_NE: |
3525 | 1899 t = octave_value::op_ne; |
578 | 1900 break; |
777 | 1901 |
578 | 1902 case EXPR_AND: |
3525 | 1903 t = octave_value::op_el_and; |
578 | 1904 break; |
777 | 1905 |
578 | 1906 case EXPR_OR: |
3525 | 1907 t = octave_value::op_el_or; |
5781 | 1908 if (op2->paren_count () == 0 && op2->is_binary_expression ()) |
4023 | 1909 { |
1910 tree_binary_expression *e | |
1911 = dynamic_cast<tree_binary_expression *> (op2); | |
1912 | |
1913 if (e->op_type () == octave_value::op_el_and) | |
5781 | 1914 warning_with_id |
1915 ("Octave:precedence-change", | |
1916 "meaning may have changed due to change in precedence for & and | operators"); | |
4023 | 1917 } |
578 | 1918 break; |
777 | 1919 |
578 | 1920 default: |
1921 panic_impossible (); | |
1922 break; | |
1923 } | |
1924 | |
1925 int l = tok_val->line (); | |
1926 int c = tok_val->column (); | |
1927 | |
2533 | 1928 tree_binary_expression *e |
7800
5861b95e9879
support for compound operators, implement trans_mul, mul_trans, herm_mul and mul_herm
Jaroslav Hajek <highegg@gmail.com>
parents:
7787
diff
changeset
|
1929 = maybe_compound_binary_expression (op1, op2, l, c, t); |
1623 | 1930 |
2533 | 1931 return fold (e); |
578 | 1932 } |
1933 | |
2375 | 1934 // Build a boolean expression. |
666 | 1935 |
578 | 1936 static tree_expression * |
2375 | 1937 make_boolean_op (int op, tree_expression *op1, token *tok_val, |
1938 tree_expression *op2) | |
578 | 1939 { |
2375 | 1940 tree_boolean_expression::type t; |
1941 | |
578 | 1942 switch (op) |
1943 { | |
2375 | 1944 case EXPR_AND_AND: |
2805 | 1945 t = tree_boolean_expression::bool_and; |
578 | 1946 break; |
777 | 1947 |
2375 | 1948 case EXPR_OR_OR: |
2805 | 1949 t = tree_boolean_expression::bool_or; |
5781 | 1950 if (op2->paren_count () == 0 && op2->is_boolean_expression ()) |
4023 | 1951 { |
1952 tree_boolean_expression *e | |
1953 = dynamic_cast<tree_boolean_expression *> (op2); | |
1954 | |
1955 if (e->op_type () == tree_boolean_expression::bool_and) | |
5781 | 1956 warning_with_id |
1957 ("Octave:precedence-change", | |
1958 "meaning may have changed due to change in precedence for && and || operators"); | |
4023 | 1959 } |
578 | 1960 break; |
777 | 1961 |
578 | 1962 default: |
1963 panic_impossible (); | |
1964 break; | |
1965 } | |
1966 | |
1967 int l = tok_val->line (); | |
1968 int c = tok_val->column (); | |
1969 | |
2533 | 1970 tree_boolean_expression *e |
1971 = new tree_boolean_expression (op1, op2, l, c, t); | |
2375 | 1972 |
2533 | 1973 return fold (e); |
578 | 1974 } |
1975 | |
2375 | 1976 // Build a prefix expression. |
666 | 1977 |
578 | 1978 static tree_expression * |
2960 | 1979 make_prefix_op (int op, tree_expression *op1, token *tok_val) |
578 | 1980 { |
3203 | 1981 octave_value::unary_op t = octave_value::unknown_unary_op; |
2375 | 1982 |
578 | 1983 switch (op) |
1984 { | |
2960 | 1985 case EXPR_NOT: |
3525 | 1986 t = octave_value::op_not; |
2960 | 1987 break; |
1988 | |
4965 | 1989 case '+': |
1990 t = octave_value::op_uplus; | |
1991 break; | |
1992 | |
2960 | 1993 case '-': |
3525 | 1994 t = octave_value::op_uminus; |
2960 | 1995 break; |
1996 | |
578 | 1997 case PLUS_PLUS: |
3525 | 1998 t = octave_value::op_incr; |
578 | 1999 break; |
777 | 2000 |
578 | 2001 case MINUS_MINUS: |
3525 | 2002 t = octave_value::op_decr; |
578 | 2003 break; |
777 | 2004 |
578 | 2005 default: |
2006 panic_impossible (); | |
2007 break; | |
2008 } | |
2009 | |
2010 int l = tok_val->line (); | |
2011 int c = tok_val->column (); | |
2012 | |
3292 | 2013 tree_prefix_expression *e |
2014 = new tree_prefix_expression (op1, l, c, t); | |
2015 | |
2016 return fold (e); | |
578 | 2017 } |
2018 | |
2375 | 2019 // Build a postfix expression. |
666 | 2020 |
578 | 2021 static tree_expression * |
2960 | 2022 make_postfix_op (int op, tree_expression *op1, token *tok_val) |
578 | 2023 { |
3203 | 2024 octave_value::unary_op t = octave_value::unknown_unary_op; |
1623 | 2025 |
578 | 2026 switch (op) |
2027 { | |
2960 | 2028 case QUOTE: |
3525 | 2029 t = octave_value::op_hermitian; |
2960 | 2030 break; |
2031 | |
2032 case TRANSPOSE: | |
3525 | 2033 t = octave_value::op_transpose; |
2960 | 2034 break; |
2035 | |
2375 | 2036 case PLUS_PLUS: |
3525 | 2037 t = octave_value::op_incr; |
578 | 2038 break; |
777 | 2039 |
2375 | 2040 case MINUS_MINUS: |
3525 | 2041 t = octave_value::op_decr; |
578 | 2042 break; |
777 | 2043 |
578 | 2044 default: |
2045 panic_impossible (); | |
2046 break; | |
2047 } | |
2048 | |
2049 int l = tok_val->line (); | |
2050 int c = tok_val->column (); | |
2051 | |
3292 | 2052 tree_postfix_expression *e |
2053 = new tree_postfix_expression (op1, l, c, t); | |
2054 | |
2055 return fold (e); | |
1623 | 2056 } |
2057 | |
2058 // Build an unwind-protect command. | |
2059 | |
2060 static tree_command * | |
2061 make_unwind_command (token *unwind_tok, tree_statement_list *body, | |
3665 | 2062 tree_statement_list *cleanup, token *end_tok, |
2063 octave_comment_list *lc, octave_comment_list *mc) | |
1623 | 2064 { |
2065 tree_command *retval = 0; | |
2066 | |
2857 | 2067 if (end_token_ok (end_tok, token::unwind_protect_end)) |
1623 | 2068 { |
3665 | 2069 octave_comment_list *tc = octave_comment_buffer::get_comment (); |
2070 | |
1623 | 2071 int l = unwind_tok->line (); |
2072 int c = unwind_tok->column (); | |
2073 | |
3665 | 2074 retval = new tree_unwind_protect_command (body, cleanup, |
2075 lc, mc, tc, l, c); | |
1623 | 2076 } |
2077 | |
2078 return retval; | |
2079 } | |
2080 | |
2081 // Build a try-catch command. | |
2082 | |
2083 static tree_command * | |
2084 make_try_command (token *try_tok, tree_statement_list *body, | |
3665 | 2085 tree_statement_list *cleanup, token *end_tok, |
2086 octave_comment_list *lc, octave_comment_list *mc) | |
1623 | 2087 { |
2088 tree_command *retval = 0; | |
2089 | |
2857 | 2090 if (end_token_ok (end_tok, token::try_catch_end)) |
1623 | 2091 { |
3665 | 2092 octave_comment_list *tc = octave_comment_buffer::get_comment (); |
2093 | |
1623 | 2094 int l = try_tok->line (); |
2095 int c = try_tok->column (); | |
2096 | |
3665 | 2097 retval = new tree_try_catch_command (body, cleanup, |
2098 lc, mc, tc, l, c); | |
1623 | 2099 } |
2100 | |
2101 return retval; | |
2102 } | |
2103 | |
2104 // Build a while command. | |
2105 | |
2106 static tree_command * | |
2107 make_while_command (token *while_tok, tree_expression *expr, | |
3665 | 2108 tree_statement_list *body, token *end_tok, |
2109 octave_comment_list *lc) | |
1623 | 2110 { |
2111 tree_command *retval = 0; | |
2112 | |
2113 maybe_warn_assign_as_truth_value (expr); | |
2114 | |
2857 | 2115 if (end_token_ok (end_tok, token::while_end)) |
1623 | 2116 { |
3665 | 2117 octave_comment_list *tc = octave_comment_buffer::get_comment (); |
2118 | |
1826 | 2119 lexer_flags.looping--; |
1623 | 2120 |
2121 int l = while_tok->line (); | |
2122 int c = while_tok->column (); | |
2123 | |
3665 | 2124 retval = new tree_while_command (expr, body, lc, tc, l, c); |
1623 | 2125 } |
2126 | |
2127 return retval; | |
2128 } | |
2129 | |
3484 | 2130 // Build a do-until command. |
2131 | |
2132 static tree_command * | |
8658
73c4516fae10
New evaluator and debugger derived from tree-walker class
John W. Eaton <jwe@octave.org>
parents:
8471
diff
changeset
|
2133 make_do_until_command (token *until_tok, tree_statement_list *body, |
3665 | 2134 tree_expression *expr, octave_comment_list *lc) |
3484 | 2135 { |
2136 tree_command *retval = 0; | |
2137 | |
2138 maybe_warn_assign_as_truth_value (expr); | |
2139 | |
3665 | 2140 octave_comment_list *tc = octave_comment_buffer::get_comment (); |
2141 | |
3484 | 2142 lexer_flags.looping--; |
2143 | |
8658
73c4516fae10
New evaluator and debugger derived from tree-walker class
John W. Eaton <jwe@octave.org>
parents:
8471
diff
changeset
|
2144 int l = until_tok->line (); |
73c4516fae10
New evaluator and debugger derived from tree-walker class
John W. Eaton <jwe@octave.org>
parents:
8471
diff
changeset
|
2145 int c = until_tok->column (); |
3484 | 2146 |
3665 | 2147 retval = new tree_do_until_command (expr, body, lc, tc, l, c); |
3484 | 2148 |
2149 return retval; | |
2150 } | |
2151 | |
1623 | 2152 // Build a for command. |
2153 | |
2154 static tree_command * | |
2970 | 2155 make_for_command (token *for_tok, tree_argument_list *lhs, |
1623 | 2156 tree_expression *expr, tree_statement_list *body, |
3665 | 2157 token *end_tok, octave_comment_list *lc) |
1623 | 2158 { |
2159 tree_command *retval = 0; | |
2160 | |
2857 | 2161 if (end_token_ok (end_tok, token::for_end)) |
1623 | 2162 { |
3665 | 2163 octave_comment_list *tc = octave_comment_buffer::get_comment (); |
2164 | |
1826 | 2165 lexer_flags.looping--; |
1623 | 2166 |
2167 int l = for_tok->line (); | |
2168 int c = for_tok->column (); | |
2169 | |
2970 | 2170 if (lhs->length () == 1) |
2171 { | |
2172 tree_expression *tmp = lhs->remove_front (); | |
2173 | |
3665 | 2174 retval = new tree_simple_for_command (tmp, expr, body, |
2175 lc, tc, l, c); | |
2970 | 2176 |
2177 delete lhs; | |
2178 } | |
2179 else | |
3665 | 2180 retval = new tree_complex_for_command (lhs, expr, body, |
2181 lc, tc, l, c); | |
1623 | 2182 } |
2183 | |
2184 return retval; | |
2185 } | |
2186 | |
4207 | 2187 // Build a break command. |
2188 | |
2189 static tree_command * | |
2190 make_break_command (token *break_tok) | |
1623 | 2191 { |
4207 | 2192 tree_command *retval = 0; |
1623 | 2193 |
2620 | 2194 int l = break_tok->line (); |
2195 int c = break_tok->column (); | |
2196 | |
8669
33783e94fb16
line number fixes and other evaluator tweaks
John W. Eaton <jwe@octave.org>
parents:
8658
diff
changeset
|
2197 // We check to see if we are evaluating a function, script, or loop |
33783e94fb16
line number fixes and other evaluator tweaks
John W. Eaton <jwe@octave.org>
parents:
8658
diff
changeset
|
2198 // so that we don't turn eval ("break;") inside a function, script, |
33783e94fb16
line number fixes and other evaluator tweaks
John W. Eaton <jwe@octave.org>
parents:
8658
diff
changeset
|
2199 // or loop into a no-op command. |
33783e94fb16
line number fixes and other evaluator tweaks
John W. Eaton <jwe@octave.org>
parents:
8658
diff
changeset
|
2200 |
3489 | 2201 if (lexer_flags.looping || lexer_flags.defining_func |
8669
33783e94fb16
line number fixes and other evaluator tweaks
John W. Eaton <jwe@octave.org>
parents:
8658
diff
changeset
|
2202 || reading_script_file || tree_evaluator::in_fcn_or_script_body |
33783e94fb16
line number fixes and other evaluator tweaks
John W. Eaton <jwe@octave.org>
parents:
8658
diff
changeset
|
2203 || tree_evaluator::in_loop_command) |
4207 | 2204 retval = new tree_break_command (l, c); |
1623 | 2205 else |
4207 | 2206 retval = new tree_no_op_command ("break", l, c); |
1623 | 2207 |
2208 return retval; | |
2209 } | |
2210 | |
4207 | 2211 // Build a continue command. |
2212 | |
2213 static tree_command * | |
2214 make_continue_command (token *continue_tok) | |
1623 | 2215 { |
4207 | 2216 tree_command *retval = 0; |
1623 | 2217 |
2620 | 2218 int l = continue_tok->line (); |
2219 int c = continue_tok->column (); | |
2220 | |
8669
33783e94fb16
line number fixes and other evaluator tweaks
John W. Eaton <jwe@octave.org>
parents:
8658
diff
changeset
|
2221 // We check to see if we are evaluating a loop so that we don't turn |
33783e94fb16
line number fixes and other evaluator tweaks
John W. Eaton <jwe@octave.org>
parents:
8658
diff
changeset
|
2222 // eval ("continue;") into a no-op command inside a loop. |
33783e94fb16
line number fixes and other evaluator tweaks
John W. Eaton <jwe@octave.org>
parents:
8658
diff
changeset
|
2223 |
33783e94fb16
line number fixes and other evaluator tweaks
John W. Eaton <jwe@octave.org>
parents:
8658
diff
changeset
|
2224 if (lexer_flags.looping || tree_evaluator::in_loop_command) |
4207 | 2225 retval = new tree_continue_command (l, c); |
1623 | 2226 else |
4207 | 2227 retval = new tree_no_op_command ("continue", l, c); |
1623 | 2228 |
2229 return retval; | |
2230 } | |
2231 | |
4207 | 2232 // Build a return command. |
2233 | |
2234 static tree_command * | |
2235 make_return_command (token *return_tok) | |
1623 | 2236 { |
4207 | 2237 tree_command *retval = 0; |
1623 | 2238 |
2620 | 2239 int l = return_tok->line (); |
2240 int c = return_tok->column (); | |
2241 | |
7787
6b521b1e3631
Add dbquit and make dbstep compatible. Use parser in debug mode to handle multi-line input
David Bateman <dbateman@free.fr>
parents:
7761
diff
changeset
|
2242 if (Vdebugging) |
6b521b1e3631
Add dbquit and make dbstep compatible. Use parser in debug mode to handle multi-line input
David Bateman <dbateman@free.fr>
parents:
7761
diff
changeset
|
2243 { |
6b521b1e3631
Add dbquit and make dbstep compatible. Use parser in debug mode to handle multi-line input
David Bateman <dbateman@free.fr>
parents:
7761
diff
changeset
|
2244 Vdebugging = false; |
6b521b1e3631
Add dbquit and make dbstep compatible. Use parser in debug mode to handle multi-line input
David Bateman <dbateman@free.fr>
parents:
7761
diff
changeset
|
2245 |
6b521b1e3631
Add dbquit and make dbstep compatible. Use parser in debug mode to handle multi-line input
David Bateman <dbateman@free.fr>
parents:
7761
diff
changeset
|
2246 retval = new tree_no_op_command ("return", l, c); |
6b521b1e3631
Add dbquit and make dbstep compatible. Use parser in debug mode to handle multi-line input
David Bateman <dbateman@free.fr>
parents:
7761
diff
changeset
|
2247 } |
1623 | 2248 else |
7787
6b521b1e3631
Add dbquit and make dbstep compatible. Use parser in debug mode to handle multi-line input
David Bateman <dbateman@free.fr>
parents:
7761
diff
changeset
|
2249 { |
8669
33783e94fb16
line number fixes and other evaluator tweaks
John W. Eaton <jwe@octave.org>
parents:
8658
diff
changeset
|
2250 // We check to see if we are evaluating a function or script so |
33783e94fb16
line number fixes and other evaluator tweaks
John W. Eaton <jwe@octave.org>
parents:
8658
diff
changeset
|
2251 // that we don't turn eval ("return;") inside a function, script, |
33783e94fb16
line number fixes and other evaluator tweaks
John W. Eaton <jwe@octave.org>
parents:
8658
diff
changeset
|
2252 // or loop into a no-op command. |
33783e94fb16
line number fixes and other evaluator tweaks
John W. Eaton <jwe@octave.org>
parents:
8658
diff
changeset
|
2253 |
7787
6b521b1e3631
Add dbquit and make dbstep compatible. Use parser in debug mode to handle multi-line input
David Bateman <dbateman@free.fr>
parents:
7761
diff
changeset
|
2254 if (lexer_flags.defining_func || reading_script_file |
8669
33783e94fb16
line number fixes and other evaluator tweaks
John W. Eaton <jwe@octave.org>
parents:
8658
diff
changeset
|
2255 || tree_evaluator::in_fcn_or_script_body) |
7787
6b521b1e3631
Add dbquit and make dbstep compatible. Use parser in debug mode to handle multi-line input
David Bateman <dbateman@free.fr>
parents:
7761
diff
changeset
|
2256 retval = new tree_return_command (l, c); |
6b521b1e3631
Add dbquit and make dbstep compatible. Use parser in debug mode to handle multi-line input
David Bateman <dbateman@free.fr>
parents:
7761
diff
changeset
|
2257 else |
6b521b1e3631
Add dbquit and make dbstep compatible. Use parser in debug mode to handle multi-line input
David Bateman <dbateman@free.fr>
parents:
7761
diff
changeset
|
2258 retval = new tree_no_op_command ("return", l, c); |
6b521b1e3631
Add dbquit and make dbstep compatible. Use parser in debug mode to handle multi-line input
David Bateman <dbateman@free.fr>
parents:
7761
diff
changeset
|
2259 } |
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 * | |
8658
73c4516fae10
New evaluator and debugger derived from tree-walker class
John W. Eaton <jwe@octave.org>
parents:
8471
diff
changeset
|
2300 make_elseif_clause (token *elseif_tok, tree_expression *expr, |
73c4516fae10
New evaluator and debugger derived from tree-walker class
John W. Eaton <jwe@octave.org>
parents:
8471
diff
changeset
|
2301 tree_statement_list *list, octave_comment_list *lc) |
1623 | 2302 { |
2303 maybe_warn_assign_as_truth_value (expr); | |
2304 | |
8658
73c4516fae10
New evaluator and debugger derived from tree-walker class
John W. Eaton <jwe@octave.org>
parents:
8471
diff
changeset
|
2305 int l = elseif_tok->line (); |
73c4516fae10
New evaluator and debugger derived from tree-walker class
John W. Eaton <jwe@octave.org>
parents:
8471
diff
changeset
|
2306 int c = elseif_tok->column (); |
73c4516fae10
New evaluator and debugger derived from tree-walker class
John W. Eaton <jwe@octave.org>
parents:
8471
diff
changeset
|
2307 |
73c4516fae10
New evaluator and debugger derived from tree-walker class
John W. Eaton <jwe@octave.org>
parents:
8471
diff
changeset
|
2308 return new tree_if_clause (expr, list, lc, l, c); |
1623 | 2309 } |
2310 | |
2764 | 2311 // Finish a switch command. |
2312 | |
2313 static tree_switch_command * | |
2314 finish_switch_command (token *switch_tok, tree_expression *expr, | |
3665 | 2315 tree_switch_case_list *list, token *end_tok, |
2316 octave_comment_list *lc) | |
2764 | 2317 { |
2318 tree_switch_command *retval = 0; | |
2319 | |
2857 | 2320 if (end_token_ok (end_tok, token::switch_end)) |
2764 | 2321 { |
3665 | 2322 octave_comment_list *tc = octave_comment_buffer::get_comment (); |
2323 | |
2764 | 2324 int l = switch_tok->line (); |
2325 int c = switch_tok->column (); | |
2326 | |
3665 | 2327 retval = new tree_switch_command (expr, list, lc, tc, l, c); |
2764 | 2328 } |
2329 | |
2330 return retval; | |
2331 } | |
2332 | |
2333 // Build a switch case. | |
2334 | |
2335 static tree_switch_case * | |
8658
73c4516fae10
New evaluator and debugger derived from tree-walker class
John W. Eaton <jwe@octave.org>
parents:
8471
diff
changeset
|
2336 make_switch_case (token *case_tok, tree_expression *expr, |
73c4516fae10
New evaluator and debugger derived from tree-walker class
John W. Eaton <jwe@octave.org>
parents:
8471
diff
changeset
|
2337 tree_statement_list *list, octave_comment_list *lc) |
2764 | 2338 { |
2339 maybe_warn_variable_switch_label (expr); | |
2340 | |
8658
73c4516fae10
New evaluator and debugger derived from tree-walker class
John W. Eaton <jwe@octave.org>
parents:
8471
diff
changeset
|
2341 int l = case_tok->line (); |
73c4516fae10
New evaluator and debugger derived from tree-walker class
John W. Eaton <jwe@octave.org>
parents:
8471
diff
changeset
|
2342 int c = case_tok->column (); |
73c4516fae10
New evaluator and debugger derived from tree-walker class
John W. Eaton <jwe@octave.org>
parents:
8471
diff
changeset
|
2343 |
73c4516fae10
New evaluator and debugger derived from tree-walker class
John W. Eaton <jwe@octave.org>
parents:
8471
diff
changeset
|
2344 return new tree_switch_case (expr, list, lc, l, c); |
2764 | 2345 } |
2346 | |
1623 | 2347 // Build an assignment to a variable. |
2348 | |
2349 static tree_expression * | |
2970 | 2350 make_assign_op (int op, tree_argument_list *lhs, token *eq_tok, |
2351 tree_expression *rhs) | |
1623 | 2352 { |
2970 | 2353 tree_expression *retval = 0; |
2354 | |
2883 | 2355 octave_value::assign_op t = octave_value::unknown_assign_op; |
2356 | |
2357 switch (op) | |
2358 { | |
2359 case '=': | |
3525 | 2360 t = octave_value::op_asn_eq; |
2883 | 2361 break; |
2362 | |
2363 case ADD_EQ: | |
3525 | 2364 t = octave_value::op_add_eq; |
2883 | 2365 break; |
2366 | |
2367 case SUB_EQ: | |
3525 | 2368 t = octave_value::op_sub_eq; |
2883 | 2369 break; |
2370 | |
2371 case MUL_EQ: | |
3525 | 2372 t = octave_value::op_mul_eq; |
2883 | 2373 break; |
2374 | |
2375 case DIV_EQ: | |
3525 | 2376 t = octave_value::op_div_eq; |
2883 | 2377 break; |
2378 | |
3204 | 2379 case LEFTDIV_EQ: |
3525 | 2380 t = octave_value::op_ldiv_eq; |
3204 | 2381 break; |
2382 | |
4018 | 2383 case POW_EQ: |
2384 t = octave_value::op_pow_eq; | |
2385 break; | |
2386 | |
2899 | 2387 case LSHIFT_EQ: |
3525 | 2388 t = octave_value::op_lshift_eq; |
2899 | 2389 break; |
2390 | |
2391 case RSHIFT_EQ: | |
3525 | 2392 t = octave_value::op_rshift_eq; |
2899 | 2393 break; |
2394 | |
2883 | 2395 case EMUL_EQ: |
3525 | 2396 t = octave_value::op_el_mul_eq; |
2883 | 2397 break; |
2398 | |
2399 case EDIV_EQ: | |
3525 | 2400 t = octave_value::op_el_div_eq; |
2883 | 2401 break; |
2402 | |
3204 | 2403 case ELEFTDIV_EQ: |
3525 | 2404 t = octave_value::op_el_ldiv_eq; |
3204 | 2405 break; |
2406 | |
4018 | 2407 case EPOW_EQ: |
2408 t = octave_value::op_el_pow_eq; | |
2409 break; | |
2410 | |
2883 | 2411 case AND_EQ: |
3525 | 2412 t = octave_value::op_el_and_eq; |
2883 | 2413 break; |
2414 | |
2415 case OR_EQ: | |
3525 | 2416 t = octave_value::op_el_or_eq; |
2883 | 2417 break; |
2418 | |
2419 default: | |
2420 panic_impossible (); | |
2421 break; | |
2422 } | |
2423 | |
1623 | 2424 int l = eq_tok->line (); |
2425 int c = eq_tok->column (); | |
2426 | |
5841 | 2427 if (lhs->is_simple_assign_lhs ()) |
666 | 2428 { |
2970 | 2429 tree_expression *tmp = lhs->remove_front (); |
2430 | |
2431 retval = new tree_simple_assignment (tmp, rhs, false, l, c, t); | |
2432 | |
2433 delete lhs; | |
666 | 2434 } |
2435 else | |
3208 | 2436 return new tree_multi_assignment (lhs, rhs, false, l, c, t); |
666 | 2437 |
2438 return retval; | |
2439 } | |
751 | 2440 |
7715
5b4d278ec828
parse scripts completely before executing
John W. Eaton <jwe@octave.org>
parents:
7699
diff
changeset
|
2441 // Define a function. |
5b4d278ec828
parse scripts completely before executing
John W. Eaton <jwe@octave.org>
parents:
7699
diff
changeset
|
2442 |
5b4d278ec828
parse scripts completely before executing
John W. Eaton <jwe@octave.org>
parents:
7699
diff
changeset
|
2443 static void |
8658
73c4516fae10
New evaluator and debugger derived from tree-walker class
John W. Eaton <jwe@octave.org>
parents:
8471
diff
changeset
|
2444 make_script (tree_statement_list *cmds, tree_statement *end_script) |
7715
5b4d278ec828
parse scripts completely before executing
John W. Eaton <jwe@octave.org>
parents:
7699
diff
changeset
|
2445 { |
5b4d278ec828
parse scripts completely before executing
John W. Eaton <jwe@octave.org>
parents:
7699
diff
changeset
|
2446 std::string doc_string; |
5b4d278ec828
parse scripts completely before executing
John W. Eaton <jwe@octave.org>
parents:
7699
diff
changeset
|
2447 |
5b4d278ec828
parse scripts completely before executing
John W. Eaton <jwe@octave.org>
parents:
7699
diff
changeset
|
2448 if (! help_buf.empty ()) |
5b4d278ec828
parse scripts completely before executing
John W. Eaton <jwe@octave.org>
parents:
7699
diff
changeset
|
2449 { |
5b4d278ec828
parse scripts completely before executing
John W. Eaton <jwe@octave.org>
parents:
7699
diff
changeset
|
2450 doc_string = help_buf.top (); |
5b4d278ec828
parse scripts completely before executing
John W. Eaton <jwe@octave.org>
parents:
7699
diff
changeset
|
2451 help_buf.pop (); |
5b4d278ec828
parse scripts completely before executing
John W. Eaton <jwe@octave.org>
parents:
7699
diff
changeset
|
2452 } |
5b4d278ec828
parse scripts completely before executing
John W. Eaton <jwe@octave.org>
parents:
7699
diff
changeset
|
2453 |
8658
73c4516fae10
New evaluator and debugger derived from tree-walker class
John W. Eaton <jwe@octave.org>
parents:
8471
diff
changeset
|
2454 if (! cmds) |
73c4516fae10
New evaluator and debugger derived from tree-walker class
John W. Eaton <jwe@octave.org>
parents:
8471
diff
changeset
|
2455 cmds = new tree_statement_list (); |
73c4516fae10
New evaluator and debugger derived from tree-walker class
John W. Eaton <jwe@octave.org>
parents:
8471
diff
changeset
|
2456 |
73c4516fae10
New evaluator and debugger derived from tree-walker class
John W. Eaton <jwe@octave.org>
parents:
8471
diff
changeset
|
2457 cmds->append (end_script); |
73c4516fae10
New evaluator and debugger derived from tree-walker class
John W. Eaton <jwe@octave.org>
parents:
8471
diff
changeset
|
2458 |
7715
5b4d278ec828
parse scripts completely before executing
John W. Eaton <jwe@octave.org>
parents:
7699
diff
changeset
|
2459 octave_user_script *script |
5b4d278ec828
parse scripts completely before executing
John W. Eaton <jwe@octave.org>
parents:
7699
diff
changeset
|
2460 = new octave_user_script (curr_fcn_file_full_name, curr_fcn_file_name, |
5b4d278ec828
parse scripts completely before executing
John W. Eaton <jwe@octave.org>
parents:
7699
diff
changeset
|
2461 cmds, doc_string); |
5b4d278ec828
parse scripts completely before executing
John W. Eaton <jwe@octave.org>
parents:
7699
diff
changeset
|
2462 |
5b4d278ec828
parse scripts completely before executing
John W. Eaton <jwe@octave.org>
parents:
7699
diff
changeset
|
2463 octave_time now; |
5b4d278ec828
parse scripts completely before executing
John W. Eaton <jwe@octave.org>
parents:
7699
diff
changeset
|
2464 |
5b4d278ec828
parse scripts completely before executing
John W. Eaton <jwe@octave.org>
parents:
7699
diff
changeset
|
2465 script->stash_fcn_file_time (now); |
5b4d278ec828
parse scripts completely before executing
John W. Eaton <jwe@octave.org>
parents:
7699
diff
changeset
|
2466 |
5b4d278ec828
parse scripts completely before executing
John W. Eaton <jwe@octave.org>
parents:
7699
diff
changeset
|
2467 curr_fcn_ptr = script; |
5b4d278ec828
parse scripts completely before executing
John W. Eaton <jwe@octave.org>
parents:
7699
diff
changeset
|
2468 } |
5b4d278ec828
parse scripts completely before executing
John W. Eaton <jwe@octave.org>
parents:
7699
diff
changeset
|
2469 |
1623 | 2470 // Begin defining a function. |
2471 | |
2891 | 2472 static octave_user_function * |
8658
73c4516fae10
New evaluator and debugger derived from tree-walker class
John W. Eaton <jwe@octave.org>
parents:
8471
diff
changeset
|
2473 start_function (tree_parameter_list *param_list, tree_statement_list *body, |
73c4516fae10
New evaluator and debugger derived from tree-walker class
John W. Eaton <jwe@octave.org>
parents:
8471
diff
changeset
|
2474 tree_statement *end_fcn_stmt) |
1623 | 2475 { |
2891 | 2476 // We'll fill in the return list later. |
2477 | |
8658
73c4516fae10
New evaluator and debugger derived from tree-walker class
John W. Eaton <jwe@octave.org>
parents:
8471
diff
changeset
|
2478 if (! body) |
73c4516fae10
New evaluator and debugger derived from tree-walker class
John W. Eaton <jwe@octave.org>
parents:
8471
diff
changeset
|
2479 body = new tree_statement_list (); |
73c4516fae10
New evaluator and debugger derived from tree-walker class
John W. Eaton <jwe@octave.org>
parents:
8471
diff
changeset
|
2480 |
73c4516fae10
New evaluator and debugger derived from tree-walker class
John W. Eaton <jwe@octave.org>
parents:
8471
diff
changeset
|
2481 body->append (end_fcn_stmt); |
73c4516fae10
New evaluator and debugger derived from tree-walker class
John W. Eaton <jwe@octave.org>
parents:
8471
diff
changeset
|
2482 |
2891 | 2483 octave_user_function *fcn |
7336 | 2484 = new octave_user_function (symbol_table::current_scope (), |
2485 param_list, 0, body); | |
1623 | 2486 |
3665 | 2487 if (fcn) |
2488 { | |
2489 octave_comment_list *tc = octave_comment_buffer::get_comment (); | |
2490 | |
2491 fcn->stash_trailing_comment (tc); | |
2492 } | |
2493 | |
1623 | 2494 return fcn; |
2495 } | |
2496 | |
8658
73c4516fae10
New evaluator and debugger derived from tree-walker class
John W. Eaton <jwe@octave.org>
parents:
8471
diff
changeset
|
2497 static tree_statement * |
73c4516fae10
New evaluator and debugger derived from tree-walker class
John W. Eaton <jwe@octave.org>
parents:
8471
diff
changeset
|
2498 make_end (const std::string& type, int l, int c) |
73c4516fae10
New evaluator and debugger derived from tree-walker class
John W. Eaton <jwe@octave.org>
parents:
8471
diff
changeset
|
2499 { |
73c4516fae10
New evaluator and debugger derived from tree-walker class
John W. Eaton <jwe@octave.org>
parents:
8471
diff
changeset
|
2500 return make_statement (new tree_no_op_command (type, l, c)); |
73c4516fae10
New evaluator and debugger derived from tree-walker class
John W. Eaton <jwe@octave.org>
parents:
8471
diff
changeset
|
2501 } |
73c4516fae10
New evaluator and debugger derived from tree-walker class
John W. Eaton <jwe@octave.org>
parents:
8471
diff
changeset
|
2502 |
1623 | 2503 // Do most of the work for defining a function. |
2504 | |
2891 | 2505 static octave_user_function * |
4872 | 2506 frob_function (const std::string& fname, octave_user_function *fcn) |
1623 | 2507 { |
4872 | 2508 std::string id_name = fname; |
1623 | 2509 |
2510 // If input is coming from a file, issue a warning if the name of | |
2511 // the file does not match the name of the function stated in the | |
2512 // file. Matlab doesn't provide a diagnostic (it ignores the stated | |
2513 // name). | |
2514 | |
5484 | 2515 if (reading_fcn_file || autoloading) |
1623 | 2516 { |
7336 | 2517 if (! (autoloading |
2518 || lexer_flags.parsing_nested_function | |
2519 || lexer_flags.parsing_class_method)) | |
1623 | 2520 { |
7336 | 2521 // FIXME -- should curr_fcn_file_name already be |
2522 // preprocessed when we get here? It seems to only be a | |
2523 // problem with relative file names. | |
2524 | |
2525 std::string nm = curr_fcn_file_name; | |
2526 | |
8007
a2ab20ba78f7
make file_ops a proper singleton class
John W. Eaton <jwe@octave.org>
parents:
8001
diff
changeset
|
2527 size_t pos = nm.find_last_of (file_ops::dir_sep_chars ()); |
7336 | 2528 |
8021 | 2529 if (pos != std::string::npos) |
7336 | 2530 nm = curr_fcn_file_name.substr (pos+1); |
2531 | |
2532 if (nm != id_name) | |
2533 { | |
2534 warning_with_id | |
2535 ("Octave:function-name-clash", | |
2536 "function name `%s' does not agree with function file name `%s'", | |
2537 id_name.c_str (), curr_fcn_file_full_name.c_str ()); | |
2538 | |
2539 id_name = nm; | |
2540 } | |
1623 | 2541 } |
2542 | |
3712 | 2543 octave_time now; |
3162 | 2544 |
4343 | 2545 fcn->stash_fcn_file_name (curr_fcn_file_full_name); |
3162 | 2546 fcn->stash_fcn_file_time (now); |
1623 | 2547 fcn->mark_as_system_fcn_file (); |
3162 | 2548 |
6323 | 2549 if (fcn_file_from_relative_lookup) |
2550 fcn->mark_relative (); | |
2551 | |
2552 if (lexer_flags.parsing_nested_function) | |
7968
0d607e8dbbfa
eliminate curr_parent_function; fix subfunction lookup
John W. Eaton <jwe@octave.org>
parents:
7903
diff
changeset
|
2553 { |
0d607e8dbbfa
eliminate curr_parent_function; fix subfunction lookup
John W. Eaton <jwe@octave.org>
parents:
7903
diff
changeset
|
2554 fcn->stash_parent_fcn_name (parent_function_name); |
0d607e8dbbfa
eliminate curr_parent_function; fix subfunction lookup
John W. Eaton <jwe@octave.org>
parents:
7903
diff
changeset
|
2555 fcn->stash_parent_fcn_scope (symbol_table::parent_scope ()); |
0d607e8dbbfa
eliminate curr_parent_function; fix subfunction lookup
John W. Eaton <jwe@octave.org>
parents:
7903
diff
changeset
|
2556 } |
6323 | 2557 |
7336 | 2558 if (lexer_flags.parsing_class_method) |
2559 { | |
2560 if (current_class_name == id_name) | |
2561 fcn->mark_as_class_constructor (); | |
2562 else | |
2563 fcn->mark_as_class_method (); | |
2564 | |
2565 fcn->stash_dispatch_class (current_class_name); | |
2566 } | |
2567 | |
5781 | 2568 std::string nm = fcn->fcn_file_name (); |
2569 | |
2570 file_stat fs (nm); | |
2571 | |
2572 if (fs && fs.is_newer (now)) | |
2573 warning_with_id ("Octave:future-time-stamp", | |
2574 "time stamp for `%s' is in the future", nm.c_str ()); | |
1623 | 2575 } |
2576 else if (! (input_from_tmp_history_file || input_from_startup_file) | |
2577 && reading_script_file | |
1755 | 2578 && curr_fcn_file_name == id_name) |
1623 | 2579 { |
2580 warning ("function `%s' defined within script file `%s'", | |
1755 | 2581 id_name.c_str (), curr_fcn_file_full_name.c_str ()); |
1623 | 2582 } |
2583 | |
4872 | 2584 fcn->stash_function_name (id_name); |
2585 | |
7336 | 2586 if (! help_buf.empty ()) |
2587 { | |
2588 fcn->document (help_buf.top ()); | |
2589 | |
2590 help_buf.pop (); | |
2591 } | |
2592 | |
7755
ea9cb4d68dbf
avoid installing subfunctions twice
John W. Eaton <jwe@octave.org>
parents:
7750
diff
changeset
|
2593 if (reading_fcn_file && ! lexer_flags.parsing_nested_function) |
7715
5b4d278ec828
parse scripts completely before executing
John W. Eaton <jwe@octave.org>
parents:
7699
diff
changeset
|
2594 curr_fcn_ptr = fcn; |
7336 | 2595 else |
7715
5b4d278ec828
parse scripts completely before executing
John W. Eaton <jwe@octave.org>
parents:
7699
diff
changeset
|
2596 curr_fcn_ptr = 0; |
4426 | 2597 |
1623 | 2598 return fcn; |
2599 } | |
2600 | |
7715
5b4d278ec828
parse scripts completely before executing
John W. Eaton <jwe@octave.org>
parents:
7699
diff
changeset
|
2601 static tree_function_def * |
3665 | 2602 finish_function (tree_parameter_list *ret_list, |
2603 octave_user_function *fcn, octave_comment_list *lc) | |
1623 | 2604 { |
7715
5b4d278ec828
parse scripts completely before executing
John W. Eaton <jwe@octave.org>
parents:
7699
diff
changeset
|
2605 tree_function_def *retval = 0; |
5b4d278ec828
parse scripts completely before executing
John W. Eaton <jwe@octave.org>
parents:
7699
diff
changeset
|
2606 |
5b4d278ec828
parse scripts completely before executing
John W. Eaton <jwe@octave.org>
parents:
7699
diff
changeset
|
2607 if (ret_list) |
5b4d278ec828
parse scripts completely before executing
John W. Eaton <jwe@octave.org>
parents:
7699
diff
changeset
|
2608 ret_list->mark_as_formal_parameters (); |
5b4d278ec828
parse scripts completely before executing
John W. Eaton <jwe@octave.org>
parents:
7699
diff
changeset
|
2609 |
5b4d278ec828
parse scripts completely before executing
John W. Eaton <jwe@octave.org>
parents:
7699
diff
changeset
|
2610 if (fcn) |
5b4d278ec828
parse scripts completely before executing
John W. Eaton <jwe@octave.org>
parents:
7699
diff
changeset
|
2611 { |
7761
5adeea5de26c
symbol table reporting functions
John W. Eaton <jwe@octave.org>
parents:
7755
diff
changeset
|
2612 std::string nm = fcn->name (); |
5adeea5de26c
symbol table reporting functions
John W. Eaton <jwe@octave.org>
parents:
7755
diff
changeset
|
2613 std::string file = fcn->fcn_file_name (); |
5adeea5de26c
symbol table reporting functions
John W. Eaton <jwe@octave.org>
parents:
7755
diff
changeset
|
2614 |
5adeea5de26c
symbol table reporting functions
John W. Eaton <jwe@octave.org>
parents:
7755
diff
changeset
|
2615 std::string tmp = nm; |
5adeea5de26c
symbol table reporting functions
John W. Eaton <jwe@octave.org>
parents:
7755
diff
changeset
|
2616 if (! file.empty ()) |
5adeea5de26c
symbol table reporting functions
John W. Eaton <jwe@octave.org>
parents:
7755
diff
changeset
|
2617 tmp += ": " + file; |
5adeea5de26c
symbol table reporting functions
John W. Eaton <jwe@octave.org>
parents:
7755
diff
changeset
|
2618 |
5adeea5de26c
symbol table reporting functions
John W. Eaton <jwe@octave.org>
parents:
7755
diff
changeset
|
2619 symbol_table::cache_name (fcn->scope (), tmp); |
5adeea5de26c
symbol table reporting functions
John W. Eaton <jwe@octave.org>
parents:
7755
diff
changeset
|
2620 |
7715
5b4d278ec828
parse scripts completely before executing
John W. Eaton <jwe@octave.org>
parents:
7699
diff
changeset
|
2621 if (lc) |
5b4d278ec828
parse scripts completely before executing
John W. Eaton <jwe@octave.org>
parents:
7699
diff
changeset
|
2622 fcn->stash_leading_comment (lc); |
5b4d278ec828
parse scripts completely before executing
John W. Eaton <jwe@octave.org>
parents:
7699
diff
changeset
|
2623 |
5b4d278ec828
parse scripts completely before executing
John W. Eaton <jwe@octave.org>
parents:
7699
diff
changeset
|
2624 fcn->define_ret_list (ret_list); |
7755
ea9cb4d68dbf
avoid installing subfunctions twice
John W. Eaton <jwe@octave.org>
parents:
7750
diff
changeset
|
2625 |
ea9cb4d68dbf
avoid installing subfunctions twice
John W. Eaton <jwe@octave.org>
parents:
7750
diff
changeset
|
2626 if (lexer_flags.parsing_nested_function) |
ea9cb4d68dbf
avoid installing subfunctions twice
John W. Eaton <jwe@octave.org>
parents:
7750
diff
changeset
|
2627 { |
ea9cb4d68dbf
avoid installing subfunctions twice
John W. Eaton <jwe@octave.org>
parents:
7750
diff
changeset
|
2628 fcn->mark_as_nested_function (); |
ea9cb4d68dbf
avoid installing subfunctions twice
John W. Eaton <jwe@octave.org>
parents:
7750
diff
changeset
|
2629 |
ea9cb4d68dbf
avoid installing subfunctions twice
John W. Eaton <jwe@octave.org>
parents:
7750
diff
changeset
|
2630 symbol_table::install_subfunction (nm, octave_value (fcn)); |
ea9cb4d68dbf
avoid installing subfunctions twice
John W. Eaton <jwe@octave.org>
parents:
7750
diff
changeset
|
2631 |
ea9cb4d68dbf
avoid installing subfunctions twice
John W. Eaton <jwe@octave.org>
parents:
7750
diff
changeset
|
2632 if (lexer_flags.parsing_nested_function < 0) |
ea9cb4d68dbf
avoid installing subfunctions twice
John W. Eaton <jwe@octave.org>
parents:
7750
diff
changeset
|
2633 { |
ea9cb4d68dbf
avoid installing subfunctions twice
John W. Eaton <jwe@octave.org>
parents:
7750
diff
changeset
|
2634 lexer_flags.parsing_nested_function = 0; |
ea9cb4d68dbf
avoid installing subfunctions twice
John W. Eaton <jwe@octave.org>
parents:
7750
diff
changeset
|
2635 symbol_table::reset_parent_scope (); |
ea9cb4d68dbf
avoid installing subfunctions twice
John W. Eaton <jwe@octave.org>
parents:
7750
diff
changeset
|
2636 } |
ea9cb4d68dbf
avoid installing subfunctions twice
John W. Eaton <jwe@octave.org>
parents:
7750
diff
changeset
|
2637 } |
ea9cb4d68dbf
avoid installing subfunctions twice
John W. Eaton <jwe@octave.org>
parents:
7750
diff
changeset
|
2638 else if (! curr_fcn_ptr) |
ea9cb4d68dbf
avoid installing subfunctions twice
John W. Eaton <jwe@octave.org>
parents:
7750
diff
changeset
|
2639 { |
ea9cb4d68dbf
avoid installing subfunctions twice
John W. Eaton <jwe@octave.org>
parents:
7750
diff
changeset
|
2640 // FIXME -- there should be a better way to indicate that we |
ea9cb4d68dbf
avoid installing subfunctions twice
John W. Eaton <jwe@octave.org>
parents:
7750
diff
changeset
|
2641 // should create a tree_function_def object other than |
ea9cb4d68dbf
avoid installing subfunctions twice
John W. Eaton <jwe@octave.org>
parents:
7750
diff
changeset
|
2642 // looking at curr_fcn_ptr... |
ea9cb4d68dbf
avoid installing subfunctions twice
John W. Eaton <jwe@octave.org>
parents:
7750
diff
changeset
|
2643 |
ea9cb4d68dbf
avoid installing subfunctions twice
John W. Eaton <jwe@octave.org>
parents:
7750
diff
changeset
|
2644 retval = new tree_function_def (fcn); |
ea9cb4d68dbf
avoid installing subfunctions twice
John W. Eaton <jwe@octave.org>
parents:
7750
diff
changeset
|
2645 } |
8282
47a3d2f829e4
clear local symbol table after parsing function
John W. Eaton <jwe@octave.org>
parents:
8150
diff
changeset
|
2646 |
8283 | 2647 // Clear any local variables that may have been added while |
2648 // parsing (for example, by force_local_variable in lex.l). | |
8282
47a3d2f829e4
clear local symbol table after parsing function
John W. Eaton <jwe@octave.org>
parents:
8150
diff
changeset
|
2649 |
47a3d2f829e4
clear local symbol table after parsing function
John W. Eaton <jwe@octave.org>
parents:
8150
diff
changeset
|
2650 symbol_table::clear_variables (fcn->scope ()); |
7715
5b4d278ec828
parse scripts completely before executing
John W. Eaton <jwe@octave.org>
parents:
7699
diff
changeset
|
2651 } |
5b4d278ec828
parse scripts completely before executing
John W. Eaton <jwe@octave.org>
parents:
7699
diff
changeset
|
2652 |
5b4d278ec828
parse scripts completely before executing
John W. Eaton <jwe@octave.org>
parents:
7699
diff
changeset
|
2653 return retval; |
1623 | 2654 } |
2655 | |
2883 | 2656 static void |
2657 recover_from_parsing_function (void) | |
2658 { | |
4238 | 2659 if (symtab_context.empty ()) |
3903 | 2660 panic_impossible (); |
2661 | |
7336 | 2662 symbol_table::set_scope (symtab_context.top ()); |
4238 | 2663 symtab_context.pop (); |
2883 | 2664 |
2665 lexer_flags.defining_func = false; | |
2666 lexer_flags.parsed_function_name = false; | |
2667 lexer_flags.looking_at_return_list = false; | |
2668 lexer_flags.looking_at_parameter_list = false; | |
2669 } | |
2670 | |
2846 | 2671 // Make an index expression. |
2672 | |
751 | 2673 static tree_index_expression * |
3929 | 2674 make_index_expression (tree_expression *expr, tree_argument_list *args, |
3933 | 2675 char type) |
751 | 2676 { |
2677 tree_index_expression *retval = 0; | |
2678 | |
2970 | 2679 int l = expr->line (); |
2680 int c = expr->column (); | |
2681 | |
2682 expr->mark_postfix_indexed (); | |
2683 | |
3933 | 2684 if (expr->is_index_expression ()) |
2685 { | |
2686 tree_index_expression *tmp = static_cast<tree_index_expression *> (expr); | |
2687 | |
2688 tmp->append (args, type); | |
2689 | |
2690 retval = tmp; | |
2691 } | |
2692 else | |
2693 retval = new tree_index_expression (expr, args, l, c, type); | |
2970 | 2694 |
2695 return retval; | |
2696 } | |
2697 | |
2698 // Make an indirect reference expression. | |
2699 | |
3930 | 2700 static tree_index_expression * |
3523 | 2701 make_indirect_ref (tree_expression *expr, const std::string& elt) |
2970 | 2702 { |
3930 | 2703 tree_index_expression *retval = 0; |
2970 | 2704 |
2705 int l = expr->line (); | |
2706 int c = expr->column (); | |
2707 | |
3933 | 2708 if (expr->is_index_expression ()) |
2709 { | |
2710 tree_index_expression *tmp = static_cast<tree_index_expression *> (expr); | |
2711 | |
2712 tmp->append (elt); | |
2713 | |
2714 retval = tmp; | |
2715 } | |
2716 else | |
2717 retval = new tree_index_expression (expr, elt, l, c); | |
2970 | 2718 |
2719 lexer_flags.looking_at_indirect_ref = false; | |
751 | 2720 |
2721 return retval; | |
2722 } | |
1511 | 2723 |
4131 | 2724 // Make an indirect reference expression with dynamic field name. |
2725 | |
2726 static tree_index_expression * | |
2727 make_indirect_ref (tree_expression *expr, tree_expression *elt) | |
2728 { | |
2729 tree_index_expression *retval = 0; | |
2730 | |
2731 int l = expr->line (); | |
2732 int c = expr->column (); | |
2733 | |
2734 if (expr->is_index_expression ()) | |
2735 { | |
2736 tree_index_expression *tmp = static_cast<tree_index_expression *> (expr); | |
2737 | |
2738 tmp->append (elt); | |
2739 | |
2740 retval = tmp; | |
2741 } | |
2742 else | |
2743 retval = new tree_index_expression (expr, elt, l, c); | |
2744 | |
2745 lexer_flags.looking_at_indirect_ref = false; | |
2746 | |
2747 return retval; | |
2748 } | |
2749 | |
2846 | 2750 // Make a declaration command. |
2751 | |
2752 static tree_decl_command * | |
2753 make_decl_command (int tok, token *tok_val, tree_decl_init_list *lst) | |
2754 { | |
2755 tree_decl_command *retval = 0; | |
2756 | |
2757 int l = tok_val->line (); | |
2758 int c = tok_val->column (); | |
2759 | |
2760 switch (tok) | |
2761 { | |
2762 case GLOBAL: | |
2763 retval = new tree_global_command (lst, l, c); | |
2764 break; | |
2765 | |
2766 case STATIC: | |
2767 if (lexer_flags.defining_func) | |
2768 retval = new tree_static_command (lst, l, c); | |
2769 else | |
2770 { | |
2771 if (reading_script_file) | |
4844 | 2772 warning ("ignoring persistent declaration near line %d of file `%s'", |
2846 | 2773 l, curr_fcn_file_full_name.c_str ()); |
2774 else | |
4844 | 2775 warning ("ignoring persistent declaration near line %d", l); |
2846 | 2776 } |
2777 break; | |
2778 | |
2779 default: | |
2780 panic_impossible (); | |
2781 break; | |
2782 } | |
2783 | |
2784 return retval; | |
2785 } | |
2786 | |
1623 | 2787 // Finish building a matrix list. |
2788 | |
2789 static tree_expression * | |
1829 | 2790 finish_matrix (tree_matrix *m) |
1623 | 2791 { |
3110 | 2792 tree_expression *retval = m; |
2793 | |
2794 unwind_protect::begin_frame ("finish_matrix"); | |
2795 | |
2796 unwind_protect_int (error_state); | |
4452 | 2797 unwind_protect_int (warning_state); |
3110 | 2798 |
3815 | 2799 unwind_protect_bool (discard_error_messages); |
4452 | 2800 unwind_protect_bool (discard_warning_messages); |
2801 | |
3815 | 2802 discard_error_messages = true; |
4452 | 2803 discard_warning_messages = true; |
1623 | 2804 |
2533 | 2805 if (m->all_elements_are_constant ()) |
1829 | 2806 { |
8658
73c4516fae10
New evaluator and debugger derived from tree-walker class
John W. Eaton <jwe@octave.org>
parents:
8471
diff
changeset
|
2807 octave_value tmp = m->rvalue1 (); |
1623 | 2808 |
3489 | 2809 if (! (error_state || warning_state)) |
2533 | 2810 { |
8658
73c4516fae10
New evaluator and debugger derived from tree-walker class
John W. Eaton <jwe@octave.org>
parents:
8471
diff
changeset
|
2811 tree_constant *tc_retval |
73c4516fae10
New evaluator and debugger derived from tree-walker class
John W. Eaton <jwe@octave.org>
parents:
8471
diff
changeset
|
2812 = new tree_constant (tmp, m->line (), m->column ()); |
2533 | 2813 |
5765 | 2814 std::ostringstream buf; |
2533 | 2815 |
2816 tree_print_code tpc (buf); | |
2817 | |
2818 m->accept (tpc); | |
2819 | |
5765 | 2820 tc_retval->stash_original_text (buf.str ()); |
2533 | 2821 |
2822 delete m; | |
2823 | |
2824 retval = tc_retval; | |
2825 } | |
1623 | 2826 } |
3110 | 2827 |
2828 unwind_protect::run_frame ("finish_matrix"); | |
1623 | 2829 |
2830 return retval; | |
2831 } | |
2832 | |
3351 | 2833 // Finish building a cell list. |
2834 | |
2835 static tree_expression * | |
2836 finish_cell (tree_cell *c) | |
2837 { | |
5875 | 2838 return finish_matrix (c); |
3351 | 2839 } |
2840 | |
1511 | 2841 static void |
2842 maybe_warn_missing_semi (tree_statement_list *t) | |
2843 { | |
5781 | 2844 if (lexer_flags.defining_func) |
1511 | 2845 { |
4219 | 2846 tree_statement *tmp = t->back(); |
1607 | 2847 |
1511 | 2848 if (tmp->is_expression ()) |
5781 | 2849 warning_with_id |
2850 ("Octave:missing-semicolon", | |
2851 "missing semicolon near line %d, column %d in file `%s'", | |
2852 tmp->line (), tmp->column (), curr_fcn_file_full_name.c_str ()); | |
1511 | 2853 } |
2854 } | |
1994 | 2855 |
8471
02de6775f1fe
parse.y: always append statements to list, but remove null statements after seeing separator
John W. Eaton <jwe@octave.org>
parents:
8448
diff
changeset
|
2856 static tree_statement_list * |
2525 | 2857 set_stmt_print_flag (tree_statement_list *list, char sep, |
2858 bool warn_missing_semi) | |
2859 { | |
8471
02de6775f1fe
parse.y: always append statements to list, but remove null statements after seeing separator
John W. Eaton <jwe@octave.org>
parents:
8448
diff
changeset
|
2860 tree_statement *tmp = list->back (); |
02de6775f1fe
parse.y: always append statements to list, but remove null statements after seeing separator
John W. Eaton <jwe@octave.org>
parents:
8448
diff
changeset
|
2861 |
2525 | 2862 switch (sep) |
2863 { | |
2864 case ';': | |
8658
73c4516fae10
New evaluator and debugger derived from tree-walker class
John W. Eaton <jwe@octave.org>
parents:
8471
diff
changeset
|
2865 tmp->set_print_flag (false); |
2525 | 2866 break; |
2867 | |
2868 case 0: | |
2869 case ',': | |
2870 case '\n': | |
8658
73c4516fae10
New evaluator and debugger derived from tree-walker class
John W. Eaton <jwe@octave.org>
parents:
8471
diff
changeset
|
2871 tmp->set_print_flag (true); |
2525 | 2872 if (warn_missing_semi) |
2873 maybe_warn_missing_semi (list); | |
2874 break; | |
2875 | |
2876 default: | |
2877 warning ("unrecognized separator type!"); | |
2878 break; | |
2879 } | |
8471
02de6775f1fe
parse.y: always append statements to list, but remove null statements after seeing separator
John W. Eaton <jwe@octave.org>
parents:
8448
diff
changeset
|
2880 |
02de6775f1fe
parse.y: always append statements to list, but remove null statements after seeing separator
John W. Eaton <jwe@octave.org>
parents:
8448
diff
changeset
|
2881 // Even if a statement is null, we add it to the list then remove it |
02de6775f1fe
parse.y: always append statements to list, but remove null statements after seeing separator
John W. Eaton <jwe@octave.org>
parents:
8448
diff
changeset
|
2882 // here so that the print flag is applied to the correct statement. |
02de6775f1fe
parse.y: always append statements to list, but remove null statements after seeing separator
John W. Eaton <jwe@octave.org>
parents:
8448
diff
changeset
|
2883 |
02de6775f1fe
parse.y: always append statements to list, but remove null statements after seeing separator
John W. Eaton <jwe@octave.org>
parents:
8448
diff
changeset
|
2884 if (tmp->is_null_statement ()) |
02de6775f1fe
parse.y: always append statements to list, but remove null statements after seeing separator
John W. Eaton <jwe@octave.org>
parents:
8448
diff
changeset
|
2885 { |
02de6775f1fe
parse.y: always append statements to list, but remove null statements after seeing separator
John W. Eaton <jwe@octave.org>
parents:
8448
diff
changeset
|
2886 list->pop_back (); |
02de6775f1fe
parse.y: always append statements to list, but remove null statements after seeing separator
John W. Eaton <jwe@octave.org>
parents:
8448
diff
changeset
|
2887 delete tmp; |
02de6775f1fe
parse.y: always append statements to list, but remove null statements after seeing separator
John W. Eaton <jwe@octave.org>
parents:
8448
diff
changeset
|
2888 } |
02de6775f1fe
parse.y: always append statements to list, but remove null statements after seeing separator
John W. Eaton <jwe@octave.org>
parents:
8448
diff
changeset
|
2889 |
02de6775f1fe
parse.y: always append statements to list, but remove null statements after seeing separator
John W. Eaton <jwe@octave.org>
parents:
8448
diff
changeset
|
2890 return list; |
2525 | 2891 } |
2892 | |
8448
d6c0d5f208de
parse.y: avoid storing null statements in statement lists
John W. Eaton <jwe@octave.org>
parents:
8447
diff
changeset
|
2893 static tree_statement_list * |
d6c0d5f208de
parse.y: avoid storing null statements in statement lists
John W. Eaton <jwe@octave.org>
parents:
8447
diff
changeset
|
2894 make_statement_list (tree_statement *stmt) |
d6c0d5f208de
parse.y: avoid storing null statements in statement lists
John W. Eaton <jwe@octave.org>
parents:
8447
diff
changeset
|
2895 { |
8471
02de6775f1fe
parse.y: always append statements to list, but remove null statements after seeing separator
John W. Eaton <jwe@octave.org>
parents:
8448
diff
changeset
|
2896 return new tree_statement_list (stmt); |
8448
d6c0d5f208de
parse.y: avoid storing null statements in statement lists
John W. Eaton <jwe@octave.org>
parents:
8447
diff
changeset
|
2897 } |
d6c0d5f208de
parse.y: avoid storing null statements in statement lists
John W. Eaton <jwe@octave.org>
parents:
8447
diff
changeset
|
2898 |
d6c0d5f208de
parse.y: avoid storing null statements in statement lists
John W. Eaton <jwe@octave.org>
parents:
8447
diff
changeset
|
2899 static tree_statement_list * |
d6c0d5f208de
parse.y: avoid storing null statements in statement lists
John W. Eaton <jwe@octave.org>
parents:
8447
diff
changeset
|
2900 append_statement_list (tree_statement_list *list, char sep, |
d6c0d5f208de
parse.y: avoid storing null statements in statement lists
John W. Eaton <jwe@octave.org>
parents:
8447
diff
changeset
|
2901 tree_statement *stmt, bool warn_missing_semi) |
d6c0d5f208de
parse.y: avoid storing null statements in statement lists
John W. Eaton <jwe@octave.org>
parents:
8447
diff
changeset
|
2902 { |
8471
02de6775f1fe
parse.y: always append statements to list, but remove null statements after seeing separator
John W. Eaton <jwe@octave.org>
parents:
8448
diff
changeset
|
2903 set_stmt_print_flag (list, sep, warn_missing_semi); |
02de6775f1fe
parse.y: always append statements to list, but remove null statements after seeing separator
John W. Eaton <jwe@octave.org>
parents:
8448
diff
changeset
|
2904 |
02de6775f1fe
parse.y: always append statements to list, but remove null statements after seeing separator
John W. Eaton <jwe@octave.org>
parents:
8448
diff
changeset
|
2905 list->append (stmt); |
02de6775f1fe
parse.y: always append statements to list, but remove null statements after seeing separator
John W. Eaton <jwe@octave.org>
parents:
8448
diff
changeset
|
2906 |
02de6775f1fe
parse.y: always append statements to list, but remove null statements after seeing separator
John W. Eaton <jwe@octave.org>
parents:
8448
diff
changeset
|
2907 return list; |
8448
d6c0d5f208de
parse.y: avoid storing null statements in statement lists
John W. Eaton <jwe@octave.org>
parents:
8447
diff
changeset
|
2908 } |
d6c0d5f208de
parse.y: avoid storing null statements in statement lists
John W. Eaton <jwe@octave.org>
parents:
8447
diff
changeset
|
2909 |
3021 | 2910 static void |
2911 safe_fclose (void *f) | |
2912 { | |
5775 | 2913 // FIXME -- comments at the end of an input file are |
3765 | 2914 // discarded (otherwise, they would be appended to the next |
2915 // statement, possibly from the command line or another file, which | |
2916 // can be quite confusing). | |
2917 | |
5308 | 2918 octave_comment_list *tc = octave_comment_buffer::get_comment (); |
2919 | |
2920 delete tc; | |
3765 | 2921 |
3021 | 2922 if (f) |
2923 fclose (static_cast<FILE *> (f)); | |
2924 } | |
2925 | |
2926 static bool | |
5175 | 2927 looks_like_copyright (const std::string& s) |
3021 | 2928 { |
7720
4e2eafef689c
unify comment and help text processing in lex.l and parse.y
John W. Eaton <jwe@octave.org>
parents:
7719
diff
changeset
|
2929 bool retval = false; |
4e2eafef689c
unify comment and help text processing in lex.l and parse.y
John W. Eaton <jwe@octave.org>
parents:
7719
diff
changeset
|
2930 |
4e2eafef689c
unify comment and help text processing in lex.l and parse.y
John W. Eaton <jwe@octave.org>
parents:
7719
diff
changeset
|
2931 if (! s.empty ()) |
4e2eafef689c
unify comment and help text processing in lex.l and parse.y
John W. Eaton <jwe@octave.org>
parents:
7719
diff
changeset
|
2932 { |
4e2eafef689c
unify comment and help text processing in lex.l and parse.y
John W. Eaton <jwe@octave.org>
parents:
7719
diff
changeset
|
2933 size_t offset = s.find_first_not_of (" \t"); |
4e2eafef689c
unify comment and help text processing in lex.l and parse.y
John W. Eaton <jwe@octave.org>
parents:
7719
diff
changeset
|
2934 |
4e2eafef689c
unify comment and help text processing in lex.l and parse.y
John W. Eaton <jwe@octave.org>
parents:
7719
diff
changeset
|
2935 retval = (s.substr (offset, 9) == "Copyright"); |
4e2eafef689c
unify comment and help text processing in lex.l and parse.y
John W. Eaton <jwe@octave.org>
parents:
7719
diff
changeset
|
2936 } |
4e2eafef689c
unify comment and help text processing in lex.l and parse.y
John W. Eaton <jwe@octave.org>
parents:
7719
diff
changeset
|
2937 |
4e2eafef689c
unify comment and help text processing in lex.l and parse.y
John W. Eaton <jwe@octave.org>
parents:
7719
diff
changeset
|
2938 return retval; |
3021 | 2939 } |
2940 | |
4540 | 2941 static int |
2942 text_getc (FILE *f) | |
2943 { | |
2944 int c = getc (f); | |
2945 | |
7728
13820b9f5fd9
more consistent handling of CR/CRLF/LF line endings in lexer and parser
John W. Eaton <jwe@octave.org>
parents:
7723
diff
changeset
|
2946 // Convert CRLF into just LF and single CR into LF. |
4540 | 2947 |
2948 if (c == '\r') | |
2949 { | |
2950 c = getc (f); | |
2951 | |
8447
adab48231a03
make input_line_number work again
John W. Eaton <jwe@octave.org>
parents:
8311
diff
changeset
|
2952 if (c != '\n') |
4540 | 2953 { |
2954 ungetc (c, f); | |
7728
13820b9f5fd9
more consistent handling of CR/CRLF/LF line endings in lexer and parser
John W. Eaton <jwe@octave.org>
parents:
7723
diff
changeset
|
2955 c = '\n'; |
4540 | 2956 } |
2957 } | |
8447
adab48231a03
make input_line_number work again
John W. Eaton <jwe@octave.org>
parents:
8311
diff
changeset
|
2958 |
adab48231a03
make input_line_number work again
John W. Eaton <jwe@octave.org>
parents:
8311
diff
changeset
|
2959 if (c == '\n') |
7723
74f5e0c7de9e
first pass at handling block comments
John W. Eaton <jwe@octave.org>
parents:
7720
diff
changeset
|
2960 input_line_number++; |
4540 | 2961 |
2962 return c; | |
2963 } | |
2964 | |
7720
4e2eafef689c
unify comment and help text processing in lex.l and parse.y
John W. Eaton <jwe@octave.org>
parents:
7719
diff
changeset
|
2965 class |
4e2eafef689c
unify comment and help text processing in lex.l and parse.y
John W. Eaton <jwe@octave.org>
parents:
7719
diff
changeset
|
2966 stdio_stream_reader : public stream_reader |
3021 | 2967 { |
7720
4e2eafef689c
unify comment and help text processing in lex.l and parse.y
John W. Eaton <jwe@octave.org>
parents:
7719
diff
changeset
|
2968 public: |
4e2eafef689c
unify comment and help text processing in lex.l and parse.y
John W. Eaton <jwe@octave.org>
parents:
7719
diff
changeset
|
2969 stdio_stream_reader (FILE *f_arg) : stream_reader (), f (f_arg) { } |
4e2eafef689c
unify comment and help text processing in lex.l and parse.y
John W. Eaton <jwe@octave.org>
parents:
7719
diff
changeset
|
2970 |
4e2eafef689c
unify comment and help text processing in lex.l and parse.y
John W. Eaton <jwe@octave.org>
parents:
7719
diff
changeset
|
2971 int getc (void) { return ::text_getc (f); } |
8447
adab48231a03
make input_line_number work again
John W. Eaton <jwe@octave.org>
parents:
8311
diff
changeset
|
2972 int ungetc (int c) |
adab48231a03
make input_line_number work again
John W. Eaton <jwe@octave.org>
parents:
8311
diff
changeset
|
2973 { |
adab48231a03
make input_line_number work again
John W. Eaton <jwe@octave.org>
parents:
8311
diff
changeset
|
2974 if (c == '\n') |
adab48231a03
make input_line_number work again
John W. Eaton <jwe@octave.org>
parents:
8311
diff
changeset
|
2975 input_line_number--; |
adab48231a03
make input_line_number work again
John W. Eaton <jwe@octave.org>
parents:
8311
diff
changeset
|
2976 |
adab48231a03
make input_line_number work again
John W. Eaton <jwe@octave.org>
parents:
8311
diff
changeset
|
2977 return ::ungetc (c, f); |
adab48231a03
make input_line_number work again
John W. Eaton <jwe@octave.org>
parents:
8311
diff
changeset
|
2978 } |
7720
4e2eafef689c
unify comment and help text processing in lex.l and parse.y
John W. Eaton <jwe@octave.org>
parents:
7719
diff
changeset
|
2979 |
4e2eafef689c
unify comment and help text processing in lex.l and parse.y
John W. Eaton <jwe@octave.org>
parents:
7719
diff
changeset
|
2980 private: |
4e2eafef689c
unify comment and help text processing in lex.l and parse.y
John W. Eaton <jwe@octave.org>
parents:
7719
diff
changeset
|
2981 FILE *f; |
4e2eafef689c
unify comment and help text processing in lex.l and parse.y
John W. Eaton <jwe@octave.org>
parents:
7719
diff
changeset
|
2982 }; |
4e2eafef689c
unify comment and help text processing in lex.l and parse.y
John W. Eaton <jwe@octave.org>
parents:
7719
diff
changeset
|
2983 |
4e2eafef689c
unify comment and help text processing in lex.l and parse.y
John W. Eaton <jwe@octave.org>
parents:
7719
diff
changeset
|
2984 static bool |
4e2eafef689c
unify comment and help text processing in lex.l and parse.y
John W. Eaton <jwe@octave.org>
parents:
7719
diff
changeset
|
2985 skip_white_space (stream_reader& reader) |
4e2eafef689c
unify comment and help text processing in lex.l and parse.y
John W. Eaton <jwe@octave.org>
parents:
7719
diff
changeset
|
2986 { |
4e2eafef689c
unify comment and help text processing in lex.l and parse.y
John W. Eaton <jwe@octave.org>
parents:
7719
diff
changeset
|
2987 int c = 0; |
4e2eafef689c
unify comment and help text processing in lex.l and parse.y
John W. Eaton <jwe@octave.org>
parents:
7719
diff
changeset
|
2988 |
4e2eafef689c
unify comment and help text processing in lex.l and parse.y
John W. Eaton <jwe@octave.org>
parents:
7719
diff
changeset
|
2989 while ((c = reader.getc ()) != EOF) |
3021 | 2990 { |
7720
4e2eafef689c
unify comment and help text processing in lex.l and parse.y
John W. Eaton <jwe@octave.org>
parents:
7719
diff
changeset
|
2991 switch (c) |
3021 | 2992 { |
7720
4e2eafef689c
unify comment and help text processing in lex.l and parse.y
John W. Eaton <jwe@octave.org>
parents:
7719
diff
changeset
|
2993 case ' ': |
4e2eafef689c
unify comment and help text processing in lex.l and parse.y
John W. Eaton <jwe@octave.org>
parents:
7719
diff
changeset
|
2994 case '\t': |
4e2eafef689c
unify comment and help text processing in lex.l and parse.y
John W. Eaton <jwe@octave.org>
parents:
7719
diff
changeset
|
2995 current_input_column++; |
4e2eafef689c
unify comment and help text processing in lex.l and parse.y
John W. Eaton <jwe@octave.org>
parents:
7719
diff
changeset
|
2996 break; |
4e2eafef689c
unify comment and help text processing in lex.l and parse.y
John W. Eaton <jwe@octave.org>
parents:
7719
diff
changeset
|
2997 |
4e2eafef689c
unify comment and help text processing in lex.l and parse.y
John W. Eaton <jwe@octave.org>
parents:
7719
diff
changeset
|
2998 case '\n': |
4e2eafef689c
unify comment and help text processing in lex.l and parse.y
John W. Eaton <jwe@octave.org>
parents:
7719
diff
changeset
|
2999 current_input_column = 0; |
4e2eafef689c
unify comment and help text processing in lex.l and parse.y
John W. Eaton <jwe@octave.org>
parents:
7719
diff
changeset
|
3000 break; |
4e2eafef689c
unify comment and help text processing in lex.l and parse.y
John W. Eaton <jwe@octave.org>
parents:
7719
diff
changeset
|
3001 |
4e2eafef689c
unify comment and help text processing in lex.l and parse.y
John W. Eaton <jwe@octave.org>
parents:
7719
diff
changeset
|
3002 default: |
4e2eafef689c
unify comment and help text processing in lex.l and parse.y
John W. Eaton <jwe@octave.org>
parents:
7719
diff
changeset
|
3003 current_input_column--; |
4e2eafef689c
unify comment and help text processing in lex.l and parse.y
John W. Eaton <jwe@octave.org>
parents:
7719
diff
changeset
|
3004 reader.ungetc (c); |
4e2eafef689c
unify comment and help text processing in lex.l and parse.y
John W. Eaton <jwe@octave.org>
parents:
7719
diff
changeset
|
3005 goto done; |
3021 | 3006 } |
3007 } | |
3008 | |
3009 done: | |
3010 | |
7720
4e2eafef689c
unify comment and help text processing in lex.l and parse.y
John W. Eaton <jwe@octave.org>
parents:
7719
diff
changeset
|
3011 return (c == EOF); |
3021 | 3012 } |
3013 | |
7720
4e2eafef689c
unify comment and help text processing in lex.l and parse.y
John W. Eaton <jwe@octave.org>
parents:
7719
diff
changeset
|
3014 static std::string |
4e2eafef689c
unify comment and help text processing in lex.l and parse.y
John W. Eaton <jwe@octave.org>
parents:
7719
diff
changeset
|
3015 gobble_leading_white_space (FILE *ffile, bool& eof) |
3021 | 3016 { |
7720
4e2eafef689c
unify comment and help text processing in lex.l and parse.y
John W. Eaton <jwe@octave.org>
parents:
7719
diff
changeset
|
3017 std::string help_txt; |
4e2eafef689c
unify comment and help text processing in lex.l and parse.y
John W. Eaton <jwe@octave.org>
parents:
7719
diff
changeset
|
3018 |
4e2eafef689c
unify comment and help text processing in lex.l and parse.y
John W. Eaton <jwe@octave.org>
parents:
7719
diff
changeset
|
3019 eof = false; |
4e2eafef689c
unify comment and help text processing in lex.l and parse.y
John W. Eaton <jwe@octave.org>
parents:
7719
diff
changeset
|
3020 |
4e2eafef689c
unify comment and help text processing in lex.l and parse.y
John W. Eaton <jwe@octave.org>
parents:
7719
diff
changeset
|
3021 // TRUE means we have already cached the help text. |
4e2eafef689c
unify comment and help text processing in lex.l and parse.y
John W. Eaton <jwe@octave.org>
parents:
7719
diff
changeset
|
3022 bool have_help_text = false; |
4e2eafef689c
unify comment and help text processing in lex.l and parse.y
John W. Eaton <jwe@octave.org>
parents:
7719
diff
changeset
|
3023 |
4e2eafef689c
unify comment and help text processing in lex.l and parse.y
John W. Eaton <jwe@octave.org>
parents:
7719
diff
changeset
|
3024 std::string txt; |
4e2eafef689c
unify comment and help text processing in lex.l and parse.y
John W. Eaton <jwe@octave.org>
parents:
7719
diff
changeset
|
3025 |
4e2eafef689c
unify comment and help text processing in lex.l and parse.y
John W. Eaton <jwe@octave.org>
parents:
7719
diff
changeset
|
3026 stdio_stream_reader stdio_reader (ffile); |
4e2eafef689c
unify comment and help text processing in lex.l and parse.y
John W. Eaton <jwe@octave.org>
parents:
7719
diff
changeset
|
3027 |
4e2eafef689c
unify comment and help text processing in lex.l and parse.y
John W. Eaton <jwe@octave.org>
parents:
7719
diff
changeset
|
3028 while (true) |
4e2eafef689c
unify comment and help text processing in lex.l and parse.y
John W. Eaton <jwe@octave.org>
parents:
7719
diff
changeset
|
3029 { |
4e2eafef689c
unify comment and help text processing in lex.l and parse.y
John W. Eaton <jwe@octave.org>
parents:
7719
diff
changeset
|
3030 eof = skip_white_space (stdio_reader); |
4e2eafef689c
unify comment and help text processing in lex.l and parse.y
John W. Eaton <jwe@octave.org>
parents:
7719
diff
changeset
|
3031 |
4e2eafef689c
unify comment and help text processing in lex.l and parse.y
John W. Eaton <jwe@octave.org>
parents:
7719
diff
changeset
|
3032 if (eof) |
4e2eafef689c
unify comment and help text processing in lex.l and parse.y
John W. Eaton <jwe@octave.org>
parents:
7719
diff
changeset
|
3033 break; |
4e2eafef689c
unify comment and help text processing in lex.l and parse.y
John W. Eaton <jwe@octave.org>
parents:
7719
diff
changeset
|
3034 |
7723
74f5e0c7de9e
first pass at handling block comments
John W. Eaton <jwe@octave.org>
parents:
7720
diff
changeset
|
3035 txt = grab_comment_block (stdio_reader, true, eof); |
7720
4e2eafef689c
unify comment and help text processing in lex.l and parse.y
John W. Eaton <jwe@octave.org>
parents:
7719
diff
changeset
|
3036 |
4e2eafef689c
unify comment and help text processing in lex.l and parse.y
John W. Eaton <jwe@octave.org>
parents:
7719
diff
changeset
|
3037 if (txt.empty ()) |
4e2eafef689c
unify comment and help text processing in lex.l and parse.y
John W. Eaton <jwe@octave.org>
parents:
7719
diff
changeset
|
3038 break; |
4e2eafef689c
unify comment and help text processing in lex.l and parse.y
John W. Eaton <jwe@octave.org>
parents:
7719
diff
changeset
|
3039 |
4e2eafef689c
unify comment and help text processing in lex.l and parse.y
John W. Eaton <jwe@octave.org>
parents:
7719
diff
changeset
|
3040 if (! (have_help_text || looks_like_copyright (txt))) |
4e2eafef689c
unify comment and help text processing in lex.l and parse.y
John W. Eaton <jwe@octave.org>
parents:
7719
diff
changeset
|
3041 { |
4e2eafef689c
unify comment and help text processing in lex.l and parse.y
John W. Eaton <jwe@octave.org>
parents:
7719
diff
changeset
|
3042 help_txt = txt; |
4e2eafef689c
unify comment and help text processing in lex.l and parse.y
John W. Eaton <jwe@octave.org>
parents:
7719
diff
changeset
|
3043 have_help_text = true; |
4e2eafef689c
unify comment and help text processing in lex.l and parse.y
John W. Eaton <jwe@octave.org>
parents:
7719
diff
changeset
|
3044 } |
4e2eafef689c
unify comment and help text processing in lex.l and parse.y
John W. Eaton <jwe@octave.org>
parents:
7719
diff
changeset
|
3045 |
4e2eafef689c
unify comment and help text processing in lex.l and parse.y
John W. Eaton <jwe@octave.org>
parents:
7719
diff
changeset
|
3046 octave_comment_buffer::append (txt); |
4e2eafef689c
unify comment and help text processing in lex.l and parse.y
John W. Eaton <jwe@octave.org>
parents:
7719
diff
changeset
|
3047 |
4e2eafef689c
unify comment and help text processing in lex.l and parse.y
John W. Eaton <jwe@octave.org>
parents:
7719
diff
changeset
|
3048 if (eof) |
4e2eafef689c
unify comment and help text processing in lex.l and parse.y
John W. Eaton <jwe@octave.org>
parents:
7719
diff
changeset
|
3049 break; |
4e2eafef689c
unify comment and help text processing in lex.l and parse.y
John W. Eaton <jwe@octave.org>
parents:
7719
diff
changeset
|
3050 } |
4e2eafef689c
unify comment and help text processing in lex.l and parse.y
John W. Eaton <jwe@octave.org>
parents:
7719
diff
changeset
|
3051 |
4e2eafef689c
unify comment and help text processing in lex.l and parse.y
John W. Eaton <jwe@octave.org>
parents:
7719
diff
changeset
|
3052 return help_txt; |
3021 | 3053 } |
3054 | |
7715
5b4d278ec828
parse scripts completely before executing
John W. Eaton <jwe@octave.org>
parents:
7699
diff
changeset
|
3055 static bool |
5b4d278ec828
parse scripts completely before executing
John W. Eaton <jwe@octave.org>
parents:
7699
diff
changeset
|
3056 looking_at_function_keyword (FILE *ffile) |
5931 | 3057 { |
7715
5b4d278ec828
parse scripts completely before executing
John W. Eaton <jwe@octave.org>
parents:
7699
diff
changeset
|
3058 bool status = false; |
3021 | 3059 |
3060 long pos = ftell (ffile); | |
3061 | |
3062 char buf [10]; | |
3063 fgets (buf, 10, ffile); | |
7715
5b4d278ec828
parse scripts completely before executing
John W. Eaton <jwe@octave.org>
parents:
7699
diff
changeset
|
3064 size_t len = strlen (buf); |
3021 | 3065 if (len > 8 && strncmp (buf, "function", 8) == 0 |
3066 && ! (isalnum (buf[8]) || buf[8] == '_')) | |
7715
5b4d278ec828
parse scripts completely before executing
John W. Eaton <jwe@octave.org>
parents:
7699
diff
changeset
|
3067 status = true; |
3021 | 3068 |
3069 fseek (ffile, pos, SEEK_SET); | |
3070 | |
3071 return status; | |
3072 } | |
3073 | |
3074 static void | |
3075 restore_command_history (void *) | |
3076 { | |
3077 command_history::ignore_entries (! Vsaving_history); | |
3078 } | |
3079 | |
3080 static void | |
3081 restore_input_stream (void *f) | |
3082 { | |
3083 command_editor::set_input_stream (static_cast<FILE *> (f)); | |
3084 } | |
3085 | |
7336 | 3086 static octave_function * |
3087 parse_fcn_file (const std::string& ff, const std::string& dispatch_type, | |
7715
5b4d278ec828
parse scripts completely before executing
John W. Eaton <jwe@octave.org>
parents:
7699
diff
changeset
|
3088 bool force_script = false, bool require_file = true, |
5b4d278ec828
parse scripts completely before executing
John W. Eaton <jwe@octave.org>
parents:
7699
diff
changeset
|
3089 const std::string& warn_for = std::string ()) |
3021 | 3090 { |
3091 unwind_protect::begin_frame ("parse_fcn_file"); | |
3092 | |
7336 | 3093 octave_function *fcn_ptr = 0; |
3021 | 3094 |
3095 // Open function file and parse. | |
3096 | |
3097 bool old_reading_fcn_file_state = reading_fcn_file; | |
3098 | |
3099 FILE *in_stream = command_editor::get_input_stream (); | |
3100 | |
3101 unwind_protect::add (restore_input_stream, in_stream); | |
3102 | |
3103 unwind_protect_ptr (ff_instream); | |
3104 | |
3105 unwind_protect_int (input_line_number); | |
3106 unwind_protect_int (current_input_column); | |
4238 | 3107 unwind_protect_int (end_tokens_expected); |
3021 | 3108 unwind_protect_bool (reading_fcn_file); |
3109 unwind_protect_bool (line_editing); | |
4238 | 3110 unwind_protect_str (parent_function_name); |
7336 | 3111 unwind_protect_str (current_class_name); |
3021 | 3112 |
8447
adab48231a03
make input_line_number work again
John W. Eaton <jwe@octave.org>
parents:
8311
diff
changeset
|
3113 input_line_number = 1; |
3021 | 3114 current_input_column = 1; |
4238 | 3115 end_tokens_expected = 0; |
3021 | 3116 reading_fcn_file = true; |
3117 line_editing = false; | |
4238 | 3118 parent_function_name = ""; |
7336 | 3119 current_class_name = dispatch_type; |
3021 | 3120 |
7715
5b4d278ec828
parse scripts completely before executing
John W. Eaton <jwe@octave.org>
parents:
7699
diff
changeset
|
3121 // The next four lines must be in this order. |
5b4d278ec828
parse scripts completely before executing
John W. Eaton <jwe@octave.org>
parents:
7699
diff
changeset
|
3122 unwind_protect::add (restore_command_history, 0); |
5b4d278ec828
parse scripts completely before executing
John W. Eaton <jwe@octave.org>
parents:
7699
diff
changeset
|
3123 |
5b4d278ec828
parse scripts completely before executing
John W. Eaton <jwe@octave.org>
parents:
7699
diff
changeset
|
3124 // FIXME -- we shouldn't need both the |
5b4d278ec828
parse scripts completely before executing
John W. Eaton <jwe@octave.org>
parents:
7699
diff
changeset
|
3125 // command_history object and the |
5b4d278ec828
parse scripts completely before executing
John W. Eaton <jwe@octave.org>
parents:
7699
diff
changeset
|
3126 // Vsaving_history variable... |
5b4d278ec828
parse scripts completely before executing
John W. Eaton <jwe@octave.org>
parents:
7699
diff
changeset
|
3127 command_history::ignore_entries (); |
5b4d278ec828
parse scripts completely before executing
John W. Eaton <jwe@octave.org>
parents:
7699
diff
changeset
|
3128 |
5b4d278ec828
parse scripts completely before executing
John W. Eaton <jwe@octave.org>
parents:
7699
diff
changeset
|
3129 unwind_protect_bool (Vsaving_history); |
5b4d278ec828
parse scripts completely before executing
John W. Eaton <jwe@octave.org>
parents:
7699
diff
changeset
|
3130 |
5b4d278ec828
parse scripts completely before executing
John W. Eaton <jwe@octave.org>
parents:
7699
diff
changeset
|
3131 Vsaving_history = false; |
5b4d278ec828
parse scripts completely before executing
John W. Eaton <jwe@octave.org>
parents:
7699
diff
changeset
|
3132 |
3021 | 3133 FILE *ffile = get_input_from_file (ff, 0); |
3134 | |
3135 unwind_protect::add (safe_fclose, ffile); | |
3136 | |
3137 if (ffile) | |
3138 { | |
7720
4e2eafef689c
unify comment and help text processing in lex.l and parse.y
John W. Eaton <jwe@octave.org>
parents:
7719
diff
changeset
|
3139 bool eof; |
4e2eafef689c
unify comment and help text processing in lex.l and parse.y
John W. Eaton <jwe@octave.org>
parents:
7719
diff
changeset
|
3140 |
4e2eafef689c
unify comment and help text processing in lex.l and parse.y
John W. Eaton <jwe@octave.org>
parents:
7719
diff
changeset
|
3141 std::string help_txt = gobble_leading_white_space (ffile, eof); |
4e2eafef689c
unify comment and help text processing in lex.l and parse.y
John W. Eaton <jwe@octave.org>
parents:
7719
diff
changeset
|
3142 |
4e2eafef689c
unify comment and help text processing in lex.l and parse.y
John W. Eaton <jwe@octave.org>
parents:
7719
diff
changeset
|
3143 if (! eof) |
3021 | 3144 { |
7720
4e2eafef689c
unify comment and help text processing in lex.l and parse.y
John W. Eaton <jwe@octave.org>
parents:
7719
diff
changeset
|
3145 std::string file_type; |
4e2eafef689c
unify comment and help text processing in lex.l and parse.y
John W. Eaton <jwe@octave.org>
parents:
7719
diff
changeset
|
3146 |
4e2eafef689c
unify comment and help text processing in lex.l and parse.y
John W. Eaton <jwe@octave.org>
parents:
7719
diff
changeset
|
3147 bool parsing_script = false; |
4e2eafef689c
unify comment and help text processing in lex.l and parse.y
John W. Eaton <jwe@octave.org>
parents:
7719
diff
changeset
|
3148 |
7750
5c6c6f4803c8
make eval('script') to work again
John W. Eaton <jwe@octave.org>
parents:
7749
diff
changeset
|
3149 unwind_protect_bool (get_input_from_eval_string); |
5c6c6f4803c8
make eval('script') to work again
John W. Eaton <jwe@octave.org>
parents:
7749
diff
changeset
|
3150 unwind_protect_bool (parser_end_of_input); |
5c6c6f4803c8
make eval('script') to work again
John W. Eaton <jwe@octave.org>
parents:
7749
diff
changeset
|
3151 |
5c6c6f4803c8
make eval('script') to work again
John W. Eaton <jwe@octave.org>
parents:
7749
diff
changeset
|
3152 get_input_from_eval_string = false; |
5c6c6f4803c8
make eval('script') to work again
John W. Eaton <jwe@octave.org>
parents:
7749
diff
changeset
|
3153 parser_end_of_input = false; |
5c6c6f4803c8
make eval('script') to work again
John W. Eaton <jwe@octave.org>
parents:
7749
diff
changeset
|
3154 |
7720
4e2eafef689c
unify comment and help text processing in lex.l and parse.y
John W. Eaton <jwe@octave.org>
parents:
7719
diff
changeset
|
3155 if (! force_script && looking_at_function_keyword (ffile)) |
4e2eafef689c
unify comment and help text processing in lex.l and parse.y
John W. Eaton <jwe@octave.org>
parents:
7719
diff
changeset
|
3156 { |
4e2eafef689c
unify comment and help text processing in lex.l and parse.y
John W. Eaton <jwe@octave.org>
parents:
7719
diff
changeset
|
3157 file_type = "function"; |
4e2eafef689c
unify comment and help text processing in lex.l and parse.y
John W. Eaton <jwe@octave.org>
parents:
7719
diff
changeset
|
3158 |
4e2eafef689c
unify comment and help text processing in lex.l and parse.y
John W. Eaton <jwe@octave.org>
parents:
7719
diff
changeset
|
3159 unwind_protect_int (Vecho_executing_commands); |
4e2eafef689c
unify comment and help text processing in lex.l and parse.y
John W. Eaton <jwe@octave.org>
parents:
7719
diff
changeset
|
3160 unwind_protect_bool (reading_fcn_file); |
4e2eafef689c
unify comment and help text processing in lex.l and parse.y
John W. Eaton <jwe@octave.org>
parents:
7719
diff
changeset
|
3161 |
4e2eafef689c
unify comment and help text processing in lex.l and parse.y
John W. Eaton <jwe@octave.org>
parents:
7719
diff
changeset
|
3162 Vecho_executing_commands = ECHO_OFF; |
4e2eafef689c
unify comment and help text processing in lex.l and parse.y
John W. Eaton <jwe@octave.org>
parents:
7719
diff
changeset
|
3163 reading_fcn_file = true; |
4e2eafef689c
unify comment and help text processing in lex.l and parse.y
John W. Eaton <jwe@octave.org>
parents:
7719
diff
changeset
|
3164 } |
4e2eafef689c
unify comment and help text processing in lex.l and parse.y
John W. Eaton <jwe@octave.org>
parents:
7719
diff
changeset
|
3165 else |
4e2eafef689c
unify comment and help text processing in lex.l and parse.y
John W. Eaton <jwe@octave.org>
parents:
7719
diff
changeset
|
3166 { |
4e2eafef689c
unify comment and help text processing in lex.l and parse.y
John W. Eaton <jwe@octave.org>
parents:
7719
diff
changeset
|
3167 file_type = "script"; |
4e2eafef689c
unify comment and help text processing in lex.l and parse.y
John W. Eaton <jwe@octave.org>
parents:
7719
diff
changeset
|
3168 |
4e2eafef689c
unify comment and help text processing in lex.l and parse.y
John W. Eaton <jwe@octave.org>
parents:
7719
diff
changeset
|
3169 // The value of `reading_fcn_file' will be restored to the |
4e2eafef689c
unify comment and help text processing in lex.l and parse.y
John W. Eaton <jwe@octave.org>
parents:
7719
diff
changeset
|
3170 // proper value when we unwind from this frame. |
4e2eafef689c
unify comment and help text processing in lex.l and parse.y
John W. Eaton <jwe@octave.org>
parents:
7719
diff
changeset
|
3171 reading_fcn_file = old_reading_fcn_file_state; |
4e2eafef689c
unify comment and help text processing in lex.l and parse.y
John W. Eaton <jwe@octave.org>
parents:
7719
diff
changeset
|
3172 |
4e2eafef689c
unify comment and help text processing in lex.l and parse.y
John W. Eaton <jwe@octave.org>
parents:
7719
diff
changeset
|
3173 unwind_protect_bool (reading_script_file); |
4e2eafef689c
unify comment and help text processing in lex.l and parse.y
John W. Eaton <jwe@octave.org>
parents:
7719
diff
changeset
|
3174 |
4e2eafef689c
unify comment and help text processing in lex.l and parse.y
John W. Eaton <jwe@octave.org>
parents:
7719
diff
changeset
|
3175 reading_script_file = true; |
4e2eafef689c
unify comment and help text processing in lex.l and parse.y
John W. Eaton <jwe@octave.org>
parents:
7719
diff
changeset
|
3176 |
4e2eafef689c
unify comment and help text processing in lex.l and parse.y
John W. Eaton <jwe@octave.org>
parents:
7719
diff
changeset
|
3177 parsing_script = true; |
4e2eafef689c
unify comment and help text processing in lex.l and parse.y
John W. Eaton <jwe@octave.org>
parents:
7719
diff
changeset
|
3178 } |
4e2eafef689c
unify comment and help text processing in lex.l and parse.y
John W. Eaton <jwe@octave.org>
parents:
7719
diff
changeset
|
3179 |
4e2eafef689c
unify comment and help text processing in lex.l and parse.y
John W. Eaton <jwe@octave.org>
parents:
7719
diff
changeset
|
3180 YY_BUFFER_STATE old_buf = current_buffer (); |
4e2eafef689c
unify comment and help text processing in lex.l and parse.y
John W. Eaton <jwe@octave.org>
parents:
7719
diff
changeset
|
3181 YY_BUFFER_STATE new_buf = create_buffer (ffile); |
4e2eafef689c
unify comment and help text processing in lex.l and parse.y
John W. Eaton <jwe@octave.org>
parents:
7719
diff
changeset
|
3182 |
4e2eafef689c
unify comment and help text processing in lex.l and parse.y
John W. Eaton <jwe@octave.org>
parents:
7719
diff
changeset
|
3183 unwind_protect::add (restore_input_buffer, old_buf); |
4e2eafef689c
unify comment and help text processing in lex.l and parse.y
John W. Eaton <jwe@octave.org>
parents:
7719
diff
changeset
|
3184 unwind_protect::add (delete_input_buffer, new_buf); |
4e2eafef689c
unify comment and help text processing in lex.l and parse.y
John W. Eaton <jwe@octave.org>
parents:
7719
diff
changeset
|
3185 |
4e2eafef689c
unify comment and help text processing in lex.l and parse.y
John W. Eaton <jwe@octave.org>
parents:
7719
diff
changeset
|
3186 switch_to_buffer (new_buf); |
4e2eafef689c
unify comment and help text processing in lex.l and parse.y
John W. Eaton <jwe@octave.org>
parents:
7719
diff
changeset
|
3187 |
4e2eafef689c
unify comment and help text processing in lex.l and parse.y
John W. Eaton <jwe@octave.org>
parents:
7719
diff
changeset
|
3188 unwind_protect_ptr (curr_fcn_ptr); |
4e2eafef689c
unify comment and help text processing in lex.l and parse.y
John W. Eaton <jwe@octave.org>
parents:
7719
diff
changeset
|
3189 curr_fcn_ptr = 0; |
4e2eafef689c
unify comment and help text processing in lex.l and parse.y
John W. Eaton <jwe@octave.org>
parents:
7719
diff
changeset
|
3190 |
4e2eafef689c
unify comment and help text processing in lex.l and parse.y
John W. Eaton <jwe@octave.org>
parents:
7719
diff
changeset
|
3191 reset_parser (); |
4e2eafef689c
unify comment and help text processing in lex.l and parse.y
John W. Eaton <jwe@octave.org>
parents:
7719
diff
changeset
|
3192 |
7723
74f5e0c7de9e
first pass at handling block comments
John W. Eaton <jwe@octave.org>
parents:
7720
diff
changeset
|
3193 if (! help_txt.empty ()) |
74f5e0c7de9e
first pass at handling block comments
John W. Eaton <jwe@octave.org>
parents:
7720
diff
changeset
|
3194 help_buf.push (help_txt); |
74f5e0c7de9e
first pass at handling block comments
John W. Eaton <jwe@octave.org>
parents:
7720
diff
changeset
|
3195 |
7720
4e2eafef689c
unify comment and help text processing in lex.l and parse.y
John W. Eaton <jwe@octave.org>
parents:
7719
diff
changeset
|
3196 if (parsing_script) |
4e2eafef689c
unify comment and help text processing in lex.l and parse.y
John W. Eaton <jwe@octave.org>
parents:
7719
diff
changeset
|
3197 prep_lexer_for_script (); |
4e2eafef689c
unify comment and help text processing in lex.l and parse.y
John W. Eaton <jwe@octave.org>
parents:
7719
diff
changeset
|
3198 |
4e2eafef689c
unify comment and help text processing in lex.l and parse.y
John W. Eaton <jwe@octave.org>
parents:
7719
diff
changeset
|
3199 lexer_flags.parsing_class_method = ! dispatch_type.empty (); |
4e2eafef689c
unify comment and help text processing in lex.l and parse.y
John W. Eaton <jwe@octave.org>
parents:
7719
diff
changeset
|
3200 |
4e2eafef689c
unify comment and help text processing in lex.l and parse.y
John W. Eaton <jwe@octave.org>
parents:
7719
diff
changeset
|
3201 int status = yyparse (); |
4e2eafef689c
unify comment and help text processing in lex.l and parse.y
John W. Eaton <jwe@octave.org>
parents:
7719
diff
changeset
|
3202 |
4e2eafef689c
unify comment and help text processing in lex.l and parse.y
John W. Eaton <jwe@octave.org>
parents:
7719
diff
changeset
|
3203 fcn_ptr = curr_fcn_ptr; |
4e2eafef689c
unify comment and help text processing in lex.l and parse.y
John W. Eaton <jwe@octave.org>
parents:
7719
diff
changeset
|
3204 |
4e2eafef689c
unify comment and help text processing in lex.l and parse.y
John W. Eaton <jwe@octave.org>
parents:
7719
diff
changeset
|
3205 if (status != 0) |
4e2eafef689c
unify comment and help text processing in lex.l and parse.y
John W. Eaton <jwe@octave.org>
parents:
7719
diff
changeset
|
3206 error ("parse error while reading %s file %s", |
4e2eafef689c
unify comment and help text processing in lex.l and parse.y
John W. Eaton <jwe@octave.org>
parents:
7719
diff
changeset
|
3207 file_type.c_str(), ff.c_str ()); |
3021 | 3208 } |
3209 } | |
7715
5b4d278ec828
parse scripts completely before executing
John W. Eaton <jwe@octave.org>
parents:
7699
diff
changeset
|
3210 else if (require_file) |
3880 | 3211 error ("no such file, `%s'", ff.c_str ()); |
7715
5b4d278ec828
parse scripts completely before executing
John W. Eaton <jwe@octave.org>
parents:
7699
diff
changeset
|
3212 else if (! warn_for.empty ()) |
5b4d278ec828
parse scripts completely before executing
John W. Eaton <jwe@octave.org>
parents:
7699
diff
changeset
|
3213 error ("%s: unable to open file `%s'", warn_for.c_str (), ff.c_str ()); |
3021 | 3214 |
3215 unwind_protect::run_frame ("parse_fcn_file"); | |
3216 | |
7336 | 3217 return fcn_ptr; |
3021 | 3218 } |
3219 | |
5484 | 3220 std::string |
7715
5b4d278ec828
parse scripts completely before executing
John W. Eaton <jwe@octave.org>
parents:
7699
diff
changeset
|
3221 get_help_from_file (const std::string& nm, bool& symbol_found, |
5b4d278ec828
parse scripts completely before executing
John W. Eaton <jwe@octave.org>
parents:
7699
diff
changeset
|
3222 std::string& file) |
5b4d278ec828
parse scripts completely before executing
John W. Eaton <jwe@octave.org>
parents:
7699
diff
changeset
|
3223 { |
5b4d278ec828
parse scripts completely before executing
John W. Eaton <jwe@octave.org>
parents:
7699
diff
changeset
|
3224 std::string retval; |
5b4d278ec828
parse scripts completely before executing
John W. Eaton <jwe@octave.org>
parents:
7699
diff
changeset
|
3225 |
5b4d278ec828
parse scripts completely before executing
John W. Eaton <jwe@octave.org>
parents:
7699
diff
changeset
|
3226 file = fcn_file_in_path (nm); |
5b4d278ec828
parse scripts completely before executing
John W. Eaton <jwe@octave.org>
parents:
7699
diff
changeset
|
3227 |
5b4d278ec828
parse scripts completely before executing
John W. Eaton <jwe@octave.org>
parents:
7699
diff
changeset
|
3228 if (! file.empty ()) |
5b4d278ec828
parse scripts completely before executing
John W. Eaton <jwe@octave.org>
parents:
7699
diff
changeset
|
3229 { |
5b4d278ec828
parse scripts completely before executing
John W. Eaton <jwe@octave.org>
parents:
7699
diff
changeset
|
3230 symbol_found = true; |
5b4d278ec828
parse scripts completely before executing
John W. Eaton <jwe@octave.org>
parents:
7699
diff
changeset
|
3231 |
5b4d278ec828
parse scripts completely before executing
John W. Eaton <jwe@octave.org>
parents:
7699
diff
changeset
|
3232 FILE *fptr = fopen (file.c_str (), "r"); |
5b4d278ec828
parse scripts completely before executing
John W. Eaton <jwe@octave.org>
parents:
7699
diff
changeset
|
3233 |
5b4d278ec828
parse scripts completely before executing
John W. Eaton <jwe@octave.org>
parents:
7699
diff
changeset
|
3234 if (fptr) |
5b4d278ec828
parse scripts completely before executing
John W. Eaton <jwe@octave.org>
parents:
7699
diff
changeset
|
3235 { |
5b4d278ec828
parse scripts completely before executing
John W. Eaton <jwe@octave.org>
parents:
7699
diff
changeset
|
3236 unwind_protect::add (safe_fclose, fptr); |
5b4d278ec828
parse scripts completely before executing
John W. Eaton <jwe@octave.org>
parents:
7699
diff
changeset
|
3237 |
7720
4e2eafef689c
unify comment and help text processing in lex.l and parse.y
John W. Eaton <jwe@octave.org>
parents:
7719
diff
changeset
|
3238 bool eof; |
4e2eafef689c
unify comment and help text processing in lex.l and parse.y
John W. Eaton <jwe@octave.org>
parents:
7719
diff
changeset
|
3239 retval = gobble_leading_white_space (fptr, eof); |
7715
5b4d278ec828
parse scripts completely before executing
John W. Eaton <jwe@octave.org>
parents:
7699
diff
changeset
|
3240 |
5b4d278ec828
parse scripts completely before executing
John W. Eaton <jwe@octave.org>
parents:
7699
diff
changeset
|
3241 if (retval.empty ()) |
5b4d278ec828
parse scripts completely before executing
John W. Eaton <jwe@octave.org>
parents:
7699
diff
changeset
|
3242 { |
5b4d278ec828
parse scripts completely before executing
John W. Eaton <jwe@octave.org>
parents:
7699
diff
changeset
|
3243 octave_function *fcn = parse_fcn_file (file, ""); |
5b4d278ec828
parse scripts completely before executing
John W. Eaton <jwe@octave.org>
parents:
7699
diff
changeset
|
3244 |
5b4d278ec828
parse scripts completely before executing
John W. Eaton <jwe@octave.org>
parents:
7699
diff
changeset
|
3245 if (fcn) |
5b4d278ec828
parse scripts completely before executing
John W. Eaton <jwe@octave.org>
parents:
7699
diff
changeset
|
3246 { |
5b4d278ec828
parse scripts completely before executing
John W. Eaton <jwe@octave.org>
parents:
7699
diff
changeset
|
3247 retval = fcn->doc_string (); |
5b4d278ec828
parse scripts completely before executing
John W. Eaton <jwe@octave.org>
parents:
7699
diff
changeset
|
3248 |
5b4d278ec828
parse scripts completely before executing
John W. Eaton <jwe@octave.org>
parents:
7699
diff
changeset
|
3249 delete fcn; |
5b4d278ec828
parse scripts completely before executing
John W. Eaton <jwe@octave.org>
parents:
7699
diff
changeset
|
3250 } |
5b4d278ec828
parse scripts completely before executing
John W. Eaton <jwe@octave.org>
parents:
7699
diff
changeset
|
3251 } |
5b4d278ec828
parse scripts completely before executing
John W. Eaton <jwe@octave.org>
parents:
7699
diff
changeset
|
3252 |
5b4d278ec828
parse scripts completely before executing
John W. Eaton <jwe@octave.org>
parents:
7699
diff
changeset
|
3253 unwind_protect::run (); |
5b4d278ec828
parse scripts completely before executing
John W. Eaton <jwe@octave.org>
parents:
7699
diff
changeset
|
3254 } |
5b4d278ec828
parse scripts completely before executing
John W. Eaton <jwe@octave.org>
parents:
7699
diff
changeset
|
3255 } |
5b4d278ec828
parse scripts completely before executing
John W. Eaton <jwe@octave.org>
parents:
7699
diff
changeset
|
3256 |
5b4d278ec828
parse scripts completely before executing
John W. Eaton <jwe@octave.org>
parents:
7699
diff
changeset
|
3257 return retval; |
5b4d278ec828
parse scripts completely before executing
John W. Eaton <jwe@octave.org>
parents:
7699
diff
changeset
|
3258 } |
5b4d278ec828
parse scripts completely before executing
John W. Eaton <jwe@octave.org>
parents:
7699
diff
changeset
|
3259 |
5b4d278ec828
parse scripts completely before executing
John W. Eaton <jwe@octave.org>
parents:
7699
diff
changeset
|
3260 std::string |
5b4d278ec828
parse scripts completely before executing
John W. Eaton <jwe@octave.org>
parents:
7699
diff
changeset
|
3261 get_help_from_file (const std::string& nm, bool& symbol_found) |
5b4d278ec828
parse scripts completely before executing
John W. Eaton <jwe@octave.org>
parents:
7699
diff
changeset
|
3262 { |
5b4d278ec828
parse scripts completely before executing
John W. Eaton <jwe@octave.org>
parents:
7699
diff
changeset
|
3263 std::string file; |
5b4d278ec828
parse scripts completely before executing
John W. Eaton <jwe@octave.org>
parents:
7699
diff
changeset
|
3264 return get_help_from_file (nm, symbol_found, file); |
5b4d278ec828
parse scripts completely before executing
John W. Eaton <jwe@octave.org>
parents:
7699
diff
changeset
|
3265 } |
5b4d278ec828
parse scripts completely before executing
John W. Eaton <jwe@octave.org>
parents:
7699
diff
changeset
|
3266 |
5b4d278ec828
parse scripts completely before executing
John W. Eaton <jwe@octave.org>
parents:
7699
diff
changeset
|
3267 std::string |
5484 | 3268 lookup_autoload (const std::string& nm) |
3269 { | |
5626 | 3270 std::string retval; |
3271 | |
3272 typedef std::map<std::string, std::string>::const_iterator am_iter; | |
3273 | |
3274 am_iter p = autoload_map.find (nm); | |
3275 | |
3276 if (p != autoload_map.end ()) | |
6323 | 3277 retval = load_path::find_file (p->second); |
5626 | 3278 |
3279 return retval; | |
5484 | 3280 } |
3281 | |
5592 | 3282 string_vector |
3283 autoloaded_functions (void) | |
3284 { | |
3285 string_vector names (autoload_map.size()); | |
3286 | |
3287 octave_idx_type i = 0; | |
5626 | 3288 typedef std::map<std::string, std::string>::const_iterator am_iter; |
3289 for (am_iter p = autoload_map.begin (); p != autoload_map.end (); p++) | |
5592 | 3290 names[i++] = p->first; |
3291 | |
3292 return names; | |
3293 } | |
3294 | |
3295 string_vector | |
3296 reverse_lookup_autoload (const std::string& nm) | |
3297 { | |
3298 string_vector names; | |
3299 | |
5626 | 3300 typedef std::map<std::string, std::string>::const_iterator am_iter; |
3301 for (am_iter p = autoload_map.begin (); p != autoload_map.end (); p++) | |
5592 | 3302 if (nm == p->second) |
3303 names.append (p->first); | |
3304 | |
3305 return names; | |
3306 } | |
3307 | |
7336 | 3308 octave_function * |
3309 load_fcn_from_file (const std::string& file_name, const std::string& dir_name, | |
3310 const std::string& dispatch_type, | |
3311 const std::string& fcn_name, bool autoload) | |
3021 | 3312 { |
7336 | 3313 octave_function *retval = 0; |
3314 | |
5484 | 3315 unwind_protect::begin_frame ("load_fcn_from_file"); |
3316 | |
7336 | 3317 std::string nm = file_name; |
6238 | 3318 |
3319 size_t nm_len = nm.length (); | |
5472 | 3320 |
3321 std::string file; | |
3322 | |
6323 | 3323 unwind_protect_bool (fcn_file_from_relative_lookup); |
3324 | |
3325 fcn_file_from_relative_lookup = false; | |
3326 | |
7336 | 3327 file = nm; |
3328 | |
3329 if ((nm_len > 4 && nm.substr (nm_len-4) == ".oct") | |
3330 || (nm_len > 4 && nm.substr (nm_len-4) == ".mex") | |
3331 || (nm_len > 2 && nm.substr (nm_len-2) == ".m")) | |
5472 | 3332 { |
6238 | 3333 nm = octave_env::base_pathname (file); |
3334 nm = nm.substr (0, nm.find_last_of ('.')); | |
5472 | 3335 } |
7336 | 3336 |
3337 if (autoload) | |
5472 | 3338 { |
7336 | 3339 unwind_protect_bool (autoloading); |
3340 autoloading = true; | |
3341 } | |
3342 | |
7749
14e05160b99f
reference counting for functions loaded from shared libraries
John W. Eaton <jwe@octave.org>
parents:
7736
diff
changeset
|
3343 fcn_file_from_relative_lookup = ! octave_env::absolute_pathname (file); |
14e05160b99f
reference counting for functions loaded from shared libraries
John W. Eaton <jwe@octave.org>
parents:
7736
diff
changeset
|
3344 |
14e05160b99f
reference counting for functions loaded from shared libraries
John W. Eaton <jwe@octave.org>
parents:
7736
diff
changeset
|
3345 file = octave_env::make_absolute (file, octave_env::getcwd ()); |
4243 | 3346 |
3347 int len = file.length (); | |
3348 | |
4244 | 3349 if (len > 4 && file.substr (len-4, len-1) == ".oct") |
3021 | 3350 { |
7336 | 3351 if (autoload && ! fcn_name.empty ()) |
3352 nm = fcn_name; | |
3353 | |
3354 retval = octave_dynamic_loader::load_oct (nm, file, fcn_file_from_relative_lookup); | |
5864 | 3355 } |
3356 else if (len > 4 && file.substr (len-4, len-1) == ".mex") | |
7336 | 3357 retval = octave_dynamic_loader::load_mex (nm, file, fcn_file_from_relative_lookup); |
4244 | 3358 else if (len > 2) |
3021 | 3359 { |
7715
5b4d278ec828
parse scripts completely before executing
John W. Eaton <jwe@octave.org>
parents:
7699
diff
changeset
|
3360 // These are needed by yyparse. |
5b4d278ec828
parse scripts completely before executing
John W. Eaton <jwe@octave.org>
parents:
7699
diff
changeset
|
3361 |
5b4d278ec828
parse scripts completely before executing
John W. Eaton <jwe@octave.org>
parents:
7699
diff
changeset
|
3362 unwind_protect_str (curr_fcn_file_name); |
5b4d278ec828
parse scripts completely before executing
John W. Eaton <jwe@octave.org>
parents:
7699
diff
changeset
|
3363 unwind_protect_str (curr_fcn_file_full_name); |
5b4d278ec828
parse scripts completely before executing
John W. Eaton <jwe@octave.org>
parents:
7699
diff
changeset
|
3364 |
5b4d278ec828
parse scripts completely before executing
John W. Eaton <jwe@octave.org>
parents:
7699
diff
changeset
|
3365 curr_fcn_file_name = nm; |
5b4d278ec828
parse scripts completely before executing
John W. Eaton <jwe@octave.org>
parents:
7699
diff
changeset
|
3366 curr_fcn_file_full_name = file; |
5b4d278ec828
parse scripts completely before executing
John W. Eaton <jwe@octave.org>
parents:
7699
diff
changeset
|
3367 |
5b4d278ec828
parse scripts completely before executing
John W. Eaton <jwe@octave.org>
parents:
7699
diff
changeset
|
3368 retval = parse_fcn_file (file, dispatch_type, autoloading); |
3021 | 3369 } |
3370 | |
7336 | 3371 if (retval) |
3372 retval->stash_dir_name (dir_name); | |
3373 | |
5484 | 3374 unwind_protect::run_frame ("load_fcn_from_file"); |
3375 | |
7336 | 3376 return retval; |
5312 | 3377 } |
3378 | |
5484 | 3379 DEFCMD (autoload, args, , |
3380 "-*- texinfo -*-\n\ | |
3381 @deftypefn {Built-in Function} {} autoload (@var{function}, @var{file})\n\ | |
3382 Define @var{function} to autoload from @var{file}.\n\ | |
5626 | 3383 \n\ |
6926 | 3384 The second argument, @var{file}, should be an absolute file name or\n\ |
3385 a file name in the same directory as the function or script from which\n\ | |
3386 the autoload command was run. @var{file} should not depend on the\n\ | |
3387 Octave load path.\n\ | |
6380 | 3388 \n\ |
3389 Normally, calls to @code{autoload} appear in PKG_ADD script files that\n\ | |
3390 are evaluated when a directory is added to the Octave's load path. To\n\ | |
6926 | 3391 avoid having to hardcode directory names in @var{file}, if @var{file}\n\ |
3392 is in the same directory as the PKG_ADD script then\n\ | |
6380 | 3393 \n\ |
3394 @example\n\ | |
6926 | 3395 autoload (\"foo\", \"bar.oct\");\n\ |
6380 | 3396 @end example\n\ |
3397 \n\ | |
6926 | 3398 will load the function @code{foo} from the file @code{bar.oct}. The above\n\ |
3399 when @code{bar.oct} is not in the same directory or uses like\n\ | |
6380 | 3400 \n\ |
3401 @example\n\ | |
6637 | 3402 autoload (\"foo\", file_in_loadpath (\"bar.oct\"))\n\ |
6380 | 3403 @end example\n\ |
3404 \n\ | |
3405 @noindent\n\ | |
6926 | 3406 are strongly discouraged, as their behavior might be unpredictable.\n\ |
6380 | 3407 \n\ |
6637 | 3408 With no arguments, return a structure containing the current autoload map.\n\ |
6380 | 3409 @seealso{PKG_ADD}\n\ |
5484 | 3410 @end deftypefn") |
3411 { | |
5626 | 3412 octave_value retval; |
5484 | 3413 |
3414 int nargin = args.length (); | |
3415 | |
5626 | 3416 if (nargin == 0) |
3417 { | |
3418 Cell func_names (dim_vector (autoload_map.size ()), 1); | |
3419 Cell file_names (dim_vector (autoload_map.size ()), 1); | |
3420 | |
3421 octave_idx_type i = 0; | |
3422 typedef std::map<std::string, std::string>::const_iterator am_iter; | |
3423 for (am_iter p = autoload_map.begin (); p != autoload_map.end (); p++) | |
3424 { | |
3425 func_names(i) = p->first; | |
3426 file_names(i) = p->second; | |
3427 | |
3428 i++; | |
3429 } | |
3430 | |
3431 Octave_map m; | |
3432 | |
3433 m.assign ("function", func_names); | |
3434 m.assign ("file", file_names); | |
3435 | |
3436 retval = m; | |
3437 } | |
3438 else if (nargin == 2) | |
5484 | 3439 { |
3440 string_vector argv = args.make_argv ("autoload"); | |
3441 | |
3442 if (! error_state) | |
6380 | 3443 { |
3444 std::string nm = argv[2]; | |
3445 | |
3446 if (! octave_env::absolute_pathname (nm)) | |
6926 | 3447 { |
7719
87eda1f8faaa
octave_user_code: new base class for octave_user_script and octave_user_function
John W. Eaton <jwe@octave.org>
parents:
7715
diff
changeset
|
3448 octave_user_code *fcn = octave_call_stack::caller_user_code (); |
87eda1f8faaa
octave_user_code: new base class for octave_user_script and octave_user_function
John W. Eaton <jwe@octave.org>
parents:
7715
diff
changeset
|
3449 |
6926 | 3450 bool found = false; |
7719
87eda1f8faaa
octave_user_code: new base class for octave_user_script and octave_user_function
John W. Eaton <jwe@octave.org>
parents:
7715
diff
changeset
|
3451 |
6926 | 3452 if (fcn) |
3453 { | |
3454 std::string fname = fcn->fcn_file_name (); | |
7719
87eda1f8faaa
octave_user_code: new base class for octave_user_script and octave_user_function
John W. Eaton <jwe@octave.org>
parents:
7715
diff
changeset
|
3455 |
6926 | 3456 if (! fname.empty ()) |
3457 { | |
7719
87eda1f8faaa
octave_user_code: new base class for octave_user_script and octave_user_function
John W. Eaton <jwe@octave.org>
parents:
7715
diff
changeset
|
3458 fname = octave_env::make_absolute (fname, octave_env::getcwd ()); |
8007
a2ab20ba78f7
make file_ops a proper singleton class
John W. Eaton <jwe@octave.org>
parents:
8001
diff
changeset
|
3459 fname = fname.substr (0, fname.find_last_of (file_ops::dir_sep_str ()) + 1); |
7719
87eda1f8faaa
octave_user_code: new base class for octave_user_script and octave_user_function
John W. Eaton <jwe@octave.org>
parents:
7715
diff
changeset
|
3460 |
6926 | 3461 file_stat fs (fname + nm); |
7719
87eda1f8faaa
octave_user_code: new base class for octave_user_script and octave_user_function
John W. Eaton <jwe@octave.org>
parents:
7715
diff
changeset
|
3462 |
6926 | 3463 if (fs.exists ()) |
3464 { | |
3465 nm = fname + nm; | |
3466 found = true; | |
3467 } | |
3468 } | |
3469 } | |
3470 if (! found) | |
3471 warning_with_id ("Octave:autoload-relative-file-name", | |
3472 "autoload: `%s' is not an absolute file name", | |
3473 nm.c_str ()); | |
3474 } | |
6380 | 3475 autoload_map[argv[1]] = nm; |
3476 } | |
5484 | 3477 } |
3478 else | |
5823 | 3479 print_usage (); |
5484 | 3480 |
3481 return retval; | |
3482 } | |
3483 | |
4486 | 3484 void |
7715
5b4d278ec828
parse scripts completely before executing
John W. Eaton <jwe@octave.org>
parents:
7699
diff
changeset
|
3485 source_file (const std::string& file_name, const std::string& context, |
5b4d278ec828
parse scripts completely before executing
John W. Eaton <jwe@octave.org>
parents:
7699
diff
changeset
|
3486 bool verbose, bool require_file, const std::string& warn_for) |
4486 | 3487 { |
3488 std::string file_full_name = file_ops::tilde_expand (file_name); | |
3489 | |
3490 unwind_protect::begin_frame ("source_file"); | |
3491 | |
3492 unwind_protect_str (curr_fcn_file_name); | |
3493 unwind_protect_str (curr_fcn_file_full_name); | |
3494 | |
3495 curr_fcn_file_name = file_name; | |
3496 curr_fcn_file_full_name = file_full_name; | |
3497 | |
5975 | 3498 if (! context.empty ()) |
3499 { | |
3500 if (context == "caller") | |
7901 | 3501 octave_call_stack::goto_caller_frame (); |
5975 | 3502 else if (context == "base") |
7901 | 3503 octave_call_stack::goto_base_frame (); |
5975 | 3504 else |
3505 error ("source: context must be \"caller\" or \"base\""); | |
7336 | 3506 |
3507 if (! error_state) | |
7901 | 3508 unwind_protect::add (octave_call_stack::unwind_pop); |
5975 | 3509 } |
3510 | |
3511 if (! error_state) | |
3512 { | |
7715
5b4d278ec828
parse scripts completely before executing
John W. Eaton <jwe@octave.org>
parents:
7699
diff
changeset
|
3513 octave_function *fcn = parse_fcn_file (file_full_name, "", true, |
5b4d278ec828
parse scripts completely before executing
John W. Eaton <jwe@octave.org>
parents:
7699
diff
changeset
|
3514 require_file, warn_for); |
5b4d278ec828
parse scripts completely before executing
John W. Eaton <jwe@octave.org>
parents:
7699
diff
changeset
|
3515 |
5b4d278ec828
parse scripts completely before executing
John W. Eaton <jwe@octave.org>
parents:
7699
diff
changeset
|
3516 if (! error_state) |
5b4d278ec828
parse scripts completely before executing
John W. Eaton <jwe@octave.org>
parents:
7699
diff
changeset
|
3517 { |
5b4d278ec828
parse scripts completely before executing
John W. Eaton <jwe@octave.org>
parents:
7699
diff
changeset
|
3518 if (fcn && fcn->is_user_script ()) |
5b4d278ec828
parse scripts completely before executing
John W. Eaton <jwe@octave.org>
parents:
7699
diff
changeset
|
3519 { |
5b4d278ec828
parse scripts completely before executing
John W. Eaton <jwe@octave.org>
parents:
7699
diff
changeset
|
3520 octave_value_list args; |
5b4d278ec828
parse scripts completely before executing
John W. Eaton <jwe@octave.org>
parents:
7699
diff
changeset
|
3521 |
5b4d278ec828
parse scripts completely before executing
John W. Eaton <jwe@octave.org>
parents:
7699
diff
changeset
|
3522 if (verbose) |
5b4d278ec828
parse scripts completely before executing
John W. Eaton <jwe@octave.org>
parents:
7699
diff
changeset
|
3523 { |
5b4d278ec828
parse scripts completely before executing
John W. Eaton <jwe@octave.org>
parents:
7699
diff
changeset
|
3524 std::cout << "executing commands from " << file_full_name << " ... "; |
5b4d278ec828
parse scripts completely before executing
John W. Eaton <jwe@octave.org>
parents:
7699
diff
changeset
|
3525 reading_startup_message_printed = true; |
5b4d278ec828
parse scripts completely before executing
John W. Eaton <jwe@octave.org>
parents:
7699
diff
changeset
|
3526 std::cout.flush (); |
5b4d278ec828
parse scripts completely before executing
John W. Eaton <jwe@octave.org>
parents:
7699
diff
changeset
|
3527 } |
5b4d278ec828
parse scripts completely before executing
John W. Eaton <jwe@octave.org>
parents:
7699
diff
changeset
|
3528 |
5b4d278ec828
parse scripts completely before executing
John W. Eaton <jwe@octave.org>
parents:
7699
diff
changeset
|
3529 fcn->do_multi_index_op (0, args); |
5b4d278ec828
parse scripts completely before executing
John W. Eaton <jwe@octave.org>
parents:
7699
diff
changeset
|
3530 |
5b4d278ec828
parse scripts completely before executing
John W. Eaton <jwe@octave.org>
parents:
7699
diff
changeset
|
3531 if (verbose) |
5b4d278ec828
parse scripts completely before executing
John W. Eaton <jwe@octave.org>
parents:
7699
diff
changeset
|
3532 std::cout << "done." << std::endl; |
5b4d278ec828
parse scripts completely before executing
John W. Eaton <jwe@octave.org>
parents:
7699
diff
changeset
|
3533 |
5b4d278ec828
parse scripts completely before executing
John W. Eaton <jwe@octave.org>
parents:
7699
diff
changeset
|
3534 delete fcn; |
5b4d278ec828
parse scripts completely before executing
John W. Eaton <jwe@octave.org>
parents:
7699
diff
changeset
|
3535 } |
5b4d278ec828
parse scripts completely before executing
John W. Eaton <jwe@octave.org>
parents:
7699
diff
changeset
|
3536 } |
5b4d278ec828
parse scripts completely before executing
John W. Eaton <jwe@octave.org>
parents:
7699
diff
changeset
|
3537 else |
5975 | 3538 error ("source: error sourcing file `%s'", |
3539 file_full_name.c_str ()); | |
3540 } | |
4486 | 3541 |
3542 unwind_protect::run_frame ("source_file"); | |
3543 } | |
3544 | |
5739 | 3545 DEFUN (mfilename, args, , |
3546 "-*- texinfo -*-\n\ | |
3547 @deftypefn {Built-in Function} {} mfilename ()\n\ | |
3548 @deftypefnx {Built-in Function} {} mfilename (@code{\"fullpath\"})\n\ | |
3549 @deftypefnx {Built-in Function} {} mfilename (@code{\"fullpathext\"})\n\ | |
3550 Return the name of the currently executing file. At the top-level,\n\ | |
3551 return the empty string. Given the argument @code{\"fullpath\"},\n\ | |
3552 include the directory part of the file name, but not the extension.\n\ | |
3553 Given the argument @code{\"fullpathext\"}, include the directory part\n\ | |
3554 of the file name and the extension.\n\ | |
5774 | 3555 @end deftypefn") |
5739 | 3556 { |
3557 octave_value retval; | |
3558 | |
3559 int nargin = args.length (); | |
3560 | |
3561 if (nargin > 1) | |
3562 { | |
5823 | 3563 print_usage (); |
5739 | 3564 return retval; |
3565 } | |
3566 | |
3567 std::string arg; | |
3568 | |
3569 if (nargin == 1) | |
3570 { | |
3571 arg = args(0).string_value (); | |
3572 | |
3573 if (error_state) | |
3574 { | |
3575 error ("mfilename: expecting argument to be a character string"); | |
3576 return retval; | |
3577 } | |
3578 } | |
3579 | |
3580 std::string fname; | |
3581 | |
7719
87eda1f8faaa
octave_user_code: new base class for octave_user_script and octave_user_function
John W. Eaton <jwe@octave.org>
parents:
7715
diff
changeset
|
3582 octave_user_code *fcn = octave_call_stack::caller_user_code (); |
5743 | 3583 |
3584 if (fcn) | |
3585 { | |
3586 fname = fcn->fcn_file_name (); | |
3587 | |
3588 if (fname.empty ()) | |
3589 fname = fcn->name (); | |
3590 } | |
5739 | 3591 |
3592 if (arg == "fullpathext") | |
3593 retval = fname; | |
3594 else | |
3595 { | |
8007
a2ab20ba78f7
make file_ops a proper singleton class
John W. Eaton <jwe@octave.org>
parents:
8001
diff
changeset
|
3596 size_t dpos = fname.rfind (file_ops::dir_sep_char ()); |
5747 | 3597 size_t epos = fname.rfind ('.'); |
3598 | |
3599 if (epos <= dpos) | |
8021 | 3600 epos = std::string::npos; |
3601 | |
3602 fname = (epos != std::string::npos) ? fname.substr (0, epos) : fname; | |
5739 | 3603 |
3604 if (arg == "fullpath") | |
3605 retval = fname; | |
3606 else | |
8021 | 3607 retval = (dpos != std::string::npos) ? fname.substr (dpos+1) : fname; |
5739 | 3608 } |
3609 | |
3610 return retval; | |
3611 } | |
3612 | |
3613 | |
3021 | 3614 DEFUN (source, args, , |
3371 | 3615 "-*- texinfo -*-\n\ |
3616 @deftypefn {Built-in Function} {} source (@var{file})\n\ | |
3617 Parse and execute the contents of @var{file}. This is equivalent to\n\ | |
3618 executing commands from a script file, but without requiring the file to\n\ | |
3619 be named @file{@var{file}.m}.\n\ | |
3620 @end deftypefn") | |
3021 | 3621 { |
3622 octave_value_list retval; | |
3623 | |
3624 int nargin = args.length (); | |
3625 | |
5975 | 3626 if (nargin == 1 || nargin == 2) |
3021 | 3627 { |
3523 | 3628 std::string file_name = args(0).string_value (); |
3021 | 3629 |
3630 if (! error_state) | |
5975 | 3631 { |
3632 std::string context; | |
3633 | |
3634 if (nargin == 2) | |
3635 context = args(1).string_value (); | |
3636 | |
3637 if (! error_state) | |
3638 source_file (file_name, context); | |
3639 else | |
3640 error ("source: expecting context to be character string"); | |
3641 } | |
3021 | 3642 else |
3643 error ("source: expecting file name as argument"); | |
3644 } | |
3645 else | |
5823 | 3646 print_usage (); |
3021 | 3647 |
3648 return retval; | |
3649 } | |
3650 | |
3726 | 3651 // Evaluate an Octave function (built-in or interpreted) and return |
3844 | 3652 // the list of result values. NAME is the name of the function to |
3653 // call. ARGS are the arguments to the function. NARGOUT is the | |
3654 // number of output arguments expected. | |
3726 | 3655 |
3021 | 3656 octave_value_list |
3523 | 3657 feval (const std::string& name, const octave_value_list& args, int nargout) |
3156 | 3658 { |
3659 octave_value_list retval; | |
3660 | |
7336 | 3661 octave_value fcn = symbol_table::find_function (name, args); |
3662 | |
3663 if (fcn.is_defined ()) | |
3664 retval = fcn.do_multi_index_op (nargout, args); | |
3665 else | |
3666 error ("feval: function `%s' not found", name.c_str ()); | |
3156 | 3667 |
3668 return retval; | |
3669 } | |
3670 | |
4342 | 3671 octave_value_list |
3672 feval (octave_function *fcn, const octave_value_list& args, int nargout) | |
3673 { | |
3674 octave_value_list retval; | |
3675 | |
3676 if (fcn) | |
3677 retval = fcn->do_multi_index_op (nargout, args); | |
3678 | |
3679 return retval; | |
3680 } | |
3681 | |
3682 static octave_value_list | |
3683 get_feval_args (const octave_value_list& args) | |
3684 { | |
3685 int tmp_nargin = args.length () - 1; | |
3686 | |
3687 octave_value_list retval (tmp_nargin, octave_value ()); | |
3688 | |
3689 for (int i = 0; i < tmp_nargin; i++) | |
3690 retval(i) = args(i+1); | |
3691 | |
3692 string_vector arg_names = args.name_tags (); | |
3693 | |
3694 if (! arg_names.empty ()) | |
3695 { | |
3696 // tmp_nargin and arg_names.length () - 1 may differ if | |
3697 // we are passed all_va_args. | |
3698 | |
3699 int n = arg_names.length () - 1; | |
3700 | |
3701 int len = n > tmp_nargin ? tmp_nargin : n; | |
3702 | |
3703 string_vector tmp_arg_names (len); | |
3704 | |
3705 for (int i = 0; i < len; i++) | |
3706 tmp_arg_names(i) = arg_names(i+1); | |
3707 | |
3708 retval.stash_name_tags (tmp_arg_names); | |
3709 } | |
3710 | |
3711 return retval; | |
3712 } | |
3713 | |
3714 | |
3726 | 3715 // Evaluate an Octave function (built-in or interpreted) and return |
3716 // the list of result values. The first element of ARGS should be a | |
3717 // string containing the name of the function to call, then the rest | |
3718 // are the actual arguments to the function. NARGOUT is the number of | |
3719 // output arguments expected. | |
3720 | |
3156 | 3721 octave_value_list |
3021 | 3722 feval (const octave_value_list& args, int nargout) |
3723 { | |
3724 octave_value_list retval; | |
3725 | |
4342 | 3726 int nargin = args.length (); |
3727 | |
3728 if (nargin > 0) | |
3021 | 3729 { |
4342 | 3730 octave_value f_arg = args(0); |
3731 | |
3732 if (f_arg.is_string ()) | |
3733 { | |
3734 std::string name = f_arg.string_value (); | |
3735 | |
3736 if (! error_state) | |
3156 | 3737 { |
4342 | 3738 octave_value_list tmp_args = get_feval_args (args); |
3739 | |
3740 retval = feval (name, tmp_args, nargout); | |
3156 | 3741 } |
4342 | 3742 } |
3743 else | |
3744 { | |
3745 octave_function *fcn = f_arg.function_value (); | |
3746 | |
3747 if (fcn) | |
3748 { | |
3749 octave_value_list tmp_args = get_feval_args (args); | |
3750 | |
3751 retval = feval (fcn, tmp_args, nargout); | |
3752 } | |
3021 | 3753 } |
3754 } | |
3755 | |
3756 return retval; | |
3757 } | |
3758 | |
3759 DEFUN (feval, args, nargout, | |
3371 | 3760 "-*- texinfo -*-\n\ |
3761 @deftypefn {Built-in Function} {} feval (@var{name}, @dots{})\n\ | |
3762 Evaluate the function named @var{name}. Any arguments after the first\n\ | |
3763 are passed on to the named function. For example,\n\ | |
3764 \n\ | |
3765 @example\n\ | |
3766 feval (\"acos\", -1)\n\ | |
3767 @result{} 3.1416\n\ | |
3768 @end example\n\ | |
3021 | 3769 \n\ |
3371 | 3770 @noindent\n\ |
3771 calls the function @code{acos} with the argument @samp{-1}.\n\ | |
3772 \n\ | |
3773 The function @code{feval} is necessary in order to be able to write\n\ | |
3774 functions that call user-supplied functions, because Octave does not\n\ | |
3775 have a way to declare a pointer to a function (like C) or to declare a\n\ | |
3776 special kind of variable that can be used to hold the name of a function\n\ | |
3777 (like @code{EXTERNAL} in Fortran). Instead, you must refer to functions\n\ | |
3778 by name, and use @code{feval} to call them.\n\ | |
3779 @end deftypefn") | |
3021 | 3780 { |
3781 octave_value_list retval; | |
3782 | |
3783 int nargin = args.length (); | |
3784 | |
3785 if (nargin > 0) | |
3786 retval = feval (args, nargout); | |
3787 else | |
5823 | 3788 print_usage (); |
3021 | 3789 |
3790 return retval; | |
3791 } | |
3792 | |
3099 | 3793 octave_value_list |
3523 | 3794 eval_string (const std::string& s, bool silent, int& parse_status, int nargout) |
3021 | 3795 { |
3877 | 3796 octave_value_list retval; |
3797 | |
3021 | 3798 unwind_protect::begin_frame ("eval_string"); |
3799 | |
8447
adab48231a03
make input_line_number work again
John W. Eaton <jwe@octave.org>
parents:
8311
diff
changeset
|
3800 unwind_protect_int (input_line_number); |
adab48231a03
make input_line_number work again
John W. Eaton <jwe@octave.org>
parents:
8311
diff
changeset
|
3801 unwind_protect_int (current_input_column); |
3021 | 3802 unwind_protect_bool (get_input_from_eval_string); |
3877 | 3803 unwind_protect_bool (input_from_eval_string_pending); |
3883 | 3804 unwind_protect_bool (parser_end_of_input); |
5189 | 3805 unwind_protect_bool (line_editing); |
3021 | 3806 unwind_protect_str (current_eval_string); |
3807 | |
8447
adab48231a03
make input_line_number work again
John W. Eaton <jwe@octave.org>
parents:
8311
diff
changeset
|
3808 input_line_number = 1; |
adab48231a03
make input_line_number work again
John W. Eaton <jwe@octave.org>
parents:
8311
diff
changeset
|
3809 current_input_column = 1; |
3021 | 3810 get_input_from_eval_string = true; |
3877 | 3811 input_from_eval_string_pending = true; |
3883 | 3812 parser_end_of_input = false; |
5189 | 3813 line_editing = false; |
3814 | |
3021 | 3815 current_eval_string = s; |
3816 | |
3817 YY_BUFFER_STATE old_buf = current_buffer (); | |
3818 YY_BUFFER_STATE new_buf = create_buffer (0); | |
3819 | |
3820 unwind_protect::add (restore_input_buffer, old_buf); | |
3821 unwind_protect::add (delete_input_buffer, new_buf); | |
3822 | |
3823 switch_to_buffer (new_buf); | |
3824 | |
3877 | 3825 do |
3826 { | |
4318 | 3827 reset_parser (); |
3828 | |
7903
8018e10d2b87
save and restore global_command as needed
John W. Eaton <jwe@octave.org>
parents:
7901
diff
changeset
|
3829 unwind_protect_ptr (global_command); |
8018e10d2b87
save and restore global_command as needed
John W. Eaton <jwe@octave.org>
parents:
7901
diff
changeset
|
3830 |
3877 | 3831 parse_status = yyparse (); |
3832 | |
8658
73c4516fae10
New evaluator and debugger derived from tree-walker class
John W. Eaton <jwe@octave.org>
parents:
8471
diff
changeset
|
3833 tree_statement_list *command_list = global_command; |
3877 | 3834 |
7903
8018e10d2b87
save and restore global_command as needed
John W. Eaton <jwe@octave.org>
parents:
7901
diff
changeset
|
3835 // Restore previous value of global_command. |
8018e10d2b87
save and restore global_command as needed
John W. Eaton <jwe@octave.org>
parents:
7901
diff
changeset
|
3836 unwind_protect::run (); |
8018e10d2b87
save and restore global_command as needed
John W. Eaton <jwe@octave.org>
parents:
7901
diff
changeset
|
3837 |
3883 | 3838 if (parse_status == 0) |
3877 | 3839 { |
8658
73c4516fae10
New evaluator and debugger derived from tree-walker class
John W. Eaton <jwe@octave.org>
parents:
8471
diff
changeset
|
3840 if (command_list) |
3883 | 3841 { |
8658
73c4516fae10
New evaluator and debugger derived from tree-walker class
John W. Eaton <jwe@octave.org>
parents:
8471
diff
changeset
|
3842 tree_statement *stmt = 0; |
73c4516fae10
New evaluator and debugger derived from tree-walker class
John W. Eaton <jwe@octave.org>
parents:
8471
diff
changeset
|
3843 |
73c4516fae10
New evaluator and debugger derived from tree-walker class
John W. Eaton <jwe@octave.org>
parents:
8471
diff
changeset
|
3844 if (command_list->length () == 1 |
73c4516fae10
New evaluator and debugger derived from tree-walker class
John W. Eaton <jwe@octave.org>
parents:
8471
diff
changeset
|
3845 && (stmt = command_list->front ()) |
73c4516fae10
New evaluator and debugger derived from tree-walker class
John W. Eaton <jwe@octave.org>
parents:
8471
diff
changeset
|
3846 && stmt->is_expression ()) |
73c4516fae10
New evaluator and debugger derived from tree-walker class
John W. Eaton <jwe@octave.org>
parents:
8471
diff
changeset
|
3847 { |
73c4516fae10
New evaluator and debugger derived from tree-walker class
John W. Eaton <jwe@octave.org>
parents:
8471
diff
changeset
|
3848 tree_expression *expr = stmt->expression (); |
73c4516fae10
New evaluator and debugger derived from tree-walker class
John W. Eaton <jwe@octave.org>
parents:
8471
diff
changeset
|
3849 |
73c4516fae10
New evaluator and debugger derived from tree-walker class
John W. Eaton <jwe@octave.org>
parents:
8471
diff
changeset
|
3850 if (silent) |
73c4516fae10
New evaluator and debugger derived from tree-walker class
John W. Eaton <jwe@octave.org>
parents:
8471
diff
changeset
|
3851 expr->set_print_flag (false); |
73c4516fae10
New evaluator and debugger derived from tree-walker class
John W. Eaton <jwe@octave.org>
parents:
8471
diff
changeset
|
3852 |
73c4516fae10
New evaluator and debugger derived from tree-walker class
John W. Eaton <jwe@octave.org>
parents:
8471
diff
changeset
|
3853 bool do_bind_ans = false; |
73c4516fae10
New evaluator and debugger derived from tree-walker class
John W. Eaton <jwe@octave.org>
parents:
8471
diff
changeset
|
3854 |
73c4516fae10
New evaluator and debugger derived from tree-walker class
John W. Eaton <jwe@octave.org>
parents:
8471
diff
changeset
|
3855 if (expr->is_identifier ()) |
73c4516fae10
New evaluator and debugger derived from tree-walker class
John W. Eaton <jwe@octave.org>
parents:
8471
diff
changeset
|
3856 { |
73c4516fae10
New evaluator and debugger derived from tree-walker class
John W. Eaton <jwe@octave.org>
parents:
8471
diff
changeset
|
3857 tree_identifier *id |
73c4516fae10
New evaluator and debugger derived from tree-walker class
John W. Eaton <jwe@octave.org>
parents:
8471
diff
changeset
|
3858 = dynamic_cast<tree_identifier *> (expr); |
73c4516fae10
New evaluator and debugger derived from tree-walker class
John W. Eaton <jwe@octave.org>
parents:
8471
diff
changeset
|
3859 |
73c4516fae10
New evaluator and debugger derived from tree-walker class
John W. Eaton <jwe@octave.org>
parents:
8471
diff
changeset
|
3860 do_bind_ans = (! id->is_variable ()); |
73c4516fae10
New evaluator and debugger derived from tree-walker class
John W. Eaton <jwe@octave.org>
parents:
8471
diff
changeset
|
3861 } |
73c4516fae10
New evaluator and debugger derived from tree-walker class
John W. Eaton <jwe@octave.org>
parents:
8471
diff
changeset
|
3862 else |
73c4516fae10
New evaluator and debugger derived from tree-walker class
John W. Eaton <jwe@octave.org>
parents:
8471
diff
changeset
|
3863 do_bind_ans = (! expr->is_assignment_expression ()); |
73c4516fae10
New evaluator and debugger derived from tree-walker class
John W. Eaton <jwe@octave.org>
parents:
8471
diff
changeset
|
3864 |
73c4516fae10
New evaluator and debugger derived from tree-walker class
John W. Eaton <jwe@octave.org>
parents:
8471
diff
changeset
|
3865 retval = expr->rvalue (nargout); |
73c4516fae10
New evaluator and debugger derived from tree-walker class
John W. Eaton <jwe@octave.org>
parents:
8471
diff
changeset
|
3866 |
73c4516fae10
New evaluator and debugger derived from tree-walker class
John W. Eaton <jwe@octave.org>
parents:
8471
diff
changeset
|
3867 if (do_bind_ans && ! (error_state || retval.empty ())) |
73c4516fae10
New evaluator and debugger derived from tree-walker class
John W. Eaton <jwe@octave.org>
parents:
8471
diff
changeset
|
3868 bind_ans (retval(0), expr->print_result ()); |
73c4516fae10
New evaluator and debugger derived from tree-walker class
John W. Eaton <jwe@octave.org>
parents:
8471
diff
changeset
|
3869 |
73c4516fae10
New evaluator and debugger derived from tree-walker class
John W. Eaton <jwe@octave.org>
parents:
8471
diff
changeset
|
3870 if (nargout == 0) |
73c4516fae10
New evaluator and debugger derived from tree-walker class
John W. Eaton <jwe@octave.org>
parents:
8471
diff
changeset
|
3871 retval = octave_value_list (); |
73c4516fae10
New evaluator and debugger derived from tree-walker class
John W. Eaton <jwe@octave.org>
parents:
8471
diff
changeset
|
3872 } |
73c4516fae10
New evaluator and debugger derived from tree-walker class
John W. Eaton <jwe@octave.org>
parents:
8471
diff
changeset
|
3873 else if (nargout == 0) |
8697
b227213a70c3
parse.y (eval_string): use the one true evaluator
John W. Eaton <jwe@octave.org>
parents:
8669
diff
changeset
|
3874 command_list->accept (*current_evaluator); |
8658
73c4516fae10
New evaluator and debugger derived from tree-walker class
John W. Eaton <jwe@octave.org>
parents:
8471
diff
changeset
|
3875 else |
73c4516fae10
New evaluator and debugger derived from tree-walker class
John W. Eaton <jwe@octave.org>
parents:
8471
diff
changeset
|
3876 error ("eval: invalid use of statement list"); |
73c4516fae10
New evaluator and debugger derived from tree-walker class
John W. Eaton <jwe@octave.org>
parents:
8471
diff
changeset
|
3877 |
73c4516fae10
New evaluator and debugger derived from tree-walker class
John W. Eaton <jwe@octave.org>
parents:
8471
diff
changeset
|
3878 delete command_list; |
73c4516fae10
New evaluator and debugger derived from tree-walker class
John W. Eaton <jwe@octave.org>
parents:
8471
diff
changeset
|
3879 |
73c4516fae10
New evaluator and debugger derived from tree-walker class
John W. Eaton <jwe@octave.org>
parents:
8471
diff
changeset
|
3880 command_list = 0; |
3883 | 3881 |
3882 if (error_state | |
4207 | 3883 || tree_return_command::returning |
3884 || tree_break_command::breaking | |
3885 || tree_continue_command::continuing) | |
3883 | 3886 break; |
3887 } | |
3888 else if (parser_end_of_input) | |
3877 | 3889 break; |
3883 | 3890 } |
3877 | 3891 } |
3892 while (parse_status == 0); | |
3021 | 3893 |
3894 unwind_protect::run_frame ("eval_string"); | |
3895 | |
3896 return retval; | |
3897 } | |
3898 | |
3899 octave_value | |
3523 | 3900 eval_string (const std::string& s, bool silent, int& parse_status) |
3021 | 3901 { |
3902 octave_value retval; | |
3903 | |
3904 octave_value_list tmp = eval_string (s, silent, parse_status, 1); | |
3905 | |
3906 if (! tmp.empty ()) | |
3907 retval = tmp(0); | |
3908 | |
3909 return retval; | |
3910 } | |
3911 | |
3912 static octave_value_list | |
3913 eval_string (const octave_value& arg, bool silent, int& parse_status, | |
3914 int nargout) | |
3915 { | |
3523 | 3916 std::string s = arg.string_value (); |
3021 | 3917 |
3918 if (error_state) | |
3919 { | |
3523 | 3920 error ("eval: expecting std::string argument"); |
4233 | 3921 return octave_value (-1); |
3021 | 3922 } |
3923 | |
3924 return eval_string (s, silent, parse_status, nargout); | |
3925 } | |
3926 | |
3927 DEFUN (eval, args, nargout, | |
3371 | 3928 "-*- texinfo -*-\n\ |
3929 @deftypefn {Built-in Function} {} eval (@var{try}, @var{catch})\n\ | |
3930 Parse the string @var{try} and evaluate it as if it were an Octave\n\ | |
6643 | 3931 program. If that fails, evaluate the optional string @var{catch}.\n\ |
4463 | 3932 The string @var{try} is evaluated in the current context,\n\ |
3933 so any results remain available after @code{eval} returns.\n\ | |
6643 | 3934 \n\ |
3935 The following example makes the variable @var{a} with the approximate\n\ | |
3936 value 3.1416 available.\n\ | |
3937 \n\ | |
3938 @example\n\ | |
3939 eval(\"a = acos(-1);\");\n\ | |
3940 @end example\n\ | |
3941 \n\ | |
3942 If an error occurs during the evaluation of @var{try} the @var{catch}\n\ | |
3943 string is evaluated, as the following example shows.\n\ | |
3944 \n\ | |
3945 @example\n\ | |
3946 eval ('error (\"This is a bad example\");',\n\ | |
8015
30629059b72d
Update the manual to reflect the changes in error output
sh@sh-laptop
parents:
8007
diff
changeset
|
3947 'printf (\"This error occurred:\\n%s\\n\", lasterr ());');\n\ |
7001 | 3948 @print{} This error occurred:\n\ |
8015
30629059b72d
Update the manual to reflect the changes in error output
sh@sh-laptop
parents:
8007
diff
changeset
|
3949 This is a bad example\n\ |
6643 | 3950 @end example\n\ |
3371 | 3951 @end deftypefn") |
3021 | 3952 { |
3953 octave_value_list retval; | |
3954 | |
3955 int nargin = args.length (); | |
3956 | |
3957 if (nargin > 0) | |
3958 { | |
3959 unwind_protect::begin_frame ("Feval"); | |
3960 | |
3961 if (nargin > 1) | |
3962 { | |
4699 | 3963 unwind_protect_int (buffer_error_messages); |
3964 buffer_error_messages++; | |
3021 | 3965 } |
3966 | |
3967 int parse_status = 0; | |
3968 | |
4463 | 3969 octave_value_list tmp = eval_string (args(0), nargout > 0, |
3970 parse_status, nargout); | |
3971 | |
3021 | 3972 if (nargin > 1 && (parse_status != 0 || error_state)) |
3973 { | |
3974 error_state = 0; | |
3975 | |
3976 // Set up for letting the user print any messages from | |
3977 // errors that occurred in the first part of this eval(). | |
3978 | |
4699 | 3979 buffer_error_messages--; |
3021 | 3980 |
8033
2ad5ba320b93
parse.y (Feval): Return value produced by evaluating CATCH string
John W. Eaton <jwe@octave.org>
parents:
8021
diff
changeset
|
3981 tmp = eval_string (args(1), nargout > 0, parse_status, nargout); |
2ad5ba320b93
parse.y (Feval): Return value produced by evaluating CATCH string
John W. Eaton <jwe@octave.org>
parents:
8021
diff
changeset
|
3982 |
2ad5ba320b93
parse.y (Feval): Return value produced by evaluating CATCH string
John W. Eaton <jwe@octave.org>
parents:
8021
diff
changeset
|
3983 if (nargout > 0) |
2ad5ba320b93
parse.y (Feval): Return value produced by evaluating CATCH string
John W. Eaton <jwe@octave.org>
parents:
8021
diff
changeset
|
3984 retval = tmp; |
3021 | 3985 } |
8033
2ad5ba320b93
parse.y (Feval): Return value produced by evaluating CATCH string
John W. Eaton <jwe@octave.org>
parents:
8021
diff
changeset
|
3986 else if (nargout > 0) |
2ad5ba320b93
parse.y (Feval): Return value produced by evaluating CATCH string
John W. Eaton <jwe@octave.org>
parents:
8021
diff
changeset
|
3987 retval = tmp; |
3021 | 3988 |
3989 unwind_protect::run_frame ("Feval"); | |
3990 } | |
3991 else | |
5823 | 3992 print_usage (); |
3021 | 3993 |
3994 return retval; | |
3995 } | |
3996 | |
7562
c827f5673321
move tests to individual source files
John W. Eaton <jwe@octave.org>
parents:
7351
diff
changeset
|
3997 /* |
c827f5673321
move tests to individual source files
John W. Eaton <jwe@octave.org>
parents:
7351
diff
changeset
|
3998 |
c827f5673321
move tests to individual source files
John W. Eaton <jwe@octave.org>
parents:
7351
diff
changeset
|
3999 %% test/octave.test/eval/eval-1.m |
c827f5673321
move tests to individual source files
John W. Eaton <jwe@octave.org>
parents:
7351
diff
changeset
|
4000 %!#test |
c827f5673321
move tests to individual source files
John W. Eaton <jwe@octave.org>
parents:
7351
diff
changeset
|
4001 %! x = 1; |
c827f5673321
move tests to individual source files
John W. Eaton <jwe@octave.org>
parents:
7351
diff
changeset
|
4002 %! assert(eval ("x"),1); |
c827f5673321
move tests to individual source files
John W. Eaton <jwe@octave.org>
parents:
7351
diff
changeset
|
4003 |
c827f5673321
move tests to individual source files
John W. Eaton <jwe@octave.org>
parents:
7351
diff
changeset
|
4004 %% test/octave.test/eval/eval-2.m |
c827f5673321
move tests to individual source files
John W. Eaton <jwe@octave.org>
parents:
7351
diff
changeset
|
4005 %!test |
c827f5673321
move tests to individual source files
John W. Eaton <jwe@octave.org>
parents:
7351
diff
changeset
|
4006 %! x = 1; |
c827f5673321
move tests to individual source files
John W. Eaton <jwe@octave.org>
parents:
7351
diff
changeset
|
4007 %! assert(eval ("x;")); |
c827f5673321
move tests to individual source files
John W. Eaton <jwe@octave.org>
parents:
7351
diff
changeset
|
4008 |
c827f5673321
move tests to individual source files
John W. Eaton <jwe@octave.org>
parents:
7351
diff
changeset
|
4009 %% test/octave.test/eval/eval-3.m |
c827f5673321
move tests to individual source files
John W. Eaton <jwe@octave.org>
parents:
7351
diff
changeset
|
4010 %!test |
c827f5673321
move tests to individual source files
John W. Eaton <jwe@octave.org>
parents:
7351
diff
changeset
|
4011 %! x = 1; |
c827f5673321
move tests to individual source files
John W. Eaton <jwe@octave.org>
parents:
7351
diff
changeset
|
4012 %! assert(eval ("x;"),1); |
c827f5673321
move tests to individual source files
John W. Eaton <jwe@octave.org>
parents:
7351
diff
changeset
|
4013 |
c827f5673321
move tests to individual source files
John W. Eaton <jwe@octave.org>
parents:
7351
diff
changeset
|
4014 %% FIXME |
c827f5673321
move tests to individual source files
John W. Eaton <jwe@octave.org>
parents:
7351
diff
changeset
|
4015 %% Disable this test as adding the ";" is redundant with eval-1 and |
c827f5673321
move tests to individual source files
John W. Eaton <jwe@octave.org>
parents:
7351
diff
changeset
|
4016 %% in any case is a syntax error with assert |
c827f5673321
move tests to individual source files
John W. Eaton <jwe@octave.org>
parents:
7351
diff
changeset
|
4017 %% test/octave.test/eval/eval-4.m |
c827f5673321
move tests to individual source files
John W. Eaton <jwe@octave.org>
parents:
7351
diff
changeset
|
4018 %!#test |
c827f5673321
move tests to individual source files
John W. Eaton <jwe@octave.org>
parents:
7351
diff
changeset
|
4019 %! x = 1; |
c827f5673321
move tests to individual source files
John W. Eaton <jwe@octave.org>
parents:
7351
diff
changeset
|
4020 %! assert(eval ("x");,1); |
c827f5673321
move tests to individual source files
John W. Eaton <jwe@octave.org>
parents:
7351
diff
changeset
|
4021 |
c827f5673321
move tests to individual source files
John W. Eaton <jwe@octave.org>
parents:
7351
diff
changeset
|
4022 %% test/octave.test/eval/eval-5.m |
c827f5673321
move tests to individual source files
John W. Eaton <jwe@octave.org>
parents:
7351
diff
changeset
|
4023 %!test |
c827f5673321
move tests to individual source files
John W. Eaton <jwe@octave.org>
parents:
7351
diff
changeset
|
4024 %! eval ("flipud = 2;"); |
c827f5673321
move tests to individual source files
John W. Eaton <jwe@octave.org>
parents:
7351
diff
changeset
|
4025 %! assert(flipud,2); |
c827f5673321
move tests to individual source files
John W. Eaton <jwe@octave.org>
parents:
7351
diff
changeset
|
4026 |
c827f5673321
move tests to individual source files
John W. Eaton <jwe@octave.org>
parents:
7351
diff
changeset
|
4027 %% test/octave.test/eval/eval-6.m |
c827f5673321
move tests to individual source files
John W. Eaton <jwe@octave.org>
parents:
7351
diff
changeset
|
4028 %!function y = f () |
c827f5673321
move tests to individual source files
John W. Eaton <jwe@octave.org>
parents:
7351
diff
changeset
|
4029 %! eval ("flipud = 2;"); |
c827f5673321
move tests to individual source files
John W. Eaton <jwe@octave.org>
parents:
7351
diff
changeset
|
4030 %! y = flipud; |
c827f5673321
move tests to individual source files
John W. Eaton <jwe@octave.org>
parents:
7351
diff
changeset
|
4031 %!test |
c827f5673321
move tests to individual source files
John W. Eaton <jwe@octave.org>
parents:
7351
diff
changeset
|
4032 %! assert(f,2); |
c827f5673321
move tests to individual source files
John W. Eaton <jwe@octave.org>
parents:
7351
diff
changeset
|
4033 |
c827f5673321
move tests to individual source files
John W. Eaton <jwe@octave.org>
parents:
7351
diff
changeset
|
4034 %% test/octave.test/eval/eval-7.m |
c827f5673321
move tests to individual source files
John W. Eaton <jwe@octave.org>
parents:
7351
diff
changeset
|
4035 %!#test |
c827f5673321
move tests to individual source files
John W. Eaton <jwe@octave.org>
parents:
7351
diff
changeset
|
4036 %! eval ("x = 1"); |
c827f5673321
move tests to individual source files
John W. Eaton <jwe@octave.org>
parents:
7351
diff
changeset
|
4037 %! assert(x,1); |
c827f5673321
move tests to individual source files
John W. Eaton <jwe@octave.org>
parents:
7351
diff
changeset
|
4038 |
c827f5673321
move tests to individual source files
John W. Eaton <jwe@octave.org>
parents:
7351
diff
changeset
|
4039 %% test/octave.test/eval/eval-8.m |
c827f5673321
move tests to individual source files
John W. Eaton <jwe@octave.org>
parents:
7351
diff
changeset
|
4040 %!test |
c827f5673321
move tests to individual source files
John W. Eaton <jwe@octave.org>
parents:
7351
diff
changeset
|
4041 %! eval ("x = 1;") |
c827f5673321
move tests to individual source files
John W. Eaton <jwe@octave.org>
parents:
7351
diff
changeset
|
4042 %! assert(x,1); |
c827f5673321
move tests to individual source files
John W. Eaton <jwe@octave.org>
parents:
7351
diff
changeset
|
4043 |
c827f5673321
move tests to individual source files
John W. Eaton <jwe@octave.org>
parents:
7351
diff
changeset
|
4044 %% test/octave.test/eval/eval-9.m |
c827f5673321
move tests to individual source files
John W. Eaton <jwe@octave.org>
parents:
7351
diff
changeset
|
4045 %!test |
c827f5673321
move tests to individual source files
John W. Eaton <jwe@octave.org>
parents:
7351
diff
changeset
|
4046 %! eval ("x = 1;"); |
c827f5673321
move tests to individual source files
John W. Eaton <jwe@octave.org>
parents:
7351
diff
changeset
|
4047 %! assert(x,1); |
c827f5673321
move tests to individual source files
John W. Eaton <jwe@octave.org>
parents:
7351
diff
changeset
|
4048 |
c827f5673321
move tests to individual source files
John W. Eaton <jwe@octave.org>
parents:
7351
diff
changeset
|
4049 %% test/octave.test/eval/eval-10.m |
c827f5673321
move tests to individual source files
John W. Eaton <jwe@octave.org>
parents:
7351
diff
changeset
|
4050 %!#test |
c827f5673321
move tests to individual source files
John W. Eaton <jwe@octave.org>
parents:
7351
diff
changeset
|
4051 %! eval ("x = 1") |
c827f5673321
move tests to individual source files
John W. Eaton <jwe@octave.org>
parents:
7351
diff
changeset
|
4052 %! assert(x,1); |
c827f5673321
move tests to individual source files
John W. Eaton <jwe@octave.org>
parents:
7351
diff
changeset
|
4053 |
c827f5673321
move tests to individual source files
John W. Eaton <jwe@octave.org>
parents:
7351
diff
changeset
|
4054 %% test/octave.test/eval/eval-11.m |
c827f5673321
move tests to individual source files
John W. Eaton <jwe@octave.org>
parents:
7351
diff
changeset
|
4055 %!test |
c827f5673321
move tests to individual source files
John W. Eaton <jwe@octave.org>
parents:
7351
diff
changeset
|
4056 %! x = 1; |
c827f5673321
move tests to individual source files
John W. Eaton <jwe@octave.org>
parents:
7351
diff
changeset
|
4057 %! y = eval ("x"); |
c827f5673321
move tests to individual source files
John W. Eaton <jwe@octave.org>
parents:
7351
diff
changeset
|
4058 %! assert(y,1); |
c827f5673321
move tests to individual source files
John W. Eaton <jwe@octave.org>
parents:
7351
diff
changeset
|
4059 |
c827f5673321
move tests to individual source files
John W. Eaton <jwe@octave.org>
parents:
7351
diff
changeset
|
4060 %% test/octave.test/eval/eval-12.m |
c827f5673321
move tests to individual source files
John W. Eaton <jwe@octave.org>
parents:
7351
diff
changeset
|
4061 %!test |
c827f5673321
move tests to individual source files
John W. Eaton <jwe@octave.org>
parents:
7351
diff
changeset
|
4062 %! x = 1; |
c827f5673321
move tests to individual source files
John W. Eaton <jwe@octave.org>
parents:
7351
diff
changeset
|
4063 %! y = eval ("x;"); |
c827f5673321
move tests to individual source files
John W. Eaton <jwe@octave.org>
parents:
7351
diff
changeset
|
4064 %! assert(y,1); |
c827f5673321
move tests to individual source files
John W. Eaton <jwe@octave.org>
parents:
7351
diff
changeset
|
4065 |
c827f5673321
move tests to individual source files
John W. Eaton <jwe@octave.org>
parents:
7351
diff
changeset
|
4066 %% test/octave.test/eval/eval-13.m |
c827f5673321
move tests to individual source files
John W. Eaton <jwe@octave.org>
parents:
7351
diff
changeset
|
4067 %!test |
c827f5673321
move tests to individual source files
John W. Eaton <jwe@octave.org>
parents:
7351
diff
changeset
|
4068 %! x = 1; |
c827f5673321
move tests to individual source files
John W. Eaton <jwe@octave.org>
parents:
7351
diff
changeset
|
4069 %! y = eval ("x;"); |
c827f5673321
move tests to individual source files
John W. Eaton <jwe@octave.org>
parents:
7351
diff
changeset
|
4070 %! assert(y,1); |
c827f5673321
move tests to individual source files
John W. Eaton <jwe@octave.org>
parents:
7351
diff
changeset
|
4071 |
c827f5673321
move tests to individual source files
John W. Eaton <jwe@octave.org>
parents:
7351
diff
changeset
|
4072 %% test/octave.test/eval/eval-14.m |
c827f5673321
move tests to individual source files
John W. Eaton <jwe@octave.org>
parents:
7351
diff
changeset
|
4073 %!test |
c827f5673321
move tests to individual source files
John W. Eaton <jwe@octave.org>
parents:
7351
diff
changeset
|
4074 %! x = 1; |
c827f5673321
move tests to individual source files
John W. Eaton <jwe@octave.org>
parents:
7351
diff
changeset
|
4075 %! y = eval ("x"); |
c827f5673321
move tests to individual source files
John W. Eaton <jwe@octave.org>
parents:
7351
diff
changeset
|
4076 %! assert(y,1); |
c827f5673321
move tests to individual source files
John W. Eaton <jwe@octave.org>
parents:
7351
diff
changeset
|
4077 |
c827f5673321
move tests to individual source files
John W. Eaton <jwe@octave.org>
parents:
7351
diff
changeset
|
4078 */ |
c827f5673321
move tests to individual source files
John W. Eaton <jwe@octave.org>
parents:
7351
diff
changeset
|
4079 |
4661 | 4080 DEFUN (assignin, args, , |
4297 | 4081 "-*- texinfo -*-\n\ |
4082 @deftypefn {Built-in Function} {} assignin (@var{context}, @var{varname}, @var{value})\n\ | |
4083 Assign @var{value} to @var{varname} in context @var{context}, which\n\ | |
4084 may be either @code{\"base\"} or @code{\"caller\"}.\n\ | |
4085 @end deftypefn") | |
4086 { | |
4087 octave_value_list retval; | |
4088 | |
4089 int nargin = args.length (); | |
4090 | |
4091 if (nargin == 3) | |
4092 { | |
4093 std::string context = args(0).string_value (); | |
4094 | |
4095 if (! error_state) | |
4096 { | |
4097 if (context == "caller") | |
7901 | 4098 octave_call_stack::goto_caller_frame (); |
4297 | 4099 else if (context == "base") |
7901 | 4100 octave_call_stack::goto_base_frame (); |
4297 | 4101 else |
4102 error ("assignin: context must be \"caller\" or \"base\""); | |
4103 | |
4104 if (! error_state) | |
4105 { | |
7901 | 4106 unwind_protect::add (octave_call_stack::unwind_pop); |
4107 | |
4297 | 4108 std::string nm = args(1).string_value (); |
4109 | |
4110 if (! error_state) | |
4111 { | |
4112 if (valid_identifier (nm)) | |
8064
4f1ebb704545
fix invalid scope use in assignin
Jaroslav Hajek <highegg@gmail.com>
parents:
8033
diff
changeset
|
4113 symbol_table::varref (nm) = args(2); |
4297 | 4114 else |
4115 error ("assignin: invalid variable name"); | |
4116 } | |
4117 else | |
4118 error ("assignin: expecting variable name as second argument"); | |
4119 } | |
4120 } | |
4121 else | |
4122 error ("assignin: expecting string as first argument"); | |
4123 } | |
4124 else | |
5823 | 4125 print_usage (); |
4297 | 4126 |
4127 return retval; | |
4128 } | |
4129 | |
4245 | 4130 DEFUN (evalin, args, nargout, |
4131 "-*- texinfo -*-\n\ | |
4132 @deftypefn {Built-in Function} {} evalin (@var{context}, @var{try}, @var{catch})\n\ | |
4133 Like @code{eval}, except that the expressions are evaluated in the\n\ | |
4134 context @var{context}, which may be either @code{\"caller\"} or\n\ | |
4246 | 4135 @code{\"base\"}.\n\ |
4245 | 4136 @end deftypefn") |
4137 { | |
4138 octave_value_list retval; | |
4139 | |
4140 int nargin = args.length (); | |
4141 | |
4142 if (nargin > 1) | |
4143 { | |
4144 std::string context = args(0).string_value (); | |
4145 | |
4146 if (! error_state) | |
4147 { | |
4148 unwind_protect::begin_frame ("Fevalin"); | |
4149 | |
4150 if (context == "caller") | |
7901 | 4151 octave_call_stack::goto_caller_frame (); |
4245 | 4152 else if (context == "base") |
7901 | 4153 octave_call_stack::goto_base_frame (); |
4245 | 4154 else |
4155 error ("evalin: context must be \"caller\" or \"base\""); | |
4156 | |
4297 | 4157 if (! error_state) |
4245 | 4158 { |
7901 | 4159 unwind_protect::add (octave_call_stack::unwind_pop); |
7336 | 4160 |
4297 | 4161 if (nargin > 2) |
4162 { | |
4699 | 4163 unwind_protect_int (buffer_error_messages); |
4164 buffer_error_messages++; | |
4297 | 4165 } |
4166 | |
4167 int parse_status = 0; | |
4168 | |
4463 | 4169 octave_value_list tmp = eval_string (args(1), nargout > 0, |
4170 parse_status, nargout); | |
4171 | |
4172 if (nargout > 0) | |
4173 retval = tmp; | |
4297 | 4174 |
4175 if (nargin > 2 && (parse_status != 0 || error_state)) | |
4176 { | |
4177 error_state = 0; | |
4178 | |
4179 // Set up for letting the user print any messages from | |
4180 // errors that occurred in the first part of this eval(). | |
4181 | |
4699 | 4182 buffer_error_messages--; |
4297 | 4183 |
4184 eval_string (args(2), 0, parse_status, nargout); | |
4185 | |
4186 retval = octave_value_list (); | |
4187 } | |
4245 | 4188 } |
4189 | |
4190 unwind_protect::run_frame ("Fevalin"); | |
4191 } | |
4192 else | |
4193 error ("evalin: expecting string as first argument"); | |
4194 } | |
4195 else | |
5823 | 4196 print_usage (); |
4245 | 4197 |
4198 return retval; | |
4199 } | |
4200 | |
8311
7124bffc89c7
parse.y (F__parser_debug_flag__): New function.
John W. Eaton <jwe@octave.org>
parents:
8283
diff
changeset
|
4201 DEFUN (__parser_debug_flag__, args, nargout, |
7124bffc89c7
parse.y (F__parser_debug_flag__): New function.
John W. Eaton <jwe@octave.org>
parents:
8283
diff
changeset
|
4202 "Undocumented internal function.") |
7124bffc89c7
parse.y (F__parser_debug_flag__): New function.
John W. Eaton <jwe@octave.org>
parents:
8283
diff
changeset
|
4203 { |
7124bffc89c7
parse.y (F__parser_debug_flag__): New function.
John W. Eaton <jwe@octave.org>
parents:
8283
diff
changeset
|
4204 octave_value retval; |
7124bffc89c7
parse.y (F__parser_debug_flag__): New function.
John W. Eaton <jwe@octave.org>
parents:
8283
diff
changeset
|
4205 |
7124bffc89c7
parse.y (F__parser_debug_flag__): New function.
John W. Eaton <jwe@octave.org>
parents:
8283
diff
changeset
|
4206 bool debug_flag = octave_debug; |
7124bffc89c7
parse.y (F__parser_debug_flag__): New function.
John W. Eaton <jwe@octave.org>
parents:
8283
diff
changeset
|
4207 |
7124bffc89c7
parse.y (F__parser_debug_flag__): New function.
John W. Eaton <jwe@octave.org>
parents:
8283
diff
changeset
|
4208 retval = set_internal_variable (debug_flag, args, nargout, |
7124bffc89c7
parse.y (F__parser_debug_flag__): New function.
John W. Eaton <jwe@octave.org>
parents:
8283
diff
changeset
|
4209 "__parser_debug_flag__"); |
7124bffc89c7
parse.y (F__parser_debug_flag__): New function.
John W. Eaton <jwe@octave.org>
parents:
8283
diff
changeset
|
4210 |
7124bffc89c7
parse.y (F__parser_debug_flag__): New function.
John W. Eaton <jwe@octave.org>
parents:
8283
diff
changeset
|
4211 octave_debug = debug_flag; |
7124bffc89c7
parse.y (F__parser_debug_flag__): New function.
John W. Eaton <jwe@octave.org>
parents:
8283
diff
changeset
|
4212 |
7124bffc89c7
parse.y (F__parser_debug_flag__): New function.
John W. Eaton <jwe@octave.org>
parents:
8283
diff
changeset
|
4213 return retval; |
7124bffc89c7
parse.y (F__parser_debug_flag__): New function.
John W. Eaton <jwe@octave.org>
parents:
8283
diff
changeset
|
4214 } |
7124bffc89c7
parse.y (F__parser_debug_flag__): New function.
John W. Eaton <jwe@octave.org>
parents:
8283
diff
changeset
|
4215 |
1994 | 4216 /* |
4217 ;;; Local Variables: *** | |
4218 ;;; mode: text *** | |
4219 ;;; End: *** | |
4220 */ |