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