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