Mercurial > octave
annotate src/oct-parse.yy @ 15037:56b8eb7c9c04 classdef
improvements in parsing classdef
* liboctave/base-list.h (octave_base_list::octave_base_list (void),
octave_base_list::octave_base_list (const std::list<elt_type>&),
octave_base_list::operator = (const octave_base_list&),
octave_base_list::~octave_base_list (void)):
Now public.
* pt-classdef.h, pt-classdef.cc: New files.
* src/Makefile.am (PT_INCLUDES): Add pt-classdef.h to the list.
(PT_SRC): Add pt-classdef.cc to the list.
* pt-all.h: Include pt-classdef.h.
* ov.cc: Include ov-classdef.h.
* ov-classdef.cc: Include pt-classdef.h.
(cdef_class:make_meta_class): New method.
(F__meta_get_class__): Delete.
(F__superclass_reference__, F__meta_class_query__):
New functions.
* pt-id.h: Include oct-lvalue.h.
* pt-walk.h (tree_walker::visit_classdef (tree_classdef&),
tree_walker::visit_classdef_attribute (tree_classdef_attribute&),
tree_walker::visit_classdef_attribute_list (tree_classdef_attribute_list&),
tree_walker::visit_classdef_superclass (tree_classdef_superclass&),
tree_walker::visit_classdef_superclass_list (tree_classdef_superclass_list&),
tree_walker::visit_classdef_property (tree_classdef_property&),
tree_walker::visit_classdef_property_list (tree_classdef_property_list&),
tree_walker::visit_classdef_properties_block (tree_classdef_properties_block&),
tree_walker::visit_classdef_methods_list (tree_classdef_methods_list&),
tree_walker::visit_classdef_methods_block (tree_classdef_methods_block&),
tree_walker::visit_classdef_event (tree_classdef_event&),
tree_walker::visit_classdef_events_list (tree_classdef_events_list&),
tree_walker::visit_classdef_events_block (tree_classdef_events_block&),
tree_walker::visit_classdef_enum (tree_classdef_enum&),
tree_walker::visit_classdef_enum_list (tree_classdef_enum_list&),
tree_walker::visit_classdef_enum_block (tree_classdef_enum_block&),
tree_walker::visit_classdef_body (tree_classdef_body&)):
New virtual functions.
* token.h, token.cc (token::sc::mr, token::sc::cr, token::sc::pr,
token::mc::mr, token::mc::pr): Delete.
(token::sc::method_name, token::sc::package_name, token::sc::class_name,
token::mc::package_name, token::mc::class_name): New member variables.
(token::method_rec, token::class_rec, token::package_rec,
token::meta_class_rec, token::meta_package_rec): Delete.
(token::superclass_method_name, token::superclass_package_name,
token::superclass_class_name, token::meta_package_name,
token::meta_class_name): New methods.
(token::token (symbol_table::symbol_record*, int, int),
token::token (symbol_table::symbol_record*, symbol_table::symbol_record*, int, int),
token::token (symbol_table::symbol_record*, symbol_table::symbol_record*, symbol_table::symbol_record*, int, int)):
Delete.
(token::token (const std::string&, const std::string&, int, int),
token::token (const std::string&, const std::string&, const std::string&, int, int)):
New constructors.
(token::scls_rec_token, token::meta_rec_token): Delete enum values.
(token::scls_name_token, token::meta_rec_token): New enum values.
(token::~token): Delete sc and mc struct memebers.
* lex.ll, lex.h (lexical_feedback::parsing_classdef_get_method,
lexical_feedback::parsing_classdef_set_method)): New data members.
(lexical_feedback::lexical_feedback, lexical_feedback::init):
Initialize new data members.
(prep_lexer_for_classdef_file): New function.
(CLASSDEF_FILE_BEGIN): New exclusive start state.
(handle_superclass_identifier, handle_meta_identifier): Split
identifier here and create token with character strings.
(display_token): Handle CLASSDEF_FILE.
(display_state): Handle CLASSDEF_FILE_BEGIN.
* oct-parse.yy: Include ov-classdef.h and pt-funcall.h.
(classdef_object): New static variable.
(make_superclass_ref, make_meta_class_query, make_classdef,
make_classdef_properties_block, make_classdef_methods_block,
make_classdef_events_block, make_classdef_enum_block)): New functions.
(dummy_type): Delete unused nonterminal type.
(tok_type, tree_funcall_type, tree_function_def_type,
tree_classdef_type, tree_classdef_attribute_type,
tree_classdef_attribute_list_type, tree_classdef_superclass_type,
tree_classdef_superclass_list_type, tree_classdef_body_type,
tree_classdef_property_type, tree_classdef_property_list_type,
tree_classdef_properties_block_type, tree_classdef_methods_list_type,
tree_classdef_methods_block_type, tree_classdef_event_type,
tree_classdef_events_list_type, tree_classdef_events_block_type,
tree_classdef_enum_type, tree_classdef_enum_list_type,
tree_classdef_enum_block_type):
New types for nonterminals.
(CLASSDEF): Declare to have a tok_val token value.
(CLASSDEF_FILE): New token.
(classdef_end, properties_beg, methods_beg, events_beg, enum_beg,
classdef1): Delete nonterminals.
(property_list): Rename from properties_list.
(attr, class_event, class_enum, class_property, property_list,
properties_block, methods_list, methods_block, opt_attr_list,
attr_list, events_list, events_blcok, enum_list, enum_block,
class_body, classdef): Declare with specific types. Create parse tree
objects for these nonterminals.
(classdef_file): New nonterminal.
(parse_fcn_file): Handle classdef files. Don't treat classdef files
as scripts.
(command): Don't handle classdef here.
(input): Accept classdef_file here.
(fcn_name): If GET, set lexer_flags.parsing_classdef_get_method.
If SET, set lexer_flags.parsing_classdef_set_method.
author | John W. Eaton <jwe@octave.org> |
---|---|
date | Fri, 27 Jul 2012 17:10:25 -0400 |
parents | 460a3c6d8bf1 |
children |
rev | line source |
---|---|
1829 | 1 /* |
1 | 2 |
14138
72c96de7a403
maint: update copyright notices for 2012
John W. Eaton <jwe@octave.org>
parents:
14084
diff
changeset
|
3 Copyright (C) 1993-2012 John W. Eaton |
9474
25ed2d6aacf6
Parse nested functions more accurately.
David Grundberg <individ@acc.umu.se>
parents:
9471
diff
changeset
|
4 Copyright (C) 2009 David Grundberg |
11523 | 5 Copyright (C) 2009-2010 VZLU Prague |
1 | 6 |
7 This file is part of Octave. | |
8 | |
9 Octave is free software; you can redistribute it and/or modify it | |
10 under the terms of the GNU General Public License as published by the | |
7016 | 11 Free Software Foundation; either version 3 of the License, or (at your |
12 option) any later version. | |
1 | 13 |
14 Octave is distributed in the hope that it will be useful, but WITHOUT | |
15 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | |
16 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License | |
17 for more details. | |
18 | |
19 You should have received a copy of the GNU General Public License | |
7016 | 20 along with Octave; see the file COPYING. If not, see |
21 <http://www.gnu.org/licenses/>. | |
1 | 22 |
23 */ | |
24 | |
25 // Parser for Octave. | |
26 | |
767 | 27 // C decarations. |
28 | |
1 | 29 %{ |
30 #define YYDEBUG 1 | |
31 | |
240 | 32 #ifdef HAVE_CONFIG_H |
1229 | 33 #include <config.h> |
240 | 34 #endif |
35 | |
3178 | 36 #include <cassert> |
10463
bbe99b2a5ba7
undo recent gnulib-related changes
John W. Eaton <jwe@octave.org>
parents:
10447
diff
changeset
|
37 #include <cstdio> |
bbe99b2a5ba7
undo recent gnulib-related changes
John W. Eaton <jwe@octave.org>
parents:
10447
diff
changeset
|
38 #include <cstdlib> |
2427 | 39 |
8950
d865363208d6
include <iosfwd> instead of <iostream> in header files
John W. Eaton <jwe@octave.org>
parents:
8920
diff
changeset
|
40 #include <iostream> |
5484 | 41 #include <map> |
5765 | 42 #include <sstream> |
5484 | 43 |
3928 | 44 #include "Cell.h" |
1 | 45 #include "Matrix.h" |
3021 | 46 #include "cmd-edit.h" |
47 #include "cmd-hist.h" | |
48 #include "file-ops.h" | |
49 #include "file-stat.h" | |
4243 | 50 #include "oct-env.h" |
3712 | 51 #include "oct-time.h" |
4171 | 52 #include "quit.h" |
1 | 53 |
3665 | 54 #include "comment-list.h" |
4243 | 55 #include "defaults.h" |
2166 | 56 #include "defun.h" |
4243 | 57 #include "dirfns.h" |
3021 | 58 #include "dynamic-ld.h" |
1351 | 59 #include "error.h" |
60 #include "input.h" | |
61 #include "lex.h" | |
5832 | 62 #include "load-path.h" |
1743 | 63 #include "oct-hist.h" |
5626 | 64 #include "oct-map.h" |
15037
56b8eb7c9c04
improvements in parsing classdef
John W. Eaton <jwe@octave.org>
parents:
14846
diff
changeset
|
65 #include "ov-classdef.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" | |
14329
8d1ae996c122
also save and restore symbol table context in parser (bug #35448)
John W. Eaton <jwe@octave.org>
parents:
14294
diff
changeset
|
72 #include "parse-private.h" |
2987 | 73 #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
|
74 #include "pt-eval.h" |
15037
56b8eb7c9c04
improvements in parsing classdef
John W. Eaton <jwe@octave.org>
parents:
14846
diff
changeset
|
75 #include "pt-funcall.h" |
1351 | 76 #include "symtab.h" |
77 #include "token.h" | |
3021 | 78 #include "unwind-prot.h" |
1 | 79 #include "utils.h" |
1351 | 80 #include "variables.h" |
1 | 81 |
10426
4db7beace28e
oct-parse.yy, lex.ll: use symbols via gnulib namespace
John W. Eaton <jwe@octave.org>
parents:
10411
diff
changeset
|
82 #if defined (GNULIB_NAMESPACE) |
4db7beace28e
oct-parse.yy, lex.ll: use symbols via gnulib namespace
John W. Eaton <jwe@octave.org>
parents:
10411
diff
changeset
|
83 // Calls to the following functions appear in the generated output from |
4db7beace28e
oct-parse.yy, lex.ll: use symbols via gnulib namespace
John W. Eaton <jwe@octave.org>
parents:
10411
diff
changeset
|
84 // Bison without the namespace tag. Redefine them so we will use them |
4db7beace28e
oct-parse.yy, lex.ll: use symbols via gnulib namespace
John W. Eaton <jwe@octave.org>
parents:
10411
diff
changeset
|
85 // via the gnulib namespace. |
4db7beace28e
oct-parse.yy, lex.ll: use symbols via gnulib namespace
John W. Eaton <jwe@octave.org>
parents:
10411
diff
changeset
|
86 #define fclose GNULIB_NAMESPACE::fclose |
4db7beace28e
oct-parse.yy, lex.ll: use symbols via gnulib namespace
John W. Eaton <jwe@octave.org>
parents:
10411
diff
changeset
|
87 #define fprintf GNULIB_NAMESPACE::fprintf |
4db7beace28e
oct-parse.yy, lex.ll: use symbols via gnulib namespace
John W. Eaton <jwe@octave.org>
parents:
10411
diff
changeset
|
88 #define malloc GNULIB_NAMESPACE::malloc |
4db7beace28e
oct-parse.yy, lex.ll: use symbols via gnulib namespace
John W. Eaton <jwe@octave.org>
parents:
10411
diff
changeset
|
89 #endif |
4db7beace28e
oct-parse.yy, lex.ll: use symbols via gnulib namespace
John W. Eaton <jwe@octave.org>
parents:
10411
diff
changeset
|
90 |
1 | 91 // The current input line number. |
8447
adab48231a03
make input_line_number work again
John W. Eaton <jwe@octave.org>
parents:
8311
diff
changeset
|
92 int input_line_number = 1; |
1 | 93 |
94 // The column of the current token. | |
143 | 95 int current_input_column = 1; |
1 | 96 |
338 | 97 // Buffer for help text snagged from function files. |
4426 | 98 std::stack<std::string> help_buf; |
1 | 99 |
3665 | 100 // Buffer for comments appearing before a function statement. |
101 static std::string fcn_comment_header; | |
102 | |
3021 | 103 // TRUE means we are using readline. |
104 // (--no-line-editing) | |
105 bool line_editing = true; | |
106 | |
107 // TRUE means we printed messages about reading startup files. | |
108 bool reading_startup_message_printed = false; | |
109 | |
110 // TRUE means input is coming from startup file. | |
111 bool input_from_startup_file = false; | |
112 | |
9474
25ed2d6aacf6
Parse nested functions more accurately.
David Grundberg <individ@acc.umu.se>
parents:
9471
diff
changeset
|
113 // = 0 currently outside any function. |
25ed2d6aacf6
Parse nested functions more accurately.
David Grundberg <individ@acc.umu.se>
parents:
9471
diff
changeset
|
114 // = 1 inside the primary function or a subfunction. |
25ed2d6aacf6
Parse nested functions more accurately.
David Grundberg <individ@acc.umu.se>
parents:
9471
diff
changeset
|
115 // > 1 means we are looking at a function definition that seems to be |
25ed2d6aacf6
Parse nested functions more accurately.
David Grundberg <individ@acc.umu.se>
parents:
9471
diff
changeset
|
116 // inside a function. Note that the function still might not be a |
25ed2d6aacf6
Parse nested functions more accurately.
David Grundberg <individ@acc.umu.se>
parents:
9471
diff
changeset
|
117 // nested function. |
25ed2d6aacf6
Parse nested functions more accurately.
David Grundberg <individ@acc.umu.se>
parents:
9471
diff
changeset
|
118 static int current_function_depth = 0; |
25ed2d6aacf6
Parse nested functions more accurately.
David Grundberg <individ@acc.umu.se>
parents:
9471
diff
changeset
|
119 |
14544
be18c9e359bf
Nested function support (bug #35772)
Max Brister <max@2bass.com>
parents:
14533
diff
changeset
|
120 // A stack holding the nested function scopes being parsed. |
be18c9e359bf
Nested function support (bug #35772)
Max Brister <max@2bass.com>
parents:
14533
diff
changeset
|
121 // We don't use std::stack, because we want the clear method. Also, we |
be18c9e359bf
Nested function support (bug #35772)
Max Brister <max@2bass.com>
parents:
14533
diff
changeset
|
122 // must access one from the top |
be18c9e359bf
Nested function support (bug #35772)
Max Brister <max@2bass.com>
parents:
14533
diff
changeset
|
123 static std::vector<symbol_table::scope_id> function_scopes; |
be18c9e359bf
Nested function support (bug #35772)
Max Brister <max@2bass.com>
parents:
14533
diff
changeset
|
124 |
9474
25ed2d6aacf6
Parse nested functions more accurately.
David Grundberg <individ@acc.umu.se>
parents:
9471
diff
changeset
|
125 // Maximum function depth detected. Just here to determine whether |
25ed2d6aacf6
Parse nested functions more accurately.
David Grundberg <individ@acc.umu.se>
parents:
9471
diff
changeset
|
126 // we have nested functions or just implicitly ended subfunctions. |
25ed2d6aacf6
Parse nested functions more accurately.
David Grundberg <individ@acc.umu.se>
parents:
9471
diff
changeset
|
127 static int max_function_depth = 0; |
25ed2d6aacf6
Parse nested functions more accurately.
David Grundberg <individ@acc.umu.se>
parents:
9471
diff
changeset
|
128 |
25ed2d6aacf6
Parse nested functions more accurately.
David Grundberg <individ@acc.umu.se>
parents:
9471
diff
changeset
|
129 // FALSE if we are still at the primary function. Subfunctions can |
25ed2d6aacf6
Parse nested functions more accurately.
David Grundberg <individ@acc.umu.se>
parents:
9471
diff
changeset
|
130 // only be declared inside function files. |
25ed2d6aacf6
Parse nested functions more accurately.
David Grundberg <individ@acc.umu.se>
parents:
9471
diff
changeset
|
131 static int parsing_subfunctions = false; |
25ed2d6aacf6
Parse nested functions more accurately.
David Grundberg <individ@acc.umu.se>
parents:
9471
diff
changeset
|
132 |
25ed2d6aacf6
Parse nested functions more accurately.
David Grundberg <individ@acc.umu.se>
parents:
9471
diff
changeset
|
133 // Have we found an explicit end to a function? |
25ed2d6aacf6
Parse nested functions more accurately.
David Grundberg <individ@acc.umu.se>
parents:
9471
diff
changeset
|
134 static bool endfunction_found = false; |
4238 | 135 |
3903 | 136 // Keep track of symbol table information when parsing functions. |
14329
8d1ae996c122
also save and restore symbol table context in parser (bug #35448)
John W. Eaton <jwe@octave.org>
parents:
14294
diff
changeset
|
137 symtab_context parser_symtab_context; |
4238 | 138 |
7336 | 139 // Name of the current class when we are parsing class methods or |
140 // constructors. | |
141 std::string current_class_name; | |
142 | |
5484 | 143 // TRUE means we are in the process of autoloading a function. |
144 static bool autoloading = false; | |
145 | |
6323 | 146 // TRUE means the current function file was found in a relative path |
147 // element. | |
148 static bool fcn_file_from_relative_lookup = false; | |
149 | |
9474
25ed2d6aacf6
Parse nested functions more accurately.
David Grundberg <individ@acc.umu.se>
parents:
9471
diff
changeset
|
150 // Pointer to the primary user function or user script function. |
25ed2d6aacf6
Parse nested functions more accurately.
David Grundberg <individ@acc.umu.se>
parents:
9471
diff
changeset
|
151 static octave_function *primary_fcn_ptr = 0; |
25ed2d6aacf6
Parse nested functions more accurately.
David Grundberg <individ@acc.umu.se>
parents:
9471
diff
changeset
|
152 |
25ed2d6aacf6
Parse nested functions more accurately.
David Grundberg <individ@acc.umu.se>
parents:
9471
diff
changeset
|
153 // Scope where we install all subfunctions and nested functions. Only |
25ed2d6aacf6
Parse nested functions more accurately.
David Grundberg <individ@acc.umu.se>
parents:
9471
diff
changeset
|
154 // used while reading function files. |
25ed2d6aacf6
Parse nested functions more accurately.
David Grundberg <individ@acc.umu.se>
parents:
9471
diff
changeset
|
155 static symbol_table::scope_id primary_fcn_scope; |
7336 | 156 |
15037
56b8eb7c9c04
improvements in parsing classdef
John W. Eaton <jwe@octave.org>
parents:
14846
diff
changeset
|
157 // Pointer to the classdef object we just parsed, if any. |
56b8eb7c9c04
improvements in parsing classdef
John W. Eaton <jwe@octave.org>
parents:
14846
diff
changeset
|
158 static tree_classdef *classdef_object = 0; |
56b8eb7c9c04
improvements in parsing classdef
John W. Eaton <jwe@octave.org>
parents:
14846
diff
changeset
|
159 |
5484 | 160 // List of autoloads (function -> file mapping). |
161 static std::map<std::string, std::string> autoload_map; | |
162 | |
496 | 163 // Forward declarations for some functions defined at the bottom of |
164 // the file. | |
165 | |
166 // Generic error messages. | |
2970 | 167 static void |
168 yyerror (const char *s); | |
1 | 169 |
578 | 170 // Error mesages for mismatched end tokens. |
2970 | 171 static void |
172 end_error (const char *type, token::end_tok_type ettype, int l, int c); | |
1 | 173 |
578 | 174 // Check to see that end tokens are properly matched. |
2970 | 175 static bool |
176 end_token_ok (token *tok, token::end_tok_type expected); | |
496 | 177 |
178 // Maybe print a warning if an assignment expression is used as the | |
179 // test in a logical expression. | |
2970 | 180 static void |
181 maybe_warn_assign_as_truth_value (tree_expression *expr); | |
1 | 182 |
2764 | 183 // Maybe print a warning about switch labels that aren't constants. |
2970 | 184 static void |
185 maybe_warn_variable_switch_label (tree_expression *expr); | |
2764 | 186 |
1623 | 187 // Finish building a range. |
2970 | 188 static tree_expression * |
189 finish_colon_expression (tree_colon_expression *e); | |
1623 | 190 |
1607 | 191 // Build a constant. |
2970 | 192 static tree_constant * |
193 make_constant (int op, token *tok_val); | |
1607 | 194 |
4342 | 195 // Build a function handle. |
196 static tree_fcn_handle * | |
197 make_fcn_handle (token *tok_val); | |
198 | |
4935 | 199 // Build an anonymous function handle. |
5861 | 200 static tree_anon_fcn_handle * |
4935 | 201 make_anon_fcn_handle (tree_parameter_list *param_list, tree_statement *stmt); |
202 | |
578 | 203 // Build a binary expression. |
2970 | 204 static tree_expression * |
205 make_binary_op (int op, tree_expression *op1, token *tok_val, | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
206 tree_expression *op2); |
578 | 207 |
2375 | 208 // Build a boolean expression. |
2970 | 209 static tree_expression * |
210 make_boolean_op (int op, tree_expression *op1, token *tok_val, | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
211 tree_expression *op2); |
2375 | 212 |
578 | 213 // Build a prefix expression. |
2970 | 214 static tree_expression * |
215 make_prefix_op (int op, tree_expression *op1, token *tok_val); | |
578 | 216 |
217 // Build a postfix expression. | |
2970 | 218 static tree_expression * |
219 make_postfix_op (int op, tree_expression *op1, token *tok_val); | |
578 | 220 |
1623 | 221 // Build an unwind-protect command. |
2970 | 222 static tree_command * |
223 make_unwind_command (token *unwind_tok, tree_statement_list *body, | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
224 tree_statement_list *cleanup, token *end_tok, |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
225 octave_comment_list *lc, octave_comment_list *mc); |
1623 | 226 |
227 // Build a try-catch command. | |
2970 | 228 static tree_command * |
229 make_try_command (token *try_tok, tree_statement_list *body, | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
230 tree_statement_list *cleanup, token *end_tok, |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
231 octave_comment_list *lc, octave_comment_list *mc); |
1623 | 232 |
233 // Build a while command. | |
2970 | 234 static tree_command * |
235 make_while_command (token *while_tok, tree_expression *expr, | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
236 tree_statement_list *body, token *end_tok, |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
237 octave_comment_list *lc); |
1623 | 238 |
3484 | 239 // Build a do-until command. |
240 static tree_command * | |
8658
73c4516fae10
New evaluator and debugger derived from tree-walker class
John W. Eaton <jwe@octave.org>
parents:
8471
diff
changeset
|
241 make_do_until_command (token *until_tok, tree_statement_list *body, |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
242 tree_expression *expr, octave_comment_list *lc); |
3484 | 243 |
1623 | 244 // Build a for command. |
2970 | 245 static tree_command * |
13245
027a2186cd90
parfor keyword and infrastructure, but handle parfor as normal for loop for now
John W. Eaton <jwe@octave.org>
parents:
13241
diff
changeset
|
246 make_for_command (int tok_id, token *for_tok, tree_argument_list *lhs, |
027a2186cd90
parfor keyword and infrastructure, but handle parfor as normal for loop for now
John W. Eaton <jwe@octave.org>
parents:
13241
diff
changeset
|
247 tree_expression *expr, tree_expression *maxproc, |
027a2186cd90
parfor keyword and infrastructure, but handle parfor as normal for loop for now
John W. Eaton <jwe@octave.org>
parents:
13241
diff
changeset
|
248 tree_statement_list *body, token *end_tok, |
027a2186cd90
parfor keyword and infrastructure, but handle parfor as normal for loop for now
John W. Eaton <jwe@octave.org>
parents:
13241
diff
changeset
|
249 octave_comment_list *lc); |
1623 | 250 |
4207 | 251 // Build a break command. |
252 static tree_command * | |
253 make_break_command (token *break_tok); | |
254 | |
255 // Build a continue command. | |
256 static tree_command * | |
257 make_continue_command (token *continue_tok); | |
258 | |
259 // Build a return command. | |
260 static tree_command * | |
261 make_return_command (token *return_tok); | |
1623 | 262 |
263 // Start an if command. | |
2970 | 264 static tree_if_command_list * |
265 start_if_command (tree_expression *expr, tree_statement_list *list); | |
1623 | 266 |
267 // Finish an if command. | |
2970 | 268 static tree_if_command * |
3665 | 269 finish_if_command (token *if_tok, tree_if_command_list *list, |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
270 token *end_tok, octave_comment_list *lc); |
1623 | 271 |
272 // Build an elseif clause. | |
2970 | 273 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
|
274 make_elseif_clause (token *elseif_tok, tree_expression *expr, |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
275 tree_statement_list *list, octave_comment_list *lc); |
1623 | 276 |
2764 | 277 // Finish a switch command. |
2970 | 278 static tree_switch_command * |
279 finish_switch_command (token *switch_tok, tree_expression *expr, | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
280 tree_switch_case_list *list, token *end_tok, |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
281 octave_comment_list *lc); |
2764 | 282 |
283 // Build a switch case. | |
2970 | 284 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
|
285 make_switch_case (token *case_tok, tree_expression *expr, |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
286 tree_statement_list *list, octave_comment_list *lc); |
2764 | 287 |
1623 | 288 // Build an assignment to a variable. |
2970 | 289 static tree_expression * |
290 make_assign_op (int op, tree_argument_list *lhs, token *eq_tok, | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
291 tree_expression *rhs); |
1623 | 292 |
7715
5b4d278ec828
parse scripts completely before executing
John W. Eaton <jwe@octave.org>
parents:
7699
diff
changeset
|
293 // Define a script. |
5b4d278ec828
parse scripts completely before executing
John W. Eaton <jwe@octave.org>
parents:
7699
diff
changeset
|
294 static void |
8658
73c4516fae10
New evaluator and debugger derived from tree-walker class
John W. Eaton <jwe@octave.org>
parents:
8471
diff
changeset
|
295 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
|
296 |
1623 | 297 // Begin defining a function. |
2970 | 298 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
|
299 start_function (tree_parameter_list *param_list, tree_statement_list *body, |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
300 tree_statement *end_function); |
8658
73c4516fae10
New evaluator and debugger derived from tree-walker class
John W. Eaton <jwe@octave.org>
parents:
8471
diff
changeset
|
301 |
73c4516fae10
New evaluator and debugger derived from tree-walker class
John W. Eaton <jwe@octave.org>
parents:
8471
diff
changeset
|
302 // 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
|
303 static tree_statement * |
73c4516fae10
New evaluator and debugger derived from tree-walker class
John W. Eaton <jwe@octave.org>
parents:
8471
diff
changeset
|
304 make_end (const std::string& type, int l, int c); |
1623 | 305 |
306 // Do most of the work for defining a function. | |
2970 | 307 static octave_user_function * |
4872 | 308 frob_function (const std::string& fname, octave_user_function *fcn); |
1623 | 309 |
310 // Finish defining a function. | |
7715
5b4d278ec828
parse scripts completely before executing
John W. Eaton <jwe@octave.org>
parents:
7699
diff
changeset
|
311 static tree_function_def * |
3665 | 312 finish_function (tree_parameter_list *ret_list, |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
313 octave_user_function *fcn, octave_comment_list *lc); |
751 | 314 |
2883 | 315 // Reset state after parsing function. |
2970 | 316 static void |
317 recover_from_parsing_function (void); | |
2883 | 318 |
751 | 319 // Make an index expression. |
2970 | 320 static tree_index_expression * |
3933 | 321 make_index_expression (tree_expression *expr, |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
322 tree_argument_list *args, char type); |
2970 | 323 |
324 // Make an indirect reference expression. | |
3930 | 325 static tree_index_expression * |
3523 | 326 make_indirect_ref (tree_expression *expr, const std::string&); |
666 | 327 |
4131 | 328 // Make an indirect reference expression with dynamic field name. |
329 static tree_index_expression * | |
330 make_indirect_ref (tree_expression *expr, tree_expression *field); | |
331 | |
2846 | 332 // Make a declaration command. |
2970 | 333 static tree_decl_command * |
334 make_decl_command (int tok, token *tok_val, tree_decl_init_list *lst); | |
2846 | 335 |
10207
76a880a588ce
error when using ~ in matrix expression
Jaroslav Hajek <highegg@gmail.com>
parents:
10206
diff
changeset
|
336 // Validate argument list forming a matrix or cell row. |
76a880a588ce
error when using ~ in matrix expression
Jaroslav Hajek <highegg@gmail.com>
parents:
10206
diff
changeset
|
337 static tree_argument_list * |
76a880a588ce
error when using ~ in matrix expression
Jaroslav Hajek <highegg@gmail.com>
parents:
10206
diff
changeset
|
338 validate_matrix_row (tree_argument_list *row); |
76a880a588ce
error when using ~ in matrix expression
Jaroslav Hajek <highegg@gmail.com>
parents:
10206
diff
changeset
|
339 |
1623 | 340 // Finish building a matrix list. |
2970 | 341 static tree_expression * |
342 finish_matrix (tree_matrix *m); | |
1623 | 343 |
3351 | 344 // Finish building a cell list. |
345 static tree_expression * | |
346 finish_cell (tree_cell *c); | |
347 | |
1511 | 348 // Maybe print a warning. Duh. |
2970 | 349 static void |
350 maybe_warn_missing_semi (tree_statement_list *); | |
1511 | 351 |
2525 | 352 // 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
|
353 static tree_statement_list * |
2970 | 354 set_stmt_print_flag (tree_statement_list *, char, bool); |
2525 | 355 |
8448
d6c0d5f208de
parse.y: avoid storing null statements in statement lists
John W. Eaton <jwe@octave.org>
parents:
8447
diff
changeset
|
356 // Create a statement list. |
d6c0d5f208de
parse.y: avoid storing null statements in statement lists
John W. Eaton <jwe@octave.org>
parents:
8447
diff
changeset
|
357 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
|
358 |
d6c0d5f208de
parse.y: avoid storing null statements in statement lists
John W. Eaton <jwe@octave.org>
parents:
8447
diff
changeset
|
359 // 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
|
360 static tree_statement_list * |
d6c0d5f208de
parse.y: avoid storing null statements in statement lists
John W. Eaton <jwe@octave.org>
parents:
8447
diff
changeset
|
361 append_statement_list (tree_statement_list *list, char sep, |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
362 tree_statement *stmt, bool warn_missing_semi); |
8448
d6c0d5f208de
parse.y: avoid storing null statements in statement lists
John W. Eaton <jwe@octave.org>
parents:
8447
diff
changeset
|
363 |
15037
56b8eb7c9c04
improvements in parsing classdef
John W. Eaton <jwe@octave.org>
parents:
14846
diff
changeset
|
364 static tree_funcall * |
56b8eb7c9c04
improvements in parsing classdef
John W. Eaton <jwe@octave.org>
parents:
14846
diff
changeset
|
365 make_superclass_ref (const std::string& method_nm, |
56b8eb7c9c04
improvements in parsing classdef
John W. Eaton <jwe@octave.org>
parents:
14846
diff
changeset
|
366 const std::string& package_nm, |
56b8eb7c9c04
improvements in parsing classdef
John W. Eaton <jwe@octave.org>
parents:
14846
diff
changeset
|
367 const std::string& class_nm, |
56b8eb7c9c04
improvements in parsing classdef
John W. Eaton <jwe@octave.org>
parents:
14846
diff
changeset
|
368 int l, int c); |
56b8eb7c9c04
improvements in parsing classdef
John W. Eaton <jwe@octave.org>
parents:
14846
diff
changeset
|
369 |
56b8eb7c9c04
improvements in parsing classdef
John W. Eaton <jwe@octave.org>
parents:
14846
diff
changeset
|
370 static tree_funcall * |
56b8eb7c9c04
improvements in parsing classdef
John W. Eaton <jwe@octave.org>
parents:
14846
diff
changeset
|
371 make_meta_class_query (const std::string& package_nm, |
56b8eb7c9c04
improvements in parsing classdef
John W. Eaton <jwe@octave.org>
parents:
14846
diff
changeset
|
372 const std::string& class_nm, |
56b8eb7c9c04
improvements in parsing classdef
John W. Eaton <jwe@octave.org>
parents:
14846
diff
changeset
|
373 int l, int c); |
56b8eb7c9c04
improvements in parsing classdef
John W. Eaton <jwe@octave.org>
parents:
14846
diff
changeset
|
374 |
56b8eb7c9c04
improvements in parsing classdef
John W. Eaton <jwe@octave.org>
parents:
14846
diff
changeset
|
375 static tree_classdef * |
56b8eb7c9c04
improvements in parsing classdef
John W. Eaton <jwe@octave.org>
parents:
14846
diff
changeset
|
376 make_classdef (token *tok_val, tree_classdef_attribute_list *a, |
56b8eb7c9c04
improvements in parsing classdef
John W. Eaton <jwe@octave.org>
parents:
14846
diff
changeset
|
377 tree_identifier *id, tree_classdef_superclass_list *sc, |
56b8eb7c9c04
improvements in parsing classdef
John W. Eaton <jwe@octave.org>
parents:
14846
diff
changeset
|
378 tree_classdef_body *body, token *end_tok, |
56b8eb7c9c04
improvements in parsing classdef
John W. Eaton <jwe@octave.org>
parents:
14846
diff
changeset
|
379 octave_comment_list *lc); |
56b8eb7c9c04
improvements in parsing classdef
John W. Eaton <jwe@octave.org>
parents:
14846
diff
changeset
|
380 |
56b8eb7c9c04
improvements in parsing classdef
John W. Eaton <jwe@octave.org>
parents:
14846
diff
changeset
|
381 static tree_classdef_properties_block * |
56b8eb7c9c04
improvements in parsing classdef
John W. Eaton <jwe@octave.org>
parents:
14846
diff
changeset
|
382 make_classdef_properties_block (token *tok_val, |
56b8eb7c9c04
improvements in parsing classdef
John W. Eaton <jwe@octave.org>
parents:
14846
diff
changeset
|
383 tree_classdef_attribute_list *a, |
56b8eb7c9c04
improvements in parsing classdef
John W. Eaton <jwe@octave.org>
parents:
14846
diff
changeset
|
384 tree_classdef_property_list *plist, |
56b8eb7c9c04
improvements in parsing classdef
John W. Eaton <jwe@octave.org>
parents:
14846
diff
changeset
|
385 token *end_tok, octave_comment_list *lc); |
56b8eb7c9c04
improvements in parsing classdef
John W. Eaton <jwe@octave.org>
parents:
14846
diff
changeset
|
386 |
56b8eb7c9c04
improvements in parsing classdef
John W. Eaton <jwe@octave.org>
parents:
14846
diff
changeset
|
387 static tree_classdef_methods_block * |
56b8eb7c9c04
improvements in parsing classdef
John W. Eaton <jwe@octave.org>
parents:
14846
diff
changeset
|
388 make_classdef_methods_block (token *tok_val, |
56b8eb7c9c04
improvements in parsing classdef
John W. Eaton <jwe@octave.org>
parents:
14846
diff
changeset
|
389 tree_classdef_attribute_list *a, |
56b8eb7c9c04
improvements in parsing classdef
John W. Eaton <jwe@octave.org>
parents:
14846
diff
changeset
|
390 tree_classdef_methods_list *mlist, |
56b8eb7c9c04
improvements in parsing classdef
John W. Eaton <jwe@octave.org>
parents:
14846
diff
changeset
|
391 token *end_tok, octave_comment_list *lc); |
56b8eb7c9c04
improvements in parsing classdef
John W. Eaton <jwe@octave.org>
parents:
14846
diff
changeset
|
392 |
56b8eb7c9c04
improvements in parsing classdef
John W. Eaton <jwe@octave.org>
parents:
14846
diff
changeset
|
393 static tree_classdef_events_block * |
56b8eb7c9c04
improvements in parsing classdef
John W. Eaton <jwe@octave.org>
parents:
14846
diff
changeset
|
394 make_classdef_events_block (token *tok_val, |
56b8eb7c9c04
improvements in parsing classdef
John W. Eaton <jwe@octave.org>
parents:
14846
diff
changeset
|
395 tree_classdef_attribute_list *a, |
56b8eb7c9c04
improvements in parsing classdef
John W. Eaton <jwe@octave.org>
parents:
14846
diff
changeset
|
396 tree_classdef_events_list *elist, |
56b8eb7c9c04
improvements in parsing classdef
John W. Eaton <jwe@octave.org>
parents:
14846
diff
changeset
|
397 token *end_tok, octave_comment_list *lc); |
56b8eb7c9c04
improvements in parsing classdef
John W. Eaton <jwe@octave.org>
parents:
14846
diff
changeset
|
398 |
56b8eb7c9c04
improvements in parsing classdef
John W. Eaton <jwe@octave.org>
parents:
14846
diff
changeset
|
399 static tree_classdef_enum_block * |
56b8eb7c9c04
improvements in parsing classdef
John W. Eaton <jwe@octave.org>
parents:
14846
diff
changeset
|
400 make_classdef_enum_block (token *tok_val, |
56b8eb7c9c04
improvements in parsing classdef
John W. Eaton <jwe@octave.org>
parents:
14846
diff
changeset
|
401 tree_classdef_attribute_list *a, |
56b8eb7c9c04
improvements in parsing classdef
John W. Eaton <jwe@octave.org>
parents:
14846
diff
changeset
|
402 tree_classdef_enum_list *elist, |
56b8eb7c9c04
improvements in parsing classdef
John W. Eaton <jwe@octave.org>
parents:
14846
diff
changeset
|
403 token *end_tok, octave_comment_list *lc); |
56b8eb7c9c04
improvements in parsing classdef
John W. Eaton <jwe@octave.org>
parents:
14846
diff
changeset
|
404 |
8448
d6c0d5f208de
parse.y: avoid storing null statements in statement lists
John W. Eaton <jwe@octave.org>
parents:
8447
diff
changeset
|
405 // Finish building a statement. |
d6c0d5f208de
parse.y: avoid storing null statements in statement lists
John W. Eaton <jwe@octave.org>
parents:
8447
diff
changeset
|
406 template <class T> |
d6c0d5f208de
parse.y: avoid storing null statements in statement lists
John W. Eaton <jwe@octave.org>
parents:
8447
diff
changeset
|
407 static tree_statement * |
d6c0d5f208de
parse.y: avoid storing null statements in statement lists
John W. Eaton <jwe@octave.org>
parents:
8447
diff
changeset
|
408 make_statement (T *arg) |
d6c0d5f208de
parse.y: avoid storing null statements in statement lists
John W. Eaton <jwe@octave.org>
parents:
8447
diff
changeset
|
409 { |
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
|
410 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
|
411 |
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
|
412 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
|
413 } |
d6c0d5f208de
parse.y: avoid storing null statements in statement lists
John W. Eaton <jwe@octave.org>
parents:
8447
diff
changeset
|
414 |
1 | 415 #define ABORT_PARSE \ |
416 do \ | |
417 { \ | |
522 | 418 global_command = 0; \ |
1 | 419 yyerrok; \ |
14329
8d1ae996c122
also save and restore symbol table context in parser (bug #35448)
John W. Eaton <jwe@octave.org>
parents:
14294
diff
changeset
|
420 if (! parser_symtab_context.empty ()) \ |
8d1ae996c122
also save and restore symbol table context in parser (bug #35448)
John W. Eaton <jwe@octave.org>
parents:
14294
diff
changeset
|
421 parser_symtab_context.pop (); \ |
14584
3a10d5bdada8
src/symtab.yy (ABORT_PARSE): Prevent multiple parse errors in eval (bug #35154)
Max Brister <max@2bass.com>
parents:
14544
diff
changeset
|
422 if ((interactive || forced_interactive) \ |
3a10d5bdada8
src/symtab.yy (ABORT_PARSE): Prevent multiple parse errors in eval (bug #35154)
Max Brister <max@2bass.com>
parents:
14544
diff
changeset
|
423 && ! get_input_from_eval_string) \ |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
424 YYACCEPT; \ |
1 | 425 else \ |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
426 YYABORT; \ |
1 | 427 } \ |
428 while (0) | |
429 | |
430 %} | |
431 | |
666 | 432 // Bison declarations. |
433 | |
4813 | 434 // Don't add spaces around the = here; it causes some versions of |
435 // bison to fail to properly recognize the directive. | |
436 | |
437 %name-prefix="octave_" | |
4753 | 438 |
1 | 439 %union |
440 { | |
2891 | 441 // The type of the basic tokens returned by the lexer. |
143 | 442 token *tok_val; |
443 | |
3665 | 444 // Comment strings that we need to deal with mid-rule. |
445 octave_comment_list *comment_type; | |
446 | |
2891 | 447 // Types for the nonterminals we generate. |
2525 | 448 char sep_type; |
15037
56b8eb7c9c04
improvements in parsing classdef
John W. Eaton <jwe@octave.org>
parents:
14846
diff
changeset
|
449 token *tok_type; |
1 | 450 tree *tree_type; |
1829 | 451 tree_matrix *tree_matrix_type; |
3351 | 452 tree_cell *tree_cell_type; |
496 | 453 tree_expression *tree_expression_type; |
2375 | 454 tree_constant *tree_constant_type; |
4342 | 455 tree_fcn_handle *tree_fcn_handle_type; |
15037
56b8eb7c9c04
improvements in parsing classdef
John W. Eaton <jwe@octave.org>
parents:
14846
diff
changeset
|
456 tree_funcall *tree_funcall_type; |
56b8eb7c9c04
improvements in parsing classdef
John W. Eaton <jwe@octave.org>
parents:
14846
diff
changeset
|
457 tree_function_def *tree_function_def_type; |
5861 | 458 tree_anon_fcn_handle *tree_anon_fcn_handle_type; |
1 | 459 tree_identifier *tree_identifier_type; |
460 tree_index_expression *tree_index_expression_type; | |
461 tree_colon_expression *tree_colon_expression_type; | |
462 tree_argument_list *tree_argument_list_type; | |
463 tree_parameter_list *tree_parameter_list_type; | |
464 tree_command *tree_command_type; | |
465 tree_if_command *tree_if_command_type; | |
578 | 466 tree_if_clause *tree_if_clause_type; |
467 tree_if_command_list *tree_if_command_list_type; | |
2764 | 468 tree_switch_command *tree_switch_command_type; |
469 tree_switch_case *tree_switch_case_type; | |
470 tree_switch_case_list *tree_switch_case_list_type; | |
2846 | 471 tree_decl_elt *tree_decl_elt_type; |
472 tree_decl_init_list *tree_decl_init_list_type; | |
473 tree_decl_command *tree_decl_command_type; | |
578 | 474 tree_statement *tree_statement_type; |
475 tree_statement_list *tree_statement_list_type; | |
2891 | 476 octave_user_function *octave_user_function_type; |
15037
56b8eb7c9c04
improvements in parsing classdef
John W. Eaton <jwe@octave.org>
parents:
14846
diff
changeset
|
477 |
56b8eb7c9c04
improvements in parsing classdef
John W. Eaton <jwe@octave.org>
parents:
14846
diff
changeset
|
478 tree_classdef *tree_classdef_type; |
56b8eb7c9c04
improvements in parsing classdef
John W. Eaton <jwe@octave.org>
parents:
14846
diff
changeset
|
479 tree_classdef_attribute* tree_classdef_attribute_type; |
56b8eb7c9c04
improvements in parsing classdef
John W. Eaton <jwe@octave.org>
parents:
14846
diff
changeset
|
480 tree_classdef_attribute_list* tree_classdef_attribute_list_type; |
56b8eb7c9c04
improvements in parsing classdef
John W. Eaton <jwe@octave.org>
parents:
14846
diff
changeset
|
481 tree_classdef_superclass* tree_classdef_superclass_type; |
56b8eb7c9c04
improvements in parsing classdef
John W. Eaton <jwe@octave.org>
parents:
14846
diff
changeset
|
482 tree_classdef_superclass_list* tree_classdef_superclass_list_type; |
56b8eb7c9c04
improvements in parsing classdef
John W. Eaton <jwe@octave.org>
parents:
14846
diff
changeset
|
483 tree_classdef_body* tree_classdef_body_type; |
56b8eb7c9c04
improvements in parsing classdef
John W. Eaton <jwe@octave.org>
parents:
14846
diff
changeset
|
484 tree_classdef_property* tree_classdef_property_type; |
56b8eb7c9c04
improvements in parsing classdef
John W. Eaton <jwe@octave.org>
parents:
14846
diff
changeset
|
485 tree_classdef_property_list* tree_classdef_property_list_type; |
56b8eb7c9c04
improvements in parsing classdef
John W. Eaton <jwe@octave.org>
parents:
14846
diff
changeset
|
486 tree_classdef_properties_block* tree_classdef_properties_block_type; |
56b8eb7c9c04
improvements in parsing classdef
John W. Eaton <jwe@octave.org>
parents:
14846
diff
changeset
|
487 tree_classdef_methods_list* tree_classdef_methods_list_type; |
56b8eb7c9c04
improvements in parsing classdef
John W. Eaton <jwe@octave.org>
parents:
14846
diff
changeset
|
488 tree_classdef_methods_block* tree_classdef_methods_block_type; |
56b8eb7c9c04
improvements in parsing classdef
John W. Eaton <jwe@octave.org>
parents:
14846
diff
changeset
|
489 tree_classdef_event* tree_classdef_event_type; |
56b8eb7c9c04
improvements in parsing classdef
John W. Eaton <jwe@octave.org>
parents:
14846
diff
changeset
|
490 tree_classdef_events_list* tree_classdef_events_list_type; |
56b8eb7c9c04
improvements in parsing classdef
John W. Eaton <jwe@octave.org>
parents:
14846
diff
changeset
|
491 tree_classdef_events_block* tree_classdef_events_block_type; |
56b8eb7c9c04
improvements in parsing classdef
John W. Eaton <jwe@octave.org>
parents:
14846
diff
changeset
|
492 tree_classdef_enum* tree_classdef_enum_type; |
56b8eb7c9c04
improvements in parsing classdef
John W. Eaton <jwe@octave.org>
parents:
14846
diff
changeset
|
493 tree_classdef_enum_list* tree_classdef_enum_list_type; |
56b8eb7c9c04
improvements in parsing classdef
John W. Eaton <jwe@octave.org>
parents:
14846
diff
changeset
|
494 tree_classdef_enum_block* tree_classdef_enum_block_type; |
1 | 495 } |
496 | |
143 | 497 // Tokens with line and column information. |
498 %token <tok_val> '=' ':' '-' '+' '*' '/' | |
4018 | 499 %token <tok_val> ADD_EQ SUB_EQ MUL_EQ DIV_EQ LEFTDIV_EQ POW_EQ |
500 %token <tok_val> EMUL_EQ EDIV_EQ ELEFTDIV_EQ EPOW_EQ AND_EQ OR_EQ | |
2899 | 501 %token <tok_val> LSHIFT_EQ RSHIFT_EQ LSHIFT RSHIFT |
428 | 502 %token <tok_val> EXPR_AND_AND EXPR_OR_OR |
143 | 503 %token <tok_val> EXPR_AND EXPR_OR EXPR_NOT |
504 %token <tok_val> EXPR_LT EXPR_LE EXPR_EQ EXPR_NE EXPR_GE EXPR_GT | |
1276 | 505 %token <tok_val> LEFTDIV EMUL EDIV ELEFTDIV EPLUS EMINUS |
506 %token <tok_val> QUOTE TRANSPOSE | |
143 | 507 %token <tok_val> PLUS_PLUS MINUS_MINUS POW EPOW |
508 %token <tok_val> NUM IMAG_NUM | |
2970 | 509 %token <tok_val> STRUCT_ELT |
2883 | 510 %token <tok_val> NAME |
143 | 511 %token <tok_val> END |
5279 | 512 %token <tok_val> DQ_STRING SQ_STRING |
13245
027a2186cd90
parfor keyword and infrastructure, but handle parfor as normal for loop for now
John W. Eaton <jwe@octave.org>
parents:
13241
diff
changeset
|
513 %token <tok_val> FOR PARFOR WHILE DO UNTIL |
1491 | 514 %token <tok_val> IF ELSEIF ELSE |
2764 | 515 %token <tok_val> SWITCH CASE OTHERWISE |
1491 | 516 %token <tok_val> BREAK CONTINUE FUNC_RET |
924 | 517 %token <tok_val> UNWIND CLEANUP |
1489 | 518 %token <tok_val> TRY CATCH |
14294
9e3983c8963c
deprecate the static keyword
John W. Eaton <jwe@octave.org>
parents:
14293
diff
changeset
|
519 %token <tok_val> GLOBAL PERSISTENT |
4342 | 520 %token <tok_val> FCN_HANDLE |
15037
56b8eb7c9c04
improvements in parsing classdef
John W. Eaton <jwe@octave.org>
parents:
14846
diff
changeset
|
521 %token <tok_val> CLASSDEF |
13249
7861a5fd3479
accept enumeration keyword
John W. Eaton <jwe@octave.org>
parents:
13246
diff
changeset
|
522 %token <tok_val> PROPERTIES METHODS EVENTS ENUMERATION |
9476 | 523 %token <tok_val> METAQUERY |
524 %token <tok_val> SUPERCLASSREF | |
525 %token <tok_val> GET SET | |
1 | 526 |
143 | 527 // Other tokens. |
2970 | 528 %token END_OF_INPUT LEXICAL_ERROR |
15037
56b8eb7c9c04
improvements in parsing classdef
John W. Eaton <jwe@octave.org>
parents:
14846
diff
changeset
|
529 %token FCN SCRIPT_FILE CLASSDEF_FILE FUNCTION_FILE |
7587
1f662945c2be
handle varargin and varargout without keywords
John W. Eaton <jwe@octave.org>
parents:
7562
diff
changeset
|
530 // %token VARARGIN VARARGOUT |
5296 | 531 %token CLOSE_BRACE |
1 | 532 |
143 | 533 // Nonterminals we construct. |
15037
56b8eb7c9c04
improvements in parsing classdef
John W. Eaton <jwe@octave.org>
parents:
14846
diff
changeset
|
534 %type <comment_type> stash_comment function_beg |
56b8eb7c9c04
improvements in parsing classdef
John W. Eaton <jwe@octave.org>
parents:
14846
diff
changeset
|
535 %type <tok_type> classdef_beg |
14533
e6aa044253eb
Allow comma at the end of an assignment list (bug #35645)
Max Brister <max@2bass.com>
parents:
14512
diff
changeset
|
536 %type <sep_type> sep_no_nl opt_sep_no_nl sep opt_sep opt_comma |
578 | 537 %type <tree_type> input |
5861 | 538 %type <tree_constant_type> string constant magic_colon |
539 %type <tree_anon_fcn_handle_type> anon_fcn_handle | |
4342 | 540 %type <tree_fcn_handle_type> fcn_handle |
3351 | 541 %type <tree_matrix_type> matrix_rows matrix_rows1 |
542 %type <tree_cell_type> cell_rows cell_rows1 | |
5102 | 543 %type <tree_expression_type> matrix cell |
12627
002948ae5bc0
fix precedence level of transpose operators (bug #32533)
John W. Eaton <jwe@octave.org>
parents:
12483
diff
changeset
|
544 %type <tree_expression_type> primary_expr oper_expr |
4207 | 545 %type <tree_expression_type> simple_expr colon_expr assign_expr expression |
10206
37a08e0ce2dc
support Matlab-style empty output/input arguments
Jaroslav Hajek <highegg@gmail.com>
parents:
10188
diff
changeset
|
546 %type <tree_identifier_type> identifier fcn_name magic_tilde |
15037
56b8eb7c9c04
improvements in parsing classdef
John W. Eaton <jwe@octave.org>
parents:
14846
diff
changeset
|
547 %type <tree_funcall_type> superclass_identifier meta_identifier |
56b8eb7c9c04
improvements in parsing classdef
John W. Eaton <jwe@octave.org>
parents:
14846
diff
changeset
|
548 %type <octave_user_function_type> function1 function2 |
2970 | 549 %type <tree_index_expression_type> word_list_cmd |
550 %type <tree_colon_expression_type> colon_expr1 | |
3351 | 551 %type <tree_argument_list_type> arg_list word_list assign_lhs |
552 %type <tree_argument_list_type> cell_or_matrix_row | |
4935 | 553 %type <tree_parameter_list_type> param_list param_list1 param_list2 |
723 | 554 %type <tree_parameter_list_type> return_list return_list1 |
2970 | 555 %type <tree_command_type> command select_command loop_command |
15037
56b8eb7c9c04
improvements in parsing classdef
John W. Eaton <jwe@octave.org>
parents:
14846
diff
changeset
|
556 %type <tree_command_type> jump_command except_command |
56b8eb7c9c04
improvements in parsing classdef
John W. Eaton <jwe@octave.org>
parents:
14846
diff
changeset
|
557 %type <tree_function_def_type> function |
56b8eb7c9c04
improvements in parsing classdef
John W. Eaton <jwe@octave.org>
parents:
14846
diff
changeset
|
558 %type <tree_classdef_type> classdef |
56b8eb7c9c04
improvements in parsing classdef
John W. Eaton <jwe@octave.org>
parents:
14846
diff
changeset
|
559 %type <tree_command_type> script_file classdef_file |
9474
25ed2d6aacf6
Parse nested functions more accurately.
David Grundberg <individ@acc.umu.se>
parents:
9471
diff
changeset
|
560 %type <tree_command_type> function_file function_list |
578 | 561 %type <tree_if_command_type> if_command |
562 %type <tree_if_clause_type> elseif_clause else_clause | |
563 %type <tree_if_command_list_type> if_cmd_list1 if_cmd_list | |
2764 | 564 %type <tree_switch_command_type> switch_command |
565 %type <tree_switch_case_type> switch_case default_case | |
566 %type <tree_switch_case_list_type> case_list1 case_list | |
2846 | 567 %type <tree_decl_elt_type> decl2 |
568 %type <tree_decl_init_list_type> decl1 | |
569 %type <tree_decl_command_type> declaration | |
15037
56b8eb7c9c04
improvements in parsing classdef
John W. Eaton <jwe@octave.org>
parents:
14846
diff
changeset
|
570 %type <tree_statement_type> statement function_end |
627 | 571 %type <tree_statement_list_type> simple_list simple_list1 list list1 |
7336 | 572 %type <tree_statement_list_type> opt_list input1 |
15037
56b8eb7c9c04
improvements in parsing classdef
John W. Eaton <jwe@octave.org>
parents:
14846
diff
changeset
|
573 |
56b8eb7c9c04
improvements in parsing classdef
John W. Eaton <jwe@octave.org>
parents:
14846
diff
changeset
|
574 %type <tree_classdef_attribute_type> attr |
56b8eb7c9c04
improvements in parsing classdef
John W. Eaton <jwe@octave.org>
parents:
14846
diff
changeset
|
575 %type <tree_classdef_attribute_list_type> attr_list opt_attr_list |
56b8eb7c9c04
improvements in parsing classdef
John W. Eaton <jwe@octave.org>
parents:
14846
diff
changeset
|
576 %type <tree_classdef_superclass_type> superclass |
56b8eb7c9c04
improvements in parsing classdef
John W. Eaton <jwe@octave.org>
parents:
14846
diff
changeset
|
577 %type <tree_classdef_superclass_list_type> superclass_list opt_superclass_list |
56b8eb7c9c04
improvements in parsing classdef
John W. Eaton <jwe@octave.org>
parents:
14846
diff
changeset
|
578 %type <tree_classdef_body_type> class_body |
56b8eb7c9c04
improvements in parsing classdef
John W. Eaton <jwe@octave.org>
parents:
14846
diff
changeset
|
579 %type <tree_classdef_property_type> class_property |
56b8eb7c9c04
improvements in parsing classdef
John W. Eaton <jwe@octave.org>
parents:
14846
diff
changeset
|
580 %type <tree_classdef_property_list_type> property_list |
56b8eb7c9c04
improvements in parsing classdef
John W. Eaton <jwe@octave.org>
parents:
14846
diff
changeset
|
581 %type <tree_classdef_properties_block_type> properties_block |
56b8eb7c9c04
improvements in parsing classdef
John W. Eaton <jwe@octave.org>
parents:
14846
diff
changeset
|
582 %type <tree_classdef_methods_list_type> methods_list |
56b8eb7c9c04
improvements in parsing classdef
John W. Eaton <jwe@octave.org>
parents:
14846
diff
changeset
|
583 %type <tree_classdef_methods_block_type> methods_block |
56b8eb7c9c04
improvements in parsing classdef
John W. Eaton <jwe@octave.org>
parents:
14846
diff
changeset
|
584 %type <tree_classdef_event_type> class_event |
56b8eb7c9c04
improvements in parsing classdef
John W. Eaton <jwe@octave.org>
parents:
14846
diff
changeset
|
585 %type <tree_classdef_events_list_type> events_list |
56b8eb7c9c04
improvements in parsing classdef
John W. Eaton <jwe@octave.org>
parents:
14846
diff
changeset
|
586 %type <tree_classdef_events_block_type> events_block |
56b8eb7c9c04
improvements in parsing classdef
John W. Eaton <jwe@octave.org>
parents:
14846
diff
changeset
|
587 %type <tree_classdef_enum_type> class_enum |
56b8eb7c9c04
improvements in parsing classdef
John W. Eaton <jwe@octave.org>
parents:
14846
diff
changeset
|
588 %type <tree_classdef_enum_list_type> enum_list |
56b8eb7c9c04
improvements in parsing classdef
John W. Eaton <jwe@octave.org>
parents:
14846
diff
changeset
|
589 %type <tree_classdef_enum_block_type> enum_block |
1 | 590 |
143 | 591 // Precedence and associativity. |
4018 | 592 %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 | 593 %left EXPR_OR_OR |
594 %left EXPR_AND_AND | |
595 %left EXPR_OR | |
596 %left EXPR_AND | |
1 | 597 %left EXPR_LT EXPR_LE EXPR_EQ EXPR_NE EXPR_GE EXPR_GT |
2899 | 598 %left LSHIFT RSHIFT |
1 | 599 %left ':' |
1276 | 600 %left '-' '+' EPLUS EMINUS |
1 | 601 %left '*' '/' LEFTDIV EMUL EDIV ELEFTDIV |
12627
002948ae5bc0
fix precedence level of transpose operators (bug #32533)
John W. Eaton <jwe@octave.org>
parents:
12483
diff
changeset
|
602 %right UNARY EXPR_NOT |
5667 | 603 %left POW EPOW QUOTE TRANSPOSE |
12627
002948ae5bc0
fix precedence level of transpose operators (bug #32533)
John W. Eaton <jwe@octave.org>
parents:
12483
diff
changeset
|
604 %right PLUS_PLUS MINUS_MINUS |
3351 | 605 %left '(' '.' '{' |
1 | 606 |
143 | 607 // Where to start. |
1 | 608 %start input |
609 | |
610 %% | |
611 | |
2970 | 612 // ============================== |
613 // Statements and statement lists | |
614 // ============================== | |
615 | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
616 input : input1 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
617 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
618 global_command = $1; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
619 promptflag = 1; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
620 YYACCEPT; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
621 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
622 | function_file |
11258
795c97ace02c
eliminate some possible memory leaks
John W. Eaton <jwe@octave.org>
parents:
11225
diff
changeset
|
623 { YYACCEPT; } |
15037
56b8eb7c9c04
improvements in parsing classdef
John W. Eaton <jwe@octave.org>
parents:
14846
diff
changeset
|
624 | classdef_file |
56b8eb7c9c04
improvements in parsing classdef
John W. Eaton <jwe@octave.org>
parents:
14846
diff
changeset
|
625 { YYACCEPT; } |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
626 | simple_list parse_error |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
627 { ABORT_PARSE; } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
628 | parse_error |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
629 { ABORT_PARSE; } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
630 ; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
631 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
632 input1 : '\n' |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
633 { $$ = 0; } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
634 | END_OF_INPUT |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
635 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
636 parser_end_of_input = 1; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
637 $$ = 0; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
638 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
639 | simple_list |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
640 { $$ = $1; } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
641 | simple_list '\n' |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
642 { $$ = $1; } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
643 | simple_list END_OF_INPUT |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
644 { $$ = $1; } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
645 ; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
646 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
647 simple_list : simple_list1 opt_sep_no_nl |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
648 { $$ = set_stmt_print_flag ($1, $2, false); } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
649 ; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
650 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
651 simple_list1 : statement |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
652 { $$ = make_statement_list ($1); } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
653 | simple_list1 sep_no_nl statement |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
654 { $$ = append_statement_list ($1, $2, $3, false); } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
655 ; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
656 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
657 opt_list : // empty |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
658 { $$ = new tree_statement_list (); } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
659 | list |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
660 { $$ = $1; } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
661 ; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
662 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
663 list : list1 opt_sep |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
664 { $$ = set_stmt_print_flag ($1, $2, true); } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
665 ; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
666 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
667 list1 : statement |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
668 { $$ = make_statement_list ($1); } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
669 | list1 sep statement |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
670 { $$ = append_statement_list ($1, $2, $3, true); } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
671 ; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
672 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
673 statement : expression |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
674 { $$ = make_statement ($1); } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
675 | command |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
676 { $$ = make_statement ($1); } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
677 | word_list_cmd |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
678 { $$ = make_statement ($1); } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
679 ; |
8746
5dd06f19e9be
handle commands in the lexer
John W. Eaton <jwe@octave.org>
parents:
8745
diff
changeset
|
680 |
5dd06f19e9be
handle commands in the lexer
John W. Eaton <jwe@octave.org>
parents:
8745
diff
changeset
|
681 // ================= |
5dd06f19e9be
handle commands in the lexer
John W. Eaton <jwe@octave.org>
parents:
8745
diff
changeset
|
682 // Word-list command |
5dd06f19e9be
handle commands in the lexer
John W. Eaton <jwe@octave.org>
parents:
8745
diff
changeset
|
683 // ================= |
5dd06f19e9be
handle commands in the lexer
John W. Eaton <jwe@octave.org>
parents:
8745
diff
changeset
|
684 |
5dd06f19e9be
handle commands in the lexer
John W. Eaton <jwe@octave.org>
parents:
8745
diff
changeset
|
685 // These are not really like expressions since they can't appear on |
5dd06f19e9be
handle commands in the lexer
John W. Eaton <jwe@octave.org>
parents:
8745
diff
changeset
|
686 // the RHS of an assignment. But they are also not like commands (IF, |
5dd06f19e9be
handle commands in the lexer
John W. Eaton <jwe@octave.org>
parents:
8745
diff
changeset
|
687 // WHILE, etc. |
5dd06f19e9be
handle commands in the lexer
John W. Eaton <jwe@octave.org>
parents:
8745
diff
changeset
|
688 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
689 word_list_cmd : identifier word_list |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
690 { $$ = make_index_expression ($1, $2, '('); } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
691 ; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
692 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
693 word_list : string |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
694 { $$ = new tree_argument_list ($1); } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
695 | word_list string |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
696 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
697 $1->append ($2); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
698 $$ = $1; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
699 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
700 ; |
1 | 701 |
2970 | 702 // =========== |
703 // Expressions | |
704 // =========== | |
705 | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
706 identifier : NAME |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
707 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
708 symbol_table::symbol_record *sr = $1->sym_rec (); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
709 $$ = new tree_identifier (*sr, $1->line (), $1->column ()); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
710 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
711 ; |
2970 | 712 |
9476 | 713 superclass_identifier |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
714 : SUPERCLASSREF |
15037
56b8eb7c9c04
improvements in parsing classdef
John W. Eaton <jwe@octave.org>
parents:
14846
diff
changeset
|
715 { |
56b8eb7c9c04
improvements in parsing classdef
John W. Eaton <jwe@octave.org>
parents:
14846
diff
changeset
|
716 std::string method_nm = $1->superclass_method_name (); |
56b8eb7c9c04
improvements in parsing classdef
John W. Eaton <jwe@octave.org>
parents:
14846
diff
changeset
|
717 std::string package_nm = $1->superclass_package_name (); |
56b8eb7c9c04
improvements in parsing classdef
John W. Eaton <jwe@octave.org>
parents:
14846
diff
changeset
|
718 std::string class_nm = $1->superclass_class_name (); |
56b8eb7c9c04
improvements in parsing classdef
John W. Eaton <jwe@octave.org>
parents:
14846
diff
changeset
|
719 |
56b8eb7c9c04
improvements in parsing classdef
John W. Eaton <jwe@octave.org>
parents:
14846
diff
changeset
|
720 $$ = make_superclass_ref (method_nm, package_nm, class_nm, |
56b8eb7c9c04
improvements in parsing classdef
John W. Eaton <jwe@octave.org>
parents:
14846
diff
changeset
|
721 $1->line (), $1->column ()); |
56b8eb7c9c04
improvements in parsing classdef
John W. Eaton <jwe@octave.org>
parents:
14846
diff
changeset
|
722 } |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
723 ; |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11572
diff
changeset
|
724 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
725 meta_identifier : METAQUERY |
15037
56b8eb7c9c04
improvements in parsing classdef
John W. Eaton <jwe@octave.org>
parents:
14846
diff
changeset
|
726 { |
56b8eb7c9c04
improvements in parsing classdef
John W. Eaton <jwe@octave.org>
parents:
14846
diff
changeset
|
727 std::string package_nm = $1->meta_package_name (); |
56b8eb7c9c04
improvements in parsing classdef
John W. Eaton <jwe@octave.org>
parents:
14846
diff
changeset
|
728 std::string class_nm = $1->meta_class_name (); |
56b8eb7c9c04
improvements in parsing classdef
John W. Eaton <jwe@octave.org>
parents:
14846
diff
changeset
|
729 |
56b8eb7c9c04
improvements in parsing classdef
John W. Eaton <jwe@octave.org>
parents:
14846
diff
changeset
|
730 $$ = make_meta_class_query (package_nm, class_nm, |
56b8eb7c9c04
improvements in parsing classdef
John W. Eaton <jwe@octave.org>
parents:
14846
diff
changeset
|
731 $1->line (), $1->column ()); |
56b8eb7c9c04
improvements in parsing classdef
John W. Eaton <jwe@octave.org>
parents:
14846
diff
changeset
|
732 } |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11572
diff
changeset
|
733 ; |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
734 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
735 string : DQ_STRING |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
736 { $$ = make_constant (DQ_STRING, $1); } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
737 | SQ_STRING |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
738 { $$ = make_constant (SQ_STRING, $1); } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
739 ; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
740 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
741 constant : NUM |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
742 { $$ = make_constant (NUM, $1); } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
743 | IMAG_NUM |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
744 { $$ = make_constant (IMAG_NUM, $1); } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
745 | string |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
746 { $$ = $1; } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
747 ; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
748 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
749 matrix : '[' ']' |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
750 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
751 $$ = new tree_constant (octave_null_matrix::instance); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
752 lexer_flags.looking_at_matrix_or_assign_lhs = false; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
753 lexer_flags.pending_local_variables.clear (); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
754 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
755 | '[' ';' ']' |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
756 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
757 $$ = new tree_constant (octave_null_matrix::instance); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
758 lexer_flags.looking_at_matrix_or_assign_lhs = false; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
759 lexer_flags.pending_local_variables.clear (); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
760 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
761 | '[' ',' ']' |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
762 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
763 $$ = new tree_constant (octave_null_matrix::instance); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
764 lexer_flags.looking_at_matrix_or_assign_lhs = false; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
765 lexer_flags.pending_local_variables.clear (); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
766 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
767 | '[' matrix_rows ']' |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
768 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
769 $$ = finish_matrix ($2); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
770 lexer_flags.looking_at_matrix_or_assign_lhs = false; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
771 lexer_flags.pending_local_variables.clear (); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
772 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
773 ; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
774 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
775 matrix_rows : matrix_rows1 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
776 { $$ = $1; } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
777 | matrix_rows1 ';' // Ignore trailing semicolon. |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
778 { $$ = $1; } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
779 ; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
780 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
781 matrix_rows1 : cell_or_matrix_row |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
782 { $$ = new tree_matrix ($1); } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
783 | matrix_rows1 ';' cell_or_matrix_row |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
784 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
785 $1->append ($3); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
786 $$ = $1; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
787 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
788 ; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
789 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
790 cell : '{' '}' |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
791 { $$ = new tree_constant (octave_value (Cell ())); } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
792 | '{' ';' '}' |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
793 { $$ = new tree_constant (octave_value (Cell ())); } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
794 | '{' cell_rows '}' |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
795 { $$ = finish_cell ($2); } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
796 ; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
797 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
798 cell_rows : cell_rows1 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
799 { $$ = $1; } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
800 | cell_rows1 ';' // Ignore trailing semicolon. |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
801 { $$ = $1; } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
802 ; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
803 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
804 cell_rows1 : cell_or_matrix_row |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
805 { $$ = new tree_cell ($1); } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
806 | cell_rows1 ';' cell_or_matrix_row |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
807 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
808 $1->append ($3); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
809 $$ = $1; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
810 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
811 ; |
3351 | 812 |
813 cell_or_matrix_row | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
814 : arg_list |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
815 { $$ = validate_matrix_row ($1); } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
816 | arg_list ',' // Ignore trailing comma. |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
817 { $$ = validate_matrix_row ($1); } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
818 ; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
819 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
820 fcn_handle : '@' FCN_HANDLE |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
821 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
822 $$ = make_fcn_handle ($2); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
823 lexer_flags.looking_at_function_handle--; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
824 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
825 ; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
826 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
827 anon_fcn_handle : '@' param_list statement |
13237
1bfca2bbea8b
fix parsing of anonymous functions inside cell array lists.
John W. Eaton <jwe@octave.org>
parents:
13125
diff
changeset
|
828 { |
1bfca2bbea8b
fix parsing of anonymous functions inside cell array lists.
John W. Eaton <jwe@octave.org>
parents:
13125
diff
changeset
|
829 lexer_flags.quote_is_transpose = false; |
1bfca2bbea8b
fix parsing of anonymous functions inside cell array lists.
John W. Eaton <jwe@octave.org>
parents:
13125
diff
changeset
|
830 $$ = make_anon_fcn_handle ($2, $3); |
1bfca2bbea8b
fix parsing of anonymous functions inside cell array lists.
John W. Eaton <jwe@octave.org>
parents:
13125
diff
changeset
|
831 } |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
832 ; |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11572
diff
changeset
|
833 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
834 primary_expr : identifier |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
835 { $$ = $1; } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
836 | constant |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
837 { $$ = $1; } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
838 | fcn_handle |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
839 { $$ = $1; } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
840 | matrix |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
841 { $$ = $1; } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
842 | cell |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
843 { $$ = $1; } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
844 | meta_identifier |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
845 { $$ = $1; } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
846 | superclass_identifier |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
847 { $$ = $1; } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
848 | '(' expression ')' |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
849 { $$ = $2->mark_in_parens (); } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
850 ; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
851 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
852 magic_colon : ':' |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
853 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
854 octave_value tmp (octave_value::magic_colon_t); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
855 $$ = new tree_constant (tmp); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
856 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
857 ; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
858 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
859 magic_tilde : EXPR_NOT |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
860 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
861 $$ = new tree_black_hole (); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
862 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
863 ; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
864 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
865 arg_list : expression |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
866 { $$ = new tree_argument_list ($1); } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
867 | magic_colon |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
868 { $$ = new tree_argument_list ($1); } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
869 | magic_tilde |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
870 { $$ = new tree_argument_list ($1); } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
871 | arg_list ',' magic_colon |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
872 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
873 $1->append ($3); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
874 $$ = $1; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
875 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
876 | arg_list ',' magic_tilde |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
877 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
878 $1->append ($3); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
879 $$ = $1; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
880 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
881 | arg_list ',' expression |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
882 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
883 $1->append ($3); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
884 $$ = $1; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
885 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
886 ; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
887 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
888 indirect_ref_op : '.' |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
889 { lexer_flags.looking_at_indirect_ref = true; } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
890 ; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
891 |
12627
002948ae5bc0
fix precedence level of transpose operators (bug #32533)
John W. Eaton <jwe@octave.org>
parents:
12483
diff
changeset
|
892 oper_expr : primary_expr |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
893 { $$ = $1; } |
12627
002948ae5bc0
fix precedence level of transpose operators (bug #32533)
John W. Eaton <jwe@octave.org>
parents:
12483
diff
changeset
|
894 | oper_expr PLUS_PLUS |
002948ae5bc0
fix precedence level of transpose operators (bug #32533)
John W. Eaton <jwe@octave.org>
parents:
12483
diff
changeset
|
895 { $$ = make_postfix_op (PLUS_PLUS, $1, $2); } |
002948ae5bc0
fix precedence level of transpose operators (bug #32533)
John W. Eaton <jwe@octave.org>
parents:
12483
diff
changeset
|
896 | oper_expr MINUS_MINUS |
002948ae5bc0
fix precedence level of transpose operators (bug #32533)
John W. Eaton <jwe@octave.org>
parents:
12483
diff
changeset
|
897 { $$ = make_postfix_op (MINUS_MINUS, $1, $2); } |
002948ae5bc0
fix precedence level of transpose operators (bug #32533)
John W. Eaton <jwe@octave.org>
parents:
12483
diff
changeset
|
898 | oper_expr '(' ')' |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
899 { $$ = make_index_expression ($1, 0, '('); } |
12627
002948ae5bc0
fix precedence level of transpose operators (bug #32533)
John W. Eaton <jwe@octave.org>
parents:
12483
diff
changeset
|
900 | oper_expr '(' arg_list ')' |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
901 { $$ = make_index_expression ($1, $3, '('); } |
12627
002948ae5bc0
fix precedence level of transpose operators (bug #32533)
John W. Eaton <jwe@octave.org>
parents:
12483
diff
changeset
|
902 | oper_expr '{' '}' |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
903 { $$ = make_index_expression ($1, 0, '{'); } |
12627
002948ae5bc0
fix precedence level of transpose operators (bug #32533)
John W. Eaton <jwe@octave.org>
parents:
12483
diff
changeset
|
904 | oper_expr '{' arg_list '}' |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
905 { $$ = make_index_expression ($1, $3, '{'); } |
12627
002948ae5bc0
fix precedence level of transpose operators (bug #32533)
John W. Eaton <jwe@octave.org>
parents:
12483
diff
changeset
|
906 | oper_expr QUOTE |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
907 { $$ = make_postfix_op (QUOTE, $1, $2); } |
12627
002948ae5bc0
fix precedence level of transpose operators (bug #32533)
John W. Eaton <jwe@octave.org>
parents:
12483
diff
changeset
|
908 | oper_expr TRANSPOSE |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
909 { $$ = make_postfix_op (TRANSPOSE, $1, $2); } |
12627
002948ae5bc0
fix precedence level of transpose operators (bug #32533)
John W. Eaton <jwe@octave.org>
parents:
12483
diff
changeset
|
910 | oper_expr indirect_ref_op STRUCT_ELT |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
911 { $$ = make_indirect_ref ($1, $3->text ()); } |
12627
002948ae5bc0
fix precedence level of transpose operators (bug #32533)
John W. Eaton <jwe@octave.org>
parents:
12483
diff
changeset
|
912 | oper_expr indirect_ref_op '(' expression ')' |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
913 { $$ = make_indirect_ref ($1, $4); } |
12627
002948ae5bc0
fix precedence level of transpose operators (bug #32533)
John W. Eaton <jwe@octave.org>
parents:
12483
diff
changeset
|
914 | PLUS_PLUS oper_expr %prec UNARY |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
915 { $$ = make_prefix_op (PLUS_PLUS, $2, $1); } |
12627
002948ae5bc0
fix precedence level of transpose operators (bug #32533)
John W. Eaton <jwe@octave.org>
parents:
12483
diff
changeset
|
916 | MINUS_MINUS oper_expr %prec UNARY |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
917 { $$ = make_prefix_op (MINUS_MINUS, $2, $1); } |
12627
002948ae5bc0
fix precedence level of transpose operators (bug #32533)
John W. Eaton <jwe@octave.org>
parents:
12483
diff
changeset
|
918 | EXPR_NOT oper_expr %prec UNARY |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
919 { $$ = make_prefix_op (EXPR_NOT, $2, $1); } |
12627
002948ae5bc0
fix precedence level of transpose operators (bug #32533)
John W. Eaton <jwe@octave.org>
parents:
12483
diff
changeset
|
920 | '+' oper_expr %prec UNARY |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
921 { $$ = make_prefix_op ('+', $2, $1); } |
12627
002948ae5bc0
fix precedence level of transpose operators (bug #32533)
John W. Eaton <jwe@octave.org>
parents:
12483
diff
changeset
|
922 | '-' oper_expr %prec UNARY |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
923 { $$ = make_prefix_op ('-', $2, $1); } |
12627
002948ae5bc0
fix precedence level of transpose operators (bug #32533)
John W. Eaton <jwe@octave.org>
parents:
12483
diff
changeset
|
924 | oper_expr POW oper_expr |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
925 { $$ = make_binary_op (POW, $1, $2, $3); } |
12627
002948ae5bc0
fix precedence level of transpose operators (bug #32533)
John W. Eaton <jwe@octave.org>
parents:
12483
diff
changeset
|
926 | oper_expr EPOW oper_expr |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
927 { $$ = make_binary_op (EPOW, $1, $2, $3); } |
12627
002948ae5bc0
fix precedence level of transpose operators (bug #32533)
John W. Eaton <jwe@octave.org>
parents:
12483
diff
changeset
|
928 | oper_expr '+' oper_expr |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
929 { $$ = make_binary_op ('+', $1, $2, $3); } |
12627
002948ae5bc0
fix precedence level of transpose operators (bug #32533)
John W. Eaton <jwe@octave.org>
parents:
12483
diff
changeset
|
930 | oper_expr '-' oper_expr |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
931 { $$ = make_binary_op ('-', $1, $2, $3); } |
12627
002948ae5bc0
fix precedence level of transpose operators (bug #32533)
John W. Eaton <jwe@octave.org>
parents:
12483
diff
changeset
|
932 | oper_expr '*' oper_expr |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
933 { $$ = make_binary_op ('*', $1, $2, $3); } |
12627
002948ae5bc0
fix precedence level of transpose operators (bug #32533)
John W. Eaton <jwe@octave.org>
parents:
12483
diff
changeset
|
934 | oper_expr '/' oper_expr |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
935 { $$ = make_binary_op ('/', $1, $2, $3); } |
12627
002948ae5bc0
fix precedence level of transpose operators (bug #32533)
John W. Eaton <jwe@octave.org>
parents:
12483
diff
changeset
|
936 | oper_expr EPLUS oper_expr |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
937 { $$ = make_binary_op ('+', $1, $2, $3); } |
12627
002948ae5bc0
fix precedence level of transpose operators (bug #32533)
John W. Eaton <jwe@octave.org>
parents:
12483
diff
changeset
|
938 | oper_expr EMINUS oper_expr |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
939 { $$ = make_binary_op ('-', $1, $2, $3); } |
12627
002948ae5bc0
fix precedence level of transpose operators (bug #32533)
John W. Eaton <jwe@octave.org>
parents:
12483
diff
changeset
|
940 | oper_expr EMUL oper_expr |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
941 { $$ = make_binary_op (EMUL, $1, $2, $3); } |
12627
002948ae5bc0
fix precedence level of transpose operators (bug #32533)
John W. Eaton <jwe@octave.org>
parents:
12483
diff
changeset
|
942 | oper_expr EDIV oper_expr |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
943 { $$ = make_binary_op (EDIV, $1, $2, $3); } |
12627
002948ae5bc0
fix precedence level of transpose operators (bug #32533)
John W. Eaton <jwe@octave.org>
parents:
12483
diff
changeset
|
944 | oper_expr LEFTDIV oper_expr |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
945 { $$ = make_binary_op (LEFTDIV, $1, $2, $3); } |
12627
002948ae5bc0
fix precedence level of transpose operators (bug #32533)
John W. Eaton <jwe@octave.org>
parents:
12483
diff
changeset
|
946 | oper_expr ELEFTDIV oper_expr |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
947 { $$ = make_binary_op (ELEFTDIV, $1, $2, $3); } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
948 ; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
949 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
950 colon_expr : colon_expr1 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
951 { $$ = finish_colon_expression ($1); } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
952 ; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
953 |
12627
002948ae5bc0
fix precedence level of transpose operators (bug #32533)
John W. Eaton <jwe@octave.org>
parents:
12483
diff
changeset
|
954 colon_expr1 : oper_expr |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
955 { $$ = new tree_colon_expression ($1); } |
12627
002948ae5bc0
fix precedence level of transpose operators (bug #32533)
John W. Eaton <jwe@octave.org>
parents:
12483
diff
changeset
|
956 | colon_expr1 ':' oper_expr |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
957 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
958 if (! ($$ = $1->append ($3))) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
959 ABORT_PARSE; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
960 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
961 ; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
962 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
963 simple_expr : colon_expr |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
964 { $$ = $1; } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
965 | simple_expr LSHIFT simple_expr |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
966 { $$ = make_binary_op (LSHIFT, $1, $2, $3); } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
967 | simple_expr RSHIFT simple_expr |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
968 { $$ = make_binary_op (RSHIFT, $1, $2, $3); } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
969 | simple_expr EXPR_LT simple_expr |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
970 { $$ = make_binary_op (EXPR_LT, $1, $2, $3); } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
971 | simple_expr EXPR_LE simple_expr |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
972 { $$ = make_binary_op (EXPR_LE, $1, $2, $3); } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
973 | simple_expr EXPR_EQ simple_expr |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
974 { $$ = make_binary_op (EXPR_EQ, $1, $2, $3); } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
975 | simple_expr EXPR_GE simple_expr |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
976 { $$ = make_binary_op (EXPR_GE, $1, $2, $3); } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
977 | simple_expr EXPR_GT simple_expr |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
978 { $$ = make_binary_op (EXPR_GT, $1, $2, $3); } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
979 | simple_expr EXPR_NE simple_expr |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
980 { $$ = make_binary_op (EXPR_NE, $1, $2, $3); } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
981 | simple_expr EXPR_AND simple_expr |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
982 { $$ = make_binary_op (EXPR_AND, $1, $2, $3); } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
983 | simple_expr EXPR_OR simple_expr |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
984 { $$ = make_binary_op (EXPR_OR, $1, $2, $3); } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
985 | simple_expr EXPR_AND_AND simple_expr |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
986 { $$ = make_boolean_op (EXPR_AND_AND, $1, $2, $3); } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
987 | simple_expr EXPR_OR_OR simple_expr |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
988 { $$ = make_boolean_op (EXPR_OR_OR, $1, $2, $3); } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
989 ; |
2970 | 990 |
991 // Arrange for the lexer to return CLOSE_BRACE for `]' by looking ahead | |
992 // one token for an assignment op. | |
993 | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
994 assign_lhs : simple_expr |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
995 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
996 $$ = new tree_argument_list ($1); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
997 $$->mark_as_simple_assign_lhs (); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
998 } |
14533
e6aa044253eb
Allow comma at the end of an assignment list (bug #35645)
Max Brister <max@2bass.com>
parents:
14512
diff
changeset
|
999 | '[' arg_list opt_comma CLOSE_BRACE |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1000 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1001 $$ = $2; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1002 lexer_flags.looking_at_matrix_or_assign_lhs = false; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1003 for (std::set<std::string>::const_iterator p = lexer_flags.pending_local_variables.begin (); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1004 p != lexer_flags.pending_local_variables.end (); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1005 p++) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1006 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1007 symbol_table::force_variable (*p); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1008 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1009 lexer_flags.pending_local_variables.clear (); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1010 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1011 ; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1012 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1013 assign_expr : assign_lhs '=' expression |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1014 { $$ = make_assign_op ('=', $1, $2, $3); } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1015 | assign_lhs ADD_EQ expression |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1016 { $$ = make_assign_op (ADD_EQ, $1, $2, $3); } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1017 | assign_lhs SUB_EQ expression |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1018 { $$ = make_assign_op (SUB_EQ, $1, $2, $3); } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1019 | assign_lhs MUL_EQ expression |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1020 { $$ = make_assign_op (MUL_EQ, $1, $2, $3); } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1021 | assign_lhs DIV_EQ expression |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1022 { $$ = make_assign_op (DIV_EQ, $1, $2, $3); } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1023 | assign_lhs LEFTDIV_EQ expression |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1024 { $$ = make_assign_op (LEFTDIV_EQ, $1, $2, $3); } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1025 | assign_lhs POW_EQ expression |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1026 { $$ = make_assign_op (POW_EQ, $1, $2, $3); } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1027 | assign_lhs LSHIFT_EQ expression |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1028 { $$ = make_assign_op (LSHIFT_EQ, $1, $2, $3); } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1029 | assign_lhs RSHIFT_EQ expression |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1030 { $$ = make_assign_op (RSHIFT_EQ, $1, $2, $3); } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1031 | assign_lhs EMUL_EQ expression |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1032 { $$ = make_assign_op (EMUL_EQ, $1, $2, $3); } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1033 | assign_lhs EDIV_EQ expression |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1034 { $$ = make_assign_op (EDIV_EQ, $1, $2, $3); } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1035 | assign_lhs ELEFTDIV_EQ expression |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1036 { $$ = make_assign_op (ELEFTDIV_EQ, $1, $2, $3); } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1037 | assign_lhs EPOW_EQ expression |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1038 { $$ = make_assign_op (EPOW_EQ, $1, $2, $3); } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1039 | assign_lhs AND_EQ expression |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1040 { $$ = make_assign_op (AND_EQ, $1, $2, $3); } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1041 | assign_lhs OR_EQ expression |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1042 { $$ = make_assign_op (OR_EQ, $1, $2, $3); } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1043 ; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1044 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1045 expression : simple_expr |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1046 { $$ = $1; } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1047 | assign_expr |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1048 { $$ = $1; } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1049 | anon_fcn_handle |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1050 { $$ = $1; } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1051 ; |
2970 | 1052 |
1053 // ================================================ | |
1054 // Commands, declarations, and function definitions | |
1055 // ================================================ | |
1056 | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1057 command : declaration |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1058 { $$ = $1; } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1059 | select_command |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1060 { $$ = $1; } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1061 | loop_command |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1062 { $$ = $1; } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1063 | jump_command |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1064 { $$ = $1; } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1065 | except_command |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1066 { $$ = $1; } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1067 | function |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1068 { $$ = $1; } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1069 | script_file |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1070 { $$ = $1; } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1071 ; |
2970 | 1072 |
1073 // ===================== | |
1074 // Declaration statemnts | |
1075 // ===================== | |
1076 | |
8701
1652e39b934e
handle command names in declaration lists
John W. Eaton <jwe@octave.org>
parents:
8697
diff
changeset
|
1077 parsing_decl_list |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1078 : // empty |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1079 { lexer_flags.looking_at_decl_list = true; } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1080 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1081 declaration : GLOBAL parsing_decl_list decl1 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1082 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1083 $$ = make_decl_command (GLOBAL, $1, $3); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1084 lexer_flags.looking_at_decl_list = false; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1085 } |
14294
9e3983c8963c
deprecate the static keyword
John W. Eaton <jwe@octave.org>
parents:
14293
diff
changeset
|
1086 | PERSISTENT parsing_decl_list decl1 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1087 { |
14294
9e3983c8963c
deprecate the static keyword
John W. Eaton <jwe@octave.org>
parents:
14293
diff
changeset
|
1088 $$ = make_decl_command (PERSISTENT, $1, $3); |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1089 lexer_flags.looking_at_decl_list = false; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1090 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1091 ; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1092 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1093 decl1 : decl2 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1094 { $$ = new tree_decl_init_list ($1); } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1095 | decl1 decl2 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1096 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1097 $1->append ($2); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1098 $$ = $1; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1099 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1100 ; |
2970 | 1101 |
7634
ae90e05ad299
fix parameter list initializer bug
John W. Eaton <jwe@octave.org>
parents:
7587
diff
changeset
|
1102 decl_param_init : // empty |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1103 { lexer_flags.looking_at_initializer_expression = true; } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1104 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1105 decl2 : identifier |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1106 { $$ = new tree_decl_elt ($1); } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1107 | identifier '=' decl_param_init expression |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1108 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1109 lexer_flags.looking_at_initializer_expression = false; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1110 $$ = new tree_decl_elt ($1, $4); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1111 } |
10206
37a08e0ce2dc
support Matlab-style empty output/input arguments
Jaroslav Hajek <highegg@gmail.com>
parents:
10188
diff
changeset
|
1112 | magic_tilde |
37a08e0ce2dc
support Matlab-style empty output/input arguments
Jaroslav Hajek <highegg@gmail.com>
parents:
10188
diff
changeset
|
1113 { |
37a08e0ce2dc
support Matlab-style empty output/input arguments
Jaroslav Hajek <highegg@gmail.com>
parents:
10188
diff
changeset
|
1114 $$ = new tree_decl_elt ($1); |
37a08e0ce2dc
support Matlab-style empty output/input arguments
Jaroslav Hajek <highegg@gmail.com>
parents:
10188
diff
changeset
|
1115 } |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1116 ; |
2970 | 1117 |
1118 // ==================== | |
1119 // Selection statements | |
1120 // ==================== | |
1121 | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1122 select_command : if_command |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1123 { $$ = $1; } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1124 | switch_command |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1125 { $$ = $1; } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1126 ; |
2970 | 1127 |
1128 // ============ | |
1129 // If statement | |
1130 // ============ | |
1131 | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1132 if_command : IF stash_comment if_cmd_list END |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1133 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1134 if (! ($$ = finish_if_command ($1, $3, $4, $2))) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1135 ABORT_PARSE; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1136 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1137 ; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1138 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1139 if_cmd_list : if_cmd_list1 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1140 { $$ = $1; } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1141 | if_cmd_list1 else_clause |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1142 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1143 $1->append ($2); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1144 $$ = $1; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1145 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1146 ; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1147 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1148 if_cmd_list1 : expression opt_sep opt_list |
11091
5677f3f7b5fa
Matlab compatible short-circuit behavior for & and | operators
John W. Eaton <jwe@octave.org>
parents:
11060
diff
changeset
|
1149 { |
5677f3f7b5fa
Matlab compatible short-circuit behavior for & and | operators
John W. Eaton <jwe@octave.org>
parents:
11060
diff
changeset
|
1150 $1->mark_braindead_shortcircuit (curr_fcn_file_full_name); |
5677f3f7b5fa
Matlab compatible short-circuit behavior for & and | operators
John W. Eaton <jwe@octave.org>
parents:
11060
diff
changeset
|
1151 |
5677f3f7b5fa
Matlab compatible short-circuit behavior for & and | operators
John W. Eaton <jwe@octave.org>
parents:
11060
diff
changeset
|
1152 $$ = start_if_command ($1, $3); |
5677f3f7b5fa
Matlab compatible short-circuit behavior for & and | operators
John W. Eaton <jwe@octave.org>
parents:
11060
diff
changeset
|
1153 } |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1154 | if_cmd_list1 elseif_clause |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1155 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1156 $1->append ($2); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1157 $$ = $1; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1158 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1159 ; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1160 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1161 elseif_clause : ELSEIF stash_comment opt_sep expression opt_sep opt_list |
11091
5677f3f7b5fa
Matlab compatible short-circuit behavior for & and | operators
John W. Eaton <jwe@octave.org>
parents:
11060
diff
changeset
|
1162 { |
5677f3f7b5fa
Matlab compatible short-circuit behavior for & and | operators
John W. Eaton <jwe@octave.org>
parents:
11060
diff
changeset
|
1163 $4->mark_braindead_shortcircuit (curr_fcn_file_full_name); |
5677f3f7b5fa
Matlab compatible short-circuit behavior for & and | operators
John W. Eaton <jwe@octave.org>
parents:
11060
diff
changeset
|
1164 |
5677f3f7b5fa
Matlab compatible short-circuit behavior for & and | operators
John W. Eaton <jwe@octave.org>
parents:
11060
diff
changeset
|
1165 $$ = make_elseif_clause ($1, $4, $6, $2); |
5677f3f7b5fa
Matlab compatible short-circuit behavior for & and | operators
John W. Eaton <jwe@octave.org>
parents:
11060
diff
changeset
|
1166 } |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1167 ; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1168 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1169 else_clause : ELSE stash_comment opt_sep opt_list |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1170 { $$ = new tree_if_clause ($4, $2); } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1171 ; |
2970 | 1172 |
1173 // ================ | |
1174 // Switch statement | |
1175 // ================ | |
1176 | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1177 switch_command : SWITCH stash_comment expression opt_sep case_list END |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1178 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1179 if (! ($$ = finish_switch_command ($1, $3, $5, $6, $2))) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1180 ABORT_PARSE; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1181 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1182 ; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1183 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1184 case_list : // empty |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1185 { $$ = new tree_switch_case_list (); } |
11317
2da532d0f41c
accept otherwise clause in switch statement without preceding case statements
John W. Eaton <jwe@octave.org>
parents:
11258
diff
changeset
|
1186 | default_case |
2da532d0f41c
accept otherwise clause in switch statement without preceding case statements
John W. Eaton <jwe@octave.org>
parents:
11258
diff
changeset
|
1187 { $$ = new tree_switch_case_list ($1); } |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1188 | case_list1 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1189 { $$ = $1; } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1190 | case_list1 default_case |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1191 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1192 $1->append ($2); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1193 $$ = $1; |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11572
diff
changeset
|
1194 } |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1195 ; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1196 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1197 case_list1 : switch_case |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1198 { $$ = new tree_switch_case_list ($1); } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1199 | case_list1 switch_case |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1200 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1201 $1->append ($2); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1202 $$ = $1; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1203 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1204 ; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1205 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1206 switch_case : CASE stash_comment opt_sep expression opt_sep opt_list |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1207 { $$ = make_switch_case ($1, $4, $6, $2); } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1208 ; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1209 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1210 default_case : OTHERWISE stash_comment opt_sep opt_list |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1211 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1212 $$ = new tree_switch_case ($4, $2); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1213 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1214 ; |
2970 | 1215 |
1216 // ======= | |
1217 // Looping | |
1218 // ======= | |
1219 | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1220 loop_command : WHILE stash_comment expression opt_sep opt_list END |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1221 { |
11091
5677f3f7b5fa
Matlab compatible short-circuit behavior for & and | operators
John W. Eaton <jwe@octave.org>
parents:
11060
diff
changeset
|
1222 $3->mark_braindead_shortcircuit (curr_fcn_file_full_name); |
5677f3f7b5fa
Matlab compatible short-circuit behavior for & and | operators
John W. Eaton <jwe@octave.org>
parents:
11060
diff
changeset
|
1223 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1224 if (! ($$ = make_while_command ($1, $3, $5, $6, $2))) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1225 ABORT_PARSE; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1226 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1227 | DO stash_comment opt_sep opt_list UNTIL expression |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1228 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1229 if (! ($$ = make_do_until_command ($5, $4, $6, $2))) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1230 ABORT_PARSE; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1231 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1232 | FOR stash_comment assign_lhs '=' expression opt_sep opt_list END |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1233 { |
13245
027a2186cd90
parfor keyword and infrastructure, but handle parfor as normal for loop for now
John W. Eaton <jwe@octave.org>
parents:
13241
diff
changeset
|
1234 if (! ($$ = make_for_command (FOR, $1, $3, $5, 0, |
027a2186cd90
parfor keyword and infrastructure, but handle parfor as normal for loop for now
John W. Eaton <jwe@octave.org>
parents:
13241
diff
changeset
|
1235 $7, $8, $2))) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1236 ABORT_PARSE; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1237 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1238 | FOR stash_comment '(' assign_lhs '=' expression ')' opt_sep opt_list END |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1239 { |
13245
027a2186cd90
parfor keyword and infrastructure, but handle parfor as normal for loop for now
John W. Eaton <jwe@octave.org>
parents:
13241
diff
changeset
|
1240 if (! ($$ = make_for_command (FOR, $1, $4, $6, 0, |
027a2186cd90
parfor keyword and infrastructure, but handle parfor as normal for loop for now
John W. Eaton <jwe@octave.org>
parents:
13241
diff
changeset
|
1241 $9, $10, $2))) |
027a2186cd90
parfor keyword and infrastructure, but handle parfor as normal for loop for now
John W. Eaton <jwe@octave.org>
parents:
13241
diff
changeset
|
1242 ABORT_PARSE; |
027a2186cd90
parfor keyword and infrastructure, but handle parfor as normal for loop for now
John W. Eaton <jwe@octave.org>
parents:
13241
diff
changeset
|
1243 } |
027a2186cd90
parfor keyword and infrastructure, but handle parfor as normal for loop for now
John W. Eaton <jwe@octave.org>
parents:
13241
diff
changeset
|
1244 | PARFOR stash_comment assign_lhs '=' expression opt_sep opt_list END |
027a2186cd90
parfor keyword and infrastructure, but handle parfor as normal for loop for now
John W. Eaton <jwe@octave.org>
parents:
13241
diff
changeset
|
1245 { |
027a2186cd90
parfor keyword and infrastructure, but handle parfor as normal for loop for now
John W. Eaton <jwe@octave.org>
parents:
13241
diff
changeset
|
1246 if (! ($$ = make_for_command (PARFOR, $1, $3, $5, |
027a2186cd90
parfor keyword and infrastructure, but handle parfor as normal for loop for now
John W. Eaton <jwe@octave.org>
parents:
13241
diff
changeset
|
1247 0, $7, $8, $2))) |
027a2186cd90
parfor keyword and infrastructure, but handle parfor as normal for loop for now
John W. Eaton <jwe@octave.org>
parents:
13241
diff
changeset
|
1248 ABORT_PARSE; |
027a2186cd90
parfor keyword and infrastructure, but handle parfor as normal for loop for now
John W. Eaton <jwe@octave.org>
parents:
13241
diff
changeset
|
1249 } |
027a2186cd90
parfor keyword and infrastructure, but handle parfor as normal for loop for now
John W. Eaton <jwe@octave.org>
parents:
13241
diff
changeset
|
1250 | PARFOR stash_comment '(' assign_lhs '=' expression ',' expression ')' opt_sep opt_list END |
027a2186cd90
parfor keyword and infrastructure, but handle parfor as normal for loop for now
John W. Eaton <jwe@octave.org>
parents:
13241
diff
changeset
|
1251 { |
027a2186cd90
parfor keyword and infrastructure, but handle parfor as normal for loop for now
John W. Eaton <jwe@octave.org>
parents:
13241
diff
changeset
|
1252 if (! ($$ = make_for_command (PARFOR, $1, $4, $6, |
027a2186cd90
parfor keyword and infrastructure, but handle parfor as normal for loop for now
John W. Eaton <jwe@octave.org>
parents:
13241
diff
changeset
|
1253 $8, $11, $12, $2))) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1254 ABORT_PARSE; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1255 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1256 ; |
2970 | 1257 |
1258 // ======= | |
1259 // Jumping | |
1260 // ======= | |
1261 | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1262 jump_command : BREAK |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1263 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1264 if (! ($$ = make_break_command ($1))) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1265 ABORT_PARSE; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1266 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1267 | CONTINUE |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1268 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1269 if (! ($$ = make_continue_command ($1))) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1270 ABORT_PARSE; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1271 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1272 | FUNC_RET |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1273 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1274 if (! ($$ = make_return_command ($1))) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1275 ABORT_PARSE; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1276 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1277 ; |
2970 | 1278 |
1279 // ========== | |
1280 // Exceptions | |
1281 // ========== | |
1282 | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1283 except_command : UNWIND stash_comment opt_sep opt_list CLEANUP |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1284 stash_comment opt_sep opt_list END |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1285 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1286 if (! ($$ = make_unwind_command ($1, $4, $8, $9, $2, $6))) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1287 ABORT_PARSE; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1288 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1289 | TRY stash_comment opt_sep opt_list CATCH |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1290 stash_comment opt_sep opt_list END |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1291 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1292 if (! ($$ = make_try_command ($1, $4, $8, $9, $2, $6))) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1293 ABORT_PARSE; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1294 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1295 | TRY stash_comment opt_sep opt_list END |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1296 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1297 if (! ($$ = make_try_command ($1, $4, 0, $5, $2, 0))) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1298 ABORT_PARSE; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1299 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1300 ; |
2970 | 1301 |
1302 // =========================================== | |
1303 // Some `subroutines' for function definitions | |
1304 // =========================================== | |
1305 | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1306 push_fcn_symtab : // empty |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1307 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1308 current_function_depth++; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1309 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1310 if (max_function_depth < current_function_depth) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1311 max_function_depth = current_function_depth; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1312 |
14329
8d1ae996c122
also save and restore symbol table context in parser (bug #35448)
John W. Eaton <jwe@octave.org>
parents:
14294
diff
changeset
|
1313 parser_symtab_context.push (); |
8d1ae996c122
also save and restore symbol table context in parser (bug #35448)
John W. Eaton <jwe@octave.org>
parents:
14294
diff
changeset
|
1314 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1315 symbol_table::set_scope (symbol_table::alloc_scope ()); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1316 |
14544
be18c9e359bf
Nested function support (bug #35772)
Max Brister <max@2bass.com>
parents:
14533
diff
changeset
|
1317 function_scopes.push_back (symbol_table::current_scope ()); |
be18c9e359bf
Nested function support (bug #35772)
Max Brister <max@2bass.com>
parents:
14533
diff
changeset
|
1318 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1319 if (! reading_script_file && current_function_depth == 1 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1320 && ! parsing_subfunctions) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1321 primary_fcn_scope = symbol_table::current_scope (); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1322 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1323 if (reading_script_file && current_function_depth > 1) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1324 yyerror ("nested functions not implemented in this context"); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1325 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1326 ; |
2970 | 1327 |
1328 // =========================== | |
1329 // List of function parameters | |
1330 // =========================== | |
1331 | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1332 param_list_beg : '(' |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1333 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1334 lexer_flags.looking_at_parameter_list = true; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1335 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1336 if (lexer_flags.looking_at_function_handle) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1337 { |
14329
8d1ae996c122
also save and restore symbol table context in parser (bug #35448)
John W. Eaton <jwe@octave.org>
parents:
14294
diff
changeset
|
1338 parser_symtab_context.push (); |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1339 symbol_table::set_scope (symbol_table::alloc_scope ()); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1340 lexer_flags.looking_at_function_handle--; |
13237
1bfca2bbea8b
fix parsing of anonymous functions inside cell array lists.
John W. Eaton <jwe@octave.org>
parents:
13125
diff
changeset
|
1341 lexer_flags.looking_at_anon_fcn_args = true; |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1342 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1343 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1344 ; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1345 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1346 param_list_end : ')' |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1347 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1348 lexer_flags.looking_at_parameter_list = false; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1349 lexer_flags.looking_for_object_index = false; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1350 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1351 ; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1352 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1353 param_list : param_list_beg param_list1 param_list_end |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1354 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1355 lexer_flags.quote_is_transpose = false; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1356 $$ = $2; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1357 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1358 | param_list_beg error |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1359 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1360 yyerror ("invalid parameter list"); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1361 $$ = 0; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1362 ABORT_PARSE; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1363 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1364 ; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1365 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1366 param_list1 : // empty |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1367 { $$ = 0; } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1368 | param_list2 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1369 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1370 $1->mark_as_formal_parameters (); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1371 if ($1->validate (tree_parameter_list::in)) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1372 $$ = $1; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1373 else |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1374 ABORT_PARSE; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1375 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1376 ; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1377 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1378 param_list2 : decl2 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1379 { $$ = new tree_parameter_list ($1); } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1380 | param_list2 ',' decl2 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1381 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1382 $1->append ($3); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1383 $$ = $1; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1384 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1385 ; |
2970 | 1386 |
1387 // =================================== | |
1388 // List of function return value names | |
1389 // =================================== | |
1390 | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1391 return_list : '[' ']' |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1392 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1393 lexer_flags.looking_at_return_list = false; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1394 $$ = new tree_parameter_list (); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1395 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1396 | return_list1 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1397 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1398 lexer_flags.looking_at_return_list = false; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1399 if ($1->validate (tree_parameter_list::out)) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1400 $$ = $1; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1401 else |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1402 ABORT_PARSE; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1403 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1404 | '[' return_list1 ']' |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1405 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1406 lexer_flags.looking_at_return_list = false; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1407 if ($2->validate (tree_parameter_list::out)) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1408 $$ = $2; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1409 else |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1410 ABORT_PARSE; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1411 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1412 ; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1413 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1414 return_list1 : identifier |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1415 { $$ = new tree_parameter_list (new tree_decl_elt ($1)); } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1416 | return_list1 ',' identifier |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1417 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1418 $1->append (new tree_decl_elt ($3)); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1419 $$ = $1; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1420 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1421 ; |
2970 | 1422 |
7715
5b4d278ec828
parse scripts completely before executing
John W. Eaton <jwe@octave.org>
parents:
7699
diff
changeset
|
1423 // =========== |
5b4d278ec828
parse scripts completely before executing
John W. Eaton <jwe@octave.org>
parents:
7699
diff
changeset
|
1424 // Script file |
5b4d278ec828
parse scripts completely before executing
John W. Eaton <jwe@octave.org>
parents:
7699
diff
changeset
|
1425 // =========== |
5b4d278ec828
parse scripts completely before executing
John W. Eaton <jwe@octave.org>
parents:
7699
diff
changeset
|
1426 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1427 script_file : SCRIPT_FILE opt_list END_OF_INPUT |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1428 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1429 tree_statement *end_of_script |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1430 = make_end ("endscript", input_line_number, |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1431 current_input_column); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1432 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1433 make_script ($2, end_of_script); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1434 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1435 $$ = 0; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1436 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1437 ; |
7715
5b4d278ec828
parse scripts completely before executing
John W. Eaton <jwe@octave.org>
parents:
7699
diff
changeset
|
1438 |
9474
25ed2d6aacf6
Parse nested functions more accurately.
David Grundberg <individ@acc.umu.se>
parents:
9471
diff
changeset
|
1439 // ============= |
25ed2d6aacf6
Parse nested functions more accurately.
David Grundberg <individ@acc.umu.se>
parents:
9471
diff
changeset
|
1440 // Function file |
25ed2d6aacf6
Parse nested functions more accurately.
David Grundberg <individ@acc.umu.se>
parents:
9471
diff
changeset
|
1441 // ============= |
25ed2d6aacf6
Parse nested functions more accurately.
David Grundberg <individ@acc.umu.se>
parents:
9471
diff
changeset
|
1442 |
25ed2d6aacf6
Parse nested functions more accurately.
David Grundberg <individ@acc.umu.se>
parents:
9471
diff
changeset
|
1443 function_file : FUNCTION_FILE function_list opt_sep END_OF_INPUT |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1444 { $$ = 0; } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1445 ; |
9474
25ed2d6aacf6
Parse nested functions more accurately.
David Grundberg <individ@acc.umu.se>
parents:
9471
diff
changeset
|
1446 |
25ed2d6aacf6
Parse nested functions more accurately.
David Grundberg <individ@acc.umu.se>
parents:
9471
diff
changeset
|
1447 function_list : function |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1448 | function_list sep function |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1449 ; |
9474
25ed2d6aacf6
Parse nested functions more accurately.
David Grundberg <individ@acc.umu.se>
parents:
9471
diff
changeset
|
1450 |
2970 | 1451 // =================== |
1452 // Function definition | |
1453 // =================== | |
1454 | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1455 function_beg : push_fcn_symtab FCN stash_comment |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1456 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1457 $$ = $3; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1458 |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11572
diff
changeset
|
1459 if (reading_classdef_file || lexer_flags.parsing_classdef) |
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11572
diff
changeset
|
1460 lexer_flags.maybe_classdef_get_set_method = true; |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1461 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1462 ; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1463 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1464 function : function_beg function1 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1465 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1466 $$ = finish_function (0, $2, $1); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1467 recover_from_parsing_function (); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1468 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1469 | function_beg return_list '=' function1 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1470 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1471 $$ = finish_function ($2, $4, $1); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1472 recover_from_parsing_function (); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1473 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1474 ; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1475 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1476 fcn_name : identifier |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1477 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1478 std::string id_name = $1->name (); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1479 |
11464
21b5284fa78d
avoid error when parsing nested functions
John W. Eaton <jwe@octave.org>
parents:
11461
diff
changeset
|
1480 lexer_flags.parsed_function_name.top () = true; |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1481 lexer_flags.maybe_classdef_get_set_method = false; |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11572
diff
changeset
|
1482 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1483 $$ = $1; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1484 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1485 | GET '.' identifier |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1486 { |
14293
71a198cca35b
improve parsing of classdef methods
John W. Eaton <jwe@octave.org>
parents:
14189
diff
changeset
|
1487 lexer_flags.parsed_function_name.top () = true; |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1488 lexer_flags.maybe_classdef_get_set_method = false; |
15037
56b8eb7c9c04
improvements in parsing classdef
John W. Eaton <jwe@octave.org>
parents:
14846
diff
changeset
|
1489 lexer_flags.parsing_classdef_get_method = true; |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1490 $$ = $3; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1491 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1492 | SET '.' identifier |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1493 { |
14293
71a198cca35b
improve parsing of classdef methods
John W. Eaton <jwe@octave.org>
parents:
14189
diff
changeset
|
1494 lexer_flags.parsed_function_name.top () = true; |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1495 lexer_flags.maybe_classdef_get_set_method = false; |
15037
56b8eb7c9c04
improvements in parsing classdef
John W. Eaton <jwe@octave.org>
parents:
14846
diff
changeset
|
1496 lexer_flags.parsing_classdef_set_method = true; |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1497 $$ = $3; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1498 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1499 ; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1500 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1501 function1 : fcn_name function2 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1502 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1503 std::string fname = $1->name (); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1504 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1505 delete $1; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1506 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1507 if (! ($$ = frob_function (fname, $2))) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1508 ABORT_PARSE; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1509 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1510 ; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1511 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1512 function2 : param_list opt_sep opt_list function_end |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1513 { $$ = start_function ($1, $3, $4); } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1514 | opt_sep opt_list function_end |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1515 { $$ = start_function (0, $2, $3); } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1516 ; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1517 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1518 function_end : END |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1519 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1520 endfunction_found = true; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1521 if (end_token_ok ($1, token::function_end)) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1522 $$ = make_end ("endfunction", $1->line (), $1->column ()); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1523 else |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1524 ABORT_PARSE; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1525 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1526 | END_OF_INPUT |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1527 { |
9474
25ed2d6aacf6
Parse nested functions more accurately.
David Grundberg <individ@acc.umu.se>
parents:
9471
diff
changeset
|
1528 // A lot of tests are based on the assumption that this is OK |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1529 // if (reading_script_file) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1530 // { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1531 // yyerror ("function body open at end of script"); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1532 // YYABORT; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1533 // } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1534 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1535 if (endfunction_found) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1536 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1537 yyerror ("inconsistent function endings -- " |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1538 "if one function is explicitly ended, " |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1539 "so must all the others"); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1540 YYABORT; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1541 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1542 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1543 if (! (reading_fcn_file || reading_script_file |
10130
0c3609dd34cf
oct-parse.yy (eval_string): save and set reading_{script,fcn,classdef}_file vars
John W. Eaton <jwe@octave.org>
parents:
10067
diff
changeset
|
1544 || get_input_from_eval_string)) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1545 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1546 yyerror ("function body open at end of input"); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1547 YYABORT; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1548 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1549 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1550 if (reading_classdef_file) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1551 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1552 yyerror ("classdef body open at end of input"); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1553 YYABORT; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1554 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1555 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1556 $$ = make_end ("endfunction", input_line_number, |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1557 current_input_column); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1558 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1559 ; |
2970 | 1560 |
15037
56b8eb7c9c04
improvements in parsing classdef
John W. Eaton <jwe@octave.org>
parents:
14846
diff
changeset
|
1561 // ============= |
56b8eb7c9c04
improvements in parsing classdef
John W. Eaton <jwe@octave.org>
parents:
14846
diff
changeset
|
1562 // Classdef file |
56b8eb7c9c04
improvements in parsing classdef
John W. Eaton <jwe@octave.org>
parents:
14846
diff
changeset
|
1563 // ============= |
56b8eb7c9c04
improvements in parsing classdef
John W. Eaton <jwe@octave.org>
parents:
14846
diff
changeset
|
1564 |
56b8eb7c9c04
improvements in parsing classdef
John W. Eaton <jwe@octave.org>
parents:
14846
diff
changeset
|
1565 classdef_file : CLASSDEF_FILE classdef opt_sep END_OF_INPUT |
56b8eb7c9c04
improvements in parsing classdef
John W. Eaton <jwe@octave.org>
parents:
14846
diff
changeset
|
1566 { |
56b8eb7c9c04
improvements in parsing classdef
John W. Eaton <jwe@octave.org>
parents:
14846
diff
changeset
|
1567 classdef_object = $2; |
56b8eb7c9c04
improvements in parsing classdef
John W. Eaton <jwe@octave.org>
parents:
14846
diff
changeset
|
1568 $$ = 0; |
56b8eb7c9c04
improvements in parsing classdef
John W. Eaton <jwe@octave.org>
parents:
14846
diff
changeset
|
1569 } |
56b8eb7c9c04
improvements in parsing classdef
John W. Eaton <jwe@octave.org>
parents:
14846
diff
changeset
|
1570 ; |
56b8eb7c9c04
improvements in parsing classdef
John W. Eaton <jwe@octave.org>
parents:
14846
diff
changeset
|
1571 |
9476 | 1572 // ======== |
1573 // Classdef | |
1574 // ======== | |
1575 | |
15037
56b8eb7c9c04
improvements in parsing classdef
John W. Eaton <jwe@octave.org>
parents:
14846
diff
changeset
|
1576 classdef_beg : CLASSDEF |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1577 { |
15037
56b8eb7c9c04
improvements in parsing classdef
John W. Eaton <jwe@octave.org>
parents:
14846
diff
changeset
|
1578 if (! reading_classdef_file) |
56b8eb7c9c04
improvements in parsing classdef
John W. Eaton <jwe@octave.org>
parents:
14846
diff
changeset
|
1579 { |
56b8eb7c9c04
improvements in parsing classdef
John W. Eaton <jwe@octave.org>
parents:
14846
diff
changeset
|
1580 yyerror ("classdef must appear inside a file containing only a class definition"); |
56b8eb7c9c04
improvements in parsing classdef
John W. Eaton <jwe@octave.org>
parents:
14846
diff
changeset
|
1581 YYABORT; |
56b8eb7c9c04
improvements in parsing classdef
John W. Eaton <jwe@octave.org>
parents:
14846
diff
changeset
|
1582 } |
56b8eb7c9c04
improvements in parsing classdef
John W. Eaton <jwe@octave.org>
parents:
14846
diff
changeset
|
1583 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1584 lexer_flags.parsing_classdef = true; |
15037
56b8eb7c9c04
improvements in parsing classdef
John W. Eaton <jwe@octave.org>
parents:
14846
diff
changeset
|
1585 $$ = $1; |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1586 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1587 ; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1588 |
15037
56b8eb7c9c04
improvements in parsing classdef
John W. Eaton <jwe@octave.org>
parents:
14846
diff
changeset
|
1589 classdef : classdef_beg stash_comment opt_attr_list identifier opt_superclass_list opt_sep class_body opt_sep END |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1590 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1591 lexer_flags.parsing_classdef = false; |
15037
56b8eb7c9c04
improvements in parsing classdef
John W. Eaton <jwe@octave.org>
parents:
14846
diff
changeset
|
1592 $$ = make_classdef ($1, $3, $4, $5, $7, $9, $2); |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1593 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1594 ; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1595 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1596 opt_attr_list : // empty |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1597 { $$ = 0; } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1598 | '(' attr_list ')' |
15037
56b8eb7c9c04
improvements in parsing classdef
John W. Eaton <jwe@octave.org>
parents:
14846
diff
changeset
|
1599 { $$ = $2; } |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1600 ; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1601 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1602 attr_list : attr |
15037
56b8eb7c9c04
improvements in parsing classdef
John W. Eaton <jwe@octave.org>
parents:
14846
diff
changeset
|
1603 { $$ = new tree_classdef_attribute_list ($1); } |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1604 | attr_list ',' attr |
15037
56b8eb7c9c04
improvements in parsing classdef
John W. Eaton <jwe@octave.org>
parents:
14846
diff
changeset
|
1605 { |
56b8eb7c9c04
improvements in parsing classdef
John W. Eaton <jwe@octave.org>
parents:
14846
diff
changeset
|
1606 $1->append ($3); |
56b8eb7c9c04
improvements in parsing classdef
John W. Eaton <jwe@octave.org>
parents:
14846
diff
changeset
|
1607 $$ = $1; |
56b8eb7c9c04
improvements in parsing classdef
John W. Eaton <jwe@octave.org>
parents:
14846
diff
changeset
|
1608 } |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1609 ; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1610 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1611 attr : identifier |
15037
56b8eb7c9c04
improvements in parsing classdef
John W. Eaton <jwe@octave.org>
parents:
14846
diff
changeset
|
1612 { $$ = new tree_classdef_attribute ($1); } |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1613 | identifier '=' decl_param_init expression |
15037
56b8eb7c9c04
improvements in parsing classdef
John W. Eaton <jwe@octave.org>
parents:
14846
diff
changeset
|
1614 { |
56b8eb7c9c04
improvements in parsing classdef
John W. Eaton <jwe@octave.org>
parents:
14846
diff
changeset
|
1615 lexer_flags.looking_at_initializer_expression = false; |
56b8eb7c9c04
improvements in parsing classdef
John W. Eaton <jwe@octave.org>
parents:
14846
diff
changeset
|
1616 $$ = new tree_classdef_attribute ($1, $4); |
56b8eb7c9c04
improvements in parsing classdef
John W. Eaton <jwe@octave.org>
parents:
14846
diff
changeset
|
1617 } |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1618 | EXPR_NOT identifier |
15037
56b8eb7c9c04
improvements in parsing classdef
John W. Eaton <jwe@octave.org>
parents:
14846
diff
changeset
|
1619 { $$ = new tree_classdef_attribute ($2, false); } |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1620 ; |
9476 | 1621 |
15037
56b8eb7c9c04
improvements in parsing classdef
John W. Eaton <jwe@octave.org>
parents:
14846
diff
changeset
|
1622 opt_superclass_list |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1623 : // empty |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1624 { $$ = 0; } |
15037
56b8eb7c9c04
improvements in parsing classdef
John W. Eaton <jwe@octave.org>
parents:
14846
diff
changeset
|
1625 | superclass_list |
56b8eb7c9c04
improvements in parsing classdef
John W. Eaton <jwe@octave.org>
parents:
14846
diff
changeset
|
1626 { $$ = $1; } |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1627 ; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1628 |
15037
56b8eb7c9c04
improvements in parsing classdef
John W. Eaton <jwe@octave.org>
parents:
14846
diff
changeset
|
1629 superclass_list : EXPR_LT superclass |
56b8eb7c9c04
improvements in parsing classdef
John W. Eaton <jwe@octave.org>
parents:
14846
diff
changeset
|
1630 { $$ = new tree_classdef_superclass_list ($2); } |
56b8eb7c9c04
improvements in parsing classdef
John W. Eaton <jwe@octave.org>
parents:
14846
diff
changeset
|
1631 | superclass_list EXPR_AND superclass |
56b8eb7c9c04
improvements in parsing classdef
John W. Eaton <jwe@octave.org>
parents:
14846
diff
changeset
|
1632 { |
56b8eb7c9c04
improvements in parsing classdef
John W. Eaton <jwe@octave.org>
parents:
14846
diff
changeset
|
1633 $1->append ($3); |
56b8eb7c9c04
improvements in parsing classdef
John W. Eaton <jwe@octave.org>
parents:
14846
diff
changeset
|
1634 $$ = $1; |
56b8eb7c9c04
improvements in parsing classdef
John W. Eaton <jwe@octave.org>
parents:
14846
diff
changeset
|
1635 } |
56b8eb7c9c04
improvements in parsing classdef
John W. Eaton <jwe@octave.org>
parents:
14846
diff
changeset
|
1636 ; |
56b8eb7c9c04
improvements in parsing classdef
John W. Eaton <jwe@octave.org>
parents:
14846
diff
changeset
|
1637 |
56b8eb7c9c04
improvements in parsing classdef
John W. Eaton <jwe@octave.org>
parents:
14846
diff
changeset
|
1638 superclass : identifier |
56b8eb7c9c04
improvements in parsing classdef
John W. Eaton <jwe@octave.org>
parents:
14846
diff
changeset
|
1639 { $$ = new tree_classdef_superclass ($1); } |
56b8eb7c9c04
improvements in parsing classdef
John W. Eaton <jwe@octave.org>
parents:
14846
diff
changeset
|
1640 | identifier '.' identifier |
56b8eb7c9c04
improvements in parsing classdef
John W. Eaton <jwe@octave.org>
parents:
14846
diff
changeset
|
1641 { $$ = new tree_classdef_superclass ($3, $1); } |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1642 ; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1643 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1644 class_body : properties_block |
15037
56b8eb7c9c04
improvements in parsing classdef
John W. Eaton <jwe@octave.org>
parents:
14846
diff
changeset
|
1645 { $$ = new tree_classdef_body ($1); } |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1646 | methods_block |
15037
56b8eb7c9c04
improvements in parsing classdef
John W. Eaton <jwe@octave.org>
parents:
14846
diff
changeset
|
1647 { $$ = new tree_classdef_body ($1); } |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1648 | events_block |
15037
56b8eb7c9c04
improvements in parsing classdef
John W. Eaton <jwe@octave.org>
parents:
14846
diff
changeset
|
1649 { $$ = new tree_classdef_body ($1); } |
13249
7861a5fd3479
accept enumeration keyword
John W. Eaton <jwe@octave.org>
parents:
13246
diff
changeset
|
1650 | enum_block |
15037
56b8eb7c9c04
improvements in parsing classdef
John W. Eaton <jwe@octave.org>
parents:
14846
diff
changeset
|
1651 { $$ = new tree_classdef_body ($1); } |
13250
f6bbdea030b2
use opt_sep instead of literal '\n' in parser rules for classdef
John W. Eaton <jwe@octave.org>
parents:
13249
diff
changeset
|
1652 | class_body opt_sep properties_block |
15037
56b8eb7c9c04
improvements in parsing classdef
John W. Eaton <jwe@octave.org>
parents:
14846
diff
changeset
|
1653 { |
56b8eb7c9c04
improvements in parsing classdef
John W. Eaton <jwe@octave.org>
parents:
14846
diff
changeset
|
1654 $1->append ($3); |
56b8eb7c9c04
improvements in parsing classdef
John W. Eaton <jwe@octave.org>
parents:
14846
diff
changeset
|
1655 $$ = $1; |
56b8eb7c9c04
improvements in parsing classdef
John W. Eaton <jwe@octave.org>
parents:
14846
diff
changeset
|
1656 } |
13250
f6bbdea030b2
use opt_sep instead of literal '\n' in parser rules for classdef
John W. Eaton <jwe@octave.org>
parents:
13249
diff
changeset
|
1657 | class_body opt_sep methods_block |
15037
56b8eb7c9c04
improvements in parsing classdef
John W. Eaton <jwe@octave.org>
parents:
14846
diff
changeset
|
1658 { |
56b8eb7c9c04
improvements in parsing classdef
John W. Eaton <jwe@octave.org>
parents:
14846
diff
changeset
|
1659 $1->append ($3); |
56b8eb7c9c04
improvements in parsing classdef
John W. Eaton <jwe@octave.org>
parents:
14846
diff
changeset
|
1660 $$ = $1; |
56b8eb7c9c04
improvements in parsing classdef
John W. Eaton <jwe@octave.org>
parents:
14846
diff
changeset
|
1661 } |
13250
f6bbdea030b2
use opt_sep instead of literal '\n' in parser rules for classdef
John W. Eaton <jwe@octave.org>
parents:
13249
diff
changeset
|
1662 | class_body opt_sep events_block |
15037
56b8eb7c9c04
improvements in parsing classdef
John W. Eaton <jwe@octave.org>
parents:
14846
diff
changeset
|
1663 { |
56b8eb7c9c04
improvements in parsing classdef
John W. Eaton <jwe@octave.org>
parents:
14846
diff
changeset
|
1664 $1->append ($3); |
56b8eb7c9c04
improvements in parsing classdef
John W. Eaton <jwe@octave.org>
parents:
14846
diff
changeset
|
1665 $$ = $1; |
56b8eb7c9c04
improvements in parsing classdef
John W. Eaton <jwe@octave.org>
parents:
14846
diff
changeset
|
1666 } |
13250
f6bbdea030b2
use opt_sep instead of literal '\n' in parser rules for classdef
John W. Eaton <jwe@octave.org>
parents:
13249
diff
changeset
|
1667 | class_body opt_sep enum_block |
15037
56b8eb7c9c04
improvements in parsing classdef
John W. Eaton <jwe@octave.org>
parents:
14846
diff
changeset
|
1668 { |
56b8eb7c9c04
improvements in parsing classdef
John W. Eaton <jwe@octave.org>
parents:
14846
diff
changeset
|
1669 $1->append ($3); |
56b8eb7c9c04
improvements in parsing classdef
John W. Eaton <jwe@octave.org>
parents:
14846
diff
changeset
|
1670 $$ = $1; |
56b8eb7c9c04
improvements in parsing classdef
John W. Eaton <jwe@octave.org>
parents:
14846
diff
changeset
|
1671 } |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1672 ; |
9476 | 1673 |
1674 properties_block | |
15037
56b8eb7c9c04
improvements in parsing classdef
John W. Eaton <jwe@octave.org>
parents:
14846
diff
changeset
|
1675 : PROPERTIES stash_comment opt_attr_list opt_sep property_list opt_sep END |
56b8eb7c9c04
improvements in parsing classdef
John W. Eaton <jwe@octave.org>
parents:
14846
diff
changeset
|
1676 { |
56b8eb7c9c04
improvements in parsing classdef
John W. Eaton <jwe@octave.org>
parents:
14846
diff
changeset
|
1677 if (! ($$ = make_classdef_properties_block ($1, $3, $5, $7, $2))) |
56b8eb7c9c04
improvements in parsing classdef
John W. Eaton <jwe@octave.org>
parents:
14846
diff
changeset
|
1678 ABORT_PARSE; |
56b8eb7c9c04
improvements in parsing classdef
John W. Eaton <jwe@octave.org>
parents:
14846
diff
changeset
|
1679 } |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1680 ; |
9476 | 1681 |
15037
56b8eb7c9c04
improvements in parsing classdef
John W. Eaton <jwe@octave.org>
parents:
14846
diff
changeset
|
1682 property_list |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1683 : class_property |
15037
56b8eb7c9c04
improvements in parsing classdef
John W. Eaton <jwe@octave.org>
parents:
14846
diff
changeset
|
1684 { $$ = new tree_classdef_property_list ($1); } |
56b8eb7c9c04
improvements in parsing classdef
John W. Eaton <jwe@octave.org>
parents:
14846
diff
changeset
|
1685 | property_list opt_sep class_property |
56b8eb7c9c04
improvements in parsing classdef
John W. Eaton <jwe@octave.org>
parents:
14846
diff
changeset
|
1686 { |
56b8eb7c9c04
improvements in parsing classdef
John W. Eaton <jwe@octave.org>
parents:
14846
diff
changeset
|
1687 $1->append ($3); |
56b8eb7c9c04
improvements in parsing classdef
John W. Eaton <jwe@octave.org>
parents:
14846
diff
changeset
|
1688 $$ = $1; |
56b8eb7c9c04
improvements in parsing classdef
John W. Eaton <jwe@octave.org>
parents:
14846
diff
changeset
|
1689 } |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1690 ; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1691 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1692 class_property : identifier |
15037
56b8eb7c9c04
improvements in parsing classdef
John W. Eaton <jwe@octave.org>
parents:
14846
diff
changeset
|
1693 { $$ = new tree_classdef_property ($1); } |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1694 | identifier '=' decl_param_init expression ';' |
15037
56b8eb7c9c04
improvements in parsing classdef
John W. Eaton <jwe@octave.org>
parents:
14846
diff
changeset
|
1695 { |
56b8eb7c9c04
improvements in parsing classdef
John W. Eaton <jwe@octave.org>
parents:
14846
diff
changeset
|
1696 lexer_flags.looking_at_initializer_expression = false; |
56b8eb7c9c04
improvements in parsing classdef
John W. Eaton <jwe@octave.org>
parents:
14846
diff
changeset
|
1697 $$ = new tree_classdef_property ($1, $4); |
56b8eb7c9c04
improvements in parsing classdef
John W. Eaton <jwe@octave.org>
parents:
14846
diff
changeset
|
1698 } |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1699 ; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1700 |
15037
56b8eb7c9c04
improvements in parsing classdef
John W. Eaton <jwe@octave.org>
parents:
14846
diff
changeset
|
1701 methods_block : METHODS stash_comment opt_attr_list opt_sep methods_list opt_sep END |
56b8eb7c9c04
improvements in parsing classdef
John W. Eaton <jwe@octave.org>
parents:
14846
diff
changeset
|
1702 { |
56b8eb7c9c04
improvements in parsing classdef
John W. Eaton <jwe@octave.org>
parents:
14846
diff
changeset
|
1703 if (! ($$ = make_classdef_methods_block ($1, $3, $5, $7, $2))) |
56b8eb7c9c04
improvements in parsing classdef
John W. Eaton <jwe@octave.org>
parents:
14846
diff
changeset
|
1704 ABORT_PARSE; |
56b8eb7c9c04
improvements in parsing classdef
John W. Eaton <jwe@octave.org>
parents:
14846
diff
changeset
|
1705 } |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1706 ; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1707 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1708 methods_list : function |
15037
56b8eb7c9c04
improvements in parsing classdef
John W. Eaton <jwe@octave.org>
parents:
14846
diff
changeset
|
1709 { |
56b8eb7c9c04
improvements in parsing classdef
John W. Eaton <jwe@octave.org>
parents:
14846
diff
changeset
|
1710 octave_value fcn; |
56b8eb7c9c04
improvements in parsing classdef
John W. Eaton <jwe@octave.org>
parents:
14846
diff
changeset
|
1711 if ($1) |
56b8eb7c9c04
improvements in parsing classdef
John W. Eaton <jwe@octave.org>
parents:
14846
diff
changeset
|
1712 fcn = $1->function (); |
56b8eb7c9c04
improvements in parsing classdef
John W. Eaton <jwe@octave.org>
parents:
14846
diff
changeset
|
1713 delete $1; |
56b8eb7c9c04
improvements in parsing classdef
John W. Eaton <jwe@octave.org>
parents:
14846
diff
changeset
|
1714 $$ = new tree_classdef_methods_list (fcn); |
56b8eb7c9c04
improvements in parsing classdef
John W. Eaton <jwe@octave.org>
parents:
14846
diff
changeset
|
1715 } |
13250
f6bbdea030b2
use opt_sep instead of literal '\n' in parser rules for classdef
John W. Eaton <jwe@octave.org>
parents:
13249
diff
changeset
|
1716 | methods_list opt_sep function |
15037
56b8eb7c9c04
improvements in parsing classdef
John W. Eaton <jwe@octave.org>
parents:
14846
diff
changeset
|
1717 { |
56b8eb7c9c04
improvements in parsing classdef
John W. Eaton <jwe@octave.org>
parents:
14846
diff
changeset
|
1718 octave_value fcn; |
56b8eb7c9c04
improvements in parsing classdef
John W. Eaton <jwe@octave.org>
parents:
14846
diff
changeset
|
1719 if ($3) |
56b8eb7c9c04
improvements in parsing classdef
John W. Eaton <jwe@octave.org>
parents:
14846
diff
changeset
|
1720 fcn = $3->function (); |
56b8eb7c9c04
improvements in parsing classdef
John W. Eaton <jwe@octave.org>
parents:
14846
diff
changeset
|
1721 delete $3; |
56b8eb7c9c04
improvements in parsing classdef
John W. Eaton <jwe@octave.org>
parents:
14846
diff
changeset
|
1722 |
56b8eb7c9c04
improvements in parsing classdef
John W. Eaton <jwe@octave.org>
parents:
14846
diff
changeset
|
1723 $1->append (fcn); |
56b8eb7c9c04
improvements in parsing classdef
John W. Eaton <jwe@octave.org>
parents:
14846
diff
changeset
|
1724 $$ = $1; |
56b8eb7c9c04
improvements in parsing classdef
John W. Eaton <jwe@octave.org>
parents:
14846
diff
changeset
|
1725 } |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1726 ; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1727 |
15037
56b8eb7c9c04
improvements in parsing classdef
John W. Eaton <jwe@octave.org>
parents:
14846
diff
changeset
|
1728 events_block : EVENTS stash_comment opt_attr_list opt_sep events_list opt_sep END |
56b8eb7c9c04
improvements in parsing classdef
John W. Eaton <jwe@octave.org>
parents:
14846
diff
changeset
|
1729 { |
56b8eb7c9c04
improvements in parsing classdef
John W. Eaton <jwe@octave.org>
parents:
14846
diff
changeset
|
1730 if (! ($$ = make_classdef_events_block ($1, $3, $5, $7, $2))) |
56b8eb7c9c04
improvements in parsing classdef
John W. Eaton <jwe@octave.org>
parents:
14846
diff
changeset
|
1731 ABORT_PARSE; |
56b8eb7c9c04
improvements in parsing classdef
John W. Eaton <jwe@octave.org>
parents:
14846
diff
changeset
|
1732 } |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1733 ; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1734 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1735 events_list : class_event |
15037
56b8eb7c9c04
improvements in parsing classdef
John W. Eaton <jwe@octave.org>
parents:
14846
diff
changeset
|
1736 { $$ = new tree_classdef_events_list ($1); } |
13250
f6bbdea030b2
use opt_sep instead of literal '\n' in parser rules for classdef
John W. Eaton <jwe@octave.org>
parents:
13249
diff
changeset
|
1737 | events_list opt_sep class_event |
15037
56b8eb7c9c04
improvements in parsing classdef
John W. Eaton <jwe@octave.org>
parents:
14846
diff
changeset
|
1738 { |
56b8eb7c9c04
improvements in parsing classdef
John W. Eaton <jwe@octave.org>
parents:
14846
diff
changeset
|
1739 $1->append ($3); |
56b8eb7c9c04
improvements in parsing classdef
John W. Eaton <jwe@octave.org>
parents:
14846
diff
changeset
|
1740 $$ = $1; |
56b8eb7c9c04
improvements in parsing classdef
John W. Eaton <jwe@octave.org>
parents:
14846
diff
changeset
|
1741 } |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1742 ; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1743 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1744 class_event : identifier |
15037
56b8eb7c9c04
improvements in parsing classdef
John W. Eaton <jwe@octave.org>
parents:
14846
diff
changeset
|
1745 { $$ = new tree_classdef_event ($1); } |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1746 ; |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11572
diff
changeset
|
1747 |
15037
56b8eb7c9c04
improvements in parsing classdef
John W. Eaton <jwe@octave.org>
parents:
14846
diff
changeset
|
1748 enum_block : ENUMERATION stash_comment opt_attr_list opt_sep enum_list opt_sep END |
56b8eb7c9c04
improvements in parsing classdef
John W. Eaton <jwe@octave.org>
parents:
14846
diff
changeset
|
1749 { |
56b8eb7c9c04
improvements in parsing classdef
John W. Eaton <jwe@octave.org>
parents:
14846
diff
changeset
|
1750 if (! ($$ = make_classdef_enum_block ($1, $3, $5, $7, $2))) |
56b8eb7c9c04
improvements in parsing classdef
John W. Eaton <jwe@octave.org>
parents:
14846
diff
changeset
|
1751 ABORT_PARSE; |
56b8eb7c9c04
improvements in parsing classdef
John W. Eaton <jwe@octave.org>
parents:
14846
diff
changeset
|
1752 } |
13249
7861a5fd3479
accept enumeration keyword
John W. Eaton <jwe@octave.org>
parents:
13246
diff
changeset
|
1753 ; |
7861a5fd3479
accept enumeration keyword
John W. Eaton <jwe@octave.org>
parents:
13246
diff
changeset
|
1754 |
7861a5fd3479
accept enumeration keyword
John W. Eaton <jwe@octave.org>
parents:
13246
diff
changeset
|
1755 enum_list : class_enum |
15037
56b8eb7c9c04
improvements in parsing classdef
John W. Eaton <jwe@octave.org>
parents:
14846
diff
changeset
|
1756 { $$ = new tree_classdef_enum_list ($1); } |
13250
f6bbdea030b2
use opt_sep instead of literal '\n' in parser rules for classdef
John W. Eaton <jwe@octave.org>
parents:
13249
diff
changeset
|
1757 | enum_list opt_sep class_enum |
15037
56b8eb7c9c04
improvements in parsing classdef
John W. Eaton <jwe@octave.org>
parents:
14846
diff
changeset
|
1758 { |
56b8eb7c9c04
improvements in parsing classdef
John W. Eaton <jwe@octave.org>
parents:
14846
diff
changeset
|
1759 $1->append ($3); |
56b8eb7c9c04
improvements in parsing classdef
John W. Eaton <jwe@octave.org>
parents:
14846
diff
changeset
|
1760 $$ = $1; |
56b8eb7c9c04
improvements in parsing classdef
John W. Eaton <jwe@octave.org>
parents:
14846
diff
changeset
|
1761 } |
13249
7861a5fd3479
accept enumeration keyword
John W. Eaton <jwe@octave.org>
parents:
13246
diff
changeset
|
1762 ; |
7861a5fd3479
accept enumeration keyword
John W. Eaton <jwe@octave.org>
parents:
13246
diff
changeset
|
1763 |
7861a5fd3479
accept enumeration keyword
John W. Eaton <jwe@octave.org>
parents:
13246
diff
changeset
|
1764 class_enum : identifier '(' expression ')' |
15037
56b8eb7c9c04
improvements in parsing classdef
John W. Eaton <jwe@octave.org>
parents:
14846
diff
changeset
|
1765 { $$ = new tree_classdef_enum ($1, $3); } |
13249
7861a5fd3479
accept enumeration keyword
John W. Eaton <jwe@octave.org>
parents:
13246
diff
changeset
|
1766 ; |
7861a5fd3479
accept enumeration keyword
John W. Eaton <jwe@octave.org>
parents:
13246
diff
changeset
|
1767 |
2970 | 1768 // ============= |
1769 // Miscellaneous | |
1770 // ============= | |
1771 | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1772 stash_comment : // empty |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1773 { $$ = octave_comment_buffer::get_comment (); } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1774 ; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1775 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1776 parse_error : LEXICAL_ERROR |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1777 { yyerror ("parse error"); } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1778 | error |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1779 ; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1780 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1781 sep_no_nl : ',' |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1782 { $$ = ','; } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1783 | ';' |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1784 { $$ = ';'; } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1785 | sep_no_nl ',' |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1786 { $$ = $1; } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1787 | sep_no_nl ';' |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1788 { $$ = $1; } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1789 ; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1790 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1791 opt_sep_no_nl : // empty |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1792 { $$ = 0; } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1793 | sep_no_nl |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1794 { $$ = $1; } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1795 ; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1796 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1797 sep : ',' |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1798 { $$ = ','; } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1799 | ';' |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1800 { $$ = ';'; } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1801 | '\n' |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1802 { $$ = '\n'; } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1803 | sep ',' |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1804 { $$ = $1; } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1805 | sep ';' |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1806 { $$ = $1; } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1807 | sep '\n' |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1808 { $$ = $1; } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1809 ; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1810 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1811 opt_sep : // empty |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1812 { $$ = 0; } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1813 | sep |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1814 { $$ = $1; } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1815 ; |
2525 | 1816 |
14533
e6aa044253eb
Allow comma at the end of an assignment list (bug #35645)
Max Brister <max@2bass.com>
parents:
14512
diff
changeset
|
1817 opt_comma : // empty |
e6aa044253eb
Allow comma at the end of an assignment list (bug #35645)
Max Brister <max@2bass.com>
parents:
14512
diff
changeset
|
1818 { $$ = 0; } |
e6aa044253eb
Allow comma at the end of an assignment list (bug #35645)
Max Brister <max@2bass.com>
parents:
14512
diff
changeset
|
1819 | ',' |
e6aa044253eb
Allow comma at the end of an assignment list (bug #35645)
Max Brister <max@2bass.com>
parents:
14512
diff
changeset
|
1820 { $$ = ','; } |
e6aa044253eb
Allow comma at the end of an assignment list (bug #35645)
Max Brister <max@2bass.com>
parents:
14512
diff
changeset
|
1821 ; |
e6aa044253eb
Allow comma at the end of an assignment list (bug #35645)
Max Brister <max@2bass.com>
parents:
14512
diff
changeset
|
1822 |
1 | 1823 %% |
1824 | |
666 | 1825 // Generic error messages. |
1826 | |
1 | 1827 static void |
2805 | 1828 yyerror (const char *s) |
1 | 1829 { |
143 | 1830 int err_col = current_input_column - 1; |
1 | 1831 |
5765 | 1832 std::ostringstream output_buf; |
1 | 1833 |
9476 | 1834 if (reading_fcn_file || reading_script_file || reading_classdef_file) |
1005 | 1835 output_buf << "parse error near line " << input_line_number |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1836 << " of file " << curr_fcn_file_full_name; |
1005 | 1837 else |
1838 output_buf << "parse error:"; | |
581 | 1839 |
1005 | 1840 if (s && strcmp (s, "parse error") != 0) |
1841 output_buf << "\n\n " << s; | |
1842 | |
1843 output_buf << "\n\n"; | |
1 | 1844 |
1755 | 1845 if (! current_input_line.empty ()) |
1 | 1846 { |
1755 | 1847 size_t len = current_input_line.length (); |
1060 | 1848 |
1755 | 1849 if (current_input_line[len-1] == '\n') |
1850 current_input_line.resize (len-1); | |
1005 | 1851 |
4051 | 1852 // Print the line, maybe with a pointer near the error token. |
1005 | 1853 |
1755 | 1854 output_buf << ">>> " << current_input_line << "\n"; |
1060 | 1855 |
1856 if (err_col == 0) | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1857 err_col = len; |
1060 | 1858 |
1859 for (int i = 0; i < err_col + 3; i++) | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1860 output_buf << " "; |
1060 | 1861 |
1862 output_buf << "^"; | |
1 | 1863 } |
1005 | 1864 |
5765 | 1865 output_buf << "\n"; |
1866 | |
1867 std::string msg = output_buf.str (); | |
1868 | |
1869 parse_error ("%s", msg.c_str ()); | |
1 | 1870 } |
1871 | |
666 | 1872 // Error mesages for mismatched end tokens. |
1873 | |
496 | 1874 static void |
2805 | 1875 end_error (const char *type, token::end_tok_type ettype, int l, int c) |
496 | 1876 { |
2805 | 1877 static const char *fmt |
1878 = "`%s' command matched by `%s' near line %d column %d"; | |
496 | 1879 |
1880 switch (ettype) | |
1881 { | |
1882 case token::simple_end: | |
1883 error (fmt, type, "end", l, c); | |
1884 break; | |
777 | 1885 |
496 | 1886 case token::for_end: |
1887 error (fmt, type, "endfor", l, c); | |
1888 break; | |
777 | 1889 |
496 | 1890 case token::function_end: |
1891 error (fmt, type, "endfunction", l, c); | |
1892 break; | |
777 | 1893 |
9476 | 1894 case token::classdef_end: |
1895 error (fmt, type, "endclassdef", l, c); | |
1896 break; | |
1897 | |
496 | 1898 case token::if_end: |
1899 error (fmt, type, "endif", l, c); | |
1900 break; | |
777 | 1901 |
3233 | 1902 case token::switch_end: |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11572
diff
changeset
|
1903 error (fmt, type, "endswitch", l, c); |
3233 | 1904 break; |
1905 | |
496 | 1906 case token::while_end: |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11572
diff
changeset
|
1907 error (fmt, type, "endwhile", l, c); |
496 | 1908 break; |
777 | 1909 |
5400 | 1910 case token::try_catch_end: |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11572
diff
changeset
|
1911 error (fmt, type, "end_try_catch", l, c); |
5400 | 1912 break; |
1913 | |
1371 | 1914 case token::unwind_protect_end: |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11572
diff
changeset
|
1915 error (fmt, type, "end_unwind_protect", l, c); |
1371 | 1916 break; |
1917 | |
496 | 1918 default: |
1919 panic_impossible (); | |
1920 break; | |
1921 } | |
1922 } | |
1923 | |
666 | 1924 // Check to see that end tokens are properly matched. |
1925 | |
2857 | 1926 static bool |
1927 end_token_ok (token *tok, token::end_tok_type expected) | |
143 | 1928 { |
2857 | 1929 bool retval = true; |
1930 | |
143 | 1931 token::end_tok_type ettype = tok->ettype (); |
2857 | 1932 |
143 | 1933 if (ettype != expected && ettype != token::simple_end) |
1934 { | |
2857 | 1935 retval = false; |
1936 | |
143 | 1937 yyerror ("parse error"); |
1938 | |
1939 int l = tok->line (); | |
1940 int c = tok->column (); | |
1941 | |
1942 switch (expected) | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1943 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1944 case token::classdef_end: |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1945 end_error ("classdef", ettype, l, c); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1946 break; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1947 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1948 case token::for_end: |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1949 end_error ("for", ettype, l, c); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1950 break; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1951 |
13249
7861a5fd3479
accept enumeration keyword
John W. Eaton <jwe@octave.org>
parents:
13246
diff
changeset
|
1952 case token::enumeration_end: |
7861a5fd3479
accept enumeration keyword
John W. Eaton <jwe@octave.org>
parents:
13246
diff
changeset
|
1953 end_error ("enumeration", ettype, l, c); |
7861a5fd3479
accept enumeration keyword
John W. Eaton <jwe@octave.org>
parents:
13246
diff
changeset
|
1954 break; |
7861a5fd3479
accept enumeration keyword
John W. Eaton <jwe@octave.org>
parents:
13246
diff
changeset
|
1955 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1956 case token::function_end: |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1957 end_error ("function", ettype, l, c); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1958 break; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1959 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1960 case token::if_end: |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1961 end_error ("if", ettype, l, c); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1962 break; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1963 |
13246 | 1964 case token::parfor_end: |
1965 end_error ("parfor", ettype, l, c); | |
1966 break; | |
1967 | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1968 case token::try_catch_end: |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1969 end_error ("try", ettype, l, c); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1970 break; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1971 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1972 case token::switch_end: |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1973 end_error ("switch", ettype, l, c); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1974 break; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1975 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1976 case token::unwind_protect_end: |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1977 end_error ("unwind_protect", ettype, l, c); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1978 break; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1979 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1980 case token::while_end: |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1981 end_error ("while", ettype, l, c); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1982 break; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1983 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1984 default: |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1985 panic_impossible (); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1986 break; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1987 } |
143 | 1988 } |
2857 | 1989 |
1990 return retval; | |
143 | 1991 } |
1992 | |
666 | 1993 // Maybe print a warning if an assignment expression is used as the |
1994 // test in a logical expression. | |
1995 | |
496 | 1996 static void |
1997 maybe_warn_assign_as_truth_value (tree_expression *expr) | |
1 | 1998 { |
5781 | 1999 if (expr->is_assignment_expression () |
2961 | 2000 && expr->paren_count () < 2) |
1 | 2001 { |
8974
fde2a916b2ac
include line and file info in parser warnings
John W. Eaton <jwe@octave.org>
parents:
8950
diff
changeset
|
2002 if (curr_fcn_file_full_name.empty ()) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
2003 warning_with_id |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
2004 ("Octave:assign-as-truth-value", |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
2005 "suggest parenthesis around assignment used as truth value"); |
8974
fde2a916b2ac
include line and file info in parser warnings
John W. Eaton <jwe@octave.org>
parents:
8950
diff
changeset
|
2006 else |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
2007 warning_with_id |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
2008 ("Octave:assign-as-truth-value", |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
2009 "suggest parenthesis around assignment used as truth value near line %d, column %d in file `%s'", |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
2010 expr->line (), expr->column (), curr_fcn_file_full_name.c_str ()); |
1 | 2011 } |
2012 } | |
578 | 2013 |
2764 | 2014 // Maybe print a warning about switch labels that aren't constants. |
2015 | |
2016 static void | |
2017 maybe_warn_variable_switch_label (tree_expression *expr) | |
2018 { | |
5781 | 2019 if (! expr->is_constant ()) |
8974
fde2a916b2ac
include line and file info in parser warnings
John W. Eaton <jwe@octave.org>
parents:
8950
diff
changeset
|
2020 { |
fde2a916b2ac
include line and file info in parser warnings
John W. Eaton <jwe@octave.org>
parents:
8950
diff
changeset
|
2021 if (curr_fcn_file_full_name.empty ()) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
2022 warning_with_id ("Octave:variable-switch-label", |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
2023 "variable switch label"); |
8974
fde2a916b2ac
include line and file info in parser warnings
John W. Eaton <jwe@octave.org>
parents:
8950
diff
changeset
|
2024 else |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
2025 warning_with_id |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
2026 ("Octave:variable-switch-label", |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
2027 "variable switch label near line %d, column %d in file `%s'", |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
2028 expr->line (), expr->column (), curr_fcn_file_full_name.c_str ()); |
8974
fde2a916b2ac
include line and file info in parser warnings
John W. Eaton <jwe@octave.org>
parents:
8950
diff
changeset
|
2029 } |
2764 | 2030 } |
2031 | |
2533 | 2032 static tree_expression * |
2033 fold (tree_binary_expression *e) | |
2034 { | |
3110 | 2035 tree_expression *retval = e; |
2036 | |
10067
6f79338c269b
omission from last patch
Jaroslav Hajek <highegg@gmail.com>
parents:
9794
diff
changeset
|
2037 unwind_protect frame; |
6f79338c269b
omission from last patch
Jaroslav Hajek <highegg@gmail.com>
parents:
9794
diff
changeset
|
2038 |
6f79338c269b
omission from last patch
Jaroslav Hajek <highegg@gmail.com>
parents:
9794
diff
changeset
|
2039 frame.protect_var (error_state); |
6f79338c269b
omission from last patch
Jaroslav Hajek <highegg@gmail.com>
parents:
9794
diff
changeset
|
2040 frame.protect_var (warning_state); |
6f79338c269b
omission from last patch
Jaroslav Hajek <highegg@gmail.com>
parents:
9794
diff
changeset
|
2041 |
6f79338c269b
omission from last patch
Jaroslav Hajek <highegg@gmail.com>
parents:
9794
diff
changeset
|
2042 frame.protect_var (discard_error_messages); |
6f79338c269b
omission from last patch
Jaroslav Hajek <highegg@gmail.com>
parents:
9794
diff
changeset
|
2043 frame.protect_var (discard_warning_messages); |
4452 | 2044 |
3815 | 2045 discard_error_messages = true; |
4452 | 2046 discard_warning_messages = true; |
2533 | 2047 |
2048 tree_expression *op1 = e->lhs (); | |
2049 tree_expression *op2 = e->rhs (); | |
2050 | |
13844
e48529b3dbd4
eliminate warnings for changes in operator precedence made years ago
John W. Eaton <jwe@octave.org>
parents:
13250
diff
changeset
|
2051 if (op1->is_constant () && op2->is_constant ()) |
2533 | 2052 { |
8658
73c4516fae10
New evaluator and debugger derived from tree-walker class
John W. Eaton <jwe@octave.org>
parents:
8471
diff
changeset
|
2053 octave_value tmp = e->rvalue1 (); |
2533 | 2054 |
3489 | 2055 if (! (error_state || warning_state)) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
2056 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
2057 tree_constant *tc_retval |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
2058 = new tree_constant (tmp, op1->line (), op1->column ()); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
2059 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
2060 std::ostringstream buf; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
2061 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
2062 tree_print_code tpc (buf); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
2063 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
2064 e->accept (tpc); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
2065 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
2066 tc_retval->stash_original_text (buf.str ()); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
2067 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
2068 delete e; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
2069 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
2070 retval = tc_retval; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
2071 } |
2533 | 2072 } |
3110 | 2073 |
3292 | 2074 return retval; |
2075 } | |
2076 | |
2077 static tree_expression * | |
2078 fold (tree_unary_expression *e) | |
2079 { | |
2080 tree_expression *retval = e; | |
2081 | |
10067
6f79338c269b
omission from last patch
Jaroslav Hajek <highegg@gmail.com>
parents:
9794
diff
changeset
|
2082 unwind_protect frame; |
6f79338c269b
omission from last patch
Jaroslav Hajek <highegg@gmail.com>
parents:
9794
diff
changeset
|
2083 |
6f79338c269b
omission from last patch
Jaroslav Hajek <highegg@gmail.com>
parents:
9794
diff
changeset
|
2084 frame.protect_var (error_state); |
6f79338c269b
omission from last patch
Jaroslav Hajek <highegg@gmail.com>
parents:
9794
diff
changeset
|
2085 frame.protect_var (warning_state); |
6f79338c269b
omission from last patch
Jaroslav Hajek <highegg@gmail.com>
parents:
9794
diff
changeset
|
2086 |
6f79338c269b
omission from last patch
Jaroslav Hajek <highegg@gmail.com>
parents:
9794
diff
changeset
|
2087 frame.protect_var (discard_error_messages); |
6f79338c269b
omission from last patch
Jaroslav Hajek <highegg@gmail.com>
parents:
9794
diff
changeset
|
2088 frame.protect_var (discard_warning_messages); |
4452 | 2089 |
3815 | 2090 discard_error_messages = true; |
4452 | 2091 discard_warning_messages = true; |
3292 | 2092 |
2093 tree_expression *op = e->operand (); | |
2094 | |
2095 if (op->is_constant ()) | |
2096 { | |
8658
73c4516fae10
New evaluator and debugger derived from tree-walker class
John W. Eaton <jwe@octave.org>
parents:
8471
diff
changeset
|
2097 octave_value tmp = e->rvalue1 (); |
3292 | 2098 |
3489 | 2099 if (! (error_state || warning_state)) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
2100 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
2101 tree_constant *tc_retval |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
2102 = new tree_constant (tmp, op->line (), op->column ()); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
2103 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
2104 std::ostringstream buf; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
2105 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
2106 tree_print_code tpc (buf); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
2107 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
2108 e->accept (tpc); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
2109 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
2110 tc_retval->stash_original_text (buf.str ()); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
2111 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
2112 delete e; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
2113 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
2114 retval = tc_retval; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
2115 } |
3292 | 2116 } |
2117 | |
2533 | 2118 return retval; |
2119 } | |
2120 | |
1623 | 2121 // Finish building a range. |
2122 | |
2123 static tree_expression * | |
2124 finish_colon_expression (tree_colon_expression *e) | |
2125 { | |
3110 | 2126 tree_expression *retval = e; |
2127 | |
10067
6f79338c269b
omission from last patch
Jaroslav Hajek <highegg@gmail.com>
parents:
9794
diff
changeset
|
2128 unwind_protect frame; |
6f79338c269b
omission from last patch
Jaroslav Hajek <highegg@gmail.com>
parents:
9794
diff
changeset
|
2129 |
6f79338c269b
omission from last patch
Jaroslav Hajek <highegg@gmail.com>
parents:
9794
diff
changeset
|
2130 frame.protect_var (error_state); |
6f79338c269b
omission from last patch
Jaroslav Hajek <highegg@gmail.com>
parents:
9794
diff
changeset
|
2131 frame.protect_var (warning_state); |
6f79338c269b
omission from last patch
Jaroslav Hajek <highegg@gmail.com>
parents:
9794
diff
changeset
|
2132 |
6f79338c269b
omission from last patch
Jaroslav Hajek <highegg@gmail.com>
parents:
9794
diff
changeset
|
2133 frame.protect_var (discard_error_messages); |
6f79338c269b
omission from last patch
Jaroslav Hajek <highegg@gmail.com>
parents:
9794
diff
changeset
|
2134 frame.protect_var (discard_warning_messages); |
4452 | 2135 |
3815 | 2136 discard_error_messages = true; |
4452 | 2137 discard_warning_messages = true; |
1623 | 2138 |
2533 | 2139 tree_expression *base = e->base (); |
2140 tree_expression *limit = e->limit (); | |
2141 tree_expression *incr = e->increment (); | |
2142 | |
2970 | 2143 if (base) |
1623 | 2144 { |
2970 | 2145 if (limit) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
2146 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
2147 if (base->is_constant () && limit->is_constant () |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
2148 && (! incr || (incr && incr->is_constant ()))) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
2149 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
2150 octave_value tmp = e->rvalue1 (); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
2151 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
2152 if (! (error_state || warning_state)) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
2153 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
2154 tree_constant *tc_retval |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
2155 = new tree_constant (tmp, base->line (), base->column ()); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
2156 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
2157 std::ostringstream buf; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
2158 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
2159 tree_print_code tpc (buf); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
2160 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
2161 e->accept (tpc); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
2162 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
2163 tc_retval->stash_original_text (buf.str ()); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
2164 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
2165 delete e; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
2166 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
2167 retval = tc_retval; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
2168 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
2169 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
2170 } |
2533 | 2171 else |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
2172 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
2173 e->preserve_base (); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
2174 delete e; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
2175 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
2176 // FIXME -- need to attempt constant folding here |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
2177 // too (we need a generic way to do that). |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
2178 retval = base; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
2179 } |
1623 | 2180 } |
2181 | |
2182 return retval; | |
2183 } | |
2184 | |
1607 | 2185 // Make a constant. |
2186 | |
2375 | 2187 static tree_constant * |
1607 | 2188 make_constant (int op, token *tok_val) |
2189 { | |
2190 int l = tok_val->line (); | |
2191 int c = tok_val->column (); | |
2192 | |
3216 | 2193 tree_constant *retval = 0; |
1607 | 2194 |
2195 switch (op) | |
2196 { | |
2197 case NUM: | |
2533 | 2198 { |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
2199 octave_value tmp (tok_val->number ()); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
2200 retval = new tree_constant (tmp, l, c); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
2201 retval->stash_original_text (tok_val->text_rep ()); |
2533 | 2202 } |
1607 | 2203 break; |
2204 | |
2205 case IMAG_NUM: | |
2206 { | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
2207 octave_value tmp (Complex (0.0, tok_val->number ())); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
2208 retval = new tree_constant (tmp, l, c); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
2209 retval->stash_original_text (tok_val->text_rep ()); |
1607 | 2210 } |
2211 break; | |
2212 | |
5279 | 2213 case DQ_STRING: |
2214 case SQ_STRING: | |
2883 | 2215 { |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
2216 std::string txt = tok_val->text (); |
7699
27a5f578750c
make_constant: handle escape sequences in dq-strings
John W. Eaton <jwe@octave.org>
parents:
7690
diff
changeset
|
2217 |
8150
283989f2da9b
make null assignment matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
8064
diff
changeset
|
2218 char delim = op == DQ_STRING ? '"' : '\''; |
283989f2da9b
make null assignment matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
8064
diff
changeset
|
2219 octave_value tmp (txt, delim); |
283989f2da9b
make null assignment matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
8064
diff
changeset
|
2220 |
283989f2da9b
make null assignment matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
8064
diff
changeset
|
2221 if (txt.empty ()) |
283989f2da9b
make null assignment matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
8064
diff
changeset
|
2222 { |
283989f2da9b
make null assignment matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
8064
diff
changeset
|
2223 if (op == DQ_STRING) |
283989f2da9b
make null assignment matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
8064
diff
changeset
|
2224 tmp = octave_null_str::instance; |
283989f2da9b
make null assignment matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
8064
diff
changeset
|
2225 else |
283989f2da9b
make null assignment matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
8064
diff
changeset
|
2226 tmp = octave_null_sq_str::instance; |
283989f2da9b
make null assignment matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
8064
diff
changeset
|
2227 } |
283989f2da9b
make null assignment matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
8064
diff
changeset
|
2228 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
2229 retval = new tree_constant (tmp, l, c); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
2230 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
2231 if (op == DQ_STRING) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
2232 txt = undo_string_escapes (txt); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
2233 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
2234 // FIXME -- maybe this should also be handled by |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
2235 // tok_val->text_rep () for character strings? |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
2236 retval->stash_original_text (delim + txt + delim); |
2883 | 2237 } |
1607 | 2238 break; |
2239 | |
2240 default: | |
2241 panic_impossible (); | |
2242 break; | |
2243 } | |
2244 | |
2245 return retval; | |
2246 } | |
2247 | |
4342 | 2248 // Make a function handle. |
2249 | |
2250 static tree_fcn_handle * | |
2251 make_fcn_handle (token *tok_val) | |
2252 { | |
2253 int l = tok_val->line (); | |
2254 int c = tok_val->column (); | |
2255 | |
2256 tree_fcn_handle *retval = new tree_fcn_handle (tok_val->text (), l, c); | |
2257 | |
2258 return retval; | |
2259 } | |
2260 | |
4935 | 2261 // Make an anonymous function handle. |
2262 | |
5861 | 2263 static tree_anon_fcn_handle * |
4935 | 2264 make_anon_fcn_handle (tree_parameter_list *param_list, tree_statement *stmt) |
2265 { | |
5775 | 2266 // FIXME -- need to get these from the location of the @ symbol. |
13125
34a49d076155
Show row/column for anonymous functions in the profiler
Daniel Kraft <d@domob.eu>
parents:
13029
diff
changeset
|
2267 int l = input_line_number; |
34a49d076155
Show row/column for anonymous functions in the profiler
Daniel Kraft <d@domob.eu>
parents:
13029
diff
changeset
|
2268 int c = current_input_column; |
4935 | 2269 |
2270 tree_parameter_list *ret_list = 0; | |
2271 | |
7336 | 2272 symbol_table::scope_id fcn_scope = symbol_table::current_scope (); |
5861 | 2273 |
14329
8d1ae996c122
also save and restore symbol table context in parser (bug #35448)
John W. Eaton <jwe@octave.org>
parents:
14294
diff
changeset
|
2274 if (parser_symtab_context.empty ()) |
5861 | 2275 panic_impossible (); |
2276 | |
14329
8d1ae996c122
also save and restore symbol table context in parser (bug #35448)
John W. Eaton <jwe@octave.org>
parents:
14294
diff
changeset
|
2277 parser_symtab_context.pop (); |
5861 | 2278 |
7351 | 2279 stmt->set_print_flag (false); |
4935 | 2280 |
2281 tree_statement_list *body = new tree_statement_list (stmt); | |
2282 | |
8658
73c4516fae10
New evaluator and debugger derived from tree-walker class
John W. Eaton <jwe@octave.org>
parents:
8471
diff
changeset
|
2283 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
|
2284 |
5861 | 2285 tree_anon_fcn_handle *retval |
7336 | 2286 = new tree_anon_fcn_handle (param_list, ret_list, body, fcn_scope, l, c); |
13125
34a49d076155
Show row/column for anonymous functions in the profiler
Daniel Kraft <d@domob.eu>
parents:
13029
diff
changeset
|
2287 // FIXME: Stash the filename. This does not work and produces |
34a49d076155
Show row/column for anonymous functions in the profiler
Daniel Kraft <d@domob.eu>
parents:
13029
diff
changeset
|
2288 // errors when executed. |
34a49d076155
Show row/column for anonymous functions in the profiler
Daniel Kraft <d@domob.eu>
parents:
13029
diff
changeset
|
2289 //retval->stash_file_name (curr_fcn_file_name); |
4935 | 2290 |
2291 return retval; | |
2292 } | |
2293 | |
666 | 2294 // Build a binary expression. |
2295 | |
578 | 2296 static tree_expression * |
2297 make_binary_op (int op, tree_expression *op1, token *tok_val, | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
2298 tree_expression *op2) |
578 | 2299 { |
2883 | 2300 octave_value::binary_op t = octave_value::unknown_binary_op; |
1623 | 2301 |
578 | 2302 switch (op) |
2303 { | |
2304 case POW: | |
3525 | 2305 t = octave_value::op_pow; |
578 | 2306 break; |
777 | 2307 |
578 | 2308 case EPOW: |
3525 | 2309 t = octave_value::op_el_pow; |
578 | 2310 break; |
777 | 2311 |
578 | 2312 case '+': |
3525 | 2313 t = octave_value::op_add; |
578 | 2314 break; |
777 | 2315 |
578 | 2316 case '-': |
3525 | 2317 t = octave_value::op_sub; |
578 | 2318 break; |
777 | 2319 |
578 | 2320 case '*': |
3525 | 2321 t = octave_value::op_mul; |
578 | 2322 break; |
777 | 2323 |
578 | 2324 case '/': |
3525 | 2325 t = octave_value::op_div; |
578 | 2326 break; |
777 | 2327 |
578 | 2328 case EMUL: |
3525 | 2329 t = octave_value::op_el_mul; |
578 | 2330 break; |
777 | 2331 |
578 | 2332 case EDIV: |
3525 | 2333 t = octave_value::op_el_div; |
578 | 2334 break; |
777 | 2335 |
578 | 2336 case LEFTDIV: |
3525 | 2337 t = octave_value::op_ldiv; |
578 | 2338 break; |
777 | 2339 |
578 | 2340 case ELEFTDIV: |
3525 | 2341 t = octave_value::op_el_ldiv; |
578 | 2342 break; |
777 | 2343 |
2899 | 2344 case LSHIFT: |
3525 | 2345 t = octave_value::op_lshift; |
2899 | 2346 break; |
2347 | |
2348 case RSHIFT: | |
3525 | 2349 t = octave_value::op_rshift; |
2899 | 2350 break; |
2351 | |
578 | 2352 case EXPR_LT: |
3525 | 2353 t = octave_value::op_lt; |
578 | 2354 break; |
777 | 2355 |
578 | 2356 case EXPR_LE: |
3525 | 2357 t = octave_value::op_le; |
578 | 2358 break; |
777 | 2359 |
578 | 2360 case EXPR_EQ: |
3525 | 2361 t = octave_value::op_eq; |
578 | 2362 break; |
777 | 2363 |
578 | 2364 case EXPR_GE: |
3525 | 2365 t = octave_value::op_ge; |
578 | 2366 break; |
777 | 2367 |
578 | 2368 case EXPR_GT: |
3525 | 2369 t = octave_value::op_gt; |
578 | 2370 break; |
777 | 2371 |
578 | 2372 case EXPR_NE: |
3525 | 2373 t = octave_value::op_ne; |
578 | 2374 break; |
777 | 2375 |
578 | 2376 case EXPR_AND: |
3525 | 2377 t = octave_value::op_el_and; |
578 | 2378 break; |
777 | 2379 |
578 | 2380 case EXPR_OR: |
3525 | 2381 t = octave_value::op_el_or; |
578 | 2382 break; |
777 | 2383 |
578 | 2384 default: |
2385 panic_impossible (); | |
2386 break; | |
2387 } | |
2388 | |
2389 int l = tok_val->line (); | |
2390 int c = tok_val->column (); | |
2391 | |
2533 | 2392 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
|
2393 = maybe_compound_binary_expression (op1, op2, l, c, t); |
1623 | 2394 |
2533 | 2395 return fold (e); |
578 | 2396 } |
2397 | |
2375 | 2398 // Build a boolean expression. |
666 | 2399 |
578 | 2400 static tree_expression * |
2375 | 2401 make_boolean_op (int op, tree_expression *op1, token *tok_val, |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
2402 tree_expression *op2) |
578 | 2403 { |
2375 | 2404 tree_boolean_expression::type t; |
2405 | |
578 | 2406 switch (op) |
2407 { | |
2375 | 2408 case EXPR_AND_AND: |
2805 | 2409 t = tree_boolean_expression::bool_and; |
578 | 2410 break; |
777 | 2411 |
2375 | 2412 case EXPR_OR_OR: |
2805 | 2413 t = tree_boolean_expression::bool_or; |
578 | 2414 break; |
777 | 2415 |
578 | 2416 default: |
2417 panic_impossible (); | |
2418 break; | |
2419 } | |
2420 | |
2421 int l = tok_val->line (); | |
2422 int c = tok_val->column (); | |
2423 | |
2533 | 2424 tree_boolean_expression *e |
2425 = new tree_boolean_expression (op1, op2, l, c, t); | |
2375 | 2426 |
2533 | 2427 return fold (e); |
578 | 2428 } |
2429 | |
2375 | 2430 // Build a prefix expression. |
666 | 2431 |
578 | 2432 static tree_expression * |
2960 | 2433 make_prefix_op (int op, tree_expression *op1, token *tok_val) |
578 | 2434 { |
3203 | 2435 octave_value::unary_op t = octave_value::unknown_unary_op; |
2375 | 2436 |
578 | 2437 switch (op) |
2438 { | |
2960 | 2439 case EXPR_NOT: |
3525 | 2440 t = octave_value::op_not; |
2960 | 2441 break; |
2442 | |
4965 | 2443 case '+': |
2444 t = octave_value::op_uplus; | |
2445 break; | |
2446 | |
2960 | 2447 case '-': |
3525 | 2448 t = octave_value::op_uminus; |
2960 | 2449 break; |
2450 | |
578 | 2451 case PLUS_PLUS: |
3525 | 2452 t = octave_value::op_incr; |
578 | 2453 break; |
777 | 2454 |
578 | 2455 case MINUS_MINUS: |
3525 | 2456 t = octave_value::op_decr; |
578 | 2457 break; |
777 | 2458 |
578 | 2459 default: |
2460 panic_impossible (); | |
2461 break; | |
2462 } | |
2463 | |
2464 int l = tok_val->line (); | |
2465 int c = tok_val->column (); | |
2466 | |
3292 | 2467 tree_prefix_expression *e |
2468 = new tree_prefix_expression (op1, l, c, t); | |
2469 | |
2470 return fold (e); | |
578 | 2471 } |
2472 | |
2375 | 2473 // Build a postfix expression. |
666 | 2474 |
578 | 2475 static tree_expression * |
2960 | 2476 make_postfix_op (int op, tree_expression *op1, token *tok_val) |
578 | 2477 { |
3203 | 2478 octave_value::unary_op t = octave_value::unknown_unary_op; |
1623 | 2479 |
578 | 2480 switch (op) |
2481 { | |
2960 | 2482 case QUOTE: |
3525 | 2483 t = octave_value::op_hermitian; |
2960 | 2484 break; |
2485 | |
2486 case TRANSPOSE: | |
3525 | 2487 t = octave_value::op_transpose; |
2960 | 2488 break; |
2489 | |
2375 | 2490 case PLUS_PLUS: |
3525 | 2491 t = octave_value::op_incr; |
578 | 2492 break; |
777 | 2493 |
2375 | 2494 case MINUS_MINUS: |
3525 | 2495 t = octave_value::op_decr; |
578 | 2496 break; |
777 | 2497 |
578 | 2498 default: |
2499 panic_impossible (); | |
2500 break; | |
2501 } | |
2502 | |
2503 int l = tok_val->line (); | |
2504 int c = tok_val->column (); | |
2505 | |
3292 | 2506 tree_postfix_expression *e |
2507 = new tree_postfix_expression (op1, l, c, t); | |
2508 | |
2509 return fold (e); | |
1623 | 2510 } |
2511 | |
2512 // Build an unwind-protect command. | |
2513 | |
2514 static tree_command * | |
2515 make_unwind_command (token *unwind_tok, tree_statement_list *body, | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
2516 tree_statement_list *cleanup, token *end_tok, |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
2517 octave_comment_list *lc, octave_comment_list *mc) |
1623 | 2518 { |
2519 tree_command *retval = 0; | |
2520 | |
2857 | 2521 if (end_token_ok (end_tok, token::unwind_protect_end)) |
1623 | 2522 { |
3665 | 2523 octave_comment_list *tc = octave_comment_buffer::get_comment (); |
2524 | |
1623 | 2525 int l = unwind_tok->line (); |
2526 int c = unwind_tok->column (); | |
2527 | |
3665 | 2528 retval = new tree_unwind_protect_command (body, cleanup, |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
2529 lc, mc, tc, l, c); |
1623 | 2530 } |
2531 | |
2532 return retval; | |
2533 } | |
2534 | |
2535 // Build a try-catch command. | |
2536 | |
2537 static tree_command * | |
2538 make_try_command (token *try_tok, tree_statement_list *body, | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
2539 tree_statement_list *cleanup, token *end_tok, |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
2540 octave_comment_list *lc, octave_comment_list *mc) |
1623 | 2541 { |
2542 tree_command *retval = 0; | |
2543 | |
2857 | 2544 if (end_token_ok (end_tok, token::try_catch_end)) |
1623 | 2545 { |
3665 | 2546 octave_comment_list *tc = octave_comment_buffer::get_comment (); |
2547 | |
1623 | 2548 int l = try_tok->line (); |
2549 int c = try_tok->column (); | |
2550 | |
3665 | 2551 retval = new tree_try_catch_command (body, cleanup, |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
2552 lc, mc, tc, l, c); |
1623 | 2553 } |
2554 | |
2555 return retval; | |
2556 } | |
2557 | |
2558 // Build a while command. | |
2559 | |
2560 static tree_command * | |
2561 make_while_command (token *while_tok, tree_expression *expr, | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
2562 tree_statement_list *body, token *end_tok, |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
2563 octave_comment_list *lc) |
1623 | 2564 { |
2565 tree_command *retval = 0; | |
2566 | |
2567 maybe_warn_assign_as_truth_value (expr); | |
2568 | |
2857 | 2569 if (end_token_ok (end_tok, token::while_end)) |
1623 | 2570 { |
3665 | 2571 octave_comment_list *tc = octave_comment_buffer::get_comment (); |
2572 | |
1826 | 2573 lexer_flags.looping--; |
1623 | 2574 |
2575 int l = while_tok->line (); | |
2576 int c = while_tok->column (); | |
2577 | |
3665 | 2578 retval = new tree_while_command (expr, body, lc, tc, l, c); |
1623 | 2579 } |
2580 | |
2581 return retval; | |
2582 } | |
2583 | |
3484 | 2584 // Build a do-until command. |
2585 | |
2586 static tree_command * | |
8658
73c4516fae10
New evaluator and debugger derived from tree-walker class
John W. Eaton <jwe@octave.org>
parents:
8471
diff
changeset
|
2587 make_do_until_command (token *until_tok, tree_statement_list *body, |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
2588 tree_expression *expr, octave_comment_list *lc) |
3484 | 2589 { |
2590 tree_command *retval = 0; | |
2591 | |
2592 maybe_warn_assign_as_truth_value (expr); | |
2593 | |
3665 | 2594 octave_comment_list *tc = octave_comment_buffer::get_comment (); |
2595 | |
3484 | 2596 lexer_flags.looping--; |
2597 | |
8658
73c4516fae10
New evaluator and debugger derived from tree-walker class
John W. Eaton <jwe@octave.org>
parents:
8471
diff
changeset
|
2598 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
|
2599 int c = until_tok->column (); |
3484 | 2600 |
3665 | 2601 retval = new tree_do_until_command (expr, body, lc, tc, l, c); |
3484 | 2602 |
2603 return retval; | |
2604 } | |
2605 | |
1623 | 2606 // Build a for command. |
2607 | |
2608 static tree_command * | |
13245
027a2186cd90
parfor keyword and infrastructure, but handle parfor as normal for loop for now
John W. Eaton <jwe@octave.org>
parents:
13241
diff
changeset
|
2609 make_for_command (int tok_id, token *for_tok, tree_argument_list *lhs, |
027a2186cd90
parfor keyword and infrastructure, but handle parfor as normal for loop for now
John W. Eaton <jwe@octave.org>
parents:
13241
diff
changeset
|
2610 tree_expression *expr, tree_expression *maxproc, |
027a2186cd90
parfor keyword and infrastructure, but handle parfor as normal for loop for now
John W. Eaton <jwe@octave.org>
parents:
13241
diff
changeset
|
2611 tree_statement_list *body, token *end_tok, |
027a2186cd90
parfor keyword and infrastructure, but handle parfor as normal for loop for now
John W. Eaton <jwe@octave.org>
parents:
13241
diff
changeset
|
2612 octave_comment_list *lc) |
1623 | 2613 { |
2614 tree_command *retval = 0; | |
2615 | |
13245
027a2186cd90
parfor keyword and infrastructure, but handle parfor as normal for loop for now
John W. Eaton <jwe@octave.org>
parents:
13241
diff
changeset
|
2616 bool parfor = tok_id == PARFOR; |
027a2186cd90
parfor keyword and infrastructure, but handle parfor as normal for loop for now
John W. Eaton <jwe@octave.org>
parents:
13241
diff
changeset
|
2617 |
027a2186cd90
parfor keyword and infrastructure, but handle parfor as normal for loop for now
John W. Eaton <jwe@octave.org>
parents:
13241
diff
changeset
|
2618 if (end_token_ok (end_tok, parfor ? token::parfor_end : token::for_end)) |
1623 | 2619 { |
3665 | 2620 octave_comment_list *tc = octave_comment_buffer::get_comment (); |
2621 | |
1826 | 2622 lexer_flags.looping--; |
1623 | 2623 |
2624 int l = for_tok->line (); | |
2625 int c = for_tok->column (); | |
2626 | |
2970 | 2627 if (lhs->length () == 1) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
2628 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
2629 tree_expression *tmp = lhs->remove_front (); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
2630 |
13245
027a2186cd90
parfor keyword and infrastructure, but handle parfor as normal for loop for now
John W. Eaton <jwe@octave.org>
parents:
13241
diff
changeset
|
2631 retval = new tree_simple_for_command (parfor, tmp, expr, maxproc, |
027a2186cd90
parfor keyword and infrastructure, but handle parfor as normal for loop for now
John W. Eaton <jwe@octave.org>
parents:
13241
diff
changeset
|
2632 body, lc, tc, l, c); |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
2633 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
2634 delete lhs; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
2635 } |
2970 | 2636 else |
13245
027a2186cd90
parfor keyword and infrastructure, but handle parfor as normal for loop for now
John W. Eaton <jwe@octave.org>
parents:
13241
diff
changeset
|
2637 { |
027a2186cd90
parfor keyword and infrastructure, but handle parfor as normal for loop for now
John W. Eaton <jwe@octave.org>
parents:
13241
diff
changeset
|
2638 if (parfor) |
027a2186cd90
parfor keyword and infrastructure, but handle parfor as normal for loop for now
John W. Eaton <jwe@octave.org>
parents:
13241
diff
changeset
|
2639 yyerror ("invalid syntax for parfor statement"); |
027a2186cd90
parfor keyword and infrastructure, but handle parfor as normal for loop for now
John W. Eaton <jwe@octave.org>
parents:
13241
diff
changeset
|
2640 else |
027a2186cd90
parfor keyword and infrastructure, but handle parfor as normal for loop for now
John W. Eaton <jwe@octave.org>
parents:
13241
diff
changeset
|
2641 retval = new tree_complex_for_command (lhs, expr, body, |
027a2186cd90
parfor keyword and infrastructure, but handle parfor as normal for loop for now
John W. Eaton <jwe@octave.org>
parents:
13241
diff
changeset
|
2642 lc, tc, l, c); |
027a2186cd90
parfor keyword and infrastructure, but handle parfor as normal for loop for now
John W. Eaton <jwe@octave.org>
parents:
13241
diff
changeset
|
2643 } |
1623 | 2644 } |
2645 | |
2646 return retval; | |
2647 } | |
2648 | |
4207 | 2649 // Build a break command. |
2650 | |
2651 static tree_command * | |
2652 make_break_command (token *break_tok) | |
1623 | 2653 { |
4207 | 2654 tree_command *retval = 0; |
1623 | 2655 |
2620 | 2656 int l = break_tok->line (); |
2657 int c = break_tok->column (); | |
2658 | |
10188
97ae300aa73a
improve implementation of break, continue, and return commands
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2659 retval = new tree_break_command (l, c); |
1623 | 2660 |
2661 return retval; | |
2662 } | |
2663 | |
4207 | 2664 // Build a continue command. |
2665 | |
2666 static tree_command * | |
2667 make_continue_command (token *continue_tok) | |
1623 | 2668 { |
4207 | 2669 tree_command *retval = 0; |
1623 | 2670 |
2620 | 2671 int l = continue_tok->line (); |
2672 int c = continue_tok->column (); | |
2673 | |
10188
97ae300aa73a
improve implementation of break, continue, and return commands
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2674 retval = new tree_continue_command (l, c); |
1623 | 2675 |
2676 return retval; | |
2677 } | |
2678 | |
4207 | 2679 // Build a return command. |
2680 | |
2681 static tree_command * | |
2682 make_return_command (token *return_tok) | |
1623 | 2683 { |
4207 | 2684 tree_command *retval = 0; |
1623 | 2685 |
2620 | 2686 int l = return_tok->line (); |
2687 int c = return_tok->column (); | |
2688 | |
10188
97ae300aa73a
improve implementation of break, continue, and return commands
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2689 retval = new tree_return_command (l, c); |
1623 | 2690 |
2691 return retval; | |
2692 } | |
2693 | |
2694 // Start an if command. | |
2695 | |
2696 static tree_if_command_list * | |
2697 start_if_command (tree_expression *expr, tree_statement_list *list) | |
2698 { | |
2699 maybe_warn_assign_as_truth_value (expr); | |
2700 | |
2701 tree_if_clause *t = new tree_if_clause (expr, list); | |
2702 | |
2703 return new tree_if_command_list (t); | |
2704 } | |
2705 | |
2706 // Finish an if command. | |
2707 | |
2708 static tree_if_command * | |
2709 finish_if_command (token *if_tok, tree_if_command_list *list, | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
2710 token *end_tok, octave_comment_list *lc) |
1623 | 2711 { |
2712 tree_if_command *retval = 0; | |
2713 | |
2857 | 2714 if (end_token_ok (end_tok, token::if_end)) |
1623 | 2715 { |
3665 | 2716 octave_comment_list *tc = octave_comment_buffer::get_comment (); |
2717 | |
1623 | 2718 int l = if_tok->line (); |
2719 int c = if_tok->column (); | |
2720 | |
8842
be7b30a24938
line/column info for switch and if statements
John W. Eaton <jwe@octave.org>
parents:
8828
diff
changeset
|
2721 if (list && ! list->empty ()) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
2722 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
2723 tree_if_clause *elt = list->front (); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
2724 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
2725 if (elt) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
2726 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
2727 elt->line (l); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
2728 elt->column (c); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
2729 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
2730 } |
8842
be7b30a24938
line/column info for switch and if statements
John W. Eaton <jwe@octave.org>
parents:
8828
diff
changeset
|
2731 |
3665 | 2732 retval = new tree_if_command (list, lc, tc, l, c); |
1623 | 2733 } |
2734 | |
2735 return retval; | |
2736 } | |
2737 | |
2738 // Build an elseif clause. | |
2739 | |
2740 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
|
2741 make_elseif_clause (token *elseif_tok, tree_expression *expr, |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
2742 tree_statement_list *list, octave_comment_list *lc) |
1623 | 2743 { |
2744 maybe_warn_assign_as_truth_value (expr); | |
2745 | |
8658
73c4516fae10
New evaluator and debugger derived from tree-walker class
John W. Eaton <jwe@octave.org>
parents:
8471
diff
changeset
|
2746 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
|
2747 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
|
2748 |
73c4516fae10
New evaluator and debugger derived from tree-walker class
John W. Eaton <jwe@octave.org>
parents:
8471
diff
changeset
|
2749 return new tree_if_clause (expr, list, lc, l, c); |
1623 | 2750 } |
2751 | |
2764 | 2752 // Finish a switch command. |
2753 | |
2754 static tree_switch_command * | |
2755 finish_switch_command (token *switch_tok, tree_expression *expr, | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
2756 tree_switch_case_list *list, token *end_tok, |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
2757 octave_comment_list *lc) |
2764 | 2758 { |
2759 tree_switch_command *retval = 0; | |
2760 | |
2857 | 2761 if (end_token_ok (end_tok, token::switch_end)) |
2764 | 2762 { |
3665 | 2763 octave_comment_list *tc = octave_comment_buffer::get_comment (); |
2764 | |
2764 | 2765 int l = switch_tok->line (); |
2766 int c = switch_tok->column (); | |
2767 | |
8842
be7b30a24938
line/column info for switch and if statements
John W. Eaton <jwe@octave.org>
parents:
8828
diff
changeset
|
2768 if (list && ! list->empty ()) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
2769 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
2770 tree_switch_case *elt = list->front (); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
2771 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
2772 if (elt) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
2773 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
2774 elt->line (l); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
2775 elt->column (c); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
2776 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
2777 } |
8842
be7b30a24938
line/column info for switch and if statements
John W. Eaton <jwe@octave.org>
parents:
8828
diff
changeset
|
2778 |
3665 | 2779 retval = new tree_switch_command (expr, list, lc, tc, l, c); |
2764 | 2780 } |
2781 | |
2782 return retval; | |
2783 } | |
2784 | |
2785 // Build a switch case. | |
2786 | |
2787 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
|
2788 make_switch_case (token *case_tok, tree_expression *expr, |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
2789 tree_statement_list *list, octave_comment_list *lc) |
2764 | 2790 { |
2791 maybe_warn_variable_switch_label (expr); | |
2792 | |
8658
73c4516fae10
New evaluator and debugger derived from tree-walker class
John W. Eaton <jwe@octave.org>
parents:
8471
diff
changeset
|
2793 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
|
2794 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
|
2795 |
73c4516fae10
New evaluator and debugger derived from tree-walker class
John W. Eaton <jwe@octave.org>
parents:
8471
diff
changeset
|
2796 return new tree_switch_case (expr, list, lc, l, c); |
2764 | 2797 } |
2798 | |
1623 | 2799 // Build an assignment to a variable. |
2800 | |
2801 static tree_expression * | |
2970 | 2802 make_assign_op (int op, tree_argument_list *lhs, token *eq_tok, |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
2803 tree_expression *rhs) |
1623 | 2804 { |
2970 | 2805 tree_expression *retval = 0; |
2806 | |
2883 | 2807 octave_value::assign_op t = octave_value::unknown_assign_op; |
2808 | |
2809 switch (op) | |
2810 { | |
2811 case '=': | |
3525 | 2812 t = octave_value::op_asn_eq; |
2883 | 2813 break; |
2814 | |
2815 case ADD_EQ: | |
3525 | 2816 t = octave_value::op_add_eq; |
2883 | 2817 break; |
2818 | |
2819 case SUB_EQ: | |
3525 | 2820 t = octave_value::op_sub_eq; |
2883 | 2821 break; |
2822 | |
2823 case MUL_EQ: | |
3525 | 2824 t = octave_value::op_mul_eq; |
2883 | 2825 break; |
2826 | |
2827 case DIV_EQ: | |
3525 | 2828 t = octave_value::op_div_eq; |
2883 | 2829 break; |
2830 | |
3204 | 2831 case LEFTDIV_EQ: |
3525 | 2832 t = octave_value::op_ldiv_eq; |
3204 | 2833 break; |
2834 | |
4018 | 2835 case POW_EQ: |
2836 t = octave_value::op_pow_eq; | |
2837 break; | |
2838 | |
2899 | 2839 case LSHIFT_EQ: |
3525 | 2840 t = octave_value::op_lshift_eq; |
2899 | 2841 break; |
2842 | |
2843 case RSHIFT_EQ: | |
3525 | 2844 t = octave_value::op_rshift_eq; |
2899 | 2845 break; |
2846 | |
2883 | 2847 case EMUL_EQ: |
3525 | 2848 t = octave_value::op_el_mul_eq; |
2883 | 2849 break; |
2850 | |
2851 case EDIV_EQ: | |
3525 | 2852 t = octave_value::op_el_div_eq; |
2883 | 2853 break; |
2854 | |
3204 | 2855 case ELEFTDIV_EQ: |
3525 | 2856 t = octave_value::op_el_ldiv_eq; |
3204 | 2857 break; |
2858 | |
4018 | 2859 case EPOW_EQ: |
2860 t = octave_value::op_el_pow_eq; | |
2861 break; | |
2862 | |
2883 | 2863 case AND_EQ: |
3525 | 2864 t = octave_value::op_el_and_eq; |
2883 | 2865 break; |
2866 | |
2867 case OR_EQ: | |
3525 | 2868 t = octave_value::op_el_or_eq; |
2883 | 2869 break; |
2870 | |
2871 default: | |
2872 panic_impossible (); | |
2873 break; | |
2874 } | |
2875 | |
1623 | 2876 int l = eq_tok->line (); |
2877 int c = eq_tok->column (); | |
2878 | |
5841 | 2879 if (lhs->is_simple_assign_lhs ()) |
666 | 2880 { |
2970 | 2881 tree_expression *tmp = lhs->remove_front (); |
2882 | |
2883 retval = new tree_simple_assignment (tmp, rhs, false, l, c, t); | |
2884 | |
2885 delete lhs; | |
666 | 2886 } |
10230
0a5a769b8fc0
disallow computed multiple assignment
Jaroslav Hajek <highegg@gmail.com>
parents:
10207
diff
changeset
|
2887 else if (t == octave_value::op_asn_eq) |
0a5a769b8fc0
disallow computed multiple assignment
Jaroslav Hajek <highegg@gmail.com>
parents:
10207
diff
changeset
|
2888 return new tree_multi_assignment (lhs, rhs, false, l, c); |
666 | 2889 else |
10230
0a5a769b8fc0
disallow computed multiple assignment
Jaroslav Hajek <highegg@gmail.com>
parents:
10207
diff
changeset
|
2890 yyerror ("computed multiple assignment not allowed"); |
666 | 2891 |
2892 return retval; | |
2893 } | |
751 | 2894 |
9474
25ed2d6aacf6
Parse nested functions more accurately.
David Grundberg <individ@acc.umu.se>
parents:
9471
diff
changeset
|
2895 // Define a script. |
7715
5b4d278ec828
parse scripts completely before executing
John W. Eaton <jwe@octave.org>
parents:
7699
diff
changeset
|
2896 |
5b4d278ec828
parse scripts completely before executing
John W. Eaton <jwe@octave.org>
parents:
7699
diff
changeset
|
2897 static void |
8658
73c4516fae10
New evaluator and debugger derived from tree-walker class
John W. Eaton <jwe@octave.org>
parents:
8471
diff
changeset
|
2898 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
|
2899 { |
5b4d278ec828
parse scripts completely before executing
John W. Eaton <jwe@octave.org>
parents:
7699
diff
changeset
|
2900 std::string doc_string; |
5b4d278ec828
parse scripts completely before executing
John W. Eaton <jwe@octave.org>
parents:
7699
diff
changeset
|
2901 |
5b4d278ec828
parse scripts completely before executing
John W. Eaton <jwe@octave.org>
parents:
7699
diff
changeset
|
2902 if (! help_buf.empty ()) |
5b4d278ec828
parse scripts completely before executing
John W. Eaton <jwe@octave.org>
parents:
7699
diff
changeset
|
2903 { |
5b4d278ec828
parse scripts completely before executing
John W. Eaton <jwe@octave.org>
parents:
7699
diff
changeset
|
2904 doc_string = help_buf.top (); |
5b4d278ec828
parse scripts completely before executing
John W. Eaton <jwe@octave.org>
parents:
7699
diff
changeset
|
2905 help_buf.pop (); |
5b4d278ec828
parse scripts completely before executing
John W. Eaton <jwe@octave.org>
parents:
7699
diff
changeset
|
2906 } |
5b4d278ec828
parse scripts completely before executing
John W. Eaton <jwe@octave.org>
parents:
7699
diff
changeset
|
2907 |
8658
73c4516fae10
New evaluator and debugger derived from tree-walker class
John W. Eaton <jwe@octave.org>
parents:
8471
diff
changeset
|
2908 if (! cmds) |
73c4516fae10
New evaluator and debugger derived from tree-walker class
John W. Eaton <jwe@octave.org>
parents:
8471
diff
changeset
|
2909 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
|
2910 |
73c4516fae10
New evaluator and debugger derived from tree-walker class
John W. Eaton <jwe@octave.org>
parents:
8471
diff
changeset
|
2911 cmds->append (end_script); |
73c4516fae10
New evaluator and debugger derived from tree-walker class
John W. Eaton <jwe@octave.org>
parents:
8471
diff
changeset
|
2912 |
7715
5b4d278ec828
parse scripts completely before executing
John W. Eaton <jwe@octave.org>
parents:
7699
diff
changeset
|
2913 octave_user_script *script |
5b4d278ec828
parse scripts completely before executing
John W. Eaton <jwe@octave.org>
parents:
7699
diff
changeset
|
2914 = new octave_user_script (curr_fcn_file_full_name, curr_fcn_file_name, |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
2915 cmds, doc_string); |
7715
5b4d278ec828
parse scripts completely before executing
John W. Eaton <jwe@octave.org>
parents:
7699
diff
changeset
|
2916 |
5b4d278ec828
parse scripts completely before executing
John W. Eaton <jwe@octave.org>
parents:
7699
diff
changeset
|
2917 octave_time now; |
5b4d278ec828
parse scripts completely before executing
John W. Eaton <jwe@octave.org>
parents:
7699
diff
changeset
|
2918 |
5b4d278ec828
parse scripts completely before executing
John W. Eaton <jwe@octave.org>
parents:
7699
diff
changeset
|
2919 script->stash_fcn_file_time (now); |
5b4d278ec828
parse scripts completely before executing
John W. Eaton <jwe@octave.org>
parents:
7699
diff
changeset
|
2920 |
9474
25ed2d6aacf6
Parse nested functions more accurately.
David Grundberg <individ@acc.umu.se>
parents:
9471
diff
changeset
|
2921 primary_fcn_ptr = script; |
8881
8ed42c679af5
after defining a script or function, clear local variables created for parsing
John W. Eaton <jwe@octave.org>
parents:
8842
diff
changeset
|
2922 |
9009
da58ec8f62e8
tag bug don't define forced variables
John W. Eaton <jwe@octave.org>
parents:
8974
diff
changeset
|
2923 // Unmark any symbols that may have been tagged as local variables |
da58ec8f62e8
tag bug don't define forced variables
John W. Eaton <jwe@octave.org>
parents:
8974
diff
changeset
|
2924 // while parsing (for example, by force_local_variable in lex.l). |
da58ec8f62e8
tag bug don't define forced variables
John W. Eaton <jwe@octave.org>
parents:
8974
diff
changeset
|
2925 |
da58ec8f62e8
tag bug don't define forced variables
John W. Eaton <jwe@octave.org>
parents:
8974
diff
changeset
|
2926 symbol_table::unmark_forced_variables (); |
7715
5b4d278ec828
parse scripts completely before executing
John W. Eaton <jwe@octave.org>
parents:
7699
diff
changeset
|
2927 } |
5b4d278ec828
parse scripts completely before executing
John W. Eaton <jwe@octave.org>
parents:
7699
diff
changeset
|
2928 |
1623 | 2929 // Begin defining a function. |
2930 | |
2891 | 2931 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
|
2932 start_function (tree_parameter_list *param_list, tree_statement_list *body, |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
2933 tree_statement *end_fcn_stmt) |
1623 | 2934 { |
2891 | 2935 // We'll fill in the return list later. |
2936 | |
8658
73c4516fae10
New evaluator and debugger derived from tree-walker class
John W. Eaton <jwe@octave.org>
parents:
8471
diff
changeset
|
2937 if (! body) |
73c4516fae10
New evaluator and debugger derived from tree-walker class
John W. Eaton <jwe@octave.org>
parents:
8471
diff
changeset
|
2938 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
|
2939 |
73c4516fae10
New evaluator and debugger derived from tree-walker class
John W. Eaton <jwe@octave.org>
parents:
8471
diff
changeset
|
2940 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
|
2941 |
2891 | 2942 octave_user_function *fcn |
7336 | 2943 = new octave_user_function (symbol_table::current_scope (), |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
2944 param_list, 0, body); |
1623 | 2945 |
3665 | 2946 if (fcn) |
2947 { | |
2948 octave_comment_list *tc = octave_comment_buffer::get_comment (); | |
2949 | |
2950 fcn->stash_trailing_comment (tc); | |
2951 } | |
2952 | |
1623 | 2953 return fcn; |
2954 } | |
2955 | |
8658
73c4516fae10
New evaluator and debugger derived from tree-walker class
John W. Eaton <jwe@octave.org>
parents:
8471
diff
changeset
|
2956 static tree_statement * |
73c4516fae10
New evaluator and debugger derived from tree-walker class
John W. Eaton <jwe@octave.org>
parents:
8471
diff
changeset
|
2957 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
|
2958 { |
73c4516fae10
New evaluator and debugger derived from tree-walker class
John W. Eaton <jwe@octave.org>
parents:
8471
diff
changeset
|
2959 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
|
2960 } |
73c4516fae10
New evaluator and debugger derived from tree-walker class
John W. Eaton <jwe@octave.org>
parents:
8471
diff
changeset
|
2961 |
1623 | 2962 // Do most of the work for defining a function. |
2963 | |
2891 | 2964 static octave_user_function * |
4872 | 2965 frob_function (const std::string& fname, octave_user_function *fcn) |
1623 | 2966 { |
4872 | 2967 std::string id_name = fname; |
1623 | 2968 |
2969 // If input is coming from a file, issue a warning if the name of | |
2970 // the file does not match the name of the function stated in the | |
2971 // file. Matlab doesn't provide a diagnostic (it ignores the stated | |
2972 // name). | |
9474
25ed2d6aacf6
Parse nested functions more accurately.
David Grundberg <individ@acc.umu.se>
parents:
9471
diff
changeset
|
2973 if (! autoloading && reading_fcn_file |
14507
3f21c0c34b8f
check for function/file name mismatch when parsing class methods
John W. Eaton <jwe@octave.org>
parents:
14360
diff
changeset
|
2974 && current_function_depth == 1 && ! parsing_subfunctions) |
9474
25ed2d6aacf6
Parse nested functions more accurately.
David Grundberg <individ@acc.umu.se>
parents:
9471
diff
changeset
|
2975 { |
25ed2d6aacf6
Parse nested functions more accurately.
David Grundberg <individ@acc.umu.se>
parents:
9471
diff
changeset
|
2976 // FIXME -- should curr_fcn_file_name already be |
25ed2d6aacf6
Parse nested functions more accurately.
David Grundberg <individ@acc.umu.se>
parents:
9471
diff
changeset
|
2977 // preprocessed when we get here? It seems to only be a |
25ed2d6aacf6
Parse nested functions more accurately.
David Grundberg <individ@acc.umu.se>
parents:
9471
diff
changeset
|
2978 // problem with relative file names. |
25ed2d6aacf6
Parse nested functions more accurately.
David Grundberg <individ@acc.umu.se>
parents:
9471
diff
changeset
|
2979 |
25ed2d6aacf6
Parse nested functions more accurately.
David Grundberg <individ@acc.umu.se>
parents:
9471
diff
changeset
|
2980 std::string nm = curr_fcn_file_name; |
25ed2d6aacf6
Parse nested functions more accurately.
David Grundberg <individ@acc.umu.se>
parents:
9471
diff
changeset
|
2981 |
25ed2d6aacf6
Parse nested functions more accurately.
David Grundberg <individ@acc.umu.se>
parents:
9471
diff
changeset
|
2982 size_t pos = nm.find_last_of (file_ops::dir_sep_chars ()); |
25ed2d6aacf6
Parse nested functions more accurately.
David Grundberg <individ@acc.umu.se>
parents:
9471
diff
changeset
|
2983 |
25ed2d6aacf6
Parse nested functions more accurately.
David Grundberg <individ@acc.umu.se>
parents:
9471
diff
changeset
|
2984 if (pos != std::string::npos) |
25ed2d6aacf6
Parse nested functions more accurately.
David Grundberg <individ@acc.umu.se>
parents:
9471
diff
changeset
|
2985 nm = curr_fcn_file_name.substr (pos+1); |
25ed2d6aacf6
Parse nested functions more accurately.
David Grundberg <individ@acc.umu.se>
parents:
9471
diff
changeset
|
2986 |
25ed2d6aacf6
Parse nested functions more accurately.
David Grundberg <individ@acc.umu.se>
parents:
9471
diff
changeset
|
2987 if (nm != id_name) |
25ed2d6aacf6
Parse nested functions more accurately.
David Grundberg <individ@acc.umu.se>
parents:
9471
diff
changeset
|
2988 { |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
2989 warning_with_id |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
2990 ("Octave:function-name-clash", |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
2991 "function name `%s' does not agree with function file name `%s'", |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
2992 id_name.c_str (), curr_fcn_file_full_name.c_str ()); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
2993 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
2994 id_name = nm; |
9474
25ed2d6aacf6
Parse nested functions more accurately.
David Grundberg <individ@acc.umu.se>
parents:
9471
diff
changeset
|
2995 } |
25ed2d6aacf6
Parse nested functions more accurately.
David Grundberg <individ@acc.umu.se>
parents:
9471
diff
changeset
|
2996 } |
1623 | 2997 |
9476 | 2998 if (reading_fcn_file || reading_classdef_file || autoloading) |
1623 | 2999 { |
3712 | 3000 octave_time now; |
3162 | 3001 |
4343 | 3002 fcn->stash_fcn_file_name (curr_fcn_file_full_name); |
3162 | 3003 fcn->stash_fcn_file_time (now); |
1623 | 3004 fcn->mark_as_system_fcn_file (); |
3162 | 3005 |
6323 | 3006 if (fcn_file_from_relative_lookup) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
3007 fcn->mark_relative (); |
6323 | 3008 |
9474
25ed2d6aacf6
Parse nested functions more accurately.
David Grundberg <individ@acc.umu.se>
parents:
9471
diff
changeset
|
3009 if (current_function_depth > 1 || parsing_subfunctions) |
7968
0d607e8dbbfa
eliminate curr_parent_function; fix subfunction lookup
John W. Eaton <jwe@octave.org>
parents:
7903
diff
changeset
|
3010 { |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
3011 fcn->stash_parent_fcn_name (curr_fcn_file_name); |
14544
be18c9e359bf
Nested function support (bug #35772)
Max Brister <max@2bass.com>
parents:
14533
diff
changeset
|
3012 |
be18c9e359bf
Nested function support (bug #35772)
Max Brister <max@2bass.com>
parents:
14533
diff
changeset
|
3013 if (current_function_depth > 1) |
14846
460a3c6d8bf1
maint: Use Octave coding convention for cuddled parenthis in function calls with empty argument lists.
Rik <octave@nomad.inbox5.com>
parents:
14584
diff
changeset
|
3014 fcn->stash_parent_fcn_scope (function_scopes[function_scopes.size ()-2]); |
14544
be18c9e359bf
Nested function support (bug #35772)
Max Brister <max@2bass.com>
parents:
14533
diff
changeset
|
3015 else |
be18c9e359bf
Nested function support (bug #35772)
Max Brister <max@2bass.com>
parents:
14533
diff
changeset
|
3016 fcn->stash_parent_fcn_scope (primary_fcn_scope); |
9474
25ed2d6aacf6
Parse nested functions more accurately.
David Grundberg <individ@acc.umu.se>
parents:
9471
diff
changeset
|
3017 } |
6323 | 3018 |
7336 | 3019 if (lexer_flags.parsing_class_method) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
3020 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
3021 if (current_class_name == id_name) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
3022 fcn->mark_as_class_constructor (); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
3023 else |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
3024 fcn->mark_as_class_method (); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
3025 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
3026 fcn->stash_dispatch_class (current_class_name); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
3027 } |
7336 | 3028 |
5781 | 3029 std::string nm = fcn->fcn_file_name (); |
3030 | |
3031 file_stat fs (nm); | |
3032 | |
3033 if (fs && fs.is_newer (now)) | |
3034 warning_with_id ("Octave:future-time-stamp", | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
3035 "time stamp for `%s' is in the future", nm.c_str ()); |
1623 | 3036 } |
3037 else if (! (input_from_tmp_history_file || input_from_startup_file) | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
3038 && reading_script_file |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
3039 && curr_fcn_file_name == id_name) |
1623 | 3040 { |
3041 warning ("function `%s' defined within script file `%s'", | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
3042 id_name.c_str (), curr_fcn_file_full_name.c_str ()); |
1623 | 3043 } |
3044 | |
4872 | 3045 fcn->stash_function_name (id_name); |
12783
ad9263d965dc
First experimental profiler implementation with flat profile.
Daniel Kraft <d@domob.eu>
parents:
12729
diff
changeset
|
3046 fcn->stash_fcn_location (input_line_number, current_input_column); |
4872 | 3047 |
9474
25ed2d6aacf6
Parse nested functions more accurately.
David Grundberg <individ@acc.umu.se>
parents:
9471
diff
changeset
|
3048 if (! help_buf.empty () && current_function_depth == 1 |
25ed2d6aacf6
Parse nested functions more accurately.
David Grundberg <individ@acc.umu.se>
parents:
9471
diff
changeset
|
3049 && ! parsing_subfunctions) |
7336 | 3050 { |
3051 fcn->document (help_buf.top ()); | |
3052 | |
3053 help_buf.pop (); | |
3054 } | |
3055 | |
9474
25ed2d6aacf6
Parse nested functions more accurately.
David Grundberg <individ@acc.umu.se>
parents:
9471
diff
changeset
|
3056 if (reading_fcn_file && current_function_depth == 1 |
25ed2d6aacf6
Parse nested functions more accurately.
David Grundberg <individ@acc.umu.se>
parents:
9471
diff
changeset
|
3057 && ! parsing_subfunctions) |
25ed2d6aacf6
Parse nested functions more accurately.
David Grundberg <individ@acc.umu.se>
parents:
9471
diff
changeset
|
3058 primary_fcn_ptr = fcn; |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11572
diff
changeset
|
3059 |
1623 | 3060 return fcn; |
3061 } | |
3062 | |
7715
5b4d278ec828
parse scripts completely before executing
John W. Eaton <jwe@octave.org>
parents:
7699
diff
changeset
|
3063 static tree_function_def * |
3665 | 3064 finish_function (tree_parameter_list *ret_list, |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
3065 octave_user_function *fcn, octave_comment_list *lc) |
1623 | 3066 { |
7715
5b4d278ec828
parse scripts completely before executing
John W. Eaton <jwe@octave.org>
parents:
7699
diff
changeset
|
3067 tree_function_def *retval = 0; |
5b4d278ec828
parse scripts completely before executing
John W. Eaton <jwe@octave.org>
parents:
7699
diff
changeset
|
3068 |
5b4d278ec828
parse scripts completely before executing
John W. Eaton <jwe@octave.org>
parents:
7699
diff
changeset
|
3069 if (ret_list) |
5b4d278ec828
parse scripts completely before executing
John W. Eaton <jwe@octave.org>
parents:
7699
diff
changeset
|
3070 ret_list->mark_as_formal_parameters (); |
5b4d278ec828
parse scripts completely before executing
John W. Eaton <jwe@octave.org>
parents:
7699
diff
changeset
|
3071 |
5b4d278ec828
parse scripts completely before executing
John W. Eaton <jwe@octave.org>
parents:
7699
diff
changeset
|
3072 if (fcn) |
5b4d278ec828
parse scripts completely before executing
John W. Eaton <jwe@octave.org>
parents:
7699
diff
changeset
|
3073 { |
7761
5adeea5de26c
symbol table reporting functions
John W. Eaton <jwe@octave.org>
parents:
7755
diff
changeset
|
3074 std::string nm = fcn->name (); |
5adeea5de26c
symbol table reporting functions
John W. Eaton <jwe@octave.org>
parents:
7755
diff
changeset
|
3075 std::string file = fcn->fcn_file_name (); |
5adeea5de26c
symbol table reporting functions
John W. Eaton <jwe@octave.org>
parents:
7755
diff
changeset
|
3076 |
5adeea5de26c
symbol table reporting functions
John W. Eaton <jwe@octave.org>
parents:
7755
diff
changeset
|
3077 std::string tmp = nm; |
5adeea5de26c
symbol table reporting functions
John W. Eaton <jwe@octave.org>
parents:
7755
diff
changeset
|
3078 if (! file.empty ()) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
3079 tmp += ": " + file; |
7761
5adeea5de26c
symbol table reporting functions
John W. Eaton <jwe@octave.org>
parents:
7755
diff
changeset
|
3080 |
5adeea5de26c
symbol table reporting functions
John W. Eaton <jwe@octave.org>
parents:
7755
diff
changeset
|
3081 symbol_table::cache_name (fcn->scope (), tmp); |
5adeea5de26c
symbol table reporting functions
John W. Eaton <jwe@octave.org>
parents:
7755
diff
changeset
|
3082 |
7715
5b4d278ec828
parse scripts completely before executing
John W. Eaton <jwe@octave.org>
parents:
7699
diff
changeset
|
3083 if (lc) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
3084 fcn->stash_leading_comment (lc); |
7715
5b4d278ec828
parse scripts completely before executing
John W. Eaton <jwe@octave.org>
parents:
7699
diff
changeset
|
3085 |
5b4d278ec828
parse scripts completely before executing
John W. Eaton <jwe@octave.org>
parents:
7699
diff
changeset
|
3086 fcn->define_ret_list (ret_list); |
7755
ea9cb4d68dbf
avoid installing subfunctions twice
John W. Eaton <jwe@octave.org>
parents:
7750
diff
changeset
|
3087 |
9474
25ed2d6aacf6
Parse nested functions more accurately.
David Grundberg <individ@acc.umu.se>
parents:
9471
diff
changeset
|
3088 if (current_function_depth > 1 || parsing_subfunctions) |
25ed2d6aacf6
Parse nested functions more accurately.
David Grundberg <individ@acc.umu.se>
parents:
9471
diff
changeset
|
3089 { |
11461
2b8531a6a3c9
Change mentions of "nested function" to the less misleading "subfunction"
David Grundberg <individ@acc.umu.se>
parents:
11388
diff
changeset
|
3090 fcn->mark_as_subfunction (); |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
3091 |
14544
be18c9e359bf
Nested function support (bug #35772)
Max Brister <max@2bass.com>
parents:
14533
diff
changeset
|
3092 if (endfunction_found && function_scopes.size () > 1) |
be18c9e359bf
Nested function support (bug #35772)
Max Brister <max@2bass.com>
parents:
14533
diff
changeset
|
3093 { |
be18c9e359bf
Nested function support (bug #35772)
Max Brister <max@2bass.com>
parents:
14533
diff
changeset
|
3094 symbol_table::scope_id pscope |
14846
460a3c6d8bf1
maint: Use Octave coding convention for cuddled parenthis in function calls with empty argument lists.
Rik <octave@nomad.inbox5.com>
parents:
14584
diff
changeset
|
3095 = function_scopes[function_scopes.size ()-2]; |
14544
be18c9e359bf
Nested function support (bug #35772)
Max Brister <max@2bass.com>
parents:
14533
diff
changeset
|
3096 |
be18c9e359bf
Nested function support (bug #35772)
Max Brister <max@2bass.com>
parents:
14533
diff
changeset
|
3097 symbol_table::install_nestfunction (nm, octave_value (fcn), |
be18c9e359bf
Nested function support (bug #35772)
Max Brister <max@2bass.com>
parents:
14533
diff
changeset
|
3098 pscope); |
be18c9e359bf
Nested function support (bug #35772)
Max Brister <max@2bass.com>
parents:
14533
diff
changeset
|
3099 } |
be18c9e359bf
Nested function support (bug #35772)
Max Brister <max@2bass.com>
parents:
14533
diff
changeset
|
3100 else |
be18c9e359bf
Nested function support (bug #35772)
Max Brister <max@2bass.com>
parents:
14533
diff
changeset
|
3101 symbol_table::install_subfunction (nm, octave_value (fcn), |
be18c9e359bf
Nested function support (bug #35772)
Max Brister <max@2bass.com>
parents:
14533
diff
changeset
|
3102 primary_fcn_scope); |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
3103 } |
9474
25ed2d6aacf6
Parse nested functions more accurately.
David Grundberg <individ@acc.umu.se>
parents:
9471
diff
changeset
|
3104 |
14544
be18c9e359bf
Nested function support (bug #35772)
Max Brister <max@2bass.com>
parents:
14533
diff
changeset
|
3105 if (current_function_depth == 1 && fcn) |
be18c9e359bf
Nested function support (bug #35772)
Max Brister <max@2bass.com>
parents:
14533
diff
changeset
|
3106 symbol_table::update_nest (fcn->scope ()); |
be18c9e359bf
Nested function support (bug #35772)
Max Brister <max@2bass.com>
parents:
14533
diff
changeset
|
3107 |
14512
e0d66b8b0c63
Avoid double delete for nested functions in commandline
Max Brister <max@2bass.com>
parents:
14507
diff
changeset
|
3108 if (! reading_fcn_file && current_function_depth == 1) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
3109 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
3110 // We are either reading a script file or defining a function |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
3111 // at the command line, so this definition creates a |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
3112 // tree_function object that is placed in the parse tree. |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
3113 // Otherwise, it is just inserted in the symbol table, |
14512
e0d66b8b0c63
Avoid double delete for nested functions in commandline
Max Brister <max@2bass.com>
parents:
14507
diff
changeset
|
3114 // either as a subfunction or nested function (see above), |
e0d66b8b0c63
Avoid double delete for nested functions in commandline
Max Brister <max@2bass.com>
parents:
14507
diff
changeset
|
3115 // or as the primary function for the file, via |
e0d66b8b0c63
Avoid double delete for nested functions in commandline
Max Brister <max@2bass.com>
parents:
14507
diff
changeset
|
3116 // primary_fcn_ptr (see also load_fcn_from_file,, |
e0d66b8b0c63
Avoid double delete for nested functions in commandline
Max Brister <max@2bass.com>
parents:
14507
diff
changeset
|
3117 // parse_fcn_file, and |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
3118 // symbol_table::fcn_info::fcn_info_rep::find_user_function). |
9761
5f8971be8e12
parse.y (finish_function): retrun function object unless parsing function file
John W. Eaton <jwe@octave.org>
parents:
9506
diff
changeset
|
3119 |
5f8971be8e12
parse.y (finish_function): retrun function object unless parsing function file
John W. Eaton <jwe@octave.org>
parents:
9506
diff
changeset
|
3120 retval = new tree_function_def (fcn); |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
3121 } |
8282
47a3d2f829e4
clear local symbol table after parsing function
John W. Eaton <jwe@octave.org>
parents:
8150
diff
changeset
|
3122 |
9009
da58ec8f62e8
tag bug don't define forced variables
John W. Eaton <jwe@octave.org>
parents:
8974
diff
changeset
|
3123 // Unmark any symbols that may have been tagged as local |
da58ec8f62e8
tag bug don't define forced variables
John W. Eaton <jwe@octave.org>
parents:
8974
diff
changeset
|
3124 // variables while parsing (for example, by force_local_variable |
da58ec8f62e8
tag bug don't define forced variables
John W. Eaton <jwe@octave.org>
parents:
8974
diff
changeset
|
3125 // in lex.l). |
da58ec8f62e8
tag bug don't define forced variables
John W. Eaton <jwe@octave.org>
parents:
8974
diff
changeset
|
3126 |
da58ec8f62e8
tag bug don't define forced variables
John W. Eaton <jwe@octave.org>
parents:
8974
diff
changeset
|
3127 symbol_table::unmark_forced_variables (fcn->scope ()); |
7715
5b4d278ec828
parse scripts completely before executing
John W. Eaton <jwe@octave.org>
parents:
7699
diff
changeset
|
3128 } |
5b4d278ec828
parse scripts completely before executing
John W. Eaton <jwe@octave.org>
parents:
7699
diff
changeset
|
3129 |
5b4d278ec828
parse scripts completely before executing
John W. Eaton <jwe@octave.org>
parents:
7699
diff
changeset
|
3130 return retval; |
1623 | 3131 } |
3132 | |
2883 | 3133 static void |
3134 recover_from_parsing_function (void) | |
3135 { | |
14329
8d1ae996c122
also save and restore symbol table context in parser (bug #35448)
John W. Eaton <jwe@octave.org>
parents:
14294
diff
changeset
|
3136 if (parser_symtab_context.empty ()) |
3903 | 3137 panic_impossible (); |
3138 | |
14329
8d1ae996c122
also save and restore symbol table context in parser (bug #35448)
John W. Eaton <jwe@octave.org>
parents:
14294
diff
changeset
|
3139 parser_symtab_context.pop (); |
2883 | 3140 |
9474
25ed2d6aacf6
Parse nested functions more accurately.
David Grundberg <individ@acc.umu.se>
parents:
9471
diff
changeset
|
3141 if (reading_fcn_file && current_function_depth == 1 |
25ed2d6aacf6
Parse nested functions more accurately.
David Grundberg <individ@acc.umu.se>
parents:
9471
diff
changeset
|
3142 && ! parsing_subfunctions) |
25ed2d6aacf6
Parse nested functions more accurately.
David Grundberg <individ@acc.umu.se>
parents:
9471
diff
changeset
|
3143 parsing_subfunctions = true; |
25ed2d6aacf6
Parse nested functions more accurately.
David Grundberg <individ@acc.umu.se>
parents:
9471
diff
changeset
|
3144 |
25ed2d6aacf6
Parse nested functions more accurately.
David Grundberg <individ@acc.umu.se>
parents:
9471
diff
changeset
|
3145 current_function_depth--; |
14544
be18c9e359bf
Nested function support (bug #35772)
Max Brister <max@2bass.com>
parents:
14533
diff
changeset
|
3146 function_scopes.pop_back (); |
9474
25ed2d6aacf6
Parse nested functions more accurately.
David Grundberg <individ@acc.umu.se>
parents:
9471
diff
changeset
|
3147 |
11367
b2191ebea12f
don't process input_event_hook when we are parsing a function
John W. Eaton <jwe@octave.org>
parents:
11317
diff
changeset
|
3148 lexer_flags.defining_func--; |
11464
21b5284fa78d
avoid error when parsing nested functions
John W. Eaton <jwe@octave.org>
parents:
11461
diff
changeset
|
3149 lexer_flags.parsed_function_name.pop (); |
2883 | 3150 lexer_flags.looking_at_return_list = false; |
3151 lexer_flags.looking_at_parameter_list = false; | |
3152 } | |
3153 | |
2846 | 3154 // Make an index expression. |
3155 | |
751 | 3156 static tree_index_expression * |
3929 | 3157 make_index_expression (tree_expression *expr, tree_argument_list *args, |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
3158 char type) |
751 | 3159 { |
3160 tree_index_expression *retval = 0; | |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11572
diff
changeset
|
3161 |
10206
37a08e0ce2dc
support Matlab-style empty output/input arguments
Jaroslav Hajek <highegg@gmail.com>
parents:
10188
diff
changeset
|
3162 if (args && args->has_magic_tilde ()) |
37a08e0ce2dc
support Matlab-style empty output/input arguments
Jaroslav Hajek <highegg@gmail.com>
parents:
10188
diff
changeset
|
3163 { |
37a08e0ce2dc
support Matlab-style empty output/input arguments
Jaroslav Hajek <highegg@gmail.com>
parents:
10188
diff
changeset
|
3164 yyerror ("invalid use of empty argument (~) in index expression"); |
37a08e0ce2dc
support Matlab-style empty output/input arguments
Jaroslav Hajek <highegg@gmail.com>
parents:
10188
diff
changeset
|
3165 return retval; |
37a08e0ce2dc
support Matlab-style empty output/input arguments
Jaroslav Hajek <highegg@gmail.com>
parents:
10188
diff
changeset
|
3166 } |
751 | 3167 |
2970 | 3168 int l = expr->line (); |
3169 int c = expr->column (); | |
3170 | |
3171 expr->mark_postfix_indexed (); | |
3172 | |
3933 | 3173 if (expr->is_index_expression ()) |
3174 { | |
3175 tree_index_expression *tmp = static_cast<tree_index_expression *> (expr); | |
3176 | |
3177 tmp->append (args, type); | |
3178 | |
3179 retval = tmp; | |
3180 } | |
3181 else | |
3182 retval = new tree_index_expression (expr, args, l, c, type); | |
2970 | 3183 |
3184 return retval; | |
3185 } | |
3186 | |
3187 // Make an indirect reference expression. | |
3188 | |
3930 | 3189 static tree_index_expression * |
3523 | 3190 make_indirect_ref (tree_expression *expr, const std::string& elt) |
2970 | 3191 { |
3930 | 3192 tree_index_expression *retval = 0; |
2970 | 3193 |
3194 int l = expr->line (); | |
3195 int c = expr->column (); | |
3196 | |
3933 | 3197 if (expr->is_index_expression ()) |
3198 { | |
3199 tree_index_expression *tmp = static_cast<tree_index_expression *> (expr); | |
3200 | |
3201 tmp->append (elt); | |
3202 | |
3203 retval = tmp; | |
3204 } | |
3205 else | |
3206 retval = new tree_index_expression (expr, elt, l, c); | |
2970 | 3207 |
3208 lexer_flags.looking_at_indirect_ref = false; | |
751 | 3209 |
3210 return retval; | |
3211 } | |
1511 | 3212 |
4131 | 3213 // Make an indirect reference expression with dynamic field name. |
3214 | |
3215 static tree_index_expression * | |
3216 make_indirect_ref (tree_expression *expr, tree_expression *elt) | |
3217 { | |
3218 tree_index_expression *retval = 0; | |
3219 | |
3220 int l = expr->line (); | |
3221 int c = expr->column (); | |
3222 | |
3223 if (expr->is_index_expression ()) | |
3224 { | |
3225 tree_index_expression *tmp = static_cast<tree_index_expression *> (expr); | |
3226 | |
3227 tmp->append (elt); | |
3228 | |
3229 retval = tmp; | |
3230 } | |
3231 else | |
3232 retval = new tree_index_expression (expr, elt, l, c); | |
3233 | |
3234 lexer_flags.looking_at_indirect_ref = false; | |
3235 | |
3236 return retval; | |
3237 } | |
3238 | |
2846 | 3239 // Make a declaration command. |
3240 | |
3241 static tree_decl_command * | |
3242 make_decl_command (int tok, token *tok_val, tree_decl_init_list *lst) | |
3243 { | |
3244 tree_decl_command *retval = 0; | |
3245 | |
3246 int l = tok_val->line (); | |
3247 int c = tok_val->column (); | |
3248 | |
3249 switch (tok) | |
3250 { | |
3251 case GLOBAL: | |
3252 retval = new tree_global_command (lst, l, c); | |
3253 break; | |
3254 | |
14294
9e3983c8963c
deprecate the static keyword
John W. Eaton <jwe@octave.org>
parents:
14293
diff
changeset
|
3255 case PERSISTENT: |
9474
25ed2d6aacf6
Parse nested functions more accurately.
David Grundberg <individ@acc.umu.se>
parents:
9471
diff
changeset
|
3256 if (current_function_depth > 0) |
14294
9e3983c8963c
deprecate the static keyword
John W. Eaton <jwe@octave.org>
parents:
14293
diff
changeset
|
3257 retval = new tree_persistent_command (lst, l, c); |
2846 | 3258 else |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
3259 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
3260 if (reading_script_file) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
3261 warning ("ignoring persistent declaration near line %d of file `%s'", |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
3262 l, curr_fcn_file_full_name.c_str ()); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
3263 else |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
3264 warning ("ignoring persistent declaration near line %d", l); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
3265 } |
2846 | 3266 break; |
3267 | |
3268 default: | |
3269 panic_impossible (); | |
3270 break; | |
3271 } | |
3272 | |
3273 return retval; | |
3274 } | |
3275 | |
10207
76a880a588ce
error when using ~ in matrix expression
Jaroslav Hajek <highegg@gmail.com>
parents:
10206
diff
changeset
|
3276 static tree_argument_list * |
76a880a588ce
error when using ~ in matrix expression
Jaroslav Hajek <highegg@gmail.com>
parents:
10206
diff
changeset
|
3277 validate_matrix_row (tree_argument_list *row) |
76a880a588ce
error when using ~ in matrix expression
Jaroslav Hajek <highegg@gmail.com>
parents:
10206
diff
changeset
|
3278 { |
76a880a588ce
error when using ~ in matrix expression
Jaroslav Hajek <highegg@gmail.com>
parents:
10206
diff
changeset
|
3279 if (row && row->has_magic_tilde ()) |
76a880a588ce
error when using ~ in matrix expression
Jaroslav Hajek <highegg@gmail.com>
parents:
10206
diff
changeset
|
3280 yyerror ("invalid use of tilde (~) in matrix expression"); |
76a880a588ce
error when using ~ in matrix expression
Jaroslav Hajek <highegg@gmail.com>
parents:
10206
diff
changeset
|
3281 return row; |
76a880a588ce
error when using ~ in matrix expression
Jaroslav Hajek <highegg@gmail.com>
parents:
10206
diff
changeset
|
3282 } |
76a880a588ce
error when using ~ in matrix expression
Jaroslav Hajek <highegg@gmail.com>
parents:
10206
diff
changeset
|
3283 |
1623 | 3284 // Finish building a matrix list. |
3285 | |
3286 static tree_expression * | |
1829 | 3287 finish_matrix (tree_matrix *m) |
1623 | 3288 { |
3110 | 3289 tree_expression *retval = m; |
3290 | |
10067
6f79338c269b
omission from last patch
Jaroslav Hajek <highegg@gmail.com>
parents:
9794
diff
changeset
|
3291 unwind_protect frame; |
6f79338c269b
omission from last patch
Jaroslav Hajek <highegg@gmail.com>
parents:
9794
diff
changeset
|
3292 |
6f79338c269b
omission from last patch
Jaroslav Hajek <highegg@gmail.com>
parents:
9794
diff
changeset
|
3293 frame.protect_var (error_state); |
6f79338c269b
omission from last patch
Jaroslav Hajek <highegg@gmail.com>
parents:
9794
diff
changeset
|
3294 frame.protect_var (warning_state); |
6f79338c269b
omission from last patch
Jaroslav Hajek <highegg@gmail.com>
parents:
9794
diff
changeset
|
3295 |
6f79338c269b
omission from last patch
Jaroslav Hajek <highegg@gmail.com>
parents:
9794
diff
changeset
|
3296 frame.protect_var (discard_error_messages); |
6f79338c269b
omission from last patch
Jaroslav Hajek <highegg@gmail.com>
parents:
9794
diff
changeset
|
3297 frame.protect_var (discard_warning_messages); |
4452 | 3298 |
3815 | 3299 discard_error_messages = true; |
4452 | 3300 discard_warning_messages = true; |
1623 | 3301 |
2533 | 3302 if (m->all_elements_are_constant ()) |
1829 | 3303 { |
8658
73c4516fae10
New evaluator and debugger derived from tree-walker class
John W. Eaton <jwe@octave.org>
parents:
8471
diff
changeset
|
3304 octave_value tmp = m->rvalue1 (); |
1623 | 3305 |
3489 | 3306 if (! (error_state || warning_state)) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
3307 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
3308 tree_constant *tc_retval |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
3309 = new tree_constant (tmp, m->line (), m->column ()); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
3310 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
3311 std::ostringstream buf; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
3312 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
3313 tree_print_code tpc (buf); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
3314 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
3315 m->accept (tpc); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
3316 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
3317 tc_retval->stash_original_text (buf.str ()); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
3318 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
3319 delete m; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
3320 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
3321 retval = tc_retval; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
3322 } |
1623 | 3323 } |
3110 | 3324 |
1623 | 3325 return retval; |
3326 } | |
3327 | |
3351 | 3328 // Finish building a cell list. |
3329 | |
3330 static tree_expression * | |
3331 finish_cell (tree_cell *c) | |
3332 { | |
5875 | 3333 return finish_matrix (c); |
3351 | 3334 } |
3335 | |
1511 | 3336 static void |
3337 maybe_warn_missing_semi (tree_statement_list *t) | |
3338 { | |
9474
25ed2d6aacf6
Parse nested functions more accurately.
David Grundberg <individ@acc.umu.se>
parents:
9471
diff
changeset
|
3339 if (current_function_depth > 0) |
1511 | 3340 { |
14846
460a3c6d8bf1
maint: Use Octave coding convention for cuddled parenthis in function calls with empty argument lists.
Rik <octave@nomad.inbox5.com>
parents:
14584
diff
changeset
|
3341 tree_statement *tmp = t->back (); |
1607 | 3342 |
1511 | 3343 if (tmp->is_expression ()) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
3344 warning_with_id |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
3345 ("Octave:missing-semicolon", |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
3346 "missing semicolon near line %d, column %d in file `%s'", |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
3347 tmp->line (), tmp->column (), curr_fcn_file_full_name.c_str ()); |
1511 | 3348 } |
3349 } | |
1994 | 3350 |
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
|
3351 static tree_statement_list * |
2525 | 3352 set_stmt_print_flag (tree_statement_list *list, char sep, |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
3353 bool warn_missing_semi) |
2525 | 3354 { |
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
|
3355 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
|
3356 |
2525 | 3357 switch (sep) |
3358 { | |
3359 case ';': | |
8658
73c4516fae10
New evaluator and debugger derived from tree-walker class
John W. Eaton <jwe@octave.org>
parents:
8471
diff
changeset
|
3360 tmp->set_print_flag (false); |
2525 | 3361 break; |
3362 | |
3363 case 0: | |
3364 case ',': | |
3365 case '\n': | |
8658
73c4516fae10
New evaluator and debugger derived from tree-walker class
John W. Eaton <jwe@octave.org>
parents:
8471
diff
changeset
|
3366 tmp->set_print_flag (true); |
2525 | 3367 if (warn_missing_semi) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
3368 maybe_warn_missing_semi (list); |
2525 | 3369 break; |
3370 | |
3371 default: | |
3372 warning ("unrecognized separator type!"); | |
3373 break; | |
3374 } | |
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
|
3375 |
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
|
3376 // 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
|
3377 // 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
|
3378 |
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
|
3379 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
|
3380 { |
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
|
3381 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
|
3382 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
|
3383 } |
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
|
3384 |
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
|
3385 return list; |
2525 | 3386 } |
3387 | |
8448
d6c0d5f208de
parse.y: avoid storing null statements in statement lists
John W. Eaton <jwe@octave.org>
parents:
8447
diff
changeset
|
3388 static tree_statement_list * |
d6c0d5f208de
parse.y: avoid storing null statements in statement lists
John W. Eaton <jwe@octave.org>
parents:
8447
diff
changeset
|
3389 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
|
3390 { |
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
|
3391 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
|
3392 } |
d6c0d5f208de
parse.y: avoid storing null statements in statement lists
John W. Eaton <jwe@octave.org>
parents:
8447
diff
changeset
|
3393 |
d6c0d5f208de
parse.y: avoid storing null statements in statement lists
John W. Eaton <jwe@octave.org>
parents:
8447
diff
changeset
|
3394 static tree_statement_list * |
d6c0d5f208de
parse.y: avoid storing null statements in statement lists
John W. Eaton <jwe@octave.org>
parents:
8447
diff
changeset
|
3395 append_statement_list (tree_statement_list *list, char sep, |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
3396 tree_statement *stmt, bool warn_missing_semi) |
8448
d6c0d5f208de
parse.y: avoid storing null statements in statement lists
John W. Eaton <jwe@octave.org>
parents:
8447
diff
changeset
|
3397 { |
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
|
3398 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
|
3399 |
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
|
3400 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
|
3401 |
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
|
3402 return list; |
8448
d6c0d5f208de
parse.y: avoid storing null statements in statement lists
John W. Eaton <jwe@octave.org>
parents:
8447
diff
changeset
|
3403 } |
d6c0d5f208de
parse.y: avoid storing null statements in statement lists
John W. Eaton <jwe@octave.org>
parents:
8447
diff
changeset
|
3404 |
15037
56b8eb7c9c04
improvements in parsing classdef
John W. Eaton <jwe@octave.org>
parents:
14846
diff
changeset
|
3405 static tree_funcall * |
56b8eb7c9c04
improvements in parsing classdef
John W. Eaton <jwe@octave.org>
parents:
14846
diff
changeset
|
3406 make_superclass_ref (const std::string& method_nm, |
56b8eb7c9c04
improvements in parsing classdef
John W. Eaton <jwe@octave.org>
parents:
14846
diff
changeset
|
3407 const std::string& package_nm, |
56b8eb7c9c04
improvements in parsing classdef
John W. Eaton <jwe@octave.org>
parents:
14846
diff
changeset
|
3408 const std::string& class_nm, |
56b8eb7c9c04
improvements in parsing classdef
John W. Eaton <jwe@octave.org>
parents:
14846
diff
changeset
|
3409 int l, int c) |
56b8eb7c9c04
improvements in parsing classdef
John W. Eaton <jwe@octave.org>
parents:
14846
diff
changeset
|
3410 { |
56b8eb7c9c04
improvements in parsing classdef
John W. Eaton <jwe@octave.org>
parents:
14846
diff
changeset
|
3411 octave_value_list args; |
56b8eb7c9c04
improvements in parsing classdef
John W. Eaton <jwe@octave.org>
parents:
14846
diff
changeset
|
3412 |
56b8eb7c9c04
improvements in parsing classdef
John W. Eaton <jwe@octave.org>
parents:
14846
diff
changeset
|
3413 args(2) = class_nm; |
56b8eb7c9c04
improvements in parsing classdef
John W. Eaton <jwe@octave.org>
parents:
14846
diff
changeset
|
3414 args(1) = package_nm; |
56b8eb7c9c04
improvements in parsing classdef
John W. Eaton <jwe@octave.org>
parents:
14846
diff
changeset
|
3415 args(0) = method_nm; |
56b8eb7c9c04
improvements in parsing classdef
John W. Eaton <jwe@octave.org>
parents:
14846
diff
changeset
|
3416 |
56b8eb7c9c04
improvements in parsing classdef
John W. Eaton <jwe@octave.org>
parents:
14846
diff
changeset
|
3417 octave_value fcn |
56b8eb7c9c04
improvements in parsing classdef
John W. Eaton <jwe@octave.org>
parents:
14846
diff
changeset
|
3418 = symbol_table::find_built_in_function ("__superclass_reference__"); |
56b8eb7c9c04
improvements in parsing classdef
John W. Eaton <jwe@octave.org>
parents:
14846
diff
changeset
|
3419 |
56b8eb7c9c04
improvements in parsing classdef
John W. Eaton <jwe@octave.org>
parents:
14846
diff
changeset
|
3420 return new tree_funcall (fcn, args); |
56b8eb7c9c04
improvements in parsing classdef
John W. Eaton <jwe@octave.org>
parents:
14846
diff
changeset
|
3421 } |
56b8eb7c9c04
improvements in parsing classdef
John W. Eaton <jwe@octave.org>
parents:
14846
diff
changeset
|
3422 |
56b8eb7c9c04
improvements in parsing classdef
John W. Eaton <jwe@octave.org>
parents:
14846
diff
changeset
|
3423 static tree_funcall * |
56b8eb7c9c04
improvements in parsing classdef
John W. Eaton <jwe@octave.org>
parents:
14846
diff
changeset
|
3424 make_meta_class_query (const std::string& package_nm, |
56b8eb7c9c04
improvements in parsing classdef
John W. Eaton <jwe@octave.org>
parents:
14846
diff
changeset
|
3425 const std::string& class_nm, |
56b8eb7c9c04
improvements in parsing classdef
John W. Eaton <jwe@octave.org>
parents:
14846
diff
changeset
|
3426 int l, int c) |
56b8eb7c9c04
improvements in parsing classdef
John W. Eaton <jwe@octave.org>
parents:
14846
diff
changeset
|
3427 { |
56b8eb7c9c04
improvements in parsing classdef
John W. Eaton <jwe@octave.org>
parents:
14846
diff
changeset
|
3428 octave_value_list args; |
56b8eb7c9c04
improvements in parsing classdef
John W. Eaton <jwe@octave.org>
parents:
14846
diff
changeset
|
3429 |
56b8eb7c9c04
improvements in parsing classdef
John W. Eaton <jwe@octave.org>
parents:
14846
diff
changeset
|
3430 args(1) = class_nm; |
56b8eb7c9c04
improvements in parsing classdef
John W. Eaton <jwe@octave.org>
parents:
14846
diff
changeset
|
3431 args(0) = package_nm; |
56b8eb7c9c04
improvements in parsing classdef
John W. Eaton <jwe@octave.org>
parents:
14846
diff
changeset
|
3432 |
56b8eb7c9c04
improvements in parsing classdef
John W. Eaton <jwe@octave.org>
parents:
14846
diff
changeset
|
3433 octave_value fcn |
56b8eb7c9c04
improvements in parsing classdef
John W. Eaton <jwe@octave.org>
parents:
14846
diff
changeset
|
3434 = symbol_table::find_built_in_function ("__meta_class_query__"); |
56b8eb7c9c04
improvements in parsing classdef
John W. Eaton <jwe@octave.org>
parents:
14846
diff
changeset
|
3435 |
56b8eb7c9c04
improvements in parsing classdef
John W. Eaton <jwe@octave.org>
parents:
14846
diff
changeset
|
3436 return new tree_funcall (fcn, args); |
56b8eb7c9c04
improvements in parsing classdef
John W. Eaton <jwe@octave.org>
parents:
14846
diff
changeset
|
3437 } |
56b8eb7c9c04
improvements in parsing classdef
John W. Eaton <jwe@octave.org>
parents:
14846
diff
changeset
|
3438 |
56b8eb7c9c04
improvements in parsing classdef
John W. Eaton <jwe@octave.org>
parents:
14846
diff
changeset
|
3439 // A CLASSDEF block defines a class that has a constructor and other |
56b8eb7c9c04
improvements in parsing classdef
John W. Eaton <jwe@octave.org>
parents:
14846
diff
changeset
|
3440 // methods, but it is not an executable command. Parsing the block |
56b8eb7c9c04
improvements in parsing classdef
John W. Eaton <jwe@octave.org>
parents:
14846
diff
changeset
|
3441 // makes some changes in the symbol table (inserting the constructor |
56b8eb7c9c04
improvements in parsing classdef
John W. Eaton <jwe@octave.org>
parents:
14846
diff
changeset
|
3442 // and methods, and adding to the list of known objects) and creates |
56b8eb7c9c04
improvements in parsing classdef
John W. Eaton <jwe@octave.org>
parents:
14846
diff
changeset
|
3443 // a parse tree containing meta information about the class. |
56b8eb7c9c04
improvements in parsing classdef
John W. Eaton <jwe@octave.org>
parents:
14846
diff
changeset
|
3444 |
56b8eb7c9c04
improvements in parsing classdef
John W. Eaton <jwe@octave.org>
parents:
14846
diff
changeset
|
3445 static tree_classdef * |
56b8eb7c9c04
improvements in parsing classdef
John W. Eaton <jwe@octave.org>
parents:
14846
diff
changeset
|
3446 make_classdef (token *tok_val, tree_classdef_attribute_list *a, |
56b8eb7c9c04
improvements in parsing classdef
John W. Eaton <jwe@octave.org>
parents:
14846
diff
changeset
|
3447 tree_identifier *id, tree_classdef_superclass_list *sc, |
56b8eb7c9c04
improvements in parsing classdef
John W. Eaton <jwe@octave.org>
parents:
14846
diff
changeset
|
3448 tree_classdef_body *body, token *end_tok, |
56b8eb7c9c04
improvements in parsing classdef
John W. Eaton <jwe@octave.org>
parents:
14846
diff
changeset
|
3449 octave_comment_list *lc) |
56b8eb7c9c04
improvements in parsing classdef
John W. Eaton <jwe@octave.org>
parents:
14846
diff
changeset
|
3450 { |
56b8eb7c9c04
improvements in parsing classdef
John W. Eaton <jwe@octave.org>
parents:
14846
diff
changeset
|
3451 tree_classdef *retval = 0; |
56b8eb7c9c04
improvements in parsing classdef
John W. Eaton <jwe@octave.org>
parents:
14846
diff
changeset
|
3452 |
56b8eb7c9c04
improvements in parsing classdef
John W. Eaton <jwe@octave.org>
parents:
14846
diff
changeset
|
3453 if (end_token_ok (end_tok, token::classdef_end)) |
56b8eb7c9c04
improvements in parsing classdef
John W. Eaton <jwe@octave.org>
parents:
14846
diff
changeset
|
3454 { |
56b8eb7c9c04
improvements in parsing classdef
John W. Eaton <jwe@octave.org>
parents:
14846
diff
changeset
|
3455 octave_comment_list *tc = octave_comment_buffer::get_comment (); |
56b8eb7c9c04
improvements in parsing classdef
John W. Eaton <jwe@octave.org>
parents:
14846
diff
changeset
|
3456 |
56b8eb7c9c04
improvements in parsing classdef
John W. Eaton <jwe@octave.org>
parents:
14846
diff
changeset
|
3457 int l = tok_val->line (); |
56b8eb7c9c04
improvements in parsing classdef
John W. Eaton <jwe@octave.org>
parents:
14846
diff
changeset
|
3458 int c = tok_val->column (); |
56b8eb7c9c04
improvements in parsing classdef
John W. Eaton <jwe@octave.org>
parents:
14846
diff
changeset
|
3459 |
56b8eb7c9c04
improvements in parsing classdef
John W. Eaton <jwe@octave.org>
parents:
14846
diff
changeset
|
3460 retval = new tree_classdef (a, id, sc, body, lc, tc, l, c); |
56b8eb7c9c04
improvements in parsing classdef
John W. Eaton <jwe@octave.org>
parents:
14846
diff
changeset
|
3461 } |
56b8eb7c9c04
improvements in parsing classdef
John W. Eaton <jwe@octave.org>
parents:
14846
diff
changeset
|
3462 |
56b8eb7c9c04
improvements in parsing classdef
John W. Eaton <jwe@octave.org>
parents:
14846
diff
changeset
|
3463 return retval; |
56b8eb7c9c04
improvements in parsing classdef
John W. Eaton <jwe@octave.org>
parents:
14846
diff
changeset
|
3464 } |
56b8eb7c9c04
improvements in parsing classdef
John W. Eaton <jwe@octave.org>
parents:
14846
diff
changeset
|
3465 |
56b8eb7c9c04
improvements in parsing classdef
John W. Eaton <jwe@octave.org>
parents:
14846
diff
changeset
|
3466 static tree_classdef_properties_block * |
56b8eb7c9c04
improvements in parsing classdef
John W. Eaton <jwe@octave.org>
parents:
14846
diff
changeset
|
3467 make_classdef_properties_block (token *tok_val, |
56b8eb7c9c04
improvements in parsing classdef
John W. Eaton <jwe@octave.org>
parents:
14846
diff
changeset
|
3468 tree_classdef_attribute_list *a, |
56b8eb7c9c04
improvements in parsing classdef
John W. Eaton <jwe@octave.org>
parents:
14846
diff
changeset
|
3469 tree_classdef_property_list *plist, |
56b8eb7c9c04
improvements in parsing classdef
John W. Eaton <jwe@octave.org>
parents:
14846
diff
changeset
|
3470 token *end_tok, octave_comment_list *lc) |
56b8eb7c9c04
improvements in parsing classdef
John W. Eaton <jwe@octave.org>
parents:
14846
diff
changeset
|
3471 { |
56b8eb7c9c04
improvements in parsing classdef
John W. Eaton <jwe@octave.org>
parents:
14846
diff
changeset
|
3472 tree_classdef_properties_block *retval = 0; |
56b8eb7c9c04
improvements in parsing classdef
John W. Eaton <jwe@octave.org>
parents:
14846
diff
changeset
|
3473 |
56b8eb7c9c04
improvements in parsing classdef
John W. Eaton <jwe@octave.org>
parents:
14846
diff
changeset
|
3474 if (end_token_ok (end_tok, token::properties_end)) |
56b8eb7c9c04
improvements in parsing classdef
John W. Eaton <jwe@octave.org>
parents:
14846
diff
changeset
|
3475 { |
56b8eb7c9c04
improvements in parsing classdef
John W. Eaton <jwe@octave.org>
parents:
14846
diff
changeset
|
3476 octave_comment_list *tc = octave_comment_buffer::get_comment (); |
56b8eb7c9c04
improvements in parsing classdef
John W. Eaton <jwe@octave.org>
parents:
14846
diff
changeset
|
3477 |
56b8eb7c9c04
improvements in parsing classdef
John W. Eaton <jwe@octave.org>
parents:
14846
diff
changeset
|
3478 int l = tok_val->line (); |
56b8eb7c9c04
improvements in parsing classdef
John W. Eaton <jwe@octave.org>
parents:
14846
diff
changeset
|
3479 int c = tok_val->column (); |
56b8eb7c9c04
improvements in parsing classdef
John W. Eaton <jwe@octave.org>
parents:
14846
diff
changeset
|
3480 |
56b8eb7c9c04
improvements in parsing classdef
John W. Eaton <jwe@octave.org>
parents:
14846
diff
changeset
|
3481 retval = new tree_classdef_properties_block (a, plist, lc, tc, l, c); |
56b8eb7c9c04
improvements in parsing classdef
John W. Eaton <jwe@octave.org>
parents:
14846
diff
changeset
|
3482 } |
56b8eb7c9c04
improvements in parsing classdef
John W. Eaton <jwe@octave.org>
parents:
14846
diff
changeset
|
3483 |
56b8eb7c9c04
improvements in parsing classdef
John W. Eaton <jwe@octave.org>
parents:
14846
diff
changeset
|
3484 return retval; |
56b8eb7c9c04
improvements in parsing classdef
John W. Eaton <jwe@octave.org>
parents:
14846
diff
changeset
|
3485 } |
56b8eb7c9c04
improvements in parsing classdef
John W. Eaton <jwe@octave.org>
parents:
14846
diff
changeset
|
3486 |
56b8eb7c9c04
improvements in parsing classdef
John W. Eaton <jwe@octave.org>
parents:
14846
diff
changeset
|
3487 static tree_classdef_methods_block * |
56b8eb7c9c04
improvements in parsing classdef
John W. Eaton <jwe@octave.org>
parents:
14846
diff
changeset
|
3488 make_classdef_methods_block (token *tok_val, |
56b8eb7c9c04
improvements in parsing classdef
John W. Eaton <jwe@octave.org>
parents:
14846
diff
changeset
|
3489 tree_classdef_attribute_list *a, |
56b8eb7c9c04
improvements in parsing classdef
John W. Eaton <jwe@octave.org>
parents:
14846
diff
changeset
|
3490 tree_classdef_methods_list *mlist, |
56b8eb7c9c04
improvements in parsing classdef
John W. Eaton <jwe@octave.org>
parents:
14846
diff
changeset
|
3491 token *end_tok, octave_comment_list *lc) |
56b8eb7c9c04
improvements in parsing classdef
John W. Eaton <jwe@octave.org>
parents:
14846
diff
changeset
|
3492 { |
56b8eb7c9c04
improvements in parsing classdef
John W. Eaton <jwe@octave.org>
parents:
14846
diff
changeset
|
3493 tree_classdef_methods_block *retval = 0; |
56b8eb7c9c04
improvements in parsing classdef
John W. Eaton <jwe@octave.org>
parents:
14846
diff
changeset
|
3494 |
56b8eb7c9c04
improvements in parsing classdef
John W. Eaton <jwe@octave.org>
parents:
14846
diff
changeset
|
3495 if (end_token_ok (end_tok, token::methods_end)) |
56b8eb7c9c04
improvements in parsing classdef
John W. Eaton <jwe@octave.org>
parents:
14846
diff
changeset
|
3496 { |
56b8eb7c9c04
improvements in parsing classdef
John W. Eaton <jwe@octave.org>
parents:
14846
diff
changeset
|
3497 octave_comment_list *tc = octave_comment_buffer::get_comment (); |
56b8eb7c9c04
improvements in parsing classdef
John W. Eaton <jwe@octave.org>
parents:
14846
diff
changeset
|
3498 |
56b8eb7c9c04
improvements in parsing classdef
John W. Eaton <jwe@octave.org>
parents:
14846
diff
changeset
|
3499 int l = tok_val->line (); |
56b8eb7c9c04
improvements in parsing classdef
John W. Eaton <jwe@octave.org>
parents:
14846
diff
changeset
|
3500 int c = tok_val->column (); |
56b8eb7c9c04
improvements in parsing classdef
John W. Eaton <jwe@octave.org>
parents:
14846
diff
changeset
|
3501 |
56b8eb7c9c04
improvements in parsing classdef
John W. Eaton <jwe@octave.org>
parents:
14846
diff
changeset
|
3502 retval = new tree_classdef_methods_block (a, mlist, lc, tc, l, c); |
56b8eb7c9c04
improvements in parsing classdef
John W. Eaton <jwe@octave.org>
parents:
14846
diff
changeset
|
3503 } |
56b8eb7c9c04
improvements in parsing classdef
John W. Eaton <jwe@octave.org>
parents:
14846
diff
changeset
|
3504 |
56b8eb7c9c04
improvements in parsing classdef
John W. Eaton <jwe@octave.org>
parents:
14846
diff
changeset
|
3505 return retval; |
56b8eb7c9c04
improvements in parsing classdef
John W. Eaton <jwe@octave.org>
parents:
14846
diff
changeset
|
3506 } |
56b8eb7c9c04
improvements in parsing classdef
John W. Eaton <jwe@octave.org>
parents:
14846
diff
changeset
|
3507 |
56b8eb7c9c04
improvements in parsing classdef
John W. Eaton <jwe@octave.org>
parents:
14846
diff
changeset
|
3508 static tree_classdef_events_block * |
56b8eb7c9c04
improvements in parsing classdef
John W. Eaton <jwe@octave.org>
parents:
14846
diff
changeset
|
3509 make_classdef_events_block (token *tok_val, |
56b8eb7c9c04
improvements in parsing classdef
John W. Eaton <jwe@octave.org>
parents:
14846
diff
changeset
|
3510 tree_classdef_attribute_list *a, |
56b8eb7c9c04
improvements in parsing classdef
John W. Eaton <jwe@octave.org>
parents:
14846
diff
changeset
|
3511 tree_classdef_events_list *elist, |
56b8eb7c9c04
improvements in parsing classdef
John W. Eaton <jwe@octave.org>
parents:
14846
diff
changeset
|
3512 token *end_tok, octave_comment_list *lc) |
56b8eb7c9c04
improvements in parsing classdef
John W. Eaton <jwe@octave.org>
parents:
14846
diff
changeset
|
3513 { |
56b8eb7c9c04
improvements in parsing classdef
John W. Eaton <jwe@octave.org>
parents:
14846
diff
changeset
|
3514 tree_classdef_events_block *retval = 0; |
56b8eb7c9c04
improvements in parsing classdef
John W. Eaton <jwe@octave.org>
parents:
14846
diff
changeset
|
3515 |
56b8eb7c9c04
improvements in parsing classdef
John W. Eaton <jwe@octave.org>
parents:
14846
diff
changeset
|
3516 if (end_token_ok (end_tok, token::events_end)) |
56b8eb7c9c04
improvements in parsing classdef
John W. Eaton <jwe@octave.org>
parents:
14846
diff
changeset
|
3517 { |
56b8eb7c9c04
improvements in parsing classdef
John W. Eaton <jwe@octave.org>
parents:
14846
diff
changeset
|
3518 octave_comment_list *tc = octave_comment_buffer::get_comment (); |
56b8eb7c9c04
improvements in parsing classdef
John W. Eaton <jwe@octave.org>
parents:
14846
diff
changeset
|
3519 |
56b8eb7c9c04
improvements in parsing classdef
John W. Eaton <jwe@octave.org>
parents:
14846
diff
changeset
|
3520 int l = tok_val->line (); |
56b8eb7c9c04
improvements in parsing classdef
John W. Eaton <jwe@octave.org>
parents:
14846
diff
changeset
|
3521 int c = tok_val->column (); |
56b8eb7c9c04
improvements in parsing classdef
John W. Eaton <jwe@octave.org>
parents:
14846
diff
changeset
|
3522 |
56b8eb7c9c04
improvements in parsing classdef
John W. Eaton <jwe@octave.org>
parents:
14846
diff
changeset
|
3523 retval = new tree_classdef_events_block (a, elist, lc, tc, l, c); |
56b8eb7c9c04
improvements in parsing classdef
John W. Eaton <jwe@octave.org>
parents:
14846
diff
changeset
|
3524 } |
56b8eb7c9c04
improvements in parsing classdef
John W. Eaton <jwe@octave.org>
parents:
14846
diff
changeset
|
3525 |
56b8eb7c9c04
improvements in parsing classdef
John W. Eaton <jwe@octave.org>
parents:
14846
diff
changeset
|
3526 return retval; |
56b8eb7c9c04
improvements in parsing classdef
John W. Eaton <jwe@octave.org>
parents:
14846
diff
changeset
|
3527 } |
56b8eb7c9c04
improvements in parsing classdef
John W. Eaton <jwe@octave.org>
parents:
14846
diff
changeset
|
3528 |
56b8eb7c9c04
improvements in parsing classdef
John W. Eaton <jwe@octave.org>
parents:
14846
diff
changeset
|
3529 static tree_classdef_enum_block * |
56b8eb7c9c04
improvements in parsing classdef
John W. Eaton <jwe@octave.org>
parents:
14846
diff
changeset
|
3530 make_classdef_enum_block (token *tok_val, |
56b8eb7c9c04
improvements in parsing classdef
John W. Eaton <jwe@octave.org>
parents:
14846
diff
changeset
|
3531 tree_classdef_attribute_list *a, |
56b8eb7c9c04
improvements in parsing classdef
John W. Eaton <jwe@octave.org>
parents:
14846
diff
changeset
|
3532 tree_classdef_enum_list *elist, |
56b8eb7c9c04
improvements in parsing classdef
John W. Eaton <jwe@octave.org>
parents:
14846
diff
changeset
|
3533 token *end_tok, octave_comment_list *lc) |
56b8eb7c9c04
improvements in parsing classdef
John W. Eaton <jwe@octave.org>
parents:
14846
diff
changeset
|
3534 { |
56b8eb7c9c04
improvements in parsing classdef
John W. Eaton <jwe@octave.org>
parents:
14846
diff
changeset
|
3535 tree_classdef_enum_block *retval = 0; |
56b8eb7c9c04
improvements in parsing classdef
John W. Eaton <jwe@octave.org>
parents:
14846
diff
changeset
|
3536 |
56b8eb7c9c04
improvements in parsing classdef
John W. Eaton <jwe@octave.org>
parents:
14846
diff
changeset
|
3537 if (end_token_ok (end_tok, token::enumeration_end)) |
56b8eb7c9c04
improvements in parsing classdef
John W. Eaton <jwe@octave.org>
parents:
14846
diff
changeset
|
3538 { |
56b8eb7c9c04
improvements in parsing classdef
John W. Eaton <jwe@octave.org>
parents:
14846
diff
changeset
|
3539 octave_comment_list *tc = octave_comment_buffer::get_comment (); |
56b8eb7c9c04
improvements in parsing classdef
John W. Eaton <jwe@octave.org>
parents:
14846
diff
changeset
|
3540 |
56b8eb7c9c04
improvements in parsing classdef
John W. Eaton <jwe@octave.org>
parents:
14846
diff
changeset
|
3541 int l = tok_val->line (); |
56b8eb7c9c04
improvements in parsing classdef
John W. Eaton <jwe@octave.org>
parents:
14846
diff
changeset
|
3542 int c = tok_val->column (); |
56b8eb7c9c04
improvements in parsing classdef
John W. Eaton <jwe@octave.org>
parents:
14846
diff
changeset
|
3543 |
56b8eb7c9c04
improvements in parsing classdef
John W. Eaton <jwe@octave.org>
parents:
14846
diff
changeset
|
3544 retval = new tree_classdef_enum_block (a, elist, lc, tc, l, c); |
56b8eb7c9c04
improvements in parsing classdef
John W. Eaton <jwe@octave.org>
parents:
14846
diff
changeset
|
3545 } |
56b8eb7c9c04
improvements in parsing classdef
John W. Eaton <jwe@octave.org>
parents:
14846
diff
changeset
|
3546 |
56b8eb7c9c04
improvements in parsing classdef
John W. Eaton <jwe@octave.org>
parents:
14846
diff
changeset
|
3547 return retval; |
56b8eb7c9c04
improvements in parsing classdef
John W. Eaton <jwe@octave.org>
parents:
14846
diff
changeset
|
3548 } |
56b8eb7c9c04
improvements in parsing classdef
John W. Eaton <jwe@octave.org>
parents:
14846
diff
changeset
|
3549 |
3021 | 3550 static void |
10067
6f79338c269b
omission from last patch
Jaroslav Hajek <highegg@gmail.com>
parents:
9794
diff
changeset
|
3551 safe_fclose (FILE *f) |
3021 | 3552 { |
5775 | 3553 // FIXME -- comments at the end of an input file are |
3765 | 3554 // discarded (otherwise, they would be appended to the next |
3555 // statement, possibly from the command line or another file, which | |
3556 // can be quite confusing). | |
3557 | |
5308 | 3558 octave_comment_list *tc = octave_comment_buffer::get_comment (); |
3559 | |
3560 delete tc; | |
3765 | 3561 |
3021 | 3562 if (f) |
3563 fclose (static_cast<FILE *> (f)); | |
3564 } | |
3565 | |
3566 static bool | |
5175 | 3567 looks_like_copyright (const std::string& s) |
3021 | 3568 { |
7720
4e2eafef689c
unify comment and help text processing in lex.l and parse.y
John W. Eaton <jwe@octave.org>
parents:
7719
diff
changeset
|
3569 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
|
3570 |
4e2eafef689c
unify comment and help text processing in lex.l and parse.y
John W. Eaton <jwe@octave.org>
parents:
7719
diff
changeset
|
3571 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
|
3572 { |
4e2eafef689c
unify comment and help text processing in lex.l and parse.y
John W. Eaton <jwe@octave.org>
parents:
7719
diff
changeset
|
3573 size_t offset = s.find_first_not_of (" \t"); |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11572
diff
changeset
|
3574 |
14180
4942b3011541
oct-parse.yy: also identify Author as start of license text
Carnë Draug <carandraug+dev@gmail.com>
parents:
14084
diff
changeset
|
3575 retval = (s.substr (offset, 9) == "Copyright" || s.substr (offset, 6) == "Author"); |
7720
4e2eafef689c
unify comment and help text processing in lex.l and parse.y
John W. Eaton <jwe@octave.org>
parents:
7719
diff
changeset
|
3576 } |
4e2eafef689c
unify comment and help text processing in lex.l and parse.y
John W. Eaton <jwe@octave.org>
parents:
7719
diff
changeset
|
3577 |
4e2eafef689c
unify comment and help text processing in lex.l and parse.y
John W. Eaton <jwe@octave.org>
parents:
7719
diff
changeset
|
3578 return retval; |
3021 | 3579 } |
3580 | |
4540 | 3581 static int |
3582 text_getc (FILE *f) | |
3583 { | |
12918
f3a8d1efe2c1
use gnulib:: qualifiers for more stdio functions
John W. Eaton <jwe@octave.org>
parents:
12719
diff
changeset
|
3584 int c = gnulib::getc (f); |
4540 | 3585 |
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
|
3586 // Convert CRLF into just LF and single CR into LF. |
4540 | 3587 |
3588 if (c == '\r') | |
3589 { | |
12918
f3a8d1efe2c1
use gnulib:: qualifiers for more stdio functions
John W. Eaton <jwe@octave.org>
parents:
12719
diff
changeset
|
3590 c = gnulib::getc (f); |
4540 | 3591 |
8447
adab48231a03
make input_line_number work again
John W. Eaton <jwe@octave.org>
parents:
8311
diff
changeset
|
3592 if (c != '\n') |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
3593 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
3594 ungetc (c, f); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
3595 c = '\n'; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
3596 } |
4540 | 3597 } |
8447
adab48231a03
make input_line_number work again
John W. Eaton <jwe@octave.org>
parents:
8311
diff
changeset
|
3598 |
adab48231a03
make input_line_number work again
John W. Eaton <jwe@octave.org>
parents:
8311
diff
changeset
|
3599 if (c == '\n') |
7723
74f5e0c7de9e
first pass at handling block comments
John W. Eaton <jwe@octave.org>
parents:
7720
diff
changeset
|
3600 input_line_number++; |
4540 | 3601 |
3602 return c; | |
3603 } | |
3604 | |
7720
4e2eafef689c
unify comment and help text processing in lex.l and parse.y
John W. Eaton <jwe@octave.org>
parents:
7719
diff
changeset
|
3605 class |
4e2eafef689c
unify comment and help text processing in lex.l and parse.y
John W. Eaton <jwe@octave.org>
parents:
7719
diff
changeset
|
3606 stdio_stream_reader : public stream_reader |
3021 | 3607 { |
7720
4e2eafef689c
unify comment and help text processing in lex.l and parse.y
John W. Eaton <jwe@octave.org>
parents:
7719
diff
changeset
|
3608 public: |
4e2eafef689c
unify comment and help text processing in lex.l and parse.y
John W. Eaton <jwe@octave.org>
parents:
7719
diff
changeset
|
3609 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
|
3610 |
4e2eafef689c
unify comment and help text processing in lex.l and parse.y
John W. Eaton <jwe@octave.org>
parents:
7719
diff
changeset
|
3611 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
|
3612 int ungetc (int c) |
adab48231a03
make input_line_number work again
John W. Eaton <jwe@octave.org>
parents:
8311
diff
changeset
|
3613 { |
adab48231a03
make input_line_number work again
John W. Eaton <jwe@octave.org>
parents:
8311
diff
changeset
|
3614 if (c == '\n') |
adab48231a03
make input_line_number work again
John W. Eaton <jwe@octave.org>
parents:
8311
diff
changeset
|
3615 input_line_number--; |
adab48231a03
make input_line_number work again
John W. Eaton <jwe@octave.org>
parents:
8311
diff
changeset
|
3616 |
adab48231a03
make input_line_number work again
John W. Eaton <jwe@octave.org>
parents:
8311
diff
changeset
|
3617 return ::ungetc (c, f); |
adab48231a03
make input_line_number work again
John W. Eaton <jwe@octave.org>
parents:
8311
diff
changeset
|
3618 } |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11572
diff
changeset
|
3619 |
7720
4e2eafef689c
unify comment and help text processing in lex.l and parse.y
John W. Eaton <jwe@octave.org>
parents:
7719
diff
changeset
|
3620 private: |
4e2eafef689c
unify comment and help text processing in lex.l and parse.y
John W. Eaton <jwe@octave.org>
parents:
7719
diff
changeset
|
3621 FILE *f; |
12222
91fa3871e9bf
oct-parse.yy (class stdio_stream_reader): disallow copying
Pascal Dupuis <Pascal.Dupuis@uclouvain.be>
parents:
11586
diff
changeset
|
3622 |
91fa3871e9bf
oct-parse.yy (class stdio_stream_reader): disallow copying
Pascal Dupuis <Pascal.Dupuis@uclouvain.be>
parents:
11586
diff
changeset
|
3623 // No copying! |
91fa3871e9bf
oct-parse.yy (class stdio_stream_reader): disallow copying
Pascal Dupuis <Pascal.Dupuis@uclouvain.be>
parents:
11586
diff
changeset
|
3624 |
91fa3871e9bf
oct-parse.yy (class stdio_stream_reader): disallow copying
Pascal Dupuis <Pascal.Dupuis@uclouvain.be>
parents:
11586
diff
changeset
|
3625 stdio_stream_reader (const stdio_stream_reader&); |
91fa3871e9bf
oct-parse.yy (class stdio_stream_reader): disallow copying
Pascal Dupuis <Pascal.Dupuis@uclouvain.be>
parents:
11586
diff
changeset
|
3626 |
91fa3871e9bf
oct-parse.yy (class stdio_stream_reader): disallow copying
Pascal Dupuis <Pascal.Dupuis@uclouvain.be>
parents:
11586
diff
changeset
|
3627 stdio_stream_reader & operator = (const stdio_stream_reader&); |
7720
4e2eafef689c
unify comment and help text processing in lex.l and parse.y
John W. Eaton <jwe@octave.org>
parents:
7719
diff
changeset
|
3628 }; |
4e2eafef689c
unify comment and help text processing in lex.l and parse.y
John W. Eaton <jwe@octave.org>
parents:
7719
diff
changeset
|
3629 |
4e2eafef689c
unify comment and help text processing in lex.l and parse.y
John W. Eaton <jwe@octave.org>
parents:
7719
diff
changeset
|
3630 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
|
3631 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
|
3632 { |
4e2eafef689c
unify comment and help text processing in lex.l and parse.y
John W. Eaton <jwe@octave.org>
parents:
7719
diff
changeset
|
3633 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
|
3634 |
4e2eafef689c
unify comment and help text processing in lex.l and parse.y
John W. Eaton <jwe@octave.org>
parents:
7719
diff
changeset
|
3635 while ((c = reader.getc ()) != EOF) |
3021 | 3636 { |
7720
4e2eafef689c
unify comment and help text processing in lex.l and parse.y
John W. Eaton <jwe@octave.org>
parents:
7719
diff
changeset
|
3637 switch (c) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
3638 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
3639 case ' ': |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
3640 case '\t': |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
3641 current_input_column++; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
3642 break; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
3643 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
3644 case '\n': |
12638
fd367312095a
oct-parse.yy (skip_white_space): Fix column number calculation.
Daniel Kraft <d@domob.eu>
parents:
12627
diff
changeset
|
3645 current_input_column = 1; |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
3646 break; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
3647 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
3648 default: |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
3649 reader.ungetc (c); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
3650 goto done; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
3651 } |
3021 | 3652 } |
3653 | |
3654 done: | |
3655 | |
7720
4e2eafef689c
unify comment and help text processing in lex.l and parse.y
John W. Eaton <jwe@octave.org>
parents:
7719
diff
changeset
|
3656 return (c == EOF); |
3021 | 3657 } |
3658 | |
9476 | 3659 static bool |
3660 looking_at_classdef_keyword (FILE *ffile) | |
3661 { | |
3662 bool status = false; | |
3663 | |
12918
f3a8d1efe2c1
use gnulib:: qualifiers for more stdio functions
John W. Eaton <jwe@octave.org>
parents:
12719
diff
changeset
|
3664 long pos = gnulib::ftell (ffile); |
9476 | 3665 |
3666 char buf [10]; | |
12918
f3a8d1efe2c1
use gnulib:: qualifiers for more stdio functions
John W. Eaton <jwe@octave.org>
parents:
12719
diff
changeset
|
3667 gnulib::fgets (buf, 10, ffile); |
9476 | 3668 size_t len = strlen (buf); |
3669 if (len > 8 && strncmp (buf, "classdef", 8) == 0 | |
3670 && ! (isalnum (buf[8]) || buf[8] == '_')) | |
3671 status = true; | |
3672 | |
12918
f3a8d1efe2c1
use gnulib:: qualifiers for more stdio functions
John W. Eaton <jwe@octave.org>
parents:
12719
diff
changeset
|
3673 gnulib::fseek (ffile, pos, SEEK_SET); |
9476 | 3674 |
3675 return status; | |
3676 } | |
3677 | |
7720
4e2eafef689c
unify comment and help text processing in lex.l and parse.y
John W. Eaton <jwe@octave.org>
parents:
7719
diff
changeset
|
3678 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
|
3679 gobble_leading_white_space (FILE *ffile, bool& eof) |
3021 | 3680 { |
7720
4e2eafef689c
unify comment and help text processing in lex.l and parse.y
John W. Eaton <jwe@octave.org>
parents:
7719
diff
changeset
|
3681 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
|
3682 |
4e2eafef689c
unify comment and help text processing in lex.l and parse.y
John W. Eaton <jwe@octave.org>
parents:
7719
diff
changeset
|
3683 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
|
3684 |
4e2eafef689c
unify comment and help text processing in lex.l and parse.y
John W. Eaton <jwe@octave.org>
parents:
7719
diff
changeset
|
3685 // 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
|
3686 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
|
3687 |
4e2eafef689c
unify comment and help text processing in lex.l and parse.y
John W. Eaton <jwe@octave.org>
parents:
7719
diff
changeset
|
3688 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
|
3689 |
4e2eafef689c
unify comment and help text processing in lex.l and parse.y
John W. Eaton <jwe@octave.org>
parents:
7719
diff
changeset
|
3690 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
|
3691 |
4e2eafef689c
unify comment and help text processing in lex.l and parse.y
John W. Eaton <jwe@octave.org>
parents:
7719
diff
changeset
|
3692 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
|
3693 { |
4e2eafef689c
unify comment and help text processing in lex.l and parse.y
John W. Eaton <jwe@octave.org>
parents:
7719
diff
changeset
|
3694 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
|
3695 |
4e2eafef689c
unify comment and help text processing in lex.l and parse.y
John W. Eaton <jwe@octave.org>
parents:
7719
diff
changeset
|
3696 if (eof) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
3697 break; |
7720
4e2eafef689c
unify comment and help text processing in lex.l and parse.y
John W. Eaton <jwe@octave.org>
parents:
7719
diff
changeset
|
3698 |
7723
74f5e0c7de9e
first pass at handling block comments
John W. Eaton <jwe@octave.org>
parents:
7720
diff
changeset
|
3699 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
|
3700 |
4e2eafef689c
unify comment and help text processing in lex.l and parse.y
John W. Eaton <jwe@octave.org>
parents:
7719
diff
changeset
|
3701 if (txt.empty ()) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
3702 break; |
7720
4e2eafef689c
unify comment and help text processing in lex.l and parse.y
John W. Eaton <jwe@octave.org>
parents:
7719
diff
changeset
|
3703 |
4e2eafef689c
unify comment and help text processing in lex.l and parse.y
John W. Eaton <jwe@octave.org>
parents:
7719
diff
changeset
|
3704 if (! (have_help_text || looks_like_copyright (txt))) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
3705 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
3706 help_txt = txt; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
3707 have_help_text = true; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
3708 } |
7720
4e2eafef689c
unify comment and help text processing in lex.l and parse.y
John W. Eaton <jwe@octave.org>
parents:
7719
diff
changeset
|
3709 |
4e2eafef689c
unify comment and help text processing in lex.l and parse.y
John W. Eaton <jwe@octave.org>
parents:
7719
diff
changeset
|
3710 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
|
3711 |
4e2eafef689c
unify comment and help text processing in lex.l and parse.y
John W. Eaton <jwe@octave.org>
parents:
7719
diff
changeset
|
3712 if (eof) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
3713 break; |
7720
4e2eafef689c
unify comment and help text processing in lex.l and parse.y
John W. Eaton <jwe@octave.org>
parents:
7719
diff
changeset
|
3714 } |
4e2eafef689c
unify comment and help text processing in lex.l and parse.y
John W. Eaton <jwe@octave.org>
parents:
7719
diff
changeset
|
3715 |
4e2eafef689c
unify comment and help text processing in lex.l and parse.y
John W. Eaton <jwe@octave.org>
parents:
7719
diff
changeset
|
3716 return help_txt; |
3021 | 3717 } |
3718 | |
7715
5b4d278ec828
parse scripts completely before executing
John W. Eaton <jwe@octave.org>
parents:
7699
diff
changeset
|
3719 static bool |
5b4d278ec828
parse scripts completely before executing
John W. Eaton <jwe@octave.org>
parents:
7699
diff
changeset
|
3720 looking_at_function_keyword (FILE *ffile) |
5931 | 3721 { |
7715
5b4d278ec828
parse scripts completely before executing
John W. Eaton <jwe@octave.org>
parents:
7699
diff
changeset
|
3722 bool status = false; |
3021 | 3723 |
12918
f3a8d1efe2c1
use gnulib:: qualifiers for more stdio functions
John W. Eaton <jwe@octave.org>
parents:
12719
diff
changeset
|
3724 long pos = gnulib::ftell (ffile); |
3021 | 3725 |
3726 char buf [10]; | |
12918
f3a8d1efe2c1
use gnulib:: qualifiers for more stdio functions
John W. Eaton <jwe@octave.org>
parents:
12719
diff
changeset
|
3727 gnulib::fgets (buf, 10, ffile); |
7715
5b4d278ec828
parse scripts completely before executing
John W. Eaton <jwe@octave.org>
parents:
7699
diff
changeset
|
3728 size_t len = strlen (buf); |
3021 | 3729 if (len > 8 && strncmp (buf, "function", 8) == 0 |
3730 && ! (isalnum (buf[8]) || buf[8] == '_')) | |
7715
5b4d278ec828
parse scripts completely before executing
John W. Eaton <jwe@octave.org>
parents:
7699
diff
changeset
|
3731 status = true; |
3021 | 3732 |
12918
f3a8d1efe2c1
use gnulib:: qualifiers for more stdio functions
John W. Eaton <jwe@octave.org>
parents:
12719
diff
changeset
|
3733 gnulib::fseek (ffile, pos, SEEK_SET); |
3021 | 3734 |
3735 return status; | |
3736 } | |
3737 | |
7336 | 3738 static octave_function * |
3739 parse_fcn_file (const std::string& ff, const std::string& dispatch_type, | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
3740 bool force_script = false, bool require_file = true, |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
3741 const std::string& warn_for = std::string ()) |
3021 | 3742 { |
10067
6f79338c269b
omission from last patch
Jaroslav Hajek <highegg@gmail.com>
parents:
9794
diff
changeset
|
3743 unwind_protect frame; |
3021 | 3744 |
7336 | 3745 octave_function *fcn_ptr = 0; |
3021 | 3746 |
3747 // Open function file and parse. | |
3748 | |
3749 FILE *in_stream = command_editor::get_input_stream (); | |
3750 | |
10067
6f79338c269b
omission from last patch
Jaroslav Hajek <highegg@gmail.com>
parents:
9794
diff
changeset
|
3751 frame.add_fcn (command_editor::set_input_stream, in_stream); |
6f79338c269b
omission from last patch
Jaroslav Hajek <highegg@gmail.com>
parents:
9794
diff
changeset
|
3752 |
6f79338c269b
omission from last patch
Jaroslav Hajek <highegg@gmail.com>
parents:
9794
diff
changeset
|
3753 frame.protect_var (ff_instream); |
6f79338c269b
omission from last patch
Jaroslav Hajek <highegg@gmail.com>
parents:
9794
diff
changeset
|
3754 |
6f79338c269b
omission from last patch
Jaroslav Hajek <highegg@gmail.com>
parents:
9794
diff
changeset
|
3755 frame.protect_var (input_line_number); |
6f79338c269b
omission from last patch
Jaroslav Hajek <highegg@gmail.com>
parents:
9794
diff
changeset
|
3756 frame.protect_var (current_input_column); |
6f79338c269b
omission from last patch
Jaroslav Hajek <highegg@gmail.com>
parents:
9794
diff
changeset
|
3757 frame.protect_var (reading_fcn_file); |
6f79338c269b
omission from last patch
Jaroslav Hajek <highegg@gmail.com>
parents:
9794
diff
changeset
|
3758 frame.protect_var (line_editing); |
6f79338c269b
omission from last patch
Jaroslav Hajek <highegg@gmail.com>
parents:
9794
diff
changeset
|
3759 frame.protect_var (current_class_name); |
6f79338c269b
omission from last patch
Jaroslav Hajek <highegg@gmail.com>
parents:
9794
diff
changeset
|
3760 frame.protect_var (current_function_depth); |
14544
be18c9e359bf
Nested function support (bug #35772)
Max Brister <max@2bass.com>
parents:
14533
diff
changeset
|
3761 frame.protect_var (function_scopes); |
10067
6f79338c269b
omission from last patch
Jaroslav Hajek <highegg@gmail.com>
parents:
9794
diff
changeset
|
3762 frame.protect_var (max_function_depth); |
6f79338c269b
omission from last patch
Jaroslav Hajek <highegg@gmail.com>
parents:
9794
diff
changeset
|
3763 frame.protect_var (parsing_subfunctions); |
6f79338c269b
omission from last patch
Jaroslav Hajek <highegg@gmail.com>
parents:
9794
diff
changeset
|
3764 frame.protect_var (endfunction_found); |
3021 | 3765 |
8447
adab48231a03
make input_line_number work again
John W. Eaton <jwe@octave.org>
parents:
8311
diff
changeset
|
3766 input_line_number = 1; |
3021 | 3767 current_input_column = 1; |
3768 reading_fcn_file = true; | |
3769 line_editing = false; | |
7336 | 3770 current_class_name = dispatch_type; |
9474
25ed2d6aacf6
Parse nested functions more accurately.
David Grundberg <individ@acc.umu.se>
parents:
9471
diff
changeset
|
3771 current_function_depth = 0; |
14544
be18c9e359bf
Nested function support (bug #35772)
Max Brister <max@2bass.com>
parents:
14533
diff
changeset
|
3772 function_scopes.clear (); |
9474
25ed2d6aacf6
Parse nested functions more accurately.
David Grundberg <individ@acc.umu.se>
parents:
9471
diff
changeset
|
3773 max_function_depth = 0; |
25ed2d6aacf6
Parse nested functions more accurately.
David Grundberg <individ@acc.umu.se>
parents:
9471
diff
changeset
|
3774 parsing_subfunctions = false; |
25ed2d6aacf6
Parse nested functions more accurately.
David Grundberg <individ@acc.umu.se>
parents:
9471
diff
changeset
|
3775 endfunction_found = false; |
3021 | 3776 |
12989
00235a6446da
eliminate duplication of internal variables controlling command history
John W. Eaton <jwe@octave.org>
parents:
12973
diff
changeset
|
3777 frame.add_fcn (command_history::ignore_entries, |
00235a6446da
eliminate duplication of internal variables controlling command history
John W. Eaton <jwe@octave.org>
parents:
12973
diff
changeset
|
3778 command_history::ignoring_entries ()); |
00235a6446da
eliminate duplication of internal variables controlling command history
John W. Eaton <jwe@octave.org>
parents:
12973
diff
changeset
|
3779 |
7715
5b4d278ec828
parse scripts completely before executing
John W. Eaton <jwe@octave.org>
parents:
7699
diff
changeset
|
3780 command_history::ignore_entries (); |
5b4d278ec828
parse scripts completely before executing
John W. Eaton <jwe@octave.org>
parents:
7699
diff
changeset
|
3781 |
3021 | 3782 FILE *ffile = get_input_from_file (ff, 0); |
3783 | |
10067
6f79338c269b
omission from last patch
Jaroslav Hajek <highegg@gmail.com>
parents:
9794
diff
changeset
|
3784 frame.add_fcn (safe_fclose, ffile); |
3021 | 3785 |
3786 if (ffile) | |
3787 { | |
7720
4e2eafef689c
unify comment and help text processing in lex.l and parse.y
John W. Eaton <jwe@octave.org>
parents:
7719
diff
changeset
|
3788 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
|
3789 |
4e2eafef689c
unify comment and help text processing in lex.l and parse.y
John W. Eaton <jwe@octave.org>
parents:
7719
diff
changeset
|
3790 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
|
3791 |
10872
988d16d5ae34
correctly .m files that are empty or contain only comments
John W. Eaton <jwe@octave.org>
parents:
10659
diff
changeset
|
3792 if (! help_txt.empty ()) |
988d16d5ae34
correctly .m files that are empty or contain only comments
John W. Eaton <jwe@octave.org>
parents:
10659
diff
changeset
|
3793 help_buf.push (help_txt); |
988d16d5ae34
correctly .m files that are empty or contain only comments
John W. Eaton <jwe@octave.org>
parents:
10659
diff
changeset
|
3794 |
7720
4e2eafef689c
unify comment and help text processing in lex.l and parse.y
John W. Eaton <jwe@octave.org>
parents:
7719
diff
changeset
|
3795 if (! eof) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
3796 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
3797 std::string file_type; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
3798 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
3799 frame.protect_var (get_input_from_eval_string); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
3800 frame.protect_var (parser_end_of_input); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
3801 frame.protect_var (reading_fcn_file); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
3802 frame.protect_var (reading_script_file); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
3803 frame.protect_var (reading_classdef_file); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
3804 frame.protect_var (Vecho_executing_commands); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
3805 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
3806 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
3807 get_input_from_eval_string = false; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
3808 parser_end_of_input = false; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
3809 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
3810 if (! force_script && looking_at_function_keyword (ffile)) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
3811 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
3812 file_type = "function"; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
3813 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
3814 Vecho_executing_commands = ECHO_OFF; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
3815 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
3816 reading_classdef_file = false; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
3817 reading_fcn_file = true; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
3818 reading_script_file = false; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
3819 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
3820 else if (! force_script && looking_at_classdef_keyword (ffile)) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
3821 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
3822 file_type = "classdef"; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
3823 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
3824 Vecho_executing_commands = ECHO_OFF; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
3825 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
3826 reading_classdef_file = true; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
3827 reading_fcn_file = false; |
15037
56b8eb7c9c04
improvements in parsing classdef
John W. Eaton <jwe@octave.org>
parents:
14846
diff
changeset
|
3828 reading_script_file = false; |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
3829 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
3830 else |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
3831 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
3832 file_type = "script"; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
3833 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
3834 Vecho_executing_commands = ECHO_OFF; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
3835 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
3836 reading_classdef_file = false; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
3837 reading_fcn_file = false; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
3838 reading_script_file = true; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
3839 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
3840 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
3841 YY_BUFFER_STATE old_buf = current_buffer (); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
3842 YY_BUFFER_STATE new_buf = create_buffer (ffile); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
3843 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
3844 frame.add_fcn (switch_to_buffer, old_buf); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
3845 frame.add_fcn (delete_buffer, new_buf); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
3846 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
3847 switch_to_buffer (new_buf); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
3848 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
3849 frame.protect_var (primary_fcn_ptr); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
3850 primary_fcn_ptr = 0; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
3851 |
15037
56b8eb7c9c04
improvements in parsing classdef
John W. Eaton <jwe@octave.org>
parents:
14846
diff
changeset
|
3852 frame.protect_var (classdef_object); |
56b8eb7c9c04
improvements in parsing classdef
John W. Eaton <jwe@octave.org>
parents:
14846
diff
changeset
|
3853 classdef_object = 0; |
56b8eb7c9c04
improvements in parsing classdef
John W. Eaton <jwe@octave.org>
parents:
14846
diff
changeset
|
3854 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
3855 reset_parser (); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
3856 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
3857 // Do this with an unwind-protect cleanup function so that |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
3858 // the forced variables will be unmarked in the event of an |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11572
diff
changeset
|
3859 // interrupt. |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
3860 symbol_table::scope_id scope = symbol_table::top_scope (); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
3861 frame.add_fcn (symbol_table::unmark_forced_variables, scope); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
3862 |
10879
5af852c93af3
oct-parse.yy: Restore parsing of help text.
Rik <octave@nomad.inbox5.com>
parents:
10872
diff
changeset
|
3863 if (! help_txt.empty ()) |
5af852c93af3
oct-parse.yy: Restore parsing of help text.
Rik <octave@nomad.inbox5.com>
parents:
10872
diff
changeset
|
3864 help_buf.push (help_txt); |
5af852c93af3
oct-parse.yy: Restore parsing of help text.
Rik <octave@nomad.inbox5.com>
parents:
10872
diff
changeset
|
3865 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
3866 if (reading_script_file) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
3867 prep_lexer_for_script_file (); |
15037
56b8eb7c9c04
improvements in parsing classdef
John W. Eaton <jwe@octave.org>
parents:
14846
diff
changeset
|
3868 else if (reading_classdef_file) |
56b8eb7c9c04
improvements in parsing classdef
John W. Eaton <jwe@octave.org>
parents:
14846
diff
changeset
|
3869 prep_lexer_for_classdef_file (); |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
3870 else |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
3871 prep_lexer_for_function_file (); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
3872 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
3873 lexer_flags.parsing_class_method = ! dispatch_type.empty (); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
3874 |
11258
795c97ace02c
eliminate some possible memory leaks
John W. Eaton <jwe@octave.org>
parents:
11225
diff
changeset
|
3875 frame.protect_var (global_command); |
795c97ace02c
eliminate some possible memory leaks
John W. Eaton <jwe@octave.org>
parents:
11225
diff
changeset
|
3876 |
795c97ace02c
eliminate some possible memory leaks
John W. Eaton <jwe@octave.org>
parents:
11225
diff
changeset
|
3877 global_command = 0; |
795c97ace02c
eliminate some possible memory leaks
John W. Eaton <jwe@octave.org>
parents:
11225
diff
changeset
|
3878 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
3879 int status = yyparse (); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
3880 |
13970 | 3881 // Use an unwind-protect cleanup function so that the |
3882 // global_command list will be deleted in the event of an | |
3883 // interrupt. | |
3884 | |
3885 frame.add_fcn (cleanup_statement_list, &global_command); | |
11258
795c97ace02c
eliminate some possible memory leaks
John W. Eaton <jwe@octave.org>
parents:
11225
diff
changeset
|
3886 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
3887 fcn_ptr = primary_fcn_ptr; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
3888 |
15037
56b8eb7c9c04
improvements in parsing classdef
John W. Eaton <jwe@octave.org>
parents:
14846
diff
changeset
|
3889 if (status == 0) |
56b8eb7c9c04
improvements in parsing classdef
John W. Eaton <jwe@octave.org>
parents:
14846
diff
changeset
|
3890 { |
56b8eb7c9c04
improvements in parsing classdef
John W. Eaton <jwe@octave.org>
parents:
14846
diff
changeset
|
3891 if (reading_classdef_file && classdef_object) |
56b8eb7c9c04
improvements in parsing classdef
John W. Eaton <jwe@octave.org>
parents:
14846
diff
changeset
|
3892 { |
56b8eb7c9c04
improvements in parsing classdef
John W. Eaton <jwe@octave.org>
parents:
14846
diff
changeset
|
3893 // Convert parse tree for classdef object to |
56b8eb7c9c04
improvements in parsing classdef
John W. Eaton <jwe@octave.org>
parents:
14846
diff
changeset
|
3894 // meta.class info (and stash it in the symbol |
56b8eb7c9c04
improvements in parsing classdef
John W. Eaton <jwe@octave.org>
parents:
14846
diff
changeset
|
3895 // table?). Return pointer to constructor? |
56b8eb7c9c04
improvements in parsing classdef
John W. Eaton <jwe@octave.org>
parents:
14846
diff
changeset
|
3896 |
56b8eb7c9c04
improvements in parsing classdef
John W. Eaton <jwe@octave.org>
parents:
14846
diff
changeset
|
3897 octave_value meta_class = classdef_object->make_meta_class (); |
56b8eb7c9c04
improvements in parsing classdef
John W. Eaton <jwe@octave.org>
parents:
14846
diff
changeset
|
3898 } |
56b8eb7c9c04
improvements in parsing classdef
John W. Eaton <jwe@octave.org>
parents:
14846
diff
changeset
|
3899 } |
56b8eb7c9c04
improvements in parsing classdef
John W. Eaton <jwe@octave.org>
parents:
14846
diff
changeset
|
3900 else |
56b8eb7c9c04
improvements in parsing classdef
John W. Eaton <jwe@octave.org>
parents:
14846
diff
changeset
|
3901 { |
56b8eb7c9c04
improvements in parsing classdef
John W. Eaton <jwe@octave.org>
parents:
14846
diff
changeset
|
3902 error ("parse error while reading %s file %s", |
56b8eb7c9c04
improvements in parsing classdef
John W. Eaton <jwe@octave.org>
parents:
14846
diff
changeset
|
3903 file_type.c_str(), ff.c_str ()); |
56b8eb7c9c04
improvements in parsing classdef
John W. Eaton <jwe@octave.org>
parents:
14846
diff
changeset
|
3904 } |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
3905 } |
10872
988d16d5ae34
correctly .m files that are empty or contain only comments
John W. Eaton <jwe@octave.org>
parents:
10659
diff
changeset
|
3906 else |
988d16d5ae34
correctly .m files that are empty or contain only comments
John W. Eaton <jwe@octave.org>
parents:
10659
diff
changeset
|
3907 { |
988d16d5ae34
correctly .m files that are empty or contain only comments
John W. Eaton <jwe@octave.org>
parents:
10659
diff
changeset
|
3908 tree_statement *end_of_script |
988d16d5ae34
correctly .m files that are empty or contain only comments
John W. Eaton <jwe@octave.org>
parents:
10659
diff
changeset
|
3909 = make_end ("endscript", input_line_number, current_input_column); |
988d16d5ae34
correctly .m files that are empty or contain only comments
John W. Eaton <jwe@octave.org>
parents:
10659
diff
changeset
|
3910 |
988d16d5ae34
correctly .m files that are empty or contain only comments
John W. Eaton <jwe@octave.org>
parents:
10659
diff
changeset
|
3911 make_script (0, end_of_script); |
988d16d5ae34
correctly .m files that are empty or contain only comments
John W. Eaton <jwe@octave.org>
parents:
10659
diff
changeset
|
3912 |
988d16d5ae34
correctly .m files that are empty or contain only comments
John W. Eaton <jwe@octave.org>
parents:
10659
diff
changeset
|
3913 fcn_ptr = primary_fcn_ptr; |
988d16d5ae34
correctly .m files that are empty or contain only comments
John W. Eaton <jwe@octave.org>
parents:
10659
diff
changeset
|
3914 } |
3021 | 3915 } |
7715
5b4d278ec828
parse scripts completely before executing
John W. Eaton <jwe@octave.org>
parents:
7699
diff
changeset
|
3916 else if (require_file) |
3880 | 3917 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
|
3918 else if (! warn_for.empty ()) |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11572
diff
changeset
|
3919 error ("%s: unable to open file `%s'", warn_for.c_str (), ff.c_str ()); |
3021 | 3920 |
7336 | 3921 return fcn_ptr; |
3021 | 3922 } |
3923 | |
5484 | 3924 std::string |
7715
5b4d278ec828
parse scripts completely before executing
John W. Eaton <jwe@octave.org>
parents:
7699
diff
changeset
|
3925 get_help_from_file (const std::string& nm, bool& symbol_found, |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
3926 std::string& file) |
7715
5b4d278ec828
parse scripts completely before executing
John W. Eaton <jwe@octave.org>
parents:
7699
diff
changeset
|
3927 { |
5b4d278ec828
parse scripts completely before executing
John W. Eaton <jwe@octave.org>
parents:
7699
diff
changeset
|
3928 std::string retval; |
5b4d278ec828
parse scripts completely before executing
John W. Eaton <jwe@octave.org>
parents:
7699
diff
changeset
|
3929 |
5b4d278ec828
parse scripts completely before executing
John W. Eaton <jwe@octave.org>
parents:
7699
diff
changeset
|
3930 file = fcn_file_in_path (nm); |
5b4d278ec828
parse scripts completely before executing
John W. Eaton <jwe@octave.org>
parents:
7699
diff
changeset
|
3931 |
5b4d278ec828
parse scripts completely before executing
John W. Eaton <jwe@octave.org>
parents:
7699
diff
changeset
|
3932 if (! file.empty ()) |
5b4d278ec828
parse scripts completely before executing
John W. Eaton <jwe@octave.org>
parents:
7699
diff
changeset
|
3933 { |
5b4d278ec828
parse scripts completely before executing
John W. Eaton <jwe@octave.org>
parents:
7699
diff
changeset
|
3934 symbol_found = true; |
5b4d278ec828
parse scripts completely before executing
John W. Eaton <jwe@octave.org>
parents:
7699
diff
changeset
|
3935 |
14153 | 3936 FILE *fptr = gnulib::fopen (file.c_str (), "r"); |
7715
5b4d278ec828
parse scripts completely before executing
John W. Eaton <jwe@octave.org>
parents:
7699
diff
changeset
|
3937 |
5b4d278ec828
parse scripts completely before executing
John W. Eaton <jwe@octave.org>
parents:
7699
diff
changeset
|
3938 if (fptr) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
3939 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
3940 unwind_protect frame; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
3941 frame.add_fcn (safe_fclose, fptr); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
3942 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
3943 bool eof; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
3944 retval = gobble_leading_white_space (fptr, eof); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
3945 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
3946 if (retval.empty ()) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
3947 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
3948 octave_function *fcn = parse_fcn_file (file, ""); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
3949 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
3950 if (fcn) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
3951 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
3952 retval = fcn->doc_string (); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
3953 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
3954 delete fcn; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
3955 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
3956 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
3957 } |
7715
5b4d278ec828
parse scripts completely before executing
John W. Eaton <jwe@octave.org>
parents:
7699
diff
changeset
|
3958 } |
5b4d278ec828
parse scripts completely before executing
John W. Eaton <jwe@octave.org>
parents:
7699
diff
changeset
|
3959 |
5b4d278ec828
parse scripts completely before executing
John W. Eaton <jwe@octave.org>
parents:
7699
diff
changeset
|
3960 return retval; |
5b4d278ec828
parse scripts completely before executing
John W. Eaton <jwe@octave.org>
parents:
7699
diff
changeset
|
3961 } |
5b4d278ec828
parse scripts completely before executing
John W. Eaton <jwe@octave.org>
parents:
7699
diff
changeset
|
3962 |
5b4d278ec828
parse scripts completely before executing
John W. Eaton <jwe@octave.org>
parents:
7699
diff
changeset
|
3963 std::string |
5b4d278ec828
parse scripts completely before executing
John W. Eaton <jwe@octave.org>
parents:
7699
diff
changeset
|
3964 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
|
3965 { |
5b4d278ec828
parse scripts completely before executing
John W. Eaton <jwe@octave.org>
parents:
7699
diff
changeset
|
3966 std::string file; |
5b4d278ec828
parse scripts completely before executing
John W. Eaton <jwe@octave.org>
parents:
7699
diff
changeset
|
3967 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
|
3968 } |
5b4d278ec828
parse scripts completely before executing
John W. Eaton <jwe@octave.org>
parents:
7699
diff
changeset
|
3969 |
5b4d278ec828
parse scripts completely before executing
John W. Eaton <jwe@octave.org>
parents:
7699
diff
changeset
|
3970 std::string |
5484 | 3971 lookup_autoload (const std::string& nm) |
3972 { | |
5626 | 3973 std::string retval; |
3974 | |
3975 typedef std::map<std::string, std::string>::const_iterator am_iter; | |
3976 | |
3977 am_iter p = autoload_map.find (nm); | |
3978 | |
3979 if (p != autoload_map.end ()) | |
6323 | 3980 retval = load_path::find_file (p->second); |
5626 | 3981 |
3982 return retval; | |
5484 | 3983 } |
3984 | |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11572
diff
changeset
|
3985 string_vector |
5592 | 3986 autoloaded_functions (void) |
3987 { | |
14846
460a3c6d8bf1
maint: Use Octave coding convention for cuddled parenthis in function calls with empty argument lists.
Rik <octave@nomad.inbox5.com>
parents:
14584
diff
changeset
|
3988 string_vector names (autoload_map.size ()); |
5592 | 3989 |
3990 octave_idx_type i = 0; | |
5626 | 3991 typedef std::map<std::string, std::string>::const_iterator am_iter; |
3992 for (am_iter p = autoload_map.begin (); p != autoload_map.end (); p++) | |
5592 | 3993 names[i++] = p->first; |
3994 | |
3995 return names; | |
3996 } | |
3997 | |
3998 string_vector | |
3999 reverse_lookup_autoload (const std::string& nm) | |
4000 { | |
4001 string_vector names; | |
4002 | |
5626 | 4003 typedef std::map<std::string, std::string>::const_iterator am_iter; |
4004 for (am_iter p = autoload_map.begin (); p != autoload_map.end (); p++) | |
5592 | 4005 if (nm == p->second) |
4006 names.append (p->first); | |
4007 | |
4008 return names; | |
4009 } | |
4010 | |
7336 | 4011 octave_function * |
4012 load_fcn_from_file (const std::string& file_name, const std::string& dir_name, | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
4013 const std::string& dispatch_type, |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
4014 const std::string& fcn_name, bool autoload) |
3021 | 4015 { |
7336 | 4016 octave_function *retval = 0; |
4017 | |
10067
6f79338c269b
omission from last patch
Jaroslav Hajek <highegg@gmail.com>
parents:
9794
diff
changeset
|
4018 unwind_protect frame; |
5484 | 4019 |
7336 | 4020 std::string nm = file_name; |
6238 | 4021 |
4022 size_t nm_len = nm.length (); | |
5472 | 4023 |
4024 std::string file; | |
4025 | |
10067
6f79338c269b
omission from last patch
Jaroslav Hajek <highegg@gmail.com>
parents:
9794
diff
changeset
|
4026 frame.protect_var (fcn_file_from_relative_lookup); |
6323 | 4027 |
4028 fcn_file_from_relative_lookup = false; | |
4029 | |
7336 | 4030 file = nm; |
4031 | |
4032 if ((nm_len > 4 && nm.substr (nm_len-4) == ".oct") | |
4033 || (nm_len > 4 && nm.substr (nm_len-4) == ".mex") | |
4034 || (nm_len > 2 && nm.substr (nm_len-2) == ".m")) | |
5472 | 4035 { |
6238 | 4036 nm = octave_env::base_pathname (file); |
4037 nm = nm.substr (0, nm.find_last_of ('.')); | |
11136
a51ac4198e1c
oct-parse.yy (load_fcn_from_file): also strip directory when computing function name from filename
John W. Eaton <jwe@octave.org>
parents:
11091
diff
changeset
|
4038 |
a51ac4198e1c
oct-parse.yy (load_fcn_from_file): also strip directory when computing function name from filename
John W. Eaton <jwe@octave.org>
parents:
11091
diff
changeset
|
4039 size_t pos = nm.find_last_of (file_ops::dir_sep_str ()); |
a51ac4198e1c
oct-parse.yy (load_fcn_from_file): also strip directory when computing function name from filename
John W. Eaton <jwe@octave.org>
parents:
11091
diff
changeset
|
4040 if (pos != std::string::npos) |
11138
40206fe759db
oct-parse.yy: fix typo in previous change
John W. Eaton <jwe@octave.org>
parents:
11136
diff
changeset
|
4041 nm = nm.substr (pos+1); |
5472 | 4042 } |
7336 | 4043 |
4044 if (autoload) | |
5472 | 4045 { |
10067
6f79338c269b
omission from last patch
Jaroslav Hajek <highegg@gmail.com>
parents:
9794
diff
changeset
|
4046 frame.protect_var (autoloading); |
7336 | 4047 autoloading = true; |
4048 } | |
4049 | |
7749
14e05160b99f
reference counting for functions loaded from shared libraries
John W. Eaton <jwe@octave.org>
parents:
7736
diff
changeset
|
4050 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
|
4051 |
10250 | 4052 file = octave_env::make_absolute (file); |
4243 | 4053 |
4054 int len = file.length (); | |
4055 | |
4244 | 4056 if (len > 4 && file.substr (len-4, len-1) == ".oct") |
3021 | 4057 { |
7336 | 4058 if (autoload && ! fcn_name.empty ()) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
4059 nm = fcn_name; |
7336 | 4060 |
4061 retval = octave_dynamic_loader::load_oct (nm, file, fcn_file_from_relative_lookup); | |
5864 | 4062 } |
4063 else if (len > 4 && file.substr (len-4, len-1) == ".mex") | |
10570
a61d7248627c
When loading a mex-file temporarily load the m-file version to get the help string (bug #29427)
David Bateman <dbateman@free.fr>
parents:
10521
diff
changeset
|
4064 { |
a61d7248627c
When loading a mex-file temporarily load the m-file version to get the help string (bug #29427)
David Bateman <dbateman@free.fr>
parents:
10521
diff
changeset
|
4065 // Temporarily load m-file version of mex-file, if it exists, |
a61d7248627c
When loading a mex-file temporarily load the m-file version to get the help string (bug #29427)
David Bateman <dbateman@free.fr>
parents:
10521
diff
changeset
|
4066 // to get the help-string to use. |
a61d7248627c
When loading a mex-file temporarily load the m-file version to get the help string (bug #29427)
David Bateman <dbateman@free.fr>
parents:
10521
diff
changeset
|
4067 frame.protect_var (curr_fcn_file_name); |
a61d7248627c
When loading a mex-file temporarily load the m-file version to get the help string (bug #29427)
David Bateman <dbateman@free.fr>
parents:
10521
diff
changeset
|
4068 frame.protect_var (curr_fcn_file_full_name); |
a61d7248627c
When loading a mex-file temporarily load the m-file version to get the help string (bug #29427)
David Bateman <dbateman@free.fr>
parents:
10521
diff
changeset
|
4069 |
a61d7248627c
When loading a mex-file temporarily load the m-file version to get the help string (bug #29427)
David Bateman <dbateman@free.fr>
parents:
10521
diff
changeset
|
4070 curr_fcn_file_name = nm; |
a61d7248627c
When loading a mex-file temporarily load the m-file version to get the help string (bug #29427)
David Bateman <dbateman@free.fr>
parents:
10521
diff
changeset
|
4071 curr_fcn_file_full_name = file.substr (0, len - 2); |
a61d7248627c
When loading a mex-file temporarily load the m-file version to get the help string (bug #29427)
David Bateman <dbateman@free.fr>
parents:
10521
diff
changeset
|
4072 |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11572
diff
changeset
|
4073 octave_function *tmpfcn = parse_fcn_file (file.substr (0, len - 2), |
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11572
diff
changeset
|
4074 dispatch_type, autoloading, |
10570
a61d7248627c
When loading a mex-file temporarily load the m-file version to get the help string (bug #29427)
David Bateman <dbateman@free.fr>
parents:
10521
diff
changeset
|
4075 false); |
a61d7248627c
When loading a mex-file temporarily load the m-file version to get the help string (bug #29427)
David Bateman <dbateman@free.fr>
parents:
10521
diff
changeset
|
4076 |
a61d7248627c
When loading a mex-file temporarily load the m-file version to get the help string (bug #29427)
David Bateman <dbateman@free.fr>
parents:
10521
diff
changeset
|
4077 retval = octave_dynamic_loader::load_mex (nm, file, fcn_file_from_relative_lookup); |
a61d7248627c
When loading a mex-file temporarily load the m-file version to get the help string (bug #29427)
David Bateman <dbateman@free.fr>
parents:
10521
diff
changeset
|
4078 |
a61d7248627c
When loading a mex-file temporarily load the m-file version to get the help string (bug #29427)
David Bateman <dbateman@free.fr>
parents:
10521
diff
changeset
|
4079 if (tmpfcn) |
a61d7248627c
When loading a mex-file temporarily load the m-file version to get the help string (bug #29427)
David Bateman <dbateman@free.fr>
parents:
10521
diff
changeset
|
4080 retval->document (tmpfcn->doc_string ()); |
a61d7248627c
When loading a mex-file temporarily load the m-file version to get the help string (bug #29427)
David Bateman <dbateman@free.fr>
parents:
10521
diff
changeset
|
4081 delete tmpfcn; |
a61d7248627c
When loading a mex-file temporarily load the m-file version to get the help string (bug #29427)
David Bateman <dbateman@free.fr>
parents:
10521
diff
changeset
|
4082 } |
4244 | 4083 else if (len > 2) |
3021 | 4084 { |
7715
5b4d278ec828
parse scripts completely before executing
John W. Eaton <jwe@octave.org>
parents:
7699
diff
changeset
|
4085 // These are needed by yyparse. |
5b4d278ec828
parse scripts completely before executing
John W. Eaton <jwe@octave.org>
parents:
7699
diff
changeset
|
4086 |
10067
6f79338c269b
omission from last patch
Jaroslav Hajek <highegg@gmail.com>
parents:
9794
diff
changeset
|
4087 frame.protect_var (curr_fcn_file_name); |
6f79338c269b
omission from last patch
Jaroslav Hajek <highegg@gmail.com>
parents:
9794
diff
changeset
|
4088 frame.protect_var (curr_fcn_file_full_name); |
7715
5b4d278ec828
parse scripts completely before executing
John W. Eaton <jwe@octave.org>
parents:
7699
diff
changeset
|
4089 |
5b4d278ec828
parse scripts completely before executing
John W. Eaton <jwe@octave.org>
parents:
7699
diff
changeset
|
4090 curr_fcn_file_name = nm; |
5b4d278ec828
parse scripts completely before executing
John W. Eaton <jwe@octave.org>
parents:
7699
diff
changeset
|
4091 curr_fcn_file_full_name = file; |
5b4d278ec828
parse scripts completely before executing
John W. Eaton <jwe@octave.org>
parents:
7699
diff
changeset
|
4092 |
5b4d278ec828
parse scripts completely before executing
John W. Eaton <jwe@octave.org>
parents:
7699
diff
changeset
|
4093 retval = parse_fcn_file (file, dispatch_type, autoloading); |
3021 | 4094 } |
4095 | |
7336 | 4096 if (retval) |
8819
96d87674b818
also stash directory name for subfunctions
John W. Eaton <jwe@octave.org>
parents:
8812
diff
changeset
|
4097 { |
96d87674b818
also stash directory name for subfunctions
John W. Eaton <jwe@octave.org>
parents:
8812
diff
changeset
|
4098 retval->stash_dir_name (dir_name); |
96d87674b818
also stash directory name for subfunctions
John W. Eaton <jwe@octave.org>
parents:
8812
diff
changeset
|
4099 |
96d87674b818
also stash directory name for subfunctions
John W. Eaton <jwe@octave.org>
parents:
8812
diff
changeset
|
4100 if (retval->is_user_function ()) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
4101 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
4102 symbol_table::scope_id id = retval->scope (); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
4103 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
4104 symbol_table::stash_dir_name_for_subfunctions (id, dir_name); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
4105 } |
8819
96d87674b818
also stash directory name for subfunctions
John W. Eaton <jwe@octave.org>
parents:
8812
diff
changeset
|
4106 } |
7336 | 4107 |
4108 return retval; | |
5312 | 4109 } |
4110 | |
8746
5dd06f19e9be
handle commands in the lexer
John W. Eaton <jwe@octave.org>
parents:
8745
diff
changeset
|
4111 DEFUN (autoload, args, , |
5484 | 4112 "-*- texinfo -*-\n\ |
4113 @deftypefn {Built-in Function} {} autoload (@var{function}, @var{file})\n\ | |
4114 Define @var{function} to autoload from @var{file}.\n\ | |
5626 | 4115 \n\ |
6926 | 4116 The second argument, @var{file}, should be an absolute file name or\n\ |
4117 a file name in the same directory as the function or script from which\n\ | |
9038
fca0dc2fb042
Cleanup documentation files stmt.texi and func.texi
Rik <rdrider0-list@yahoo.com>
parents:
8974
diff
changeset
|
4118 the autoload command was run. @var{file} should not depend on the\n\ |
6926 | 4119 Octave load path.\n\ |
6380 | 4120 \n\ |
4121 Normally, calls to @code{autoload} appear in PKG_ADD script files that\n\ | |
4122 are evaluated when a directory is added to the Octave's load path. To\n\ | |
6926 | 4123 avoid having to hardcode directory names in @var{file}, if @var{file}\n\ |
4124 is in the same directory as the PKG_ADD script then\n\ | |
6380 | 4125 \n\ |
4126 @example\n\ | |
6926 | 4127 autoload (\"foo\", \"bar.oct\");\n\ |
6380 | 4128 @end example\n\ |
4129 \n\ | |
11572
7d6d8c1e471f
Grammarcheck Texinfo for files in src directory.
Rik <octave@nomad.inbox5.com>
parents:
11523
diff
changeset
|
4130 @noindent\n\ |
9038
fca0dc2fb042
Cleanup documentation files stmt.texi and func.texi
Rik <rdrider0-list@yahoo.com>
parents:
8974
diff
changeset
|
4131 will load the function @code{foo} from the file @code{bar.oct}. The above\n\ |
6926 | 4132 when @code{bar.oct} is not in the same directory or uses like\n\ |
6380 | 4133 \n\ |
4134 @example\n\ | |
6637 | 4135 autoload (\"foo\", file_in_loadpath (\"bar.oct\"))\n\ |
6380 | 4136 @end example\n\ |
4137 \n\ | |
4138 @noindent\n\ | |
6926 | 4139 are strongly discouraged, as their behavior might be unpredictable.\n\ |
6380 | 4140 \n\ |
6637 | 4141 With no arguments, return a structure containing the current autoload map.\n\ |
6380 | 4142 @seealso{PKG_ADD}\n\ |
5484 | 4143 @end deftypefn") |
4144 { | |
5626 | 4145 octave_value retval; |
5484 | 4146 |
4147 int nargin = args.length (); | |
4148 | |
5626 | 4149 if (nargin == 0) |
4150 { | |
10350
12884915a8e4
merge MArray classes & improve Array interface
Jaroslav Hajek <highegg@gmail.com>
parents:
10315
diff
changeset
|
4151 Cell func_names (dim_vector (autoload_map.size (), 1)); |
12884915a8e4
merge MArray classes & improve Array interface
Jaroslav Hajek <highegg@gmail.com>
parents:
10315
diff
changeset
|
4152 Cell file_names (dim_vector (autoload_map.size (), 1)); |
5626 | 4153 |
4154 octave_idx_type i = 0; | |
4155 typedef std::map<std::string, std::string>::const_iterator am_iter; | |
4156 for (am_iter p = autoload_map.begin (); p != autoload_map.end (); p++) | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
4157 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
4158 func_names(i) = p->first; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
4159 file_names(i) = p->second; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
4160 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
4161 i++; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
4162 } |
5626 | 4163 |
11060
54697b37d8bf
replace Octave_map->octave_scalar_map in oct-parse.yy and ov-fcn-handle.cc
Jaroslav Hajek <highegg@gmail.com>
parents:
10879
diff
changeset
|
4164 octave_map m; |
5626 | 4165 |
4166 m.assign ("function", func_names); | |
4167 m.assign ("file", file_names); | |
4168 | |
4169 retval = m; | |
4170 } | |
4171 else if (nargin == 2) | |
5484 | 4172 { |
4173 string_vector argv = args.make_argv ("autoload"); | |
4174 | |
4175 if (! error_state) | |
6380 | 4176 { |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
4177 std::string nm = argv[2]; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
4178 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
4179 if (! octave_env::absolute_pathname (nm)) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
4180 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
4181 octave_user_code *fcn = octave_call_stack::caller_user_code (); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
4182 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
4183 bool found = false; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
4184 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
4185 if (fcn) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
4186 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
4187 std::string fname = fcn->fcn_file_name (); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
4188 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
4189 if (! fname.empty ()) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
4190 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
4191 fname = octave_env::make_absolute (fname); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
4192 fname = fname.substr (0, fname.find_last_of (file_ops::dir_sep_str ()) + 1); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
4193 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
4194 file_stat fs (fname + nm); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
4195 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
4196 if (fs.exists ()) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
4197 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
4198 nm = fname + nm; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
4199 found = true; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
4200 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
4201 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
4202 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
4203 if (! found) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
4204 warning_with_id ("Octave:autoload-relative-file-name", |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
4205 "autoload: `%s' is not an absolute file name", |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
4206 nm.c_str ()); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
4207 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
4208 autoload_map[argv[1]] = nm; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
4209 } |
5484 | 4210 } |
4211 else | |
5823 | 4212 print_usage (); |
5484 | 4213 |
4214 return retval; | |
4215 } | |
4216 | |
4486 | 4217 void |
7715
5b4d278ec828
parse scripts completely before executing
John W. Eaton <jwe@octave.org>
parents:
7699
diff
changeset
|
4218 source_file (const std::string& file_name, const std::string& context, |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
4219 bool verbose, bool require_file, const std::string& warn_for) |
4486 | 4220 { |
10578
cb0883127251
limit on recursion via calls to source function
John W. Eaton <jwe@octave.org>
parents:
10570
diff
changeset
|
4221 // Map from absolute name of script file to recursion level. We |
cb0883127251
limit on recursion via calls to source function
John W. Eaton <jwe@octave.org>
parents:
10570
diff
changeset
|
4222 // use a map instead of simply placing a limit on recursion in the |
cb0883127251
limit on recursion via calls to source function
John W. Eaton <jwe@octave.org>
parents:
10570
diff
changeset
|
4223 // source_file function so that two mutually recursive scripts |
cb0883127251
limit on recursion via calls to source function
John W. Eaton <jwe@octave.org>
parents:
10570
diff
changeset
|
4224 // written as |
cb0883127251
limit on recursion via calls to source function
John W. Eaton <jwe@octave.org>
parents:
10570
diff
changeset
|
4225 // |
cb0883127251
limit on recursion via calls to source function
John W. Eaton <jwe@octave.org>
parents:
10570
diff
changeset
|
4226 // foo1.m: |
cb0883127251
limit on recursion via calls to source function
John W. Eaton <jwe@octave.org>
parents:
10570
diff
changeset
|
4227 // ------ |
cb0883127251
limit on recursion via calls to source function
John W. Eaton <jwe@octave.org>
parents:
10570
diff
changeset
|
4228 // foo2 |
cb0883127251
limit on recursion via calls to source function
John W. Eaton <jwe@octave.org>
parents:
10570
diff
changeset
|
4229 // |
cb0883127251
limit on recursion via calls to source function
John W. Eaton <jwe@octave.org>
parents:
10570
diff
changeset
|
4230 // foo2.m: |
cb0883127251
limit on recursion via calls to source function
John W. Eaton <jwe@octave.org>
parents:
10570
diff
changeset
|
4231 // ------ |
cb0883127251
limit on recursion via calls to source function
John W. Eaton <jwe@octave.org>
parents:
10570
diff
changeset
|
4232 // foo1 |
cb0883127251
limit on recursion via calls to source function
John W. Eaton <jwe@octave.org>
parents:
10570
diff
changeset
|
4233 // |
cb0883127251
limit on recursion via calls to source function
John W. Eaton <jwe@octave.org>
parents:
10570
diff
changeset
|
4234 // and called with |
cb0883127251
limit on recursion via calls to source function
John W. Eaton <jwe@octave.org>
parents:
10570
diff
changeset
|
4235 // |
cb0883127251
limit on recursion via calls to source function
John W. Eaton <jwe@octave.org>
parents:
10570
diff
changeset
|
4236 // foo1 |
cb0883127251
limit on recursion via calls to source function
John W. Eaton <jwe@octave.org>
parents:
10570
diff
changeset
|
4237 // |
cb0883127251
limit on recursion via calls to source function
John W. Eaton <jwe@octave.org>
parents:
10570
diff
changeset
|
4238 // (for example) will behave the same if they are written as |
cb0883127251
limit on recursion via calls to source function
John W. Eaton <jwe@octave.org>
parents:
10570
diff
changeset
|
4239 // |
cb0883127251
limit on recursion via calls to source function
John W. Eaton <jwe@octave.org>
parents:
10570
diff
changeset
|
4240 // foo1.m: |
cb0883127251
limit on recursion via calls to source function
John W. Eaton <jwe@octave.org>
parents:
10570
diff
changeset
|
4241 // ------ |
cb0883127251
limit on recursion via calls to source function
John W. Eaton <jwe@octave.org>
parents:
10570
diff
changeset
|
4242 // source ("foo2.m") |
cb0883127251
limit on recursion via calls to source function
John W. Eaton <jwe@octave.org>
parents:
10570
diff
changeset
|
4243 // |
cb0883127251
limit on recursion via calls to source function
John W. Eaton <jwe@octave.org>
parents:
10570
diff
changeset
|
4244 // foo2.m: |
cb0883127251
limit on recursion via calls to source function
John W. Eaton <jwe@octave.org>
parents:
10570
diff
changeset
|
4245 // ------ |
cb0883127251
limit on recursion via calls to source function
John W. Eaton <jwe@octave.org>
parents:
10570
diff
changeset
|
4246 // source ("foo1.m") |
cb0883127251
limit on recursion via calls to source function
John W. Eaton <jwe@octave.org>
parents:
10570
diff
changeset
|
4247 // |
cb0883127251
limit on recursion via calls to source function
John W. Eaton <jwe@octave.org>
parents:
10570
diff
changeset
|
4248 // and called with |
cb0883127251
limit on recursion via calls to source function
John W. Eaton <jwe@octave.org>
parents:
10570
diff
changeset
|
4249 // |
cb0883127251
limit on recursion via calls to source function
John W. Eaton <jwe@octave.org>
parents:
10570
diff
changeset
|
4250 // source ("foo1.m") |
cb0883127251
limit on recursion via calls to source function
John W. Eaton <jwe@octave.org>
parents:
10570
diff
changeset
|
4251 // |
cb0883127251
limit on recursion via calls to source function
John W. Eaton <jwe@octave.org>
parents:
10570
diff
changeset
|
4252 // (for example). |
cb0883127251
limit on recursion via calls to source function
John W. Eaton <jwe@octave.org>
parents:
10570
diff
changeset
|
4253 |
cb0883127251
limit on recursion via calls to source function
John W. Eaton <jwe@octave.org>
parents:
10570
diff
changeset
|
4254 static std::map<std::string, int> source_call_depth; |
cb0883127251
limit on recursion via calls to source function
John W. Eaton <jwe@octave.org>
parents:
10570
diff
changeset
|
4255 |
4486 | 4256 std::string file_full_name = file_ops::tilde_expand (file_name); |
4257 | |
10578
cb0883127251
limit on recursion via calls to source function
John W. Eaton <jwe@octave.org>
parents:
10570
diff
changeset
|
4258 file_full_name = octave_env::make_absolute (file_full_name); |
cb0883127251
limit on recursion via calls to source function
John W. Eaton <jwe@octave.org>
parents:
10570
diff
changeset
|
4259 |
10067
6f79338c269b
omission from last patch
Jaroslav Hajek <highegg@gmail.com>
parents:
9794
diff
changeset
|
4260 unwind_protect frame; |
6f79338c269b
omission from last patch
Jaroslav Hajek <highegg@gmail.com>
parents:
9794
diff
changeset
|
4261 |
6f79338c269b
omission from last patch
Jaroslav Hajek <highegg@gmail.com>
parents:
9794
diff
changeset
|
4262 frame.protect_var (curr_fcn_file_name); |
6f79338c269b
omission from last patch
Jaroslav Hajek <highegg@gmail.com>
parents:
9794
diff
changeset
|
4263 frame.protect_var (curr_fcn_file_full_name); |
4486 | 4264 |
4265 curr_fcn_file_name = file_name; | |
4266 curr_fcn_file_full_name = file_full_name; | |
4267 | |
10578
cb0883127251
limit on recursion via calls to source function
John W. Eaton <jwe@octave.org>
parents:
10570
diff
changeset
|
4268 if (source_call_depth.find (file_full_name) == source_call_depth.end ()) |
cb0883127251
limit on recursion via calls to source function
John W. Eaton <jwe@octave.org>
parents:
10570
diff
changeset
|
4269 source_call_depth[file_full_name] = -1; |
cb0883127251
limit on recursion via calls to source function
John W. Eaton <jwe@octave.org>
parents:
10570
diff
changeset
|
4270 |
cb0883127251
limit on recursion via calls to source function
John W. Eaton <jwe@octave.org>
parents:
10570
diff
changeset
|
4271 frame.protect_var (source_call_depth[file_full_name]); |
cb0883127251
limit on recursion via calls to source function
John W. Eaton <jwe@octave.org>
parents:
10570
diff
changeset
|
4272 |
cb0883127251
limit on recursion via calls to source function
John W. Eaton <jwe@octave.org>
parents:
10570
diff
changeset
|
4273 source_call_depth[file_full_name]++; |
cb0883127251
limit on recursion via calls to source function
John W. Eaton <jwe@octave.org>
parents:
10570
diff
changeset
|
4274 |
cb0883127251
limit on recursion via calls to source function
John W. Eaton <jwe@octave.org>
parents:
10570
diff
changeset
|
4275 if (source_call_depth[file_full_name] >= Vmax_recursion_depth) |
cb0883127251
limit on recursion via calls to source function
John W. Eaton <jwe@octave.org>
parents:
10570
diff
changeset
|
4276 { |
cb0883127251
limit on recursion via calls to source function
John W. Eaton <jwe@octave.org>
parents:
10570
diff
changeset
|
4277 error ("max_recursion_depth exceeded"); |
cb0883127251
limit on recursion via calls to source function
John W. Eaton <jwe@octave.org>
parents:
10570
diff
changeset
|
4278 return; |
cb0883127251
limit on recursion via calls to source function
John W. Eaton <jwe@octave.org>
parents:
10570
diff
changeset
|
4279 } |
cb0883127251
limit on recursion via calls to source function
John W. Eaton <jwe@octave.org>
parents:
10570
diff
changeset
|
4280 |
5975 | 4281 if (! context.empty ()) |
4282 { | |
4283 if (context == "caller") | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
4284 octave_call_stack::goto_caller_frame (); |
5975 | 4285 else if (context == "base") |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
4286 octave_call_stack::goto_base_frame (); |
5975 | 4287 else |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
4288 error ("source: context must be \"caller\" or \"base\""); |
7336 | 4289 |
4290 if (! error_state) | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
4291 frame.add_fcn (octave_call_stack::pop); |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11572
diff
changeset
|
4292 } |
5975 | 4293 |
4294 if (! error_state) | |
4295 { | |
7715
5b4d278ec828
parse scripts completely before executing
John W. Eaton <jwe@octave.org>
parents:
7699
diff
changeset
|
4296 octave_function *fcn = parse_fcn_file (file_full_name, "", true, |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
4297 require_file, warn_for); |
7715
5b4d278ec828
parse scripts completely before executing
John W. Eaton <jwe@octave.org>
parents:
7699
diff
changeset
|
4298 |
5b4d278ec828
parse scripts completely before executing
John W. Eaton <jwe@octave.org>
parents:
7699
diff
changeset
|
4299 if (! error_state) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
4300 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
4301 if (fcn && fcn->is_user_script ()) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
4302 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
4303 octave_value_list args; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
4304 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
4305 if (verbose) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
4306 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
4307 std::cout << "executing commands from " << file_full_name << " ... "; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
4308 reading_startup_message_printed = true; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
4309 std::cout.flush (); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
4310 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
4311 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
4312 fcn->do_multi_index_op (0, args); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
4313 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
4314 if (verbose) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
4315 std::cout << "done." << std::endl; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
4316 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
4317 delete fcn; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
4318 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
4319 } |
7715
5b4d278ec828
parse scripts completely before executing
John W. Eaton <jwe@octave.org>
parents:
7699
diff
changeset
|
4320 else |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
4321 error ("source: error sourcing file `%s'", |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
4322 file_full_name.c_str ()); |
5975 | 4323 } |
4486 | 4324 } |
4325 | |
5739 | 4326 DEFUN (mfilename, args, , |
4327 "-*- texinfo -*-\n\ | |
11572
7d6d8c1e471f
Grammarcheck Texinfo for files in src directory.
Rik <octave@nomad.inbox5.com>
parents:
11523
diff
changeset
|
4328 @deftypefn {Built-in Function} {} mfilename ()\n\ |
12719
7b5bfd6a8e28
doc: Don't use @code macro within @deftypefn macro
Rik <octave@nomad.inbox5.com>
parents:
12483
diff
changeset
|
4329 @deftypefnx {Built-in Function} {} mfilename (\"fullpath\")\n\ |
7b5bfd6a8e28
doc: Don't use @code macro within @deftypefn macro
Rik <octave@nomad.inbox5.com>
parents:
12483
diff
changeset
|
4330 @deftypefnx {Built-in Function} {} mfilename (\"fullpathext\")\n\ |
5739 | 4331 Return the name of the currently executing file. At the top-level,\n\ |
4332 return the empty string. Given the argument @code{\"fullpath\"},\n\ | |
4333 include the directory part of the file name, but not the extension.\n\ | |
4334 Given the argument @code{\"fullpathext\"}, include the directory part\n\ | |
4335 of the file name and the extension.\n\ | |
5774 | 4336 @end deftypefn") |
5739 | 4337 { |
4338 octave_value retval; | |
4339 | |
4340 int nargin = args.length (); | |
4341 | |
4342 if (nargin > 1) | |
4343 { | |
5823 | 4344 print_usage (); |
5739 | 4345 return retval; |
4346 } | |
4347 | |
4348 std::string arg; | |
4349 | |
4350 if (nargin == 1) | |
4351 { | |
4352 arg = args(0).string_value (); | |
4353 | |
4354 if (error_state) | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
4355 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
4356 error ("mfilename: expecting argument to be a character string"); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
4357 return retval; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
4358 } |
5739 | 4359 } |
4360 | |
4361 std::string fname; | |
4362 | |
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
|
4363 octave_user_code *fcn = octave_call_stack::caller_user_code (); |
5743 | 4364 |
4365 if (fcn) | |
4366 { | |
4367 fname = fcn->fcn_file_name (); | |
4368 | |
4369 if (fname.empty ()) | |
4370 fname = fcn->name (); | |
4371 } | |
5739 | 4372 |
4373 if (arg == "fullpathext") | |
4374 retval = fname; | |
4375 else | |
4376 { | |
8007
a2ab20ba78f7
make file_ops a proper singleton class
John W. Eaton <jwe@octave.org>
parents:
8001
diff
changeset
|
4377 size_t dpos = fname.rfind (file_ops::dir_sep_char ()); |
5747 | 4378 size_t epos = fname.rfind ('.'); |
4379 | |
4380 if (epos <= dpos) | |
8021 | 4381 epos = std::string::npos; |
4382 | |
4383 fname = (epos != std::string::npos) ? fname.substr (0, epos) : fname; | |
5739 | 4384 |
4385 if (arg == "fullpath") | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
4386 retval = fname; |
5739 | 4387 else |
8021 | 4388 retval = (dpos != std::string::npos) ? fname.substr (dpos+1) : fname; |
5739 | 4389 } |
4390 | |
4391 return retval; | |
4392 } | |
4393 | |
4394 | |
3021 | 4395 DEFUN (source, args, , |
3371 | 4396 "-*- texinfo -*-\n\ |
4397 @deftypefn {Built-in Function} {} source (@var{file})\n\ | |
4398 Parse and execute the contents of @var{file}. This is equivalent to\n\ | |
4399 executing commands from a script file, but without requiring the file to\n\ | |
4400 be named @file{@var{file}.m}.\n\ | |
4401 @end deftypefn") | |
3021 | 4402 { |
4403 octave_value_list retval; | |
4404 | |
4405 int nargin = args.length (); | |
4406 | |
5975 | 4407 if (nargin == 1 || nargin == 2) |
3021 | 4408 { |
3523 | 4409 std::string file_name = args(0).string_value (); |
3021 | 4410 |
4411 if (! error_state) | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
4412 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
4413 std::string context; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
4414 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
4415 if (nargin == 2) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
4416 context = args(1).string_value (); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
4417 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
4418 if (! error_state) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
4419 source_file (file_name, context); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
4420 else |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
4421 error ("source: expecting context to be character string"); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
4422 } |
3021 | 4423 else |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
4424 error ("source: expecting file name as argument"); |
3021 | 4425 } |
4426 else | |
5823 | 4427 print_usage (); |
3021 | 4428 |
4429 return retval; | |
4430 } | |
4431 | |
3726 | 4432 // Evaluate an Octave function (built-in or interpreted) and return |
3844 | 4433 // the list of result values. NAME is the name of the function to |
4434 // call. ARGS are the arguments to the function. NARGOUT is the | |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11572
diff
changeset
|
4435 // number of output arguments expected. |
3726 | 4436 |
3021 | 4437 octave_value_list |
3523 | 4438 feval (const std::string& name, const octave_value_list& args, int nargout) |
3156 | 4439 { |
4440 octave_value_list retval; | |
4441 | |
7336 | 4442 octave_value fcn = symbol_table::find_function (name, args); |
4443 | |
4444 if (fcn.is_defined ()) | |
4445 retval = fcn.do_multi_index_op (nargout, args); | |
4446 else | |
10443
34e51d4e199b
implement smart warnings about missing Matlab functionality
Jaroslav Hajek <highegg@gmail.com>
parents:
10426
diff
changeset
|
4447 { |
34e51d4e199b
implement smart warnings about missing Matlab functionality
Jaroslav Hajek <highegg@gmail.com>
parents:
10426
diff
changeset
|
4448 maybe_missing_function_hook (name); |
34e51d4e199b
implement smart warnings about missing Matlab functionality
Jaroslav Hajek <highegg@gmail.com>
parents:
10426
diff
changeset
|
4449 if (! error_state) |
34e51d4e199b
implement smart warnings about missing Matlab functionality
Jaroslav Hajek <highegg@gmail.com>
parents:
10426
diff
changeset
|
4450 error ("feval: function `%s' not found", name.c_str ()); |
34e51d4e199b
implement smart warnings about missing Matlab functionality
Jaroslav Hajek <highegg@gmail.com>
parents:
10426
diff
changeset
|
4451 } |
3156 | 4452 |
4453 return retval; | |
4454 } | |
4455 | |
4342 | 4456 octave_value_list |
4457 feval (octave_function *fcn, const octave_value_list& args, int nargout) | |
4458 { | |
4459 octave_value_list retval; | |
4460 | |
4461 if (fcn) | |
4462 retval = fcn->do_multi_index_op (nargout, args); | |
4463 | |
4464 return retval; | |
4465 } | |
4466 | |
4467 static octave_value_list | |
4468 get_feval_args (const octave_value_list& args) | |
4469 { | |
10659
8baff2aceabc
fix slicing value lists with name tags (bug #29960)
Jaroslav Hajek <highegg@gmail.com>
parents:
10578
diff
changeset
|
4470 return args.slice (1, args.length () - 1, true); |
4342 | 4471 } |
4472 | |
4473 | |
3726 | 4474 // Evaluate an Octave function (built-in or interpreted) and return |
4475 // the list of result values. The first element of ARGS should be a | |
4476 // string containing the name of the function to call, then the rest | |
4477 // are the actual arguments to the function. NARGOUT is the number of | |
4478 // output arguments expected. | |
4479 | |
3156 | 4480 octave_value_list |
3021 | 4481 feval (const octave_value_list& args, int nargout) |
4482 { | |
4483 octave_value_list retval; | |
4484 | |
4342 | 4485 int nargin = args.length (); |
4486 | |
4487 if (nargin > 0) | |
3021 | 4488 { |
4342 | 4489 octave_value f_arg = args(0); |
4490 | |
4491 if (f_arg.is_string ()) | |
4492 { | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
4493 std::string name = f_arg.string_value (); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
4494 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
4495 if (! error_state) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
4496 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
4497 octave_value_list tmp_args = get_feval_args (args); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
4498 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
4499 retval = feval (name, tmp_args, nargout); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
4500 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
4501 } |
13241
2a8dcb5b3a00
improve default indexing for objects
John W. Eaton <jwe@octave.org>
parents:
13237
diff
changeset
|
4502 else if (f_arg.is_function_handle () |
2a8dcb5b3a00
improve default indexing for objects
John W. Eaton <jwe@octave.org>
parents:
13237
diff
changeset
|
4503 || f_arg.is_anonymous_function () |
2a8dcb5b3a00
improve default indexing for objects
John W. Eaton <jwe@octave.org>
parents:
13237
diff
changeset
|
4504 || f_arg.is_inline_function ()) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
4505 { |
10492
a6b64a7a3769
make feval work with overloaded handles
Jaroslav Hajek <highegg@gmail.com>
parents:
10463
diff
changeset
|
4506 const octave_value_list tmp_args = get_feval_args (args); |
a6b64a7a3769
make feval work with overloaded handles
Jaroslav Hajek <highegg@gmail.com>
parents:
10463
diff
changeset
|
4507 |
a6b64a7a3769
make feval work with overloaded handles
Jaroslav Hajek <highegg@gmail.com>
parents:
10463
diff
changeset
|
4508 retval = f_arg.do_multi_index_op (nargout, tmp_args); |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
4509 } |
10492
a6b64a7a3769
make feval work with overloaded handles
Jaroslav Hajek <highegg@gmail.com>
parents:
10463
diff
changeset
|
4510 else |
a6b64a7a3769
make feval work with overloaded handles
Jaroslav Hajek <highegg@gmail.com>
parents:
10463
diff
changeset
|
4511 error ("feval: first argument must be a string, inline function or a function handle"); |
3021 | 4512 } |
4513 | |
4514 return retval; | |
4515 } | |
4516 | |
4517 DEFUN (feval, args, nargout, | |
3371 | 4518 "-*- texinfo -*-\n\ |
4519 @deftypefn {Built-in Function} {} feval (@var{name}, @dots{})\n\ | |
4520 Evaluate the function named @var{name}. Any arguments after the first\n\ | |
4521 are passed on to the named function. For example,\n\ | |
4522 \n\ | |
4523 @example\n\ | |
11572
7d6d8c1e471f
Grammarcheck Texinfo for files in src directory.
Rik <octave@nomad.inbox5.com>
parents:
11523
diff
changeset
|
4524 @group\n\ |
3371 | 4525 feval (\"acos\", -1)\n\ |
4526 @result{} 3.1416\n\ | |
11572
7d6d8c1e471f
Grammarcheck Texinfo for files in src directory.
Rik <octave@nomad.inbox5.com>
parents:
11523
diff
changeset
|
4527 @end group\n\ |
3371 | 4528 @end example\n\ |
3021 | 4529 \n\ |
3371 | 4530 @noindent\n\ |
4531 calls the function @code{acos} with the argument @samp{-1}.\n\ | |
4532 \n\ | |
12946
8b5b85e26246
octave-parse.yy (feval): Update docstring to refer to function handles.
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents:
12918
diff
changeset
|
4533 The function @code{feval} can also be used with function handles of\n\ |
13019
1653d3a86fca
doc: Fix warnings and errors in Texinfo required for building docs on stable branch.
Rik <octave@nomad.inbox5.com>
parents:
12946
diff
changeset
|
4534 any sort (@pxref{Function Handles}). Historically, @code{feval} was\n\ |
12946
8b5b85e26246
octave-parse.yy (feval): Update docstring to refer to function handles.
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents:
12918
diff
changeset
|
4535 the only way to call user-supplied functions in strings, but\n\ |
8b5b85e26246
octave-parse.yy (feval): Update docstring to refer to function handles.
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents:
12918
diff
changeset
|
4536 function handles are now preferred due to the cleaner syntax they\n\ |
13019
1653d3a86fca
doc: Fix warnings and errors in Texinfo required for building docs on stable branch.
Rik <octave@nomad.inbox5.com>
parents:
12946
diff
changeset
|
4537 offer. For example,\n\ |
12946
8b5b85e26246
octave-parse.yy (feval): Update docstring to refer to function handles.
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents:
12918
diff
changeset
|
4538 \n\ |
8b5b85e26246
octave-parse.yy (feval): Update docstring to refer to function handles.
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents:
12918
diff
changeset
|
4539 @example\n\ |
8b5b85e26246
octave-parse.yy (feval): Update docstring to refer to function handles.
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents:
12918
diff
changeset
|
4540 @group\n\ |
8b5b85e26246
octave-parse.yy (feval): Update docstring to refer to function handles.
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents:
12918
diff
changeset
|
4541 @var{f} = @@exp;\n\ |
8b5b85e26246
octave-parse.yy (feval): Update docstring to refer to function handles.
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents:
12918
diff
changeset
|
4542 feval (@var{f}, 1)\n\ |
14360
97883071e8e4
doc: Correct off-by-1 spacings in all .cc docstrings
Rik <octave@nomad.inbox5.com>
parents:
14329
diff
changeset
|
4543 @result{} 2.7183\n\ |
12946
8b5b85e26246
octave-parse.yy (feval): Update docstring to refer to function handles.
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents:
12918
diff
changeset
|
4544 @var{f} (1)\n\ |
14360
97883071e8e4
doc: Correct off-by-1 spacings in all .cc docstrings
Rik <octave@nomad.inbox5.com>
parents:
14329
diff
changeset
|
4545 @result{} 2.7183\n\ |
12946
8b5b85e26246
octave-parse.yy (feval): Update docstring to refer to function handles.
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents:
12918
diff
changeset
|
4546 @end group\n\ |
8b5b85e26246
octave-parse.yy (feval): Update docstring to refer to function handles.
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents:
12918
diff
changeset
|
4547 @end example\n\ |
8b5b85e26246
octave-parse.yy (feval): Update docstring to refer to function handles.
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents:
12918
diff
changeset
|
4548 \n\ |
8b5b85e26246
octave-parse.yy (feval): Update docstring to refer to function handles.
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents:
12918
diff
changeset
|
4549 @noindent\n\ |
13019
1653d3a86fca
doc: Fix warnings and errors in Texinfo required for building docs on stable branch.
Rik <octave@nomad.inbox5.com>
parents:
12946
diff
changeset
|
4550 are equivalent ways to call the function referred to by @var{f}. If it\n\ |
12946
8b5b85e26246
octave-parse.yy (feval): Update docstring to refer to function handles.
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents:
12918
diff
changeset
|
4551 cannot be predicted beforehand that @var{f} is a function handle or the\n\ |
8b5b85e26246
octave-parse.yy (feval): Update docstring to refer to function handles.
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents:
12918
diff
changeset
|
4552 function name in a string, @code{feval} can be used instead.\n\ |
3371 | 4553 @end deftypefn") |
3021 | 4554 { |
4555 octave_value_list retval; | |
4556 | |
4557 int nargin = args.length (); | |
4558 | |
4559 if (nargin > 0) | |
4560 retval = feval (args, nargout); | |
4561 else | |
5823 | 4562 print_usage (); |
3021 | 4563 |
4564 return retval; | |
4565 } | |
4566 | |
11225
8d8e10058df6
move builtin function from dispatch.cc to oct-parse.yy
John W. Eaton <jwe@octave.org>
parents:
11138
diff
changeset
|
4567 DEFUN (builtin, args, nargout, |
8d8e10058df6
move builtin function from dispatch.cc to oct-parse.yy
John W. Eaton <jwe@octave.org>
parents:
11138
diff
changeset
|
4568 "-*- texinfo -*-\n\ |
8d8e10058df6
move builtin function from dispatch.cc to oct-parse.yy
John W. Eaton <jwe@octave.org>
parents:
11138
diff
changeset
|
4569 @deftypefn {Loadable Function} {[@dots{}]} builtin (@var{f}, @dots{})\n\ |
8d8e10058df6
move builtin function from dispatch.cc to oct-parse.yy
John W. Eaton <jwe@octave.org>
parents:
11138
diff
changeset
|
4570 Call the base function @var{f} even if @var{f} is overloaded to\n\ |
11388
027fbc389898
Remove seealso reference to deprecated function dispatch.
Rik <octave@nomad.inbox5.com>
parents:
11367
diff
changeset
|
4571 another function for the given type signature.\n\ |
11225
8d8e10058df6
move builtin function from dispatch.cc to oct-parse.yy
John W. Eaton <jwe@octave.org>
parents:
11138
diff
changeset
|
4572 @end deftypefn") |
8d8e10058df6
move builtin function from dispatch.cc to oct-parse.yy
John W. Eaton <jwe@octave.org>
parents:
11138
diff
changeset
|
4573 { |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11572
diff
changeset
|
4574 octave_value_list retval; |
11225
8d8e10058df6
move builtin function from dispatch.cc to oct-parse.yy
John W. Eaton <jwe@octave.org>
parents:
11138
diff
changeset
|
4575 |
8d8e10058df6
move builtin function from dispatch.cc to oct-parse.yy
John W. Eaton <jwe@octave.org>
parents:
11138
diff
changeset
|
4576 int nargin = args.length (); |
8d8e10058df6
move builtin function from dispatch.cc to oct-parse.yy
John W. Eaton <jwe@octave.org>
parents:
11138
diff
changeset
|
4577 |
8d8e10058df6
move builtin function from dispatch.cc to oct-parse.yy
John W. Eaton <jwe@octave.org>
parents:
11138
diff
changeset
|
4578 if (nargin > 0) |
8d8e10058df6
move builtin function from dispatch.cc to oct-parse.yy
John W. Eaton <jwe@octave.org>
parents:
11138
diff
changeset
|
4579 { |
8d8e10058df6
move builtin function from dispatch.cc to oct-parse.yy
John W. Eaton <jwe@octave.org>
parents:
11138
diff
changeset
|
4580 const std::string name (args(0).string_value ()); |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11572
diff
changeset
|
4581 |
11225
8d8e10058df6
move builtin function from dispatch.cc to oct-parse.yy
John W. Eaton <jwe@octave.org>
parents:
11138
diff
changeset
|
4582 if (! error_state) |
8d8e10058df6
move builtin function from dispatch.cc to oct-parse.yy
John W. Eaton <jwe@octave.org>
parents:
11138
diff
changeset
|
4583 { |
8d8e10058df6
move builtin function from dispatch.cc to oct-parse.yy
John W. Eaton <jwe@octave.org>
parents:
11138
diff
changeset
|
4584 octave_value fcn = symbol_table::builtin_find (name); |
8d8e10058df6
move builtin function from dispatch.cc to oct-parse.yy
John W. Eaton <jwe@octave.org>
parents:
11138
diff
changeset
|
4585 |
8d8e10058df6
move builtin function from dispatch.cc to oct-parse.yy
John W. Eaton <jwe@octave.org>
parents:
11138
diff
changeset
|
4586 if (fcn.is_defined ()) |
8d8e10058df6
move builtin function from dispatch.cc to oct-parse.yy
John W. Eaton <jwe@octave.org>
parents:
11138
diff
changeset
|
4587 retval = feval (fcn.function_value (), args.splice (0, 1), |
8d8e10058df6
move builtin function from dispatch.cc to oct-parse.yy
John W. Eaton <jwe@octave.org>
parents:
11138
diff
changeset
|
4588 nargout); |
8d8e10058df6
move builtin function from dispatch.cc to oct-parse.yy
John W. Eaton <jwe@octave.org>
parents:
11138
diff
changeset
|
4589 else |
8d8e10058df6
move builtin function from dispatch.cc to oct-parse.yy
John W. Eaton <jwe@octave.org>
parents:
11138
diff
changeset
|
4590 error ("builtin: lookup for symbol `%s' failed", name.c_str ()); |
8d8e10058df6
move builtin function from dispatch.cc to oct-parse.yy
John W. Eaton <jwe@octave.org>
parents:
11138
diff
changeset
|
4591 } |
8d8e10058df6
move builtin function from dispatch.cc to oct-parse.yy
John W. Eaton <jwe@octave.org>
parents:
11138
diff
changeset
|
4592 else |
12483
7a5aacf65f81
Rewrite error strings in src/ to use variables named in documentation.
Rik <octave@nomad.inbox5.com>
parents:
12400
diff
changeset
|
4593 error ("builtin: function name (F) must be a string"); |
11225
8d8e10058df6
move builtin function from dispatch.cc to oct-parse.yy
John W. Eaton <jwe@octave.org>
parents:
11138
diff
changeset
|
4594 } |
8d8e10058df6
move builtin function from dispatch.cc to oct-parse.yy
John W. Eaton <jwe@octave.org>
parents:
11138
diff
changeset
|
4595 else |
8d8e10058df6
move builtin function from dispatch.cc to oct-parse.yy
John W. Eaton <jwe@octave.org>
parents:
11138
diff
changeset
|
4596 print_usage (); |
8d8e10058df6
move builtin function from dispatch.cc to oct-parse.yy
John W. Eaton <jwe@octave.org>
parents:
11138
diff
changeset
|
4597 |
8d8e10058df6
move builtin function from dispatch.cc to oct-parse.yy
John W. Eaton <jwe@octave.org>
parents:
11138
diff
changeset
|
4598 return retval; |
8d8e10058df6
move builtin function from dispatch.cc to oct-parse.yy
John W. Eaton <jwe@octave.org>
parents:
11138
diff
changeset
|
4599 } |
8d8e10058df6
move builtin function from dispatch.cc to oct-parse.yy
John W. Eaton <jwe@octave.org>
parents:
11138
diff
changeset
|
4600 |
3099 | 4601 octave_value_list |
3523 | 4602 eval_string (const std::string& s, bool silent, int& parse_status, int nargout) |
3021 | 4603 { |
3877 | 4604 octave_value_list retval; |
4605 | |
10067
6f79338c269b
omission from last patch
Jaroslav Hajek <highegg@gmail.com>
parents:
9794
diff
changeset
|
4606 unwind_protect frame; |
6f79338c269b
omission from last patch
Jaroslav Hajek <highegg@gmail.com>
parents:
9794
diff
changeset
|
4607 |
6f79338c269b
omission from last patch
Jaroslav Hajek <highegg@gmail.com>
parents:
9794
diff
changeset
|
4608 frame.protect_var (input_line_number); |
6f79338c269b
omission from last patch
Jaroslav Hajek <highegg@gmail.com>
parents:
9794
diff
changeset
|
4609 frame.protect_var (current_input_column); |
6f79338c269b
omission from last patch
Jaroslav Hajek <highegg@gmail.com>
parents:
9794
diff
changeset
|
4610 frame.protect_var (get_input_from_eval_string); |
6f79338c269b
omission from last patch
Jaroslav Hajek <highegg@gmail.com>
parents:
9794
diff
changeset
|
4611 frame.protect_var (input_from_eval_string_pending); |
6f79338c269b
omission from last patch
Jaroslav Hajek <highegg@gmail.com>
parents:
9794
diff
changeset
|
4612 frame.protect_var (parser_end_of_input); |
6f79338c269b
omission from last patch
Jaroslav Hajek <highegg@gmail.com>
parents:
9794
diff
changeset
|
4613 frame.protect_var (line_editing); |
6f79338c269b
omission from last patch
Jaroslav Hajek <highegg@gmail.com>
parents:
9794
diff
changeset
|
4614 frame.protect_var (current_eval_string); |
6f79338c269b
omission from last patch
Jaroslav Hajek <highegg@gmail.com>
parents:
9794
diff
changeset
|
4615 frame.protect_var (current_function_depth); |
14544
be18c9e359bf
Nested function support (bug #35772)
Max Brister <max@2bass.com>
parents:
14533
diff
changeset
|
4616 frame.protect_var (function_scopes); |
10067
6f79338c269b
omission from last patch
Jaroslav Hajek <highegg@gmail.com>
parents:
9794
diff
changeset
|
4617 frame.protect_var (max_function_depth); |
6f79338c269b
omission from last patch
Jaroslav Hajek <highegg@gmail.com>
parents:
9794
diff
changeset
|
4618 frame.protect_var (parsing_subfunctions); |
6f79338c269b
omission from last patch
Jaroslav Hajek <highegg@gmail.com>
parents:
9794
diff
changeset
|
4619 frame.protect_var (endfunction_found); |
10130
0c3609dd34cf
oct-parse.yy (eval_string): save and set reading_{script,fcn,classdef}_file vars
John W. Eaton <jwe@octave.org>
parents:
10067
diff
changeset
|
4620 frame.protect_var (reading_fcn_file); |
0c3609dd34cf
oct-parse.yy (eval_string): save and set reading_{script,fcn,classdef}_file vars
John W. Eaton <jwe@octave.org>
parents:
10067
diff
changeset
|
4621 frame.protect_var (reading_script_file); |
0c3609dd34cf
oct-parse.yy (eval_string): save and set reading_{script,fcn,classdef}_file vars
John W. Eaton <jwe@octave.org>
parents:
10067
diff
changeset
|
4622 frame.protect_var (reading_classdef_file); |
3021 | 4623 |
8447
adab48231a03
make input_line_number work again
John W. Eaton <jwe@octave.org>
parents:
8311
diff
changeset
|
4624 input_line_number = 1; |
adab48231a03
make input_line_number work again
John W. Eaton <jwe@octave.org>
parents:
8311
diff
changeset
|
4625 current_input_column = 1; |
3021 | 4626 get_input_from_eval_string = true; |
3877 | 4627 input_from_eval_string_pending = true; |
3883 | 4628 parser_end_of_input = false; |
5189 | 4629 line_editing = false; |
9474
25ed2d6aacf6
Parse nested functions more accurately.
David Grundberg <individ@acc.umu.se>
parents:
9471
diff
changeset
|
4630 current_function_depth = 0; |
14544
be18c9e359bf
Nested function support (bug #35772)
Max Brister <max@2bass.com>
parents:
14533
diff
changeset
|
4631 function_scopes.clear (); |
9474
25ed2d6aacf6
Parse nested functions more accurately.
David Grundberg <individ@acc.umu.se>
parents:
9471
diff
changeset
|
4632 max_function_depth = 0; |
25ed2d6aacf6
Parse nested functions more accurately.
David Grundberg <individ@acc.umu.se>
parents:
9471
diff
changeset
|
4633 parsing_subfunctions = false; |
25ed2d6aacf6
Parse nested functions more accurately.
David Grundberg <individ@acc.umu.se>
parents:
9471
diff
changeset
|
4634 endfunction_found = false; |
10130
0c3609dd34cf
oct-parse.yy (eval_string): save and set reading_{script,fcn,classdef}_file vars
John W. Eaton <jwe@octave.org>
parents:
10067
diff
changeset
|
4635 reading_fcn_file = false; |
0c3609dd34cf
oct-parse.yy (eval_string): save and set reading_{script,fcn,classdef}_file vars
John W. Eaton <jwe@octave.org>
parents:
10067
diff
changeset
|
4636 reading_script_file = false; |
0c3609dd34cf
oct-parse.yy (eval_string): save and set reading_{script,fcn,classdef}_file vars
John W. Eaton <jwe@octave.org>
parents:
10067
diff
changeset
|
4637 reading_classdef_file = false; |
5189 | 4638 |
3021 | 4639 current_eval_string = s; |
4640 | |
4641 YY_BUFFER_STATE old_buf = current_buffer (); | |
4642 YY_BUFFER_STATE new_buf = create_buffer (0); | |
4643 | |
10067
6f79338c269b
omission from last patch
Jaroslav Hajek <highegg@gmail.com>
parents:
9794
diff
changeset
|
4644 frame.add_fcn (switch_to_buffer, old_buf); |
6f79338c269b
omission from last patch
Jaroslav Hajek <highegg@gmail.com>
parents:
9794
diff
changeset
|
4645 frame.add_fcn (delete_buffer, new_buf); |
3021 | 4646 |
4647 switch_to_buffer (new_buf); | |
4648 | |
3877 | 4649 do |
4650 { | |
4318 | 4651 reset_parser (); |
4652 | |
10067
6f79338c269b
omission from last patch
Jaroslav Hajek <highegg@gmail.com>
parents:
9794
diff
changeset
|
4653 frame.protect_var (global_command); |
7903
8018e10d2b87
save and restore global_command as needed
John W. Eaton <jwe@octave.org>
parents:
7901
diff
changeset
|
4654 |
11258
795c97ace02c
eliminate some possible memory leaks
John W. Eaton <jwe@octave.org>
parents:
11225
diff
changeset
|
4655 global_command = 0; |
795c97ace02c
eliminate some possible memory leaks
John W. Eaton <jwe@octave.org>
parents:
11225
diff
changeset
|
4656 |
9260
9c2349a51218
properly unmark forced variables
John W. Eaton <jwe@octave.org>
parents:
9144
diff
changeset
|
4657 // Do this with an unwind-protect cleanup function so that the |
9c2349a51218
properly unmark forced variables
John W. Eaton <jwe@octave.org>
parents:
9144
diff
changeset
|
4658 // forced variables will be unmarked in the event of an |
9c2349a51218
properly unmark forced variables
John W. Eaton <jwe@octave.org>
parents:
9144
diff
changeset
|
4659 // interrupt. |
9c2349a51218
properly unmark forced variables
John W. Eaton <jwe@octave.org>
parents:
9144
diff
changeset
|
4660 symbol_table::scope_id scope = symbol_table::top_scope (); |
10067
6f79338c269b
omission from last patch
Jaroslav Hajek <highegg@gmail.com>
parents:
9794
diff
changeset
|
4661 frame.add_fcn (symbol_table::unmark_forced_variables, scope); |
9260
9c2349a51218
properly unmark forced variables
John W. Eaton <jwe@octave.org>
parents:
9144
diff
changeset
|
4662 |
3877 | 4663 parse_status = yyparse (); |
4664 | |
8658
73c4516fae10
New evaluator and debugger derived from tree-walker class
John W. Eaton <jwe@octave.org>
parents:
8471
diff
changeset
|
4665 tree_statement_list *command_list = global_command; |
3877 | 4666 |
9260
9c2349a51218
properly unmark forced variables
John W. Eaton <jwe@octave.org>
parents:
9144
diff
changeset
|
4667 // Unmark forced variables. |
7903
8018e10d2b87
save and restore global_command as needed
John W. Eaton <jwe@octave.org>
parents:
7901
diff
changeset
|
4668 // Restore previous value of global_command. |
10067
6f79338c269b
omission from last patch
Jaroslav Hajek <highegg@gmail.com>
parents:
9794
diff
changeset
|
4669 frame.run_top (2); |
7903
8018e10d2b87
save and restore global_command as needed
John W. Eaton <jwe@octave.org>
parents:
7901
diff
changeset
|
4670 |
3883 | 4671 if (parse_status == 0) |
3877 | 4672 { |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
4673 if (command_list) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
4674 { |
13970 | 4675 unwind_protect inner_frame; |
4676 | |
4677 // Use an unwind-protect cleanup function so that the | |
4678 // global_command list will be deleted in the event of an | |
4679 // interrupt. | |
4680 | |
4681 inner_frame.add_fcn (cleanup_statement_list, &command_list); | |
4682 | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
4683 tree_statement *stmt = 0; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
4684 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
4685 if (command_list->length () == 1 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
4686 && (stmt = command_list->front ()) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
4687 && stmt->is_expression ()) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
4688 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
4689 tree_expression *expr = stmt->expression (); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
4690 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
4691 if (silent) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
4692 expr->set_print_flag (false); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
4693 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
4694 bool do_bind_ans = false; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
4695 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
4696 if (expr->is_identifier ()) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
4697 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
4698 tree_identifier *id |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
4699 = dynamic_cast<tree_identifier *> (expr); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
4700 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
4701 do_bind_ans = (! id->is_variable ()); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
4702 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
4703 else |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
4704 do_bind_ans = (! expr->is_assignment_expression ()); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
4705 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
4706 retval = expr->rvalue (nargout); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
4707 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
4708 if (do_bind_ans && ! (error_state || retval.empty ())) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
4709 bind_ans (retval(0), expr->print_result ()); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
4710 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
4711 if (nargout == 0) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
4712 retval = octave_value_list (); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
4713 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
4714 else if (nargout == 0) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
4715 command_list->accept (*current_evaluator); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
4716 else |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
4717 error ("eval: invalid use of statement list"); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
4718 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
4719 if (error_state |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
4720 || tree_return_command::returning |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
4721 || tree_break_command::breaking |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
4722 || tree_continue_command::continuing) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
4723 break; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
4724 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
4725 else if (parser_end_of_input) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
4726 break; |
3883 | 4727 } |
3877 | 4728 } |
4729 while (parse_status == 0); | |
3021 | 4730 |
4731 return retval; | |
4732 } | |
4733 | |
4734 octave_value | |
3523 | 4735 eval_string (const std::string& s, bool silent, int& parse_status) |
3021 | 4736 { |
4737 octave_value retval; | |
4738 | |
4739 octave_value_list tmp = eval_string (s, silent, parse_status, 1); | |
4740 | |
4741 if (! tmp.empty ()) | |
4742 retval = tmp(0); | |
4743 | |
4744 return retval; | |
4745 } | |
4746 | |
4747 static octave_value_list | |
4748 eval_string (const octave_value& arg, bool silent, int& parse_status, | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
4749 int nargout) |
3021 | 4750 { |
3523 | 4751 std::string s = arg.string_value (); |
3021 | 4752 |
4753 if (error_state) | |
4754 { | |
3523 | 4755 error ("eval: expecting std::string argument"); |
4233 | 4756 return octave_value (-1); |
3021 | 4757 } |
4758 | |
4759 return eval_string (s, silent, parse_status, nargout); | |
4760 } | |
4761 | |
13970 | 4762 void |
4763 cleanup_statement_list (tree_statement_list **lst) | |
4764 { | |
4765 if (*lst) | |
4766 { | |
4767 delete *lst; | |
4768 *lst = 0; | |
4769 } | |
4770 } | |
4771 | |
3021 | 4772 DEFUN (eval, args, nargout, |
3371 | 4773 "-*- texinfo -*-\n\ |
14172
cba1c681f1b7
doc: Update seealso references for eval family of functions.
Rik <octave@nomad.inbox5.com>
parents:
14153
diff
changeset
|
4774 @deftypefn {Built-in Function} {} eval (@var{try})\n\ |
cba1c681f1b7
doc: Update seealso references for eval family of functions.
Rik <octave@nomad.inbox5.com>
parents:
14153
diff
changeset
|
4775 @deftypefnx {Built-in Function} {} eval (@var{try}, @var{catch})\n\ |
3371 | 4776 Parse the string @var{try} and evaluate it as if it were an Octave\n\ |
6643 | 4777 program. If that fails, evaluate the optional string @var{catch}.\n\ |
4463 | 4778 The string @var{try} is evaluated in the current context,\n\ |
4779 so any results remain available after @code{eval} returns.\n\ | |
6643 | 4780 \n\ |
4781 The following example makes the variable @var{a} with the approximate\n\ | |
4782 value 3.1416 available.\n\ | |
4783 \n\ | |
4784 @example\n\ | |
14360
97883071e8e4
doc: Correct off-by-1 spacings in all .cc docstrings
Rik <octave@nomad.inbox5.com>
parents:
14329
diff
changeset
|
4785 eval (\"a = acos(-1);\");\n\ |
6643 | 4786 @end example\n\ |
4787 \n\ | |
4788 If an error occurs during the evaluation of @var{try} the @var{catch}\n\ | |
8828 | 4789 string is evaluated, as the following example shows:\n\ |
6643 | 4790 \n\ |
4791 @example\n\ | |
11572
7d6d8c1e471f
Grammarcheck Texinfo for files in src directory.
Rik <octave@nomad.inbox5.com>
parents:
11523
diff
changeset
|
4792 @group\n\ |
6643 | 4793 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
|
4794 'printf (\"This error occurred:\\n%s\\n\", lasterr ());');\n\ |
7001 | 4795 @print{} This error occurred:\n\ |
8015
30629059b72d
Update the manual to reflect the changes in error output
sh@sh-laptop
parents:
8007
diff
changeset
|
4796 This is a bad example\n\ |
11572
7d6d8c1e471f
Grammarcheck Texinfo for files in src directory.
Rik <octave@nomad.inbox5.com>
parents:
11523
diff
changeset
|
4797 @end group\n\ |
6643 | 4798 @end example\n\ |
14172
cba1c681f1b7
doc: Update seealso references for eval family of functions.
Rik <octave@nomad.inbox5.com>
parents:
14153
diff
changeset
|
4799 \n\ |
cba1c681f1b7
doc: Update seealso references for eval family of functions.
Rik <octave@nomad.inbox5.com>
parents:
14153
diff
changeset
|
4800 Consider using try/catch blocks instead if you are only using @code{eval}\n\ |
cba1c681f1b7
doc: Update seealso references for eval family of functions.
Rik <octave@nomad.inbox5.com>
parents:
14153
diff
changeset
|
4801 as an error-capturing mechanism rather than for the execution of arbitrary\n\ |
cba1c681f1b7
doc: Update seealso references for eval family of functions.
Rik <octave@nomad.inbox5.com>
parents:
14153
diff
changeset
|
4802 code strings.\n\ |
cba1c681f1b7
doc: Update seealso references for eval family of functions.
Rik <octave@nomad.inbox5.com>
parents:
14153
diff
changeset
|
4803 @seealso{evalin}\n\ |
3371 | 4804 @end deftypefn") |
3021 | 4805 { |
4806 octave_value_list retval; | |
4807 | |
4808 int nargin = args.length (); | |
4809 | |
4810 if (nargin > 0) | |
4811 { | |
10067
6f79338c269b
omission from last patch
Jaroslav Hajek <highegg@gmail.com>
parents:
9794
diff
changeset
|
4812 unwind_protect frame; |
3021 | 4813 |
4814 if (nargin > 1) | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
4815 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
4816 frame.protect_var (buffer_error_messages); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
4817 buffer_error_messages++; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
4818 } |
3021 | 4819 |
4820 int parse_status = 0; | |
4821 | |
4463 | 4822 octave_value_list tmp = eval_string (args(0), nargout > 0, |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
4823 parse_status, nargout); |
4463 | 4824 |
3021 | 4825 if (nargin > 1 && (parse_status != 0 || error_state)) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
4826 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
4827 error_state = 0; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
4828 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
4829 // Set up for letting the user print any messages from |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
4830 // errors that occurred in the first part of this eval(). |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
4831 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
4832 buffer_error_messages--; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
4833 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
4834 tmp = eval_string (args(1), nargout > 0, parse_status, nargout); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
4835 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
4836 if (nargout > 0) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
4837 retval = tmp; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
4838 } |
8033
2ad5ba320b93
parse.y (Feval): Return value produced by evaluating CATCH string
John W. Eaton <jwe@octave.org>
parents:
8021
diff
changeset
|
4839 else if (nargout > 0) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
4840 retval = tmp; |
3021 | 4841 } |
4842 else | |
5823 | 4843 print_usage (); |
3021 | 4844 |
4845 return retval; | |
4846 } | |
4847 | |
7562
c827f5673321
move tests to individual source files
John W. Eaton <jwe@octave.org>
parents:
7351
diff
changeset
|
4848 /* |
c827f5673321
move tests to individual source files
John W. Eaton <jwe@octave.org>
parents:
7351
diff
changeset
|
4849 |
14084
5aba9fa234cf
Modernize %!tests for eval()
Rik <octave@nomad.inbox5.com>
parents:
13970
diff
changeset
|
4850 %!shared x |
7562
c827f5673321
move tests to individual source files
John W. Eaton <jwe@octave.org>
parents:
7351
diff
changeset
|
4851 %! x = 1; |
14084
5aba9fa234cf
Modernize %!tests for eval()
Rik <octave@nomad.inbox5.com>
parents:
13970
diff
changeset
|
4852 |
5aba9fa234cf
Modernize %!tests for eval()
Rik <octave@nomad.inbox5.com>
parents:
13970
diff
changeset
|
4853 %!assert (eval ("x"), 1) |
5aba9fa234cf
Modernize %!tests for eval()
Rik <octave@nomad.inbox5.com>
parents:
13970
diff
changeset
|
4854 %!assert (eval ("x;")) |
5aba9fa234cf
Modernize %!tests for eval()
Rik <octave@nomad.inbox5.com>
parents:
13970
diff
changeset
|
4855 %!assert (eval ("x;"), 1); |
5aba9fa234cf
Modernize %!tests for eval()
Rik <octave@nomad.inbox5.com>
parents:
13970
diff
changeset
|
4856 |
7562
c827f5673321
move tests to individual source files
John W. Eaton <jwe@octave.org>
parents:
7351
diff
changeset
|
4857 %!test |
14084
5aba9fa234cf
Modernize %!tests for eval()
Rik <octave@nomad.inbox5.com>
parents:
13970
diff
changeset
|
4858 %! y = eval ("x"); |
5aba9fa234cf
Modernize %!tests for eval()
Rik <octave@nomad.inbox5.com>
parents:
13970
diff
changeset
|
4859 %! assert (y, 1); |
5aba9fa234cf
Modernize %!tests for eval()
Rik <octave@nomad.inbox5.com>
parents:
13970
diff
changeset
|
4860 |
5aba9fa234cf
Modernize %!tests for eval()
Rik <octave@nomad.inbox5.com>
parents:
13970
diff
changeset
|
4861 %!test |
5aba9fa234cf
Modernize %!tests for eval()
Rik <octave@nomad.inbox5.com>
parents:
13970
diff
changeset
|
4862 %! y = eval ("x;"); |
5aba9fa234cf
Modernize %!tests for eval()
Rik <octave@nomad.inbox5.com>
parents:
13970
diff
changeset
|
4863 %! assert (y, 1); |
5aba9fa234cf
Modernize %!tests for eval()
Rik <octave@nomad.inbox5.com>
parents:
13970
diff
changeset
|
4864 |
5aba9fa234cf
Modernize %!tests for eval()
Rik <octave@nomad.inbox5.com>
parents:
13970
diff
changeset
|
4865 %!test |
5aba9fa234cf
Modernize %!tests for eval()
Rik <octave@nomad.inbox5.com>
parents:
13970
diff
changeset
|
4866 %! eval ("x = 1;") |
5aba9fa234cf
Modernize %!tests for eval()
Rik <octave@nomad.inbox5.com>
parents:
13970
diff
changeset
|
4867 %! assert (x,1); |
5aba9fa234cf
Modernize %!tests for eval()
Rik <octave@nomad.inbox5.com>
parents:
13970
diff
changeset
|
4868 |
7562
c827f5673321
move tests to individual source files
John W. Eaton <jwe@octave.org>
parents:
7351
diff
changeset
|
4869 %!test |
c827f5673321
move tests to individual source files
John W. Eaton <jwe@octave.org>
parents:
7351
diff
changeset
|
4870 %! eval ("flipud = 2;"); |
14084
5aba9fa234cf
Modernize %!tests for eval()
Rik <octave@nomad.inbox5.com>
parents:
13970
diff
changeset
|
4871 %! assert (flipud, 2); |
5aba9fa234cf
Modernize %!tests for eval()
Rik <octave@nomad.inbox5.com>
parents:
13970
diff
changeset
|
4872 |
5aba9fa234cf
Modernize %!tests for eval()
Rik <octave@nomad.inbox5.com>
parents:
13970
diff
changeset
|
4873 %!function y = __f () |
7562
c827f5673321
move tests to individual source files
John W. Eaton <jwe@octave.org>
parents:
7351
diff
changeset
|
4874 %! eval ("flipud = 2;"); |
c827f5673321
move tests to individual source files
John W. Eaton <jwe@octave.org>
parents:
7351
diff
changeset
|
4875 %! y = flipud; |
14084
5aba9fa234cf
Modernize %!tests for eval()
Rik <octave@nomad.inbox5.com>
parents:
13970
diff
changeset
|
4876 %!endfunction |
5aba9fa234cf
Modernize %!tests for eval()
Rik <octave@nomad.inbox5.com>
parents:
13970
diff
changeset
|
4877 %!assert (__f(), 2) |
7562
c827f5673321
move tests to individual source files
John W. Eaton <jwe@octave.org>
parents:
7351
diff
changeset
|
4878 |
14533
e6aa044253eb
Allow comma at the end of an assignment list (bug #35645)
Max Brister <max@2bass.com>
parents:
14512
diff
changeset
|
4879 % bug #35645 |
e6aa044253eb
Allow comma at the end of an assignment list (bug #35645)
Max Brister <max@2bass.com>
parents:
14512
diff
changeset
|
4880 %!test |
e6aa044253eb
Allow comma at the end of an assignment list (bug #35645)
Max Brister <max@2bass.com>
parents:
14512
diff
changeset
|
4881 %! [a,] = gcd (1,2); |
e6aa044253eb
Allow comma at the end of an assignment list (bug #35645)
Max Brister <max@2bass.com>
parents:
14512
diff
changeset
|
4882 %! [a,b,] = gcd (1, 2); |
e6aa044253eb
Allow comma at the end of an assignment list (bug #35645)
Max Brister <max@2bass.com>
parents:
14512
diff
changeset
|
4883 |
7562
c827f5673321
move tests to individual source files
John W. Eaton <jwe@octave.org>
parents:
7351
diff
changeset
|
4884 */ |
c827f5673321
move tests to individual source files
John W. Eaton <jwe@octave.org>
parents:
7351
diff
changeset
|
4885 |
4661 | 4886 DEFUN (assignin, args, , |
4297 | 4887 "-*- texinfo -*-\n\ |
4888 @deftypefn {Built-in Function} {} assignin (@var{context}, @var{varname}, @var{value})\n\ | |
4889 Assign @var{value} to @var{varname} in context @var{context}, which\n\ | |
4890 may be either @code{\"base\"} or @code{\"caller\"}.\n\ | |
14172
cba1c681f1b7
doc: Update seealso references for eval family of functions.
Rik <octave@nomad.inbox5.com>
parents:
14153
diff
changeset
|
4891 @seealso{evalin}\n\ |
4297 | 4892 @end deftypefn") |
4893 { | |
4894 octave_value_list retval; | |
4895 | |
4896 int nargin = args.length (); | |
4897 | |
4898 if (nargin == 3) | |
4899 { | |
4900 std::string context = args(0).string_value (); | |
4901 | |
4902 if (! error_state) | |
4903 { | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
4904 unwind_protect frame; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
4905 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
4906 if (context == "caller") |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
4907 octave_call_stack::goto_caller_frame (); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
4908 else if (context == "base") |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
4909 octave_call_stack::goto_base_frame (); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
4910 else |
12483
7a5aacf65f81
Rewrite error strings in src/ to use variables named in documentation.
Rik <octave@nomad.inbox5.com>
parents:
12400
diff
changeset
|
4911 error ("assignin: CONTEXT must be \"caller\" or \"base\""); |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
4912 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
4913 if (! error_state) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
4914 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
4915 frame.add_fcn (octave_call_stack::pop); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
4916 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
4917 std::string nm = args(1).string_value (); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
4918 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
4919 if (! error_state) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
4920 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
4921 if (valid_identifier (nm)) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
4922 symbol_table::varref (nm) = args(2); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
4923 else |
12483
7a5aacf65f81
Rewrite error strings in src/ to use variables named in documentation.
Rik <octave@nomad.inbox5.com>
parents:
12400
diff
changeset
|
4924 error ("assignin: invalid variable name in argument VARNAME"); |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
4925 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
4926 else |
12483
7a5aacf65f81
Rewrite error strings in src/ to use variables named in documentation.
Rik <octave@nomad.inbox5.com>
parents:
12400
diff
changeset
|
4927 error ("assignin: VARNAME must be a string"); |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
4928 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
4929 } |
4297 | 4930 else |
12483
7a5aacf65f81
Rewrite error strings in src/ to use variables named in documentation.
Rik <octave@nomad.inbox5.com>
parents:
12400
diff
changeset
|
4931 error ("assignin: CONTEXT must be a string"); |
4297 | 4932 } |
4933 else | |
5823 | 4934 print_usage (); |
4297 | 4935 |
4936 return retval; | |
4937 } | |
4938 | |
4245 | 4939 DEFUN (evalin, args, nargout, |
4940 "-*- texinfo -*-\n\ | |
14172
cba1c681f1b7
doc: Update seealso references for eval family of functions.
Rik <octave@nomad.inbox5.com>
parents:
14153
diff
changeset
|
4941 @deftypefn {Built-in Function} {} evalin (@var{context}, @var{try})\n\ |
cba1c681f1b7
doc: Update seealso references for eval family of functions.
Rik <octave@nomad.inbox5.com>
parents:
14153
diff
changeset
|
4942 @deftypefnx {Built-in Function} {} evalin (@var{context}, @var{try}, @var{catch})\n\ |
4245 | 4943 Like @code{eval}, except that the expressions are evaluated in the\n\ |
4944 context @var{context}, which may be either @code{\"caller\"} or\n\ | |
4246 | 4945 @code{\"base\"}.\n\ |
14172
cba1c681f1b7
doc: Update seealso references for eval family of functions.
Rik <octave@nomad.inbox5.com>
parents:
14153
diff
changeset
|
4946 @seealso{eval, assignin}\n\ |
4245 | 4947 @end deftypefn") |
4948 { | |
4949 octave_value_list retval; | |
4950 | |
4951 int nargin = args.length (); | |
4952 | |
4953 if (nargin > 1) | |
4954 { | |
4955 std::string context = args(0).string_value (); | |
4956 | |
4957 if (! error_state) | |
4958 { | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
4959 unwind_protect frame; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
4960 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
4961 if (context == "caller") |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
4962 octave_call_stack::goto_caller_frame (); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
4963 else if (context == "base") |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
4964 octave_call_stack::goto_base_frame (); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
4965 else |
12483
7a5aacf65f81
Rewrite error strings in src/ to use variables named in documentation.
Rik <octave@nomad.inbox5.com>
parents:
12400
diff
changeset
|
4966 error ("evalin: CONTEXT must be \"caller\" or \"base\""); |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
4967 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
4968 if (! error_state) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
4969 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
4970 frame.add_fcn (octave_call_stack::pop); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
4971 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
4972 if (nargin > 2) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
4973 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
4974 frame.protect_var (buffer_error_messages); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
4975 buffer_error_messages++; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
4976 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
4977 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
4978 int parse_status = 0; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
4979 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
4980 octave_value_list tmp = eval_string (args(1), nargout > 0, |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
4981 parse_status, nargout); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
4982 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
4983 if (nargout > 0) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
4984 retval = tmp; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
4985 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
4986 if (nargin > 2 && (parse_status != 0 || error_state)) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
4987 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
4988 error_state = 0; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
4989 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
4990 // Set up for letting the user print any messages from |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
4991 // errors that occurred in the first part of this eval(). |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
4992 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
4993 buffer_error_messages--; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
4994 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
4995 tmp = eval_string (args(2), nargout > 0, |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
4996 parse_status, nargout); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
4997 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
4998 retval = (nargout > 0) ? tmp : octave_value_list (); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
4999 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
5000 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
5001 } |
4245 | 5002 else |
12483
7a5aacf65f81
Rewrite error strings in src/ to use variables named in documentation.
Rik <octave@nomad.inbox5.com>
parents:
12400
diff
changeset
|
5003 error ("evalin: CONTEXT must be a string"); |
4245 | 5004 } |
5005 else | |
5823 | 5006 print_usage (); |
4245 | 5007 |
5008 return retval; | |
5009 } | |
5010 | |
8311
7124bffc89c7
parse.y (F__parser_debug_flag__): New function.
John W. Eaton <jwe@octave.org>
parents:
8283
diff
changeset
|
5011 DEFUN (__parser_debug_flag__, args, nargout, |
8812
7d48766c21a5
use consistent format for doc strings of internal functions
John W. Eaton <jwe@octave.org>
parents:
8746
diff
changeset
|
5012 "-*- texinfo -*-\n\ |
7d48766c21a5
use consistent format for doc strings of internal functions
John W. Eaton <jwe@octave.org>
parents:
8746
diff
changeset
|
5013 @deftypefn {Built-in Function} {@var{old_val} =} __parser_debug_flag__ (@var{new_val}))\n\ |
7d48766c21a5
use consistent format for doc strings of internal functions
John W. Eaton <jwe@octave.org>
parents:
8746
diff
changeset
|
5014 Undocumented internal function.\n\ |
7d48766c21a5
use consistent format for doc strings of internal functions
John W. Eaton <jwe@octave.org>
parents:
8746
diff
changeset
|
5015 @end deftypefn") |
8311
7124bffc89c7
parse.y (F__parser_debug_flag__): New function.
John W. Eaton <jwe@octave.org>
parents:
8283
diff
changeset
|
5016 { |
7124bffc89c7
parse.y (F__parser_debug_flag__): New function.
John W. Eaton <jwe@octave.org>
parents:
8283
diff
changeset
|
5017 octave_value retval; |
7124bffc89c7
parse.y (F__parser_debug_flag__): New function.
John W. Eaton <jwe@octave.org>
parents:
8283
diff
changeset
|
5018 |
7124bffc89c7
parse.y (F__parser_debug_flag__): New function.
John W. Eaton <jwe@octave.org>
parents:
8283
diff
changeset
|
5019 bool debug_flag = octave_debug; |
7124bffc89c7
parse.y (F__parser_debug_flag__): New function.
John W. Eaton <jwe@octave.org>
parents:
8283
diff
changeset
|
5020 |
7124bffc89c7
parse.y (F__parser_debug_flag__): New function.
John W. Eaton <jwe@octave.org>
parents:
8283
diff
changeset
|
5021 retval = set_internal_variable (debug_flag, args, nargout, |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
5022 "__parser_debug_flag__"); |
8311
7124bffc89c7
parse.y (F__parser_debug_flag__): New function.
John W. Eaton <jwe@octave.org>
parents:
8283
diff
changeset
|
5023 |
7124bffc89c7
parse.y (F__parser_debug_flag__): New function.
John W. Eaton <jwe@octave.org>
parents:
8283
diff
changeset
|
5024 octave_debug = debug_flag; |
7124bffc89c7
parse.y (F__parser_debug_flag__): New function.
John W. Eaton <jwe@octave.org>
parents:
8283
diff
changeset
|
5025 |
7124bffc89c7
parse.y (F__parser_debug_flag__): New function.
John W. Eaton <jwe@octave.org>
parents:
8283
diff
changeset
|
5026 return retval; |
7124bffc89c7
parse.y (F__parser_debug_flag__): New function.
John W. Eaton <jwe@octave.org>
parents:
8283
diff
changeset
|
5027 } |