Mercurial > octave-nkf
annotate libinterp/parse-tree/oct-parse.in.yy @ 20579:52ce821a52fd
eliminate simple uses of error_state in parser and lexer
* lex.ll, oct-parse.in.yy: Eliminate simple uses of global error_state
variable.
author | John W. Eaton <jwe@octave.org> |
---|---|
date | Sat, 03 Oct 2015 16:21:58 -0400 |
parents | b70cc4bd8109 |
children | 235d059cf329 |
rev | line source |
---|---|
1829 | 1 /* |
1 | 2 |
19731
4197fc428c7d
maint: Update copyright notices for 2015.
John W. Eaton <jwe@octave.org>
parents:
19631
diff
changeset
|
3 Copyright (C) 1993-2015 John W. Eaton |
9474
25ed2d6aacf6
Parse nested functions more accurately.
David Grundberg <individ@acc.umu.se>
parents:
9471
diff
changeset
|
4 Copyright (C) 2009 David Grundberg |
11523 | 5 Copyright (C) 2009-2010 VZLU Prague |
1 | 6 |
7 This file is part of Octave. | |
8 | |
9 Octave is free software; you can redistribute it and/or modify it | |
10 under the terms of the GNU General Public License as published by the | |
7016 | 11 Free Software Foundation; either version 3 of the License, or (at your |
12 option) any later version. | |
1 | 13 |
14 Octave is distributed in the hope that it will be useful, but WITHOUT | |
15 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | |
16 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License | |
17 for more details. | |
18 | |
19 You should have received a copy of the GNU General Public License | |
7016 | 20 along with Octave; see the file COPYING. If not, see |
21 <http://www.gnu.org/licenses/>. | |
1 | 22 |
23 */ | |
24 | |
25 // Parser for Octave. | |
26 | |
767 | 27 // C decarations. |
28 | |
1 | 29 %{ |
30 #define YYDEBUG 1 | |
31 | |
240 | 32 #ifdef HAVE_CONFIG_H |
1229 | 33 #include <config.h> |
240 | 34 #endif |
35 | |
3178 | 36 #include <cassert> |
10463
bbe99b2a5ba7
undo recent gnulib-related changes
John W. Eaton <jwe@octave.org>
parents:
10447
diff
changeset
|
37 #include <cstdio> |
bbe99b2a5ba7
undo recent gnulib-related changes
John W. Eaton <jwe@octave.org>
parents:
10447
diff
changeset
|
38 #include <cstdlib> |
2427 | 39 |
8950
d865363208d6
include <iosfwd> instead of <iostream> in header files
John W. Eaton <jwe@octave.org>
parents:
8920
diff
changeset
|
40 #include <iostream> |
5484 | 41 #include <map> |
5765 | 42 #include <sstream> |
5484 | 43 |
3928 | 44 #include "Cell.h" |
1 | 45 #include "Matrix.h" |
3021 | 46 #include "cmd-edit.h" |
47 #include "cmd-hist.h" | |
48 #include "file-ops.h" | |
49 #include "file-stat.h" | |
4243 | 50 #include "oct-env.h" |
3712 | 51 #include "oct-time.h" |
4171 | 52 #include "quit.h" |
1 | 53 |
3665 | 54 #include "comment-list.h" |
4243 | 55 #include "defaults.h" |
2166 | 56 #include "defun.h" |
4243 | 57 #include "dirfns.h" |
3021 | 58 #include "dynamic-ld.h" |
1351 | 59 #include "error.h" |
60 #include "input.h" | |
61 #include "lex.h" | |
5832 | 62 #include "load-path.h" |
1743 | 63 #include "oct-hist.h" |
5626 | 64 #include "oct-map.h" |
15037
56b8eb7c9c04
improvements in parsing classdef
John W. Eaton <jwe@octave.org>
parents:
14846
diff
changeset
|
65 #include "ov-classdef.h" |
4935 | 66 #include "ov-fcn-handle.h" |
2970 | 67 #include "ov-usr-fcn.h" |
8150
283989f2da9b
make null assignment matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
8064
diff
changeset
|
68 #include "ov-null-mat.h" |
1670 | 69 #include "toplev.h" |
1351 | 70 #include "pager.h" |
71 #include "parse.h" | |
2987 | 72 #include "pt-all.h" |
8658
73c4516fae10
New evaluator and debugger derived from tree-walker class
John W. Eaton <jwe@octave.org>
parents:
8471
diff
changeset
|
73 #include "pt-eval.h" |
15037
56b8eb7c9c04
improvements in parsing classdef
John W. Eaton <jwe@octave.org>
parents:
14846
diff
changeset
|
74 #include "pt-funcall.h" |
1351 | 75 #include "symtab.h" |
76 #include "token.h" | |
3021 | 77 #include "unwind-prot.h" |
1 | 78 #include "utils.h" |
1351 | 79 #include "variables.h" |
1 | 80 |
16149
49dfba4fd3c5
use pure parser and reentrant lexer interfaces
John W. Eaton <jwe@octave.org>
parents:
16147
diff
changeset
|
81 // 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
|
82 #include <oct-parse.h> |
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 extern int octave_lex (YYSTYPE *, void *); |
49dfba4fd3c5
use pure parser and reentrant lexer interfaces
John W. Eaton <jwe@octave.org>
parents:
16147
diff
changeset
|
85 |
49dfba4fd3c5
use pure parser and reentrant lexer interfaces
John W. Eaton <jwe@octave.org>
parents:
16147
diff
changeset
|
86 // Global access to currently active lexer. |
49dfba4fd3c5
use pure parser and reentrant lexer interfaces
John W. Eaton <jwe@octave.org>
parents:
16147
diff
changeset
|
87 // 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
|
88 octave_base_lexer *LEXER = 0; |
16149
49dfba4fd3c5
use pure parser and reentrant lexer interfaces
John W. Eaton <jwe@octave.org>
parents:
16147
diff
changeset
|
89 |
10426
4db7beace28e
oct-parse.yy, lex.ll: use symbols via gnulib namespace
John W. Eaton <jwe@octave.org>
parents:
10411
diff
changeset
|
90 #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
|
91 // 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
|
92 // 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
|
93 // 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
|
94 #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
|
95 #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
|
96 #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
|
97 #endif |
4db7beace28e
oct-parse.yy, lex.ll: use symbols via gnulib namespace
John W. Eaton <jwe@octave.org>
parents:
10411
diff
changeset
|
98 |
3021 | 99 // TRUE means we printed messages about reading startup files. |
100 bool reading_startup_message_printed = false; | |
101 | |
5484 | 102 // List of autoloads (function -> file mapping). |
103 static std::map<std::string, std::string> autoload_map; | |
104 | |
496 | 105 // Forward declarations for some functions defined at the bottom of |
106 // the file. | |
107 | |
16288
fe3b9a51e625
rename curr_lexer, curr_parser, CURR_LEXER
John W. Eaton <jwe@octave.org>
parents:
16287
diff
changeset
|
108 static void yyerror (octave_base_parser& parser, const char *s); |
1 | 109 |
110 #define ABORT_PARSE \ | |
111 do \ | |
112 { \ | |
113 yyerrok; \ | |
19883
1c9ed5b4c73d
input.h: change meaning of interactive and forced_interactive global variables.
Carnë Draug <carandraug@octave.org>
parents:
19812
diff
changeset
|
114 if (interactive && ! lexer.input_from_eval_string ()) \ |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
115 YYACCEPT; \ |
1 | 116 else \ |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
117 YYABORT; \ |
1 | 118 } \ |
119 while (0) | |
120 | |
16288
fe3b9a51e625
rename curr_lexer, curr_parser, CURR_LEXER
John W. Eaton <jwe@octave.org>
parents:
16287
diff
changeset
|
121 #define lexer parser.lexer |
fe3b9a51e625
rename curr_lexer, curr_parser, CURR_LEXER
John W. Eaton <jwe@octave.org>
parents:
16287
diff
changeset
|
122 #define scanner lexer.scanner |
16149
49dfba4fd3c5
use pure parser and reentrant lexer interfaces
John W. Eaton <jwe@octave.org>
parents:
16147
diff
changeset
|
123 |
1 | 124 %} |
125 | |
666 | 126 // Bison declarations. |
127 | |
17743
af5ad573c665
oct-parse.in.yy: Add %expect declaration.
John W. Eaton <jwe@octave.org>
parents:
17731
diff
changeset
|
128 // The grammar currently has 14 shift/reduce conflicts. Ensure that |
af5ad573c665
oct-parse.in.yy: Add %expect declaration.
John W. Eaton <jwe@octave.org>
parents:
17731
diff
changeset
|
129 // we notice if that number changes. |
af5ad573c665
oct-parse.in.yy: Add %expect declaration.
John W. Eaton <jwe@octave.org>
parents:
17731
diff
changeset
|
130 |
af5ad573c665
oct-parse.in.yy: Add %expect declaration.
John W. Eaton <jwe@octave.org>
parents:
17731
diff
changeset
|
131 %expect 14 |
af5ad573c665
oct-parse.in.yy: Add %expect declaration.
John W. Eaton <jwe@octave.org>
parents:
17731
diff
changeset
|
132 |
19008
d8abf813c69f
handle changes in bison 3.x
John W. Eaton <jwe@octave.org>
parents:
18531
diff
changeset
|
133 %API_PREFIX_DECL% |
4753 | 134 |
16149
49dfba4fd3c5
use pure parser and reentrant lexer interfaces
John W. Eaton <jwe@octave.org>
parents:
16147
diff
changeset
|
135 // 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
|
136 // 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
|
137 // 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
|
138 // 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
|
139 // 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
|
140 // 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
|
141 // 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
|
142 // 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
|
143 |
49dfba4fd3c5
use pure parser and reentrant lexer interfaces
John W. Eaton <jwe@octave.org>
parents:
16147
diff
changeset
|
144 %define api.pure |
16174
39096b290a2f
check syntax used to enable bison push/pull parser
John W. Eaton <jwe@octave.org>
parents:
16167
diff
changeset
|
145 %PUSH_PULL_DECL% |
16288
fe3b9a51e625
rename curr_lexer, curr_parser, CURR_LEXER
John W. Eaton <jwe@octave.org>
parents:
16287
diff
changeset
|
146 %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
|
147 %lex-param { void *scanner } |
49dfba4fd3c5
use pure parser and reentrant lexer interfaces
John W. Eaton <jwe@octave.org>
parents:
16147
diff
changeset
|
148 |
1 | 149 %union |
150 { | |
19812
bf737d927707
eliminate bison warnings from oct-parse.yy
John W. Eaton <jwe@octave.org>
parents:
19743
diff
changeset
|
151 int dummy_type; |
bf737d927707
eliminate bison warnings from oct-parse.yy
John W. Eaton <jwe@octave.org>
parents:
19743
diff
changeset
|
152 |
2891 | 153 // The type of the basic tokens returned by the lexer. |
143 | 154 token *tok_val; |
155 | |
3665 | 156 // Comment strings that we need to deal with mid-rule. |
157 octave_comment_list *comment_type; | |
158 | |
2891 | 159 // Types for the nonterminals we generate. |
19812
bf737d927707
eliminate bison warnings from oct-parse.yy
John W. Eaton <jwe@octave.org>
parents:
19743
diff
changeset
|
160 char punct_type; |
1 | 161 tree *tree_type; |
1829 | 162 tree_matrix *tree_matrix_type; |
3351 | 163 tree_cell *tree_cell_type; |
496 | 164 tree_expression *tree_expression_type; |
2375 | 165 tree_constant *tree_constant_type; |
4342 | 166 tree_fcn_handle *tree_fcn_handle_type; |
15037
56b8eb7c9c04
improvements in parsing classdef
John W. Eaton <jwe@octave.org>
parents:
14846
diff
changeset
|
167 tree_funcall *tree_funcall_type; |
56b8eb7c9c04
improvements in parsing classdef
John W. Eaton <jwe@octave.org>
parents:
14846
diff
changeset
|
168 tree_function_def *tree_function_def_type; |
5861 | 169 tree_anon_fcn_handle *tree_anon_fcn_handle_type; |
1 | 170 tree_identifier *tree_identifier_type; |
171 tree_index_expression *tree_index_expression_type; | |
172 tree_colon_expression *tree_colon_expression_type; | |
173 tree_argument_list *tree_argument_list_type; | |
174 tree_parameter_list *tree_parameter_list_type; | |
175 tree_command *tree_command_type; | |
176 tree_if_command *tree_if_command_type; | |
578 | 177 tree_if_clause *tree_if_clause_type; |
178 tree_if_command_list *tree_if_command_list_type; | |
2764 | 179 tree_switch_command *tree_switch_command_type; |
180 tree_switch_case *tree_switch_case_type; | |
181 tree_switch_case_list *tree_switch_case_list_type; | |
2846 | 182 tree_decl_elt *tree_decl_elt_type; |
183 tree_decl_init_list *tree_decl_init_list_type; | |
184 tree_decl_command *tree_decl_command_type; | |
578 | 185 tree_statement *tree_statement_type; |
186 tree_statement_list *tree_statement_list_type; | |
2891 | 187 octave_user_function *octave_user_function_type; |
15037
56b8eb7c9c04
improvements in parsing classdef
John W. Eaton <jwe@octave.org>
parents:
14846
diff
changeset
|
188 |
56b8eb7c9c04
improvements in parsing classdef
John W. Eaton <jwe@octave.org>
parents:
14846
diff
changeset
|
189 tree_classdef *tree_classdef_type; |
56b8eb7c9c04
improvements in parsing classdef
John W. Eaton <jwe@octave.org>
parents:
14846
diff
changeset
|
190 tree_classdef_attribute* tree_classdef_attribute_type; |
56b8eb7c9c04
improvements in parsing classdef
John W. Eaton <jwe@octave.org>
parents:
14846
diff
changeset
|
191 tree_classdef_attribute_list* tree_classdef_attribute_list_type; |
56b8eb7c9c04
improvements in parsing classdef
John W. Eaton <jwe@octave.org>
parents:
14846
diff
changeset
|
192 tree_classdef_superclass* tree_classdef_superclass_type; |
56b8eb7c9c04
improvements in parsing classdef
John W. Eaton <jwe@octave.org>
parents:
14846
diff
changeset
|
193 tree_classdef_superclass_list* tree_classdef_superclass_list_type; |
56b8eb7c9c04
improvements in parsing classdef
John W. Eaton <jwe@octave.org>
parents:
14846
diff
changeset
|
194 tree_classdef_body* tree_classdef_body_type; |
56b8eb7c9c04
improvements in parsing classdef
John W. Eaton <jwe@octave.org>
parents:
14846
diff
changeset
|
195 tree_classdef_property* tree_classdef_property_type; |
56b8eb7c9c04
improvements in parsing classdef
John W. Eaton <jwe@octave.org>
parents:
14846
diff
changeset
|
196 tree_classdef_property_list* tree_classdef_property_list_type; |
56b8eb7c9c04
improvements in parsing classdef
John W. Eaton <jwe@octave.org>
parents:
14846
diff
changeset
|
197 tree_classdef_properties_block* tree_classdef_properties_block_type; |
56b8eb7c9c04
improvements in parsing classdef
John W. Eaton <jwe@octave.org>
parents:
14846
diff
changeset
|
198 tree_classdef_methods_list* tree_classdef_methods_list_type; |
56b8eb7c9c04
improvements in parsing classdef
John W. Eaton <jwe@octave.org>
parents:
14846
diff
changeset
|
199 tree_classdef_methods_block* tree_classdef_methods_block_type; |
56b8eb7c9c04
improvements in parsing classdef
John W. Eaton <jwe@octave.org>
parents:
14846
diff
changeset
|
200 tree_classdef_event* tree_classdef_event_type; |
56b8eb7c9c04
improvements in parsing classdef
John W. Eaton <jwe@octave.org>
parents:
14846
diff
changeset
|
201 tree_classdef_events_list* tree_classdef_events_list_type; |
56b8eb7c9c04
improvements in parsing classdef
John W. Eaton <jwe@octave.org>
parents:
14846
diff
changeset
|
202 tree_classdef_events_block* tree_classdef_events_block_type; |
56b8eb7c9c04
improvements in parsing classdef
John W. Eaton <jwe@octave.org>
parents:
14846
diff
changeset
|
203 tree_classdef_enum* tree_classdef_enum_type; |
56b8eb7c9c04
improvements in parsing classdef
John W. Eaton <jwe@octave.org>
parents:
14846
diff
changeset
|
204 tree_classdef_enum_list* tree_classdef_enum_list_type; |
56b8eb7c9c04
improvements in parsing classdef
John W. Eaton <jwe@octave.org>
parents:
14846
diff
changeset
|
205 tree_classdef_enum_block* tree_classdef_enum_block_type; |
1 | 206 } |
207 | |
143 | 208 // Tokens with line and column information. |
209 %token <tok_val> '=' ':' '-' '+' '*' '/' | |
4018 | 210 %token <tok_val> ADD_EQ SUB_EQ MUL_EQ DIV_EQ LEFTDIV_EQ POW_EQ |
211 %token <tok_val> EMUL_EQ EDIV_EQ ELEFTDIV_EQ EPOW_EQ AND_EQ OR_EQ | |
2899 | 212 %token <tok_val> LSHIFT_EQ RSHIFT_EQ LSHIFT RSHIFT |
428 | 213 %token <tok_val> EXPR_AND_AND EXPR_OR_OR |
143 | 214 %token <tok_val> EXPR_AND EXPR_OR EXPR_NOT |
215 %token <tok_val> EXPR_LT EXPR_LE EXPR_EQ EXPR_NE EXPR_GE EXPR_GT | |
1276 | 216 %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
|
217 %token <tok_val> HERMITIAN TRANSPOSE |
143 | 218 %token <tok_val> PLUS_PLUS MINUS_MINUS POW EPOW |
219 %token <tok_val> NUM IMAG_NUM | |
2970 | 220 %token <tok_val> STRUCT_ELT |
2883 | 221 %token <tok_val> NAME |
143 | 222 %token <tok_val> END |
5279 | 223 %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
|
224 %token <tok_val> FOR PARFOR WHILE DO UNTIL |
1491 | 225 %token <tok_val> IF ELSEIF ELSE |
2764 | 226 %token <tok_val> SWITCH CASE OTHERWISE |
1491 | 227 %token <tok_val> BREAK CONTINUE FUNC_RET |
924 | 228 %token <tok_val> UNWIND CLEANUP |
1489 | 229 %token <tok_val> TRY CATCH |
14294
9e3983c8963c
deprecate the static keyword
John W. Eaton <jwe@octave.org>
parents:
14293
diff
changeset
|
230 %token <tok_val> GLOBAL PERSISTENT |
4342 | 231 %token <tok_val> FCN_HANDLE |
15037
56b8eb7c9c04
improvements in parsing classdef
John W. Eaton <jwe@octave.org>
parents:
14846
diff
changeset
|
232 %token <tok_val> CLASSDEF |
13249
7861a5fd3479
accept enumeration keyword
John W. Eaton <jwe@octave.org>
parents:
13246
diff
changeset
|
233 %token <tok_val> PROPERTIES METHODS EVENTS ENUMERATION |
9476 | 234 %token <tok_val> METAQUERY |
235 %token <tok_val> SUPERCLASSREF | |
18520
932aca9a7c57
Allow multi-level classdef package.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
18419
diff
changeset
|
236 %token <tok_val> FQ_IDENT |
9476 | 237 %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
|
238 %token <tok_val> FCN |
1 | 239 |
143 | 240 // Other tokens. |
19812
bf737d927707
eliminate bison warnings from oct-parse.yy
John W. Eaton <jwe@octave.org>
parents:
19743
diff
changeset
|
241 %token<dummy_type> END_OF_INPUT LEXICAL_ERROR |
bf737d927707
eliminate bison warnings from oct-parse.yy
John W. Eaton <jwe@octave.org>
parents:
19743
diff
changeset
|
242 %token<dummy_type> INPUT_FILE |
7587
1f662945c2be
handle varargin and varargout without keywords
John W. Eaton <jwe@octave.org>
parents:
7562
diff
changeset
|
243 // %token VARARGIN VARARGOUT |
1 | 244 |
19812
bf737d927707
eliminate bison warnings from oct-parse.yy
John W. Eaton <jwe@octave.org>
parents:
19743
diff
changeset
|
245 %token<dummy_type> '(' ')' '[' ']' '{' '}' '.' ',' ';' '@' '\n' |
bf737d927707
eliminate bison warnings from oct-parse.yy
John W. Eaton <jwe@octave.org>
parents:
19743
diff
changeset
|
246 |
143 | 247 // Nonterminals we construct. |
19812
bf737d927707
eliminate bison warnings from oct-parse.yy
John W. Eaton <jwe@octave.org>
parents:
19743
diff
changeset
|
248 %type <dummy_type> indirect_ref_op decl_param_init push_fcn_symtab |
bf737d927707
eliminate bison warnings from oct-parse.yy
John W. Eaton <jwe@octave.org>
parents:
19743
diff
changeset
|
249 %type <dummy_type> param_list_beg param_list_end stmt_begin parse_error |
16644
856cb7cba231
maint: periodic merge of default to classdef
John W. Eaton <jwe@octave.org>
diff
changeset
|
250 %type <comment_type> stash_comment |
17657
df266c923b83
delete unnecessary tok_type semantic value in parser
John W. Eaton <jwe@octave.org>
parents:
17656
diff
changeset
|
251 %type <tok_val> function_beg classdef_beg |
19812
bf737d927707
eliminate bison warnings from oct-parse.yy
John W. Eaton <jwe@octave.org>
parents:
19743
diff
changeset
|
252 %type <punct_type> sep_no_nl opt_sep_no_nl nl opt_nl sep opt_sep |
578 | 253 %type <tree_type> input |
5861 | 254 %type <tree_constant_type> string constant magic_colon |
255 %type <tree_anon_fcn_handle_type> anon_fcn_handle | |
4342 | 256 %type <tree_fcn_handle_type> fcn_handle |
16924
aebb54d99dba
improve compatibility of parsing of matrices and cell arrays
John W. Eaton <jwe@octave.org>
parents:
16850
diff
changeset
|
257 %type <tree_matrix_type> matrix_rows |
aebb54d99dba
improve compatibility of parsing of matrices and cell arrays
John W. Eaton <jwe@octave.org>
parents:
16850
diff
changeset
|
258 %type <tree_cell_type> cell_rows |
5102 | 259 %type <tree_expression_type> matrix cell |
17622
fd712a12fe53
compatibility for power operator precedence and direction (bug #33304)
Axel Mathéi <axel.mathei@gmail.com>
parents:
17618
diff
changeset
|
260 %type <tree_expression_type> primary_expr oper_expr power_expr |
4207 | 261 %type <tree_expression_type> simple_expr colon_expr assign_expr expression |
17283
e6c0ac8ce5b6
eliminate parse conflicts introduced by changeset 923ce8b42db2
John W. Eaton <jwe@octave.org>
parents:
17281
diff
changeset
|
262 %type <tree_identifier_type> identifier fcn_name magic_tilde |
15037
56b8eb7c9c04
improvements in parsing classdef
John W. Eaton <jwe@octave.org>
parents:
14846
diff
changeset
|
263 %type <tree_funcall_type> superclass_identifier meta_identifier |
56b8eb7c9c04
improvements in parsing classdef
John W. Eaton <jwe@octave.org>
parents:
14846
diff
changeset
|
264 %type <octave_user_function_type> function1 function2 |
2970 | 265 %type <tree_index_expression_type> word_list_cmd |
266 %type <tree_colon_expression_type> colon_expr1 | |
3351 | 267 %type <tree_argument_list_type> arg_list word_list assign_lhs |
268 %type <tree_argument_list_type> cell_or_matrix_row | |
4935 | 269 %type <tree_parameter_list_type> param_list param_list1 param_list2 |
723 | 270 %type <tree_parameter_list_type> return_list return_list1 |
2970 | 271 %type <tree_command_type> command select_command loop_command |
15037
56b8eb7c9c04
improvements in parsing classdef
John W. Eaton <jwe@octave.org>
parents:
14846
diff
changeset
|
272 %type <tree_command_type> jump_command except_command |
56b8eb7c9c04
improvements in parsing classdef
John W. Eaton <jwe@octave.org>
parents:
14846
diff
changeset
|
273 %type <tree_function_def_type> function |
56b8eb7c9c04
improvements in parsing classdef
John W. Eaton <jwe@octave.org>
parents:
14846
diff
changeset
|
274 %type <tree_classdef_type> classdef |
16211
3449bf257514
maint: fix botched merge of default to classdef
John W. Eaton <jwe@octave.org>
parents:
16205
diff
changeset
|
275 %type <tree_command_type> file |
578 | 276 %type <tree_if_command_type> if_command |
277 %type <tree_if_clause_type> elseif_clause else_clause | |
278 %type <tree_if_command_list_type> if_cmd_list1 if_cmd_list | |
2764 | 279 %type <tree_switch_command_type> switch_command |
280 %type <tree_switch_case_type> switch_case default_case | |
281 %type <tree_switch_case_list_type> case_list1 case_list | |
17317
56fe31b248de
disallow ~ in global and persistent declaration lists
John W. Eaton <jwe@octave.org>
parents:
17316
diff
changeset
|
282 %type <tree_decl_elt_type> decl2 param_list_elt |
2846 | 283 %type <tree_decl_init_list_type> decl1 |
284 %type <tree_decl_command_type> declaration | |
15037
56b8eb7c9c04
improvements in parsing classdef
John W. Eaton <jwe@octave.org>
parents:
14846
diff
changeset
|
285 %type <tree_statement_type> statement function_end |
627 | 286 %type <tree_statement_list_type> simple_list simple_list1 list list1 |
17322
4c1ae06111c9
allow parser to accept empty statements (bug #37099)
John W. Eaton <jwe@octave.org>
parents:
17317
diff
changeset
|
287 %type <tree_statement_list_type> opt_list |
15037
56b8eb7c9c04
improvements in parsing classdef
John W. Eaton <jwe@octave.org>
parents:
14846
diff
changeset
|
288 %type <tree_classdef_attribute_type> attr |
56b8eb7c9c04
improvements in parsing classdef
John W. Eaton <jwe@octave.org>
parents:
14846
diff
changeset
|
289 %type <tree_classdef_attribute_list_type> attr_list opt_attr_list |
56b8eb7c9c04
improvements in parsing classdef
John W. Eaton <jwe@octave.org>
parents:
14846
diff
changeset
|
290 %type <tree_classdef_superclass_type> superclass |
56b8eb7c9c04
improvements in parsing classdef
John W. Eaton <jwe@octave.org>
parents:
14846
diff
changeset
|
291 %type <tree_classdef_superclass_list_type> superclass_list opt_superclass_list |
56b8eb7c9c04
improvements in parsing classdef
John W. Eaton <jwe@octave.org>
parents:
14846
diff
changeset
|
292 %type <tree_classdef_body_type> class_body |
56b8eb7c9c04
improvements in parsing classdef
John W. Eaton <jwe@octave.org>
parents:
14846
diff
changeset
|
293 %type <tree_classdef_property_type> class_property |
56b8eb7c9c04
improvements in parsing classdef
John W. Eaton <jwe@octave.org>
parents:
14846
diff
changeset
|
294 %type <tree_classdef_property_list_type> property_list |
56b8eb7c9c04
improvements in parsing classdef
John W. Eaton <jwe@octave.org>
parents:
14846
diff
changeset
|
295 %type <tree_classdef_properties_block_type> properties_block |
56b8eb7c9c04
improvements in parsing classdef
John W. Eaton <jwe@octave.org>
parents:
14846
diff
changeset
|
296 %type <tree_classdef_methods_list_type> methods_list |
56b8eb7c9c04
improvements in parsing classdef
John W. Eaton <jwe@octave.org>
parents:
14846
diff
changeset
|
297 %type <tree_classdef_methods_block_type> methods_block |
56b8eb7c9c04
improvements in parsing classdef
John W. Eaton <jwe@octave.org>
parents:
14846
diff
changeset
|
298 %type <tree_classdef_event_type> class_event |
56b8eb7c9c04
improvements in parsing classdef
John W. Eaton <jwe@octave.org>
parents:
14846
diff
changeset
|
299 %type <tree_classdef_events_list_type> events_list |
56b8eb7c9c04
improvements in parsing classdef
John W. Eaton <jwe@octave.org>
parents:
14846
diff
changeset
|
300 %type <tree_classdef_events_block_type> events_block |
56b8eb7c9c04
improvements in parsing classdef
John W. Eaton <jwe@octave.org>
parents:
14846
diff
changeset
|
301 %type <tree_classdef_enum_type> class_enum |
56b8eb7c9c04
improvements in parsing classdef
John W. Eaton <jwe@octave.org>
parents:
14846
diff
changeset
|
302 %type <tree_classdef_enum_list_type> enum_list |
56b8eb7c9c04
improvements in parsing classdef
John W. Eaton <jwe@octave.org>
parents:
14846
diff
changeset
|
303 %type <tree_classdef_enum_block_type> enum_block |
18262
69990d5edcc2
Allow to parse external methods declaration in classdef files.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
18157
diff
changeset
|
304 %type <tree_function_def_type> method_decl method |
69990d5edcc2
Allow to parse external methods declaration in classdef files.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
18157
diff
changeset
|
305 %type <octave_user_function_type> method_decl1 |
1 | 306 |
143 | 307 // Precedence and associativity. |
4018 | 308 %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 | 309 %left EXPR_OR_OR |
310 %left EXPR_AND_AND | |
311 %left EXPR_OR | |
312 %left EXPR_AND | |
1 | 313 %left EXPR_LT EXPR_LE EXPR_EQ EXPR_NE EXPR_GE EXPR_GT |
2899 | 314 %left LSHIFT RSHIFT |
1 | 315 %left ':' |
1276 | 316 %left '-' '+' EPLUS EMINUS |
1 | 317 %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
|
318 %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
|
319 %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
|
320 %right PLUS_PLUS MINUS_MINUS |
3351 | 321 %left '(' '.' '{' |
1 | 322 |
17629
1e8f8900a041
clean up partially constructed parse tree objects on parse errors (bug #40231)
John W. Eaton <jwe@octave.org>
parents:
17622
diff
changeset
|
323 // How to clean up if there is a parse error. We handle deleting tokens |
1e8f8900a041
clean up partially constructed parse tree objects on parse errors (bug #40231)
John W. Eaton <jwe@octave.org>
parents:
17622
diff
changeset
|
324 // and comments seperately and separators are just characters. The |
1e8f8900a041
clean up partially constructed parse tree objects on parse errors (bug #40231)
John W. Eaton <jwe@octave.org>
parents:
17622
diff
changeset
|
325 // remaining items are dynamically allocated parse tree objects that |
17658
0c5f50706ba3
attempt to catch possible memory leaks in parser cleanup
John W. Eaton <jwe@octave.org>
parents:
17632
diff
changeset
|
326 // must be deleted. Use the wildcard case (<*>) to detect unhandled |
0c5f50706ba3
attempt to catch possible memory leaks in parser cleanup
John W. Eaton <jwe@octave.org>
parents:
17632
diff
changeset
|
327 // cases (for example, a new semantic type is added but not handled |
0c5f50706ba3
attempt to catch possible memory leaks in parser cleanup
John W. Eaton <jwe@octave.org>
parents:
17632
diff
changeset
|
328 // here). |
0c5f50706ba3
attempt to catch possible memory leaks in parser cleanup
John W. Eaton <jwe@octave.org>
parents:
17632
diff
changeset
|
329 |
0c5f50706ba3
attempt to catch possible memory leaks in parser cleanup
John W. Eaton <jwe@octave.org>
parents:
17632
diff
changeset
|
330 %destructor { } <tok_val> |
19812
bf737d927707
eliminate bison warnings from oct-parse.yy
John W. Eaton <jwe@octave.org>
parents:
19743
diff
changeset
|
331 %destructor { } <punct_type> |
17658
0c5f50706ba3
attempt to catch possible memory leaks in parser cleanup
John W. Eaton <jwe@octave.org>
parents:
17632
diff
changeset
|
332 %destructor { } <comment_type> |
0c5f50706ba3
attempt to catch possible memory leaks in parser cleanup
John W. Eaton <jwe@octave.org>
parents:
17632
diff
changeset
|
333 %destructor { } <> |
0c5f50706ba3
attempt to catch possible memory leaks in parser cleanup
John W. Eaton <jwe@octave.org>
parents:
17632
diff
changeset
|
334 |
19627
446c46af4b42
strip trailing whitespace from most source files
John W. Eaton <jwe@octave.org>
parents:
19008
diff
changeset
|
335 %destructor { delete $$; } <tree_type> |
446c46af4b42
strip trailing whitespace from most source files
John W. Eaton <jwe@octave.org>
parents:
19008
diff
changeset
|
336 %destructor { delete $$; } <tree_matrix_type> |
446c46af4b42
strip trailing whitespace from most source files
John W. Eaton <jwe@octave.org>
parents:
19008
diff
changeset
|
337 %destructor { delete $$; } <tree_cell_type> |
446c46af4b42
strip trailing whitespace from most source files
John W. Eaton <jwe@octave.org>
parents:
19008
diff
changeset
|
338 %destructor { delete $$; } <tree_expression_type> |
446c46af4b42
strip trailing whitespace from most source files
John W. Eaton <jwe@octave.org>
parents:
19008
diff
changeset
|
339 %destructor { delete $$; } <tree_constant_type> |
446c46af4b42
strip trailing whitespace from most source files
John W. Eaton <jwe@octave.org>
parents:
19008
diff
changeset
|
340 %destructor { delete $$; } <tree_fcn_handle_type> |
19812
bf737d927707
eliminate bison warnings from oct-parse.yy
John W. Eaton <jwe@octave.org>
parents:
19743
diff
changeset
|
341 %destructor { delete $$; } <tree_funcall_type> |
bf737d927707
eliminate bison warnings from oct-parse.yy
John W. Eaton <jwe@octave.org>
parents:
19743
diff
changeset
|
342 %destructor { delete $$; } <tree_function_def_type> |
19627
446c46af4b42
strip trailing whitespace from most source files
John W. Eaton <jwe@octave.org>
parents:
19008
diff
changeset
|
343 %destructor { delete $$; } <tree_anon_fcn_handle_type> |
446c46af4b42
strip trailing whitespace from most source files
John W. Eaton <jwe@octave.org>
parents:
19008
diff
changeset
|
344 %destructor { delete $$; } <tree_identifier_type> |
446c46af4b42
strip trailing whitespace from most source files
John W. Eaton <jwe@octave.org>
parents:
19008
diff
changeset
|
345 %destructor { delete $$; } <tree_index_expression_type> |
446c46af4b42
strip trailing whitespace from most source files
John W. Eaton <jwe@octave.org>
parents:
19008
diff
changeset
|
346 %destructor { delete $$; } <tree_colon_expression_type> |
446c46af4b42
strip trailing whitespace from most source files
John W. Eaton <jwe@octave.org>
parents:
19008
diff
changeset
|
347 %destructor { delete $$; } <tree_argument_list_type> |
446c46af4b42
strip trailing whitespace from most source files
John W. Eaton <jwe@octave.org>
parents:
19008
diff
changeset
|
348 %destructor { delete $$; } <tree_parameter_list_type> |
446c46af4b42
strip trailing whitespace from most source files
John W. Eaton <jwe@octave.org>
parents:
19008
diff
changeset
|
349 %destructor { delete $$; } <tree_command_type> |
446c46af4b42
strip trailing whitespace from most source files
John W. Eaton <jwe@octave.org>
parents:
19008
diff
changeset
|
350 %destructor { delete $$; } <tree_if_command_type> |
446c46af4b42
strip trailing whitespace from most source files
John W. Eaton <jwe@octave.org>
parents:
19008
diff
changeset
|
351 %destructor { delete $$; } <tree_if_clause_type> |
446c46af4b42
strip trailing whitespace from most source files
John W. Eaton <jwe@octave.org>
parents:
19008
diff
changeset
|
352 %destructor { delete $$; } <tree_if_command_list_type> |
446c46af4b42
strip trailing whitespace from most source files
John W. Eaton <jwe@octave.org>
parents:
19008
diff
changeset
|
353 %destructor { delete $$; } <tree_switch_command_type> |
446c46af4b42
strip trailing whitespace from most source files
John W. Eaton <jwe@octave.org>
parents:
19008
diff
changeset
|
354 %destructor { delete $$; } <tree_switch_case_type> |
446c46af4b42
strip trailing whitespace from most source files
John W. Eaton <jwe@octave.org>
parents:
19008
diff
changeset
|
355 %destructor { delete $$; } <tree_switch_case_list_type> |
446c46af4b42
strip trailing whitespace from most source files
John W. Eaton <jwe@octave.org>
parents:
19008
diff
changeset
|
356 %destructor { delete $$; } <tree_decl_elt_type> |
446c46af4b42
strip trailing whitespace from most source files
John W. Eaton <jwe@octave.org>
parents:
19008
diff
changeset
|
357 %destructor { delete $$; } <tree_decl_init_list_type> |
446c46af4b42
strip trailing whitespace from most source files
John W. Eaton <jwe@octave.org>
parents:
19008
diff
changeset
|
358 %destructor { delete $$; } <tree_decl_command_type> |
446c46af4b42
strip trailing whitespace from most source files
John W. Eaton <jwe@octave.org>
parents:
19008
diff
changeset
|
359 %destructor { delete $$; } <tree_statement_type> |
446c46af4b42
strip trailing whitespace from most source files
John W. Eaton <jwe@octave.org>
parents:
19008
diff
changeset
|
360 %destructor { delete $$; } <tree_statement_list_type> |
446c46af4b42
strip trailing whitespace from most source files
John W. Eaton <jwe@octave.org>
parents:
19008
diff
changeset
|
361 %destructor { delete $$; } <octave_user_function_type> |
17658
0c5f50706ba3
attempt to catch possible memory leaks in parser cleanup
John W. Eaton <jwe@octave.org>
parents:
17632
diff
changeset
|
362 |
18262
69990d5edcc2
Allow to parse external methods declaration in classdef files.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
18157
diff
changeset
|
363 %destructor { delete $$; } <tree_classdef_type> |
69990d5edcc2
Allow to parse external methods declaration in classdef files.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
18157
diff
changeset
|
364 %destructor { delete $$; } <tree_classdef_attribute_type> |
69990d5edcc2
Allow to parse external methods declaration in classdef files.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
18157
diff
changeset
|
365 %destructor { delete $$; } <tree_classdef_attribute_list_type> |
69990d5edcc2
Allow to parse external methods declaration in classdef files.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
18157
diff
changeset
|
366 %destructor { delete $$; } <tree_classdef_superclass_type> |
69990d5edcc2
Allow to parse external methods declaration in classdef files.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
18157
diff
changeset
|
367 %destructor { delete $$; } <tree_classdef_superclass_list_type> |
69990d5edcc2
Allow to parse external methods declaration in classdef files.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
18157
diff
changeset
|
368 %destructor { delete $$; } <tree_classdef_body_type> |
69990d5edcc2
Allow to parse external methods declaration in classdef files.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
18157
diff
changeset
|
369 %destructor { delete $$; } <tree_classdef_property_type> |
69990d5edcc2
Allow to parse external methods declaration in classdef files.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
18157
diff
changeset
|
370 %destructor { delete $$; } <tree_classdef_property_list_type> |
69990d5edcc2
Allow to parse external methods declaration in classdef files.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
18157
diff
changeset
|
371 %destructor { delete $$; } <tree_classdef_properties_block_type> |
69990d5edcc2
Allow to parse external methods declaration in classdef files.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
18157
diff
changeset
|
372 %destructor { delete $$; } <tree_classdef_methods_list_type> |
69990d5edcc2
Allow to parse external methods declaration in classdef files.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
18157
diff
changeset
|
373 %destructor { delete $$; } <tree_classdef_methods_block_type> |
69990d5edcc2
Allow to parse external methods declaration in classdef files.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
18157
diff
changeset
|
374 %destructor { delete $$; } <tree_classdef_event_type> |
69990d5edcc2
Allow to parse external methods declaration in classdef files.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
18157
diff
changeset
|
375 %destructor { delete $$; } <tree_classdef_events_list_type> |
69990d5edcc2
Allow to parse external methods declaration in classdef files.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
18157
diff
changeset
|
376 %destructor { delete $$; } <tree_classdef_events_block_type> |
69990d5edcc2
Allow to parse external methods declaration in classdef files.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
18157
diff
changeset
|
377 %destructor { delete $$; } <tree_classdef_enum_type> |
69990d5edcc2
Allow to parse external methods declaration in classdef files.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
18157
diff
changeset
|
378 %destructor { delete $$; } <tree_classdef_enum_list_type> |
69990d5edcc2
Allow to parse external methods declaration in classdef files.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
18157
diff
changeset
|
379 %destructor { delete $$; } <tree_classdef_enum_block_type> |
69990d5edcc2
Allow to parse external methods declaration in classdef files.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
18157
diff
changeset
|
380 |
19812
bf737d927707
eliminate bison warnings from oct-parse.yy
John W. Eaton <jwe@octave.org>
parents:
19743
diff
changeset
|
381 // Defining a generic destructor generates a warning if destructors are |
bf737d927707
eliminate bison warnings from oct-parse.yy
John W. Eaton <jwe@octave.org>
parents:
19743
diff
changeset
|
382 // already explicitly declared for all types. |
bf737d927707
eliminate bison warnings from oct-parse.yy
John W. Eaton <jwe@octave.org>
parents:
19743
diff
changeset
|
383 // |
bf737d927707
eliminate bison warnings from oct-parse.yy
John W. Eaton <jwe@octave.org>
parents:
19743
diff
changeset
|
384 // %destructor { |
bf737d927707
eliminate bison warnings from oct-parse.yy
John W. Eaton <jwe@octave.org>
parents:
19743
diff
changeset
|
385 // warning_with_id |
bf737d927707
eliminate bison warnings from oct-parse.yy
John W. Eaton <jwe@octave.org>
parents:
19743
diff
changeset
|
386 // ("Octave:parser-destructor", |
bf737d927707
eliminate bison warnings from oct-parse.yy
John W. Eaton <jwe@octave.org>
parents:
19743
diff
changeset
|
387 // "possible memory leak in cleanup following parse error"); |
bf737d927707
eliminate bison warnings from oct-parse.yy
John W. Eaton <jwe@octave.org>
parents:
19743
diff
changeset
|
388 // } <*> |
17629
1e8f8900a041
clean up partially constructed parse tree objects on parse errors (bug #40231)
John W. Eaton <jwe@octave.org>
parents:
17622
diff
changeset
|
389 |
143 | 390 // Where to start. |
1 | 391 %start input |
392 | |
393 %% | |
394 | |
2970 | 395 // ============================== |
396 // Statements and statement lists | |
397 // ============================== | |
398 | |
17322
4c1ae06111c9
allow parser to accept empty statements (bug #37099)
John W. Eaton <jwe@octave.org>
parents:
17317
diff
changeset
|
399 input : simple_list '\n' |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
400 { |
19812
bf737d927707
eliminate bison warnings from oct-parse.yy
John W. Eaton <jwe@octave.org>
parents:
19743
diff
changeset
|
401 $$ = 0; |
16288
fe3b9a51e625
rename curr_lexer, curr_parser, CURR_LEXER
John W. Eaton <jwe@octave.org>
parents:
16287
diff
changeset
|
402 parser.stmt_list = $1; |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
403 YYACCEPT; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
404 } |
17322
4c1ae06111c9
allow parser to accept empty statements (bug #37099)
John W. Eaton <jwe@octave.org>
parents:
17317
diff
changeset
|
405 | simple_list END_OF_INPUT |
4c1ae06111c9
allow parser to accept empty statements (bug #37099)
John W. Eaton <jwe@octave.org>
parents:
17317
diff
changeset
|
406 { |
19812
bf737d927707
eliminate bison warnings from oct-parse.yy
John W. Eaton <jwe@octave.org>
parents:
19743
diff
changeset
|
407 $$ = 0; |
17322
4c1ae06111c9
allow parser to accept empty statements (bug #37099)
John W. Eaton <jwe@octave.org>
parents:
17317
diff
changeset
|
408 lexer.end_of_input = true; |
4c1ae06111c9
allow parser to accept empty statements (bug #37099)
John W. Eaton <jwe@octave.org>
parents:
17317
diff
changeset
|
409 parser.stmt_list = $1; |
4c1ae06111c9
allow parser to accept empty statements (bug #37099)
John W. Eaton <jwe@octave.org>
parents:
17317
diff
changeset
|
410 YYACCEPT; |
4c1ae06111c9
allow parser to accept empty statements (bug #37099)
John W. Eaton <jwe@octave.org>
parents:
17317
diff
changeset
|
411 } |
17326
f444e4cef9b9
avoid exiting Octave on parse error (bug #39862)
John W. Eaton <jwe@octave.org>
parents:
17322
diff
changeset
|
412 | parse_error |
19812
bf737d927707
eliminate bison warnings from oct-parse.yy
John W. Eaton <jwe@octave.org>
parents:
19743
diff
changeset
|
413 { |
bf737d927707
eliminate bison warnings from oct-parse.yy
John W. Eaton <jwe@octave.org>
parents:
19743
diff
changeset
|
414 $$ = 0; |
bf737d927707
eliminate bison warnings from oct-parse.yy
John W. Eaton <jwe@octave.org>
parents:
19743
diff
changeset
|
415 ABORT_PARSE; |
bf737d927707
eliminate bison warnings from oct-parse.yy
John W. Eaton <jwe@octave.org>
parents:
19743
diff
changeset
|
416 } |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
417 ; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
418 |
17322
4c1ae06111c9
allow parser to accept empty statements (bug #37099)
John W. Eaton <jwe@octave.org>
parents:
17317
diff
changeset
|
419 simple_list : opt_sep_no_nl |
19812
bf737d927707
eliminate bison warnings from oct-parse.yy
John W. Eaton <jwe@octave.org>
parents:
19743
diff
changeset
|
420 { |
bf737d927707
eliminate bison warnings from oct-parse.yy
John W. Eaton <jwe@octave.org>
parents:
19743
diff
changeset
|
421 YYUSE ($1); |
bf737d927707
eliminate bison warnings from oct-parse.yy
John W. Eaton <jwe@octave.org>
parents:
19743
diff
changeset
|
422 |
bf737d927707
eliminate bison warnings from oct-parse.yy
John W. Eaton <jwe@octave.org>
parents:
19743
diff
changeset
|
423 $$ = 0; |
bf737d927707
eliminate bison warnings from oct-parse.yy
John W. Eaton <jwe@octave.org>
parents:
19743
diff
changeset
|
424 } |
17322
4c1ae06111c9
allow parser to accept empty statements (bug #37099)
John W. Eaton <jwe@octave.org>
parents:
17317
diff
changeset
|
425 | 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
|
426 { $$ = 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
|
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 simple_list1 : statement |
16288
fe3b9a51e625
rename curr_lexer, curr_parser, CURR_LEXER
John W. Eaton <jwe@octave.org>
parents:
16287
diff
changeset
|
430 { $$ = parser.make_statement_list ($1); } |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
431 | 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
|
432 { $$ = 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
|
433 ; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
434 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
435 opt_list : // empty |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
436 { $$ = new tree_statement_list (); } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
437 | list |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
438 { $$ = $1; } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
439 ; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
440 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
441 list : list1 opt_sep |
16288
fe3b9a51e625
rename curr_lexer, curr_parser, CURR_LEXER
John W. Eaton <jwe@octave.org>
parents:
16287
diff
changeset
|
442 { $$ = 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
|
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 list1 : statement |
16288
fe3b9a51e625
rename curr_lexer, curr_parser, CURR_LEXER
John W. Eaton <jwe@octave.org>
parents:
16287
diff
changeset
|
446 { $$ = parser.make_statement_list ($1); } |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
447 | list1 sep statement |
16288
fe3b9a51e625
rename curr_lexer, curr_parser, CURR_LEXER
John W. Eaton <jwe@octave.org>
parents:
16287
diff
changeset
|
448 { $$ = 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
|
449 ; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
450 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
451 statement : expression |
17693
efbe746f8fa8
eliminate octave_comment_buffer singleton
John W. Eaton <jwe@octave.org>
parents:
17673
diff
changeset
|
452 { $$ = parser.make_statement ($1); } |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
453 | command |
17693
efbe746f8fa8
eliminate octave_comment_buffer singleton
John W. Eaton <jwe@octave.org>
parents:
17673
diff
changeset
|
454 { $$ = parser.make_statement ($1); } |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
455 | word_list_cmd |
17693
efbe746f8fa8
eliminate octave_comment_buffer singleton
John W. Eaton <jwe@octave.org>
parents:
17673
diff
changeset
|
456 { $$ = parser.make_statement ($1); } |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
457 ; |
8746
5dd06f19e9be
handle commands in the lexer
John W. Eaton <jwe@octave.org>
parents:
8745
diff
changeset
|
458 |
5dd06f19e9be
handle commands in the lexer
John W. Eaton <jwe@octave.org>
parents:
8745
diff
changeset
|
459 // ================= |
5dd06f19e9be
handle commands in the lexer
John W. Eaton <jwe@octave.org>
parents:
8745
diff
changeset
|
460 // Word-list command |
5dd06f19e9be
handle commands in the lexer
John W. Eaton <jwe@octave.org>
parents:
8745
diff
changeset
|
461 // ================= |
5dd06f19e9be
handle commands in the lexer
John W. Eaton <jwe@octave.org>
parents:
8745
diff
changeset
|
462 |
5dd06f19e9be
handle commands in the lexer
John W. Eaton <jwe@octave.org>
parents:
8745
diff
changeset
|
463 // 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
|
464 // 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
|
465 // WHILE, etc. |
5dd06f19e9be
handle commands in the lexer
John W. Eaton <jwe@octave.org>
parents:
8745
diff
changeset
|
466 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
467 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
|
468 { |
a4af67e0d22c
oct-parse.in.yy: a{~}.b segfaults the interpreter (bug #37804)
Max Brister <max@2bass.com>
parents:
16294
diff
changeset
|
469 $$ = 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
|
470 if (! $$) |
17632
bd0a84de3375
further reduce memory leaks from parse errors (bug #40231)
John W. Eaton <jwe@octave.org>
parents:
17629
diff
changeset
|
471 { |
bd0a84de3375
further reduce memory leaks from parse errors (bug #40231)
John W. Eaton <jwe@octave.org>
parents:
17629
diff
changeset
|
472 // make_index_expression deleted $1 and $2. |
bd0a84de3375
further reduce memory leaks from parse errors (bug #40231)
John W. Eaton <jwe@octave.org>
parents:
17629
diff
changeset
|
473 ABORT_PARSE; |
bd0a84de3375
further reduce memory leaks from parse errors (bug #40231)
John W. Eaton <jwe@octave.org>
parents:
17629
diff
changeset
|
474 } |
16302
a4af67e0d22c
oct-parse.in.yy: a{~}.b segfaults the interpreter (bug #37804)
Max Brister <max@2bass.com>
parents:
16294
diff
changeset
|
475 } |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
476 ; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
477 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
478 word_list : string |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
479 { $$ = new tree_argument_list ($1); } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
480 | word_list string |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
481 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
482 $1->append ($2); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
483 $$ = $1; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
484 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
485 ; |
1 | 486 |
2970 | 487 // =========== |
488 // Expressions | |
489 // =========== | |
490 | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
491 identifier : NAME |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
492 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
493 symbol_table::symbol_record *sr = $1->sym_rec (); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
494 $$ = new tree_identifier (*sr, $1->line (), $1->column ()); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
495 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
496 ; |
2970 | 497 |
9476 | 498 superclass_identifier |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
499 : SUPERCLASSREF |
15037
56b8eb7c9c04
improvements in parsing classdef
John W. Eaton <jwe@octave.org>
parents:
14846
diff
changeset
|
500 { |
56b8eb7c9c04
improvements in parsing classdef
John W. Eaton <jwe@octave.org>
parents:
14846
diff
changeset
|
501 std::string method_nm = $1->superclass_method_name (); |
56b8eb7c9c04
improvements in parsing classdef
John W. Eaton <jwe@octave.org>
parents:
14846
diff
changeset
|
502 std::string class_nm = $1->superclass_class_name (); |
56b8eb7c9c04
improvements in parsing classdef
John W. Eaton <jwe@octave.org>
parents:
14846
diff
changeset
|
503 |
18961
09eb8a2ddb02
eliminate some unused parameter warnings in parser functions
John W. Eaton <jwe@octave.org>
parents:
18537
diff
changeset
|
504 $$ = parser.make_superclass_ref (method_nm, class_nm); |
15037
56b8eb7c9c04
improvements in parsing classdef
John W. Eaton <jwe@octave.org>
parents:
14846
diff
changeset
|
505 } |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
506 ; |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11572
diff
changeset
|
507 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
508 meta_identifier : METAQUERY |
15037
56b8eb7c9c04
improvements in parsing classdef
John W. Eaton <jwe@octave.org>
parents:
14846
diff
changeset
|
509 { |
18520
932aca9a7c57
Allow multi-level classdef package.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
18419
diff
changeset
|
510 std::string class_nm = $1->text (); |
932aca9a7c57
Allow multi-level classdef package.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
18419
diff
changeset
|
511 |
18961
09eb8a2ddb02
eliminate some unused parameter warnings in parser functions
John W. Eaton <jwe@octave.org>
parents:
18537
diff
changeset
|
512 $$ = parser.make_meta_class_query (class_nm); |
15037
56b8eb7c9c04
improvements in parsing classdef
John W. Eaton <jwe@octave.org>
parents:
14846
diff
changeset
|
513 } |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11572
diff
changeset
|
514 ; |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
515 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
516 string : DQ_STRING |
16288
fe3b9a51e625
rename curr_lexer, curr_parser, CURR_LEXER
John W. Eaton <jwe@octave.org>
parents:
16287
diff
changeset
|
517 { $$ = parser.make_constant (DQ_STRING, $1); } |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
518 | SQ_STRING |
16288
fe3b9a51e625
rename curr_lexer, curr_parser, CURR_LEXER
John W. Eaton <jwe@octave.org>
parents:
16287
diff
changeset
|
519 { $$ = parser.make_constant (SQ_STRING, $1); } |
10315
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 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
522 constant : NUM |
16288
fe3b9a51e625
rename curr_lexer, curr_parser, CURR_LEXER
John W. Eaton <jwe@octave.org>
parents:
16287
diff
changeset
|
523 { $$ = parser.make_constant (NUM, $1); } |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
524 | IMAG_NUM |
16288
fe3b9a51e625
rename curr_lexer, curr_parser, CURR_LEXER
John W. Eaton <jwe@octave.org>
parents:
16287
diff
changeset
|
525 { $$ = parser.make_constant (IMAG_NUM, $1); } |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
526 | string |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
527 { $$ = $1; } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
528 ; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
529 |
16924
aebb54d99dba
improve compatibility of parsing of matrices and cell arrays
John W. Eaton <jwe@octave.org>
parents:
16850
diff
changeset
|
530 matrix : '[' matrix_rows ']' |
16288
fe3b9a51e625
rename curr_lexer, curr_parser, CURR_LEXER
John W. Eaton <jwe@octave.org>
parents:
16287
diff
changeset
|
531 { $$ = parser.finish_matrix ($2); } |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
532 ; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
533 |
16924
aebb54d99dba
improve compatibility of parsing of matrices and cell arrays
John W. Eaton <jwe@octave.org>
parents:
16850
diff
changeset
|
534 matrix_rows : cell_or_matrix_row |
aebb54d99dba
improve compatibility of parsing of matrices and cell arrays
John W. Eaton <jwe@octave.org>
parents:
16850
diff
changeset
|
535 { $$ = $1 ? new tree_matrix ($1) : 0; } |
aebb54d99dba
improve compatibility of parsing of matrices and cell arrays
John W. Eaton <jwe@octave.org>
parents:
16850
diff
changeset
|
536 | matrix_rows ';' cell_or_matrix_row |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
537 { |
16924
aebb54d99dba
improve compatibility of parsing of matrices and cell arrays
John W. Eaton <jwe@octave.org>
parents:
16850
diff
changeset
|
538 if ($1) |
aebb54d99dba
improve compatibility of parsing of matrices and cell arrays
John W. Eaton <jwe@octave.org>
parents:
16850
diff
changeset
|
539 { |
aebb54d99dba
improve compatibility of parsing of matrices and cell arrays
John W. Eaton <jwe@octave.org>
parents:
16850
diff
changeset
|
540 if ($3) |
aebb54d99dba
improve compatibility of parsing of matrices and cell arrays
John W. Eaton <jwe@octave.org>
parents:
16850
diff
changeset
|
541 $1->append ($3); |
aebb54d99dba
improve compatibility of parsing of matrices and cell arrays
John W. Eaton <jwe@octave.org>
parents:
16850
diff
changeset
|
542 |
aebb54d99dba
improve compatibility of parsing of matrices and cell arrays
John W. Eaton <jwe@octave.org>
parents:
16850
diff
changeset
|
543 $$ = $1; |
aebb54d99dba
improve compatibility of parsing of matrices and cell arrays
John W. Eaton <jwe@octave.org>
parents:
16850
diff
changeset
|
544 } |
aebb54d99dba
improve compatibility of parsing of matrices and cell arrays
John W. Eaton <jwe@octave.org>
parents:
16850
diff
changeset
|
545 else |
aebb54d99dba
improve compatibility of parsing of matrices and cell arrays
John W. Eaton <jwe@octave.org>
parents:
16850
diff
changeset
|
546 $$ = $3 ? new tree_matrix ($3) : 0; |
10315
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 ; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
549 |
16924
aebb54d99dba
improve compatibility of parsing of matrices and cell arrays
John W. Eaton <jwe@octave.org>
parents:
16850
diff
changeset
|
550 cell : '{' cell_rows '}' |
16288
fe3b9a51e625
rename curr_lexer, curr_parser, CURR_LEXER
John W. Eaton <jwe@octave.org>
parents:
16287
diff
changeset
|
551 { $$ = parser.finish_cell ($2); } |
10315
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 |
16924
aebb54d99dba
improve compatibility of parsing of matrices and cell arrays
John W. Eaton <jwe@octave.org>
parents:
16850
diff
changeset
|
554 cell_rows : cell_or_matrix_row |
aebb54d99dba
improve compatibility of parsing of matrices and cell arrays
John W. Eaton <jwe@octave.org>
parents:
16850
diff
changeset
|
555 { $$ = $1 ? new tree_cell ($1) : 0; } |
aebb54d99dba
improve compatibility of parsing of matrices and cell arrays
John W. Eaton <jwe@octave.org>
parents:
16850
diff
changeset
|
556 | cell_rows ';' cell_or_matrix_row |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
557 { |
16924
aebb54d99dba
improve compatibility of parsing of matrices and cell arrays
John W. Eaton <jwe@octave.org>
parents:
16850
diff
changeset
|
558 if ($1) |
aebb54d99dba
improve compatibility of parsing of matrices and cell arrays
John W. Eaton <jwe@octave.org>
parents:
16850
diff
changeset
|
559 { |
aebb54d99dba
improve compatibility of parsing of matrices and cell arrays
John W. Eaton <jwe@octave.org>
parents:
16850
diff
changeset
|
560 if ($3) |
aebb54d99dba
improve compatibility of parsing of matrices and cell arrays
John W. Eaton <jwe@octave.org>
parents:
16850
diff
changeset
|
561 $1->append ($3); |
aebb54d99dba
improve compatibility of parsing of matrices and cell arrays
John W. Eaton <jwe@octave.org>
parents:
16850
diff
changeset
|
562 |
aebb54d99dba
improve compatibility of parsing of matrices and cell arrays
John W. Eaton <jwe@octave.org>
parents:
16850
diff
changeset
|
563 $$ = $1; |
aebb54d99dba
improve compatibility of parsing of matrices and cell arrays
John W. Eaton <jwe@octave.org>
parents:
16850
diff
changeset
|
564 } |
aebb54d99dba
improve compatibility of parsing of matrices and cell arrays
John W. Eaton <jwe@octave.org>
parents:
16850
diff
changeset
|
565 else |
aebb54d99dba
improve compatibility of parsing of matrices and cell arrays
John W. Eaton <jwe@octave.org>
parents:
16850
diff
changeset
|
566 $$ = $3 ? new tree_cell ($3) : 0; |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
567 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
568 ; |
3351 | 569 |
16924
aebb54d99dba
improve compatibility of parsing of matrices and cell arrays
John W. Eaton <jwe@octave.org>
parents:
16850
diff
changeset
|
570 // tree_argument_list objects can't be empty or have leading or trailing |
aebb54d99dba
improve compatibility of parsing of matrices and cell arrays
John W. Eaton <jwe@octave.org>
parents:
16850
diff
changeset
|
571 // commas, but those are all allowed in matrix and cell array rows. |
aebb54d99dba
improve compatibility of parsing of matrices and cell arrays
John W. Eaton <jwe@octave.org>
parents:
16850
diff
changeset
|
572 |
3351 | 573 cell_or_matrix_row |
16924
aebb54d99dba
improve compatibility of parsing of matrices and cell arrays
John W. Eaton <jwe@octave.org>
parents:
16850
diff
changeset
|
574 : // empty |
aebb54d99dba
improve compatibility of parsing of matrices and cell arrays
John W. Eaton <jwe@octave.org>
parents:
16850
diff
changeset
|
575 { $$ = 0; } |
aebb54d99dba
improve compatibility of parsing of matrices and cell arrays
John W. Eaton <jwe@octave.org>
parents:
16850
diff
changeset
|
576 | ',' |
aebb54d99dba
improve compatibility of parsing of matrices and cell arrays
John W. Eaton <jwe@octave.org>
parents:
16850
diff
changeset
|
577 { $$ = 0; } |
aebb54d99dba
improve compatibility of parsing of matrices and cell arrays
John W. Eaton <jwe@octave.org>
parents:
16850
diff
changeset
|
578 | arg_list |
16257
db7f07b22b9b
1/10 commits reworking the lexer
John W. Eaton <jwe@octave.org>
parents:
16251
diff
changeset
|
579 { $$ = $1; } |
16924
aebb54d99dba
improve compatibility of parsing of matrices and cell arrays
John W. Eaton <jwe@octave.org>
parents:
16850
diff
changeset
|
580 | arg_list ',' |
16257
db7f07b22b9b
1/10 commits reworking the lexer
John W. Eaton <jwe@octave.org>
parents:
16251
diff
changeset
|
581 { $$ = $1; } |
16924
aebb54d99dba
improve compatibility of parsing of matrices and cell arrays
John W. Eaton <jwe@octave.org>
parents:
16850
diff
changeset
|
582 | ',' arg_list |
aebb54d99dba
improve compatibility of parsing of matrices and cell arrays
John W. Eaton <jwe@octave.org>
parents:
16850
diff
changeset
|
583 { $$ = $2; } |
aebb54d99dba
improve compatibility of parsing of matrices and cell arrays
John W. Eaton <jwe@octave.org>
parents:
16850
diff
changeset
|
584 | ',' arg_list ',' |
aebb54d99dba
improve compatibility of parsing of matrices and cell arrays
John W. Eaton <jwe@octave.org>
parents:
16850
diff
changeset
|
585 { $$ = $2; } |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
586 ; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
587 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
588 fcn_handle : '@' FCN_HANDLE |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
589 { |
16288
fe3b9a51e625
rename curr_lexer, curr_parser, CURR_LEXER
John W. Eaton <jwe@octave.org>
parents:
16287
diff
changeset
|
590 $$ = parser.make_fcn_handle ($2); |
fe3b9a51e625
rename curr_lexer, curr_parser, CURR_LEXER
John W. Eaton <jwe@octave.org>
parents:
16287
diff
changeset
|
591 lexer.looking_at_function_handle--; |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
592 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
593 ; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
594 |
16681
d3619d4d267c
recognize character string at beginning of statement (bug #38926, #38958)
John W. Eaton <jwe@octave.org>
parents:
16627
diff
changeset
|
595 anon_fcn_handle : '@' param_list stmt_begin statement |
13237
1bfca2bbea8b
fix parsing of anonymous functions inside cell array lists.
John W. Eaton <jwe@octave.org>
parents:
13125
diff
changeset
|
596 { |
16681
d3619d4d267c
recognize character string at beginning of statement (bug #38926, #38958)
John W. Eaton <jwe@octave.org>
parents:
16627
diff
changeset
|
597 $$ = parser.make_anon_fcn_handle ($2, $4); |
16288
fe3b9a51e625
rename curr_lexer, curr_parser, CURR_LEXER
John W. Eaton <jwe@octave.org>
parents:
16287
diff
changeset
|
598 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
|
599 } |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
600 ; |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11572
diff
changeset
|
601 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
602 primary_expr : identifier |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
603 { $$ = $1; } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
604 | constant |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
605 { $$ = $1; } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
606 | fcn_handle |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
607 { $$ = $1; } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
608 | matrix |
16257
db7f07b22b9b
1/10 commits reworking the lexer
John W. Eaton <jwe@octave.org>
parents:
16251
diff
changeset
|
609 { |
16288
fe3b9a51e625
rename curr_lexer, curr_parser, CURR_LEXER
John W. Eaton <jwe@octave.org>
parents:
16287
diff
changeset
|
610 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
|
611 $$ = $1; |
db7f07b22b9b
1/10 commits reworking the lexer
John W. Eaton <jwe@octave.org>
parents:
16251
diff
changeset
|
612 } |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
613 | cell |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
614 { $$ = $1; } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
615 | meta_identifier |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
616 { $$ = $1; } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
617 | superclass_identifier |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
618 { $$ = $1; } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
619 | '(' expression ')' |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
620 { $$ = $2->mark_in_parens (); } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
621 ; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
622 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
623 magic_colon : ':' |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
624 { |
19812
bf737d927707
eliminate bison warnings from oct-parse.yy
John W. Eaton <jwe@octave.org>
parents:
19743
diff
changeset
|
625 YYUSE ($1); |
bf737d927707
eliminate bison warnings from oct-parse.yy
John W. Eaton <jwe@octave.org>
parents:
19743
diff
changeset
|
626 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
627 octave_value tmp (octave_value::magic_colon_t); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
628 $$ = new tree_constant (tmp); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
629 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
630 ; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
631 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
632 magic_tilde : EXPR_NOT |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
633 { |
19812
bf737d927707
eliminate bison warnings from oct-parse.yy
John W. Eaton <jwe@octave.org>
parents:
19743
diff
changeset
|
634 YYUSE ($1); |
bf737d927707
eliminate bison warnings from oct-parse.yy
John W. Eaton <jwe@octave.org>
parents:
19743
diff
changeset
|
635 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
636 $$ = new tree_black_hole (); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
637 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
638 ; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
639 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
640 arg_list : expression |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
641 { $$ = new tree_argument_list ($1); } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
642 | magic_colon |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
643 { $$ = new tree_argument_list ($1); } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
644 | magic_tilde |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
645 { $$ = new tree_argument_list ($1); } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
646 | arg_list ',' magic_colon |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
647 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
648 $1->append ($3); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
649 $$ = $1; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
650 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
651 | arg_list ',' magic_tilde |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
652 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
653 $1->append ($3); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
654 $$ = $1; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
655 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
656 | arg_list ',' expression |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
657 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
658 $1->append ($3); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
659 $$ = $1; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
660 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
661 ; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
662 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
663 indirect_ref_op : '.' |
19812
bf737d927707
eliminate bison warnings from oct-parse.yy
John W. Eaton <jwe@octave.org>
parents:
19743
diff
changeset
|
664 { |
bf737d927707
eliminate bison warnings from oct-parse.yy
John W. Eaton <jwe@octave.org>
parents:
19743
diff
changeset
|
665 $$ = 0; |
bf737d927707
eliminate bison warnings from oct-parse.yy
John W. Eaton <jwe@octave.org>
parents:
19743
diff
changeset
|
666 lexer.looking_at_indirect_ref = true; |
bf737d927707
eliminate bison warnings from oct-parse.yy
John W. Eaton <jwe@octave.org>
parents:
19743
diff
changeset
|
667 } |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
668 ; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
669 |
12627
002948ae5bc0
fix precedence level of transpose operators (bug #32533)
John W. Eaton <jwe@octave.org>
parents:
12483
diff
changeset
|
670 oper_expr : primary_expr |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
671 { $$ = $1; } |
12627
002948ae5bc0
fix precedence level of transpose operators (bug #32533)
John W. Eaton <jwe@octave.org>
parents:
12483
diff
changeset
|
672 | oper_expr PLUS_PLUS |
16288
fe3b9a51e625
rename curr_lexer, curr_parser, CURR_LEXER
John W. Eaton <jwe@octave.org>
parents:
16287
diff
changeset
|
673 { $$ = 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
|
674 | oper_expr MINUS_MINUS |
16288
fe3b9a51e625
rename curr_lexer, curr_parser, CURR_LEXER
John W. Eaton <jwe@octave.org>
parents:
16287
diff
changeset
|
675 { $$ = 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
|
676 | oper_expr '(' ')' |
16302
a4af67e0d22c
oct-parse.in.yy: a{~}.b segfaults the interpreter (bug #37804)
Max Brister <max@2bass.com>
parents:
16294
diff
changeset
|
677 { |
a4af67e0d22c
oct-parse.in.yy: a{~}.b segfaults the interpreter (bug #37804)
Max Brister <max@2bass.com>
parents:
16294
diff
changeset
|
678 $$ = 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
|
679 if (! $$) |
17632
bd0a84de3375
further reduce memory leaks from parse errors (bug #40231)
John W. Eaton <jwe@octave.org>
parents:
17629
diff
changeset
|
680 { |
bd0a84de3375
further reduce memory leaks from parse errors (bug #40231)
John W. Eaton <jwe@octave.org>
parents:
17629
diff
changeset
|
681 // make_index_expression deleted $1. |
bd0a84de3375
further reduce memory leaks from parse errors (bug #40231)
John W. Eaton <jwe@octave.org>
parents:
17629
diff
changeset
|
682 ABORT_PARSE; |
bd0a84de3375
further reduce memory leaks from parse errors (bug #40231)
John W. Eaton <jwe@octave.org>
parents:
17629
diff
changeset
|
683 } |
16302
a4af67e0d22c
oct-parse.in.yy: a{~}.b segfaults the interpreter (bug #37804)
Max Brister <max@2bass.com>
parents:
16294
diff
changeset
|
684 } |
12627
002948ae5bc0
fix precedence level of transpose operators (bug #32533)
John W. Eaton <jwe@octave.org>
parents:
12483
diff
changeset
|
685 | 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
|
686 { |
a4af67e0d22c
oct-parse.in.yy: a{~}.b segfaults the interpreter (bug #37804)
Max Brister <max@2bass.com>
parents:
16294
diff
changeset
|
687 $$ = 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
|
688 if (! $$) |
17632
bd0a84de3375
further reduce memory leaks from parse errors (bug #40231)
John W. Eaton <jwe@octave.org>
parents:
17629
diff
changeset
|
689 { |
bd0a84de3375
further reduce memory leaks from parse errors (bug #40231)
John W. Eaton <jwe@octave.org>
parents:
17629
diff
changeset
|
690 // make_index_expression deleted $1 and $3. |
bd0a84de3375
further reduce memory leaks from parse errors (bug #40231)
John W. Eaton <jwe@octave.org>
parents:
17629
diff
changeset
|
691 ABORT_PARSE; |
bd0a84de3375
further reduce memory leaks from parse errors (bug #40231)
John W. Eaton <jwe@octave.org>
parents:
17629
diff
changeset
|
692 } |
16302
a4af67e0d22c
oct-parse.in.yy: a{~}.b segfaults the interpreter (bug #37804)
Max Brister <max@2bass.com>
parents:
16294
diff
changeset
|
693 } |
12627
002948ae5bc0
fix precedence level of transpose operators (bug #32533)
John W. Eaton <jwe@octave.org>
parents:
12483
diff
changeset
|
694 | oper_expr '{' '}' |
16302
a4af67e0d22c
oct-parse.in.yy: a{~}.b segfaults the interpreter (bug #37804)
Max Brister <max@2bass.com>
parents:
16294
diff
changeset
|
695 { |
a4af67e0d22c
oct-parse.in.yy: a{~}.b segfaults the interpreter (bug #37804)
Max Brister <max@2bass.com>
parents:
16294
diff
changeset
|
696 $$ = 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
|
697 if (! $$) |
17632
bd0a84de3375
further reduce memory leaks from parse errors (bug #40231)
John W. Eaton <jwe@octave.org>
parents:
17629
diff
changeset
|
698 { |
bd0a84de3375
further reduce memory leaks from parse errors (bug #40231)
John W. Eaton <jwe@octave.org>
parents:
17629
diff
changeset
|
699 // make_index_expression deleted $1. |
bd0a84de3375
further reduce memory leaks from parse errors (bug #40231)
John W. Eaton <jwe@octave.org>
parents:
17629
diff
changeset
|
700 ABORT_PARSE; |
bd0a84de3375
further reduce memory leaks from parse errors (bug #40231)
John W. Eaton <jwe@octave.org>
parents:
17629
diff
changeset
|
701 } |
16302
a4af67e0d22c
oct-parse.in.yy: a{~}.b segfaults the interpreter (bug #37804)
Max Brister <max@2bass.com>
parents:
16294
diff
changeset
|
702 } |
12627
002948ae5bc0
fix precedence level of transpose operators (bug #32533)
John W. Eaton <jwe@octave.org>
parents:
12483
diff
changeset
|
703 | 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
|
704 { |
a4af67e0d22c
oct-parse.in.yy: a{~}.b segfaults the interpreter (bug #37804)
Max Brister <max@2bass.com>
parents:
16294
diff
changeset
|
705 $$ = 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
|
706 if (! $$) |
17632
bd0a84de3375
further reduce memory leaks from parse errors (bug #40231)
John W. Eaton <jwe@octave.org>
parents:
17629
diff
changeset
|
707 { |
bd0a84de3375
further reduce memory leaks from parse errors (bug #40231)
John W. Eaton <jwe@octave.org>
parents:
17629
diff
changeset
|
708 // make_index_expression deleted $1 and $3. |
bd0a84de3375
further reduce memory leaks from parse errors (bug #40231)
John W. Eaton <jwe@octave.org>
parents:
17629
diff
changeset
|
709 ABORT_PARSE; |
bd0a84de3375
further reduce memory leaks from parse errors (bug #40231)
John W. Eaton <jwe@octave.org>
parents:
17629
diff
changeset
|
710 } |
16302
a4af67e0d22c
oct-parse.in.yy: a{~}.b segfaults the interpreter (bug #37804)
Max Brister <max@2bass.com>
parents:
16294
diff
changeset
|
711 } |
16284
09881dab3aaf
* lex.ll, oct-parse.in.yy (HERMITIAN): Rename token from QUOTE.
John W. Eaton <jwe@octave.org>
parents:
16279
diff
changeset
|
712 | oper_expr HERMITIAN |
16288
fe3b9a51e625
rename curr_lexer, curr_parser, CURR_LEXER
John W. Eaton <jwe@octave.org>
parents:
16287
diff
changeset
|
713 { $$ = 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
|
714 | oper_expr TRANSPOSE |
16288
fe3b9a51e625
rename curr_lexer, curr_parser, CURR_LEXER
John W. Eaton <jwe@octave.org>
parents:
16287
diff
changeset
|
715 { $$ = 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
|
716 | 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
|
717 { $$ = 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
|
718 | 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
|
719 { $$ = 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
|
720 | 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
|
721 { $$ = 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
|
722 | 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
|
723 { $$ = 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
|
724 | 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
|
725 { $$ = 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
|
726 | '+' oper_expr %prec UNARY |
16288
fe3b9a51e625
rename curr_lexer, curr_parser, CURR_LEXER
John W. Eaton <jwe@octave.org>
parents:
16287
diff
changeset
|
727 { $$ = 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
|
728 | '-' oper_expr %prec UNARY |
16288
fe3b9a51e625
rename curr_lexer, curr_parser, CURR_LEXER
John W. Eaton <jwe@octave.org>
parents:
16287
diff
changeset
|
729 { $$ = parser.make_prefix_op ('-', $2, $1); } |
17622
fd712a12fe53
compatibility for power operator precedence and direction (bug #33304)
Axel Mathéi <axel.mathei@gmail.com>
parents:
17618
diff
changeset
|
730 | oper_expr POW power_expr |
16288
fe3b9a51e625
rename curr_lexer, curr_parser, CURR_LEXER
John W. Eaton <jwe@octave.org>
parents:
16287
diff
changeset
|
731 { $$ = parser.make_binary_op (POW, $1, $2, $3); } |
17622
fd712a12fe53
compatibility for power operator precedence and direction (bug #33304)
Axel Mathéi <axel.mathei@gmail.com>
parents:
17618
diff
changeset
|
732 | oper_expr EPOW power_expr |
16288
fe3b9a51e625
rename curr_lexer, curr_parser, CURR_LEXER
John W. Eaton <jwe@octave.org>
parents:
16287
diff
changeset
|
733 { $$ = 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
|
734 | oper_expr '+' oper_expr |
16288
fe3b9a51e625
rename curr_lexer, curr_parser, CURR_LEXER
John W. Eaton <jwe@octave.org>
parents:
16287
diff
changeset
|
735 { $$ = 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
|
736 | oper_expr '-' oper_expr |
16288
fe3b9a51e625
rename curr_lexer, curr_parser, CURR_LEXER
John W. Eaton <jwe@octave.org>
parents:
16287
diff
changeset
|
737 { $$ = 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
|
738 | oper_expr '*' oper_expr |
16288
fe3b9a51e625
rename curr_lexer, curr_parser, CURR_LEXER
John W. Eaton <jwe@octave.org>
parents:
16287
diff
changeset
|
739 { $$ = 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
|
740 | oper_expr '/' oper_expr |
16288
fe3b9a51e625
rename curr_lexer, curr_parser, CURR_LEXER
John W. Eaton <jwe@octave.org>
parents:
16287
diff
changeset
|
741 { $$ = 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
|
742 | oper_expr EPLUS oper_expr |
16288
fe3b9a51e625
rename curr_lexer, curr_parser, CURR_LEXER
John W. Eaton <jwe@octave.org>
parents:
16287
diff
changeset
|
743 { $$ = 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
|
744 | oper_expr EMINUS oper_expr |
16288
fe3b9a51e625
rename curr_lexer, curr_parser, CURR_LEXER
John W. Eaton <jwe@octave.org>
parents:
16287
diff
changeset
|
745 { $$ = 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
|
746 | oper_expr EMUL oper_expr |
16288
fe3b9a51e625
rename curr_lexer, curr_parser, CURR_LEXER
John W. Eaton <jwe@octave.org>
parents:
16287
diff
changeset
|
747 { $$ = 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
|
748 | oper_expr EDIV oper_expr |
16288
fe3b9a51e625
rename curr_lexer, curr_parser, CURR_LEXER
John W. Eaton <jwe@octave.org>
parents:
16287
diff
changeset
|
749 { $$ = 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
|
750 | oper_expr LEFTDIV oper_expr |
16288
fe3b9a51e625
rename curr_lexer, curr_parser, CURR_LEXER
John W. Eaton <jwe@octave.org>
parents:
16287
diff
changeset
|
751 { $$ = 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
|
752 | oper_expr ELEFTDIV oper_expr |
16288
fe3b9a51e625
rename curr_lexer, curr_parser, CURR_LEXER
John W. Eaton <jwe@octave.org>
parents:
16287
diff
changeset
|
753 { $$ = 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
|
754 ; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
755 |
17622
fd712a12fe53
compatibility for power operator precedence and direction (bug #33304)
Axel Mathéi <axel.mathei@gmail.com>
parents:
17618
diff
changeset
|
756 power_expr : primary_expr |
fd712a12fe53
compatibility for power operator precedence and direction (bug #33304)
Axel Mathéi <axel.mathei@gmail.com>
parents:
17618
diff
changeset
|
757 { $$ = $1; } |
fd712a12fe53
compatibility for power operator precedence and direction (bug #33304)
Axel Mathéi <axel.mathei@gmail.com>
parents:
17618
diff
changeset
|
758 | power_expr PLUS_PLUS |
fd712a12fe53
compatibility for power operator precedence and direction (bug #33304)
Axel Mathéi <axel.mathei@gmail.com>
parents:
17618
diff
changeset
|
759 { $$ = parser.make_postfix_op (PLUS_PLUS, $1, $2); } |
fd712a12fe53
compatibility for power operator precedence and direction (bug #33304)
Axel Mathéi <axel.mathei@gmail.com>
parents:
17618
diff
changeset
|
760 | power_expr MINUS_MINUS |
fd712a12fe53
compatibility for power operator precedence and direction (bug #33304)
Axel Mathéi <axel.mathei@gmail.com>
parents:
17618
diff
changeset
|
761 { $$ = parser.make_postfix_op (MINUS_MINUS, $1, $2); } |
fd712a12fe53
compatibility for power operator precedence and direction (bug #33304)
Axel Mathéi <axel.mathei@gmail.com>
parents:
17618
diff
changeset
|
762 | power_expr '(' ')' |
fd712a12fe53
compatibility for power operator precedence and direction (bug #33304)
Axel Mathéi <axel.mathei@gmail.com>
parents:
17618
diff
changeset
|
763 { |
fd712a12fe53
compatibility for power operator precedence and direction (bug #33304)
Axel Mathéi <axel.mathei@gmail.com>
parents:
17618
diff
changeset
|
764 $$ = parser.make_index_expression ($1, 0, '('); |
fd712a12fe53
compatibility for power operator precedence and direction (bug #33304)
Axel Mathéi <axel.mathei@gmail.com>
parents:
17618
diff
changeset
|
765 if (! $$) |
17632
bd0a84de3375
further reduce memory leaks from parse errors (bug #40231)
John W. Eaton <jwe@octave.org>
parents:
17629
diff
changeset
|
766 { |
bd0a84de3375
further reduce memory leaks from parse errors (bug #40231)
John W. Eaton <jwe@octave.org>
parents:
17629
diff
changeset
|
767 // make_index_expression deleted $1. |
bd0a84de3375
further reduce memory leaks from parse errors (bug #40231)
John W. Eaton <jwe@octave.org>
parents:
17629
diff
changeset
|
768 ABORT_PARSE; |
bd0a84de3375
further reduce memory leaks from parse errors (bug #40231)
John W. Eaton <jwe@octave.org>
parents:
17629
diff
changeset
|
769 } |
17622
fd712a12fe53
compatibility for power operator precedence and direction (bug #33304)
Axel Mathéi <axel.mathei@gmail.com>
parents:
17618
diff
changeset
|
770 } |
fd712a12fe53
compatibility for power operator precedence and direction (bug #33304)
Axel Mathéi <axel.mathei@gmail.com>
parents:
17618
diff
changeset
|
771 | power_expr '(' arg_list ')' |
fd712a12fe53
compatibility for power operator precedence and direction (bug #33304)
Axel Mathéi <axel.mathei@gmail.com>
parents:
17618
diff
changeset
|
772 { |
fd712a12fe53
compatibility for power operator precedence and direction (bug #33304)
Axel Mathéi <axel.mathei@gmail.com>
parents:
17618
diff
changeset
|
773 $$ = parser.make_index_expression ($1, $3, '('); |
fd712a12fe53
compatibility for power operator precedence and direction (bug #33304)
Axel Mathéi <axel.mathei@gmail.com>
parents:
17618
diff
changeset
|
774 if (! $$) |
17632
bd0a84de3375
further reduce memory leaks from parse errors (bug #40231)
John W. Eaton <jwe@octave.org>
parents:
17629
diff
changeset
|
775 { |
bd0a84de3375
further reduce memory leaks from parse errors (bug #40231)
John W. Eaton <jwe@octave.org>
parents:
17629
diff
changeset
|
776 // make_index_expression deleted $1 and $3. |
bd0a84de3375
further reduce memory leaks from parse errors (bug #40231)
John W. Eaton <jwe@octave.org>
parents:
17629
diff
changeset
|
777 ABORT_PARSE; |
bd0a84de3375
further reduce memory leaks from parse errors (bug #40231)
John W. Eaton <jwe@octave.org>
parents:
17629
diff
changeset
|
778 } |
17622
fd712a12fe53
compatibility for power operator precedence and direction (bug #33304)
Axel Mathéi <axel.mathei@gmail.com>
parents:
17618
diff
changeset
|
779 } |
fd712a12fe53
compatibility for power operator precedence and direction (bug #33304)
Axel Mathéi <axel.mathei@gmail.com>
parents:
17618
diff
changeset
|
780 | power_expr '{' '}' |
fd712a12fe53
compatibility for power operator precedence and direction (bug #33304)
Axel Mathéi <axel.mathei@gmail.com>
parents:
17618
diff
changeset
|
781 { |
fd712a12fe53
compatibility for power operator precedence and direction (bug #33304)
Axel Mathéi <axel.mathei@gmail.com>
parents:
17618
diff
changeset
|
782 $$ = parser.make_index_expression ($1, 0, '{'); |
fd712a12fe53
compatibility for power operator precedence and direction (bug #33304)
Axel Mathéi <axel.mathei@gmail.com>
parents:
17618
diff
changeset
|
783 if (! $$) |
17632
bd0a84de3375
further reduce memory leaks from parse errors (bug #40231)
John W. Eaton <jwe@octave.org>
parents:
17629
diff
changeset
|
784 { |
bd0a84de3375
further reduce memory leaks from parse errors (bug #40231)
John W. Eaton <jwe@octave.org>
parents:
17629
diff
changeset
|
785 // make_index_expression deleted $1. |
bd0a84de3375
further reduce memory leaks from parse errors (bug #40231)
John W. Eaton <jwe@octave.org>
parents:
17629
diff
changeset
|
786 ABORT_PARSE; |
bd0a84de3375
further reduce memory leaks from parse errors (bug #40231)
John W. Eaton <jwe@octave.org>
parents:
17629
diff
changeset
|
787 } |
17622
fd712a12fe53
compatibility for power operator precedence and direction (bug #33304)
Axel Mathéi <axel.mathei@gmail.com>
parents:
17618
diff
changeset
|
788 } |
fd712a12fe53
compatibility for power operator precedence and direction (bug #33304)
Axel Mathéi <axel.mathei@gmail.com>
parents:
17618
diff
changeset
|
789 | power_expr '{' arg_list '}' |
fd712a12fe53
compatibility for power operator precedence and direction (bug #33304)
Axel Mathéi <axel.mathei@gmail.com>
parents:
17618
diff
changeset
|
790 { |
fd712a12fe53
compatibility for power operator precedence and direction (bug #33304)
Axel Mathéi <axel.mathei@gmail.com>
parents:
17618
diff
changeset
|
791 $$ = parser.make_index_expression ($1, $3, '{'); |
fd712a12fe53
compatibility for power operator precedence and direction (bug #33304)
Axel Mathéi <axel.mathei@gmail.com>
parents:
17618
diff
changeset
|
792 if (! $$) |
17632
bd0a84de3375
further reduce memory leaks from parse errors (bug #40231)
John W. Eaton <jwe@octave.org>
parents:
17629
diff
changeset
|
793 { |
bd0a84de3375
further reduce memory leaks from parse errors (bug #40231)
John W. Eaton <jwe@octave.org>
parents:
17629
diff
changeset
|
794 // make_index_expression deleted $1 and $3. |
bd0a84de3375
further reduce memory leaks from parse errors (bug #40231)
John W. Eaton <jwe@octave.org>
parents:
17629
diff
changeset
|
795 ABORT_PARSE; |
bd0a84de3375
further reduce memory leaks from parse errors (bug #40231)
John W. Eaton <jwe@octave.org>
parents:
17629
diff
changeset
|
796 } |
17622
fd712a12fe53
compatibility for power operator precedence and direction (bug #33304)
Axel Mathéi <axel.mathei@gmail.com>
parents:
17618
diff
changeset
|
797 } |
fd712a12fe53
compatibility for power operator precedence and direction (bug #33304)
Axel Mathéi <axel.mathei@gmail.com>
parents:
17618
diff
changeset
|
798 | power_expr indirect_ref_op STRUCT_ELT |
fd712a12fe53
compatibility for power operator precedence and direction (bug #33304)
Axel Mathéi <axel.mathei@gmail.com>
parents:
17618
diff
changeset
|
799 { $$ = parser.make_indirect_ref ($1, $3->text ()); } |
fd712a12fe53
compatibility for power operator precedence and direction (bug #33304)
Axel Mathéi <axel.mathei@gmail.com>
parents:
17618
diff
changeset
|
800 | power_expr indirect_ref_op '(' expression ')' |
fd712a12fe53
compatibility for power operator precedence and direction (bug #33304)
Axel Mathéi <axel.mathei@gmail.com>
parents:
17618
diff
changeset
|
801 { $$ = parser.make_indirect_ref ($1, $4); } |
fd712a12fe53
compatibility for power operator precedence and direction (bug #33304)
Axel Mathéi <axel.mathei@gmail.com>
parents:
17618
diff
changeset
|
802 | PLUS_PLUS power_expr %prec POW |
fd712a12fe53
compatibility for power operator precedence and direction (bug #33304)
Axel Mathéi <axel.mathei@gmail.com>
parents:
17618
diff
changeset
|
803 { $$ = parser.make_prefix_op (PLUS_PLUS, $2, $1); } |
fd712a12fe53
compatibility for power operator precedence and direction (bug #33304)
Axel Mathéi <axel.mathei@gmail.com>
parents:
17618
diff
changeset
|
804 | MINUS_MINUS power_expr %prec POW |
fd712a12fe53
compatibility for power operator precedence and direction (bug #33304)
Axel Mathéi <axel.mathei@gmail.com>
parents:
17618
diff
changeset
|
805 { $$ = parser.make_prefix_op (MINUS_MINUS, $2, $1); } |
fd712a12fe53
compatibility for power operator precedence and direction (bug #33304)
Axel Mathéi <axel.mathei@gmail.com>
parents:
17618
diff
changeset
|
806 | EXPR_NOT power_expr %prec POW |
fd712a12fe53
compatibility for power operator precedence and direction (bug #33304)
Axel Mathéi <axel.mathei@gmail.com>
parents:
17618
diff
changeset
|
807 { $$ = parser.make_prefix_op (EXPR_NOT, $2, $1); } |
fd712a12fe53
compatibility for power operator precedence and direction (bug #33304)
Axel Mathéi <axel.mathei@gmail.com>
parents:
17618
diff
changeset
|
808 | '+' power_expr %prec POW |
fd712a12fe53
compatibility for power operator precedence and direction (bug #33304)
Axel Mathéi <axel.mathei@gmail.com>
parents:
17618
diff
changeset
|
809 { $$ = parser.make_prefix_op ('+', $2, $1); } |
fd712a12fe53
compatibility for power operator precedence and direction (bug #33304)
Axel Mathéi <axel.mathei@gmail.com>
parents:
17618
diff
changeset
|
810 | '-' power_expr %prec POW |
fd712a12fe53
compatibility for power operator precedence and direction (bug #33304)
Axel Mathéi <axel.mathei@gmail.com>
parents:
17618
diff
changeset
|
811 { $$ = parser.make_prefix_op ('-', $2, $1); } |
fd712a12fe53
compatibility for power operator precedence and direction (bug #33304)
Axel Mathéi <axel.mathei@gmail.com>
parents:
17618
diff
changeset
|
812 ; |
fd712a12fe53
compatibility for power operator precedence and direction (bug #33304)
Axel Mathéi <axel.mathei@gmail.com>
parents:
17618
diff
changeset
|
813 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
814 colon_expr : colon_expr1 |
16288
fe3b9a51e625
rename curr_lexer, curr_parser, CURR_LEXER
John W. Eaton <jwe@octave.org>
parents:
16287
diff
changeset
|
815 { $$ = parser.finish_colon_expression ($1); } |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
816 ; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
817 |
12627
002948ae5bc0
fix precedence level of transpose operators (bug #32533)
John W. Eaton <jwe@octave.org>
parents:
12483
diff
changeset
|
818 colon_expr1 : oper_expr |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
819 { $$ = 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
|
820 | colon_expr1 ':' oper_expr |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
821 { |
19812
bf737d927707
eliminate bison warnings from oct-parse.yy
John W. Eaton <jwe@octave.org>
parents:
19743
diff
changeset
|
822 YYUSE ($2); |
bf737d927707
eliminate bison warnings from oct-parse.yy
John W. Eaton <jwe@octave.org>
parents:
19743
diff
changeset
|
823 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
824 if (! ($$ = $1->append ($3))) |
17632
bd0a84de3375
further reduce memory leaks from parse errors (bug #40231)
John W. Eaton <jwe@octave.org>
parents:
17629
diff
changeset
|
825 { |
bd0a84de3375
further reduce memory leaks from parse errors (bug #40231)
John W. Eaton <jwe@octave.org>
parents:
17629
diff
changeset
|
826 delete $1; |
bd0a84de3375
further reduce memory leaks from parse errors (bug #40231)
John W. Eaton <jwe@octave.org>
parents:
17629
diff
changeset
|
827 delete $3; |
bd0a84de3375
further reduce memory leaks from parse errors (bug #40231)
John W. Eaton <jwe@octave.org>
parents:
17629
diff
changeset
|
828 ABORT_PARSE; |
bd0a84de3375
further reduce memory leaks from parse errors (bug #40231)
John W. Eaton <jwe@octave.org>
parents:
17629
diff
changeset
|
829 } |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
830 } |
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 simple_expr : colon_expr |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
834 { $$ = $1; } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
835 | simple_expr LSHIFT simple_expr |
16288
fe3b9a51e625
rename curr_lexer, curr_parser, CURR_LEXER
John W. Eaton <jwe@octave.org>
parents:
16287
diff
changeset
|
836 { $$ = 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
|
837 | simple_expr RSHIFT simple_expr |
16288
fe3b9a51e625
rename curr_lexer, curr_parser, CURR_LEXER
John W. Eaton <jwe@octave.org>
parents:
16287
diff
changeset
|
838 { $$ = 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
|
839 | 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
|
840 { $$ = 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
|
841 | 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
|
842 { $$ = 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
|
843 | 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
|
844 { $$ = 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
|
845 | 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
|
846 { $$ = 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
|
847 | 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
|
848 { $$ = 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
|
849 | 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
|
850 { $$ = 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
|
851 | 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
|
852 { $$ = 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
|
853 | 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
|
854 { $$ = 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
|
855 | 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
|
856 { $$ = 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
|
857 | 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
|
858 { $$ = 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
|
859 ; |
2970 | 860 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
861 assign_lhs : simple_expr |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
862 { |
16288
fe3b9a51e625
rename curr_lexer, curr_parser, CURR_LEXER
John W. Eaton <jwe@octave.org>
parents:
16287
diff
changeset
|
863 $$ = parser.validate_matrix_for_assignment ($1); |
16273
c5e5f6ccac5d
9/10 commits reworking the lexer
John W. Eaton <jwe@octave.org>
parents:
16265
diff
changeset
|
864 |
c5e5f6ccac5d
9/10 commits reworking the lexer
John W. Eaton <jwe@octave.org>
parents:
16265
diff
changeset
|
865 if ($$) |
16288
fe3b9a51e625
rename curr_lexer, curr_parser, CURR_LEXER
John W. Eaton <jwe@octave.org>
parents:
16287
diff
changeset
|
866 { 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
|
867 else |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
868 { |
16277
8cb65fd72164
eliminate obsolete concepts of "pending local" and "forced" variables
John W. Eaton <jwe@octave.org>
parents:
16273
diff
changeset
|
869 // validate_matrix_for_assignment deleted $1. |
16273
c5e5f6ccac5d
9/10 commits reworking the lexer
John W. Eaton <jwe@octave.org>
parents:
16265
diff
changeset
|
870 ABORT_PARSE; |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
871 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
872 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
873 ; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
874 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
875 assign_expr : assign_lhs '=' expression |
16288
fe3b9a51e625
rename curr_lexer, curr_parser, CURR_LEXER
John W. Eaton <jwe@octave.org>
parents:
16287
diff
changeset
|
876 { $$ = parser.make_assign_op ('=', $1, $2, $3); } |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
877 | assign_lhs ADD_EQ expression |
16288
fe3b9a51e625
rename curr_lexer, curr_parser, CURR_LEXER
John W. Eaton <jwe@octave.org>
parents:
16287
diff
changeset
|
878 { $$ = 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
|
879 | assign_lhs SUB_EQ expression |
16288
fe3b9a51e625
rename curr_lexer, curr_parser, CURR_LEXER
John W. Eaton <jwe@octave.org>
parents:
16287
diff
changeset
|
880 { $$ = 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
|
881 | assign_lhs MUL_EQ expression |
16288
fe3b9a51e625
rename curr_lexer, curr_parser, CURR_LEXER
John W. Eaton <jwe@octave.org>
parents:
16287
diff
changeset
|
882 { $$ = 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
|
883 | assign_lhs DIV_EQ expression |
16288
fe3b9a51e625
rename curr_lexer, curr_parser, CURR_LEXER
John W. Eaton <jwe@octave.org>
parents:
16287
diff
changeset
|
884 { $$ = 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
|
885 | assign_lhs LEFTDIV_EQ expression |
16288
fe3b9a51e625
rename curr_lexer, curr_parser, CURR_LEXER
John W. Eaton <jwe@octave.org>
parents:
16287
diff
changeset
|
886 { $$ = 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
|
887 | assign_lhs POW_EQ expression |
16288
fe3b9a51e625
rename curr_lexer, curr_parser, CURR_LEXER
John W. Eaton <jwe@octave.org>
parents:
16287
diff
changeset
|
888 { $$ = 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
|
889 | assign_lhs LSHIFT_EQ expression |
16288
fe3b9a51e625
rename curr_lexer, curr_parser, CURR_LEXER
John W. Eaton <jwe@octave.org>
parents:
16287
diff
changeset
|
890 { $$ = 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
|
891 | assign_lhs RSHIFT_EQ expression |
16288
fe3b9a51e625
rename curr_lexer, curr_parser, CURR_LEXER
John W. Eaton <jwe@octave.org>
parents:
16287
diff
changeset
|
892 { $$ = 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
|
893 | assign_lhs EMUL_EQ expression |
16288
fe3b9a51e625
rename curr_lexer, curr_parser, CURR_LEXER
John W. Eaton <jwe@octave.org>
parents:
16287
diff
changeset
|
894 { $$ = 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
|
895 | assign_lhs EDIV_EQ expression |
16288
fe3b9a51e625
rename curr_lexer, curr_parser, CURR_LEXER
John W. Eaton <jwe@octave.org>
parents:
16287
diff
changeset
|
896 { $$ = 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
|
897 | assign_lhs ELEFTDIV_EQ expression |
16288
fe3b9a51e625
rename curr_lexer, curr_parser, CURR_LEXER
John W. Eaton <jwe@octave.org>
parents:
16287
diff
changeset
|
898 { $$ = 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
|
899 | assign_lhs EPOW_EQ expression |
16288
fe3b9a51e625
rename curr_lexer, curr_parser, CURR_LEXER
John W. Eaton <jwe@octave.org>
parents:
16287
diff
changeset
|
900 { $$ = 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
|
901 | assign_lhs AND_EQ expression |
16288
fe3b9a51e625
rename curr_lexer, curr_parser, CURR_LEXER
John W. Eaton <jwe@octave.org>
parents:
16287
diff
changeset
|
902 { $$ = 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
|
903 | assign_lhs OR_EQ expression |
16288
fe3b9a51e625
rename curr_lexer, curr_parser, CURR_LEXER
John W. Eaton <jwe@octave.org>
parents:
16287
diff
changeset
|
904 { $$ = 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
|
905 ; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
906 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
907 expression : simple_expr |
16273
c5e5f6ccac5d
9/10 commits reworking the lexer
John W. Eaton <jwe@octave.org>
parents:
16265
diff
changeset
|
908 { |
c5e5f6ccac5d
9/10 commits reworking the lexer
John W. Eaton <jwe@octave.org>
parents:
16265
diff
changeset
|
909 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
|
910 { |
16288
fe3b9a51e625
rename curr_lexer, curr_parser, CURR_LEXER
John W. Eaton <jwe@octave.org>
parents:
16287
diff
changeset
|
911 if (parser.validate_array_list ($1)) |
16273
c5e5f6ccac5d
9/10 commits reworking the lexer
John W. Eaton <jwe@octave.org>
parents:
16265
diff
changeset
|
912 $$ = $1; |
c5e5f6ccac5d
9/10 commits reworking the lexer
John W. Eaton <jwe@octave.org>
parents:
16265
diff
changeset
|
913 else |
c5e5f6ccac5d
9/10 commits reworking the lexer
John W. Eaton <jwe@octave.org>
parents:
16265
diff
changeset
|
914 { |
c5e5f6ccac5d
9/10 commits reworking the lexer
John W. Eaton <jwe@octave.org>
parents:
16265
diff
changeset
|
915 delete $1; |
c5e5f6ccac5d
9/10 commits reworking the lexer
John W. Eaton <jwe@octave.org>
parents:
16265
diff
changeset
|
916 ABORT_PARSE; |
c5e5f6ccac5d
9/10 commits reworking the lexer
John W. Eaton <jwe@octave.org>
parents:
16265
diff
changeset
|
917 } |
c5e5f6ccac5d
9/10 commits reworking the lexer
John W. Eaton <jwe@octave.org>
parents:
16265
diff
changeset
|
918 } |
c5e5f6ccac5d
9/10 commits reworking the lexer
John W. Eaton <jwe@octave.org>
parents:
16265
diff
changeset
|
919 else |
c5e5f6ccac5d
9/10 commits reworking the lexer
John W. Eaton <jwe@octave.org>
parents:
16265
diff
changeset
|
920 $$ = $1; |
c5e5f6ccac5d
9/10 commits reworking the lexer
John W. Eaton <jwe@octave.org>
parents:
16265
diff
changeset
|
921 } |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
922 | assign_expr |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
923 { $$ = $1; } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
924 | anon_fcn_handle |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
925 { $$ = $1; } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
926 ; |
2970 | 927 |
928 // ================================================ | |
929 // Commands, declarations, and function definitions | |
930 // ================================================ | |
931 | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
932 command : declaration |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
933 { $$ = $1; } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
934 | select_command |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
935 { $$ = $1; } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
936 | loop_command |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
937 { $$ = $1; } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
938 | jump_command |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
939 { $$ = $1; } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
940 | except_command |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
941 { $$ = $1; } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
942 | function |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
943 { $$ = $1; } |
16203
127cccb037bf
move more global parser and lexer variables to classes
John W. Eaton <jwe@octave.org>
parents:
16199
diff
changeset
|
944 | file |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
945 { $$ = $1; } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
946 ; |
2970 | 947 |
948 // ===================== | |
949 // Declaration statemnts | |
950 // ===================== | |
951 | |
16263
9acb86e6ac90
4/10 commits reworking the lexer
John W. Eaton <jwe@octave.org>
parents:
16259
diff
changeset
|
952 declaration : GLOBAL decl1 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
953 { |
16288
fe3b9a51e625
rename curr_lexer, curr_parser, CURR_LEXER
John W. Eaton <jwe@octave.org>
parents:
16287
diff
changeset
|
954 $$ = 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
|
955 lexer.looking_at_decl_list = false; |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
956 } |
16263
9acb86e6ac90
4/10 commits reworking the lexer
John W. Eaton <jwe@octave.org>
parents:
16259
diff
changeset
|
957 | PERSISTENT decl1 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
958 { |
16288
fe3b9a51e625
rename curr_lexer, curr_parser, CURR_LEXER
John W. Eaton <jwe@octave.org>
parents:
16287
diff
changeset
|
959 $$ = 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
|
960 lexer.looking_at_decl_list = false; |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
961 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
962 ; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
963 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
964 decl1 : decl2 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
965 { $$ = new tree_decl_init_list ($1); } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
966 | decl1 decl2 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
967 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
968 $1->append ($2); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
969 $$ = $1; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
970 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
971 ; |
2970 | 972 |
7634
ae90e05ad299
fix parameter list initializer bug
John W. Eaton <jwe@octave.org>
parents:
7587
diff
changeset
|
973 decl_param_init : // empty |
19812
bf737d927707
eliminate bison warnings from oct-parse.yy
John W. Eaton <jwe@octave.org>
parents:
19743
diff
changeset
|
974 { |
bf737d927707
eliminate bison warnings from oct-parse.yy
John W. Eaton <jwe@octave.org>
parents:
19743
diff
changeset
|
975 $$ = 0; |
bf737d927707
eliminate bison warnings from oct-parse.yy
John W. Eaton <jwe@octave.org>
parents:
19743
diff
changeset
|
976 lexer.looking_at_initializer_expression = true; |
bf737d927707
eliminate bison warnings from oct-parse.yy
John W. Eaton <jwe@octave.org>
parents:
19743
diff
changeset
|
977 } |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
978 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
979 decl2 : identifier |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
980 { $$ = new tree_decl_elt ($1); } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
981 | identifier '=' decl_param_init expression |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
982 { |
19812
bf737d927707
eliminate bison warnings from oct-parse.yy
John W. Eaton <jwe@octave.org>
parents:
19743
diff
changeset
|
983 YYUSE ($2); |
bf737d927707
eliminate bison warnings from oct-parse.yy
John W. Eaton <jwe@octave.org>
parents:
19743
diff
changeset
|
984 |
16288
fe3b9a51e625
rename curr_lexer, curr_parser, CURR_LEXER
John W. Eaton <jwe@octave.org>
parents:
16287
diff
changeset
|
985 lexer.looking_at_initializer_expression = false; |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
986 $$ = new tree_decl_elt ($1, $4); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
987 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
988 ; |
2970 | 989 |
990 // ==================== | |
991 // Selection statements | |
992 // ==================== | |
993 | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
994 select_command : if_command |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
995 { $$ = $1; } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
996 | switch_command |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
997 { $$ = $1; } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
998 ; |
2970 | 999 |
1000 // ============ | |
1001 // If statement | |
1002 // ============ | |
1003 | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1004 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
|
1005 { |
16288
fe3b9a51e625
rename curr_lexer, curr_parser, CURR_LEXER
John W. Eaton <jwe@octave.org>
parents:
16287
diff
changeset
|
1006 if (! ($$ = parser.finish_if_command ($1, $3, $4, $2))) |
17632
bd0a84de3375
further reduce memory leaks from parse errors (bug #40231)
John W. Eaton <jwe@octave.org>
parents:
17629
diff
changeset
|
1007 { |
bd0a84de3375
further reduce memory leaks from parse errors (bug #40231)
John W. Eaton <jwe@octave.org>
parents:
17629
diff
changeset
|
1008 // finish_if_command deleted $3. |
bd0a84de3375
further reduce memory leaks from parse errors (bug #40231)
John W. Eaton <jwe@octave.org>
parents:
17629
diff
changeset
|
1009 ABORT_PARSE; |
bd0a84de3375
further reduce memory leaks from parse errors (bug #40231)
John W. Eaton <jwe@octave.org>
parents:
17629
diff
changeset
|
1010 } |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1011 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1012 ; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1013 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1014 if_cmd_list : if_cmd_list1 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1015 { $$ = $1; } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1016 | if_cmd_list1 else_clause |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1017 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1018 $1->append ($2); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1019 $$ = $1; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1020 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1021 ; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1022 |
16681
d3619d4d267c
recognize character string at beginning of statement (bug #38926, #38958)
John W. Eaton <jwe@octave.org>
parents:
16627
diff
changeset
|
1023 if_cmd_list1 : expression stmt_begin opt_sep opt_list |
11091
5677f3f7b5fa
Matlab compatible short-circuit behavior for & and | operators
John W. Eaton <jwe@octave.org>
parents:
11060
diff
changeset
|
1024 { |
19812
bf737d927707
eliminate bison warnings from oct-parse.yy
John W. Eaton <jwe@octave.org>
parents:
19743
diff
changeset
|
1025 YYUSE ($3); |
bf737d927707
eliminate bison warnings from oct-parse.yy
John W. Eaton <jwe@octave.org>
parents:
19743
diff
changeset
|
1026 |
18126
d76f790b4eec
enable do_braindead_shortcircuit_evaluation by default and deprecate
John W. Eaton <jwe@octave.org>
parents:
17796
diff
changeset
|
1027 $1->mark_braindead_shortcircuit (); |
16288
fe3b9a51e625
rename curr_lexer, curr_parser, CURR_LEXER
John W. Eaton <jwe@octave.org>
parents:
16287
diff
changeset
|
1028 |
16681
d3619d4d267c
recognize character string at beginning of statement (bug #38926, #38958)
John W. Eaton <jwe@octave.org>
parents:
16627
diff
changeset
|
1029 $$ = parser.start_if_command ($1, $4); |
11091
5677f3f7b5fa
Matlab compatible short-circuit behavior for & and | operators
John W. Eaton <jwe@octave.org>
parents:
11060
diff
changeset
|
1030 } |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1031 | if_cmd_list1 elseif_clause |
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 $1->append ($2); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1034 $$ = $1; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1035 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1036 ; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1037 |
16681
d3619d4d267c
recognize character string at beginning of statement (bug #38926, #38958)
John W. Eaton <jwe@octave.org>
parents:
16627
diff
changeset
|
1038 elseif_clause : ELSEIF stash_comment opt_sep expression stmt_begin opt_sep opt_list |
11091
5677f3f7b5fa
Matlab compatible short-circuit behavior for & and | operators
John W. Eaton <jwe@octave.org>
parents:
11060
diff
changeset
|
1039 { |
19812
bf737d927707
eliminate bison warnings from oct-parse.yy
John W. Eaton <jwe@octave.org>
parents:
19743
diff
changeset
|
1040 YYUSE ($3); |
bf737d927707
eliminate bison warnings from oct-parse.yy
John W. Eaton <jwe@octave.org>
parents:
19743
diff
changeset
|
1041 YYUSE ($6); |
bf737d927707
eliminate bison warnings from oct-parse.yy
John W. Eaton <jwe@octave.org>
parents:
19743
diff
changeset
|
1042 |
18126
d76f790b4eec
enable do_braindead_shortcircuit_evaluation by default and deprecate
John W. Eaton <jwe@octave.org>
parents:
17796
diff
changeset
|
1043 $4->mark_braindead_shortcircuit (); |
16288
fe3b9a51e625
rename curr_lexer, curr_parser, CURR_LEXER
John W. Eaton <jwe@octave.org>
parents:
16287
diff
changeset
|
1044 |
16681
d3619d4d267c
recognize character string at beginning of statement (bug #38926, #38958)
John W. Eaton <jwe@octave.org>
parents:
16627
diff
changeset
|
1045 $$ = parser.make_elseif_clause ($1, $4, $7, $2); |
11091
5677f3f7b5fa
Matlab compatible short-circuit behavior for & and | operators
John W. Eaton <jwe@octave.org>
parents:
11060
diff
changeset
|
1046 } |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1047 ; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1048 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1049 else_clause : ELSE stash_comment opt_sep opt_list |
19812
bf737d927707
eliminate bison warnings from oct-parse.yy
John W. Eaton <jwe@octave.org>
parents:
19743
diff
changeset
|
1050 { |
bf737d927707
eliminate bison warnings from oct-parse.yy
John W. Eaton <jwe@octave.org>
parents:
19743
diff
changeset
|
1051 YYUSE ($1); |
bf737d927707
eliminate bison warnings from oct-parse.yy
John W. Eaton <jwe@octave.org>
parents:
19743
diff
changeset
|
1052 YYUSE ($3); |
bf737d927707
eliminate bison warnings from oct-parse.yy
John W. Eaton <jwe@octave.org>
parents:
19743
diff
changeset
|
1053 |
bf737d927707
eliminate bison warnings from oct-parse.yy
John W. Eaton <jwe@octave.org>
parents:
19743
diff
changeset
|
1054 $$ = new tree_if_clause ($4, $2); |
bf737d927707
eliminate bison warnings from oct-parse.yy
John W. Eaton <jwe@octave.org>
parents:
19743
diff
changeset
|
1055 } |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1056 ; |
2970 | 1057 |
1058 // ================ | |
1059 // Switch statement | |
1060 // ================ | |
1061 | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1062 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
|
1063 { |
19812
bf737d927707
eliminate bison warnings from oct-parse.yy
John W. Eaton <jwe@octave.org>
parents:
19743
diff
changeset
|
1064 YYUSE ($4); |
bf737d927707
eliminate bison warnings from oct-parse.yy
John W. Eaton <jwe@octave.org>
parents:
19743
diff
changeset
|
1065 |
16288
fe3b9a51e625
rename curr_lexer, curr_parser, CURR_LEXER
John W. Eaton <jwe@octave.org>
parents:
16287
diff
changeset
|
1066 if (! ($$ = parser.finish_switch_command ($1, $3, $5, $6, $2))) |
17632
bd0a84de3375
further reduce memory leaks from parse errors (bug #40231)
John W. Eaton <jwe@octave.org>
parents:
17629
diff
changeset
|
1067 { |
bd0a84de3375
further reduce memory leaks from parse errors (bug #40231)
John W. Eaton <jwe@octave.org>
parents:
17629
diff
changeset
|
1068 // finish_switch_command deleted $3 adn $5. |
bd0a84de3375
further reduce memory leaks from parse errors (bug #40231)
John W. Eaton <jwe@octave.org>
parents:
17629
diff
changeset
|
1069 ABORT_PARSE; |
bd0a84de3375
further reduce memory leaks from parse errors (bug #40231)
John W. Eaton <jwe@octave.org>
parents:
17629
diff
changeset
|
1070 } |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1071 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1072 ; |
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 case_list : // empty |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1075 { $$ = 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
|
1076 | default_case |
2da532d0f41c
accept otherwise clause in switch statement without preceding case statements
John W. Eaton <jwe@octave.org>
parents:
11258
diff
changeset
|
1077 { $$ = new tree_switch_case_list ($1); } |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1078 | case_list1 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1079 { $$ = $1; } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1080 | case_list1 default_case |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1081 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1082 $1->append ($2); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1083 $$ = $1; |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11572
diff
changeset
|
1084 } |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1085 ; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1086 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1087 case_list1 : switch_case |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1088 { $$ = new tree_switch_case_list ($1); } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1089 | case_list1 switch_case |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1090 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1091 $1->append ($2); |
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 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1094 ; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1095 |
16681
d3619d4d267c
recognize character string at beginning of statement (bug #38926, #38958)
John W. Eaton <jwe@octave.org>
parents:
16627
diff
changeset
|
1096 switch_case : CASE stash_comment opt_sep expression stmt_begin opt_sep opt_list |
19812
bf737d927707
eliminate bison warnings from oct-parse.yy
John W. Eaton <jwe@octave.org>
parents:
19743
diff
changeset
|
1097 { |
bf737d927707
eliminate bison warnings from oct-parse.yy
John W. Eaton <jwe@octave.org>
parents:
19743
diff
changeset
|
1098 YYUSE ($3); |
bf737d927707
eliminate bison warnings from oct-parse.yy
John W. Eaton <jwe@octave.org>
parents:
19743
diff
changeset
|
1099 YYUSE ($6); |
bf737d927707
eliminate bison warnings from oct-parse.yy
John W. Eaton <jwe@octave.org>
parents:
19743
diff
changeset
|
1100 |
bf737d927707
eliminate bison warnings from oct-parse.yy
John W. Eaton <jwe@octave.org>
parents:
19743
diff
changeset
|
1101 $$ = parser.make_switch_case ($1, $4, $7, $2); |
bf737d927707
eliminate bison warnings from oct-parse.yy
John W. Eaton <jwe@octave.org>
parents:
19743
diff
changeset
|
1102 } |
10315
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 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
|
1106 { |
19812
bf737d927707
eliminate bison warnings from oct-parse.yy
John W. Eaton <jwe@octave.org>
parents:
19743
diff
changeset
|
1107 YYUSE ($1); |
bf737d927707
eliminate bison warnings from oct-parse.yy
John W. Eaton <jwe@octave.org>
parents:
19743
diff
changeset
|
1108 YYUSE ($3); |
bf737d927707
eliminate bison warnings from oct-parse.yy
John W. Eaton <jwe@octave.org>
parents:
19743
diff
changeset
|
1109 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1110 $$ = new tree_switch_case ($4, $2); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1111 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1112 ; |
2970 | 1113 |
1114 // ======= | |
1115 // Looping | |
1116 // ======= | |
1117 | |
16681
d3619d4d267c
recognize character string at beginning of statement (bug #38926, #38958)
John W. Eaton <jwe@octave.org>
parents:
16627
diff
changeset
|
1118 loop_command : WHILE stash_comment expression stmt_begin opt_sep opt_list END |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1119 { |
19812
bf737d927707
eliminate bison warnings from oct-parse.yy
John W. Eaton <jwe@octave.org>
parents:
19743
diff
changeset
|
1120 YYUSE ($5); |
bf737d927707
eliminate bison warnings from oct-parse.yy
John W. Eaton <jwe@octave.org>
parents:
19743
diff
changeset
|
1121 |
18126
d76f790b4eec
enable do_braindead_shortcircuit_evaluation by default and deprecate
John W. Eaton <jwe@octave.org>
parents:
17796
diff
changeset
|
1122 $3->mark_braindead_shortcircuit (); |
16288
fe3b9a51e625
rename curr_lexer, curr_parser, CURR_LEXER
John W. Eaton <jwe@octave.org>
parents:
16287
diff
changeset
|
1123 |
16681
d3619d4d267c
recognize character string at beginning of statement (bug #38926, #38958)
John W. Eaton <jwe@octave.org>
parents:
16627
diff
changeset
|
1124 if (! ($$ = parser.make_while_command ($1, $3, $6, $7, $2))) |
17632
bd0a84de3375
further reduce memory leaks from parse errors (bug #40231)
John W. Eaton <jwe@octave.org>
parents:
17629
diff
changeset
|
1125 { |
bd0a84de3375
further reduce memory leaks from parse errors (bug #40231)
John W. Eaton <jwe@octave.org>
parents:
17629
diff
changeset
|
1126 // make_while_command deleted $3 and $6. |
bd0a84de3375
further reduce memory leaks from parse errors (bug #40231)
John W. Eaton <jwe@octave.org>
parents:
17629
diff
changeset
|
1127 ABORT_PARSE; |
bd0a84de3375
further reduce memory leaks from parse errors (bug #40231)
John W. Eaton <jwe@octave.org>
parents:
17629
diff
changeset
|
1128 } |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1129 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1130 | 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
|
1131 { |
19812
bf737d927707
eliminate bison warnings from oct-parse.yy
John W. Eaton <jwe@octave.org>
parents:
19743
diff
changeset
|
1132 YYUSE ($1); |
bf737d927707
eliminate bison warnings from oct-parse.yy
John W. Eaton <jwe@octave.org>
parents:
19743
diff
changeset
|
1133 YYUSE ($3); |
bf737d927707
eliminate bison warnings from oct-parse.yy
John W. Eaton <jwe@octave.org>
parents:
19743
diff
changeset
|
1134 |
17632
bd0a84de3375
further reduce memory leaks from parse errors (bug #40231)
John W. Eaton <jwe@octave.org>
parents:
17629
diff
changeset
|
1135 $$ = 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
|
1136 } |
16681
d3619d4d267c
recognize character string at beginning of statement (bug #38926, #38958)
John W. Eaton <jwe@octave.org>
parents:
16627
diff
changeset
|
1137 | FOR stash_comment assign_lhs '=' expression stmt_begin opt_sep opt_list END |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1138 { |
19812
bf737d927707
eliminate bison warnings from oct-parse.yy
John W. Eaton <jwe@octave.org>
parents:
19743
diff
changeset
|
1139 YYUSE ($4); |
bf737d927707
eliminate bison warnings from oct-parse.yy
John W. Eaton <jwe@octave.org>
parents:
19743
diff
changeset
|
1140 YYUSE ($7); |
bf737d927707
eliminate bison warnings from oct-parse.yy
John W. Eaton <jwe@octave.org>
parents:
19743
diff
changeset
|
1141 |
16288
fe3b9a51e625
rename curr_lexer, curr_parser, CURR_LEXER
John W. Eaton <jwe@octave.org>
parents:
16287
diff
changeset
|
1142 if (! ($$ = parser.make_for_command (FOR, $1, $3, $5, 0, |
17632
bd0a84de3375
further reduce memory leaks from parse errors (bug #40231)
John W. Eaton <jwe@octave.org>
parents:
17629
diff
changeset
|
1143 $8, $9, $2))) |
bd0a84de3375
further reduce memory leaks from parse errors (bug #40231)
John W. Eaton <jwe@octave.org>
parents:
17629
diff
changeset
|
1144 { |
bd0a84de3375
further reduce memory leaks from parse errors (bug #40231)
John W. Eaton <jwe@octave.org>
parents:
17629
diff
changeset
|
1145 // make_for_command deleted $3, $5, and $8. |
bd0a84de3375
further reduce memory leaks from parse errors (bug #40231)
John W. Eaton <jwe@octave.org>
parents:
17629
diff
changeset
|
1146 ABORT_PARSE; |
bd0a84de3375
further reduce memory leaks from parse errors (bug #40231)
John W. Eaton <jwe@octave.org>
parents:
17629
diff
changeset
|
1147 } |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1148 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1149 | 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
|
1150 { |
19812
bf737d927707
eliminate bison warnings from oct-parse.yy
John W. Eaton <jwe@octave.org>
parents:
19743
diff
changeset
|
1151 YYUSE ($5); |
bf737d927707
eliminate bison warnings from oct-parse.yy
John W. Eaton <jwe@octave.org>
parents:
19743
diff
changeset
|
1152 YYUSE ($8); |
bf737d927707
eliminate bison warnings from oct-parse.yy
John W. Eaton <jwe@octave.org>
parents:
19743
diff
changeset
|
1153 |
16288
fe3b9a51e625
rename curr_lexer, curr_parser, CURR_LEXER
John W. Eaton <jwe@octave.org>
parents:
16287
diff
changeset
|
1154 if (! ($$ = parser.make_for_command (FOR, $1, $4, $6, 0, |
17632
bd0a84de3375
further reduce memory leaks from parse errors (bug #40231)
John W. Eaton <jwe@octave.org>
parents:
17629
diff
changeset
|
1155 $9, $10, $2))) |
bd0a84de3375
further reduce memory leaks from parse errors (bug #40231)
John W. Eaton <jwe@octave.org>
parents:
17629
diff
changeset
|
1156 { |
bd0a84de3375
further reduce memory leaks from parse errors (bug #40231)
John W. Eaton <jwe@octave.org>
parents:
17629
diff
changeset
|
1157 // make_for_command deleted $4, $6, and $9. |
bd0a84de3375
further reduce memory leaks from parse errors (bug #40231)
John W. Eaton <jwe@octave.org>
parents:
17629
diff
changeset
|
1158 ABORT_PARSE; |
bd0a84de3375
further reduce memory leaks from parse errors (bug #40231)
John W. Eaton <jwe@octave.org>
parents:
17629
diff
changeset
|
1159 } |
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
|
1160 } |
16681
d3619d4d267c
recognize character string at beginning of statement (bug #38926, #38958)
John W. Eaton <jwe@octave.org>
parents:
16627
diff
changeset
|
1161 | PARFOR stash_comment assign_lhs '=' expression stmt_begin opt_sep opt_list END |
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
|
1162 { |
19812
bf737d927707
eliminate bison warnings from oct-parse.yy
John W. Eaton <jwe@octave.org>
parents:
19743
diff
changeset
|
1163 YYUSE ($4); |
bf737d927707
eliminate bison warnings from oct-parse.yy
John W. Eaton <jwe@octave.org>
parents:
19743
diff
changeset
|
1164 YYUSE ($7); |
bf737d927707
eliminate bison warnings from oct-parse.yy
John W. Eaton <jwe@octave.org>
parents:
19743
diff
changeset
|
1165 |
16288
fe3b9a51e625
rename curr_lexer, curr_parser, CURR_LEXER
John W. Eaton <jwe@octave.org>
parents:
16287
diff
changeset
|
1166 if (! ($$ = parser.make_for_command (PARFOR, $1, $3, $5, |
17632
bd0a84de3375
further reduce memory leaks from parse errors (bug #40231)
John W. Eaton <jwe@octave.org>
parents:
17629
diff
changeset
|
1167 0, $8, $9, $2))) |
bd0a84de3375
further reduce memory leaks from parse errors (bug #40231)
John W. Eaton <jwe@octave.org>
parents:
17629
diff
changeset
|
1168 { |
bd0a84de3375
further reduce memory leaks from parse errors (bug #40231)
John W. Eaton <jwe@octave.org>
parents:
17629
diff
changeset
|
1169 // make_for_command deleted $3, $5, and $8. |
bd0a84de3375
further reduce memory leaks from parse errors (bug #40231)
John W. Eaton <jwe@octave.org>
parents:
17629
diff
changeset
|
1170 ABORT_PARSE; |
bd0a84de3375
further reduce memory leaks from parse errors (bug #40231)
John W. Eaton <jwe@octave.org>
parents:
17629
diff
changeset
|
1171 } |
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
|
1172 } |
027a2186cd90
parfor keyword and infrastructure, but handle parfor as normal for loop for now
John W. Eaton <jwe@octave.org>
parents:
13241
diff
changeset
|
1173 | 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
|
1174 { |
19812
bf737d927707
eliminate bison warnings from oct-parse.yy
John W. Eaton <jwe@octave.org>
parents:
19743
diff
changeset
|
1175 YYUSE ($5); |
bf737d927707
eliminate bison warnings from oct-parse.yy
John W. Eaton <jwe@octave.org>
parents:
19743
diff
changeset
|
1176 YYUSE ($10); |
bf737d927707
eliminate bison warnings from oct-parse.yy
John W. Eaton <jwe@octave.org>
parents:
19743
diff
changeset
|
1177 |
16288
fe3b9a51e625
rename curr_lexer, curr_parser, CURR_LEXER
John W. Eaton <jwe@octave.org>
parents:
16287
diff
changeset
|
1178 if (! ($$ = parser.make_for_command (PARFOR, $1, $4, $6, |
17632
bd0a84de3375
further reduce memory leaks from parse errors (bug #40231)
John W. Eaton <jwe@octave.org>
parents:
17629
diff
changeset
|
1179 $8, $11, $12, $2))) |
bd0a84de3375
further reduce memory leaks from parse errors (bug #40231)
John W. Eaton <jwe@octave.org>
parents:
17629
diff
changeset
|
1180 { |
bd0a84de3375
further reduce memory leaks from parse errors (bug #40231)
John W. Eaton <jwe@octave.org>
parents:
17629
diff
changeset
|
1181 // make_for_command deleted $4, $6, $8, and $11. |
bd0a84de3375
further reduce memory leaks from parse errors (bug #40231)
John W. Eaton <jwe@octave.org>
parents:
17629
diff
changeset
|
1182 ABORT_PARSE; |
bd0a84de3375
further reduce memory leaks from parse errors (bug #40231)
John W. Eaton <jwe@octave.org>
parents:
17629
diff
changeset
|
1183 } |
10315
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 ; |
2970 | 1186 |
1187 // ======= | |
1188 // Jumping | |
1189 // ======= | |
1190 | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1191 jump_command : BREAK |
17632
bd0a84de3375
further reduce memory leaks from parse errors (bug #40231)
John W. Eaton <jwe@octave.org>
parents:
17629
diff
changeset
|
1192 { $$ = parser.make_break_command ($1); } |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1193 | CONTINUE |
17632
bd0a84de3375
further reduce memory leaks from parse errors (bug #40231)
John W. Eaton <jwe@octave.org>
parents:
17629
diff
changeset
|
1194 { $$ = parser.make_continue_command ($1); } |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1195 | FUNC_RET |
17632
bd0a84de3375
further reduce memory leaks from parse errors (bug #40231)
John W. Eaton <jwe@octave.org>
parents:
17629
diff
changeset
|
1196 { $$ = parser.make_return_command ($1); } |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1197 ; |
2970 | 1198 |
1199 // ========== | |
1200 // Exceptions | |
1201 // ========== | |
1202 | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1203 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
|
1204 stash_comment opt_sep opt_list END |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1205 { |
19812
bf737d927707
eliminate bison warnings from oct-parse.yy
John W. Eaton <jwe@octave.org>
parents:
19743
diff
changeset
|
1206 YYUSE ($3); |
bf737d927707
eliminate bison warnings from oct-parse.yy
John W. Eaton <jwe@octave.org>
parents:
19743
diff
changeset
|
1207 YYUSE ($5); |
bf737d927707
eliminate bison warnings from oct-parse.yy
John W. Eaton <jwe@octave.org>
parents:
19743
diff
changeset
|
1208 YYUSE ($7); |
bf737d927707
eliminate bison warnings from oct-parse.yy
John W. Eaton <jwe@octave.org>
parents:
19743
diff
changeset
|
1209 |
16288
fe3b9a51e625
rename curr_lexer, curr_parser, CURR_LEXER
John W. Eaton <jwe@octave.org>
parents:
16287
diff
changeset
|
1210 if (! ($$ = parser.make_unwind_command ($1, $4, $8, $9, $2, $6))) |
17632
bd0a84de3375
further reduce memory leaks from parse errors (bug #40231)
John W. Eaton <jwe@octave.org>
parents:
17629
diff
changeset
|
1211 { |
bd0a84de3375
further reduce memory leaks from parse errors (bug #40231)
John W. Eaton <jwe@octave.org>
parents:
17629
diff
changeset
|
1212 // make_unwind_command deleted $4 and $8. |
bd0a84de3375
further reduce memory leaks from parse errors (bug #40231)
John W. Eaton <jwe@octave.org>
parents:
17629
diff
changeset
|
1213 ABORT_PARSE; |
bd0a84de3375
further reduce memory leaks from parse errors (bug #40231)
John W. Eaton <jwe@octave.org>
parents:
17629
diff
changeset
|
1214 } |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1215 } |
17283
e6c0ac8ce5b6
eliminate parse conflicts introduced by changeset 923ce8b42db2
John W. Eaton <jwe@octave.org>
parents:
17281
diff
changeset
|
1216 | TRY stash_comment opt_sep opt_list CATCH stash_comment |
e6c0ac8ce5b6
eliminate parse conflicts introduced by changeset 923ce8b42db2
John W. Eaton <jwe@octave.org>
parents:
17281
diff
changeset
|
1217 opt_sep opt_list END |
17249
923ce8b42db2
improve try-catch-statement to save exception to a variable (bug #33217)
Stefan Mahr <dac922@gmx.de>
parents:
17170
diff
changeset
|
1218 { |
19812
bf737d927707
eliminate bison warnings from oct-parse.yy
John W. Eaton <jwe@octave.org>
parents:
19743
diff
changeset
|
1219 YYUSE ($3); |
bf737d927707
eliminate bison warnings from oct-parse.yy
John W. Eaton <jwe@octave.org>
parents:
19743
diff
changeset
|
1220 YYUSE ($5); |
bf737d927707
eliminate bison warnings from oct-parse.yy
John W. Eaton <jwe@octave.org>
parents:
19743
diff
changeset
|
1221 YYUSE ($7); |
bf737d927707
eliminate bison warnings from oct-parse.yy
John W. Eaton <jwe@octave.org>
parents:
19743
diff
changeset
|
1222 |
17283
e6c0ac8ce5b6
eliminate parse conflicts introduced by changeset 923ce8b42db2
John W. Eaton <jwe@octave.org>
parents:
17281
diff
changeset
|
1223 if (! ($$ = parser.make_try_command ($1, $4, $7, $8, $9, $2, $6))) |
17632
bd0a84de3375
further reduce memory leaks from parse errors (bug #40231)
John W. Eaton <jwe@octave.org>
parents:
17629
diff
changeset
|
1224 { |
bd0a84de3375
further reduce memory leaks from parse errors (bug #40231)
John W. Eaton <jwe@octave.org>
parents:
17629
diff
changeset
|
1225 // make_try_command deleted $4 and $8. |
bd0a84de3375
further reduce memory leaks from parse errors (bug #40231)
John W. Eaton <jwe@octave.org>
parents:
17629
diff
changeset
|
1226 ABORT_PARSE; |
bd0a84de3375
further reduce memory leaks from parse errors (bug #40231)
John W. Eaton <jwe@octave.org>
parents:
17629
diff
changeset
|
1227 } |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1228 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1229 | TRY stash_comment opt_sep opt_list END |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1230 { |
19812
bf737d927707
eliminate bison warnings from oct-parse.yy
John W. Eaton <jwe@octave.org>
parents:
19743
diff
changeset
|
1231 YYUSE ($3); |
bf737d927707
eliminate bison warnings from oct-parse.yy
John W. Eaton <jwe@octave.org>
parents:
19743
diff
changeset
|
1232 |
17249
923ce8b42db2
improve try-catch-statement to save exception to a variable (bug #33217)
Stefan Mahr <dac922@gmx.de>
parents:
17170
diff
changeset
|
1233 if (! ($$ = parser.make_try_command ($1, $4, 0, 0, $5, $2, 0))) |
17632
bd0a84de3375
further reduce memory leaks from parse errors (bug #40231)
John W. Eaton <jwe@octave.org>
parents:
17629
diff
changeset
|
1234 { |
bd0a84de3375
further reduce memory leaks from parse errors (bug #40231)
John W. Eaton <jwe@octave.org>
parents:
17629
diff
changeset
|
1235 // make_try_command deleted $4. |
bd0a84de3375
further reduce memory leaks from parse errors (bug #40231)
John W. Eaton <jwe@octave.org>
parents:
17629
diff
changeset
|
1236 ABORT_PARSE; |
bd0a84de3375
further reduce memory leaks from parse errors (bug #40231)
John W. Eaton <jwe@octave.org>
parents:
17629
diff
changeset
|
1237 } |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1238 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1239 ; |
2970 | 1240 |
1241 // =========================================== | |
15466
d174210ce1ec
use ' instead of ` in error messages, warnings and most comments
John W. Eaton <jwe@octave.org>
parents:
14189
diff
changeset
|
1242 // Some 'subroutines' for function definitions |
2970 | 1243 // =========================================== |
1244 | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1245 push_fcn_symtab : // empty |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1246 { |
19812
bf737d927707
eliminate bison warnings from oct-parse.yy
John W. Eaton <jwe@octave.org>
parents:
19743
diff
changeset
|
1247 $$ = 0; |
bf737d927707
eliminate bison warnings from oct-parse.yy
John W. Eaton <jwe@octave.org>
parents:
19743
diff
changeset
|
1248 |
16288
fe3b9a51e625
rename curr_lexer, curr_parser, CURR_LEXER
John W. Eaton <jwe@octave.org>
parents:
16287
diff
changeset
|
1249 parser.curr_fcn_depth++; |
fe3b9a51e625
rename curr_lexer, curr_parser, CURR_LEXER
John W. Eaton <jwe@octave.org>
parents:
16287
diff
changeset
|
1250 |
fe3b9a51e625
rename curr_lexer, curr_parser, CURR_LEXER
John W. Eaton <jwe@octave.org>
parents:
16287
diff
changeset
|
1251 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
|
1252 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
|
1253 |
16320
09f0cb9cac7d
don't modify symbol table scope in the parser
John W. Eaton <jwe@octave.org>
parents:
16302
diff
changeset
|
1254 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
|
1255 |
09f0cb9cac7d
don't modify symbol table scope in the parser
John W. Eaton <jwe@octave.org>
parents:
16302
diff
changeset
|
1256 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
|
1257 (lexer.symtab_context.curr_scope ()); |
16288
fe3b9a51e625
rename curr_lexer, curr_parser, CURR_LEXER
John W. Eaton <jwe@octave.org>
parents:
16287
diff
changeset
|
1258 |
fe3b9a51e625
rename curr_lexer, curr_parser, CURR_LEXER
John W. Eaton <jwe@octave.org>
parents:
16287
diff
changeset
|
1259 if (! lexer.reading_script_file |
fe3b9a51e625
rename curr_lexer, curr_parser, CURR_LEXER
John W. Eaton <jwe@octave.org>
parents:
16287
diff
changeset
|
1260 && parser.curr_fcn_depth == 1 |
fe3b9a51e625
rename curr_lexer, curr_parser, CURR_LEXER
John W. Eaton <jwe@octave.org>
parents:
16287
diff
changeset
|
1261 && ! parser.parsing_subfunctions) |
16320
09f0cb9cac7d
don't modify symbol table scope in the parser
John W. Eaton <jwe@octave.org>
parents:
16302
diff
changeset
|
1262 parser.primary_fcn_scope |
09f0cb9cac7d
don't modify symbol table scope in the parser
John W. Eaton <jwe@octave.org>
parents:
16302
diff
changeset
|
1263 = lexer.symtab_context.curr_scope (); |
16288
fe3b9a51e625
rename curr_lexer, curr_parser, CURR_LEXER
John W. Eaton <jwe@octave.org>
parents:
16287
diff
changeset
|
1264 |
fe3b9a51e625
rename curr_lexer, curr_parser, CURR_LEXER
John W. Eaton <jwe@octave.org>
parents:
16287
diff
changeset
|
1265 if (lexer.reading_script_file |
fe3b9a51e625
rename curr_lexer, curr_parser, CURR_LEXER
John W. Eaton <jwe@octave.org>
parents:
16287
diff
changeset
|
1266 && parser.curr_fcn_depth > 1) |
fe3b9a51e625
rename curr_lexer, curr_parser, CURR_LEXER
John W. Eaton <jwe@octave.org>
parents:
16287
diff
changeset
|
1267 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
|
1268 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1269 ; |
2970 | 1270 |
1271 // =========================== | |
1272 // List of function parameters | |
1273 // =========================== | |
1274 | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1275 param_list_beg : '(' |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1276 { |
19812
bf737d927707
eliminate bison warnings from oct-parse.yy
John W. Eaton <jwe@octave.org>
parents:
19743
diff
changeset
|
1277 $$ = 0; |
16288
fe3b9a51e625
rename curr_lexer, curr_parser, CURR_LEXER
John W. Eaton <jwe@octave.org>
parents:
16287
diff
changeset
|
1278 lexer.looking_at_parameter_list = true; |
fe3b9a51e625
rename curr_lexer, curr_parser, CURR_LEXER
John W. Eaton <jwe@octave.org>
parents:
16287
diff
changeset
|
1279 |
fe3b9a51e625
rename curr_lexer, curr_parser, CURR_LEXER
John W. Eaton <jwe@octave.org>
parents:
16287
diff
changeset
|
1280 if (lexer.looking_at_function_handle) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1281 { |
16320
09f0cb9cac7d
don't modify symbol table scope in the parser
John W. Eaton <jwe@octave.org>
parents:
16302
diff
changeset
|
1282 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
|
1283 lexer.looking_at_function_handle--; |
fe3b9a51e625
rename curr_lexer, curr_parser, CURR_LEXER
John W. Eaton <jwe@octave.org>
parents:
16287
diff
changeset
|
1284 lexer.looking_at_anon_fcn_args = true; |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1285 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1286 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1287 ; |
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 param_list_end : ')' |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1290 { |
19812
bf737d927707
eliminate bison warnings from oct-parse.yy
John W. Eaton <jwe@octave.org>
parents:
19743
diff
changeset
|
1291 $$ = 0; |
16288
fe3b9a51e625
rename curr_lexer, curr_parser, CURR_LEXER
John W. Eaton <jwe@octave.org>
parents:
16287
diff
changeset
|
1292 lexer.looking_at_parameter_list = false; |
fe3b9a51e625
rename curr_lexer, curr_parser, CURR_LEXER
John W. Eaton <jwe@octave.org>
parents:
16287
diff
changeset
|
1293 lexer.looking_for_object_index = false; |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1294 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1295 ; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1296 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1297 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
|
1298 { |
11115c237231
recognize variables when parsing (bug #38576)
John W. Eaton <jwe@octave.org>
parents:
16320
diff
changeset
|
1299 if ($2) |
11115c237231
recognize variables when parsing (bug #38576)
John W. Eaton <jwe@octave.org>
parents:
16320
diff
changeset
|
1300 lexer.mark_as_variables ($2->variable_names ()); |
11115c237231
recognize variables when parsing (bug #38576)
John W. Eaton <jwe@octave.org>
parents:
16320
diff
changeset
|
1301 |
11115c237231
recognize variables when parsing (bug #38576)
John W. Eaton <jwe@octave.org>
parents:
16320
diff
changeset
|
1302 $$ = $2; |
11115c237231
recognize variables when parsing (bug #38576)
John W. Eaton <jwe@octave.org>
parents:
16320
diff
changeset
|
1303 } |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1304 | param_list_beg error |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1305 { |
16288
fe3b9a51e625
rename curr_lexer, curr_parser, CURR_LEXER
John W. Eaton <jwe@octave.org>
parents:
16287
diff
changeset
|
1306 parser.bison_error ("invalid parameter list"); |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1307 $$ = 0; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1308 ABORT_PARSE; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1309 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1310 ; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1311 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1312 param_list1 : // empty |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1313 { $$ = 0; } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1314 | param_list2 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1315 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1316 $1->mark_as_formal_parameters (); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1317 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
|
1318 { |
11115c237231
recognize variables when parsing (bug #38576)
John W. Eaton <jwe@octave.org>
parents:
16320
diff
changeset
|
1319 lexer.mark_as_variables ($1->variable_names ()); |
11115c237231
recognize variables when parsing (bug #38576)
John W. Eaton <jwe@octave.org>
parents:
16320
diff
changeset
|
1320 $$ = $1; |
11115c237231
recognize variables when parsing (bug #38576)
John W. Eaton <jwe@octave.org>
parents:
16320
diff
changeset
|
1321 } |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1322 else |
17632
bd0a84de3375
further reduce memory leaks from parse errors (bug #40231)
John W. Eaton <jwe@octave.org>
parents:
17629
diff
changeset
|
1323 { |
bd0a84de3375
further reduce memory leaks from parse errors (bug #40231)
John W. Eaton <jwe@octave.org>
parents:
17629
diff
changeset
|
1324 delete $1; |
bd0a84de3375
further reduce memory leaks from parse errors (bug #40231)
John W. Eaton <jwe@octave.org>
parents:
17629
diff
changeset
|
1325 ABORT_PARSE; |
bd0a84de3375
further reduce memory leaks from parse errors (bug #40231)
John W. Eaton <jwe@octave.org>
parents:
17629
diff
changeset
|
1326 } |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1327 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1328 ; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1329 |
17317
56fe31b248de
disallow ~ in global and persistent declaration lists
John W. Eaton <jwe@octave.org>
parents:
17316
diff
changeset
|
1330 param_list2 : param_list_elt |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1331 { $$ = new tree_parameter_list ($1); } |
17317
56fe31b248de
disallow ~ in global and persistent declaration lists
John W. Eaton <jwe@octave.org>
parents:
17316
diff
changeset
|
1332 | param_list2 ',' param_list_elt |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1333 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1334 $1->append ($3); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1335 $$ = $1; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1336 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1337 ; |
2970 | 1338 |
17317
56fe31b248de
disallow ~ in global and persistent declaration lists
John W. Eaton <jwe@octave.org>
parents:
17316
diff
changeset
|
1339 param_list_elt : decl2 |
56fe31b248de
disallow ~ in global and persistent declaration lists
John W. Eaton <jwe@octave.org>
parents:
17316
diff
changeset
|
1340 { $$ = $1; } |
56fe31b248de
disallow ~ in global and persistent declaration lists
John W. Eaton <jwe@octave.org>
parents:
17316
diff
changeset
|
1341 | magic_tilde |
56fe31b248de
disallow ~ in global and persistent declaration lists
John W. Eaton <jwe@octave.org>
parents:
17316
diff
changeset
|
1342 { $$ = new tree_decl_elt ($1); } |
56fe31b248de
disallow ~ in global and persistent declaration lists
John W. Eaton <jwe@octave.org>
parents:
17316
diff
changeset
|
1343 ; |
56fe31b248de
disallow ~ in global and persistent declaration lists
John W. Eaton <jwe@octave.org>
parents:
17316
diff
changeset
|
1344 |
2970 | 1345 // =================================== |
1346 // List of function return value names | |
1347 // =================================== | |
1348 | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1349 return_list : '[' ']' |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1350 { |
16288
fe3b9a51e625
rename curr_lexer, curr_parser, CURR_LEXER
John W. Eaton <jwe@octave.org>
parents:
16287
diff
changeset
|
1351 lexer.looking_at_return_list = false; |
17316
8e2906e2fb26
avoid reduce/reduce conflict in parser rules
John W. Eaton <jwe@octave.org>
parents:
17283
diff
changeset
|
1352 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1353 $$ = new tree_parameter_list (); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1354 } |
17316
8e2906e2fb26
avoid reduce/reduce conflict in parser rules
John W. Eaton <jwe@octave.org>
parents:
17283
diff
changeset
|
1355 | identifier |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1356 { |
16288
fe3b9a51e625
rename curr_lexer, curr_parser, CURR_LEXER
John W. Eaton <jwe@octave.org>
parents:
16287
diff
changeset
|
1357 lexer.looking_at_return_list = false; |
17316
8e2906e2fb26
avoid reduce/reduce conflict in parser rules
John W. Eaton <jwe@octave.org>
parents:
17283
diff
changeset
|
1358 |
8e2906e2fb26
avoid reduce/reduce conflict in parser rules
John W. Eaton <jwe@octave.org>
parents:
17283
diff
changeset
|
1359 tree_parameter_list *tmp = new tree_parameter_list ($1); |
8e2906e2fb26
avoid reduce/reduce conflict in parser rules
John W. Eaton <jwe@octave.org>
parents:
17283
diff
changeset
|
1360 |
8e2906e2fb26
avoid reduce/reduce conflict in parser rules
John W. Eaton <jwe@octave.org>
parents:
17283
diff
changeset
|
1361 // Even though this parameter list can contain only |
8e2906e2fb26
avoid reduce/reduce conflict in parser rules
John W. Eaton <jwe@octave.org>
parents:
17283
diff
changeset
|
1362 // a single identifier, we still need to validate it |
8e2906e2fb26
avoid reduce/reduce conflict in parser rules
John W. Eaton <jwe@octave.org>
parents:
17283
diff
changeset
|
1363 // to check for varargin or varargout. |
8e2906e2fb26
avoid reduce/reduce conflict in parser rules
John W. Eaton <jwe@octave.org>
parents:
17283
diff
changeset
|
1364 |
8e2906e2fb26
avoid reduce/reduce conflict in parser rules
John W. Eaton <jwe@octave.org>
parents:
17283
diff
changeset
|
1365 if (tmp->validate (tree_parameter_list::out)) |
8e2906e2fb26
avoid reduce/reduce conflict in parser rules
John W. Eaton <jwe@octave.org>
parents:
17283
diff
changeset
|
1366 $$ = tmp; |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1367 else |
17632
bd0a84de3375
further reduce memory leaks from parse errors (bug #40231)
John W. Eaton <jwe@octave.org>
parents:
17629
diff
changeset
|
1368 { |
bd0a84de3375
further reduce memory leaks from parse errors (bug #40231)
John W. Eaton <jwe@octave.org>
parents:
17629
diff
changeset
|
1369 delete tmp; |
bd0a84de3375
further reduce memory leaks from parse errors (bug #40231)
John W. Eaton <jwe@octave.org>
parents:
17629
diff
changeset
|
1370 ABORT_PARSE; |
bd0a84de3375
further reduce memory leaks from parse errors (bug #40231)
John W. Eaton <jwe@octave.org>
parents:
17629
diff
changeset
|
1371 } |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1372 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1373 | '[' return_list1 ']' |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1374 { |
16288
fe3b9a51e625
rename curr_lexer, curr_parser, CURR_LEXER
John W. Eaton <jwe@octave.org>
parents:
16287
diff
changeset
|
1375 lexer.looking_at_return_list = false; |
17316
8e2906e2fb26
avoid reduce/reduce conflict in parser rules
John W. Eaton <jwe@octave.org>
parents:
17283
diff
changeset
|
1376 |
8e2906e2fb26
avoid reduce/reduce conflict in parser rules
John W. Eaton <jwe@octave.org>
parents:
17283
diff
changeset
|
1377 // Check for duplicate parameter names, varargin, |
8e2906e2fb26
avoid reduce/reduce conflict in parser rules
John W. Eaton <jwe@octave.org>
parents:
17283
diff
changeset
|
1378 // or varargout. |
8e2906e2fb26
avoid reduce/reduce conflict in parser rules
John W. Eaton <jwe@octave.org>
parents:
17283
diff
changeset
|
1379 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1380 if ($2->validate (tree_parameter_list::out)) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1381 $$ = $2; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1382 else |
17632
bd0a84de3375
further reduce memory leaks from parse errors (bug #40231)
John W. Eaton <jwe@octave.org>
parents:
17629
diff
changeset
|
1383 { |
bd0a84de3375
further reduce memory leaks from parse errors (bug #40231)
John W. Eaton <jwe@octave.org>
parents:
17629
diff
changeset
|
1384 delete $2; |
bd0a84de3375
further reduce memory leaks from parse errors (bug #40231)
John W. Eaton <jwe@octave.org>
parents:
17629
diff
changeset
|
1385 ABORT_PARSE; |
bd0a84de3375
further reduce memory leaks from parse errors (bug #40231)
John W. Eaton <jwe@octave.org>
parents:
17629
diff
changeset
|
1386 } |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1387 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1388 ; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1389 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1390 return_list1 : identifier |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1391 { $$ = 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
|
1392 | return_list1 ',' identifier |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1393 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1394 $1->append (new tree_decl_elt ($3)); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1395 $$ = $1; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1396 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1397 ; |
2970 | 1398 |
16203
127cccb037bf
move more global parser and lexer variables to classes
John W. Eaton <jwe@octave.org>
parents:
16199
diff
changeset
|
1399 // ======================= |
127cccb037bf
move more global parser and lexer variables to classes
John W. Eaton <jwe@octave.org>
parents:
16199
diff
changeset
|
1400 // Script or function file |
127cccb037bf
move more global parser and lexer variables to classes
John W. Eaton <jwe@octave.org>
parents:
16199
diff
changeset
|
1401 // ======================= |
127cccb037bf
move more global parser and lexer variables to classes
John W. Eaton <jwe@octave.org>
parents:
16199
diff
changeset
|
1402 |
127cccb037bf
move more global parser and lexer variables to classes
John W. Eaton <jwe@octave.org>
parents:
16199
diff
changeset
|
1403 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
|
1404 { |
19812
bf737d927707
eliminate bison warnings from oct-parse.yy
John W. Eaton <jwe@octave.org>
parents:
19743
diff
changeset
|
1405 YYUSE ($2); |
bf737d927707
eliminate bison warnings from oct-parse.yy
John W. Eaton <jwe@octave.org>
parents:
19743
diff
changeset
|
1406 |
17618
77eff9c6fb09
avoid memory leak when parsing function files (bug #40218)
John W. Eaton <jwe@octave.org>
parents:
17377
diff
changeset
|
1407 if (lexer.reading_fcn_file) |
77eff9c6fb09
avoid memory leak when parsing function files (bug #40218)
John W. Eaton <jwe@octave.org>
parents:
17377
diff
changeset
|
1408 { |
77eff9c6fb09
avoid memory leak when parsing function files (bug #40218)
John W. Eaton <jwe@octave.org>
parents:
17377
diff
changeset
|
1409 // Delete the dummy statement_list we created |
77eff9c6fb09
avoid memory leak when parsing function files (bug #40218)
John W. Eaton <jwe@octave.org>
parents:
17377
diff
changeset
|
1410 // after parsing the function. Any function |
77eff9c6fb09
avoid memory leak when parsing function files (bug #40218)
John W. Eaton <jwe@octave.org>
parents:
17377
diff
changeset
|
1411 // definitions found in the file have already |
77eff9c6fb09
avoid memory leak when parsing function files (bug #40218)
John W. Eaton <jwe@octave.org>
parents:
17377
diff
changeset
|
1412 // been stored in the symbol table or in |
77eff9c6fb09
avoid memory leak when parsing function files (bug #40218)
John W. Eaton <jwe@octave.org>
parents:
17377
diff
changeset
|
1413 // octave_base_parser::primary_fcn_ptr. |
77eff9c6fb09
avoid memory leak when parsing function files (bug #40218)
John W. Eaton <jwe@octave.org>
parents:
17377
diff
changeset
|
1414 |
77eff9c6fb09
avoid memory leak when parsing function files (bug #40218)
John W. Eaton <jwe@octave.org>
parents:
17377
diff
changeset
|
1415 delete $3; |
77eff9c6fb09
avoid memory leak when parsing function files (bug #40218)
John W. Eaton <jwe@octave.org>
parents:
17377
diff
changeset
|
1416 } |
77eff9c6fb09
avoid memory leak when parsing function files (bug #40218)
John W. Eaton <jwe@octave.org>
parents:
17377
diff
changeset
|
1417 else |
16203
127cccb037bf
move more global parser and lexer variables to classes
John W. Eaton <jwe@octave.org>
parents:
16199
diff
changeset
|
1418 { |
127cccb037bf
move more global parser and lexer variables to classes
John W. Eaton <jwe@octave.org>
parents:
16199
diff
changeset
|
1419 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
|
1420 = 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
|
1421 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
|
1422 lexer.current_input_column); |
16288
fe3b9a51e625
rename curr_lexer, curr_parser, CURR_LEXER
John W. Eaton <jwe@octave.org>
parents:
16287
diff
changeset
|
1423 |
fe3b9a51e625
rename curr_lexer, curr_parser, CURR_LEXER
John W. Eaton <jwe@octave.org>
parents:
16287
diff
changeset
|
1424 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
|
1425 } |
10315
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 $$ = 0; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1428 } |
16211
3449bf257514
maint: fix botched merge of default to classdef
John W. Eaton <jwe@octave.org>
parents:
16205
diff
changeset
|
1429 | INPUT_FILE opt_nl classdef opt_sep END_OF_INPUT |
3449bf257514
maint: fix botched merge of default to classdef
John W. Eaton <jwe@octave.org>
parents:
16205
diff
changeset
|
1430 { |
19812
bf737d927707
eliminate bison warnings from oct-parse.yy
John W. Eaton <jwe@octave.org>
parents:
19743
diff
changeset
|
1431 YYUSE ($2); |
bf737d927707
eliminate bison warnings from oct-parse.yy
John W. Eaton <jwe@octave.org>
parents:
19743
diff
changeset
|
1432 YYUSE ($4); |
bf737d927707
eliminate bison warnings from oct-parse.yy
John W. Eaton <jwe@octave.org>
parents:
19743
diff
changeset
|
1433 |
16289
bde729ba8381
maint: periodic merge of default to classdef
John W. Eaton <jwe@octave.org>
diff
changeset
|
1434 if (lexer.reading_classdef_file) |
bde729ba8381
maint: periodic merge of default to classdef
John W. Eaton <jwe@octave.org>
diff
changeset
|
1435 parser.classdef_object = $3; |
16211
3449bf257514
maint: fix botched merge of default to classdef
John W. Eaton <jwe@octave.org>
parents:
16205
diff
changeset
|
1436 |
3449bf257514
maint: fix botched merge of default to classdef
John W. Eaton <jwe@octave.org>
parents:
16205
diff
changeset
|
1437 $$ = 0; |
3449bf257514
maint: fix botched merge of default to classdef
John W. Eaton <jwe@octave.org>
parents:
16205
diff
changeset
|
1438 } |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1439 ; |
7715
5b4d278ec828
parse scripts completely before executing
John W. Eaton <jwe@octave.org>
parents:
7699
diff
changeset
|
1440 |
2970 | 1441 // =================== |
1442 // Function definition | |
1443 // =================== | |
1444 | |
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
|
1445 function_beg : push_fcn_symtab FCN |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1446 { |
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
|
1447 $$ = $2; |
16288
fe3b9a51e625
rename curr_lexer, curr_parser, CURR_LEXER
John W. Eaton <jwe@octave.org>
parents:
16287
diff
changeset
|
1448 if (lexer.reading_classdef_file |
fe3b9a51e625
rename curr_lexer, curr_parser, CURR_LEXER
John W. Eaton <jwe@octave.org>
parents:
16287
diff
changeset
|
1449 || lexer.parsing_classdef) |
fe3b9a51e625
rename curr_lexer, curr_parser, CURR_LEXER
John W. Eaton <jwe@octave.org>
parents:
16287
diff
changeset
|
1450 lexer.maybe_classdef_get_set_method = true; |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1451 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1452 ; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1453 |
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
|
1454 function : function_beg stash_comment function1 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1455 { |
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
|
1456 $$ = 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
|
1457 $1->column ()); |
16288
fe3b9a51e625
rename curr_lexer, curr_parser, CURR_LEXER
John W. Eaton <jwe@octave.org>
parents:
16287
diff
changeset
|
1458 parser.recover_from_parsing_function (); |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1459 } |
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
|
1460 | function_beg stash_comment return_list '=' function1 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1461 { |
19812
bf737d927707
eliminate bison warnings from oct-parse.yy
John W. Eaton <jwe@octave.org>
parents:
19743
diff
changeset
|
1462 YYUSE ($4); |
bf737d927707
eliminate bison warnings from oct-parse.yy
John W. Eaton <jwe@octave.org>
parents:
19743
diff
changeset
|
1463 |
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
|
1464 $$ = 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
|
1465 $1->column ()); |
16288
fe3b9a51e625
rename curr_lexer, curr_parser, CURR_LEXER
John W. Eaton <jwe@octave.org>
parents:
16287
diff
changeset
|
1466 parser.recover_from_parsing_function (); |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1467 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1468 ; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1469 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1470 fcn_name : identifier |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1471 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1472 std::string id_name = $1->name (); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1473 |
16288
fe3b9a51e625
rename curr_lexer, curr_parser, CURR_LEXER
John W. Eaton <jwe@octave.org>
parents:
16287
diff
changeset
|
1474 lexer.parsed_function_name.top () = true; |
fe3b9a51e625
rename curr_lexer, curr_parser, CURR_LEXER
John W. Eaton <jwe@octave.org>
parents:
16287
diff
changeset
|
1475 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
|
1476 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1477 $$ = $1; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1478 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1479 | GET '.' identifier |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1480 { |
19812
bf737d927707
eliminate bison warnings from oct-parse.yy
John W. Eaton <jwe@octave.org>
parents:
19743
diff
changeset
|
1481 YYUSE ($1); |
bf737d927707
eliminate bison warnings from oct-parse.yy
John W. Eaton <jwe@octave.org>
parents:
19743
diff
changeset
|
1482 |
16288
fe3b9a51e625
rename curr_lexer, curr_parser, CURR_LEXER
John W. Eaton <jwe@octave.org>
parents:
16287
diff
changeset
|
1483 lexer.parsed_function_name.top () = true; |
fe3b9a51e625
rename curr_lexer, curr_parser, CURR_LEXER
John W. Eaton <jwe@octave.org>
parents:
16287
diff
changeset
|
1484 lexer.maybe_classdef_get_set_method = false; |
16289
bde729ba8381
maint: periodic merge of default to classdef
John W. Eaton <jwe@octave.org>
diff
changeset
|
1485 lexer.parsing_classdef_get_method = true; |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1486 $$ = $3; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1487 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1488 | SET '.' identifier |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1489 { |
19812
bf737d927707
eliminate bison warnings from oct-parse.yy
John W. Eaton <jwe@octave.org>
parents:
19743
diff
changeset
|
1490 YYUSE ($1); |
bf737d927707
eliminate bison warnings from oct-parse.yy
John W. Eaton <jwe@octave.org>
parents:
19743
diff
changeset
|
1491 |
16288
fe3b9a51e625
rename curr_lexer, curr_parser, CURR_LEXER
John W. Eaton <jwe@octave.org>
parents:
16287
diff
changeset
|
1492 lexer.parsed_function_name.top () = true; |
fe3b9a51e625
rename curr_lexer, curr_parser, CURR_LEXER
John W. Eaton <jwe@octave.org>
parents:
16287
diff
changeset
|
1493 lexer.maybe_classdef_get_set_method = false; |
16289
bde729ba8381
maint: periodic merge of default to classdef
John W. Eaton <jwe@octave.org>
diff
changeset
|
1494 lexer.parsing_classdef_set_method = true; |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1495 $$ = $3; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1496 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1497 ; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1498 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1499 function1 : fcn_name function2 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1500 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1501 std::string fname = $1->name (); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1502 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1503 delete $1; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1504 |
16698
13b3b92ea99c
Implement property accessors.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
16683
diff
changeset
|
1505 if (lexer.parsing_classdef_get_method) |
13b3b92ea99c
Implement property accessors.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
16683
diff
changeset
|
1506 fname.insert (0, "get."); |
13b3b92ea99c
Implement property accessors.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
16683
diff
changeset
|
1507 else if (lexer.parsing_classdef_set_method) |
13b3b92ea99c
Implement property accessors.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
16683
diff
changeset
|
1508 fname.insert (0, "set."); |
13b3b92ea99c
Implement property accessors.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
16683
diff
changeset
|
1509 |
18395
2319bf776fa2
Fix parsing of classdef property accessors.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
18341
diff
changeset
|
1510 lexer.parsing_classdef_get_method = false; |
2319bf776fa2
Fix parsing of classdef property accessors.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
18341
diff
changeset
|
1511 lexer.parsing_classdef_set_method = false; |
2319bf776fa2
Fix parsing of classdef property accessors.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
18341
diff
changeset
|
1512 |
17632
bd0a84de3375
further reduce memory leaks from parse errors (bug #40231)
John W. Eaton <jwe@octave.org>
parents:
17629
diff
changeset
|
1513 $$ = parser.frob_function (fname, $2); |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1514 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1515 ; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1516 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1517 function2 : param_list opt_sep opt_list function_end |
19812
bf737d927707
eliminate bison warnings from oct-parse.yy
John W. Eaton <jwe@octave.org>
parents:
19743
diff
changeset
|
1518 { |
bf737d927707
eliminate bison warnings from oct-parse.yy
John W. Eaton <jwe@octave.org>
parents:
19743
diff
changeset
|
1519 YYUSE ($2); |
bf737d927707
eliminate bison warnings from oct-parse.yy
John W. Eaton <jwe@octave.org>
parents:
19743
diff
changeset
|
1520 |
bf737d927707
eliminate bison warnings from oct-parse.yy
John W. Eaton <jwe@octave.org>
parents:
19743
diff
changeset
|
1521 $$ = parser.start_function ($1, $3, $4); |
bf737d927707
eliminate bison warnings from oct-parse.yy
John W. Eaton <jwe@octave.org>
parents:
19743
diff
changeset
|
1522 } |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1523 | opt_sep opt_list function_end |
19812
bf737d927707
eliminate bison warnings from oct-parse.yy
John W. Eaton <jwe@octave.org>
parents:
19743
diff
changeset
|
1524 { |
bf737d927707
eliminate bison warnings from oct-parse.yy
John W. Eaton <jwe@octave.org>
parents:
19743
diff
changeset
|
1525 YYUSE ($1); |
bf737d927707
eliminate bison warnings from oct-parse.yy
John W. Eaton <jwe@octave.org>
parents:
19743
diff
changeset
|
1526 |
bf737d927707
eliminate bison warnings from oct-parse.yy
John W. Eaton <jwe@octave.org>
parents:
19743
diff
changeset
|
1527 $$ = parser.start_function (0, $2, $3); |
bf737d927707
eliminate bison warnings from oct-parse.yy
John W. Eaton <jwe@octave.org>
parents:
19743
diff
changeset
|
1528 } |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1529 ; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1530 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1531 function_end : END |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1532 { |
16288
fe3b9a51e625
rename curr_lexer, curr_parser, CURR_LEXER
John W. Eaton <jwe@octave.org>
parents:
16287
diff
changeset
|
1533 parser.endfunction_found = true; |
fe3b9a51e625
rename curr_lexer, curr_parser, CURR_LEXER
John W. Eaton <jwe@octave.org>
parents:
16287
diff
changeset
|
1534 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
|
1535 $$ = 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
|
1536 $1->line (), $1->column ()); |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1537 else |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1538 ABORT_PARSE; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1539 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1540 | END_OF_INPUT |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1541 { |
9474
25ed2d6aacf6
Parse nested functions more accurately.
David Grundberg <individ@acc.umu.se>
parents:
9471
diff
changeset
|
1542 // 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
|
1543 // if (lexer.reading_script_file) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1544 // { |
16288
fe3b9a51e625
rename curr_lexer, curr_parser, CURR_LEXER
John W. Eaton <jwe@octave.org>
parents:
16287
diff
changeset
|
1545 // 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
|
1546 // YYABORT; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1547 // } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1548 |
16288
fe3b9a51e625
rename curr_lexer, curr_parser, CURR_LEXER
John W. Eaton <jwe@octave.org>
parents:
16287
diff
changeset
|
1549 if (parser.endfunction_found) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1550 { |
16288
fe3b9a51e625
rename curr_lexer, curr_parser, CURR_LEXER
John W. Eaton <jwe@octave.org>
parents:
16287
diff
changeset
|
1551 parser.bison_error ("inconsistent function endings -- " |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1552 "if one function is explicitly ended, " |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1553 "so must all the others"); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1554 YYABORT; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1555 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1556 |
16288
fe3b9a51e625
rename curr_lexer, curr_parser, CURR_LEXER
John W. Eaton <jwe@octave.org>
parents:
16287
diff
changeset
|
1557 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
|
1558 || lexer.input_from_eval_string ())) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1559 { |
16288
fe3b9a51e625
rename curr_lexer, curr_parser, CURR_LEXER
John W. Eaton <jwe@octave.org>
parents:
16287
diff
changeset
|
1560 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
|
1561 YYABORT; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1562 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1563 |
16288
fe3b9a51e625
rename curr_lexer, curr_parser, CURR_LEXER
John W. Eaton <jwe@octave.org>
parents:
16287
diff
changeset
|
1564 if (lexer.reading_classdef_file) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1565 { |
16288
fe3b9a51e625
rename curr_lexer, curr_parser, CURR_LEXER
John W. Eaton <jwe@octave.org>
parents:
16287
diff
changeset
|
1566 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
|
1567 YYABORT; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1568 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1569 |
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
|
1570 $$ = 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
|
1571 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
|
1572 lexer.current_input_column); |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1573 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1574 ; |
2970 | 1575 |
9476 | 1576 // ======== |
1577 // Classdef | |
1578 // ======== | |
1579 | |
15037
56b8eb7c9c04
improvements in parsing classdef
John W. Eaton <jwe@octave.org>
parents:
14846
diff
changeset
|
1580 classdef_beg : CLASSDEF |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1581 { |
16289
bde729ba8381
maint: periodic merge of default to classdef
John W. Eaton <jwe@octave.org>
diff
changeset
|
1582 if (! lexer.reading_classdef_file) |
15037
56b8eb7c9c04
improvements in parsing classdef
John W. Eaton <jwe@octave.org>
parents:
14846
diff
changeset
|
1583 { |
16289
bde729ba8381
maint: periodic merge of default to classdef
John W. Eaton <jwe@octave.org>
diff
changeset
|
1584 parser.bison_error ("classdef must appear inside a file containing only a class definition"); |
15037
56b8eb7c9c04
improvements in parsing classdef
John W. Eaton <jwe@octave.org>
parents:
14846
diff
changeset
|
1585 YYABORT; |
56b8eb7c9c04
improvements in parsing classdef
John W. Eaton <jwe@octave.org>
parents:
14846
diff
changeset
|
1586 } |
56b8eb7c9c04
improvements in parsing classdef
John W. Eaton <jwe@octave.org>
parents:
14846
diff
changeset
|
1587 |
16288
fe3b9a51e625
rename curr_lexer, curr_parser, CURR_LEXER
John W. Eaton <jwe@octave.org>
parents:
16287
diff
changeset
|
1588 lexer.parsing_classdef = true; |
15037
56b8eb7c9c04
improvements in parsing classdef
John W. Eaton <jwe@octave.org>
parents:
14846
diff
changeset
|
1589 $$ = $1; |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1590 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1591 ; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1592 |
15037
56b8eb7c9c04
improvements in parsing classdef
John W. Eaton <jwe@octave.org>
parents:
14846
diff
changeset
|
1593 classdef : classdef_beg stash_comment opt_attr_list identifier opt_superclass_list opt_sep class_body opt_sep END |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1594 { |
19812
bf737d927707
eliminate bison warnings from oct-parse.yy
John W. Eaton <jwe@octave.org>
parents:
19743
diff
changeset
|
1595 YYUSE ($6); |
bf737d927707
eliminate bison warnings from oct-parse.yy
John W. Eaton <jwe@octave.org>
parents:
19743
diff
changeset
|
1596 YYUSE ($8); |
bf737d927707
eliminate bison warnings from oct-parse.yy
John W. Eaton <jwe@octave.org>
parents:
19743
diff
changeset
|
1597 |
16288
fe3b9a51e625
rename curr_lexer, curr_parser, CURR_LEXER
John W. Eaton <jwe@octave.org>
parents:
16287
diff
changeset
|
1598 lexer.parsing_classdef = false; |
fe3b9a51e625
rename curr_lexer, curr_parser, CURR_LEXER
John W. Eaton <jwe@octave.org>
parents:
16287
diff
changeset
|
1599 |
16289
bde729ba8381
maint: periodic merge of default to classdef
John W. Eaton <jwe@octave.org>
diff
changeset
|
1600 if (! ($$ = parser.make_classdef ($1, $3, $4, $5, $7, $9, $2))) |
17656
2b1047efc4fb
don't leak memory when parsing classdef objects fails
John W. Eaton <jwe@octave.org>
parents:
17654
diff
changeset
|
1601 { |
2b1047efc4fb
don't leak memory when parsing classdef objects fails
John W. Eaton <jwe@octave.org>
parents:
17654
diff
changeset
|
1602 // make_classdef deleted $3, $4, $5, and $7. |
2b1047efc4fb
don't leak memory when parsing classdef objects fails
John W. Eaton <jwe@octave.org>
parents:
17654
diff
changeset
|
1603 ABORT_PARSE; |
2b1047efc4fb
don't leak memory when parsing classdef objects fails
John W. Eaton <jwe@octave.org>
parents:
17654
diff
changeset
|
1604 } |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1605 } |
18419
9154dc252f47
Allow empty classdef or methods/properties/... blocks
Michael Goffioul <michael.goffioul@gmail.com>
parents:
18395
diff
changeset
|
1606 | classdef_beg stash_comment opt_attr_list identifier opt_superclass_list opt_sep END |
9154dc252f47
Allow empty classdef or methods/properties/... blocks
Michael Goffioul <michael.goffioul@gmail.com>
parents:
18395
diff
changeset
|
1607 { |
19812
bf737d927707
eliminate bison warnings from oct-parse.yy
John W. Eaton <jwe@octave.org>
parents:
19743
diff
changeset
|
1608 YYUSE ($6); |
bf737d927707
eliminate bison warnings from oct-parse.yy
John W. Eaton <jwe@octave.org>
parents:
19743
diff
changeset
|
1609 |
18419
9154dc252f47
Allow empty classdef or methods/properties/... blocks
Michael Goffioul <michael.goffioul@gmail.com>
parents:
18395
diff
changeset
|
1610 lexer.parsing_classdef = false; |
9154dc252f47
Allow empty classdef or methods/properties/... blocks
Michael Goffioul <michael.goffioul@gmail.com>
parents:
18395
diff
changeset
|
1611 |
9154dc252f47
Allow empty classdef or methods/properties/... blocks
Michael Goffioul <michael.goffioul@gmail.com>
parents:
18395
diff
changeset
|
1612 if (! ($$ = parser.make_classdef ($1, $3, $4, $5, 0, $7, $2))) |
9154dc252f47
Allow empty classdef or methods/properties/... blocks
Michael Goffioul <michael.goffioul@gmail.com>
parents:
18395
diff
changeset
|
1613 { |
9154dc252f47
Allow empty classdef or methods/properties/... blocks
Michael Goffioul <michael.goffioul@gmail.com>
parents:
18395
diff
changeset
|
1614 // make_classdef deleted $3, $4, and $5. |
9154dc252f47
Allow empty classdef or methods/properties/... blocks
Michael Goffioul <michael.goffioul@gmail.com>
parents:
18395
diff
changeset
|
1615 ABORT_PARSE; |
9154dc252f47
Allow empty classdef or methods/properties/... blocks
Michael Goffioul <michael.goffioul@gmail.com>
parents:
18395
diff
changeset
|
1616 } |
9154dc252f47
Allow empty classdef or methods/properties/... blocks
Michael Goffioul <michael.goffioul@gmail.com>
parents:
18395
diff
changeset
|
1617 } |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1618 ; |
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 opt_attr_list : // empty |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1621 { $$ = 0; } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1622 | '(' attr_list ')' |
15037
56b8eb7c9c04
improvements in parsing classdef
John W. Eaton <jwe@octave.org>
parents:
14846
diff
changeset
|
1623 { $$ = $2; } |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1624 ; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1625 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1626 attr_list : attr |
15037
56b8eb7c9c04
improvements in parsing classdef
John W. Eaton <jwe@octave.org>
parents:
14846
diff
changeset
|
1627 { $$ = new tree_classdef_attribute_list ($1); } |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1628 | attr_list ',' attr |
15037
56b8eb7c9c04
improvements in parsing classdef
John W. Eaton <jwe@octave.org>
parents:
14846
diff
changeset
|
1629 { |
56b8eb7c9c04
improvements in parsing classdef
John W. Eaton <jwe@octave.org>
parents:
14846
diff
changeset
|
1630 $1->append ($3); |
56b8eb7c9c04
improvements in parsing classdef
John W. Eaton <jwe@octave.org>
parents:
14846
diff
changeset
|
1631 $$ = $1; |
56b8eb7c9c04
improvements in parsing classdef
John W. Eaton <jwe@octave.org>
parents:
14846
diff
changeset
|
1632 } |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1633 ; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1634 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1635 attr : identifier |
15037
56b8eb7c9c04
improvements in parsing classdef
John W. Eaton <jwe@octave.org>
parents:
14846
diff
changeset
|
1636 { $$ = new tree_classdef_attribute ($1); } |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1637 | identifier '=' decl_param_init expression |
15037
56b8eb7c9c04
improvements in parsing classdef
John W. Eaton <jwe@octave.org>
parents:
14846
diff
changeset
|
1638 { |
19812
bf737d927707
eliminate bison warnings from oct-parse.yy
John W. Eaton <jwe@octave.org>
parents:
19743
diff
changeset
|
1639 YYUSE ($2); |
bf737d927707
eliminate bison warnings from oct-parse.yy
John W. Eaton <jwe@octave.org>
parents:
19743
diff
changeset
|
1640 |
16289
bde729ba8381
maint: periodic merge of default to classdef
John W. Eaton <jwe@octave.org>
diff
changeset
|
1641 lexer.looking_at_initializer_expression = false; |
15037
56b8eb7c9c04
improvements in parsing classdef
John W. Eaton <jwe@octave.org>
parents:
14846
diff
changeset
|
1642 $$ = new tree_classdef_attribute ($1, $4); |
56b8eb7c9c04
improvements in parsing classdef
John W. Eaton <jwe@octave.org>
parents:
14846
diff
changeset
|
1643 } |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1644 | EXPR_NOT identifier |
19812
bf737d927707
eliminate bison warnings from oct-parse.yy
John W. Eaton <jwe@octave.org>
parents:
19743
diff
changeset
|
1645 { |
bf737d927707
eliminate bison warnings from oct-parse.yy
John W. Eaton <jwe@octave.org>
parents:
19743
diff
changeset
|
1646 YYUSE ($1); |
bf737d927707
eliminate bison warnings from oct-parse.yy
John W. Eaton <jwe@octave.org>
parents:
19743
diff
changeset
|
1647 |
bf737d927707
eliminate bison warnings from oct-parse.yy
John W. Eaton <jwe@octave.org>
parents:
19743
diff
changeset
|
1648 $$ = new tree_classdef_attribute ($2, false); |
bf737d927707
eliminate bison warnings from oct-parse.yy
John W. Eaton <jwe@octave.org>
parents:
19743
diff
changeset
|
1649 } |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1650 ; |
9476 | 1651 |
15037
56b8eb7c9c04
improvements in parsing classdef
John W. Eaton <jwe@octave.org>
parents:
14846
diff
changeset
|
1652 opt_superclass_list |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1653 : // empty |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1654 { $$ = 0; } |
15037
56b8eb7c9c04
improvements in parsing classdef
John W. Eaton <jwe@octave.org>
parents:
14846
diff
changeset
|
1655 | superclass_list |
56b8eb7c9c04
improvements in parsing classdef
John W. Eaton <jwe@octave.org>
parents:
14846
diff
changeset
|
1656 { $$ = $1; } |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1657 ; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1658 |
18520
932aca9a7c57
Allow multi-level classdef package.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
18419
diff
changeset
|
1659 superclass_list : EXPR_LT |
19812
bf737d927707
eliminate bison warnings from oct-parse.yy
John W. Eaton <jwe@octave.org>
parents:
19743
diff
changeset
|
1660 { |
bf737d927707
eliminate bison warnings from oct-parse.yy
John W. Eaton <jwe@octave.org>
parents:
19743
diff
changeset
|
1661 YYUSE ($1); |
bf737d927707
eliminate bison warnings from oct-parse.yy
John W. Eaton <jwe@octave.org>
parents:
19743
diff
changeset
|
1662 |
bf737d927707
eliminate bison warnings from oct-parse.yy
John W. Eaton <jwe@octave.org>
parents:
19743
diff
changeset
|
1663 lexer.enable_fq_identifier (); |
bf737d927707
eliminate bison warnings from oct-parse.yy
John W. Eaton <jwe@octave.org>
parents:
19743
diff
changeset
|
1664 } |
18520
932aca9a7c57
Allow multi-level classdef package.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
18419
diff
changeset
|
1665 superclass |
932aca9a7c57
Allow multi-level classdef package.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
18419
diff
changeset
|
1666 { $$ = new tree_classdef_superclass_list ($3); } |
932aca9a7c57
Allow multi-level classdef package.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
18419
diff
changeset
|
1667 | superclass_list EXPR_AND |
19812
bf737d927707
eliminate bison warnings from oct-parse.yy
John W. Eaton <jwe@octave.org>
parents:
19743
diff
changeset
|
1668 { |
bf737d927707
eliminate bison warnings from oct-parse.yy
John W. Eaton <jwe@octave.org>
parents:
19743
diff
changeset
|
1669 YYUSE ($2); |
bf737d927707
eliminate bison warnings from oct-parse.yy
John W. Eaton <jwe@octave.org>
parents:
19743
diff
changeset
|
1670 |
bf737d927707
eliminate bison warnings from oct-parse.yy
John W. Eaton <jwe@octave.org>
parents:
19743
diff
changeset
|
1671 lexer.enable_fq_identifier (); |
bf737d927707
eliminate bison warnings from oct-parse.yy
John W. Eaton <jwe@octave.org>
parents:
19743
diff
changeset
|
1672 } |
18520
932aca9a7c57
Allow multi-level classdef package.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
18419
diff
changeset
|
1673 superclass |
15037
56b8eb7c9c04
improvements in parsing classdef
John W. Eaton <jwe@octave.org>
parents:
14846
diff
changeset
|
1674 { |
18520
932aca9a7c57
Allow multi-level classdef package.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
18419
diff
changeset
|
1675 $1->append ($4); |
15037
56b8eb7c9c04
improvements in parsing classdef
John W. Eaton <jwe@octave.org>
parents:
14846
diff
changeset
|
1676 $$ = $1; |
56b8eb7c9c04
improvements in parsing classdef
John W. Eaton <jwe@octave.org>
parents:
14846
diff
changeset
|
1677 } |
56b8eb7c9c04
improvements in parsing classdef
John W. Eaton <jwe@octave.org>
parents:
14846
diff
changeset
|
1678 ; |
56b8eb7c9c04
improvements in parsing classdef
John W. Eaton <jwe@octave.org>
parents:
14846
diff
changeset
|
1679 |
18520
932aca9a7c57
Allow multi-level classdef package.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
18419
diff
changeset
|
1680 superclass : FQ_IDENT |
932aca9a7c57
Allow multi-level classdef package.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
18419
diff
changeset
|
1681 { $$ = new tree_classdef_superclass ($1->text ()); } |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1682 ; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1683 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1684 class_body : properties_block |
15037
56b8eb7c9c04
improvements in parsing classdef
John W. Eaton <jwe@octave.org>
parents:
14846
diff
changeset
|
1685 { $$ = new tree_classdef_body ($1); } |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1686 | methods_block |
15037
56b8eb7c9c04
improvements in parsing classdef
John W. Eaton <jwe@octave.org>
parents:
14846
diff
changeset
|
1687 { $$ = new tree_classdef_body ($1); } |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1688 | events_block |
15037
56b8eb7c9c04
improvements in parsing classdef
John W. Eaton <jwe@octave.org>
parents:
14846
diff
changeset
|
1689 { $$ = new tree_classdef_body ($1); } |
13249
7861a5fd3479
accept enumeration keyword
John W. Eaton <jwe@octave.org>
parents:
13246
diff
changeset
|
1690 | enum_block |
15037
56b8eb7c9c04
improvements in parsing classdef
John W. Eaton <jwe@octave.org>
parents:
14846
diff
changeset
|
1691 { $$ = new tree_classdef_body ($1); } |
13250
f6bbdea030b2
use opt_sep instead of literal '\n' in parser rules for classdef
John W. Eaton <jwe@octave.org>
parents:
13249
diff
changeset
|
1692 | class_body opt_sep properties_block |
15037
56b8eb7c9c04
improvements in parsing classdef
John W. Eaton <jwe@octave.org>
parents:
14846
diff
changeset
|
1693 { |
19812
bf737d927707
eliminate bison warnings from oct-parse.yy
John W. Eaton <jwe@octave.org>
parents:
19743
diff
changeset
|
1694 YYUSE ($2); |
bf737d927707
eliminate bison warnings from oct-parse.yy
John W. Eaton <jwe@octave.org>
parents:
19743
diff
changeset
|
1695 |
15037
56b8eb7c9c04
improvements in parsing classdef
John W. Eaton <jwe@octave.org>
parents:
14846
diff
changeset
|
1696 $1->append ($3); |
56b8eb7c9c04
improvements in parsing classdef
John W. Eaton <jwe@octave.org>
parents:
14846
diff
changeset
|
1697 $$ = $1; |
56b8eb7c9c04
improvements in parsing classdef
John W. Eaton <jwe@octave.org>
parents:
14846
diff
changeset
|
1698 } |
13250
f6bbdea030b2
use opt_sep instead of literal '\n' in parser rules for classdef
John W. Eaton <jwe@octave.org>
parents:
13249
diff
changeset
|
1699 | class_body opt_sep methods_block |
15037
56b8eb7c9c04
improvements in parsing classdef
John W. Eaton <jwe@octave.org>
parents:
14846
diff
changeset
|
1700 { |
19812
bf737d927707
eliminate bison warnings from oct-parse.yy
John W. Eaton <jwe@octave.org>
parents:
19743
diff
changeset
|
1701 YYUSE ($2); |
bf737d927707
eliminate bison warnings from oct-parse.yy
John W. Eaton <jwe@octave.org>
parents:
19743
diff
changeset
|
1702 |
15037
56b8eb7c9c04
improvements in parsing classdef
John W. Eaton <jwe@octave.org>
parents:
14846
diff
changeset
|
1703 $1->append ($3); |
56b8eb7c9c04
improvements in parsing classdef
John W. Eaton <jwe@octave.org>
parents:
14846
diff
changeset
|
1704 $$ = $1; |
56b8eb7c9c04
improvements in parsing classdef
John W. Eaton <jwe@octave.org>
parents:
14846
diff
changeset
|
1705 } |
13250
f6bbdea030b2
use opt_sep instead of literal '\n' in parser rules for classdef
John W. Eaton <jwe@octave.org>
parents:
13249
diff
changeset
|
1706 | class_body opt_sep events_block |
15037
56b8eb7c9c04
improvements in parsing classdef
John W. Eaton <jwe@octave.org>
parents:
14846
diff
changeset
|
1707 { |
19812
bf737d927707
eliminate bison warnings from oct-parse.yy
John W. Eaton <jwe@octave.org>
parents:
19743
diff
changeset
|
1708 YYUSE ($2); |
bf737d927707
eliminate bison warnings from oct-parse.yy
John W. Eaton <jwe@octave.org>
parents:
19743
diff
changeset
|
1709 |
15037
56b8eb7c9c04
improvements in parsing classdef
John W. Eaton <jwe@octave.org>
parents:
14846
diff
changeset
|
1710 $1->append ($3); |
56b8eb7c9c04
improvements in parsing classdef
John W. Eaton <jwe@octave.org>
parents:
14846
diff
changeset
|
1711 $$ = $1; |
56b8eb7c9c04
improvements in parsing classdef
John W. Eaton <jwe@octave.org>
parents:
14846
diff
changeset
|
1712 } |
13250
f6bbdea030b2
use opt_sep instead of literal '\n' in parser rules for classdef
John W. Eaton <jwe@octave.org>
parents:
13249
diff
changeset
|
1713 | class_body opt_sep enum_block |
15037
56b8eb7c9c04
improvements in parsing classdef
John W. Eaton <jwe@octave.org>
parents:
14846
diff
changeset
|
1714 { |
19812
bf737d927707
eliminate bison warnings from oct-parse.yy
John W. Eaton <jwe@octave.org>
parents:
19743
diff
changeset
|
1715 YYUSE ($2); |
bf737d927707
eliminate bison warnings from oct-parse.yy
John W. Eaton <jwe@octave.org>
parents:
19743
diff
changeset
|
1716 |
15037
56b8eb7c9c04
improvements in parsing classdef
John W. Eaton <jwe@octave.org>
parents:
14846
diff
changeset
|
1717 $1->append ($3); |
56b8eb7c9c04
improvements in parsing classdef
John W. Eaton <jwe@octave.org>
parents:
14846
diff
changeset
|
1718 $$ = $1; |
56b8eb7c9c04
improvements in parsing classdef
John W. Eaton <jwe@octave.org>
parents:
14846
diff
changeset
|
1719 } |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1720 ; |
9476 | 1721 |
1722 properties_block | |
15037
56b8eb7c9c04
improvements in parsing classdef
John W. Eaton <jwe@octave.org>
parents:
14846
diff
changeset
|
1723 : PROPERTIES stash_comment opt_attr_list opt_sep property_list opt_sep END |
56b8eb7c9c04
improvements in parsing classdef
John W. Eaton <jwe@octave.org>
parents:
14846
diff
changeset
|
1724 { |
19812
bf737d927707
eliminate bison warnings from oct-parse.yy
John W. Eaton <jwe@octave.org>
parents:
19743
diff
changeset
|
1725 YYUSE ($4); |
bf737d927707
eliminate bison warnings from oct-parse.yy
John W. Eaton <jwe@octave.org>
parents:
19743
diff
changeset
|
1726 YYUSE ($6); |
bf737d927707
eliminate bison warnings from oct-parse.yy
John W. Eaton <jwe@octave.org>
parents:
19743
diff
changeset
|
1727 |
16289
bde729ba8381
maint: periodic merge of default to classdef
John W. Eaton <jwe@octave.org>
diff
changeset
|
1728 if (! ($$ = parser.make_classdef_properties_block |
17656
2b1047efc4fb
don't leak memory when parsing classdef objects fails
John W. Eaton <jwe@octave.org>
parents:
17654
diff
changeset
|
1729 ($1, $3, $5, $7, $2))) |
2b1047efc4fb
don't leak memory when parsing classdef objects fails
John W. Eaton <jwe@octave.org>
parents:
17654
diff
changeset
|
1730 { |
2b1047efc4fb
don't leak memory when parsing classdef objects fails
John W. Eaton <jwe@octave.org>
parents:
17654
diff
changeset
|
1731 // make_classdef_properties_block delete $3 and $5. |
2b1047efc4fb
don't leak memory when parsing classdef objects fails
John W. Eaton <jwe@octave.org>
parents:
17654
diff
changeset
|
1732 ABORT_PARSE; |
2b1047efc4fb
don't leak memory when parsing classdef objects fails
John W. Eaton <jwe@octave.org>
parents:
17654
diff
changeset
|
1733 } |
15037
56b8eb7c9c04
improvements in parsing classdef
John W. Eaton <jwe@octave.org>
parents:
14846
diff
changeset
|
1734 } |
18419
9154dc252f47
Allow empty classdef or methods/properties/... blocks
Michael Goffioul <michael.goffioul@gmail.com>
parents:
18395
diff
changeset
|
1735 | PROPERTIES stash_comment opt_attr_list opt_sep END |
9154dc252f47
Allow empty classdef or methods/properties/... blocks
Michael Goffioul <michael.goffioul@gmail.com>
parents:
18395
diff
changeset
|
1736 { |
19812
bf737d927707
eliminate bison warnings from oct-parse.yy
John W. Eaton <jwe@octave.org>
parents:
19743
diff
changeset
|
1737 YYUSE ($4); |
bf737d927707
eliminate bison warnings from oct-parse.yy
John W. Eaton <jwe@octave.org>
parents:
19743
diff
changeset
|
1738 |
18419
9154dc252f47
Allow empty classdef or methods/properties/... blocks
Michael Goffioul <michael.goffioul@gmail.com>
parents:
18395
diff
changeset
|
1739 if (! ($$ = parser.make_classdef_properties_block |
9154dc252f47
Allow empty classdef or methods/properties/... blocks
Michael Goffioul <michael.goffioul@gmail.com>
parents:
18395
diff
changeset
|
1740 ($1, $3, 0, $5, $2))) |
9154dc252f47
Allow empty classdef or methods/properties/... blocks
Michael Goffioul <michael.goffioul@gmail.com>
parents:
18395
diff
changeset
|
1741 { |
9154dc252f47
Allow empty classdef or methods/properties/... blocks
Michael Goffioul <michael.goffioul@gmail.com>
parents:
18395
diff
changeset
|
1742 // make_classdef_properties_block delete $3. |
9154dc252f47
Allow empty classdef or methods/properties/... blocks
Michael Goffioul <michael.goffioul@gmail.com>
parents:
18395
diff
changeset
|
1743 ABORT_PARSE; |
9154dc252f47
Allow empty classdef or methods/properties/... blocks
Michael Goffioul <michael.goffioul@gmail.com>
parents:
18395
diff
changeset
|
1744 } |
9154dc252f47
Allow empty classdef or methods/properties/... blocks
Michael Goffioul <michael.goffioul@gmail.com>
parents:
18395
diff
changeset
|
1745 } |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1746 ; |
9476 | 1747 |
15037
56b8eb7c9c04
improvements in parsing classdef
John W. Eaton <jwe@octave.org>
parents:
14846
diff
changeset
|
1748 property_list |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1749 : class_property |
15037
56b8eb7c9c04
improvements in parsing classdef
John W. Eaton <jwe@octave.org>
parents:
14846
diff
changeset
|
1750 { $$ = new tree_classdef_property_list ($1); } |
56b8eb7c9c04
improvements in parsing classdef
John W. Eaton <jwe@octave.org>
parents:
14846
diff
changeset
|
1751 | property_list opt_sep class_property |
56b8eb7c9c04
improvements in parsing classdef
John W. Eaton <jwe@octave.org>
parents:
14846
diff
changeset
|
1752 { |
19812
bf737d927707
eliminate bison warnings from oct-parse.yy
John W. Eaton <jwe@octave.org>
parents:
19743
diff
changeset
|
1753 YYUSE ($2); |
bf737d927707
eliminate bison warnings from oct-parse.yy
John W. Eaton <jwe@octave.org>
parents:
19743
diff
changeset
|
1754 |
15037
56b8eb7c9c04
improvements in parsing classdef
John W. Eaton <jwe@octave.org>
parents:
14846
diff
changeset
|
1755 $1->append ($3); |
56b8eb7c9c04
improvements in parsing classdef
John W. Eaton <jwe@octave.org>
parents:
14846
diff
changeset
|
1756 $$ = $1; |
56b8eb7c9c04
improvements in parsing classdef
John W. Eaton <jwe@octave.org>
parents:
14846
diff
changeset
|
1757 } |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1758 ; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1759 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1760 class_property : identifier |
15037
56b8eb7c9c04
improvements in parsing classdef
John W. Eaton <jwe@octave.org>
parents:
14846
diff
changeset
|
1761 { $$ = new tree_classdef_property ($1); } |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1762 | identifier '=' decl_param_init expression ';' |
15037
56b8eb7c9c04
improvements in parsing classdef
John W. Eaton <jwe@octave.org>
parents:
14846
diff
changeset
|
1763 { |
19812
bf737d927707
eliminate bison warnings from oct-parse.yy
John W. Eaton <jwe@octave.org>
parents:
19743
diff
changeset
|
1764 YYUSE ($2); |
bf737d927707
eliminate bison warnings from oct-parse.yy
John W. Eaton <jwe@octave.org>
parents:
19743
diff
changeset
|
1765 |
16289
bde729ba8381
maint: periodic merge of default to classdef
John W. Eaton <jwe@octave.org>
diff
changeset
|
1766 lexer.looking_at_initializer_expression = false; |
15037
56b8eb7c9c04
improvements in parsing classdef
John W. Eaton <jwe@octave.org>
parents:
14846
diff
changeset
|
1767 $$ = new tree_classdef_property ($1, $4); |
56b8eb7c9c04
improvements in parsing classdef
John W. Eaton <jwe@octave.org>
parents:
14846
diff
changeset
|
1768 } |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1769 ; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1770 |
15037
56b8eb7c9c04
improvements in parsing classdef
John W. Eaton <jwe@octave.org>
parents:
14846
diff
changeset
|
1771 methods_block : METHODS stash_comment opt_attr_list opt_sep methods_list opt_sep END |
56b8eb7c9c04
improvements in parsing classdef
John W. Eaton <jwe@octave.org>
parents:
14846
diff
changeset
|
1772 { |
19812
bf737d927707
eliminate bison warnings from oct-parse.yy
John W. Eaton <jwe@octave.org>
parents:
19743
diff
changeset
|
1773 YYUSE ($4); |
bf737d927707
eliminate bison warnings from oct-parse.yy
John W. Eaton <jwe@octave.org>
parents:
19743
diff
changeset
|
1774 YYUSE ($6); |
bf737d927707
eliminate bison warnings from oct-parse.yy
John W. Eaton <jwe@octave.org>
parents:
19743
diff
changeset
|
1775 |
16289
bde729ba8381
maint: periodic merge of default to classdef
John W. Eaton <jwe@octave.org>
diff
changeset
|
1776 if (! ($$ = parser.make_classdef_methods_block |
17656
2b1047efc4fb
don't leak memory when parsing classdef objects fails
John W. Eaton <jwe@octave.org>
parents:
17654
diff
changeset
|
1777 ($1, $3, $5, $7, $2))) |
2b1047efc4fb
don't leak memory when parsing classdef objects fails
John W. Eaton <jwe@octave.org>
parents:
17654
diff
changeset
|
1778 { |
2b1047efc4fb
don't leak memory when parsing classdef objects fails
John W. Eaton <jwe@octave.org>
parents:
17654
diff
changeset
|
1779 // make_classdef_methods_block deleted $3 and $5. |
2b1047efc4fb
don't leak memory when parsing classdef objects fails
John W. Eaton <jwe@octave.org>
parents:
17654
diff
changeset
|
1780 ABORT_PARSE; |
2b1047efc4fb
don't leak memory when parsing classdef objects fails
John W. Eaton <jwe@octave.org>
parents:
17654
diff
changeset
|
1781 } |
15037
56b8eb7c9c04
improvements in parsing classdef
John W. Eaton <jwe@octave.org>
parents:
14846
diff
changeset
|
1782 } |
18419
9154dc252f47
Allow empty classdef or methods/properties/... blocks
Michael Goffioul <michael.goffioul@gmail.com>
parents:
18395
diff
changeset
|
1783 | METHODS stash_comment opt_attr_list opt_sep END |
9154dc252f47
Allow empty classdef or methods/properties/... blocks
Michael Goffioul <michael.goffioul@gmail.com>
parents:
18395
diff
changeset
|
1784 { |
19812
bf737d927707
eliminate bison warnings from oct-parse.yy
John W. Eaton <jwe@octave.org>
parents:
19743
diff
changeset
|
1785 YYUSE ($4); |
bf737d927707
eliminate bison warnings from oct-parse.yy
John W. Eaton <jwe@octave.org>
parents:
19743
diff
changeset
|
1786 |
18419
9154dc252f47
Allow empty classdef or methods/properties/... blocks
Michael Goffioul <michael.goffioul@gmail.com>
parents:
18395
diff
changeset
|
1787 if (! ($$ = parser.make_classdef_methods_block |
9154dc252f47
Allow empty classdef or methods/properties/... blocks
Michael Goffioul <michael.goffioul@gmail.com>
parents:
18395
diff
changeset
|
1788 ($1, $3, 0, $5, $2))) |
9154dc252f47
Allow empty classdef or methods/properties/... blocks
Michael Goffioul <michael.goffioul@gmail.com>
parents:
18395
diff
changeset
|
1789 { |
9154dc252f47
Allow empty classdef or methods/properties/... blocks
Michael Goffioul <michael.goffioul@gmail.com>
parents:
18395
diff
changeset
|
1790 // make_classdef_methods_block deleted $3. |
9154dc252f47
Allow empty classdef or methods/properties/... blocks
Michael Goffioul <michael.goffioul@gmail.com>
parents:
18395
diff
changeset
|
1791 ABORT_PARSE; |
9154dc252f47
Allow empty classdef or methods/properties/... blocks
Michael Goffioul <michael.goffioul@gmail.com>
parents:
18395
diff
changeset
|
1792 } |
9154dc252f47
Allow empty classdef or methods/properties/... blocks
Michael Goffioul <michael.goffioul@gmail.com>
parents:
18395
diff
changeset
|
1793 } |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1794 ; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1795 ; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1796 |
18262
69990d5edcc2
Allow to parse external methods declaration in classdef files.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
18157
diff
changeset
|
1797 method_decl1 : identifier |
18308
c1baf94184af
* oct-parse.in.yy: Suppress TAB characters.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
18304
diff
changeset
|
1798 { |
18262
69990d5edcc2
Allow to parse external methods declaration in classdef files.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
18157
diff
changeset
|
1799 if (! ($$ = parser.start_classdef_external_method ($1, 0))) |
69990d5edcc2
Allow to parse external methods declaration in classdef files.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
18157
diff
changeset
|
1800 ABORT_PARSE; |
69990d5edcc2
Allow to parse external methods declaration in classdef files.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
18157
diff
changeset
|
1801 } |
18308
c1baf94184af
* oct-parse.in.yy: Suppress TAB characters.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
18304
diff
changeset
|
1802 | identifier param_list |
18341
02b349ccf0ec
Allow "end" method declaration/definition in classde files.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
18308
diff
changeset
|
1803 { |
02b349ccf0ec
Allow "end" method declaration/definition in classde files.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
18308
diff
changeset
|
1804 if (! ($$ = parser.start_classdef_external_method ($1, $2))) |
18262
69990d5edcc2
Allow to parse external methods declaration in classdef files.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
18157
diff
changeset
|
1805 ABORT_PARSE; |
69990d5edcc2
Allow to parse external methods declaration in classdef files.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
18157
diff
changeset
|
1806 } |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1807 ; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1808 |
18262
69990d5edcc2
Allow to parse external methods declaration in classdef files.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
18157
diff
changeset
|
1809 method_decl : stash_comment method_decl1 |
18308
c1baf94184af
* oct-parse.in.yy: Suppress TAB characters.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
18304
diff
changeset
|
1810 { $$ = parser.finish_classdef_external_method ($2, 0, $1); } |
18341
02b349ccf0ec
Allow "end" method declaration/definition in classde files.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
18308
diff
changeset
|
1811 | stash_comment return_list '=' |
02b349ccf0ec
Allow "end" method declaration/definition in classde files.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
18308
diff
changeset
|
1812 { |
19812
bf737d927707
eliminate bison warnings from oct-parse.yy
John W. Eaton <jwe@octave.org>
parents:
19743
diff
changeset
|
1813 YYUSE ($3); |
bf737d927707
eliminate bison warnings from oct-parse.yy
John W. Eaton <jwe@octave.org>
parents:
19743
diff
changeset
|
1814 |
18341
02b349ccf0ec
Allow "end" method declaration/definition in classde files.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
18308
diff
changeset
|
1815 lexer.defining_func++; |
02b349ccf0ec
Allow "end" method declaration/definition in classde files.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
18308
diff
changeset
|
1816 lexer.parsed_function_name.push (false); |
02b349ccf0ec
Allow "end" method declaration/definition in classde files.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
18308
diff
changeset
|
1817 } |
02b349ccf0ec
Allow "end" method declaration/definition in classde files.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
18308
diff
changeset
|
1818 method_decl1 |
02b349ccf0ec
Allow "end" method declaration/definition in classde files.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
18308
diff
changeset
|
1819 { |
02b349ccf0ec
Allow "end" method declaration/definition in classde files.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
18308
diff
changeset
|
1820 lexer.defining_func--; |
02b349ccf0ec
Allow "end" method declaration/definition in classde files.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
18308
diff
changeset
|
1821 lexer.parsed_function_name.pop (); |
02b349ccf0ec
Allow "end" method declaration/definition in classde files.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
18308
diff
changeset
|
1822 $$ = parser.finish_classdef_external_method ($5, $2, $1); |
02b349ccf0ec
Allow "end" method declaration/definition in classde files.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
18308
diff
changeset
|
1823 } |
18262
69990d5edcc2
Allow to parse external methods declaration in classdef files.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
18157
diff
changeset
|
1824 ; |
69990d5edcc2
Allow to parse external methods declaration in classdef files.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
18157
diff
changeset
|
1825 |
69990d5edcc2
Allow to parse external methods declaration in classdef files.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
18157
diff
changeset
|
1826 method : method_decl |
18308
c1baf94184af
* oct-parse.in.yy: Suppress TAB characters.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
18304
diff
changeset
|
1827 { $$ = $1; } |
c1baf94184af
* oct-parse.in.yy: Suppress TAB characters.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
18304
diff
changeset
|
1828 | function |
18262
69990d5edcc2
Allow to parse external methods declaration in classdef files.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
18157
diff
changeset
|
1829 { $$ = $1; } |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1830 ; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1831 |
18262
69990d5edcc2
Allow to parse external methods declaration in classdef files.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
18157
diff
changeset
|
1832 methods_list : method |
15037
56b8eb7c9c04
improvements in parsing classdef
John W. Eaton <jwe@octave.org>
parents:
14846
diff
changeset
|
1833 { |
56b8eb7c9c04
improvements in parsing classdef
John W. Eaton <jwe@octave.org>
parents:
14846
diff
changeset
|
1834 octave_value fcn; |
56b8eb7c9c04
improvements in parsing classdef
John W. Eaton <jwe@octave.org>
parents:
14846
diff
changeset
|
1835 if ($1) |
56b8eb7c9c04
improvements in parsing classdef
John W. Eaton <jwe@octave.org>
parents:
14846
diff
changeset
|
1836 fcn = $1->function (); |
56b8eb7c9c04
improvements in parsing classdef
John W. Eaton <jwe@octave.org>
parents:
14846
diff
changeset
|
1837 delete $1; |
56b8eb7c9c04
improvements in parsing classdef
John W. Eaton <jwe@octave.org>
parents:
14846
diff
changeset
|
1838 $$ = new tree_classdef_methods_list (fcn); |
56b8eb7c9c04
improvements in parsing classdef
John W. Eaton <jwe@octave.org>
parents:
14846
diff
changeset
|
1839 } |
18262
69990d5edcc2
Allow to parse external methods declaration in classdef files.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
18157
diff
changeset
|
1840 | methods_list opt_sep method |
15037
56b8eb7c9c04
improvements in parsing classdef
John W. Eaton <jwe@octave.org>
parents:
14846
diff
changeset
|
1841 { |
19812
bf737d927707
eliminate bison warnings from oct-parse.yy
John W. Eaton <jwe@octave.org>
parents:
19743
diff
changeset
|
1842 YYUSE ($2); |
bf737d927707
eliminate bison warnings from oct-parse.yy
John W. Eaton <jwe@octave.org>
parents:
19743
diff
changeset
|
1843 |
15037
56b8eb7c9c04
improvements in parsing classdef
John W. Eaton <jwe@octave.org>
parents:
14846
diff
changeset
|
1844 octave_value fcn; |
56b8eb7c9c04
improvements in parsing classdef
John W. Eaton <jwe@octave.org>
parents:
14846
diff
changeset
|
1845 if ($3) |
56b8eb7c9c04
improvements in parsing classdef
John W. Eaton <jwe@octave.org>
parents:
14846
diff
changeset
|
1846 fcn = $3->function (); |
56b8eb7c9c04
improvements in parsing classdef
John W. Eaton <jwe@octave.org>
parents:
14846
diff
changeset
|
1847 delete $3; |
56b8eb7c9c04
improvements in parsing classdef
John W. Eaton <jwe@octave.org>
parents:
14846
diff
changeset
|
1848 |
56b8eb7c9c04
improvements in parsing classdef
John W. Eaton <jwe@octave.org>
parents:
14846
diff
changeset
|
1849 $1->append (fcn); |
56b8eb7c9c04
improvements in parsing classdef
John W. Eaton <jwe@octave.org>
parents:
14846
diff
changeset
|
1850 $$ = $1; |
56b8eb7c9c04
improvements in parsing classdef
John W. Eaton <jwe@octave.org>
parents:
14846
diff
changeset
|
1851 } |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1852 ; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1853 |
15037
56b8eb7c9c04
improvements in parsing classdef
John W. Eaton <jwe@octave.org>
parents:
14846
diff
changeset
|
1854 events_block : EVENTS stash_comment opt_attr_list opt_sep events_list opt_sep END |
56b8eb7c9c04
improvements in parsing classdef
John W. Eaton <jwe@octave.org>
parents:
14846
diff
changeset
|
1855 { |
19812
bf737d927707
eliminate bison warnings from oct-parse.yy
John W. Eaton <jwe@octave.org>
parents:
19743
diff
changeset
|
1856 YYUSE ($4); |
bf737d927707
eliminate bison warnings from oct-parse.yy
John W. Eaton <jwe@octave.org>
parents:
19743
diff
changeset
|
1857 YYUSE ($6); |
bf737d927707
eliminate bison warnings from oct-parse.yy
John W. Eaton <jwe@octave.org>
parents:
19743
diff
changeset
|
1858 |
16289
bde729ba8381
maint: periodic merge of default to classdef
John W. Eaton <jwe@octave.org>
diff
changeset
|
1859 if (! ($$ = parser.make_classdef_events_block |
17656
2b1047efc4fb
don't leak memory when parsing classdef objects fails
John W. Eaton <jwe@octave.org>
parents:
17654
diff
changeset
|
1860 ($1, $3, $5, $7, $2))) |
2b1047efc4fb
don't leak memory when parsing classdef objects fails
John W. Eaton <jwe@octave.org>
parents:
17654
diff
changeset
|
1861 { |
2b1047efc4fb
don't leak memory when parsing classdef objects fails
John W. Eaton <jwe@octave.org>
parents:
17654
diff
changeset
|
1862 // make_classdef_events_block deleted $3 and $5. |
2b1047efc4fb
don't leak memory when parsing classdef objects fails
John W. Eaton <jwe@octave.org>
parents:
17654
diff
changeset
|
1863 ABORT_PARSE; |
2b1047efc4fb
don't leak memory when parsing classdef objects fails
John W. Eaton <jwe@octave.org>
parents:
17654
diff
changeset
|
1864 } |
15037
56b8eb7c9c04
improvements in parsing classdef
John W. Eaton <jwe@octave.org>
parents:
14846
diff
changeset
|
1865 } |
18419
9154dc252f47
Allow empty classdef or methods/properties/... blocks
Michael Goffioul <michael.goffioul@gmail.com>
parents:
18395
diff
changeset
|
1866 | EVENTS stash_comment opt_attr_list opt_sep END |
9154dc252f47
Allow empty classdef or methods/properties/... blocks
Michael Goffioul <michael.goffioul@gmail.com>
parents:
18395
diff
changeset
|
1867 { |
19812
bf737d927707
eliminate bison warnings from oct-parse.yy
John W. Eaton <jwe@octave.org>
parents:
19743
diff
changeset
|
1868 YYUSE ($4); |
bf737d927707
eliminate bison warnings from oct-parse.yy
John W. Eaton <jwe@octave.org>
parents:
19743
diff
changeset
|
1869 |
18419
9154dc252f47
Allow empty classdef or methods/properties/... blocks
Michael Goffioul <michael.goffioul@gmail.com>
parents:
18395
diff
changeset
|
1870 if (! ($$ = parser.make_classdef_events_block |
9154dc252f47
Allow empty classdef or methods/properties/... blocks
Michael Goffioul <michael.goffioul@gmail.com>
parents:
18395
diff
changeset
|
1871 ($1, $3, 0, $5, $2))) |
9154dc252f47
Allow empty classdef or methods/properties/... blocks
Michael Goffioul <michael.goffioul@gmail.com>
parents:
18395
diff
changeset
|
1872 { |
9154dc252f47
Allow empty classdef or methods/properties/... blocks
Michael Goffioul <michael.goffioul@gmail.com>
parents:
18395
diff
changeset
|
1873 // make_classdef_events_block deleted $3. |
9154dc252f47
Allow empty classdef or methods/properties/... blocks
Michael Goffioul <michael.goffioul@gmail.com>
parents:
18395
diff
changeset
|
1874 ABORT_PARSE; |
9154dc252f47
Allow empty classdef or methods/properties/... blocks
Michael Goffioul <michael.goffioul@gmail.com>
parents:
18395
diff
changeset
|
1875 } |
9154dc252f47
Allow empty classdef or methods/properties/... blocks
Michael Goffioul <michael.goffioul@gmail.com>
parents:
18395
diff
changeset
|
1876 } |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1877 ; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1878 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1879 events_list : class_event |
15037
56b8eb7c9c04
improvements in parsing classdef
John W. Eaton <jwe@octave.org>
parents:
14846
diff
changeset
|
1880 { $$ = new tree_classdef_events_list ($1); } |
13250
f6bbdea030b2
use opt_sep instead of literal '\n' in parser rules for classdef
John W. Eaton <jwe@octave.org>
parents:
13249
diff
changeset
|
1881 | events_list opt_sep class_event |
15037
56b8eb7c9c04
improvements in parsing classdef
John W. Eaton <jwe@octave.org>
parents:
14846
diff
changeset
|
1882 { |
19812
bf737d927707
eliminate bison warnings from oct-parse.yy
John W. Eaton <jwe@octave.org>
parents:
19743
diff
changeset
|
1883 YYUSE ($2); |
bf737d927707
eliminate bison warnings from oct-parse.yy
John W. Eaton <jwe@octave.org>
parents:
19743
diff
changeset
|
1884 |
15037
56b8eb7c9c04
improvements in parsing classdef
John W. Eaton <jwe@octave.org>
parents:
14846
diff
changeset
|
1885 $1->append ($3); |
56b8eb7c9c04
improvements in parsing classdef
John W. Eaton <jwe@octave.org>
parents:
14846
diff
changeset
|
1886 $$ = $1; |
56b8eb7c9c04
improvements in parsing classdef
John W. Eaton <jwe@octave.org>
parents:
14846
diff
changeset
|
1887 } |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1888 ; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1889 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1890 class_event : identifier |
15037
56b8eb7c9c04
improvements in parsing classdef
John W. Eaton <jwe@octave.org>
parents:
14846
diff
changeset
|
1891 { $$ = new tree_classdef_event ($1); } |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1892 ; |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11572
diff
changeset
|
1893 |
15037
56b8eb7c9c04
improvements in parsing classdef
John W. Eaton <jwe@octave.org>
parents:
14846
diff
changeset
|
1894 enum_block : ENUMERATION stash_comment opt_attr_list opt_sep enum_list opt_sep END |
56b8eb7c9c04
improvements in parsing classdef
John W. Eaton <jwe@octave.org>
parents:
14846
diff
changeset
|
1895 { |
19812
bf737d927707
eliminate bison warnings from oct-parse.yy
John W. Eaton <jwe@octave.org>
parents:
19743
diff
changeset
|
1896 YYUSE ($4); |
bf737d927707
eliminate bison warnings from oct-parse.yy
John W. Eaton <jwe@octave.org>
parents:
19743
diff
changeset
|
1897 YYUSE ($6); |
bf737d927707
eliminate bison warnings from oct-parse.yy
John W. Eaton <jwe@octave.org>
parents:
19743
diff
changeset
|
1898 |
16289
bde729ba8381
maint: periodic merge of default to classdef
John W. Eaton <jwe@octave.org>
diff
changeset
|
1899 if (! ($$ = parser.make_classdef_enum_block |
17656
2b1047efc4fb
don't leak memory when parsing classdef objects fails
John W. Eaton <jwe@octave.org>
parents:
17654
diff
changeset
|
1900 ($1, $3, $5, $7, $2))) |
2b1047efc4fb
don't leak memory when parsing classdef objects fails
John W. Eaton <jwe@octave.org>
parents:
17654
diff
changeset
|
1901 { |
2b1047efc4fb
don't leak memory when parsing classdef objects fails
John W. Eaton <jwe@octave.org>
parents:
17654
diff
changeset
|
1902 // make_classdef_enum_block deleted $3 and $5. |
2b1047efc4fb
don't leak memory when parsing classdef objects fails
John W. Eaton <jwe@octave.org>
parents:
17654
diff
changeset
|
1903 ABORT_PARSE; |
2b1047efc4fb
don't leak memory when parsing classdef objects fails
John W. Eaton <jwe@octave.org>
parents:
17654
diff
changeset
|
1904 } |
15037
56b8eb7c9c04
improvements in parsing classdef
John W. Eaton <jwe@octave.org>
parents:
14846
diff
changeset
|
1905 } |
18419
9154dc252f47
Allow empty classdef or methods/properties/... blocks
Michael Goffioul <michael.goffioul@gmail.com>
parents:
18395
diff
changeset
|
1906 | ENUMERATION stash_comment opt_attr_list opt_sep END |
9154dc252f47
Allow empty classdef or methods/properties/... blocks
Michael Goffioul <michael.goffioul@gmail.com>
parents:
18395
diff
changeset
|
1907 { |
19812
bf737d927707
eliminate bison warnings from oct-parse.yy
John W. Eaton <jwe@octave.org>
parents:
19743
diff
changeset
|
1908 YYUSE ($4); |
bf737d927707
eliminate bison warnings from oct-parse.yy
John W. Eaton <jwe@octave.org>
parents:
19743
diff
changeset
|
1909 |
18419
9154dc252f47
Allow empty classdef or methods/properties/... blocks
Michael Goffioul <michael.goffioul@gmail.com>
parents:
18395
diff
changeset
|
1910 if (! ($$ = parser.make_classdef_enum_block |
9154dc252f47
Allow empty classdef or methods/properties/... blocks
Michael Goffioul <michael.goffioul@gmail.com>
parents:
18395
diff
changeset
|
1911 ($1, $3, 0, $5, $2))) |
9154dc252f47
Allow empty classdef or methods/properties/... blocks
Michael Goffioul <michael.goffioul@gmail.com>
parents:
18395
diff
changeset
|
1912 { |
9154dc252f47
Allow empty classdef or methods/properties/... blocks
Michael Goffioul <michael.goffioul@gmail.com>
parents:
18395
diff
changeset
|
1913 // make_classdef_enum_block deleted $3. |
9154dc252f47
Allow empty classdef or methods/properties/... blocks
Michael Goffioul <michael.goffioul@gmail.com>
parents:
18395
diff
changeset
|
1914 ABORT_PARSE; |
9154dc252f47
Allow empty classdef or methods/properties/... blocks
Michael Goffioul <michael.goffioul@gmail.com>
parents:
18395
diff
changeset
|
1915 } |
9154dc252f47
Allow empty classdef or methods/properties/... blocks
Michael Goffioul <michael.goffioul@gmail.com>
parents:
18395
diff
changeset
|
1916 } |
13249
7861a5fd3479
accept enumeration keyword
John W. Eaton <jwe@octave.org>
parents:
13246
diff
changeset
|
1917 ; |
7861a5fd3479
accept enumeration keyword
John W. Eaton <jwe@octave.org>
parents:
13246
diff
changeset
|
1918 |
7861a5fd3479
accept enumeration keyword
John W. Eaton <jwe@octave.org>
parents:
13246
diff
changeset
|
1919 enum_list : class_enum |
15037
56b8eb7c9c04
improvements in parsing classdef
John W. Eaton <jwe@octave.org>
parents:
14846
diff
changeset
|
1920 { $$ = new tree_classdef_enum_list ($1); } |
13250
f6bbdea030b2
use opt_sep instead of literal '\n' in parser rules for classdef
John W. Eaton <jwe@octave.org>
parents:
13249
diff
changeset
|
1921 | enum_list opt_sep class_enum |
15037
56b8eb7c9c04
improvements in parsing classdef
John W. Eaton <jwe@octave.org>
parents:
14846
diff
changeset
|
1922 { |
19812
bf737d927707
eliminate bison warnings from oct-parse.yy
John W. Eaton <jwe@octave.org>
parents:
19743
diff
changeset
|
1923 YYUSE ($2); |
bf737d927707
eliminate bison warnings from oct-parse.yy
John W. Eaton <jwe@octave.org>
parents:
19743
diff
changeset
|
1924 |
15037
56b8eb7c9c04
improvements in parsing classdef
John W. Eaton <jwe@octave.org>
parents:
14846
diff
changeset
|
1925 $1->append ($3); |
56b8eb7c9c04
improvements in parsing classdef
John W. Eaton <jwe@octave.org>
parents:
14846
diff
changeset
|
1926 $$ = $1; |
56b8eb7c9c04
improvements in parsing classdef
John W. Eaton <jwe@octave.org>
parents:
14846
diff
changeset
|
1927 } |
13249
7861a5fd3479
accept enumeration keyword
John W. Eaton <jwe@octave.org>
parents:
13246
diff
changeset
|
1928 ; |
7861a5fd3479
accept enumeration keyword
John W. Eaton <jwe@octave.org>
parents:
13246
diff
changeset
|
1929 |
7861a5fd3479
accept enumeration keyword
John W. Eaton <jwe@octave.org>
parents:
13246
diff
changeset
|
1930 class_enum : identifier '(' expression ')' |
15037
56b8eb7c9c04
improvements in parsing classdef
John W. Eaton <jwe@octave.org>
parents:
14846
diff
changeset
|
1931 { $$ = new tree_classdef_enum ($1, $3); } |
13249
7861a5fd3479
accept enumeration keyword
John W. Eaton <jwe@octave.org>
parents:
13246
diff
changeset
|
1932 ; |
7861a5fd3479
accept enumeration keyword
John W. Eaton <jwe@octave.org>
parents:
13246
diff
changeset
|
1933 |
2970 | 1934 // ============= |
1935 // Miscellaneous | |
1936 // ============= | |
1937 | |
16681
d3619d4d267c
recognize character string at beginning of statement (bug #38926, #38958)
John W. Eaton <jwe@octave.org>
parents:
16627
diff
changeset
|
1938 stmt_begin : // empty |
19812
bf737d927707
eliminate bison warnings from oct-parse.yy
John W. Eaton <jwe@octave.org>
parents:
19743
diff
changeset
|
1939 { |
bf737d927707
eliminate bison warnings from oct-parse.yy
John W. Eaton <jwe@octave.org>
parents:
19743
diff
changeset
|
1940 $$ = 0; |
bf737d927707
eliminate bison warnings from oct-parse.yy
John W. Eaton <jwe@octave.org>
parents:
19743
diff
changeset
|
1941 lexer.at_beginning_of_statement = true; |
bf737d927707
eliminate bison warnings from oct-parse.yy
John W. Eaton <jwe@octave.org>
parents:
19743
diff
changeset
|
1942 } |
16681
d3619d4d267c
recognize character string at beginning of statement (bug #38926, #38958)
John W. Eaton <jwe@octave.org>
parents:
16627
diff
changeset
|
1943 ; |
d3619d4d267c
recognize character string at beginning of statement (bug #38926, #38958)
John W. Eaton <jwe@octave.org>
parents:
16627
diff
changeset
|
1944 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1945 stash_comment : // empty |
17693
efbe746f8fa8
eliminate octave_comment_buffer singleton
John W. Eaton <jwe@octave.org>
parents:
17673
diff
changeset
|
1946 { $$ = lexer.get_comment (); } |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1947 ; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1948 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1949 parse_error : LEXICAL_ERROR |
19812
bf737d927707
eliminate bison warnings from oct-parse.yy
John W. Eaton <jwe@octave.org>
parents:
19743
diff
changeset
|
1950 { |
bf737d927707
eliminate bison warnings from oct-parse.yy
John W. Eaton <jwe@octave.org>
parents:
19743
diff
changeset
|
1951 $$ = 0; |
bf737d927707
eliminate bison warnings from oct-parse.yy
John W. Eaton <jwe@octave.org>
parents:
19743
diff
changeset
|
1952 parser.bison_error ("parse error"); |
bf737d927707
eliminate bison warnings from oct-parse.yy
John W. Eaton <jwe@octave.org>
parents:
19743
diff
changeset
|
1953 } |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1954 | error |
19812
bf737d927707
eliminate bison warnings from oct-parse.yy
John W. Eaton <jwe@octave.org>
parents:
19743
diff
changeset
|
1955 { $$ = 0; } |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1956 ; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1957 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1958 sep_no_nl : ',' |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1959 { $$ = ','; } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1960 | ';' |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1961 { $$ = ';'; } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1962 | sep_no_nl ',' |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1963 { $$ = $1; } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1964 | sep_no_nl ';' |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1965 { $$ = $1; } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1966 ; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1967 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1968 opt_sep_no_nl : // empty |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1969 { $$ = 0; } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1970 | sep_no_nl |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1971 { $$ = $1; } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1972 ; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1973 |
16203
127cccb037bf
move more global parser and lexer variables to classes
John W. Eaton <jwe@octave.org>
parents:
16199
diff
changeset
|
1974 opt_nl : // empty |
127cccb037bf
move more global parser and lexer variables to classes
John W. Eaton <jwe@octave.org>
parents:
16199
diff
changeset
|
1975 { $$ = 0; } |
127cccb037bf
move more global parser and lexer variables to classes
John W. Eaton <jwe@octave.org>
parents:
16199
diff
changeset
|
1976 | nl |
127cccb037bf
move more global parser and lexer variables to classes
John W. Eaton <jwe@octave.org>
parents:
16199
diff
changeset
|
1977 { $$ = $1; } |
127cccb037bf
move more global parser and lexer variables to classes
John W. Eaton <jwe@octave.org>
parents:
16199
diff
changeset
|
1978 ; |
127cccb037bf
move more global parser and lexer variables to classes
John W. Eaton <jwe@octave.org>
parents:
16199
diff
changeset
|
1979 |
127cccb037bf
move more global parser and lexer variables to classes
John W. Eaton <jwe@octave.org>
parents:
16199
diff
changeset
|
1980 nl : '\n' |
127cccb037bf
move more global parser and lexer variables to classes
John W. Eaton <jwe@octave.org>
parents:
16199
diff
changeset
|
1981 { $$ = '\n'; } |
127cccb037bf
move more global parser and lexer variables to classes
John W. Eaton <jwe@octave.org>
parents:
16199
diff
changeset
|
1982 | nl '\n' |
127cccb037bf
move more global parser and lexer variables to classes
John W. Eaton <jwe@octave.org>
parents:
16199
diff
changeset
|
1983 { $$ = $1; } |
127cccb037bf
move more global parser and lexer variables to classes
John W. Eaton <jwe@octave.org>
parents:
16199
diff
changeset
|
1984 ; |
127cccb037bf
move more global parser and lexer variables to classes
John W. Eaton <jwe@octave.org>
parents:
16199
diff
changeset
|
1985 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1986 sep : ',' |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1987 { $$ = ','; } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1988 | ';' |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1989 { $$ = ';'; } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1990 | '\n' |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1991 { $$ = '\n'; } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1992 | sep ',' |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1993 { $$ = $1; } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1994 | sep ';' |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1995 { $$ = $1; } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1996 | sep '\n' |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1997 { $$ = $1; } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1998 ; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1999 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
2000 opt_sep : // empty |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
2001 { $$ = 0; } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
2002 | sep |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
2003 { $$ = $1; } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
2004 ; |
2525 | 2005 |
1 | 2006 %% |
2007 | |
666 | 2008 // Generic error messages. |
2009 | |
16288
fe3b9a51e625
rename curr_lexer, curr_parser, CURR_LEXER
John W. Eaton <jwe@octave.org>
parents:
16287
diff
changeset
|
2010 #undef lexer |
16149
49dfba4fd3c5
use pure parser and reentrant lexer interfaces
John W. Eaton <jwe@octave.org>
parents:
16147
diff
changeset
|
2011 |
1 | 2012 static void |
16288
fe3b9a51e625
rename curr_lexer, curr_parser, CURR_LEXER
John W. Eaton <jwe@octave.org>
parents:
16287
diff
changeset
|
2013 yyerror (octave_base_parser& parser, const char *s) |
1 | 2014 { |
16288
fe3b9a51e625
rename curr_lexer, curr_parser, CURR_LEXER
John W. Eaton <jwe@octave.org>
parents:
16287
diff
changeset
|
2015 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
|
2016 } |
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
|
2017 |
16287
04a7953496a7
create base class for parser; use reference for curr_lexer
John W. Eaton <jwe@octave.org>
parents:
16285
diff
changeset
|
2018 octave_base_parser::~octave_base_parser (void) |
16157
335041cc657a
optionally use push parser interface
John W. Eaton <jwe@octave.org>
parents:
16153
diff
changeset
|
2019 { |
16177
a7669b4d27f6
eliminate global global_command variable
John W. Eaton <jwe@octave.org>
parents:
16174
diff
changeset
|
2020 delete stmt_list; |
a7669b4d27f6
eliminate global global_command variable
John W. Eaton <jwe@octave.org>
parents:
16174
diff
changeset
|
2021 |
16288
fe3b9a51e625
rename curr_lexer, curr_parser, CURR_LEXER
John W. Eaton <jwe@octave.org>
parents:
16287
diff
changeset
|
2022 delete &lexer; |
16157
335041cc657a
optionally use push parser interface
John W. Eaton <jwe@octave.org>
parents:
16153
diff
changeset
|
2023 } |
16287
04a7953496a7
create base class for parser; use reference for curr_lexer
John W. Eaton <jwe@octave.org>
parents:
16285
diff
changeset
|
2024 |
16177
a7669b4d27f6
eliminate global global_command variable
John W. Eaton <jwe@octave.org>
parents:
16174
diff
changeset
|
2025 void |
16287
04a7953496a7
create base class for parser; use reference for curr_lexer
John W. Eaton <jwe@octave.org>
parents:
16285
diff
changeset
|
2026 octave_base_parser::reset (void) |
16177
a7669b4d27f6
eliminate global global_command variable
John W. Eaton <jwe@octave.org>
parents:
16174
diff
changeset
|
2027 { |
16574
b678d2d10e53
reset parser state on parse error (bug #38840)
John W. Eaton <jwe@octave.org>
parents:
16442
diff
changeset
|
2028 endfunction_found = false; |
b678d2d10e53
reset parser state on parse error (bug #38840)
John W. Eaton <jwe@octave.org>
parents:
16442
diff
changeset
|
2029 autoloading = false; |
b678d2d10e53
reset parser state on parse error (bug #38840)
John W. Eaton <jwe@octave.org>
parents:
16442
diff
changeset
|
2030 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
|
2031 parsing_subfunctions = false; |
b678d2d10e53
reset parser state on parse error (bug #38840)
John W. Eaton <jwe@octave.org>
parents:
16442
diff
changeset
|
2032 max_fcn_depth = 0; |
b678d2d10e53
reset parser state on parse error (bug #38840)
John W. Eaton <jwe@octave.org>
parents:
16442
diff
changeset
|
2033 curr_fcn_depth = 0; |
b678d2d10e53
reset parser state on parse error (bug #38840)
John W. Eaton <jwe@octave.org>
parents:
16442
diff
changeset
|
2034 primary_fcn_scope = -1; |
b678d2d10e53
reset parser state on parse error (bug #38840)
John W. Eaton <jwe@octave.org>
parents:
16442
diff
changeset
|
2035 curr_class_name = ""; |
16676
7368654f302f
Initial support for (classdef) packages.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
16644
diff
changeset
|
2036 curr_package_name = ""; |
16574
b678d2d10e53
reset parser state on parse error (bug #38840)
John W. Eaton <jwe@octave.org>
parents:
16442
diff
changeset
|
2037 function_scopes.clear (); |
b678d2d10e53
reset parser state on parse error (bug #38840)
John W. Eaton <jwe@octave.org>
parents:
16442
diff
changeset
|
2038 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
|
2039 subfunction_names.clear (); |
16574
b678d2d10e53
reset parser state on parse error (bug #38840)
John W. Eaton <jwe@octave.org>
parents:
16442
diff
changeset
|
2040 |
16177
a7669b4d27f6
eliminate global global_command variable
John W. Eaton <jwe@octave.org>
parents:
16174
diff
changeset
|
2041 delete stmt_list; |
a7669b4d27f6
eliminate global global_command variable
John W. Eaton <jwe@octave.org>
parents:
16174
diff
changeset
|
2042 stmt_list = 0; |
a7669b4d27f6
eliminate global global_command variable
John W. Eaton <jwe@octave.org>
parents:
16174
diff
changeset
|
2043 |
16288
fe3b9a51e625
rename curr_lexer, curr_parser, CURR_LEXER
John W. Eaton <jwe@octave.org>
parents:
16287
diff
changeset
|
2044 lexer.reset (); |
16138
284e2ca86ef7
execute parser using member function of octave_parser class
John W. Eaton <jwe@octave.org>
parents:
16136
diff
changeset
|
2045 } |
284e2ca86ef7
execute parser using member function of octave_parser class
John W. Eaton <jwe@octave.org>
parents:
16136
diff
changeset
|
2046 |
666 | 2047 // Error mesages for mismatched end tokens. |
2048 | |
16134
ec9c6222ef5a
move static parser helper functions to octave_parser class
John W. Eaton <jwe@octave.org>
parents:
16133
diff
changeset
|
2049 void |
16287
04a7953496a7
create base class for parser; use reference for curr_lexer
John W. Eaton <jwe@octave.org>
parents:
16285
diff
changeset
|
2050 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
|
2051 int l, int c) |
496 | 2052 { |
2805 | 2053 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
|
2054 = "'%s' command matched by '%s' near line %d column %d"; |
496 | 2055 |
2056 switch (ettype) | |
2057 { | |
2058 case token::simple_end: | |
2059 error (fmt, type, "end", l, c); | |
2060 break; | |
777 | 2061 |
20110
8aa424ffc076
handle all end token types when reporting parse errors (bug #44824)
John W. Eaton <jwe@octave.org>
parents:
19883
diff
changeset
|
2062 case token::classdef_end: |
8aa424ffc076
handle all end token types when reporting parse errors (bug #44824)
John W. Eaton <jwe@octave.org>
parents:
19883
diff
changeset
|
2063 error (fmt, type, "endclassdef", l, c); |
8aa424ffc076
handle all end token types when reporting parse errors (bug #44824)
John W. Eaton <jwe@octave.org>
parents:
19883
diff
changeset
|
2064 break; |
8aa424ffc076
handle all end token types when reporting parse errors (bug #44824)
John W. Eaton <jwe@octave.org>
parents:
19883
diff
changeset
|
2065 |
8aa424ffc076
handle all end token types when reporting parse errors (bug #44824)
John W. Eaton <jwe@octave.org>
parents:
19883
diff
changeset
|
2066 case token::enumeration_end: |
8aa424ffc076
handle all end token types when reporting parse errors (bug #44824)
John W. Eaton <jwe@octave.org>
parents:
19883
diff
changeset
|
2067 error (fmt, type, "endenumeration", l, c); |
8aa424ffc076
handle all end token types when reporting parse errors (bug #44824)
John W. Eaton <jwe@octave.org>
parents:
19883
diff
changeset
|
2068 break; |
8aa424ffc076
handle all end token types when reporting parse errors (bug #44824)
John W. Eaton <jwe@octave.org>
parents:
19883
diff
changeset
|
2069 |
8aa424ffc076
handle all end token types when reporting parse errors (bug #44824)
John W. Eaton <jwe@octave.org>
parents:
19883
diff
changeset
|
2070 case token::events_end: |
8aa424ffc076
handle all end token types when reporting parse errors (bug #44824)
John W. Eaton <jwe@octave.org>
parents:
19883
diff
changeset
|
2071 error (fmt, type, "endevents", l, c); |
8aa424ffc076
handle all end token types when reporting parse errors (bug #44824)
John W. Eaton <jwe@octave.org>
parents:
19883
diff
changeset
|
2072 break; |
8aa424ffc076
handle all end token types when reporting parse errors (bug #44824)
John W. Eaton <jwe@octave.org>
parents:
19883
diff
changeset
|
2073 |
496 | 2074 case token::for_end: |
2075 error (fmt, type, "endfor", l, c); | |
2076 break; | |
777 | 2077 |
496 | 2078 case token::function_end: |
2079 error (fmt, type, "endfunction", l, c); | |
2080 break; | |
777 | 2081 |
496 | 2082 case token::if_end: |
2083 error (fmt, type, "endif", l, c); | |
2084 break; | |
777 | 2085 |
20110
8aa424ffc076
handle all end token types when reporting parse errors (bug #44824)
John W. Eaton <jwe@octave.org>
parents:
19883
diff
changeset
|
2086 case token::methods_end: |
8aa424ffc076
handle all end token types when reporting parse errors (bug #44824)
John W. Eaton <jwe@octave.org>
parents:
19883
diff
changeset
|
2087 error (fmt, type, "endmethods", l, c); |
8aa424ffc076
handle all end token types when reporting parse errors (bug #44824)
John W. Eaton <jwe@octave.org>
parents:
19883
diff
changeset
|
2088 break; |
8aa424ffc076
handle all end token types when reporting parse errors (bug #44824)
John W. Eaton <jwe@octave.org>
parents:
19883
diff
changeset
|
2089 |
8aa424ffc076
handle all end token types when reporting parse errors (bug #44824)
John W. Eaton <jwe@octave.org>
parents:
19883
diff
changeset
|
2090 case token::parfor_end: |
8aa424ffc076
handle all end token types when reporting parse errors (bug #44824)
John W. Eaton <jwe@octave.org>
parents:
19883
diff
changeset
|
2091 error (fmt, type, "endparfor", l, c); |
8aa424ffc076
handle all end token types when reporting parse errors (bug #44824)
John W. Eaton <jwe@octave.org>
parents:
19883
diff
changeset
|
2092 break; |
8aa424ffc076
handle all end token types when reporting parse errors (bug #44824)
John W. Eaton <jwe@octave.org>
parents:
19883
diff
changeset
|
2093 |
8aa424ffc076
handle all end token types when reporting parse errors (bug #44824)
John W. Eaton <jwe@octave.org>
parents:
19883
diff
changeset
|
2094 case token::properties_end: |
8aa424ffc076
handle all end token types when reporting parse errors (bug #44824)
John W. Eaton <jwe@octave.org>
parents:
19883
diff
changeset
|
2095 error (fmt, type, "endproperties", l, c); |
8aa424ffc076
handle all end token types when reporting parse errors (bug #44824)
John W. Eaton <jwe@octave.org>
parents:
19883
diff
changeset
|
2096 break; |
8aa424ffc076
handle all end token types when reporting parse errors (bug #44824)
John W. Eaton <jwe@octave.org>
parents:
19883
diff
changeset
|
2097 |
3233 | 2098 case token::switch_end: |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11572
diff
changeset
|
2099 error (fmt, type, "endswitch", l, c); |
3233 | 2100 break; |
2101 | |
5400 | 2102 case token::try_catch_end: |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11572
diff
changeset
|
2103 error (fmt, type, "end_try_catch", l, c); |
5400 | 2104 break; |
2105 | |
1371 | 2106 case token::unwind_protect_end: |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11572
diff
changeset
|
2107 error (fmt, type, "end_unwind_protect", l, c); |
1371 | 2108 break; |
2109 | |
20110
8aa424ffc076
handle all end token types when reporting parse errors (bug #44824)
John W. Eaton <jwe@octave.org>
parents:
19883
diff
changeset
|
2110 case token::while_end: |
8aa424ffc076
handle all end token types when reporting parse errors (bug #44824)
John W. Eaton <jwe@octave.org>
parents:
19883
diff
changeset
|
2111 error (fmt, type, "endwhile", l, c); |
8aa424ffc076
handle all end token types when reporting parse errors (bug #44824)
John W. Eaton <jwe@octave.org>
parents:
19883
diff
changeset
|
2112 break; |
8aa424ffc076
handle all end token types when reporting parse errors (bug #44824)
John W. Eaton <jwe@octave.org>
parents:
19883
diff
changeset
|
2113 |
496 | 2114 default: |
2115 panic_impossible (); | |
2116 break; | |
2117 } | |
2118 } | |
2119 | |
666 | 2120 // Check to see that end tokens are properly matched. |
2121 | |
16134
ec9c6222ef5a
move static parser helper functions to octave_parser class
John W. Eaton <jwe@octave.org>
parents:
16133
diff
changeset
|
2122 bool |
16287
04a7953496a7
create base class for parser; use reference for curr_lexer
John W. Eaton <jwe@octave.org>
parents:
16285
diff
changeset
|
2123 octave_base_parser::end_token_ok (token *tok, token::end_tok_type expected) |
143 | 2124 { |
2857 | 2125 bool retval = true; |
2126 | |
143 | 2127 token::end_tok_type ettype = tok->ettype (); |
2857 | 2128 |
143 | 2129 if (ettype != expected && ettype != token::simple_end) |
2130 { | |
2857 | 2131 retval = false; |
2132 | |
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
|
2133 bison_error ("parse error"); |
143 | 2134 |
2135 int l = tok->line (); | |
2136 int c = tok->column (); | |
2137 | |
2138 switch (expected) | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
2139 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
2140 case token::classdef_end: |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
2141 end_error ("classdef", ettype, l, c); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
2142 break; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
2143 |
20110
8aa424ffc076
handle all end token types when reporting parse errors (bug #44824)
John W. Eaton <jwe@octave.org>
parents:
19883
diff
changeset
|
2144 case token::enumeration_end: |
8aa424ffc076
handle all end token types when reporting parse errors (bug #44824)
John W. Eaton <jwe@octave.org>
parents:
19883
diff
changeset
|
2145 end_error ("enumeration", ettype, l, c); |
8aa424ffc076
handle all end token types when reporting parse errors (bug #44824)
John W. Eaton <jwe@octave.org>
parents:
19883
diff
changeset
|
2146 break; |
8aa424ffc076
handle all end token types when reporting parse errors (bug #44824)
John W. Eaton <jwe@octave.org>
parents:
19883
diff
changeset
|
2147 |
8aa424ffc076
handle all end token types when reporting parse errors (bug #44824)
John W. Eaton <jwe@octave.org>
parents:
19883
diff
changeset
|
2148 case token::events_end: |
8aa424ffc076
handle all end token types when reporting parse errors (bug #44824)
John W. Eaton <jwe@octave.org>
parents:
19883
diff
changeset
|
2149 end_error ("events", ettype, l, c); |
8aa424ffc076
handle all end token types when reporting parse errors (bug #44824)
John W. Eaton <jwe@octave.org>
parents:
19883
diff
changeset
|
2150 break; |
8aa424ffc076
handle all end token types when reporting parse errors (bug #44824)
John W. Eaton <jwe@octave.org>
parents:
19883
diff
changeset
|
2151 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
2152 case token::for_end: |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
2153 end_error ("for", ettype, l, c); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
2154 break; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
2155 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
2156 case token::function_end: |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
2157 end_error ("function", ettype, l, c); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
2158 break; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
2159 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
2160 case token::if_end: |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
2161 end_error ("if", ettype, l, c); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
2162 break; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
2163 |
20110
8aa424ffc076
handle all end token types when reporting parse errors (bug #44824)
John W. Eaton <jwe@octave.org>
parents:
19883
diff
changeset
|
2164 case token::methods_end: |
8aa424ffc076
handle all end token types when reporting parse errors (bug #44824)
John W. Eaton <jwe@octave.org>
parents:
19883
diff
changeset
|
2165 end_error ("methods", ettype, l, c); |
8aa424ffc076
handle all end token types when reporting parse errors (bug #44824)
John W. Eaton <jwe@octave.org>
parents:
19883
diff
changeset
|
2166 break; |
8aa424ffc076
handle all end token types when reporting parse errors (bug #44824)
John W. Eaton <jwe@octave.org>
parents:
19883
diff
changeset
|
2167 |
13246 | 2168 case token::parfor_end: |
2169 end_error ("parfor", ettype, l, c); | |
2170 break; | |
2171 | |
20110
8aa424ffc076
handle all end token types when reporting parse errors (bug #44824)
John W. Eaton <jwe@octave.org>
parents:
19883
diff
changeset
|
2172 case token::properties_end: |
8aa424ffc076
handle all end token types when reporting parse errors (bug #44824)
John W. Eaton <jwe@octave.org>
parents:
19883
diff
changeset
|
2173 end_error ("properties", ettype, l, c); |
8aa424ffc076
handle all end token types when reporting parse errors (bug #44824)
John W. Eaton <jwe@octave.org>
parents:
19883
diff
changeset
|
2174 break; |
8aa424ffc076
handle all end token types when reporting parse errors (bug #44824)
John W. Eaton <jwe@octave.org>
parents:
19883
diff
changeset
|
2175 |
8aa424ffc076
handle all end token types when reporting parse errors (bug #44824)
John W. Eaton <jwe@octave.org>
parents:
19883
diff
changeset
|
2176 case token::switch_end: |
8aa424ffc076
handle all end token types when reporting parse errors (bug #44824)
John W. Eaton <jwe@octave.org>
parents:
19883
diff
changeset
|
2177 end_error ("switch", ettype, l, c); |
8aa424ffc076
handle all end token types when reporting parse errors (bug #44824)
John W. Eaton <jwe@octave.org>
parents:
19883
diff
changeset
|
2178 break; |
8aa424ffc076
handle all end token types when reporting parse errors (bug #44824)
John W. Eaton <jwe@octave.org>
parents:
19883
diff
changeset
|
2179 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
2180 case token::try_catch_end: |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
2181 end_error ("try", ettype, l, c); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
2182 break; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
2183 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
2184 case token::unwind_protect_end: |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
2185 end_error ("unwind_protect", ettype, l, c); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
2186 break; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
2187 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
2188 case token::while_end: |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
2189 end_error ("while", ettype, l, c); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
2190 break; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
2191 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
2192 default: |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
2193 panic_impossible (); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
2194 break; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
2195 } |
143 | 2196 } |
2857 | 2197 |
2198 return retval; | |
143 | 2199 } |
2200 | |
666 | 2201 // Maybe print a warning if an assignment expression is used as the |
2202 // test in a logical expression. | |
2203 | |
16134
ec9c6222ef5a
move static parser helper functions to octave_parser class
John W. Eaton <jwe@octave.org>
parents:
16133
diff
changeset
|
2204 void |
16287
04a7953496a7
create base class for parser; use reference for curr_lexer
John W. Eaton <jwe@octave.org>
parents:
16285
diff
changeset
|
2205 octave_base_parser::maybe_warn_assign_as_truth_value (tree_expression *expr) |
1 | 2206 { |
5781 | 2207 if (expr->is_assignment_expression () |
2961 | 2208 && expr->paren_count () < 2) |
1 | 2209 { |
16288
fe3b9a51e625
rename curr_lexer, curr_parser, CURR_LEXER
John W. Eaton <jwe@octave.org>
parents:
16287
diff
changeset
|
2210 if (lexer.fcn_file_full_name.empty ()) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
2211 warning_with_id |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
2212 ("Octave:assign-as-truth-value", |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
2213 "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
|
2214 else |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
2215 warning_with_id |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
2216 ("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
|
2217 "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
|
2218 expr->line (), expr->column (), lexer.fcn_file_full_name.c_str ()); |
1 | 2219 } |
2220 } | |
578 | 2221 |
2764 | 2222 // Maybe print a warning about switch labels that aren't constants. |
2223 | |
16134
ec9c6222ef5a
move static parser helper functions to octave_parser class
John W. Eaton <jwe@octave.org>
parents:
16133
diff
changeset
|
2224 void |
16287
04a7953496a7
create base class for parser; use reference for curr_lexer
John W. Eaton <jwe@octave.org>
parents:
16285
diff
changeset
|
2225 octave_base_parser::maybe_warn_variable_switch_label (tree_expression *expr) |
2764 | 2226 { |
5781 | 2227 if (! expr->is_constant ()) |
8974
fde2a916b2ac
include line and file info in parser warnings
John W. Eaton <jwe@octave.org>
parents:
8950
diff
changeset
|
2228 { |
16288
fe3b9a51e625
rename curr_lexer, curr_parser, CURR_LEXER
John W. Eaton <jwe@octave.org>
parents:
16287
diff
changeset
|
2229 if (lexer.fcn_file_full_name.empty ()) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
2230 warning_with_id ("Octave:variable-switch-label", |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
2231 "variable switch label"); |
8974
fde2a916b2ac
include line and file info in parser warnings
John W. Eaton <jwe@octave.org>
parents:
8950
diff
changeset
|
2232 else |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
2233 warning_with_id |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
2234 ("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
|
2235 "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
|
2236 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
|
2237 } |
2764 | 2238 } |
2239 | |
1623 | 2240 // Finish building a range. |
2241 | |
16134
ec9c6222ef5a
move static parser helper functions to octave_parser class
John W. Eaton <jwe@octave.org>
parents:
16133
diff
changeset
|
2242 tree_expression * |
16287
04a7953496a7
create base class for parser; use reference for curr_lexer
John W. Eaton <jwe@octave.org>
parents:
16285
diff
changeset
|
2243 octave_base_parser::finish_colon_expression (tree_colon_expression *e) |
1623 | 2244 { |
3110 | 2245 tree_expression *retval = e; |
2246 | |
10067
6f79338c269b
omission from last patch
Jaroslav Hajek <highegg@gmail.com>
parents:
9794
diff
changeset
|
2247 unwind_protect frame; |
6f79338c269b
omission from last patch
Jaroslav Hajek <highegg@gmail.com>
parents:
9794
diff
changeset
|
2248 |
6f79338c269b
omission from last patch
Jaroslav Hajek <highegg@gmail.com>
parents:
9794
diff
changeset
|
2249 frame.protect_var (discard_error_messages); |
6f79338c269b
omission from last patch
Jaroslav Hajek <highegg@gmail.com>
parents:
9794
diff
changeset
|
2250 frame.protect_var (discard_warning_messages); |
4452 | 2251 |
3815 | 2252 discard_error_messages = true; |
4452 | 2253 discard_warning_messages = true; |
1623 | 2254 |
2533 | 2255 tree_expression *base = e->base (); |
2256 tree_expression *limit = e->limit (); | |
2257 tree_expression *incr = e->increment (); | |
2258 | |
2970 | 2259 if (base) |
1623 | 2260 { |
2970 | 2261 if (limit) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
2262 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
2263 if (base->is_constant () && limit->is_constant () |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
2264 && (! incr || (incr && incr->is_constant ()))) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
2265 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
2266 octave_value tmp = e->rvalue1 (); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
2267 |
20579
52ce821a52fd
eliminate simple uses of error_state in parser and lexer
John W. Eaton <jwe@octave.org>
parents:
20569
diff
changeset
|
2268 tree_constant *tc_retval |
52ce821a52fd
eliminate simple uses of error_state in parser and lexer
John W. Eaton <jwe@octave.org>
parents:
20569
diff
changeset
|
2269 = new tree_constant (tmp, base->line (), base->column ()); |
52ce821a52fd
eliminate simple uses of error_state in parser and lexer
John W. Eaton <jwe@octave.org>
parents:
20569
diff
changeset
|
2270 |
52ce821a52fd
eliminate simple uses of error_state in parser and lexer
John W. Eaton <jwe@octave.org>
parents:
20569
diff
changeset
|
2271 std::ostringstream buf; |
52ce821a52fd
eliminate simple uses of error_state in parser and lexer
John W. Eaton <jwe@octave.org>
parents:
20569
diff
changeset
|
2272 |
52ce821a52fd
eliminate simple uses of error_state in parser and lexer
John W. Eaton <jwe@octave.org>
parents:
20569
diff
changeset
|
2273 tree_print_code tpc (buf); |
52ce821a52fd
eliminate simple uses of error_state in parser and lexer
John W. Eaton <jwe@octave.org>
parents:
20569
diff
changeset
|
2274 |
52ce821a52fd
eliminate simple uses of error_state in parser and lexer
John W. Eaton <jwe@octave.org>
parents:
20569
diff
changeset
|
2275 e->accept (tpc); |
52ce821a52fd
eliminate simple uses of error_state in parser and lexer
John W. Eaton <jwe@octave.org>
parents:
20569
diff
changeset
|
2276 |
52ce821a52fd
eliminate simple uses of error_state in parser and lexer
John W. Eaton <jwe@octave.org>
parents:
20569
diff
changeset
|
2277 tc_retval->stash_original_text (buf.str ()); |
52ce821a52fd
eliminate simple uses of error_state in parser and lexer
John W. Eaton <jwe@octave.org>
parents:
20569
diff
changeset
|
2278 |
52ce821a52fd
eliminate simple uses of error_state in parser and lexer
John W. Eaton <jwe@octave.org>
parents:
20569
diff
changeset
|
2279 delete e; |
52ce821a52fd
eliminate simple uses of error_state in parser and lexer
John W. Eaton <jwe@octave.org>
parents:
20569
diff
changeset
|
2280 |
52ce821a52fd
eliminate simple uses of error_state in parser and lexer
John W. Eaton <jwe@octave.org>
parents:
20569
diff
changeset
|
2281 retval = tc_retval; |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
2282 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
2283 } |
2533 | 2284 else |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
2285 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
2286 e->preserve_base (); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
2287 delete e; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
2288 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
2289 retval = base; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
2290 } |
1623 | 2291 } |
2292 | |
2293 return retval; | |
2294 } | |
2295 | |
1607 | 2296 // Make a constant. |
2297 | |
16134
ec9c6222ef5a
move static parser helper functions to octave_parser class
John W. Eaton <jwe@octave.org>
parents:
16133
diff
changeset
|
2298 tree_constant * |
16287
04a7953496a7
create base class for parser; use reference for curr_lexer
John W. Eaton <jwe@octave.org>
parents:
16285
diff
changeset
|
2299 octave_base_parser::make_constant (int op, token *tok_val) |
1607 | 2300 { |
2301 int l = tok_val->line (); | |
2302 int c = tok_val->column (); | |
2303 | |
3216 | 2304 tree_constant *retval = 0; |
1607 | 2305 |
2306 switch (op) | |
2307 { | |
2308 case NUM: | |
2533 | 2309 { |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
2310 octave_value tmp (tok_val->number ()); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
2311 retval = new tree_constant (tmp, l, c); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
2312 retval->stash_original_text (tok_val->text_rep ()); |
2533 | 2313 } |
1607 | 2314 break; |
2315 | |
2316 case IMAG_NUM: | |
2317 { | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
2318 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
|
2319 retval = new tree_constant (tmp, l, c); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
2320 retval->stash_original_text (tok_val->text_rep ()); |
1607 | 2321 } |
2322 break; | |
2323 | |
5279 | 2324 case DQ_STRING: |
2325 case SQ_STRING: | |
2883 | 2326 { |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
2327 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
|
2328 |
8150
283989f2da9b
make null assignment matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
8064
diff
changeset
|
2329 char delim = op == DQ_STRING ? '"' : '\''; |
283989f2da9b
make null assignment matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
8064
diff
changeset
|
2330 octave_value tmp (txt, delim); |
283989f2da9b
make null assignment matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
8064
diff
changeset
|
2331 |
283989f2da9b
make null assignment matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
8064
diff
changeset
|
2332 if (txt.empty ()) |
283989f2da9b
make null assignment matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
8064
diff
changeset
|
2333 { |
283989f2da9b
make null assignment matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
8064
diff
changeset
|
2334 if (op == DQ_STRING) |
283989f2da9b
make null assignment matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
8064
diff
changeset
|
2335 tmp = octave_null_str::instance; |
283989f2da9b
make null assignment matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
8064
diff
changeset
|
2336 else |
283989f2da9b
make null assignment matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
8064
diff
changeset
|
2337 tmp = octave_null_sq_str::instance; |
283989f2da9b
make null assignment matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
8064
diff
changeset
|
2338 } |
283989f2da9b
make null assignment matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
8064
diff
changeset
|
2339 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
2340 retval = new tree_constant (tmp, l, c); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
2341 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
2342 if (op == DQ_STRING) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
2343 txt = undo_string_escapes (txt); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
2344 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
2345 // FIXME -- maybe this should also be handled by |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
2346 // tok_val->text_rep () for character strings? |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
2347 retval->stash_original_text (delim + txt + delim); |
2883 | 2348 } |
1607 | 2349 break; |
2350 | |
2351 default: | |
2352 panic_impossible (); | |
2353 break; | |
2354 } | |
2355 | |
2356 return retval; | |
2357 } | |
2358 | |
4342 | 2359 // Make a function handle. |
2360 | |
16134
ec9c6222ef5a
move static parser helper functions to octave_parser class
John W. Eaton <jwe@octave.org>
parents:
16133
diff
changeset
|
2361 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
|
2362 octave_base_parser::make_fcn_handle (token *tok_val) |
4342 | 2363 { |
2364 int l = tok_val->line (); | |
2365 int c = tok_val->column (); | |
2366 | |
2367 tree_fcn_handle *retval = new tree_fcn_handle (tok_val->text (), l, c); | |
2368 | |
2369 return retval; | |
2370 } | |
2371 | |
4935 | 2372 // Make an anonymous function handle. |
2373 | |
16134
ec9c6222ef5a
move static parser helper functions to octave_parser class
John W. Eaton <jwe@octave.org>
parents:
16133
diff
changeset
|
2374 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
|
2375 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
|
2376 tree_statement *stmt) |
4935 | 2377 { |
5775 | 2378 // 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
|
2379 int l = lexer.input_line_number; |
fe3b9a51e625
rename curr_lexer, curr_parser, CURR_LEXER
John W. Eaton <jwe@octave.org>
parents:
16287
diff
changeset
|
2380 int c = lexer.current_input_column; |
4935 | 2381 |
2382 tree_parameter_list *ret_list = 0; | |
2383 | |
16320
09f0cb9cac7d
don't modify symbol table scope in the parser
John W. Eaton <jwe@octave.org>
parents:
16302
diff
changeset
|
2384 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
|
2385 |
09f0cb9cac7d
don't modify symbol table scope in the parser
John W. Eaton <jwe@octave.org>
parents:
16302
diff
changeset
|
2386 lexer.symtab_context.pop (); |
5861 | 2387 |
7351 | 2388 stmt->set_print_flag (false); |
4935 | 2389 |
2390 tree_statement_list *body = new tree_statement_list (stmt); | |
2391 | |
8658
73c4516fae10
New evaluator and debugger derived from tree-walker class
John W. Eaton <jwe@octave.org>
parents:
8471
diff
changeset
|
2392 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
|
2393 |
5861 | 2394 tree_anon_fcn_handle *retval |
7336 | 2395 = 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
|
2396 // 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
|
2397 // errors when executed. |
16288
fe3b9a51e625
rename curr_lexer, curr_parser, CURR_LEXER
John W. Eaton <jwe@octave.org>
parents:
16287
diff
changeset
|
2398 //retval->stash_file_name (lexer.fcn_file_name); |
4935 | 2399 |
2400 return retval; | |
2401 } | |
2402 | |
666 | 2403 // Build a binary expression. |
2404 | |
16134
ec9c6222ef5a
move static parser helper functions to octave_parser class
John W. Eaton <jwe@octave.org>
parents:
16133
diff
changeset
|
2405 tree_expression * |
16287
04a7953496a7
create base class for parser; use reference for curr_lexer
John W. Eaton <jwe@octave.org>
parents:
16285
diff
changeset
|
2406 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
|
2407 token *tok_val, tree_expression *op2) |
578 | 2408 { |
2883 | 2409 octave_value::binary_op t = octave_value::unknown_binary_op; |
1623 | 2410 |
578 | 2411 switch (op) |
2412 { | |
2413 case POW: | |
3525 | 2414 t = octave_value::op_pow; |
578 | 2415 break; |
777 | 2416 |
578 | 2417 case EPOW: |
3525 | 2418 t = octave_value::op_el_pow; |
578 | 2419 break; |
777 | 2420 |
578 | 2421 case '+': |
3525 | 2422 t = octave_value::op_add; |
578 | 2423 break; |
777 | 2424 |
578 | 2425 case '-': |
3525 | 2426 t = octave_value::op_sub; |
578 | 2427 break; |
777 | 2428 |
578 | 2429 case '*': |
3525 | 2430 t = octave_value::op_mul; |
578 | 2431 break; |
777 | 2432 |
578 | 2433 case '/': |
3525 | 2434 t = octave_value::op_div; |
578 | 2435 break; |
777 | 2436 |
578 | 2437 case EMUL: |
3525 | 2438 t = octave_value::op_el_mul; |
578 | 2439 break; |
777 | 2440 |
578 | 2441 case EDIV: |
3525 | 2442 t = octave_value::op_el_div; |
578 | 2443 break; |
777 | 2444 |
578 | 2445 case LEFTDIV: |
3525 | 2446 t = octave_value::op_ldiv; |
578 | 2447 break; |
777 | 2448 |
578 | 2449 case ELEFTDIV: |
3525 | 2450 t = octave_value::op_el_ldiv; |
578 | 2451 break; |
777 | 2452 |
2899 | 2453 case LSHIFT: |
3525 | 2454 t = octave_value::op_lshift; |
2899 | 2455 break; |
2456 | |
2457 case RSHIFT: | |
3525 | 2458 t = octave_value::op_rshift; |
2899 | 2459 break; |
2460 | |
578 | 2461 case EXPR_LT: |
3525 | 2462 t = octave_value::op_lt; |
578 | 2463 break; |
777 | 2464 |
578 | 2465 case EXPR_LE: |
3525 | 2466 t = octave_value::op_le; |
578 | 2467 break; |
777 | 2468 |
578 | 2469 case EXPR_EQ: |
3525 | 2470 t = octave_value::op_eq; |
578 | 2471 break; |
777 | 2472 |
578 | 2473 case EXPR_GE: |
3525 | 2474 t = octave_value::op_ge; |
578 | 2475 break; |
777 | 2476 |
578 | 2477 case EXPR_GT: |
3525 | 2478 t = octave_value::op_gt; |
578 | 2479 break; |
777 | 2480 |
578 | 2481 case EXPR_NE: |
3525 | 2482 t = octave_value::op_ne; |
578 | 2483 break; |
777 | 2484 |
578 | 2485 case EXPR_AND: |
3525 | 2486 t = octave_value::op_el_and; |
578 | 2487 break; |
777 | 2488 |
578 | 2489 case EXPR_OR: |
3525 | 2490 t = octave_value::op_el_or; |
578 | 2491 break; |
777 | 2492 |
578 | 2493 default: |
2494 panic_impossible (); | |
2495 break; | |
2496 } | |
2497 | |
2498 int l = tok_val->line (); | |
2499 int c = tok_val->column (); | |
2500 | |
18157
bf638abc95de
eliminate constant folding in parser
John W. Eaton <jwe@octave.org>
parents:
18131
diff
changeset
|
2501 return maybe_compound_binary_expression (op1, op2, l, c, t); |
578 | 2502 } |
2503 | |
2375 | 2504 // Build a boolean expression. |
666 | 2505 |
16134
ec9c6222ef5a
move static parser helper functions to octave_parser class
John W. Eaton <jwe@octave.org>
parents:
16133
diff
changeset
|
2506 tree_expression * |
16287
04a7953496a7
create base class for parser; use reference for curr_lexer
John W. Eaton <jwe@octave.org>
parents:
16285
diff
changeset
|
2507 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
|
2508 token *tok_val, tree_expression *op2) |
578 | 2509 { |
2375 | 2510 tree_boolean_expression::type t; |
2511 | |
578 | 2512 switch (op) |
2513 { | |
2375 | 2514 case EXPR_AND_AND: |
2805 | 2515 t = tree_boolean_expression::bool_and; |
578 | 2516 break; |
777 | 2517 |
2375 | 2518 case EXPR_OR_OR: |
2805 | 2519 t = tree_boolean_expression::bool_or; |
578 | 2520 break; |
777 | 2521 |
578 | 2522 default: |
2523 panic_impossible (); | |
2524 break; | |
2525 } | |
2526 | |
2527 int l = tok_val->line (); | |
2528 int c = tok_val->column (); | |
2529 | |
18157
bf638abc95de
eliminate constant folding in parser
John W. Eaton <jwe@octave.org>
parents:
18131
diff
changeset
|
2530 return new tree_boolean_expression (op1, op2, l, c, t); |
578 | 2531 } |
2532 | |
2375 | 2533 // Build a prefix expression. |
666 | 2534 |
16134
ec9c6222ef5a
move static parser helper functions to octave_parser class
John W. Eaton <jwe@octave.org>
parents:
16133
diff
changeset
|
2535 tree_expression * |
16287
04a7953496a7
create base class for parser; use reference for curr_lexer
John W. Eaton <jwe@octave.org>
parents:
16285
diff
changeset
|
2536 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
|
2537 token *tok_val) |
578 | 2538 { |
3203 | 2539 octave_value::unary_op t = octave_value::unknown_unary_op; |
2375 | 2540 |
578 | 2541 switch (op) |
2542 { | |
2960 | 2543 case EXPR_NOT: |
3525 | 2544 t = octave_value::op_not; |
2960 | 2545 break; |
2546 | |
4965 | 2547 case '+': |
2548 t = octave_value::op_uplus; | |
2549 break; | |
2550 | |
2960 | 2551 case '-': |
3525 | 2552 t = octave_value::op_uminus; |
2960 | 2553 break; |
2554 | |
578 | 2555 case PLUS_PLUS: |
3525 | 2556 t = octave_value::op_incr; |
578 | 2557 break; |
777 | 2558 |
578 | 2559 case MINUS_MINUS: |
3525 | 2560 t = octave_value::op_decr; |
578 | 2561 break; |
777 | 2562 |
578 | 2563 default: |
2564 panic_impossible (); | |
2565 break; | |
2566 } | |
2567 | |
2568 int l = tok_val->line (); | |
2569 int c = tok_val->column (); | |
2570 | |
18157
bf638abc95de
eliminate constant folding in parser
John W. Eaton <jwe@octave.org>
parents:
18131
diff
changeset
|
2571 return new tree_prefix_expression (op1, l, c, t); |
578 | 2572 } |
2573 | |
2375 | 2574 // Build a postfix expression. |
666 | 2575 |
16134
ec9c6222ef5a
move static parser helper functions to octave_parser class
John W. Eaton <jwe@octave.org>
parents:
16133
diff
changeset
|
2576 tree_expression * |
16287
04a7953496a7
create base class for parser; use reference for curr_lexer
John W. Eaton <jwe@octave.org>
parents:
16285
diff
changeset
|
2577 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
|
2578 token *tok_val) |
578 | 2579 { |
3203 | 2580 octave_value::unary_op t = octave_value::unknown_unary_op; |
1623 | 2581 |
578 | 2582 switch (op) |
2583 { | |
16284
09881dab3aaf
* lex.ll, oct-parse.in.yy (HERMITIAN): Rename token from QUOTE.
John W. Eaton <jwe@octave.org>
parents:
16279
diff
changeset
|
2584 case HERMITIAN: |
3525 | 2585 t = octave_value::op_hermitian; |
2960 | 2586 break; |
2587 | |
2588 case TRANSPOSE: | |
3525 | 2589 t = octave_value::op_transpose; |
2960 | 2590 break; |
2591 | |
2375 | 2592 case PLUS_PLUS: |
3525 | 2593 t = octave_value::op_incr; |
578 | 2594 break; |
777 | 2595 |
2375 | 2596 case MINUS_MINUS: |
3525 | 2597 t = octave_value::op_decr; |
578 | 2598 break; |
777 | 2599 |
578 | 2600 default: |
2601 panic_impossible (); | |
2602 break; | |
2603 } | |
2604 | |
2605 int l = tok_val->line (); | |
2606 int c = tok_val->column (); | |
2607 | |
18157
bf638abc95de
eliminate constant folding in parser
John W. Eaton <jwe@octave.org>
parents:
18131
diff
changeset
|
2608 return new tree_postfix_expression (op1, l, c, t); |
1623 | 2609 } |
2610 | |
2611 // Build an unwind-protect command. | |
2612 | |
16134
ec9c6222ef5a
move static parser helper functions to octave_parser class
John W. Eaton <jwe@octave.org>
parents:
16133
diff
changeset
|
2613 tree_command * |
16287
04a7953496a7
create base class for parser; use reference for curr_lexer
John W. Eaton <jwe@octave.org>
parents:
16285
diff
changeset
|
2614 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
|
2615 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
|
2616 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
|
2617 token *end_tok, |
04a7953496a7
create base class for parser; use reference for curr_lexer
John W. Eaton <jwe@octave.org>
parents:
16285
diff
changeset
|
2618 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
|
2619 octave_comment_list *mc) |
1623 | 2620 { |
2621 tree_command *retval = 0; | |
2622 | |
2857 | 2623 if (end_token_ok (end_tok, token::unwind_protect_end)) |
1623 | 2624 { |
17693
efbe746f8fa8
eliminate octave_comment_buffer singleton
John W. Eaton <jwe@octave.org>
parents:
17673
diff
changeset
|
2625 octave_comment_list *tc = lexer.comment_buf.get_comment (); |
3665 | 2626 |
1623 | 2627 int l = unwind_tok->line (); |
2628 int c = unwind_tok->column (); | |
2629 | |
16136
ed36d5543b27
don't declare octave_parser member functions static
John W. Eaton <jwe@octave.org>
parents:
16134
diff
changeset
|
2630 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
|
2631 lc, mc, tc, l, c); |
1623 | 2632 } |
17632
bd0a84de3375
further reduce memory leaks from parse errors (bug #40231)
John W. Eaton <jwe@octave.org>
parents:
17629
diff
changeset
|
2633 else |
bd0a84de3375
further reduce memory leaks from parse errors (bug #40231)
John W. Eaton <jwe@octave.org>
parents:
17629
diff
changeset
|
2634 { |
bd0a84de3375
further reduce memory leaks from parse errors (bug #40231)
John W. Eaton <jwe@octave.org>
parents:
17629
diff
changeset
|
2635 delete body; |
bd0a84de3375
further reduce memory leaks from parse errors (bug #40231)
John W. Eaton <jwe@octave.org>
parents:
17629
diff
changeset
|
2636 delete cleanup_stmts; |
bd0a84de3375
further reduce memory leaks from parse errors (bug #40231)
John W. Eaton <jwe@octave.org>
parents:
17629
diff
changeset
|
2637 } |
1623 | 2638 |
2639 return retval; | |
2640 } | |
2641 | |
2642 // Build a try-catch command. | |
2643 | |
16134
ec9c6222ef5a
move static parser helper functions to octave_parser class
John W. Eaton <jwe@octave.org>
parents:
16133
diff
changeset
|
2644 tree_command * |
16287
04a7953496a7
create base class for parser; use reference for curr_lexer
John W. Eaton <jwe@octave.org>
parents:
16285
diff
changeset
|
2645 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
|
2646 tree_statement_list *body, |
17283
e6c0ac8ce5b6
eliminate parse conflicts introduced by changeset 923ce8b42db2
John W. Eaton <jwe@octave.org>
parents:
17281
diff
changeset
|
2647 char catch_sep, |
16287
04a7953496a7
create base class for parser; use reference for curr_lexer
John W. Eaton <jwe@octave.org>
parents:
16285
diff
changeset
|
2648 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
|
2649 token *end_tok, |
04a7953496a7
create base class for parser; use reference for curr_lexer
John W. Eaton <jwe@octave.org>
parents:
16285
diff
changeset
|
2650 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
|
2651 octave_comment_list *mc) |
1623 | 2652 { |
2653 tree_command *retval = 0; | |
2654 | |
2857 | 2655 if (end_token_ok (end_tok, token::try_catch_end)) |
1623 | 2656 { |
17693
efbe746f8fa8
eliminate octave_comment_buffer singleton
John W. Eaton <jwe@octave.org>
parents:
17673
diff
changeset
|
2657 octave_comment_list *tc = lexer.comment_buf.get_comment (); |
3665 | 2658 |
1623 | 2659 int l = try_tok->line (); |
2660 int c = try_tok->column (); | |
2661 | |
17283
e6c0ac8ce5b6
eliminate parse conflicts introduced by changeset 923ce8b42db2
John W. Eaton <jwe@octave.org>
parents:
17281
diff
changeset
|
2662 tree_identifier *id = 0; |
e6c0ac8ce5b6
eliminate parse conflicts introduced by changeset 923ce8b42db2
John W. Eaton <jwe@octave.org>
parents:
17281
diff
changeset
|
2663 |
e6c0ac8ce5b6
eliminate parse conflicts introduced by changeset 923ce8b42db2
John W. Eaton <jwe@octave.org>
parents:
17281
diff
changeset
|
2664 if (! catch_sep && cleanup_stmts && ! cleanup_stmts->empty ()) |
e6c0ac8ce5b6
eliminate parse conflicts introduced by changeset 923ce8b42db2
John W. Eaton <jwe@octave.org>
parents:
17281
diff
changeset
|
2665 { |
e6c0ac8ce5b6
eliminate parse conflicts introduced by changeset 923ce8b42db2
John W. Eaton <jwe@octave.org>
parents:
17281
diff
changeset
|
2666 tree_statement *stmt = cleanup_stmts->front (); |
e6c0ac8ce5b6
eliminate parse conflicts introduced by changeset 923ce8b42db2
John W. Eaton <jwe@octave.org>
parents:
17281
diff
changeset
|
2667 |
e6c0ac8ce5b6
eliminate parse conflicts introduced by changeset 923ce8b42db2
John W. Eaton <jwe@octave.org>
parents:
17281
diff
changeset
|
2668 if (stmt) |
e6c0ac8ce5b6
eliminate parse conflicts introduced by changeset 923ce8b42db2
John W. Eaton <jwe@octave.org>
parents:
17281
diff
changeset
|
2669 { |
e6c0ac8ce5b6
eliminate parse conflicts introduced by changeset 923ce8b42db2
John W. Eaton <jwe@octave.org>
parents:
17281
diff
changeset
|
2670 tree_expression *expr = stmt->expression (); |
e6c0ac8ce5b6
eliminate parse conflicts introduced by changeset 923ce8b42db2
John W. Eaton <jwe@octave.org>
parents:
17281
diff
changeset
|
2671 |
e6c0ac8ce5b6
eliminate parse conflicts introduced by changeset 923ce8b42db2
John W. Eaton <jwe@octave.org>
parents:
17281
diff
changeset
|
2672 if (expr && expr->is_identifier ()) |
e6c0ac8ce5b6
eliminate parse conflicts introduced by changeset 923ce8b42db2
John W. Eaton <jwe@octave.org>
parents:
17281
diff
changeset
|
2673 { |
e6c0ac8ce5b6
eliminate parse conflicts introduced by changeset 923ce8b42db2
John W. Eaton <jwe@octave.org>
parents:
17281
diff
changeset
|
2674 id = dynamic_cast<tree_identifier *> (expr); |
e6c0ac8ce5b6
eliminate parse conflicts introduced by changeset 923ce8b42db2
John W. Eaton <jwe@octave.org>
parents:
17281
diff
changeset
|
2675 |
e6c0ac8ce5b6
eliminate parse conflicts introduced by changeset 923ce8b42db2
John W. Eaton <jwe@octave.org>
parents:
17281
diff
changeset
|
2676 cleanup_stmts->pop_front (); |
17673
9f6e4e5c2bac
avoid memory leak in parser (bug #40231)
John W. Eaton <jwe@octave.org>
parents:
17658
diff
changeset
|
2677 |
9f6e4e5c2bac
avoid memory leak in parser (bug #40231)
John W. Eaton <jwe@octave.org>
parents:
17658
diff
changeset
|
2678 stmt->set_expression (0); |
9f6e4e5c2bac
avoid memory leak in parser (bug #40231)
John W. Eaton <jwe@octave.org>
parents:
17658
diff
changeset
|
2679 delete stmt; |
17283
e6c0ac8ce5b6
eliminate parse conflicts introduced by changeset 923ce8b42db2
John W. Eaton <jwe@octave.org>
parents:
17281
diff
changeset
|
2680 } |
e6c0ac8ce5b6
eliminate parse conflicts introduced by changeset 923ce8b42db2
John W. Eaton <jwe@octave.org>
parents:
17281
diff
changeset
|
2681 } |
e6c0ac8ce5b6
eliminate parse conflicts introduced by changeset 923ce8b42db2
John W. Eaton <jwe@octave.org>
parents:
17281
diff
changeset
|
2682 } |
e6c0ac8ce5b6
eliminate parse conflicts introduced by changeset 923ce8b42db2
John W. Eaton <jwe@octave.org>
parents:
17281
diff
changeset
|
2683 |
17249
923ce8b42db2
improve try-catch-statement to save exception to a variable (bug #33217)
Stefan Mahr <dac922@gmx.de>
parents:
17170
diff
changeset
|
2684 retval = new tree_try_catch_command (body, cleanup_stmts, id, |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
2685 lc, mc, tc, l, c); |
1623 | 2686 } |
17632
bd0a84de3375
further reduce memory leaks from parse errors (bug #40231)
John W. Eaton <jwe@octave.org>
parents:
17629
diff
changeset
|
2687 else |
bd0a84de3375
further reduce memory leaks from parse errors (bug #40231)
John W. Eaton <jwe@octave.org>
parents:
17629
diff
changeset
|
2688 { |
bd0a84de3375
further reduce memory leaks from parse errors (bug #40231)
John W. Eaton <jwe@octave.org>
parents:
17629
diff
changeset
|
2689 delete body; |
bd0a84de3375
further reduce memory leaks from parse errors (bug #40231)
John W. Eaton <jwe@octave.org>
parents:
17629
diff
changeset
|
2690 delete cleanup_stmts; |
bd0a84de3375
further reduce memory leaks from parse errors (bug #40231)
John W. Eaton <jwe@octave.org>
parents:
17629
diff
changeset
|
2691 } |
1623 | 2692 |
2693 return retval; | |
2694 } | |
2695 | |
2696 // Build a while command. | |
2697 | |
16134
ec9c6222ef5a
move static parser helper functions to octave_parser class
John W. Eaton <jwe@octave.org>
parents:
16133
diff
changeset
|
2698 tree_command * |
16287
04a7953496a7
create base class for parser; use reference for curr_lexer
John W. Eaton <jwe@octave.org>
parents:
16285
diff
changeset
|
2699 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
|
2700 tree_expression *expr, |
04a7953496a7
create base class for parser; use reference for curr_lexer
John W. Eaton <jwe@octave.org>
parents:
16285
diff
changeset
|
2701 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
|
2702 token *end_tok, |
04a7953496a7
create base class for parser; use reference for curr_lexer
John W. Eaton <jwe@octave.org>
parents:
16285
diff
changeset
|
2703 octave_comment_list *lc) |
1623 | 2704 { |
2705 tree_command *retval = 0; | |
2706 | |
2707 maybe_warn_assign_as_truth_value (expr); | |
2708 | |
2857 | 2709 if (end_token_ok (end_tok, token::while_end)) |
1623 | 2710 { |
17693
efbe746f8fa8
eliminate octave_comment_buffer singleton
John W. Eaton <jwe@octave.org>
parents:
17673
diff
changeset
|
2711 octave_comment_list *tc = lexer.comment_buf.get_comment (); |
3665 | 2712 |
16288
fe3b9a51e625
rename curr_lexer, curr_parser, CURR_LEXER
John W. Eaton <jwe@octave.org>
parents:
16287
diff
changeset
|
2713 lexer.looping--; |
1623 | 2714 |
2715 int l = while_tok->line (); | |
2716 int c = while_tok->column (); | |
2717 | |
3665 | 2718 retval = new tree_while_command (expr, body, lc, tc, l, c); |
1623 | 2719 } |
17632
bd0a84de3375
further reduce memory leaks from parse errors (bug #40231)
John W. Eaton <jwe@octave.org>
parents:
17629
diff
changeset
|
2720 else |
bd0a84de3375
further reduce memory leaks from parse errors (bug #40231)
John W. Eaton <jwe@octave.org>
parents:
17629
diff
changeset
|
2721 { |
bd0a84de3375
further reduce memory leaks from parse errors (bug #40231)
John W. Eaton <jwe@octave.org>
parents:
17629
diff
changeset
|
2722 delete expr; |
bd0a84de3375
further reduce memory leaks from parse errors (bug #40231)
John W. Eaton <jwe@octave.org>
parents:
17629
diff
changeset
|
2723 delete body; |
bd0a84de3375
further reduce memory leaks from parse errors (bug #40231)
John W. Eaton <jwe@octave.org>
parents:
17629
diff
changeset
|
2724 } |
1623 | 2725 |
2726 return retval; | |
2727 } | |
2728 | |
3484 | 2729 // Build a do-until command. |
2730 | |
16134
ec9c6222ef5a
move static parser helper functions to octave_parser class
John W. Eaton <jwe@octave.org>
parents:
16133
diff
changeset
|
2731 tree_command * |
16287
04a7953496a7
create base class for parser; use reference for curr_lexer
John W. Eaton <jwe@octave.org>
parents:
16285
diff
changeset
|
2732 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
|
2733 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
|
2734 tree_expression *expr, |
04a7953496a7
create base class for parser; use reference for curr_lexer
John W. Eaton <jwe@octave.org>
parents:
16285
diff
changeset
|
2735 octave_comment_list *lc) |
3484 | 2736 { |
2737 maybe_warn_assign_as_truth_value (expr); | |
2738 | |
17693
efbe746f8fa8
eliminate octave_comment_buffer singleton
John W. Eaton <jwe@octave.org>
parents:
17673
diff
changeset
|
2739 octave_comment_list *tc = lexer.comment_buf.get_comment (); |
3665 | 2740 |
16288
fe3b9a51e625
rename curr_lexer, curr_parser, CURR_LEXER
John W. Eaton <jwe@octave.org>
parents:
16287
diff
changeset
|
2741 lexer.looping--; |
3484 | 2742 |
8658
73c4516fae10
New evaluator and debugger derived from tree-walker class
John W. Eaton <jwe@octave.org>
parents:
8471
diff
changeset
|
2743 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
|
2744 int c = until_tok->column (); |
3484 | 2745 |
17632
bd0a84de3375
further reduce memory leaks from parse errors (bug #40231)
John W. Eaton <jwe@octave.org>
parents:
17629
diff
changeset
|
2746 return new tree_do_until_command (expr, body, lc, tc, l, c); |
3484 | 2747 } |
2748 | |
1623 | 2749 // Build a for command. |
2750 | |
16134
ec9c6222ef5a
move static parser helper functions to octave_parser class
John W. Eaton <jwe@octave.org>
parents:
16133
diff
changeset
|
2751 tree_command * |
16287
04a7953496a7
create base class for parser; use reference for curr_lexer
John W. Eaton <jwe@octave.org>
parents:
16285
diff
changeset
|
2752 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
|
2753 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
|
2754 tree_expression *expr, |
04a7953496a7
create base class for parser; use reference for curr_lexer
John W. Eaton <jwe@octave.org>
parents:
16285
diff
changeset
|
2755 tree_expression *maxproc, |
04a7953496a7
create base class for parser; use reference for curr_lexer
John W. Eaton <jwe@octave.org>
parents:
16285
diff
changeset
|
2756 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
|
2757 token *end_tok, |
04a7953496a7
create base class for parser; use reference for curr_lexer
John W. Eaton <jwe@octave.org>
parents:
16285
diff
changeset
|
2758 octave_comment_list *lc) |
1623 | 2759 { |
2760 tree_command *retval = 0; | |
2761 | |
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
|
2762 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
|
2763 |
027a2186cd90
parfor keyword and infrastructure, but handle parfor as normal for loop for now
John W. Eaton <jwe@octave.org>
parents:
13241
diff
changeset
|
2764 if (end_token_ok (end_tok, parfor ? token::parfor_end : token::for_end)) |
1623 | 2765 { |
19428
b39cbe9f3bb0
allow ranges to be disabled
John W. Eaton <jwe@octave.org>
parents:
19010
diff
changeset
|
2766 expr->mark_as_for_cmd_expr (); |
b39cbe9f3bb0
allow ranges to be disabled
John W. Eaton <jwe@octave.org>
parents:
19010
diff
changeset
|
2767 |
17693
efbe746f8fa8
eliminate octave_comment_buffer singleton
John W. Eaton <jwe@octave.org>
parents:
17673
diff
changeset
|
2768 octave_comment_list *tc = lexer.comment_buf.get_comment (); |
3665 | 2769 |
16288
fe3b9a51e625
rename curr_lexer, curr_parser, CURR_LEXER
John W. Eaton <jwe@octave.org>
parents:
16287
diff
changeset
|
2770 lexer.looping--; |
1623 | 2771 |
2772 int l = for_tok->line (); | |
2773 int c = for_tok->column (); | |
2774 | |
2970 | 2775 if (lhs->length () == 1) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
2776 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
2777 tree_expression *tmp = lhs->remove_front (); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
2778 |
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
|
2779 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
|
2780 body, lc, tc, l, c); |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
2781 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
2782 delete lhs; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
2783 } |
2970 | 2784 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
|
2785 { |
027a2186cd90
parfor keyword and infrastructure, but handle parfor as normal for loop for now
John W. Eaton <jwe@octave.org>
parents:
13241
diff
changeset
|
2786 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
|
2787 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
|
2788 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
|
2789 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
|
2790 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
|
2791 } |
1623 | 2792 } |
17632
bd0a84de3375
further reduce memory leaks from parse errors (bug #40231)
John W. Eaton <jwe@octave.org>
parents:
17629
diff
changeset
|
2793 else |
bd0a84de3375
further reduce memory leaks from parse errors (bug #40231)
John W. Eaton <jwe@octave.org>
parents:
17629
diff
changeset
|
2794 { |
bd0a84de3375
further reduce memory leaks from parse errors (bug #40231)
John W. Eaton <jwe@octave.org>
parents:
17629
diff
changeset
|
2795 delete lhs; |
bd0a84de3375
further reduce memory leaks from parse errors (bug #40231)
John W. Eaton <jwe@octave.org>
parents:
17629
diff
changeset
|
2796 delete expr; |
bd0a84de3375
further reduce memory leaks from parse errors (bug #40231)
John W. Eaton <jwe@octave.org>
parents:
17629
diff
changeset
|
2797 delete maxproc; |
bd0a84de3375
further reduce memory leaks from parse errors (bug #40231)
John W. Eaton <jwe@octave.org>
parents:
17629
diff
changeset
|
2798 delete body; |
bd0a84de3375
further reduce memory leaks from parse errors (bug #40231)
John W. Eaton <jwe@octave.org>
parents:
17629
diff
changeset
|
2799 } |
1623 | 2800 |
2801 return retval; | |
2802 } | |
2803 | |
4207 | 2804 // Build a break command. |
2805 | |
16134
ec9c6222ef5a
move static parser helper functions to octave_parser class
John W. Eaton <jwe@octave.org>
parents:
16133
diff
changeset
|
2806 tree_command * |
16287
04a7953496a7
create base class for parser; use reference for curr_lexer
John W. Eaton <jwe@octave.org>
parents:
16285
diff
changeset
|
2807 octave_base_parser::make_break_command (token *break_tok) |
1623 | 2808 { |
2620 | 2809 int l = break_tok->line (); |
2810 int c = break_tok->column (); | |
2811 | |
17632
bd0a84de3375
further reduce memory leaks from parse errors (bug #40231)
John W. Eaton <jwe@octave.org>
parents:
17629
diff
changeset
|
2812 return new tree_break_command (l, c); |
1623 | 2813 } |
2814 | |
4207 | 2815 // Build a continue command. |
2816 | |
16134
ec9c6222ef5a
move static parser helper functions to octave_parser class
John W. Eaton <jwe@octave.org>
parents:
16133
diff
changeset
|
2817 tree_command * |
16287
04a7953496a7
create base class for parser; use reference for curr_lexer
John W. Eaton <jwe@octave.org>
parents:
16285
diff
changeset
|
2818 octave_base_parser::make_continue_command (token *continue_tok) |
1623 | 2819 { |
2620 | 2820 int l = continue_tok->line (); |
2821 int c = continue_tok->column (); | |
2822 | |
17632
bd0a84de3375
further reduce memory leaks from parse errors (bug #40231)
John W. Eaton <jwe@octave.org>
parents:
17629
diff
changeset
|
2823 return new tree_continue_command (l, c); |
1623 | 2824 } |
2825 | |
4207 | 2826 // Build a return command. |
2827 | |
16134
ec9c6222ef5a
move static parser helper functions to octave_parser class
John W. Eaton <jwe@octave.org>
parents:
16133
diff
changeset
|
2828 tree_command * |
16287
04a7953496a7
create base class for parser; use reference for curr_lexer
John W. Eaton <jwe@octave.org>
parents:
16285
diff
changeset
|
2829 octave_base_parser::make_return_command (token *return_tok) |
1623 | 2830 { |
2620 | 2831 int l = return_tok->line (); |
2832 int c = return_tok->column (); | |
2833 | |
17632
bd0a84de3375
further reduce memory leaks from parse errors (bug #40231)
John W. Eaton <jwe@octave.org>
parents:
17629
diff
changeset
|
2834 return new tree_return_command (l, c); |
1623 | 2835 } |
2836 | |
2837 // Start an if command. | |
2838 | |
16134
ec9c6222ef5a
move static parser helper functions to octave_parser class
John W. Eaton <jwe@octave.org>
parents:
16133
diff
changeset
|
2839 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
|
2840 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
|
2841 tree_statement_list *list) |
1623 | 2842 { |
2843 maybe_warn_assign_as_truth_value (expr); | |
2844 | |
2845 tree_if_clause *t = new tree_if_clause (expr, list); | |
2846 | |
2847 return new tree_if_command_list (t); | |
2848 } | |
2849 | |
2850 // Finish an if command. | |
2851 | |
16134
ec9c6222ef5a
move static parser helper functions to octave_parser class
John W. Eaton <jwe@octave.org>
parents:
16133
diff
changeset
|
2852 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
|
2853 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
|
2854 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
|
2855 token *end_tok, |
04a7953496a7
create base class for parser; use reference for curr_lexer
John W. Eaton <jwe@octave.org>
parents:
16285
diff
changeset
|
2856 octave_comment_list *lc) |
1623 | 2857 { |
2858 tree_if_command *retval = 0; | |
2859 | |
2857 | 2860 if (end_token_ok (end_tok, token::if_end)) |
1623 | 2861 { |
17693
efbe746f8fa8
eliminate octave_comment_buffer singleton
John W. Eaton <jwe@octave.org>
parents:
17673
diff
changeset
|
2862 octave_comment_list *tc = lexer.comment_buf.get_comment (); |
3665 | 2863 |
1623 | 2864 int l = if_tok->line (); |
2865 int c = if_tok->column (); | |
2866 | |
8842
be7b30a24938
line/column info for switch and if statements
John W. Eaton <jwe@octave.org>
parents:
8828
diff
changeset
|
2867 if (list && ! list->empty ()) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
2868 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
2869 tree_if_clause *elt = list->front (); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
2870 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
2871 if (elt) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
2872 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
2873 elt->line (l); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
2874 elt->column (c); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
2875 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
2876 } |
8842
be7b30a24938
line/column info for switch and if statements
John W. Eaton <jwe@octave.org>
parents:
8828
diff
changeset
|
2877 |
3665 | 2878 retval = new tree_if_command (list, lc, tc, l, c); |
1623 | 2879 } |
17632
bd0a84de3375
further reduce memory leaks from parse errors (bug #40231)
John W. Eaton <jwe@octave.org>
parents:
17629
diff
changeset
|
2880 else |
bd0a84de3375
further reduce memory leaks from parse errors (bug #40231)
John W. Eaton <jwe@octave.org>
parents:
17629
diff
changeset
|
2881 delete list; |
1623 | 2882 |
2883 return retval; | |
2884 } | |
2885 | |
2886 // Build an elseif clause. | |
2887 | |
16134
ec9c6222ef5a
move static parser helper functions to octave_parser class
John W. Eaton <jwe@octave.org>
parents:
16133
diff
changeset
|
2888 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
|
2889 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
|
2890 tree_expression *expr, |
04a7953496a7
create base class for parser; use reference for curr_lexer
John W. Eaton <jwe@octave.org>
parents:
16285
diff
changeset
|
2891 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
|
2892 octave_comment_list *lc) |
1623 | 2893 { |
2894 maybe_warn_assign_as_truth_value (expr); | |
2895 | |
8658
73c4516fae10
New evaluator and debugger derived from tree-walker class
John W. Eaton <jwe@octave.org>
parents:
8471
diff
changeset
|
2896 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
|
2897 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
|
2898 |
73c4516fae10
New evaluator and debugger derived from tree-walker class
John W. Eaton <jwe@octave.org>
parents:
8471
diff
changeset
|
2899 return new tree_if_clause (expr, list, lc, l, c); |
1623 | 2900 } |
2901 | |
2764 | 2902 // Finish a switch command. |
2903 | |
16134
ec9c6222ef5a
move static parser helper functions to octave_parser class
John W. Eaton <jwe@octave.org>
parents:
16133
diff
changeset
|
2904 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
|
2905 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
|
2906 tree_expression *expr, |
04a7953496a7
create base class for parser; use reference for curr_lexer
John W. Eaton <jwe@octave.org>
parents:
16285
diff
changeset
|
2907 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
|
2908 token *end_tok, |
04a7953496a7
create base class for parser; use reference for curr_lexer
John W. Eaton <jwe@octave.org>
parents:
16285
diff
changeset
|
2909 octave_comment_list *lc) |
2764 | 2910 { |
2911 tree_switch_command *retval = 0; | |
2912 | |
2857 | 2913 if (end_token_ok (end_tok, token::switch_end)) |
2764 | 2914 { |
17693
efbe746f8fa8
eliminate octave_comment_buffer singleton
John W. Eaton <jwe@octave.org>
parents:
17673
diff
changeset
|
2915 octave_comment_list *tc = lexer.comment_buf.get_comment (); |
3665 | 2916 |
2764 | 2917 int l = switch_tok->line (); |
2918 int c = switch_tok->column (); | |
2919 | |
8842
be7b30a24938
line/column info for switch and if statements
John W. Eaton <jwe@octave.org>
parents:
8828
diff
changeset
|
2920 if (list && ! list->empty ()) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
2921 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
2922 tree_switch_case *elt = list->front (); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
2923 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
2924 if (elt) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
2925 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
2926 elt->line (l); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
2927 elt->column (c); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
2928 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
2929 } |
8842
be7b30a24938
line/column info for switch and if statements
John W. Eaton <jwe@octave.org>
parents:
8828
diff
changeset
|
2930 |
3665 | 2931 retval = new tree_switch_command (expr, list, lc, tc, l, c); |
2764 | 2932 } |
17632
bd0a84de3375
further reduce memory leaks from parse errors (bug #40231)
John W. Eaton <jwe@octave.org>
parents:
17629
diff
changeset
|
2933 else |
bd0a84de3375
further reduce memory leaks from parse errors (bug #40231)
John W. Eaton <jwe@octave.org>
parents:
17629
diff
changeset
|
2934 { |
bd0a84de3375
further reduce memory leaks from parse errors (bug #40231)
John W. Eaton <jwe@octave.org>
parents:
17629
diff
changeset
|
2935 delete expr; |
bd0a84de3375
further reduce memory leaks from parse errors (bug #40231)
John W. Eaton <jwe@octave.org>
parents:
17629
diff
changeset
|
2936 delete list; |
bd0a84de3375
further reduce memory leaks from parse errors (bug #40231)
John W. Eaton <jwe@octave.org>
parents:
17629
diff
changeset
|
2937 } |
2764 | 2938 |
2939 return retval; | |
2940 } | |
2941 | |
2942 // Build a switch case. | |
2943 | |
16134
ec9c6222ef5a
move static parser helper functions to octave_parser class
John W. Eaton <jwe@octave.org>
parents:
16133
diff
changeset
|
2944 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
|
2945 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
|
2946 tree_expression *expr, |
04a7953496a7
create base class for parser; use reference for curr_lexer
John W. Eaton <jwe@octave.org>
parents:
16285
diff
changeset
|
2947 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
|
2948 octave_comment_list *lc) |
2764 | 2949 { |
2950 maybe_warn_variable_switch_label (expr); | |
2951 | |
8658
73c4516fae10
New evaluator and debugger derived from tree-walker class
John W. Eaton <jwe@octave.org>
parents:
8471
diff
changeset
|
2952 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
|
2953 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
|
2954 |
73c4516fae10
New evaluator and debugger derived from tree-walker class
John W. Eaton <jwe@octave.org>
parents:
8471
diff
changeset
|
2955 return new tree_switch_case (expr, list, lc, l, c); |
2764 | 2956 } |
2957 | |
1623 | 2958 // Build an assignment to a variable. |
2959 | |
16134
ec9c6222ef5a
move static parser helper functions to octave_parser class
John W. Eaton <jwe@octave.org>
parents:
16133
diff
changeset
|
2960 tree_expression * |
16287
04a7953496a7
create base class for parser; use reference for curr_lexer
John W. Eaton <jwe@octave.org>
parents:
16285
diff
changeset
|
2961 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
|
2962 token *eq_tok, tree_expression *rhs) |
1623 | 2963 { |
2970 | 2964 tree_expression *retval = 0; |
2965 | |
2883 | 2966 octave_value::assign_op t = octave_value::unknown_assign_op; |
2967 | |
2968 switch (op) | |
2969 { | |
2970 case '=': | |
3525 | 2971 t = octave_value::op_asn_eq; |
2883 | 2972 break; |
2973 | |
2974 case ADD_EQ: | |
3525 | 2975 t = octave_value::op_add_eq; |
2883 | 2976 break; |
2977 | |
2978 case SUB_EQ: | |
3525 | 2979 t = octave_value::op_sub_eq; |
2883 | 2980 break; |
2981 | |
2982 case MUL_EQ: | |
3525 | 2983 t = octave_value::op_mul_eq; |
2883 | 2984 break; |
2985 | |
2986 case DIV_EQ: | |
3525 | 2987 t = octave_value::op_div_eq; |
2883 | 2988 break; |
2989 | |
3204 | 2990 case LEFTDIV_EQ: |
3525 | 2991 t = octave_value::op_ldiv_eq; |
3204 | 2992 break; |
2993 | |
4018 | 2994 case POW_EQ: |
2995 t = octave_value::op_pow_eq; | |
2996 break; | |
2997 | |
2899 | 2998 case LSHIFT_EQ: |
3525 | 2999 t = octave_value::op_lshift_eq; |
2899 | 3000 break; |
3001 | |
3002 case RSHIFT_EQ: | |
3525 | 3003 t = octave_value::op_rshift_eq; |
2899 | 3004 break; |
3005 | |
2883 | 3006 case EMUL_EQ: |
3525 | 3007 t = octave_value::op_el_mul_eq; |
2883 | 3008 break; |
3009 | |
3010 case EDIV_EQ: | |
3525 | 3011 t = octave_value::op_el_div_eq; |
2883 | 3012 break; |
3013 | |
3204 | 3014 case ELEFTDIV_EQ: |
3525 | 3015 t = octave_value::op_el_ldiv_eq; |
3204 | 3016 break; |
3017 | |
4018 | 3018 case EPOW_EQ: |
3019 t = octave_value::op_el_pow_eq; | |
3020 break; | |
3021 | |
2883 | 3022 case AND_EQ: |
3525 | 3023 t = octave_value::op_el_and_eq; |
2883 | 3024 break; |
3025 | |
3026 case OR_EQ: | |
3525 | 3027 t = octave_value::op_el_or_eq; |
2883 | 3028 break; |
3029 | |
3030 default: | |
3031 panic_impossible (); | |
3032 break; | |
3033 } | |
3034 | |
1623 | 3035 int l = eq_tok->line (); |
3036 int c = eq_tok->column (); | |
3037 | |
5841 | 3038 if (lhs->is_simple_assign_lhs ()) |
666 | 3039 { |
2970 | 3040 tree_expression *tmp = lhs->remove_front (); |
3041 | |
3042 retval = new tree_simple_assignment (tmp, rhs, false, l, c, t); | |
3043 | |
3044 delete lhs; | |
666 | 3045 } |
10230
0a5a769b8fc0
disallow computed multiple assignment
Jaroslav Hajek <highegg@gmail.com>
parents:
10207
diff
changeset
|
3046 else if (t == octave_value::op_asn_eq) |
0a5a769b8fc0
disallow computed multiple assignment
Jaroslav Hajek <highegg@gmail.com>
parents:
10207
diff
changeset
|
3047 return new tree_multi_assignment (lhs, rhs, false, l, c); |
666 | 3048 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
|
3049 bison_error ("computed multiple assignment not allowed"); |
666 | 3050 |
3051 return retval; | |
3052 } | |
751 | 3053 |
9474
25ed2d6aacf6
Parse nested functions more accurately.
David Grundberg <individ@acc.umu.se>
parents:
9471
diff
changeset
|
3054 // Define a script. |
7715
5b4d278ec828
parse scripts completely before executing
John W. Eaton <jwe@octave.org>
parents:
7699
diff
changeset
|
3055 |
16134
ec9c6222ef5a
move static parser helper functions to octave_parser class
John W. Eaton <jwe@octave.org>
parents:
16133
diff
changeset
|
3056 void |
16287
04a7953496a7
create base class for parser; use reference for curr_lexer
John W. Eaton <jwe@octave.org>
parents:
16285
diff
changeset
|
3057 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
|
3058 tree_statement *end_script) |
7715
5b4d278ec828
parse scripts completely before executing
John W. Eaton <jwe@octave.org>
parents:
7699
diff
changeset
|
3059 { |
8658
73c4516fae10
New evaluator and debugger derived from tree-walker class
John W. Eaton <jwe@octave.org>
parents:
8471
diff
changeset
|
3060 if (! cmds) |
73c4516fae10
New evaluator and debugger derived from tree-walker class
John W. Eaton <jwe@octave.org>
parents:
8471
diff
changeset
|
3061 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
|
3062 |
73c4516fae10
New evaluator and debugger derived from tree-walker class
John W. Eaton <jwe@octave.org>
parents:
8471
diff
changeset
|
3063 cmds->append (end_script); |
73c4516fae10
New evaluator and debugger derived from tree-walker class
John W. Eaton <jwe@octave.org>
parents:
8471
diff
changeset
|
3064 |
7715
5b4d278ec828
parse scripts completely before executing
John W. Eaton <jwe@octave.org>
parents:
7699
diff
changeset
|
3065 octave_user_script *script |
16288
fe3b9a51e625
rename curr_lexer, curr_parser, CURR_LEXER
John W. Eaton <jwe@octave.org>
parents:
16287
diff
changeset
|
3066 = 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
|
3067 lexer.fcn_file_name, |
fe3b9a51e625
rename curr_lexer, curr_parser, CURR_LEXER
John W. Eaton <jwe@octave.org>
parents:
16287
diff
changeset
|
3068 cmds, lexer.help_text); |
fe3b9a51e625
rename curr_lexer, curr_parser, CURR_LEXER
John W. Eaton <jwe@octave.org>
parents:
16287
diff
changeset
|
3069 |
fe3b9a51e625
rename curr_lexer, curr_parser, CURR_LEXER
John W. Eaton <jwe@octave.org>
parents:
16287
diff
changeset
|
3070 lexer.help_text = ""; |
7715
5b4d278ec828
parse scripts completely before executing
John W. Eaton <jwe@octave.org>
parents:
7699
diff
changeset
|
3071 |
5b4d278ec828
parse scripts completely before executing
John W. Eaton <jwe@octave.org>
parents:
7699
diff
changeset
|
3072 octave_time now; |
5b4d278ec828
parse scripts completely before executing
John W. Eaton <jwe@octave.org>
parents:
7699
diff
changeset
|
3073 |
5b4d278ec828
parse scripts completely before executing
John W. Eaton <jwe@octave.org>
parents:
7699
diff
changeset
|
3074 script->stash_fcn_file_time (now); |
5b4d278ec828
parse scripts completely before executing
John W. Eaton <jwe@octave.org>
parents:
7699
diff
changeset
|
3075 |
9474
25ed2d6aacf6
Parse nested functions more accurately.
David Grundberg <individ@acc.umu.se>
parents:
9471
diff
changeset
|
3076 primary_fcn_ptr = script; |
7715
5b4d278ec828
parse scripts completely before executing
John W. Eaton <jwe@octave.org>
parents:
7699
diff
changeset
|
3077 } |
5b4d278ec828
parse scripts completely before executing
John W. Eaton <jwe@octave.org>
parents:
7699
diff
changeset
|
3078 |
1623 | 3079 // Begin defining a function. |
3080 | |
16134
ec9c6222ef5a
move static parser helper functions to octave_parser class
John W. Eaton <jwe@octave.org>
parents:
16133
diff
changeset
|
3081 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
|
3082 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
|
3083 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
|
3084 tree_statement *end_fcn_stmt) |
1623 | 3085 { |
2891 | 3086 // We'll fill in the return list later. |
3087 | |
8658
73c4516fae10
New evaluator and debugger derived from tree-walker class
John W. Eaton <jwe@octave.org>
parents:
8471
diff
changeset
|
3088 if (! body) |
73c4516fae10
New evaluator and debugger derived from tree-walker class
John W. Eaton <jwe@octave.org>
parents:
8471
diff
changeset
|
3089 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
|
3090 |
73c4516fae10
New evaluator and debugger derived from tree-walker class
John W. Eaton <jwe@octave.org>
parents:
8471
diff
changeset
|
3091 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
|
3092 |
2891 | 3093 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
|
3094 = 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
|
3095 param_list, 0, body); |
1623 | 3096 |
3665 | 3097 if (fcn) |
3098 { | |
17693
efbe746f8fa8
eliminate octave_comment_buffer singleton
John W. Eaton <jwe@octave.org>
parents:
17673
diff
changeset
|
3099 octave_comment_list *tc = lexer.comment_buf.get_comment (); |
3665 | 3100 |
3101 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
|
3102 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
|
3103 end_fcn_stmt->column ()); |
3665 | 3104 } |
3105 | |
1623 | 3106 return fcn; |
3107 } | |
3108 | |
16134
ec9c6222ef5a
move static parser helper functions to octave_parser class
John W. Eaton <jwe@octave.org>
parents:
16133
diff
changeset
|
3109 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
|
3110 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
|
3111 { |
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
|
3112 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
|
3113 } |
73c4516fae10
New evaluator and debugger derived from tree-walker class
John W. Eaton <jwe@octave.org>
parents:
8471
diff
changeset
|
3114 |
1623 | 3115 // Do most of the work for defining a function. |
3116 | |
16134
ec9c6222ef5a
move static parser helper functions to octave_parser class
John W. Eaton <jwe@octave.org>
parents:
16133
diff
changeset
|
3117 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
|
3118 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
|
3119 octave_user_function *fcn) |
1623 | 3120 { |
4872 | 3121 std::string id_name = fname; |
1623 | 3122 |
3123 // If input is coming from a file, issue a warning if the name of | |
3124 // the file does not match the name of the function stated in the | |
3125 // file. Matlab doesn't provide a diagnostic (it ignores the stated | |
3126 // name). | |
16288
fe3b9a51e625
rename curr_lexer, curr_parser, CURR_LEXER
John W. Eaton <jwe@octave.org>
parents:
16287
diff
changeset
|
3127 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
|
3128 && curr_fcn_depth == 1 && ! parsing_subfunctions) |
9474
25ed2d6aacf6
Parse nested functions more accurately.
David Grundberg <individ@acc.umu.se>
parents:
9471
diff
changeset
|
3129 { |
16288
fe3b9a51e625
rename curr_lexer, curr_parser, CURR_LEXER
John W. Eaton <jwe@octave.org>
parents:
16287
diff
changeset
|
3130 // 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
|
3131 // 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
|
3132 // problem with relative file names. |
25ed2d6aacf6
Parse nested functions more accurately.
David Grundberg <individ@acc.umu.se>
parents:
9471
diff
changeset
|
3133 |
16288
fe3b9a51e625
rename curr_lexer, curr_parser, CURR_LEXER
John W. Eaton <jwe@octave.org>
parents:
16287
diff
changeset
|
3134 std::string nm = lexer.fcn_file_name; |
9474
25ed2d6aacf6
Parse nested functions more accurately.
David Grundberg <individ@acc.umu.se>
parents:
9471
diff
changeset
|
3135 |
25ed2d6aacf6
Parse nested functions more accurately.
David Grundberg <individ@acc.umu.se>
parents:
9471
diff
changeset
|
3136 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
|
3137 |
25ed2d6aacf6
Parse nested functions more accurately.
David Grundberg <individ@acc.umu.se>
parents:
9471
diff
changeset
|
3138 if (pos != std::string::npos) |
16288
fe3b9a51e625
rename curr_lexer, curr_parser, CURR_LEXER
John W. Eaton <jwe@octave.org>
parents:
16287
diff
changeset
|
3139 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
|
3140 |
25ed2d6aacf6
Parse nested functions more accurately.
David Grundberg <individ@acc.umu.se>
parents:
9471
diff
changeset
|
3141 if (nm != id_name) |
25ed2d6aacf6
Parse nested functions more accurately.
David Grundberg <individ@acc.umu.se>
parents:
9471
diff
changeset
|
3142 { |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
3143 warning_with_id |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
3144 ("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
|
3145 "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
|
3146 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
|
3147 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
3148 id_name = nm; |
9474
25ed2d6aacf6
Parse nested functions more accurately.
David Grundberg <individ@acc.umu.se>
parents:
9471
diff
changeset
|
3149 } |
25ed2d6aacf6
Parse nested functions more accurately.
David Grundberg <individ@acc.umu.se>
parents:
9471
diff
changeset
|
3150 } |
1623 | 3151 |
16288
fe3b9a51e625
rename curr_lexer, curr_parser, CURR_LEXER
John W. Eaton <jwe@octave.org>
parents:
16287
diff
changeset
|
3152 if (lexer.reading_fcn_file || lexer.reading_classdef_file || autoloading) |
1623 | 3153 { |
3712 | 3154 octave_time now; |
3162 | 3155 |
16288
fe3b9a51e625
rename curr_lexer, curr_parser, CURR_LEXER
John W. Eaton <jwe@octave.org>
parents:
16287
diff
changeset
|
3156 fcn->stash_fcn_file_name (lexer.fcn_file_full_name); |
3162 | 3157 fcn->stash_fcn_file_time (now); |
1623 | 3158 fcn->mark_as_system_fcn_file (); |
3162 | 3159 |
6323 | 3160 if (fcn_file_from_relative_lookup) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
3161 fcn->mark_relative (); |
6323 | 3162 |
16153
a57c2c8c8163
move some variables into the octave_parser class
John W. Eaton <jwe@octave.org>
parents:
16151
diff
changeset
|
3163 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
|
3164 { |
16288
fe3b9a51e625
rename curr_lexer, curr_parser, CURR_LEXER
John W. Eaton <jwe@octave.org>
parents:
16287
diff
changeset
|
3165 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
|
3166 |
16153
a57c2c8c8163
move some variables into the octave_parser class
John W. Eaton <jwe@octave.org>
parents:
16151
diff
changeset
|
3167 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
|
3168 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
|
3169 else |
be18c9e359bf
Nested function support (bug #35772)
Max Brister <max@2bass.com>
parents:
14533
diff
changeset
|
3170 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
|
3171 } |
6323 | 3172 |
16288
fe3b9a51e625
rename curr_lexer, curr_parser, CURR_LEXER
John W. Eaton <jwe@octave.org>
parents:
16287
diff
changeset
|
3173 if (lexer.parsing_class_method) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
3174 { |
16153
a57c2c8c8163
move some variables into the octave_parser class
John W. Eaton <jwe@octave.org>
parents:
16151
diff
changeset
|
3175 if (curr_class_name == id_name) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
3176 fcn->mark_as_class_constructor (); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
3177 else |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
3178 fcn->mark_as_class_method (); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
3179 |
16153
a57c2c8c8163
move some variables into the octave_parser class
John W. Eaton <jwe@octave.org>
parents:
16151
diff
changeset
|
3180 fcn->stash_dispatch_class (curr_class_name); |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
3181 } |
7336 | 3182 |
5781 | 3183 std::string nm = fcn->fcn_file_name (); |
3184 | |
3185 file_stat fs (nm); | |
3186 | |
3187 if (fs && fs.is_newer (now)) | |
3188 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
|
3189 "time stamp for '%s' is in the future", nm.c_str ()); |
1623 | 3190 } |
16203
127cccb037bf
move more global parser and lexer variables to classes
John W. Eaton <jwe@octave.org>
parents:
16199
diff
changeset
|
3191 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
|
3192 && ! lexer.force_script |
fe3b9a51e625
rename curr_lexer, curr_parser, CURR_LEXER
John W. Eaton <jwe@octave.org>
parents:
16287
diff
changeset
|
3193 && lexer.reading_script_file |
fe3b9a51e625
rename curr_lexer, curr_parser, CURR_LEXER
John W. Eaton <jwe@octave.org>
parents:
16287
diff
changeset
|
3194 && lexer.fcn_file_name == id_name) |
1623 | 3195 { |
15466
d174210ce1ec
use ' instead of ` in error messages, warnings and most comments
John W. Eaton <jwe@octave.org>
parents:
14189
diff
changeset
|
3196 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
|
3197 id_name.c_str (), lexer.fcn_file_full_name.c_str ()); |
1623 | 3198 } |
3199 | |
4872 | 3200 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
|
3201 |
fe3b9a51e625
rename curr_lexer, curr_parser, CURR_LEXER
John W. Eaton <jwe@octave.org>
parents:
16287
diff
changeset
|
3202 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
|
3203 && ! parsing_subfunctions) |
7336 | 3204 { |
16288
fe3b9a51e625
rename curr_lexer, curr_parser, CURR_LEXER
John W. Eaton <jwe@octave.org>
parents:
16287
diff
changeset
|
3205 fcn->document (lexer.help_text); |
fe3b9a51e625
rename curr_lexer, curr_parser, CURR_LEXER
John W. Eaton <jwe@octave.org>
parents:
16287
diff
changeset
|
3206 |
fe3b9a51e625
rename curr_lexer, curr_parser, CURR_LEXER
John W. Eaton <jwe@octave.org>
parents:
16287
diff
changeset
|
3207 lexer.help_text = ""; |
7336 | 3208 } |
3209 | |
16288
fe3b9a51e625
rename curr_lexer, curr_parser, CURR_LEXER
John W. Eaton <jwe@octave.org>
parents:
16287
diff
changeset
|
3210 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
|
3211 && ! parsing_subfunctions) |
25ed2d6aacf6
Parse nested functions more accurately.
David Grundberg <individ@acc.umu.se>
parents:
9471
diff
changeset
|
3212 primary_fcn_ptr = fcn; |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11572
diff
changeset
|
3213 |
1623 | 3214 return fcn; |
3215 } | |
3216 | |
16134
ec9c6222ef5a
move static parser helper functions to octave_parser class
John W. Eaton <jwe@octave.org>
parents:
16133
diff
changeset
|
3217 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
|
3218 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
|
3219 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
|
3220 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
|
3221 int l, int c) |
1623 | 3222 { |
7715
5b4d278ec828
parse scripts completely before executing
John W. Eaton <jwe@octave.org>
parents:
7699
diff
changeset
|
3223 tree_function_def *retval = 0; |
5b4d278ec828
parse scripts completely before executing
John W. Eaton <jwe@octave.org>
parents:
7699
diff
changeset
|
3224 |
5b4d278ec828
parse scripts completely before executing
John W. Eaton <jwe@octave.org>
parents:
7699
diff
changeset
|
3225 if (ret_list) |
5b4d278ec828
parse scripts completely before executing
John W. Eaton <jwe@octave.org>
parents:
7699
diff
changeset
|
3226 ret_list->mark_as_formal_parameters (); |
5b4d278ec828
parse scripts completely before executing
John W. Eaton <jwe@octave.org>
parents:
7699
diff
changeset
|
3227 |
5b4d278ec828
parse scripts completely before executing
John W. Eaton <jwe@octave.org>
parents:
7699
diff
changeset
|
3228 if (fcn) |
5b4d278ec828
parse scripts completely before executing
John W. Eaton <jwe@octave.org>
parents:
7699
diff
changeset
|
3229 { |
7761
5adeea5de26c
symbol table reporting functions
John W. Eaton <jwe@octave.org>
parents:
7755
diff
changeset
|
3230 std::string nm = fcn->name (); |
5adeea5de26c
symbol table reporting functions
John W. Eaton <jwe@octave.org>
parents:
7755
diff
changeset
|
3231 std::string file = fcn->fcn_file_name (); |
5adeea5de26c
symbol table reporting functions
John W. Eaton <jwe@octave.org>
parents:
7755
diff
changeset
|
3232 |
5adeea5de26c
symbol table reporting functions
John W. Eaton <jwe@octave.org>
parents:
7755
diff
changeset
|
3233 std::string tmp = nm; |
5adeea5de26c
symbol table reporting functions
John W. Eaton <jwe@octave.org>
parents:
7755
diff
changeset
|
3234 if (! file.empty ()) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
3235 tmp += ": " + file; |
7761
5adeea5de26c
symbol table reporting functions
John W. Eaton <jwe@octave.org>
parents:
7755
diff
changeset
|
3236 |
5adeea5de26c
symbol table reporting functions
John W. Eaton <jwe@octave.org>
parents:
7755
diff
changeset
|
3237 symbol_table::cache_name (fcn->scope (), tmp); |
5adeea5de26c
symbol table reporting functions
John W. Eaton <jwe@octave.org>
parents:
7755
diff
changeset
|
3238 |
7715
5b4d278ec828
parse scripts completely before executing
John W. Eaton <jwe@octave.org>
parents:
7699
diff
changeset
|
3239 if (lc) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
3240 fcn->stash_leading_comment (lc); |
7715
5b4d278ec828
parse scripts completely before executing
John W. Eaton <jwe@octave.org>
parents:
7699
diff
changeset
|
3241 |
5b4d278ec828
parse scripts completely before executing
John W. Eaton <jwe@octave.org>
parents:
7699
diff
changeset
|
3242 fcn->define_ret_list (ret_list); |
7755
ea9cb4d68dbf
avoid installing subfunctions twice
John W. Eaton <jwe@octave.org>
parents:
7750
diff
changeset
|
3243 |
16153
a57c2c8c8163
move some variables into the octave_parser class
John W. Eaton <jwe@octave.org>
parents:
16151
diff
changeset
|
3244 if (curr_fcn_depth > 1 || parsing_subfunctions) |
9474
25ed2d6aacf6
Parse nested functions more accurately.
David Grundberg <individ@acc.umu.se>
parents:
9471
diff
changeset
|
3245 { |
11461
2b8531a6a3c9
Change mentions of "nested function" to the less misleading "subfunction"
David Grundberg <individ@acc.umu.se>
parents:
11388
diff
changeset
|
3246 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
|
3247 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
|
3248 |
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
|
3249 subfunction_names.push_back (nm); |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
3250 |
14544
be18c9e359bf
Nested function support (bug #35772)
Max Brister <max@2bass.com>
parents:
14533
diff
changeset
|
3251 if (endfunction_found && function_scopes.size () > 1) |
be18c9e359bf
Nested function support (bug #35772)
Max Brister <max@2bass.com>
parents:
14533
diff
changeset
|
3252 { |
be18c9e359bf
Nested function support (bug #35772)
Max Brister <max@2bass.com>
parents:
14533
diff
changeset
|
3253 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
|
3254 = function_scopes[function_scopes.size ()-2]; |
14544
be18c9e359bf
Nested function support (bug #35772)
Max Brister <max@2bass.com>
parents:
14533
diff
changeset
|
3255 |
be18c9e359bf
Nested function support (bug #35772)
Max Brister <max@2bass.com>
parents:
14533
diff
changeset
|
3256 symbol_table::install_nestfunction (nm, octave_value (fcn), |
be18c9e359bf
Nested function support (bug #35772)
Max Brister <max@2bass.com>
parents:
14533
diff
changeset
|
3257 pscope); |
be18c9e359bf
Nested function support (bug #35772)
Max Brister <max@2bass.com>
parents:
14533
diff
changeset
|
3258 } |
be18c9e359bf
Nested function support (bug #35772)
Max Brister <max@2bass.com>
parents:
14533
diff
changeset
|
3259 else |
be18c9e359bf
Nested function support (bug #35772)
Max Brister <max@2bass.com>
parents:
14533
diff
changeset
|
3260 symbol_table::install_subfunction (nm, octave_value (fcn), |
be18c9e359bf
Nested function support (bug #35772)
Max Brister <max@2bass.com>
parents:
14533
diff
changeset
|
3261 primary_fcn_scope); |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
3262 } |
9474
25ed2d6aacf6
Parse nested functions more accurately.
David Grundberg <individ@acc.umu.se>
parents:
9471
diff
changeset
|
3263 |
16153
a57c2c8c8163
move some variables into the octave_parser class
John W. Eaton <jwe@octave.org>
parents:
16151
diff
changeset
|
3264 if (curr_fcn_depth == 1 && fcn) |
14544
be18c9e359bf
Nested function support (bug #35772)
Max Brister <max@2bass.com>
parents:
14533
diff
changeset
|
3265 symbol_table::update_nest (fcn->scope ()); |
be18c9e359bf
Nested function support (bug #35772)
Max Brister <max@2bass.com>
parents:
14533
diff
changeset
|
3266 |
16288
fe3b9a51e625
rename curr_lexer, curr_parser, CURR_LEXER
John W. Eaton <jwe@octave.org>
parents:
16287
diff
changeset
|
3267 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
|
3268 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
3269 // 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
|
3270 // 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
|
3271 // 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
|
3272 // 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
|
3273 // 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
|
3274 // 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
|
3275 // 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
|
3276 // parse_fcn_file, and |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
3277 // 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
|
3278 |
5f8971be8e12
parse.y (finish_function): retrun function object unless parsing function file
John W. Eaton <jwe@octave.org>
parents:
9506
diff
changeset
|
3279 retval = new tree_function_def (fcn); |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
3280 } |
7715
5b4d278ec828
parse scripts completely before executing
John W. Eaton <jwe@octave.org>
parents:
7699
diff
changeset
|
3281 } |
5b4d278ec828
parse scripts completely before executing
John W. Eaton <jwe@octave.org>
parents:
7699
diff
changeset
|
3282 |
5b4d278ec828
parse scripts completely before executing
John W. Eaton <jwe@octave.org>
parents:
7699
diff
changeset
|
3283 return retval; |
1623 | 3284 } |
3285 | |
16134
ec9c6222ef5a
move static parser helper functions to octave_parser class
John W. Eaton <jwe@octave.org>
parents:
16133
diff
changeset
|
3286 void |
16287
04a7953496a7
create base class for parser; use reference for curr_lexer
John W. Eaton <jwe@octave.org>
parents:
16285
diff
changeset
|
3287 octave_base_parser::recover_from_parsing_function (void) |
2883 | 3288 { |
16320
09f0cb9cac7d
don't modify symbol table scope in the parser
John W. Eaton <jwe@octave.org>
parents:
16302
diff
changeset
|
3289 lexer.symtab_context.pop (); |
2883 | 3290 |
16288
fe3b9a51e625
rename curr_lexer, curr_parser, CURR_LEXER
John W. Eaton <jwe@octave.org>
parents:
16287
diff
changeset
|
3291 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
|
3292 && ! parsing_subfunctions) |
25ed2d6aacf6
Parse nested functions more accurately.
David Grundberg <individ@acc.umu.se>
parents:
9471
diff
changeset
|
3293 parsing_subfunctions = true; |
25ed2d6aacf6
Parse nested functions more accurately.
David Grundberg <individ@acc.umu.se>
parents:
9471
diff
changeset
|
3294 |
16153
a57c2c8c8163
move some variables into the octave_parser class
John W. Eaton <jwe@octave.org>
parents:
16151
diff
changeset
|
3295 curr_fcn_depth--; |
14544
be18c9e359bf
Nested function support (bug #35772)
Max Brister <max@2bass.com>
parents:
14533
diff
changeset
|
3296 function_scopes.pop_back (); |
9474
25ed2d6aacf6
Parse nested functions more accurately.
David Grundberg <individ@acc.umu.se>
parents:
9471
diff
changeset
|
3297 |
16288
fe3b9a51e625
rename curr_lexer, curr_parser, CURR_LEXER
John W. Eaton <jwe@octave.org>
parents:
16287
diff
changeset
|
3298 lexer.defining_func--; |
fe3b9a51e625
rename curr_lexer, curr_parser, CURR_LEXER
John W. Eaton <jwe@octave.org>
parents:
16287
diff
changeset
|
3299 lexer.parsed_function_name.pop (); |
fe3b9a51e625
rename curr_lexer, curr_parser, CURR_LEXER
John W. Eaton <jwe@octave.org>
parents:
16287
diff
changeset
|
3300 lexer.looking_at_return_list = false; |
fe3b9a51e625
rename curr_lexer, curr_parser, CURR_LEXER
John W. Eaton <jwe@octave.org>
parents:
16287
diff
changeset
|
3301 lexer.looking_at_parameter_list = false; |
2883 | 3302 } |
3303 | |
16155
0259254a3ccc
maint: periodic merge of default to classdef
John W. Eaton <jwe@octave.org>
diff
changeset
|
3304 tree_funcall * |
16289
bde729ba8381
maint: periodic merge of default to classdef
John W. Eaton <jwe@octave.org>
diff
changeset
|
3305 octave_base_parser::make_superclass_ref (const std::string& method_nm, |
18961
09eb8a2ddb02
eliminate some unused parameter warnings in parser functions
John W. Eaton <jwe@octave.org>
parents:
18537
diff
changeset
|
3306 const std::string& class_nm) |
16155
0259254a3ccc
maint: periodic merge of default to classdef
John W. Eaton <jwe@octave.org>
diff
changeset
|
3307 { |
0259254a3ccc
maint: periodic merge of default to classdef
John W. Eaton <jwe@octave.org>
diff
changeset
|
3308 octave_value_list args; |
0259254a3ccc
maint: periodic merge of default to classdef
John W. Eaton <jwe@octave.org>
diff
changeset
|
3309 |
18520
932aca9a7c57
Allow multi-level classdef package.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
18419
diff
changeset
|
3310 args(1) = class_nm; |
16155
0259254a3ccc
maint: periodic merge of default to classdef
John W. Eaton <jwe@octave.org>
diff
changeset
|
3311 args(0) = method_nm; |
0259254a3ccc
maint: periodic merge of default to classdef
John W. Eaton <jwe@octave.org>
diff
changeset
|
3312 |
0259254a3ccc
maint: periodic merge of default to classdef
John W. Eaton <jwe@octave.org>
diff
changeset
|
3313 octave_value fcn |
0259254a3ccc
maint: periodic merge of default to classdef
John W. Eaton <jwe@octave.org>
diff
changeset
|
3314 = symbol_table::find_built_in_function ("__superclass_reference__"); |
0259254a3ccc
maint: periodic merge of default to classdef
John W. Eaton <jwe@octave.org>
diff
changeset
|
3315 |
0259254a3ccc
maint: periodic merge of default to classdef
John W. Eaton <jwe@octave.org>
diff
changeset
|
3316 return new tree_funcall (fcn, args); |
0259254a3ccc
maint: periodic merge of default to classdef
John W. Eaton <jwe@octave.org>
diff
changeset
|
3317 } |
0259254a3ccc
maint: periodic merge of default to classdef
John W. Eaton <jwe@octave.org>
diff
changeset
|
3318 |
0259254a3ccc
maint: periodic merge of default to classdef
John W. Eaton <jwe@octave.org>
diff
changeset
|
3319 tree_funcall * |
18961
09eb8a2ddb02
eliminate some unused parameter warnings in parser functions
John W. Eaton <jwe@octave.org>
parents:
18537
diff
changeset
|
3320 octave_base_parser::make_meta_class_query (const std::string& class_nm) |
16155
0259254a3ccc
maint: periodic merge of default to classdef
John W. Eaton <jwe@octave.org>
diff
changeset
|
3321 { |
0259254a3ccc
maint: periodic merge of default to classdef
John W. Eaton <jwe@octave.org>
diff
changeset
|
3322 octave_value_list args; |
0259254a3ccc
maint: periodic merge of default to classdef
John W. Eaton <jwe@octave.org>
diff
changeset
|
3323 |
18520
932aca9a7c57
Allow multi-level classdef package.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
18419
diff
changeset
|
3324 args(0) = class_nm; |
16155
0259254a3ccc
maint: periodic merge of default to classdef
John W. Eaton <jwe@octave.org>
diff
changeset
|
3325 |
0259254a3ccc
maint: periodic merge of default to classdef
John W. Eaton <jwe@octave.org>
diff
changeset
|
3326 octave_value fcn |
0259254a3ccc
maint: periodic merge of default to classdef
John W. Eaton <jwe@octave.org>
diff
changeset
|
3327 = symbol_table::find_built_in_function ("__meta_class_query__"); |
0259254a3ccc
maint: periodic merge of default to classdef
John W. Eaton <jwe@octave.org>
diff
changeset
|
3328 |
0259254a3ccc
maint: periodic merge of default to classdef
John W. Eaton <jwe@octave.org>
diff
changeset
|
3329 return new tree_funcall (fcn, args); |
0259254a3ccc
maint: periodic merge of default to classdef
John W. Eaton <jwe@octave.org>
diff
changeset
|
3330 } |
0259254a3ccc
maint: periodic merge of default to classdef
John W. Eaton <jwe@octave.org>
diff
changeset
|
3331 |
0259254a3ccc
maint: periodic merge of default to classdef
John W. Eaton <jwe@octave.org>
diff
changeset
|
3332 // A CLASSDEF block defines a class that has a constructor and other |
0259254a3ccc
maint: periodic merge of default to classdef
John W. Eaton <jwe@octave.org>
diff
changeset
|
3333 // methods, but it is not an executable command. Parsing the block |
0259254a3ccc
maint: periodic merge of default to classdef
John W. Eaton <jwe@octave.org>
diff
changeset
|
3334 // makes some changes in the symbol table (inserting the constructor |
0259254a3ccc
maint: periodic merge of default to classdef
John W. Eaton <jwe@octave.org>
diff
changeset
|
3335 // and methods, and adding to the list of known objects) and creates |
0259254a3ccc
maint: periodic merge of default to classdef
John W. Eaton <jwe@octave.org>
diff
changeset
|
3336 // a parse tree containing meta information about the class. |
0259254a3ccc
maint: periodic merge of default to classdef
John W. Eaton <jwe@octave.org>
diff
changeset
|
3337 |
0259254a3ccc
maint: periodic merge of default to classdef
John W. Eaton <jwe@octave.org>
diff
changeset
|
3338 tree_classdef * |
16289
bde729ba8381
maint: periodic merge of default to classdef
John W. Eaton <jwe@octave.org>
diff
changeset
|
3339 octave_base_parser::make_classdef (token *tok_val, |
bde729ba8381
maint: periodic merge of default to classdef
John W. Eaton <jwe@octave.org>
diff
changeset
|
3340 tree_classdef_attribute_list *a, |
bde729ba8381
maint: periodic merge of default to classdef
John W. Eaton <jwe@octave.org>
diff
changeset
|
3341 tree_identifier *id, |
bde729ba8381
maint: periodic merge of default to classdef
John W. Eaton <jwe@octave.org>
diff
changeset
|
3342 tree_classdef_superclass_list *sc, |
bde729ba8381
maint: periodic merge of default to classdef
John W. Eaton <jwe@octave.org>
diff
changeset
|
3343 tree_classdef_body *body, token *end_tok, |
bde729ba8381
maint: periodic merge of default to classdef
John W. Eaton <jwe@octave.org>
diff
changeset
|
3344 octave_comment_list *lc) |
16155
0259254a3ccc
maint: periodic merge of default to classdef
John W. Eaton <jwe@octave.org>
diff
changeset
|
3345 { |
0259254a3ccc
maint: periodic merge of default to classdef
John W. Eaton <jwe@octave.org>
diff
changeset
|
3346 tree_classdef *retval = 0; |
0259254a3ccc
maint: periodic merge of default to classdef
John W. Eaton <jwe@octave.org>
diff
changeset
|
3347 |
0259254a3ccc
maint: periodic merge of default to classdef
John W. Eaton <jwe@octave.org>
diff
changeset
|
3348 std::string cls_name = id->name (); |
0259254a3ccc
maint: periodic merge of default to classdef
John W. Eaton <jwe@octave.org>
diff
changeset
|
3349 |
16289
bde729ba8381
maint: periodic merge of default to classdef
John W. Eaton <jwe@octave.org>
diff
changeset
|
3350 std::string nm = lexer.fcn_file_name; |
16155
0259254a3ccc
maint: periodic merge of default to classdef
John W. Eaton <jwe@octave.org>
diff
changeset
|
3351 |
0259254a3ccc
maint: periodic merge of default to classdef
John W. Eaton <jwe@octave.org>
diff
changeset
|
3352 size_t pos = nm.find_last_of (file_ops::dir_sep_chars ()); |
0259254a3ccc
maint: periodic merge of default to classdef
John W. Eaton <jwe@octave.org>
diff
changeset
|
3353 |
0259254a3ccc
maint: periodic merge of default to classdef
John W. Eaton <jwe@octave.org>
diff
changeset
|
3354 if (pos != std::string::npos) |
16289
bde729ba8381
maint: periodic merge of default to classdef
John W. Eaton <jwe@octave.org>
diff
changeset
|
3355 nm = lexer.fcn_file_name.substr (pos+1); |
16155
0259254a3ccc
maint: periodic merge of default to classdef
John W. Eaton <jwe@octave.org>
diff
changeset
|
3356 |
0259254a3ccc
maint: periodic merge of default to classdef
John W. Eaton <jwe@octave.org>
diff
changeset
|
3357 if (nm != cls_name) |
17656
2b1047efc4fb
don't leak memory when parsing classdef objects fails
John W. Eaton <jwe@octave.org>
parents:
17654
diff
changeset
|
3358 bison_error ("invalid classdef definition, the class name must match the file name"); |
2b1047efc4fb
don't leak memory when parsing classdef objects fails
John W. Eaton <jwe@octave.org>
parents:
17654
diff
changeset
|
3359 else if (end_token_ok (end_tok, token::classdef_end)) |
16155
0259254a3ccc
maint: periodic merge of default to classdef
John W. Eaton <jwe@octave.org>
diff
changeset
|
3360 { |
17745
93b3d03b05e7
maint: periodic merge of default to classdef
John W. Eaton <jwe@octave.org>
diff
changeset
|
3361 octave_comment_list *tc = lexer.comment_buf.get_comment (); |
16155
0259254a3ccc
maint: periodic merge of default to classdef
John W. Eaton <jwe@octave.org>
diff
changeset
|
3362 |
0259254a3ccc
maint: periodic merge of default to classdef
John W. Eaton <jwe@octave.org>
diff
changeset
|
3363 int l = tok_val->line (); |
0259254a3ccc
maint: periodic merge of default to classdef
John W. Eaton <jwe@octave.org>
diff
changeset
|
3364 int c = tok_val->column (); |
0259254a3ccc
maint: periodic merge of default to classdef
John W. Eaton <jwe@octave.org>
diff
changeset
|
3365 |
18419
9154dc252f47
Allow empty classdef or methods/properties/... blocks
Michael Goffioul <michael.goffioul@gmail.com>
parents:
18395
diff
changeset
|
3366 if (! body) |
9154dc252f47
Allow empty classdef or methods/properties/... blocks
Michael Goffioul <michael.goffioul@gmail.com>
parents:
18395
diff
changeset
|
3367 body = new tree_classdef_body (); |
9154dc252f47
Allow empty classdef or methods/properties/... blocks
Michael Goffioul <michael.goffioul@gmail.com>
parents:
18395
diff
changeset
|
3368 |
17656
2b1047efc4fb
don't leak memory when parsing classdef objects fails
John W. Eaton <jwe@octave.org>
parents:
17654
diff
changeset
|
3369 retval = new tree_classdef (a, id, sc, body, lc, tc, |
2b1047efc4fb
don't leak memory when parsing classdef objects fails
John W. Eaton <jwe@octave.org>
parents:
17654
diff
changeset
|
3370 curr_package_name, l, c); |
2b1047efc4fb
don't leak memory when parsing classdef objects fails
John W. Eaton <jwe@octave.org>
parents:
17654
diff
changeset
|
3371 } |
2b1047efc4fb
don't leak memory when parsing classdef objects fails
John W. Eaton <jwe@octave.org>
parents:
17654
diff
changeset
|
3372 |
2b1047efc4fb
don't leak memory when parsing classdef objects fails
John W. Eaton <jwe@octave.org>
parents:
17654
diff
changeset
|
3373 if (! retval) |
2b1047efc4fb
don't leak memory when parsing classdef objects fails
John W. Eaton <jwe@octave.org>
parents:
17654
diff
changeset
|
3374 { |
2b1047efc4fb
don't leak memory when parsing classdef objects fails
John W. Eaton <jwe@octave.org>
parents:
17654
diff
changeset
|
3375 delete a; |
2b1047efc4fb
don't leak memory when parsing classdef objects fails
John W. Eaton <jwe@octave.org>
parents:
17654
diff
changeset
|
3376 delete id; |
2b1047efc4fb
don't leak memory when parsing classdef objects fails
John W. Eaton <jwe@octave.org>
parents:
17654
diff
changeset
|
3377 delete sc; |
2b1047efc4fb
don't leak memory when parsing classdef objects fails
John W. Eaton <jwe@octave.org>
parents:
17654
diff
changeset
|
3378 delete body; |
16155
0259254a3ccc
maint: periodic merge of default to classdef
John W. Eaton <jwe@octave.org>
diff
changeset
|
3379 } |
0259254a3ccc
maint: periodic merge of default to classdef
John W. Eaton <jwe@octave.org>
diff
changeset
|
3380 |
0259254a3ccc
maint: periodic merge of default to classdef
John W. Eaton <jwe@octave.org>
diff
changeset
|
3381 return retval; |
0259254a3ccc
maint: periodic merge of default to classdef
John W. Eaton <jwe@octave.org>
diff
changeset
|
3382 } |
0259254a3ccc
maint: periodic merge of default to classdef
John W. Eaton <jwe@octave.org>
diff
changeset
|
3383 |
0259254a3ccc
maint: periodic merge of default to classdef
John W. Eaton <jwe@octave.org>
diff
changeset
|
3384 tree_classdef_properties_block * |
16289
bde729ba8381
maint: periodic merge of default to classdef
John W. Eaton <jwe@octave.org>
diff
changeset
|
3385 octave_base_parser::make_classdef_properties_block (token *tok_val, |
bde729ba8381
maint: periodic merge of default to classdef
John W. Eaton <jwe@octave.org>
diff
changeset
|
3386 tree_classdef_attribute_list *a, |
bde729ba8381
maint: periodic merge of default to classdef
John W. Eaton <jwe@octave.org>
diff
changeset
|
3387 tree_classdef_property_list *plist, |
bde729ba8381
maint: periodic merge of default to classdef
John W. Eaton <jwe@octave.org>
diff
changeset
|
3388 token *end_tok, |
bde729ba8381
maint: periodic merge of default to classdef
John W. Eaton <jwe@octave.org>
diff
changeset
|
3389 octave_comment_list *lc) |
16155
0259254a3ccc
maint: periodic merge of default to classdef
John W. Eaton <jwe@octave.org>
diff
changeset
|
3390 { |
0259254a3ccc
maint: periodic merge of default to classdef
John W. Eaton <jwe@octave.org>
diff
changeset
|
3391 tree_classdef_properties_block *retval = 0; |
0259254a3ccc
maint: periodic merge of default to classdef
John W. Eaton <jwe@octave.org>
diff
changeset
|
3392 |
0259254a3ccc
maint: periodic merge of default to classdef
John W. Eaton <jwe@octave.org>
diff
changeset
|
3393 if (end_token_ok (end_tok, token::properties_end)) |
0259254a3ccc
maint: periodic merge of default to classdef
John W. Eaton <jwe@octave.org>
diff
changeset
|
3394 { |
17745
93b3d03b05e7
maint: periodic merge of default to classdef
John W. Eaton <jwe@octave.org>
diff
changeset
|
3395 octave_comment_list *tc = lexer.comment_buf.get_comment (); |
16155
0259254a3ccc
maint: periodic merge of default to classdef
John W. Eaton <jwe@octave.org>
diff
changeset
|
3396 |
0259254a3ccc
maint: periodic merge of default to classdef
John W. Eaton <jwe@octave.org>
diff
changeset
|
3397 int l = tok_val->line (); |
0259254a3ccc
maint: periodic merge of default to classdef
John W. Eaton <jwe@octave.org>
diff
changeset
|
3398 int c = tok_val->column (); |
0259254a3ccc
maint: periodic merge of default to classdef
John W. Eaton <jwe@octave.org>
diff
changeset
|
3399 |
18419
9154dc252f47
Allow empty classdef or methods/properties/... blocks
Michael Goffioul <michael.goffioul@gmail.com>
parents:
18395
diff
changeset
|
3400 if (! plist) |
9154dc252f47
Allow empty classdef or methods/properties/... blocks
Michael Goffioul <michael.goffioul@gmail.com>
parents:
18395
diff
changeset
|
3401 plist = new tree_classdef_property_list (); |
9154dc252f47
Allow empty classdef or methods/properties/... blocks
Michael Goffioul <michael.goffioul@gmail.com>
parents:
18395
diff
changeset
|
3402 |
16155
0259254a3ccc
maint: periodic merge of default to classdef
John W. Eaton <jwe@octave.org>
diff
changeset
|
3403 retval = new tree_classdef_properties_block (a, plist, lc, tc, l, c); |
0259254a3ccc
maint: periodic merge of default to classdef
John W. Eaton <jwe@octave.org>
diff
changeset
|
3404 } |
17656
2b1047efc4fb
don't leak memory when parsing classdef objects fails
John W. Eaton <jwe@octave.org>
parents:
17654
diff
changeset
|
3405 else |
2b1047efc4fb
don't leak memory when parsing classdef objects fails
John W. Eaton <jwe@octave.org>
parents:
17654
diff
changeset
|
3406 { |
2b1047efc4fb
don't leak memory when parsing classdef objects fails
John W. Eaton <jwe@octave.org>
parents:
17654
diff
changeset
|
3407 delete a; |
2b1047efc4fb
don't leak memory when parsing classdef objects fails
John W. Eaton <jwe@octave.org>
parents:
17654
diff
changeset
|
3408 delete plist; |
2b1047efc4fb
don't leak memory when parsing classdef objects fails
John W. Eaton <jwe@octave.org>
parents:
17654
diff
changeset
|
3409 } |
16155
0259254a3ccc
maint: periodic merge of default to classdef
John W. Eaton <jwe@octave.org>
diff
changeset
|
3410 |
0259254a3ccc
maint: periodic merge of default to classdef
John W. Eaton <jwe@octave.org>
diff
changeset
|
3411 return retval; |
0259254a3ccc
maint: periodic merge of default to classdef
John W. Eaton <jwe@octave.org>
diff
changeset
|
3412 } |
0259254a3ccc
maint: periodic merge of default to classdef
John W. Eaton <jwe@octave.org>
diff
changeset
|
3413 |
0259254a3ccc
maint: periodic merge of default to classdef
John W. Eaton <jwe@octave.org>
diff
changeset
|
3414 tree_classdef_methods_block * |
16289
bde729ba8381
maint: periodic merge of default to classdef
John W. Eaton <jwe@octave.org>
diff
changeset
|
3415 octave_base_parser::make_classdef_methods_block (token *tok_val, |
bde729ba8381
maint: periodic merge of default to classdef
John W. Eaton <jwe@octave.org>
diff
changeset
|
3416 tree_classdef_attribute_list *a, |
bde729ba8381
maint: periodic merge of default to classdef
John W. Eaton <jwe@octave.org>
diff
changeset
|
3417 tree_classdef_methods_list *mlist, |
bde729ba8381
maint: periodic merge of default to classdef
John W. Eaton <jwe@octave.org>
diff
changeset
|
3418 token *end_tok, |
bde729ba8381
maint: periodic merge of default to classdef
John W. Eaton <jwe@octave.org>
diff
changeset
|
3419 octave_comment_list *lc) |
16155
0259254a3ccc
maint: periodic merge of default to classdef
John W. Eaton <jwe@octave.org>
diff
changeset
|
3420 { |
0259254a3ccc
maint: periodic merge of default to classdef
John W. Eaton <jwe@octave.org>
diff
changeset
|
3421 tree_classdef_methods_block *retval = 0; |
0259254a3ccc
maint: periodic merge of default to classdef
John W. Eaton <jwe@octave.org>
diff
changeset
|
3422 |
0259254a3ccc
maint: periodic merge of default to classdef
John W. Eaton <jwe@octave.org>
diff
changeset
|
3423 if (end_token_ok (end_tok, token::methods_end)) |
0259254a3ccc
maint: periodic merge of default to classdef
John W. Eaton <jwe@octave.org>
diff
changeset
|
3424 { |
17745
93b3d03b05e7
maint: periodic merge of default to classdef
John W. Eaton <jwe@octave.org>
diff
changeset
|
3425 octave_comment_list *tc = lexer.comment_buf.get_comment (); |
16155
0259254a3ccc
maint: periodic merge of default to classdef
John W. Eaton <jwe@octave.org>
diff
changeset
|
3426 |
0259254a3ccc
maint: periodic merge of default to classdef
John W. Eaton <jwe@octave.org>
diff
changeset
|
3427 int l = tok_val->line (); |
0259254a3ccc
maint: periodic merge of default to classdef
John W. Eaton <jwe@octave.org>
diff
changeset
|
3428 int c = tok_val->column (); |
0259254a3ccc
maint: periodic merge of default to classdef
John W. Eaton <jwe@octave.org>
diff
changeset
|
3429 |
18419
9154dc252f47
Allow empty classdef or methods/properties/... blocks
Michael Goffioul <michael.goffioul@gmail.com>
parents:
18395
diff
changeset
|
3430 if (! mlist) |
9154dc252f47
Allow empty classdef or methods/properties/... blocks
Michael Goffioul <michael.goffioul@gmail.com>
parents:
18395
diff
changeset
|
3431 mlist = new tree_classdef_methods_list (); |
9154dc252f47
Allow empty classdef or methods/properties/... blocks
Michael Goffioul <michael.goffioul@gmail.com>
parents:
18395
diff
changeset
|
3432 |
16155
0259254a3ccc
maint: periodic merge of default to classdef
John W. Eaton <jwe@octave.org>
diff
changeset
|
3433 retval = new tree_classdef_methods_block (a, mlist, lc, tc, l, c); |
0259254a3ccc
maint: periodic merge of default to classdef
John W. Eaton <jwe@octave.org>
diff
changeset
|
3434 } |
17656
2b1047efc4fb
don't leak memory when parsing classdef objects fails
John W. Eaton <jwe@octave.org>
parents:
17654
diff
changeset
|
3435 else |
2b1047efc4fb
don't leak memory when parsing classdef objects fails
John W. Eaton <jwe@octave.org>
parents:
17654
diff
changeset
|
3436 { |
2b1047efc4fb
don't leak memory when parsing classdef objects fails
John W. Eaton <jwe@octave.org>
parents:
17654
diff
changeset
|
3437 delete a; |
2b1047efc4fb
don't leak memory when parsing classdef objects fails
John W. Eaton <jwe@octave.org>
parents:
17654
diff
changeset
|
3438 delete mlist; |
2b1047efc4fb
don't leak memory when parsing classdef objects fails
John W. Eaton <jwe@octave.org>
parents:
17654
diff
changeset
|
3439 } |
16155
0259254a3ccc
maint: periodic merge of default to classdef
John W. Eaton <jwe@octave.org>
diff
changeset
|
3440 |
0259254a3ccc
maint: periodic merge of default to classdef
John W. Eaton <jwe@octave.org>
diff
changeset
|
3441 return retval; |
0259254a3ccc
maint: periodic merge of default to classdef
John W. Eaton <jwe@octave.org>
diff
changeset
|
3442 } |
0259254a3ccc
maint: periodic merge of default to classdef
John W. Eaton <jwe@octave.org>
diff
changeset
|
3443 |
0259254a3ccc
maint: periodic merge of default to classdef
John W. Eaton <jwe@octave.org>
diff
changeset
|
3444 tree_classdef_events_block * |
16289
bde729ba8381
maint: periodic merge of default to classdef
John W. Eaton <jwe@octave.org>
diff
changeset
|
3445 octave_base_parser::make_classdef_events_block (token *tok_val, |
bde729ba8381
maint: periodic merge of default to classdef
John W. Eaton <jwe@octave.org>
diff
changeset
|
3446 tree_classdef_attribute_list *a, |
bde729ba8381
maint: periodic merge of default to classdef
John W. Eaton <jwe@octave.org>
diff
changeset
|
3447 tree_classdef_events_list *elist, |
bde729ba8381
maint: periodic merge of default to classdef
John W. Eaton <jwe@octave.org>
diff
changeset
|
3448 token *end_tok, |
bde729ba8381
maint: periodic merge of default to classdef
John W. Eaton <jwe@octave.org>
diff
changeset
|
3449 octave_comment_list *lc) |
16155
0259254a3ccc
maint: periodic merge of default to classdef
John W. Eaton <jwe@octave.org>
diff
changeset
|
3450 { |
0259254a3ccc
maint: periodic merge of default to classdef
John W. Eaton <jwe@octave.org>
diff
changeset
|
3451 tree_classdef_events_block *retval = 0; |
0259254a3ccc
maint: periodic merge of default to classdef
John W. Eaton <jwe@octave.org>
diff
changeset
|
3452 |
0259254a3ccc
maint: periodic merge of default to classdef
John W. Eaton <jwe@octave.org>
diff
changeset
|
3453 if (end_token_ok (end_tok, token::events_end)) |
0259254a3ccc
maint: periodic merge of default to classdef
John W. Eaton <jwe@octave.org>
diff
changeset
|
3454 { |
17745
93b3d03b05e7
maint: periodic merge of default to classdef
John W. Eaton <jwe@octave.org>
diff
changeset
|
3455 octave_comment_list *tc = lexer.comment_buf.get_comment (); |
16155
0259254a3ccc
maint: periodic merge of default to classdef
John W. Eaton <jwe@octave.org>
diff
changeset
|
3456 |
0259254a3ccc
maint: periodic merge of default to classdef
John W. Eaton <jwe@octave.org>
diff
changeset
|
3457 int l = tok_val->line (); |
0259254a3ccc
maint: periodic merge of default to classdef
John W. Eaton <jwe@octave.org>
diff
changeset
|
3458 int c = tok_val->column (); |
0259254a3ccc
maint: periodic merge of default to classdef
John W. Eaton <jwe@octave.org>
diff
changeset
|
3459 |
18419
9154dc252f47
Allow empty classdef or methods/properties/... blocks
Michael Goffioul <michael.goffioul@gmail.com>
parents:
18395
diff
changeset
|
3460 if (! elist) |
9154dc252f47
Allow empty classdef or methods/properties/... blocks
Michael Goffioul <michael.goffioul@gmail.com>
parents:
18395
diff
changeset
|
3461 elist = new tree_classdef_events_list (); |
9154dc252f47
Allow empty classdef or methods/properties/... blocks
Michael Goffioul <michael.goffioul@gmail.com>
parents:
18395
diff
changeset
|
3462 |
16155
0259254a3ccc
maint: periodic merge of default to classdef
John W. Eaton <jwe@octave.org>
diff
changeset
|
3463 retval = new tree_classdef_events_block (a, elist, lc, tc, l, c); |
0259254a3ccc
maint: periodic merge of default to classdef
John W. Eaton <jwe@octave.org>
diff
changeset
|
3464 } |
17656
2b1047efc4fb
don't leak memory when parsing classdef objects fails
John W. Eaton <jwe@octave.org>
parents:
17654
diff
changeset
|
3465 else |
2b1047efc4fb
don't leak memory when parsing classdef objects fails
John W. Eaton <jwe@octave.org>
parents:
17654
diff
changeset
|
3466 { |
2b1047efc4fb
don't leak memory when parsing classdef objects fails
John W. Eaton <jwe@octave.org>
parents:
17654
diff
changeset
|
3467 delete a; |
2b1047efc4fb
don't leak memory when parsing classdef objects fails
John W. Eaton <jwe@octave.org>
parents:
17654
diff
changeset
|
3468 delete elist; |
2b1047efc4fb
don't leak memory when parsing classdef objects fails
John W. Eaton <jwe@octave.org>
parents:
17654
diff
changeset
|
3469 } |
16155
0259254a3ccc
maint: periodic merge of default to classdef
John W. Eaton <jwe@octave.org>
diff
changeset
|
3470 |
0259254a3ccc
maint: periodic merge of default to classdef
John W. Eaton <jwe@octave.org>
diff
changeset
|
3471 return retval; |
0259254a3ccc
maint: periodic merge of default to classdef
John W. Eaton <jwe@octave.org>
diff
changeset
|
3472 } |
0259254a3ccc
maint: periodic merge of default to classdef
John W. Eaton <jwe@octave.org>
diff
changeset
|
3473 |
0259254a3ccc
maint: periodic merge of default to classdef
John W. Eaton <jwe@octave.org>
diff
changeset
|
3474 tree_classdef_enum_block * |
16289
bde729ba8381
maint: periodic merge of default to classdef
John W. Eaton <jwe@octave.org>
diff
changeset
|
3475 octave_base_parser::make_classdef_enum_block (token *tok_val, |
bde729ba8381
maint: periodic merge of default to classdef
John W. Eaton <jwe@octave.org>
diff
changeset
|
3476 tree_classdef_attribute_list *a, |
bde729ba8381
maint: periodic merge of default to classdef
John W. Eaton <jwe@octave.org>
diff
changeset
|
3477 tree_classdef_enum_list *elist, |
bde729ba8381
maint: periodic merge of default to classdef
John W. Eaton <jwe@octave.org>
diff
changeset
|
3478 token *end_tok, |
bde729ba8381
maint: periodic merge of default to classdef
John W. Eaton <jwe@octave.org>
diff
changeset
|
3479 octave_comment_list *lc) |
16155
0259254a3ccc
maint: periodic merge of default to classdef
John W. Eaton <jwe@octave.org>
diff
changeset
|
3480 { |
0259254a3ccc
maint: periodic merge of default to classdef
John W. Eaton <jwe@octave.org>
diff
changeset
|
3481 tree_classdef_enum_block *retval = 0; |
0259254a3ccc
maint: periodic merge of default to classdef
John W. Eaton <jwe@octave.org>
diff
changeset
|
3482 |
0259254a3ccc
maint: periodic merge of default to classdef
John W. Eaton <jwe@octave.org>
diff
changeset
|
3483 if (end_token_ok (end_tok, token::enumeration_end)) |
0259254a3ccc
maint: periodic merge of default to classdef
John W. Eaton <jwe@octave.org>
diff
changeset
|
3484 { |
17745
93b3d03b05e7
maint: periodic merge of default to classdef
John W. Eaton <jwe@octave.org>
diff
changeset
|
3485 octave_comment_list *tc = lexer.comment_buf.get_comment (); |
16155
0259254a3ccc
maint: periodic merge of default to classdef
John W. Eaton <jwe@octave.org>
diff
changeset
|
3486 |
0259254a3ccc
maint: periodic merge of default to classdef
John W. Eaton <jwe@octave.org>
diff
changeset
|
3487 int l = tok_val->line (); |
0259254a3ccc
maint: periodic merge of default to classdef
John W. Eaton <jwe@octave.org>
diff
changeset
|
3488 int c = tok_val->column (); |
0259254a3ccc
maint: periodic merge of default to classdef
John W. Eaton <jwe@octave.org>
diff
changeset
|
3489 |
18419
9154dc252f47
Allow empty classdef or methods/properties/... blocks
Michael Goffioul <michael.goffioul@gmail.com>
parents:
18395
diff
changeset
|
3490 if (! elist) |
9154dc252f47
Allow empty classdef or methods/properties/... blocks
Michael Goffioul <michael.goffioul@gmail.com>
parents:
18395
diff
changeset
|
3491 elist = new tree_classdef_enum_list (); |
9154dc252f47
Allow empty classdef or methods/properties/... blocks
Michael Goffioul <michael.goffioul@gmail.com>
parents:
18395
diff
changeset
|
3492 |
16155
0259254a3ccc
maint: periodic merge of default to classdef
John W. Eaton <jwe@octave.org>
diff
changeset
|
3493 retval = new tree_classdef_enum_block (a, elist, lc, tc, l, c); |
0259254a3ccc
maint: periodic merge of default to classdef
John W. Eaton <jwe@octave.org>
diff
changeset
|
3494 } |
17656
2b1047efc4fb
don't leak memory when parsing classdef objects fails
John W. Eaton <jwe@octave.org>
parents:
17654
diff
changeset
|
3495 else |
2b1047efc4fb
don't leak memory when parsing classdef objects fails
John W. Eaton <jwe@octave.org>
parents:
17654
diff
changeset
|
3496 { |
2b1047efc4fb
don't leak memory when parsing classdef objects fails
John W. Eaton <jwe@octave.org>
parents:
17654
diff
changeset
|
3497 delete a; |
2b1047efc4fb
don't leak memory when parsing classdef objects fails
John W. Eaton <jwe@octave.org>
parents:
17654
diff
changeset
|
3498 delete elist; |
2b1047efc4fb
don't leak memory when parsing classdef objects fails
John W. Eaton <jwe@octave.org>
parents:
17654
diff
changeset
|
3499 } |
16155
0259254a3ccc
maint: periodic merge of default to classdef
John W. Eaton <jwe@octave.org>
diff
changeset
|
3500 |
0259254a3ccc
maint: periodic merge of default to classdef
John W. Eaton <jwe@octave.org>
diff
changeset
|
3501 return retval; |
2883 | 3502 } |
3503 | |
18262
69990d5edcc2
Allow to parse external methods declaration in classdef files.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
18157
diff
changeset
|
3504 octave_user_function* |
69990d5edcc2
Allow to parse external methods declaration in classdef files.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
18157
diff
changeset
|
3505 octave_base_parser::start_classdef_external_method (tree_identifier *id, |
18308
c1baf94184af
* oct-parse.in.yy: Suppress TAB characters.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
18304
diff
changeset
|
3506 tree_parameter_list *pl) |
18262
69990d5edcc2
Allow to parse external methods declaration in classdef files.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
18157
diff
changeset
|
3507 { |
69990d5edcc2
Allow to parse external methods declaration in classdef files.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
18157
diff
changeset
|
3508 octave_user_function* retval = 0; |
69990d5edcc2
Allow to parse external methods declaration in classdef files.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
18157
diff
changeset
|
3509 |
69990d5edcc2
Allow to parse external methods declaration in classdef files.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
18157
diff
changeset
|
3510 // External methods are only allowed within @-folders. In this case, |
69990d5edcc2
Allow to parse external methods declaration in classdef files.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
18157
diff
changeset
|
3511 // curr_class_name will be non-empty. |
69990d5edcc2
Allow to parse external methods declaration in classdef files.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
18157
diff
changeset
|
3512 |
69990d5edcc2
Allow to parse external methods declaration in classdef files.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
18157
diff
changeset
|
3513 if (! curr_class_name.empty ()) |
69990d5edcc2
Allow to parse external methods declaration in classdef files.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
18157
diff
changeset
|
3514 { |
69990d5edcc2
Allow to parse external methods declaration in classdef files.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
18157
diff
changeset
|
3515 |
69990d5edcc2
Allow to parse external methods declaration in classdef files.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
18157
diff
changeset
|
3516 std::string mname = id->name (); |
69990d5edcc2
Allow to parse external methods declaration in classdef files.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
18157
diff
changeset
|
3517 |
69990d5edcc2
Allow to parse external methods declaration in classdef files.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
18157
diff
changeset
|
3518 // Methods that cannot be declared outside the classdef file: |
69990d5edcc2
Allow to parse external methods declaration in classdef files.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
18157
diff
changeset
|
3519 // - methods with '.' character (e.g. property accessors) |
69990d5edcc2
Allow to parse external methods declaration in classdef files.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
18157
diff
changeset
|
3520 // - class constructor |
69990d5edcc2
Allow to parse external methods declaration in classdef files.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
18157
diff
changeset
|
3521 // - `delete' |
69990d5edcc2
Allow to parse external methods declaration in classdef files.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
18157
diff
changeset
|
3522 |
69990d5edcc2
Allow to parse external methods declaration in classdef files.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
18157
diff
changeset
|
3523 if (mname.find_first_of (".") == std::string::npos |
69990d5edcc2
Allow to parse external methods declaration in classdef files.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
18157
diff
changeset
|
3524 && mname != "delete" |
69990d5edcc2
Allow to parse external methods declaration in classdef files.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
18157
diff
changeset
|
3525 && mname != curr_class_name) |
69990d5edcc2
Allow to parse external methods declaration in classdef files.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
18157
diff
changeset
|
3526 { |
69990d5edcc2
Allow to parse external methods declaration in classdef files.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
18157
diff
changeset
|
3527 // Create a dummy function that is used until the real method |
69990d5edcc2
Allow to parse external methods declaration in classdef files.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
18157
diff
changeset
|
3528 // is loaded. |
69990d5edcc2
Allow to parse external methods declaration in classdef files.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
18157
diff
changeset
|
3529 |
69990d5edcc2
Allow to parse external methods declaration in classdef files.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
18157
diff
changeset
|
3530 retval = new octave_user_function (-1, pl); |
69990d5edcc2
Allow to parse external methods declaration in classdef files.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
18157
diff
changeset
|
3531 |
69990d5edcc2
Allow to parse external methods declaration in classdef files.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
18157
diff
changeset
|
3532 retval->stash_function_name (mname); |
69990d5edcc2
Allow to parse external methods declaration in classdef files.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
18157
diff
changeset
|
3533 |
69990d5edcc2
Allow to parse external methods declaration in classdef files.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
18157
diff
changeset
|
3534 int l = id->line (); |
69990d5edcc2
Allow to parse external methods declaration in classdef files.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
18157
diff
changeset
|
3535 int c = id->column (); |
69990d5edcc2
Allow to parse external methods declaration in classdef files.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
18157
diff
changeset
|
3536 |
69990d5edcc2
Allow to parse external methods declaration in classdef files.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
18157
diff
changeset
|
3537 retval->stash_fcn_location (l, c); |
69990d5edcc2
Allow to parse external methods declaration in classdef files.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
18157
diff
changeset
|
3538 } |
69990d5edcc2
Allow to parse external methods declaration in classdef files.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
18157
diff
changeset
|
3539 else |
69990d5edcc2
Allow to parse external methods declaration in classdef files.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
18157
diff
changeset
|
3540 bison_error ("invalid external method declaration, an external " |
69990d5edcc2
Allow to parse external methods declaration in classdef files.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
18157
diff
changeset
|
3541 "method cannot be the class constructor, `delete' " |
69990d5edcc2
Allow to parse external methods declaration in classdef files.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
18157
diff
changeset
|
3542 "or have a dot (.) character in its name"); |
69990d5edcc2
Allow to parse external methods declaration in classdef files.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
18157
diff
changeset
|
3543 } |
69990d5edcc2
Allow to parse external methods declaration in classdef files.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
18157
diff
changeset
|
3544 else |
69990d5edcc2
Allow to parse external methods declaration in classdef files.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
18157
diff
changeset
|
3545 bison_error ("external methods are only allowed in @-folders"); |
69990d5edcc2
Allow to parse external methods declaration in classdef files.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
18157
diff
changeset
|
3546 |
69990d5edcc2
Allow to parse external methods declaration in classdef files.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
18157
diff
changeset
|
3547 if (! retval) |
69990d5edcc2
Allow to parse external methods declaration in classdef files.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
18157
diff
changeset
|
3548 delete id; |
69990d5edcc2
Allow to parse external methods declaration in classdef files.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
18157
diff
changeset
|
3549 |
69990d5edcc2
Allow to parse external methods declaration in classdef files.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
18157
diff
changeset
|
3550 return retval; |
69990d5edcc2
Allow to parse external methods declaration in classdef files.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
18157
diff
changeset
|
3551 } |
69990d5edcc2
Allow to parse external methods declaration in classdef files.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
18157
diff
changeset
|
3552 |
69990d5edcc2
Allow to parse external methods declaration in classdef files.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
18157
diff
changeset
|
3553 tree_function_def * |
69990d5edcc2
Allow to parse external methods declaration in classdef files.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
18157
diff
changeset
|
3554 octave_base_parser::finish_classdef_external_method (octave_user_function *fcn, |
18308
c1baf94184af
* oct-parse.in.yy: Suppress TAB characters.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
18304
diff
changeset
|
3555 tree_parameter_list *ret_list, |
18262
69990d5edcc2
Allow to parse external methods declaration in classdef files.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
18157
diff
changeset
|
3556 octave_comment_list *cl) |
69990d5edcc2
Allow to parse external methods declaration in classdef files.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
18157
diff
changeset
|
3557 { |
69990d5edcc2
Allow to parse external methods declaration in classdef files.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
18157
diff
changeset
|
3558 if (ret_list) |
69990d5edcc2
Allow to parse external methods declaration in classdef files.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
18157
diff
changeset
|
3559 fcn->define_ret_list (ret_list); |
69990d5edcc2
Allow to parse external methods declaration in classdef files.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
18157
diff
changeset
|
3560 |
69990d5edcc2
Allow to parse external methods declaration in classdef files.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
18157
diff
changeset
|
3561 if (cl) |
69990d5edcc2
Allow to parse external methods declaration in classdef files.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
18157
diff
changeset
|
3562 fcn->stash_leading_comment (cl); |
69990d5edcc2
Allow to parse external methods declaration in classdef files.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
18157
diff
changeset
|
3563 |
69990d5edcc2
Allow to parse external methods declaration in classdef files.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
18157
diff
changeset
|
3564 int l = fcn->beginning_line (); |
69990d5edcc2
Allow to parse external methods declaration in classdef files.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
18157
diff
changeset
|
3565 int c = fcn->beginning_column (); |
69990d5edcc2
Allow to parse external methods declaration in classdef files.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
18157
diff
changeset
|
3566 |
69990d5edcc2
Allow to parse external methods declaration in classdef files.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
18157
diff
changeset
|
3567 return new tree_function_def (fcn, l, c); |
69990d5edcc2
Allow to parse external methods declaration in classdef files.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
18157
diff
changeset
|
3568 } |
69990d5edcc2
Allow to parse external methods declaration in classdef files.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
18157
diff
changeset
|
3569 |
2846 | 3570 // Make an index expression. |
3571 | |
16134
ec9c6222ef5a
move static parser helper functions to octave_parser class
John W. Eaton <jwe@octave.org>
parents:
16133
diff
changeset
|
3572 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
|
3573 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
|
3574 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
|
3575 char type) |
751 | 3576 { |
3577 tree_index_expression *retval = 0; | |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11572
diff
changeset
|
3578 |
10206
37a08e0ce2dc
support Matlab-style empty output/input arguments
Jaroslav Hajek <highegg@gmail.com>
parents:
10188
diff
changeset
|
3579 if (args && args->has_magic_tilde ()) |
37a08e0ce2dc
support Matlab-style empty output/input arguments
Jaroslav Hajek <highegg@gmail.com>
parents:
10188
diff
changeset
|
3580 { |
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
|
3581 bison_error ("invalid use of empty argument (~) in index expression"); |
17632
bd0a84de3375
further reduce memory leaks from parse errors (bug #40231)
John W. Eaton <jwe@octave.org>
parents:
17629
diff
changeset
|
3582 |
bd0a84de3375
further reduce memory leaks from parse errors (bug #40231)
John W. Eaton <jwe@octave.org>
parents:
17629
diff
changeset
|
3583 delete expr; |
bd0a84de3375
further reduce memory leaks from parse errors (bug #40231)
John W. Eaton <jwe@octave.org>
parents:
17629
diff
changeset
|
3584 delete args; |
bd0a84de3375
further reduce memory leaks from parse errors (bug #40231)
John W. Eaton <jwe@octave.org>
parents:
17629
diff
changeset
|
3585 |
10206
37a08e0ce2dc
support Matlab-style empty output/input arguments
Jaroslav Hajek <highegg@gmail.com>
parents:
10188
diff
changeset
|
3586 return retval; |
37a08e0ce2dc
support Matlab-style empty output/input arguments
Jaroslav Hajek <highegg@gmail.com>
parents:
10188
diff
changeset
|
3587 } |
751 | 3588 |
2970 | 3589 int l = expr->line (); |
3590 int c = expr->column (); | |
3591 | |
19631
db92e7e28e1f
strip trailing whitespace from most source files
John W. Eaton <jwe@octave.org>
parents:
19630
diff
changeset
|
3592 if (! expr->is_postfix_indexed ()) |
15954
46ca8488de92
Re-engineer tree_expression postfix handling to make it more flexible.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15895
diff
changeset
|
3593 expr->set_postfix_index (type); |
2970 | 3594 |
3933 | 3595 if (expr->is_index_expression ()) |
3596 { | |
3597 tree_index_expression *tmp = static_cast<tree_index_expression *> (expr); | |
3598 | |
3599 tmp->append (args, type); | |
3600 | |
3601 retval = tmp; | |
3602 } | |
3603 else | |
3604 retval = new tree_index_expression (expr, args, l, c, type); | |
2970 | 3605 |
3606 return retval; | |
3607 } | |
3608 | |
3609 // Make an indirect reference expression. | |
3610 | |
16134
ec9c6222ef5a
move static parser helper functions to octave_parser class
John W. Eaton <jwe@octave.org>
parents:
16133
diff
changeset
|
3611 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
|
3612 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
|
3613 const std::string& elt) |
2970 | 3614 { |
3930 | 3615 tree_index_expression *retval = 0; |
2970 | 3616 |
3617 int l = expr->line (); | |
3618 int c = expr->column (); | |
3619 | |
19631
db92e7e28e1f
strip trailing whitespace from most source files
John W. Eaton <jwe@octave.org>
parents:
19630
diff
changeset
|
3620 if (! expr->is_postfix_indexed ()) |
15954
46ca8488de92
Re-engineer tree_expression postfix handling to make it more flexible.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15895
diff
changeset
|
3621 expr->set_postfix_index ('.'); |
46ca8488de92
Re-engineer tree_expression postfix handling to make it more flexible.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15895
diff
changeset
|
3622 |
3933 | 3623 if (expr->is_index_expression ()) |
3624 { | |
3625 tree_index_expression *tmp = static_cast<tree_index_expression *> (expr); | |
3626 | |
3627 tmp->append (elt); | |
3628 | |
3629 retval = tmp; | |
3630 } | |
3631 else | |
3632 retval = new tree_index_expression (expr, elt, l, c); | |
2970 | 3633 |
16288
fe3b9a51e625
rename curr_lexer, curr_parser, CURR_LEXER
John W. Eaton <jwe@octave.org>
parents:
16287
diff
changeset
|
3634 lexer.looking_at_indirect_ref = false; |
751 | 3635 |
3636 return retval; | |
3637 } | |
1511 | 3638 |
4131 | 3639 // Make an indirect reference expression with dynamic field name. |
3640 | |
16134
ec9c6222ef5a
move static parser helper functions to octave_parser class
John W. Eaton <jwe@octave.org>
parents:
16133
diff
changeset
|
3641 tree_index_expression * |
16289
bde729ba8381
maint: periodic merge of default to classdef
John W. Eaton <jwe@octave.org>
diff
changeset
|
3642 octave_base_parser::make_indirect_ref (tree_expression *expr, |
bde729ba8381
maint: periodic merge of default to classdef
John W. Eaton <jwe@octave.org>
diff
changeset
|
3643 tree_expression *elt) |
4131 | 3644 { |
3645 tree_index_expression *retval = 0; | |
3646 | |
3647 int l = expr->line (); | |
3648 int c = expr->column (); | |
3649 | |
19631
db92e7e28e1f
strip trailing whitespace from most source files
John W. Eaton <jwe@octave.org>
parents:
19630
diff
changeset
|
3650 if (! expr->is_postfix_indexed ()) |
15954
46ca8488de92
Re-engineer tree_expression postfix handling to make it more flexible.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15895
diff
changeset
|
3651 expr->set_postfix_index ('.'); |
46ca8488de92
Re-engineer tree_expression postfix handling to make it more flexible.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15895
diff
changeset
|
3652 |
4131 | 3653 if (expr->is_index_expression ()) |
3654 { | |
3655 tree_index_expression *tmp = static_cast<tree_index_expression *> (expr); | |
3656 | |
3657 tmp->append (elt); | |
3658 | |
3659 retval = tmp; | |
3660 } | |
3661 else | |
3662 retval = new tree_index_expression (expr, elt, l, c); | |
3663 | |
16288
fe3b9a51e625
rename curr_lexer, curr_parser, CURR_LEXER
John W. Eaton <jwe@octave.org>
parents:
16287
diff
changeset
|
3664 lexer.looking_at_indirect_ref = false; |
4131 | 3665 |
3666 return retval; | |
3667 } | |
3668 | |
2846 | 3669 // Make a declaration command. |
3670 | |
16134
ec9c6222ef5a
move static parser helper functions to octave_parser class
John W. Eaton <jwe@octave.org>
parents:
16133
diff
changeset
|
3671 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
|
3672 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
|
3673 tree_decl_init_list *lst) |
2846 | 3674 { |
3675 tree_decl_command *retval = 0; | |
3676 | |
3677 int l = tok_val->line (); | |
3678 int c = tok_val->column (); | |
3679 | |
3680 switch (tok) | |
3681 { | |
3682 case GLOBAL: | |
3683 retval = new tree_global_command (lst, l, c); | |
3684 break; | |
3685 | |
14294
9e3983c8963c
deprecate the static keyword
John W. Eaton <jwe@octave.org>
parents:
14293
diff
changeset
|
3686 case PERSISTENT: |
16153
a57c2c8c8163
move some variables into the octave_parser class
John W. Eaton <jwe@octave.org>
parents:
16151
diff
changeset
|
3687 if (curr_fcn_depth > 0) |
14294
9e3983c8963c
deprecate the static keyword
John W. Eaton <jwe@octave.org>
parents:
14293
diff
changeset
|
3688 retval = new tree_persistent_command (lst, l, c); |
2846 | 3689 else |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
3690 { |
16288
fe3b9a51e625
rename curr_lexer, curr_parser, CURR_LEXER
John W. Eaton <jwe@octave.org>
parents:
16287
diff
changeset
|
3691 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
|
3692 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
|
3693 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
|
3694 else |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
3695 warning ("ignoring persistent declaration near line %d", l); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
3696 } |
2846 | 3697 break; |
3698 | |
3699 default: | |
3700 panic_impossible (); | |
3701 break; | |
3702 } | |
3703 | |
3704 return retval; | |
3705 } | |
3706 | |
16273
c5e5f6ccac5d
9/10 commits reworking the lexer
John W. Eaton <jwe@octave.org>
parents:
16265
diff
changeset
|
3707 bool |
16287
04a7953496a7
create base class for parser; use reference for curr_lexer
John W. Eaton <jwe@octave.org>
parents:
16285
diff
changeset
|
3708 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
|
3709 { |
c5e5f6ccac5d
9/10 commits reworking the lexer
John W. Eaton <jwe@octave.org>
parents:
16265
diff
changeset
|
3710 bool retval = true; |
c5e5f6ccac5d
9/10 commits reworking the lexer
John W. Eaton <jwe@octave.org>
parents:
16265
diff
changeset
|
3711 |
c5e5f6ccac5d
9/10 commits reworking the lexer
John W. Eaton <jwe@octave.org>
parents:
16265
diff
changeset
|
3712 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
|
3713 |
c5e5f6ccac5d
9/10 commits reworking the lexer
John W. Eaton <jwe@octave.org>
parents:
16265
diff
changeset
|
3714 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
|
3715 { |
c5e5f6ccac5d
9/10 commits reworking the lexer
John W. Eaton <jwe@octave.org>
parents:
16265
diff
changeset
|
3716 tree_argument_list *row = *i; |
c5e5f6ccac5d
9/10 commits reworking the lexer
John W. Eaton <jwe@octave.org>
parents:
16265
diff
changeset
|
3717 |
c5e5f6ccac5d
9/10 commits reworking the lexer
John W. Eaton <jwe@octave.org>
parents:
16265
diff
changeset
|
3718 if (row && row->has_magic_tilde ()) |
c5e5f6ccac5d
9/10 commits reworking the lexer
John W. Eaton <jwe@octave.org>
parents:
16265
diff
changeset
|
3719 { |
c5e5f6ccac5d
9/10 commits reworking the lexer
John W. Eaton <jwe@octave.org>
parents:
16265
diff
changeset
|
3720 retval = false; |
c5e5f6ccac5d
9/10 commits reworking the lexer
John W. Eaton <jwe@octave.org>
parents:
16265
diff
changeset
|
3721 if (e->is_matrix ()) |
c5e5f6ccac5d
9/10 commits reworking the lexer
John W. Eaton <jwe@octave.org>
parents:
16265
diff
changeset
|
3722 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
|
3723 else |
c5e5f6ccac5d
9/10 commits reworking the lexer
John W. Eaton <jwe@octave.org>
parents:
16265
diff
changeset
|
3724 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
|
3725 break; |
c5e5f6ccac5d
9/10 commits reworking the lexer
John W. Eaton <jwe@octave.org>
parents:
16265
diff
changeset
|
3726 } |
c5e5f6ccac5d
9/10 commits reworking the lexer
John W. Eaton <jwe@octave.org>
parents:
16265
diff
changeset
|
3727 } |
c5e5f6ccac5d
9/10 commits reworking the lexer
John W. Eaton <jwe@octave.org>
parents:
16265
diff
changeset
|
3728 |
c5e5f6ccac5d
9/10 commits reworking the lexer
John W. Eaton <jwe@octave.org>
parents:
16265
diff
changeset
|
3729 return retval; |
c5e5f6ccac5d
9/10 commits reworking the lexer
John W. Eaton <jwe@octave.org>
parents:
16265
diff
changeset
|
3730 } |
c5e5f6ccac5d
9/10 commits reworking the lexer
John W. Eaton <jwe@octave.org>
parents:
16265
diff
changeset
|
3731 |
16134
ec9c6222ef5a
move static parser helper functions to octave_parser class
John W. Eaton <jwe@octave.org>
parents:
16133
diff
changeset
|
3732 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
|
3733 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
|
3734 { |
16273
c5e5f6ccac5d
9/10 commits reworking the lexer
John W. Eaton <jwe@octave.org>
parents:
16265
diff
changeset
|
3735 tree_argument_list *retval = 0; |
c5e5f6ccac5d
9/10 commits reworking the lexer
John W. Eaton <jwe@octave.org>
parents:
16265
diff
changeset
|
3736 |
c5e5f6ccac5d
9/10 commits reworking the lexer
John W. Eaton <jwe@octave.org>
parents:
16265
diff
changeset
|
3737 if (e->is_constant ()) |
c5e5f6ccac5d
9/10 commits reworking the lexer
John W. Eaton <jwe@octave.org>
parents:
16265
diff
changeset
|
3738 { |
16285
3389152014ca
improve validation of left hand side of assignment expressions in parser
John W. Eaton <jwe@octave.org>
parents:
16284
diff
changeset
|
3739 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
|
3740 |
3389152014ca
improve validation of left hand side of assignment expressions in parser
John W. Eaton <jwe@octave.org>
parents:
16284
diff
changeset
|
3741 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
|
3742 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
|
3743 else |
3389152014ca
improve validation of left hand side of assignment expressions in parser
John W. Eaton <jwe@octave.org>
parents:
16284
diff
changeset
|
3744 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
|
3745 |
16273
c5e5f6ccac5d
9/10 commits reworking the lexer
John W. Eaton <jwe@octave.org>
parents:
16265
diff
changeset
|
3746 delete e; |
c5e5f6ccac5d
9/10 commits reworking the lexer
John W. Eaton <jwe@octave.org>
parents:
16265
diff
changeset
|
3747 } |
c5e5f6ccac5d
9/10 commits reworking the lexer
John W. Eaton <jwe@octave.org>
parents:
16265
diff
changeset
|
3748 else |
c5e5f6ccac5d
9/10 commits reworking the lexer
John W. Eaton <jwe@octave.org>
parents:
16265
diff
changeset
|
3749 { |
16285
3389152014ca
improve validation of left hand side of assignment expressions in parser
John W. Eaton <jwe@octave.org>
parents:
16284
diff
changeset
|
3750 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
|
3751 |
3389152014ca
improve validation of left hand side of assignment expressions in parser
John W. Eaton <jwe@octave.org>
parents:
16284
diff
changeset
|
3752 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
|
3753 |
3389152014ca
improve validation of left hand side of assignment expressions in parser
John W. Eaton <jwe@octave.org>
parents:
16284
diff
changeset
|
3754 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
|
3755 { |
3389152014ca
improve validation of left hand side of assignment expressions in parser
John W. Eaton <jwe@octave.org>
parents:
16284
diff
changeset
|
3756 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
|
3757 |
3389152014ca
improve validation of left hand side of assignment expressions in parser
John W. Eaton <jwe@octave.org>
parents:
16284
diff
changeset
|
3758 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
|
3759 { |
3389152014ca
improve validation of left hand side of assignment expressions in parser
John W. Eaton <jwe@octave.org>
parents:
16284
diff
changeset
|
3760 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
|
3761 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
|
3762 delete e; |
3389152014ca
improve validation of left hand side of assignment expressions in parser
John W. Eaton <jwe@octave.org>
parents:
16284
diff
changeset
|
3763 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
|
3764 } |
3389152014ca
improve validation of left hand side of assignment expressions in parser
John W. Eaton <jwe@octave.org>
parents:
16284
diff
changeset
|
3765 } |
3389152014ca
improve validation of left hand side of assignment expressions in parser
John W. Eaton <jwe@octave.org>
parents:
16284
diff
changeset
|
3766 else |
3389152014ca
improve validation of left hand side of assignment expressions in parser
John W. Eaton <jwe@octave.org>
parents:
16284
diff
changeset
|
3767 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
|
3768 |
3389152014ca
improve validation of left hand side of assignment expressions in parser
John W. Eaton <jwe@octave.org>
parents:
16284
diff
changeset
|
3769 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
|
3770 { |
11115c237231
recognize variables when parsing (bug #38576)
John W. Eaton <jwe@octave.org>
parents:
16320
diff
changeset
|
3771 lexer.mark_as_variables (tmp->variable_names ()); |
11115c237231
recognize variables when parsing (bug #38576)
John W. Eaton <jwe@octave.org>
parents:
16320
diff
changeset
|
3772 retval = tmp; |
11115c237231
recognize variables when parsing (bug #38576)
John W. Eaton <jwe@octave.org>
parents:
16320
diff
changeset
|
3773 } |
16285
3389152014ca
improve validation of left hand side of assignment expressions in parser
John W. Eaton <jwe@octave.org>
parents:
16284
diff
changeset
|
3774 else |
3389152014ca
improve validation of left hand side of assignment expressions in parser
John W. Eaton <jwe@octave.org>
parents:
16284
diff
changeset
|
3775 { |
3389152014ca
improve validation of left hand side of assignment expressions in parser
John W. Eaton <jwe@octave.org>
parents:
16284
diff
changeset
|
3776 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
|
3777 delete tmp; |
3389152014ca
improve validation of left hand side of assignment expressions in parser
John W. Eaton <jwe@octave.org>
parents:
16284
diff
changeset
|
3778 } |
3389152014ca
improve validation of left hand side of assignment expressions in parser
John W. Eaton <jwe@octave.org>
parents:
16284
diff
changeset
|
3779 |
3389152014ca
improve validation of left hand side of assignment expressions in parser
John W. Eaton <jwe@octave.org>
parents:
16284
diff
changeset
|
3780 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
|
3781 retval->mark_as_simple_assign_lhs (); |
16273
c5e5f6ccac5d
9/10 commits reworking the lexer
John W. Eaton <jwe@octave.org>
parents:
16265
diff
changeset
|
3782 } |
c5e5f6ccac5d
9/10 commits reworking the lexer
John W. Eaton <jwe@octave.org>
parents:
16265
diff
changeset
|
3783 |
c5e5f6ccac5d
9/10 commits reworking the lexer
John W. Eaton <jwe@octave.org>
parents:
16265
diff
changeset
|
3784 return retval; |
10207
76a880a588ce
error when using ~ in matrix expression
Jaroslav Hajek <highegg@gmail.com>
parents:
10206
diff
changeset
|
3785 } |
76a880a588ce
error when using ~ in matrix expression
Jaroslav Hajek <highegg@gmail.com>
parents:
10206
diff
changeset
|
3786 |
16237
70f465930546
rearrange class heirarchy for tree_cell and tree_matrix
John W. Eaton <jwe@octave.org>
parents:
16210
diff
changeset
|
3787 // Finish building an array_list. |
1623 | 3788 |
16134
ec9c6222ef5a
move static parser helper functions to octave_parser class
John W. Eaton <jwe@octave.org>
parents:
16133
diff
changeset
|
3789 tree_expression * |
16287
04a7953496a7
create base class for parser; use reference for curr_lexer
John W. Eaton <jwe@octave.org>
parents:
16285
diff
changeset
|
3790 octave_base_parser::finish_array_list (tree_array_list *array_list) |
1623 | 3791 { |
16237
70f465930546
rearrange class heirarchy for tree_cell and tree_matrix
John W. Eaton <jwe@octave.org>
parents:
16210
diff
changeset
|
3792 tree_expression *retval = array_list; |
3110 | 3793 |
10067
6f79338c269b
omission from last patch
Jaroslav Hajek <highegg@gmail.com>
parents:
9794
diff
changeset
|
3794 unwind_protect frame; |
6f79338c269b
omission from last patch
Jaroslav Hajek <highegg@gmail.com>
parents:
9794
diff
changeset
|
3795 |
6f79338c269b
omission from last patch
Jaroslav Hajek <highegg@gmail.com>
parents:
9794
diff
changeset
|
3796 frame.protect_var (discard_error_messages); |
6f79338c269b
omission from last patch
Jaroslav Hajek <highegg@gmail.com>
parents:
9794
diff
changeset
|
3797 frame.protect_var (discard_warning_messages); |
4452 | 3798 |
3815 | 3799 discard_error_messages = true; |
4452 | 3800 discard_warning_messages = true; |
1623 | 3801 |
16237
70f465930546
rearrange class heirarchy for tree_cell and tree_matrix
John W. Eaton <jwe@octave.org>
parents:
16210
diff
changeset
|
3802 if (array_list->all_elements_are_constant ()) |
1829 | 3803 { |
16237
70f465930546
rearrange class heirarchy for tree_cell and tree_matrix
John W. Eaton <jwe@octave.org>
parents:
16210
diff
changeset
|
3804 octave_value tmp = array_list->rvalue1 (); |
1623 | 3805 |
20579
52ce821a52fd
eliminate simple uses of error_state in parser and lexer
John W. Eaton <jwe@octave.org>
parents:
20569
diff
changeset
|
3806 tree_constant *tc_retval |
52ce821a52fd
eliminate simple uses of error_state in parser and lexer
John W. Eaton <jwe@octave.org>
parents:
20569
diff
changeset
|
3807 = new tree_constant (tmp, array_list->line (), |
52ce821a52fd
eliminate simple uses of error_state in parser and lexer
John W. Eaton <jwe@octave.org>
parents:
20569
diff
changeset
|
3808 array_list->column ()); |
52ce821a52fd
eliminate simple uses of error_state in parser and lexer
John W. Eaton <jwe@octave.org>
parents:
20569
diff
changeset
|
3809 |
52ce821a52fd
eliminate simple uses of error_state in parser and lexer
John W. Eaton <jwe@octave.org>
parents:
20569
diff
changeset
|
3810 std::ostringstream buf; |
52ce821a52fd
eliminate simple uses of error_state in parser and lexer
John W. Eaton <jwe@octave.org>
parents:
20569
diff
changeset
|
3811 |
52ce821a52fd
eliminate simple uses of error_state in parser and lexer
John W. Eaton <jwe@octave.org>
parents:
20569
diff
changeset
|
3812 tree_print_code tpc (buf); |
52ce821a52fd
eliminate simple uses of error_state in parser and lexer
John W. Eaton <jwe@octave.org>
parents:
20569
diff
changeset
|
3813 |
52ce821a52fd
eliminate simple uses of error_state in parser and lexer
John W. Eaton <jwe@octave.org>
parents:
20569
diff
changeset
|
3814 array_list->accept (tpc); |
52ce821a52fd
eliminate simple uses of error_state in parser and lexer
John W. Eaton <jwe@octave.org>
parents:
20569
diff
changeset
|
3815 |
52ce821a52fd
eliminate simple uses of error_state in parser and lexer
John W. Eaton <jwe@octave.org>
parents:
20569
diff
changeset
|
3816 tc_retval->stash_original_text (buf.str ()); |
52ce821a52fd
eliminate simple uses of error_state in parser and lexer
John W. Eaton <jwe@octave.org>
parents:
20569
diff
changeset
|
3817 |
52ce821a52fd
eliminate simple uses of error_state in parser and lexer
John W. Eaton <jwe@octave.org>
parents:
20569
diff
changeset
|
3818 delete array_list; |
52ce821a52fd
eliminate simple uses of error_state in parser and lexer
John W. Eaton <jwe@octave.org>
parents:
20569
diff
changeset
|
3819 |
52ce821a52fd
eliminate simple uses of error_state in parser and lexer
John W. Eaton <jwe@octave.org>
parents:
20569
diff
changeset
|
3820 retval = tc_retval; |
1623 | 3821 } |
3110 | 3822 |
1623 | 3823 return retval; |
3824 } | |
3825 | |
16237
70f465930546
rearrange class heirarchy for tree_cell and tree_matrix
John W. Eaton <jwe@octave.org>
parents:
16210
diff
changeset
|
3826 // 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
|
3827 |
70f465930546
rearrange class heirarchy for tree_cell and tree_matrix
John W. Eaton <jwe@octave.org>
parents:
16210
diff
changeset
|
3828 tree_expression * |
16287
04a7953496a7
create base class for parser; use reference for curr_lexer
John W. Eaton <jwe@octave.org>
parents:
16285
diff
changeset
|
3829 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
|
3830 { |
16924
aebb54d99dba
improve compatibility of parsing of matrices and cell arrays
John W. Eaton <jwe@octave.org>
parents:
16850
diff
changeset
|
3831 return (m |
aebb54d99dba
improve compatibility of parsing of matrices and cell arrays
John W. Eaton <jwe@octave.org>
parents:
16850
diff
changeset
|
3832 ? finish_array_list (m) |
aebb54d99dba
improve compatibility of parsing of matrices and cell arrays
John W. Eaton <jwe@octave.org>
parents:
16850
diff
changeset
|
3833 : new tree_constant (octave_null_matrix::instance)); |
16237
70f465930546
rearrange class heirarchy for tree_cell and tree_matrix
John W. Eaton <jwe@octave.org>
parents:
16210
diff
changeset
|
3834 } |
70f465930546
rearrange class heirarchy for tree_cell and tree_matrix
John W. Eaton <jwe@octave.org>
parents:
16210
diff
changeset
|
3835 |
3351 | 3836 // Finish building a cell list. |
3837 | |
16134
ec9c6222ef5a
move static parser helper functions to octave_parser class
John W. Eaton <jwe@octave.org>
parents:
16133
diff
changeset
|
3838 tree_expression * |
16287
04a7953496a7
create base class for parser; use reference for curr_lexer
John W. Eaton <jwe@octave.org>
parents:
16285
diff
changeset
|
3839 octave_base_parser::finish_cell (tree_cell *c) |
3351 | 3840 { |
16924
aebb54d99dba
improve compatibility of parsing of matrices and cell arrays
John W. Eaton <jwe@octave.org>
parents:
16850
diff
changeset
|
3841 return (c |
aebb54d99dba
improve compatibility of parsing of matrices and cell arrays
John W. Eaton <jwe@octave.org>
parents:
16850
diff
changeset
|
3842 ? finish_array_list (c) |
aebb54d99dba
improve compatibility of parsing of matrices and cell arrays
John W. Eaton <jwe@octave.org>
parents:
16850
diff
changeset
|
3843 : new tree_constant (octave_value (Cell ()))); |
3351 | 3844 } |
3845 | |
16134
ec9c6222ef5a
move static parser helper functions to octave_parser class
John W. Eaton <jwe@octave.org>
parents:
16133
diff
changeset
|
3846 void |
16287
04a7953496a7
create base class for parser; use reference for curr_lexer
John W. Eaton <jwe@octave.org>
parents:
16285
diff
changeset
|
3847 octave_base_parser::maybe_warn_missing_semi (tree_statement_list *t) |
1511 | 3848 { |
16153
a57c2c8c8163
move some variables into the octave_parser class
John W. Eaton <jwe@octave.org>
parents:
16151
diff
changeset
|
3849 if (curr_fcn_depth > 0) |
1511 | 3850 { |
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
|
3851 tree_statement *tmp = t->back (); |
1607 | 3852 |
1511 | 3853 if (tmp->is_expression ()) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
3854 warning_with_id |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
3855 ("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
|
3856 "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
|
3857 tmp->line (), tmp->column (), lexer.fcn_file_full_name.c_str ()); |
1511 | 3858 } |
3859 } | |
1994 | 3860 |
16134
ec9c6222ef5a
move static parser helper functions to octave_parser class
John W. Eaton <jwe@octave.org>
parents:
16133
diff
changeset
|
3861 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
|
3862 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
|
3863 char sep, bool warn_missing_semi) |
2525 | 3864 { |
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
|
3865 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
|
3866 |
2525 | 3867 switch (sep) |
3868 { | |
3869 case ';': | |
8658
73c4516fae10
New evaluator and debugger derived from tree-walker class
John W. Eaton <jwe@octave.org>
parents:
8471
diff
changeset
|
3870 tmp->set_print_flag (false); |
2525 | 3871 break; |
3872 | |
3873 case 0: | |
3874 case ',': | |
3875 case '\n': | |
8658
73c4516fae10
New evaluator and debugger derived from tree-walker class
John W. Eaton <jwe@octave.org>
parents:
8471
diff
changeset
|
3876 tmp->set_print_flag (true); |
2525 | 3877 if (warn_missing_semi) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
3878 maybe_warn_missing_semi (list); |
2525 | 3879 break; |
3880 | |
3881 default: | |
3882 warning ("unrecognized separator type!"); | |
3883 break; | |
3884 } | |
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
|
3885 |
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
|
3886 // 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
|
3887 // 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
|
3888 |
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
|
3889 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
|
3890 { |
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
|
3891 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
|
3892 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
|
3893 } |
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
|
3894 |
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
|
3895 return list; |
2525 | 3896 } |
3897 | |
17693
efbe746f8fa8
eliminate octave_comment_buffer singleton
John W. Eaton <jwe@octave.org>
parents:
17673
diff
changeset
|
3898 // Finish building a statement. |
efbe746f8fa8
eliminate octave_comment_buffer singleton
John W. Eaton <jwe@octave.org>
parents:
17673
diff
changeset
|
3899 template <class T> |
efbe746f8fa8
eliminate octave_comment_buffer singleton
John W. Eaton <jwe@octave.org>
parents:
17673
diff
changeset
|
3900 tree_statement * |
efbe746f8fa8
eliminate octave_comment_buffer singleton
John W. Eaton <jwe@octave.org>
parents:
17673
diff
changeset
|
3901 octave_base_parser::make_statement (T *arg) |
efbe746f8fa8
eliminate octave_comment_buffer singleton
John W. Eaton <jwe@octave.org>
parents:
17673
diff
changeset
|
3902 { |
efbe746f8fa8
eliminate octave_comment_buffer singleton
John W. Eaton <jwe@octave.org>
parents:
17673
diff
changeset
|
3903 octave_comment_list *comment = lexer.get_comment (); |
efbe746f8fa8
eliminate octave_comment_buffer singleton
John W. Eaton <jwe@octave.org>
parents:
17673
diff
changeset
|
3904 |
efbe746f8fa8
eliminate octave_comment_buffer singleton
John W. Eaton <jwe@octave.org>
parents:
17673
diff
changeset
|
3905 return new tree_statement (arg, comment); |
efbe746f8fa8
eliminate octave_comment_buffer singleton
John W. Eaton <jwe@octave.org>
parents:
17673
diff
changeset
|
3906 } |
efbe746f8fa8
eliminate octave_comment_buffer singleton
John W. Eaton <jwe@octave.org>
parents:
17673
diff
changeset
|
3907 |
16134
ec9c6222ef5a
move static parser helper functions to octave_parser class
John W. Eaton <jwe@octave.org>
parents:
16133
diff
changeset
|
3908 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
|
3909 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
|
3910 { |
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
|
3911 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
|
3912 } |
d6c0d5f208de
parse.y: avoid storing null statements in statement lists
John W. Eaton <jwe@octave.org>
parents:
8447
diff
changeset
|
3913 |
16134
ec9c6222ef5a
move static parser helper functions to octave_parser class
John W. Eaton <jwe@octave.org>
parents:
16133
diff
changeset
|
3914 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
|
3915 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
|
3916 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
|
3917 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
|
3918 { |
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
|
3919 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
|
3920 |
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
|
3921 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
|
3922 |
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
|
3923 return list; |
8448
d6c0d5f208de
parse.y: avoid storing null statements in statement lists
John W. Eaton <jwe@octave.org>
parents:
8447
diff
changeset
|
3924 } |
d6c0d5f208de
parse.y: avoid storing null statements in statement lists
John W. Eaton <jwe@octave.org>
parents:
8447
diff
changeset
|
3925 |
16145
edddf8903f15
maint: reorder functions in oct-parse.yy
John W. Eaton <jwe@octave.org>
parents:
16142
diff
changeset
|
3926 void |
16287
04a7953496a7
create base class for parser; use reference for curr_lexer
John W. Eaton <jwe@octave.org>
parents:
16285
diff
changeset
|
3927 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
|
3928 { |
16288
fe3b9a51e625
rename curr_lexer, curr_parser, CURR_LEXER
John W. Eaton <jwe@octave.org>
parents:
16287
diff
changeset
|
3929 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
|
3930 |
edddf8903f15
maint: reorder functions in oct-parse.yy
John W. Eaton <jwe@octave.org>
parents:
16142
diff
changeset
|
3931 std::ostringstream output_buf; |
edddf8903f15
maint: reorder functions in oct-parse.yy
John W. Eaton <jwe@octave.org>
parents:
16142
diff
changeset
|
3932 |
16288
fe3b9a51e625
rename curr_lexer, curr_parser, CURR_LEXER
John W. Eaton <jwe@octave.org>
parents:
16287
diff
changeset
|
3933 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
|
3934 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
|
3935 << " 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
|
3936 else |
edddf8903f15
maint: reorder functions in oct-parse.yy
John W. Eaton <jwe@octave.org>
parents:
16142
diff
changeset
|
3937 output_buf << "parse error:"; |
edddf8903f15
maint: reorder functions in oct-parse.yy
John W. Eaton <jwe@octave.org>
parents:
16142
diff
changeset
|
3938 |
edddf8903f15
maint: reorder functions in oct-parse.yy
John W. Eaton <jwe@octave.org>
parents:
16142
diff
changeset
|
3939 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
|
3940 output_buf << "\n\n " << s; |
edddf8903f15
maint: reorder functions in oct-parse.yy
John W. Eaton <jwe@octave.org>
parents:
16142
diff
changeset
|
3941 |
edddf8903f15
maint: reorder functions in oct-parse.yy
John W. Eaton <jwe@octave.org>
parents:
16142
diff
changeset
|
3942 output_buf << "\n\n"; |
edddf8903f15
maint: reorder functions in oct-parse.yy
John W. Eaton <jwe@octave.org>
parents:
16142
diff
changeset
|
3943 |
16288
fe3b9a51e625
rename curr_lexer, curr_parser, CURR_LEXER
John W. Eaton <jwe@octave.org>
parents:
16287
diff
changeset
|
3944 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
|
3945 |
0467d68ca891
move current_input_line to lexical_feedback class
John W. Eaton <jwe@octave.org>
parents:
16203
diff
changeset
|
3946 if (! curr_line.empty ()) |
16145
edddf8903f15
maint: reorder functions in oct-parse.yy
John W. Eaton <jwe@octave.org>
parents:
16142
diff
changeset
|
3947 { |
16207
0467d68ca891
move current_input_line to lexical_feedback class
John W. Eaton <jwe@octave.org>
parents:
16203
diff
changeset
|
3948 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
|
3949 |
0467d68ca891
move current_input_line to lexical_feedback class
John W. Eaton <jwe@octave.org>
parents:
16203
diff
changeset
|
3950 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
|
3951 curr_line.resize (len-1); |
16145
edddf8903f15
maint: reorder functions in oct-parse.yy
John W. Eaton <jwe@octave.org>
parents:
16142
diff
changeset
|
3952 |
edddf8903f15
maint: reorder functions in oct-parse.yy
John W. Eaton <jwe@octave.org>
parents:
16142
diff
changeset
|
3953 // 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
|
3954 |
16207
0467d68ca891
move current_input_line to lexical_feedback class
John W. Eaton <jwe@octave.org>
parents:
16203
diff
changeset
|
3955 output_buf << ">>> " << curr_line << "\n"; |
16145
edddf8903f15
maint: reorder functions in oct-parse.yy
John W. Eaton <jwe@octave.org>
parents:
16142
diff
changeset
|
3956 |
edddf8903f15
maint: reorder functions in oct-parse.yy
John W. Eaton <jwe@octave.org>
parents:
16142
diff
changeset
|
3957 if (err_col == 0) |
edddf8903f15
maint: reorder functions in oct-parse.yy
John W. Eaton <jwe@octave.org>
parents:
16142
diff
changeset
|
3958 err_col = len; |
edddf8903f15
maint: reorder functions in oct-parse.yy
John W. Eaton <jwe@octave.org>
parents:
16142
diff
changeset
|
3959 |
edddf8903f15
maint: reorder functions in oct-parse.yy
John W. Eaton <jwe@octave.org>
parents:
16142
diff
changeset
|
3960 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
|
3961 output_buf << " "; |
edddf8903f15
maint: reorder functions in oct-parse.yy
John W. Eaton <jwe@octave.org>
parents:
16142
diff
changeset
|
3962 |
edddf8903f15
maint: reorder functions in oct-parse.yy
John W. Eaton <jwe@octave.org>
parents:
16142
diff
changeset
|
3963 output_buf << "^"; |
edddf8903f15
maint: reorder functions in oct-parse.yy
John W. Eaton <jwe@octave.org>
parents:
16142
diff
changeset
|
3964 } |
edddf8903f15
maint: reorder functions in oct-parse.yy
John W. Eaton <jwe@octave.org>
parents:
16142
diff
changeset
|
3965 |
edddf8903f15
maint: reorder functions in oct-parse.yy
John W. Eaton <jwe@octave.org>
parents:
16142
diff
changeset
|
3966 output_buf << "\n"; |
edddf8903f15
maint: reorder functions in oct-parse.yy
John W. Eaton <jwe@octave.org>
parents:
16142
diff
changeset
|
3967 |
edddf8903f15
maint: reorder functions in oct-parse.yy
John W. Eaton <jwe@octave.org>
parents:
16142
diff
changeset
|
3968 std::string msg = output_buf.str (); |
edddf8903f15
maint: reorder functions in oct-parse.yy
John W. Eaton <jwe@octave.org>
parents:
16142
diff
changeset
|
3969 |
edddf8903f15
maint: reorder functions in oct-parse.yy
John W. Eaton <jwe@octave.org>
parents:
16142
diff
changeset
|
3970 parse_error ("%s", msg.c_str ()); |
edddf8903f15
maint: reorder functions in oct-parse.yy
John W. Eaton <jwe@octave.org>
parents:
16142
diff
changeset
|
3971 } |
edddf8903f15
maint: reorder functions in oct-parse.yy
John W. Eaton <jwe@octave.org>
parents:
16142
diff
changeset
|
3972 |
16287
04a7953496a7
create base class for parser; use reference for curr_lexer
John W. Eaton <jwe@octave.org>
parents:
16285
diff
changeset
|
3973 int |
04a7953496a7
create base class for parser; use reference for curr_lexer
John W. Eaton <jwe@octave.org>
parents:
16285
diff
changeset
|
3974 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
|
3975 { |
04a7953496a7
create base class for parser; use reference for curr_lexer
John W. Eaton <jwe@octave.org>
parents:
16285
diff
changeset
|
3976 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
|
3977 } |
04a7953496a7
create base class for parser; use reference for curr_lexer
John W. Eaton <jwe@octave.org>
parents:
16285
diff
changeset
|
3978 |
16294
0925d1f6875e
push parser/lexer interface
John W. Eaton <jwe@octave.org>
parents:
16293
diff
changeset
|
3979 octave_push_parser::~octave_push_parser (void) |
0925d1f6875e
push parser/lexer interface
John W. Eaton <jwe@octave.org>
parents:
16293
diff
changeset
|
3980 { |
0925d1f6875e
push parser/lexer interface
John W. Eaton <jwe@octave.org>
parents:
16293
diff
changeset
|
3981 yypstate_delete (static_cast<yypstate *> (parser_state)); |
0925d1f6875e
push parser/lexer interface
John W. Eaton <jwe@octave.org>
parents:
16293
diff
changeset
|
3982 } |
0925d1f6875e
push parser/lexer interface
John W. Eaton <jwe@octave.org>
parents:
16293
diff
changeset
|
3983 |
0925d1f6875e
push parser/lexer interface
John W. Eaton <jwe@octave.org>
parents:
16293
diff
changeset
|
3984 void |
0925d1f6875e
push parser/lexer interface
John W. Eaton <jwe@octave.org>
parents:
16293
diff
changeset
|
3985 octave_push_parser::init (void) |
0925d1f6875e
push parser/lexer interface
John W. Eaton <jwe@octave.org>
parents:
16293
diff
changeset
|
3986 { |
0925d1f6875e
push parser/lexer interface
John W. Eaton <jwe@octave.org>
parents:
16293
diff
changeset
|
3987 parser_state = yypstate_new (); |
0925d1f6875e
push parser/lexer interface
John W. Eaton <jwe@octave.org>
parents:
16293
diff
changeset
|
3988 } |
0925d1f6875e
push parser/lexer interface
John W. Eaton <jwe@octave.org>
parents:
16293
diff
changeset
|
3989 |
0925d1f6875e
push parser/lexer interface
John W. Eaton <jwe@octave.org>
parents:
16293
diff
changeset
|
3990 // 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
|
3991 // finish the parse. |
0925d1f6875e
push parser/lexer interface
John W. Eaton <jwe@octave.org>
parents:
16293
diff
changeset
|
3992 |
0925d1f6875e
push parser/lexer interface
John W. Eaton <jwe@octave.org>
parents:
16293
diff
changeset
|
3993 int |
0925d1f6875e
push parser/lexer interface
John W. Eaton <jwe@octave.org>
parents:
16293
diff
changeset
|
3994 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
|
3995 { |
0925d1f6875e
push parser/lexer interface
John W. Eaton <jwe@octave.org>
parents:
16293
diff
changeset
|
3996 int status = -1; |
0925d1f6875e
push parser/lexer interface
John W. Eaton <jwe@octave.org>
parents:
16293
diff
changeset
|
3997 |
0925d1f6875e
push parser/lexer interface
John W. Eaton <jwe@octave.org>
parents:
16293
diff
changeset
|
3998 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
|
3999 |
0925d1f6875e
push parser/lexer interface
John W. Eaton <jwe@octave.org>
parents:
16293
diff
changeset
|
4000 do |
19627
446c46af4b42
strip trailing whitespace from most source files
John W. Eaton <jwe@octave.org>
parents:
19008
diff
changeset
|
4001 { |
16294
0925d1f6875e
push parser/lexer interface
John W. Eaton <jwe@octave.org>
parents:
16293
diff
changeset
|
4002 YYSTYPE lval; |
0925d1f6875e
push parser/lexer interface
John W. Eaton <jwe@octave.org>
parents:
16293
diff
changeset
|
4003 |
0925d1f6875e
push parser/lexer interface
John W. Eaton <jwe@octave.org>
parents:
16293
diff
changeset
|
4004 int token = octave_lex (&lval, scanner); |
0925d1f6875e
push parser/lexer interface
John W. Eaton <jwe@octave.org>
parents:
16293
diff
changeset
|
4005 |
0925d1f6875e
push parser/lexer interface
John W. Eaton <jwe@octave.org>
parents:
16293
diff
changeset
|
4006 if (token < 0) |
0925d1f6875e
push parser/lexer interface
John W. Eaton <jwe@octave.org>
parents:
16293
diff
changeset
|
4007 { |
0925d1f6875e
push parser/lexer interface
John W. Eaton <jwe@octave.org>
parents:
16293
diff
changeset
|
4008 if (! eof && lexer.at_end_of_buffer ()) |
0925d1f6875e
push parser/lexer interface
John W. Eaton <jwe@octave.org>
parents:
16293
diff
changeset
|
4009 { |
0925d1f6875e
push parser/lexer interface
John W. Eaton <jwe@octave.org>
parents:
16293
diff
changeset
|
4010 status = -1; |
0925d1f6875e
push parser/lexer interface
John W. Eaton <jwe@octave.org>
parents:
16293
diff
changeset
|
4011 break; |
0925d1f6875e
push parser/lexer interface
John W. Eaton <jwe@octave.org>
parents:
16293
diff
changeset
|
4012 } |
0925d1f6875e
push parser/lexer interface
John W. Eaton <jwe@octave.org>
parents:
16293
diff
changeset
|
4013 } |
0925d1f6875e
push parser/lexer interface
John W. Eaton <jwe@octave.org>
parents:
16293
diff
changeset
|
4014 |
0925d1f6875e
push parser/lexer interface
John W. Eaton <jwe@octave.org>
parents:
16293
diff
changeset
|
4015 yypstate *pstate = static_cast<yypstate *> (parser_state); |
0925d1f6875e
push parser/lexer interface
John W. Eaton <jwe@octave.org>
parents:
16293
diff
changeset
|
4016 |
0925d1f6875e
push parser/lexer interface
John W. Eaton <jwe@octave.org>
parents:
16293
diff
changeset
|
4017 status = octave_push_parse (pstate, token, &lval, *this); |
0925d1f6875e
push parser/lexer interface
John W. Eaton <jwe@octave.org>
parents:
16293
diff
changeset
|
4018 } |
0925d1f6875e
push parser/lexer interface
John W. Eaton <jwe@octave.org>
parents:
16293
diff
changeset
|
4019 while (status == YYPUSH_MORE); |
0925d1f6875e
push parser/lexer interface
John W. Eaton <jwe@octave.org>
parents:
16293
diff
changeset
|
4020 |
0925d1f6875e
push parser/lexer interface
John W. Eaton <jwe@octave.org>
parents:
16293
diff
changeset
|
4021 return status; |
0925d1f6875e
push parser/lexer interface
John W. Eaton <jwe@octave.org>
parents:
16293
diff
changeset
|
4022 } |
0925d1f6875e
push parser/lexer interface
John W. Eaton <jwe@octave.org>
parents:
16293
diff
changeset
|
4023 |
3021 | 4024 static void |
10067
6f79338c269b
omission from last patch
Jaroslav Hajek <highegg@gmail.com>
parents:
9794
diff
changeset
|
4025 safe_fclose (FILE *f) |
3021 | 4026 { |
4027 if (f) | |
4028 fclose (static_cast<FILE *> (f)); | |
4029 } | |
4030 | |
7336 | 4031 static octave_function * |
16203
127cccb037bf
move more global parser and lexer variables to classes
John W. Eaton <jwe@octave.org>
parents:
16199
diff
changeset
|
4032 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
|
4033 const std::string& dispatch_type, |
16676
7368654f302f
Initial support for (classdef) packages.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
16644
diff
changeset
|
4034 const std::string& package_name, |
19627
446c46af4b42
strip trailing whitespace from most source files
John W. Eaton <jwe@octave.org>
parents:
19008
diff
changeset
|
4035 bool require_file, bool force_script, bool autoload, |
16153
a57c2c8c8163
move some variables into the octave_parser class
John W. Eaton <jwe@octave.org>
parents:
16151
diff
changeset
|
4036 bool relative_lookup, const std::string& warn_for) |
3021 | 4037 { |
10067
6f79338c269b
omission from last patch
Jaroslav Hajek <highegg@gmail.com>
parents:
9794
diff
changeset
|
4038 unwind_protect frame; |
3021 | 4039 |
7336 | 4040 octave_function *fcn_ptr = 0; |
3021 | 4041 |
4042 // Open function file and parse. | |
4043 | |
4044 FILE *in_stream = command_editor::get_input_stream (); | |
4045 | |
10067
6f79338c269b
omission from last patch
Jaroslav Hajek <highegg@gmail.com>
parents:
9794
diff
changeset
|
4046 frame.add_fcn (command_editor::set_input_stream, in_stream); |
6f79338c269b
omission from last patch
Jaroslav Hajek <highegg@gmail.com>
parents:
9794
diff
changeset
|
4047 |
12989
00235a6446da
eliminate duplication of internal variables controlling command history
John W. Eaton <jwe@octave.org>
parents:
12973
diff
changeset
|
4048 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
|
4049 command_history::ignoring_entries ()); |
00235a6446da
eliminate duplication of internal variables controlling command history
John W. Eaton <jwe@octave.org>
parents:
12973
diff
changeset
|
4050 |
7715
5b4d278ec828
parse scripts completely before executing
John W. Eaton <jwe@octave.org>
parents:
7699
diff
changeset
|
4051 command_history::ignore_entries (); |
5b4d278ec828
parse scripts completely before executing
John W. Eaton <jwe@octave.org>
parents:
7699
diff
changeset
|
4052 |
16198
2c5c538be353
clean up input.cc and eliminate ff_instream global variable
John W. Eaton <jwe@octave.org>
parents:
16195
diff
changeset
|
4053 FILE *ffile = 0; |
2c5c538be353
clean up input.cc and eliminate ff_instream global variable
John W. Eaton <jwe@octave.org>
parents:
16195
diff
changeset
|
4054 |
16203
127cccb037bf
move more global parser and lexer variables to classes
John W. Eaton <jwe@octave.org>
parents:
16199
diff
changeset
|
4055 if (! full_file.empty ()) |
127cccb037bf
move more global parser and lexer variables to classes
John W. Eaton <jwe@octave.org>
parents:
16199
diff
changeset
|
4056 ffile = gnulib::fopen (full_file.c_str (), "rb"); |
3021 | 4057 |
4058 if (ffile) | |
4059 { | |
19743
5cfb3ccbf24a
style fixes for resource management
John W. Eaton <jwe@octave.org>
parents:
19731
diff
changeset
|
4060 frame.add_fcn (safe_fclose, ffile); |
5cfb3ccbf24a
style fixes for resource management
John W. Eaton <jwe@octave.org>
parents:
19731
diff
changeset
|
4061 |
16287
04a7953496a7
create base class for parser; use reference for curr_lexer
John W. Eaton <jwe@octave.org>
parents:
16285
diff
changeset
|
4062 // 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
|
4063 frame.protect_var (LEXER); |
fe3b9a51e625
rename curr_lexer, curr_parser, CURR_LEXER
John W. Eaton <jwe@octave.org>
parents:
16287
diff
changeset
|
4064 |
fe3b9a51e625
rename curr_lexer, curr_parser, CURR_LEXER
John W. Eaton <jwe@octave.org>
parents:
16287
diff
changeset
|
4065 octave_parser parser (ffile); |
fe3b9a51e625
rename curr_lexer, curr_parser, CURR_LEXER
John W. Eaton <jwe@octave.org>
parents:
16287
diff
changeset
|
4066 |
fe3b9a51e625
rename curr_lexer, curr_parser, CURR_LEXER
John W. Eaton <jwe@octave.org>
parents:
16287
diff
changeset
|
4067 parser.curr_class_name = dispatch_type; |
16676
7368654f302f
Initial support for (classdef) packages.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
16644
diff
changeset
|
4068 parser.curr_package_name = package_name; |
16288
fe3b9a51e625
rename curr_lexer, curr_parser, CURR_LEXER
John W. Eaton <jwe@octave.org>
parents:
16287
diff
changeset
|
4069 parser.autoloading = autoload; |
fe3b9a51e625
rename curr_lexer, curr_parser, CURR_LEXER
John W. Eaton <jwe@octave.org>
parents:
16287
diff
changeset
|
4070 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
|
4071 |
fe3b9a51e625
rename curr_lexer, curr_parser, CURR_LEXER
John W. Eaton <jwe@octave.org>
parents:
16287
diff
changeset
|
4072 parser.lexer.force_script = force_script; |
fe3b9a51e625
rename curr_lexer, curr_parser, CURR_LEXER
John W. Eaton <jwe@octave.org>
parents:
16287
diff
changeset
|
4073 parser.lexer.prep_for_file (); |
fe3b9a51e625
rename curr_lexer, curr_parser, CURR_LEXER
John W. Eaton <jwe@octave.org>
parents:
16287
diff
changeset
|
4074 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
|
4075 |
fe3b9a51e625
rename curr_lexer, curr_parser, CURR_LEXER
John W. Eaton <jwe@octave.org>
parents:
16287
diff
changeset
|
4076 parser.lexer.fcn_file_name = file; |
fe3b9a51e625
rename curr_lexer, curr_parser, CURR_LEXER
John W. Eaton <jwe@octave.org>
parents:
16287
diff
changeset
|
4077 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
|
4078 |
fe3b9a51e625
rename curr_lexer, curr_parser, CURR_LEXER
John W. Eaton <jwe@octave.org>
parents:
16287
diff
changeset
|
4079 int status = parser.run (); |
fe3b9a51e625
rename curr_lexer, curr_parser, CURR_LEXER
John W. Eaton <jwe@octave.org>
parents:
16287
diff
changeset
|
4080 |
fe3b9a51e625
rename curr_lexer, curr_parser, CURR_LEXER
John W. Eaton <jwe@octave.org>
parents:
16287
diff
changeset
|
4081 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
|
4082 |
16211
3449bf257514
maint: fix botched merge of default to classdef
John W. Eaton <jwe@octave.org>
parents:
16205
diff
changeset
|
4083 if (status == 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
|
4084 { |
16289
bde729ba8381
maint: periodic merge of default to classdef
John W. Eaton <jwe@octave.org>
diff
changeset
|
4085 if (parser.lexer.reading_classdef_file |
bde729ba8381
maint: periodic merge of default to classdef
John W. Eaton <jwe@octave.org>
diff
changeset
|
4086 && parser.classdef_object) |
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
|
4087 { |
16211
3449bf257514
maint: fix botched merge of default to classdef
John W. Eaton <jwe@octave.org>
parents:
16205
diff
changeset
|
4088 // Convert parse tree for classdef object to |
3449bf257514
maint: fix botched merge of default to classdef
John W. Eaton <jwe@octave.org>
parents:
16205
diff
changeset
|
4089 // meta.class info (and stash it in the symbol |
3449bf257514
maint: fix botched merge of default to classdef
John W. Eaton <jwe@octave.org>
parents:
16205
diff
changeset
|
4090 // table?). Return pointer to constructor? |
3449bf257514
maint: fix botched merge of default to classdef
John W. Eaton <jwe@octave.org>
parents:
16205
diff
changeset
|
4091 |
3449bf257514
maint: fix botched merge of default to classdef
John W. Eaton <jwe@octave.org>
parents:
16205
diff
changeset
|
4092 if (fcn_ptr) |
3449bf257514
maint: fix botched merge of default to classdef
John W. Eaton <jwe@octave.org>
parents:
16205
diff
changeset
|
4093 panic_impossible (); |
3449bf257514
maint: fix botched merge of default to classdef
John W. Eaton <jwe@octave.org>
parents:
16205
diff
changeset
|
4094 |
18263
b5be1a2aa5ab
Initial implementation for classdef methods in separate files.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
18262
diff
changeset
|
4095 bool is_at_folder = ! dispatch_type.empty (); |
b5be1a2aa5ab
Initial implementation for classdef methods in separate files.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
18262
diff
changeset
|
4096 |
b5be1a2aa5ab
Initial implementation for classdef methods in separate files.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
18262
diff
changeset
|
4097 fcn_ptr = |
b5be1a2aa5ab
Initial implementation for classdef methods in separate files.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
18262
diff
changeset
|
4098 parser.classdef_object->make_meta_class (is_at_folder); |
15037
56b8eb7c9c04
improvements in parsing classdef
John W. Eaton <jwe@octave.org>
parents:
14846
diff
changeset
|
4099 } |
16644
856cb7cba231
maint: periodic merge of default to classdef
John W. Eaton <jwe@octave.org>
diff
changeset
|
4100 else if (fcn_ptr) |
856cb7cba231
maint: periodic merge of default to classdef
John W. Eaton <jwe@octave.org>
diff
changeset
|
4101 { |
856cb7cba231
maint: periodic merge of default to classdef
John W. Eaton <jwe@octave.org>
diff
changeset
|
4102 fcn_ptr->maybe_relocate_end (); |
856cb7cba231
maint: periodic merge of default to classdef
John W. Eaton <jwe@octave.org>
diff
changeset
|
4103 |
856cb7cba231
maint: periodic merge of default to classdef
John W. Eaton <jwe@octave.org>
diff
changeset
|
4104 if (parser.parsing_subfunctions) |
856cb7cba231
maint: periodic merge of default to classdef
John W. Eaton <jwe@octave.org>
diff
changeset
|
4105 { |
856cb7cba231
maint: periodic merge of default to classdef
John W. Eaton <jwe@octave.org>
diff
changeset
|
4106 if (! parser.endfunction_found) |
856cb7cba231
maint: periodic merge of default to classdef
John W. Eaton <jwe@octave.org>
diff
changeset
|
4107 parser.subfunction_names.reverse (); |
856cb7cba231
maint: periodic merge of default to classdef
John W. Eaton <jwe@octave.org>
diff
changeset
|
4108 |
856cb7cba231
maint: periodic merge of default to classdef
John W. Eaton <jwe@octave.org>
diff
changeset
|
4109 fcn_ptr->stash_subfunction_names (parser.subfunction_names); |
856cb7cba231
maint: periodic merge of default to classdef
John W. Eaton <jwe@octave.org>
diff
changeset
|
4110 } |
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
|
4111 } |
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
|
4112 } |
10872
988d16d5ae34
correctly .m files that are empty or contain only comments
John W. Eaton <jwe@octave.org>
parents:
10659
diff
changeset
|
4113 else |
16203
127cccb037bf
move more global parser and lexer variables to classes
John W. Eaton <jwe@octave.org>
parents:
16199
diff
changeset
|
4114 error ("parse error while reading file %s", full_file.c_str ()); |
3021 | 4115 } |
7715
5b4d278ec828
parse scripts completely before executing
John W. Eaton <jwe@octave.org>
parents:
7699
diff
changeset
|
4116 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
|
4117 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
|
4118 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
|
4119 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
|
4120 full_file.c_str ()); |
3021 | 4121 |
7336 | 4122 return fcn_ptr; |
3021 | 4123 } |
4124 | |
5484 | 4125 std::string |
7715
5b4d278ec828
parse scripts completely before executing
John W. Eaton <jwe@octave.org>
parents:
7699
diff
changeset
|
4126 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
|
4127 std::string& full_file) |
7715
5b4d278ec828
parse scripts completely before executing
John W. Eaton <jwe@octave.org>
parents:
7699
diff
changeset
|
4128 { |
5b4d278ec828
parse scripts completely before executing
John W. Eaton <jwe@octave.org>
parents:
7699
diff
changeset
|
4129 std::string retval; |
5b4d278ec828
parse scripts completely before executing
John W. Eaton <jwe@octave.org>
parents:
7699
diff
changeset
|
4130 |
16203
127cccb037bf
move more global parser and lexer variables to classes
John W. Eaton <jwe@octave.org>
parents:
16199
diff
changeset
|
4131 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
|
4132 |
127cccb037bf
move more global parser and lexer variables to classes
John W. Eaton <jwe@octave.org>
parents:
16199
diff
changeset
|
4133 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
|
4134 |
127cccb037bf
move more global parser and lexer variables to classes
John W. Eaton <jwe@octave.org>
parents:
16199
diff
changeset
|
4135 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
|
4136 |
127cccb037bf
move more global parser and lexer variables to classes
John W. Eaton <jwe@octave.org>
parents:
16199
diff
changeset
|
4137 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
|
4138 || (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
|
4139 || (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
|
4140 { |
127cccb037bf
move more global parser and lexer variables to classes
John W. Eaton <jwe@octave.org>
parents:
16199
diff
changeset
|
4141 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
|
4142 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
|
4143 |
127cccb037bf
move more global parser and lexer variables to classes
John W. Eaton <jwe@octave.org>
parents:
16199
diff
changeset
|
4144 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
|
4145 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
|
4146 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
|
4147 } |
7715
5b4d278ec828
parse scripts completely before executing
John W. Eaton <jwe@octave.org>
parents:
7699
diff
changeset
|
4148 |
5b4d278ec828
parse scripts completely before executing
John W. Eaton <jwe@octave.org>
parents:
7699
diff
changeset
|
4149 if (! file.empty ()) |
5b4d278ec828
parse scripts completely before executing
John W. Eaton <jwe@octave.org>
parents:
7699
diff
changeset
|
4150 { |
5b4d278ec828
parse scripts completely before executing
John W. Eaton <jwe@octave.org>
parents:
7699
diff
changeset
|
4151 symbol_found = true; |
5b4d278ec828
parse scripts completely before executing
John W. Eaton <jwe@octave.org>
parents:
7699
diff
changeset
|
4152 |
16203
127cccb037bf
move more global parser and lexer variables to classes
John W. Eaton <jwe@octave.org>
parents:
16199
diff
changeset
|
4153 octave_function *fcn |
16676
7368654f302f
Initial support for (classdef) packages.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
16644
diff
changeset
|
4154 = parse_fcn_file (full_file, file, "", "", true, false, false, false, |
7368654f302f
Initial support for (classdef) packages.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
16644
diff
changeset
|
4155 ""); |
16203
127cccb037bf
move more global parser and lexer variables to classes
John W. Eaton <jwe@octave.org>
parents:
16199
diff
changeset
|
4156 |
127cccb037bf
move more global parser and lexer variables to classes
John W. Eaton <jwe@octave.org>
parents:
16199
diff
changeset
|
4157 if (fcn) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
4158 { |
16203
127cccb037bf
move more global parser and lexer variables to classes
John W. Eaton <jwe@octave.org>
parents:
16199
diff
changeset
|
4159 retval = fcn->doc_string (); |
127cccb037bf
move more global parser and lexer variables to classes
John W. Eaton <jwe@octave.org>
parents:
16199
diff
changeset
|
4160 |
127cccb037bf
move more global parser and lexer variables to classes
John W. Eaton <jwe@octave.org>
parents:
16199
diff
changeset
|
4161 delete fcn; |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
4162 } |
7715
5b4d278ec828
parse scripts completely before executing
John W. Eaton <jwe@octave.org>
parents:
7699
diff
changeset
|
4163 } |
5b4d278ec828
parse scripts completely before executing
John W. Eaton <jwe@octave.org>
parents:
7699
diff
changeset
|
4164 |
5b4d278ec828
parse scripts completely before executing
John W. Eaton <jwe@octave.org>
parents:
7699
diff
changeset
|
4165 return retval; |
5b4d278ec828
parse scripts completely before executing
John W. Eaton <jwe@octave.org>
parents:
7699
diff
changeset
|
4166 } |
5b4d278ec828
parse scripts completely before executing
John W. Eaton <jwe@octave.org>
parents:
7699
diff
changeset
|
4167 |
5b4d278ec828
parse scripts completely before executing
John W. Eaton <jwe@octave.org>
parents:
7699
diff
changeset
|
4168 std::string |
5b4d278ec828
parse scripts completely before executing
John W. Eaton <jwe@octave.org>
parents:
7699
diff
changeset
|
4169 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
|
4170 { |
5b4d278ec828
parse scripts completely before executing
John W. Eaton <jwe@octave.org>
parents:
7699
diff
changeset
|
4171 std::string file; |
5b4d278ec828
parse scripts completely before executing
John W. Eaton <jwe@octave.org>
parents:
7699
diff
changeset
|
4172 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
|
4173 } |
5b4d278ec828
parse scripts completely before executing
John W. Eaton <jwe@octave.org>
parents:
7699
diff
changeset
|
4174 |
5b4d278ec828
parse scripts completely before executing
John W. Eaton <jwe@octave.org>
parents:
7699
diff
changeset
|
4175 std::string |
5484 | 4176 lookup_autoload (const std::string& nm) |
4177 { | |
5626 | 4178 std::string retval; |
4179 | |
4180 typedef std::map<std::string, std::string>::const_iterator am_iter; | |
4181 | |
4182 am_iter p = autoload_map.find (nm); | |
4183 | |
4184 if (p != autoload_map.end ()) | |
6323 | 4185 retval = load_path::find_file (p->second); |
5626 | 4186 |
4187 return retval; | |
5484 | 4188 } |
4189 | |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11572
diff
changeset
|
4190 string_vector |
5592 | 4191 autoloaded_functions (void) |
4192 { | |
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
|
4193 string_vector names (autoload_map.size ()); |
5592 | 4194 |
4195 octave_idx_type i = 0; | |
5626 | 4196 typedef std::map<std::string, std::string>::const_iterator am_iter; |
4197 for (am_iter p = autoload_map.begin (); p != autoload_map.end (); p++) | |
5592 | 4198 names[i++] = p->first; |
4199 | |
4200 return names; | |
4201 } | |
4202 | |
4203 string_vector | |
4204 reverse_lookup_autoload (const std::string& nm) | |
4205 { | |
4206 string_vector names; | |
4207 | |
5626 | 4208 typedef std::map<std::string, std::string>::const_iterator am_iter; |
4209 for (am_iter p = autoload_map.begin (); p != autoload_map.end (); p++) | |
5592 | 4210 if (nm == p->second) |
4211 names.append (p->first); | |
4212 | |
4213 return names; | |
4214 } | |
4215 | |
7336 | 4216 octave_function * |
4217 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
|
4218 const std::string& dispatch_type, |
16676
7368654f302f
Initial support for (classdef) packages.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
16644
diff
changeset
|
4219 const std::string& package_name, |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
4220 const std::string& fcn_name, bool autoload) |
3021 | 4221 { |
7336 | 4222 octave_function *retval = 0; |
4223 | |
10067
6f79338c269b
omission from last patch
Jaroslav Hajek <highegg@gmail.com>
parents:
9794
diff
changeset
|
4224 unwind_protect frame; |
5484 | 4225 |
7336 | 4226 std::string nm = file_name; |
6238 | 4227 |
4228 size_t nm_len = nm.length (); | |
5472 | 4229 |
4230 std::string file; | |
4231 | |
16153
a57c2c8c8163
move some variables into the octave_parser class
John W. Eaton <jwe@octave.org>
parents:
16151
diff
changeset
|
4232 bool relative_lookup = false; |
6323 | 4233 |
7336 | 4234 file = nm; |
4235 | |
4236 if ((nm_len > 4 && nm.substr (nm_len-4) == ".oct") | |
4237 || (nm_len > 4 && nm.substr (nm_len-4) == ".mex") | |
4238 || (nm_len > 2 && nm.substr (nm_len-2) == ".m")) | |
5472 | 4239 { |
6238 | 4240 nm = octave_env::base_pathname (file); |
4241 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
|
4242 |
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
|
4243 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
|
4244 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
|
4245 nm = nm.substr (pos+1); |
5472 | 4246 } |
7336 | 4247 |
16153
a57c2c8c8163
move some variables into the octave_parser class
John W. Eaton <jwe@octave.org>
parents:
16151
diff
changeset
|
4248 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
|
4249 |
10250 | 4250 file = octave_env::make_absolute (file); |
4243 | 4251 |
4252 int len = file.length (); | |
4253 | |
4244 | 4254 if (len > 4 && file.substr (len-4, len-1) == ".oct") |
3021 | 4255 { |
7336 | 4256 if (autoload && ! fcn_name.empty ()) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
4257 nm = fcn_name; |
7336 | 4258 |
16153
a57c2c8c8163
move some variables into the octave_parser class
John W. Eaton <jwe@octave.org>
parents:
16151
diff
changeset
|
4259 retval = octave_dynamic_loader::load_oct (nm, file, relative_lookup); |
5864 | 4260 } |
4261 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
|
4262 { |
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
|
4263 // 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
|
4264 // 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
|
4265 |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11572
diff
changeset
|
4266 octave_function *tmpfcn = parse_fcn_file (file.substr (0, len - 2), |
16676
7368654f302f
Initial support for (classdef) packages.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
16644
diff
changeset
|
4267 nm, dispatch_type, |
7368654f302f
Initial support for (classdef) packages.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
16644
diff
changeset
|
4268 package_name, false, |
16153
a57c2c8c8163
move some variables into the octave_parser class
John W. Eaton <jwe@octave.org>
parents:
16151
diff
changeset
|
4269 autoload, autoload, |
a57c2c8c8163
move some variables into the octave_parser class
John W. Eaton <jwe@octave.org>
parents:
16151
diff
changeset
|
4270 relative_lookup, ""); |
a57c2c8c8163
move some variables into the octave_parser class
John W. Eaton <jwe@octave.org>
parents:
16151
diff
changeset
|
4271 |
a57c2c8c8163
move some variables into the octave_parser class
John W. Eaton <jwe@octave.org>
parents:
16151
diff
changeset
|
4272 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
|
4273 |
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
|
4274 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
|
4275 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
|
4276 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
|
4277 } |
4244 | 4278 else if (len > 2) |
3021 | 4279 { |
16676
7368654f302f
Initial support for (classdef) packages.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
16644
diff
changeset
|
4280 retval = parse_fcn_file (file, nm, dispatch_type, package_name, true, |
7368654f302f
Initial support for (classdef) packages.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
16644
diff
changeset
|
4281 autoload, autoload, relative_lookup, ""); |
3021 | 4282 } |
4283 | |
7336 | 4284 if (retval) |
8819
96d87674b818
also stash directory name for subfunctions
John W. Eaton <jwe@octave.org>
parents:
8812
diff
changeset
|
4285 { |
96d87674b818
also stash directory name for subfunctions
John W. Eaton <jwe@octave.org>
parents:
8812
diff
changeset
|
4286 retval->stash_dir_name (dir_name); |
18304
b0e8cc676396
Fix out-of-date status check for package functions.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
18263
diff
changeset
|
4287 retval->stash_package_name (package_name); |
8819
96d87674b818
also stash directory name for subfunctions
John W. Eaton <jwe@octave.org>
parents:
8812
diff
changeset
|
4288 |
96d87674b818
also stash directory name for subfunctions
John W. Eaton <jwe@octave.org>
parents:
8812
diff
changeset
|
4289 if (retval->is_user_function ()) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
4290 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
4291 symbol_table::scope_id id = retval->scope (); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
4292 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
4293 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
|
4294 } |
8819
96d87674b818
also stash directory name for subfunctions
John W. Eaton <jwe@octave.org>
parents:
8812
diff
changeset
|
4295 } |
7336 | 4296 |
4297 return retval; | |
5312 | 4298 } |
4299 | |
8746
5dd06f19e9be
handle commands in the lexer
John W. Eaton <jwe@octave.org>
parents:
8745
diff
changeset
|
4300 DEFUN (autoload, args, , |
5484 | 4301 "-*- texinfo -*-\n\ |
18531
04b4fb217b1a
doc: Improve documentation strings in parse-tree directory.
Rik <rik@octave.org>
parents:
17796
diff
changeset
|
4302 @deftypefn {Built-in Function} {@var{autoload_map} =} autoload ()\n\ |
04b4fb217b1a
doc: Improve documentation strings in parse-tree directory.
Rik <rik@octave.org>
parents:
17796
diff
changeset
|
4303 @deftypefnx {Built-in Function} {} autoload (@var{function}, @var{file})\n\ |
04b4fb217b1a
doc: Improve documentation strings in parse-tree directory.
Rik <rik@octave.org>
parents:
17796
diff
changeset
|
4304 @deftypefnx {Built-in Function} {} autoload (@dots{}, \"remove\")\n\ |
5484 | 4305 Define @var{function} to autoload from @var{file}.\n\ |
5626 | 4306 \n\ |
20198
075a5e2e1ba5
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
20110
diff
changeset
|
4307 The second argument, @var{file}, should be an absolute file name or a file\n\ |
075a5e2e1ba5
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
20110
diff
changeset
|
4308 name in the same directory as the function or script from which the autoload\n\ |
075a5e2e1ba5
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
20110
diff
changeset
|
4309 command was run. @var{file} @emph{should not} depend on the Octave load\n\ |
075a5e2e1ba5
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
20110
diff
changeset
|
4310 path.\n\ |
6380 | 4311 \n\ |
20198
075a5e2e1ba5
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
20110
diff
changeset
|
4312 Normally, calls to @code{autoload} appear in PKG_ADD script files that are\n\ |
075a5e2e1ba5
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
20110
diff
changeset
|
4313 evaluated when a directory is added to Octave's load path. To avoid having\n\ |
075a5e2e1ba5
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
20110
diff
changeset
|
4314 to hardcode directory names in @var{file}, if @var{file} is in the same\n\ |
075a5e2e1ba5
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
20110
diff
changeset
|
4315 directory as the PKG_ADD script then\n\ |
6380 | 4316 \n\ |
4317 @example\n\ | |
6926 | 4318 autoload (\"foo\", \"bar.oct\");\n\ |
6380 | 4319 @end example\n\ |
4320 \n\ | |
11572
7d6d8c1e471f
Grammarcheck Texinfo for files in src directory.
Rik <octave@nomad.inbox5.com>
parents:
11523
diff
changeset
|
4321 @noindent\n\ |
9038
fca0dc2fb042
Cleanup documentation files stmt.texi and func.texi
Rik <rdrider0-list@yahoo.com>
parents:
8974
diff
changeset
|
4322 will load the function @code{foo} from the file @code{bar.oct}. The above\n\ |
18531
04b4fb217b1a
doc: Improve documentation strings in parse-tree directory.
Rik <rik@octave.org>
parents:
17796
diff
changeset
|
4323 usage when @code{bar.oct} is not in the same directory, or usages such as\n\ |
6380 | 4324 \n\ |
4325 @example\n\ | |
6637 | 4326 autoload (\"foo\", file_in_loadpath (\"bar.oct\"))\n\ |
6380 | 4327 @end example\n\ |
4328 \n\ | |
4329 @noindent\n\ | |
16789
2f63d2f3ff11
doc: Update docstrings in oct-parse.in.yy.
Rik <rik@octave.org>
parents:
16681
diff
changeset
|
4330 are strongly discouraged, as their behavior may be unpredictable.\n\ |
6380 | 4331 \n\ |
6637 | 4332 With no arguments, return a structure containing the current autoload map.\n\ |
16848
77c8aae15908
accept remove option for autoload
Juan Pablo Carbajal <ajuanpi+dev@gmail.com>
parents:
16789
diff
changeset
|
4333 \n\ |
18531
04b4fb217b1a
doc: Improve documentation strings in parse-tree directory.
Rik <rik@octave.org>
parents:
17796
diff
changeset
|
4334 If a third argument @qcode{\"remove\"} is given, the function is cleared and\n\ |
16848
77c8aae15908
accept remove option for autoload
Juan Pablo Carbajal <ajuanpi+dev@gmail.com>
parents:
16789
diff
changeset
|
4335 not loaded anymore during the current Octave session.\n\ |
77c8aae15908
accept remove option for autoload
Juan Pablo Carbajal <ajuanpi+dev@gmail.com>
parents:
16789
diff
changeset
|
4336 \n\ |
6380 | 4337 @seealso{PKG_ADD}\n\ |
5484 | 4338 @end deftypefn") |
4339 { | |
5626 | 4340 octave_value retval; |
5484 | 4341 |
4342 int nargin = args.length (); | |
4343 | |
5626 | 4344 if (nargin == 0) |
4345 { | |
10350
12884915a8e4
merge MArray classes & improve Array interface
Jaroslav Hajek <highegg@gmail.com>
parents:
10315
diff
changeset
|
4346 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
|
4347 Cell file_names (dim_vector (autoload_map.size (), 1)); |
5626 | 4348 |
4349 octave_idx_type i = 0; | |
4350 typedef std::map<std::string, std::string>::const_iterator am_iter; | |
4351 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
|
4352 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
4353 func_names(i) = p->first; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
4354 file_names(i) = p->second; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
4355 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
4356 i++; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
4357 } |
5626 | 4358 |
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
|
4359 octave_map m; |
5626 | 4360 |
4361 m.assign ("function", func_names); | |
4362 m.assign ("file", file_names); | |
4363 | |
4364 retval = m; | |
4365 } | |
16848
77c8aae15908
accept remove option for autoload
Juan Pablo Carbajal <ajuanpi+dev@gmail.com>
parents:
16789
diff
changeset
|
4366 else if (nargin == 2 || nargin == 3) |
5484 | 4367 { |
4368 string_vector argv = args.make_argv ("autoload"); | |
4369 | |
20579
52ce821a52fd
eliminate simple uses of error_state in parser and lexer
John W. Eaton <jwe@octave.org>
parents:
20569
diff
changeset
|
4370 std::string nm = argv[2]; |
52ce821a52fd
eliminate simple uses of error_state in parser and lexer
John W. Eaton <jwe@octave.org>
parents:
20569
diff
changeset
|
4371 |
52ce821a52fd
eliminate simple uses of error_state in parser and lexer
John W. Eaton <jwe@octave.org>
parents:
20569
diff
changeset
|
4372 if (! octave_env::absolute_pathname (nm)) |
6380 | 4373 { |
20579
52ce821a52fd
eliminate simple uses of error_state in parser and lexer
John W. Eaton <jwe@octave.org>
parents:
20569
diff
changeset
|
4374 octave_user_code *fcn = octave_call_stack::caller_user_code (); |
52ce821a52fd
eliminate simple uses of error_state in parser and lexer
John W. Eaton <jwe@octave.org>
parents:
20569
diff
changeset
|
4375 |
52ce821a52fd
eliminate simple uses of error_state in parser and lexer
John W. Eaton <jwe@octave.org>
parents:
20569
diff
changeset
|
4376 bool found = false; |
52ce821a52fd
eliminate simple uses of error_state in parser and lexer
John W. Eaton <jwe@octave.org>
parents:
20569
diff
changeset
|
4377 |
52ce821a52fd
eliminate simple uses of error_state in parser and lexer
John W. Eaton <jwe@octave.org>
parents:
20569
diff
changeset
|
4378 if (fcn) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
4379 { |
20579
52ce821a52fd
eliminate simple uses of error_state in parser and lexer
John W. Eaton <jwe@octave.org>
parents:
20569
diff
changeset
|
4380 std::string fname = fcn->fcn_file_name (); |
52ce821a52fd
eliminate simple uses of error_state in parser and lexer
John W. Eaton <jwe@octave.org>
parents:
20569
diff
changeset
|
4381 |
52ce821a52fd
eliminate simple uses of error_state in parser and lexer
John W. Eaton <jwe@octave.org>
parents:
20569
diff
changeset
|
4382 if (! fname.empty ()) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
4383 { |
20579
52ce821a52fd
eliminate simple uses of error_state in parser and lexer
John W. Eaton <jwe@octave.org>
parents:
20569
diff
changeset
|
4384 fname = octave_env::make_absolute (fname); |
52ce821a52fd
eliminate simple uses of error_state in parser and lexer
John W. Eaton <jwe@octave.org>
parents:
20569
diff
changeset
|
4385 fname = fname.substr (0, fname.find_last_of (file_ops::dir_sep_str ()) + 1); |
52ce821a52fd
eliminate simple uses of error_state in parser and lexer
John W. Eaton <jwe@octave.org>
parents:
20569
diff
changeset
|
4386 |
52ce821a52fd
eliminate simple uses of error_state in parser and lexer
John W. Eaton <jwe@octave.org>
parents:
20569
diff
changeset
|
4387 file_stat fs (fname + nm); |
52ce821a52fd
eliminate simple uses of error_state in parser and lexer
John W. Eaton <jwe@octave.org>
parents:
20569
diff
changeset
|
4388 |
52ce821a52fd
eliminate simple uses of error_state in parser and lexer
John W. Eaton <jwe@octave.org>
parents:
20569
diff
changeset
|
4389 if (fs.exists ()) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
4390 { |
20579
52ce821a52fd
eliminate simple uses of error_state in parser and lexer
John W. Eaton <jwe@octave.org>
parents:
20569
diff
changeset
|
4391 nm = fname + nm; |
52ce821a52fd
eliminate simple uses of error_state in parser and lexer
John W. Eaton <jwe@octave.org>
parents:
20569
diff
changeset
|
4392 found = true; |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
4393 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
4394 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
4395 } |
20579
52ce821a52fd
eliminate simple uses of error_state in parser and lexer
John W. Eaton <jwe@octave.org>
parents:
20569
diff
changeset
|
4396 if (! found) |
52ce821a52fd
eliminate simple uses of error_state in parser and lexer
John W. Eaton <jwe@octave.org>
parents:
20569
diff
changeset
|
4397 warning_with_id ("Octave:autoload-relative-file-name", |
52ce821a52fd
eliminate simple uses of error_state in parser and lexer
John W. Eaton <jwe@octave.org>
parents:
20569
diff
changeset
|
4398 "autoload: '%s' is not an absolute file name", |
52ce821a52fd
eliminate simple uses of error_state in parser and lexer
John W. Eaton <jwe@octave.org>
parents:
20569
diff
changeset
|
4399 nm.c_str ()); |
52ce821a52fd
eliminate simple uses of error_state in parser and lexer
John W. Eaton <jwe@octave.org>
parents:
20569
diff
changeset
|
4400 } |
52ce821a52fd
eliminate simple uses of error_state in parser and lexer
John W. Eaton <jwe@octave.org>
parents:
20569
diff
changeset
|
4401 if (nargin == 2) |
52ce821a52fd
eliminate simple uses of error_state in parser and lexer
John W. Eaton <jwe@octave.org>
parents:
20569
diff
changeset
|
4402 autoload_map[argv[1]] = nm; |
52ce821a52fd
eliminate simple uses of error_state in parser and lexer
John W. Eaton <jwe@octave.org>
parents:
20569
diff
changeset
|
4403 else if (nargin == 3) |
52ce821a52fd
eliminate simple uses of error_state in parser and lexer
John W. Eaton <jwe@octave.org>
parents:
20569
diff
changeset
|
4404 { |
52ce821a52fd
eliminate simple uses of error_state in parser and lexer
John W. Eaton <jwe@octave.org>
parents:
20569
diff
changeset
|
4405 if (argv[3].compare ("remove") != 0) |
52ce821a52fd
eliminate simple uses of error_state in parser and lexer
John W. Eaton <jwe@octave.org>
parents:
20569
diff
changeset
|
4406 error_with_id ("Octave:invalid-input-arg", |
52ce821a52fd
eliminate simple uses of error_state in parser and lexer
John W. Eaton <jwe@octave.org>
parents:
20569
diff
changeset
|
4407 "autoload: third argument can only be 'remove'"); |
52ce821a52fd
eliminate simple uses of error_state in parser and lexer
John W. Eaton <jwe@octave.org>
parents:
20569
diff
changeset
|
4408 |
52ce821a52fd
eliminate simple uses of error_state in parser and lexer
John W. Eaton <jwe@octave.org>
parents:
20569
diff
changeset
|
4409 // Remove function from symbol table and autoload map. |
52ce821a52fd
eliminate simple uses of error_state in parser and lexer
John W. Eaton <jwe@octave.org>
parents:
20569
diff
changeset
|
4410 symbol_table::clear_dld_function (argv[1]); |
52ce821a52fd
eliminate simple uses of error_state in parser and lexer
John W. Eaton <jwe@octave.org>
parents:
20569
diff
changeset
|
4411 autoload_map.erase (argv[1]); |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
4412 } |
5484 | 4413 } |
4414 else | |
5823 | 4415 print_usage (); |
5484 | 4416 |
4417 return retval; | |
4418 } | |
4419 | |
4486 | 4420 void |
7715
5b4d278ec828
parse scripts completely before executing
John W. Eaton <jwe@octave.org>
parents:
7699
diff
changeset
|
4421 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
|
4422 bool verbose, bool require_file, const std::string& warn_for) |
4486 | 4423 { |
10578
cb0883127251
limit on recursion via calls to source function
John W. Eaton <jwe@octave.org>
parents:
10570
diff
changeset
|
4424 // 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
|
4425 // 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
|
4426 // 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
|
4427 // written as |
cb0883127251
limit on recursion via calls to source function
John W. Eaton <jwe@octave.org>
parents:
10570
diff
changeset
|
4428 // |
cb0883127251
limit on recursion via calls to source function
John W. Eaton <jwe@octave.org>
parents:
10570
diff
changeset
|
4429 // foo1.m: |
cb0883127251
limit on recursion via calls to source function
John W. Eaton <jwe@octave.org>
parents:
10570
diff
changeset
|
4430 // ------ |
cb0883127251
limit on recursion via calls to source function
John W. Eaton <jwe@octave.org>
parents:
10570
diff
changeset
|
4431 // foo2 |
cb0883127251
limit on recursion via calls to source function
John W. Eaton <jwe@octave.org>
parents:
10570
diff
changeset
|
4432 // |
cb0883127251
limit on recursion via calls to source function
John W. Eaton <jwe@octave.org>
parents:
10570
diff
changeset
|
4433 // foo2.m: |
cb0883127251
limit on recursion via calls to source function
John W. Eaton <jwe@octave.org>
parents:
10570
diff
changeset
|
4434 // ------ |
cb0883127251
limit on recursion via calls to source function
John W. Eaton <jwe@octave.org>
parents:
10570
diff
changeset
|
4435 // foo1 |
cb0883127251
limit on recursion via calls to source function
John W. Eaton <jwe@octave.org>
parents:
10570
diff
changeset
|
4436 // |
cb0883127251
limit on recursion via calls to source function
John W. Eaton <jwe@octave.org>
parents:
10570
diff
changeset
|
4437 // and called with |
cb0883127251
limit on recursion via calls to source function
John W. Eaton <jwe@octave.org>
parents:
10570
diff
changeset
|
4438 // |
cb0883127251
limit on recursion via calls to source function
John W. Eaton <jwe@octave.org>
parents:
10570
diff
changeset
|
4439 // foo1 |
cb0883127251
limit on recursion via calls to source function
John W. Eaton <jwe@octave.org>
parents:
10570
diff
changeset
|
4440 // |
cb0883127251
limit on recursion via calls to source function
John W. Eaton <jwe@octave.org>
parents:
10570
diff
changeset
|
4441 // (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
|
4442 // |
cb0883127251
limit on recursion via calls to source function
John W. Eaton <jwe@octave.org>
parents:
10570
diff
changeset
|
4443 // foo1.m: |
cb0883127251
limit on recursion via calls to source function
John W. Eaton <jwe@octave.org>
parents:
10570
diff
changeset
|
4444 // ------ |
cb0883127251
limit on recursion via calls to source function
John W. Eaton <jwe@octave.org>
parents:
10570
diff
changeset
|
4445 // source ("foo2.m") |
cb0883127251
limit on recursion via calls to source function
John W. Eaton <jwe@octave.org>
parents:
10570
diff
changeset
|
4446 // |
cb0883127251
limit on recursion via calls to source function
John W. Eaton <jwe@octave.org>
parents:
10570
diff
changeset
|
4447 // foo2.m: |
cb0883127251
limit on recursion via calls to source function
John W. Eaton <jwe@octave.org>
parents:
10570
diff
changeset
|
4448 // ------ |
cb0883127251
limit on recursion via calls to source function
John W. Eaton <jwe@octave.org>
parents:
10570
diff
changeset
|
4449 // source ("foo1.m") |
cb0883127251
limit on recursion via calls to source function
John W. Eaton <jwe@octave.org>
parents:
10570
diff
changeset
|
4450 // |
cb0883127251
limit on recursion via calls to source function
John W. Eaton <jwe@octave.org>
parents:
10570
diff
changeset
|
4451 // and called with |
cb0883127251
limit on recursion via calls to source function
John W. Eaton <jwe@octave.org>
parents:
10570
diff
changeset
|
4452 // |
cb0883127251
limit on recursion via calls to source function
John W. Eaton <jwe@octave.org>
parents:
10570
diff
changeset
|
4453 // source ("foo1.m") |
cb0883127251
limit on recursion via calls to source function
John W. Eaton <jwe@octave.org>
parents:
10570
diff
changeset
|
4454 // |
cb0883127251
limit on recursion via calls to source function
John W. Eaton <jwe@octave.org>
parents:
10570
diff
changeset
|
4455 // (for example). |
cb0883127251
limit on recursion via calls to source function
John W. Eaton <jwe@octave.org>
parents:
10570
diff
changeset
|
4456 |
cb0883127251
limit on recursion via calls to source function
John W. Eaton <jwe@octave.org>
parents:
10570
diff
changeset
|
4457 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
|
4458 |
4486 | 4459 std::string file_full_name = file_ops::tilde_expand (file_name); |
4460 | |
10578
cb0883127251
limit on recursion via calls to source function
John W. Eaton <jwe@octave.org>
parents:
10570
diff
changeset
|
4461 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
|
4462 |
10067
6f79338c269b
omission from last patch
Jaroslav Hajek <highegg@gmail.com>
parents:
9794
diff
changeset
|
4463 unwind_protect frame; |
6f79338c269b
omission from last patch
Jaroslav Hajek <highegg@gmail.com>
parents:
9794
diff
changeset
|
4464 |
10578
cb0883127251
limit on recursion via calls to source function
John W. Eaton <jwe@octave.org>
parents:
10570
diff
changeset
|
4465 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
|
4466 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
|
4467 |
cb0883127251
limit on recursion via calls to source function
John W. Eaton <jwe@octave.org>
parents:
10570
diff
changeset
|
4468 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
|
4469 |
cb0883127251
limit on recursion via calls to source function
John W. Eaton <jwe@octave.org>
parents:
10570
diff
changeset
|
4470 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
|
4471 |
cb0883127251
limit on recursion via calls to source function
John W. Eaton <jwe@octave.org>
parents:
10570
diff
changeset
|
4472 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
|
4473 { |
cb0883127251
limit on recursion via calls to source function
John W. Eaton <jwe@octave.org>
parents:
10570
diff
changeset
|
4474 error ("max_recursion_depth exceeded"); |
cb0883127251
limit on recursion via calls to source function
John W. Eaton <jwe@octave.org>
parents:
10570
diff
changeset
|
4475 return; |
cb0883127251
limit on recursion via calls to source function
John W. Eaton <jwe@octave.org>
parents:
10570
diff
changeset
|
4476 } |
cb0883127251
limit on recursion via calls to source function
John W. Eaton <jwe@octave.org>
parents:
10570
diff
changeset
|
4477 |
5975 | 4478 if (! context.empty ()) |
4479 { | |
4480 if (context == "caller") | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
4481 octave_call_stack::goto_caller_frame (); |
5975 | 4482 else if (context == "base") |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
4483 octave_call_stack::goto_base_frame (); |
5975 | 4484 else |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
4485 error ("source: context must be \"caller\" or \"base\""); |
7336 | 4486 |
20579
52ce821a52fd
eliminate simple uses of error_state in parser and lexer
John W. Eaton <jwe@octave.org>
parents:
20569
diff
changeset
|
4487 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
|
4488 } |
5975 | 4489 |
20579
52ce821a52fd
eliminate simple uses of error_state in parser and lexer
John W. Eaton <jwe@octave.org>
parents:
20569
diff
changeset
|
4490 try |
5975 | 4491 { |
16203
127cccb037bf
move more global parser and lexer variables to classes
John W. Eaton <jwe@octave.org>
parents:
16199
diff
changeset
|
4492 octave_function *fcn = parse_fcn_file (file_full_name, file_name, |
16676
7368654f302f
Initial support for (classdef) packages.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
16644
diff
changeset
|
4493 "", "", require_file, true, |
16203
127cccb037bf
move more global parser and lexer variables to classes
John W. Eaton <jwe@octave.org>
parents:
16199
diff
changeset
|
4494 false, false, warn_for); |
20579
52ce821a52fd
eliminate simple uses of error_state in parser and lexer
John W. Eaton <jwe@octave.org>
parents:
20569
diff
changeset
|
4495 } |
52ce821a52fd
eliminate simple uses of error_state in parser and lexer
John W. Eaton <jwe@octave.org>
parents:
20569
diff
changeset
|
4496 catch (const octave_execution_error) |
52ce821a52fd
eliminate simple uses of error_state in parser and lexer
John W. Eaton <jwe@octave.org>
parents:
20569
diff
changeset
|
4497 { |
52ce821a52fd
eliminate simple uses of error_state in parser and lexer
John W. Eaton <jwe@octave.org>
parents:
20569
diff
changeset
|
4498 error ("source: error sourcing file '%s'", |
52ce821a52fd
eliminate simple uses of error_state in parser and lexer
John W. Eaton <jwe@octave.org>
parents:
20569
diff
changeset
|
4499 file_full_name.c_str ()); |
52ce821a52fd
eliminate simple uses of error_state in parser and lexer
John W. Eaton <jwe@octave.org>
parents:
20569
diff
changeset
|
4500 } |
52ce821a52fd
eliminate simple uses of error_state in parser and lexer
John W. Eaton <jwe@octave.org>
parents:
20569
diff
changeset
|
4501 |
52ce821a52fd
eliminate simple uses of error_state in parser and lexer
John W. Eaton <jwe@octave.org>
parents:
20569
diff
changeset
|
4502 if (fcn && fcn->is_user_script ()) |
52ce821a52fd
eliminate simple uses of error_state in parser and lexer
John W. Eaton <jwe@octave.org>
parents:
20569
diff
changeset
|
4503 { |
52ce821a52fd
eliminate simple uses of error_state in parser and lexer
John W. Eaton <jwe@octave.org>
parents:
20569
diff
changeset
|
4504 octave_value_list args; |
52ce821a52fd
eliminate simple uses of error_state in parser and lexer
John W. Eaton <jwe@octave.org>
parents:
20569
diff
changeset
|
4505 |
52ce821a52fd
eliminate simple uses of error_state in parser and lexer
John W. Eaton <jwe@octave.org>
parents:
20569
diff
changeset
|
4506 if (verbose) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
4507 { |
20579
52ce821a52fd
eliminate simple uses of error_state in parser and lexer
John W. Eaton <jwe@octave.org>
parents:
20569
diff
changeset
|
4508 std::cout << "executing commands from " << file_full_name << " ... "; |
52ce821a52fd
eliminate simple uses of error_state in parser and lexer
John W. Eaton <jwe@octave.org>
parents:
20569
diff
changeset
|
4509 reading_startup_message_printed = true; |
52ce821a52fd
eliminate simple uses of error_state in parser and lexer
John W. Eaton <jwe@octave.org>
parents:
20569
diff
changeset
|
4510 std::cout.flush (); |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
4511 } |
20579
52ce821a52fd
eliminate simple uses of error_state in parser and lexer
John W. Eaton <jwe@octave.org>
parents:
20569
diff
changeset
|
4512 |
52ce821a52fd
eliminate simple uses of error_state in parser and lexer
John W. Eaton <jwe@octave.org>
parents:
20569
diff
changeset
|
4513 fcn->do_multi_index_op (0, args); |
52ce821a52fd
eliminate simple uses of error_state in parser and lexer
John W. Eaton <jwe@octave.org>
parents:
20569
diff
changeset
|
4514 |
52ce821a52fd
eliminate simple uses of error_state in parser and lexer
John W. Eaton <jwe@octave.org>
parents:
20569
diff
changeset
|
4515 if (verbose) |
52ce821a52fd
eliminate simple uses of error_state in parser and lexer
John W. Eaton <jwe@octave.org>
parents:
20569
diff
changeset
|
4516 std::cout << "done." << std::endl; |
52ce821a52fd
eliminate simple uses of error_state in parser and lexer
John W. Eaton <jwe@octave.org>
parents:
20569
diff
changeset
|
4517 |
52ce821a52fd
eliminate simple uses of error_state in parser and lexer
John W. Eaton <jwe@octave.org>
parents:
20569
diff
changeset
|
4518 delete fcn; |
5975 | 4519 } |
4486 | 4520 } |
4521 | |
5739 | 4522 DEFUN (mfilename, args, , |
4523 "-*- texinfo -*-\n\ | |
11572
7d6d8c1e471f
Grammarcheck Texinfo for files in src directory.
Rik <octave@nomad.inbox5.com>
parents:
11523
diff
changeset
|
4524 @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
|
4525 @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
|
4526 @deftypefnx {Built-in Function} {} mfilename (\"fullpathext\")\n\ |
18531
04b4fb217b1a
doc: Improve documentation strings in parse-tree directory.
Rik <rik@octave.org>
parents:
17796
diff
changeset
|
4527 Return the name of the currently executing file.\n\ |
04b4fb217b1a
doc: Improve documentation strings in parse-tree directory.
Rik <rik@octave.org>
parents:
17796
diff
changeset
|
4528 \n\ |
20198
075a5e2e1ba5
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
20110
diff
changeset
|
4529 When called from outside an m-file return the empty string.\n\ |
075a5e2e1ba5
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
20110
diff
changeset
|
4530 \n\ |
075a5e2e1ba5
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
20110
diff
changeset
|
4531 Given the argument @qcode{\"fullpath\"}, include the directory part of the\n\ |
075a5e2e1ba5
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
20110
diff
changeset
|
4532 file name, but not the extension.\n\ |
075a5e2e1ba5
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
20110
diff
changeset
|
4533 \n\ |
075a5e2e1ba5
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
20110
diff
changeset
|
4534 Given the argument @qcode{\"fullpathext\"}, include the directory part of\n\ |
075a5e2e1ba5
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
20110
diff
changeset
|
4535 the file name and the extension.\n\ |
5774 | 4536 @end deftypefn") |
5739 | 4537 { |
4538 octave_value retval; | |
4539 | |
4540 int nargin = args.length (); | |
4541 | |
4542 if (nargin > 1) | |
4543 { | |
5823 | 4544 print_usage (); |
5739 | 4545 return retval; |
4546 } | |
4547 | |
4548 std::string arg; | |
4549 | |
4550 if (nargin == 1) | |
4551 { | |
4552 arg = args(0).string_value (); | |
4553 | |
4554 if (error_state) | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
4555 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
4556 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
|
4557 return retval; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
4558 } |
5739 | 4559 } |
4560 | |
4561 std::string fname; | |
4562 | |
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
|
4563 octave_user_code *fcn = octave_call_stack::caller_user_code (); |
5743 | 4564 |
4565 if (fcn) | |
4566 { | |
4567 fname = fcn->fcn_file_name (); | |
4568 | |
4569 if (fname.empty ()) | |
4570 fname = fcn->name (); | |
4571 } | |
5739 | 4572 |
4573 if (arg == "fullpathext") | |
4574 retval = fname; | |
4575 else | |
4576 { | |
8007
a2ab20ba78f7
make file_ops a proper singleton class
John W. Eaton <jwe@octave.org>
parents:
8001
diff
changeset
|
4577 size_t dpos = fname.rfind (file_ops::dir_sep_char ()); |
5747 | 4578 size_t epos = fname.rfind ('.'); |
4579 | |
4580 if (epos <= dpos) | |
8021 | 4581 epos = std::string::npos; |
4582 | |
4583 fname = (epos != std::string::npos) ? fname.substr (0, epos) : fname; | |
5739 | 4584 |
4585 if (arg == "fullpath") | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
4586 retval = fname; |
5739 | 4587 else |
8021 | 4588 retval = (dpos != std::string::npos) ? fname.substr (dpos+1) : fname; |
5739 | 4589 } |
4590 | |
4591 return retval; | |
4592 } | |
4593 | |
3021 | 4594 DEFUN (source, args, , |
3371 | 4595 "-*- texinfo -*-\n\ |
4596 @deftypefn {Built-in Function} {} source (@var{file})\n\ | |
18531
04b4fb217b1a
doc: Improve documentation strings in parse-tree directory.
Rik <rik@octave.org>
parents:
17796
diff
changeset
|
4597 Parse and execute the contents of @var{file}.\n\ |
04b4fb217b1a
doc: Improve documentation strings in parse-tree directory.
Rik <rik@octave.org>
parents:
17796
diff
changeset
|
4598 \n\ |
04b4fb217b1a
doc: Improve documentation strings in parse-tree directory.
Rik <rik@octave.org>
parents:
17796
diff
changeset
|
4599 This is equivalent to executing commands from a script file, but without\n\ |
04b4fb217b1a
doc: Improve documentation strings in parse-tree directory.
Rik <rik@octave.org>
parents:
17796
diff
changeset
|
4600 requiring the file to be named @file{@var{file}.m}.\n\ |
04b4fb217b1a
doc: Improve documentation strings in parse-tree directory.
Rik <rik@octave.org>
parents:
17796
diff
changeset
|
4601 @seealso{run}\n\ |
3371 | 4602 @end deftypefn") |
3021 | 4603 { |
4604 octave_value_list retval; | |
4605 | |
4606 int nargin = args.length (); | |
4607 | |
5975 | 4608 if (nargin == 1 || nargin == 2) |
3021 | 4609 { |
3523 | 4610 std::string file_name = args(0).string_value (); |
3021 | 4611 |
4612 if (! error_state) | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
4613 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
4614 std::string context; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
4615 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
4616 if (nargin == 2) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
4617 context = args(1).string_value (); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
4618 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
4619 if (! error_state) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
4620 source_file (file_name, context); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
4621 else |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
4622 error ("source: expecting context to be character string"); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
4623 } |
3021 | 4624 else |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
4625 error ("source: expecting file name as argument"); |
3021 | 4626 } |
4627 else | |
5823 | 4628 print_usage (); |
3021 | 4629 |
4630 return retval; | |
4631 } | |
4632 | |
3726 | 4633 // Evaluate an Octave function (built-in or interpreted) and return |
3844 | 4634 // the list of result values. NAME is the name of the function to |
4635 // 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
|
4636 // number of output arguments expected. |
3726 | 4637 |
3021 | 4638 octave_value_list |
3523 | 4639 feval (const std::string& name, const octave_value_list& args, int nargout) |
3156 | 4640 { |
4641 octave_value_list retval; | |
4642 | |
7336 | 4643 octave_value fcn = symbol_table::find_function (name, args); |
4644 | |
4645 if (fcn.is_defined ()) | |
4646 retval = fcn.do_multi_index_op (nargout, args); | |
4647 else | |
10443
34e51d4e199b
implement smart warnings about missing Matlab functionality
Jaroslav Hajek <highegg@gmail.com>
parents:
10426
diff
changeset
|
4648 { |
20579
52ce821a52fd
eliminate simple uses of error_state in parser and lexer
John W. Eaton <jwe@octave.org>
parents:
20569
diff
changeset
|
4649 try |
52ce821a52fd
eliminate simple uses of error_state in parser and lexer
John W. Eaton <jwe@octave.org>
parents:
20569
diff
changeset
|
4650 { |
52ce821a52fd
eliminate simple uses of error_state in parser and lexer
John W. Eaton <jwe@octave.org>
parents:
20569
diff
changeset
|
4651 maybe_missing_function_hook (name); |
52ce821a52fd
eliminate simple uses of error_state in parser and lexer
John W. Eaton <jwe@octave.org>
parents:
20569
diff
changeset
|
4652 } |
52ce821a52fd
eliminate simple uses of error_state in parser and lexer
John W. Eaton <jwe@octave.org>
parents:
20569
diff
changeset
|
4653 catch (const octave_execution_exception&) |
52ce821a52fd
eliminate simple uses of error_state in parser and lexer
John W. Eaton <jwe@octave.org>
parents:
20569
diff
changeset
|
4654 { |
52ce821a52fd
eliminate simple uses of error_state in parser and lexer
John W. Eaton <jwe@octave.org>
parents:
20569
diff
changeset
|
4655 error ("feval: function '%s' not found", name.c_str ()); |
52ce821a52fd
eliminate simple uses of error_state in parser and lexer
John W. Eaton <jwe@octave.org>
parents:
20569
diff
changeset
|
4656 } |
10443
34e51d4e199b
implement smart warnings about missing Matlab functionality
Jaroslav Hajek <highegg@gmail.com>
parents:
10426
diff
changeset
|
4657 } |
3156 | 4658 |
4659 return retval; | |
4660 } | |
4661 | |
4342 | 4662 octave_value_list |
4663 feval (octave_function *fcn, const octave_value_list& args, int nargout) | |
4664 { | |
4665 octave_value_list retval; | |
4666 | |
4667 if (fcn) | |
4668 retval = fcn->do_multi_index_op (nargout, args); | |
4669 | |
4670 return retval; | |
4671 } | |
4672 | |
4673 static octave_value_list | |
4674 get_feval_args (const octave_value_list& args) | |
4675 { | |
10659
8baff2aceabc
fix slicing value lists with name tags (bug #29960)
Jaroslav Hajek <highegg@gmail.com>
parents:
10578
diff
changeset
|
4676 return args.slice (1, args.length () - 1, true); |
4342 | 4677 } |
4678 | |
4679 | |
3726 | 4680 // Evaluate an Octave function (built-in or interpreted) and return |
4681 // the list of result values. The first element of ARGS should be a | |
4682 // string containing the name of the function to call, then the rest | |
4683 // are the actual arguments to the function. NARGOUT is the number of | |
4684 // output arguments expected. | |
4685 | |
3156 | 4686 octave_value_list |
3021 | 4687 feval (const octave_value_list& args, int nargout) |
4688 { | |
4689 octave_value_list retval; | |
4690 | |
4342 | 4691 int nargin = args.length (); |
4692 | |
4693 if (nargin > 0) | |
3021 | 4694 { |
4342 | 4695 octave_value f_arg = args(0); |
4696 | |
4697 if (f_arg.is_string ()) | |
4698 { | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
4699 std::string name = f_arg.string_value (); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
4700 |
20579
52ce821a52fd
eliminate simple uses of error_state in parser and lexer
John W. Eaton <jwe@octave.org>
parents:
20569
diff
changeset
|
4701 octave_value_list tmp_args = get_feval_args (args); |
52ce821a52fd
eliminate simple uses of error_state in parser and lexer
John W. Eaton <jwe@octave.org>
parents:
20569
diff
changeset
|
4702 |
52ce821a52fd
eliminate simple uses of error_state in parser and lexer
John W. Eaton <jwe@octave.org>
parents:
20569
diff
changeset
|
4703 retval = feval (name, tmp_args, nargout); |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
4704 } |
13241
2a8dcb5b3a00
improve default indexing for objects
John W. Eaton <jwe@octave.org>
parents:
13237
diff
changeset
|
4705 else if (f_arg.is_function_handle () |
2a8dcb5b3a00
improve default indexing for objects
John W. Eaton <jwe@octave.org>
parents:
13237
diff
changeset
|
4706 || f_arg.is_anonymous_function () |
2a8dcb5b3a00
improve default indexing for objects
John W. Eaton <jwe@octave.org>
parents:
13237
diff
changeset
|
4707 || f_arg.is_inline_function ()) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
4708 { |
10492
a6b64a7a3769
make feval work with overloaded handles
Jaroslav Hajek <highegg@gmail.com>
parents:
10463
diff
changeset
|
4709 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
|
4710 |
a6b64a7a3769
make feval work with overloaded handles
Jaroslav Hajek <highegg@gmail.com>
parents:
10463
diff
changeset
|
4711 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
|
4712 } |
10492
a6b64a7a3769
make feval work with overloaded handles
Jaroslav Hajek <highegg@gmail.com>
parents:
10463
diff
changeset
|
4713 else |
a6b64a7a3769
make feval work with overloaded handles
Jaroslav Hajek <highegg@gmail.com>
parents:
10463
diff
changeset
|
4714 error ("feval: first argument must be a string, inline function or a function handle"); |
3021 | 4715 } |
4716 | |
4717 return retval; | |
4718 } | |
4719 | |
4720 DEFUN (feval, args, nargout, | |
3371 | 4721 "-*- texinfo -*-\n\ |
4722 @deftypefn {Built-in Function} {} feval (@var{name}, @dots{})\n\ | |
20198
075a5e2e1ba5
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
20110
diff
changeset
|
4723 Evaluate the function named @var{name}.\n\ |
075a5e2e1ba5
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
20110
diff
changeset
|
4724 \n\ |
075a5e2e1ba5
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
20110
diff
changeset
|
4725 Any arguments after the first are passed as inputs to the named function.\n\ |
075a5e2e1ba5
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
20110
diff
changeset
|
4726 For example,\n\ |
3371 | 4727 \n\ |
4728 @example\n\ | |
11572
7d6d8c1e471f
Grammarcheck Texinfo for files in src directory.
Rik <octave@nomad.inbox5.com>
parents:
11523
diff
changeset
|
4729 @group\n\ |
3371 | 4730 feval (\"acos\", -1)\n\ |
4731 @result{} 3.1416\n\ | |
11572
7d6d8c1e471f
Grammarcheck Texinfo for files in src directory.
Rik <octave@nomad.inbox5.com>
parents:
11523
diff
changeset
|
4732 @end group\n\ |
3371 | 4733 @end example\n\ |
3021 | 4734 \n\ |
3371 | 4735 @noindent\n\ |
4736 calls the function @code{acos} with the argument @samp{-1}.\n\ | |
4737 \n\ | |
20198
075a5e2e1ba5
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
20110
diff
changeset
|
4738 The function @code{feval} can also be used with function handles of any sort\n\ |
075a5e2e1ba5
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
20110
diff
changeset
|
4739 (@pxref{Function Handles}). Historically, @code{feval} was the only way to\n\ |
075a5e2e1ba5
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
20110
diff
changeset
|
4740 call user-supplied functions in strings, but function handles are now\n\ |
075a5e2e1ba5
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
20110
diff
changeset
|
4741 preferred due to the cleaner syntax they 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
|
4742 \n\ |
8b5b85e26246
octave-parse.yy (feval): Update docstring to refer to function handles.
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents:
12918
diff
changeset
|
4743 @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
|
4744 @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
|
4745 @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
|
4746 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
|
4747 @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
|
4748 @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
|
4749 @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
|
4750 @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
|
4751 @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
|
4752 \n\ |
8b5b85e26246
octave-parse.yy (feval): Update docstring to refer to function handles.
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents:
12918
diff
changeset
|
4753 @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
|
4754 are equivalent ways to call the function referred to by @var{f}. If it\n\ |
16789
2f63d2f3ff11
doc: Update docstrings in oct-parse.in.yy.
Rik <rik@octave.org>
parents:
16681
diff
changeset
|
4755 cannot be predicted beforehand whether @var{f} is a function handle,\n\ |
2f63d2f3ff11
doc: Update docstrings in oct-parse.in.yy.
Rik <rik@octave.org>
parents:
16681
diff
changeset
|
4756 function name in a string, or inline function then @code{feval} can be used\n\ |
2f63d2f3ff11
doc: Update docstrings in oct-parse.in.yy.
Rik <rik@octave.org>
parents:
16681
diff
changeset
|
4757 instead.\n\ |
3371 | 4758 @end deftypefn") |
3021 | 4759 { |
4760 octave_value_list retval; | |
4761 | |
4762 int nargin = args.length (); | |
4763 | |
4764 if (nargin > 0) | |
4765 retval = feval (args, nargout); | |
4766 else | |
5823 | 4767 print_usage (); |
3021 | 4768 |
4769 return retval; | |
4770 } | |
4771 | |
11225
8d8e10058df6
move builtin function from dispatch.cc to oct-parse.yy
John W. Eaton <jwe@octave.org>
parents:
11138
diff
changeset
|
4772 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
|
4773 "-*- texinfo -*-\n\ |
18531
04b4fb217b1a
doc: Improve documentation strings in parse-tree directory.
Rik <rik@octave.org>
parents:
17796
diff
changeset
|
4774 @deftypefn {Built-in Function} {[@dots{}] =} builtin (@var{f}, @dots{})\n\ |
20198
075a5e2e1ba5
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
20110
diff
changeset
|
4775 Call the base function @var{f} even if @var{f} is overloaded to another\n\ |
075a5e2e1ba5
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
20110
diff
changeset
|
4776 function for the given type signature.\n\ |
16789
2f63d2f3ff11
doc: Update docstrings in oct-parse.in.yy.
Rik <rik@octave.org>
parents:
16681
diff
changeset
|
4777 \n\ |
20198
075a5e2e1ba5
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
20110
diff
changeset
|
4778 This is normally useful when doing object-oriented programming and there is\n\ |
075a5e2e1ba5
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
20110
diff
changeset
|
4779 a requirement to call one of Octave's base functions rather than the\n\ |
075a5e2e1ba5
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
20110
diff
changeset
|
4780 overloaded one of a new class.\n\ |
16789
2f63d2f3ff11
doc: Update docstrings in oct-parse.in.yy.
Rik <rik@octave.org>
parents:
16681
diff
changeset
|
4781 \n\ |
2f63d2f3ff11
doc: Update docstrings in oct-parse.in.yy.
Rik <rik@octave.org>
parents:
16681
diff
changeset
|
4782 A trivial example which redefines the @code{sin} function to be the\n\ |
2f63d2f3ff11
doc: Update docstrings in oct-parse.in.yy.
Rik <rik@octave.org>
parents:
16681
diff
changeset
|
4783 @code{cos} function shows how @code{builtin} works.\n\ |
2f63d2f3ff11
doc: Update docstrings in oct-parse.in.yy.
Rik <rik@octave.org>
parents:
16681
diff
changeset
|
4784 \n\ |
2f63d2f3ff11
doc: Update docstrings in oct-parse.in.yy.
Rik <rik@octave.org>
parents:
16681
diff
changeset
|
4785 @example\n\ |
2f63d2f3ff11
doc: Update docstrings in oct-parse.in.yy.
Rik <rik@octave.org>
parents:
16681
diff
changeset
|
4786 @group\n\ |
2f63d2f3ff11
doc: Update docstrings in oct-parse.in.yy.
Rik <rik@octave.org>
parents:
16681
diff
changeset
|
4787 sin (0)\n\ |
2f63d2f3ff11
doc: Update docstrings in oct-parse.in.yy.
Rik <rik@octave.org>
parents:
16681
diff
changeset
|
4788 @result{} 0\n\ |
2f63d2f3ff11
doc: Update docstrings in oct-parse.in.yy.
Rik <rik@octave.org>
parents:
16681
diff
changeset
|
4789 function y = sin (x), y = cos (x); endfunction\n\ |
2f63d2f3ff11
doc: Update docstrings in oct-parse.in.yy.
Rik <rik@octave.org>
parents:
16681
diff
changeset
|
4790 sin (0)\n\ |
2f63d2f3ff11
doc: Update docstrings in oct-parse.in.yy.
Rik <rik@octave.org>
parents:
16681
diff
changeset
|
4791 @result{} 1\n\ |
2f63d2f3ff11
doc: Update docstrings in oct-parse.in.yy.
Rik <rik@octave.org>
parents:
16681
diff
changeset
|
4792 builtin (\"sin\", 0)\n\ |
2f63d2f3ff11
doc: Update docstrings in oct-parse.in.yy.
Rik <rik@octave.org>
parents:
16681
diff
changeset
|
4793 @result{} 0\n\ |
2f63d2f3ff11
doc: Update docstrings in oct-parse.in.yy.
Rik <rik@octave.org>
parents:
16681
diff
changeset
|
4794 @end group\n\ |
2f63d2f3ff11
doc: Update docstrings in oct-parse.in.yy.
Rik <rik@octave.org>
parents:
16681
diff
changeset
|
4795 @end example\n\ |
11225
8d8e10058df6
move builtin function from dispatch.cc to oct-parse.yy
John W. Eaton <jwe@octave.org>
parents:
11138
diff
changeset
|
4796 @end deftypefn") |
8d8e10058df6
move builtin function from dispatch.cc to oct-parse.yy
John W. Eaton <jwe@octave.org>
parents:
11138
diff
changeset
|
4797 { |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11572
diff
changeset
|
4798 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
|
4799 |
8d8e10058df6
move builtin function from dispatch.cc to oct-parse.yy
John W. Eaton <jwe@octave.org>
parents:
11138
diff
changeset
|
4800 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
|
4801 |
8d8e10058df6
move builtin function from dispatch.cc to oct-parse.yy
John W. Eaton <jwe@octave.org>
parents:
11138
diff
changeset
|
4802 if (nargin > 0) |
8d8e10058df6
move builtin function from dispatch.cc to oct-parse.yy
John W. Eaton <jwe@octave.org>
parents:
11138
diff
changeset
|
4803 { |
8d8e10058df6
move builtin function from dispatch.cc to oct-parse.yy
John W. Eaton <jwe@octave.org>
parents:
11138
diff
changeset
|
4804 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
|
4805 |
11225
8d8e10058df6
move builtin function from dispatch.cc to oct-parse.yy
John W. Eaton <jwe@octave.org>
parents:
11138
diff
changeset
|
4806 if (! error_state) |
8d8e10058df6
move builtin function from dispatch.cc to oct-parse.yy
John W. Eaton <jwe@octave.org>
parents:
11138
diff
changeset
|
4807 { |
8d8e10058df6
move builtin function from dispatch.cc to oct-parse.yy
John W. Eaton <jwe@octave.org>
parents:
11138
diff
changeset
|
4808 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
|
4809 |
8d8e10058df6
move builtin function from dispatch.cc to oct-parse.yy
John W. Eaton <jwe@octave.org>
parents:
11138
diff
changeset
|
4810 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
|
4811 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
|
4812 nargout); |
8d8e10058df6
move builtin function from dispatch.cc to oct-parse.yy
John W. Eaton <jwe@octave.org>
parents:
11138
diff
changeset
|
4813 else |
15466
d174210ce1ec
use ' instead of ` in error messages, warnings and most comments
John W. Eaton <jwe@octave.org>
parents:
14189
diff
changeset
|
4814 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
|
4815 } |
8d8e10058df6
move builtin function from dispatch.cc to oct-parse.yy
John W. Eaton <jwe@octave.org>
parents:
11138
diff
changeset
|
4816 else |
12483
7a5aacf65f81
Rewrite error strings in src/ to use variables named in documentation.
Rik <octave@nomad.inbox5.com>
parents:
12400
diff
changeset
|
4817 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
|
4818 } |
8d8e10058df6
move builtin function from dispatch.cc to oct-parse.yy
John W. Eaton <jwe@octave.org>
parents:
11138
diff
changeset
|
4819 else |
8d8e10058df6
move builtin function from dispatch.cc to oct-parse.yy
John W. Eaton <jwe@octave.org>
parents:
11138
diff
changeset
|
4820 print_usage (); |
8d8e10058df6
move builtin function from dispatch.cc to oct-parse.yy
John W. Eaton <jwe@octave.org>
parents:
11138
diff
changeset
|
4821 |
8d8e10058df6
move builtin function from dispatch.cc to oct-parse.yy
John W. Eaton <jwe@octave.org>
parents:
11138
diff
changeset
|
4822 return retval; |
8d8e10058df6
move builtin function from dispatch.cc to oct-parse.yy
John W. Eaton <jwe@octave.org>
parents:
11138
diff
changeset
|
4823 } |
8d8e10058df6
move builtin function from dispatch.cc to oct-parse.yy
John W. Eaton <jwe@octave.org>
parents:
11138
diff
changeset
|
4824 |
3099 | 4825 octave_value_list |
16195
b52d2f9294b6
use class for reading lexer input
John W. Eaton <jwe@octave.org>
parents:
16187
diff
changeset
|
4826 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
|
4827 int& parse_status, int nargout) |
3021 | 4828 { |
3877 | 4829 octave_value_list retval; |
4830 | |
16288
fe3b9a51e625
rename curr_lexer, curr_parser, CURR_LEXER
John W. Eaton <jwe@octave.org>
parents:
16287
diff
changeset
|
4831 octave_parser parser (eval_str); |
16195
b52d2f9294b6
use class for reading lexer input
John W. Eaton <jwe@octave.org>
parents:
16187
diff
changeset
|
4832 |
3877 | 4833 do |
4834 { | |
16288
fe3b9a51e625
rename curr_lexer, curr_parser, CURR_LEXER
John W. Eaton <jwe@octave.org>
parents:
16287
diff
changeset
|
4835 parser.reset (); |
fe3b9a51e625
rename curr_lexer, curr_parser, CURR_LEXER
John W. Eaton <jwe@octave.org>
parents:
16287
diff
changeset
|
4836 |
fe3b9a51e625
rename curr_lexer, curr_parser, CURR_LEXER
John W. Eaton <jwe@octave.org>
parents:
16287
diff
changeset
|
4837 parse_status = parser.run (); |
3877 | 4838 |
3883 | 4839 if (parse_status == 0) |
3877 | 4840 { |
16288
fe3b9a51e625
rename curr_lexer, curr_parser, CURR_LEXER
John W. Eaton <jwe@octave.org>
parents:
16287
diff
changeset
|
4841 if (parser.stmt_list) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
4842 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
4843 tree_statement *stmt = 0; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
4844 |
16288
fe3b9a51e625
rename curr_lexer, curr_parser, CURR_LEXER
John W. Eaton <jwe@octave.org>
parents:
16287
diff
changeset
|
4845 if (parser.stmt_list->length () == 1 |
fe3b9a51e625
rename curr_lexer, curr_parser, CURR_LEXER
John W. Eaton <jwe@octave.org>
parents:
16287
diff
changeset
|
4846 && (stmt = parser.stmt_list->front ()) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
4847 && stmt->is_expression ()) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
4848 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
4849 tree_expression *expr = stmt->expression (); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
4850 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
4851 if (silent) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
4852 expr->set_print_flag (false); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
4853 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
4854 bool do_bind_ans = false; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
4855 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
4856 if (expr->is_identifier ()) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
4857 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
4858 tree_identifier *id |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
4859 = dynamic_cast<tree_identifier *> (expr); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
4860 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
4861 do_bind_ans = (! id->is_variable ()); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
4862 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
4863 else |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
4864 do_bind_ans = (! expr->is_assignment_expression ()); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
4865 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
4866 retval = expr->rvalue (nargout); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
4867 |
20579
52ce821a52fd
eliminate simple uses of error_state in parser and lexer
John W. Eaton <jwe@octave.org>
parents:
20569
diff
changeset
|
4868 if (do_bind_ans && ! retval.empty ()) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
4869 bind_ans (retval(0), expr->print_result ()); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
4870 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
4871 if (nargout == 0) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
4872 retval = octave_value_list (); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
4873 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
4874 else if (nargout == 0) |
16288
fe3b9a51e625
rename curr_lexer, curr_parser, CURR_LEXER
John W. Eaton <jwe@octave.org>
parents:
16287
diff
changeset
|
4875 parser.stmt_list->accept (*current_evaluator); |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
4876 else |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
4877 error ("eval: invalid use of statement list"); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
4878 |
20579
52ce821a52fd
eliminate simple uses of error_state in parser and lexer
John W. Eaton <jwe@octave.org>
parents:
20569
diff
changeset
|
4879 if (tree_return_command::returning |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
4880 || tree_break_command::breaking |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
4881 || tree_continue_command::continuing) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
4882 break; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
4883 } |
16288
fe3b9a51e625
rename curr_lexer, curr_parser, CURR_LEXER
John W. Eaton <jwe@octave.org>
parents:
16287
diff
changeset
|
4884 else if (parser.lexer.end_of_input) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
4885 break; |
3883 | 4886 } |
3877 | 4887 } |
4888 while (parse_status == 0); | |
3021 | 4889 |
4890 return retval; | |
4891 } | |
4892 | |
4893 octave_value | |
16195
b52d2f9294b6
use class for reading lexer input
John W. Eaton <jwe@octave.org>
parents:
16187
diff
changeset
|
4894 eval_string (const std::string& eval_str, bool silent, int& parse_status) |
3021 | 4895 { |
4896 octave_value retval; | |
4897 | |
16195
b52d2f9294b6
use class for reading lexer input
John W. Eaton <jwe@octave.org>
parents:
16187
diff
changeset
|
4898 octave_value_list tmp = eval_string (eval_str, silent, parse_status, 1); |
3021 | 4899 |
4900 if (! tmp.empty ()) | |
4901 retval = tmp(0); | |
4902 | |
4903 return retval; | |
4904 } | |
4905 | |
4906 static octave_value_list | |
4907 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
|
4908 int nargout) |
3021 | 4909 { |
3523 | 4910 std::string s = arg.string_value (); |
3021 | 4911 |
4912 if (error_state) | |
4913 { | |
3523 | 4914 error ("eval: expecting std::string argument"); |
4233 | 4915 return octave_value (-1); |
3021 | 4916 } |
4917 | |
4918 return eval_string (s, silent, parse_status, nargout); | |
4919 } | |
4920 | |
13970 | 4921 void |
4922 cleanup_statement_list (tree_statement_list **lst) | |
4923 { | |
4924 if (*lst) | |
4925 { | |
4926 delete *lst; | |
4927 *lst = 0; | |
4928 } | |
4929 } | |
4930 | |
3021 | 4931 DEFUN (eval, args, nargout, |
3371 | 4932 "-*- texinfo -*-\n\ |
14172
cba1c681f1b7
doc: Update seealso references for eval family of functions.
Rik <octave@nomad.inbox5.com>
parents:
14153
diff
changeset
|
4933 @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
|
4934 @deftypefnx {Built-in Function} {} eval (@var{try}, @var{catch})\n\ |
3371 | 4935 Parse the string @var{try} and evaluate it as if it were an Octave\n\ |
20198
075a5e2e1ba5
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
20110
diff
changeset
|
4936 program.\n\ |
075a5e2e1ba5
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
20110
diff
changeset
|
4937 \n\ |
075a5e2e1ba5
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
20110
diff
changeset
|
4938 If execution fails, evaluate the optional string @var{catch}.\n\ |
075a5e2e1ba5
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
20110
diff
changeset
|
4939 \n\ |
075a5e2e1ba5
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
20110
diff
changeset
|
4940 The string @var{try} is evaluated in the current context, so any results\n\ |
075a5e2e1ba5
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
20110
diff
changeset
|
4941 remain available after @code{eval} returns.\n\ |
6643 | 4942 \n\ |
18531
04b4fb217b1a
doc: Improve documentation strings in parse-tree directory.
Rik <rik@octave.org>
parents:
17796
diff
changeset
|
4943 The following example creates the variable @var{A} with the approximate\n\ |
04b4fb217b1a
doc: Improve documentation strings in parse-tree directory.
Rik <rik@octave.org>
parents:
17796
diff
changeset
|
4944 value of 3.1416 in the current workspace.\n\ |
6643 | 4945 \n\ |
4946 @example\n\ | |
16789
2f63d2f3ff11
doc: Update docstrings in oct-parse.in.yy.
Rik <rik@octave.org>
parents:
16681
diff
changeset
|
4947 eval (\"A = acos(-1);\");\n\ |
6643 | 4948 @end example\n\ |
4949 \n\ | |
18531
04b4fb217b1a
doc: Improve documentation strings in parse-tree directory.
Rik <rik@octave.org>
parents:
17796
diff
changeset
|
4950 If an error occurs during the evaluation of @var{try} then the @var{catch}\n\ |
8828 | 4951 string is evaluated, as the following example shows:\n\ |
6643 | 4952 \n\ |
4953 @example\n\ | |
11572
7d6d8c1e471f
Grammarcheck Texinfo for files in src directory.
Rik <octave@nomad.inbox5.com>
parents:
11523
diff
changeset
|
4954 @group\n\ |
6643 | 4955 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
|
4956 'printf (\"This error occurred:\\n%s\\n\", lasterr ());');\n\ |
7001 | 4957 @print{} This error occurred:\n\ |
8015
30629059b72d
Update the manual to reflect the changes in error output
sh@sh-laptop
parents:
8007
diff
changeset
|
4958 This is a bad example\n\ |
11572
7d6d8c1e471f
Grammarcheck Texinfo for files in src directory.
Rik <octave@nomad.inbox5.com>
parents:
11523
diff
changeset
|
4959 @end group\n\ |
6643 | 4960 @end example\n\ |
14172
cba1c681f1b7
doc: Update seealso references for eval family of functions.
Rik <octave@nomad.inbox5.com>
parents:
14153
diff
changeset
|
4961 \n\ |
18531
04b4fb217b1a
doc: Improve documentation strings in parse-tree directory.
Rik <rik@octave.org>
parents:
17796
diff
changeset
|
4962 Programming Note: if you are only using @code{eval} as an error-capturing\n\ |
04b4fb217b1a
doc: Improve documentation strings in parse-tree directory.
Rik <rik@octave.org>
parents:
17796
diff
changeset
|
4963 mechanism, rather than for the execution of arbitrary code strings,\n\ |
04b4fb217b1a
doc: Improve documentation strings in parse-tree directory.
Rik <rik@octave.org>
parents:
17796
diff
changeset
|
4964 Consider using try/catch blocks or unwind_protect/unwind_protect_cleanup\n\ |
04b4fb217b1a
doc: Improve documentation strings in parse-tree directory.
Rik <rik@octave.org>
parents:
17796
diff
changeset
|
4965 blocks instead. These techniques have higher performance and don't introduce\n\ |
04b4fb217b1a
doc: Improve documentation strings in parse-tree directory.
Rik <rik@octave.org>
parents:
17796
diff
changeset
|
4966 the security considerations that the evaluation of arbitrary code does.\n\ |
14172
cba1c681f1b7
doc: Update seealso references for eval family of functions.
Rik <octave@nomad.inbox5.com>
parents:
14153
diff
changeset
|
4967 @seealso{evalin}\n\ |
3371 | 4968 @end deftypefn") |
3021 | 4969 { |
4970 octave_value_list retval; | |
4971 | |
4972 int nargin = args.length (); | |
4973 | |
4974 if (nargin > 0) | |
4975 { | |
10067
6f79338c269b
omission from last patch
Jaroslav Hajek <highegg@gmail.com>
parents:
9794
diff
changeset
|
4976 unwind_protect frame; |
3021 | 4977 |
4978 if (nargin > 1) | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
4979 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
4980 frame.protect_var (buffer_error_messages); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
4981 buffer_error_messages++; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
4982 } |
3021 | 4983 |
4984 int parse_status = 0; | |
4985 | |
20569
b70cc4bd8109
begin removal of global error_state variable
John W. Eaton <jwe@octave.org>
parents:
20198
diff
changeset
|
4986 bool execution_error = false; |
b70cc4bd8109
begin removal of global error_state variable
John W. Eaton <jwe@octave.org>
parents:
20198
diff
changeset
|
4987 |
b70cc4bd8109
begin removal of global error_state variable
John W. Eaton <jwe@octave.org>
parents:
20198
diff
changeset
|
4988 octave_value_list tmp; |
b70cc4bd8109
begin removal of global error_state variable
John W. Eaton <jwe@octave.org>
parents:
20198
diff
changeset
|
4989 |
b70cc4bd8109
begin removal of global error_state variable
John W. Eaton <jwe@octave.org>
parents:
20198
diff
changeset
|
4990 try |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
4991 { |
20569
b70cc4bd8109
begin removal of global error_state variable
John W. Eaton <jwe@octave.org>
parents:
20198
diff
changeset
|
4992 tmp = eval_string (args(0), nargout > 0, parse_status, nargout); |
b70cc4bd8109
begin removal of global error_state variable
John W. Eaton <jwe@octave.org>
parents:
20198
diff
changeset
|
4993 } |
b70cc4bd8109
begin removal of global error_state variable
John W. Eaton <jwe@octave.org>
parents:
20198
diff
changeset
|
4994 catch (const octave_execution_exception&) |
b70cc4bd8109
begin removal of global error_state variable
John W. Eaton <jwe@octave.org>
parents:
20198
diff
changeset
|
4995 { |
b70cc4bd8109
begin removal of global error_state variable
John W. Eaton <jwe@octave.org>
parents:
20198
diff
changeset
|
4996 execution_error = true; |
b70cc4bd8109
begin removal of global error_state variable
John W. Eaton <jwe@octave.org>
parents:
20198
diff
changeset
|
4997 } |
b70cc4bd8109
begin removal of global error_state variable
John W. Eaton <jwe@octave.org>
parents:
20198
diff
changeset
|
4998 |
b70cc4bd8109
begin removal of global error_state variable
John W. Eaton <jwe@octave.org>
parents:
20198
diff
changeset
|
4999 if (nargin > 1 && (parse_status != 0 || execution_error)) |
b70cc4bd8109
begin removal of global error_state variable
John W. Eaton <jwe@octave.org>
parents:
20198
diff
changeset
|
5000 { |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
5001 // 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
|
5002 // 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
|
5003 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
5004 buffer_error_messages--; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
5005 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
5006 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
|
5007 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
5008 if (nargout > 0) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
5009 retval = tmp; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
5010 } |
20569
b70cc4bd8109
begin removal of global error_state variable
John W. Eaton <jwe@octave.org>
parents:
20198
diff
changeset
|
5011 else |
b70cc4bd8109
begin removal of global error_state variable
John W. Eaton <jwe@octave.org>
parents:
20198
diff
changeset
|
5012 { |
b70cc4bd8109
begin removal of global error_state variable
John W. Eaton <jwe@octave.org>
parents:
20198
diff
changeset
|
5013 if (nargout > 0) |
b70cc4bd8109
begin removal of global error_state variable
John W. Eaton <jwe@octave.org>
parents:
20198
diff
changeset
|
5014 retval = tmp; |
b70cc4bd8109
begin removal of global error_state variable
John W. Eaton <jwe@octave.org>
parents:
20198
diff
changeset
|
5015 |
b70cc4bd8109
begin removal of global error_state variable
John W. Eaton <jwe@octave.org>
parents:
20198
diff
changeset
|
5016 // FIXME: we should really be rethrowing whatever exception occurred, |
b70cc4bd8109
begin removal of global error_state variable
John W. Eaton <jwe@octave.org>
parents:
20198
diff
changeset
|
5017 // not just throwing an execution exception. |
b70cc4bd8109
begin removal of global error_state variable
John W. Eaton <jwe@octave.org>
parents:
20198
diff
changeset
|
5018 if (execution_error) |
b70cc4bd8109
begin removal of global error_state variable
John W. Eaton <jwe@octave.org>
parents:
20198
diff
changeset
|
5019 octave_throw_execution_exception (); |
b70cc4bd8109
begin removal of global error_state variable
John W. Eaton <jwe@octave.org>
parents:
20198
diff
changeset
|
5020 } |
3021 | 5021 } |
5022 else | |
5823 | 5023 print_usage (); |
3021 | 5024 |
5025 return retval; | |
5026 } | |
5027 | |
7562
c827f5673321
move tests to individual source files
John W. Eaton <jwe@octave.org>
parents:
7351
diff
changeset
|
5028 /* |
c827f5673321
move tests to individual source files
John W. Eaton <jwe@octave.org>
parents:
7351
diff
changeset
|
5029 |
14084
5aba9fa234cf
Modernize %!tests for eval()
Rik <octave@nomad.inbox5.com>
parents:
13970
diff
changeset
|
5030 %!shared x |
7562
c827f5673321
move tests to individual source files
John W. Eaton <jwe@octave.org>
parents:
7351
diff
changeset
|
5031 %! x = 1; |
14084
5aba9fa234cf
Modernize %!tests for eval()
Rik <octave@nomad.inbox5.com>
parents:
13970
diff
changeset
|
5032 |
5aba9fa234cf
Modernize %!tests for eval()
Rik <octave@nomad.inbox5.com>
parents:
13970
diff
changeset
|
5033 %!assert (eval ("x"), 1) |
5aba9fa234cf
Modernize %!tests for eval()
Rik <octave@nomad.inbox5.com>
parents:
13970
diff
changeset
|
5034 %!assert (eval ("x;")) |
5aba9fa234cf
Modernize %!tests for eval()
Rik <octave@nomad.inbox5.com>
parents:
13970
diff
changeset
|
5035 %!assert (eval ("x;"), 1); |
5aba9fa234cf
Modernize %!tests for eval()
Rik <octave@nomad.inbox5.com>
parents:
13970
diff
changeset
|
5036 |
7562
c827f5673321
move tests to individual source files
John W. Eaton <jwe@octave.org>
parents:
7351
diff
changeset
|
5037 %!test |
14084
5aba9fa234cf
Modernize %!tests for eval()
Rik <octave@nomad.inbox5.com>
parents:
13970
diff
changeset
|
5038 %! y = eval ("x"); |
5aba9fa234cf
Modernize %!tests for eval()
Rik <octave@nomad.inbox5.com>
parents:
13970
diff
changeset
|
5039 %! assert (y, 1); |
5aba9fa234cf
Modernize %!tests for eval()
Rik <octave@nomad.inbox5.com>
parents:
13970
diff
changeset
|
5040 |
5aba9fa234cf
Modernize %!tests for eval()
Rik <octave@nomad.inbox5.com>
parents:
13970
diff
changeset
|
5041 %!test |
5aba9fa234cf
Modernize %!tests for eval()
Rik <octave@nomad.inbox5.com>
parents:
13970
diff
changeset
|
5042 %! y = eval ("x;"); |
5aba9fa234cf
Modernize %!tests for eval()
Rik <octave@nomad.inbox5.com>
parents:
13970
diff
changeset
|
5043 %! assert (y, 1); |
5aba9fa234cf
Modernize %!tests for eval()
Rik <octave@nomad.inbox5.com>
parents:
13970
diff
changeset
|
5044 |
5aba9fa234cf
Modernize %!tests for eval()
Rik <octave@nomad.inbox5.com>
parents:
13970
diff
changeset
|
5045 %!test |
5aba9fa234cf
Modernize %!tests for eval()
Rik <octave@nomad.inbox5.com>
parents:
13970
diff
changeset
|
5046 %! eval ("x = 1;") |
5aba9fa234cf
Modernize %!tests for eval()
Rik <octave@nomad.inbox5.com>
parents:
13970
diff
changeset
|
5047 %! assert (x,1); |
5aba9fa234cf
Modernize %!tests for eval()
Rik <octave@nomad.inbox5.com>
parents:
13970
diff
changeset
|
5048 |
7562
c827f5673321
move tests to individual source files
John W. Eaton <jwe@octave.org>
parents:
7351
diff
changeset
|
5049 %!test |
c827f5673321
move tests to individual source files
John W. Eaton <jwe@octave.org>
parents:
7351
diff
changeset
|
5050 %! eval ("flipud = 2;"); |
14084
5aba9fa234cf
Modernize %!tests for eval()
Rik <octave@nomad.inbox5.com>
parents:
13970
diff
changeset
|
5051 %! assert (flipud, 2); |
5aba9fa234cf
Modernize %!tests for eval()
Rik <octave@nomad.inbox5.com>
parents:
13970
diff
changeset
|
5052 |
5aba9fa234cf
Modernize %!tests for eval()
Rik <octave@nomad.inbox5.com>
parents:
13970
diff
changeset
|
5053 %!function y = __f () |
7562
c827f5673321
move tests to individual source files
John W. Eaton <jwe@octave.org>
parents:
7351
diff
changeset
|
5054 %! eval ("flipud = 2;"); |
c827f5673321
move tests to individual source files
John W. Eaton <jwe@octave.org>
parents:
7351
diff
changeset
|
5055 %! y = flipud; |
14084
5aba9fa234cf
Modernize %!tests for eval()
Rik <octave@nomad.inbox5.com>
parents:
13970
diff
changeset
|
5056 %!endfunction |
5aba9fa234cf
Modernize %!tests for eval()
Rik <octave@nomad.inbox5.com>
parents:
13970
diff
changeset
|
5057 %!assert (__f(), 2) |
7562
c827f5673321
move tests to individual source files
John W. Eaton <jwe@octave.org>
parents:
7351
diff
changeset
|
5058 |
14533
e6aa044253eb
Allow comma at the end of an assignment list (bug #35645)
Max Brister <max@2bass.com>
parents:
14512
diff
changeset
|
5059 % bug #35645 |
e6aa044253eb
Allow comma at the end of an assignment list (bug #35645)
Max Brister <max@2bass.com>
parents:
14512
diff
changeset
|
5060 %!test |
e6aa044253eb
Allow comma at the end of an assignment list (bug #35645)
Max Brister <max@2bass.com>
parents:
14512
diff
changeset
|
5061 %! [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
|
5062 %! [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
|
5063 |
7562
c827f5673321
move tests to individual source files
John W. Eaton <jwe@octave.org>
parents:
7351
diff
changeset
|
5064 */ |
c827f5673321
move tests to individual source files
John W. Eaton <jwe@octave.org>
parents:
7351
diff
changeset
|
5065 |
4661 | 5066 DEFUN (assignin, args, , |
4297 | 5067 "-*- texinfo -*-\n\ |
5068 @deftypefn {Built-in Function} {} assignin (@var{context}, @var{varname}, @var{value})\n\ | |
5069 Assign @var{value} to @var{varname} in context @var{context}, which\n\ | |
17281
bc924baa2c4e
doc: Add new @qcode macro for code samples which are quoted.
Rik <rik@octave.org>
parents:
17249
diff
changeset
|
5070 may be either @qcode{\"base\"} or @qcode{\"caller\"}.\n\ |
14172
cba1c681f1b7
doc: Update seealso references for eval family of functions.
Rik <octave@nomad.inbox5.com>
parents:
14153
diff
changeset
|
5071 @seealso{evalin}\n\ |
4297 | 5072 @end deftypefn") |
5073 { | |
5074 octave_value_list retval; | |
5075 | |
5076 int nargin = args.length (); | |
5077 | |
5078 if (nargin == 3) | |
5079 { | |
5080 std::string context = args(0).string_value (); | |
5081 | |
5082 if (! error_state) | |
5083 { | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
5084 unwind_protect frame; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
5085 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
5086 if (context == "caller") |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
5087 octave_call_stack::goto_caller_frame (); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
5088 else if (context == "base") |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
5089 octave_call_stack::goto_base_frame (); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
5090 else |
12483
7a5aacf65f81
Rewrite error strings in src/ to use variables named in documentation.
Rik <octave@nomad.inbox5.com>
parents:
12400
diff
changeset
|
5091 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
|
5092 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
5093 if (! error_state) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
5094 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
5095 frame.add_fcn (octave_call_stack::pop); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
5096 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
5097 std::string nm = args(1).string_value (); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
5098 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
5099 if (! error_state) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
5100 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
5101 if (valid_identifier (nm)) |
16442
302157614308
deprecate symbol_table::varref functions
John W. Eaton <jwe@octave.org>
parents:
16360
diff
changeset
|
5102 symbol_table::assign (nm, args(2)); |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
5103 else |
12483
7a5aacf65f81
Rewrite error strings in src/ to use variables named in documentation.
Rik <octave@nomad.inbox5.com>
parents:
12400
diff
changeset
|
5104 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
|
5105 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
5106 else |
12483
7a5aacf65f81
Rewrite error strings in src/ to use variables named in documentation.
Rik <octave@nomad.inbox5.com>
parents:
12400
diff
changeset
|
5107 error ("assignin: VARNAME must be a string"); |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
5108 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
5109 } |
4297 | 5110 else |
12483
7a5aacf65f81
Rewrite error strings in src/ to use variables named in documentation.
Rik <octave@nomad.inbox5.com>
parents:
12400
diff
changeset
|
5111 error ("assignin: CONTEXT must be a string"); |
4297 | 5112 } |
5113 else | |
5823 | 5114 print_usage (); |
4297 | 5115 |
5116 return retval; | |
5117 } | |
5118 | |
4245 | 5119 DEFUN (evalin, args, nargout, |
5120 "-*- texinfo -*-\n\ | |
14172
cba1c681f1b7
doc: Update seealso references for eval family of functions.
Rik <octave@nomad.inbox5.com>
parents:
14153
diff
changeset
|
5121 @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
|
5122 @deftypefnx {Built-in Function} {} evalin (@var{context}, @var{try}, @var{catch})\n\ |
20198
075a5e2e1ba5
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
20110
diff
changeset
|
5123 Like @code{eval}, except that the expressions are evaluated in the context\n\ |
075a5e2e1ba5
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
20110
diff
changeset
|
5124 @var{context}, which may be either @qcode{\"caller\"} or @qcode{\"base\"}.\n\ |
14172
cba1c681f1b7
doc: Update seealso references for eval family of functions.
Rik <octave@nomad.inbox5.com>
parents:
14153
diff
changeset
|
5125 @seealso{eval, assignin}\n\ |
4245 | 5126 @end deftypefn") |
5127 { | |
5128 octave_value_list retval; | |
5129 | |
5130 int nargin = args.length (); | |
5131 | |
5132 if (nargin > 1) | |
5133 { | |
5134 std::string context = args(0).string_value (); | |
5135 | |
5136 if (! error_state) | |
5137 { | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
5138 unwind_protect frame; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
5139 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
5140 if (context == "caller") |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
5141 octave_call_stack::goto_caller_frame (); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
5142 else if (context == "base") |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
5143 octave_call_stack::goto_base_frame (); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
5144 else |
12483
7a5aacf65f81
Rewrite error strings in src/ to use variables named in documentation.
Rik <octave@nomad.inbox5.com>
parents:
12400
diff
changeset
|
5145 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
|
5146 |
20579
52ce821a52fd
eliminate simple uses of error_state in parser and lexer
John W. Eaton <jwe@octave.org>
parents:
20569
diff
changeset
|
5147 frame.add_fcn (octave_call_stack::pop); |
52ce821a52fd
eliminate simple uses of error_state in parser and lexer
John W. Eaton <jwe@octave.org>
parents:
20569
diff
changeset
|
5148 |
52ce821a52fd
eliminate simple uses of error_state in parser and lexer
John W. Eaton <jwe@octave.org>
parents:
20569
diff
changeset
|
5149 if (nargin > 2) |
52ce821a52fd
eliminate simple uses of error_state in parser and lexer
John W. Eaton <jwe@octave.org>
parents:
20569
diff
changeset
|
5150 { |
52ce821a52fd
eliminate simple uses of error_state in parser and lexer
John W. Eaton <jwe@octave.org>
parents:
20569
diff
changeset
|
5151 frame.protect_var (buffer_error_messages); |
52ce821a52fd
eliminate simple uses of error_state in parser and lexer
John W. Eaton <jwe@octave.org>
parents:
20569
diff
changeset
|
5152 buffer_error_messages++; |
52ce821a52fd
eliminate simple uses of error_state in parser and lexer
John W. Eaton <jwe@octave.org>
parents:
20569
diff
changeset
|
5153 } |
52ce821a52fd
eliminate simple uses of error_state in parser and lexer
John W. Eaton <jwe@octave.org>
parents:
20569
diff
changeset
|
5154 |
52ce821a52fd
eliminate simple uses of error_state in parser and lexer
John W. Eaton <jwe@octave.org>
parents:
20569
diff
changeset
|
5155 int parse_status = 0; |
52ce821a52fd
eliminate simple uses of error_state in parser and lexer
John W. Eaton <jwe@octave.org>
parents:
20569
diff
changeset
|
5156 |
52ce821a52fd
eliminate simple uses of error_state in parser and lexer
John W. Eaton <jwe@octave.org>
parents:
20569
diff
changeset
|
5157 bool execution_error = false; |
52ce821a52fd
eliminate simple uses of error_state in parser and lexer
John W. Eaton <jwe@octave.org>
parents:
20569
diff
changeset
|
5158 |
52ce821a52fd
eliminate simple uses of error_state in parser and lexer
John W. Eaton <jwe@octave.org>
parents:
20569
diff
changeset
|
5159 octave_value_list tmp; |
52ce821a52fd
eliminate simple uses of error_state in parser and lexer
John W. Eaton <jwe@octave.org>
parents:
20569
diff
changeset
|
5160 |
52ce821a52fd
eliminate simple uses of error_state in parser and lexer
John W. Eaton <jwe@octave.org>
parents:
20569
diff
changeset
|
5161 try |
52ce821a52fd
eliminate simple uses of error_state in parser and lexer
John W. Eaton <jwe@octave.org>
parents:
20569
diff
changeset
|
5162 { |
52ce821a52fd
eliminate simple uses of error_state in parser and lexer
John W. Eaton <jwe@octave.org>
parents:
20569
diff
changeset
|
5163 tmp = eval_string (args(1), nargout > 0, |
52ce821a52fd
eliminate simple uses of error_state in parser and lexer
John W. Eaton <jwe@octave.org>
parents:
20569
diff
changeset
|
5164 parse_status, nargout); |
52ce821a52fd
eliminate simple uses of error_state in parser and lexer
John W. Eaton <jwe@octave.org>
parents:
20569
diff
changeset
|
5165 } |
52ce821a52fd
eliminate simple uses of error_state in parser and lexer
John W. Eaton <jwe@octave.org>
parents:
20569
diff
changeset
|
5166 catch (const octave_execution_exception&) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
5167 { |
20579
52ce821a52fd
eliminate simple uses of error_state in parser and lexer
John W. Eaton <jwe@octave.org>
parents:
20569
diff
changeset
|
5168 execution_error = true; |
52ce821a52fd
eliminate simple uses of error_state in parser and lexer
John W. Eaton <jwe@octave.org>
parents:
20569
diff
changeset
|
5169 } |
52ce821a52fd
eliminate simple uses of error_state in parser and lexer
John W. Eaton <jwe@octave.org>
parents:
20569
diff
changeset
|
5170 |
52ce821a52fd
eliminate simple uses of error_state in parser and lexer
John W. Eaton <jwe@octave.org>
parents:
20569
diff
changeset
|
5171 if (nargin > 2 && (parse_status != 0 || execution_error)) |
52ce821a52fd
eliminate simple uses of error_state in parser and lexer
John W. Eaton <jwe@octave.org>
parents:
20569
diff
changeset
|
5172 { |
52ce821a52fd
eliminate simple uses of error_state in parser and lexer
John W. Eaton <jwe@octave.org>
parents:
20569
diff
changeset
|
5173 // Set up for letting the user print any messages from |
52ce821a52fd
eliminate simple uses of error_state in parser and lexer
John W. Eaton <jwe@octave.org>
parents:
20569
diff
changeset
|
5174 // errors that occurred in the first part of this eval(). |
52ce821a52fd
eliminate simple uses of error_state in parser and lexer
John W. Eaton <jwe@octave.org>
parents:
20569
diff
changeset
|
5175 |
52ce821a52fd
eliminate simple uses of error_state in parser and lexer
John W. Eaton <jwe@octave.org>
parents:
20569
diff
changeset
|
5176 buffer_error_messages--; |
52ce821a52fd
eliminate simple uses of error_state in parser and lexer
John W. Eaton <jwe@octave.org>
parents:
20569
diff
changeset
|
5177 |
52ce821a52fd
eliminate simple uses of error_state in parser and lexer
John W. Eaton <jwe@octave.org>
parents:
20569
diff
changeset
|
5178 tmp = eval_string (args(2), nargout > 0, |
52ce821a52fd
eliminate simple uses of error_state in parser and lexer
John W. Eaton <jwe@octave.org>
parents:
20569
diff
changeset
|
5179 parse_status, nargout); |
52ce821a52fd
eliminate simple uses of error_state in parser and lexer
John W. Eaton <jwe@octave.org>
parents:
20569
diff
changeset
|
5180 |
52ce821a52fd
eliminate simple uses of error_state in parser and lexer
John W. Eaton <jwe@octave.org>
parents:
20569
diff
changeset
|
5181 retval = (nargout > 0) ? tmp : octave_value_list (); |
52ce821a52fd
eliminate simple uses of error_state in parser and lexer
John W. Eaton <jwe@octave.org>
parents:
20569
diff
changeset
|
5182 } |
52ce821a52fd
eliminate simple uses of error_state in parser and lexer
John W. Eaton <jwe@octave.org>
parents:
20569
diff
changeset
|
5183 else |
52ce821a52fd
eliminate simple uses of error_state in parser and lexer
John W. Eaton <jwe@octave.org>
parents:
20569
diff
changeset
|
5184 { |
52ce821a52fd
eliminate simple uses of error_state in parser and lexer
John W. Eaton <jwe@octave.org>
parents:
20569
diff
changeset
|
5185 if (nargout > 0) |
52ce821a52fd
eliminate simple uses of error_state in parser and lexer
John W. Eaton <jwe@octave.org>
parents:
20569
diff
changeset
|
5186 retval = tmp; |
52ce821a52fd
eliminate simple uses of error_state in parser and lexer
John W. Eaton <jwe@octave.org>
parents:
20569
diff
changeset
|
5187 |
52ce821a52fd
eliminate simple uses of error_state in parser and lexer
John W. Eaton <jwe@octave.org>
parents:
20569
diff
changeset
|
5188 // FIXME: we should really be rethrowing whatever |
52ce821a52fd
eliminate simple uses of error_state in parser and lexer
John W. Eaton <jwe@octave.org>
parents:
20569
diff
changeset
|
5189 // exception occurred, not just throwing an |
52ce821a52fd
eliminate simple uses of error_state in parser and lexer
John W. Eaton <jwe@octave.org>
parents:
20569
diff
changeset
|
5190 // execution exception. |
52ce821a52fd
eliminate simple uses of error_state in parser and lexer
John W. Eaton <jwe@octave.org>
parents:
20569
diff
changeset
|
5191 if (execution_error) |
52ce821a52fd
eliminate simple uses of error_state in parser and lexer
John W. Eaton <jwe@octave.org>
parents:
20569
diff
changeset
|
5192 octave_throw_execution_exception (); |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
5193 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
5194 } |
4245 | 5195 else |
12483
7a5aacf65f81
Rewrite error strings in src/ to use variables named in documentation.
Rik <octave@nomad.inbox5.com>
parents:
12400
diff
changeset
|
5196 error ("evalin: CONTEXT must be a string"); |
4245 | 5197 } |
5198 else | |
5823 | 5199 print_usage (); |
4245 | 5200 |
5201 return retval; | |
5202 } | |
5203 | |
8311
7124bffc89c7
parse.y (F__parser_debug_flag__): New function.
John W. Eaton <jwe@octave.org>
parents:
8283
diff
changeset
|
5204 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
|
5205 "-*- texinfo -*-\n\ |
18531
04b4fb217b1a
doc: Improve documentation strings in parse-tree directory.
Rik <rik@octave.org>
parents:
17796
diff
changeset
|
5206 @deftypefn {Built-in Function} {@var{val} =} __parser_debug_flag__ ()\n\ |
04b4fb217b1a
doc: Improve documentation strings in parse-tree directory.
Rik <rik@octave.org>
parents:
17796
diff
changeset
|
5207 @deftypefnx {Built-in Function} {@var{old_val} =} __parser_debug_flag__ (@var{new_val})\n\ |
04b4fb217b1a
doc: Improve documentation strings in parse-tree directory.
Rik <rik@octave.org>
parents:
17796
diff
changeset
|
5208 Query or set the internal flag that determines whether Octave's parser prints\n\ |
04b4fb217b1a
doc: Improve documentation strings in parse-tree directory.
Rik <rik@octave.org>
parents:
17796
diff
changeset
|
5209 debug information as it processes an expression.\n\ |
04b4fb217b1a
doc: Improve documentation strings in parse-tree directory.
Rik <rik@octave.org>
parents:
17796
diff
changeset
|
5210 @seealso{__lexer_debug_flag__}\n\ |
8812
7d48766c21a5
use consistent format for doc strings of internal functions
John W. Eaton <jwe@octave.org>
parents:
8746
diff
changeset
|
5211 @end deftypefn") |
8311
7124bffc89c7
parse.y (F__parser_debug_flag__): New function.
John W. Eaton <jwe@octave.org>
parents:
8283
diff
changeset
|
5212 { |
7124bffc89c7
parse.y (F__parser_debug_flag__): New function.
John W. Eaton <jwe@octave.org>
parents:
8283
diff
changeset
|
5213 octave_value retval; |
7124bffc89c7
parse.y (F__parser_debug_flag__): New function.
John W. Eaton <jwe@octave.org>
parents:
8283
diff
changeset
|
5214 |
7124bffc89c7
parse.y (F__parser_debug_flag__): New function.
John W. Eaton <jwe@octave.org>
parents:
8283
diff
changeset
|
5215 bool debug_flag = octave_debug; |
7124bffc89c7
parse.y (F__parser_debug_flag__): New function.
John W. Eaton <jwe@octave.org>
parents:
8283
diff
changeset
|
5216 |
7124bffc89c7
parse.y (F__parser_debug_flag__): New function.
John W. Eaton <jwe@octave.org>
parents:
8283
diff
changeset
|
5217 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
|
5218 "__parser_debug_flag__"); |
8311
7124bffc89c7
parse.y (F__parser_debug_flag__): New function.
John W. Eaton <jwe@octave.org>
parents:
8283
diff
changeset
|
5219 |
7124bffc89c7
parse.y (F__parser_debug_flag__): New function.
John W. Eaton <jwe@octave.org>
parents:
8283
diff
changeset
|
5220 octave_debug = debug_flag; |
7124bffc89c7
parse.y (F__parser_debug_flag__): New function.
John W. Eaton <jwe@octave.org>
parents:
8283
diff
changeset
|
5221 |
7124bffc89c7
parse.y (F__parser_debug_flag__): New function.
John W. Eaton <jwe@octave.org>
parents:
8283
diff
changeset
|
5222 return retval; |
7124bffc89c7
parse.y (F__parser_debug_flag__): New function.
John W. Eaton <jwe@octave.org>
parents:
8283
diff
changeset
|
5223 } |
17342
091e4df179de
new function to help with debugging by parsing .m files without executing them
John W. Eaton <jwe@octave.org>
parents:
17326
diff
changeset
|
5224 |
17377
15e2ad6372f7
maint: Tweaks to remove compiler warnings.
Rik <rik@octave.org>
parents:
17342
diff
changeset
|
5225 DEFUN (__parse_file__, args, , |
17342
091e4df179de
new function to help with debugging by parsing .m files without executing them
John W. Eaton <jwe@octave.org>
parents:
17326
diff
changeset
|
5226 "-*- texinfo -*-\n\ |
091e4df179de
new function to help with debugging by parsing .m files without executing them
John W. Eaton <jwe@octave.org>
parents:
17326
diff
changeset
|
5227 @deftypefn {Built-in Function} {} __parse_file__ (@var{file}, @var{verbose})\n\ |
091e4df179de
new function to help with debugging by parsing .m files without executing them
John W. Eaton <jwe@octave.org>
parents:
17326
diff
changeset
|
5228 Undocumented internal function.\n\ |
091e4df179de
new function to help with debugging by parsing .m files without executing them
John W. Eaton <jwe@octave.org>
parents:
17326
diff
changeset
|
5229 @end deftypefn") |
091e4df179de
new function to help with debugging by parsing .m files without executing them
John W. Eaton <jwe@octave.org>
parents:
17326
diff
changeset
|
5230 { |
091e4df179de
new function to help with debugging by parsing .m files without executing them
John W. Eaton <jwe@octave.org>
parents:
17326
diff
changeset
|
5231 octave_value retval; |
091e4df179de
new function to help with debugging by parsing .m files without executing them
John W. Eaton <jwe@octave.org>
parents:
17326
diff
changeset
|
5232 |
091e4df179de
new function to help with debugging by parsing .m files without executing them
John W. Eaton <jwe@octave.org>
parents:
17326
diff
changeset
|
5233 int nargin = args.length (); |
091e4df179de
new function to help with debugging by parsing .m files without executing them
John W. Eaton <jwe@octave.org>
parents:
17326
diff
changeset
|
5234 |
091e4df179de
new function to help with debugging by parsing .m files without executing them
John W. Eaton <jwe@octave.org>
parents:
17326
diff
changeset
|
5235 if (nargin == 1 || nargin == 2) |
091e4df179de
new function to help with debugging by parsing .m files without executing them
John W. Eaton <jwe@octave.org>
parents:
17326
diff
changeset
|
5236 { |
091e4df179de
new function to help with debugging by parsing .m files without executing them
John W. Eaton <jwe@octave.org>
parents:
17326
diff
changeset
|
5237 std::string file = args(0).string_value (); |
19627
446c46af4b42
strip trailing whitespace from most source files
John W. Eaton <jwe@octave.org>
parents:
19008
diff
changeset
|
5238 |
17342
091e4df179de
new function to help with debugging by parsing .m files without executing them
John W. Eaton <jwe@octave.org>
parents:
17326
diff
changeset
|
5239 std::string full_file = octave_env::make_absolute (file); |
091e4df179de
new function to help with debugging by parsing .m files without executing them
John W. Eaton <jwe@octave.org>
parents:
17326
diff
changeset
|
5240 |
091e4df179de
new function to help with debugging by parsing .m files without executing them
John W. Eaton <jwe@octave.org>
parents:
17326
diff
changeset
|
5241 size_t file_len = file.length (); |
091e4df179de
new function to help with debugging by parsing .m files without executing them
John W. Eaton <jwe@octave.org>
parents:
17326
diff
changeset
|
5242 |
091e4df179de
new function to help with debugging by parsing .m files without executing them
John W. Eaton <jwe@octave.org>
parents:
17326
diff
changeset
|
5243 if ((file_len > 4 && file.substr (file_len-4) == ".oct") |
091e4df179de
new function to help with debugging by parsing .m files without executing them
John W. Eaton <jwe@octave.org>
parents:
17326
diff
changeset
|
5244 || (file_len > 4 && file.substr (file_len-4) == ".mex") |
091e4df179de
new function to help with debugging by parsing .m files without executing them
John W. Eaton <jwe@octave.org>
parents:
17326
diff
changeset
|
5245 || (file_len > 2 && file.substr (file_len-2) == ".m")) |
091e4df179de
new function to help with debugging by parsing .m files without executing them
John W. Eaton <jwe@octave.org>
parents:
17326
diff
changeset
|
5246 { |
091e4df179de
new function to help with debugging by parsing .m files without executing them
John W. Eaton <jwe@octave.org>
parents:
17326
diff
changeset
|
5247 file = octave_env::base_pathname (file); |
091e4df179de
new function to help with debugging by parsing .m files without executing them
John W. Eaton <jwe@octave.org>
parents:
17326
diff
changeset
|
5248 file = file.substr (0, file.find_last_of ('.')); |
091e4df179de
new function to help with debugging by parsing .m files without executing them
John W. Eaton <jwe@octave.org>
parents:
17326
diff
changeset
|
5249 |
091e4df179de
new function to help with debugging by parsing .m files without executing them
John W. Eaton <jwe@octave.org>
parents:
17326
diff
changeset
|
5250 size_t pos = file.find_last_of (file_ops::dir_sep_str ()); |
091e4df179de
new function to help with debugging by parsing .m files without executing them
John W. Eaton <jwe@octave.org>
parents:
17326
diff
changeset
|
5251 if (pos != std::string::npos) |
091e4df179de
new function to help with debugging by parsing .m files without executing them
John W. Eaton <jwe@octave.org>
parents:
17326
diff
changeset
|
5252 file = file.substr (pos+1); |
091e4df179de
new function to help with debugging by parsing .m files without executing them
John W. Eaton <jwe@octave.org>
parents:
17326
diff
changeset
|
5253 } |
091e4df179de
new function to help with debugging by parsing .m files without executing them
John W. Eaton <jwe@octave.org>
parents:
17326
diff
changeset
|
5254 |
091e4df179de
new function to help with debugging by parsing .m files without executing them
John W. Eaton <jwe@octave.org>
parents:
17326
diff
changeset
|
5255 if (! error_state) |
091e4df179de
new function to help with debugging by parsing .m files without executing them
John W. Eaton <jwe@octave.org>
parents:
17326
diff
changeset
|
5256 { |
091e4df179de
new function to help with debugging by parsing .m files without executing them
John W. Eaton <jwe@octave.org>
parents:
17326
diff
changeset
|
5257 if (nargin == 2) |
091e4df179de
new function to help with debugging by parsing .m files without executing them
John W. Eaton <jwe@octave.org>
parents:
17326
diff
changeset
|
5258 octave_stdout << "parsing " << full_file << std::endl; |
091e4df179de
new function to help with debugging by parsing .m files without executing them
John W. Eaton <jwe@octave.org>
parents:
17326
diff
changeset
|
5259 |
17577
c702371ff6df
maint: periodic merge of default to classdef
John W. Eaton <jwe@octave.org>
diff
changeset
|
5260 octave_function *fcn = parse_fcn_file (full_file, file, "", "", |
17342
091e4df179de
new function to help with debugging by parsing .m files without executing them
John W. Eaton <jwe@octave.org>
parents:
17326
diff
changeset
|
5261 true, false, false, |
091e4df179de
new function to help with debugging by parsing .m files without executing them
John W. Eaton <jwe@octave.org>
parents:
17326
diff
changeset
|
5262 false, "__parse_file__"); |
091e4df179de
new function to help with debugging by parsing .m files without executing them
John W. Eaton <jwe@octave.org>
parents:
17326
diff
changeset
|
5263 |
091e4df179de
new function to help with debugging by parsing .m files without executing them
John W. Eaton <jwe@octave.org>
parents:
17326
diff
changeset
|
5264 if (fcn) |
091e4df179de
new function to help with debugging by parsing .m files without executing them
John W. Eaton <jwe@octave.org>
parents:
17326
diff
changeset
|
5265 delete fcn; |
091e4df179de
new function to help with debugging by parsing .m files without executing them
John W. Eaton <jwe@octave.org>
parents:
17326
diff
changeset
|
5266 } |
091e4df179de
new function to help with debugging by parsing .m files without executing them
John W. Eaton <jwe@octave.org>
parents:
17326
diff
changeset
|
5267 else |
091e4df179de
new function to help with debugging by parsing .m files without executing them
John W. Eaton <jwe@octave.org>
parents:
17326
diff
changeset
|
5268 error ("__parse_file__: expecting file name as argument"); |
091e4df179de
new function to help with debugging by parsing .m files without executing them
John W. Eaton <jwe@octave.org>
parents:
17326
diff
changeset
|
5269 } |
091e4df179de
new function to help with debugging by parsing .m files without executing them
John W. Eaton <jwe@octave.org>
parents:
17326
diff
changeset
|
5270 else |
091e4df179de
new function to help with debugging by parsing .m files without executing them
John W. Eaton <jwe@octave.org>
parents:
17326
diff
changeset
|
5271 print_usage (); |
091e4df179de
new function to help with debugging by parsing .m files without executing them
John W. Eaton <jwe@octave.org>
parents:
17326
diff
changeset
|
5272 |
091e4df179de
new function to help with debugging by parsing .m files without executing them
John W. Eaton <jwe@octave.org>
parents:
17326
diff
changeset
|
5273 return retval; |
091e4df179de
new function to help with debugging by parsing .m files without executing them
John W. Eaton <jwe@octave.org>
parents:
17326
diff
changeset
|
5274 } |