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