annotate libinterp/parse-tree/oct-parse.in.yy @ 21361:9ca194f7a858

disallow assignment to "end" in indexed assignments (bug #46459) * parse.h, oct-parse.in.yy (octave_base_parser::valid_id_for_assignment): New function. (octave_base_parser::make_assign_op): Use it.
author John W. Eaton <jwe@octave.org>
date Fri, 26 Feb 2016 13:13:21 -0500
parents a4faec57f4c8
children 105224df2330
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
1829
7d2982b55242 [project @ 1996-02-02 14:12:59 by jwe]
jwe
parents: 1826
diff changeset
1 /*
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
2
19697
4197fc428c7d maint: Update copyright notices for 2015.
John W. Eaton <jwe@octave.org>
parents: 19597
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
fd0a3ac60b0e update copyright notices
John W. Eaton <jwe@octave.org>
parents: 11464
diff changeset
5 Copyright (C) 2009-2010 VZLU Prague
21075
5ed379c8decd Add new function evalc to core.
Oliver Heimlich <oheim@posteo.de>
parents: 21073
diff changeset
6 Copyright (C) 2016 Oliver Heimlich
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
7
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
8 This file is part of Octave.
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
9
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
10 Octave is free software; you can redistribute it and/or modify it
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
11 under the terms of the GNU General Public License as published by the
7016
93c65f2a5668 [project @ 2007-10-12 06:40:56 by jwe]
jwe
parents: 7001
diff changeset
12 Free Software Foundation; either version 3 of the License, or (at your
93c65f2a5668 [project @ 2007-10-12 06:40:56 by jwe]
jwe
parents: 7001
diff changeset
13 option) any later version.
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
14
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
15 Octave is distributed in the hope that it will be useful, but WITHOUT
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
16 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
17 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
18 for more details.
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
19
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
20 You should have received a copy of the GNU General Public License
7016
93c65f2a5668 [project @ 2007-10-12 06:40:56 by jwe]
jwe
parents: 7001
diff changeset
21 along with Octave; see the file COPYING. If not, see
93c65f2a5668 [project @ 2007-10-12 06:40:56 by jwe]
jwe
parents: 7001
diff changeset
22 <http://www.gnu.org/licenses/>.
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
23
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
24 */
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
25
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
26 // Parser for Octave.
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
27
767
42731861ee09 [project @ 1994-10-05 21:26:54 by jwe]
jwe
parents: 751
diff changeset
28 // C decarations.
42731861ee09 [project @ 1994-10-05 21:26:54 by jwe]
jwe
parents: 751
diff changeset
29
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
30 %{
21023
ec532a439c6f rework method of disabling warnings from GCC
John W. Eaton <jwe@octave.org>
parents: 21021
diff changeset
31
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
32 #define YYDEBUG 1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
33
240
a99f28f5e351 [project @ 1993-11-30 20:24:36 by jwe]
jwe
parents: 206
diff changeset
34 #ifdef HAVE_CONFIG_H
21301
40de9f8f23a6 Use '#include "config.h"' rather than <config.h>.
Rik <rik@octave.org>
parents: 21294
diff changeset
35 #include "config.h"
240
a99f28f5e351 [project @ 1993-11-30 20:24:36 by jwe]
jwe
parents: 206
diff changeset
36 #endif
a99f28f5e351 [project @ 1993-11-30 20:24:36 by jwe]
jwe
parents: 206
diff changeset
37
3178
09a3064a3a17 [project @ 1998-06-23 03:46:42 by jwe]
jwe
parents: 3165
diff changeset
38 #include <cassert>
10463
bbe99b2a5ba7 undo recent gnulib-related changes
John W. Eaton <jwe@octave.org>
parents: 10447
diff changeset
39 #include <cstdio>
bbe99b2a5ba7 undo recent gnulib-related changes
John W. Eaton <jwe@octave.org>
parents: 10447
diff changeset
40 #include <cstdlib>
2427
2f50b24ce84f [project @ 1996-10-25 06:15:28 by jwe]
jwe
parents: 2375
diff changeset
41
8950
d865363208d6 include <iosfwd> instead of <iostream> in header files
John W. Eaton <jwe@octave.org>
parents: 8920
diff changeset
42 #include <iostream>
5484
2ff5363a16bd [project @ 2005-10-06 17:12:12 by jwe]
jwe
parents: 5472
diff changeset
43 #include <map>
5765
7ba9ad1fec11 [project @ 2006-04-17 05:05:15 by jwe]
jwe
parents: 5760
diff changeset
44 #include <sstream>
5484
2ff5363a16bd [project @ 2005-10-06 17:12:12 by jwe]
jwe
parents: 5472
diff changeset
45
3928
e8627dc4bdf2 [project @ 2002-05-03 19:56:01 by jwe]
jwe
parents: 3903
diff changeset
46 #include "Cell.h"
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
47 #include "Matrix.h"
3021
18d64612e67a [project @ 1997-06-03 22:18:56 by jwe]
jwe
parents: 3016
diff changeset
48 #include "cmd-edit.h"
18d64612e67a [project @ 1997-06-03 22:18:56 by jwe]
jwe
parents: 3016
diff changeset
49 #include "cmd-hist.h"
18d64612e67a [project @ 1997-06-03 22:18:56 by jwe]
jwe
parents: 3016
diff changeset
50 #include "file-ops.h"
18d64612e67a [project @ 1997-06-03 22:18:56 by jwe]
jwe
parents: 3016
diff changeset
51 #include "file-stat.h"
4243
7e4d5b5520e5 [project @ 2002-12-27 05:30:59 by jwe]
jwe
parents: 4240
diff changeset
52 #include "oct-env.h"
3712
7066a8065e7e [project @ 2000-08-22 06:21:20 by jwe]
jwe
parents: 3665
diff changeset
53 #include "oct-time.h"
4171
04694e5b4239 [project @ 2002-11-12 20:27:24 by jwe]
jwe
parents: 4131
diff changeset
54 #include "quit.h"
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
55
3665
0689afb1d001 [project @ 2000-05-11 19:07:56 by jwe]
jwe
parents: 3544
diff changeset
56 #include "comment-list.h"
4243
7e4d5b5520e5 [project @ 2002-12-27 05:30:59 by jwe]
jwe
parents: 4240
diff changeset
57 #include "defaults.h"
2166
d68119516779 [project @ 1996-05-13 13:41:55 by jwe]
jwe
parents: 2124
diff changeset
58 #include "defun.h"
4243
7e4d5b5520e5 [project @ 2002-12-27 05:30:59 by jwe]
jwe
parents: 4240
diff changeset
59 #include "dirfns.h"
3021
18d64612e67a [project @ 1997-06-03 22:18:56 by jwe]
jwe
parents: 3016
diff changeset
60 #include "dynamic-ld.h"
1351
8256c4c57419 [project @ 1995-09-05 08:02:08 by jwe]
jwe
parents: 1315
diff changeset
61 #include "error.h"
8256c4c57419 [project @ 1995-09-05 08:02:08 by jwe]
jwe
parents: 1315
diff changeset
62 #include "input.h"
8256c4c57419 [project @ 1995-09-05 08:02:08 by jwe]
jwe
parents: 1315
diff changeset
63 #include "lex.h"
5832
5e41e06f6a78 [project @ 2006-05-26 21:41:32 by jwe]
jwe
parents: 5823
diff changeset
64 #include "load-path.h"
1743
ab8612a09449 [project @ 1996-01-12 11:25:30 by jwe]
jwe
parents: 1740
diff changeset
65 #include "oct-hist.h"
5626
3236b4d98fde [project @ 2006-02-15 20:25:39 by jwe]
jwe
parents: 5615
diff changeset
66 #include "oct-map.h"
15037
56b8eb7c9c04 improvements in parsing classdef
John W. Eaton <jwe@octave.org>
parents: 14846
diff changeset
67 #include "ov-classdef.h"
4935
4fc993a4e072 [project @ 2004-08-06 03:17:12 by jwe]
jwe
parents: 4930
diff changeset
68 #include "ov-fcn-handle.h"
2970
b9e64477f703 [project @ 1997-05-15 18:04:21 by jwe]
jwe
parents: 2961
diff changeset
69 #include "ov-usr-fcn.h"
8150
283989f2da9b make null assignment matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents: 8064
diff changeset
70 #include "ov-null-mat.h"
1670
6708c53892c1 [project @ 1995-12-27 04:33:00 by jwe]
jwe
parents: 1623
diff changeset
71 #include "toplev.h"
1351
8256c4c57419 [project @ 1995-09-05 08:02:08 by jwe]
jwe
parents: 1315
diff changeset
72 #include "pager.h"
8256c4c57419 [project @ 1995-09-05 08:02:08 by jwe]
jwe
parents: 1315
diff changeset
73 #include "parse.h"
2987
ae20b3f37f5e [project @ 1997-05-16 07:05:15 by jwe]
jwe
parents: 2982
diff changeset
74 #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
75 #include "pt-eval.h"
15037
56b8eb7c9c04 improvements in parsing classdef
John W. Eaton <jwe@octave.org>
parents: 14846
diff changeset
76 #include "pt-funcall.h"
1351
8256c4c57419 [project @ 1995-09-05 08:02:08 by jwe]
jwe
parents: 1315
diff changeset
77 #include "symtab.h"
8256c4c57419 [project @ 1995-09-05 08:02:08 by jwe]
jwe
parents: 1315
diff changeset
78 #include "token.h"
3021
18d64612e67a [project @ 1997-06-03 22:18:56 by jwe]
jwe
parents: 3016
diff changeset
79 #include "unwind-prot.h"
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
80 #include "utils.h"
1351
8256c4c57419 [project @ 1995-09-05 08:02:08 by jwe]
jwe
parents: 1315
diff changeset
81 #include "variables.h"
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
82
16149
49dfba4fd3c5 use pure parser and reentrant lexer interfaces
John W. Eaton <jwe@octave.org>
parents: 16147
diff changeset
83 // 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
84 #include <oct-parse.h>
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 extern int octave_lex (YYSTYPE *, void *);
49dfba4fd3c5 use pure parser and reentrant lexer interfaces
John W. Eaton <jwe@octave.org>
parents: 16147
diff changeset
87
49dfba4fd3c5 use pure parser and reentrant lexer interfaces
John W. Eaton <jwe@octave.org>
parents: 16147
diff changeset
88 // Global access to currently active lexer.
21066
258c787cd9ce maint: Use "FIXME:" consistently in code base.
Rik <rik@octave.org>
parents: 21065
diff changeset
89 // 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
90 octave_base_lexer *LEXER = 0;
16149
49dfba4fd3c5 use pure parser and reentrant lexer interfaces
John W. Eaton <jwe@octave.org>
parents: 16147
diff changeset
91
10426
4db7beace28e oct-parse.yy, lex.ll: use symbols via gnulib namespace
John W. Eaton <jwe@octave.org>
parents: 10411
diff changeset
92 #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
93 // 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
94 // 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
95 // 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
96 #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
97 #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
98 #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
99 #endif
4db7beace28e oct-parse.yy, lex.ll: use symbols via gnulib namespace
John W. Eaton <jwe@octave.org>
parents: 10411
diff changeset
100
3021
18d64612e67a [project @ 1997-06-03 22:18:56 by jwe]
jwe
parents: 3016
diff changeset
101 // TRUE means we printed messages about reading startup files.
18d64612e67a [project @ 1997-06-03 22:18:56 by jwe]
jwe
parents: 3016
diff changeset
102 bool reading_startup_message_printed = false;
18d64612e67a [project @ 1997-06-03 22:18:56 by jwe]
jwe
parents: 3016
diff changeset
103
5484
2ff5363a16bd [project @ 2005-10-06 17:12:12 by jwe]
jwe
parents: 5472
diff changeset
104 // List of autoloads (function -> file mapping).
2ff5363a16bd [project @ 2005-10-06 17:12:12 by jwe]
jwe
parents: 5472
diff changeset
105 static std::map<std::string, std::string> autoload_map;
2ff5363a16bd [project @ 2005-10-06 17:12:12 by jwe]
jwe
parents: 5472
diff changeset
106
496
e7c5b23b34d3 [project @ 1994-07-06 15:02:26 by jwe]
jwe
parents: 482
diff changeset
107 // Forward declarations for some functions defined at the bottom of
e7c5b23b34d3 [project @ 1994-07-06 15:02:26 by jwe]
jwe
parents: 482
diff changeset
108 // the file.
e7c5b23b34d3 [project @ 1994-07-06 15:02:26 by jwe]
jwe
parents: 482
diff changeset
109
16288
fe3b9a51e625 rename curr_lexer, curr_parser, CURR_LEXER
John W. Eaton <jwe@octave.org>
parents: 16287
diff changeset
110 static void yyerror (octave_base_parser& parser, const char *s);
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
111
16288
fe3b9a51e625 rename curr_lexer, curr_parser, CURR_LEXER
John W. Eaton <jwe@octave.org>
parents: 16287
diff changeset
112 #define lexer parser.lexer
fe3b9a51e625 rename curr_lexer, curr_parser, CURR_LEXER
John W. Eaton <jwe@octave.org>
parents: 16287
diff changeset
113 #define scanner lexer.scanner
16149
49dfba4fd3c5 use pure parser and reentrant lexer interfaces
John W. Eaton <jwe@octave.org>
parents: 16147
diff changeset
114
21023
ec532a439c6f rework method of disabling warnings from GCC
John W. Eaton <jwe@octave.org>
parents: 21021
diff changeset
115 #if defined (HAVE_PRAGMA_GCC_DIAGNOSTIC)
ec532a439c6f rework method of disabling warnings from GCC
John W. Eaton <jwe@octave.org>
parents: 21021
diff changeset
116 // Disable this warning for code that is generated by Bison, including
ec532a439c6f rework method of disabling warnings from GCC
John W. Eaton <jwe@octave.org>
parents: 21021
diff changeset
117 // grammar rules. Push the current state so we can restore the warning
ec532a439c6f rework method of disabling warnings from GCC
John W. Eaton <jwe@octave.org>
parents: 21021
diff changeset
118 // state prior to functions we define at the bottom of the file.
ec532a439c6f rework method of disabling warnings from GCC
John W. Eaton <jwe@octave.org>
parents: 21021
diff changeset
119 #pragma GCC diagnostic push
ec532a439c6f rework method of disabling warnings from GCC
John W. Eaton <jwe@octave.org>
parents: 21021
diff changeset
120 #pragma GCC diagnostic ignored "-Wold-style-cast"
ec532a439c6f rework method of disabling warnings from GCC
John W. Eaton <jwe@octave.org>
parents: 21021
diff changeset
121 #endif
ec532a439c6f rework method of disabling warnings from GCC
John W. Eaton <jwe@octave.org>
parents: 21021
diff changeset
122
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
123 %}
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
124
666
fb4f6556b443 [project @ 1994-09-06 21:22:46 by jwe]
jwe
parents: 627
diff changeset
125 // Bison declarations.
fb4f6556b443 [project @ 1994-09-06 21:22:46 by jwe]
jwe
parents: 627
diff changeset
126
17743
af5ad573c665 oct-parse.in.yy: Add %expect declaration.
John W. Eaton <jwe@octave.org>
parents: 17731
diff changeset
127 // 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
128 // we notice if that number changes.
af5ad573c665 oct-parse.in.yy: Add %expect declaration.
John W. Eaton <jwe@octave.org>
parents: 17731
diff changeset
129
af5ad573c665 oct-parse.in.yy: Add %expect declaration.
John W. Eaton <jwe@octave.org>
parents: 17731
diff changeset
130 %expect 14
af5ad573c665 oct-parse.in.yy: Add %expect declaration.
John W. Eaton <jwe@octave.org>
parents: 17731
diff changeset
131
18974
d8abf813c69f handle changes in bison 3.x
John W. Eaton <jwe@octave.org>
parents: 18531
diff changeset
132 %API_PREFIX_DECL%
4753
9f0ce1536368 [project @ 2004-02-13 17:55:24 by jwe]
jwe
parents: 4699
diff changeset
133
16149
49dfba4fd3c5 use pure parser and reentrant lexer interfaces
John W. Eaton <jwe@octave.org>
parents: 16147
diff changeset
134 // 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
135 // 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
136 // 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
137 // 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
138 // 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
139 // 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
140 // 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
141 // 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
142
49dfba4fd3c5 use pure parser and reentrant lexer interfaces
John W. Eaton <jwe@octave.org>
parents: 16147
diff changeset
143 %define api.pure
16174
39096b290a2f check syntax used to enable bison push/pull parser
John W. Eaton <jwe@octave.org>
parents: 16167
diff changeset
144 %PUSH_PULL_DECL%
16288
fe3b9a51e625 rename curr_lexer, curr_parser, CURR_LEXER
John W. Eaton <jwe@octave.org>
parents: 16287
diff changeset
145 %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
146 %lex-param { void *scanner }
49dfba4fd3c5 use pure parser and reentrant lexer interfaces
John W. Eaton <jwe@octave.org>
parents: 16147
diff changeset
147
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
148 %union
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
149 {
19778
bf737d927707 eliminate bison warnings from oct-parse.yy
John W. Eaton <jwe@octave.org>
parents: 19709
diff changeset
150 int dummy_type;
bf737d927707 eliminate bison warnings from oct-parse.yy
John W. Eaton <jwe@octave.org>
parents: 19709
diff changeset
151
2891
1a30f46e1870 [project @ 1997-04-28 01:49:00 by jwe]
jwe
parents: 2884
diff changeset
152 // The type of the basic tokens returned by the lexer.
143
7849db4b6dbc [project @ 1993-10-04 02:36:45 by jwe]
jwe
parents: 118
diff changeset
153 token *tok_val;
7849db4b6dbc [project @ 1993-10-04 02:36:45 by jwe]
jwe
parents: 118
diff changeset
154
3665
0689afb1d001 [project @ 2000-05-11 19:07:56 by jwe]
jwe
parents: 3544
diff changeset
155 // Comment strings that we need to deal with mid-rule.
0689afb1d001 [project @ 2000-05-11 19:07:56 by jwe]
jwe
parents: 3544
diff changeset
156 octave_comment_list *comment_type;
0689afb1d001 [project @ 2000-05-11 19:07:56 by jwe]
jwe
parents: 3544
diff changeset
157
2891
1a30f46e1870 [project @ 1997-04-28 01:49:00 by jwe]
jwe
parents: 2884
diff changeset
158 // Types for the nonterminals we generate.
19778
bf737d927707 eliminate bison warnings from oct-parse.yy
John W. Eaton <jwe@octave.org>
parents: 19709
diff changeset
159 char punct_type;
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
160 tree *tree_type;
1829
7d2982b55242 [project @ 1996-02-02 14:12:59 by jwe]
jwe
parents: 1826
diff changeset
161 tree_matrix *tree_matrix_type;
3351
8623649c967c [project @ 1999-11-15 16:17:01 by jwe]
jwe
parents: 3347
diff changeset
162 tree_cell *tree_cell_type;
496
e7c5b23b34d3 [project @ 1994-07-06 15:02:26 by jwe]
jwe
parents: 482
diff changeset
163 tree_expression *tree_expression_type;
2375
7ef24992e290 [project @ 1996-10-12 00:39:52 by jwe]
jwe
parents: 2200
diff changeset
164 tree_constant *tree_constant_type;
4342
813effe14ee1 [project @ 2003-02-20 08:35:55 by jwe]
jwe
parents: 4318
diff changeset
165 tree_fcn_handle *tree_fcn_handle_type;
15037
56b8eb7c9c04 improvements in parsing classdef
John W. Eaton <jwe@octave.org>
parents: 14846
diff changeset
166 tree_funcall *tree_funcall_type;
56b8eb7c9c04 improvements in parsing classdef
John W. Eaton <jwe@octave.org>
parents: 14846
diff changeset
167 tree_function_def *tree_function_def_type;
5861
2a6cb4ed8f1e [project @ 2006-06-16 05:09:41 by jwe]
jwe
parents: 5848
diff changeset
168 tree_anon_fcn_handle *tree_anon_fcn_handle_type;
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
169 tree_identifier *tree_identifier_type;
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
170 tree_index_expression *tree_index_expression_type;
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
171 tree_colon_expression *tree_colon_expression_type;
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
172 tree_argument_list *tree_argument_list_type;
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
173 tree_parameter_list *tree_parameter_list_type;
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
174 tree_command *tree_command_type;
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
175 tree_if_command *tree_if_command_type;
578
d169be9237fb [project @ 1994-08-03 20:06:54 by jwe]
jwe
parents: 572
diff changeset
176 tree_if_clause *tree_if_clause_type;
d169be9237fb [project @ 1994-08-03 20:06:54 by jwe]
jwe
parents: 572
diff changeset
177 tree_if_command_list *tree_if_command_list_type;
2764
2c0f259cf83d [project @ 1997-03-01 02:30:26 by jwe]
jwe
parents: 2745
diff changeset
178 tree_switch_command *tree_switch_command_type;
2c0f259cf83d [project @ 1997-03-01 02:30:26 by jwe]
jwe
parents: 2745
diff changeset
179 tree_switch_case *tree_switch_case_type;
2c0f259cf83d [project @ 1997-03-01 02:30:26 by jwe]
jwe
parents: 2745
diff changeset
180 tree_switch_case_list *tree_switch_case_list_type;
2846
52e7c4509983 [project @ 1997-03-26 23:27:35 by jwe]
jwe
parents: 2825
diff changeset
181 tree_decl_elt *tree_decl_elt_type;
52e7c4509983 [project @ 1997-03-26 23:27:35 by jwe]
jwe
parents: 2825
diff changeset
182 tree_decl_init_list *tree_decl_init_list_type;
52e7c4509983 [project @ 1997-03-26 23:27:35 by jwe]
jwe
parents: 2825
diff changeset
183 tree_decl_command *tree_decl_command_type;
578
d169be9237fb [project @ 1994-08-03 20:06:54 by jwe]
jwe
parents: 572
diff changeset
184 tree_statement *tree_statement_type;
d169be9237fb [project @ 1994-08-03 20:06:54 by jwe]
jwe
parents: 572
diff changeset
185 tree_statement_list *tree_statement_list_type;
2891
1a30f46e1870 [project @ 1997-04-28 01:49:00 by jwe]
jwe
parents: 2884
diff changeset
186 octave_user_function *octave_user_function_type;
15037
56b8eb7c9c04 improvements in parsing classdef
John W. Eaton <jwe@octave.org>
parents: 14846
diff changeset
187
56b8eb7c9c04 improvements in parsing classdef
John W. Eaton <jwe@octave.org>
parents: 14846
diff changeset
188 tree_classdef *tree_classdef_type;
56b8eb7c9c04 improvements in parsing classdef
John W. Eaton <jwe@octave.org>
parents: 14846
diff changeset
189 tree_classdef_attribute* tree_classdef_attribute_type;
56b8eb7c9c04 improvements in parsing classdef
John W. Eaton <jwe@octave.org>
parents: 14846
diff changeset
190 tree_classdef_attribute_list* tree_classdef_attribute_list_type;
56b8eb7c9c04 improvements in parsing classdef
John W. Eaton <jwe@octave.org>
parents: 14846
diff changeset
191 tree_classdef_superclass* tree_classdef_superclass_type;
56b8eb7c9c04 improvements in parsing classdef
John W. Eaton <jwe@octave.org>
parents: 14846
diff changeset
192 tree_classdef_superclass_list* tree_classdef_superclass_list_type;
56b8eb7c9c04 improvements in parsing classdef
John W. Eaton <jwe@octave.org>
parents: 14846
diff changeset
193 tree_classdef_body* tree_classdef_body_type;
56b8eb7c9c04 improvements in parsing classdef
John W. Eaton <jwe@octave.org>
parents: 14846
diff changeset
194 tree_classdef_property* tree_classdef_property_type;
56b8eb7c9c04 improvements in parsing classdef
John W. Eaton <jwe@octave.org>
parents: 14846
diff changeset
195 tree_classdef_property_list* tree_classdef_property_list_type;
56b8eb7c9c04 improvements in parsing classdef
John W. Eaton <jwe@octave.org>
parents: 14846
diff changeset
196 tree_classdef_properties_block* tree_classdef_properties_block_type;
56b8eb7c9c04 improvements in parsing classdef
John W. Eaton <jwe@octave.org>
parents: 14846
diff changeset
197 tree_classdef_methods_list* tree_classdef_methods_list_type;
56b8eb7c9c04 improvements in parsing classdef
John W. Eaton <jwe@octave.org>
parents: 14846
diff changeset
198 tree_classdef_methods_block* tree_classdef_methods_block_type;
56b8eb7c9c04 improvements in parsing classdef
John W. Eaton <jwe@octave.org>
parents: 14846
diff changeset
199 tree_classdef_event* tree_classdef_event_type;
56b8eb7c9c04 improvements in parsing classdef
John W. Eaton <jwe@octave.org>
parents: 14846
diff changeset
200 tree_classdef_events_list* tree_classdef_events_list_type;
56b8eb7c9c04 improvements in parsing classdef
John W. Eaton <jwe@octave.org>
parents: 14846
diff changeset
201 tree_classdef_events_block* tree_classdef_events_block_type;
56b8eb7c9c04 improvements in parsing classdef
John W. Eaton <jwe@octave.org>
parents: 14846
diff changeset
202 tree_classdef_enum* tree_classdef_enum_type;
56b8eb7c9c04 improvements in parsing classdef
John W. Eaton <jwe@octave.org>
parents: 14846
diff changeset
203 tree_classdef_enum_list* tree_classdef_enum_list_type;
56b8eb7c9c04 improvements in parsing classdef
John W. Eaton <jwe@octave.org>
parents: 14846
diff changeset
204 tree_classdef_enum_block* tree_classdef_enum_block_type;
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
205 }
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
206
143
7849db4b6dbc [project @ 1993-10-04 02:36:45 by jwe]
jwe
parents: 118
diff changeset
207 // Tokens with line and column information.
7849db4b6dbc [project @ 1993-10-04 02:36:45 by jwe]
jwe
parents: 118
diff changeset
208 %token <tok_val> '=' ':' '-' '+' '*' '/'
4018
a8621d87fbf5 [project @ 2002-08-05 03:17:25 by jwe]
jwe
parents: 4009
diff changeset
209 %token <tok_val> ADD_EQ SUB_EQ MUL_EQ DIV_EQ LEFTDIV_EQ POW_EQ
a8621d87fbf5 [project @ 2002-08-05 03:17:25 by jwe]
jwe
parents: 4009
diff changeset
210 %token <tok_val> EMUL_EQ EDIV_EQ ELEFTDIV_EQ EPOW_EQ AND_EQ OR_EQ
428
fa0453b25410 [project @ 1994-05-25 01:06:28 by jwe]
jwe
parents: 341
diff changeset
211 %token <tok_val> EXPR_AND_AND EXPR_OR_OR
143
7849db4b6dbc [project @ 1993-10-04 02:36:45 by jwe]
jwe
parents: 118
diff changeset
212 %token <tok_val> EXPR_AND EXPR_OR EXPR_NOT
7849db4b6dbc [project @ 1993-10-04 02:36:45 by jwe]
jwe
parents: 118
diff changeset
213 %token <tok_val> EXPR_LT EXPR_LE EXPR_EQ EXPR_NE EXPR_GE EXPR_GT
1276
cbdf7db98554 [project @ 1995-04-24 15:31:24 by jwe]
jwe
parents: 1266
diff changeset
214 %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
215 %token <tok_val> HERMITIAN TRANSPOSE
143
7849db4b6dbc [project @ 1993-10-04 02:36:45 by jwe]
jwe
parents: 118
diff changeset
216 %token <tok_val> PLUS_PLUS MINUS_MINUS POW EPOW
7849db4b6dbc [project @ 1993-10-04 02:36:45 by jwe]
jwe
parents: 118
diff changeset
217 %token <tok_val> NUM IMAG_NUM
2970
b9e64477f703 [project @ 1997-05-15 18:04:21 by jwe]
jwe
parents: 2961
diff changeset
218 %token <tok_val> STRUCT_ELT
2883
0b3954110c77 [project @ 1997-04-24 09:57:05 by jwe]
jwe
parents: 2865
diff changeset
219 %token <tok_val> NAME
143
7849db4b6dbc [project @ 1993-10-04 02:36:45 by jwe]
jwe
parents: 118
diff changeset
220 %token <tok_val> END
5279
bd32f770c09a [project @ 2005-04-12 21:55:31 by jwe]
jwe
parents: 5189
diff changeset
221 %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
222 %token <tok_val> FOR PARFOR WHILE DO UNTIL
1491
893b416bb919 [project @ 1995-09-29 04:03:01 by jwe]
jwe
parents: 1489
diff changeset
223 %token <tok_val> IF ELSEIF ELSE
2764
2c0f259cf83d [project @ 1997-03-01 02:30:26 by jwe]
jwe
parents: 2745
diff changeset
224 %token <tok_val> SWITCH CASE OTHERWISE
1491
893b416bb919 [project @ 1995-09-29 04:03:01 by jwe]
jwe
parents: 1489
diff changeset
225 %token <tok_val> BREAK CONTINUE FUNC_RET
924
8b0920cc1d64 [project @ 1994-11-15 00:40:50 by jwe]
jwe
parents: 922
diff changeset
226 %token <tok_val> UNWIND CLEANUP
1489
3e705c864019 [project @ 1995-09-28 05:38:26 by jwe]
jwe
parents: 1371
diff changeset
227 %token <tok_val> TRY CATCH
14294
9e3983c8963c deprecate the static keyword
John W. Eaton <jwe@octave.org>
parents: 14293
diff changeset
228 %token <tok_val> GLOBAL PERSISTENT
4342
813effe14ee1 [project @ 2003-02-20 08:35:55 by jwe]
jwe
parents: 4318
diff changeset
229 %token <tok_val> FCN_HANDLE
15037
56b8eb7c9c04 improvements in parsing classdef
John W. Eaton <jwe@octave.org>
parents: 14846
diff changeset
230 %token <tok_val> CLASSDEF
13249
7861a5fd3479 accept enumeration keyword
John W. Eaton <jwe@octave.org>
parents: 13246
diff changeset
231 %token <tok_val> PROPERTIES METHODS EVENTS ENUMERATION
9476
d9b25c5b8ee5 handle classdef syntax in lexer and parser
Ryan Rusaw
parents: 9474
diff changeset
232 %token <tok_val> METAQUERY
d9b25c5b8ee5 handle classdef syntax in lexer and parser
Ryan Rusaw
parents: 9474
diff changeset
233 %token <tok_val> SUPERCLASSREF
18520
932aca9a7c57 Allow multi-level classdef package.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 18419
diff changeset
234 %token <tok_val> FQ_IDENT
9476
d9b25c5b8ee5 handle classdef syntax in lexer and parser
Ryan Rusaw
parents: 9474
diff changeset
235 %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
236 %token <tok_val> FCN
21064
a9f2c2d72892 handle lexical errors as parser errors (bug #46877)
John W. Eaton <jwe@octave.org>
parents: 21063
diff changeset
237 %token <tok_val> LEXICAL_ERROR
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
238
143
7849db4b6dbc [project @ 1993-10-04 02:36:45 by jwe]
jwe
parents: 118
diff changeset
239 // Other tokens.
21064
a9f2c2d72892 handle lexical errors as parser errors (bug #46877)
John W. Eaton <jwe@octave.org>
parents: 21063
diff changeset
240 %token<dummy_type> END_OF_INPUT
19778
bf737d927707 eliminate bison warnings from oct-parse.yy
John W. Eaton <jwe@octave.org>
parents: 19709
diff changeset
241 %token<dummy_type> INPUT_FILE
7587
1f662945c2be handle varargin and varargout without keywords
John W. Eaton <jwe@octave.org>
parents: 7562
diff changeset
242 // %token VARARGIN VARARGOUT
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
243
19778
bf737d927707 eliminate bison warnings from oct-parse.yy
John W. Eaton <jwe@octave.org>
parents: 19709
diff changeset
244 %token<dummy_type> '(' ')' '[' ']' '{' '}' '.' ',' ';' '@' '\n'
bf737d927707 eliminate bison warnings from oct-parse.yy
John W. Eaton <jwe@octave.org>
parents: 19709
diff changeset
245
143
7849db4b6dbc [project @ 1993-10-04 02:36:45 by jwe]
jwe
parents: 118
diff changeset
246 // Nonterminals we construct.
19778
bf737d927707 eliminate bison warnings from oct-parse.yy
John W. Eaton <jwe@octave.org>
parents: 19709
diff changeset
247 %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: 19709
diff changeset
248 %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>
parents: 16595 16627
diff changeset
249 %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
250 %type <tok_val> function_beg classdef_beg
19778
bf737d927707 eliminate bison warnings from oct-parse.yy
John W. Eaton <jwe@octave.org>
parents: 19709
diff changeset
251 %type <punct_type> sep_no_nl opt_sep_no_nl nl opt_nl sep opt_sep
578
d169be9237fb [project @ 1994-08-03 20:06:54 by jwe]
jwe
parents: 572
diff changeset
252 %type <tree_type> input
5861
2a6cb4ed8f1e [project @ 2006-06-16 05:09:41 by jwe]
jwe
parents: 5848
diff changeset
253 %type <tree_constant_type> string constant magic_colon
2a6cb4ed8f1e [project @ 2006-06-16 05:09:41 by jwe]
jwe
parents: 5848
diff changeset
254 %type <tree_anon_fcn_handle_type> anon_fcn_handle
4342
813effe14ee1 [project @ 2003-02-20 08:35:55 by jwe]
jwe
parents: 4318
diff changeset
255 %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
256 %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
257 %type <tree_cell_type> cell_rows
5102
b04b30d30c66 [project @ 2004-12-28 01:59:05 by jwe]
jwe
parents: 5013
diff changeset
258 %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
259 %type <tree_expression_type> primary_expr oper_expr power_expr
4207
fa3482b34599 [project @ 2002-12-03 18:22:05 by jwe]
jwe
parents: 4186
diff changeset
260 %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
261 %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
262 %type <tree_funcall_type> superclass_identifier meta_identifier
56b8eb7c9c04 improvements in parsing classdef
John W. Eaton <jwe@octave.org>
parents: 14846
diff changeset
263 %type <octave_user_function_type> function1 function2
2970
b9e64477f703 [project @ 1997-05-15 18:04:21 by jwe]
jwe
parents: 2961
diff changeset
264 %type <tree_index_expression_type> word_list_cmd
b9e64477f703 [project @ 1997-05-15 18:04:21 by jwe]
jwe
parents: 2961
diff changeset
265 %type <tree_colon_expression_type> colon_expr1
3351
8623649c967c [project @ 1999-11-15 16:17:01 by jwe]
jwe
parents: 3347
diff changeset
266 %type <tree_argument_list_type> arg_list word_list assign_lhs
8623649c967c [project @ 1999-11-15 16:17:01 by jwe]
jwe
parents: 3347
diff changeset
267 %type <tree_argument_list_type> cell_or_matrix_row
4935
4fc993a4e072 [project @ 2004-08-06 03:17:12 by jwe]
jwe
parents: 4930
diff changeset
268 %type <tree_parameter_list_type> param_list param_list1 param_list2
723
1c072f20b522 [project @ 1994-09-21 16:00:10 by jwe]
jwe
parents: 666
diff changeset
269 %type <tree_parameter_list_type> return_list return_list1
2970
b9e64477f703 [project @ 1997-05-15 18:04:21 by jwe]
jwe
parents: 2961
diff changeset
270 %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
271 %type <tree_command_type> jump_command except_command
56b8eb7c9c04 improvements in parsing classdef
John W. Eaton <jwe@octave.org>
parents: 14846
diff changeset
272 %type <tree_function_def_type> function
56b8eb7c9c04 improvements in parsing classdef
John W. Eaton <jwe@octave.org>
parents: 14846
diff changeset
273 %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
274 %type <tree_command_type> file
578
d169be9237fb [project @ 1994-08-03 20:06:54 by jwe]
jwe
parents: 572
diff changeset
275 %type <tree_if_command_type> if_command
d169be9237fb [project @ 1994-08-03 20:06:54 by jwe]
jwe
parents: 572
diff changeset
276 %type <tree_if_clause_type> elseif_clause else_clause
d169be9237fb [project @ 1994-08-03 20:06:54 by jwe]
jwe
parents: 572
diff changeset
277 %type <tree_if_command_list_type> if_cmd_list1 if_cmd_list
2764
2c0f259cf83d [project @ 1997-03-01 02:30:26 by jwe]
jwe
parents: 2745
diff changeset
278 %type <tree_switch_command_type> switch_command
2c0f259cf83d [project @ 1997-03-01 02:30:26 by jwe]
jwe
parents: 2745
diff changeset
279 %type <tree_switch_case_type> switch_case default_case
2c0f259cf83d [project @ 1997-03-01 02:30:26 by jwe]
jwe
parents: 2745
diff changeset
280 %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
281 %type <tree_decl_elt_type> decl2 param_list_elt
2846
52e7c4509983 [project @ 1997-03-26 23:27:35 by jwe]
jwe
parents: 2825
diff changeset
282 %type <tree_decl_init_list_type> decl1
52e7c4509983 [project @ 1997-03-26 23:27:35 by jwe]
jwe
parents: 2825
diff changeset
283 %type <tree_decl_command_type> declaration
15037
56b8eb7c9c04 improvements in parsing classdef
John W. Eaton <jwe@octave.org>
parents: 14846
diff changeset
284 %type <tree_statement_type> statement function_end
627
739d16c30481 [project @ 1994-08-19 13:23:14 by jwe]
jwe
parents: 620
diff changeset
285 %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
286 %type <tree_statement_list_type> opt_list
15037
56b8eb7c9c04 improvements in parsing classdef
John W. Eaton <jwe@octave.org>
parents: 14846
diff changeset
287 %type <tree_classdef_attribute_type> attr
56b8eb7c9c04 improvements in parsing classdef
John W. Eaton <jwe@octave.org>
parents: 14846
diff changeset
288 %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
289 %type <tree_classdef_superclass_type> superclass
56b8eb7c9c04 improvements in parsing classdef
John W. Eaton <jwe@octave.org>
parents: 14846
diff changeset
290 %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
291 %type <tree_classdef_body_type> class_body
56b8eb7c9c04 improvements in parsing classdef
John W. Eaton <jwe@octave.org>
parents: 14846
diff changeset
292 %type <tree_classdef_property_type> class_property
56b8eb7c9c04 improvements in parsing classdef
John W. Eaton <jwe@octave.org>
parents: 14846
diff changeset
293 %type <tree_classdef_property_list_type> property_list
56b8eb7c9c04 improvements in parsing classdef
John W. Eaton <jwe@octave.org>
parents: 14846
diff changeset
294 %type <tree_classdef_properties_block_type> properties_block
56b8eb7c9c04 improvements in parsing classdef
John W. Eaton <jwe@octave.org>
parents: 14846
diff changeset
295 %type <tree_classdef_methods_list_type> methods_list
56b8eb7c9c04 improvements in parsing classdef
John W. Eaton <jwe@octave.org>
parents: 14846
diff changeset
296 %type <tree_classdef_methods_block_type> methods_block
56b8eb7c9c04 improvements in parsing classdef
John W. Eaton <jwe@octave.org>
parents: 14846
diff changeset
297 %type <tree_classdef_event_type> class_event
56b8eb7c9c04 improvements in parsing classdef
John W. Eaton <jwe@octave.org>
parents: 14846
diff changeset
298 %type <tree_classdef_events_list_type> events_list
56b8eb7c9c04 improvements in parsing classdef
John W. Eaton <jwe@octave.org>
parents: 14846
diff changeset
299 %type <tree_classdef_events_block_type> events_block
56b8eb7c9c04 improvements in parsing classdef
John W. Eaton <jwe@octave.org>
parents: 14846
diff changeset
300 %type <tree_classdef_enum_type> class_enum
56b8eb7c9c04 improvements in parsing classdef
John W. Eaton <jwe@octave.org>
parents: 14846
diff changeset
301 %type <tree_classdef_enum_list_type> enum_list
56b8eb7c9c04 improvements in parsing classdef
John W. Eaton <jwe@octave.org>
parents: 14846
diff changeset
302 %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: 18158
diff changeset
303 %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: 18158
diff changeset
304 %type <octave_user_function_type> method_decl1
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
305
143
7849db4b6dbc [project @ 1993-10-04 02:36:45 by jwe]
jwe
parents: 118
diff changeset
306 // Precedence and associativity.
21294
3d375b0905a0 eliminate unused << and >> operators from Octave scripting language
John W. Eaton <jwe@octave.org>
parents: 21159
diff changeset
307 %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
4023
ef3caf27cb9c [project @ 2002-08-07 06:54:41 by jwe]
jwe
parents: 4018
diff changeset
308 %left EXPR_OR_OR
ef3caf27cb9c [project @ 2002-08-07 06:54:41 by jwe]
jwe
parents: 4018
diff changeset
309 %left EXPR_AND_AND
ef3caf27cb9c [project @ 2002-08-07 06:54:41 by jwe]
jwe
parents: 4018
diff changeset
310 %left EXPR_OR
ef3caf27cb9c [project @ 2002-08-07 06:54:41 by jwe]
jwe
parents: 4018
diff changeset
311 %left EXPR_AND
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
312 %left EXPR_LT EXPR_LE EXPR_EQ EXPR_NE EXPR_GE EXPR_GT
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
313 %left ':'
1276
cbdf7db98554 [project @ 1995-04-24 15:31:24 by jwe]
jwe
parents: 1266
diff changeset
314 %left '-' '+' EPLUS EMINUS
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
315 %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
316 %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
317 %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
318 %right PLUS_PLUS MINUS_MINUS
3351
8623649c967c [project @ 1999-11-15 16:17:01 by jwe]
jwe
parents: 3347
diff changeset
319 %left '(' '.' '{'
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
320
17629
1e8f8900a041 clean up partially constructed parse tree objects on parse errors (bug #40231)
John W. Eaton <jwe@octave.org>
parents: 17622
diff changeset
321 // 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
322 // 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
323 // 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
324 // 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
325 // 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
326 // here).
0c5f50706ba3 attempt to catch possible memory leaks in parser cleanup
John W. Eaton <jwe@octave.org>
parents: 17632
diff changeset
327
0c5f50706ba3 attempt to catch possible memory leaks in parser cleanup
John W. Eaton <jwe@octave.org>
parents: 17632
diff changeset
328 %destructor { } <tok_val>
19778
bf737d927707 eliminate bison warnings from oct-parse.yy
John W. Eaton <jwe@octave.org>
parents: 19709
diff changeset
329 %destructor { } <punct_type>
17658
0c5f50706ba3 attempt to catch possible memory leaks in parser cleanup
John W. Eaton <jwe@octave.org>
parents: 17632
diff changeset
330 %destructor { } <comment_type>
0c5f50706ba3 attempt to catch possible memory leaks in parser cleanup
John W. Eaton <jwe@octave.org>
parents: 17632
diff changeset
331 %destructor { } <>
0c5f50706ba3 attempt to catch possible memory leaks in parser cleanup
John W. Eaton <jwe@octave.org>
parents: 17632
diff changeset
332
19593
446c46af4b42 strip trailing whitespace from most source files
John W. Eaton <jwe@octave.org>
parents: 18974
diff changeset
333 %destructor { delete $$; } <tree_type>
446c46af4b42 strip trailing whitespace from most source files
John W. Eaton <jwe@octave.org>
parents: 18974
diff changeset
334 %destructor { delete $$; } <tree_matrix_type>
446c46af4b42 strip trailing whitespace from most source files
John W. Eaton <jwe@octave.org>
parents: 18974
diff changeset
335 %destructor { delete $$; } <tree_cell_type>
446c46af4b42 strip trailing whitespace from most source files
John W. Eaton <jwe@octave.org>
parents: 18974
diff changeset
336 %destructor { delete $$; } <tree_expression_type>
446c46af4b42 strip trailing whitespace from most source files
John W. Eaton <jwe@octave.org>
parents: 18974
diff changeset
337 %destructor { delete $$; } <tree_constant_type>
446c46af4b42 strip trailing whitespace from most source files
John W. Eaton <jwe@octave.org>
parents: 18974
diff changeset
338 %destructor { delete $$; } <tree_fcn_handle_type>
19778
bf737d927707 eliminate bison warnings from oct-parse.yy
John W. Eaton <jwe@octave.org>
parents: 19709
diff changeset
339 %destructor { delete $$; } <tree_funcall_type>
bf737d927707 eliminate bison warnings from oct-parse.yy
John W. Eaton <jwe@octave.org>
parents: 19709
diff changeset
340 %destructor { delete $$; } <tree_function_def_type>
19593
446c46af4b42 strip trailing whitespace from most source files
John W. Eaton <jwe@octave.org>
parents: 18974
diff changeset
341 %destructor { delete $$; } <tree_anon_fcn_handle_type>
446c46af4b42 strip trailing whitespace from most source files
John W. Eaton <jwe@octave.org>
parents: 18974
diff changeset
342 %destructor { delete $$; } <tree_identifier_type>
446c46af4b42 strip trailing whitespace from most source files
John W. Eaton <jwe@octave.org>
parents: 18974
diff changeset
343 %destructor { delete $$; } <tree_index_expression_type>
446c46af4b42 strip trailing whitespace from most source files
John W. Eaton <jwe@octave.org>
parents: 18974
diff changeset
344 %destructor { delete $$; } <tree_colon_expression_type>
446c46af4b42 strip trailing whitespace from most source files
John W. Eaton <jwe@octave.org>
parents: 18974
diff changeset
345 %destructor { delete $$; } <tree_argument_list_type>
446c46af4b42 strip trailing whitespace from most source files
John W. Eaton <jwe@octave.org>
parents: 18974
diff changeset
346 %destructor { delete $$; } <tree_parameter_list_type>
446c46af4b42 strip trailing whitespace from most source files
John W. Eaton <jwe@octave.org>
parents: 18974
diff changeset
347 %destructor { delete $$; } <tree_command_type>
446c46af4b42 strip trailing whitespace from most source files
John W. Eaton <jwe@octave.org>
parents: 18974
diff changeset
348 %destructor { delete $$; } <tree_if_command_type>
446c46af4b42 strip trailing whitespace from most source files
John W. Eaton <jwe@octave.org>
parents: 18974
diff changeset
349 %destructor { delete $$; } <tree_if_clause_type>
446c46af4b42 strip trailing whitespace from most source files
John W. Eaton <jwe@octave.org>
parents: 18974
diff changeset
350 %destructor { delete $$; } <tree_if_command_list_type>
446c46af4b42 strip trailing whitespace from most source files
John W. Eaton <jwe@octave.org>
parents: 18974
diff changeset
351 %destructor { delete $$; } <tree_switch_command_type>
446c46af4b42 strip trailing whitespace from most source files
John W. Eaton <jwe@octave.org>
parents: 18974
diff changeset
352 %destructor { delete $$; } <tree_switch_case_type>
446c46af4b42 strip trailing whitespace from most source files
John W. Eaton <jwe@octave.org>
parents: 18974
diff changeset
353 %destructor { delete $$; } <tree_switch_case_list_type>
446c46af4b42 strip trailing whitespace from most source files
John W. Eaton <jwe@octave.org>
parents: 18974
diff changeset
354 %destructor { delete $$; } <tree_decl_elt_type>
446c46af4b42 strip trailing whitespace from most source files
John W. Eaton <jwe@octave.org>
parents: 18974
diff changeset
355 %destructor { delete $$; } <tree_decl_init_list_type>
446c46af4b42 strip trailing whitespace from most source files
John W. Eaton <jwe@octave.org>
parents: 18974
diff changeset
356 %destructor { delete $$; } <tree_decl_command_type>
446c46af4b42 strip trailing whitespace from most source files
John W. Eaton <jwe@octave.org>
parents: 18974
diff changeset
357 %destructor { delete $$; } <tree_statement_type>
446c46af4b42 strip trailing whitespace from most source files
John W. Eaton <jwe@octave.org>
parents: 18974
diff changeset
358 %destructor { delete $$; } <tree_statement_list_type>
446c46af4b42 strip trailing whitespace from most source files
John W. Eaton <jwe@octave.org>
parents: 18974
diff changeset
359 %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
360
18262
69990d5edcc2 Allow to parse external methods declaration in classdef files.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 18158
diff changeset
361 %destructor { delete $$; } <tree_classdef_type>
69990d5edcc2 Allow to parse external methods declaration in classdef files.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 18158
diff changeset
362 %destructor { delete $$; } <tree_classdef_attribute_type>
69990d5edcc2 Allow to parse external methods declaration in classdef files.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 18158
diff changeset
363 %destructor { delete $$; } <tree_classdef_attribute_list_type>
69990d5edcc2 Allow to parse external methods declaration in classdef files.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 18158
diff changeset
364 %destructor { delete $$; } <tree_classdef_superclass_type>
69990d5edcc2 Allow to parse external methods declaration in classdef files.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 18158
diff changeset
365 %destructor { delete $$; } <tree_classdef_superclass_list_type>
69990d5edcc2 Allow to parse external methods declaration in classdef files.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 18158
diff changeset
366 %destructor { delete $$; } <tree_classdef_body_type>
69990d5edcc2 Allow to parse external methods declaration in classdef files.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 18158
diff changeset
367 %destructor { delete $$; } <tree_classdef_property_type>
69990d5edcc2 Allow to parse external methods declaration in classdef files.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 18158
diff changeset
368 %destructor { delete $$; } <tree_classdef_property_list_type>
69990d5edcc2 Allow to parse external methods declaration in classdef files.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 18158
diff changeset
369 %destructor { delete $$; } <tree_classdef_properties_block_type>
69990d5edcc2 Allow to parse external methods declaration in classdef files.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 18158
diff changeset
370 %destructor { delete $$; } <tree_classdef_methods_list_type>
69990d5edcc2 Allow to parse external methods declaration in classdef files.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 18158
diff changeset
371 %destructor { delete $$; } <tree_classdef_methods_block_type>
69990d5edcc2 Allow to parse external methods declaration in classdef files.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 18158
diff changeset
372 %destructor { delete $$; } <tree_classdef_event_type>
69990d5edcc2 Allow to parse external methods declaration in classdef files.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 18158
diff changeset
373 %destructor { delete $$; } <tree_classdef_events_list_type>
69990d5edcc2 Allow to parse external methods declaration in classdef files.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 18158
diff changeset
374 %destructor { delete $$; } <tree_classdef_events_block_type>
69990d5edcc2 Allow to parse external methods declaration in classdef files.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 18158
diff changeset
375 %destructor { delete $$; } <tree_classdef_enum_type>
69990d5edcc2 Allow to parse external methods declaration in classdef files.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 18158
diff changeset
376 %destructor { delete $$; } <tree_classdef_enum_list_type>
69990d5edcc2 Allow to parse external methods declaration in classdef files.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 18158
diff changeset
377 %destructor { delete $$; } <tree_classdef_enum_block_type>
69990d5edcc2 Allow to parse external methods declaration in classdef files.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 18158
diff changeset
378
19778
bf737d927707 eliminate bison warnings from oct-parse.yy
John W. Eaton <jwe@octave.org>
parents: 19709
diff changeset
379 // 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: 19709
diff changeset
380 // already explicitly declared for all types.
bf737d927707 eliminate bison warnings from oct-parse.yy
John W. Eaton <jwe@octave.org>
parents: 19709
diff changeset
381 //
bf737d927707 eliminate bison warnings from oct-parse.yy
John W. Eaton <jwe@octave.org>
parents: 19709
diff changeset
382 // %destructor {
bf737d927707 eliminate bison warnings from oct-parse.yy
John W. Eaton <jwe@octave.org>
parents: 19709
diff changeset
383 // warning_with_id
bf737d927707 eliminate bison warnings from oct-parse.yy
John W. Eaton <jwe@octave.org>
parents: 19709
diff changeset
384 // ("Octave:parser-destructor",
bf737d927707 eliminate bison warnings from oct-parse.yy
John W. Eaton <jwe@octave.org>
parents: 19709
diff changeset
385 // "possible memory leak in cleanup following parse error");
bf737d927707 eliminate bison warnings from oct-parse.yy
John W. Eaton <jwe@octave.org>
parents: 19709
diff changeset
386 // } <*>
17629
1e8f8900a041 clean up partially constructed parse tree objects on parse errors (bug #40231)
John W. Eaton <jwe@octave.org>
parents: 17622
diff changeset
387
143
7849db4b6dbc [project @ 1993-10-04 02:36:45 by jwe]
jwe
parents: 118
diff changeset
388 // Where to start.
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
389 %start input
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
390
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
391 %%
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
392
2970
b9e64477f703 [project @ 1997-05-15 18:04:21 by jwe]
jwe
parents: 2961
diff changeset
393 // ==============================
b9e64477f703 [project @ 1997-05-15 18:04:21 by jwe]
jwe
parents: 2961
diff changeset
394 // Statements and statement lists
b9e64477f703 [project @ 1997-05-15 18:04:21 by jwe]
jwe
parents: 2961
diff changeset
395 // ==============================
b9e64477f703 [project @ 1997-05-15 18:04:21 by jwe]
jwe
parents: 2961
diff changeset
396
17322
4c1ae06111c9 allow parser to accept empty statements (bug #37099)
John W. Eaton <jwe@octave.org>
parents: 17317
diff changeset
397 input : simple_list '\n'
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
398 {
19778
bf737d927707 eliminate bison warnings from oct-parse.yy
John W. Eaton <jwe@octave.org>
parents: 19709
diff changeset
399 $$ = 0;
16288
fe3b9a51e625 rename curr_lexer, curr_parser, CURR_LEXER
John W. Eaton <jwe@octave.org>
parents: 16287
diff changeset
400 parser.stmt_list = $1;
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
401 YYACCEPT;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
402 }
17322
4c1ae06111c9 allow parser to accept empty statements (bug #37099)
John W. Eaton <jwe@octave.org>
parents: 17317
diff changeset
403 | simple_list END_OF_INPUT
4c1ae06111c9 allow parser to accept empty statements (bug #37099)
John W. Eaton <jwe@octave.org>
parents: 17317
diff changeset
404 {
19778
bf737d927707 eliminate bison warnings from oct-parse.yy
John W. Eaton <jwe@octave.org>
parents: 19709
diff changeset
405 $$ = 0;
17322
4c1ae06111c9 allow parser to accept empty statements (bug #37099)
John W. Eaton <jwe@octave.org>
parents: 17317
diff changeset
406 lexer.end_of_input = true;
4c1ae06111c9 allow parser to accept empty statements (bug #37099)
John W. Eaton <jwe@octave.org>
parents: 17317
diff changeset
407 parser.stmt_list = $1;
4c1ae06111c9 allow parser to accept empty statements (bug #37099)
John W. Eaton <jwe@octave.org>
parents: 17317
diff changeset
408 YYACCEPT;
4c1ae06111c9 allow parser to accept empty statements (bug #37099)
John W. Eaton <jwe@octave.org>
parents: 17317
diff changeset
409 }
17326
f444e4cef9b9 avoid exiting Octave on parse error (bug #39862)
John W. Eaton <jwe@octave.org>
parents: 17322
diff changeset
410 | parse_error
19778
bf737d927707 eliminate bison warnings from oct-parse.yy
John W. Eaton <jwe@octave.org>
parents: 19709
diff changeset
411 {
bf737d927707 eliminate bison warnings from oct-parse.yy
John W. Eaton <jwe@octave.org>
parents: 19709
diff changeset
412 $$ = 0;
21073
f7cc48f601d2 additional reworking of error handling in the parser (bug #46877)
John W. Eaton <jwe@octave.org>
parents: 21071
diff changeset
413 YYABORT;
19778
bf737d927707 eliminate bison warnings from oct-parse.yy
John W. Eaton <jwe@octave.org>
parents: 19709
diff changeset
414 }
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
415 ;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
416
17322
4c1ae06111c9 allow parser to accept empty statements (bug #37099)
John W. Eaton <jwe@octave.org>
parents: 17317
diff changeset
417 simple_list : opt_sep_no_nl
19778
bf737d927707 eliminate bison warnings from oct-parse.yy
John W. Eaton <jwe@octave.org>
parents: 19709
diff changeset
418 {
bf737d927707 eliminate bison warnings from oct-parse.yy
John W. Eaton <jwe@octave.org>
parents: 19709
diff changeset
419 YYUSE ($1);
bf737d927707 eliminate bison warnings from oct-parse.yy
John W. Eaton <jwe@octave.org>
parents: 19709
diff changeset
420
bf737d927707 eliminate bison warnings from oct-parse.yy
John W. Eaton <jwe@octave.org>
parents: 19709
diff changeset
421 $$ = 0;
bf737d927707 eliminate bison warnings from oct-parse.yy
John W. Eaton <jwe@octave.org>
parents: 19709
diff changeset
422 }
17322
4c1ae06111c9 allow parser to accept empty statements (bug #37099)
John W. Eaton <jwe@octave.org>
parents: 17317
diff changeset
423 | 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
424 { $$ = 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
425 ;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
426
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
427 simple_list1 : statement
16288
fe3b9a51e625 rename curr_lexer, curr_parser, CURR_LEXER
John W. Eaton <jwe@octave.org>
parents: 16287
diff changeset
428 { $$ = parser.make_statement_list ($1); }
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
429 | 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
430 { $$ = 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
431 ;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
432
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
433 opt_list : // empty
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
434 { $$ = new tree_statement_list (); }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
435 | list
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
436 { $$ = $1; }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
437 ;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
438
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
439 list : list1 opt_sep
16288
fe3b9a51e625 rename curr_lexer, curr_parser, CURR_LEXER
John W. Eaton <jwe@octave.org>
parents: 16287
diff changeset
440 { $$ = 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
441 ;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
442
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
443 list1 : statement
16288
fe3b9a51e625 rename curr_lexer, curr_parser, CURR_LEXER
John W. Eaton <jwe@octave.org>
parents: 16287
diff changeset
444 { $$ = parser.make_statement_list ($1); }
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
445 | list1 sep statement
16288
fe3b9a51e625 rename curr_lexer, curr_parser, CURR_LEXER
John W. Eaton <jwe@octave.org>
parents: 16287
diff changeset
446 { $$ = 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
447 ;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
448
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
449 statement : expression
17693
efbe746f8fa8 eliminate octave_comment_buffer singleton
John W. Eaton <jwe@octave.org>
parents: 17673
diff changeset
450 { $$ = parser.make_statement ($1); }
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
451 | command
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 | word_list_cmd
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 ;
8746
5dd06f19e9be handle commands in the lexer
John W. Eaton <jwe@octave.org>
parents: 8745
diff changeset
456
5dd06f19e9be handle commands in the lexer
John W. Eaton <jwe@octave.org>
parents: 8745
diff changeset
457 // =================
5dd06f19e9be handle commands in the lexer
John W. Eaton <jwe@octave.org>
parents: 8745
diff changeset
458 // Word-list command
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
5dd06f19e9be handle commands in the lexer
John W. Eaton <jwe@octave.org>
parents: 8745
diff changeset
461 // 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
462 // 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
463 // WHILE, etc.
5dd06f19e9be handle commands in the lexer
John W. Eaton <jwe@octave.org>
parents: 8745
diff changeset
464
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
465 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
466 {
a4af67e0d22c oct-parse.in.yy: a{~}.b segfaults the interpreter (bug #37804)
Max Brister <max@2bass.com>
parents: 16294
diff changeset
467 $$ = 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
468 if (! $$)
17632
bd0a84de3375 further reduce memory leaks from parse errors (bug #40231)
John W. Eaton <jwe@octave.org>
parents: 17629
diff changeset
469 {
bd0a84de3375 further reduce memory leaks from parse errors (bug #40231)
John W. Eaton <jwe@octave.org>
parents: 17629
diff changeset
470 // make_index_expression deleted $1 and $2.
21073
f7cc48f601d2 additional reworking of error handling in the parser (bug #46877)
John W. Eaton <jwe@octave.org>
parents: 21071
diff changeset
471 YYABORT;
17632
bd0a84de3375 further reduce memory leaks from parse errors (bug #40231)
John W. Eaton <jwe@octave.org>
parents: 17629
diff changeset
472 }
16302
a4af67e0d22c oct-parse.in.yy: a{~}.b segfaults the interpreter (bug #37804)
Max Brister <max@2bass.com>
parents: 16294
diff changeset
473 }
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
474 ;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
475
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
476 word_list : string
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
477 { $$ = new tree_argument_list ($1); }
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 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
480 $1->append ($2);
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
481 $$ = $1;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
482 }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
483 ;
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
484
2970
b9e64477f703 [project @ 1997-05-15 18:04:21 by jwe]
jwe
parents: 2961
diff changeset
485 // ===========
b9e64477f703 [project @ 1997-05-15 18:04:21 by jwe]
jwe
parents: 2961
diff changeset
486 // Expressions
b9e64477f703 [project @ 1997-05-15 18:04:21 by jwe]
jwe
parents: 2961
diff changeset
487 // ===========
b9e64477f703 [project @ 1997-05-15 18:04:21 by jwe]
jwe
parents: 2961
diff changeset
488
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
489 identifier : NAME
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
490 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
491 symbol_table::symbol_record *sr = $1->sym_rec ();
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
492 $$ = new tree_identifier (*sr, $1->line (), $1->column ());
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
493 }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
494 ;
2970
b9e64477f703 [project @ 1997-05-15 18:04:21 by jwe]
jwe
parents: 2961
diff changeset
495
9476
d9b25c5b8ee5 handle classdef syntax in lexer and parser
Ryan Rusaw
parents: 9474
diff changeset
496 superclass_identifier
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
497 : SUPERCLASSREF
15037
56b8eb7c9c04 improvements in parsing classdef
John W. Eaton <jwe@octave.org>
parents: 14846
diff changeset
498 {
56b8eb7c9c04 improvements in parsing classdef
John W. Eaton <jwe@octave.org>
parents: 14846
diff changeset
499 std::string method_nm = $1->superclass_method_name ();
56b8eb7c9c04 improvements in parsing classdef
John W. Eaton <jwe@octave.org>
parents: 14846
diff changeset
500 std::string class_nm = $1->superclass_class_name ();
56b8eb7c9c04 improvements in parsing classdef
John W. Eaton <jwe@octave.org>
parents: 14846
diff changeset
501
18927
09eb8a2ddb02 eliminate some unused parameter warnings in parser functions
John W. Eaton <jwe@octave.org>
parents: 18537
diff changeset
502 $$ = parser.make_superclass_ref (method_nm, class_nm);
15037
56b8eb7c9c04 improvements in parsing classdef
John W. Eaton <jwe@octave.org>
parents: 14846
diff changeset
503 }
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
504 ;
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11572
diff changeset
505
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
506 meta_identifier : METAQUERY
15037
56b8eb7c9c04 improvements in parsing classdef
John W. Eaton <jwe@octave.org>
parents: 14846
diff changeset
507 {
18520
932aca9a7c57 Allow multi-level classdef package.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 18419
diff changeset
508 std::string class_nm = $1->text ();
932aca9a7c57 Allow multi-level classdef package.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 18419
diff changeset
509
18927
09eb8a2ddb02 eliminate some unused parameter warnings in parser functions
John W. Eaton <jwe@octave.org>
parents: 18537
diff changeset
510 $$ = parser.make_meta_class_query (class_nm);
15037
56b8eb7c9c04 improvements in parsing classdef
John W. Eaton <jwe@octave.org>
parents: 14846
diff changeset
511 }
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11572
diff changeset
512 ;
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
513
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
514 string : DQ_STRING
16288
fe3b9a51e625 rename curr_lexer, curr_parser, CURR_LEXER
John W. Eaton <jwe@octave.org>
parents: 16287
diff changeset
515 { $$ = parser.make_constant (DQ_STRING, $1); }
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
516 | SQ_STRING
16288
fe3b9a51e625 rename curr_lexer, curr_parser, CURR_LEXER
John W. Eaton <jwe@octave.org>
parents: 16287
diff changeset
517 { $$ = parser.make_constant (SQ_STRING, $1); }
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
518 ;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
519
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
520 constant : NUM
16288
fe3b9a51e625 rename curr_lexer, curr_parser, CURR_LEXER
John W. Eaton <jwe@octave.org>
parents: 16287
diff changeset
521 { $$ = parser.make_constant (NUM, $1); }
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
522 | IMAG_NUM
16288
fe3b9a51e625 rename curr_lexer, curr_parser, CURR_LEXER
John W. Eaton <jwe@octave.org>
parents: 16287
diff changeset
523 { $$ = parser.make_constant (IMAG_NUM, $1); }
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
524 | string
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
525 { $$ = $1; }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
526 ;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
527
16924
aebb54d99dba improve compatibility of parsing of matrices and cell arrays
John W. Eaton <jwe@octave.org>
parents: 16850
diff changeset
528 matrix : '[' matrix_rows ']'
16288
fe3b9a51e625 rename curr_lexer, curr_parser, CURR_LEXER
John W. Eaton <jwe@octave.org>
parents: 16287
diff changeset
529 { $$ = parser.finish_matrix ($2); }
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
530 ;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
531
16924
aebb54d99dba improve compatibility of parsing of matrices and cell arrays
John W. Eaton <jwe@octave.org>
parents: 16850
diff changeset
532 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
533 { $$ = $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
534 | matrix_rows ';' cell_or_matrix_row
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
535 {
16924
aebb54d99dba improve compatibility of parsing of matrices and cell arrays
John W. Eaton <jwe@octave.org>
parents: 16850
diff changeset
536 if ($1)
aebb54d99dba improve compatibility of parsing of matrices and cell arrays
John W. Eaton <jwe@octave.org>
parents: 16850
diff changeset
537 {
aebb54d99dba improve compatibility of parsing of matrices and cell arrays
John W. Eaton <jwe@octave.org>
parents: 16850
diff changeset
538 if ($3)
aebb54d99dba improve compatibility of parsing of matrices and cell arrays
John W. Eaton <jwe@octave.org>
parents: 16850
diff changeset
539 $1->append ($3);
aebb54d99dba improve compatibility of parsing of matrices and cell arrays
John W. Eaton <jwe@octave.org>
parents: 16850
diff changeset
540
aebb54d99dba improve compatibility of parsing of matrices and cell arrays
John W. Eaton <jwe@octave.org>
parents: 16850
diff changeset
541 $$ = $1;
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 else
aebb54d99dba improve compatibility of parsing of matrices and cell arrays
John W. Eaton <jwe@octave.org>
parents: 16850
diff changeset
544 $$ = $3 ? new tree_matrix ($3) : 0;
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
545 }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
546 ;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
547
16924
aebb54d99dba improve compatibility of parsing of matrices and cell arrays
John W. Eaton <jwe@octave.org>
parents: 16850
diff changeset
548 cell : '{' cell_rows '}'
16288
fe3b9a51e625 rename curr_lexer, curr_parser, CURR_LEXER
John W. Eaton <jwe@octave.org>
parents: 16287
diff changeset
549 { $$ = parser.finish_cell ($2); }
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
550 ;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
551
16924
aebb54d99dba improve compatibility of parsing of matrices and cell arrays
John W. Eaton <jwe@octave.org>
parents: 16850
diff changeset
552 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
553 { $$ = $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
554 | cell_rows ';' cell_or_matrix_row
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
555 {
16924
aebb54d99dba improve compatibility of parsing of matrices and cell arrays
John W. Eaton <jwe@octave.org>
parents: 16850
diff changeset
556 if ($1)
aebb54d99dba improve compatibility of parsing of matrices and cell arrays
John W. Eaton <jwe@octave.org>
parents: 16850
diff changeset
557 {
aebb54d99dba improve compatibility of parsing of matrices and cell arrays
John W. Eaton <jwe@octave.org>
parents: 16850
diff changeset
558 if ($3)
aebb54d99dba improve compatibility of parsing of matrices and cell arrays
John W. Eaton <jwe@octave.org>
parents: 16850
diff changeset
559 $1->append ($3);
aebb54d99dba improve compatibility of parsing of matrices and cell arrays
John W. Eaton <jwe@octave.org>
parents: 16850
diff changeset
560
aebb54d99dba improve compatibility of parsing of matrices and cell arrays
John W. Eaton <jwe@octave.org>
parents: 16850
diff changeset
561 $$ = $1;
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 else
aebb54d99dba improve compatibility of parsing of matrices and cell arrays
John W. Eaton <jwe@octave.org>
parents: 16850
diff changeset
564 $$ = $3 ? new tree_cell ($3) : 0;
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
565 }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
566 ;
3351
8623649c967c [project @ 1999-11-15 16:17:01 by jwe]
jwe
parents: 3347
diff changeset
567
16924
aebb54d99dba improve compatibility of parsing of matrices and cell arrays
John W. Eaton <jwe@octave.org>
parents: 16850
diff changeset
568 // 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
569 // 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
570
3351
8623649c967c [project @ 1999-11-15 16:17:01 by jwe]
jwe
parents: 3347
diff changeset
571 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
572 : // empty
aebb54d99dba improve compatibility of parsing of matrices and cell arrays
John W. Eaton <jwe@octave.org>
parents: 16850
diff changeset
573 { $$ = 0; }
aebb54d99dba improve compatibility of parsing of matrices and cell arrays
John W. Eaton <jwe@octave.org>
parents: 16850
diff changeset
574 | ','
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 | arg_list
16257
db7f07b22b9b 1/10 commits reworking the lexer
John W. Eaton <jwe@octave.org>
parents: 16251
diff changeset
577 { $$ = $1; }
16924
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
aebb54d99dba improve compatibility of parsing of matrices and cell arrays
John W. Eaton <jwe@octave.org>
parents: 16850
diff changeset
581 { $$ = $2; }
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; }
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
584 ;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
585
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
586 fcn_handle : '@' FCN_HANDLE
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
587 {
16288
fe3b9a51e625 rename curr_lexer, curr_parser, CURR_LEXER
John W. Eaton <jwe@octave.org>
parents: 16287
diff changeset
588 $$ = parser.make_fcn_handle ($2);
fe3b9a51e625 rename curr_lexer, curr_parser, CURR_LEXER
John W. Eaton <jwe@octave.org>
parents: 16287
diff changeset
589 lexer.looking_at_function_handle--;
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
590 }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
591 ;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
592
16681
d3619d4d267c recognize character string at beginning of statement (bug #38926, #38958)
John W. Eaton <jwe@octave.org>
parents: 16627
diff changeset
593 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
594 {
16681
d3619d4d267c recognize character string at beginning of statement (bug #38926, #38958)
John W. Eaton <jwe@octave.org>
parents: 16627
diff changeset
595 $$ = 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
596 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
597 }
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
598 ;
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11572
diff changeset
599
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
600 primary_expr : identifier
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
601 { $$ = $1; }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
602 | constant
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 | fcn_handle
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 | matrix
16257
db7f07b22b9b 1/10 commits reworking the lexer
John W. Eaton <jwe@octave.org>
parents: 16251
diff changeset
607 {
16288
fe3b9a51e625 rename curr_lexer, curr_parser, CURR_LEXER
John W. Eaton <jwe@octave.org>
parents: 16287
diff changeset
608 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
609 $$ = $1;
db7f07b22b9b 1/10 commits reworking the lexer
John W. Eaton <jwe@octave.org>
parents: 16251
diff changeset
610 }
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
611 | cell
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
612 { $$ = $1; }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
613 | meta_identifier
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 | superclass_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 | '(' expression ')'
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
618 { $$ = $2->mark_in_parens (); }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
619 ;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
620
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
621 magic_colon : ':'
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
622 {
19778
bf737d927707 eliminate bison warnings from oct-parse.yy
John W. Eaton <jwe@octave.org>
parents: 19709
diff changeset
623 YYUSE ($1);
bf737d927707 eliminate bison warnings from oct-parse.yy
John W. Eaton <jwe@octave.org>
parents: 19709
diff changeset
624
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
625 octave_value tmp (octave_value::magic_colon_t);
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
626 $$ = new tree_constant (tmp);
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
627 }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
628 ;
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 magic_tilde : EXPR_NOT
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
631 {
19778
bf737d927707 eliminate bison warnings from oct-parse.yy
John W. Eaton <jwe@octave.org>
parents: 19709
diff changeset
632 YYUSE ($1);
bf737d927707 eliminate bison warnings from oct-parse.yy
John W. Eaton <jwe@octave.org>
parents: 19709
diff changeset
633
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
634 $$ = new tree_black_hole ();
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
635 }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
636 ;
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 arg_list : expression
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
639 { $$ = new tree_argument_list ($1); }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
640 | magic_colon
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_tilde
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 | arg_list ',' magic_colon
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
645 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
646 $1->append ($3);
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
647 $$ = $1;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
648 }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
649 | arg_list ',' magic_tilde
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 $1->append ($3);
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
652 $$ = $1;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
653 }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
654 | arg_list ',' expression
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 $1->append ($3);
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
657 $$ = $1;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
658 }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
659 ;
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 indirect_ref_op : '.'
19778
bf737d927707 eliminate bison warnings from oct-parse.yy
John W. Eaton <jwe@octave.org>
parents: 19709
diff changeset
662 {
bf737d927707 eliminate bison warnings from oct-parse.yy
John W. Eaton <jwe@octave.org>
parents: 19709
diff changeset
663 $$ = 0;
bf737d927707 eliminate bison warnings from oct-parse.yy
John W. Eaton <jwe@octave.org>
parents: 19709
diff changeset
664 lexer.looking_at_indirect_ref = true;
bf737d927707 eliminate bison warnings from oct-parse.yy
John W. Eaton <jwe@octave.org>
parents: 19709
diff changeset
665 }
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
666 ;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
667
12627
002948ae5bc0 fix precedence level of transpose operators (bug #32533)
John W. Eaton <jwe@octave.org>
parents: 12483
diff changeset
668 oper_expr : primary_expr
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
669 { $$ = $1; }
12627
002948ae5bc0 fix precedence level of transpose operators (bug #32533)
John W. Eaton <jwe@octave.org>
parents: 12483
diff changeset
670 | oper_expr PLUS_PLUS
16288
fe3b9a51e625 rename curr_lexer, curr_parser, CURR_LEXER
John W. Eaton <jwe@octave.org>
parents: 16287
diff changeset
671 { $$ = 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
672 | oper_expr MINUS_MINUS
16288
fe3b9a51e625 rename curr_lexer, curr_parser, CURR_LEXER
John W. Eaton <jwe@octave.org>
parents: 16287
diff changeset
673 { $$ = 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
674 | oper_expr '(' ')'
16302
a4af67e0d22c oct-parse.in.yy: a{~}.b segfaults the interpreter (bug #37804)
Max Brister <max@2bass.com>
parents: 16294
diff changeset
675 {
a4af67e0d22c oct-parse.in.yy: a{~}.b segfaults the interpreter (bug #37804)
Max Brister <max@2bass.com>
parents: 16294
diff changeset
676 $$ = 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
677 if (! $$)
17632
bd0a84de3375 further reduce memory leaks from parse errors (bug #40231)
John W. Eaton <jwe@octave.org>
parents: 17629
diff changeset
678 {
bd0a84de3375 further reduce memory leaks from parse errors (bug #40231)
John W. Eaton <jwe@octave.org>
parents: 17629
diff changeset
679 // make_index_expression deleted $1.
21073
f7cc48f601d2 additional reworking of error handling in the parser (bug #46877)
John W. Eaton <jwe@octave.org>
parents: 21071
diff changeset
680 YYABORT;
17632
bd0a84de3375 further reduce memory leaks from parse errors (bug #40231)
John W. Eaton <jwe@octave.org>
parents: 17629
diff changeset
681 }
16302
a4af67e0d22c oct-parse.in.yy: a{~}.b segfaults the interpreter (bug #37804)
Max Brister <max@2bass.com>
parents: 16294
diff changeset
682 }
12627
002948ae5bc0 fix precedence level of transpose operators (bug #32533)
John W. Eaton <jwe@octave.org>
parents: 12483
diff changeset
683 | 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
684 {
a4af67e0d22c oct-parse.in.yy: a{~}.b segfaults the interpreter (bug #37804)
Max Brister <max@2bass.com>
parents: 16294
diff changeset
685 $$ = 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
686 if (! $$)
17632
bd0a84de3375 further reduce memory leaks from parse errors (bug #40231)
John W. Eaton <jwe@octave.org>
parents: 17629
diff changeset
687 {
bd0a84de3375 further reduce memory leaks from parse errors (bug #40231)
John W. Eaton <jwe@octave.org>
parents: 17629
diff changeset
688 // make_index_expression deleted $1 and $3.
21073
f7cc48f601d2 additional reworking of error handling in the parser (bug #46877)
John W. Eaton <jwe@octave.org>
parents: 21071
diff changeset
689 YYABORT;
17632
bd0a84de3375 further reduce memory leaks from parse errors (bug #40231)
John W. Eaton <jwe@octave.org>
parents: 17629
diff changeset
690 }
16302
a4af67e0d22c oct-parse.in.yy: a{~}.b segfaults the interpreter (bug #37804)
Max Brister <max@2bass.com>
parents: 16294
diff changeset
691 }
12627
002948ae5bc0 fix precedence level of transpose operators (bug #32533)
John W. Eaton <jwe@octave.org>
parents: 12483
diff changeset
692 | oper_expr '{' '}'
16302
a4af67e0d22c oct-parse.in.yy: a{~}.b segfaults the interpreter (bug #37804)
Max Brister <max@2bass.com>
parents: 16294
diff changeset
693 {
a4af67e0d22c oct-parse.in.yy: a{~}.b segfaults the interpreter (bug #37804)
Max Brister <max@2bass.com>
parents: 16294
diff changeset
694 $$ = 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
695 if (! $$)
17632
bd0a84de3375 further reduce memory leaks from parse errors (bug #40231)
John W. Eaton <jwe@octave.org>
parents: 17629
diff changeset
696 {
bd0a84de3375 further reduce memory leaks from parse errors (bug #40231)
John W. Eaton <jwe@octave.org>
parents: 17629
diff changeset
697 // make_index_expression deleted $1.
21073
f7cc48f601d2 additional reworking of error handling in the parser (bug #46877)
John W. Eaton <jwe@octave.org>
parents: 21071
diff changeset
698 YYABORT;
17632
bd0a84de3375 further reduce memory leaks from parse errors (bug #40231)
John W. Eaton <jwe@octave.org>
parents: 17629
diff changeset
699 }
16302
a4af67e0d22c oct-parse.in.yy: a{~}.b segfaults the interpreter (bug #37804)
Max Brister <max@2bass.com>
parents: 16294
diff changeset
700 }
12627
002948ae5bc0 fix precedence level of transpose operators (bug #32533)
John W. Eaton <jwe@octave.org>
parents: 12483
diff changeset
701 | 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
702 {
a4af67e0d22c oct-parse.in.yy: a{~}.b segfaults the interpreter (bug #37804)
Max Brister <max@2bass.com>
parents: 16294
diff changeset
703 $$ = 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
704 if (! $$)
17632
bd0a84de3375 further reduce memory leaks from parse errors (bug #40231)
John W. Eaton <jwe@octave.org>
parents: 17629
diff changeset
705 {
bd0a84de3375 further reduce memory leaks from parse errors (bug #40231)
John W. Eaton <jwe@octave.org>
parents: 17629
diff changeset
706 // make_index_expression deleted $1 and $3.
21073
f7cc48f601d2 additional reworking of error handling in the parser (bug #46877)
John W. Eaton <jwe@octave.org>
parents: 21071
diff changeset
707 YYABORT;
17632
bd0a84de3375 further reduce memory leaks from parse errors (bug #40231)
John W. Eaton <jwe@octave.org>
parents: 17629
diff changeset
708 }
16302
a4af67e0d22c oct-parse.in.yy: a{~}.b segfaults the interpreter (bug #37804)
Max Brister <max@2bass.com>
parents: 16294
diff changeset
709 }
16284
09881dab3aaf * lex.ll, oct-parse.in.yy (HERMITIAN): Rename token from QUOTE.
John W. Eaton <jwe@octave.org>
parents: 16279
diff changeset
710 | oper_expr HERMITIAN
16288
fe3b9a51e625 rename curr_lexer, curr_parser, CURR_LEXER
John W. Eaton <jwe@octave.org>
parents: 16287
diff changeset
711 { $$ = 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
712 | oper_expr TRANSPOSE
16288
fe3b9a51e625 rename curr_lexer, curr_parser, CURR_LEXER
John W. Eaton <jwe@octave.org>
parents: 16287
diff changeset
713 { $$ = 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
714 | 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
715 { $$ = 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
716 | 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
717 { $$ = 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
718 | 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
719 { $$ = 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
720 | 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
721 { $$ = 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
722 | 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
723 { $$ = 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
724 | '+' 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 ('+', $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); }
17622
fd712a12fe53 compatibility for power operator precedence and direction (bug #33304)
Axel Mathéi <axel.mathei@gmail.com>
parents: 17618
diff changeset
728 | oper_expr POW power_expr
16288
fe3b9a51e625 rename curr_lexer, curr_parser, CURR_LEXER
John W. Eaton <jwe@octave.org>
parents: 16287
diff changeset
729 { $$ = 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
730 | oper_expr EPOW 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 (EPOW, $1, $2, $3); }
12627
002948ae5bc0 fix precedence level of transpose operators (bug #32533)
John W. Eaton <jwe@octave.org>
parents: 12483
diff changeset
732 | oper_expr '+' oper_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 ('+', $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 EPLUS 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 EMINUS 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 EMUL 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 (EMUL, $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 EDIV 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 (EDIV, $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 LEFTDIV 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 (LEFTDIV, $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 ELEFTDIV 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 (ELEFTDIV, $1, $2, $3); }
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
752 ;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
753
17622
fd712a12fe53 compatibility for power operator precedence and direction (bug #33304)
Axel Mathéi <axel.mathei@gmail.com>
parents: 17618
diff changeset
754 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
755 { $$ = $1; }
fd712a12fe53 compatibility for power operator precedence and direction (bug #33304)
Axel Mathéi <axel.mathei@gmail.com>
parents: 17618
diff changeset
756 | 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
757 { $$ = 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
758 | 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
759 { $$ = 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
760 | power_expr '(' ')'
fd712a12fe53 compatibility for power operator precedence and direction (bug #33304)
Axel Mathéi <axel.mathei@gmail.com>
parents: 17618
diff changeset
761 {
fd712a12fe53 compatibility for power operator precedence and direction (bug #33304)
Axel Mathéi <axel.mathei@gmail.com>
parents: 17618
diff changeset
762 $$ = 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
763 if (! $$)
17632
bd0a84de3375 further reduce memory leaks from parse errors (bug #40231)
John W. Eaton <jwe@octave.org>
parents: 17629
diff changeset
764 {
bd0a84de3375 further reduce memory leaks from parse errors (bug #40231)
John W. Eaton <jwe@octave.org>
parents: 17629
diff changeset
765 // make_index_expression deleted $1.
21073
f7cc48f601d2 additional reworking of error handling in the parser (bug #46877)
John W. Eaton <jwe@octave.org>
parents: 21071
diff changeset
766 YYABORT;
17632
bd0a84de3375 further reduce memory leaks from parse errors (bug #40231)
John W. Eaton <jwe@octave.org>
parents: 17629
diff changeset
767 }
17622
fd712a12fe53 compatibility for power operator precedence and direction (bug #33304)
Axel Mathéi <axel.mathei@gmail.com>
parents: 17618
diff changeset
768 }
fd712a12fe53 compatibility for power operator precedence and direction (bug #33304)
Axel Mathéi <axel.mathei@gmail.com>
parents: 17618
diff changeset
769 | 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
770 {
fd712a12fe53 compatibility for power operator precedence and direction (bug #33304)
Axel Mathéi <axel.mathei@gmail.com>
parents: 17618
diff changeset
771 $$ = 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
772 if (! $$)
17632
bd0a84de3375 further reduce memory leaks from parse errors (bug #40231)
John W. Eaton <jwe@octave.org>
parents: 17629
diff changeset
773 {
bd0a84de3375 further reduce memory leaks from parse errors (bug #40231)
John W. Eaton <jwe@octave.org>
parents: 17629
diff changeset
774 // make_index_expression deleted $1 and $3.
21073
f7cc48f601d2 additional reworking of error handling in the parser (bug #46877)
John W. Eaton <jwe@octave.org>
parents: 21071
diff changeset
775 YYABORT;
17632
bd0a84de3375 further reduce memory leaks from parse errors (bug #40231)
John W. Eaton <jwe@octave.org>
parents: 17629
diff changeset
776 }
17622
fd712a12fe53 compatibility for power operator precedence and direction (bug #33304)
Axel Mathéi <axel.mathei@gmail.com>
parents: 17618
diff changeset
777 }
fd712a12fe53 compatibility for power operator precedence and direction (bug #33304)
Axel Mathéi <axel.mathei@gmail.com>
parents: 17618
diff changeset
778 | power_expr '{' '}'
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 $$ = 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
781 if (! $$)
17632
bd0a84de3375 further reduce memory leaks from parse errors (bug #40231)
John W. Eaton <jwe@octave.org>
parents: 17629
diff changeset
782 {
bd0a84de3375 further reduce memory leaks from parse errors (bug #40231)
John W. Eaton <jwe@octave.org>
parents: 17629
diff changeset
783 // make_index_expression deleted $1.
21073
f7cc48f601d2 additional reworking of error handling in the parser (bug #46877)
John W. Eaton <jwe@octave.org>
parents: 21071
diff changeset
784 YYABORT;
17632
bd0a84de3375 further reduce memory leaks from parse errors (bug #40231)
John W. Eaton <jwe@octave.org>
parents: 17629
diff changeset
785 }
17622
fd712a12fe53 compatibility for power operator precedence and direction (bug #33304)
Axel Mathéi <axel.mathei@gmail.com>
parents: 17618
diff changeset
786 }
fd712a12fe53 compatibility for power operator precedence and direction (bug #33304)
Axel Mathéi <axel.mathei@gmail.com>
parents: 17618
diff changeset
787 | 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
788 {
fd712a12fe53 compatibility for power operator precedence and direction (bug #33304)
Axel Mathéi <axel.mathei@gmail.com>
parents: 17618
diff changeset
789 $$ = 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
790 if (! $$)
17632
bd0a84de3375 further reduce memory leaks from parse errors (bug #40231)
John W. Eaton <jwe@octave.org>
parents: 17629
diff changeset
791 {
bd0a84de3375 further reduce memory leaks from parse errors (bug #40231)
John W. Eaton <jwe@octave.org>
parents: 17629
diff changeset
792 // make_index_expression deleted $1 and $3.
21073
f7cc48f601d2 additional reworking of error handling in the parser (bug #46877)
John W. Eaton <jwe@octave.org>
parents: 21071
diff changeset
793 YYABORT;
17632
bd0a84de3375 further reduce memory leaks from parse errors (bug #40231)
John W. Eaton <jwe@octave.org>
parents: 17629
diff changeset
794 }
17622
fd712a12fe53 compatibility for power operator precedence and direction (bug #33304)
Axel Mathéi <axel.mathei@gmail.com>
parents: 17618
diff changeset
795 }
fd712a12fe53 compatibility for power operator precedence and direction (bug #33304)
Axel Mathéi <axel.mathei@gmail.com>
parents: 17618
diff changeset
796 | 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
797 { $$ = 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
798 | 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
799 { $$ = 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
800 | 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
801 { $$ = 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
802 | 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
803 { $$ = 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
804 | 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
805 { $$ = 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
806 | '+' 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 ('+', $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 ;
fd712a12fe53 compatibility for power operator precedence and direction (bug #33304)
Axel Mathéi <axel.mathei@gmail.com>
parents: 17618
diff changeset
811
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
812 colon_expr : colon_expr1
16288
fe3b9a51e625 rename curr_lexer, curr_parser, CURR_LEXER
John W. Eaton <jwe@octave.org>
parents: 16287
diff changeset
813 { $$ = parser.finish_colon_expression ($1); }
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
814 ;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
815
12627
002948ae5bc0 fix precedence level of transpose operators (bug #32533)
John W. Eaton <jwe@octave.org>
parents: 12483
diff changeset
816 colon_expr1 : oper_expr
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
817 { $$ = 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
818 | colon_expr1 ':' oper_expr
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
819 {
19778
bf737d927707 eliminate bison warnings from oct-parse.yy
John W. Eaton <jwe@octave.org>
parents: 19709
diff changeset
820 YYUSE ($2);
bf737d927707 eliminate bison warnings from oct-parse.yy
John W. Eaton <jwe@octave.org>
parents: 19709
diff changeset
821
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
822 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
823 {
bd0a84de3375 further reduce memory leaks from parse errors (bug #40231)
John W. Eaton <jwe@octave.org>
parents: 17629
diff changeset
824 delete $1;
bd0a84de3375 further reduce memory leaks from parse errors (bug #40231)
John W. Eaton <jwe@octave.org>
parents: 17629
diff changeset
825 delete $3;
21073
f7cc48f601d2 additional reworking of error handling in the parser (bug #46877)
John W. Eaton <jwe@octave.org>
parents: 21071
diff changeset
826 YYABORT;
17632
bd0a84de3375 further reduce memory leaks from parse errors (bug #40231)
John W. Eaton <jwe@octave.org>
parents: 17629
diff changeset
827 }
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
828 }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
829 ;
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 simple_expr : colon_expr
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
832 { $$ = $1; }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
833 | 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
834 { $$ = 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
835 | 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
836 { $$ = 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
837 | 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
838 { $$ = 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
839 | 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
840 { $$ = 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
841 | 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
842 { $$ = 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
843 | 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
844 { $$ = 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
845 | 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
846 { $$ = 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
847 | 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
848 { $$ = 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
849 | 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
850 { $$ = 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
851 | 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
852 { $$ = 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
853 ;
2970
b9e64477f703 [project @ 1997-05-15 18:04:21 by jwe]
jwe
parents: 2961
diff changeset
854
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
855 assign_lhs : simple_expr
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
856 {
16288
fe3b9a51e625 rename curr_lexer, curr_parser, CURR_LEXER
John W. Eaton <jwe@octave.org>
parents: 16287
diff changeset
857 $$ = parser.validate_matrix_for_assignment ($1);
16273
c5e5f6ccac5d 9/10 commits reworking the lexer
John W. Eaton <jwe@octave.org>
parents: 16265
diff changeset
858
c5e5f6ccac5d 9/10 commits reworking the lexer
John W. Eaton <jwe@octave.org>
parents: 16265
diff changeset
859 if ($$)
16288
fe3b9a51e625 rename curr_lexer, curr_parser, CURR_LEXER
John W. Eaton <jwe@octave.org>
parents: 16287
diff changeset
860 { 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
861 else
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
862 {
16277
8cb65fd72164 eliminate obsolete concepts of "pending local" and "forced" variables
John W. Eaton <jwe@octave.org>
parents: 16273
diff changeset
863 // validate_matrix_for_assignment deleted $1.
21073
f7cc48f601d2 additional reworking of error handling in the parser (bug #46877)
John W. Eaton <jwe@octave.org>
parents: 21071
diff changeset
864 YYABORT;
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
865 }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
866 }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
867 ;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
868
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
869 assign_expr : assign_lhs '=' expression
16288
fe3b9a51e625 rename curr_lexer, curr_parser, CURR_LEXER
John W. Eaton <jwe@octave.org>
parents: 16287
diff changeset
870 { $$ = parser.make_assign_op ('=', $1, $2, $3); }
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
871 | assign_lhs ADD_EQ expression
16288
fe3b9a51e625 rename curr_lexer, curr_parser, CURR_LEXER
John W. Eaton <jwe@octave.org>
parents: 16287
diff changeset
872 { $$ = 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
873 | assign_lhs SUB_EQ expression
16288
fe3b9a51e625 rename curr_lexer, curr_parser, CURR_LEXER
John W. Eaton <jwe@octave.org>
parents: 16287
diff changeset
874 { $$ = 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
875 | assign_lhs MUL_EQ 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 (MUL_EQ, $1, $2, $3); }
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
877 | assign_lhs DIV_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 (DIV_EQ, $1, $2, $3); }
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
879 | assign_lhs LEFTDIV_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 (LEFTDIV_EQ, $1, $2, $3); }
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
881 | assign_lhs POW_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 (POW_EQ, $1, $2, $3); }
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
883 | assign_lhs EMUL_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 (EMUL_EQ, $1, $2, $3); }
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
885 | assign_lhs EDIV_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 (EDIV_EQ, $1, $2, $3); }
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
887 | assign_lhs ELEFTDIV_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 (ELEFTDIV_EQ, $1, $2, $3); }
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
889 | assign_lhs EPOW_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 (EPOW_EQ, $1, $2, $3); }
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
891 | assign_lhs AND_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 (AND_EQ, $1, $2, $3); }
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
893 | assign_lhs OR_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 (OR_EQ, $1, $2, $3); }
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
895 ;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
896
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
897 expression : simple_expr
16273
c5e5f6ccac5d 9/10 commits reworking the lexer
John W. Eaton <jwe@octave.org>
parents: 16265
diff changeset
898 {
c5e5f6ccac5d 9/10 commits reworking the lexer
John W. Eaton <jwe@octave.org>
parents: 16265
diff changeset
899 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
900 {
16288
fe3b9a51e625 rename curr_lexer, curr_parser, CURR_LEXER
John W. Eaton <jwe@octave.org>
parents: 16287
diff changeset
901 if (parser.validate_array_list ($1))
16273
c5e5f6ccac5d 9/10 commits reworking the lexer
John W. Eaton <jwe@octave.org>
parents: 16265
diff changeset
902 $$ = $1;
c5e5f6ccac5d 9/10 commits reworking the lexer
John W. Eaton <jwe@octave.org>
parents: 16265
diff changeset
903 else
c5e5f6ccac5d 9/10 commits reworking the lexer
John W. Eaton <jwe@octave.org>
parents: 16265
diff changeset
904 {
c5e5f6ccac5d 9/10 commits reworking the lexer
John W. Eaton <jwe@octave.org>
parents: 16265
diff changeset
905 delete $1;
21073
f7cc48f601d2 additional reworking of error handling in the parser (bug #46877)
John W. Eaton <jwe@octave.org>
parents: 21071
diff changeset
906 YYABORT;
16273
c5e5f6ccac5d 9/10 commits reworking the lexer
John W. Eaton <jwe@octave.org>
parents: 16265
diff changeset
907 }
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 else
c5e5f6ccac5d 9/10 commits reworking the lexer
John W. Eaton <jwe@octave.org>
parents: 16265
diff changeset
910 $$ = $1;
c5e5f6ccac5d 9/10 commits reworking the lexer
John W. Eaton <jwe@octave.org>
parents: 16265
diff changeset
911 }
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
912 | assign_expr
21073
f7cc48f601d2 additional reworking of error handling in the parser (bug #46877)
John W. Eaton <jwe@octave.org>
parents: 21071
diff changeset
913 {
f7cc48f601d2 additional reworking of error handling in the parser (bug #46877)
John W. Eaton <jwe@octave.org>
parents: 21071
diff changeset
914 if (! $1)
f7cc48f601d2 additional reworking of error handling in the parser (bug #46877)
John W. Eaton <jwe@octave.org>
parents: 21071
diff changeset
915 YYABORT;
f7cc48f601d2 additional reworking of error handling in the parser (bug #46877)
John W. Eaton <jwe@octave.org>
parents: 21071
diff changeset
916
f7cc48f601d2 additional reworking of error handling in the parser (bug #46877)
John W. Eaton <jwe@octave.org>
parents: 21071
diff changeset
917 $$ = $1;
f7cc48f601d2 additional reworking of error handling in the parser (bug #46877)
John W. Eaton <jwe@octave.org>
parents: 21071
diff changeset
918 }
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
919 | anon_fcn_handle
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
920 { $$ = $1; }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
921 ;
2970
b9e64477f703 [project @ 1997-05-15 18:04:21 by jwe]
jwe
parents: 2961
diff changeset
922
b9e64477f703 [project @ 1997-05-15 18:04:21 by jwe]
jwe
parents: 2961
diff changeset
923 // ================================================
b9e64477f703 [project @ 1997-05-15 18:04:21 by jwe]
jwe
parents: 2961
diff changeset
924 // Commands, declarations, and function definitions
b9e64477f703 [project @ 1997-05-15 18:04:21 by jwe]
jwe
parents: 2961
diff changeset
925 // ================================================
b9e64477f703 [project @ 1997-05-15 18:04:21 by jwe]
jwe
parents: 2961
diff changeset
926
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
927 command : declaration
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
928 { $$ = $1; }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
929 | select_command
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
930 { $$ = $1; }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
931 | loop_command
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
932 { $$ = $1; }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
933 | jump_command
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
934 { $$ = $1; }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
935 | except_command
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
936 { $$ = $1; }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
937 | function
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
938 { $$ = $1; }
16203
127cccb037bf move more global parser and lexer variables to classes
John W. Eaton <jwe@octave.org>
parents: 16199
diff changeset
939 | file
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
940 { $$ = $1; }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
941 ;
2970
b9e64477f703 [project @ 1997-05-15 18:04:21 by jwe]
jwe
parents: 2961
diff changeset
942
b9e64477f703 [project @ 1997-05-15 18:04:21 by jwe]
jwe
parents: 2961
diff changeset
943 // =====================
b9e64477f703 [project @ 1997-05-15 18:04:21 by jwe]
jwe
parents: 2961
diff changeset
944 // Declaration statemnts
b9e64477f703 [project @ 1997-05-15 18:04:21 by jwe]
jwe
parents: 2961
diff changeset
945 // =====================
b9e64477f703 [project @ 1997-05-15 18:04:21 by jwe]
jwe
parents: 2961
diff changeset
946
16263
9acb86e6ac90 4/10 commits reworking the lexer
John W. Eaton <jwe@octave.org>
parents: 16259
diff changeset
947 declaration : GLOBAL decl1
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
948 {
16288
fe3b9a51e625 rename curr_lexer, curr_parser, CURR_LEXER
John W. Eaton <jwe@octave.org>
parents: 16287
diff changeset
949 $$ = 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
950 lexer.looking_at_decl_list = false;
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
951 }
16263
9acb86e6ac90 4/10 commits reworking the lexer
John W. Eaton <jwe@octave.org>
parents: 16259
diff changeset
952 | PERSISTENT 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 (PERSISTENT, $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 }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
957 ;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
958
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
959 decl1 : decl2
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
960 { $$ = new tree_decl_init_list ($1); }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
961 | decl1 decl2
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 $1->append ($2);
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
964 $$ = $1;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
965 }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
966 ;
2970
b9e64477f703 [project @ 1997-05-15 18:04:21 by jwe]
jwe
parents: 2961
diff changeset
967
7634
ae90e05ad299 fix parameter list initializer bug
John W. Eaton <jwe@octave.org>
parents: 7587
diff changeset
968 decl_param_init : // empty
19778
bf737d927707 eliminate bison warnings from oct-parse.yy
John W. Eaton <jwe@octave.org>
parents: 19709
diff changeset
969 {
bf737d927707 eliminate bison warnings from oct-parse.yy
John W. Eaton <jwe@octave.org>
parents: 19709
diff changeset
970 $$ = 0;
bf737d927707 eliminate bison warnings from oct-parse.yy
John W. Eaton <jwe@octave.org>
parents: 19709
diff changeset
971 lexer.looking_at_initializer_expression = true;
bf737d927707 eliminate bison warnings from oct-parse.yy
John W. Eaton <jwe@octave.org>
parents: 19709
diff changeset
972 }
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
973
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
974 decl2 : identifier
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
975 { $$ = new tree_decl_elt ($1); }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
976 | identifier '=' decl_param_init expression
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
977 {
19778
bf737d927707 eliminate bison warnings from oct-parse.yy
John W. Eaton <jwe@octave.org>
parents: 19709
diff changeset
978 YYUSE ($2);
bf737d927707 eliminate bison warnings from oct-parse.yy
John W. Eaton <jwe@octave.org>
parents: 19709
diff changeset
979
16288
fe3b9a51e625 rename curr_lexer, curr_parser, CURR_LEXER
John W. Eaton <jwe@octave.org>
parents: 16287
diff changeset
980 lexer.looking_at_initializer_expression = false;
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
981 $$ = new tree_decl_elt ($1, $4);
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
982 }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
983 ;
2970
b9e64477f703 [project @ 1997-05-15 18:04:21 by jwe]
jwe
parents: 2961
diff changeset
984
b9e64477f703 [project @ 1997-05-15 18:04:21 by jwe]
jwe
parents: 2961
diff changeset
985 // ====================
b9e64477f703 [project @ 1997-05-15 18:04:21 by jwe]
jwe
parents: 2961
diff changeset
986 // Selection statements
b9e64477f703 [project @ 1997-05-15 18:04:21 by jwe]
jwe
parents: 2961
diff changeset
987 // ====================
b9e64477f703 [project @ 1997-05-15 18:04:21 by jwe]
jwe
parents: 2961
diff changeset
988
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
989 select_command : if_command
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
990 { $$ = $1; }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
991 | switch_command
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
992 { $$ = $1; }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
993 ;
2970
b9e64477f703 [project @ 1997-05-15 18:04:21 by jwe]
jwe
parents: 2961
diff changeset
994
b9e64477f703 [project @ 1997-05-15 18:04:21 by jwe]
jwe
parents: 2961
diff changeset
995 // ============
b9e64477f703 [project @ 1997-05-15 18:04:21 by jwe]
jwe
parents: 2961
diff changeset
996 // If statement
b9e64477f703 [project @ 1997-05-15 18:04:21 by jwe]
jwe
parents: 2961
diff changeset
997 // ============
b9e64477f703 [project @ 1997-05-15 18:04:21 by jwe]
jwe
parents: 2961
diff changeset
998
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
999 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
1000 {
16288
fe3b9a51e625 rename curr_lexer, curr_parser, CURR_LEXER
John W. Eaton <jwe@octave.org>
parents: 16287
diff changeset
1001 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
1002 {
bd0a84de3375 further reduce memory leaks from parse errors (bug #40231)
John W. Eaton <jwe@octave.org>
parents: 17629
diff changeset
1003 // finish_if_command deleted $3.
21073
f7cc48f601d2 additional reworking of error handling in the parser (bug #46877)
John W. Eaton <jwe@octave.org>
parents: 21071
diff changeset
1004 YYABORT;
17632
bd0a84de3375 further reduce memory leaks from parse errors (bug #40231)
John W. Eaton <jwe@octave.org>
parents: 17629
diff changeset
1005 }
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
1006 }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
1007 ;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
1008
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
1009 if_cmd_list : if_cmd_list1
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
1010 { $$ = $1; }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
1011 | if_cmd_list1 else_clause
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 $1->append ($2);
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
1014 $$ = $1;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
1015 }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
1016 ;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
1017
16681
d3619d4d267c recognize character string at beginning of statement (bug #38926, #38958)
John W. Eaton <jwe@octave.org>
parents: 16627
diff changeset
1018 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
1019 {
19778
bf737d927707 eliminate bison warnings from oct-parse.yy
John W. Eaton <jwe@octave.org>
parents: 19709
diff changeset
1020 YYUSE ($3);
bf737d927707 eliminate bison warnings from oct-parse.yy
John W. Eaton <jwe@octave.org>
parents: 19709
diff changeset
1021
18127
d76f790b4eec enable do_braindead_shortcircuit_evaluation by default and deprecate
John W. Eaton <jwe@octave.org>
parents: 17796
diff changeset
1022 $1->mark_braindead_shortcircuit ();
16288
fe3b9a51e625 rename curr_lexer, curr_parser, CURR_LEXER
John W. Eaton <jwe@octave.org>
parents: 16287
diff changeset
1023
16681
d3619d4d267c recognize character string at beginning of statement (bug #38926, #38958)
John W. Eaton <jwe@octave.org>
parents: 16627
diff changeset
1024 $$ = 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
1025 }
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
1026 | if_cmd_list1 elseif_clause
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
1027 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
1028 $1->append ($2);
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
1029 $$ = $1;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
1030 }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
1031 ;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
1032
16681
d3619d4d267c recognize character string at beginning of statement (bug #38926, #38958)
John W. Eaton <jwe@octave.org>
parents: 16627
diff changeset
1033 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
1034 {
19778
bf737d927707 eliminate bison warnings from oct-parse.yy
John W. Eaton <jwe@octave.org>
parents: 19709
diff changeset
1035 YYUSE ($3);
bf737d927707 eliminate bison warnings from oct-parse.yy
John W. Eaton <jwe@octave.org>
parents: 19709
diff changeset
1036 YYUSE ($6);
bf737d927707 eliminate bison warnings from oct-parse.yy
John W. Eaton <jwe@octave.org>
parents: 19709
diff changeset
1037
18127
d76f790b4eec enable do_braindead_shortcircuit_evaluation by default and deprecate
John W. Eaton <jwe@octave.org>
parents: 17796
diff changeset
1038 $4->mark_braindead_shortcircuit ();
16288
fe3b9a51e625 rename curr_lexer, curr_parser, CURR_LEXER
John W. Eaton <jwe@octave.org>
parents: 16287
diff changeset
1039
16681
d3619d4d267c recognize character string at beginning of statement (bug #38926, #38958)
John W. Eaton <jwe@octave.org>
parents: 16627
diff changeset
1040 $$ = 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
1041 }
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
1042 ;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
1043
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
1044 else_clause : ELSE stash_comment opt_sep opt_list
19778
bf737d927707 eliminate bison warnings from oct-parse.yy
John W. Eaton <jwe@octave.org>
parents: 19709
diff changeset
1045 {
bf737d927707 eliminate bison warnings from oct-parse.yy
John W. Eaton <jwe@octave.org>
parents: 19709
diff changeset
1046 YYUSE ($1);
bf737d927707 eliminate bison warnings from oct-parse.yy
John W. Eaton <jwe@octave.org>
parents: 19709
diff changeset
1047 YYUSE ($3);
bf737d927707 eliminate bison warnings from oct-parse.yy
John W. Eaton <jwe@octave.org>
parents: 19709
diff changeset
1048
bf737d927707 eliminate bison warnings from oct-parse.yy
John W. Eaton <jwe@octave.org>
parents: 19709
diff changeset
1049 $$ = new tree_if_clause ($4, $2);
bf737d927707 eliminate bison warnings from oct-parse.yy
John W. Eaton <jwe@octave.org>
parents: 19709
diff changeset
1050 }
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
1051 ;
2970
b9e64477f703 [project @ 1997-05-15 18:04:21 by jwe]
jwe
parents: 2961
diff changeset
1052
b9e64477f703 [project @ 1997-05-15 18:04:21 by jwe]
jwe
parents: 2961
diff changeset
1053 // ================
b9e64477f703 [project @ 1997-05-15 18:04:21 by jwe]
jwe
parents: 2961
diff changeset
1054 // Switch statement
b9e64477f703 [project @ 1997-05-15 18:04:21 by jwe]
jwe
parents: 2961
diff changeset
1055 // ================
b9e64477f703 [project @ 1997-05-15 18:04:21 by jwe]
jwe
parents: 2961
diff changeset
1056
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
1057 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
1058 {
19778
bf737d927707 eliminate bison warnings from oct-parse.yy
John W. Eaton <jwe@octave.org>
parents: 19709
diff changeset
1059 YYUSE ($4);
bf737d927707 eliminate bison warnings from oct-parse.yy
John W. Eaton <jwe@octave.org>
parents: 19709
diff changeset
1060
16288
fe3b9a51e625 rename curr_lexer, curr_parser, CURR_LEXER
John W. Eaton <jwe@octave.org>
parents: 16287
diff changeset
1061 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
1062 {
bd0a84de3375 further reduce memory leaks from parse errors (bug #40231)
John W. Eaton <jwe@octave.org>
parents: 17629
diff changeset
1063 // finish_switch_command deleted $3 adn $5.
21073
f7cc48f601d2 additional reworking of error handling in the parser (bug #46877)
John W. Eaton <jwe@octave.org>
parents: 21071
diff changeset
1064 YYABORT;
17632
bd0a84de3375 further reduce memory leaks from parse errors (bug #40231)
John W. Eaton <jwe@octave.org>
parents: 17629
diff changeset
1065 }
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
1066 }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
1067 ;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
1068
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
1069 case_list : // empty
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
1070 { $$ = 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
1071 | default_case
2da532d0f41c accept otherwise clause in switch statement without preceding case statements
John W. Eaton <jwe@octave.org>
parents: 11258
diff changeset
1072 { $$ = new tree_switch_case_list ($1); }
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
1073 | case_list1
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
1074 { $$ = $1; }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
1075 | case_list1 default_case
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
1076 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
1077 $1->append ($2);
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
1078 $$ = $1;
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11572
diff changeset
1079 }
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
1080 ;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
1081
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
1082 case_list1 : switch_case
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
1083 { $$ = new tree_switch_case_list ($1); }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
1084 | case_list1 switch_case
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 $1->append ($2);
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
1087 $$ = $1;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
1088 }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
1089 ;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
1090
16681
d3619d4d267c recognize character string at beginning of statement (bug #38926, #38958)
John W. Eaton <jwe@octave.org>
parents: 16627
diff changeset
1091 switch_case : CASE stash_comment opt_sep expression stmt_begin opt_sep opt_list
19778
bf737d927707 eliminate bison warnings from oct-parse.yy
John W. Eaton <jwe@octave.org>
parents: 19709
diff changeset
1092 {
bf737d927707 eliminate bison warnings from oct-parse.yy
John W. Eaton <jwe@octave.org>
parents: 19709
diff changeset
1093 YYUSE ($3);
bf737d927707 eliminate bison warnings from oct-parse.yy
John W. Eaton <jwe@octave.org>
parents: 19709
diff changeset
1094 YYUSE ($6);
bf737d927707 eliminate bison warnings from oct-parse.yy
John W. Eaton <jwe@octave.org>
parents: 19709
diff changeset
1095
bf737d927707 eliminate bison warnings from oct-parse.yy
John W. Eaton <jwe@octave.org>
parents: 19709
diff changeset
1096 $$ = parser.make_switch_case ($1, $4, $7, $2);
bf737d927707 eliminate bison warnings from oct-parse.yy
John W. Eaton <jwe@octave.org>
parents: 19709
diff changeset
1097 }
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
1098 ;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
1099
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
1100 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
1101 {
19778
bf737d927707 eliminate bison warnings from oct-parse.yy
John W. Eaton <jwe@octave.org>
parents: 19709
diff changeset
1102 YYUSE ($1);
bf737d927707 eliminate bison warnings from oct-parse.yy
John W. Eaton <jwe@octave.org>
parents: 19709
diff changeset
1103 YYUSE ($3);
bf737d927707 eliminate bison warnings from oct-parse.yy
John W. Eaton <jwe@octave.org>
parents: 19709
diff changeset
1104
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
1105 $$ = new tree_switch_case ($4, $2);
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
1106 }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
1107 ;
2970
b9e64477f703 [project @ 1997-05-15 18:04:21 by jwe]
jwe
parents: 2961
diff changeset
1108
b9e64477f703 [project @ 1997-05-15 18:04:21 by jwe]
jwe
parents: 2961
diff changeset
1109 // =======
b9e64477f703 [project @ 1997-05-15 18:04:21 by jwe]
jwe
parents: 2961
diff changeset
1110 // Looping
b9e64477f703 [project @ 1997-05-15 18:04:21 by jwe]
jwe
parents: 2961
diff changeset
1111 // =======
b9e64477f703 [project @ 1997-05-15 18:04:21 by jwe]
jwe
parents: 2961
diff changeset
1112
16681
d3619d4d267c recognize character string at beginning of statement (bug #38926, #38958)
John W. Eaton <jwe@octave.org>
parents: 16627
diff changeset
1113 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
1114 {
19778
bf737d927707 eliminate bison warnings from oct-parse.yy
John W. Eaton <jwe@octave.org>
parents: 19709
diff changeset
1115 YYUSE ($5);
bf737d927707 eliminate bison warnings from oct-parse.yy
John W. Eaton <jwe@octave.org>
parents: 19709
diff changeset
1116
18127
d76f790b4eec enable do_braindead_shortcircuit_evaluation by default and deprecate
John W. Eaton <jwe@octave.org>
parents: 17796
diff changeset
1117 $3->mark_braindead_shortcircuit ();
16288
fe3b9a51e625 rename curr_lexer, curr_parser, CURR_LEXER
John W. Eaton <jwe@octave.org>
parents: 16287
diff changeset
1118
16681
d3619d4d267c recognize character string at beginning of statement (bug #38926, #38958)
John W. Eaton <jwe@octave.org>
parents: 16627
diff changeset
1119 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
1120 {
bd0a84de3375 further reduce memory leaks from parse errors (bug #40231)
John W. Eaton <jwe@octave.org>
parents: 17629
diff changeset
1121 // make_while_command deleted $3 and $6.
21073
f7cc48f601d2 additional reworking of error handling in the parser (bug #46877)
John W. Eaton <jwe@octave.org>
parents: 21071
diff changeset
1122 YYABORT;
17632
bd0a84de3375 further reduce memory leaks from parse errors (bug #40231)
John W. Eaton <jwe@octave.org>
parents: 17629
diff changeset
1123 }
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
1124 }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
1125 | 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
1126 {
19778
bf737d927707 eliminate bison warnings from oct-parse.yy
John W. Eaton <jwe@octave.org>
parents: 19709
diff changeset
1127 YYUSE ($1);
bf737d927707 eliminate bison warnings from oct-parse.yy
John W. Eaton <jwe@octave.org>
parents: 19709
diff changeset
1128 YYUSE ($3);
bf737d927707 eliminate bison warnings from oct-parse.yy
John W. Eaton <jwe@octave.org>
parents: 19709
diff changeset
1129
17632
bd0a84de3375 further reduce memory leaks from parse errors (bug #40231)
John W. Eaton <jwe@octave.org>
parents: 17629
diff changeset
1130 $$ = 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
1131 }
16681
d3619d4d267c recognize character string at beginning of statement (bug #38926, #38958)
John W. Eaton <jwe@octave.org>
parents: 16627
diff changeset
1132 | 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
1133 {
19778
bf737d927707 eliminate bison warnings from oct-parse.yy
John W. Eaton <jwe@octave.org>
parents: 19709
diff changeset
1134 YYUSE ($4);
bf737d927707 eliminate bison warnings from oct-parse.yy
John W. Eaton <jwe@octave.org>
parents: 19709
diff changeset
1135 YYUSE ($7);
bf737d927707 eliminate bison warnings from oct-parse.yy
John W. Eaton <jwe@octave.org>
parents: 19709
diff changeset
1136
16288
fe3b9a51e625 rename curr_lexer, curr_parser, CURR_LEXER
John W. Eaton <jwe@octave.org>
parents: 16287
diff changeset
1137 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
1138 $8, $9, $2)))
bd0a84de3375 further reduce memory leaks from parse errors (bug #40231)
John W. Eaton <jwe@octave.org>
parents: 17629
diff changeset
1139 {
bd0a84de3375 further reduce memory leaks from parse errors (bug #40231)
John W. Eaton <jwe@octave.org>
parents: 17629
diff changeset
1140 // make_for_command deleted $3, $5, and $8.
21073
f7cc48f601d2 additional reworking of error handling in the parser (bug #46877)
John W. Eaton <jwe@octave.org>
parents: 21071
diff changeset
1141 YYABORT;
17632
bd0a84de3375 further reduce memory leaks from parse errors (bug #40231)
John W. Eaton <jwe@octave.org>
parents: 17629
diff changeset
1142 }
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
1143 }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
1144 | 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
1145 {
19778
bf737d927707 eliminate bison warnings from oct-parse.yy
John W. Eaton <jwe@octave.org>
parents: 19709
diff changeset
1146 YYUSE ($5);
bf737d927707 eliminate bison warnings from oct-parse.yy
John W. Eaton <jwe@octave.org>
parents: 19709
diff changeset
1147 YYUSE ($8);
bf737d927707 eliminate bison warnings from oct-parse.yy
John W. Eaton <jwe@octave.org>
parents: 19709
diff changeset
1148
16288
fe3b9a51e625 rename curr_lexer, curr_parser, CURR_LEXER
John W. Eaton <jwe@octave.org>
parents: 16287
diff changeset
1149 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
1150 $9, $10, $2)))
bd0a84de3375 further reduce memory leaks from parse errors (bug #40231)
John W. Eaton <jwe@octave.org>
parents: 17629
diff changeset
1151 {
bd0a84de3375 further reduce memory leaks from parse errors (bug #40231)
John W. Eaton <jwe@octave.org>
parents: 17629
diff changeset
1152 // make_for_command deleted $4, $6, and $9.
21073
f7cc48f601d2 additional reworking of error handling in the parser (bug #46877)
John W. Eaton <jwe@octave.org>
parents: 21071
diff changeset
1153 YYABORT;
17632
bd0a84de3375 further reduce memory leaks from parse errors (bug #40231)
John W. Eaton <jwe@octave.org>
parents: 17629
diff changeset
1154 }
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
1155 }
16681
d3619d4d267c recognize character string at beginning of statement (bug #38926, #38958)
John W. Eaton <jwe@octave.org>
parents: 16627
diff changeset
1156 | 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
1157 {
19778
bf737d927707 eliminate bison warnings from oct-parse.yy
John W. Eaton <jwe@octave.org>
parents: 19709
diff changeset
1158 YYUSE ($4);
bf737d927707 eliminate bison warnings from oct-parse.yy
John W. Eaton <jwe@octave.org>
parents: 19709
diff changeset
1159 YYUSE ($7);
bf737d927707 eliminate bison warnings from oct-parse.yy
John W. Eaton <jwe@octave.org>
parents: 19709
diff changeset
1160
16288
fe3b9a51e625 rename curr_lexer, curr_parser, CURR_LEXER
John W. Eaton <jwe@octave.org>
parents: 16287
diff changeset
1161 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
1162 0, $8, $9, $2)))
bd0a84de3375 further reduce memory leaks from parse errors (bug #40231)
John W. Eaton <jwe@octave.org>
parents: 17629
diff changeset
1163 {
bd0a84de3375 further reduce memory leaks from parse errors (bug #40231)
John W. Eaton <jwe@octave.org>
parents: 17629
diff changeset
1164 // make_for_command deleted $3, $5, and $8.
21073
f7cc48f601d2 additional reworking of error handling in the parser (bug #46877)
John W. Eaton <jwe@octave.org>
parents: 21071
diff changeset
1165 YYABORT;
17632
bd0a84de3375 further reduce memory leaks from parse errors (bug #40231)
John W. Eaton <jwe@octave.org>
parents: 17629
diff changeset
1166 }
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
1167 }
027a2186cd90 parfor keyword and infrastructure, but handle parfor as normal for loop for now
John W. Eaton <jwe@octave.org>
parents: 13241
diff changeset
1168 | 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
1169 {
19778
bf737d927707 eliminate bison warnings from oct-parse.yy
John W. Eaton <jwe@octave.org>
parents: 19709
diff changeset
1170 YYUSE ($5);
bf737d927707 eliminate bison warnings from oct-parse.yy
John W. Eaton <jwe@octave.org>
parents: 19709
diff changeset
1171 YYUSE ($10);
bf737d927707 eliminate bison warnings from oct-parse.yy
John W. Eaton <jwe@octave.org>
parents: 19709
diff changeset
1172
16288
fe3b9a51e625 rename curr_lexer, curr_parser, CURR_LEXER
John W. Eaton <jwe@octave.org>
parents: 16287
diff changeset
1173 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
1174 $8, $11, $12, $2)))
bd0a84de3375 further reduce memory leaks from parse errors (bug #40231)
John W. Eaton <jwe@octave.org>
parents: 17629
diff changeset
1175 {
bd0a84de3375 further reduce memory leaks from parse errors (bug #40231)
John W. Eaton <jwe@octave.org>
parents: 17629
diff changeset
1176 // make_for_command deleted $4, $6, $8, and $11.
21073
f7cc48f601d2 additional reworking of error handling in the parser (bug #46877)
John W. Eaton <jwe@octave.org>
parents: 21071
diff changeset
1177 YYABORT;
17632
bd0a84de3375 further reduce memory leaks from parse errors (bug #40231)
John W. Eaton <jwe@octave.org>
parents: 17629
diff changeset
1178 }
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
1179 }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
1180 ;
2970
b9e64477f703 [project @ 1997-05-15 18:04:21 by jwe]
jwe
parents: 2961
diff changeset
1181
b9e64477f703 [project @ 1997-05-15 18:04:21 by jwe]
jwe
parents: 2961
diff changeset
1182 // =======
b9e64477f703 [project @ 1997-05-15 18:04:21 by jwe]
jwe
parents: 2961
diff changeset
1183 // Jumping
b9e64477f703 [project @ 1997-05-15 18:04:21 by jwe]
jwe
parents: 2961
diff changeset
1184 // =======
b9e64477f703 [project @ 1997-05-15 18:04:21 by jwe]
jwe
parents: 2961
diff changeset
1185
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
1186 jump_command : BREAK
17632
bd0a84de3375 further reduce memory leaks from parse errors (bug #40231)
John W. Eaton <jwe@octave.org>
parents: 17629
diff changeset
1187 { $$ = parser.make_break_command ($1); }
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
1188 | CONTINUE
17632
bd0a84de3375 further reduce memory leaks from parse errors (bug #40231)
John W. Eaton <jwe@octave.org>
parents: 17629
diff changeset
1189 { $$ = parser.make_continue_command ($1); }
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
1190 | FUNC_RET
17632
bd0a84de3375 further reduce memory leaks from parse errors (bug #40231)
John W. Eaton <jwe@octave.org>
parents: 17629
diff changeset
1191 { $$ = parser.make_return_command ($1); }
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
1192 ;
2970
b9e64477f703 [project @ 1997-05-15 18:04:21 by jwe]
jwe
parents: 2961
diff changeset
1193
b9e64477f703 [project @ 1997-05-15 18:04:21 by jwe]
jwe
parents: 2961
diff changeset
1194 // ==========
b9e64477f703 [project @ 1997-05-15 18:04:21 by jwe]
jwe
parents: 2961
diff changeset
1195 // Exceptions
b9e64477f703 [project @ 1997-05-15 18:04:21 by jwe]
jwe
parents: 2961
diff changeset
1196 // ==========
b9e64477f703 [project @ 1997-05-15 18:04:21 by jwe]
jwe
parents: 2961
diff changeset
1197
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
1198 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
1199 stash_comment opt_sep opt_list END
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
1200 {
19778
bf737d927707 eliminate bison warnings from oct-parse.yy
John W. Eaton <jwe@octave.org>
parents: 19709
diff changeset
1201 YYUSE ($3);
bf737d927707 eliminate bison warnings from oct-parse.yy
John W. Eaton <jwe@octave.org>
parents: 19709
diff changeset
1202 YYUSE ($5);
bf737d927707 eliminate bison warnings from oct-parse.yy
John W. Eaton <jwe@octave.org>
parents: 19709
diff changeset
1203 YYUSE ($7);
bf737d927707 eliminate bison warnings from oct-parse.yy
John W. Eaton <jwe@octave.org>
parents: 19709
diff changeset
1204
16288
fe3b9a51e625 rename curr_lexer, curr_parser, CURR_LEXER
John W. Eaton <jwe@octave.org>
parents: 16287
diff changeset
1205 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
1206 {
bd0a84de3375 further reduce memory leaks from parse errors (bug #40231)
John W. Eaton <jwe@octave.org>
parents: 17629
diff changeset
1207 // make_unwind_command deleted $4 and $8.
21073
f7cc48f601d2 additional reworking of error handling in the parser (bug #46877)
John W. Eaton <jwe@octave.org>
parents: 21071
diff changeset
1208 YYABORT;
17632
bd0a84de3375 further reduce memory leaks from parse errors (bug #40231)
John W. Eaton <jwe@octave.org>
parents: 17629
diff changeset
1209 }
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
1210 }
17283
e6c0ac8ce5b6 eliminate parse conflicts introduced by changeset 923ce8b42db2
John W. Eaton <jwe@octave.org>
parents: 17281
diff changeset
1211 | 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
1212 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
1213 {
19778
bf737d927707 eliminate bison warnings from oct-parse.yy
John W. Eaton <jwe@octave.org>
parents: 19709
diff changeset
1214 YYUSE ($3);
bf737d927707 eliminate bison warnings from oct-parse.yy
John W. Eaton <jwe@octave.org>
parents: 19709
diff changeset
1215 YYUSE ($5);
bf737d927707 eliminate bison warnings from oct-parse.yy
John W. Eaton <jwe@octave.org>
parents: 19709
diff changeset
1216 YYUSE ($7);
bf737d927707 eliminate bison warnings from oct-parse.yy
John W. Eaton <jwe@octave.org>
parents: 19709
diff changeset
1217
17283
e6c0ac8ce5b6 eliminate parse conflicts introduced by changeset 923ce8b42db2
John W. Eaton <jwe@octave.org>
parents: 17281
diff changeset
1218 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
1219 {
bd0a84de3375 further reduce memory leaks from parse errors (bug #40231)
John W. Eaton <jwe@octave.org>
parents: 17629
diff changeset
1220 // make_try_command deleted $4 and $8.
21073
f7cc48f601d2 additional reworking of error handling in the parser (bug #46877)
John W. Eaton <jwe@octave.org>
parents: 21071
diff changeset
1221 YYABORT;
17632
bd0a84de3375 further reduce memory leaks from parse errors (bug #40231)
John W. Eaton <jwe@octave.org>
parents: 17629
diff changeset
1222 }
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
1223 }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
1224 | TRY stash_comment opt_sep opt_list END
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
1225 {
19778
bf737d927707 eliminate bison warnings from oct-parse.yy
John W. Eaton <jwe@octave.org>
parents: 19709
diff changeset
1226 YYUSE ($3);
bf737d927707 eliminate bison warnings from oct-parse.yy
John W. Eaton <jwe@octave.org>
parents: 19709
diff changeset
1227
17249
923ce8b42db2 improve try-catch-statement to save exception to a variable (bug #33217)
Stefan Mahr <dac922@gmx.de>
parents: 17170
diff changeset
1228 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
1229 {
bd0a84de3375 further reduce memory leaks from parse errors (bug #40231)
John W. Eaton <jwe@octave.org>
parents: 17629
diff changeset
1230 // make_try_command deleted $4.
21073
f7cc48f601d2 additional reworking of error handling in the parser (bug #46877)
John W. Eaton <jwe@octave.org>
parents: 21071
diff changeset
1231 YYABORT;
17632
bd0a84de3375 further reduce memory leaks from parse errors (bug #40231)
John W. Eaton <jwe@octave.org>
parents: 17629
diff changeset
1232 }
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
1233 }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
1234 ;
2970
b9e64477f703 [project @ 1997-05-15 18:04:21 by jwe]
jwe
parents: 2961
diff changeset
1235
b9e64477f703 [project @ 1997-05-15 18:04:21 by jwe]
jwe
parents: 2961
diff changeset
1236 // ===========================================
15466
d174210ce1ec use ' instead of ` in error messages, warnings and most comments
John W. Eaton <jwe@octave.org>
parents: 14189
diff changeset
1237 // Some 'subroutines' for function definitions
2970
b9e64477f703 [project @ 1997-05-15 18:04:21 by jwe]
jwe
parents: 2961
diff changeset
1238 // ===========================================
b9e64477f703 [project @ 1997-05-15 18:04:21 by jwe]
jwe
parents: 2961
diff changeset
1239
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
1240 push_fcn_symtab : // empty
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
1241 {
19778
bf737d927707 eliminate bison warnings from oct-parse.yy
John W. Eaton <jwe@octave.org>
parents: 19709
diff changeset
1242 $$ = 0;
bf737d927707 eliminate bison warnings from oct-parse.yy
John W. Eaton <jwe@octave.org>
parents: 19709
diff changeset
1243
16288
fe3b9a51e625 rename curr_lexer, curr_parser, CURR_LEXER
John W. Eaton <jwe@octave.org>
parents: 16287
diff changeset
1244 parser.curr_fcn_depth++;
fe3b9a51e625 rename curr_lexer, curr_parser, CURR_LEXER
John W. Eaton <jwe@octave.org>
parents: 16287
diff changeset
1245
fe3b9a51e625 rename curr_lexer, curr_parser, CURR_LEXER
John W. Eaton <jwe@octave.org>
parents: 16287
diff changeset
1246 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
1247 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
1248
16320
09f0cb9cac7d don't modify symbol table scope in the parser
John W. Eaton <jwe@octave.org>
parents: 16302
diff changeset
1249 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
1250
09f0cb9cac7d don't modify symbol table scope in the parser
John W. Eaton <jwe@octave.org>
parents: 16302
diff changeset
1251 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
1252 (lexer.symtab_context.curr_scope ());
16288
fe3b9a51e625 rename curr_lexer, curr_parser, CURR_LEXER
John W. Eaton <jwe@octave.org>
parents: 16287
diff changeset
1253
fe3b9a51e625 rename curr_lexer, curr_parser, CURR_LEXER
John W. Eaton <jwe@octave.org>
parents: 16287
diff changeset
1254 if (! lexer.reading_script_file
fe3b9a51e625 rename curr_lexer, curr_parser, CURR_LEXER
John W. Eaton <jwe@octave.org>
parents: 16287
diff changeset
1255 && parser.curr_fcn_depth == 1
fe3b9a51e625 rename curr_lexer, curr_parser, CURR_LEXER
John W. Eaton <jwe@octave.org>
parents: 16287
diff changeset
1256 && ! parser.parsing_subfunctions)
16320
09f0cb9cac7d don't modify symbol table scope in the parser
John W. Eaton <jwe@octave.org>
parents: 16302
diff changeset
1257 parser.primary_fcn_scope
09f0cb9cac7d don't modify symbol table scope in the parser
John W. Eaton <jwe@octave.org>
parents: 16302
diff changeset
1258 = lexer.symtab_context.curr_scope ();
16288
fe3b9a51e625 rename curr_lexer, curr_parser, CURR_LEXER
John W. Eaton <jwe@octave.org>
parents: 16287
diff changeset
1259
fe3b9a51e625 rename curr_lexer, curr_parser, CURR_LEXER
John W. Eaton <jwe@octave.org>
parents: 16287
diff changeset
1260 if (lexer.reading_script_file
fe3b9a51e625 rename curr_lexer, curr_parser, CURR_LEXER
John W. Eaton <jwe@octave.org>
parents: 16287
diff changeset
1261 && parser.curr_fcn_depth > 1)
21073
f7cc48f601d2 additional reworking of error handling in the parser (bug #46877)
John W. Eaton <jwe@octave.org>
parents: 21071
diff changeset
1262 {
f7cc48f601d2 additional reworking of error handling in the parser (bug #46877)
John W. Eaton <jwe@octave.org>
parents: 21071
diff changeset
1263 parser.bison_error ("nested functions not implemented in this context");
f7cc48f601d2 additional reworking of error handling in the parser (bug #46877)
John W. Eaton <jwe@octave.org>
parents: 21071
diff changeset
1264 YYABORT;
f7cc48f601d2 additional reworking of error handling in the parser (bug #46877)
John W. Eaton <jwe@octave.org>
parents: 21071
diff changeset
1265 }
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
1266 }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
1267 ;
2970
b9e64477f703 [project @ 1997-05-15 18:04:21 by jwe]
jwe
parents: 2961
diff changeset
1268
b9e64477f703 [project @ 1997-05-15 18:04:21 by jwe]
jwe
parents: 2961
diff changeset
1269 // ===========================
b9e64477f703 [project @ 1997-05-15 18:04:21 by jwe]
jwe
parents: 2961
diff changeset
1270 // List of function parameters
b9e64477f703 [project @ 1997-05-15 18:04:21 by jwe]
jwe
parents: 2961
diff changeset
1271 // ===========================
b9e64477f703 [project @ 1997-05-15 18:04:21 by jwe]
jwe
parents: 2961
diff changeset
1272
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
1273 param_list_beg : '('
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
1274 {
19778
bf737d927707 eliminate bison warnings from oct-parse.yy
John W. Eaton <jwe@octave.org>
parents: 19709
diff changeset
1275 $$ = 0;
16288
fe3b9a51e625 rename curr_lexer, curr_parser, CURR_LEXER
John W. Eaton <jwe@octave.org>
parents: 16287
diff changeset
1276 lexer.looking_at_parameter_list = true;
fe3b9a51e625 rename curr_lexer, curr_parser, CURR_LEXER
John W. Eaton <jwe@octave.org>
parents: 16287
diff changeset
1277
fe3b9a51e625 rename curr_lexer, curr_parser, CURR_LEXER
John W. Eaton <jwe@octave.org>
parents: 16287
diff changeset
1278 if (lexer.looking_at_function_handle)
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
1279 {
16320
09f0cb9cac7d don't modify symbol table scope in the parser
John W. Eaton <jwe@octave.org>
parents: 16302
diff changeset
1280 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
1281 lexer.looking_at_function_handle--;
fe3b9a51e625 rename curr_lexer, curr_parser, CURR_LEXER
John W. Eaton <jwe@octave.org>
parents: 16287
diff changeset
1282 lexer.looking_at_anon_fcn_args = true;
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
1283 }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
1284 }
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 param_list_end : ')'
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
1288 {
19778
bf737d927707 eliminate bison warnings from oct-parse.yy
John W. Eaton <jwe@octave.org>
parents: 19709
diff changeset
1289 $$ = 0;
16288
fe3b9a51e625 rename curr_lexer, curr_parser, CURR_LEXER
John W. Eaton <jwe@octave.org>
parents: 16287
diff changeset
1290 lexer.looking_at_parameter_list = false;
fe3b9a51e625 rename curr_lexer, curr_parser, CURR_LEXER
John W. Eaton <jwe@octave.org>
parents: 16287
diff changeset
1291 lexer.looking_for_object_index = false;
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
1292 }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
1293 ;
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 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
1296 {
11115c237231 recognize variables when parsing (bug #38576)
John W. Eaton <jwe@octave.org>
parents: 16320
diff changeset
1297 if ($2)
11115c237231 recognize variables when parsing (bug #38576)
John W. Eaton <jwe@octave.org>
parents: 16320
diff changeset
1298 lexer.mark_as_variables ($2->variable_names ());
11115c237231 recognize variables when parsing (bug #38576)
John W. Eaton <jwe@octave.org>
parents: 16320
diff changeset
1299
11115c237231 recognize variables when parsing (bug #38576)
John W. Eaton <jwe@octave.org>
parents: 16320
diff changeset
1300 $$ = $2;
11115c237231 recognize variables when parsing (bug #38576)
John W. Eaton <jwe@octave.org>
parents: 16320
diff changeset
1301 }
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
1302 | param_list_beg error
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
1303 {
21073
f7cc48f601d2 additional reworking of error handling in the parser (bug #46877)
John W. Eaton <jwe@octave.org>
parents: 21071
diff changeset
1304 $$ = 0;
16288
fe3b9a51e625 rename curr_lexer, curr_parser, CURR_LEXER
John W. Eaton <jwe@octave.org>
parents: 16287
diff changeset
1305 parser.bison_error ("invalid parameter list");
21073
f7cc48f601d2 additional reworking of error handling in the parser (bug #46877)
John W. Eaton <jwe@octave.org>
parents: 21071
diff changeset
1306 YYABORT;
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
1307 }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
1308 ;
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 param_list1 : // empty
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
1311 { $$ = 0; }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
1312 | param_list2
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
1313 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
1314 $1->mark_as_formal_parameters ();
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
1315 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
1316 {
11115c237231 recognize variables when parsing (bug #38576)
John W. Eaton <jwe@octave.org>
parents: 16320
diff changeset
1317 lexer.mark_as_variables ($1->variable_names ());
11115c237231 recognize variables when parsing (bug #38576)
John W. Eaton <jwe@octave.org>
parents: 16320
diff changeset
1318 $$ = $1;
11115c237231 recognize variables when parsing (bug #38576)
John W. Eaton <jwe@octave.org>
parents: 16320
diff changeset
1319 }
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
1320 else
17632
bd0a84de3375 further reduce memory leaks from parse errors (bug #40231)
John W. Eaton <jwe@octave.org>
parents: 17629
diff changeset
1321 {
bd0a84de3375 further reduce memory leaks from parse errors (bug #40231)
John W. Eaton <jwe@octave.org>
parents: 17629
diff changeset
1322 delete $1;
21073
f7cc48f601d2 additional reworking of error handling in the parser (bug #46877)
John W. Eaton <jwe@octave.org>
parents: 21071
diff changeset
1323 YYABORT;
17632
bd0a84de3375 further reduce memory leaks from parse errors (bug #40231)
John W. Eaton <jwe@octave.org>
parents: 17629
diff changeset
1324 }
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
1325 }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
1326 ;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
1327
17317
56fe31b248de disallow ~ in global and persistent declaration lists
John W. Eaton <jwe@octave.org>
parents: 17316
diff changeset
1328 param_list2 : param_list_elt
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
1329 { $$ = new tree_parameter_list ($1); }
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 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
1332 $1->append ($3);
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
1333 $$ = $1;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
1334 }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
1335 ;
2970
b9e64477f703 [project @ 1997-05-15 18:04:21 by jwe]
jwe
parents: 2961
diff changeset
1336
17317
56fe31b248de disallow ~ in global and persistent declaration lists
John W. Eaton <jwe@octave.org>
parents: 17316
diff changeset
1337 param_list_elt : decl2
56fe31b248de disallow ~ in global and persistent declaration lists
John W. Eaton <jwe@octave.org>
parents: 17316
diff changeset
1338 { $$ = $1; }
56fe31b248de disallow ~ in global and persistent declaration lists
John W. Eaton <jwe@octave.org>
parents: 17316
diff changeset
1339 | magic_tilde
56fe31b248de disallow ~ in global and persistent declaration lists
John W. Eaton <jwe@octave.org>
parents: 17316
diff changeset
1340 { $$ = new tree_decl_elt ($1); }
56fe31b248de disallow ~ in global and persistent declaration lists
John W. Eaton <jwe@octave.org>
parents: 17316
diff changeset
1341 ;
56fe31b248de disallow ~ in global and persistent declaration lists
John W. Eaton <jwe@octave.org>
parents: 17316
diff changeset
1342
2970
b9e64477f703 [project @ 1997-05-15 18:04:21 by jwe]
jwe
parents: 2961
diff changeset
1343 // ===================================
b9e64477f703 [project @ 1997-05-15 18:04:21 by jwe]
jwe
parents: 2961
diff changeset
1344 // List of function return value names
b9e64477f703 [project @ 1997-05-15 18:04:21 by jwe]
jwe
parents: 2961
diff changeset
1345 // ===================================
b9e64477f703 [project @ 1997-05-15 18:04:21 by jwe]
jwe
parents: 2961
diff changeset
1346
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
1347 return_list : '[' ']'
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
1348 {
16288
fe3b9a51e625 rename curr_lexer, curr_parser, CURR_LEXER
John W. Eaton <jwe@octave.org>
parents: 16287
diff changeset
1349 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
1350
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
1351 $$ = new tree_parameter_list ();
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
1352 }
17316
8e2906e2fb26 avoid reduce/reduce conflict in parser rules
John W. Eaton <jwe@octave.org>
parents: 17283
diff changeset
1353 | identifier
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
1354 {
16288
fe3b9a51e625 rename curr_lexer, curr_parser, CURR_LEXER
John W. Eaton <jwe@octave.org>
parents: 16287
diff changeset
1355 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
1356
8e2906e2fb26 avoid reduce/reduce conflict in parser rules
John W. Eaton <jwe@octave.org>
parents: 17283
diff changeset
1357 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
1358
8e2906e2fb26 avoid reduce/reduce conflict in parser rules
John W. Eaton <jwe@octave.org>
parents: 17283
diff changeset
1359 // 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
1360 // 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
1361 // to check for varargin or varargout.
8e2906e2fb26 avoid reduce/reduce conflict in parser rules
John W. Eaton <jwe@octave.org>
parents: 17283
diff changeset
1362
8e2906e2fb26 avoid reduce/reduce conflict in parser rules
John W. Eaton <jwe@octave.org>
parents: 17283
diff changeset
1363 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
1364 $$ = tmp;
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
1365 else
17632
bd0a84de3375 further reduce memory leaks from parse errors (bug #40231)
John W. Eaton <jwe@octave.org>
parents: 17629
diff changeset
1366 {
bd0a84de3375 further reduce memory leaks from parse errors (bug #40231)
John W. Eaton <jwe@octave.org>
parents: 17629
diff changeset
1367 delete tmp;
21073
f7cc48f601d2 additional reworking of error handling in the parser (bug #46877)
John W. Eaton <jwe@octave.org>
parents: 21071
diff changeset
1368 YYABORT;
17632
bd0a84de3375 further reduce memory leaks from parse errors (bug #40231)
John W. Eaton <jwe@octave.org>
parents: 17629
diff changeset
1369 }
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
1370 }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
1371 | '[' return_list1 ']'
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
1372 {
16288
fe3b9a51e625 rename curr_lexer, curr_parser, CURR_LEXER
John W. Eaton <jwe@octave.org>
parents: 16287
diff changeset
1373 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
1374
8e2906e2fb26 avoid reduce/reduce conflict in parser rules
John W. Eaton <jwe@octave.org>
parents: 17283
diff changeset
1375 // Check for duplicate parameter names, varargin,
8e2906e2fb26 avoid reduce/reduce conflict in parser rules
John W. Eaton <jwe@octave.org>
parents: 17283
diff changeset
1376 // or varargout.
8e2906e2fb26 avoid reduce/reduce conflict in parser rules
John W. Eaton <jwe@octave.org>
parents: 17283
diff changeset
1377
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
1378 if ($2->validate (tree_parameter_list::out))
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
1379 $$ = $2;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
1380 else
17632
bd0a84de3375 further reduce memory leaks from parse errors (bug #40231)
John W. Eaton <jwe@octave.org>
parents: 17629
diff changeset
1381 {
bd0a84de3375 further reduce memory leaks from parse errors (bug #40231)
John W. Eaton <jwe@octave.org>
parents: 17629
diff changeset
1382 delete $2;
21073
f7cc48f601d2 additional reworking of error handling in the parser (bug #46877)
John W. Eaton <jwe@octave.org>
parents: 21071
diff changeset
1383 YYABORT;
17632
bd0a84de3375 further reduce memory leaks from parse errors (bug #40231)
John W. Eaton <jwe@octave.org>
parents: 17629
diff changeset
1384 }
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
1385 }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
1386 ;
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 return_list1 : identifier
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
1389 { $$ = 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
1390 | return_list1 ',' identifier
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
1391 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
1392 $1->append (new tree_decl_elt ($3));
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
1393 $$ = $1;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
1394 }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
1395 ;
2970
b9e64477f703 [project @ 1997-05-15 18:04:21 by jwe]
jwe
parents: 2961
diff changeset
1396
16203
127cccb037bf move more global parser and lexer variables to classes
John W. Eaton <jwe@octave.org>
parents: 16199
diff changeset
1397 // =======================
127cccb037bf move more global parser and lexer variables to classes
John W. Eaton <jwe@octave.org>
parents: 16199
diff changeset
1398 // Script or function file
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
127cccb037bf move more global parser and lexer variables to classes
John W. Eaton <jwe@octave.org>
parents: 16199
diff changeset
1401 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
1402 {
19778
bf737d927707 eliminate bison warnings from oct-parse.yy
John W. Eaton <jwe@octave.org>
parents: 19709
diff changeset
1403 YYUSE ($2);
bf737d927707 eliminate bison warnings from oct-parse.yy
John W. Eaton <jwe@octave.org>
parents: 19709
diff changeset
1404
17618
77eff9c6fb09 avoid memory leak when parsing function files (bug #40218)
John W. Eaton <jwe@octave.org>
parents: 17377
diff changeset
1405 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
1406 {
77eff9c6fb09 avoid memory leak when parsing function files (bug #40218)
John W. Eaton <jwe@octave.org>
parents: 17377
diff changeset
1407 // 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
1408 // 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
1409 // 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
1410 // 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
1411 // 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
1412
77eff9c6fb09 avoid memory leak when parsing function files (bug #40218)
John W. Eaton <jwe@octave.org>
parents: 17377
diff changeset
1413 delete $3;
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 else
16203
127cccb037bf move more global parser and lexer variables to classes
John W. Eaton <jwe@octave.org>
parents: 16199
diff changeset
1416 {
127cccb037bf move more global parser and lexer variables to classes
John W. Eaton <jwe@octave.org>
parents: 16199
diff changeset
1417 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
1418 = 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
1419 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
1420 lexer.current_input_column);
16288
fe3b9a51e625 rename curr_lexer, curr_parser, CURR_LEXER
John W. Eaton <jwe@octave.org>
parents: 16287
diff changeset
1421
fe3b9a51e625 rename curr_lexer, curr_parser, CURR_LEXER
John W. Eaton <jwe@octave.org>
parents: 16287
diff changeset
1422 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
1423 }
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
1424
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
1425 $$ = 0;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
1426 }
16211
3449bf257514 maint: fix botched merge of default to classdef
John W. Eaton <jwe@octave.org>
parents: 16205
diff changeset
1427 | 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
1428 {
19778
bf737d927707 eliminate bison warnings from oct-parse.yy
John W. Eaton <jwe@octave.org>
parents: 19709
diff changeset
1429 YYUSE ($2);
bf737d927707 eliminate bison warnings from oct-parse.yy
John W. Eaton <jwe@octave.org>
parents: 19709
diff changeset
1430 YYUSE ($4);
bf737d927707 eliminate bison warnings from oct-parse.yy
John W. Eaton <jwe@octave.org>
parents: 19709
diff changeset
1431
16289
bde729ba8381 maint: periodic merge of default to classdef
John W. Eaton <jwe@octave.org>
parents: 16286 16288
diff changeset
1432 if (lexer.reading_classdef_file)
bde729ba8381 maint: periodic merge of default to classdef
John W. Eaton <jwe@octave.org>
parents: 16286 16288
diff changeset
1433 parser.classdef_object = $3;
16211
3449bf257514 maint: fix botched merge of default to classdef
John W. Eaton <jwe@octave.org>
parents: 16205
diff changeset
1434
3449bf257514 maint: fix botched merge of default to classdef
John W. Eaton <jwe@octave.org>
parents: 16205
diff changeset
1435 $$ = 0;
3449bf257514 maint: fix botched merge of default to classdef
John W. Eaton <jwe@octave.org>
parents: 16205
diff changeset
1436 }
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
1437 ;
7715
5b4d278ec828 parse scripts completely before executing
John W. Eaton <jwe@octave.org>
parents: 7699
diff changeset
1438
2970
b9e64477f703 [project @ 1997-05-15 18:04:21 by jwe]
jwe
parents: 2961
diff changeset
1439 // ===================
b9e64477f703 [project @ 1997-05-15 18:04:21 by jwe]
jwe
parents: 2961
diff changeset
1440 // Function definition
b9e64477f703 [project @ 1997-05-15 18:04:21 by jwe]
jwe
parents: 2961
diff changeset
1441 // ===================
b9e64477f703 [project @ 1997-05-15 18:04:21 by jwe]
jwe
parents: 2961
diff changeset
1442
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
1443 function_beg : push_fcn_symtab FCN
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
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 $$ = $2;
16288
fe3b9a51e625 rename curr_lexer, curr_parser, CURR_LEXER
John W. Eaton <jwe@octave.org>
parents: 16287
diff changeset
1446 if (lexer.reading_classdef_file
fe3b9a51e625 rename curr_lexer, curr_parser, CURR_LEXER
John W. Eaton <jwe@octave.org>
parents: 16287
diff changeset
1447 || lexer.parsing_classdef)
fe3b9a51e625 rename curr_lexer, curr_parser, CURR_LEXER
John W. Eaton <jwe@octave.org>
parents: 16287
diff changeset
1448 lexer.maybe_classdef_get_set_method = true;
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
1449 }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
1450 ;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
1451
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
1452 function : function_beg stash_comment function1
10315
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 $$ = 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
1455 $1->column ());
16288
fe3b9a51e625 rename curr_lexer, curr_parser, CURR_LEXER
John W. Eaton <jwe@octave.org>
parents: 16287
diff changeset
1456 parser.recover_from_parsing_function ();
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
1457 }
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
1458 | function_beg stash_comment return_list '=' function1
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
1459 {
19778
bf737d927707 eliminate bison warnings from oct-parse.yy
John W. Eaton <jwe@octave.org>
parents: 19709
diff changeset
1460 YYUSE ($4);
bf737d927707 eliminate bison warnings from oct-parse.yy
John W. Eaton <jwe@octave.org>
parents: 19709
diff changeset
1461
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
1462 $$ = 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
1463 $1->column ());
16288
fe3b9a51e625 rename curr_lexer, curr_parser, CURR_LEXER
John W. Eaton <jwe@octave.org>
parents: 16287
diff changeset
1464 parser.recover_from_parsing_function ();
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
1465 }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
1466 ;
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 fcn_name : identifier
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 std::string id_name = $1->name ();
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
1471
16288
fe3b9a51e625 rename curr_lexer, curr_parser, CURR_LEXER
John W. Eaton <jwe@octave.org>
parents: 16287
diff changeset
1472 lexer.parsed_function_name.top () = true;
fe3b9a51e625 rename curr_lexer, curr_parser, CURR_LEXER
John W. Eaton <jwe@octave.org>
parents: 16287
diff changeset
1473 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
1474
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
1475 $$ = $1;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
1476 }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
1477 | GET '.' identifier
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
1478 {
19778
bf737d927707 eliminate bison warnings from oct-parse.yy
John W. Eaton <jwe@octave.org>
parents: 19709
diff changeset
1479 YYUSE ($1);
bf737d927707 eliminate bison warnings from oct-parse.yy
John W. Eaton <jwe@octave.org>
parents: 19709
diff changeset
1480
16288
fe3b9a51e625 rename curr_lexer, curr_parser, CURR_LEXER
John W. Eaton <jwe@octave.org>
parents: 16287
diff changeset
1481 lexer.parsed_function_name.top () = true;
fe3b9a51e625 rename curr_lexer, curr_parser, CURR_LEXER
John W. Eaton <jwe@octave.org>
parents: 16287
diff changeset
1482 lexer.maybe_classdef_get_set_method = false;
16289
bde729ba8381 maint: periodic merge of default to classdef
John W. Eaton <jwe@octave.org>
parents: 16286 16288
diff changeset
1483 lexer.parsing_classdef_get_method = true;
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
1484 $$ = $3;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
1485 }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
1486 | SET '.' identifier
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
1487 {
19778
bf737d927707 eliminate bison warnings from oct-parse.yy
John W. Eaton <jwe@octave.org>
parents: 19709
diff changeset
1488 YYUSE ($1);
bf737d927707 eliminate bison warnings from oct-parse.yy
John W. Eaton <jwe@octave.org>
parents: 19709
diff changeset
1489
16288
fe3b9a51e625 rename curr_lexer, curr_parser, CURR_LEXER
John W. Eaton <jwe@octave.org>
parents: 16287
diff changeset
1490 lexer.parsed_function_name.top () = true;
fe3b9a51e625 rename curr_lexer, curr_parser, CURR_LEXER
John W. Eaton <jwe@octave.org>
parents: 16287
diff changeset
1491 lexer.maybe_classdef_get_set_method = false;
16289
bde729ba8381 maint: periodic merge of default to classdef
John W. Eaton <jwe@octave.org>
parents: 16286 16288
diff changeset
1492 lexer.parsing_classdef_set_method = true;
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
1493 $$ = $3;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
1494 }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
1495 ;
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 function1 : fcn_name function2
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 std::string fname = $1->name ();
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 delete $1;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
1502
16698
13b3b92ea99c Implement property accessors.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 16683
diff changeset
1503 if (lexer.parsing_classdef_get_method)
13b3b92ea99c Implement property accessors.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 16683
diff changeset
1504 fname.insert (0, "get.");
13b3b92ea99c Implement property accessors.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 16683
diff changeset
1505 else if (lexer.parsing_classdef_set_method)
13b3b92ea99c Implement property accessors.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 16683
diff changeset
1506 fname.insert (0, "set.");
13b3b92ea99c Implement property accessors.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 16683
diff changeset
1507
18395
2319bf776fa2 Fix parsing of classdef property accessors.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 18341
diff changeset
1508 lexer.parsing_classdef_get_method = false;
2319bf776fa2 Fix parsing of classdef property accessors.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 18341
diff changeset
1509 lexer.parsing_classdef_set_method = false;
2319bf776fa2 Fix parsing of classdef property accessors.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 18341
diff changeset
1510
17632
bd0a84de3375 further reduce memory leaks from parse errors (bug #40231)
John W. Eaton <jwe@octave.org>
parents: 17629
diff changeset
1511 $$ = parser.frob_function (fname, $2);
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
1512 }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
1513 ;
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 function2 : param_list opt_sep opt_list function_end
19778
bf737d927707 eliminate bison warnings from oct-parse.yy
John W. Eaton <jwe@octave.org>
parents: 19709
diff changeset
1516 {
bf737d927707 eliminate bison warnings from oct-parse.yy
John W. Eaton <jwe@octave.org>
parents: 19709
diff changeset
1517 YYUSE ($2);
bf737d927707 eliminate bison warnings from oct-parse.yy
John W. Eaton <jwe@octave.org>
parents: 19709
diff changeset
1518
bf737d927707 eliminate bison warnings from oct-parse.yy
John W. Eaton <jwe@octave.org>
parents: 19709
diff changeset
1519 $$ = parser.start_function ($1, $3, $4);
bf737d927707 eliminate bison warnings from oct-parse.yy
John W. Eaton <jwe@octave.org>
parents: 19709
diff changeset
1520 }
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
1521 | opt_sep opt_list function_end
19778
bf737d927707 eliminate bison warnings from oct-parse.yy
John W. Eaton <jwe@octave.org>
parents: 19709
diff changeset
1522 {
bf737d927707 eliminate bison warnings from oct-parse.yy
John W. Eaton <jwe@octave.org>
parents: 19709
diff changeset
1523 YYUSE ($1);
bf737d927707 eliminate bison warnings from oct-parse.yy
John W. Eaton <jwe@octave.org>
parents: 19709
diff changeset
1524
bf737d927707 eliminate bison warnings from oct-parse.yy
John W. Eaton <jwe@octave.org>
parents: 19709
diff changeset
1525 $$ = parser.start_function (0, $2, $3);
bf737d927707 eliminate bison warnings from oct-parse.yy
John W. Eaton <jwe@octave.org>
parents: 19709
diff changeset
1526 }
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
1527 ;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
1528
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
1529 function_end : END
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
1530 {
16288
fe3b9a51e625 rename curr_lexer, curr_parser, CURR_LEXER
John W. Eaton <jwe@octave.org>
parents: 16287
diff changeset
1531 parser.endfunction_found = true;
21071
f25c14056b7c overhaul parser error handling for end token mismatch
John W. Eaton <jwe@octave.org>
parents: 21066
diff changeset
1532
16288
fe3b9a51e625 rename curr_lexer, curr_parser, CURR_LEXER
John W. Eaton <jwe@octave.org>
parents: 16287
diff changeset
1533 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
1534 $$ = 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
1535 $1->line (), $1->column ());
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
1536 else
21071
f25c14056b7c overhaul parser error handling for end token mismatch
John W. Eaton <jwe@octave.org>
parents: 21066
diff changeset
1537 {
f25c14056b7c overhaul parser error handling for end token mismatch
John W. Eaton <jwe@octave.org>
parents: 21066
diff changeset
1538 parser.end_token_error ($1, token::function_end);
21073
f7cc48f601d2 additional reworking of error handling in the parser (bug #46877)
John W. Eaton <jwe@octave.org>
parents: 21071
diff changeset
1539 YYABORT;
21071
f25c14056b7c overhaul parser error handling for end token mismatch
John W. Eaton <jwe@octave.org>
parents: 21066
diff changeset
1540 }
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
1541 }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
1542 | END_OF_INPUT
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
1543 {
9474
25ed2d6aacf6 Parse nested functions more accurately.
David Grundberg <individ@acc.umu.se>
parents: 9471
diff changeset
1544 // 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
1545 // if (lexer.reading_script_file)
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
1546 // {
16288
fe3b9a51e625 rename curr_lexer, curr_parser, CURR_LEXER
John W. Eaton <jwe@octave.org>
parents: 16287
diff changeset
1547 // 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
1548 // YYABORT;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
1549 // }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
1550
16288
fe3b9a51e625 rename curr_lexer, curr_parser, CURR_LEXER
John W. Eaton <jwe@octave.org>
parents: 16287
diff changeset
1551 if (parser.endfunction_found)
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
1552 {
16288
fe3b9a51e625 rename curr_lexer, curr_parser, CURR_LEXER
John W. Eaton <jwe@octave.org>
parents: 16287
diff changeset
1553 parser.bison_error ("inconsistent function endings -- "
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
1554 "if one function is explicitly ended, "
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
1555 "so must all the others");
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
1556 YYABORT;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
1557 }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
1558
16288
fe3b9a51e625 rename curr_lexer, curr_parser, CURR_LEXER
John W. Eaton <jwe@octave.org>
parents: 16287
diff changeset
1559 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
1560 || lexer.input_from_eval_string ()))
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
1561 {
16288
fe3b9a51e625 rename curr_lexer, curr_parser, CURR_LEXER
John W. Eaton <jwe@octave.org>
parents: 16287
diff changeset
1562 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
1563 YYABORT;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
1564 }
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 if (lexer.reading_classdef_file)
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
1567 {
16288
fe3b9a51e625 rename curr_lexer, curr_parser, CURR_LEXER
John W. Eaton <jwe@octave.org>
parents: 16287
diff changeset
1568 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
1569 YYABORT;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
1570 }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
1571
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
1572 $$ = 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
1573 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
1574 lexer.current_input_column);
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
1575 }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
1576 ;
2970
b9e64477f703 [project @ 1997-05-15 18:04:21 by jwe]
jwe
parents: 2961
diff changeset
1577
9476
d9b25c5b8ee5 handle classdef syntax in lexer and parser
Ryan Rusaw
parents: 9474
diff changeset
1578 // ========
d9b25c5b8ee5 handle classdef syntax in lexer and parser
Ryan Rusaw
parents: 9474
diff changeset
1579 // Classdef
d9b25c5b8ee5 handle classdef syntax in lexer and parser
Ryan Rusaw
parents: 9474
diff changeset
1580 // ========
d9b25c5b8ee5 handle classdef syntax in lexer and parser
Ryan Rusaw
parents: 9474
diff changeset
1581
15037
56b8eb7c9c04 improvements in parsing classdef
John W. Eaton <jwe@octave.org>
parents: 14846
diff changeset
1582 classdef_beg : CLASSDEF
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
1583 {
16289
bde729ba8381 maint: periodic merge of default to classdef
John W. Eaton <jwe@octave.org>
parents: 16286 16288
diff changeset
1584 if (! lexer.reading_classdef_file)
15037
56b8eb7c9c04 improvements in parsing classdef
John W. Eaton <jwe@octave.org>
parents: 14846
diff changeset
1585 {
16289
bde729ba8381 maint: periodic merge of default to classdef
John W. Eaton <jwe@octave.org>
parents: 16286 16288
diff changeset
1586 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
1587 YYABORT;
56b8eb7c9c04 improvements in parsing classdef
John W. Eaton <jwe@octave.org>
parents: 14846
diff changeset
1588 }
56b8eb7c9c04 improvements in parsing classdef
John W. Eaton <jwe@octave.org>
parents: 14846
diff changeset
1589
16288
fe3b9a51e625 rename curr_lexer, curr_parser, CURR_LEXER
John W. Eaton <jwe@octave.org>
parents: 16287
diff changeset
1590 lexer.parsing_classdef = true;
15037
56b8eb7c9c04 improvements in parsing classdef
John W. Eaton <jwe@octave.org>
parents: 14846
diff changeset
1591 $$ = $1;
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
1592 }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
1593 ;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
1594
15037
56b8eb7c9c04 improvements in parsing classdef
John W. Eaton <jwe@octave.org>
parents: 14846
diff changeset
1595 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
1596 {
19778
bf737d927707 eliminate bison warnings from oct-parse.yy
John W. Eaton <jwe@octave.org>
parents: 19709
diff changeset
1597 YYUSE ($6);
bf737d927707 eliminate bison warnings from oct-parse.yy
John W. Eaton <jwe@octave.org>
parents: 19709
diff changeset
1598 YYUSE ($8);
bf737d927707 eliminate bison warnings from oct-parse.yy
John W. Eaton <jwe@octave.org>
parents: 19709
diff changeset
1599
16288
fe3b9a51e625 rename curr_lexer, curr_parser, CURR_LEXER
John W. Eaton <jwe@octave.org>
parents: 16287
diff changeset
1600 lexer.parsing_classdef = false;
fe3b9a51e625 rename curr_lexer, curr_parser, CURR_LEXER
John W. Eaton <jwe@octave.org>
parents: 16287
diff changeset
1601
16289
bde729ba8381 maint: periodic merge of default to classdef
John W. Eaton <jwe@octave.org>
parents: 16286 16288
diff changeset
1602 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
1603 {
2b1047efc4fb don't leak memory when parsing classdef objects fails
John W. Eaton <jwe@octave.org>
parents: 17654
diff changeset
1604 // make_classdef deleted $3, $4, $5, and $7.
21073
f7cc48f601d2 additional reworking of error handling in the parser (bug #46877)
John W. Eaton <jwe@octave.org>
parents: 21071
diff changeset
1605 YYABORT;
17656
2b1047efc4fb don't leak memory when parsing classdef objects fails
John W. Eaton <jwe@octave.org>
parents: 17654
diff changeset
1606 }
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
1607 }
18419
9154dc252f47 Allow empty classdef or methods/properties/... blocks
Michael Goffioul <michael.goffioul@gmail.com>
parents: 18395
diff changeset
1608 | 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
1609 {
19778
bf737d927707 eliminate bison warnings from oct-parse.yy
John W. Eaton <jwe@octave.org>
parents: 19709
diff changeset
1610 YYUSE ($6);
bf737d927707 eliminate bison warnings from oct-parse.yy
John W. Eaton <jwe@octave.org>
parents: 19709
diff changeset
1611
18419
9154dc252f47 Allow empty classdef or methods/properties/... blocks
Michael Goffioul <michael.goffioul@gmail.com>
parents: 18395
diff changeset
1612 lexer.parsing_classdef = false;
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 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
1615 {
9154dc252f47 Allow empty classdef or methods/properties/... blocks
Michael Goffioul <michael.goffioul@gmail.com>
parents: 18395
diff changeset
1616 // make_classdef deleted $3, $4, and $5.
21073
f7cc48f601d2 additional reworking of error handling in the parser (bug #46877)
John W. Eaton <jwe@octave.org>
parents: 21071
diff changeset
1617 YYABORT;
18419
9154dc252f47 Allow empty classdef or methods/properties/... blocks
Michael Goffioul <michael.goffioul@gmail.com>
parents: 18395
diff changeset
1618 }
9154dc252f47 Allow empty classdef or methods/properties/... blocks
Michael Goffioul <michael.goffioul@gmail.com>
parents: 18395
diff changeset
1619 }
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
1620 ;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
1621
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
1622 opt_attr_list : // empty
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
1623 { $$ = 0; }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
1624 | '(' attr_list ')'
15037
56b8eb7c9c04 improvements in parsing classdef
John W. Eaton <jwe@octave.org>
parents: 14846
diff changeset
1625 { $$ = $2; }
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
1626 ;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
1627
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
1628 attr_list : attr
15037
56b8eb7c9c04 improvements in parsing classdef
John W. Eaton <jwe@octave.org>
parents: 14846
diff changeset
1629 { $$ = new tree_classdef_attribute_list ($1); }
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
1630 | attr_list ',' attr
15037
56b8eb7c9c04 improvements in parsing classdef
John W. Eaton <jwe@octave.org>
parents: 14846
diff changeset
1631 {
56b8eb7c9c04 improvements in parsing classdef
John W. Eaton <jwe@octave.org>
parents: 14846
diff changeset
1632 $1->append ($3);
56b8eb7c9c04 improvements in parsing classdef
John W. Eaton <jwe@octave.org>
parents: 14846
diff changeset
1633 $$ = $1;
56b8eb7c9c04 improvements in parsing classdef
John W. Eaton <jwe@octave.org>
parents: 14846
diff changeset
1634 }
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
1635 ;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
1636
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
1637 attr : identifier
15037
56b8eb7c9c04 improvements in parsing classdef
John W. Eaton <jwe@octave.org>
parents: 14846
diff changeset
1638 { $$ = new tree_classdef_attribute ($1); }
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
1639 | identifier '=' decl_param_init expression
15037
56b8eb7c9c04 improvements in parsing classdef
John W. Eaton <jwe@octave.org>
parents: 14846
diff changeset
1640 {
19778
bf737d927707 eliminate bison warnings from oct-parse.yy
John W. Eaton <jwe@octave.org>
parents: 19709
diff changeset
1641 YYUSE ($2);
bf737d927707 eliminate bison warnings from oct-parse.yy
John W. Eaton <jwe@octave.org>
parents: 19709
diff changeset
1642
16289
bde729ba8381 maint: periodic merge of default to classdef
John W. Eaton <jwe@octave.org>
parents: 16286 16288
diff changeset
1643 lexer.looking_at_initializer_expression = false;
15037
56b8eb7c9c04 improvements in parsing classdef
John W. Eaton <jwe@octave.org>
parents: 14846
diff changeset
1644 $$ = new tree_classdef_attribute ($1, $4);
56b8eb7c9c04 improvements in parsing classdef
John W. Eaton <jwe@octave.org>
parents: 14846
diff changeset
1645 }
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
1646 | EXPR_NOT identifier
19778
bf737d927707 eliminate bison warnings from oct-parse.yy
John W. Eaton <jwe@octave.org>
parents: 19709
diff changeset
1647 {
bf737d927707 eliminate bison warnings from oct-parse.yy
John W. Eaton <jwe@octave.org>
parents: 19709
diff changeset
1648 YYUSE ($1);
bf737d927707 eliminate bison warnings from oct-parse.yy
John W. Eaton <jwe@octave.org>
parents: 19709
diff changeset
1649
bf737d927707 eliminate bison warnings from oct-parse.yy
John W. Eaton <jwe@octave.org>
parents: 19709
diff changeset
1650 $$ = new tree_classdef_attribute ($2, false);
bf737d927707 eliminate bison warnings from oct-parse.yy
John W. Eaton <jwe@octave.org>
parents: 19709
diff changeset
1651 }
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
1652 ;
9476
d9b25c5b8ee5 handle classdef syntax in lexer and parser
Ryan Rusaw
parents: 9474
diff changeset
1653
15037
56b8eb7c9c04 improvements in parsing classdef
John W. Eaton <jwe@octave.org>
parents: 14846
diff changeset
1654 opt_superclass_list
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
1655 : // empty
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
1656 { $$ = 0; }
15037
56b8eb7c9c04 improvements in parsing classdef
John W. Eaton <jwe@octave.org>
parents: 14846
diff changeset
1657 | superclass_list
56b8eb7c9c04 improvements in parsing classdef
John W. Eaton <jwe@octave.org>
parents: 14846
diff changeset
1658 { $$ = $1; }
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
1659 ;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
1660
18520
932aca9a7c57 Allow multi-level classdef package.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 18419
diff changeset
1661 superclass_list : EXPR_LT
19778
bf737d927707 eliminate bison warnings from oct-parse.yy
John W. Eaton <jwe@octave.org>
parents: 19709
diff changeset
1662 {
bf737d927707 eliminate bison warnings from oct-parse.yy
John W. Eaton <jwe@octave.org>
parents: 19709
diff changeset
1663 YYUSE ($1);
bf737d927707 eliminate bison warnings from oct-parse.yy
John W. Eaton <jwe@octave.org>
parents: 19709
diff changeset
1664
bf737d927707 eliminate bison warnings from oct-parse.yy
John W. Eaton <jwe@octave.org>
parents: 19709
diff changeset
1665 lexer.enable_fq_identifier ();
bf737d927707 eliminate bison warnings from oct-parse.yy
John W. Eaton <jwe@octave.org>
parents: 19709
diff changeset
1666 }
18520
932aca9a7c57 Allow multi-level classdef package.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 18419
diff changeset
1667 superclass
932aca9a7c57 Allow multi-level classdef package.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 18419
diff changeset
1668 { $$ = new tree_classdef_superclass_list ($3); }
932aca9a7c57 Allow multi-level classdef package.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 18419
diff changeset
1669 | superclass_list EXPR_AND
19778
bf737d927707 eliminate bison warnings from oct-parse.yy
John W. Eaton <jwe@octave.org>
parents: 19709
diff changeset
1670 {
bf737d927707 eliminate bison warnings from oct-parse.yy
John W. Eaton <jwe@octave.org>
parents: 19709
diff changeset
1671 YYUSE ($2);
bf737d927707 eliminate bison warnings from oct-parse.yy
John W. Eaton <jwe@octave.org>
parents: 19709
diff changeset
1672
bf737d927707 eliminate bison warnings from oct-parse.yy
John W. Eaton <jwe@octave.org>
parents: 19709
diff changeset
1673 lexer.enable_fq_identifier ();
bf737d927707 eliminate bison warnings from oct-parse.yy
John W. Eaton <jwe@octave.org>
parents: 19709
diff changeset
1674 }
18520
932aca9a7c57 Allow multi-level classdef package.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 18419
diff changeset
1675 superclass
15037
56b8eb7c9c04 improvements in parsing classdef
John W. Eaton <jwe@octave.org>
parents: 14846
diff changeset
1676 {
18520
932aca9a7c57 Allow multi-level classdef package.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 18419
diff changeset
1677 $1->append ($4);
15037
56b8eb7c9c04 improvements in parsing classdef
John W. Eaton <jwe@octave.org>
parents: 14846
diff changeset
1678 $$ = $1;
56b8eb7c9c04 improvements in parsing classdef
John W. Eaton <jwe@octave.org>
parents: 14846
diff changeset
1679 }
56b8eb7c9c04 improvements in parsing classdef
John W. Eaton <jwe@octave.org>
parents: 14846
diff changeset
1680 ;
56b8eb7c9c04 improvements in parsing classdef
John W. Eaton <jwe@octave.org>
parents: 14846
diff changeset
1681
18520
932aca9a7c57 Allow multi-level classdef package.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 18419
diff changeset
1682 superclass : FQ_IDENT
932aca9a7c57 Allow multi-level classdef package.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 18419
diff changeset
1683 { $$ = new tree_classdef_superclass ($1->text ()); }
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
1684 ;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
1685
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
1686 class_body : properties_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 | methods_block
15037
56b8eb7c9c04 improvements in parsing classdef
John W. Eaton <jwe@octave.org>
parents: 14846
diff changeset
1689 { $$ = new tree_classdef_body ($1); }
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
1690 | events_block
15037
56b8eb7c9c04 improvements in parsing classdef
John W. Eaton <jwe@octave.org>
parents: 14846
diff changeset
1691 { $$ = new tree_classdef_body ($1); }
13249
7861a5fd3479 accept enumeration keyword
John W. Eaton <jwe@octave.org>
parents: 13246
diff changeset
1692 | enum_block
15037
56b8eb7c9c04 improvements in parsing classdef
John W. Eaton <jwe@octave.org>
parents: 14846
diff changeset
1693 { $$ = 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
1694 | class_body opt_sep properties_block
15037
56b8eb7c9c04 improvements in parsing classdef
John W. Eaton <jwe@octave.org>
parents: 14846
diff changeset
1695 {
19778
bf737d927707 eliminate bison warnings from oct-parse.yy
John W. Eaton <jwe@octave.org>
parents: 19709
diff changeset
1696 YYUSE ($2);
bf737d927707 eliminate bison warnings from oct-parse.yy
John W. Eaton <jwe@octave.org>
parents: 19709
diff changeset
1697
15037
56b8eb7c9c04 improvements in parsing classdef
John W. Eaton <jwe@octave.org>
parents: 14846
diff changeset
1698 $1->append ($3);
56b8eb7c9c04 improvements in parsing classdef
John W. Eaton <jwe@octave.org>
parents: 14846
diff changeset
1699 $$ = $1;
56b8eb7c9c04 improvements in parsing classdef
John W. Eaton <jwe@octave.org>
parents: 14846
diff changeset
1700 }
13250
f6bbdea030b2 use opt_sep instead of literal '\n' in parser rules for classdef
John W. Eaton <jwe@octave.org>
parents: 13249
diff changeset
1701 | class_body opt_sep methods_block
15037
56b8eb7c9c04 improvements in parsing classdef
John W. Eaton <jwe@octave.org>
parents: 14846
diff changeset
1702 {
19778
bf737d927707 eliminate bison warnings from oct-parse.yy
John W. Eaton <jwe@octave.org>
parents: 19709
diff changeset
1703 YYUSE ($2);
bf737d927707 eliminate bison warnings from oct-parse.yy
John W. Eaton <jwe@octave.org>
parents: 19709
diff changeset
1704
15037
56b8eb7c9c04 improvements in parsing classdef
John W. Eaton <jwe@octave.org>
parents: 14846
diff changeset
1705 $1->append ($3);
56b8eb7c9c04 improvements in parsing classdef
John W. Eaton <jwe@octave.org>
parents: 14846
diff changeset
1706 $$ = $1;
56b8eb7c9c04 improvements in parsing classdef
John W. Eaton <jwe@octave.org>
parents: 14846
diff changeset
1707 }
13250
f6bbdea030b2 use opt_sep instead of literal '\n' in parser rules for classdef
John W. Eaton <jwe@octave.org>
parents: 13249
diff changeset
1708 | class_body opt_sep events_block
15037
56b8eb7c9c04 improvements in parsing classdef
John W. Eaton <jwe@octave.org>
parents: 14846
diff changeset
1709 {
19778
bf737d927707 eliminate bison warnings from oct-parse.yy
John W. Eaton <jwe@octave.org>
parents: 19709
diff changeset
1710 YYUSE ($2);
bf737d927707 eliminate bison warnings from oct-parse.yy
John W. Eaton <jwe@octave.org>
parents: 19709
diff changeset
1711
15037
56b8eb7c9c04 improvements in parsing classdef
John W. Eaton <jwe@octave.org>
parents: 14846
diff changeset
1712 $1->append ($3);
56b8eb7c9c04 improvements in parsing classdef
John W. Eaton <jwe@octave.org>
parents: 14846
diff changeset
1713 $$ = $1;
56b8eb7c9c04 improvements in parsing classdef
John W. Eaton <jwe@octave.org>
parents: 14846
diff changeset
1714 }
13250
f6bbdea030b2 use opt_sep instead of literal '\n' in parser rules for classdef
John W. Eaton <jwe@octave.org>
parents: 13249
diff changeset
1715 | class_body opt_sep enum_block
15037
56b8eb7c9c04 improvements in parsing classdef
John W. Eaton <jwe@octave.org>
parents: 14846
diff changeset
1716 {
19778
bf737d927707 eliminate bison warnings from oct-parse.yy
John W. Eaton <jwe@octave.org>
parents: 19709
diff changeset
1717 YYUSE ($2);
bf737d927707 eliminate bison warnings from oct-parse.yy
John W. Eaton <jwe@octave.org>
parents: 19709
diff changeset
1718
15037
56b8eb7c9c04 improvements in parsing classdef
John W. Eaton <jwe@octave.org>
parents: 14846
diff changeset
1719 $1->append ($3);
56b8eb7c9c04 improvements in parsing classdef
John W. Eaton <jwe@octave.org>
parents: 14846
diff changeset
1720 $$ = $1;
56b8eb7c9c04 improvements in parsing classdef
John W. Eaton <jwe@octave.org>
parents: 14846
diff changeset
1721 }
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
1722 ;
9476
d9b25c5b8ee5 handle classdef syntax in lexer and parser
Ryan Rusaw
parents: 9474
diff changeset
1723
d9b25c5b8ee5 handle classdef syntax in lexer and parser
Ryan Rusaw
parents: 9474
diff changeset
1724 properties_block
15037
56b8eb7c9c04 improvements in parsing classdef
John W. Eaton <jwe@octave.org>
parents: 14846
diff changeset
1725 : 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
1726 {
19778
bf737d927707 eliminate bison warnings from oct-parse.yy
John W. Eaton <jwe@octave.org>
parents: 19709
diff changeset
1727 YYUSE ($4);
bf737d927707 eliminate bison warnings from oct-parse.yy
John W. Eaton <jwe@octave.org>
parents: 19709
diff changeset
1728 YYUSE ($6);
bf737d927707 eliminate bison warnings from oct-parse.yy
John W. Eaton <jwe@octave.org>
parents: 19709
diff changeset
1729
16289
bde729ba8381 maint: periodic merge of default to classdef
John W. Eaton <jwe@octave.org>
parents: 16286 16288
diff changeset
1730 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
1731 ($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
1732 {
2b1047efc4fb don't leak memory when parsing classdef objects fails
John W. Eaton <jwe@octave.org>
parents: 17654
diff changeset
1733 // make_classdef_properties_block delete $3 and $5.
21073
f7cc48f601d2 additional reworking of error handling in the parser (bug #46877)
John W. Eaton <jwe@octave.org>
parents: 21071
diff changeset
1734 YYABORT;
17656
2b1047efc4fb don't leak memory when parsing classdef objects fails
John W. Eaton <jwe@octave.org>
parents: 17654
diff changeset
1735 }
15037
56b8eb7c9c04 improvements in parsing classdef
John W. Eaton <jwe@octave.org>
parents: 14846
diff changeset
1736 }
18419
9154dc252f47 Allow empty classdef or methods/properties/... blocks
Michael Goffioul <michael.goffioul@gmail.com>
parents: 18395
diff changeset
1737 | 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
1738 {
19778
bf737d927707 eliminate bison warnings from oct-parse.yy
John W. Eaton <jwe@octave.org>
parents: 19709
diff changeset
1739 YYUSE ($4);
bf737d927707 eliminate bison warnings from oct-parse.yy
John W. Eaton <jwe@octave.org>
parents: 19709
diff changeset
1740
18419
9154dc252f47 Allow empty classdef or methods/properties/... blocks
Michael Goffioul <michael.goffioul@gmail.com>
parents: 18395
diff changeset
1741 if (! ($$ = parser.make_classdef_properties_block
9154dc252f47 Allow empty classdef or methods/properties/... blocks
Michael Goffioul <michael.goffioul@gmail.com>
parents: 18395
diff changeset
1742 ($1, $3, 0, $5, $2)))
9154dc252f47 Allow empty classdef or methods/properties/... blocks
Michael Goffioul <michael.goffioul@gmail.com>
parents: 18395
diff changeset
1743 {
9154dc252f47 Allow empty classdef or methods/properties/... blocks
Michael Goffioul <michael.goffioul@gmail.com>
parents: 18395
diff changeset
1744 // make_classdef_properties_block delete $3.
21073
f7cc48f601d2 additional reworking of error handling in the parser (bug #46877)
John W. Eaton <jwe@octave.org>
parents: 21071
diff changeset
1745 YYABORT;
18419
9154dc252f47 Allow empty classdef or methods/properties/... blocks
Michael Goffioul <michael.goffioul@gmail.com>
parents: 18395
diff changeset
1746 }
9154dc252f47 Allow empty classdef or methods/properties/... blocks
Michael Goffioul <michael.goffioul@gmail.com>
parents: 18395
diff changeset
1747 }
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
1748 ;
9476
d9b25c5b8ee5 handle classdef syntax in lexer and parser
Ryan Rusaw
parents: 9474
diff changeset
1749
15037
56b8eb7c9c04 improvements in parsing classdef
John W. Eaton <jwe@octave.org>
parents: 14846
diff changeset
1750 property_list
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
1751 : class_property
15037
56b8eb7c9c04 improvements in parsing classdef
John W. Eaton <jwe@octave.org>
parents: 14846
diff changeset
1752 { $$ = new tree_classdef_property_list ($1); }
56b8eb7c9c04 improvements in parsing classdef
John W. Eaton <jwe@octave.org>
parents: 14846
diff changeset
1753 | property_list opt_sep class_property
56b8eb7c9c04 improvements in parsing classdef
John W. Eaton <jwe@octave.org>
parents: 14846
diff changeset
1754 {
19778
bf737d927707 eliminate bison warnings from oct-parse.yy
John W. Eaton <jwe@octave.org>
parents: 19709
diff changeset
1755 YYUSE ($2);
bf737d927707 eliminate bison warnings from oct-parse.yy
John W. Eaton <jwe@octave.org>
parents: 19709
diff changeset
1756
15037
56b8eb7c9c04 improvements in parsing classdef
John W. Eaton <jwe@octave.org>
parents: 14846
diff changeset
1757 $1->append ($3);
56b8eb7c9c04 improvements in parsing classdef
John W. Eaton <jwe@octave.org>
parents: 14846
diff changeset
1758 $$ = $1;
56b8eb7c9c04 improvements in parsing classdef
John W. Eaton <jwe@octave.org>
parents: 14846
diff changeset
1759 }
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
1760 ;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
1761
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
1762 class_property : identifier
15037
56b8eb7c9c04 improvements in parsing classdef
John W. Eaton <jwe@octave.org>
parents: 14846
diff changeset
1763 { $$ = new tree_classdef_property ($1); }
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
1764 | identifier '=' decl_param_init expression ';'
15037
56b8eb7c9c04 improvements in parsing classdef
John W. Eaton <jwe@octave.org>
parents: 14846
diff changeset
1765 {
19778
bf737d927707 eliminate bison warnings from oct-parse.yy
John W. Eaton <jwe@octave.org>
parents: 19709
diff changeset
1766 YYUSE ($2);
bf737d927707 eliminate bison warnings from oct-parse.yy
John W. Eaton <jwe@octave.org>
parents: 19709
diff changeset
1767
16289
bde729ba8381 maint: periodic merge of default to classdef
John W. Eaton <jwe@octave.org>
parents: 16286 16288
diff changeset
1768 lexer.looking_at_initializer_expression = false;
15037
56b8eb7c9c04 improvements in parsing classdef
John W. Eaton <jwe@octave.org>
parents: 14846
diff changeset
1769 $$ = new tree_classdef_property ($1, $4);
56b8eb7c9c04 improvements in parsing classdef
John W. Eaton <jwe@octave.org>
parents: 14846
diff changeset
1770 }
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
1771 ;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
1772
15037
56b8eb7c9c04 improvements in parsing classdef
John W. Eaton <jwe@octave.org>
parents: 14846
diff changeset
1773 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
1774 {
19778
bf737d927707 eliminate bison warnings from oct-parse.yy
John W. Eaton <jwe@octave.org>
parents: 19709
diff changeset
1775 YYUSE ($4);
bf737d927707 eliminate bison warnings from oct-parse.yy
John W. Eaton <jwe@octave.org>
parents: 19709
diff changeset
1776 YYUSE ($6);
bf737d927707 eliminate bison warnings from oct-parse.yy
John W. Eaton <jwe@octave.org>
parents: 19709
diff changeset
1777
16289
bde729ba8381 maint: periodic merge of default to classdef
John W. Eaton <jwe@octave.org>
parents: 16286 16288
diff changeset
1778 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
1779 ($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
1780 {
2b1047efc4fb don't leak memory when parsing classdef objects fails
John W. Eaton <jwe@octave.org>
parents: 17654
diff changeset
1781 // make_classdef_methods_block deleted $3 and $5.
21073
f7cc48f601d2 additional reworking of error handling in the parser (bug #46877)
John W. Eaton <jwe@octave.org>
parents: 21071
diff changeset
1782 YYABORT;
17656
2b1047efc4fb don't leak memory when parsing classdef objects fails
John W. Eaton <jwe@octave.org>
parents: 17654
diff changeset
1783 }
15037
56b8eb7c9c04 improvements in parsing classdef
John W. Eaton <jwe@octave.org>
parents: 14846
diff changeset
1784 }
18419
9154dc252f47 Allow empty classdef or methods/properties/... blocks
Michael Goffioul <michael.goffioul@gmail.com>
parents: 18395
diff changeset
1785 | 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
1786 {
19778
bf737d927707 eliminate bison warnings from oct-parse.yy
John W. Eaton <jwe@octave.org>
parents: 19709
diff changeset
1787 YYUSE ($4);
bf737d927707 eliminate bison warnings from oct-parse.yy
John W. Eaton <jwe@octave.org>
parents: 19709
diff changeset
1788
18419
9154dc252f47 Allow empty classdef or methods/properties/... blocks
Michael Goffioul <michael.goffioul@gmail.com>
parents: 18395
diff changeset
1789 if (! ($$ = parser.make_classdef_methods_block
9154dc252f47 Allow empty classdef or methods/properties/... blocks
Michael Goffioul <michael.goffioul@gmail.com>
parents: 18395
diff changeset
1790 ($1, $3, 0, $5, $2)))
9154dc252f47 Allow empty classdef or methods/properties/... blocks
Michael Goffioul <michael.goffioul@gmail.com>
parents: 18395
diff changeset
1791 {
9154dc252f47 Allow empty classdef or methods/properties/... blocks
Michael Goffioul <michael.goffioul@gmail.com>
parents: 18395
diff changeset
1792 // make_classdef_methods_block deleted $3.
21073
f7cc48f601d2 additional reworking of error handling in the parser (bug #46877)
John W. Eaton <jwe@octave.org>
parents: 21071
diff changeset
1793 YYABORT;
18419
9154dc252f47 Allow empty classdef or methods/properties/... blocks
Michael Goffioul <michael.goffioul@gmail.com>
parents: 18395
diff changeset
1794 }
9154dc252f47 Allow empty classdef or methods/properties/... blocks
Michael Goffioul <michael.goffioul@gmail.com>
parents: 18395
diff changeset
1795 }
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
1796 ;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
1797 ;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
1798
18262
69990d5edcc2 Allow to parse external methods declaration in classdef files.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 18158
diff changeset
1799 method_decl1 : identifier
18308
c1baf94184af * oct-parse.in.yy: Suppress TAB characters.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 18304
diff changeset
1800 {
18262
69990d5edcc2 Allow to parse external methods declaration in classdef files.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 18158
diff changeset
1801 if (! ($$ = parser.start_classdef_external_method ($1, 0)))
21073
f7cc48f601d2 additional reworking of error handling in the parser (bug #46877)
John W. Eaton <jwe@octave.org>
parents: 21071
diff changeset
1802 YYABORT;
18262
69990d5edcc2 Allow to parse external methods declaration in classdef files.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 18158
diff changeset
1803 }
18308
c1baf94184af * oct-parse.in.yy: Suppress TAB characters.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 18304
diff changeset
1804 | identifier param_list
18341
02b349ccf0ec Allow "end" method declaration/definition in classde files.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 18308
diff changeset
1805 {
02b349ccf0ec Allow "end" method declaration/definition in classde files.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 18308
diff changeset
1806 if (! ($$ = parser.start_classdef_external_method ($1, $2)))
21073
f7cc48f601d2 additional reworking of error handling in the parser (bug #46877)
John W. Eaton <jwe@octave.org>
parents: 21071
diff changeset
1807 YYABORT;
18262
69990d5edcc2 Allow to parse external methods declaration in classdef files.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 18158
diff changeset
1808 }
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
1809 ;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
1810
18262
69990d5edcc2 Allow to parse external methods declaration in classdef files.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 18158
diff changeset
1811 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
1812 { $$ = 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
1813 | stash_comment return_list '='
02b349ccf0ec Allow "end" method declaration/definition in classde files.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 18308
diff changeset
1814 {
19778
bf737d927707 eliminate bison warnings from oct-parse.yy
John W. Eaton <jwe@octave.org>
parents: 19709
diff changeset
1815 YYUSE ($3);
bf737d927707 eliminate bison warnings from oct-parse.yy
John W. Eaton <jwe@octave.org>
parents: 19709
diff changeset
1816
18341
02b349ccf0ec Allow "end" method declaration/definition in classde files.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 18308
diff changeset
1817 lexer.defining_func++;
02b349ccf0ec Allow "end" method declaration/definition in classde files.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 18308
diff changeset
1818 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
1819 }
02b349ccf0ec Allow "end" method declaration/definition in classde files.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 18308
diff changeset
1820 method_decl1
02b349ccf0ec Allow "end" method declaration/definition in classde files.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 18308
diff changeset
1821 {
02b349ccf0ec Allow "end" method declaration/definition in classde files.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 18308
diff changeset
1822 lexer.defining_func--;
02b349ccf0ec Allow "end" method declaration/definition in classde files.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 18308
diff changeset
1823 lexer.parsed_function_name.pop ();
02b349ccf0ec Allow "end" method declaration/definition in classde files.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 18308
diff changeset
1824 $$ = 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
1825 }
18262
69990d5edcc2 Allow to parse external methods declaration in classdef files.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 18158
diff changeset
1826 ;
69990d5edcc2 Allow to parse external methods declaration in classdef files.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 18158
diff changeset
1827
69990d5edcc2 Allow to parse external methods declaration in classdef files.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 18158
diff changeset
1828 method : method_decl
18308
c1baf94184af * oct-parse.in.yy: Suppress TAB characters.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 18304
diff changeset
1829 { $$ = $1; }
c1baf94184af * oct-parse.in.yy: Suppress TAB characters.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 18304
diff changeset
1830 | function
18262
69990d5edcc2 Allow to parse external methods declaration in classdef files.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 18158
diff changeset
1831 { $$ = $1; }
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
1832 ;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
1833
18262
69990d5edcc2 Allow to parse external methods declaration in classdef files.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 18158
diff changeset
1834 methods_list : method
15037
56b8eb7c9c04 improvements in parsing classdef
John W. Eaton <jwe@octave.org>
parents: 14846
diff changeset
1835 {
56b8eb7c9c04 improvements in parsing classdef
John W. Eaton <jwe@octave.org>
parents: 14846
diff changeset
1836 octave_value fcn;
56b8eb7c9c04 improvements in parsing classdef
John W. Eaton <jwe@octave.org>
parents: 14846
diff changeset
1837 if ($1)
56b8eb7c9c04 improvements in parsing classdef
John W. Eaton <jwe@octave.org>
parents: 14846
diff changeset
1838 fcn = $1->function ();
56b8eb7c9c04 improvements in parsing classdef
John W. Eaton <jwe@octave.org>
parents: 14846
diff changeset
1839 delete $1;
56b8eb7c9c04 improvements in parsing classdef
John W. Eaton <jwe@octave.org>
parents: 14846
diff changeset
1840 $$ = new tree_classdef_methods_list (fcn);
56b8eb7c9c04 improvements in parsing classdef
John W. Eaton <jwe@octave.org>
parents: 14846
diff changeset
1841 }
18262
69990d5edcc2 Allow to parse external methods declaration in classdef files.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 18158
diff changeset
1842 | methods_list opt_sep method
15037
56b8eb7c9c04 improvements in parsing classdef
John W. Eaton <jwe@octave.org>
parents: 14846
diff changeset
1843 {
19778
bf737d927707 eliminate bison warnings from oct-parse.yy
John W. Eaton <jwe@octave.org>
parents: 19709
diff changeset
1844 YYUSE ($2);
bf737d927707 eliminate bison warnings from oct-parse.yy
John W. Eaton <jwe@octave.org>
parents: 19709
diff changeset
1845
15037
56b8eb7c9c04 improvements in parsing classdef
John W. Eaton <jwe@octave.org>
parents: 14846
diff changeset
1846 octave_value fcn;
56b8eb7c9c04 improvements in parsing classdef
John W. Eaton <jwe@octave.org>
parents: 14846
diff changeset
1847 if ($3)
56b8eb7c9c04 improvements in parsing classdef
John W. Eaton <jwe@octave.org>
parents: 14846
diff changeset
1848 fcn = $3->function ();
56b8eb7c9c04 improvements in parsing classdef
John W. Eaton <jwe@octave.org>
parents: 14846
diff changeset
1849 delete $3;
56b8eb7c9c04 improvements in parsing classdef
John W. Eaton <jwe@octave.org>
parents: 14846
diff changeset
1850
56b8eb7c9c04 improvements in parsing classdef
John W. Eaton <jwe@octave.org>
parents: 14846
diff changeset
1851 $1->append (fcn);
56b8eb7c9c04 improvements in parsing classdef
John W. Eaton <jwe@octave.org>
parents: 14846
diff changeset
1852 $$ = $1;
56b8eb7c9c04 improvements in parsing classdef
John W. Eaton <jwe@octave.org>
parents: 14846
diff changeset
1853 }
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
1854 ;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
1855
15037
56b8eb7c9c04 improvements in parsing classdef
John W. Eaton <jwe@octave.org>
parents: 14846
diff changeset
1856 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
1857 {
19778
bf737d927707 eliminate bison warnings from oct-parse.yy
John W. Eaton <jwe@octave.org>
parents: 19709
diff changeset
1858 YYUSE ($4);
bf737d927707 eliminate bison warnings from oct-parse.yy
John W. Eaton <jwe@octave.org>
parents: 19709
diff changeset
1859 YYUSE ($6);
bf737d927707 eliminate bison warnings from oct-parse.yy
John W. Eaton <jwe@octave.org>
parents: 19709
diff changeset
1860
16289
bde729ba8381 maint: periodic merge of default to classdef
John W. Eaton <jwe@octave.org>
parents: 16286 16288
diff changeset
1861 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
1862 ($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
1863 {
2b1047efc4fb don't leak memory when parsing classdef objects fails
John W. Eaton <jwe@octave.org>
parents: 17654
diff changeset
1864 // make_classdef_events_block deleted $3 and $5.
21073
f7cc48f601d2 additional reworking of error handling in the parser (bug #46877)
John W. Eaton <jwe@octave.org>
parents: 21071
diff changeset
1865 YYABORT;
17656
2b1047efc4fb don't leak memory when parsing classdef objects fails
John W. Eaton <jwe@octave.org>
parents: 17654
diff changeset
1866 }
15037
56b8eb7c9c04 improvements in parsing classdef
John W. Eaton <jwe@octave.org>
parents: 14846
diff changeset
1867 }
18419
9154dc252f47 Allow empty classdef or methods/properties/... blocks
Michael Goffioul <michael.goffioul@gmail.com>
parents: 18395
diff changeset
1868 | 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
1869 {
19778
bf737d927707 eliminate bison warnings from oct-parse.yy
John W. Eaton <jwe@octave.org>
parents: 19709
diff changeset
1870 YYUSE ($4);
bf737d927707 eliminate bison warnings from oct-parse.yy
John W. Eaton <jwe@octave.org>
parents: 19709
diff changeset
1871
18419
9154dc252f47 Allow empty classdef or methods/properties/... blocks
Michael Goffioul <michael.goffioul@gmail.com>
parents: 18395
diff changeset
1872 if (! ($$ = parser.make_classdef_events_block
9154dc252f47 Allow empty classdef or methods/properties/... blocks
Michael Goffioul <michael.goffioul@gmail.com>
parents: 18395
diff changeset
1873 ($1, $3, 0, $5, $2)))
9154dc252f47 Allow empty classdef or methods/properties/... blocks
Michael Goffioul <michael.goffioul@gmail.com>
parents: 18395
diff changeset
1874 {
9154dc252f47 Allow empty classdef or methods/properties/... blocks
Michael Goffioul <michael.goffioul@gmail.com>
parents: 18395
diff changeset
1875 // make_classdef_events_block deleted $3.
21073
f7cc48f601d2 additional reworking of error handling in the parser (bug #46877)
John W. Eaton <jwe@octave.org>
parents: 21071
diff changeset
1876 YYABORT;
18419
9154dc252f47 Allow empty classdef or methods/properties/... blocks
Michael Goffioul <michael.goffioul@gmail.com>
parents: 18395
diff changeset
1877 }
9154dc252f47 Allow empty classdef or methods/properties/... blocks
Michael Goffioul <michael.goffioul@gmail.com>
parents: 18395
diff changeset
1878 }
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
1879 ;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
1880
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
1881 events_list : class_event
15037
56b8eb7c9c04 improvements in parsing classdef
John W. Eaton <jwe@octave.org>
parents: 14846
diff changeset
1882 { $$ = 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
1883 | events_list opt_sep class_event
15037
56b8eb7c9c04 improvements in parsing classdef
John W. Eaton <jwe@octave.org>
parents: 14846
diff changeset
1884 {
19778
bf737d927707 eliminate bison warnings from oct-parse.yy
John W. Eaton <jwe@octave.org>
parents: 19709
diff changeset
1885 YYUSE ($2);
bf737d927707 eliminate bison warnings from oct-parse.yy
John W. Eaton <jwe@octave.org>
parents: 19709
diff changeset
1886
15037
56b8eb7c9c04 improvements in parsing classdef
John W. Eaton <jwe@octave.org>
parents: 14846
diff changeset
1887 $1->append ($3);
56b8eb7c9c04 improvements in parsing classdef
John W. Eaton <jwe@octave.org>
parents: 14846
diff changeset
1888 $$ = $1;
56b8eb7c9c04 improvements in parsing classdef
John W. Eaton <jwe@octave.org>
parents: 14846
diff changeset
1889 }
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
1890 ;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
1891
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
1892 class_event : identifier
15037
56b8eb7c9c04 improvements in parsing classdef
John W. Eaton <jwe@octave.org>
parents: 14846
diff changeset
1893 { $$ = new tree_classdef_event ($1); }
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
1894 ;
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11572
diff changeset
1895
15037
56b8eb7c9c04 improvements in parsing classdef
John W. Eaton <jwe@octave.org>
parents: 14846
diff changeset
1896 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
1897 {
19778
bf737d927707 eliminate bison warnings from oct-parse.yy
John W. Eaton <jwe@octave.org>
parents: 19709
diff changeset
1898 YYUSE ($4);
bf737d927707 eliminate bison warnings from oct-parse.yy
John W. Eaton <jwe@octave.org>
parents: 19709
diff changeset
1899 YYUSE ($6);
bf737d927707 eliminate bison warnings from oct-parse.yy
John W. Eaton <jwe@octave.org>
parents: 19709
diff changeset
1900
16289
bde729ba8381 maint: periodic merge of default to classdef
John W. Eaton <jwe@octave.org>
parents: 16286 16288
diff changeset
1901 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
1902 ($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
1903 {
2b1047efc4fb don't leak memory when parsing classdef objects fails
John W. Eaton <jwe@octave.org>
parents: 17654
diff changeset
1904 // make_classdef_enum_block deleted $3 and $5.
21073
f7cc48f601d2 additional reworking of error handling in the parser (bug #46877)
John W. Eaton <jwe@octave.org>
parents: 21071
diff changeset
1905 YYABORT;
17656
2b1047efc4fb don't leak memory when parsing classdef objects fails
John W. Eaton <jwe@octave.org>
parents: 17654
diff changeset
1906 }
15037
56b8eb7c9c04 improvements in parsing classdef
John W. Eaton <jwe@octave.org>
parents: 14846
diff changeset
1907 }
18419
9154dc252f47 Allow empty classdef or methods/properties/... blocks
Michael Goffioul <michael.goffioul@gmail.com>
parents: 18395
diff changeset
1908 | 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
1909 {
19778
bf737d927707 eliminate bison warnings from oct-parse.yy
John W. Eaton <jwe@octave.org>
parents: 19709
diff changeset
1910 YYUSE ($4);
bf737d927707 eliminate bison warnings from oct-parse.yy
John W. Eaton <jwe@octave.org>
parents: 19709
diff changeset
1911
18419
9154dc252f47 Allow empty classdef or methods/properties/... blocks
Michael Goffioul <michael.goffioul@gmail.com>
parents: 18395
diff changeset
1912 if (! ($$ = parser.make_classdef_enum_block
9154dc252f47 Allow empty classdef or methods/properties/... blocks
Michael Goffioul <michael.goffioul@gmail.com>
parents: 18395
diff changeset
1913 ($1, $3, 0, $5, $2)))
9154dc252f47 Allow empty classdef or methods/properties/... blocks
Michael Goffioul <michael.goffioul@gmail.com>
parents: 18395
diff changeset
1914 {
9154dc252f47 Allow empty classdef or methods/properties/... blocks
Michael Goffioul <michael.goffioul@gmail.com>
parents: 18395
diff changeset
1915 // make_classdef_enum_block deleted $3.
21073
f7cc48f601d2 additional reworking of error handling in the parser (bug #46877)
John W. Eaton <jwe@octave.org>
parents: 21071
diff changeset
1916 YYABORT;
18419
9154dc252f47 Allow empty classdef or methods/properties/... blocks
Michael Goffioul <michael.goffioul@gmail.com>
parents: 18395
diff changeset
1917 }
9154dc252f47 Allow empty classdef or methods/properties/... blocks
Michael Goffioul <michael.goffioul@gmail.com>
parents: 18395
diff changeset
1918 }
13249
7861a5fd3479 accept enumeration keyword
John W. Eaton <jwe@octave.org>
parents: 13246
diff changeset
1919 ;
7861a5fd3479 accept enumeration keyword
John W. Eaton <jwe@octave.org>
parents: 13246
diff changeset
1920
7861a5fd3479 accept enumeration keyword
John W. Eaton <jwe@octave.org>
parents: 13246
diff changeset
1921 enum_list : class_enum
15037
56b8eb7c9c04 improvements in parsing classdef
John W. Eaton <jwe@octave.org>
parents: 14846
diff changeset
1922 { $$ = 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
1923 | enum_list opt_sep class_enum
15037
56b8eb7c9c04 improvements in parsing classdef
John W. Eaton <jwe@octave.org>
parents: 14846
diff changeset
1924 {
19778
bf737d927707 eliminate bison warnings from oct-parse.yy
John W. Eaton <jwe@octave.org>
parents: 19709
diff changeset
1925 YYUSE ($2);
bf737d927707 eliminate bison warnings from oct-parse.yy
John W. Eaton <jwe@octave.org>
parents: 19709
diff changeset
1926
15037
56b8eb7c9c04 improvements in parsing classdef
John W. Eaton <jwe@octave.org>
parents: 14846
diff changeset
1927 $1->append ($3);
56b8eb7c9c04 improvements in parsing classdef
John W. Eaton <jwe@octave.org>
parents: 14846
diff changeset
1928 $$ = $1;
56b8eb7c9c04 improvements in parsing classdef
John W. Eaton <jwe@octave.org>
parents: 14846
diff changeset
1929 }
13249
7861a5fd3479 accept enumeration keyword
John W. Eaton <jwe@octave.org>
parents: 13246
diff changeset
1930 ;
7861a5fd3479 accept enumeration keyword
John W. Eaton <jwe@octave.org>
parents: 13246
diff changeset
1931
7861a5fd3479 accept enumeration keyword
John W. Eaton <jwe@octave.org>
parents: 13246
diff changeset
1932 class_enum : identifier '(' expression ')'
15037
56b8eb7c9c04 improvements in parsing classdef
John W. Eaton <jwe@octave.org>
parents: 14846
diff changeset
1933 { $$ = new tree_classdef_enum ($1, $3); }
13249
7861a5fd3479 accept enumeration keyword
John W. Eaton <jwe@octave.org>
parents: 13246
diff changeset
1934 ;
7861a5fd3479 accept enumeration keyword
John W. Eaton <jwe@octave.org>
parents: 13246
diff changeset
1935
2970
b9e64477f703 [project @ 1997-05-15 18:04:21 by jwe]
jwe
parents: 2961
diff changeset
1936 // =============
b9e64477f703 [project @ 1997-05-15 18:04:21 by jwe]
jwe
parents: 2961
diff changeset
1937 // Miscellaneous
b9e64477f703 [project @ 1997-05-15 18:04:21 by jwe]
jwe
parents: 2961
diff changeset
1938 // =============
b9e64477f703 [project @ 1997-05-15 18:04:21 by jwe]
jwe
parents: 2961
diff changeset
1939
16681
d3619d4d267c recognize character string at beginning of statement (bug #38926, #38958)
John W. Eaton <jwe@octave.org>
parents: 16627
diff changeset
1940 stmt_begin : // empty
19778
bf737d927707 eliminate bison warnings from oct-parse.yy
John W. Eaton <jwe@octave.org>
parents: 19709
diff changeset
1941 {
bf737d927707 eliminate bison warnings from oct-parse.yy
John W. Eaton <jwe@octave.org>
parents: 19709
diff changeset
1942 $$ = 0;
bf737d927707 eliminate bison warnings from oct-parse.yy
John W. Eaton <jwe@octave.org>
parents: 19709
diff changeset
1943 lexer.at_beginning_of_statement = true;
bf737d927707 eliminate bison warnings from oct-parse.yy
John W. Eaton <jwe@octave.org>
parents: 19709
diff changeset
1944 }
16681
d3619d4d267c recognize character string at beginning of statement (bug #38926, #38958)
John W. Eaton <jwe@octave.org>
parents: 16627
diff changeset
1945 ;
d3619d4d267c recognize character string at beginning of statement (bug #38926, #38958)
John W. Eaton <jwe@octave.org>
parents: 16627
diff changeset
1946
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
1947 stash_comment : // empty
17693
efbe746f8fa8 eliminate octave_comment_buffer singleton
John W. Eaton <jwe@octave.org>
parents: 17673
diff changeset
1948 { $$ = lexer.get_comment (); }
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
1949 ;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
1950
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
1951 parse_error : LEXICAL_ERROR
19778
bf737d927707 eliminate bison warnings from oct-parse.yy
John W. Eaton <jwe@octave.org>
parents: 19709
diff changeset
1952 {
bf737d927707 eliminate bison warnings from oct-parse.yy
John W. Eaton <jwe@octave.org>
parents: 19709
diff changeset
1953 $$ = 0;
21064
a9f2c2d72892 handle lexical errors as parser errors (bug #46877)
John W. Eaton <jwe@octave.org>
parents: 21063
diff changeset
1954 std::string msg = $1->text ();
a9f2c2d72892 handle lexical errors as parser errors (bug #46877)
John W. Eaton <jwe@octave.org>
parents: 21063
diff changeset
1955 parser.bison_error (msg.c_str ());
19778
bf737d927707 eliminate bison warnings from oct-parse.yy
John W. Eaton <jwe@octave.org>
parents: 19709
diff changeset
1956 }
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
1957 | error
19778
bf737d927707 eliminate bison warnings from oct-parse.yy
John W. Eaton <jwe@octave.org>
parents: 19709
diff changeset
1958 { $$ = 0; }
10315
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 sep_no_nl : ','
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
1962 { $$ = ','; }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
1963 | ';'
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
1964 { $$ = ';'; }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
1965 | sep_no_nl ','
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
1966 { $$ = $1; }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
1967 | sep_no_nl ';'
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
1968 { $$ = $1; }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
1969 ;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
1970
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
1971 opt_sep_no_nl : // empty
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
1972 { $$ = 0; }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
1973 | sep_no_nl
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
1974 { $$ = $1; }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
1975 ;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
1976
16203
127cccb037bf move more global parser and lexer variables to classes
John W. Eaton <jwe@octave.org>
parents: 16199
diff changeset
1977 opt_nl : // empty
127cccb037bf move more global parser and lexer variables to classes
John W. Eaton <jwe@octave.org>
parents: 16199
diff changeset
1978 { $$ = 0; }
127cccb037bf move more global parser and lexer variables to classes
John W. Eaton <jwe@octave.org>
parents: 16199
diff changeset
1979 | nl
127cccb037bf move more global parser and lexer variables to classes
John W. Eaton <jwe@octave.org>
parents: 16199
diff changeset
1980 { $$ = $1; }
127cccb037bf move more global parser and lexer variables to classes
John W. Eaton <jwe@octave.org>
parents: 16199
diff changeset
1981 ;
127cccb037bf move more global parser and lexer variables to classes
John W. Eaton <jwe@octave.org>
parents: 16199
diff changeset
1982
127cccb037bf move more global parser and lexer variables to classes
John W. Eaton <jwe@octave.org>
parents: 16199
diff changeset
1983 nl : '\n'
127cccb037bf move more global parser and lexer variables to classes
John W. Eaton <jwe@octave.org>
parents: 16199
diff changeset
1984 { $$ = '\n'; }
127cccb037bf move more global parser and lexer variables to classes
John W. Eaton <jwe@octave.org>
parents: 16199
diff changeset
1985 | nl '\n'
127cccb037bf move more global parser and lexer variables to classes
John W. Eaton <jwe@octave.org>
parents: 16199
diff changeset
1986 { $$ = $1; }
127cccb037bf move more global parser and lexer variables to classes
John W. Eaton <jwe@octave.org>
parents: 16199
diff changeset
1987 ;
127cccb037bf move more global parser and lexer variables to classes
John W. Eaton <jwe@octave.org>
parents: 16199
diff changeset
1988
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
1989 sep : ','
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
1990 { $$ = ','; }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
1991 | ';'
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
1992 { $$ = ';'; }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
1993 | '\n'
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
1994 { $$ = '\n'; }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
1995 | sep ','
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
1996 { $$ = $1; }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
1997 | sep ';'
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
1998 { $$ = $1; }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
1999 | sep '\n'
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
2000 { $$ = $1; }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
2001 ;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
2002
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
2003 opt_sep : // empty
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
2004 { $$ = 0; }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
2005 | sep
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
2006 { $$ = $1; }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
2007 ;
2525
8561d88be5f2 [project @ 1996-11-17 21:23:31 by jwe]
jwe
parents: 2524
diff changeset
2008
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
2009 %%
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
2010
21023
ec532a439c6f rework method of disabling warnings from GCC
John W. Eaton <jwe@octave.org>
parents: 21021
diff changeset
2011 #if defined (HAVE_PRAGMA_GCC_DIAGNOSTIC)
ec532a439c6f rework method of disabling warnings from GCC
John W. Eaton <jwe@octave.org>
parents: 21021
diff changeset
2012 // Restore prevailing warning state for remainder of the file.
ec532a439c6f rework method of disabling warnings from GCC
John W. Eaton <jwe@octave.org>
parents: 21021
diff changeset
2013 #pragma GCC diagnostic pop
ec532a439c6f rework method of disabling warnings from GCC
John W. Eaton <jwe@octave.org>
parents: 21021
diff changeset
2014 #endif
ec532a439c6f rework method of disabling warnings from GCC
John W. Eaton <jwe@octave.org>
parents: 21021
diff changeset
2015
666
fb4f6556b443 [project @ 1994-09-06 21:22:46 by jwe]
jwe
parents: 627
diff changeset
2016 // Generic error messages.
fb4f6556b443 [project @ 1994-09-06 21:22:46 by jwe]
jwe
parents: 627
diff changeset
2017
16288
fe3b9a51e625 rename curr_lexer, curr_parser, CURR_LEXER
John W. Eaton <jwe@octave.org>
parents: 16287
diff changeset
2018 #undef lexer
16149
49dfba4fd3c5 use pure parser and reentrant lexer interfaces
John W. Eaton <jwe@octave.org>
parents: 16147
diff changeset
2019
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
2020 static void
16288
fe3b9a51e625 rename curr_lexer, curr_parser, CURR_LEXER
John W. Eaton <jwe@octave.org>
parents: 16287
diff changeset
2021 yyerror (octave_base_parser& parser, const char *s)
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
2022 {
16288
fe3b9a51e625 rename curr_lexer, curr_parser, CURR_LEXER
John W. Eaton <jwe@octave.org>
parents: 16287
diff changeset
2023 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
2024 }
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
2025
21063
202cfd2b4514 store parser state in base class; use it in push and pull parsers
John W. Eaton <jwe@octave.org>
parents: 21055
diff changeset
2026 octave_base_parser::octave_base_parser (octave_base_lexer& lxr)
202cfd2b4514 store parser state in base class; use it in push and pull parsers
John W. Eaton <jwe@octave.org>
parents: 21055
diff changeset
2027 : endfunction_found (false), autoloading (false),
202cfd2b4514 store parser state in base class; use it in push and pull parsers
John W. Eaton <jwe@octave.org>
parents: 21055
diff changeset
2028 fcn_file_from_relative_lookup (false), parsing_subfunctions (false),
202cfd2b4514 store parser state in base class; use it in push and pull parsers
John W. Eaton <jwe@octave.org>
parents: 21055
diff changeset
2029 max_fcn_depth (0), curr_fcn_depth (0), primary_fcn_scope (-1),
202cfd2b4514 store parser state in base class; use it in push and pull parsers
John W. Eaton <jwe@octave.org>
parents: 21055
diff changeset
2030 curr_class_name (), curr_package_name (), function_scopes (),
202cfd2b4514 store parser state in base class; use it in push and pull parsers
John W. Eaton <jwe@octave.org>
parents: 21055
diff changeset
2031 primary_fcn_ptr (0), subfunction_names (), classdef_object (0),
202cfd2b4514 store parser state in base class; use it in push and pull parsers
John W. Eaton <jwe@octave.org>
parents: 21055
diff changeset
2032 stmt_list (0), lexer (lxr), parser_state (yypstate_new ())
202cfd2b4514 store parser state in base class; use it in push and pull parsers
John W. Eaton <jwe@octave.org>
parents: 21055
diff changeset
2033 { }
202cfd2b4514 store parser state in base class; use it in push and pull parsers
John W. Eaton <jwe@octave.org>
parents: 21055
diff changeset
2034
16287
04a7953496a7 create base class for parser; use reference for curr_lexer
John W. Eaton <jwe@octave.org>
parents: 16285
diff changeset
2035 octave_base_parser::~octave_base_parser (void)
16157
335041cc657a optionally use push parser interface
John W. Eaton <jwe@octave.org>
parents: 16153
diff changeset
2036 {
16177
a7669b4d27f6 eliminate global global_command variable
John W. Eaton <jwe@octave.org>
parents: 16174
diff changeset
2037 delete stmt_list;
a7669b4d27f6 eliminate global global_command variable
John W. Eaton <jwe@octave.org>
parents: 16174
diff changeset
2038
16288
fe3b9a51e625 rename curr_lexer, curr_parser, CURR_LEXER
John W. Eaton <jwe@octave.org>
parents: 16287
diff changeset
2039 delete &lexer;
21063
202cfd2b4514 store parser state in base class; use it in push and pull parsers
John W. Eaton <jwe@octave.org>
parents: 21055
diff changeset
2040
202cfd2b4514 store parser state in base class; use it in push and pull parsers
John W. Eaton <jwe@octave.org>
parents: 21055
diff changeset
2041 // FIXME: Deleting the internal Bison parser state structure does
202cfd2b4514 store parser state in base class; use it in push and pull parsers
John W. Eaton <jwe@octave.org>
parents: 21055
diff changeset
2042 // not clean up any partial parse trees in the event of an interrupt or
202cfd2b4514 store parser state in base class; use it in push and pull parsers
John W. Eaton <jwe@octave.org>
parents: 21055
diff changeset
2043 // error. It's not clear how to safely do that with the C language
202cfd2b4514 store parser state in base class; use it in push and pull parsers
John W. Eaton <jwe@octave.org>
parents: 21055
diff changeset
2044 // parser that Bison generates. The C++ language parser that Bison
202cfd2b4514 store parser state in base class; use it in push and pull parsers
John W. Eaton <jwe@octave.org>
parents: 21055
diff changeset
2045 // generates would do it for us automatically whenever an exception
202cfd2b4514 store parser state in base class; use it in push and pull parsers
John W. Eaton <jwe@octave.org>
parents: 21055
diff changeset
2046 // is thrown while parsing input, but there is currently no C++
202cfd2b4514 store parser state in base class; use it in push and pull parsers
John W. Eaton <jwe@octave.org>
parents: 21055
diff changeset
2047 // interface for a push parser.
202cfd2b4514 store parser state in base class; use it in push and pull parsers
John W. Eaton <jwe@octave.org>
parents: 21055
diff changeset
2048
202cfd2b4514 store parser state in base class; use it in push and pull parsers
John W. Eaton <jwe@octave.org>
parents: 21055
diff changeset
2049 yypstate_delete (static_cast<yypstate *> (parser_state));
16157
335041cc657a optionally use push parser interface
John W. Eaton <jwe@octave.org>
parents: 16153
diff changeset
2050 }
16287
04a7953496a7 create base class for parser; use reference for curr_lexer
John W. Eaton <jwe@octave.org>
parents: 16285
diff changeset
2051
16177
a7669b4d27f6 eliminate global global_command variable
John W. Eaton <jwe@octave.org>
parents: 16174
diff changeset
2052 void
16287
04a7953496a7 create base class for parser; use reference for curr_lexer
John W. Eaton <jwe@octave.org>
parents: 16285
diff changeset
2053 octave_base_parser::reset (void)
16177
a7669b4d27f6 eliminate global global_command variable
John W. Eaton <jwe@octave.org>
parents: 16174
diff changeset
2054 {
16574
b678d2d10e53 reset parser state on parse error (bug #38840)
John W. Eaton <jwe@octave.org>
parents: 16442
diff changeset
2055 endfunction_found = false;
b678d2d10e53 reset parser state on parse error (bug #38840)
John W. Eaton <jwe@octave.org>
parents: 16442
diff changeset
2056 autoloading = false;
b678d2d10e53 reset parser state on parse error (bug #38840)
John W. Eaton <jwe@octave.org>
parents: 16442
diff changeset
2057 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
2058 parsing_subfunctions = false;
b678d2d10e53 reset parser state on parse error (bug #38840)
John W. Eaton <jwe@octave.org>
parents: 16442
diff changeset
2059 max_fcn_depth = 0;
b678d2d10e53 reset parser state on parse error (bug #38840)
John W. Eaton <jwe@octave.org>
parents: 16442
diff changeset
2060 curr_fcn_depth = 0;
b678d2d10e53 reset parser state on parse error (bug #38840)
John W. Eaton <jwe@octave.org>
parents: 16442
diff changeset
2061 primary_fcn_scope = -1;
b678d2d10e53 reset parser state on parse error (bug #38840)
John W. Eaton <jwe@octave.org>
parents: 16442
diff changeset
2062 curr_class_name = "";
16676
7368654f302f Initial support for (classdef) packages.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 16644
diff changeset
2063 curr_package_name = "";
16574
b678d2d10e53 reset parser state on parse error (bug #38840)
John W. Eaton <jwe@octave.org>
parents: 16442
diff changeset
2064 function_scopes.clear ();
b678d2d10e53 reset parser state on parse error (bug #38840)
John W. Eaton <jwe@octave.org>
parents: 16442
diff changeset
2065 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
2066 subfunction_names.clear ();
16574
b678d2d10e53 reset parser state on parse error (bug #38840)
John W. Eaton <jwe@octave.org>
parents: 16442
diff changeset
2067
16177
a7669b4d27f6 eliminate global global_command variable
John W. Eaton <jwe@octave.org>
parents: 16174
diff changeset
2068 delete stmt_list;
a7669b4d27f6 eliminate global global_command variable
John W. Eaton <jwe@octave.org>
parents: 16174
diff changeset
2069 stmt_list = 0;
a7669b4d27f6 eliminate global global_command variable
John W. Eaton <jwe@octave.org>
parents: 16174
diff changeset
2070
16288
fe3b9a51e625 rename curr_lexer, curr_parser, CURR_LEXER
John W. Eaton <jwe@octave.org>
parents: 16287
diff changeset
2071 lexer.reset ();
21063
202cfd2b4514 store parser state in base class; use it in push and pull parsers
John W. Eaton <jwe@octave.org>
parents: 21055
diff changeset
2072
202cfd2b4514 store parser state in base class; use it in push and pull parsers
John W. Eaton <jwe@octave.org>
parents: 21055
diff changeset
2073 yypstate_delete (static_cast<yypstate *> (parser_state));
202cfd2b4514 store parser state in base class; use it in push and pull parsers
John W. Eaton <jwe@octave.org>
parents: 21055
diff changeset
2074 parser_state = yypstate_new ();
16138
284e2ca86ef7 execute parser using member function of octave_parser class
John W. Eaton <jwe@octave.org>
parents: 16136
diff changeset
2075 }
284e2ca86ef7 execute parser using member function of octave_parser class
John W. Eaton <jwe@octave.org>
parents: 16136
diff changeset
2076
666
fb4f6556b443 [project @ 1994-09-06 21:22:46 by jwe]
jwe
parents: 627
diff changeset
2077 // Error mesages for mismatched end tokens.
fb4f6556b443 [project @ 1994-09-06 21:22:46 by jwe]
jwe
parents: 627
diff changeset
2078
21071
f25c14056b7c overhaul parser error handling for end token mismatch
John W. Eaton <jwe@octave.org>
parents: 21066
diff changeset
2079 static std::string
f25c14056b7c overhaul parser error handling for end token mismatch
John W. Eaton <jwe@octave.org>
parents: 21066
diff changeset
2080 end_token_as_string (token::end_tok_type ettype)
496
e7c5b23b34d3 [project @ 1994-07-06 15:02:26 by jwe]
jwe
parents: 482
diff changeset
2081 {
21071
f25c14056b7c overhaul parser error handling for end token mismatch
John W. Eaton <jwe@octave.org>
parents: 21066
diff changeset
2082 std::string retval = "<unknown>";
496
e7c5b23b34d3 [project @ 1994-07-06 15:02:26 by jwe]
jwe
parents: 482
diff changeset
2083
e7c5b23b34d3 [project @ 1994-07-06 15:02:26 by jwe]
jwe
parents: 482
diff changeset
2084 switch (ettype)
e7c5b23b34d3 [project @ 1994-07-06 15:02:26 by jwe]
jwe
parents: 482
diff changeset
2085 {
e7c5b23b34d3 [project @ 1994-07-06 15:02:26 by jwe]
jwe
parents: 482
diff changeset
2086 case token::simple_end:
21071
f25c14056b7c overhaul parser error handling for end token mismatch
John W. Eaton <jwe@octave.org>
parents: 21066
diff changeset
2087 retval = "end";
496
e7c5b23b34d3 [project @ 1994-07-06 15:02:26 by jwe]
jwe
parents: 482
diff changeset
2088 break;
777
a2f9d3fd720c [project @ 1994-10-07 14:01:53 by jwe]
jwe
parents: 773
diff changeset
2089
20075
8aa424ffc076 handle all end token types when reporting parse errors (bug #44824)
John W. Eaton <jwe@octave.org>
parents: 19849
diff changeset
2090 case token::classdef_end:
21071
f25c14056b7c overhaul parser error handling for end token mismatch
John W. Eaton <jwe@octave.org>
parents: 21066
diff changeset
2091 retval = "endclassdef";
20075
8aa424ffc076 handle all end token types when reporting parse errors (bug #44824)
John W. Eaton <jwe@octave.org>
parents: 19849
diff changeset
2092 break;
8aa424ffc076 handle all end token types when reporting parse errors (bug #44824)
John W. Eaton <jwe@octave.org>
parents: 19849
diff changeset
2093
8aa424ffc076 handle all end token types when reporting parse errors (bug #44824)
John W. Eaton <jwe@octave.org>
parents: 19849
diff changeset
2094 case token::enumeration_end:
21071
f25c14056b7c overhaul parser error handling for end token mismatch
John W. Eaton <jwe@octave.org>
parents: 21066
diff changeset
2095 retval = "endenumeration";
20075
8aa424ffc076 handle all end token types when reporting parse errors (bug #44824)
John W. Eaton <jwe@octave.org>
parents: 19849
diff changeset
2096 break;
8aa424ffc076 handle all end token types when reporting parse errors (bug #44824)
John W. Eaton <jwe@octave.org>
parents: 19849
diff changeset
2097
8aa424ffc076 handle all end token types when reporting parse errors (bug #44824)
John W. Eaton <jwe@octave.org>
parents: 19849
diff changeset
2098 case token::events_end:
21071
f25c14056b7c overhaul parser error handling for end token mismatch
John W. Eaton <jwe@octave.org>
parents: 21066
diff changeset
2099 retval = "endevents";
20075
8aa424ffc076 handle all end token types when reporting parse errors (bug #44824)
John W. Eaton <jwe@octave.org>
parents: 19849
diff changeset
2100 break;
8aa424ffc076 handle all end token types when reporting parse errors (bug #44824)
John W. Eaton <jwe@octave.org>
parents: 19849
diff changeset
2101
496
e7c5b23b34d3 [project @ 1994-07-06 15:02:26 by jwe]
jwe
parents: 482
diff changeset
2102 case token::for_end:
21071
f25c14056b7c overhaul parser error handling for end token mismatch
John W. Eaton <jwe@octave.org>
parents: 21066
diff changeset
2103 retval = "endfor";
496
e7c5b23b34d3 [project @ 1994-07-06 15:02:26 by jwe]
jwe
parents: 482
diff changeset
2104 break;
777
a2f9d3fd720c [project @ 1994-10-07 14:01:53 by jwe]
jwe
parents: 773
diff changeset
2105
496
e7c5b23b34d3 [project @ 1994-07-06 15:02:26 by jwe]
jwe
parents: 482
diff changeset
2106 case token::function_end:
21071
f25c14056b7c overhaul parser error handling for end token mismatch
John W. Eaton <jwe@octave.org>
parents: 21066
diff changeset
2107 retval = "endfunction";
496
e7c5b23b34d3 [project @ 1994-07-06 15:02:26 by jwe]
jwe
parents: 482
diff changeset
2108 break;
777
a2f9d3fd720c [project @ 1994-10-07 14:01:53 by jwe]
jwe
parents: 773
diff changeset
2109
496
e7c5b23b34d3 [project @ 1994-07-06 15:02:26 by jwe]
jwe
parents: 482
diff changeset
2110 case token::if_end:
21071
f25c14056b7c overhaul parser error handling for end token mismatch
John W. Eaton <jwe@octave.org>
parents: 21066
diff changeset
2111 retval = "endif";
496
e7c5b23b34d3 [project @ 1994-07-06 15:02:26 by jwe]
jwe
parents: 482
diff changeset
2112 break;
777
a2f9d3fd720c [project @ 1994-10-07 14:01:53 by jwe]
jwe
parents: 773
diff changeset
2113
20075
8aa424ffc076 handle all end token types when reporting parse errors (bug #44824)
John W. Eaton <jwe@octave.org>
parents: 19849
diff changeset
2114 case token::methods_end:
21071
f25c14056b7c overhaul parser error handling for end token mismatch
John W. Eaton <jwe@octave.org>
parents: 21066
diff changeset
2115 retval = "endmethods";
20075
8aa424ffc076 handle all end token types when reporting parse errors (bug #44824)
John W. Eaton <jwe@octave.org>
parents: 19849
diff changeset
2116 break;
8aa424ffc076 handle all end token types when reporting parse errors (bug #44824)
John W. Eaton <jwe@octave.org>
parents: 19849
diff changeset
2117
8aa424ffc076 handle all end token types when reporting parse errors (bug #44824)
John W. Eaton <jwe@octave.org>
parents: 19849
diff changeset
2118 case token::parfor_end:
21071
f25c14056b7c overhaul parser error handling for end token mismatch
John W. Eaton <jwe@octave.org>
parents: 21066
diff changeset
2119 retval = "endparfor";
20075
8aa424ffc076 handle all end token types when reporting parse errors (bug #44824)
John W. Eaton <jwe@octave.org>
parents: 19849
diff changeset
2120 break;
8aa424ffc076 handle all end token types when reporting parse errors (bug #44824)
John W. Eaton <jwe@octave.org>
parents: 19849
diff changeset
2121
8aa424ffc076 handle all end token types when reporting parse errors (bug #44824)
John W. Eaton <jwe@octave.org>
parents: 19849
diff changeset
2122 case token::properties_end:
21071
f25c14056b7c overhaul parser error handling for end token mismatch
John W. Eaton <jwe@octave.org>
parents: 21066
diff changeset
2123 retval = "endproperties";
20075
8aa424ffc076 handle all end token types when reporting parse errors (bug #44824)
John W. Eaton <jwe@octave.org>
parents: 19849
diff changeset
2124 break;
8aa424ffc076 handle all end token types when reporting parse errors (bug #44824)
John W. Eaton <jwe@octave.org>
parents: 19849
diff changeset
2125
3233
98d0ee053ba4 [project @ 1999-01-27 20:23:40 by jwe]
jwe
parents: 3216
diff changeset
2126 case token::switch_end:
21071
f25c14056b7c overhaul parser error handling for end token mismatch
John W. Eaton <jwe@octave.org>
parents: 21066
diff changeset
2127 retval = "endswitch";
3233
98d0ee053ba4 [project @ 1999-01-27 20:23:40 by jwe]
jwe
parents: 3216
diff changeset
2128 break;
98d0ee053ba4 [project @ 1999-01-27 20:23:40 by jwe]
jwe
parents: 3216
diff changeset
2129
5400
c7e3cf2fce3e [project @ 2005-07-05 15:01:32 by jwe]
jwe
parents: 5397
diff changeset
2130 case token::try_catch_end:
21071
f25c14056b7c overhaul parser error handling for end token mismatch
John W. Eaton <jwe@octave.org>
parents: 21066
diff changeset
2131 retval = "end_try_catch";
5400
c7e3cf2fce3e [project @ 2005-07-05 15:01:32 by jwe]
jwe
parents: 5397
diff changeset
2132 break;
c7e3cf2fce3e [project @ 2005-07-05 15:01:32 by jwe]
jwe
parents: 5397
diff changeset
2133
1371
766af9ca8edb [project @ 1995-09-06 21:36:02 by jwe]
jwe
parents: 1351
diff changeset
2134 case token::unwind_protect_end:
21071
f25c14056b7c overhaul parser error handling for end token mismatch
John W. Eaton <jwe@octave.org>
parents: 21066
diff changeset
2135 retval = "end_unwind_protect";
1371
766af9ca8edb [project @ 1995-09-06 21:36:02 by jwe]
jwe
parents: 1351
diff changeset
2136 break;
766af9ca8edb [project @ 1995-09-06 21:36:02 by jwe]
jwe
parents: 1351
diff changeset
2137
20075
8aa424ffc076 handle all end token types when reporting parse errors (bug #44824)
John W. Eaton <jwe@octave.org>
parents: 19849
diff changeset
2138 case token::while_end:
21071
f25c14056b7c overhaul parser error handling for end token mismatch
John W. Eaton <jwe@octave.org>
parents: 21066
diff changeset
2139 retval = "endwhile";
20075
8aa424ffc076 handle all end token types when reporting parse errors (bug #44824)
John W. Eaton <jwe@octave.org>
parents: 19849
diff changeset
2140 break;
8aa424ffc076 handle all end token types when reporting parse errors (bug #44824)
John W. Eaton <jwe@octave.org>
parents: 19849
diff changeset
2141
496
e7c5b23b34d3 [project @ 1994-07-06 15:02:26 by jwe]
jwe
parents: 482
diff changeset
2142 default:
e7c5b23b34d3 [project @ 1994-07-06 15:02:26 by jwe]
jwe
parents: 482
diff changeset
2143 panic_impossible ();
e7c5b23b34d3 [project @ 1994-07-06 15:02:26 by jwe]
jwe
parents: 482
diff changeset
2144 break;
e7c5b23b34d3 [project @ 1994-07-06 15:02:26 by jwe]
jwe
parents: 482
diff changeset
2145 }
21071
f25c14056b7c overhaul parser error handling for end token mismatch
John W. Eaton <jwe@octave.org>
parents: 21066
diff changeset
2146
f25c14056b7c overhaul parser error handling for end token mismatch
John W. Eaton <jwe@octave.org>
parents: 21066
diff changeset
2147 return retval;
496
e7c5b23b34d3 [project @ 1994-07-06 15:02:26 by jwe]
jwe
parents: 482
diff changeset
2148 }
e7c5b23b34d3 [project @ 1994-07-06 15:02:26 by jwe]
jwe
parents: 482
diff changeset
2149
21071
f25c14056b7c overhaul parser error handling for end token mismatch
John W. Eaton <jwe@octave.org>
parents: 21066
diff changeset
2150 void
f25c14056b7c overhaul parser error handling for end token mismatch
John W. Eaton <jwe@octave.org>
parents: 21066
diff changeset
2151 octave_base_parser::end_token_error (token *tok, token::end_tok_type expected)
f25c14056b7c overhaul parser error handling for end token mismatch
John W. Eaton <jwe@octave.org>
parents: 21066
diff changeset
2152 {
f25c14056b7c overhaul parser error handling for end token mismatch
John W. Eaton <jwe@octave.org>
parents: 21066
diff changeset
2153 std::string msg = ("'" + end_token_as_string (expected)
f25c14056b7c overhaul parser error handling for end token mismatch
John W. Eaton <jwe@octave.org>
parents: 21066
diff changeset
2154 + "' command matched by '"
f25c14056b7c overhaul parser error handling for end token mismatch
John W. Eaton <jwe@octave.org>
parents: 21066
diff changeset
2155 + end_token_as_string (tok->ettype ()) + "'");
f25c14056b7c overhaul parser error handling for end token mismatch
John W. Eaton <jwe@octave.org>
parents: 21066
diff changeset
2156
f25c14056b7c overhaul parser error handling for end token mismatch
John W. Eaton <jwe@octave.org>
parents: 21066
diff changeset
2157 bison_error (msg, tok->line (), tok->column ());
f25c14056b7c overhaul parser error handling for end token mismatch
John W. Eaton <jwe@octave.org>
parents: 21066
diff changeset
2158 }
f25c14056b7c overhaul parser error handling for end token mismatch
John W. Eaton <jwe@octave.org>
parents: 21066
diff changeset
2159
f25c14056b7c overhaul parser error handling for end token mismatch
John W. Eaton <jwe@octave.org>
parents: 21066
diff changeset
2160
666
fb4f6556b443 [project @ 1994-09-06 21:22:46 by jwe]
jwe
parents: 627
diff changeset
2161 // Check to see that end tokens are properly matched.
fb4f6556b443 [project @ 1994-09-06 21:22:46 by jwe]
jwe
parents: 627
diff changeset
2162
16134
ec9c6222ef5a move static parser helper functions to octave_parser class
John W. Eaton <jwe@octave.org>
parents: 16133
diff changeset
2163 bool
16287
04a7953496a7 create base class for parser; use reference for curr_lexer
John W. Eaton <jwe@octave.org>
parents: 16285
diff changeset
2164 octave_base_parser::end_token_ok (token *tok, token::end_tok_type expected)
143
7849db4b6dbc [project @ 1993-10-04 02:36:45 by jwe]
jwe
parents: 118
diff changeset
2165 {
7849db4b6dbc [project @ 1993-10-04 02:36:45 by jwe]
jwe
parents: 118
diff changeset
2166 token::end_tok_type ettype = tok->ettype ();
2857
5448c8cba402 [project @ 1997-03-31 07:06:10 by jwe]
jwe
parents: 2856
diff changeset
2167
21071
f25c14056b7c overhaul parser error handling for end token mismatch
John W. Eaton <jwe@octave.org>
parents: 21066
diff changeset
2168 return ettype == expected || ettype == token::simple_end;
143
7849db4b6dbc [project @ 1993-10-04 02:36:45 by jwe]
jwe
parents: 118
diff changeset
2169 }
7849db4b6dbc [project @ 1993-10-04 02:36:45 by jwe]
jwe
parents: 118
diff changeset
2170
666
fb4f6556b443 [project @ 1994-09-06 21:22:46 by jwe]
jwe
parents: 627
diff changeset
2171 // Maybe print a warning if an assignment expression is used as the
fb4f6556b443 [project @ 1994-09-06 21:22:46 by jwe]
jwe
parents: 627
diff changeset
2172 // test in a logical expression.
fb4f6556b443 [project @ 1994-09-06 21:22:46 by jwe]
jwe
parents: 627
diff changeset
2173
16134
ec9c6222ef5a move static parser helper functions to octave_parser class
John W. Eaton <jwe@octave.org>
parents: 16133
diff changeset
2174 void
16287
04a7953496a7 create base class for parser; use reference for curr_lexer
John W. Eaton <jwe@octave.org>
parents: 16285
diff changeset
2175 octave_base_parser::maybe_warn_assign_as_truth_value (tree_expression *expr)
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
2176 {
5781
faafc2d98b8d [project @ 2006-05-02 19:40:19 by jwe]
jwe
parents: 5775
diff changeset
2177 if (expr->is_assignment_expression ()
2961
8a77d52c9d02 [project @ 1997-05-12 01:36:04 by jwe]
jwe
parents: 2960
diff changeset
2178 && expr->paren_count () < 2)
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
2179 {
16288
fe3b9a51e625 rename curr_lexer, curr_parser, CURR_LEXER
John W. Eaton <jwe@octave.org>
parents: 16287
diff changeset
2180 if (lexer.fcn_file_full_name.empty ())
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
2181 warning_with_id
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
2182 ("Octave:assign-as-truth-value",
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
2183 "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
2184 else
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
2185 warning_with_id
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
2186 ("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
2187 "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
2188 expr->line (), expr->column (), lexer.fcn_file_full_name.c_str ());
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
2189 }
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
2190 }
578
d169be9237fb [project @ 1994-08-03 20:06:54 by jwe]
jwe
parents: 572
diff changeset
2191
2764
2c0f259cf83d [project @ 1997-03-01 02:30:26 by jwe]
jwe
parents: 2745
diff changeset
2192 // Maybe print a warning about switch labels that aren't constants.
2c0f259cf83d [project @ 1997-03-01 02:30:26 by jwe]
jwe
parents: 2745
diff changeset
2193
16134
ec9c6222ef5a move static parser helper functions to octave_parser class
John W. Eaton <jwe@octave.org>
parents: 16133
diff changeset
2194 void
16287
04a7953496a7 create base class for parser; use reference for curr_lexer
John W. Eaton <jwe@octave.org>
parents: 16285
diff changeset
2195 octave_base_parser::maybe_warn_variable_switch_label (tree_expression *expr)
2764
2c0f259cf83d [project @ 1997-03-01 02:30:26 by jwe]
jwe
parents: 2745
diff changeset
2196 {
5781
faafc2d98b8d [project @ 2006-05-02 19:40:19 by jwe]
jwe
parents: 5775
diff changeset
2197 if (! expr->is_constant ())
8974
fde2a916b2ac include line and file info in parser warnings
John W. Eaton <jwe@octave.org>
parents: 8950
diff changeset
2198 {
16288
fe3b9a51e625 rename curr_lexer, curr_parser, CURR_LEXER
John W. Eaton <jwe@octave.org>
parents: 16287
diff changeset
2199 if (lexer.fcn_file_full_name.empty ())
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
2200 warning_with_id ("Octave:variable-switch-label",
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
2201 "variable switch label");
8974
fde2a916b2ac include line and file info in parser warnings
John W. Eaton <jwe@octave.org>
parents: 8950
diff changeset
2202 else
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
2203 warning_with_id
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
2204 ("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
2205 "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
2206 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
2207 }
2764
2c0f259cf83d [project @ 1997-03-01 02:30:26 by jwe]
jwe
parents: 2745
diff changeset
2208 }
2c0f259cf83d [project @ 1997-03-01 02:30:26 by jwe]
jwe
parents: 2745
diff changeset
2209
1623
fa7a847f9b92 [project @ 1995-11-06 18:05:09 by jwe]
jwe
parents: 1607
diff changeset
2210 // Finish building a range.
fa7a847f9b92 [project @ 1995-11-06 18:05:09 by jwe]
jwe
parents: 1607
diff changeset
2211
16134
ec9c6222ef5a move static parser helper functions to octave_parser class
John W. Eaton <jwe@octave.org>
parents: 16133
diff changeset
2212 tree_expression *
16287
04a7953496a7 create base class for parser; use reference for curr_lexer
John W. Eaton <jwe@octave.org>
parents: 16285
diff changeset
2213 octave_base_parser::finish_colon_expression (tree_colon_expression *e)
1623
fa7a847f9b92 [project @ 1995-11-06 18:05:09 by jwe]
jwe
parents: 1607
diff changeset
2214 {
3110
fe2d1ae8926b [project @ 1997-11-21 02:11:19 by jwe]
jwe
parents: 3099
diff changeset
2215 tree_expression *retval = e;
fe2d1ae8926b [project @ 1997-11-21 02:11:19 by jwe]
jwe
parents: 3099
diff changeset
2216
10067
6f79338c269b omission from last patch
Jaroslav Hajek <highegg@gmail.com>
parents: 9794
diff changeset
2217 unwind_protect frame;
6f79338c269b omission from last patch
Jaroslav Hajek <highegg@gmail.com>
parents: 9794
diff changeset
2218
6f79338c269b omission from last patch
Jaroslav Hajek <highegg@gmail.com>
parents: 9794
diff changeset
2219 frame.protect_var (discard_error_messages);
6f79338c269b omission from last patch
Jaroslav Hajek <highegg@gmail.com>
parents: 9794
diff changeset
2220 frame.protect_var (discard_warning_messages);
4452
f3c21a1d1c62 [project @ 2003-07-09 23:20:18 by jwe]
jwe
parents: 4426
diff changeset
2221
3815
c554ad71bafc [project @ 2001-04-19 19:50:52 by jwe]
jwe
parents: 3802
diff changeset
2222 discard_error_messages = true;
4452
f3c21a1d1c62 [project @ 2003-07-09 23:20:18 by jwe]
jwe
parents: 4426
diff changeset
2223 discard_warning_messages = true;
1623
fa7a847f9b92 [project @ 1995-11-06 18:05:09 by jwe]
jwe
parents: 1607
diff changeset
2224
2533
987e934bbb8c [project @ 1996-11-19 18:21:23 by jwe]
jwe
parents: 2525
diff changeset
2225 tree_expression *base = e->base ();
987e934bbb8c [project @ 1996-11-19 18:21:23 by jwe]
jwe
parents: 2525
diff changeset
2226 tree_expression *limit = e->limit ();
987e934bbb8c [project @ 1996-11-19 18:21:23 by jwe]
jwe
parents: 2525
diff changeset
2227 tree_expression *incr = e->increment ();
987e934bbb8c [project @ 1996-11-19 18:21:23 by jwe]
jwe
parents: 2525
diff changeset
2228
2970
b9e64477f703 [project @ 1997-05-15 18:04:21 by jwe]
jwe
parents: 2961
diff changeset
2229 if (base)
1623
fa7a847f9b92 [project @ 1995-11-06 18:05:09 by jwe]
jwe
parents: 1607
diff changeset
2230 {
2970
b9e64477f703 [project @ 1997-05-15 18:04:21 by jwe]
jwe
parents: 2961
diff changeset
2231 if (limit)
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
2232 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
2233 if (base->is_constant () && limit->is_constant ()
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
2234 && (! incr || (incr && incr->is_constant ())))
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
2235 {
20769
58e79b0078e4 handle exceptions when discarding error messages (bug #46534)
John W. Eaton <jwe@octave.org>
parents: 20756
diff changeset
2236 try
58e79b0078e4 handle exceptions when discarding error messages (bug #46534)
John W. Eaton <jwe@octave.org>
parents: 20756
diff changeset
2237 {
58e79b0078e4 handle exceptions when discarding error messages (bug #46534)
John W. Eaton <jwe@octave.org>
parents: 20756
diff changeset
2238 octave_value tmp = e->rvalue1 ();
58e79b0078e4 handle exceptions when discarding error messages (bug #46534)
John W. Eaton <jwe@octave.org>
parents: 20756
diff changeset
2239
58e79b0078e4 handle exceptions when discarding error messages (bug #46534)
John W. Eaton <jwe@octave.org>
parents: 20756
diff changeset
2240 tree_constant *tc_retval
58e79b0078e4 handle exceptions when discarding error messages (bug #46534)
John W. Eaton <jwe@octave.org>
parents: 20756
diff changeset
2241 = new tree_constant (tmp, base->line (), base->column ());
58e79b0078e4 handle exceptions when discarding error messages (bug #46534)
John W. Eaton <jwe@octave.org>
parents: 20756
diff changeset
2242
58e79b0078e4 handle exceptions when discarding error messages (bug #46534)
John W. Eaton <jwe@octave.org>
parents: 20756
diff changeset
2243 std::ostringstream buf;
58e79b0078e4 handle exceptions when discarding error messages (bug #46534)
John W. Eaton <jwe@octave.org>
parents: 20756
diff changeset
2244
58e79b0078e4 handle exceptions when discarding error messages (bug #46534)
John W. Eaton <jwe@octave.org>
parents: 20756
diff changeset
2245 tree_print_code tpc (buf);
58e79b0078e4 handle exceptions when discarding error messages (bug #46534)
John W. Eaton <jwe@octave.org>
parents: 20756
diff changeset
2246
58e79b0078e4 handle exceptions when discarding error messages (bug #46534)
John W. Eaton <jwe@octave.org>
parents: 20756
diff changeset
2247 e->accept (tpc);
58e79b0078e4 handle exceptions when discarding error messages (bug #46534)
John W. Eaton <jwe@octave.org>
parents: 20756
diff changeset
2248
58e79b0078e4 handle exceptions when discarding error messages (bug #46534)
John W. Eaton <jwe@octave.org>
parents: 20756
diff changeset
2249 tc_retval->stash_original_text (buf.str ());
58e79b0078e4 handle exceptions when discarding error messages (bug #46534)
John W. Eaton <jwe@octave.org>
parents: 20756
diff changeset
2250
58e79b0078e4 handle exceptions when discarding error messages (bug #46534)
John W. Eaton <jwe@octave.org>
parents: 20756
diff changeset
2251 delete e;
58e79b0078e4 handle exceptions when discarding error messages (bug #46534)
John W. Eaton <jwe@octave.org>
parents: 20756
diff changeset
2252
58e79b0078e4 handle exceptions when discarding error messages (bug #46534)
John W. Eaton <jwe@octave.org>
parents: 20756
diff changeset
2253 retval = tc_retval;
58e79b0078e4 handle exceptions when discarding error messages (bug #46534)
John W. Eaton <jwe@octave.org>
parents: 20756
diff changeset
2254 }
58e79b0078e4 handle exceptions when discarding error messages (bug #46534)
John W. Eaton <jwe@octave.org>
parents: 20756
diff changeset
2255 catch (const octave_execution_exception&)
58e79b0078e4 handle exceptions when discarding error messages (bug #46534)
John W. Eaton <jwe@octave.org>
parents: 20756
diff changeset
2256 {
58e79b0078e4 handle exceptions when discarding error messages (bug #46534)
John W. Eaton <jwe@octave.org>
parents: 20756
diff changeset
2257 recover_from_exception ();
58e79b0078e4 handle exceptions when discarding error messages (bug #46534)
John W. Eaton <jwe@octave.org>
parents: 20756
diff changeset
2258 }
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
2259 }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
2260 }
2533
987e934bbb8c [project @ 1996-11-19 18:21:23 by jwe]
jwe
parents: 2525
diff changeset
2261 else
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 e->preserve_base ();
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
2264 delete e;
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 retval = base;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
2267 }
1623
fa7a847f9b92 [project @ 1995-11-06 18:05:09 by jwe]
jwe
parents: 1607
diff changeset
2268 }
fa7a847f9b92 [project @ 1995-11-06 18:05:09 by jwe]
jwe
parents: 1607
diff changeset
2269
fa7a847f9b92 [project @ 1995-11-06 18:05:09 by jwe]
jwe
parents: 1607
diff changeset
2270 return retval;
fa7a847f9b92 [project @ 1995-11-06 18:05:09 by jwe]
jwe
parents: 1607
diff changeset
2271 }
fa7a847f9b92 [project @ 1995-11-06 18:05:09 by jwe]
jwe
parents: 1607
diff changeset
2272
1607
795527e9db19 [project @ 1995-11-02 13:03:36 by jwe]
jwe
parents: 1588
diff changeset
2273 // Make a constant.
795527e9db19 [project @ 1995-11-02 13:03:36 by jwe]
jwe
parents: 1588
diff changeset
2274
16134
ec9c6222ef5a move static parser helper functions to octave_parser class
John W. Eaton <jwe@octave.org>
parents: 16133
diff changeset
2275 tree_constant *
16287
04a7953496a7 create base class for parser; use reference for curr_lexer
John W. Eaton <jwe@octave.org>
parents: 16285
diff changeset
2276 octave_base_parser::make_constant (int op, token *tok_val)
1607
795527e9db19 [project @ 1995-11-02 13:03:36 by jwe]
jwe
parents: 1588
diff changeset
2277 {
795527e9db19 [project @ 1995-11-02 13:03:36 by jwe]
jwe
parents: 1588
diff changeset
2278 int l = tok_val->line ();
795527e9db19 [project @ 1995-11-02 13:03:36 by jwe]
jwe
parents: 1588
diff changeset
2279 int c = tok_val->column ();
795527e9db19 [project @ 1995-11-02 13:03:36 by jwe]
jwe
parents: 1588
diff changeset
2280
3216
60a89a69a70a [project @ 1998-11-11 20:47:03 by jwe]
jwe
parents: 3208
diff changeset
2281 tree_constant *retval = 0;
1607
795527e9db19 [project @ 1995-11-02 13:03:36 by jwe]
jwe
parents: 1588
diff changeset
2282
795527e9db19 [project @ 1995-11-02 13:03:36 by jwe]
jwe
parents: 1588
diff changeset
2283 switch (op)
795527e9db19 [project @ 1995-11-02 13:03:36 by jwe]
jwe
parents: 1588
diff changeset
2284 {
795527e9db19 [project @ 1995-11-02 13:03:36 by jwe]
jwe
parents: 1588
diff changeset
2285 case NUM:
2533
987e934bbb8c [project @ 1996-11-19 18:21:23 by jwe]
jwe
parents: 2525
diff changeset
2286 {
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
2287 octave_value tmp (tok_val->number ());
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
2288 retval = new tree_constant (tmp, l, c);
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
2289 retval->stash_original_text (tok_val->text_rep ());
2533
987e934bbb8c [project @ 1996-11-19 18:21:23 by jwe]
jwe
parents: 2525
diff changeset
2290 }
1607
795527e9db19 [project @ 1995-11-02 13:03:36 by jwe]
jwe
parents: 1588
diff changeset
2291 break;
795527e9db19 [project @ 1995-11-02 13:03:36 by jwe]
jwe
parents: 1588
diff changeset
2292
795527e9db19 [project @ 1995-11-02 13:03:36 by jwe]
jwe
parents: 1588
diff changeset
2293 case IMAG_NUM:
795527e9db19 [project @ 1995-11-02 13:03:36 by jwe]
jwe
parents: 1588
diff changeset
2294 {
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
2295 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
2296 retval = new tree_constant (tmp, l, c);
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
2297 retval->stash_original_text (tok_val->text_rep ());
1607
795527e9db19 [project @ 1995-11-02 13:03:36 by jwe]
jwe
parents: 1588
diff changeset
2298 }
795527e9db19 [project @ 1995-11-02 13:03:36 by jwe]
jwe
parents: 1588
diff changeset
2299 break;
795527e9db19 [project @ 1995-11-02 13:03:36 by jwe]
jwe
parents: 1588
diff changeset
2300
5279
bd32f770c09a [project @ 2005-04-12 21:55:31 by jwe]
jwe
parents: 5189
diff changeset
2301 case DQ_STRING:
bd32f770c09a [project @ 2005-04-12 21:55:31 by jwe]
jwe
parents: 5189
diff changeset
2302 case SQ_STRING:
2883
0b3954110c77 [project @ 1997-04-24 09:57:05 by jwe]
jwe
parents: 2865
diff changeset
2303 {
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
2304 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
2305
8150
283989f2da9b make null assignment matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents: 8064
diff changeset
2306 char delim = op == DQ_STRING ? '"' : '\'';
283989f2da9b make null assignment matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents: 8064
diff changeset
2307 octave_value tmp (txt, delim);
283989f2da9b make null assignment matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents: 8064
diff changeset
2308
283989f2da9b make null assignment matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents: 8064
diff changeset
2309 if (txt.empty ())
283989f2da9b make null assignment matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents: 8064
diff changeset
2310 {
283989f2da9b make null assignment matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents: 8064
diff changeset
2311 if (op == DQ_STRING)
283989f2da9b make null assignment matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents: 8064
diff changeset
2312 tmp = octave_null_str::instance;
283989f2da9b make null assignment matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents: 8064
diff changeset
2313 else
283989f2da9b make null assignment matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents: 8064
diff changeset
2314 tmp = octave_null_sq_str::instance;
283989f2da9b make null assignment matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents: 8064
diff changeset
2315 }
283989f2da9b make null assignment matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents: 8064
diff changeset
2316
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
2317 retval = new tree_constant (tmp, l, c);
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
2318
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
2319 if (op == DQ_STRING)
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
2320 txt = undo_string_escapes (txt);
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
2321
21066
258c787cd9ce maint: Use "FIXME:" consistently in code base.
Rik <rik@octave.org>
parents: 21065
diff changeset
2322 // FIXME: maybe this should also be handled by
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
2323 // tok_val->text_rep () for character strings?
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
2324 retval->stash_original_text (delim + txt + delim);
2883
0b3954110c77 [project @ 1997-04-24 09:57:05 by jwe]
jwe
parents: 2865
diff changeset
2325 }
1607
795527e9db19 [project @ 1995-11-02 13:03:36 by jwe]
jwe
parents: 1588
diff changeset
2326 break;
795527e9db19 [project @ 1995-11-02 13:03:36 by jwe]
jwe
parents: 1588
diff changeset
2327
795527e9db19 [project @ 1995-11-02 13:03:36 by jwe]
jwe
parents: 1588
diff changeset
2328 default:
795527e9db19 [project @ 1995-11-02 13:03:36 by jwe]
jwe
parents: 1588
diff changeset
2329 panic_impossible ();
795527e9db19 [project @ 1995-11-02 13:03:36 by jwe]
jwe
parents: 1588
diff changeset
2330 break;
795527e9db19 [project @ 1995-11-02 13:03:36 by jwe]
jwe
parents: 1588
diff changeset
2331 }
795527e9db19 [project @ 1995-11-02 13:03:36 by jwe]
jwe
parents: 1588
diff changeset
2332
795527e9db19 [project @ 1995-11-02 13:03:36 by jwe]
jwe
parents: 1588
diff changeset
2333 return retval;
795527e9db19 [project @ 1995-11-02 13:03:36 by jwe]
jwe
parents: 1588
diff changeset
2334 }
795527e9db19 [project @ 1995-11-02 13:03:36 by jwe]
jwe
parents: 1588
diff changeset
2335
4342
813effe14ee1 [project @ 2003-02-20 08:35:55 by jwe]
jwe
parents: 4318
diff changeset
2336 // Make a function handle.
813effe14ee1 [project @ 2003-02-20 08:35:55 by jwe]
jwe
parents: 4318
diff changeset
2337
16134
ec9c6222ef5a move static parser helper functions to octave_parser class
John W. Eaton <jwe@octave.org>
parents: 16133
diff changeset
2338 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
2339 octave_base_parser::make_fcn_handle (token *tok_val)
4342
813effe14ee1 [project @ 2003-02-20 08:35:55 by jwe]
jwe
parents: 4318
diff changeset
2340 {
813effe14ee1 [project @ 2003-02-20 08:35:55 by jwe]
jwe
parents: 4318
diff changeset
2341 int l = tok_val->line ();
813effe14ee1 [project @ 2003-02-20 08:35:55 by jwe]
jwe
parents: 4318
diff changeset
2342 int c = tok_val->column ();
813effe14ee1 [project @ 2003-02-20 08:35:55 by jwe]
jwe
parents: 4318
diff changeset
2343
813effe14ee1 [project @ 2003-02-20 08:35:55 by jwe]
jwe
parents: 4318
diff changeset
2344 tree_fcn_handle *retval = new tree_fcn_handle (tok_val->text (), l, c);
813effe14ee1 [project @ 2003-02-20 08:35:55 by jwe]
jwe
parents: 4318
diff changeset
2345
813effe14ee1 [project @ 2003-02-20 08:35:55 by jwe]
jwe
parents: 4318
diff changeset
2346 return retval;
813effe14ee1 [project @ 2003-02-20 08:35:55 by jwe]
jwe
parents: 4318
diff changeset
2347 }
813effe14ee1 [project @ 2003-02-20 08:35:55 by jwe]
jwe
parents: 4318
diff changeset
2348
4935
4fc993a4e072 [project @ 2004-08-06 03:17:12 by jwe]
jwe
parents: 4930
diff changeset
2349 // Make an anonymous function handle.
4fc993a4e072 [project @ 2004-08-06 03:17:12 by jwe]
jwe
parents: 4930
diff changeset
2350
16134
ec9c6222ef5a move static parser helper functions to octave_parser class
John W. Eaton <jwe@octave.org>
parents: 16133
diff changeset
2351 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
2352 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
2353 tree_statement *stmt)
4935
4fc993a4e072 [project @ 2004-08-06 03:17:12 by jwe]
jwe
parents: 4930
diff changeset
2354 {
21066
258c787cd9ce maint: Use "FIXME:" consistently in code base.
Rik <rik@octave.org>
parents: 21065
diff changeset
2355 // 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
2356 int l = lexer.input_line_number;
fe3b9a51e625 rename curr_lexer, curr_parser, CURR_LEXER
John W. Eaton <jwe@octave.org>
parents: 16287
diff changeset
2357 int c = lexer.current_input_column;
4935
4fc993a4e072 [project @ 2004-08-06 03:17:12 by jwe]
jwe
parents: 4930
diff changeset
2358
4fc993a4e072 [project @ 2004-08-06 03:17:12 by jwe]
jwe
parents: 4930
diff changeset
2359 tree_parameter_list *ret_list = 0;
4fc993a4e072 [project @ 2004-08-06 03:17:12 by jwe]
jwe
parents: 4930
diff changeset
2360
16320
09f0cb9cac7d don't modify symbol table scope in the parser
John W. Eaton <jwe@octave.org>
parents: 16302
diff changeset
2361 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
2362
09f0cb9cac7d don't modify symbol table scope in the parser
John W. Eaton <jwe@octave.org>
parents: 16302
diff changeset
2363 lexer.symtab_context.pop ();
5861
2a6cb4ed8f1e [project @ 2006-06-16 05:09:41 by jwe]
jwe
parents: 5848
diff changeset
2364
7351
8470a6b0b769 [project @ 2008-01-07 17:57:24 by jwe]
jwe
parents: 7336
diff changeset
2365 stmt->set_print_flag (false);
4935
4fc993a4e072 [project @ 2004-08-06 03:17:12 by jwe]
jwe
parents: 4930
diff changeset
2366
4fc993a4e072 [project @ 2004-08-06 03:17:12 by jwe]
jwe
parents: 4930
diff changeset
2367 tree_statement_list *body = new tree_statement_list (stmt);
4fc993a4e072 [project @ 2004-08-06 03:17:12 by jwe]
jwe
parents: 4930
diff changeset
2368
8658
73c4516fae10 New evaluator and debugger derived from tree-walker class
John W. Eaton <jwe@octave.org>
parents: 8471
diff changeset
2369 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
2370
5861
2a6cb4ed8f1e [project @ 2006-06-16 05:09:41 by jwe]
jwe
parents: 5848
diff changeset
2371 tree_anon_fcn_handle *retval
7336
745a8299c2b5 [project @ 2007-12-28 20:56:55 by jwe]
jwe
parents: 7017
diff changeset
2372 = 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
2373 // 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
2374 // errors when executed.
16288
fe3b9a51e625 rename curr_lexer, curr_parser, CURR_LEXER
John W. Eaton <jwe@octave.org>
parents: 16287
diff changeset
2375 //retval->stash_file_name (lexer.fcn_file_name);
4935
4fc993a4e072 [project @ 2004-08-06 03:17:12 by jwe]
jwe
parents: 4930
diff changeset
2376
4fc993a4e072 [project @ 2004-08-06 03:17:12 by jwe]
jwe
parents: 4930
diff changeset
2377 return retval;
4fc993a4e072 [project @ 2004-08-06 03:17:12 by jwe]
jwe
parents: 4930
diff changeset
2378 }
4fc993a4e072 [project @ 2004-08-06 03:17:12 by jwe]
jwe
parents: 4930
diff changeset
2379
666
fb4f6556b443 [project @ 1994-09-06 21:22:46 by jwe]
jwe
parents: 627
diff changeset
2380 // Build a binary expression.
fb4f6556b443 [project @ 1994-09-06 21:22:46 by jwe]
jwe
parents: 627
diff changeset
2381
16134
ec9c6222ef5a move static parser helper functions to octave_parser class
John W. Eaton <jwe@octave.org>
parents: 16133
diff changeset
2382 tree_expression *
16287
04a7953496a7 create base class for parser; use reference for curr_lexer
John W. Eaton <jwe@octave.org>
parents: 16285
diff changeset
2383 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
2384 token *tok_val, tree_expression *op2)
578
d169be9237fb [project @ 1994-08-03 20:06:54 by jwe]
jwe
parents: 572
diff changeset
2385 {
2883
0b3954110c77 [project @ 1997-04-24 09:57:05 by jwe]
jwe
parents: 2865
diff changeset
2386 octave_value::binary_op t = octave_value::unknown_binary_op;
1623
fa7a847f9b92 [project @ 1995-11-06 18:05:09 by jwe]
jwe
parents: 1607
diff changeset
2387
578
d169be9237fb [project @ 1994-08-03 20:06:54 by jwe]
jwe
parents: 572
diff changeset
2388 switch (op)
d169be9237fb [project @ 1994-08-03 20:06:54 by jwe]
jwe
parents: 572
diff changeset
2389 {
d169be9237fb [project @ 1994-08-03 20:06:54 by jwe]
jwe
parents: 572
diff changeset
2390 case POW:
3525
6cfa474c5b99 [project @ 2000-02-02 10:48:41 by jwe]
jwe
parents: 3523
diff changeset
2391 t = octave_value::op_pow;
578
d169be9237fb [project @ 1994-08-03 20:06:54 by jwe]
jwe
parents: 572
diff changeset
2392 break;
777
a2f9d3fd720c [project @ 1994-10-07 14:01:53 by jwe]
jwe
parents: 773
diff changeset
2393
578
d169be9237fb [project @ 1994-08-03 20:06:54 by jwe]
jwe
parents: 572
diff changeset
2394 case EPOW:
3525
6cfa474c5b99 [project @ 2000-02-02 10:48:41 by jwe]
jwe
parents: 3523
diff changeset
2395 t = octave_value::op_el_pow;
578
d169be9237fb [project @ 1994-08-03 20:06:54 by jwe]
jwe
parents: 572
diff changeset
2396 break;
777
a2f9d3fd720c [project @ 1994-10-07 14:01:53 by jwe]
jwe
parents: 773
diff changeset
2397
578
d169be9237fb [project @ 1994-08-03 20:06:54 by jwe]
jwe
parents: 572
diff changeset
2398 case '+':
3525
6cfa474c5b99 [project @ 2000-02-02 10:48:41 by jwe]
jwe
parents: 3523
diff changeset
2399 t = octave_value::op_add;
578
d169be9237fb [project @ 1994-08-03 20:06:54 by jwe]
jwe
parents: 572
diff changeset
2400 break;
777
a2f9d3fd720c [project @ 1994-10-07 14:01:53 by jwe]
jwe
parents: 773
diff changeset
2401
578
d169be9237fb [project @ 1994-08-03 20:06:54 by jwe]
jwe
parents: 572
diff changeset
2402 case '-':
3525
6cfa474c5b99 [project @ 2000-02-02 10:48:41 by jwe]
jwe
parents: 3523
diff changeset
2403 t = octave_value::op_sub;
578
d169be9237fb [project @ 1994-08-03 20:06:54 by jwe]
jwe
parents: 572
diff changeset
2404 break;
777
a2f9d3fd720c [project @ 1994-10-07 14:01:53 by jwe]
jwe
parents: 773
diff changeset
2405
578
d169be9237fb [project @ 1994-08-03 20:06:54 by jwe]
jwe
parents: 572
diff changeset
2406 case '*':
3525
6cfa474c5b99 [project @ 2000-02-02 10:48:41 by jwe]
jwe
parents: 3523
diff changeset
2407 t = octave_value::op_mul;
578
d169be9237fb [project @ 1994-08-03 20:06:54 by jwe]
jwe
parents: 572
diff changeset
2408 break;
777
a2f9d3fd720c [project @ 1994-10-07 14:01:53 by jwe]
jwe
parents: 773
diff changeset
2409
578
d169be9237fb [project @ 1994-08-03 20:06:54 by jwe]
jwe
parents: 572
diff changeset
2410 case '/':
3525
6cfa474c5b99 [project @ 2000-02-02 10:48:41 by jwe]
jwe
parents: 3523
diff changeset
2411 t = octave_value::op_div;
578
d169be9237fb [project @ 1994-08-03 20:06:54 by jwe]
jwe
parents: 572
diff changeset
2412 break;
777
a2f9d3fd720c [project @ 1994-10-07 14:01:53 by jwe]
jwe
parents: 773
diff changeset
2413
578
d169be9237fb [project @ 1994-08-03 20:06:54 by jwe]
jwe
parents: 572
diff changeset
2414 case EMUL:
3525
6cfa474c5b99 [project @ 2000-02-02 10:48:41 by jwe]
jwe
parents: 3523
diff changeset
2415 t = octave_value::op_el_mul;
578
d169be9237fb [project @ 1994-08-03 20:06:54 by jwe]
jwe
parents: 572
diff changeset
2416 break;
777
a2f9d3fd720c [project @ 1994-10-07 14:01:53 by jwe]
jwe
parents: 773
diff changeset
2417
578
d169be9237fb [project @ 1994-08-03 20:06:54 by jwe]
jwe
parents: 572
diff changeset
2418 case EDIV:
3525
6cfa474c5b99 [project @ 2000-02-02 10:48:41 by jwe]
jwe
parents: 3523
diff changeset
2419 t = octave_value::op_el_div;
578
d169be9237fb [project @ 1994-08-03 20:06:54 by jwe]
jwe
parents: 572
diff changeset
2420 break;
777
a2f9d3fd720c [project @ 1994-10-07 14:01:53 by jwe]
jwe
parents: 773
diff changeset
2421
578
d169be9237fb [project @ 1994-08-03 20:06:54 by jwe]
jwe
parents: 572
diff changeset
2422 case LEFTDIV:
3525
6cfa474c5b99 [project @ 2000-02-02 10:48:41 by jwe]
jwe
parents: 3523
diff changeset
2423 t = octave_value::op_ldiv;
578
d169be9237fb [project @ 1994-08-03 20:06:54 by jwe]
jwe
parents: 572
diff changeset
2424 break;
777
a2f9d3fd720c [project @ 1994-10-07 14:01:53 by jwe]
jwe
parents: 773
diff changeset
2425
578
d169be9237fb [project @ 1994-08-03 20:06:54 by jwe]
jwe
parents: 572
diff changeset
2426 case ELEFTDIV:
3525
6cfa474c5b99 [project @ 2000-02-02 10:48:41 by jwe]
jwe
parents: 3523
diff changeset
2427 t = octave_value::op_el_ldiv;
578
d169be9237fb [project @ 1994-08-03 20:06:54 by jwe]
jwe
parents: 572
diff changeset
2428 break;
777
a2f9d3fd720c [project @ 1994-10-07 14:01:53 by jwe]
jwe
parents: 773
diff changeset
2429
578
d169be9237fb [project @ 1994-08-03 20:06:54 by jwe]
jwe
parents: 572
diff changeset
2430 case EXPR_LT:
3525
6cfa474c5b99 [project @ 2000-02-02 10:48:41 by jwe]
jwe
parents: 3523
diff changeset
2431 t = octave_value::op_lt;
578
d169be9237fb [project @ 1994-08-03 20:06:54 by jwe]
jwe
parents: 572
diff changeset
2432 break;
777
a2f9d3fd720c [project @ 1994-10-07 14:01:53 by jwe]
jwe
parents: 773
diff changeset
2433
578
d169be9237fb [project @ 1994-08-03 20:06:54 by jwe]
jwe
parents: 572
diff changeset
2434 case EXPR_LE:
3525
6cfa474c5b99 [project @ 2000-02-02 10:48:41 by jwe]
jwe
parents: 3523
diff changeset
2435 t = octave_value::op_le;
578
d169be9237fb [project @ 1994-08-03 20:06:54 by jwe]
jwe
parents: 572
diff changeset
2436 break;
777
a2f9d3fd720c [project @ 1994-10-07 14:01:53 by jwe]
jwe
parents: 773
diff changeset
2437
578
d169be9237fb [project @ 1994-08-03 20:06:54 by jwe]
jwe
parents: 572
diff changeset
2438 case EXPR_EQ:
3525
6cfa474c5b99 [project @ 2000-02-02 10:48:41 by jwe]
jwe
parents: 3523
diff changeset
2439 t = octave_value::op_eq;
578
d169be9237fb [project @ 1994-08-03 20:06:54 by jwe]
jwe
parents: 572
diff changeset
2440 break;
777
a2f9d3fd720c [project @ 1994-10-07 14:01:53 by jwe]
jwe
parents: 773
diff changeset
2441
578
d169be9237fb [project @ 1994-08-03 20:06:54 by jwe]
jwe
parents: 572
diff changeset
2442 case EXPR_GE:
3525
6cfa474c5b99 [project @ 2000-02-02 10:48:41 by jwe]
jwe
parents: 3523
diff changeset
2443 t = octave_value::op_ge;
578
d169be9237fb [project @ 1994-08-03 20:06:54 by jwe]
jwe
parents: 572
diff changeset
2444 break;
777
a2f9d3fd720c [project @ 1994-10-07 14:01:53 by jwe]
jwe
parents: 773
diff changeset
2445
578
d169be9237fb [project @ 1994-08-03 20:06:54 by jwe]
jwe
parents: 572
diff changeset
2446 case EXPR_GT:
3525
6cfa474c5b99 [project @ 2000-02-02 10:48:41 by jwe]
jwe
parents: 3523
diff changeset
2447 t = octave_value::op_gt;
578
d169be9237fb [project @ 1994-08-03 20:06:54 by jwe]
jwe
parents: 572
diff changeset
2448 break;
777
a2f9d3fd720c [project @ 1994-10-07 14:01:53 by jwe]
jwe
parents: 773
diff changeset
2449
578
d169be9237fb [project @ 1994-08-03 20:06:54 by jwe]
jwe
parents: 572
diff changeset
2450 case EXPR_NE:
3525
6cfa474c5b99 [project @ 2000-02-02 10:48:41 by jwe]
jwe
parents: 3523
diff changeset
2451 t = octave_value::op_ne;
578
d169be9237fb [project @ 1994-08-03 20:06:54 by jwe]
jwe
parents: 572
diff changeset
2452 break;
777
a2f9d3fd720c [project @ 1994-10-07 14:01:53 by jwe]
jwe
parents: 773
diff changeset
2453
578
d169be9237fb [project @ 1994-08-03 20:06:54 by jwe]
jwe
parents: 572
diff changeset
2454 case EXPR_AND:
3525
6cfa474c5b99 [project @ 2000-02-02 10:48:41 by jwe]
jwe
parents: 3523
diff changeset
2455 t = octave_value::op_el_and;
578
d169be9237fb [project @ 1994-08-03 20:06:54 by jwe]
jwe
parents: 572
diff changeset
2456 break;
777
a2f9d3fd720c [project @ 1994-10-07 14:01:53 by jwe]
jwe
parents: 773
diff changeset
2457
578
d169be9237fb [project @ 1994-08-03 20:06:54 by jwe]
jwe
parents: 572
diff changeset
2458 case EXPR_OR:
3525
6cfa474c5b99 [project @ 2000-02-02 10:48:41 by jwe]
jwe
parents: 3523
diff changeset
2459 t = octave_value::op_el_or;
578
d169be9237fb [project @ 1994-08-03 20:06:54 by jwe]
jwe
parents: 572
diff changeset
2460 break;
777
a2f9d3fd720c [project @ 1994-10-07 14:01:53 by jwe]
jwe
parents: 773
diff changeset
2461
578
d169be9237fb [project @ 1994-08-03 20:06:54 by jwe]
jwe
parents: 572
diff changeset
2462 default:
d169be9237fb [project @ 1994-08-03 20:06:54 by jwe]
jwe
parents: 572
diff changeset
2463 panic_impossible ();
d169be9237fb [project @ 1994-08-03 20:06:54 by jwe]
jwe
parents: 572
diff changeset
2464 break;
d169be9237fb [project @ 1994-08-03 20:06:54 by jwe]
jwe
parents: 572
diff changeset
2465 }
d169be9237fb [project @ 1994-08-03 20:06:54 by jwe]
jwe
parents: 572
diff changeset
2466
d169be9237fb [project @ 1994-08-03 20:06:54 by jwe]
jwe
parents: 572
diff changeset
2467 int l = tok_val->line ();
d169be9237fb [project @ 1994-08-03 20:06:54 by jwe]
jwe
parents: 572
diff changeset
2468 int c = tok_val->column ();
d169be9237fb [project @ 1994-08-03 20:06:54 by jwe]
jwe
parents: 572
diff changeset
2469
18158
bf638abc95de eliminate constant folding in parser
John W. Eaton <jwe@octave.org>
parents: 18132
diff changeset
2470 return maybe_compound_binary_expression (op1, op2, l, c, t);
578
d169be9237fb [project @ 1994-08-03 20:06:54 by jwe]
jwe
parents: 572
diff changeset
2471 }
d169be9237fb [project @ 1994-08-03 20:06:54 by jwe]
jwe
parents: 572
diff changeset
2472
2375
7ef24992e290 [project @ 1996-10-12 00:39:52 by jwe]
jwe
parents: 2200
diff changeset
2473 // Build a boolean expression.
666
fb4f6556b443 [project @ 1994-09-06 21:22:46 by jwe]
jwe
parents: 627
diff changeset
2474
16134
ec9c6222ef5a move static parser helper functions to octave_parser class
John W. Eaton <jwe@octave.org>
parents: 16133
diff changeset
2475 tree_expression *
16287
04a7953496a7 create base class for parser; use reference for curr_lexer
John W. Eaton <jwe@octave.org>
parents: 16285
diff changeset
2476 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
2477 token *tok_val, tree_expression *op2)
578
d169be9237fb [project @ 1994-08-03 20:06:54 by jwe]
jwe
parents: 572
diff changeset
2478 {
2375
7ef24992e290 [project @ 1996-10-12 00:39:52 by jwe]
jwe
parents: 2200
diff changeset
2479 tree_boolean_expression::type t;
7ef24992e290 [project @ 1996-10-12 00:39:52 by jwe]
jwe
parents: 2200
diff changeset
2480
578
d169be9237fb [project @ 1994-08-03 20:06:54 by jwe]
jwe
parents: 572
diff changeset
2481 switch (op)
d169be9237fb [project @ 1994-08-03 20:06:54 by jwe]
jwe
parents: 572
diff changeset
2482 {
2375
7ef24992e290 [project @ 1996-10-12 00:39:52 by jwe]
jwe
parents: 2200
diff changeset
2483 case EXPR_AND_AND:
2805
68e6d0c93fc8 [project @ 1997-03-11 04:52:44 by jwe]
jwe
parents: 2791
diff changeset
2484 t = tree_boolean_expression::bool_and;
578
d169be9237fb [project @ 1994-08-03 20:06:54 by jwe]
jwe
parents: 572
diff changeset
2485 break;
777
a2f9d3fd720c [project @ 1994-10-07 14:01:53 by jwe]
jwe
parents: 773
diff changeset
2486
2375
7ef24992e290 [project @ 1996-10-12 00:39:52 by jwe]
jwe
parents: 2200
diff changeset
2487 case EXPR_OR_OR:
2805
68e6d0c93fc8 [project @ 1997-03-11 04:52:44 by jwe]
jwe
parents: 2791
diff changeset
2488 t = tree_boolean_expression::bool_or;
578
d169be9237fb [project @ 1994-08-03 20:06:54 by jwe]
jwe
parents: 572
diff changeset
2489 break;
777
a2f9d3fd720c [project @ 1994-10-07 14:01:53 by jwe]
jwe
parents: 773
diff changeset
2490
578
d169be9237fb [project @ 1994-08-03 20:06:54 by jwe]
jwe
parents: 572
diff changeset
2491 default:
d169be9237fb [project @ 1994-08-03 20:06:54 by jwe]
jwe
parents: 572
diff changeset
2492 panic_impossible ();
d169be9237fb [project @ 1994-08-03 20:06:54 by jwe]
jwe
parents: 572
diff changeset
2493 break;
d169be9237fb [project @ 1994-08-03 20:06:54 by jwe]
jwe
parents: 572
diff changeset
2494 }
d169be9237fb [project @ 1994-08-03 20:06:54 by jwe]
jwe
parents: 572
diff changeset
2495
d169be9237fb [project @ 1994-08-03 20:06:54 by jwe]
jwe
parents: 572
diff changeset
2496 int l = tok_val->line ();
d169be9237fb [project @ 1994-08-03 20:06:54 by jwe]
jwe
parents: 572
diff changeset
2497 int c = tok_val->column ();
d169be9237fb [project @ 1994-08-03 20:06:54 by jwe]
jwe
parents: 572
diff changeset
2498
18158
bf638abc95de eliminate constant folding in parser
John W. Eaton <jwe@octave.org>
parents: 18132
diff changeset
2499 return new tree_boolean_expression (op1, op2, l, c, t);
578
d169be9237fb [project @ 1994-08-03 20:06:54 by jwe]
jwe
parents: 572
diff changeset
2500 }
d169be9237fb [project @ 1994-08-03 20:06:54 by jwe]
jwe
parents: 572
diff changeset
2501
2375
7ef24992e290 [project @ 1996-10-12 00:39:52 by jwe]
jwe
parents: 2200
diff changeset
2502 // Build a prefix expression.
666
fb4f6556b443 [project @ 1994-09-06 21:22:46 by jwe]
jwe
parents: 627
diff changeset
2503
16134
ec9c6222ef5a move static parser helper functions to octave_parser class
John W. Eaton <jwe@octave.org>
parents: 16133
diff changeset
2504 tree_expression *
16287
04a7953496a7 create base class for parser; use reference for curr_lexer
John W. Eaton <jwe@octave.org>
parents: 16285
diff changeset
2505 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
2506 token *tok_val)
578
d169be9237fb [project @ 1994-08-03 20:06:54 by jwe]
jwe
parents: 572
diff changeset
2507 {
3203
bc61b0e8d60e [project @ 1998-10-30 20:26:27 by jwe]
jwe
parents: 3195
diff changeset
2508 octave_value::unary_op t = octave_value::unknown_unary_op;
2375
7ef24992e290 [project @ 1996-10-12 00:39:52 by jwe]
jwe
parents: 2200
diff changeset
2509
578
d169be9237fb [project @ 1994-08-03 20:06:54 by jwe]
jwe
parents: 572
diff changeset
2510 switch (op)
d169be9237fb [project @ 1994-08-03 20:06:54 by jwe]
jwe
parents: 572
diff changeset
2511 {
2960
194b50e4725b [project @ 1997-05-12 00:43:54 by jwe]
jwe
parents: 2899
diff changeset
2512 case EXPR_NOT:
3525
6cfa474c5b99 [project @ 2000-02-02 10:48:41 by jwe]
jwe
parents: 3523
diff changeset
2513 t = octave_value::op_not;
2960
194b50e4725b [project @ 1997-05-12 00:43:54 by jwe]
jwe
parents: 2899
diff changeset
2514 break;
194b50e4725b [project @ 1997-05-12 00:43:54 by jwe]
jwe
parents: 2899
diff changeset
2515
4965
c0d8e8afa82f [project @ 2004-09-06 20:19:57 by jwe]
jwe
parents: 4935
diff changeset
2516 case '+':
c0d8e8afa82f [project @ 2004-09-06 20:19:57 by jwe]
jwe
parents: 4935
diff changeset
2517 t = octave_value::op_uplus;
c0d8e8afa82f [project @ 2004-09-06 20:19:57 by jwe]
jwe
parents: 4935
diff changeset
2518 break;
c0d8e8afa82f [project @ 2004-09-06 20:19:57 by jwe]
jwe
parents: 4935
diff changeset
2519
2960
194b50e4725b [project @ 1997-05-12 00:43:54 by jwe]
jwe
parents: 2899
diff changeset
2520 case '-':
3525
6cfa474c5b99 [project @ 2000-02-02 10:48:41 by jwe]
jwe
parents: 3523
diff changeset
2521 t = octave_value::op_uminus;
2960
194b50e4725b [project @ 1997-05-12 00:43:54 by jwe]
jwe
parents: 2899
diff changeset
2522 break;
194b50e4725b [project @ 1997-05-12 00:43:54 by jwe]
jwe
parents: 2899
diff changeset
2523
578
d169be9237fb [project @ 1994-08-03 20:06:54 by jwe]
jwe
parents: 572
diff changeset
2524 case PLUS_PLUS:
3525
6cfa474c5b99 [project @ 2000-02-02 10:48:41 by jwe]
jwe
parents: 3523
diff changeset
2525 t = octave_value::op_incr;
578
d169be9237fb [project @ 1994-08-03 20:06:54 by jwe]
jwe
parents: 572
diff changeset
2526 break;
777
a2f9d3fd720c [project @ 1994-10-07 14:01:53 by jwe]
jwe
parents: 773
diff changeset
2527
578
d169be9237fb [project @ 1994-08-03 20:06:54 by jwe]
jwe
parents: 572
diff changeset
2528 case MINUS_MINUS:
3525
6cfa474c5b99 [project @ 2000-02-02 10:48:41 by jwe]
jwe
parents: 3523
diff changeset
2529 t = octave_value::op_decr;
578
d169be9237fb [project @ 1994-08-03 20:06:54 by jwe]
jwe
parents: 572
diff changeset
2530 break;
777
a2f9d3fd720c [project @ 1994-10-07 14:01:53 by jwe]
jwe
parents: 773
diff changeset
2531
578
d169be9237fb [project @ 1994-08-03 20:06:54 by jwe]
jwe
parents: 572
diff changeset
2532 default:
d169be9237fb [project @ 1994-08-03 20:06:54 by jwe]
jwe
parents: 572
diff changeset
2533 panic_impossible ();
d169be9237fb [project @ 1994-08-03 20:06:54 by jwe]
jwe
parents: 572
diff changeset
2534 break;
d169be9237fb [project @ 1994-08-03 20:06:54 by jwe]
jwe
parents: 572
diff changeset
2535 }
d169be9237fb [project @ 1994-08-03 20:06:54 by jwe]
jwe
parents: 572
diff changeset
2536
d169be9237fb [project @ 1994-08-03 20:06:54 by jwe]
jwe
parents: 572
diff changeset
2537 int l = tok_val->line ();
d169be9237fb [project @ 1994-08-03 20:06:54 by jwe]
jwe
parents: 572
diff changeset
2538 int c = tok_val->column ();
d169be9237fb [project @ 1994-08-03 20:06:54 by jwe]
jwe
parents: 572
diff changeset
2539
18158
bf638abc95de eliminate constant folding in parser
John W. Eaton <jwe@octave.org>
parents: 18132
diff changeset
2540 return new tree_prefix_expression (op1, l, c, t);
578
d169be9237fb [project @ 1994-08-03 20:06:54 by jwe]
jwe
parents: 572
diff changeset
2541 }
d169be9237fb [project @ 1994-08-03 20:06:54 by jwe]
jwe
parents: 572
diff changeset
2542
2375
7ef24992e290 [project @ 1996-10-12 00:39:52 by jwe]
jwe
parents: 2200
diff changeset
2543 // Build a postfix expression.
666
fb4f6556b443 [project @ 1994-09-06 21:22:46 by jwe]
jwe
parents: 627
diff changeset
2544
16134
ec9c6222ef5a move static parser helper functions to octave_parser class
John W. Eaton <jwe@octave.org>
parents: 16133
diff changeset
2545 tree_expression *
16287
04a7953496a7 create base class for parser; use reference for curr_lexer
John W. Eaton <jwe@octave.org>
parents: 16285
diff changeset
2546 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
2547 token *tok_val)
578
d169be9237fb [project @ 1994-08-03 20:06:54 by jwe]
jwe
parents: 572
diff changeset
2548 {
3203
bc61b0e8d60e [project @ 1998-10-30 20:26:27 by jwe]
jwe
parents: 3195
diff changeset
2549 octave_value::unary_op t = octave_value::unknown_unary_op;
1623
fa7a847f9b92 [project @ 1995-11-06 18:05:09 by jwe]
jwe
parents: 1607
diff changeset
2550
578
d169be9237fb [project @ 1994-08-03 20:06:54 by jwe]
jwe
parents: 572
diff changeset
2551 switch (op)
d169be9237fb [project @ 1994-08-03 20:06:54 by jwe]
jwe
parents: 572
diff changeset
2552 {
16284
09881dab3aaf * lex.ll, oct-parse.in.yy (HERMITIAN): Rename token from QUOTE.
John W. Eaton <jwe@octave.org>
parents: 16279
diff changeset
2553 case HERMITIAN:
3525
6cfa474c5b99 [project @ 2000-02-02 10:48:41 by jwe]
jwe
parents: 3523
diff changeset
2554 t = octave_value::op_hermitian;
2960
194b50e4725b [project @ 1997-05-12 00:43:54 by jwe]
jwe
parents: 2899
diff changeset
2555 break;
194b50e4725b [project @ 1997-05-12 00:43:54 by jwe]
jwe
parents: 2899
diff changeset
2556
194b50e4725b [project @ 1997-05-12 00:43:54 by jwe]
jwe
parents: 2899
diff changeset
2557 case TRANSPOSE:
3525
6cfa474c5b99 [project @ 2000-02-02 10:48:41 by jwe]
jwe
parents: 3523
diff changeset
2558 t = octave_value::op_transpose;
2960
194b50e4725b [project @ 1997-05-12 00:43:54 by jwe]
jwe
parents: 2899
diff changeset
2559 break;
194b50e4725b [project @ 1997-05-12 00:43:54 by jwe]
jwe
parents: 2899
diff changeset
2560
2375
7ef24992e290 [project @ 1996-10-12 00:39:52 by jwe]
jwe
parents: 2200
diff changeset
2561 case PLUS_PLUS:
3525
6cfa474c5b99 [project @ 2000-02-02 10:48:41 by jwe]
jwe
parents: 3523
diff changeset
2562 t = octave_value::op_incr;
578
d169be9237fb [project @ 1994-08-03 20:06:54 by jwe]
jwe
parents: 572
diff changeset
2563 break;
777
a2f9d3fd720c [project @ 1994-10-07 14:01:53 by jwe]
jwe
parents: 773
diff changeset
2564
2375
7ef24992e290 [project @ 1996-10-12 00:39:52 by jwe]
jwe
parents: 2200
diff changeset
2565 case MINUS_MINUS:
3525
6cfa474c5b99 [project @ 2000-02-02 10:48:41 by jwe]
jwe
parents: 3523
diff changeset
2566 t = octave_value::op_decr;
578
d169be9237fb [project @ 1994-08-03 20:06:54 by jwe]
jwe
parents: 572
diff changeset
2567 break;
777
a2f9d3fd720c [project @ 1994-10-07 14:01:53 by jwe]
jwe
parents: 773
diff changeset
2568
578
d169be9237fb [project @ 1994-08-03 20:06:54 by jwe]
jwe
parents: 572
diff changeset
2569 default:
d169be9237fb [project @ 1994-08-03 20:06:54 by jwe]
jwe
parents: 572
diff changeset
2570 panic_impossible ();
d169be9237fb [project @ 1994-08-03 20:06:54 by jwe]
jwe
parents: 572
diff changeset
2571 break;
d169be9237fb [project @ 1994-08-03 20:06:54 by jwe]
jwe
parents: 572
diff changeset
2572 }
d169be9237fb [project @ 1994-08-03 20:06:54 by jwe]
jwe
parents: 572
diff changeset
2573
d169be9237fb [project @ 1994-08-03 20:06:54 by jwe]
jwe
parents: 572
diff changeset
2574 int l = tok_val->line ();
d169be9237fb [project @ 1994-08-03 20:06:54 by jwe]
jwe
parents: 572
diff changeset
2575 int c = tok_val->column ();
d169be9237fb [project @ 1994-08-03 20:06:54 by jwe]
jwe
parents: 572
diff changeset
2576
18158
bf638abc95de eliminate constant folding in parser
John W. Eaton <jwe@octave.org>
parents: 18132
diff changeset
2577 return new tree_postfix_expression (op1, l, c, t);
1623
fa7a847f9b92 [project @ 1995-11-06 18:05:09 by jwe]
jwe
parents: 1607
diff changeset
2578 }
fa7a847f9b92 [project @ 1995-11-06 18:05:09 by jwe]
jwe
parents: 1607
diff changeset
2579
fa7a847f9b92 [project @ 1995-11-06 18:05:09 by jwe]
jwe
parents: 1607
diff changeset
2580 // Build an unwind-protect command.
fa7a847f9b92 [project @ 1995-11-06 18:05:09 by jwe]
jwe
parents: 1607
diff changeset
2581
16134
ec9c6222ef5a move static parser helper functions to octave_parser class
John W. Eaton <jwe@octave.org>
parents: 16133
diff changeset
2582 tree_command *
16287
04a7953496a7 create base class for parser; use reference for curr_lexer
John W. Eaton <jwe@octave.org>
parents: 16285
diff changeset
2583 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
2584 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
2585 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
2586 token *end_tok,
04a7953496a7 create base class for parser; use reference for curr_lexer
John W. Eaton <jwe@octave.org>
parents: 16285
diff changeset
2587 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
2588 octave_comment_list *mc)
1623
fa7a847f9b92 [project @ 1995-11-06 18:05:09 by jwe]
jwe
parents: 1607
diff changeset
2589 {
fa7a847f9b92 [project @ 1995-11-06 18:05:09 by jwe]
jwe
parents: 1607
diff changeset
2590 tree_command *retval = 0;
fa7a847f9b92 [project @ 1995-11-06 18:05:09 by jwe]
jwe
parents: 1607
diff changeset
2591
2857
5448c8cba402 [project @ 1997-03-31 07:06:10 by jwe]
jwe
parents: 2856
diff changeset
2592 if (end_token_ok (end_tok, token::unwind_protect_end))
1623
fa7a847f9b92 [project @ 1995-11-06 18:05:09 by jwe]
jwe
parents: 1607
diff changeset
2593 {
17693
efbe746f8fa8 eliminate octave_comment_buffer singleton
John W. Eaton <jwe@octave.org>
parents: 17673
diff changeset
2594 octave_comment_list *tc = lexer.comment_buf.get_comment ();
3665
0689afb1d001 [project @ 2000-05-11 19:07:56 by jwe]
jwe
parents: 3544
diff changeset
2595
1623
fa7a847f9b92 [project @ 1995-11-06 18:05:09 by jwe]
jwe
parents: 1607
diff changeset
2596 int l = unwind_tok->line ();
fa7a847f9b92 [project @ 1995-11-06 18:05:09 by jwe]
jwe
parents: 1607
diff changeset
2597 int c = unwind_tok->column ();
fa7a847f9b92 [project @ 1995-11-06 18:05:09 by jwe]
jwe
parents: 1607
diff changeset
2598
16136
ed36d5543b27 don't declare octave_parser member functions static
John W. Eaton <jwe@octave.org>
parents: 16134
diff changeset
2599 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
2600 lc, mc, tc, l, c);
1623
fa7a847f9b92 [project @ 1995-11-06 18:05:09 by jwe]
jwe
parents: 1607
diff changeset
2601 }
17632
bd0a84de3375 further reduce memory leaks from parse errors (bug #40231)
John W. Eaton <jwe@octave.org>
parents: 17629
diff changeset
2602 else
bd0a84de3375 further reduce memory leaks from parse errors (bug #40231)
John W. Eaton <jwe@octave.org>
parents: 17629
diff changeset
2603 {
bd0a84de3375 further reduce memory leaks from parse errors (bug #40231)
John W. Eaton <jwe@octave.org>
parents: 17629
diff changeset
2604 delete body;
bd0a84de3375 further reduce memory leaks from parse errors (bug #40231)
John W. Eaton <jwe@octave.org>
parents: 17629
diff changeset
2605 delete cleanup_stmts;
21071
f25c14056b7c overhaul parser error handling for end token mismatch
John W. Eaton <jwe@octave.org>
parents: 21066
diff changeset
2606
f25c14056b7c overhaul parser error handling for end token mismatch
John W. Eaton <jwe@octave.org>
parents: 21066
diff changeset
2607 end_token_error (end_tok, token::unwind_protect_end);
17632
bd0a84de3375 further reduce memory leaks from parse errors (bug #40231)
John W. Eaton <jwe@octave.org>
parents: 17629
diff changeset
2608 }
1623
fa7a847f9b92 [project @ 1995-11-06 18:05:09 by jwe]
jwe
parents: 1607
diff changeset
2609
fa7a847f9b92 [project @ 1995-11-06 18:05:09 by jwe]
jwe
parents: 1607
diff changeset
2610 return retval;
fa7a847f9b92 [project @ 1995-11-06 18:05:09 by jwe]
jwe
parents: 1607
diff changeset
2611 }
fa7a847f9b92 [project @ 1995-11-06 18:05:09 by jwe]
jwe
parents: 1607
diff changeset
2612
fa7a847f9b92 [project @ 1995-11-06 18:05:09 by jwe]
jwe
parents: 1607
diff changeset
2613 // Build a try-catch command.
fa7a847f9b92 [project @ 1995-11-06 18:05:09 by jwe]
jwe
parents: 1607
diff changeset
2614
16134
ec9c6222ef5a move static parser helper functions to octave_parser class
John W. Eaton <jwe@octave.org>
parents: 16133
diff changeset
2615 tree_command *
16287
04a7953496a7 create base class for parser; use reference for curr_lexer
John W. Eaton <jwe@octave.org>
parents: 16285
diff changeset
2616 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
2617 tree_statement_list *body,
17283
e6c0ac8ce5b6 eliminate parse conflicts introduced by changeset 923ce8b42db2
John W. Eaton <jwe@octave.org>
parents: 17281
diff changeset
2618 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
2619 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
2620 token *end_tok,
04a7953496a7 create base class for parser; use reference for curr_lexer
John W. Eaton <jwe@octave.org>
parents: 16285
diff changeset
2621 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
2622 octave_comment_list *mc)
1623
fa7a847f9b92 [project @ 1995-11-06 18:05:09 by jwe]
jwe
parents: 1607
diff changeset
2623 {
fa7a847f9b92 [project @ 1995-11-06 18:05:09 by jwe]
jwe
parents: 1607
diff changeset
2624 tree_command *retval = 0;
fa7a847f9b92 [project @ 1995-11-06 18:05:09 by jwe]
jwe
parents: 1607
diff changeset
2625
2857
5448c8cba402 [project @ 1997-03-31 07:06:10 by jwe]
jwe
parents: 2856
diff changeset
2626 if (end_token_ok (end_tok, token::try_catch_end))
1623
fa7a847f9b92 [project @ 1995-11-06 18:05:09 by jwe]
jwe
parents: 1607
diff changeset
2627 {
17693
efbe746f8fa8 eliminate octave_comment_buffer singleton
John W. Eaton <jwe@octave.org>
parents: 17673
diff changeset
2628 octave_comment_list *tc = lexer.comment_buf.get_comment ();
3665
0689afb1d001 [project @ 2000-05-11 19:07:56 by jwe]
jwe
parents: 3544
diff changeset
2629
1623
fa7a847f9b92 [project @ 1995-11-06 18:05:09 by jwe]
jwe
parents: 1607
diff changeset
2630 int l = try_tok->line ();
fa7a847f9b92 [project @ 1995-11-06 18:05:09 by jwe]
jwe
parents: 1607
diff changeset
2631 int c = try_tok->column ();
fa7a847f9b92 [project @ 1995-11-06 18:05:09 by jwe]
jwe
parents: 1607
diff changeset
2632
17283
e6c0ac8ce5b6 eliminate parse conflicts introduced by changeset 923ce8b42db2
John W. Eaton <jwe@octave.org>
parents: 17281
diff changeset
2633 tree_identifier *id = 0;
e6c0ac8ce5b6 eliminate parse conflicts introduced by changeset 923ce8b42db2
John W. Eaton <jwe@octave.org>
parents: 17281
diff changeset
2634
e6c0ac8ce5b6 eliminate parse conflicts introduced by changeset 923ce8b42db2
John W. Eaton <jwe@octave.org>
parents: 17281
diff changeset
2635 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
2636 {
e6c0ac8ce5b6 eliminate parse conflicts introduced by changeset 923ce8b42db2
John W. Eaton <jwe@octave.org>
parents: 17281
diff changeset
2637 tree_statement *stmt = cleanup_stmts->front ();
e6c0ac8ce5b6 eliminate parse conflicts introduced by changeset 923ce8b42db2
John W. Eaton <jwe@octave.org>
parents: 17281
diff changeset
2638
e6c0ac8ce5b6 eliminate parse conflicts introduced by changeset 923ce8b42db2
John W. Eaton <jwe@octave.org>
parents: 17281
diff changeset
2639 if (stmt)
e6c0ac8ce5b6 eliminate parse conflicts introduced by changeset 923ce8b42db2
John W. Eaton <jwe@octave.org>
parents: 17281
diff changeset
2640 {
e6c0ac8ce5b6 eliminate parse conflicts introduced by changeset 923ce8b42db2
John W. Eaton <jwe@octave.org>
parents: 17281
diff changeset
2641 tree_expression *expr = stmt->expression ();
e6c0ac8ce5b6 eliminate parse conflicts introduced by changeset 923ce8b42db2
John W. Eaton <jwe@octave.org>
parents: 17281
diff changeset
2642
e6c0ac8ce5b6 eliminate parse conflicts introduced by changeset 923ce8b42db2
John W. Eaton <jwe@octave.org>
parents: 17281
diff changeset
2643 if (expr && expr->is_identifier ())
e6c0ac8ce5b6 eliminate parse conflicts introduced by changeset 923ce8b42db2
John W. Eaton <jwe@octave.org>
parents: 17281
diff changeset
2644 {
e6c0ac8ce5b6 eliminate parse conflicts introduced by changeset 923ce8b42db2
John W. Eaton <jwe@octave.org>
parents: 17281
diff changeset
2645 id = dynamic_cast<tree_identifier *> (expr);
e6c0ac8ce5b6 eliminate parse conflicts introduced by changeset 923ce8b42db2
John W. Eaton <jwe@octave.org>
parents: 17281
diff changeset
2646
e6c0ac8ce5b6 eliminate parse conflicts introduced by changeset 923ce8b42db2
John W. Eaton <jwe@octave.org>
parents: 17281
diff changeset
2647 cleanup_stmts->pop_front ();
17673
9f6e4e5c2bac avoid memory leak in parser (bug #40231)
John W. Eaton <jwe@octave.org>
parents: 17658
diff changeset
2648
9f6e4e5c2bac avoid memory leak in parser (bug #40231)
John W. Eaton <jwe@octave.org>
parents: 17658
diff changeset
2649 stmt->set_expression (0);
9f6e4e5c2bac avoid memory leak in parser (bug #40231)
John W. Eaton <jwe@octave.org>
parents: 17658
diff changeset
2650 delete stmt;
17283
e6c0ac8ce5b6 eliminate parse conflicts introduced by changeset 923ce8b42db2
John W. Eaton <jwe@octave.org>
parents: 17281
diff changeset
2651 }
e6c0ac8ce5b6 eliminate parse conflicts introduced by changeset 923ce8b42db2
John W. Eaton <jwe@octave.org>
parents: 17281
diff changeset
2652 }
e6c0ac8ce5b6 eliminate parse conflicts introduced by changeset 923ce8b42db2
John W. Eaton <jwe@octave.org>
parents: 17281
diff changeset
2653 }
e6c0ac8ce5b6 eliminate parse conflicts introduced by changeset 923ce8b42db2
John W. Eaton <jwe@octave.org>
parents: 17281
diff changeset
2654
17249
923ce8b42db2 improve try-catch-statement to save exception to a variable (bug #33217)
Stefan Mahr <dac922@gmx.de>
parents: 17170
diff changeset
2655 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
2656 lc, mc, tc, l, c);
1623
fa7a847f9b92 [project @ 1995-11-06 18:05:09 by jwe]
jwe
parents: 1607
diff changeset
2657 }
17632
bd0a84de3375 further reduce memory leaks from parse errors (bug #40231)
John W. Eaton <jwe@octave.org>
parents: 17629
diff changeset
2658 else
bd0a84de3375 further reduce memory leaks from parse errors (bug #40231)
John W. Eaton <jwe@octave.org>
parents: 17629
diff changeset
2659 {
bd0a84de3375 further reduce memory leaks from parse errors (bug #40231)
John W. Eaton <jwe@octave.org>
parents: 17629
diff changeset
2660 delete body;
bd0a84de3375 further reduce memory leaks from parse errors (bug #40231)
John W. Eaton <jwe@octave.org>
parents: 17629
diff changeset
2661 delete cleanup_stmts;
21071
f25c14056b7c overhaul parser error handling for end token mismatch
John W. Eaton <jwe@octave.org>
parents: 21066
diff changeset
2662
f25c14056b7c overhaul parser error handling for end token mismatch
John W. Eaton <jwe@octave.org>
parents: 21066
diff changeset
2663 end_token_error (end_tok, token::try_catch_end);
17632
bd0a84de3375 further reduce memory leaks from parse errors (bug #40231)
John W. Eaton <jwe@octave.org>
parents: 17629
diff changeset
2664 }
1623
fa7a847f9b92 [project @ 1995-11-06 18:05:09 by jwe]
jwe
parents: 1607
diff changeset
2665
fa7a847f9b92 [project @ 1995-11-06 18:05:09 by jwe]
jwe
parents: 1607
diff changeset
2666 return retval;
fa7a847f9b92 [project @ 1995-11-06 18:05:09 by jwe]
jwe
parents: 1607
diff changeset
2667 }
fa7a847f9b92 [project @ 1995-11-06 18:05:09 by jwe]
jwe
parents: 1607
diff changeset
2668
fa7a847f9b92 [project @ 1995-11-06 18:05:09 by jwe]
jwe
parents: 1607
diff changeset
2669 // Build a while command.
fa7a847f9b92 [project @ 1995-11-06 18:05:09 by jwe]
jwe
parents: 1607
diff changeset
2670
16134
ec9c6222ef5a move static parser helper functions to octave_parser class
John W. Eaton <jwe@octave.org>
parents: 16133
diff changeset
2671 tree_command *
16287
04a7953496a7 create base class for parser; use reference for curr_lexer
John W. Eaton <jwe@octave.org>
parents: 16285
diff changeset
2672 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
2673 tree_expression *expr,
04a7953496a7 create base class for parser; use reference for curr_lexer
John W. Eaton <jwe@octave.org>
parents: 16285
diff changeset
2674 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
2675 token *end_tok,
04a7953496a7 create base class for parser; use reference for curr_lexer
John W. Eaton <jwe@octave.org>
parents: 16285
diff changeset
2676 octave_comment_list *lc)
1623
fa7a847f9b92 [project @ 1995-11-06 18:05:09 by jwe]
jwe
parents: 1607
diff changeset
2677 {
fa7a847f9b92 [project @ 1995-11-06 18:05:09 by jwe]
jwe
parents: 1607
diff changeset
2678 tree_command *retval = 0;
fa7a847f9b92 [project @ 1995-11-06 18:05:09 by jwe]
jwe
parents: 1607
diff changeset
2679
fa7a847f9b92 [project @ 1995-11-06 18:05:09 by jwe]
jwe
parents: 1607
diff changeset
2680 maybe_warn_assign_as_truth_value (expr);
fa7a847f9b92 [project @ 1995-11-06 18:05:09 by jwe]
jwe
parents: 1607
diff changeset
2681
2857
5448c8cba402 [project @ 1997-03-31 07:06:10 by jwe]
jwe
parents: 2856
diff changeset
2682 if (end_token_ok (end_tok, token::while_end))
1623
fa7a847f9b92 [project @ 1995-11-06 18:05:09 by jwe]
jwe
parents: 1607
diff changeset
2683 {
17693
efbe746f8fa8 eliminate octave_comment_buffer singleton
John W. Eaton <jwe@octave.org>
parents: 17673
diff changeset
2684 octave_comment_list *tc = lexer.comment_buf.get_comment ();
3665
0689afb1d001 [project @ 2000-05-11 19:07:56 by jwe]
jwe
parents: 3544
diff changeset
2685
16288
fe3b9a51e625 rename curr_lexer, curr_parser, CURR_LEXER
John W. Eaton <jwe@octave.org>
parents: 16287
diff changeset
2686 lexer.looping--;
1623
fa7a847f9b92 [project @ 1995-11-06 18:05:09 by jwe]
jwe
parents: 1607
diff changeset
2687
fa7a847f9b92 [project @ 1995-11-06 18:05:09 by jwe]
jwe
parents: 1607
diff changeset
2688 int l = while_tok->line ();
fa7a847f9b92 [project @ 1995-11-06 18:05:09 by jwe]
jwe
parents: 1607
diff changeset
2689 int c = while_tok->column ();
fa7a847f9b92 [project @ 1995-11-06 18:05:09 by jwe]
jwe
parents: 1607
diff changeset
2690
3665
0689afb1d001 [project @ 2000-05-11 19:07:56 by jwe]
jwe
parents: 3544
diff changeset
2691 retval = new tree_while_command (expr, body, lc, tc, l, c);
1623
fa7a847f9b92 [project @ 1995-11-06 18:05:09 by jwe]
jwe
parents: 1607
diff changeset
2692 }
17632
bd0a84de3375 further reduce memory leaks from parse errors (bug #40231)
John W. Eaton <jwe@octave.org>
parents: 17629
diff changeset
2693 else
bd0a84de3375 further reduce memory leaks from parse errors (bug #40231)
John W. Eaton <jwe@octave.org>
parents: 17629
diff changeset
2694 {
bd0a84de3375 further reduce memory leaks from parse errors (bug #40231)
John W. Eaton <jwe@octave.org>
parents: 17629
diff changeset
2695 delete expr;
bd0a84de3375 further reduce memory leaks from parse errors (bug #40231)
John W. Eaton <jwe@octave.org>
parents: 17629
diff changeset
2696 delete body;
21071
f25c14056b7c overhaul parser error handling for end token mismatch
John W. Eaton <jwe@octave.org>
parents: 21066
diff changeset
2697
f25c14056b7c overhaul parser error handling for end token mismatch
John W. Eaton <jwe@octave.org>
parents: 21066
diff changeset
2698 end_token_error (end_tok, token::while_end);
17632
bd0a84de3375 further reduce memory leaks from parse errors (bug #40231)
John W. Eaton <jwe@octave.org>
parents: 17629
diff changeset
2699 }
1623
fa7a847f9b92 [project @ 1995-11-06 18:05:09 by jwe]
jwe
parents: 1607
diff changeset
2700
fa7a847f9b92 [project @ 1995-11-06 18:05:09 by jwe]
jwe
parents: 1607
diff changeset
2701 return retval;
fa7a847f9b92 [project @ 1995-11-06 18:05:09 by jwe]
jwe
parents: 1607
diff changeset
2702 }
fa7a847f9b92 [project @ 1995-11-06 18:05:09 by jwe]
jwe
parents: 1607
diff changeset
2703
3484
8b1f46ac2b64 [project @ 2000-01-27 23:30:45 by jwe]
jwe
parents: 3446
diff changeset
2704 // Build a do-until command.
8b1f46ac2b64 [project @ 2000-01-27 23:30:45 by jwe]
jwe
parents: 3446
diff changeset
2705
16134
ec9c6222ef5a move static parser helper functions to octave_parser class
John W. Eaton <jwe@octave.org>
parents: 16133
diff changeset
2706 tree_command *
16287
04a7953496a7 create base class for parser; use reference for curr_lexer
John W. Eaton <jwe@octave.org>
parents: 16285
diff changeset
2707 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
2708 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
2709 tree_expression *expr,
04a7953496a7 create base class for parser; use reference for curr_lexer
John W. Eaton <jwe@octave.org>
parents: 16285
diff changeset
2710 octave_comment_list *lc)
3484
8b1f46ac2b64 [project @ 2000-01-27 23:30:45 by jwe]
jwe
parents: 3446
diff changeset
2711 {
8b1f46ac2b64 [project @ 2000-01-27 23:30:45 by jwe]
jwe
parents: 3446
diff changeset
2712 maybe_warn_assign_as_truth_value (expr);
8b1f46ac2b64 [project @ 2000-01-27 23:30:45 by jwe]
jwe
parents: 3446
diff changeset
2713
17693
efbe746f8fa8 eliminate octave_comment_buffer singleton
John W. Eaton <jwe@octave.org>
parents: 17673
diff changeset
2714 octave_comment_list *tc = lexer.comment_buf.get_comment ();
3665
0689afb1d001 [project @ 2000-05-11 19:07:56 by jwe]
jwe
parents: 3544
diff changeset
2715
16288
fe3b9a51e625 rename curr_lexer, curr_parser, CURR_LEXER
John W. Eaton <jwe@octave.org>
parents: 16287
diff changeset
2716 lexer.looping--;
3484
8b1f46ac2b64 [project @ 2000-01-27 23:30:45 by jwe]
jwe
parents: 3446
diff changeset
2717
8658
73c4516fae10 New evaluator and debugger derived from tree-walker class
John W. Eaton <jwe@octave.org>
parents: 8471
diff changeset
2718 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
2719 int c = until_tok->column ();
3484
8b1f46ac2b64 [project @ 2000-01-27 23:30:45 by jwe]
jwe
parents: 3446
diff changeset
2720
17632
bd0a84de3375 further reduce memory leaks from parse errors (bug #40231)
John W. Eaton <jwe@octave.org>
parents: 17629
diff changeset
2721 return new tree_do_until_command (expr, body, lc, tc, l, c);
3484
8b1f46ac2b64 [project @ 2000-01-27 23:30:45 by jwe]
jwe
parents: 3446
diff changeset
2722 }
8b1f46ac2b64 [project @ 2000-01-27 23:30:45 by jwe]
jwe
parents: 3446
diff changeset
2723
1623
fa7a847f9b92 [project @ 1995-11-06 18:05:09 by jwe]
jwe
parents: 1607
diff changeset
2724 // Build a for command.
fa7a847f9b92 [project @ 1995-11-06 18:05:09 by jwe]
jwe
parents: 1607
diff changeset
2725
16134
ec9c6222ef5a move static parser helper functions to octave_parser class
John W. Eaton <jwe@octave.org>
parents: 16133
diff changeset
2726 tree_command *
16287
04a7953496a7 create base class for parser; use reference for curr_lexer
John W. Eaton <jwe@octave.org>
parents: 16285
diff changeset
2727 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
2728 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
2729 tree_expression *expr,
04a7953496a7 create base class for parser; use reference for curr_lexer
John W. Eaton <jwe@octave.org>
parents: 16285
diff changeset
2730 tree_expression *maxproc,
04a7953496a7 create base class for parser; use reference for curr_lexer
John W. Eaton <jwe@octave.org>
parents: 16285
diff changeset
2731 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
2732 token *end_tok,
04a7953496a7 create base class for parser; use reference for curr_lexer
John W. Eaton <jwe@octave.org>
parents: 16285
diff changeset
2733 octave_comment_list *lc)
1623
fa7a847f9b92 [project @ 1995-11-06 18:05:09 by jwe]
jwe
parents: 1607
diff changeset
2734 {
fa7a847f9b92 [project @ 1995-11-06 18:05:09 by jwe]
jwe
parents: 1607
diff changeset
2735 tree_command *retval = 0;
fa7a847f9b92 [project @ 1995-11-06 18:05:09 by jwe]
jwe
parents: 1607
diff changeset
2736
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
2737 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
2738
027a2186cd90 parfor keyword and infrastructure, but handle parfor as normal for loop for now
John W. Eaton <jwe@octave.org>
parents: 13241
diff changeset
2739 if (end_token_ok (end_tok, parfor ? token::parfor_end : token::for_end))
1623
fa7a847f9b92 [project @ 1995-11-06 18:05:09 by jwe]
jwe
parents: 1607
diff changeset
2740 {
19394
b39cbe9f3bb0 allow ranges to be disabled
John W. Eaton <jwe@octave.org>
parents: 18976
diff changeset
2741 expr->mark_as_for_cmd_expr ();
b39cbe9f3bb0 allow ranges to be disabled
John W. Eaton <jwe@octave.org>
parents: 18976
diff changeset
2742
17693
efbe746f8fa8 eliminate octave_comment_buffer singleton
John W. Eaton <jwe@octave.org>
parents: 17673
diff changeset
2743 octave_comment_list *tc = lexer.comment_buf.get_comment ();
3665
0689afb1d001 [project @ 2000-05-11 19:07:56 by jwe]
jwe
parents: 3544
diff changeset
2744
16288
fe3b9a51e625 rename curr_lexer, curr_parser, CURR_LEXER
John W. Eaton <jwe@octave.org>
parents: 16287
diff changeset
2745 lexer.looping--;
1623
fa7a847f9b92 [project @ 1995-11-06 18:05:09 by jwe]
jwe
parents: 1607
diff changeset
2746
fa7a847f9b92 [project @ 1995-11-06 18:05:09 by jwe]
jwe
parents: 1607
diff changeset
2747 int l = for_tok->line ();
fa7a847f9b92 [project @ 1995-11-06 18:05:09 by jwe]
jwe
parents: 1607
diff changeset
2748 int c = for_tok->column ();
fa7a847f9b92 [project @ 1995-11-06 18:05:09 by jwe]
jwe
parents: 1607
diff changeset
2749
2970
b9e64477f703 [project @ 1997-05-15 18:04:21 by jwe]
jwe
parents: 2961
diff changeset
2750 if (lhs->length () == 1)
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
2751 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
2752 tree_expression *tmp = lhs->remove_front ();
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
2753
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
2754 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
2755 body, lc, tc, l, c);
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
2756
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
2757 delete lhs;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
2758 }
2970
b9e64477f703 [project @ 1997-05-15 18:04:21 by jwe]
jwe
parents: 2961
diff changeset
2759 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
2760 {
027a2186cd90 parfor keyword and infrastructure, but handle parfor as normal for loop for now
John W. Eaton <jwe@octave.org>
parents: 13241
diff changeset
2761 if (parfor)
21073
f7cc48f601d2 additional reworking of error handling in the parser (bug #46877)
John W. Eaton <jwe@octave.org>
parents: 21071
diff changeset
2762 {
f7cc48f601d2 additional reworking of error handling in the parser (bug #46877)
John W. Eaton <jwe@octave.org>
parents: 21071
diff changeset
2763 delete lhs;
f7cc48f601d2 additional reworking of error handling in the parser (bug #46877)
John W. Eaton <jwe@octave.org>
parents: 21071
diff changeset
2764 delete expr;
f7cc48f601d2 additional reworking of error handling in the parser (bug #46877)
John W. Eaton <jwe@octave.org>
parents: 21071
diff changeset
2765 delete maxproc;
f7cc48f601d2 additional reworking of error handling in the parser (bug #46877)
John W. Eaton <jwe@octave.org>
parents: 21071
diff changeset
2766 delete body;
f7cc48f601d2 additional reworking of error handling in the parser (bug #46877)
John W. Eaton <jwe@octave.org>
parents: 21071
diff changeset
2767
f7cc48f601d2 additional reworking of error handling in the parser (bug #46877)
John W. Eaton <jwe@octave.org>
parents: 21071
diff changeset
2768 bison_error ("invalid syntax for parfor statement");
f7cc48f601d2 additional reworking of error handling in the parser (bug #46877)
John W. Eaton <jwe@octave.org>
parents: 21071
diff changeset
2769 }
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
2770 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
2771 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
2772 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
2773 }
1623
fa7a847f9b92 [project @ 1995-11-06 18:05:09 by jwe]
jwe
parents: 1607
diff changeset
2774 }
17632
bd0a84de3375 further reduce memory leaks from parse errors (bug #40231)
John W. Eaton <jwe@octave.org>
parents: 17629
diff changeset
2775 else
bd0a84de3375 further reduce memory leaks from parse errors (bug #40231)
John W. Eaton <jwe@octave.org>
parents: 17629
diff changeset
2776 {
bd0a84de3375 further reduce memory leaks from parse errors (bug #40231)
John W. Eaton <jwe@octave.org>
parents: 17629
diff changeset
2777 delete lhs;
bd0a84de3375 further reduce memory leaks from parse errors (bug #40231)
John W. Eaton <jwe@octave.org>
parents: 17629
diff changeset
2778 delete expr;
bd0a84de3375 further reduce memory leaks from parse errors (bug #40231)
John W. Eaton <jwe@octave.org>
parents: 17629
diff changeset
2779 delete maxproc;
bd0a84de3375 further reduce memory leaks from parse errors (bug #40231)
John W. Eaton <jwe@octave.org>
parents: 17629
diff changeset
2780 delete body;
21071
f25c14056b7c overhaul parser error handling for end token mismatch
John W. Eaton <jwe@octave.org>
parents: 21066
diff changeset
2781
f25c14056b7c overhaul parser error handling for end token mismatch
John W. Eaton <jwe@octave.org>
parents: 21066
diff changeset
2782 end_token_error (end_tok, parfor ? token::parfor_end : token::for_end);
17632
bd0a84de3375 further reduce memory leaks from parse errors (bug #40231)
John W. Eaton <jwe@octave.org>
parents: 17629
diff changeset
2783 }
1623
fa7a847f9b92 [project @ 1995-11-06 18:05:09 by jwe]
jwe
parents: 1607
diff changeset
2784
fa7a847f9b92 [project @ 1995-11-06 18:05:09 by jwe]
jwe
parents: 1607
diff changeset
2785 return retval;
fa7a847f9b92 [project @ 1995-11-06 18:05:09 by jwe]
jwe
parents: 1607
diff changeset
2786 }
fa7a847f9b92 [project @ 1995-11-06 18:05:09 by jwe]
jwe
parents: 1607
diff changeset
2787
4207
fa3482b34599 [project @ 2002-12-03 18:22:05 by jwe]
jwe
parents: 4186
diff changeset
2788 // Build a break command.
fa3482b34599 [project @ 2002-12-03 18:22:05 by jwe]
jwe
parents: 4186
diff changeset
2789
16134
ec9c6222ef5a move static parser helper functions to octave_parser class
John W. Eaton <jwe@octave.org>
parents: 16133
diff changeset
2790 tree_command *
16287
04a7953496a7 create base class for parser; use reference for curr_lexer
John W. Eaton <jwe@octave.org>
parents: 16285
diff changeset
2791 octave_base_parser::make_break_command (token *break_tok)
1623
fa7a847f9b92 [project @ 1995-11-06 18:05:09 by jwe]
jwe
parents: 1607
diff changeset
2792 {
2620
5c773d4745d6 [project @ 1997-01-23 16:26:25 by jwe]
jwe
parents: 2542
diff changeset
2793 int l = break_tok->line ();
5c773d4745d6 [project @ 1997-01-23 16:26:25 by jwe]
jwe
parents: 2542
diff changeset
2794 int c = break_tok->column ();
5c773d4745d6 [project @ 1997-01-23 16:26:25 by jwe]
jwe
parents: 2542
diff changeset
2795
17632
bd0a84de3375 further reduce memory leaks from parse errors (bug #40231)
John W. Eaton <jwe@octave.org>
parents: 17629
diff changeset
2796 return new tree_break_command (l, c);
1623
fa7a847f9b92 [project @ 1995-11-06 18:05:09 by jwe]
jwe
parents: 1607
diff changeset
2797 }
fa7a847f9b92 [project @ 1995-11-06 18:05:09 by jwe]
jwe
parents: 1607
diff changeset
2798
4207
fa3482b34599 [project @ 2002-12-03 18:22:05 by jwe]
jwe
parents: 4186
diff changeset
2799 // Build a continue command.
fa3482b34599 [project @ 2002-12-03 18:22:05 by jwe]
jwe
parents: 4186
diff changeset
2800
16134
ec9c6222ef5a move static parser helper functions to octave_parser class
John W. Eaton <jwe@octave.org>
parents: 16133
diff changeset
2801 tree_command *
16287
04a7953496a7 create base class for parser; use reference for curr_lexer
John W. Eaton <jwe@octave.org>
parents: 16285
diff changeset
2802 octave_base_parser::make_continue_command (token *continue_tok)
1623
fa7a847f9b92 [project @ 1995-11-06 18:05:09 by jwe]
jwe
parents: 1607
diff changeset
2803 {
2620
5c773d4745d6 [project @ 1997-01-23 16:26:25 by jwe]
jwe
parents: 2542
diff changeset
2804 int l = continue_tok->line ();
5c773d4745d6 [project @ 1997-01-23 16:26:25 by jwe]
jwe
parents: 2542
diff changeset
2805 int c = continue_tok->column ();
5c773d4745d6 [project @ 1997-01-23 16:26:25 by jwe]
jwe
parents: 2542
diff changeset
2806
17632
bd0a84de3375 further reduce memory leaks from parse errors (bug #40231)
John W. Eaton <jwe@octave.org>
parents: 17629
diff changeset
2807 return new tree_continue_command (l, c);
1623
fa7a847f9b92 [project @ 1995-11-06 18:05:09 by jwe]
jwe
parents: 1607
diff changeset
2808 }
fa7a847f9b92 [project @ 1995-11-06 18:05:09 by jwe]
jwe
parents: 1607
diff changeset
2809
4207
fa3482b34599 [project @ 2002-12-03 18:22:05 by jwe]
jwe
parents: 4186
diff changeset
2810 // Build a return command.
fa3482b34599 [project @ 2002-12-03 18:22:05 by jwe]
jwe
parents: 4186
diff changeset
2811
16134
ec9c6222ef5a move static parser helper functions to octave_parser class
John W. Eaton <jwe@octave.org>
parents: 16133
diff changeset
2812 tree_command *
16287
04a7953496a7 create base class for parser; use reference for curr_lexer
John W. Eaton <jwe@octave.org>
parents: 16285
diff changeset
2813 octave_base_parser::make_return_command (token *return_tok)
1623
fa7a847f9b92 [project @ 1995-11-06 18:05:09 by jwe]
jwe
parents: 1607
diff changeset
2814 {
2620
5c773d4745d6 [project @ 1997-01-23 16:26:25 by jwe]
jwe
parents: 2542
diff changeset
2815 int l = return_tok->line ();
5c773d4745d6 [project @ 1997-01-23 16:26:25 by jwe]
jwe
parents: 2542
diff changeset
2816 int c = return_tok->column ();
5c773d4745d6 [project @ 1997-01-23 16:26:25 by jwe]
jwe
parents: 2542
diff changeset
2817
17632
bd0a84de3375 further reduce memory leaks from parse errors (bug #40231)
John W. Eaton <jwe@octave.org>
parents: 17629
diff changeset
2818 return new tree_return_command (l, c);
1623
fa7a847f9b92 [project @ 1995-11-06 18:05:09 by jwe]
jwe
parents: 1607
diff changeset
2819 }
fa7a847f9b92 [project @ 1995-11-06 18:05:09 by jwe]
jwe
parents: 1607
diff changeset
2820
fa7a847f9b92 [project @ 1995-11-06 18:05:09 by jwe]
jwe
parents: 1607
diff changeset
2821 // Start an if command.
fa7a847f9b92 [project @ 1995-11-06 18:05:09 by jwe]
jwe
parents: 1607
diff changeset
2822
16134
ec9c6222ef5a move static parser helper functions to octave_parser class
John W. Eaton <jwe@octave.org>
parents: 16133
diff changeset
2823 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
2824 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
2825 tree_statement_list *list)
1623
fa7a847f9b92 [project @ 1995-11-06 18:05:09 by jwe]
jwe
parents: 1607
diff changeset
2826 {
fa7a847f9b92 [project @ 1995-11-06 18:05:09 by jwe]
jwe
parents: 1607
diff changeset
2827 maybe_warn_assign_as_truth_value (expr);
fa7a847f9b92 [project @ 1995-11-06 18:05:09 by jwe]
jwe
parents: 1607
diff changeset
2828
fa7a847f9b92 [project @ 1995-11-06 18:05:09 by jwe]
jwe
parents: 1607
diff changeset
2829 tree_if_clause *t = new tree_if_clause (expr, list);
fa7a847f9b92 [project @ 1995-11-06 18:05:09 by jwe]
jwe
parents: 1607
diff changeset
2830
fa7a847f9b92 [project @ 1995-11-06 18:05:09 by jwe]
jwe
parents: 1607
diff changeset
2831 return new tree_if_command_list (t);
fa7a847f9b92 [project @ 1995-11-06 18:05:09 by jwe]
jwe
parents: 1607
diff changeset
2832 }
fa7a847f9b92 [project @ 1995-11-06 18:05:09 by jwe]
jwe
parents: 1607
diff changeset
2833
fa7a847f9b92 [project @ 1995-11-06 18:05:09 by jwe]
jwe
parents: 1607
diff changeset
2834 // Finish an if command.
fa7a847f9b92 [project @ 1995-11-06 18:05:09 by jwe]
jwe
parents: 1607
diff changeset
2835
16134
ec9c6222ef5a move static parser helper functions to octave_parser class
John W. Eaton <jwe@octave.org>
parents: 16133
diff changeset
2836 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
2837 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
2838 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
2839 token *end_tok,
04a7953496a7 create base class for parser; use reference for curr_lexer
John W. Eaton <jwe@octave.org>
parents: 16285
diff changeset
2840 octave_comment_list *lc)
1623
fa7a847f9b92 [project @ 1995-11-06 18:05:09 by jwe]
jwe
parents: 1607
diff changeset
2841 {
fa7a847f9b92 [project @ 1995-11-06 18:05:09 by jwe]
jwe
parents: 1607
diff changeset
2842 tree_if_command *retval = 0;
fa7a847f9b92 [project @ 1995-11-06 18:05:09 by jwe]
jwe
parents: 1607
diff changeset
2843
2857
5448c8cba402 [project @ 1997-03-31 07:06:10 by jwe]
jwe
parents: 2856
diff changeset
2844 if (end_token_ok (end_tok, token::if_end))
1623
fa7a847f9b92 [project @ 1995-11-06 18:05:09 by jwe]
jwe
parents: 1607
diff changeset
2845 {
17693
efbe746f8fa8 eliminate octave_comment_buffer singleton
John W. Eaton <jwe@octave.org>
parents: 17673
diff changeset
2846 octave_comment_list *tc = lexer.comment_buf.get_comment ();
3665
0689afb1d001 [project @ 2000-05-11 19:07:56 by jwe]
jwe
parents: 3544
diff changeset
2847
1623
fa7a847f9b92 [project @ 1995-11-06 18:05:09 by jwe]
jwe
parents: 1607
diff changeset
2848 int l = if_tok->line ();
fa7a847f9b92 [project @ 1995-11-06 18:05:09 by jwe]
jwe
parents: 1607
diff changeset
2849 int c = if_tok->column ();
fa7a847f9b92 [project @ 1995-11-06 18:05:09 by jwe]
jwe
parents: 1607
diff changeset
2850
8842
be7b30a24938 line/column info for switch and if statements
John W. Eaton <jwe@octave.org>
parents: 8828
diff changeset
2851 if (list && ! list->empty ())
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
2852 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
2853 tree_if_clause *elt = list->front ();
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
2854
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
2855 if (elt)
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
2856 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
2857 elt->line (l);
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
2858 elt->column (c);
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
2859 }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
2860 }
8842
be7b30a24938 line/column info for switch and if statements
John W. Eaton <jwe@octave.org>
parents: 8828
diff changeset
2861
3665
0689afb1d001 [project @ 2000-05-11 19:07:56 by jwe]
jwe
parents: 3544
diff changeset
2862 retval = new tree_if_command (list, lc, tc, l, c);
1623
fa7a847f9b92 [project @ 1995-11-06 18:05:09 by jwe]
jwe
parents: 1607
diff changeset
2863 }
17632
bd0a84de3375 further reduce memory leaks from parse errors (bug #40231)
John W. Eaton <jwe@octave.org>
parents: 17629
diff changeset
2864 else
21071
f25c14056b7c overhaul parser error handling for end token mismatch
John W. Eaton <jwe@octave.org>
parents: 21066
diff changeset
2865 {
f25c14056b7c overhaul parser error handling for end token mismatch
John W. Eaton <jwe@octave.org>
parents: 21066
diff changeset
2866 delete list;
f25c14056b7c overhaul parser error handling for end token mismatch
John W. Eaton <jwe@octave.org>
parents: 21066
diff changeset
2867
f25c14056b7c overhaul parser error handling for end token mismatch
John W. Eaton <jwe@octave.org>
parents: 21066
diff changeset
2868 end_token_error (end_tok, token::if_end);
f25c14056b7c overhaul parser error handling for end token mismatch
John W. Eaton <jwe@octave.org>
parents: 21066
diff changeset
2869 }
1623
fa7a847f9b92 [project @ 1995-11-06 18:05:09 by jwe]
jwe
parents: 1607
diff changeset
2870
fa7a847f9b92 [project @ 1995-11-06 18:05:09 by jwe]
jwe
parents: 1607
diff changeset
2871 return retval;
fa7a847f9b92 [project @ 1995-11-06 18:05:09 by jwe]
jwe
parents: 1607
diff changeset
2872 }
fa7a847f9b92 [project @ 1995-11-06 18:05:09 by jwe]
jwe
parents: 1607
diff changeset
2873
fa7a847f9b92 [project @ 1995-11-06 18:05:09 by jwe]
jwe
parents: 1607
diff changeset
2874 // Build an elseif clause.
fa7a847f9b92 [project @ 1995-11-06 18:05:09 by jwe]
jwe
parents: 1607
diff changeset
2875
16134
ec9c6222ef5a move static parser helper functions to octave_parser class
John W. Eaton <jwe@octave.org>
parents: 16133
diff changeset
2876 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
2877 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
2878 tree_expression *expr,
04a7953496a7 create base class for parser; use reference for curr_lexer
John W. Eaton <jwe@octave.org>
parents: 16285
diff changeset
2879 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
2880 octave_comment_list *lc)
1623
fa7a847f9b92 [project @ 1995-11-06 18:05:09 by jwe]
jwe
parents: 1607
diff changeset
2881 {
fa7a847f9b92 [project @ 1995-11-06 18:05:09 by jwe]
jwe
parents: 1607
diff changeset
2882 maybe_warn_assign_as_truth_value (expr);
fa7a847f9b92 [project @ 1995-11-06 18:05:09 by jwe]
jwe
parents: 1607
diff changeset
2883
8658
73c4516fae10 New evaluator and debugger derived from tree-walker class
John W. Eaton <jwe@octave.org>
parents: 8471
diff changeset
2884 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
2885 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
2886
73c4516fae10 New evaluator and debugger derived from tree-walker class
John W. Eaton <jwe@octave.org>
parents: 8471
diff changeset
2887 return new tree_if_clause (expr, list, lc, l, c);
1623
fa7a847f9b92 [project @ 1995-11-06 18:05:09 by jwe]
jwe
parents: 1607
diff changeset
2888 }
fa7a847f9b92 [project @ 1995-11-06 18:05:09 by jwe]
jwe
parents: 1607
diff changeset
2889
2764
2c0f259cf83d [project @ 1997-03-01 02:30:26 by jwe]
jwe
parents: 2745
diff changeset
2890 // Finish a switch command.
2c0f259cf83d [project @ 1997-03-01 02:30:26 by jwe]
jwe
parents: 2745
diff changeset
2891
16134
ec9c6222ef5a move static parser helper functions to octave_parser class
John W. Eaton <jwe@octave.org>
parents: 16133
diff changeset
2892 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
2893 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
2894 tree_expression *expr,
04a7953496a7 create base class for parser; use reference for curr_lexer
John W. Eaton <jwe@octave.org>
parents: 16285
diff changeset
2895 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
2896 token *end_tok,
04a7953496a7 create base class for parser; use reference for curr_lexer
John W. Eaton <jwe@octave.org>
parents: 16285
diff changeset
2897 octave_comment_list *lc)
2764
2c0f259cf83d [project @ 1997-03-01 02:30:26 by jwe]
jwe
parents: 2745
diff changeset
2898 {
2c0f259cf83d [project @ 1997-03-01 02:30:26 by jwe]
jwe
parents: 2745
diff changeset
2899 tree_switch_command *retval = 0;
2c0f259cf83d [project @ 1997-03-01 02:30:26 by jwe]
jwe
parents: 2745
diff changeset
2900
2857
5448c8cba402 [project @ 1997-03-31 07:06:10 by jwe]
jwe
parents: 2856
diff changeset
2901 if (end_token_ok (end_tok, token::switch_end))
2764
2c0f259cf83d [project @ 1997-03-01 02:30:26 by jwe]
jwe
parents: 2745
diff changeset
2902 {
17693
efbe746f8fa8 eliminate octave_comment_buffer singleton
John W. Eaton <jwe@octave.org>
parents: 17673
diff changeset
2903 octave_comment_list *tc = lexer.comment_buf.get_comment ();
3665
0689afb1d001 [project @ 2000-05-11 19:07:56 by jwe]
jwe
parents: 3544
diff changeset
2904
2764
2c0f259cf83d [project @ 1997-03-01 02:30:26 by jwe]
jwe
parents: 2745
diff changeset
2905 int l = switch_tok->line ();
2c0f259cf83d [project @ 1997-03-01 02:30:26 by jwe]
jwe
parents: 2745
diff changeset
2906 int c = switch_tok->column ();
2c0f259cf83d [project @ 1997-03-01 02:30:26 by jwe]
jwe
parents: 2745
diff changeset
2907
8842
be7b30a24938 line/column info for switch and if statements
John W. Eaton <jwe@octave.org>
parents: 8828
diff changeset
2908 if (list && ! list->empty ())
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
2909 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
2910 tree_switch_case *elt = list->front ();
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
2911
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
2912 if (elt)
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
2913 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
2914 elt->line (l);
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
2915 elt->column (c);
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
2916 }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
2917 }
8842
be7b30a24938 line/column info for switch and if statements
John W. Eaton <jwe@octave.org>
parents: 8828
diff changeset
2918
3665
0689afb1d001 [project @ 2000-05-11 19:07:56 by jwe]
jwe
parents: 3544
diff changeset
2919 retval = new tree_switch_command (expr, list, lc, tc, l, c);
2764
2c0f259cf83d [project @ 1997-03-01 02:30:26 by jwe]
jwe
parents: 2745
diff changeset
2920 }
17632
bd0a84de3375 further reduce memory leaks from parse errors (bug #40231)
John W. Eaton <jwe@octave.org>
parents: 17629
diff changeset
2921 else
bd0a84de3375 further reduce memory leaks from parse errors (bug #40231)
John W. Eaton <jwe@octave.org>
parents: 17629
diff changeset
2922 {
bd0a84de3375 further reduce memory leaks from parse errors (bug #40231)
John W. Eaton <jwe@octave.org>
parents: 17629
diff changeset
2923 delete expr;
bd0a84de3375 further reduce memory leaks from parse errors (bug #40231)
John W. Eaton <jwe@octave.org>
parents: 17629
diff changeset
2924 delete list;
21071
f25c14056b7c overhaul parser error handling for end token mismatch
John W. Eaton <jwe@octave.org>
parents: 21066
diff changeset
2925
f25c14056b7c overhaul parser error handling for end token mismatch
John W. Eaton <jwe@octave.org>
parents: 21066
diff changeset
2926 end_token_error (end_tok, token::switch_end);
17632
bd0a84de3375 further reduce memory leaks from parse errors (bug #40231)
John W. Eaton <jwe@octave.org>
parents: 17629
diff changeset
2927 }
2764
2c0f259cf83d [project @ 1997-03-01 02:30:26 by jwe]
jwe
parents: 2745
diff changeset
2928
2c0f259cf83d [project @ 1997-03-01 02:30:26 by jwe]
jwe
parents: 2745
diff changeset
2929 return retval;
2c0f259cf83d [project @ 1997-03-01 02:30:26 by jwe]
jwe
parents: 2745
diff changeset
2930 }
2c0f259cf83d [project @ 1997-03-01 02:30:26 by jwe]
jwe
parents: 2745
diff changeset
2931
2c0f259cf83d [project @ 1997-03-01 02:30:26 by jwe]
jwe
parents: 2745
diff changeset
2932 // Build a switch case.
2c0f259cf83d [project @ 1997-03-01 02:30:26 by jwe]
jwe
parents: 2745
diff changeset
2933
16134
ec9c6222ef5a move static parser helper functions to octave_parser class
John W. Eaton <jwe@octave.org>
parents: 16133
diff changeset
2934 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
2935 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
2936 tree_expression *expr,
04a7953496a7 create base class for parser; use reference for curr_lexer
John W. Eaton <jwe@octave.org>
parents: 16285
diff changeset
2937 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
2938 octave_comment_list *lc)
2764
2c0f259cf83d [project @ 1997-03-01 02:30:26 by jwe]
jwe
parents: 2745
diff changeset
2939 {
2c0f259cf83d [project @ 1997-03-01 02:30:26 by jwe]
jwe
parents: 2745
diff changeset
2940 maybe_warn_variable_switch_label (expr);
2c0f259cf83d [project @ 1997-03-01 02:30:26 by jwe]
jwe
parents: 2745
diff changeset
2941
8658
73c4516fae10 New evaluator and debugger derived from tree-walker class
John W. Eaton <jwe@octave.org>
parents: 8471
diff changeset
2942 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
2943 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
2944
73c4516fae10 New evaluator and debugger derived from tree-walker class
John W. Eaton <jwe@octave.org>
parents: 8471
diff changeset
2945 return new tree_switch_case (expr, list, lc, l, c);
2764
2c0f259cf83d [project @ 1997-03-01 02:30:26 by jwe]
jwe
parents: 2745
diff changeset
2946 }
2c0f259cf83d [project @ 1997-03-01 02:30:26 by jwe]
jwe
parents: 2745
diff changeset
2947
1623
fa7a847f9b92 [project @ 1995-11-06 18:05:09 by jwe]
jwe
parents: 1607
diff changeset
2948 // Build an assignment to a variable.
fa7a847f9b92 [project @ 1995-11-06 18:05:09 by jwe]
jwe
parents: 1607
diff changeset
2949
16134
ec9c6222ef5a move static parser helper functions to octave_parser class
John W. Eaton <jwe@octave.org>
parents: 16133
diff changeset
2950 tree_expression *
16287
04a7953496a7 create base class for parser; use reference for curr_lexer
John W. Eaton <jwe@octave.org>
parents: 16285
diff changeset
2951 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
2952 token *eq_tok, tree_expression *rhs)
1623
fa7a847f9b92 [project @ 1995-11-06 18:05:09 by jwe]
jwe
parents: 1607
diff changeset
2953 {
2883
0b3954110c77 [project @ 1997-04-24 09:57:05 by jwe]
jwe
parents: 2865
diff changeset
2954 octave_value::assign_op t = octave_value::unknown_assign_op;
0b3954110c77 [project @ 1997-04-24 09:57:05 by jwe]
jwe
parents: 2865
diff changeset
2955
0b3954110c77 [project @ 1997-04-24 09:57:05 by jwe]
jwe
parents: 2865
diff changeset
2956 switch (op)
0b3954110c77 [project @ 1997-04-24 09:57:05 by jwe]
jwe
parents: 2865
diff changeset
2957 {
0b3954110c77 [project @ 1997-04-24 09:57:05 by jwe]
jwe
parents: 2865
diff changeset
2958 case '=':
3525
6cfa474c5b99 [project @ 2000-02-02 10:48:41 by jwe]
jwe
parents: 3523
diff changeset
2959 t = octave_value::op_asn_eq;
2883
0b3954110c77 [project @ 1997-04-24 09:57:05 by jwe]
jwe
parents: 2865
diff changeset
2960 break;
0b3954110c77 [project @ 1997-04-24 09:57:05 by jwe]
jwe
parents: 2865
diff changeset
2961
0b3954110c77 [project @ 1997-04-24 09:57:05 by jwe]
jwe
parents: 2865
diff changeset
2962 case ADD_EQ:
3525
6cfa474c5b99 [project @ 2000-02-02 10:48:41 by jwe]
jwe
parents: 3523
diff changeset
2963 t = octave_value::op_add_eq;
2883
0b3954110c77 [project @ 1997-04-24 09:57:05 by jwe]
jwe
parents: 2865
diff changeset
2964 break;
0b3954110c77 [project @ 1997-04-24 09:57:05 by jwe]
jwe
parents: 2865
diff changeset
2965
0b3954110c77 [project @ 1997-04-24 09:57:05 by jwe]
jwe
parents: 2865
diff changeset
2966 case SUB_EQ:
3525
6cfa474c5b99 [project @ 2000-02-02 10:48:41 by jwe]
jwe
parents: 3523
diff changeset
2967 t = octave_value::op_sub_eq;
2883
0b3954110c77 [project @ 1997-04-24 09:57:05 by jwe]
jwe
parents: 2865
diff changeset
2968 break;
0b3954110c77 [project @ 1997-04-24 09:57:05 by jwe]
jwe
parents: 2865
diff changeset
2969
0b3954110c77 [project @ 1997-04-24 09:57:05 by jwe]
jwe
parents: 2865
diff changeset
2970 case MUL_EQ:
3525
6cfa474c5b99 [project @ 2000-02-02 10:48:41 by jwe]
jwe
parents: 3523
diff changeset
2971 t = octave_value::op_mul_eq;
2883
0b3954110c77 [project @ 1997-04-24 09:57:05 by jwe]
jwe
parents: 2865
diff changeset
2972 break;
0b3954110c77 [project @ 1997-04-24 09:57:05 by jwe]
jwe
parents: 2865
diff changeset
2973
0b3954110c77 [project @ 1997-04-24 09:57:05 by jwe]
jwe
parents: 2865
diff changeset
2974 case DIV_EQ:
3525
6cfa474c5b99 [project @ 2000-02-02 10:48:41 by jwe]
jwe
parents: 3523
diff changeset
2975 t = octave_value::op_div_eq;
2883
0b3954110c77 [project @ 1997-04-24 09:57:05 by jwe]
jwe
parents: 2865
diff changeset
2976 break;
0b3954110c77 [project @ 1997-04-24 09:57:05 by jwe]
jwe
parents: 2865
diff changeset
2977
3204
81738e630f57 [project @ 1998-10-30 23:28:29 by jwe]
jwe
parents: 3203
diff changeset
2978 case LEFTDIV_EQ:
3525
6cfa474c5b99 [project @ 2000-02-02 10:48:41 by jwe]
jwe
parents: 3523
diff changeset
2979 t = octave_value::op_ldiv_eq;
3204
81738e630f57 [project @ 1998-10-30 23:28:29 by jwe]
jwe
parents: 3203
diff changeset
2980 break;
81738e630f57 [project @ 1998-10-30 23:28:29 by jwe]
jwe
parents: 3203
diff changeset
2981
4018
a8621d87fbf5 [project @ 2002-08-05 03:17:25 by jwe]
jwe
parents: 4009
diff changeset
2982 case POW_EQ:
a8621d87fbf5 [project @ 2002-08-05 03:17:25 by jwe]
jwe
parents: 4009
diff changeset
2983 t = octave_value::op_pow_eq;
a8621d87fbf5 [project @ 2002-08-05 03:17:25 by jwe]
jwe
parents: 4009
diff changeset
2984 break;
a8621d87fbf5 [project @ 2002-08-05 03:17:25 by jwe]
jwe
parents: 4009
diff changeset
2985
2883
0b3954110c77 [project @ 1997-04-24 09:57:05 by jwe]
jwe
parents: 2865
diff changeset
2986 case EMUL_EQ:
3525
6cfa474c5b99 [project @ 2000-02-02 10:48:41 by jwe]
jwe
parents: 3523
diff changeset
2987 t = octave_value::op_el_mul_eq;
2883
0b3954110c77 [project @ 1997-04-24 09:57:05 by jwe]
jwe
parents: 2865
diff changeset
2988 break;
0b3954110c77 [project @ 1997-04-24 09:57:05 by jwe]
jwe
parents: 2865
diff changeset
2989
0b3954110c77 [project @ 1997-04-24 09:57:05 by jwe]
jwe
parents: 2865
diff changeset
2990 case EDIV_EQ:
3525
6cfa474c5b99 [project @ 2000-02-02 10:48:41 by jwe]
jwe
parents: 3523
diff changeset
2991 t = octave_value::op_el_div_eq;
2883
0b3954110c77 [project @ 1997-04-24 09:57:05 by jwe]
jwe
parents: 2865
diff changeset
2992 break;
0b3954110c77 [project @ 1997-04-24 09:57:05 by jwe]
jwe
parents: 2865
diff changeset
2993
3204
81738e630f57 [project @ 1998-10-30 23:28:29 by jwe]
jwe
parents: 3203
diff changeset
2994 case ELEFTDIV_EQ:
3525
6cfa474c5b99 [project @ 2000-02-02 10:48:41 by jwe]
jwe
parents: 3523
diff changeset
2995 t = octave_value::op_el_ldiv_eq;
3204
81738e630f57 [project @ 1998-10-30 23:28:29 by jwe]
jwe
parents: 3203
diff changeset
2996 break;
81738e630f57 [project @ 1998-10-30 23:28:29 by jwe]
jwe
parents: 3203
diff changeset
2997
4018
a8621d87fbf5 [project @ 2002-08-05 03:17:25 by jwe]
jwe
parents: 4009
diff changeset
2998 case EPOW_EQ:
a8621d87fbf5 [project @ 2002-08-05 03:17:25 by jwe]
jwe
parents: 4009
diff changeset
2999 t = octave_value::op_el_pow_eq;
a8621d87fbf5 [project @ 2002-08-05 03:17:25 by jwe]
jwe
parents: 4009
diff changeset
3000 break;
a8621d87fbf5 [project @ 2002-08-05 03:17:25 by jwe]
jwe
parents: 4009
diff changeset
3001
2883
0b3954110c77 [project @ 1997-04-24 09:57:05 by jwe]
jwe
parents: 2865
diff changeset
3002 case AND_EQ:
3525
6cfa474c5b99 [project @ 2000-02-02 10:48:41 by jwe]
jwe
parents: 3523
diff changeset
3003 t = octave_value::op_el_and_eq;
2883
0b3954110c77 [project @ 1997-04-24 09:57:05 by jwe]
jwe
parents: 2865
diff changeset
3004 break;
0b3954110c77 [project @ 1997-04-24 09:57:05 by jwe]
jwe
parents: 2865
diff changeset
3005
0b3954110c77 [project @ 1997-04-24 09:57:05 by jwe]
jwe
parents: 2865
diff changeset
3006 case OR_EQ:
3525
6cfa474c5b99 [project @ 2000-02-02 10:48:41 by jwe]
jwe
parents: 3523
diff changeset
3007 t = octave_value::op_el_or_eq;
2883
0b3954110c77 [project @ 1997-04-24 09:57:05 by jwe]
jwe
parents: 2865
diff changeset
3008 break;
0b3954110c77 [project @ 1997-04-24 09:57:05 by jwe]
jwe
parents: 2865
diff changeset
3009
0b3954110c77 [project @ 1997-04-24 09:57:05 by jwe]
jwe
parents: 2865
diff changeset
3010 default:
0b3954110c77 [project @ 1997-04-24 09:57:05 by jwe]
jwe
parents: 2865
diff changeset
3011 panic_impossible ();
0b3954110c77 [project @ 1997-04-24 09:57:05 by jwe]
jwe
parents: 2865
diff changeset
3012 break;
0b3954110c77 [project @ 1997-04-24 09:57:05 by jwe]
jwe
parents: 2865
diff changeset
3013 }
0b3954110c77 [project @ 1997-04-24 09:57:05 by jwe]
jwe
parents: 2865
diff changeset
3014
1623
fa7a847f9b92 [project @ 1995-11-06 18:05:09 by jwe]
jwe
parents: 1607
diff changeset
3015 int l = eq_tok->line ();
fa7a847f9b92 [project @ 1995-11-06 18:05:09 by jwe]
jwe
parents: 1607
diff changeset
3016 int c = eq_tok->column ();
fa7a847f9b92 [project @ 1995-11-06 18:05:09 by jwe]
jwe
parents: 1607
diff changeset
3017
21361
9ca194f7a858 disallow assignment to "end" in indexed assignments (bug #46459)
John W. Eaton <jwe@octave.org>
parents: 21317
diff changeset
3018 if (! lhs->is_simple_assign_lhs () && t != octave_value::op_asn_eq)
666
fb4f6556b443 [project @ 1994-09-06 21:22:46 by jwe]
jwe
parents: 627
diff changeset
3019 {
21361
9ca194f7a858 disallow assignment to "end" in indexed assignments (bug #46459)
John W. Eaton <jwe@octave.org>
parents: 21317
diff changeset
3020 // Multiple assignments like [x,y] OP= rhs are only valid for
9ca194f7a858 disallow assignment to "end" in indexed assignments (bug #46459)
John W. Eaton <jwe@octave.org>
parents: 21317
diff changeset
3021 // '=', not '+=', etc.
2970
b9e64477f703 [project @ 1997-05-15 18:04:21 by jwe]
jwe
parents: 2961
diff changeset
3022
b9e64477f703 [project @ 1997-05-15 18:04:21 by jwe]
jwe
parents: 2961
diff changeset
3023 delete lhs;
21361
9ca194f7a858 disallow assignment to "end" in indexed assignments (bug #46459)
John W. Eaton <jwe@octave.org>
parents: 21317
diff changeset
3024 delete rhs;
9ca194f7a858 disallow assignment to "end" in indexed assignments (bug #46459)
John W. Eaton <jwe@octave.org>
parents: 21317
diff changeset
3025
9ca194f7a858 disallow assignment to "end" in indexed assignments (bug #46459)
John W. Eaton <jwe@octave.org>
parents: 21317
diff changeset
3026 bison_error ("computed multiple assignment not allowed", l, c);
9ca194f7a858 disallow assignment to "end" in indexed assignments (bug #46459)
John W. Eaton <jwe@octave.org>
parents: 21317
diff changeset
3027
9ca194f7a858 disallow assignment to "end" in indexed assignments (bug #46459)
John W. Eaton <jwe@octave.org>
parents: 21317
diff changeset
3028 return 0;
666
fb4f6556b443 [project @ 1994-09-06 21:22:46 by jwe]
jwe
parents: 627
diff changeset
3029 }
21361
9ca194f7a858 disallow assignment to "end" in indexed assignments (bug #46459)
John W. Eaton <jwe@octave.org>
parents: 21317
diff changeset
3030
9ca194f7a858 disallow assignment to "end" in indexed assignments (bug #46459)
John W. Eaton <jwe@octave.org>
parents: 21317
diff changeset
3031 if (lhs->is_simple_assign_lhs ())
9ca194f7a858 disallow assignment to "end" in indexed assignments (bug #46459)
John W. Eaton <jwe@octave.org>
parents: 21317
diff changeset
3032 {
9ca194f7a858 disallow assignment to "end" in indexed assignments (bug #46459)
John W. Eaton <jwe@octave.org>
parents: 21317
diff changeset
3033 // We are looking at a simple assignment statement like x = rhs;
9ca194f7a858 disallow assignment to "end" in indexed assignments (bug #46459)
John W. Eaton <jwe@octave.org>
parents: 21317
diff changeset
3034
9ca194f7a858 disallow assignment to "end" in indexed assignments (bug #46459)
John W. Eaton <jwe@octave.org>
parents: 21317
diff changeset
3035 tree_expression *tmp = lhs->remove_front ();
9ca194f7a858 disallow assignment to "end" in indexed assignments (bug #46459)
John W. Eaton <jwe@octave.org>
parents: 21317
diff changeset
3036
9ca194f7a858 disallow assignment to "end" in indexed assignments (bug #46459)
John W. Eaton <jwe@octave.org>
parents: 21317
diff changeset
3037 if ((tmp->is_identifier () || tmp->is_index_expression ())
9ca194f7a858 disallow assignment to "end" in indexed assignments (bug #46459)
John W. Eaton <jwe@octave.org>
parents: 21317
diff changeset
3038 && ! valid_id_for_assignment (tmp->name ()))
9ca194f7a858 disallow assignment to "end" in indexed assignments (bug #46459)
John W. Eaton <jwe@octave.org>
parents: 21317
diff changeset
3039 {
9ca194f7a858 disallow assignment to "end" in indexed assignments (bug #46459)
John W. Eaton <jwe@octave.org>
parents: 21317
diff changeset
3040 std::string kw = tmp->name ();
9ca194f7a858 disallow assignment to "end" in indexed assignments (bug #46459)
John W. Eaton <jwe@octave.org>
parents: 21317
diff changeset
3041
9ca194f7a858 disallow assignment to "end" in indexed assignments (bug #46459)
John W. Eaton <jwe@octave.org>
parents: 21317
diff changeset
3042 delete tmp;
9ca194f7a858 disallow assignment to "end" in indexed assignments (bug #46459)
John W. Eaton <jwe@octave.org>
parents: 21317
diff changeset
3043 delete lhs;
9ca194f7a858 disallow assignment to "end" in indexed assignments (bug #46459)
John W. Eaton <jwe@octave.org>
parents: 21317
diff changeset
3044 delete rhs;
9ca194f7a858 disallow assignment to "end" in indexed assignments (bug #46459)
John W. Eaton <jwe@octave.org>
parents: 21317
diff changeset
3045
9ca194f7a858 disallow assignment to "end" in indexed assignments (bug #46459)
John W. Eaton <jwe@octave.org>
parents: 21317
diff changeset
3046 bison_error ("invalid assignment to keyword \"" + kw + "\"", l, c);
9ca194f7a858 disallow assignment to "end" in indexed assignments (bug #46459)
John W. Eaton <jwe@octave.org>
parents: 21317
diff changeset
3047
9ca194f7a858 disallow assignment to "end" in indexed assignments (bug #46459)
John W. Eaton <jwe@octave.org>
parents: 21317
diff changeset
3048 return 0;
9ca194f7a858 disallow assignment to "end" in indexed assignments (bug #46459)
John W. Eaton <jwe@octave.org>
parents: 21317
diff changeset
3049 }
9ca194f7a858 disallow assignment to "end" in indexed assignments (bug #46459)
John W. Eaton <jwe@octave.org>
parents: 21317
diff changeset
3050
9ca194f7a858 disallow assignment to "end" in indexed assignments (bug #46459)
John W. Eaton <jwe@octave.org>
parents: 21317
diff changeset
3051 delete lhs;
9ca194f7a858 disallow assignment to "end" in indexed assignments (bug #46459)
John W. Eaton <jwe@octave.org>
parents: 21317
diff changeset
3052
9ca194f7a858 disallow assignment to "end" in indexed assignments (bug #46459)
John W. Eaton <jwe@octave.org>
parents: 21317
diff changeset
3053 return new tree_simple_assignment (tmp, rhs, false, l, c, t);
9ca194f7a858 disallow assignment to "end" in indexed assignments (bug #46459)
John W. Eaton <jwe@octave.org>
parents: 21317
diff changeset
3054 }
666
fb4f6556b443 [project @ 1994-09-06 21:22:46 by jwe]
jwe
parents: 627
diff changeset
3055 else
21073
f7cc48f601d2 additional reworking of error handling in the parser (bug #46877)
John W. Eaton <jwe@octave.org>
parents: 21071
diff changeset
3056 {
21361
9ca194f7a858 disallow assignment to "end" in indexed assignments (bug #46459)
John W. Eaton <jwe@octave.org>
parents: 21317
diff changeset
3057 std::list<std::string> names = lhs->variable_names ();
9ca194f7a858 disallow assignment to "end" in indexed assignments (bug #46459)
John W. Eaton <jwe@octave.org>
parents: 21317
diff changeset
3058
9ca194f7a858 disallow assignment to "end" in indexed assignments (bug #46459)
John W. Eaton <jwe@octave.org>
parents: 21317
diff changeset
3059 for (std::list<std::string>::const_iterator it = names.begin ();
9ca194f7a858 disallow assignment to "end" in indexed assignments (bug #46459)
John W. Eaton <jwe@octave.org>
parents: 21317
diff changeset
3060 it != names.end (); it++)
9ca194f7a858 disallow assignment to "end" in indexed assignments (bug #46459)
John W. Eaton <jwe@octave.org>
parents: 21317
diff changeset
3061 {
9ca194f7a858 disallow assignment to "end" in indexed assignments (bug #46459)
John W. Eaton <jwe@octave.org>
parents: 21317
diff changeset
3062 std::string kw = *it;
9ca194f7a858 disallow assignment to "end" in indexed assignments (bug #46459)
John W. Eaton <jwe@octave.org>
parents: 21317
diff changeset
3063
9ca194f7a858 disallow assignment to "end" in indexed assignments (bug #46459)
John W. Eaton <jwe@octave.org>
parents: 21317
diff changeset
3064 if (! valid_id_for_assignment (kw))
9ca194f7a858 disallow assignment to "end" in indexed assignments (bug #46459)
John W. Eaton <jwe@octave.org>
parents: 21317
diff changeset
3065 {
9ca194f7a858 disallow assignment to "end" in indexed assignments (bug #46459)
John W. Eaton <jwe@octave.org>
parents: 21317
diff changeset
3066 delete lhs;
9ca194f7a858 disallow assignment to "end" in indexed assignments (bug #46459)
John W. Eaton <jwe@octave.org>
parents: 21317
diff changeset
3067 delete rhs;
9ca194f7a858 disallow assignment to "end" in indexed assignments (bug #46459)
John W. Eaton <jwe@octave.org>
parents: 21317
diff changeset
3068
9ca194f7a858 disallow assignment to "end" in indexed assignments (bug #46459)
John W. Eaton <jwe@octave.org>
parents: 21317
diff changeset
3069 bison_error ("invalid assignment to keyword \"" + kw + "\"", l, c);
9ca194f7a858 disallow assignment to "end" in indexed assignments (bug #46459)
John W. Eaton <jwe@octave.org>
parents: 21317
diff changeset
3070
9ca194f7a858 disallow assignment to "end" in indexed assignments (bug #46459)
John W. Eaton <jwe@octave.org>
parents: 21317
diff changeset
3071 return 0;
9ca194f7a858 disallow assignment to "end" in indexed assignments (bug #46459)
John W. Eaton <jwe@octave.org>
parents: 21317
diff changeset
3072 }
9ca194f7a858 disallow assignment to "end" in indexed assignments (bug #46459)
John W. Eaton <jwe@octave.org>
parents: 21317
diff changeset
3073 }
9ca194f7a858 disallow assignment to "end" in indexed assignments (bug #46459)
John W. Eaton <jwe@octave.org>
parents: 21317
diff changeset
3074
9ca194f7a858 disallow assignment to "end" in indexed assignments (bug #46459)
John W. Eaton <jwe@octave.org>
parents: 21317
diff changeset
3075 return new tree_multi_assignment (lhs, rhs, false, l, c);
21073
f7cc48f601d2 additional reworking of error handling in the parser (bug #46877)
John W. Eaton <jwe@octave.org>
parents: 21071
diff changeset
3076 }
666
fb4f6556b443 [project @ 1994-09-06 21:22:46 by jwe]
jwe
parents: 627
diff changeset
3077 }
751
c9f3cb77478d [project @ 1994-09-30 18:46:17 by jwe]
jwe
parents: 723
diff changeset
3078
9474
25ed2d6aacf6 Parse nested functions more accurately.
David Grundberg <individ@acc.umu.se>
parents: 9471
diff changeset
3079 // Define a script.
7715
5b4d278ec828 parse scripts completely before executing
John W. Eaton <jwe@octave.org>
parents: 7699
diff changeset
3080
16134
ec9c6222ef5a move static parser helper functions to octave_parser class
John W. Eaton <jwe@octave.org>
parents: 16133
diff changeset
3081 void
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::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
3083 tree_statement *end_script)
7715
5b4d278ec828 parse scripts completely before executing
John W. Eaton <jwe@octave.org>
parents: 7699
diff changeset
3084 {
8658
73c4516fae10 New evaluator and debugger derived from tree-walker class
John W. Eaton <jwe@octave.org>
parents: 8471
diff changeset
3085 if (! cmds)
73c4516fae10 New evaluator and debugger derived from tree-walker class
John W. Eaton <jwe@octave.org>
parents: 8471
diff changeset
3086 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
3087
73c4516fae10 New evaluator and debugger derived from tree-walker class
John W. Eaton <jwe@octave.org>
parents: 8471
diff changeset
3088 cmds->append (end_script);
73c4516fae10 New evaluator and debugger derived from tree-walker class
John W. Eaton <jwe@octave.org>
parents: 8471
diff changeset
3089
7715
5b4d278ec828 parse scripts completely before executing
John W. Eaton <jwe@octave.org>
parents: 7699
diff changeset
3090 octave_user_script *script
16288
fe3b9a51e625 rename curr_lexer, curr_parser, CURR_LEXER
John W. Eaton <jwe@octave.org>
parents: 16287
diff changeset
3091 = 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
3092 lexer.fcn_file_name,
fe3b9a51e625 rename curr_lexer, curr_parser, CURR_LEXER
John W. Eaton <jwe@octave.org>
parents: 16287
diff changeset
3093 cmds, lexer.help_text);
fe3b9a51e625 rename curr_lexer, curr_parser, CURR_LEXER
John W. Eaton <jwe@octave.org>
parents: 16287
diff changeset
3094
fe3b9a51e625 rename curr_lexer, curr_parser, CURR_LEXER
John W. Eaton <jwe@octave.org>
parents: 16287
diff changeset
3095 lexer.help_text = "";
7715
5b4d278ec828 parse scripts completely before executing
John W. Eaton <jwe@octave.org>
parents: 7699
diff changeset
3096
5b4d278ec828 parse scripts completely before executing
John W. Eaton <jwe@octave.org>
parents: 7699
diff changeset
3097 octave_time now;
5b4d278ec828 parse scripts completely before executing
John W. Eaton <jwe@octave.org>
parents: 7699
diff changeset
3098
5b4d278ec828 parse scripts completely before executing
John W. Eaton <jwe@octave.org>
parents: 7699
diff changeset
3099 script->stash_fcn_file_time (now);
5b4d278ec828 parse scripts completely before executing
John W. Eaton <jwe@octave.org>
parents: 7699
diff changeset
3100
9474
25ed2d6aacf6 Parse nested functions more accurately.
David Grundberg <individ@acc.umu.se>
parents: 9471
diff changeset
3101 primary_fcn_ptr = script;
7715
5b4d278ec828 parse scripts completely before executing
John W. Eaton <jwe@octave.org>
parents: 7699
diff changeset
3102 }
5b4d278ec828 parse scripts completely before executing
John W. Eaton <jwe@octave.org>
parents: 7699
diff changeset
3103
1623
fa7a847f9b92 [project @ 1995-11-06 18:05:09 by jwe]
jwe
parents: 1607
diff changeset
3104 // Begin defining a function.
fa7a847f9b92 [project @ 1995-11-06 18:05:09 by jwe]
jwe
parents: 1607
diff changeset
3105
16134
ec9c6222ef5a move static parser helper functions to octave_parser class
John W. Eaton <jwe@octave.org>
parents: 16133
diff changeset
3106 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
3107 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
3108 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
3109 tree_statement *end_fcn_stmt)
1623
fa7a847f9b92 [project @ 1995-11-06 18:05:09 by jwe]
jwe
parents: 1607
diff changeset
3110 {
2891
1a30f46e1870 [project @ 1997-04-28 01:49:00 by jwe]
jwe
parents: 2884
diff changeset
3111 // We'll fill in the return list later.
1a30f46e1870 [project @ 1997-04-28 01:49:00 by jwe]
jwe
parents: 2884
diff changeset
3112
8658
73c4516fae10 New evaluator and debugger derived from tree-walker class
John W. Eaton <jwe@octave.org>
parents: 8471
diff changeset
3113 if (! body)
73c4516fae10 New evaluator and debugger derived from tree-walker class
John W. Eaton <jwe@octave.org>
parents: 8471
diff changeset
3114 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
3115
73c4516fae10 New evaluator and debugger derived from tree-walker class
John W. Eaton <jwe@octave.org>
parents: 8471
diff changeset
3116 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
3117
2891
1a30f46e1870 [project @ 1997-04-28 01:49:00 by jwe]
jwe
parents: 2884
diff changeset
3118 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
3119 = 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
3120 param_list, 0, body);
1623
fa7a847f9b92 [project @ 1995-11-06 18:05:09 by jwe]
jwe
parents: 1607
diff changeset
3121
3665
0689afb1d001 [project @ 2000-05-11 19:07:56 by jwe]
jwe
parents: 3544
diff changeset
3122 if (fcn)
0689afb1d001 [project @ 2000-05-11 19:07:56 by jwe]
jwe
parents: 3544
diff changeset
3123 {
17693
efbe746f8fa8 eliminate octave_comment_buffer singleton
John W. Eaton <jwe@octave.org>
parents: 17673
diff changeset
3124 octave_comment_list *tc = lexer.comment_buf.get_comment ();
3665
0689afb1d001 [project @ 2000-05-11 19:07:56 by jwe]
jwe
parents: 3544
diff changeset
3125
0689afb1d001 [project @ 2000-05-11 19:07:56 by jwe]
jwe
parents: 3544
diff changeset
3126 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
3127 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
3128 end_fcn_stmt->column ());
3665
0689afb1d001 [project @ 2000-05-11 19:07:56 by jwe]
jwe
parents: 3544
diff changeset
3129 }
0689afb1d001 [project @ 2000-05-11 19:07:56 by jwe]
jwe
parents: 3544
diff changeset
3130
1623
fa7a847f9b92 [project @ 1995-11-06 18:05:09 by jwe]
jwe
parents: 1607
diff changeset
3131 return fcn;
fa7a847f9b92 [project @ 1995-11-06 18:05:09 by jwe]
jwe
parents: 1607
diff changeset
3132 }
fa7a847f9b92 [project @ 1995-11-06 18:05:09 by jwe]
jwe
parents: 1607
diff changeset
3133
16134
ec9c6222ef5a move static parser helper functions to octave_parser class
John W. Eaton <jwe@octave.org>
parents: 16133
diff changeset
3134 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
3135 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
3136 {
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
3137 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
3138 }
73c4516fae10 New evaluator and debugger derived from tree-walker class
John W. Eaton <jwe@octave.org>
parents: 8471
diff changeset
3139
1623
fa7a847f9b92 [project @ 1995-11-06 18:05:09 by jwe]
jwe
parents: 1607
diff changeset
3140 // Do most of the work for defining a function.
fa7a847f9b92 [project @ 1995-11-06 18:05:09 by jwe]
jwe
parents: 1607
diff changeset
3141
16134
ec9c6222ef5a move static parser helper functions to octave_parser class
John W. Eaton <jwe@octave.org>
parents: 16133
diff changeset
3142 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
3143 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
3144 octave_user_function *fcn)
1623
fa7a847f9b92 [project @ 1995-11-06 18:05:09 by jwe]
jwe
parents: 1607
diff changeset
3145 {
4872
fe71c458f438 [project @ 2004-04-21 20:09:32 by jwe]
jwe
parents: 4844
diff changeset
3146 std::string id_name = fname;
1623
fa7a847f9b92 [project @ 1995-11-06 18:05:09 by jwe]
jwe
parents: 1607
diff changeset
3147
fa7a847f9b92 [project @ 1995-11-06 18:05:09 by jwe]
jwe
parents: 1607
diff changeset
3148 // If input is coming from a file, issue a warning if the name of
fa7a847f9b92 [project @ 1995-11-06 18:05:09 by jwe]
jwe
parents: 1607
diff changeset
3149 // the file does not match the name of the function stated in the
fa7a847f9b92 [project @ 1995-11-06 18:05:09 by jwe]
jwe
parents: 1607
diff changeset
3150 // file. Matlab doesn't provide a diagnostic (it ignores the stated
fa7a847f9b92 [project @ 1995-11-06 18:05:09 by jwe]
jwe
parents: 1607
diff changeset
3151 // name).
16288
fe3b9a51e625 rename curr_lexer, curr_parser, CURR_LEXER
John W. Eaton <jwe@octave.org>
parents: 16287
diff changeset
3152 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
3153 && curr_fcn_depth == 1 && ! parsing_subfunctions)
9474
25ed2d6aacf6 Parse nested functions more accurately.
David Grundberg <individ@acc.umu.se>
parents: 9471
diff changeset
3154 {
21066
258c787cd9ce maint: Use "FIXME:" consistently in code base.
Rik <rik@octave.org>
parents: 21065
diff changeset
3155 // 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
3156 // preprocessed when we get here? It seems to only be a
20713
2469d78a1d8b Consistently use 'filename' rather than 'file name' throughout code base.
Rik <rik@octave.org>
parents: 20700
diff changeset
3157 // problem with relative filenames.
9474
25ed2d6aacf6 Parse nested functions more accurately.
David Grundberg <individ@acc.umu.se>
parents: 9471
diff changeset
3158
16288
fe3b9a51e625 rename curr_lexer, curr_parser, CURR_LEXER
John W. Eaton <jwe@octave.org>
parents: 16287
diff changeset
3159 std::string nm = lexer.fcn_file_name;
9474
25ed2d6aacf6 Parse nested functions more accurately.
David Grundberg <individ@acc.umu.se>
parents: 9471
diff changeset
3160
25ed2d6aacf6 Parse nested functions more accurately.
David Grundberg <individ@acc.umu.se>
parents: 9471
diff changeset
3161 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
3162
25ed2d6aacf6 Parse nested functions more accurately.
David Grundberg <individ@acc.umu.se>
parents: 9471
diff changeset
3163 if (pos != std::string::npos)
16288
fe3b9a51e625 rename curr_lexer, curr_parser, CURR_LEXER
John W. Eaton <jwe@octave.org>
parents: 16287
diff changeset
3164 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
3165
25ed2d6aacf6 Parse nested functions more accurately.
David Grundberg <individ@acc.umu.se>
parents: 9471
diff changeset
3166 if (nm != id_name)
25ed2d6aacf6 Parse nested functions more accurately.
David Grundberg <individ@acc.umu.se>
parents: 9471
diff changeset
3167 {
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
3168 warning_with_id
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
3169 ("Octave:function-name-clash",
20713
2469d78a1d8b Consistently use 'filename' rather than 'file name' throughout code base.
Rik <rik@octave.org>
parents: 20700
diff changeset
3170 "function name '%s' does not agree with function filename '%s'",
16288
fe3b9a51e625 rename curr_lexer, curr_parser, CURR_LEXER
John W. Eaton <jwe@octave.org>
parents: 16287
diff changeset
3171 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
3172
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
3173 id_name = nm;
9474
25ed2d6aacf6 Parse nested functions more accurately.
David Grundberg <individ@acc.umu.se>
parents: 9471
diff changeset
3174 }
25ed2d6aacf6 Parse nested functions more accurately.
David Grundberg <individ@acc.umu.se>
parents: 9471
diff changeset
3175 }
1623
fa7a847f9b92 [project @ 1995-11-06 18:05:09 by jwe]
jwe
parents: 1607
diff changeset
3176
16288
fe3b9a51e625 rename curr_lexer, curr_parser, CURR_LEXER
John W. Eaton <jwe@octave.org>
parents: 16287
diff changeset
3177 if (lexer.reading_fcn_file || lexer.reading_classdef_file || autoloading)
1623
fa7a847f9b92 [project @ 1995-11-06 18:05:09 by jwe]
jwe
parents: 1607
diff changeset
3178 {
3712
7066a8065e7e [project @ 2000-08-22 06:21:20 by jwe]
jwe
parents: 3665
diff changeset
3179 octave_time now;
3162
7c96e85c76db [project @ 1998-04-08 18:19:35 by jwe]
jwe
parents: 3156
diff changeset
3180
16288
fe3b9a51e625 rename curr_lexer, curr_parser, CURR_LEXER
John W. Eaton <jwe@octave.org>
parents: 16287
diff changeset
3181 fcn->stash_fcn_file_name (lexer.fcn_file_full_name);
3162
7c96e85c76db [project @ 1998-04-08 18:19:35 by jwe]
jwe
parents: 3156
diff changeset
3182 fcn->stash_fcn_file_time (now);
1623
fa7a847f9b92 [project @ 1995-11-06 18:05:09 by jwe]
jwe
parents: 1607
diff changeset
3183 fcn->mark_as_system_fcn_file ();
3162
7c96e85c76db [project @ 1998-04-08 18:19:35 by jwe]
jwe
parents: 3156
diff changeset
3184
6323
ea65de49e18e [project @ 2007-02-17 02:51:02 by jwe]
jwe
parents: 6238
diff changeset
3185 if (fcn_file_from_relative_lookup)
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
3186 fcn->mark_relative ();
6323
ea65de49e18e [project @ 2007-02-17 02:51:02 by jwe]
jwe
parents: 6238
diff changeset
3187
16153
a57c2c8c8163 move some variables into the octave_parser class
John W. Eaton <jwe@octave.org>
parents: 16151
diff changeset
3188 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
3189 {
16288
fe3b9a51e625 rename curr_lexer, curr_parser, CURR_LEXER
John W. Eaton <jwe@octave.org>
parents: 16287
diff changeset
3190 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
3191
16153
a57c2c8c8163 move some variables into the octave_parser class
John W. Eaton <jwe@octave.org>
parents: 16151
diff changeset
3192 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
3193 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
3194 else
be18c9e359bf Nested function support (bug #35772)
Max Brister <max@2bass.com>
parents: 14533
diff changeset
3195 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
3196 }
6323
ea65de49e18e [project @ 2007-02-17 02:51:02 by jwe]
jwe
parents: 6238
diff changeset
3197
16288
fe3b9a51e625 rename curr_lexer, curr_parser, CURR_LEXER
John W. Eaton <jwe@octave.org>
parents: 16287
diff changeset
3198 if (lexer.parsing_class_method)
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
3199 {
16153
a57c2c8c8163 move some variables into the octave_parser class
John W. Eaton <jwe@octave.org>
parents: 16151
diff changeset
3200 if (curr_class_name == id_name)
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
3201 fcn->mark_as_class_constructor ();
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
3202 else
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
3203 fcn->mark_as_class_method ();
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
3204
16153
a57c2c8c8163 move some variables into the octave_parser class
John W. Eaton <jwe@octave.org>
parents: 16151
diff changeset
3205 fcn->stash_dispatch_class (curr_class_name);
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
3206 }
7336
745a8299c2b5 [project @ 2007-12-28 20:56:55 by jwe]
jwe
parents: 7017
diff changeset
3207
5781
faafc2d98b8d [project @ 2006-05-02 19:40:19 by jwe]
jwe
parents: 5775
diff changeset
3208 std::string nm = fcn->fcn_file_name ();
faafc2d98b8d [project @ 2006-05-02 19:40:19 by jwe]
jwe
parents: 5775
diff changeset
3209
faafc2d98b8d [project @ 2006-05-02 19:40:19 by jwe]
jwe
parents: 5775
diff changeset
3210 file_stat fs (nm);
faafc2d98b8d [project @ 2006-05-02 19:40:19 by jwe]
jwe
parents: 5775
diff changeset
3211
faafc2d98b8d [project @ 2006-05-02 19:40:19 by jwe]
jwe
parents: 5775
diff changeset
3212 if (fs && fs.is_newer (now))
faafc2d98b8d [project @ 2006-05-02 19:40:19 by jwe]
jwe
parents: 5775
diff changeset
3213 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
3214 "time stamp for '%s' is in the future", nm.c_str ());
1623
fa7a847f9b92 [project @ 1995-11-06 18:05:09 by jwe]
jwe
parents: 1607
diff changeset
3215 }
16203
127cccb037bf move more global parser and lexer variables to classes
John W. Eaton <jwe@octave.org>
parents: 16199
diff changeset
3216 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
3217 && ! lexer.force_script
fe3b9a51e625 rename curr_lexer, curr_parser, CURR_LEXER
John W. Eaton <jwe@octave.org>
parents: 16287
diff changeset
3218 && lexer.reading_script_file
fe3b9a51e625 rename curr_lexer, curr_parser, CURR_LEXER
John W. Eaton <jwe@octave.org>
parents: 16287
diff changeset
3219 && lexer.fcn_file_name == id_name)
1623
fa7a847f9b92 [project @ 1995-11-06 18:05:09 by jwe]
jwe
parents: 1607
diff changeset
3220 {
15466
d174210ce1ec use ' instead of ` in error messages, warnings and most comments
John W. Eaton <jwe@octave.org>
parents: 14189
diff changeset
3221 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
3222 id_name.c_str (), lexer.fcn_file_full_name.c_str ());
1623
fa7a847f9b92 [project @ 1995-11-06 18:05:09 by jwe]
jwe
parents: 1607
diff changeset
3223 }
fa7a847f9b92 [project @ 1995-11-06 18:05:09 by jwe]
jwe
parents: 1607
diff changeset
3224
4872
fe71c458f438 [project @ 2004-04-21 20:09:32 by jwe]
jwe
parents: 4844
diff changeset
3225 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
3226
fe3b9a51e625 rename curr_lexer, curr_parser, CURR_LEXER
John W. Eaton <jwe@octave.org>
parents: 16287
diff changeset
3227 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
3228 && ! parsing_subfunctions)
7336
745a8299c2b5 [project @ 2007-12-28 20:56:55 by jwe]
jwe
parents: 7017
diff changeset
3229 {
16288
fe3b9a51e625 rename curr_lexer, curr_parser, CURR_LEXER
John W. Eaton <jwe@octave.org>
parents: 16287
diff changeset
3230 fcn->document (lexer.help_text);
fe3b9a51e625 rename curr_lexer, curr_parser, CURR_LEXER
John W. Eaton <jwe@octave.org>
parents: 16287
diff changeset
3231
fe3b9a51e625 rename curr_lexer, curr_parser, CURR_LEXER
John W. Eaton <jwe@octave.org>
parents: 16287
diff changeset
3232 lexer.help_text = "";
7336
745a8299c2b5 [project @ 2007-12-28 20:56:55 by jwe]
jwe
parents: 7017
diff changeset
3233 }
745a8299c2b5 [project @ 2007-12-28 20:56:55 by jwe]
jwe
parents: 7017
diff changeset
3234
16288
fe3b9a51e625 rename curr_lexer, curr_parser, CURR_LEXER
John W. Eaton <jwe@octave.org>
parents: 16287
diff changeset
3235 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
3236 && ! parsing_subfunctions)
25ed2d6aacf6 Parse nested functions more accurately.
David Grundberg <individ@acc.umu.se>
parents: 9471
diff changeset
3237 primary_fcn_ptr = fcn;
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11572
diff changeset
3238
1623
fa7a847f9b92 [project @ 1995-11-06 18:05:09 by jwe]
jwe
parents: 1607
diff changeset
3239 return fcn;
fa7a847f9b92 [project @ 1995-11-06 18:05:09 by jwe]
jwe
parents: 1607
diff changeset
3240 }
fa7a847f9b92 [project @ 1995-11-06 18:05:09 by jwe]
jwe
parents: 1607
diff changeset
3241
16134
ec9c6222ef5a move static parser helper functions to octave_parser class
John W. Eaton <jwe@octave.org>
parents: 16133
diff changeset
3242 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
3243 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
3244 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
3245 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
3246 int l, int c)
1623
fa7a847f9b92 [project @ 1995-11-06 18:05:09 by jwe]
jwe
parents: 1607
diff changeset
3247 {
7715
5b4d278ec828 parse scripts completely before executing
John W. Eaton <jwe@octave.org>
parents: 7699
diff changeset
3248 tree_function_def *retval = 0;
5b4d278ec828 parse scripts completely before executing
John W. Eaton <jwe@octave.org>
parents: 7699
diff changeset
3249
5b4d278ec828 parse scripts completely before executing
John W. Eaton <jwe@octave.org>
parents: 7699
diff changeset
3250 if (ret_list)
5b4d278ec828 parse scripts completely before executing
John W. Eaton <jwe@octave.org>
parents: 7699
diff changeset
3251 ret_list->mark_as_formal_parameters ();
5b4d278ec828 parse scripts completely before executing
John W. Eaton <jwe@octave.org>
parents: 7699
diff changeset
3252
5b4d278ec828 parse scripts completely before executing
John W. Eaton <jwe@octave.org>
parents: 7699
diff changeset
3253 if (fcn)
5b4d278ec828 parse scripts completely before executing
John W. Eaton <jwe@octave.org>
parents: 7699
diff changeset
3254 {
7761
5adeea5de26c symbol table reporting functions
John W. Eaton <jwe@octave.org>
parents: 7755
diff changeset
3255 std::string nm = fcn->name ();
5adeea5de26c symbol table reporting functions
John W. Eaton <jwe@octave.org>
parents: 7755
diff changeset
3256 std::string file = fcn->fcn_file_name ();
5adeea5de26c symbol table reporting functions
John W. Eaton <jwe@octave.org>
parents: 7755
diff changeset
3257
5adeea5de26c symbol table reporting functions
John W. Eaton <jwe@octave.org>
parents: 7755
diff changeset
3258 std::string tmp = nm;
5adeea5de26c symbol table reporting functions
John W. Eaton <jwe@octave.org>
parents: 7755
diff changeset
3259 if (! file.empty ())
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
3260 tmp += ": " + file;
7761
5adeea5de26c symbol table reporting functions
John W. Eaton <jwe@octave.org>
parents: 7755
diff changeset
3261
5adeea5de26c symbol table reporting functions
John W. Eaton <jwe@octave.org>
parents: 7755
diff changeset
3262 symbol_table::cache_name (fcn->scope (), tmp);
5adeea5de26c symbol table reporting functions
John W. Eaton <jwe@octave.org>
parents: 7755
diff changeset
3263
7715
5b4d278ec828 parse scripts completely before executing
John W. Eaton <jwe@octave.org>
parents: 7699
diff changeset
3264 if (lc)
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
3265 fcn->stash_leading_comment (lc);
7715
5b4d278ec828 parse scripts completely before executing
John W. Eaton <jwe@octave.org>
parents: 7699
diff changeset
3266
5b4d278ec828 parse scripts completely before executing
John W. Eaton <jwe@octave.org>
parents: 7699
diff changeset
3267 fcn->define_ret_list (ret_list);
7755
ea9cb4d68dbf avoid installing subfunctions twice
John W. Eaton <jwe@octave.org>
parents: 7750
diff changeset
3268
16153
a57c2c8c8163 move some variables into the octave_parser class
John W. Eaton <jwe@octave.org>
parents: 16151
diff changeset
3269 if (curr_fcn_depth > 1 || parsing_subfunctions)
9474
25ed2d6aacf6 Parse nested functions more accurately.
David Grundberg <individ@acc.umu.se>
parents: 9471
diff changeset
3270 {
11461
2b8531a6a3c9 Change mentions of "nested function" to the less misleading "subfunction"
David Grundberg <individ@acc.umu.se>
parents: 11388
diff changeset
3271 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
3272 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
3273
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
3274 subfunction_names.push_back (nm);
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
3275
14544
be18c9e359bf Nested function support (bug #35772)
Max Brister <max@2bass.com>
parents: 14533
diff changeset
3276 if (endfunction_found && function_scopes.size () > 1)
be18c9e359bf Nested function support (bug #35772)
Max Brister <max@2bass.com>
parents: 14533
diff changeset
3277 {
be18c9e359bf Nested function support (bug #35772)
Max Brister <max@2bass.com>
parents: 14533
diff changeset
3278 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
3279 = function_scopes[function_scopes.size ()-2];
14544
be18c9e359bf Nested function support (bug #35772)
Max Brister <max@2bass.com>
parents: 14533
diff changeset
3280
be18c9e359bf Nested function support (bug #35772)
Max Brister <max@2bass.com>
parents: 14533
diff changeset
3281 symbol_table::install_nestfunction (nm, octave_value (fcn),
be18c9e359bf Nested function support (bug #35772)
Max Brister <max@2bass.com>
parents: 14533
diff changeset
3282 pscope);
be18c9e359bf Nested function support (bug #35772)
Max Brister <max@2bass.com>
parents: 14533
diff changeset
3283 }
be18c9e359bf Nested function support (bug #35772)
Max Brister <max@2bass.com>
parents: 14533
diff changeset
3284 else
be18c9e359bf Nested function support (bug #35772)
Max Brister <max@2bass.com>
parents: 14533
diff changeset
3285 symbol_table::install_subfunction (nm, octave_value (fcn),
be18c9e359bf Nested function support (bug #35772)
Max Brister <max@2bass.com>
parents: 14533
diff changeset
3286 primary_fcn_scope);
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
3287 }
9474
25ed2d6aacf6 Parse nested functions more accurately.
David Grundberg <individ@acc.umu.se>
parents: 9471
diff changeset
3288
16153
a57c2c8c8163 move some variables into the octave_parser class
John W. Eaton <jwe@octave.org>
parents: 16151
diff changeset
3289 if (curr_fcn_depth == 1 && fcn)
14544
be18c9e359bf Nested function support (bug #35772)
Max Brister <max@2bass.com>
parents: 14533
diff changeset
3290 symbol_table::update_nest (fcn->scope ());
be18c9e359bf Nested function support (bug #35772)
Max Brister <max@2bass.com>
parents: 14533
diff changeset
3291
16288
fe3b9a51e625 rename curr_lexer, curr_parser, CURR_LEXER
John W. Eaton <jwe@octave.org>
parents: 16287
diff changeset
3292 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
3293 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
3294 // 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
3295 // 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
3296 // 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
3297 // 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
3298 // 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
3299 // 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
3300 // 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
3301 // parse_fcn_file, and
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
3302 // 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
3303
5f8971be8e12 parse.y (finish_function): retrun function object unless parsing function file
John W. Eaton <jwe@octave.org>
parents: 9506
diff changeset
3304 retval = new tree_function_def (fcn);
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
3305 }
7715
5b4d278ec828 parse scripts completely before executing
John W. Eaton <jwe@octave.org>
parents: 7699
diff changeset
3306 }
5b4d278ec828 parse scripts completely before executing
John W. Eaton <jwe@octave.org>
parents: 7699
diff changeset
3307
5b4d278ec828 parse scripts completely before executing
John W. Eaton <jwe@octave.org>
parents: 7699
diff changeset
3308 return retval;
1623
fa7a847f9b92 [project @ 1995-11-06 18:05:09 by jwe]
jwe
parents: 1607
diff changeset
3309 }
fa7a847f9b92 [project @ 1995-11-06 18:05:09 by jwe]
jwe
parents: 1607
diff changeset
3310
16134
ec9c6222ef5a move static parser helper functions to octave_parser class
John W. Eaton <jwe@octave.org>
parents: 16133
diff changeset
3311 void
16287
04a7953496a7 create base class for parser; use reference for curr_lexer
John W. Eaton <jwe@octave.org>
parents: 16285
diff changeset
3312 octave_base_parser::recover_from_parsing_function (void)
2883
0b3954110c77 [project @ 1997-04-24 09:57:05 by jwe]
jwe
parents: 2865
diff changeset
3313 {
16320
09f0cb9cac7d don't modify symbol table scope in the parser
John W. Eaton <jwe@octave.org>
parents: 16302
diff changeset
3314 lexer.symtab_context.pop ();
2883
0b3954110c77 [project @ 1997-04-24 09:57:05 by jwe]
jwe
parents: 2865
diff changeset
3315
16288
fe3b9a51e625 rename curr_lexer, curr_parser, CURR_LEXER
John W. Eaton <jwe@octave.org>
parents: 16287
diff changeset
3316 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
3317 && ! parsing_subfunctions)
25ed2d6aacf6 Parse nested functions more accurately.
David Grundberg <individ@acc.umu.se>
parents: 9471
diff changeset
3318 parsing_subfunctions = true;
25ed2d6aacf6 Parse nested functions more accurately.
David Grundberg <individ@acc.umu.se>
parents: 9471
diff changeset
3319
16153
a57c2c8c8163 move some variables into the octave_parser class
John W. Eaton <jwe@octave.org>
parents: 16151
diff changeset
3320 curr_fcn_depth--;
14544
be18c9e359bf Nested function support (bug #35772)
Max Brister <max@2bass.com>
parents: 14533
diff changeset
3321 function_scopes.pop_back ();
9474
25ed2d6aacf6 Parse nested functions more accurately.
David Grundberg <individ@acc.umu.se>
parents: 9471
diff changeset
3322
16288
fe3b9a51e625 rename curr_lexer, curr_parser, CURR_LEXER
John W. Eaton <jwe@octave.org>
parents: 16287
diff changeset
3323 lexer.defining_func--;
fe3b9a51e625 rename curr_lexer, curr_parser, CURR_LEXER
John W. Eaton <jwe@octave.org>
parents: 16287
diff changeset
3324 lexer.parsed_function_name.pop ();
fe3b9a51e625 rename curr_lexer, curr_parser, CURR_LEXER
John W. Eaton <jwe@octave.org>
parents: 16287
diff changeset
3325 lexer.looking_at_return_list = false;
fe3b9a51e625 rename curr_lexer, curr_parser, CURR_LEXER
John W. Eaton <jwe@octave.org>
parents: 16287
diff changeset
3326 lexer.looking_at_parameter_list = false;
2883
0b3954110c77 [project @ 1997-04-24 09:57:05 by jwe]
jwe
parents: 2865
diff changeset
3327 }
0b3954110c77 [project @ 1997-04-24 09:57:05 by jwe]
jwe
parents: 2865
diff changeset
3328
16155
0259254a3ccc maint: periodic merge of default to classdef
John W. Eaton <jwe@octave.org>
parents: 15954 16153
diff changeset
3329 tree_funcall *
16289
bde729ba8381 maint: periodic merge of default to classdef
John W. Eaton <jwe@octave.org>
parents: 16286 16288
diff changeset
3330 octave_base_parser::make_superclass_ref (const std::string& method_nm,
18927
09eb8a2ddb02 eliminate some unused parameter warnings in parser functions
John W. Eaton <jwe@octave.org>
parents: 18537
diff changeset
3331 const std::string& class_nm)
16155
0259254a3ccc maint: periodic merge of default to classdef
John W. Eaton <jwe@octave.org>
parents: 15954 16153
diff changeset
3332 {
0259254a3ccc maint: periodic merge of default to classdef
John W. Eaton <jwe@octave.org>
parents: 15954 16153
diff changeset
3333 octave_value_list args;
0259254a3ccc maint: periodic merge of default to classdef
John W. Eaton <jwe@octave.org>
parents: 15954 16153
diff changeset
3334
18520
932aca9a7c57 Allow multi-level classdef package.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 18419
diff changeset
3335 args(1) = class_nm;
16155
0259254a3ccc maint: periodic merge of default to classdef
John W. Eaton <jwe@octave.org>
parents: 15954 16153
diff changeset
3336 args(0) = method_nm;
0259254a3ccc maint: periodic merge of default to classdef
John W. Eaton <jwe@octave.org>
parents: 15954 16153
diff changeset
3337
0259254a3ccc maint: periodic merge of default to classdef
John W. Eaton <jwe@octave.org>
parents: 15954 16153
diff changeset
3338 octave_value fcn
0259254a3ccc maint: periodic merge of default to classdef
John W. Eaton <jwe@octave.org>
parents: 15954 16153
diff changeset
3339 = symbol_table::find_built_in_function ("__superclass_reference__");
0259254a3ccc maint: periodic merge of default to classdef
John W. Eaton <jwe@octave.org>
parents: 15954 16153
diff changeset
3340
0259254a3ccc maint: periodic merge of default to classdef
John W. Eaton <jwe@octave.org>
parents: 15954 16153
diff changeset
3341 return new tree_funcall (fcn, args);
0259254a3ccc maint: periodic merge of default to classdef
John W. Eaton <jwe@octave.org>
parents: 15954 16153
diff changeset
3342 }
0259254a3ccc maint: periodic merge of default to classdef
John W. Eaton <jwe@octave.org>
parents: 15954 16153
diff changeset
3343
0259254a3ccc maint: periodic merge of default to classdef
John W. Eaton <jwe@octave.org>
parents: 15954 16153
diff changeset
3344 tree_funcall *
18927
09eb8a2ddb02 eliminate some unused parameter warnings in parser functions
John W. Eaton <jwe@octave.org>
parents: 18537
diff changeset
3345 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>
parents: 15954 16153
diff changeset
3346 {
0259254a3ccc maint: periodic merge of default to classdef
John W. Eaton <jwe@octave.org>
parents: 15954 16153
diff changeset
3347 octave_value_list args;
0259254a3ccc maint: periodic merge of default to classdef
John W. Eaton <jwe@octave.org>
parents: 15954 16153
diff changeset
3348
18520
932aca9a7c57 Allow multi-level classdef package.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 18419
diff changeset
3349 args(0) = class_nm;
16155
0259254a3ccc maint: periodic merge of default to classdef
John W. Eaton <jwe@octave.org>
parents: 15954 16153
diff changeset
3350
0259254a3ccc maint: periodic merge of default to classdef
John W. Eaton <jwe@octave.org>
parents: 15954 16153
diff changeset
3351 octave_value fcn
0259254a3ccc maint: periodic merge of default to classdef
John W. Eaton <jwe@octave.org>
parents: 15954 16153
diff changeset
3352 = symbol_table::find_built_in_function ("__meta_class_query__");
0259254a3ccc maint: periodic merge of default to classdef
John W. Eaton <jwe@octave.org>
parents: 15954 16153
diff changeset
3353
0259254a3ccc maint: periodic merge of default to classdef
John W. Eaton <jwe@octave.org>
parents: 15954 16153
diff changeset
3354 return new tree_funcall (fcn, args);
0259254a3ccc maint: periodic merge of default to classdef
John W. Eaton <jwe@octave.org>
parents: 15954 16153
diff changeset
3355 }
0259254a3ccc maint: periodic merge of default to classdef
John W. Eaton <jwe@octave.org>
parents: 15954 16153
diff changeset
3356
0259254a3ccc maint: periodic merge of default to classdef
John W. Eaton <jwe@octave.org>
parents: 15954 16153
diff changeset
3357 // 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>
parents: 15954 16153
diff changeset
3358 // 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>
parents: 15954 16153
diff changeset
3359 // makes some changes in the symbol table (inserting the constructor
0259254a3ccc maint: periodic merge of default to classdef
John W. Eaton <jwe@octave.org>
parents: 15954 16153
diff changeset
3360 // 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>
parents: 15954 16153
diff changeset
3361 // a parse tree containing meta information about the class.
0259254a3ccc maint: periodic merge of default to classdef
John W. Eaton <jwe@octave.org>
parents: 15954 16153
diff changeset
3362
0259254a3ccc maint: periodic merge of default to classdef
John W. Eaton <jwe@octave.org>
parents: 15954 16153
diff changeset
3363 tree_classdef *
16289
bde729ba8381 maint: periodic merge of default to classdef
John W. Eaton <jwe@octave.org>
parents: 16286 16288
diff changeset
3364 octave_base_parser::make_classdef (token *tok_val,
bde729ba8381 maint: periodic merge of default to classdef
John W. Eaton <jwe@octave.org>
parents: 16286 16288
diff changeset
3365 tree_classdef_attribute_list *a,
bde729ba8381 maint: periodic merge of default to classdef
John W. Eaton <jwe@octave.org>
parents: 16286 16288
diff changeset
3366 tree_identifier *id,
bde729ba8381 maint: periodic merge of default to classdef
John W. Eaton <jwe@octave.org>
parents: 16286 16288
diff changeset
3367 tree_classdef_superclass_list *sc,
bde729ba8381 maint: periodic merge of default to classdef
John W. Eaton <jwe@octave.org>
parents: 16286 16288
diff changeset
3368 tree_classdef_body *body, token *end_tok,
bde729ba8381 maint: periodic merge of default to classdef
John W. Eaton <jwe@octave.org>
parents: 16286 16288
diff changeset
3369 octave_comment_list *lc)
16155
0259254a3ccc maint: periodic merge of default to classdef
John W. Eaton <jwe@octave.org>
parents: 15954 16153
diff changeset
3370 {
0259254a3ccc maint: periodic merge of default to classdef
John W. Eaton <jwe@octave.org>
parents: 15954 16153
diff changeset
3371 tree_classdef *retval = 0;
0259254a3ccc maint: periodic merge of default to classdef
John W. Eaton <jwe@octave.org>
parents: 15954 16153
diff changeset
3372
0259254a3ccc maint: periodic merge of default to classdef
John W. Eaton <jwe@octave.org>
parents: 15954 16153
diff changeset
3373 std::string cls_name = id->name ();
0259254a3ccc maint: periodic merge of default to classdef
John W. Eaton <jwe@octave.org>
parents: 15954 16153
diff changeset
3374
16289
bde729ba8381 maint: periodic merge of default to classdef
John W. Eaton <jwe@octave.org>
parents: 16286 16288
diff changeset
3375 std::string nm = lexer.fcn_file_name;
16155
0259254a3ccc maint: periodic merge of default to classdef
John W. Eaton <jwe@octave.org>
parents: 15954 16153
diff changeset
3376
0259254a3ccc maint: periodic merge of default to classdef
John W. Eaton <jwe@octave.org>
parents: 15954 16153
diff changeset
3377 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>
parents: 15954 16153
diff changeset
3378
0259254a3ccc maint: periodic merge of default to classdef
John W. Eaton <jwe@octave.org>
parents: 15954 16153
diff changeset
3379 if (pos != std::string::npos)
16289
bde729ba8381 maint: periodic merge of default to classdef
John W. Eaton <jwe@octave.org>
parents: 16286 16288
diff changeset
3380 nm = lexer.fcn_file_name.substr (pos+1);
16155
0259254a3ccc maint: periodic merge of default to classdef
John W. Eaton <jwe@octave.org>
parents: 15954 16153
diff changeset
3381
0259254a3ccc maint: periodic merge of default to classdef
John W. Eaton <jwe@octave.org>
parents: 15954 16153
diff changeset
3382 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
3383 {
2b1047efc4fb don't leak memory when parsing classdef objects fails
John W. Eaton <jwe@octave.org>
parents: 17654
diff changeset
3384 delete a;
2b1047efc4fb don't leak memory when parsing classdef objects fails
John W. Eaton <jwe@octave.org>
parents: 17654
diff changeset
3385 delete id;
2b1047efc4fb don't leak memory when parsing classdef objects fails
John W. Eaton <jwe@octave.org>
parents: 17654
diff changeset
3386 delete sc;
2b1047efc4fb don't leak memory when parsing classdef objects fails
John W. Eaton <jwe@octave.org>
parents: 17654
diff changeset
3387 delete body;
21071
f25c14056b7c overhaul parser error handling for end token mismatch
John W. Eaton <jwe@octave.org>
parents: 21066
diff changeset
3388
f25c14056b7c overhaul parser error handling for end token mismatch
John W. Eaton <jwe@octave.org>
parents: 21066
diff changeset
3389 bison_error ("invalid classdef definition, the class name must match the filename");
f25c14056b7c overhaul parser error handling for end token mismatch
John W. Eaton <jwe@octave.org>
parents: 21066
diff changeset
3390
f25c14056b7c overhaul parser error handling for end token mismatch
John W. Eaton <jwe@octave.org>
parents: 21066
diff changeset
3391 }
f25c14056b7c overhaul parser error handling for end token mismatch
John W. Eaton <jwe@octave.org>
parents: 21066
diff changeset
3392 else
f25c14056b7c overhaul parser error handling for end token mismatch
John W. Eaton <jwe@octave.org>
parents: 21066
diff changeset
3393 {
f25c14056b7c overhaul parser error handling for end token mismatch
John W. Eaton <jwe@octave.org>
parents: 21066
diff changeset
3394 if (end_token_ok (end_tok, token::classdef_end))
f25c14056b7c overhaul parser error handling for end token mismatch
John W. Eaton <jwe@octave.org>
parents: 21066
diff changeset
3395 {
f25c14056b7c overhaul parser error handling for end token mismatch
John W. Eaton <jwe@octave.org>
parents: 21066
diff changeset
3396 octave_comment_list *tc = lexer.comment_buf.get_comment ();
f25c14056b7c overhaul parser error handling for end token mismatch
John W. Eaton <jwe@octave.org>
parents: 21066
diff changeset
3397
f25c14056b7c overhaul parser error handling for end token mismatch
John W. Eaton <jwe@octave.org>
parents: 21066
diff changeset
3398 int l = tok_val->line ();
f25c14056b7c overhaul parser error handling for end token mismatch
John W. Eaton <jwe@octave.org>
parents: 21066
diff changeset
3399 int c = tok_val->column ();
f25c14056b7c overhaul parser error handling for end token mismatch
John W. Eaton <jwe@octave.org>
parents: 21066
diff changeset
3400
f25c14056b7c overhaul parser error handling for end token mismatch
John W. Eaton <jwe@octave.org>
parents: 21066
diff changeset
3401 if (! body)
f25c14056b7c overhaul parser error handling for end token mismatch
John W. Eaton <jwe@octave.org>
parents: 21066
diff changeset
3402 body = new tree_classdef_body ();
f25c14056b7c overhaul parser error handling for end token mismatch
John W. Eaton <jwe@octave.org>
parents: 21066
diff changeset
3403
f25c14056b7c overhaul parser error handling for end token mismatch
John W. Eaton <jwe@octave.org>
parents: 21066
diff changeset
3404 retval = new tree_classdef (a, id, sc, body, lc, tc,
f25c14056b7c overhaul parser error handling for end token mismatch
John W. Eaton <jwe@octave.org>
parents: 21066
diff changeset
3405 curr_package_name, l, c);
f25c14056b7c overhaul parser error handling for end token mismatch
John W. Eaton <jwe@octave.org>
parents: 21066
diff changeset
3406 }
f25c14056b7c overhaul parser error handling for end token mismatch
John W. Eaton <jwe@octave.org>
parents: 21066
diff changeset
3407 else
f25c14056b7c overhaul parser error handling for end token mismatch
John W. Eaton <jwe@octave.org>
parents: 21066
diff changeset
3408 {
f25c14056b7c overhaul parser error handling for end token mismatch
John W. Eaton <jwe@octave.org>
parents: 21066
diff changeset
3409 delete a;
f25c14056b7c overhaul parser error handling for end token mismatch
John W. Eaton <jwe@octave.org>
parents: 21066
diff changeset
3410 delete id;
f25c14056b7c overhaul parser error handling for end token mismatch
John W. Eaton <jwe@octave.org>
parents: 21066
diff changeset
3411 delete sc;
f25c14056b7c overhaul parser error handling for end token mismatch
John W. Eaton <jwe@octave.org>
parents: 21066
diff changeset
3412 delete body;
f25c14056b7c overhaul parser error handling for end token mismatch
John W. Eaton <jwe@octave.org>
parents: 21066
diff changeset
3413
f25c14056b7c overhaul parser error handling for end token mismatch
John W. Eaton <jwe@octave.org>
parents: 21066
diff changeset
3414 end_token_error (end_tok, token::switch_end);
f25c14056b7c overhaul parser error handling for end token mismatch
John W. Eaton <jwe@octave.org>
parents: 21066
diff changeset
3415 }
16155
0259254a3ccc maint: periodic merge of default to classdef
John W. Eaton <jwe@octave.org>
parents: 15954 16153
diff changeset
3416 }
0259254a3ccc maint: periodic merge of default to classdef
John W. Eaton <jwe@octave.org>
parents: 15954 16153
diff changeset
3417
0259254a3ccc maint: periodic merge of default to classdef
John W. Eaton <jwe@octave.org>
parents: 15954 16153
diff changeset
3418 return retval;
0259254a3ccc maint: periodic merge of default to classdef
John W. Eaton <jwe@octave.org>
parents: 15954 16153
diff changeset
3419 }
0259254a3ccc maint: periodic merge of default to classdef
John W. Eaton <jwe@octave.org>
parents: 15954 16153
diff changeset
3420
0259254a3ccc maint: periodic merge of default to classdef
John W. Eaton <jwe@octave.org>
parents: 15954 16153
diff changeset
3421 tree_classdef_properties_block *
16289
bde729ba8381 maint: periodic merge of default to classdef
John W. Eaton <jwe@octave.org>
parents: 16286 16288
diff changeset
3422 octave_base_parser::make_classdef_properties_block (token *tok_val,
bde729ba8381 maint: periodic merge of default to classdef
John W. Eaton <jwe@octave.org>
parents: 16286 16288
diff changeset
3423 tree_classdef_attribute_list *a,
bde729ba8381 maint: periodic merge of default to classdef
John W. Eaton <jwe@octave.org>
parents: 16286 16288
diff changeset
3424 tree_classdef_property_list *plist,
bde729ba8381 maint: periodic merge of default to classdef
John W. Eaton <jwe@octave.org>
parents: 16286 16288
diff changeset
3425 token *end_tok,
bde729ba8381 maint: periodic merge of default to classdef
John W. Eaton <jwe@octave.org>
parents: 16286 16288
diff changeset
3426 octave_comment_list *lc)
16155
0259254a3ccc maint: periodic merge of default to classdef
John W. Eaton <jwe@octave.org>
parents: 15954 16153
diff changeset
3427 {
0259254a3ccc maint: periodic merge of default to classdef
John W. Eaton <jwe@octave.org>
parents: 15954 16153
diff changeset
3428 tree_classdef_properties_block *retval = 0;
0259254a3ccc maint: periodic merge of default to classdef
John W. Eaton <jwe@octave.org>
parents: 15954 16153
diff changeset
3429
0259254a3ccc maint: periodic merge of default to classdef
John W. Eaton <jwe@octave.org>
parents: 15954 16153
diff changeset
3430 if (end_token_ok (end_tok, token::properties_end))
0259254a3ccc maint: periodic merge of default to classdef
John W. Eaton <jwe@octave.org>
parents: 15954 16153
diff changeset
3431 {
17745
93b3d03b05e7 maint: periodic merge of default to classdef
John W. Eaton <jwe@octave.org>
parents: 17735 17744
diff changeset
3432 octave_comment_list *tc = lexer.comment_buf.get_comment ();
16155
0259254a3ccc maint: periodic merge of default to classdef
John W. Eaton <jwe@octave.org>
parents: 15954 16153
diff changeset
3433
0259254a3ccc maint: periodic merge of default to classdef
John W. Eaton <jwe@octave.org>
parents: 15954 16153
diff changeset
3434 int l = tok_val->line ();
0259254a3ccc maint: periodic merge of default to classdef
John W. Eaton <jwe@octave.org>
parents: 15954 16153
diff changeset
3435 int c = tok_val->column ();
0259254a3ccc maint: periodic merge of default to classdef
John W. Eaton <jwe@octave.org>
parents: 15954 16153
diff changeset
3436
18419
9154dc252f47 Allow empty classdef or methods/properties/... blocks
Michael Goffioul <michael.goffioul@gmail.com>
parents: 18395
diff changeset
3437 if (! plist)
9154dc252f47 Allow empty classdef or methods/properties/... blocks
Michael Goffioul <michael.goffioul@gmail.com>
parents: 18395
diff changeset
3438 plist = new tree_classdef_property_list ();
9154dc252f47 Allow empty classdef or methods/properties/... blocks
Michael Goffioul <michael.goffioul@gmail.com>
parents: 18395
diff changeset
3439
16155
0259254a3ccc maint: periodic merge of default to classdef
John W. Eaton <jwe@octave.org>
parents: 15954 16153
diff changeset
3440 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>
parents: 15954 16153
diff changeset
3441 }
17656
2b1047efc4fb don't leak memory when parsing classdef objects fails
John W. Eaton <jwe@octave.org>
parents: 17654
diff changeset
3442 else
2b1047efc4fb don't leak memory when parsing classdef objects fails
John W. Eaton <jwe@octave.org>
parents: 17654
diff changeset
3443 {
2b1047efc4fb don't leak memory when parsing classdef objects fails
John W. Eaton <jwe@octave.org>
parents: 17654
diff changeset
3444 delete a;
2b1047efc4fb don't leak memory when parsing classdef objects fails
John W. Eaton <jwe@octave.org>
parents: 17654
diff changeset
3445 delete plist;
21071
f25c14056b7c overhaul parser error handling for end token mismatch
John W. Eaton <jwe@octave.org>
parents: 21066
diff changeset
3446
f25c14056b7c overhaul parser error handling for end token mismatch
John W. Eaton <jwe@octave.org>
parents: 21066
diff changeset
3447 end_token_error (end_tok, token::properties_end);
17656
2b1047efc4fb don't leak memory when parsing classdef objects fails
John W. Eaton <jwe@octave.org>
parents: 17654
diff changeset
3448 }
16155
0259254a3ccc maint: periodic merge of default to classdef
John W. Eaton <jwe@octave.org>
parents: 15954 16153
diff changeset
3449
0259254a3ccc maint: periodic merge of default to classdef
John W. Eaton <jwe@octave.org>
parents: 15954 16153
diff changeset
3450 return retval;
0259254a3ccc maint: periodic merge of default to classdef
John W. Eaton <jwe@octave.org>
parents: 15954 16153
diff changeset
3451 }
0259254a3ccc maint: periodic merge of default to classdef
John W. Eaton <jwe@octave.org>
parents: 15954 16153
diff changeset
3452
0259254a3ccc maint: periodic merge of default to classdef
John W. Eaton <jwe@octave.org>
parents: 15954 16153
diff changeset
3453 tree_classdef_methods_block *
16289
bde729ba8381 maint: periodic merge of default to classdef
John W. Eaton <jwe@octave.org>
parents: 16286 16288
diff changeset
3454 octave_base_parser::make_classdef_methods_block (token *tok_val,
bde729ba8381 maint: periodic merge of default to classdef
John W. Eaton <jwe@octave.org>
parents: 16286 16288
diff changeset
3455 tree_classdef_attribute_list *a,
bde729ba8381 maint: periodic merge of default to classdef
John W. Eaton <jwe@octave.org>
parents: 16286 16288
diff changeset
3456 tree_classdef_methods_list *mlist,
bde729ba8381 maint: periodic merge of default to classdef
John W. Eaton <jwe@octave.org>
parents: 16286 16288
diff changeset
3457 token *end_tok,
bde729ba8381 maint: periodic merge of default to classdef
John W. Eaton <jwe@octave.org>
parents: 16286 16288
diff changeset
3458 octave_comment_list *lc)
16155
0259254a3ccc maint: periodic merge of default to classdef
John W. Eaton <jwe@octave.org>
parents: 15954 16153
diff changeset
3459 {
0259254a3ccc maint: periodic merge of default to classdef
John W. Eaton <jwe@octave.org>
parents: 15954 16153
diff changeset
3460 tree_classdef_methods_block *retval = 0;
0259254a3ccc maint: periodic merge of default to classdef
John W. Eaton <jwe@octave.org>
parents: 15954 16153
diff changeset
3461
0259254a3ccc maint: periodic merge of default to classdef
John W. Eaton <jwe@octave.org>
parents: 15954 16153
diff changeset
3462 if (end_token_ok (end_tok, token::methods_end))
0259254a3ccc maint: periodic merge of default to classdef
John W. Eaton <jwe@octave.org>
parents: 15954 16153
diff changeset
3463 {
17745
93b3d03b05e7 maint: periodic merge of default to classdef
John W. Eaton <jwe@octave.org>
parents: 17735 17744
diff changeset
3464 octave_comment_list *tc = lexer.comment_buf.get_comment ();
16155
0259254a3ccc maint: periodic merge of default to classdef
John W. Eaton <jwe@octave.org>
parents: 15954 16153
diff changeset
3465
0259254a3ccc maint: periodic merge of default to classdef
John W. Eaton <jwe@octave.org>
parents: 15954 16153
diff changeset
3466 int l = tok_val->line ();
0259254a3ccc maint: periodic merge of default to classdef
John W. Eaton <jwe@octave.org>
parents: 15954 16153
diff changeset
3467 int c = tok_val->column ();
0259254a3ccc maint: periodic merge of default to classdef
John W. Eaton <jwe@octave.org>
parents: 15954 16153
diff changeset
3468
18419
9154dc252f47 Allow empty classdef or methods/properties/... blocks
Michael Goffioul <michael.goffioul@gmail.com>
parents: 18395
diff changeset
3469 if (! mlist)
9154dc252f47 Allow empty classdef or methods/properties/... blocks
Michael Goffioul <michael.goffioul@gmail.com>
parents: 18395
diff changeset
3470 mlist = new tree_classdef_methods_list ();
9154dc252f47 Allow empty classdef or methods/properties/... blocks
Michael Goffioul <michael.goffioul@gmail.com>
parents: 18395
diff changeset
3471
16155
0259254a3ccc maint: periodic merge of default to classdef
John W. Eaton <jwe@octave.org>
parents: 15954 16153
diff changeset
3472 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>
parents: 15954 16153
diff changeset
3473 }
17656
2b1047efc4fb don't leak memory when parsing classdef objects fails
John W. Eaton <jwe@octave.org>
parents: 17654
diff changeset
3474 else
2b1047efc4fb don't leak memory when parsing classdef objects fails
John W. Eaton <jwe@octave.org>
parents: 17654
diff changeset
3475 {
2b1047efc4fb don't leak memory when parsing classdef objects fails
John W. Eaton <jwe@octave.org>
parents: 17654
diff changeset
3476 delete a;
2b1047efc4fb don't leak memory when parsing classdef objects fails
John W. Eaton <jwe@octave.org>
parents: 17654
diff changeset
3477 delete mlist;
21071
f25c14056b7c overhaul parser error handling for end token mismatch
John W. Eaton <jwe@octave.org>
parents: 21066
diff changeset
3478
f25c14056b7c overhaul parser error handling for end token mismatch
John W. Eaton <jwe@octave.org>
parents: 21066
diff changeset
3479 end_token_error (end_tok, token::methods_end);
17656
2b1047efc4fb don't leak memory when parsing classdef objects fails
John W. Eaton <jwe@octave.org>
parents: 17654
diff changeset
3480 }
16155
0259254a3ccc maint: periodic merge of default to classdef
John W. Eaton <jwe@octave.org>
parents: 15954 16153
diff changeset
3481
0259254a3ccc maint: periodic merge of default to classdef
John W. Eaton <jwe@octave.org>
parents: 15954 16153
diff changeset
3482 return retval;
0259254a3ccc maint: periodic merge of default to classdef
John W. Eaton <jwe@octave.org>
parents: 15954 16153
diff changeset
3483 }
0259254a3ccc maint: periodic merge of default to classdef
John W. Eaton <jwe@octave.org>
parents: 15954 16153
diff changeset
3484
0259254a3ccc maint: periodic merge of default to classdef
John W. Eaton <jwe@octave.org>
parents: 15954 16153
diff changeset
3485 tree_classdef_events_block *
16289
bde729ba8381 maint: periodic merge of default to classdef
John W. Eaton <jwe@octave.org>
parents: 16286 16288
diff changeset
3486 octave_base_parser::make_classdef_events_block (token *tok_val,
bde729ba8381 maint: periodic merge of default to classdef
John W. Eaton <jwe@octave.org>
parents: 16286 16288
diff changeset
3487 tree_classdef_attribute_list *a,
bde729ba8381 maint: periodic merge of default to classdef
John W. Eaton <jwe@octave.org>
parents: 16286 16288
diff changeset
3488 tree_classdef_events_list *elist,
bde729ba8381 maint: periodic merge of default to classdef
John W. Eaton <jwe@octave.org>
parents: 16286 16288
diff changeset
3489 token *end_tok,
bde729ba8381 maint: periodic merge of default to classdef
John W. Eaton <jwe@octave.org>
parents: 16286 16288
diff changeset
3490 octave_comment_list *lc)
16155
0259254a3ccc maint: periodic merge of default to classdef
John W. Eaton <jwe@octave.org>
parents: 15954 16153
diff changeset
3491 {
0259254a3ccc maint: periodic merge of default to classdef
John W. Eaton <jwe@octave.org>
parents: 15954 16153
diff changeset
3492 tree_classdef_events_block *retval = 0;
0259254a3ccc maint: periodic merge of default to classdef
John W. Eaton <jwe@octave.org>
parents: 15954 16153
diff changeset
3493
0259254a3ccc maint: periodic merge of default to classdef
John W. Eaton <jwe@octave.org>
parents: 15954 16153
diff changeset
3494 if (end_token_ok (end_tok, token::events_end))
0259254a3ccc maint: periodic merge of default to classdef
John W. Eaton <jwe@octave.org>
parents: 15954 16153
diff changeset
3495 {
17745
93b3d03b05e7 maint: periodic merge of default to classdef
John W. Eaton <jwe@octave.org>
parents: 17735 17744
diff changeset
3496 octave_comment_list *tc = lexer.comment_buf.get_comment ();
16155
0259254a3ccc maint: periodic merge of default to classdef
John W. Eaton <jwe@octave.org>
parents: 15954 16153
diff changeset
3497
0259254a3ccc maint: periodic merge of default to classdef
John W. Eaton <jwe@octave.org>
parents: 15954 16153
diff changeset
3498 int l = tok_val->line ();
0259254a3ccc maint: periodic merge of default to classdef
John W. Eaton <jwe@octave.org>
parents: 15954 16153
diff changeset
3499 int c = tok_val->column ();
0259254a3ccc maint: periodic merge of default to classdef
John W. Eaton <jwe@octave.org>
parents: 15954 16153
diff changeset
3500
18419
9154dc252f47 Allow empty classdef or methods/properties/... blocks
Michael Goffioul <michael.goffioul@gmail.com>
parents: 18395
diff changeset
3501 if (! elist)
9154dc252f47 Allow empty classdef or methods/properties/... blocks
Michael Goffioul <michael.goffioul@gmail.com>
parents: 18395
diff changeset
3502 elist = new tree_classdef_events_list ();
9154dc252f47 Allow empty classdef or methods/properties/... blocks
Michael Goffioul <michael.goffioul@gmail.com>
parents: 18395
diff changeset
3503
16155
0259254a3ccc maint: periodic merge of default to classdef
John W. Eaton <jwe@octave.org>
parents: 15954 16153
diff changeset
3504 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>
parents: 15954 16153
diff changeset
3505 }
17656
2b1047efc4fb don't leak memory when parsing classdef objects fails
John W. Eaton <jwe@octave.org>
parents: 17654
diff changeset
3506 else
2b1047efc4fb don't leak memory when parsing classdef objects fails
John W. Eaton <jwe@octave.org>
parents: 17654
diff changeset
3507 {
2b1047efc4fb don't leak memory when parsing classdef objects fails
John W. Eaton <jwe@octave.org>
parents: 17654
diff changeset
3508 delete a;
2b1047efc4fb don't leak memory when parsing classdef objects fails
John W. Eaton <jwe@octave.org>
parents: 17654
diff changeset
3509 delete elist;
21071
f25c14056b7c overhaul parser error handling for end token mismatch
John W. Eaton <jwe@octave.org>
parents: 21066
diff changeset
3510
f25c14056b7c overhaul parser error handling for end token mismatch
John W. Eaton <jwe@octave.org>
parents: 21066
diff changeset
3511 end_token_error (end_tok, token::events_end);
17656
2b1047efc4fb don't leak memory when parsing classdef objects fails
John W. Eaton <jwe@octave.org>
parents: 17654
diff changeset
3512 }
16155
0259254a3ccc maint: periodic merge of default to classdef
John W. Eaton <jwe@octave.org>
parents: 15954 16153
diff changeset
3513
0259254a3ccc maint: periodic merge of default to classdef
John W. Eaton <jwe@octave.org>
parents: 15954 16153
diff changeset
3514 return retval;
0259254a3ccc maint: periodic merge of default to classdef
John W. Eaton <jwe@octave.org>
parents: 15954 16153
diff changeset
3515 }
0259254a3ccc maint: periodic merge of default to classdef
John W. Eaton <jwe@octave.org>
parents: 15954 16153
diff changeset
3516
0259254a3ccc maint: periodic merge of default to classdef
John W. Eaton <jwe@octave.org>
parents: 15954 16153
diff changeset
3517 tree_classdef_enum_block *
16289
bde729ba8381 maint: periodic merge of default to classdef
John W. Eaton <jwe@octave.org>
parents: 16286 16288
diff changeset
3518 octave_base_parser::make_classdef_enum_block (token *tok_val,
bde729ba8381 maint: periodic merge of default to classdef
John W. Eaton <jwe@octave.org>
parents: 16286 16288
diff changeset
3519 tree_classdef_attribute_list *a,
bde729ba8381 maint: periodic merge of default to classdef
John W. Eaton <jwe@octave.org>
parents: 16286 16288
diff changeset
3520 tree_classdef_enum_list *elist,
bde729ba8381 maint: periodic merge of default to classdef
John W. Eaton <jwe@octave.org>
parents: 16286 16288
diff changeset
3521 token *end_tok,
bde729ba8381 maint: periodic merge of default to classdef
John W. Eaton <jwe@octave.org>
parents: 16286 16288
diff changeset
3522 octave_comment_list *lc)
16155
0259254a3ccc maint: periodic merge of default to classdef
John W. Eaton <jwe@octave.org>
parents: 15954 16153
diff changeset
3523 {
0259254a3ccc maint: periodic merge of default to classdef
John W. Eaton <jwe@octave.org>
parents: 15954 16153
diff changeset
3524 tree_classdef_enum_block *retval = 0;
0259254a3ccc maint: periodic merge of default to classdef
John W. Eaton <jwe@octave.org>
parents: 15954 16153
diff changeset
3525
0259254a3ccc maint: periodic merge of default to classdef
John W. Eaton <jwe@octave.org>
parents: 15954 16153
diff changeset
3526 if (end_token_ok (end_tok, token::enumeration_end))
0259254a3ccc maint: periodic merge of default to classdef
John W. Eaton <jwe@octave.org>
parents: 15954 16153
diff changeset
3527 {
17745
93b3d03b05e7 maint: periodic merge of default to classdef
John W. Eaton <jwe@octave.org>
parents: 17735 17744
diff changeset
3528 octave_comment_list *tc = lexer.comment_buf.get_comment ();
16155
0259254a3ccc maint: periodic merge of default to classdef
John W. Eaton <jwe@octave.org>
parents: 15954 16153
diff changeset
3529
0259254a3ccc maint: periodic merge of default to classdef
John W. Eaton <jwe@octave.org>
parents: 15954 16153
diff changeset
3530 int l = tok_val->line ();
0259254a3ccc maint: periodic merge of default to classdef
John W. Eaton <jwe@octave.org>
parents: 15954 16153
diff changeset
3531 int c = tok_val->column ();
0259254a3ccc maint: periodic merge of default to classdef
John W. Eaton <jwe@octave.org>
parents: 15954 16153
diff changeset
3532
18419
9154dc252f47 Allow empty classdef or methods/properties/... blocks
Michael Goffioul <michael.goffioul@gmail.com>
parents: 18395
diff changeset
3533 if (! elist)
9154dc252f47 Allow empty classdef or methods/properties/... blocks
Michael Goffioul <michael.goffioul@gmail.com>
parents: 18395
diff changeset
3534 elist = new tree_classdef_enum_list ();
9154dc252f47 Allow empty classdef or methods/properties/... blocks
Michael Goffioul <michael.goffioul@gmail.com>
parents: 18395
diff changeset
3535
16155
0259254a3ccc maint: periodic merge of default to classdef
John W. Eaton <jwe@octave.org>
parents: 15954 16153
diff changeset
3536 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>
parents: 15954 16153
diff changeset
3537 }
17656
2b1047efc4fb don't leak memory when parsing classdef objects fails
John W. Eaton <jwe@octave.org>
parents: 17654
diff changeset
3538 else
2b1047efc4fb don't leak memory when parsing classdef objects fails
John W. Eaton <jwe@octave.org>
parents: 17654
diff changeset
3539 {
2b1047efc4fb don't leak memory when parsing classdef objects fails
John W. Eaton <jwe@octave.org>
parents: 17654
diff changeset
3540 delete a;
2b1047efc4fb don't leak memory when parsing classdef objects fails
John W. Eaton <jwe@octave.org>
parents: 17654
diff changeset
3541 delete elist;
21071
f25c14056b7c overhaul parser error handling for end token mismatch
John W. Eaton <jwe@octave.org>
parents: 21066
diff changeset
3542
f25c14056b7c overhaul parser error handling for end token mismatch
John W. Eaton <jwe@octave.org>
parents: 21066
diff changeset
3543 end_token_error (end_tok, token::enumeration_end);
17656
2b1047efc4fb don't leak memory when parsing classdef objects fails
John W. Eaton <jwe@octave.org>
parents: 17654
diff changeset
3544 }
16155
0259254a3ccc maint: periodic merge of default to classdef
John W. Eaton <jwe@octave.org>
parents: 15954 16153
diff changeset
3545
0259254a3ccc maint: periodic merge of default to classdef
John W. Eaton <jwe@octave.org>
parents: 15954 16153
diff changeset
3546 return retval;
2883
0b3954110c77 [project @ 1997-04-24 09:57:05 by jwe]
jwe
parents: 2865
diff changeset
3547 }
0b3954110c77 [project @ 1997-04-24 09:57:05 by jwe]
jwe
parents: 2865
diff changeset
3548
18262
69990d5edcc2 Allow to parse external methods declaration in classdef files.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 18158
diff changeset
3549 octave_user_function*
69990d5edcc2 Allow to parse external methods declaration in classdef files.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 18158
diff changeset
3550 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
3551 tree_parameter_list *pl)
18262
69990d5edcc2 Allow to parse external methods declaration in classdef files.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 18158
diff changeset
3552 {
69990d5edcc2 Allow to parse external methods declaration in classdef files.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 18158
diff changeset
3553 octave_user_function* retval = 0;
69990d5edcc2 Allow to parse external methods declaration in classdef files.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 18158
diff changeset
3554
69990d5edcc2 Allow to parse external methods declaration in classdef files.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 18158
diff changeset
3555 // 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: 18158
diff changeset
3556 // curr_class_name will be non-empty.
69990d5edcc2 Allow to parse external methods declaration in classdef files.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 18158
diff changeset
3557
69990d5edcc2 Allow to parse external methods declaration in classdef files.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 18158
diff changeset
3558 if (! curr_class_name.empty ())
69990d5edcc2 Allow to parse external methods declaration in classdef files.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 18158
diff changeset
3559 {
69990d5edcc2 Allow to parse external methods declaration in classdef files.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 18158
diff changeset
3560
69990d5edcc2 Allow to parse external methods declaration in classdef files.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 18158
diff changeset
3561 std::string mname = id->name ();
69990d5edcc2 Allow to parse external methods declaration in classdef files.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 18158
diff changeset
3562
69990d5edcc2 Allow to parse external methods declaration in classdef files.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 18158
diff changeset
3563 // 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: 18158
diff changeset
3564 // - methods with '.' character (e.g. property accessors)
69990d5edcc2 Allow to parse external methods declaration in classdef files.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 18158
diff changeset
3565 // - class constructor
69990d5edcc2 Allow to parse external methods declaration in classdef files.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 18158
diff changeset
3566 // - `delete'
69990d5edcc2 Allow to parse external methods declaration in classdef files.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 18158
diff changeset
3567
69990d5edcc2 Allow to parse external methods declaration in classdef files.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 18158
diff changeset
3568 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: 18158
diff changeset
3569 && mname != "delete"
69990d5edcc2 Allow to parse external methods declaration in classdef files.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 18158
diff changeset
3570 && mname != curr_class_name)
69990d5edcc2 Allow to parse external methods declaration in classdef files.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 18158
diff changeset
3571 {
69990d5edcc2 Allow to parse external methods declaration in classdef files.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 18158
diff changeset
3572 // 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: 18158
diff changeset
3573 // is loaded.
69990d5edcc2 Allow to parse external methods declaration in classdef files.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 18158
diff changeset
3574
69990d5edcc2 Allow to parse external methods declaration in classdef files.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 18158
diff changeset
3575 retval = new octave_user_function (-1, pl);
69990d5edcc2 Allow to parse external methods declaration in classdef files.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 18158
diff changeset
3576
69990d5edcc2 Allow to parse external methods declaration in classdef files.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 18158
diff changeset
3577 retval->stash_function_name (mname);
69990d5edcc2 Allow to parse external methods declaration in classdef files.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 18158
diff changeset
3578
69990d5edcc2 Allow to parse external methods declaration in classdef files.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 18158
diff changeset
3579 int l = id->line ();
69990d5edcc2 Allow to parse external methods declaration in classdef files.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 18158
diff changeset
3580 int c = id->column ();
69990d5edcc2 Allow to parse external methods declaration in classdef files.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 18158
diff changeset
3581
69990d5edcc2 Allow to parse external methods declaration in classdef files.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 18158
diff changeset
3582 retval->stash_fcn_location (l, c);
69990d5edcc2 Allow to parse external methods declaration in classdef files.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 18158
diff changeset
3583 }
69990d5edcc2 Allow to parse external methods declaration in classdef files.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 18158
diff changeset
3584 else
69990d5edcc2 Allow to parse external methods declaration in classdef files.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 18158
diff changeset
3585 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: 18158
diff changeset
3586 "method cannot be the class constructor, `delete' "
69990d5edcc2 Allow to parse external methods declaration in classdef files.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 18158
diff changeset
3587 "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: 18158
diff changeset
3588 }
69990d5edcc2 Allow to parse external methods declaration in classdef files.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 18158
diff changeset
3589 else
69990d5edcc2 Allow to parse external methods declaration in classdef files.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 18158
diff changeset
3590 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: 18158
diff changeset
3591
69990d5edcc2 Allow to parse external methods declaration in classdef files.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 18158
diff changeset
3592 if (! retval)
69990d5edcc2 Allow to parse external methods declaration in classdef files.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 18158
diff changeset
3593 delete id;
69990d5edcc2 Allow to parse external methods declaration in classdef files.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 18158
diff changeset
3594
69990d5edcc2 Allow to parse external methods declaration in classdef files.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 18158
diff changeset
3595 return retval;
69990d5edcc2 Allow to parse external methods declaration in classdef files.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 18158
diff changeset
3596 }
69990d5edcc2 Allow to parse external methods declaration in classdef files.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 18158
diff changeset
3597
69990d5edcc2 Allow to parse external methods declaration in classdef files.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 18158
diff changeset
3598 tree_function_def *
69990d5edcc2 Allow to parse external methods declaration in classdef files.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 18158
diff changeset
3599 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
3600 tree_parameter_list *ret_list,
18262
69990d5edcc2 Allow to parse external methods declaration in classdef files.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 18158
diff changeset
3601 octave_comment_list *cl)
69990d5edcc2 Allow to parse external methods declaration in classdef files.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 18158
diff changeset
3602 {
69990d5edcc2 Allow to parse external methods declaration in classdef files.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 18158
diff changeset
3603 if (ret_list)
69990d5edcc2 Allow to parse external methods declaration in classdef files.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 18158
diff changeset
3604 fcn->define_ret_list (ret_list);
69990d5edcc2 Allow to parse external methods declaration in classdef files.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 18158
diff changeset
3605
69990d5edcc2 Allow to parse external methods declaration in classdef files.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 18158
diff changeset
3606 if (cl)
69990d5edcc2 Allow to parse external methods declaration in classdef files.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 18158
diff changeset
3607 fcn->stash_leading_comment (cl);
69990d5edcc2 Allow to parse external methods declaration in classdef files.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 18158
diff changeset
3608
69990d5edcc2 Allow to parse external methods declaration in classdef files.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 18158
diff changeset
3609 int l = fcn->beginning_line ();
69990d5edcc2 Allow to parse external methods declaration in classdef files.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 18158
diff changeset
3610 int c = fcn->beginning_column ();
69990d5edcc2 Allow to parse external methods declaration in classdef files.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 18158
diff changeset
3611
69990d5edcc2 Allow to parse external methods declaration in classdef files.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 18158
diff changeset
3612 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: 18158
diff changeset
3613 }
69990d5edcc2 Allow to parse external methods declaration in classdef files.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 18158
diff changeset
3614
2846
52e7c4509983 [project @ 1997-03-26 23:27:35 by jwe]
jwe
parents: 2825
diff changeset
3615 // Make an index expression.
52e7c4509983 [project @ 1997-03-26 23:27:35 by jwe]
jwe
parents: 2825
diff changeset
3616
16134
ec9c6222ef5a move static parser helper functions to octave_parser class
John W. Eaton <jwe@octave.org>
parents: 16133
diff changeset
3617 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
3618 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
3619 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
3620 char type)
751
c9f3cb77478d [project @ 1994-09-30 18:46:17 by jwe]
jwe
parents: 723
diff changeset
3621 {
c9f3cb77478d [project @ 1994-09-30 18:46:17 by jwe]
jwe
parents: 723
diff changeset
3622 tree_index_expression *retval = 0;
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11572
diff changeset
3623
10206
37a08e0ce2dc support Matlab-style empty output/input arguments
Jaroslav Hajek <highegg@gmail.com>
parents: 10188
diff changeset
3624 if (args && args->has_magic_tilde ())
37a08e0ce2dc support Matlab-style empty output/input arguments
Jaroslav Hajek <highegg@gmail.com>
parents: 10188
diff changeset
3625 {
17632
bd0a84de3375 further reduce memory leaks from parse errors (bug #40231)
John W. Eaton <jwe@octave.org>
parents: 17629
diff changeset
3626 delete expr;
bd0a84de3375 further reduce memory leaks from parse errors (bug #40231)
John W. Eaton <jwe@octave.org>
parents: 17629
diff changeset
3627 delete args;
bd0a84de3375 further reduce memory leaks from parse errors (bug #40231)
John W. Eaton <jwe@octave.org>
parents: 17629
diff changeset
3628
21073
f7cc48f601d2 additional reworking of error handling in the parser (bug #46877)
John W. Eaton <jwe@octave.org>
parents: 21071
diff changeset
3629 bison_error ("invalid use of empty argument (~) in index expression");
3933
f9ea3dcf58ee [project @ 2002-05-15 03:21:00 by jwe]
jwe
parents: 3930
diff changeset
3630 }
f9ea3dcf58ee [project @ 2002-05-15 03:21:00 by jwe]
jwe
parents: 3930
diff changeset
3631 else
21073
f7cc48f601d2 additional reworking of error handling in the parser (bug #46877)
John W. Eaton <jwe@octave.org>
parents: 21071
diff changeset
3632 {
f7cc48f601d2 additional reworking of error handling in the parser (bug #46877)
John W. Eaton <jwe@octave.org>
parents: 21071
diff changeset
3633 int l = expr->line ();
f7cc48f601d2 additional reworking of error handling in the parser (bug #46877)
John W. Eaton <jwe@octave.org>
parents: 21071
diff changeset
3634 int c = expr->column ();
f7cc48f601d2 additional reworking of error handling in the parser (bug #46877)
John W. Eaton <jwe@octave.org>
parents: 21071
diff changeset
3635
f7cc48f601d2 additional reworking of error handling in the parser (bug #46877)
John W. Eaton <jwe@octave.org>
parents: 21071
diff changeset
3636 if (! expr->is_postfix_indexed ())
f7cc48f601d2 additional reworking of error handling in the parser (bug #46877)
John W. Eaton <jwe@octave.org>
parents: 21071
diff changeset
3637 expr->set_postfix_index (type);
f7cc48f601d2 additional reworking of error handling in the parser (bug #46877)
John W. Eaton <jwe@octave.org>
parents: 21071
diff changeset
3638
f7cc48f601d2 additional reworking of error handling in the parser (bug #46877)
John W. Eaton <jwe@octave.org>
parents: 21071
diff changeset
3639 if (expr->is_index_expression ())
f7cc48f601d2 additional reworking of error handling in the parser (bug #46877)
John W. Eaton <jwe@octave.org>
parents: 21071
diff changeset
3640 {
f7cc48f601d2 additional reworking of error handling in the parser (bug #46877)
John W. Eaton <jwe@octave.org>
parents: 21071
diff changeset
3641 tree_index_expression *tmp = static_cast<tree_index_expression *> (expr);
f7cc48f601d2 additional reworking of error handling in the parser (bug #46877)
John W. Eaton <jwe@octave.org>
parents: 21071
diff changeset
3642
f7cc48f601d2 additional reworking of error handling in the parser (bug #46877)
John W. Eaton <jwe@octave.org>
parents: 21071
diff changeset
3643 tmp->append (args, type);
f7cc48f601d2 additional reworking of error handling in the parser (bug #46877)
John W. Eaton <jwe@octave.org>
parents: 21071
diff changeset
3644
f7cc48f601d2 additional reworking of error handling in the parser (bug #46877)
John W. Eaton <jwe@octave.org>
parents: 21071
diff changeset
3645 retval = tmp;
f7cc48f601d2 additional reworking of error handling in the parser (bug #46877)
John W. Eaton <jwe@octave.org>
parents: 21071
diff changeset
3646 }
f7cc48f601d2 additional reworking of error handling in the parser (bug #46877)
John W. Eaton <jwe@octave.org>
parents: 21071
diff changeset
3647 else
f7cc48f601d2 additional reworking of error handling in the parser (bug #46877)
John W. Eaton <jwe@octave.org>
parents: 21071
diff changeset
3648 retval = new tree_index_expression (expr, args, l, c, type);
f7cc48f601d2 additional reworking of error handling in the parser (bug #46877)
John W. Eaton <jwe@octave.org>
parents: 21071
diff changeset
3649 }
2970
b9e64477f703 [project @ 1997-05-15 18:04:21 by jwe]
jwe
parents: 2961
diff changeset
3650
b9e64477f703 [project @ 1997-05-15 18:04:21 by jwe]
jwe
parents: 2961
diff changeset
3651 return retval;
b9e64477f703 [project @ 1997-05-15 18:04:21 by jwe]
jwe
parents: 2961
diff changeset
3652 }
b9e64477f703 [project @ 1997-05-15 18:04:21 by jwe]
jwe
parents: 2961
diff changeset
3653
b9e64477f703 [project @ 1997-05-15 18:04:21 by jwe]
jwe
parents: 2961
diff changeset
3654 // Make an indirect reference expression.
b9e64477f703 [project @ 1997-05-15 18:04:21 by jwe]
jwe
parents: 2961
diff changeset
3655
16134
ec9c6222ef5a move static parser helper functions to octave_parser class
John W. Eaton <jwe@octave.org>
parents: 16133
diff changeset
3656 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
3657 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
3658 const std::string& elt)
2970
b9e64477f703 [project @ 1997-05-15 18:04:21 by jwe]
jwe
parents: 2961
diff changeset
3659 {
3930
61d4427c016e [project @ 2002-05-07 00:47:31 by jwe]
jwe
parents: 3929
diff changeset
3660 tree_index_expression *retval = 0;
2970
b9e64477f703 [project @ 1997-05-15 18:04:21 by jwe]
jwe
parents: 2961
diff changeset
3661
b9e64477f703 [project @ 1997-05-15 18:04:21 by jwe]
jwe
parents: 2961
diff changeset
3662 int l = expr->line ();
b9e64477f703 [project @ 1997-05-15 18:04:21 by jwe]
jwe
parents: 2961
diff changeset
3663 int c = expr->column ();
b9e64477f703 [project @ 1997-05-15 18:04:21 by jwe]
jwe
parents: 2961
diff changeset
3664
19597
db92e7e28e1f strip trailing whitespace from most source files
John W. Eaton <jwe@octave.org>
parents: 19596
diff changeset
3665 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
3666 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
3667
3933
f9ea3dcf58ee [project @ 2002-05-15 03:21:00 by jwe]
jwe
parents: 3930
diff changeset
3668 if (expr->is_index_expression ())
f9ea3dcf58ee [project @ 2002-05-15 03:21:00 by jwe]
jwe
parents: 3930
diff changeset
3669 {
f9ea3dcf58ee [project @ 2002-05-15 03:21:00 by jwe]
jwe
parents: 3930
diff changeset
3670 tree_index_expression *tmp = static_cast<tree_index_expression *> (expr);
f9ea3dcf58ee [project @ 2002-05-15 03:21:00 by jwe]
jwe
parents: 3930
diff changeset
3671
f9ea3dcf58ee [project @ 2002-05-15 03:21:00 by jwe]
jwe
parents: 3930
diff changeset
3672 tmp->append (elt);
f9ea3dcf58ee [project @ 2002-05-15 03:21:00 by jwe]
jwe
parents: 3930
diff changeset
3673
f9ea3dcf58ee [project @ 2002-05-15 03:21:00 by jwe]
jwe
parents: 3930
diff changeset
3674 retval = tmp;
f9ea3dcf58ee [project @ 2002-05-15 03:21:00 by jwe]
jwe
parents: 3930
diff changeset
3675 }
f9ea3dcf58ee [project @ 2002-05-15 03:21:00 by jwe]
jwe
parents: 3930
diff changeset
3676 else
f9ea3dcf58ee [project @ 2002-05-15 03:21:00 by jwe]
jwe
parents: 3930
diff changeset
3677 retval = new tree_index_expression (expr, elt, l, c);
2970
b9e64477f703 [project @ 1997-05-15 18:04:21 by jwe]
jwe
parents: 2961
diff changeset
3678
16288
fe3b9a51e625 rename curr_lexer, curr_parser, CURR_LEXER
John W. Eaton <jwe@octave.org>
parents: 16287
diff changeset
3679 lexer.looking_at_indirect_ref = false;
751
c9f3cb77478d [project @ 1994-09-30 18:46:17 by jwe]
jwe
parents: 723
diff changeset
3680
c9f3cb77478d [project @ 1994-09-30 18:46:17 by jwe]
jwe
parents: 723
diff changeset
3681 return retval;
c9f3cb77478d [project @ 1994-09-30 18:46:17 by jwe]
jwe
parents: 723
diff changeset
3682 }
1511
74f9e88a2c12 [project @ 1995-10-03 10:49:31 by jwe]
jwe
parents: 1491
diff changeset
3683
4131
597fbc55ea40 [project @ 2002-10-29 17:12:53 by jwe]
jwe
parents: 4064
diff changeset
3684 // Make an indirect reference expression with dynamic field name.
597fbc55ea40 [project @ 2002-10-29 17:12:53 by jwe]
jwe
parents: 4064
diff changeset
3685
16134
ec9c6222ef5a move static parser helper functions to octave_parser class
John W. Eaton <jwe@octave.org>
parents: 16133
diff changeset
3686 tree_index_expression *
16289
bde729ba8381 maint: periodic merge of default to classdef
John W. Eaton <jwe@octave.org>
parents: 16286 16288
diff changeset
3687 octave_base_parser::make_indirect_ref (tree_expression *expr,
bde729ba8381 maint: periodic merge of default to classdef
John W. Eaton <jwe@octave.org>
parents: 16286 16288
diff changeset
3688 tree_expression *elt)
4131
597fbc55ea40 [project @ 2002-10-29 17:12:53 by jwe]
jwe
parents: 4064
diff changeset
3689 {
597fbc55ea40 [project @ 2002-10-29 17:12:53 by jwe]
jwe
parents: 4064
diff changeset
3690 tree_index_expression *retval = 0;
597fbc55ea40 [project @ 2002-10-29 17:12:53 by jwe]
jwe
parents: 4064
diff changeset
3691
597fbc55ea40 [project @ 2002-10-29 17:12:53 by jwe]
jwe
parents: 4064
diff changeset
3692 int l = expr->line ();
597fbc55ea40 [project @ 2002-10-29 17:12:53 by jwe]
jwe
parents: 4064
diff changeset
3693 int c = expr->column ();
597fbc55ea40 [project @ 2002-10-29 17:12:53 by jwe]
jwe
parents: 4064
diff changeset
3694
19597
db92e7e28e1f strip trailing whitespace from most source files
John W. Eaton <jwe@octave.org>
parents: 19596
diff changeset
3695 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
3696 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
3697
4131
597fbc55ea40 [project @ 2002-10-29 17:12:53 by jwe]
jwe
parents: 4064
diff changeset
3698 if (expr->is_index_expression ())
597fbc55ea40 [project @ 2002-10-29 17:12:53 by jwe]
jwe
parents: 4064
diff changeset
3699 {
597fbc55ea40 [project @ 2002-10-29 17:12:53 by jwe]
jwe
parents: 4064
diff changeset
3700 tree_index_expression *tmp = static_cast<tree_index_expression *> (expr);
597fbc55ea40 [project @ 2002-10-29 17:12:53 by jwe]
jwe
parents: 4064
diff changeset
3701
597fbc55ea40 [project @ 2002-10-29 17:12:53 by jwe]
jwe
parents: 4064
diff changeset
3702 tmp->append (elt);
597fbc55ea40 [project @ 2002-10-29 17:12:53 by jwe]
jwe
parents: 4064
diff changeset
3703
597fbc55ea40 [project @ 2002-10-29 17:12:53 by jwe]
jwe
parents: 4064
diff changeset
3704 retval = tmp;
597fbc55ea40 [project @ 2002-10-29 17:12:53 by jwe]
jwe
parents: 4064
diff changeset
3705 }
597fbc55ea40 [project @ 2002-10-29 17:12:53 by jwe]
jwe
parents: 4064
diff changeset
3706 else
597fbc55ea40 [project @ 2002-10-29 17:12:53 by jwe]
jwe
parents: 4064
diff changeset
3707 retval = new tree_index_expression (expr, elt, l, c);
597fbc55ea40 [project @ 2002-10-29 17:12:53 by jwe]
jwe
parents: 4064
diff changeset
3708
16288
fe3b9a51e625 rename curr_lexer, curr_parser, CURR_LEXER
John W. Eaton <jwe@octave.org>
parents: 16287
diff changeset
3709 lexer.looking_at_indirect_ref = false;
4131
597fbc55ea40 [project @ 2002-10-29 17:12:53 by jwe]
jwe
parents: 4064
diff changeset
3710
597fbc55ea40 [project @ 2002-10-29 17:12:53 by jwe]
jwe
parents: 4064
diff changeset
3711 return retval;
597fbc55ea40 [project @ 2002-10-29 17:12:53 by jwe]
jwe
parents: 4064
diff changeset
3712 }
597fbc55ea40 [project @ 2002-10-29 17:12:53 by jwe]
jwe
parents: 4064
diff changeset
3713
2846
52e7c4509983 [project @ 1997-03-26 23:27:35 by jwe]
jwe
parents: 2825
diff changeset
3714 // Make a declaration command.
52e7c4509983 [project @ 1997-03-26 23:27:35 by jwe]
jwe
parents: 2825
diff changeset
3715
16134
ec9c6222ef5a move static parser helper functions to octave_parser class
John W. Eaton <jwe@octave.org>
parents: 16133
diff changeset
3716 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
3717 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
3718 tree_decl_init_list *lst)
2846
52e7c4509983 [project @ 1997-03-26 23:27:35 by jwe]
jwe
parents: 2825
diff changeset
3719 {
52e7c4509983 [project @ 1997-03-26 23:27:35 by jwe]
jwe
parents: 2825
diff changeset
3720 tree_decl_command *retval = 0;
52e7c4509983 [project @ 1997-03-26 23:27:35 by jwe]
jwe
parents: 2825
diff changeset
3721
52e7c4509983 [project @ 1997-03-26 23:27:35 by jwe]
jwe
parents: 2825
diff changeset
3722 int l = tok_val->line ();
52e7c4509983 [project @ 1997-03-26 23:27:35 by jwe]
jwe
parents: 2825
diff changeset
3723 int c = tok_val->column ();
52e7c4509983 [project @ 1997-03-26 23:27:35 by jwe]
jwe
parents: 2825
diff changeset
3724
52e7c4509983 [project @ 1997-03-26 23:27:35 by jwe]
jwe
parents: 2825
diff changeset
3725 switch (tok)
52e7c4509983 [project @ 1997-03-26 23:27:35 by jwe]
jwe
parents: 2825
diff changeset
3726 {
52e7c4509983 [project @ 1997-03-26 23:27:35 by jwe]
jwe
parents: 2825
diff changeset
3727 case GLOBAL:
52e7c4509983 [project @ 1997-03-26 23:27:35 by jwe]
jwe
parents: 2825
diff changeset
3728 retval = new tree_global_command (lst, l, c);
52e7c4509983 [project @ 1997-03-26 23:27:35 by jwe]
jwe
parents: 2825
diff changeset
3729 break;
52e7c4509983 [project @ 1997-03-26 23:27:35 by jwe]
jwe
parents: 2825
diff changeset
3730
14294
9e3983c8963c deprecate the static keyword
John W. Eaton <jwe@octave.org>
parents: 14293
diff changeset
3731 case PERSISTENT:
16153
a57c2c8c8163 move some variables into the octave_parser class
John W. Eaton <jwe@octave.org>
parents: 16151
diff changeset
3732 if (curr_fcn_depth > 0)
14294
9e3983c8963c deprecate the static keyword
John W. Eaton <jwe@octave.org>
parents: 14293
diff changeset
3733 retval = new tree_persistent_command (lst, l, c);
2846
52e7c4509983 [project @ 1997-03-26 23:27:35 by jwe]
jwe
parents: 2825
diff changeset
3734 else
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
3735 {
16288
fe3b9a51e625 rename curr_lexer, curr_parser, CURR_LEXER
John W. Eaton <jwe@octave.org>
parents: 16287
diff changeset
3736 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
3737 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
3738 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
3739 else
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
3740 warning ("ignoring persistent declaration near line %d", l);
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
3741 }
2846
52e7c4509983 [project @ 1997-03-26 23:27:35 by jwe]
jwe
parents: 2825
diff changeset
3742 break;
52e7c4509983 [project @ 1997-03-26 23:27:35 by jwe]
jwe
parents: 2825
diff changeset
3743
52e7c4509983 [project @ 1997-03-26 23:27:35 by jwe]
jwe
parents: 2825
diff changeset
3744 default:
52e7c4509983 [project @ 1997-03-26 23:27:35 by jwe]
jwe
parents: 2825
diff changeset
3745 panic_impossible ();
52e7c4509983 [project @ 1997-03-26 23:27:35 by jwe]
jwe
parents: 2825
diff changeset
3746 break;
52e7c4509983 [project @ 1997-03-26 23:27:35 by jwe]
jwe
parents: 2825
diff changeset
3747 }
52e7c4509983 [project @ 1997-03-26 23:27:35 by jwe]
jwe
parents: 2825
diff changeset
3748
52e7c4509983 [project @ 1997-03-26 23:27:35 by jwe]
jwe
parents: 2825
diff changeset
3749 return retval;
52e7c4509983 [project @ 1997-03-26 23:27:35 by jwe]
jwe
parents: 2825
diff changeset
3750 }
52e7c4509983 [project @ 1997-03-26 23:27:35 by jwe]
jwe
parents: 2825
diff changeset
3751
16273
c5e5f6ccac5d 9/10 commits reworking the lexer
John W. Eaton <jwe@octave.org>
parents: 16265
diff changeset
3752 bool
16287
04a7953496a7 create base class for parser; use reference for curr_lexer
John W. Eaton <jwe@octave.org>
parents: 16285
diff changeset
3753 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
3754 {
c5e5f6ccac5d 9/10 commits reworking the lexer
John W. Eaton <jwe@octave.org>
parents: 16265
diff changeset
3755 bool retval = true;
c5e5f6ccac5d 9/10 commits reworking the lexer
John W. Eaton <jwe@octave.org>
parents: 16265
diff changeset
3756
c5e5f6ccac5d 9/10 commits reworking the lexer
John W. Eaton <jwe@octave.org>
parents: 16265
diff changeset
3757 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
3758
c5e5f6ccac5d 9/10 commits reworking the lexer
John W. Eaton <jwe@octave.org>
parents: 16265
diff changeset
3759 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
3760 {
c5e5f6ccac5d 9/10 commits reworking the lexer
John W. Eaton <jwe@octave.org>
parents: 16265
diff changeset
3761 tree_argument_list *row = *i;
c5e5f6ccac5d 9/10 commits reworking the lexer
John W. Eaton <jwe@octave.org>
parents: 16265
diff changeset
3762
c5e5f6ccac5d 9/10 commits reworking the lexer
John W. Eaton <jwe@octave.org>
parents: 16265
diff changeset
3763 if (row && row->has_magic_tilde ())
c5e5f6ccac5d 9/10 commits reworking the lexer
John W. Eaton <jwe@octave.org>
parents: 16265
diff changeset
3764 {
c5e5f6ccac5d 9/10 commits reworking the lexer
John W. Eaton <jwe@octave.org>
parents: 16265
diff changeset
3765 retval = false;
21073
f7cc48f601d2 additional reworking of error handling in the parser (bug #46877)
John W. Eaton <jwe@octave.org>
parents: 21071
diff changeset
3766
16273
c5e5f6ccac5d 9/10 commits reworking the lexer
John W. Eaton <jwe@octave.org>
parents: 16265
diff changeset
3767 if (e->is_matrix ())
21055
5e00ed38a58b maint: Replace if/error/else paradigm with just if/error.
Rik <rik@octave.org>
parents: 21023
diff changeset
3768 bison_error ("invalid use of tilde (~) in matrix expression");
5e00ed38a58b maint: Replace if/error/else paradigm with just if/error.
Rik <rik@octave.org>
parents: 21023
diff changeset
3769 else
5e00ed38a58b maint: Replace if/error/else paradigm with just if/error.
Rik <rik@octave.org>
parents: 21023
diff changeset
3770 bison_error ("invalid use of tilde (~) in cell expression");
21073
f7cc48f601d2 additional reworking of error handling in the parser (bug #46877)
John W. Eaton <jwe@octave.org>
parents: 21071
diff changeset
3771
16273
c5e5f6ccac5d 9/10 commits reworking the lexer
John W. Eaton <jwe@octave.org>
parents: 16265
diff changeset
3772 break;
c5e5f6ccac5d 9/10 commits reworking the lexer
John W. Eaton <jwe@octave.org>
parents: 16265
diff changeset
3773 }
c5e5f6ccac5d 9/10 commits reworking the lexer
John W. Eaton <jwe@octave.org>
parents: 16265
diff changeset
3774 }
c5e5f6ccac5d 9/10 commits reworking the lexer
John W. Eaton <jwe@octave.org>
parents: 16265
diff changeset
3775
c5e5f6ccac5d 9/10 commits reworking the lexer
John W. Eaton <jwe@octave.org>
parents: 16265
diff changeset
3776 return retval;
c5e5f6ccac5d 9/10 commits reworking the lexer
John W. Eaton <jwe@octave.org>
parents: 16265
diff changeset
3777 }
c5e5f6ccac5d 9/10 commits reworking the lexer
John W. Eaton <jwe@octave.org>
parents: 16265
diff changeset
3778
16134
ec9c6222ef5a move static parser helper functions to octave_parser class
John W. Eaton <jwe@octave.org>
parents: 16133
diff changeset
3779 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
3780 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
3781 {
16273
c5e5f6ccac5d 9/10 commits reworking the lexer
John W. Eaton <jwe@octave.org>
parents: 16265
diff changeset
3782 tree_argument_list *retval = 0;
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 if (e->is_constant ())
c5e5f6ccac5d 9/10 commits reworking the lexer
John W. Eaton <jwe@octave.org>
parents: 16265
diff changeset
3785 {
16285
3389152014ca improve validation of left hand side of assignment expressions in parser
John W. Eaton <jwe@octave.org>
parents: 16284
diff changeset
3786 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
3787
21073
f7cc48f601d2 additional reworking of error handling in the parser (bug #46877)
John W. Eaton <jwe@octave.org>
parents: 21071
diff changeset
3788 delete e;
f7cc48f601d2 additional reworking of error handling in the parser (bug #46877)
John W. Eaton <jwe@octave.org>
parents: 21071
diff changeset
3789
16285
3389152014ca improve validation of left hand side of assignment expressions in parser
John W. Eaton <jwe@octave.org>
parents: 16284
diff changeset
3790 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
3791 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
3792 else
3389152014ca improve validation of left hand side of assignment expressions in parser
John W. Eaton <jwe@octave.org>
parents: 16284
diff changeset
3793 bison_error ("invalid constant left hand side of assignment");
16273
c5e5f6ccac5d 9/10 commits reworking the lexer
John W. Eaton <jwe@octave.org>
parents: 16265
diff changeset
3794 }
c5e5f6ccac5d 9/10 commits reworking the lexer
John W. Eaton <jwe@octave.org>
parents: 16265
diff changeset
3795 else
c5e5f6ccac5d 9/10 commits reworking the lexer
John W. Eaton <jwe@octave.org>
parents: 16265
diff changeset
3796 {
16285
3389152014ca improve validation of left hand side of assignment expressions in parser
John W. Eaton <jwe@octave.org>
parents: 16284
diff changeset
3797 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
3798
3389152014ca improve validation of left hand side of assignment expressions in parser
John W. Eaton <jwe@octave.org>
parents: 16284
diff changeset
3799 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
3800
3389152014ca improve validation of left hand side of assignment expressions in parser
John W. Eaton <jwe@octave.org>
parents: 16284
diff changeset
3801 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
3802 {
3389152014ca improve validation of left hand side of assignment expressions in parser
John W. Eaton <jwe@octave.org>
parents: 16284
diff changeset
3803 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
3804
3389152014ca improve validation of left hand side of assignment expressions in parser
John W. Eaton <jwe@octave.org>
parents: 16284
diff changeset
3805 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
3806 {
3389152014ca improve validation of left hand side of assignment expressions in parser
John W. Eaton <jwe@octave.org>
parents: 16284
diff changeset
3807 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
3808 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
3809 delete e;
3389152014ca improve validation of left hand side of assignment expressions in parser
John W. Eaton <jwe@octave.org>
parents: 16284
diff changeset
3810 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
3811 }
3389152014ca improve validation of left hand side of assignment expressions in parser
John W. Eaton <jwe@octave.org>
parents: 16284
diff changeset
3812 }
3389152014ca improve validation of left hand side of assignment expressions in parser
John W. Eaton <jwe@octave.org>
parents: 16284
diff changeset
3813 else
3389152014ca improve validation of left hand side of assignment expressions in parser
John W. Eaton <jwe@octave.org>
parents: 16284
diff changeset
3814 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
3815
3389152014ca improve validation of left hand side of assignment expressions in parser
John W. Eaton <jwe@octave.org>
parents: 16284
diff changeset
3816 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
3817 {
11115c237231 recognize variables when parsing (bug #38576)
John W. Eaton <jwe@octave.org>
parents: 16320
diff changeset
3818 lexer.mark_as_variables (tmp->variable_names ());
11115c237231 recognize variables when parsing (bug #38576)
John W. Eaton <jwe@octave.org>
parents: 16320
diff changeset
3819 retval = tmp;
11115c237231 recognize variables when parsing (bug #38576)
John W. Eaton <jwe@octave.org>
parents: 16320
diff changeset
3820 }
16285
3389152014ca improve validation of left hand side of assignment expressions in parser
John W. Eaton <jwe@octave.org>
parents: 16284
diff changeset
3821 else
3389152014ca improve validation of left hand side of assignment expressions in parser
John W. Eaton <jwe@octave.org>
parents: 16284
diff changeset
3822 {
21073
f7cc48f601d2 additional reworking of error handling in the parser (bug #46877)
John W. Eaton <jwe@octave.org>
parents: 21071
diff changeset
3823 delete tmp;
f7cc48f601d2 additional reworking of error handling in the parser (bug #46877)
John W. Eaton <jwe@octave.org>
parents: 21071
diff changeset
3824
16285
3389152014ca improve validation of left hand side of assignment expressions in parser
John W. Eaton <jwe@octave.org>
parents: 16284
diff changeset
3825 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
3826 }
3389152014ca improve validation of left hand side of assignment expressions in parser
John W. Eaton <jwe@octave.org>
parents: 16284
diff changeset
3827
3389152014ca improve validation of left hand side of assignment expressions in parser
John W. Eaton <jwe@octave.org>
parents: 16284
diff changeset
3828 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
3829 retval->mark_as_simple_assign_lhs ();
16273
c5e5f6ccac5d 9/10 commits reworking the lexer
John W. Eaton <jwe@octave.org>
parents: 16265
diff changeset
3830 }
c5e5f6ccac5d 9/10 commits reworking the lexer
John W. Eaton <jwe@octave.org>
parents: 16265
diff changeset
3831
c5e5f6ccac5d 9/10 commits reworking the lexer
John W. Eaton <jwe@octave.org>
parents: 16265
diff changeset
3832 return retval;
10207
76a880a588ce error when using ~ in matrix expression
Jaroslav Hajek <highegg@gmail.com>
parents: 10206
diff changeset
3833 }
76a880a588ce error when using ~ in matrix expression
Jaroslav Hajek <highegg@gmail.com>
parents: 10206
diff changeset
3834
16237
70f465930546 rearrange class heirarchy for tree_cell and tree_matrix
John W. Eaton <jwe@octave.org>
parents: 16210
diff changeset
3835 // Finish building an array_list.
1623
fa7a847f9b92 [project @ 1995-11-06 18:05:09 by jwe]
jwe
parents: 1607
diff changeset
3836
16134
ec9c6222ef5a move static parser helper functions to octave_parser class
John W. Eaton <jwe@octave.org>
parents: 16133
diff changeset
3837 tree_expression *
16287
04a7953496a7 create base class for parser; use reference for curr_lexer
John W. Eaton <jwe@octave.org>
parents: 16285
diff changeset
3838 octave_base_parser::finish_array_list (tree_array_list *array_list)
1623
fa7a847f9b92 [project @ 1995-11-06 18:05:09 by jwe]
jwe
parents: 1607
diff changeset
3839 {
16237
70f465930546 rearrange class heirarchy for tree_cell and tree_matrix
John W. Eaton <jwe@octave.org>
parents: 16210
diff changeset
3840 tree_expression *retval = array_list;
3110
fe2d1ae8926b [project @ 1997-11-21 02:11:19 by jwe]
jwe
parents: 3099
diff changeset
3841
10067
6f79338c269b omission from last patch
Jaroslav Hajek <highegg@gmail.com>
parents: 9794
diff changeset
3842 unwind_protect frame;
6f79338c269b omission from last patch
Jaroslav Hajek <highegg@gmail.com>
parents: 9794
diff changeset
3843
6f79338c269b omission from last patch
Jaroslav Hajek <highegg@gmail.com>
parents: 9794
diff changeset
3844 frame.protect_var (discard_error_messages);
6f79338c269b omission from last patch
Jaroslav Hajek <highegg@gmail.com>
parents: 9794
diff changeset
3845 frame.protect_var (discard_warning_messages);
4452
f3c21a1d1c62 [project @ 2003-07-09 23:20:18 by jwe]
jwe
parents: 4426
diff changeset
3846
3815
c554ad71bafc [project @ 2001-04-19 19:50:52 by jwe]
jwe
parents: 3802
diff changeset
3847 discard_error_messages = true;
4452
f3c21a1d1c62 [project @ 2003-07-09 23:20:18 by jwe]
jwe
parents: 4426
diff changeset
3848 discard_warning_messages = true;
1623
fa7a847f9b92 [project @ 1995-11-06 18:05:09 by jwe]
jwe
parents: 1607
diff changeset
3849
16237
70f465930546 rearrange class heirarchy for tree_cell and tree_matrix
John W. Eaton <jwe@octave.org>
parents: 16210
diff changeset
3850 if (array_list->all_elements_are_constant ())
1829
7d2982b55242 [project @ 1996-02-02 14:12:59 by jwe]
jwe
parents: 1826
diff changeset
3851 {
20769
58e79b0078e4 handle exceptions when discarding error messages (bug #46534)
John W. Eaton <jwe@octave.org>
parents: 20756
diff changeset
3852 try
58e79b0078e4 handle exceptions when discarding error messages (bug #46534)
John W. Eaton <jwe@octave.org>
parents: 20756
diff changeset
3853 {
58e79b0078e4 handle exceptions when discarding error messages (bug #46534)
John W. Eaton <jwe@octave.org>
parents: 20756
diff changeset
3854 octave_value tmp = array_list->rvalue1 ();
58e79b0078e4 handle exceptions when discarding error messages (bug #46534)
John W. Eaton <jwe@octave.org>
parents: 20756
diff changeset
3855
58e79b0078e4 handle exceptions when discarding error messages (bug #46534)
John W. Eaton <jwe@octave.org>
parents: 20756
diff changeset
3856 tree_constant *tc_retval
58e79b0078e4 handle exceptions when discarding error messages (bug #46534)
John W. Eaton <jwe@octave.org>
parents: 20756
diff changeset
3857 = new tree_constant (tmp, array_list->line (),
58e79b0078e4 handle exceptions when discarding error messages (bug #46534)
John W. Eaton <jwe@octave.org>
parents: 20756
diff changeset
3858 array_list->column ());
58e79b0078e4 handle exceptions when discarding error messages (bug #46534)
John W. Eaton <jwe@octave.org>
parents: 20756
diff changeset
3859
58e79b0078e4 handle exceptions when discarding error messages (bug #46534)
John W. Eaton <jwe@octave.org>
parents: 20756
diff changeset
3860 std::ostringstream buf;
58e79b0078e4 handle exceptions when discarding error messages (bug #46534)
John W. Eaton <jwe@octave.org>
parents: 20756
diff changeset
3861
58e79b0078e4 handle exceptions when discarding error messages (bug #46534)
John W. Eaton <jwe@octave.org>
parents: 20756
diff changeset
3862 tree_print_code tpc (buf);
58e79b0078e4 handle exceptions when discarding error messages (bug #46534)
John W. Eaton <jwe@octave.org>
parents: 20756
diff changeset
3863
58e79b0078e4 handle exceptions when discarding error messages (bug #46534)
John W. Eaton <jwe@octave.org>
parents: 20756
diff changeset
3864 array_list->accept (tpc);
58e79b0078e4 handle exceptions when discarding error messages (bug #46534)
John W. Eaton <jwe@octave.org>
parents: 20756
diff changeset
3865
58e79b0078e4 handle exceptions when discarding error messages (bug #46534)
John W. Eaton <jwe@octave.org>
parents: 20756
diff changeset
3866 tc_retval->stash_original_text (buf.str ());
58e79b0078e4 handle exceptions when discarding error messages (bug #46534)
John W. Eaton <jwe@octave.org>
parents: 20756
diff changeset
3867
58e79b0078e4 handle exceptions when discarding error messages (bug #46534)
John W. Eaton <jwe@octave.org>
parents: 20756
diff changeset
3868 delete array_list;
58e79b0078e4 handle exceptions when discarding error messages (bug #46534)
John W. Eaton <jwe@octave.org>
parents: 20756
diff changeset
3869
58e79b0078e4 handle exceptions when discarding error messages (bug #46534)
John W. Eaton <jwe@octave.org>
parents: 20756
diff changeset
3870 retval = tc_retval;
58e79b0078e4 handle exceptions when discarding error messages (bug #46534)
John W. Eaton <jwe@octave.org>
parents: 20756
diff changeset
3871 }
58e79b0078e4 handle exceptions when discarding error messages (bug #46534)
John W. Eaton <jwe@octave.org>
parents: 20756
diff changeset
3872 catch (const octave_execution_exception&)
58e79b0078e4 handle exceptions when discarding error messages (bug #46534)
John W. Eaton <jwe@octave.org>
parents: 20756
diff changeset
3873 {
58e79b0078e4 handle exceptions when discarding error messages (bug #46534)
John W. Eaton <jwe@octave.org>
parents: 20756
diff changeset
3874 recover_from_exception ();
58e79b0078e4 handle exceptions when discarding error messages (bug #46534)
John W. Eaton <jwe@octave.org>
parents: 20756
diff changeset
3875 }
1623
fa7a847f9b92 [project @ 1995-11-06 18:05:09 by jwe]
jwe
parents: 1607
diff changeset
3876 }
3110
fe2d1ae8926b [project @ 1997-11-21 02:11:19 by jwe]
jwe
parents: 3099
diff changeset
3877
1623
fa7a847f9b92 [project @ 1995-11-06 18:05:09 by jwe]
jwe
parents: 1607
diff changeset
3878 return retval;
fa7a847f9b92 [project @ 1995-11-06 18:05:09 by jwe]
jwe
parents: 1607
diff changeset
3879 }
fa7a847f9b92 [project @ 1995-11-06 18:05:09 by jwe]
jwe
parents: 1607
diff changeset
3880
16237
70f465930546 rearrange class heirarchy for tree_cell and tree_matrix
John W. Eaton <jwe@octave.org>
parents: 16210
diff changeset
3881 // 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
3882
70f465930546 rearrange class heirarchy for tree_cell and tree_matrix
John W. Eaton <jwe@octave.org>
parents: 16210
diff changeset
3883 tree_expression *
16287
04a7953496a7 create base class for parser; use reference for curr_lexer
John W. Eaton <jwe@octave.org>
parents: 16285
diff changeset
3884 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
3885 {
16924
aebb54d99dba improve compatibility of parsing of matrices and cell arrays
John W. Eaton <jwe@octave.org>
parents: 16850
diff changeset
3886 return (m
aebb54d99dba improve compatibility of parsing of matrices and cell arrays
John W. Eaton <jwe@octave.org>
parents: 16850
diff changeset
3887 ? finish_array_list (m)
aebb54d99dba improve compatibility of parsing of matrices and cell arrays
John W. Eaton <jwe@octave.org>
parents: 16850
diff changeset
3888 : 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
3889 }
70f465930546 rearrange class heirarchy for tree_cell and tree_matrix
John W. Eaton <jwe@octave.org>
parents: 16210
diff changeset
3890
3351
8623649c967c [project @ 1999-11-15 16:17:01 by jwe]
jwe
parents: 3347
diff changeset
3891 // Finish building a cell list.
8623649c967c [project @ 1999-11-15 16:17:01 by jwe]
jwe
parents: 3347
diff changeset
3892
16134
ec9c6222ef5a move static parser helper functions to octave_parser class
John W. Eaton <jwe@octave.org>
parents: 16133
diff changeset
3893 tree_expression *
16287
04a7953496a7 create base class for parser; use reference for curr_lexer
John W. Eaton <jwe@octave.org>
parents: 16285
diff changeset
3894 octave_base_parser::finish_cell (tree_cell *c)
3351
8623649c967c [project @ 1999-11-15 16:17:01 by jwe]
jwe
parents: 3347
diff changeset
3895 {
16924
aebb54d99dba improve compatibility of parsing of matrices and cell arrays
John W. Eaton <jwe@octave.org>
parents: 16850
diff changeset
3896 return (c
aebb54d99dba improve compatibility of parsing of matrices and cell arrays
John W. Eaton <jwe@octave.org>
parents: 16850
diff changeset
3897 ? finish_array_list (c)
aebb54d99dba improve compatibility of parsing of matrices and cell arrays
John W. Eaton <jwe@octave.org>
parents: 16850
diff changeset
3898 : new tree_constant (octave_value (Cell ())));
3351
8623649c967c [project @ 1999-11-15 16:17:01 by jwe]
jwe
parents: 3347
diff changeset
3899 }
8623649c967c [project @ 1999-11-15 16:17:01 by jwe]
jwe
parents: 3347
diff changeset
3900
16134
ec9c6222ef5a move static parser helper functions to octave_parser class
John W. Eaton <jwe@octave.org>
parents: 16133
diff changeset
3901 void
16287
04a7953496a7 create base class for parser; use reference for curr_lexer
John W. Eaton <jwe@octave.org>
parents: 16285
diff changeset
3902 octave_base_parser::maybe_warn_missing_semi (tree_statement_list *t)
1511
74f9e88a2c12 [project @ 1995-10-03 10:49:31 by jwe]
jwe
parents: 1491
diff changeset
3903 {
16153
a57c2c8c8163 move some variables into the octave_parser class
John W. Eaton <jwe@octave.org>
parents: 16151
diff changeset
3904 if (curr_fcn_depth > 0)
1511
74f9e88a2c12 [project @ 1995-10-03 10:49:31 by jwe]
jwe
parents: 1491
diff changeset
3905 {
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
3906 tree_statement *tmp = t->back ();
1607
795527e9db19 [project @ 1995-11-02 13:03:36 by jwe]
jwe
parents: 1588
diff changeset
3907
1511
74f9e88a2c12 [project @ 1995-10-03 10:49:31 by jwe]
jwe
parents: 1491
diff changeset
3908 if (tmp->is_expression ())
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
3909 warning_with_id
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
3910 ("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
3911 "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
3912 tmp->line (), tmp->column (), lexer.fcn_file_full_name.c_str ());
1511
74f9e88a2c12 [project @ 1995-10-03 10:49:31 by jwe]
jwe
parents: 1491
diff changeset
3913 }
74f9e88a2c12 [project @ 1995-10-03 10:49:31 by jwe]
jwe
parents: 1491
diff changeset
3914 }
1994
c2d20f365b84 [project @ 1996-03-03 01:19:32 by jwe]
jwe
parents: 1884
diff changeset
3915
16134
ec9c6222ef5a move static parser helper functions to octave_parser class
John W. Eaton <jwe@octave.org>
parents: 16133
diff changeset
3916 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
3917 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
3918 char sep, bool warn_missing_semi)
2525
8561d88be5f2 [project @ 1996-11-17 21:23:31 by jwe]
jwe
parents: 2524
diff changeset
3919 {
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
3920 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
3921
2525
8561d88be5f2 [project @ 1996-11-17 21:23:31 by jwe]
jwe
parents: 2524
diff changeset
3922 switch (sep)
8561d88be5f2 [project @ 1996-11-17 21:23:31 by jwe]
jwe
parents: 2524
diff changeset
3923 {
8561d88be5f2 [project @ 1996-11-17 21:23:31 by jwe]
jwe
parents: 2524
diff changeset
3924 case ';':
8658
73c4516fae10 New evaluator and debugger derived from tree-walker class
John W. Eaton <jwe@octave.org>
parents: 8471
diff changeset
3925 tmp->set_print_flag (false);
2525
8561d88be5f2 [project @ 1996-11-17 21:23:31 by jwe]
jwe
parents: 2524
diff changeset
3926 break;
8561d88be5f2 [project @ 1996-11-17 21:23:31 by jwe]
jwe
parents: 2524
diff changeset
3927
8561d88be5f2 [project @ 1996-11-17 21:23:31 by jwe]
jwe
parents: 2524
diff changeset
3928 case 0:
8561d88be5f2 [project @ 1996-11-17 21:23:31 by jwe]
jwe
parents: 2524
diff changeset
3929 case ',':
8561d88be5f2 [project @ 1996-11-17 21:23:31 by jwe]
jwe
parents: 2524
diff changeset
3930 case '\n':
8658
73c4516fae10 New evaluator and debugger derived from tree-walker class
John W. Eaton <jwe@octave.org>
parents: 8471
diff changeset
3931 tmp->set_print_flag (true);
2525
8561d88be5f2 [project @ 1996-11-17 21:23:31 by jwe]
jwe
parents: 2524
diff changeset
3932 if (warn_missing_semi)
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
3933 maybe_warn_missing_semi (list);
2525
8561d88be5f2 [project @ 1996-11-17 21:23:31 by jwe]
jwe
parents: 2524
diff changeset
3934 break;
8561d88be5f2 [project @ 1996-11-17 21:23:31 by jwe]
jwe
parents: 2524
diff changeset
3935
8561d88be5f2 [project @ 1996-11-17 21:23:31 by jwe]
jwe
parents: 2524
diff changeset
3936 default:
8561d88be5f2 [project @ 1996-11-17 21:23:31 by jwe]
jwe
parents: 2524
diff changeset
3937 warning ("unrecognized separator type!");
8561d88be5f2 [project @ 1996-11-17 21:23:31 by jwe]
jwe
parents: 2524
diff changeset
3938 break;
8561d88be5f2 [project @ 1996-11-17 21:23:31 by jwe]
jwe
parents: 2524
diff changeset
3939 }
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
3940
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
3941 // 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
3942 // 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
3943
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
3944 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
3945 {
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
3946 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
3947 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
3948 }
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
3949
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
3950 return list;
2525
8561d88be5f2 [project @ 1996-11-17 21:23:31 by jwe]
jwe
parents: 2524
diff changeset
3951 }
8561d88be5f2 [project @ 1996-11-17 21:23:31 by jwe]
jwe
parents: 2524
diff changeset
3952
17693
efbe746f8fa8 eliminate octave_comment_buffer singleton
John W. Eaton <jwe@octave.org>
parents: 17673
diff changeset
3953 // Finish building a statement.
21139
538b57866b90 consistently use "typename" intead of "class" in template declarations
John W. Eaton <jwe@octave.org>
parents: 21075
diff changeset
3954 template <typename T>
17693
efbe746f8fa8 eliminate octave_comment_buffer singleton
John W. Eaton <jwe@octave.org>
parents: 17673
diff changeset
3955 tree_statement *
efbe746f8fa8 eliminate octave_comment_buffer singleton
John W. Eaton <jwe@octave.org>
parents: 17673
diff changeset
3956 octave_base_parser::make_statement (T *arg)
efbe746f8fa8 eliminate octave_comment_buffer singleton
John W. Eaton <jwe@octave.org>
parents: 17673
diff changeset
3957 {
efbe746f8fa8 eliminate octave_comment_buffer singleton
John W. Eaton <jwe@octave.org>
parents: 17673
diff changeset
3958 octave_comment_list *comment = lexer.get_comment ();
efbe746f8fa8 eliminate octave_comment_buffer singleton
John W. Eaton <jwe@octave.org>
parents: 17673
diff changeset
3959
efbe746f8fa8 eliminate octave_comment_buffer singleton
John W. Eaton <jwe@octave.org>
parents: 17673
diff changeset
3960 return new tree_statement (arg, comment);
efbe746f8fa8 eliminate octave_comment_buffer singleton
John W. Eaton <jwe@octave.org>
parents: 17673
diff changeset
3961 }
efbe746f8fa8 eliminate octave_comment_buffer singleton
John W. Eaton <jwe@octave.org>
parents: 17673
diff changeset
3962
16134
ec9c6222ef5a move static parser helper functions to octave_parser class
John W. Eaton <jwe@octave.org>
parents: 16133
diff changeset
3963 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
3964 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
3965 {
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
3966 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
3967 }
d6c0d5f208de parse.y: avoid storing null statements in statement lists
John W. Eaton <jwe@octave.org>
parents: 8447
diff changeset
3968
16134
ec9c6222ef5a move static parser helper functions to octave_parser class
John W. Eaton <jwe@octave.org>
parents: 16133
diff changeset
3969 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
3970 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
3971 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
3972 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
3973 {
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
3974 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
3975
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
3976 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
3977
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
3978 return list;
8448
d6c0d5f208de parse.y: avoid storing null statements in statement lists
John W. Eaton <jwe@octave.org>
parents: 8447
diff changeset
3979 }
d6c0d5f208de parse.y: avoid storing null statements in statement lists
John W. Eaton <jwe@octave.org>
parents: 8447
diff changeset
3980
16145
edddf8903f15 maint: reorder functions in oct-parse.yy
John W. Eaton <jwe@octave.org>
parents: 16142
diff changeset
3981 void
21065
e1ee2203efe0 allow location info to be passed to octave_base_parser::bison_error
John W. Eaton <jwe@octave.org>
parents: 21064
diff changeset
3982 octave_base_parser::bison_error (const std::string& str, int l, int c)
16145
edddf8903f15 maint: reorder functions in oct-parse.yy
John W. Eaton <jwe@octave.org>
parents: 16142
diff changeset
3983 {
21065
e1ee2203efe0 allow location info to be passed to octave_base_parser::bison_error
John W. Eaton <jwe@octave.org>
parents: 21064
diff changeset
3984 int err_line = l < 0 ? lexer.input_line_number : l;
e1ee2203efe0 allow location info to be passed to octave_base_parser::bison_error
John W. Eaton <jwe@octave.org>
parents: 21064
diff changeset
3985 int err_col = c < 0 ? lexer.current_input_column - 1 : c;
16145
edddf8903f15 maint: reorder functions in oct-parse.yy
John W. Eaton <jwe@octave.org>
parents: 16142
diff changeset
3986
edddf8903f15 maint: reorder functions in oct-parse.yy
John W. Eaton <jwe@octave.org>
parents: 16142
diff changeset
3987 std::ostringstream output_buf;
edddf8903f15 maint: reorder functions in oct-parse.yy
John W. Eaton <jwe@octave.org>
parents: 16142
diff changeset
3988
16288
fe3b9a51e625 rename curr_lexer, curr_parser, CURR_LEXER
John W. Eaton <jwe@octave.org>
parents: 16287
diff changeset
3989 if (lexer.reading_fcn_file || lexer.reading_script_file || lexer.reading_classdef_file)
21065
e1ee2203efe0 allow location info to be passed to octave_base_parser::bison_error
John W. Eaton <jwe@octave.org>
parents: 21064
diff changeset
3990 output_buf << "parse error near line " << err_line
16288
fe3b9a51e625 rename curr_lexer, curr_parser, CURR_LEXER
John W. Eaton <jwe@octave.org>
parents: 16287
diff changeset
3991 << " 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
3992 else
edddf8903f15 maint: reorder functions in oct-parse.yy
John W. Eaton <jwe@octave.org>
parents: 16142
diff changeset
3993 output_buf << "parse error:";
edddf8903f15 maint: reorder functions in oct-parse.yy
John W. Eaton <jwe@octave.org>
parents: 16142
diff changeset
3994
21065
e1ee2203efe0 allow location info to be passed to octave_base_parser::bison_error
John W. Eaton <jwe@octave.org>
parents: 21064
diff changeset
3995 if (str != "parse error")
e1ee2203efe0 allow location info to be passed to octave_base_parser::bison_error
John W. Eaton <jwe@octave.org>
parents: 21064
diff changeset
3996 output_buf << "\n\n " << str;
16145
edddf8903f15 maint: reorder functions in oct-parse.yy
John W. Eaton <jwe@octave.org>
parents: 16142
diff changeset
3997
edddf8903f15 maint: reorder functions in oct-parse.yy
John W. Eaton <jwe@octave.org>
parents: 16142
diff changeset
3998 output_buf << "\n\n";
edddf8903f15 maint: reorder functions in oct-parse.yy
John W. Eaton <jwe@octave.org>
parents: 16142
diff changeset
3999
16288
fe3b9a51e625 rename curr_lexer, curr_parser, CURR_LEXER
John W. Eaton <jwe@octave.org>
parents: 16287
diff changeset
4000 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
4001
0467d68ca891 move current_input_line to lexical_feedback class
John W. Eaton <jwe@octave.org>
parents: 16203
diff changeset
4002 if (! curr_line.empty ())
16145
edddf8903f15 maint: reorder functions in oct-parse.yy
John W. Eaton <jwe@octave.org>
parents: 16142
diff changeset
4003 {
16207
0467d68ca891 move current_input_line to lexical_feedback class
John W. Eaton <jwe@octave.org>
parents: 16203
diff changeset
4004 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
4005
0467d68ca891 move current_input_line to lexical_feedback class
John W. Eaton <jwe@octave.org>
parents: 16203
diff changeset
4006 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
4007 curr_line.resize (len-1);
16145
edddf8903f15 maint: reorder functions in oct-parse.yy
John W. Eaton <jwe@octave.org>
parents: 16142
diff changeset
4008
edddf8903f15 maint: reorder functions in oct-parse.yy
John W. Eaton <jwe@octave.org>
parents: 16142
diff changeset
4009 // 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
4010
16207
0467d68ca891 move current_input_line to lexical_feedback class
John W. Eaton <jwe@octave.org>
parents: 16203
diff changeset
4011 output_buf << ">>> " << curr_line << "\n";
16145
edddf8903f15 maint: reorder functions in oct-parse.yy
John W. Eaton <jwe@octave.org>
parents: 16142
diff changeset
4012
edddf8903f15 maint: reorder functions in oct-parse.yy
John W. Eaton <jwe@octave.org>
parents: 16142
diff changeset
4013 if (err_col == 0)
edddf8903f15 maint: reorder functions in oct-parse.yy
John W. Eaton <jwe@octave.org>
parents: 16142
diff changeset
4014 err_col = len;
edddf8903f15 maint: reorder functions in oct-parse.yy
John W. Eaton <jwe@octave.org>
parents: 16142
diff changeset
4015
edddf8903f15 maint: reorder functions in oct-parse.yy
John W. Eaton <jwe@octave.org>
parents: 16142
diff changeset
4016 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
4017 output_buf << " ";
edddf8903f15 maint: reorder functions in oct-parse.yy
John W. Eaton <jwe@octave.org>
parents: 16142
diff changeset
4018
edddf8903f15 maint: reorder functions in oct-parse.yy
John W. Eaton <jwe@octave.org>
parents: 16142
diff changeset
4019 output_buf << "^";
edddf8903f15 maint: reorder functions in oct-parse.yy
John W. Eaton <jwe@octave.org>
parents: 16142
diff changeset
4020 }
edddf8903f15 maint: reorder functions in oct-parse.yy
John W. Eaton <jwe@octave.org>
parents: 16142
diff changeset
4021
edddf8903f15 maint: reorder functions in oct-parse.yy
John W. Eaton <jwe@octave.org>
parents: 16142
diff changeset
4022 output_buf << "\n";
edddf8903f15 maint: reorder functions in oct-parse.yy
John W. Eaton <jwe@octave.org>
parents: 16142
diff changeset
4023
21073
f7cc48f601d2 additional reworking of error handling in the parser (bug #46877)
John W. Eaton <jwe@octave.org>
parents: 21071
diff changeset
4024 parse_error_msg = output_buf.str ();
16145
edddf8903f15 maint: reorder functions in oct-parse.yy
John W. Eaton <jwe@octave.org>
parents: 16142
diff changeset
4025 }
edddf8903f15 maint: reorder functions in oct-parse.yy
John W. Eaton <jwe@octave.org>
parents: 16142
diff changeset
4026
21361
9ca194f7a858 disallow assignment to "end" in indexed assignments (bug #46459)
John W. Eaton <jwe@octave.org>
parents: 21317
diff changeset
4027 bool
9ca194f7a858 disallow assignment to "end" in indexed assignments (bug #46459)
John W. Eaton <jwe@octave.org>
parents: 21317
diff changeset
4028 octave_base_parser::valid_id_for_assignment (const std::string& s)
9ca194f7a858 disallow assignment to "end" in indexed assignments (bug #46459)
John W. Eaton <jwe@octave.org>
parents: 21317
diff changeset
4029 {
9ca194f7a858 disallow assignment to "end" in indexed assignments (bug #46459)
John W. Eaton <jwe@octave.org>
parents: 21317
diff changeset
4030 // is_keyword will return true for some identfiers that are only
9ca194f7a858 disallow assignment to "end" in indexed assignments (bug #46459)
John W. Eaton <jwe@octave.org>
parents: 21317
diff changeset
4031 // keywords in certain contexts.
9ca194f7a858 disallow assignment to "end" in indexed assignments (bug #46459)
John W. Eaton <jwe@octave.org>
parents: 21317
diff changeset
4032
9ca194f7a858 disallow assignment to "end" in indexed assignments (bug #46459)
John W. Eaton <jwe@octave.org>
parents: 21317
diff changeset
4033 return (! is_keyword (s)
9ca194f7a858 disallow assignment to "end" in indexed assignments (bug #46459)
John W. Eaton <jwe@octave.org>
parents: 21317
diff changeset
4034 || (! lexer.parsing_classdef
9ca194f7a858 disallow assignment to "end" in indexed assignments (bug #46459)
John W. Eaton <jwe@octave.org>
parents: 21317
diff changeset
4035 && (s == "enumeration" || s == "events"
9ca194f7a858 disallow assignment to "end" in indexed assignments (bug #46459)
John W. Eaton <jwe@octave.org>
parents: 21317
diff changeset
4036 || s == "methods" || s == "properties")));
9ca194f7a858 disallow assignment to "end" in indexed assignments (bug #46459)
John W. Eaton <jwe@octave.org>
parents: 21317
diff changeset
4037 }
9ca194f7a858 disallow assignment to "end" in indexed assignments (bug #46459)
John W. Eaton <jwe@octave.org>
parents: 21317
diff changeset
4038
16287
04a7953496a7 create base class for parser; use reference for curr_lexer
John W. Eaton <jwe@octave.org>
parents: 16285
diff changeset
4039 int
04a7953496a7 create base class for parser; use reference for curr_lexer
John W. Eaton <jwe@octave.org>
parents: 16285
diff changeset
4040 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
4041 {
21073
f7cc48f601d2 additional reworking of error handling in the parser (bug #46877)
John W. Eaton <jwe@octave.org>
parents: 21071
diff changeset
4042 int status = -1;
f7cc48f601d2 additional reworking of error handling in the parser (bug #46877)
John W. Eaton <jwe@octave.org>
parents: 21071
diff changeset
4043
f7cc48f601d2 additional reworking of error handling in the parser (bug #46877)
John W. Eaton <jwe@octave.org>
parents: 21071
diff changeset
4044 yypstate *pstate = static_cast<yypstate *> (parser_state);
f7cc48f601d2 additional reworking of error handling in the parser (bug #46877)
John W. Eaton <jwe@octave.org>
parents: 21071
diff changeset
4045
f7cc48f601d2 additional reworking of error handling in the parser (bug #46877)
John W. Eaton <jwe@octave.org>
parents: 21071
diff changeset
4046 try
f7cc48f601d2 additional reworking of error handling in the parser (bug #46877)
John W. Eaton <jwe@octave.org>
parents: 21071
diff changeset
4047 {
f7cc48f601d2 additional reworking of error handling in the parser (bug #46877)
John W. Eaton <jwe@octave.org>
parents: 21071
diff changeset
4048 status = octave_pull_parse (pstate, *this);
f7cc48f601d2 additional reworking of error handling in the parser (bug #46877)
John W. Eaton <jwe@octave.org>
parents: 21071
diff changeset
4049 }
f7cc48f601d2 additional reworking of error handling in the parser (bug #46877)
John W. Eaton <jwe@octave.org>
parents: 21071
diff changeset
4050 catch (octave_execution_exception& e)
f7cc48f601d2 additional reworking of error handling in the parser (bug #46877)
John W. Eaton <jwe@octave.org>
parents: 21071
diff changeset
4051 {
f7cc48f601d2 additional reworking of error handling in the parser (bug #46877)
John W. Eaton <jwe@octave.org>
parents: 21071
diff changeset
4052 std::string file = lexer.fcn_file_full_name;
f7cc48f601d2 additional reworking of error handling in the parser (bug #46877)
John W. Eaton <jwe@octave.org>
parents: 21071
diff changeset
4053
f7cc48f601d2 additional reworking of error handling in the parser (bug #46877)
John W. Eaton <jwe@octave.org>
parents: 21071
diff changeset
4054 if (file.empty ())
f7cc48f601d2 additional reworking of error handling in the parser (bug #46877)
John W. Eaton <jwe@octave.org>
parents: 21071
diff changeset
4055 error (e, "parse error");
f7cc48f601d2 additional reworking of error handling in the parser (bug #46877)
John W. Eaton <jwe@octave.org>
parents: 21071
diff changeset
4056 else
f7cc48f601d2 additional reworking of error handling in the parser (bug #46877)
John W. Eaton <jwe@octave.org>
parents: 21071
diff changeset
4057 error (e, "parse error in %s", file.c_str ());
f7cc48f601d2 additional reworking of error handling in the parser (bug #46877)
John W. Eaton <jwe@octave.org>
parents: 21071
diff changeset
4058 }
21159
4aa8e4b868c9 Handle interrupt thrown by dbquit (bug #46931)
Lachlan Andrew <lachlanbis@gmail.com>
parents: 21139
diff changeset
4059 catch (octave_interrupt_exception &)
4aa8e4b868c9 Handle interrupt thrown by dbquit (bug #46931)
Lachlan Andrew <lachlanbis@gmail.com>
parents: 21139
diff changeset
4060 {
4aa8e4b868c9 Handle interrupt thrown by dbquit (bug #46931)
Lachlan Andrew <lachlanbis@gmail.com>
parents: 21139
diff changeset
4061 throw;
4aa8e4b868c9 Handle interrupt thrown by dbquit (bug #46931)
Lachlan Andrew <lachlanbis@gmail.com>
parents: 21139
diff changeset
4062 }
21073
f7cc48f601d2 additional reworking of error handling in the parser (bug #46877)
John W. Eaton <jwe@octave.org>
parents: 21071
diff changeset
4063 catch (...)
f7cc48f601d2 additional reworking of error handling in the parser (bug #46877)
John W. Eaton <jwe@octave.org>
parents: 21071
diff changeset
4064 {
f7cc48f601d2 additional reworking of error handling in the parser (bug #46877)
John W. Eaton <jwe@octave.org>
parents: 21071
diff changeset
4065 std::string file = lexer.fcn_file_full_name;
f7cc48f601d2 additional reworking of error handling in the parser (bug #46877)
John W. Eaton <jwe@octave.org>
parents: 21071
diff changeset
4066
f7cc48f601d2 additional reworking of error handling in the parser (bug #46877)
John W. Eaton <jwe@octave.org>
parents: 21071
diff changeset
4067 if (file.empty ())
f7cc48f601d2 additional reworking of error handling in the parser (bug #46877)
John W. Eaton <jwe@octave.org>
parents: 21071
diff changeset
4068 error ("unexpected exception while parsing input");
f7cc48f601d2 additional reworking of error handling in the parser (bug #46877)
John W. Eaton <jwe@octave.org>
parents: 21071
diff changeset
4069 else
f7cc48f601d2 additional reworking of error handling in the parser (bug #46877)
John W. Eaton <jwe@octave.org>
parents: 21071
diff changeset
4070 error ("unexpected exception while parsing %s", file.c_str ());
f7cc48f601d2 additional reworking of error handling in the parser (bug #46877)
John W. Eaton <jwe@octave.org>
parents: 21071
diff changeset
4071 }
f7cc48f601d2 additional reworking of error handling in the parser (bug #46877)
John W. Eaton <jwe@octave.org>
parents: 21071
diff changeset
4072
f7cc48f601d2 additional reworking of error handling in the parser (bug #46877)
John W. Eaton <jwe@octave.org>
parents: 21071
diff changeset
4073 if (status != 0)
f7cc48f601d2 additional reworking of error handling in the parser (bug #46877)
John W. Eaton <jwe@octave.org>
parents: 21071
diff changeset
4074 parse_error ("%s", parse_error_msg.c_str ());
f7cc48f601d2 additional reworking of error handling in the parser (bug #46877)
John W. Eaton <jwe@octave.org>
parents: 21071
diff changeset
4075
f7cc48f601d2 additional reworking of error handling in the parser (bug #46877)
John W. Eaton <jwe@octave.org>
parents: 21071
diff changeset
4076 return status;
16287
04a7953496a7 create base class for parser; use reference for curr_lexer
John W. Eaton <jwe@octave.org>
parents: 16285
diff changeset
4077 }
04a7953496a7 create base class for parser; use reference for curr_lexer
John W. Eaton <jwe@octave.org>
parents: 16285
diff changeset
4078
16294
0925d1f6875e push parser/lexer interface
John W. Eaton <jwe@octave.org>
parents: 16293
diff changeset
4079 // 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
4080 // finish the parse.
0925d1f6875e push parser/lexer interface
John W. Eaton <jwe@octave.org>
parents: 16293
diff changeset
4081
0925d1f6875e push parser/lexer interface
John W. Eaton <jwe@octave.org>
parents: 16293
diff changeset
4082 int
0925d1f6875e push parser/lexer interface
John W. Eaton <jwe@octave.org>
parents: 16293
diff changeset
4083 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
4084 {
0925d1f6875e push parser/lexer interface
John W. Eaton <jwe@octave.org>
parents: 16293
diff changeset
4085 int status = -1;
0925d1f6875e push parser/lexer interface
John W. Eaton <jwe@octave.org>
parents: 16293
diff changeset
4086
0925d1f6875e push parser/lexer interface
John W. Eaton <jwe@octave.org>
parents: 16293
diff changeset
4087 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
4088
0925d1f6875e push parser/lexer interface
John W. Eaton <jwe@octave.org>
parents: 16293
diff changeset
4089 do
19593
446c46af4b42 strip trailing whitespace from most source files
John W. Eaton <jwe@octave.org>
parents: 18974
diff changeset
4090 {
16294
0925d1f6875e push parser/lexer interface
John W. Eaton <jwe@octave.org>
parents: 16293
diff changeset
4091 YYSTYPE lval;
0925d1f6875e push parser/lexer interface
John W. Eaton <jwe@octave.org>
parents: 16293
diff changeset
4092
0925d1f6875e push parser/lexer interface
John W. Eaton <jwe@octave.org>
parents: 16293
diff changeset
4093 int token = octave_lex (&lval, scanner);
0925d1f6875e push parser/lexer interface
John W. Eaton <jwe@octave.org>
parents: 16293
diff changeset
4094
0925d1f6875e push parser/lexer interface
John W. Eaton <jwe@octave.org>
parents: 16293
diff changeset
4095 if (token < 0)
0925d1f6875e push parser/lexer interface
John W. Eaton <jwe@octave.org>
parents: 16293
diff changeset
4096 {
0925d1f6875e push parser/lexer interface
John W. Eaton <jwe@octave.org>
parents: 16293
diff changeset
4097 if (! eof && lexer.at_end_of_buffer ())
0925d1f6875e push parser/lexer interface
John W. Eaton <jwe@octave.org>
parents: 16293
diff changeset
4098 {
0925d1f6875e push parser/lexer interface
John W. Eaton <jwe@octave.org>
parents: 16293
diff changeset
4099 status = -1;
0925d1f6875e push parser/lexer interface
John W. Eaton <jwe@octave.org>
parents: 16293
diff changeset
4100 break;
0925d1f6875e push parser/lexer interface
John W. Eaton <jwe@octave.org>
parents: 16293
diff changeset
4101 }
0925d1f6875e push parser/lexer interface
John W. Eaton <jwe@octave.org>
parents: 16293
diff changeset
4102 }
0925d1f6875e push parser/lexer interface
John W. Eaton <jwe@octave.org>
parents: 16293
diff changeset
4103
0925d1f6875e push parser/lexer interface
John W. Eaton <jwe@octave.org>
parents: 16293
diff changeset
4104 yypstate *pstate = static_cast<yypstate *> (parser_state);
0925d1f6875e push parser/lexer interface
John W. Eaton <jwe@octave.org>
parents: 16293
diff changeset
4105
21073
f7cc48f601d2 additional reworking of error handling in the parser (bug #46877)
John W. Eaton <jwe@octave.org>
parents: 21071
diff changeset
4106 try
f7cc48f601d2 additional reworking of error handling in the parser (bug #46877)
John W. Eaton <jwe@octave.org>
parents: 21071
diff changeset
4107 {
f7cc48f601d2 additional reworking of error handling in the parser (bug #46877)
John W. Eaton <jwe@octave.org>
parents: 21071
diff changeset
4108 status = octave_push_parse (pstate, token, &lval, *this);
f7cc48f601d2 additional reworking of error handling in the parser (bug #46877)
John W. Eaton <jwe@octave.org>
parents: 21071
diff changeset
4109 }
f7cc48f601d2 additional reworking of error handling in the parser (bug #46877)
John W. Eaton <jwe@octave.org>
parents: 21071
diff changeset
4110 catch (octave_execution_exception& e)
f7cc48f601d2 additional reworking of error handling in the parser (bug #46877)
John W. Eaton <jwe@octave.org>
parents: 21071
diff changeset
4111 {
f7cc48f601d2 additional reworking of error handling in the parser (bug #46877)
John W. Eaton <jwe@octave.org>
parents: 21071
diff changeset
4112 std::string file = lexer.fcn_file_full_name;
f7cc48f601d2 additional reworking of error handling in the parser (bug #46877)
John W. Eaton <jwe@octave.org>
parents: 21071
diff changeset
4113
f7cc48f601d2 additional reworking of error handling in the parser (bug #46877)
John W. Eaton <jwe@octave.org>
parents: 21071
diff changeset
4114 if (file.empty ())
f7cc48f601d2 additional reworking of error handling in the parser (bug #46877)
John W. Eaton <jwe@octave.org>
parents: 21071
diff changeset
4115 error (e, "parse error");
f7cc48f601d2 additional reworking of error handling in the parser (bug #46877)
John W. Eaton <jwe@octave.org>
parents: 21071
diff changeset
4116 else
f7cc48f601d2 additional reworking of error handling in the parser (bug #46877)
John W. Eaton <jwe@octave.org>
parents: 21071
diff changeset
4117 error (e, "parse error in %s", file.c_str ());
f7cc48f601d2 additional reworking of error handling in the parser (bug #46877)
John W. Eaton <jwe@octave.org>
parents: 21071
diff changeset
4118 }
21159
4aa8e4b868c9 Handle interrupt thrown by dbquit (bug #46931)
Lachlan Andrew <lachlanbis@gmail.com>
parents: 21139
diff changeset
4119 catch (octave_interrupt_exception &)
4aa8e4b868c9 Handle interrupt thrown by dbquit (bug #46931)
Lachlan Andrew <lachlanbis@gmail.com>
parents: 21139
diff changeset
4120 {
4aa8e4b868c9 Handle interrupt thrown by dbquit (bug #46931)
Lachlan Andrew <lachlanbis@gmail.com>
parents: 21139
diff changeset
4121 throw;
4aa8e4b868c9 Handle interrupt thrown by dbquit (bug #46931)
Lachlan Andrew <lachlanbis@gmail.com>
parents: 21139
diff changeset
4122 }
21073
f7cc48f601d2 additional reworking of error handling in the parser (bug #46877)
John W. Eaton <jwe@octave.org>
parents: 21071
diff changeset
4123 catch (...)
f7cc48f601d2 additional reworking of error handling in the parser (bug #46877)
John W. Eaton <jwe@octave.org>
parents: 21071
diff changeset
4124 {
f7cc48f601d2 additional reworking of error handling in the parser (bug #46877)
John W. Eaton <jwe@octave.org>
parents: 21071
diff changeset
4125 std::string file = lexer.fcn_file_full_name;
f7cc48f601d2 additional reworking of error handling in the parser (bug #46877)
John W. Eaton <jwe@octave.org>
parents: 21071
diff changeset
4126
f7cc48f601d2 additional reworking of error handling in the parser (bug #46877)
John W. Eaton <jwe@octave.org>
parents: 21071
diff changeset
4127 if (file.empty ())
f7cc48f601d2 additional reworking of error handling in the parser (bug #46877)
John W. Eaton <jwe@octave.org>
parents: 21071
diff changeset
4128 error ("unexpected exception while parsing input");
f7cc48f601d2 additional reworking of error handling in the parser (bug #46877)
John W. Eaton <jwe@octave.org>
parents: 21071
diff changeset
4129 else
f7cc48f601d2 additional reworking of error handling in the parser (bug #46877)
John W. Eaton <jwe@octave.org>
parents: 21071
diff changeset
4130 error ("unexpected exception while parsing %s", file.c_str ());
f7cc48f601d2 additional reworking of error handling in the parser (bug #46877)
John W. Eaton <jwe@octave.org>
parents: 21071
diff changeset
4131 }
16294
0925d1f6875e push parser/lexer interface
John W. Eaton <jwe@octave.org>
parents: 16293
diff changeset
4132 }
0925d1f6875e push parser/lexer interface
John W. Eaton <jwe@octave.org>
parents: 16293
diff changeset
4133 while (status == YYPUSH_MORE);
0925d1f6875e push parser/lexer interface
John W. Eaton <jwe@octave.org>
parents: 16293
diff changeset
4134
21073
f7cc48f601d2 additional reworking of error handling in the parser (bug #46877)
John W. Eaton <jwe@octave.org>
parents: 21071
diff changeset
4135 if (status != 0)
f7cc48f601d2 additional reworking of error handling in the parser (bug #46877)
John W. Eaton <jwe@octave.org>
parents: 21071
diff changeset
4136 parse_error ("%s", parse_error_msg.c_str ());
f7cc48f601d2 additional reworking of error handling in the parser (bug #46877)
John W. Eaton <jwe@octave.org>
parents: 21071
diff changeset
4137
16294
0925d1f6875e push parser/lexer interface
John W. Eaton <jwe@octave.org>
parents: 16293
diff changeset
4138 return status;
0925d1f6875e push parser/lexer interface
John W. Eaton <jwe@octave.org>
parents: 16293
diff changeset
4139 }
0925d1f6875e push parser/lexer interface
John W. Eaton <jwe@octave.org>
parents: 16293
diff changeset
4140
3021
18d64612e67a [project @ 1997-06-03 22:18:56 by jwe]
jwe
parents: 3016
diff changeset
4141 static void
10067
6f79338c269b omission from last patch
Jaroslav Hajek <highegg@gmail.com>
parents: 9794
diff changeset
4142 safe_fclose (FILE *f)
3021
18d64612e67a [project @ 1997-06-03 22:18:56 by jwe]
jwe
parents: 3016
diff changeset
4143 {
18d64612e67a [project @ 1997-06-03 22:18:56 by jwe]
jwe
parents: 3016
diff changeset
4144 if (f)
18d64612e67a [project @ 1997-06-03 22:18:56 by jwe]
jwe
parents: 3016
diff changeset
4145 fclose (static_cast<FILE *> (f));
18d64612e67a [project @ 1997-06-03 22:18:56 by jwe]
jwe
parents: 3016
diff changeset
4146 }
18d64612e67a [project @ 1997-06-03 22:18:56 by jwe]
jwe
parents: 3016
diff changeset
4147
7336
745a8299c2b5 [project @ 2007-12-28 20:56:55 by jwe]
jwe
parents: 7017
diff changeset
4148 static octave_function *
16203
127cccb037bf move more global parser and lexer variables to classes
John W. Eaton <jwe@octave.org>
parents: 16199
diff changeset
4149 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
4150 const std::string& dispatch_type,
16676
7368654f302f Initial support for (classdef) packages.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 16644
diff changeset
4151 const std::string& package_name,
19593
446c46af4b42 strip trailing whitespace from most source files
John W. Eaton <jwe@octave.org>
parents: 18974
diff changeset
4152 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
4153 bool relative_lookup, const std::string& warn_for)
3021
18d64612e67a [project @ 1997-06-03 22:18:56 by jwe]
jwe
parents: 3016
diff changeset
4154 {
10067
6f79338c269b omission from last patch
Jaroslav Hajek <highegg@gmail.com>
parents: 9794
diff changeset
4155 unwind_protect frame;
3021
18d64612e67a [project @ 1997-06-03 22:18:56 by jwe]
jwe
parents: 3016
diff changeset
4156
7336
745a8299c2b5 [project @ 2007-12-28 20:56:55 by jwe]
jwe
parents: 7017
diff changeset
4157 octave_function *fcn_ptr = 0;
3021
18d64612e67a [project @ 1997-06-03 22:18:56 by jwe]
jwe
parents: 3016
diff changeset
4158
18d64612e67a [project @ 1997-06-03 22:18:56 by jwe]
jwe
parents: 3016
diff changeset
4159 // Open function file and parse.
18d64612e67a [project @ 1997-06-03 22:18:56 by jwe]
jwe
parents: 3016
diff changeset
4160
18d64612e67a [project @ 1997-06-03 22:18:56 by jwe]
jwe
parents: 3016
diff changeset
4161 FILE *in_stream = command_editor::get_input_stream ();
18d64612e67a [project @ 1997-06-03 22:18:56 by jwe]
jwe
parents: 3016
diff changeset
4162
10067
6f79338c269b omission from last patch
Jaroslav Hajek <highegg@gmail.com>
parents: 9794
diff changeset
4163 frame.add_fcn (command_editor::set_input_stream, in_stream);
6f79338c269b omission from last patch
Jaroslav Hajek <highegg@gmail.com>
parents: 9794
diff changeset
4164
12989
00235a6446da eliminate duplication of internal variables controlling command history
John W. Eaton <jwe@octave.org>
parents: 12973
diff changeset
4165 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
4166 command_history::ignoring_entries ());
00235a6446da eliminate duplication of internal variables controlling command history
John W. Eaton <jwe@octave.org>
parents: 12973
diff changeset
4167
7715
5b4d278ec828 parse scripts completely before executing
John W. Eaton <jwe@octave.org>
parents: 7699
diff changeset
4168 command_history::ignore_entries ();
5b4d278ec828 parse scripts completely before executing
John W. Eaton <jwe@octave.org>
parents: 7699
diff changeset
4169
16198
2c5c538be353 clean up input.cc and eliminate ff_instream global variable
John W. Eaton <jwe@octave.org>
parents: 16195
diff changeset
4170 FILE *ffile = 0;
2c5c538be353 clean up input.cc and eliminate ff_instream global variable
John W. Eaton <jwe@octave.org>
parents: 16195
diff changeset
4171
16203
127cccb037bf move more global parser and lexer variables to classes
John W. Eaton <jwe@octave.org>
parents: 16199
diff changeset
4172 if (! full_file.empty ())
127cccb037bf move more global parser and lexer variables to classes
John W. Eaton <jwe@octave.org>
parents: 16199
diff changeset
4173 ffile = gnulib::fopen (full_file.c_str (), "rb");
3021
18d64612e67a [project @ 1997-06-03 22:18:56 by jwe]
jwe
parents: 3016
diff changeset
4174
18d64612e67a [project @ 1997-06-03 22:18:56 by jwe]
jwe
parents: 3016
diff changeset
4175 if (ffile)
18d64612e67a [project @ 1997-06-03 22:18:56 by jwe]
jwe
parents: 3016
diff changeset
4176 {
19709
5cfb3ccbf24a style fixes for resource management
John W. Eaton <jwe@octave.org>
parents: 19697
diff changeset
4177 frame.add_fcn (safe_fclose, ffile);
5cfb3ccbf24a style fixes for resource management
John W. Eaton <jwe@octave.org>
parents: 19697
diff changeset
4178
16287
04a7953496a7 create base class for parser; use reference for curr_lexer
John W. Eaton <jwe@octave.org>
parents: 16285
diff changeset
4179 // 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
4180 frame.protect_var (LEXER);
fe3b9a51e625 rename curr_lexer, curr_parser, CURR_LEXER
John W. Eaton <jwe@octave.org>
parents: 16287
diff changeset
4181
fe3b9a51e625 rename curr_lexer, curr_parser, CURR_LEXER
John W. Eaton <jwe@octave.org>
parents: 16287
diff changeset
4182 octave_parser parser (ffile);
fe3b9a51e625 rename curr_lexer, curr_parser, CURR_LEXER
John W. Eaton <jwe@octave.org>
parents: 16287
diff changeset
4183
fe3b9a51e625 rename curr_lexer, curr_parser, CURR_LEXER
John W. Eaton <jwe@octave.org>
parents: 16287
diff changeset
4184 parser.curr_class_name = dispatch_type;
16676
7368654f302f Initial support for (classdef) packages.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 16644
diff changeset
4185 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
4186 parser.autoloading = autoload;
fe3b9a51e625 rename curr_lexer, curr_parser, CURR_LEXER
John W. Eaton <jwe@octave.org>
parents: 16287
diff changeset
4187 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
4188
fe3b9a51e625 rename curr_lexer, curr_parser, CURR_LEXER
John W. Eaton <jwe@octave.org>
parents: 16287
diff changeset
4189 parser.lexer.force_script = force_script;
fe3b9a51e625 rename curr_lexer, curr_parser, CURR_LEXER
John W. Eaton <jwe@octave.org>
parents: 16287
diff changeset
4190 parser.lexer.prep_for_file ();
fe3b9a51e625 rename curr_lexer, curr_parser, CURR_LEXER
John W. Eaton <jwe@octave.org>
parents: 16287
diff changeset
4191 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
4192
fe3b9a51e625 rename curr_lexer, curr_parser, CURR_LEXER
John W. Eaton <jwe@octave.org>
parents: 16287
diff changeset
4193 parser.lexer.fcn_file_name = file;
fe3b9a51e625 rename curr_lexer, curr_parser, CURR_LEXER
John W. Eaton <jwe@octave.org>
parents: 16287
diff changeset
4194 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
4195
fe3b9a51e625 rename curr_lexer, curr_parser, CURR_LEXER
John W. Eaton <jwe@octave.org>
parents: 16287
diff changeset
4196 int status = parser.run ();
fe3b9a51e625 rename curr_lexer, curr_parser, CURR_LEXER
John W. Eaton <jwe@octave.org>
parents: 16287
diff changeset
4197
fe3b9a51e625 rename curr_lexer, curr_parser, CURR_LEXER
John W. Eaton <jwe@octave.org>
parents: 16287
diff changeset
4198 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
4199
16211
3449bf257514 maint: fix botched merge of default to classdef
John W. Eaton <jwe@octave.org>
parents: 16205
diff changeset
4200 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
4201 {
16289
bde729ba8381 maint: periodic merge of default to classdef
John W. Eaton <jwe@octave.org>
parents: 16286 16288
diff changeset
4202 if (parser.lexer.reading_classdef_file
bde729ba8381 maint: periodic merge of default to classdef
John W. Eaton <jwe@octave.org>
parents: 16286 16288
diff changeset
4203 && 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
4204 {
16211
3449bf257514 maint: fix botched merge of default to classdef
John W. Eaton <jwe@octave.org>
parents: 16205
diff changeset
4205 // 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
4206 // 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
4207 // table?). Return pointer to constructor?
3449bf257514 maint: fix botched merge of default to classdef
John W. Eaton <jwe@octave.org>
parents: 16205
diff changeset
4208
3449bf257514 maint: fix botched merge of default to classdef
John W. Eaton <jwe@octave.org>
parents: 16205
diff changeset
4209 if (fcn_ptr)
3449bf257514 maint: fix botched merge of default to classdef
John W. Eaton <jwe@octave.org>
parents: 16205
diff changeset
4210 panic_impossible ();
3449bf257514 maint: fix botched merge of default to classdef
John W. Eaton <jwe@octave.org>
parents: 16205
diff changeset
4211
18263
b5be1a2aa5ab Initial implementation for classdef methods in separate files.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 18262
diff changeset
4212 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
4213
b5be1a2aa5ab Initial implementation for classdef methods in separate files.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 18262
diff changeset
4214 fcn_ptr =
b5be1a2aa5ab Initial implementation for classdef methods in separate files.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 18262
diff changeset
4215 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
4216 }
16644
856cb7cba231 maint: periodic merge of default to classdef
John W. Eaton <jwe@octave.org>
parents: 16595 16627
diff changeset
4217 else if (fcn_ptr)
856cb7cba231 maint: periodic merge of default to classdef
John W. Eaton <jwe@octave.org>
parents: 16595 16627
diff changeset
4218 {
856cb7cba231 maint: periodic merge of default to classdef
John W. Eaton <jwe@octave.org>
parents: 16595 16627
diff changeset
4219 fcn_ptr->maybe_relocate_end ();
856cb7cba231 maint: periodic merge of default to classdef
John W. Eaton <jwe@octave.org>
parents: 16595 16627
diff changeset
4220
856cb7cba231 maint: periodic merge of default to classdef
John W. Eaton <jwe@octave.org>
parents: 16595 16627
diff changeset
4221 if (parser.parsing_subfunctions)
856cb7cba231 maint: periodic merge of default to classdef
John W. Eaton <jwe@octave.org>
parents: 16595 16627
diff changeset
4222 {
856cb7cba231 maint: periodic merge of default to classdef
John W. Eaton <jwe@octave.org>
parents: 16595 16627
diff changeset
4223 if (! parser.endfunction_found)
856cb7cba231 maint: periodic merge of default to classdef
John W. Eaton <jwe@octave.org>
parents: 16595 16627
diff changeset
4224 parser.subfunction_names.reverse ();
856cb7cba231 maint: periodic merge of default to classdef
John W. Eaton <jwe@octave.org>
parents: 16595 16627
diff changeset
4225
856cb7cba231 maint: periodic merge of default to classdef
John W. Eaton <jwe@octave.org>
parents: 16595 16627
diff changeset
4226 fcn_ptr->stash_subfunction_names (parser.subfunction_names);
856cb7cba231 maint: periodic merge of default to classdef
John W. Eaton <jwe@octave.org>
parents: 16595 16627
diff changeset
4227 }
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
4228 }
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
4229 }
10872
988d16d5ae34 correctly .m files that are empty or contain only comments
John W. Eaton <jwe@octave.org>
parents: 10659
diff changeset
4230 else
16203
127cccb037bf move more global parser and lexer variables to classes
John W. Eaton <jwe@octave.org>
parents: 16199
diff changeset
4231 error ("parse error while reading file %s", full_file.c_str ());
3021
18d64612e67a [project @ 1997-06-03 22:18:56 by jwe]
jwe
parents: 3016
diff changeset
4232 }
7715
5b4d278ec828 parse scripts completely before executing
John W. Eaton <jwe@octave.org>
parents: 7699
diff changeset
4233 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
4234 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
4235 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
4236 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
4237 full_file.c_str ());
3021
18d64612e67a [project @ 1997-06-03 22:18:56 by jwe]
jwe
parents: 3016
diff changeset
4238
7336
745a8299c2b5 [project @ 2007-12-28 20:56:55 by jwe]
jwe
parents: 7017
diff changeset
4239 return fcn_ptr;
3021
18d64612e67a [project @ 1997-06-03 22:18:56 by jwe]
jwe
parents: 3016
diff changeset
4240 }
18d64612e67a [project @ 1997-06-03 22:18:56 by jwe]
jwe
parents: 3016
diff changeset
4241
5484
2ff5363a16bd [project @ 2005-10-06 17:12:12 by jwe]
jwe
parents: 5472
diff changeset
4242 std::string
7715
5b4d278ec828 parse scripts completely before executing
John W. Eaton <jwe@octave.org>
parents: 7699
diff changeset
4243 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
4244 std::string& full_file)
7715
5b4d278ec828 parse scripts completely before executing
John W. Eaton <jwe@octave.org>
parents: 7699
diff changeset
4245 {
5b4d278ec828 parse scripts completely before executing
John W. Eaton <jwe@octave.org>
parents: 7699
diff changeset
4246 std::string retval;
5b4d278ec828 parse scripts completely before executing
John W. Eaton <jwe@octave.org>
parents: 7699
diff changeset
4247
16203
127cccb037bf move more global parser and lexer variables to classes
John W. Eaton <jwe@octave.org>
parents: 16199
diff changeset
4248 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
4249
127cccb037bf move more global parser and lexer variables to classes
John W. Eaton <jwe@octave.org>
parents: 16199
diff changeset
4250 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
4251
127cccb037bf move more global parser and lexer variables to classes
John W. Eaton <jwe@octave.org>
parents: 16199
diff changeset
4252 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
4253
127cccb037bf move more global parser and lexer variables to classes
John W. Eaton <jwe@octave.org>
parents: 16199
diff changeset
4254 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
4255 || (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
4256 || (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
4257 {
127cccb037bf move more global parser and lexer variables to classes
John W. Eaton <jwe@octave.org>
parents: 16199
diff changeset
4258 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
4259 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
4260
127cccb037bf move more global parser and lexer variables to classes
John W. Eaton <jwe@octave.org>
parents: 16199
diff changeset
4261 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
4262 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
4263 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
4264 }
7715
5b4d278ec828 parse scripts completely before executing
John W. Eaton <jwe@octave.org>
parents: 7699
diff changeset
4265
5b4d278ec828 parse scripts completely before executing
John W. Eaton <jwe@octave.org>
parents: 7699
diff changeset
4266 if (! file.empty ())
5b4d278ec828 parse scripts completely before executing
John W. Eaton <jwe@octave.org>
parents: 7699
diff changeset
4267 {
5b4d278ec828 parse scripts completely before executing
John W. Eaton <jwe@octave.org>
parents: 7699
diff changeset
4268 symbol_found = true;
5b4d278ec828 parse scripts completely before executing
John W. Eaton <jwe@octave.org>
parents: 7699
diff changeset
4269
16203
127cccb037bf move more global parser and lexer variables to classes
John W. Eaton <jwe@octave.org>
parents: 16199
diff changeset
4270 octave_function *fcn
16676
7368654f302f Initial support for (classdef) packages.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 16644
diff changeset
4271 = 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
4272 "");
16203
127cccb037bf move more global parser and lexer variables to classes
John W. Eaton <jwe@octave.org>
parents: 16199
diff changeset
4273
127cccb037bf move more global parser and lexer variables to classes
John W. Eaton <jwe@octave.org>
parents: 16199
diff changeset
4274 if (fcn)
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
4275 {
16203
127cccb037bf move more global parser and lexer variables to classes
John W. Eaton <jwe@octave.org>
parents: 16199
diff changeset
4276 retval = fcn->doc_string ();
127cccb037bf move more global parser and lexer variables to classes
John W. Eaton <jwe@octave.org>
parents: 16199
diff changeset
4277
127cccb037bf move more global parser and lexer variables to classes
John W. Eaton <jwe@octave.org>
parents: 16199
diff changeset
4278 delete fcn;
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
4279 }
7715
5b4d278ec828 parse scripts completely before executing
John W. Eaton <jwe@octave.org>
parents: 7699
diff changeset
4280 }
5b4d278ec828 parse scripts completely before executing
John W. Eaton <jwe@octave.org>
parents: 7699
diff changeset
4281
5b4d278ec828 parse scripts completely before executing
John W. Eaton <jwe@octave.org>
parents: 7699
diff changeset
4282 return retval;
5b4d278ec828 parse scripts completely before executing
John W. Eaton <jwe@octave.org>
parents: 7699
diff changeset
4283 }
5b4d278ec828 parse scripts completely before executing
John W. Eaton <jwe@octave.org>
parents: 7699
diff changeset
4284
5b4d278ec828 parse scripts completely before executing
John W. Eaton <jwe@octave.org>
parents: 7699
diff changeset
4285 std::string
5b4d278ec828 parse scripts completely before executing
John W. Eaton <jwe@octave.org>
parents: 7699
diff changeset
4286 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
4287 {
5b4d278ec828 parse scripts completely before executing
John W. Eaton <jwe@octave.org>
parents: 7699
diff changeset
4288 std::string file;
5b4d278ec828 parse scripts completely before executing
John W. Eaton <jwe@octave.org>
parents: 7699
diff changeset
4289 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
4290 }
5b4d278ec828 parse scripts completely before executing
John W. Eaton <jwe@octave.org>
parents: 7699
diff changeset
4291
5b4d278ec828 parse scripts completely before executing
John W. Eaton <jwe@octave.org>
parents: 7699
diff changeset
4292 std::string
5484
2ff5363a16bd [project @ 2005-10-06 17:12:12 by jwe]
jwe
parents: 5472
diff changeset
4293 lookup_autoload (const std::string& nm)
2ff5363a16bd [project @ 2005-10-06 17:12:12 by jwe]
jwe
parents: 5472
diff changeset
4294 {
5626
3236b4d98fde [project @ 2006-02-15 20:25:39 by jwe]
jwe
parents: 5615
diff changeset
4295 std::string retval;
3236b4d98fde [project @ 2006-02-15 20:25:39 by jwe]
jwe
parents: 5615
diff changeset
4296
3236b4d98fde [project @ 2006-02-15 20:25:39 by jwe]
jwe
parents: 5615
diff changeset
4297 typedef std::map<std::string, std::string>::const_iterator am_iter;
3236b4d98fde [project @ 2006-02-15 20:25:39 by jwe]
jwe
parents: 5615
diff changeset
4298
3236b4d98fde [project @ 2006-02-15 20:25:39 by jwe]
jwe
parents: 5615
diff changeset
4299 am_iter p = autoload_map.find (nm);
3236b4d98fde [project @ 2006-02-15 20:25:39 by jwe]
jwe
parents: 5615
diff changeset
4300
3236b4d98fde [project @ 2006-02-15 20:25:39 by jwe]
jwe
parents: 5615
diff changeset
4301 if (p != autoload_map.end ())
6323
ea65de49e18e [project @ 2007-02-17 02:51:02 by jwe]
jwe
parents: 6238
diff changeset
4302 retval = load_path::find_file (p->second);
5626
3236b4d98fde [project @ 2006-02-15 20:25:39 by jwe]
jwe
parents: 5615
diff changeset
4303
3236b4d98fde [project @ 2006-02-15 20:25:39 by jwe]
jwe
parents: 5615
diff changeset
4304 return retval;
5484
2ff5363a16bd [project @ 2005-10-06 17:12:12 by jwe]
jwe
parents: 5472
diff changeset
4305 }
2ff5363a16bd [project @ 2005-10-06 17:12:12 by jwe]
jwe
parents: 5472
diff changeset
4306
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11572
diff changeset
4307 string_vector
5592
61d6cebd243b [project @ 2006-01-12 17:55:22 by dbateman]
dbateman
parents: 5484
diff changeset
4308 autoloaded_functions (void)
61d6cebd243b [project @ 2006-01-12 17:55:22 by dbateman]
dbateman
parents: 5484
diff changeset
4309 {
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
4310 string_vector names (autoload_map.size ());
5592
61d6cebd243b [project @ 2006-01-12 17:55:22 by dbateman]
dbateman
parents: 5484
diff changeset
4311
61d6cebd243b [project @ 2006-01-12 17:55:22 by dbateman]
dbateman
parents: 5484
diff changeset
4312 octave_idx_type i = 0;
5626
3236b4d98fde [project @ 2006-02-15 20:25:39 by jwe]
jwe
parents: 5615
diff changeset
4313 typedef std::map<std::string, std::string>::const_iterator am_iter;
3236b4d98fde [project @ 2006-02-15 20:25:39 by jwe]
jwe
parents: 5615
diff changeset
4314 for (am_iter p = autoload_map.begin (); p != autoload_map.end (); p++)
5592
61d6cebd243b [project @ 2006-01-12 17:55:22 by dbateman]
dbateman
parents: 5484
diff changeset
4315 names[i++] = p->first;
61d6cebd243b [project @ 2006-01-12 17:55:22 by dbateman]
dbateman
parents: 5484
diff changeset
4316
61d6cebd243b [project @ 2006-01-12 17:55:22 by dbateman]
dbateman
parents: 5484
diff changeset
4317 return names;
61d6cebd243b [project @ 2006-01-12 17:55:22 by dbateman]
dbateman
parents: 5484
diff changeset
4318 }
61d6cebd243b [project @ 2006-01-12 17:55:22 by dbateman]
dbateman
parents: 5484
diff changeset
4319
61d6cebd243b [project @ 2006-01-12 17:55:22 by dbateman]
dbateman
parents: 5484
diff changeset
4320 string_vector
61d6cebd243b [project @ 2006-01-12 17:55:22 by dbateman]
dbateman
parents: 5484
diff changeset
4321 reverse_lookup_autoload (const std::string& nm)
61d6cebd243b [project @ 2006-01-12 17:55:22 by dbateman]
dbateman
parents: 5484
diff changeset
4322 {
61d6cebd243b [project @ 2006-01-12 17:55:22 by dbateman]
dbateman
parents: 5484
diff changeset
4323 string_vector names;
61d6cebd243b [project @ 2006-01-12 17:55:22 by dbateman]
dbateman
parents: 5484
diff changeset
4324
5626
3236b4d98fde [project @ 2006-02-15 20:25:39 by jwe]
jwe
parents: 5615
diff changeset
4325 typedef std::map<std::string, std::string>::const_iterator am_iter;
3236b4d98fde [project @ 2006-02-15 20:25:39 by jwe]
jwe
parents: 5615
diff changeset
4326 for (am_iter p = autoload_map.begin (); p != autoload_map.end (); p++)
5592
61d6cebd243b [project @ 2006-01-12 17:55:22 by dbateman]
dbateman
parents: 5484
diff changeset
4327 if (nm == p->second)
61d6cebd243b [project @ 2006-01-12 17:55:22 by dbateman]
dbateman
parents: 5484
diff changeset
4328 names.append (p->first);
61d6cebd243b [project @ 2006-01-12 17:55:22 by dbateman]
dbateman
parents: 5484
diff changeset
4329
61d6cebd243b [project @ 2006-01-12 17:55:22 by dbateman]
dbateman
parents: 5484
diff changeset
4330 return names;
61d6cebd243b [project @ 2006-01-12 17:55:22 by dbateman]
dbateman
parents: 5484
diff changeset
4331 }
61d6cebd243b [project @ 2006-01-12 17:55:22 by dbateman]
dbateman
parents: 5484
diff changeset
4332
7336
745a8299c2b5 [project @ 2007-12-28 20:56:55 by jwe]
jwe
parents: 7017
diff changeset
4333 octave_function *
745a8299c2b5 [project @ 2007-12-28 20:56:55 by jwe]
jwe
parents: 7017
diff changeset
4334 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
4335 const std::string& dispatch_type,
16676
7368654f302f Initial support for (classdef) packages.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 16644
diff changeset
4336 const std::string& package_name,
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
4337 const std::string& fcn_name, bool autoload)
3021
18d64612e67a [project @ 1997-06-03 22:18:56 by jwe]
jwe
parents: 3016
diff changeset
4338 {
7336
745a8299c2b5 [project @ 2007-12-28 20:56:55 by jwe]
jwe
parents: 7017
diff changeset
4339 octave_function *retval = 0;
745a8299c2b5 [project @ 2007-12-28 20:56:55 by jwe]
jwe
parents: 7017
diff changeset
4340
10067
6f79338c269b omission from last patch
Jaroslav Hajek <highegg@gmail.com>
parents: 9794
diff changeset
4341 unwind_protect frame;
5484
2ff5363a16bd [project @ 2005-10-06 17:12:12 by jwe]
jwe
parents: 5472
diff changeset
4342
7336
745a8299c2b5 [project @ 2007-12-28 20:56:55 by jwe]
jwe
parents: 7017
diff changeset
4343 std::string nm = file_name;
6238
3ecd8d2c5654 [project @ 2007-01-10 21:13:21 by jwe]
jwe
parents: 6235
diff changeset
4344
3ecd8d2c5654 [project @ 2007-01-10 21:13:21 by jwe]
jwe
parents: 6235
diff changeset
4345 size_t nm_len = nm.length ();
5472
e2f85b298a74 [project @ 2005-09-23 21:10:36 by jwe]
jwe
parents: 5400
diff changeset
4346
e2f85b298a74 [project @ 2005-09-23 21:10:36 by jwe]
jwe
parents: 5400
diff changeset
4347 std::string file;
e2f85b298a74 [project @ 2005-09-23 21:10:36 by jwe]
jwe
parents: 5400
diff changeset
4348
16153
a57c2c8c8163 move some variables into the octave_parser class
John W. Eaton <jwe@octave.org>
parents: 16151
diff changeset
4349 bool relative_lookup = false;
6323
ea65de49e18e [project @ 2007-02-17 02:51:02 by jwe]
jwe
parents: 6238
diff changeset
4350
7336
745a8299c2b5 [project @ 2007-12-28 20:56:55 by jwe]
jwe
parents: 7017
diff changeset
4351 file = nm;
745a8299c2b5 [project @ 2007-12-28 20:56:55 by jwe]
jwe
parents: 7017
diff changeset
4352
745a8299c2b5 [project @ 2007-12-28 20:56:55 by jwe]
jwe
parents: 7017
diff changeset
4353 if ((nm_len > 4 && nm.substr (nm_len-4) == ".oct")
745a8299c2b5 [project @ 2007-12-28 20:56:55 by jwe]
jwe
parents: 7017
diff changeset
4354 || (nm_len > 4 && nm.substr (nm_len-4) == ".mex")
745a8299c2b5 [project @ 2007-12-28 20:56:55 by jwe]
jwe
parents: 7017
diff changeset
4355 || (nm_len > 2 && nm.substr (nm_len-2) == ".m"))
5472
e2f85b298a74 [project @ 2005-09-23 21:10:36 by jwe]
jwe
parents: 5400
diff changeset
4356 {
6238
3ecd8d2c5654 [project @ 2007-01-10 21:13:21 by jwe]
jwe
parents: 6235
diff changeset
4357 nm = octave_env::base_pathname (file);
3ecd8d2c5654 [project @ 2007-01-10 21:13:21 by jwe]
jwe
parents: 6235
diff changeset
4358 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
4359
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
4360 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
4361 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
4362 nm = nm.substr (pos+1);
5472
e2f85b298a74 [project @ 2005-09-23 21:10:36 by jwe]
jwe
parents: 5400
diff changeset
4363 }
7336
745a8299c2b5 [project @ 2007-12-28 20:56:55 by jwe]
jwe
parents: 7017
diff changeset
4364
16153
a57c2c8c8163 move some variables into the octave_parser class
John W. Eaton <jwe@octave.org>
parents: 16151
diff changeset
4365 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
4366
10250
2d47356a7a1a use gnulib getcwd module
John W. Eaton <jwe@octave.org>
parents: 10230
diff changeset
4367 file = octave_env::make_absolute (file);
4243
7e4d5b5520e5 [project @ 2002-12-27 05:30:59 by jwe]
jwe
parents: 4240
diff changeset
4368
7e4d5b5520e5 [project @ 2002-12-27 05:30:59 by jwe]
jwe
parents: 4240
diff changeset
4369 int len = file.length ();
7e4d5b5520e5 [project @ 2002-12-27 05:30:59 by jwe]
jwe
parents: 4240
diff changeset
4370
4244
189df16144fc [project @ 2002-12-28 02:00:05 by jwe]
jwe
parents: 4243
diff changeset
4371 if (len > 4 && file.substr (len-4, len-1) == ".oct")
3021
18d64612e67a [project @ 1997-06-03 22:18:56 by jwe]
jwe
parents: 3016
diff changeset
4372 {
7336
745a8299c2b5 [project @ 2007-12-28 20:56:55 by jwe]
jwe
parents: 7017
diff changeset
4373 if (autoload && ! fcn_name.empty ())
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
4374 nm = fcn_name;
7336
745a8299c2b5 [project @ 2007-12-28 20:56:55 by jwe]
jwe
parents: 7017
diff changeset
4375
16153
a57c2c8c8163 move some variables into the octave_parser class
John W. Eaton <jwe@octave.org>
parents: 16151
diff changeset
4376 retval = octave_dynamic_loader::load_oct (nm, file, relative_lookup);
5864
e884ab4f29ee [project @ 2006-06-22 00:57:27 by jwe]
jwe
parents: 5861
diff changeset
4377 }
e884ab4f29ee [project @ 2006-06-22 00:57:27 by jwe]
jwe
parents: 5861
diff changeset
4378 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
4379 {
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
4380 // 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
4381 // 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
4382
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11572
diff changeset
4383 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
4384 nm, dispatch_type,
7368654f302f Initial support for (classdef) packages.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 16644
diff changeset
4385 package_name, false,
16153
a57c2c8c8163 move some variables into the octave_parser class
John W. Eaton <jwe@octave.org>
parents: 16151
diff changeset
4386 autoload, autoload,
a57c2c8c8163 move some variables into the octave_parser class
John W. Eaton <jwe@octave.org>
parents: 16151
diff changeset
4387 relative_lookup, "");
a57c2c8c8163 move some variables into the octave_parser class
John W. Eaton <jwe@octave.org>
parents: 16151
diff changeset
4388
a57c2c8c8163 move some variables into the octave_parser class
John W. Eaton <jwe@octave.org>
parents: 16151
diff changeset
4389 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
4390
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
4391 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
4392 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
4393 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
4394 }
4244
189df16144fc [project @ 2002-12-28 02:00:05 by jwe]
jwe
parents: 4243
diff changeset
4395 else if (len > 2)
3021
18d64612e67a [project @ 1997-06-03 22:18:56 by jwe]
jwe
parents: 3016
diff changeset
4396 {
16676
7368654f302f Initial support for (classdef) packages.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 16644
diff changeset
4397 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
4398 autoload, autoload, relative_lookup, "");
3021
18d64612e67a [project @ 1997-06-03 22:18:56 by jwe]
jwe
parents: 3016
diff changeset
4399 }
18d64612e67a [project @ 1997-06-03 22:18:56 by jwe]
jwe
parents: 3016
diff changeset
4400
7336
745a8299c2b5 [project @ 2007-12-28 20:56:55 by jwe]
jwe
parents: 7017
diff changeset
4401 if (retval)
8819
96d87674b818 also stash directory name for subfunctions
John W. Eaton <jwe@octave.org>
parents: 8812
diff changeset
4402 {
96d87674b818 also stash directory name for subfunctions
John W. Eaton <jwe@octave.org>
parents: 8812
diff changeset
4403 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
4404 retval->stash_package_name (package_name);
8819
96d87674b818 also stash directory name for subfunctions
John W. Eaton <jwe@octave.org>
parents: 8812
diff changeset
4405
96d87674b818 also stash directory name for subfunctions
John W. Eaton <jwe@octave.org>
parents: 8812
diff changeset
4406 if (retval->is_user_function ())
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
4407 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
4408 symbol_table::scope_id id = retval->scope ();
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
4409
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
4410 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
4411 }
8819
96d87674b818 also stash directory name for subfunctions
John W. Eaton <jwe@octave.org>
parents: 8812
diff changeset
4412 }
7336
745a8299c2b5 [project @ 2007-12-28 20:56:55 by jwe]
jwe
parents: 7017
diff changeset
4413
745a8299c2b5 [project @ 2007-12-28 20:56:55 by jwe]
jwe
parents: 7017
diff changeset
4414 return retval;
5312
80c1aa832cb2 [project @ 2005-04-28 01:54:46 by jwe]
jwe
parents: 5309
diff changeset
4415 }
80c1aa832cb2 [project @ 2005-04-28 01:54:46 by jwe]
jwe
parents: 5309
diff changeset
4416
8746
5dd06f19e9be handle commands in the lexer
John W. Eaton <jwe@octave.org>
parents: 8745
diff changeset
4417 DEFUN (autoload, args, ,
5484
2ff5363a16bd [project @ 2005-10-06 17:12:12 by jwe]
jwe
parents: 5472
diff changeset
4418 "-*- texinfo -*-\n\
20895
7697a3433e37 doc: Remove class of function from docstring from generated C++ files.
Rik <rik@octave.org>
parents: 20818
diff changeset
4419 @deftypefn {} {@var{autoload_map} =} autoload ()\n\
7697a3433e37 doc: Remove class of function from docstring from generated C++ files.
Rik <rik@octave.org>
parents: 20818
diff changeset
4420 @deftypefnx {} {} autoload (@var{function}, @var{file})\n\
7697a3433e37 doc: Remove class of function from docstring from generated C++ files.
Rik <rik@octave.org>
parents: 20818
diff changeset
4421 @deftypefnx {} {} autoload (@dots{}, \"remove\")\n\
5484
2ff5363a16bd [project @ 2005-10-06 17:12:12 by jwe]
jwe
parents: 5472
diff changeset
4422 Define @var{function} to autoload from @var{file}.\n\
5626
3236b4d98fde [project @ 2006-02-15 20:25:39 by jwe]
jwe
parents: 5615
diff changeset
4423 \n\
20713
2469d78a1d8b Consistently use 'filename' rather than 'file name' throughout code base.
Rik <rik@octave.org>
parents: 20700
diff changeset
4424 The second argument, @var{file}, should be an absolute filename or a file\n\
20163
075a5e2e1ba5 doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents: 20075
diff changeset
4425 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: 20075
diff changeset
4426 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: 20075
diff changeset
4427 path.\n\
6380
ac3d67504f85 [project @ 2007-03-02 22:08:06 by jwe]
jwe
parents: 6379
diff changeset
4428 \n\
20163
075a5e2e1ba5 doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents: 20075
diff changeset
4429 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: 20075
diff changeset
4430 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: 20075
diff changeset
4431 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: 20075
diff changeset
4432 directory as the PKG_ADD script then\n\
6380
ac3d67504f85 [project @ 2007-03-02 22:08:06 by jwe]
jwe
parents: 6379
diff changeset
4433 \n\
ac3d67504f85 [project @ 2007-03-02 22:08:06 by jwe]
jwe
parents: 6379
diff changeset
4434 @example\n\
6926
c05fbb1b7e1f [project @ 2007-09-26 19:56:54 by dbateman]
dbateman
parents: 6657
diff changeset
4435 autoload (\"foo\", \"bar.oct\");\n\
6380
ac3d67504f85 [project @ 2007-03-02 22:08:06 by jwe]
jwe
parents: 6379
diff changeset
4436 @end example\n\
ac3d67504f85 [project @ 2007-03-02 22:08:06 by jwe]
jwe
parents: 6379
diff changeset
4437 \n\
11572
7d6d8c1e471f Grammarcheck Texinfo for files in src directory.
Rik <octave@nomad.inbox5.com>
parents: 11523
diff changeset
4438 @noindent\n\
9038
fca0dc2fb042 Cleanup documentation files stmt.texi and func.texi
Rik <rdrider0-list@yahoo.com>
parents: 8974
diff changeset
4439 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
4440 usage when @code{bar.oct} is not in the same directory, or usages such as\n\
6380
ac3d67504f85 [project @ 2007-03-02 22:08:06 by jwe]
jwe
parents: 6379
diff changeset
4441 \n\
ac3d67504f85 [project @ 2007-03-02 22:08:06 by jwe]
jwe
parents: 6379
diff changeset
4442 @example\n\
6637
c18ed0e7ee41 [project @ 2007-05-21 19:12:46 by jwe]
jwe
parents: 6431
diff changeset
4443 autoload (\"foo\", file_in_loadpath (\"bar.oct\"))\n\
6380
ac3d67504f85 [project @ 2007-03-02 22:08:06 by jwe]
jwe
parents: 6379
diff changeset
4444 @end example\n\
ac3d67504f85 [project @ 2007-03-02 22:08:06 by jwe]
jwe
parents: 6379
diff changeset
4445 \n\
ac3d67504f85 [project @ 2007-03-02 22:08:06 by jwe]
jwe
parents: 6379
diff changeset
4446 @noindent\n\
16789
2f63d2f3ff11 doc: Update docstrings in oct-parse.in.yy.
Rik <rik@octave.org>
parents: 16681
diff changeset
4447 are strongly discouraged, as their behavior may be unpredictable.\n\
6380
ac3d67504f85 [project @ 2007-03-02 22:08:06 by jwe]
jwe
parents: 6379
diff changeset
4448 \n\
6637
c18ed0e7ee41 [project @ 2007-05-21 19:12:46 by jwe]
jwe
parents: 6431
diff changeset
4449 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
4450 \n\
18531
04b4fb217b1a doc: Improve documentation strings in parse-tree directory.
Rik <rik@octave.org>
parents: 17796
diff changeset
4451 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
4452 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
4453 \n\
6380
ac3d67504f85 [project @ 2007-03-02 22:08:06 by jwe]
jwe
parents: 6379
diff changeset
4454 @seealso{PKG_ADD}\n\
5484
2ff5363a16bd [project @ 2005-10-06 17:12:12 by jwe]
jwe
parents: 5472
diff changeset
4455 @end deftypefn")
2ff5363a16bd [project @ 2005-10-06 17:12:12 by jwe]
jwe
parents: 5472
diff changeset
4456 {
5626
3236b4d98fde [project @ 2006-02-15 20:25:39 by jwe]
jwe
parents: 5615
diff changeset
4457 octave_value retval;
5484
2ff5363a16bd [project @ 2005-10-06 17:12:12 by jwe]
jwe
parents: 5472
diff changeset
4458
2ff5363a16bd [project @ 2005-10-06 17:12:12 by jwe]
jwe
parents: 5472
diff changeset
4459 int nargin = args.length ();
2ff5363a16bd [project @ 2005-10-06 17:12:12 by jwe]
jwe
parents: 5472
diff changeset
4460
20798
bb585db6dee2 eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
4461 if (nargin == 1 || nargin > 3)
bb585db6dee2 eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
4462 print_usage ();
bb585db6dee2 eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
4463
5626
3236b4d98fde [project @ 2006-02-15 20:25:39 by jwe]
jwe
parents: 5615
diff changeset
4464 if (nargin == 0)
3236b4d98fde [project @ 2006-02-15 20:25:39 by jwe]
jwe
parents: 5615
diff changeset
4465 {
10350
12884915a8e4 merge MArray classes & improve Array interface
Jaroslav Hajek <highegg@gmail.com>
parents: 10315
diff changeset
4466 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
4467 Cell file_names (dim_vector (autoload_map.size (), 1));
5626
3236b4d98fde [project @ 2006-02-15 20:25:39 by jwe]
jwe
parents: 5615
diff changeset
4468
3236b4d98fde [project @ 2006-02-15 20:25:39 by jwe]
jwe
parents: 5615
diff changeset
4469 octave_idx_type i = 0;
3236b4d98fde [project @ 2006-02-15 20:25:39 by jwe]
jwe
parents: 5615
diff changeset
4470 typedef std::map<std::string, std::string>::const_iterator am_iter;
3236b4d98fde [project @ 2006-02-15 20:25:39 by jwe]
jwe
parents: 5615
diff changeset
4471 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
4472 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
4473 func_names(i) = p->first;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
4474 file_names(i) = p->second;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
4475
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
4476 i++;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
4477 }
5626
3236b4d98fde [project @ 2006-02-15 20:25:39 by jwe]
jwe
parents: 5615
diff changeset
4478
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
4479 octave_map m;
5626
3236b4d98fde [project @ 2006-02-15 20:25:39 by jwe]
jwe
parents: 5615
diff changeset
4480
3236b4d98fde [project @ 2006-02-15 20:25:39 by jwe]
jwe
parents: 5615
diff changeset
4481 m.assign ("function", func_names);
3236b4d98fde [project @ 2006-02-15 20:25:39 by jwe]
jwe
parents: 5615
diff changeset
4482 m.assign ("file", file_names);
3236b4d98fde [project @ 2006-02-15 20:25:39 by jwe]
jwe
parents: 5615
diff changeset
4483
3236b4d98fde [project @ 2006-02-15 20:25:39 by jwe]
jwe
parents: 5615
diff changeset
4484 retval = m;
3236b4d98fde [project @ 2006-02-15 20:25:39 by jwe]
jwe
parents: 5615
diff changeset
4485 }
20798
bb585db6dee2 eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
4486 else
5484
2ff5363a16bd [project @ 2005-10-06 17:12:12 by jwe]
jwe
parents: 5472
diff changeset
4487 {
2ff5363a16bd [project @ 2005-10-06 17:12:12 by jwe]
jwe
parents: 5472
diff changeset
4488 string_vector argv = args.make_argv ("autoload");
2ff5363a16bd [project @ 2005-10-06 17:12:12 by jwe]
jwe
parents: 5472
diff changeset
4489
20547
52ce821a52fd eliminate simple uses of error_state in parser and lexer
John W. Eaton <jwe@octave.org>
parents: 20535
diff changeset
4490 std::string nm = argv[2];
52ce821a52fd eliminate simple uses of error_state in parser and lexer
John W. Eaton <jwe@octave.org>
parents: 20535
diff changeset
4491
52ce821a52fd eliminate simple uses of error_state in parser and lexer
John W. Eaton <jwe@octave.org>
parents: 20535
diff changeset
4492 if (! octave_env::absolute_pathname (nm))
6380
ac3d67504f85 [project @ 2007-03-02 22:08:06 by jwe]
jwe
parents: 6379
diff changeset
4493 {
20547
52ce821a52fd eliminate simple uses of error_state in parser and lexer
John W. Eaton <jwe@octave.org>
parents: 20535
diff changeset
4494 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: 20535
diff changeset
4495
52ce821a52fd eliminate simple uses of error_state in parser and lexer
John W. Eaton <jwe@octave.org>
parents: 20535
diff changeset
4496 bool found = false;
52ce821a52fd eliminate simple uses of error_state in parser and lexer
John W. Eaton <jwe@octave.org>
parents: 20535
diff changeset
4497
52ce821a52fd eliminate simple uses of error_state in parser and lexer
John W. Eaton <jwe@octave.org>
parents: 20535
diff changeset
4498 if (fcn)
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
4499 {
20547
52ce821a52fd eliminate simple uses of error_state in parser and lexer
John W. Eaton <jwe@octave.org>
parents: 20535
diff changeset
4500 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: 20535
diff changeset
4501
52ce821a52fd eliminate simple uses of error_state in parser and lexer
John W. Eaton <jwe@octave.org>
parents: 20535
diff changeset
4502 if (! fname.empty ())
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
4503 {
20547
52ce821a52fd eliminate simple uses of error_state in parser and lexer
John W. Eaton <jwe@octave.org>
parents: 20535
diff changeset
4504 fname = octave_env::make_absolute (fname);
52ce821a52fd eliminate simple uses of error_state in parser and lexer
John W. Eaton <jwe@octave.org>
parents: 20535
diff changeset
4505 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: 20535
diff changeset
4506
52ce821a52fd eliminate simple uses of error_state in parser and lexer
John W. Eaton <jwe@octave.org>
parents: 20535
diff changeset
4507 file_stat fs (fname + nm);
52ce821a52fd eliminate simple uses of error_state in parser and lexer
John W. Eaton <jwe@octave.org>
parents: 20535
diff changeset
4508
52ce821a52fd eliminate simple uses of error_state in parser and lexer
John W. Eaton <jwe@octave.org>
parents: 20535
diff changeset
4509 if (fs.exists ())
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
4510 {
20547
52ce821a52fd eliminate simple uses of error_state in parser and lexer
John W. Eaton <jwe@octave.org>
parents: 20535
diff changeset
4511 nm = fname + nm;
52ce821a52fd eliminate simple uses of error_state in parser and lexer
John W. Eaton <jwe@octave.org>
parents: 20535
diff changeset
4512 found = true;
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
4513 }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
4514 }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
4515 }
20547
52ce821a52fd eliminate simple uses of error_state in parser and lexer
John W. Eaton <jwe@octave.org>
parents: 20535
diff changeset
4516 if (! found)
52ce821a52fd eliminate simple uses of error_state in parser and lexer
John W. Eaton <jwe@octave.org>
parents: 20535
diff changeset
4517 warning_with_id ("Octave:autoload-relative-file-name",
20713
2469d78a1d8b Consistently use 'filename' rather than 'file name' throughout code base.
Rik <rik@octave.org>
parents: 20700
diff changeset
4518 "autoload: '%s' is not an absolute filename",
20547
52ce821a52fd eliminate simple uses of error_state in parser and lexer
John W. Eaton <jwe@octave.org>
parents: 20535
diff changeset
4519 nm.c_str ());
52ce821a52fd eliminate simple uses of error_state in parser and lexer
John W. Eaton <jwe@octave.org>
parents: 20535
diff changeset
4520 }
52ce821a52fd eliminate simple uses of error_state in parser and lexer
John W. Eaton <jwe@octave.org>
parents: 20535
diff changeset
4521 if (nargin == 2)
52ce821a52fd eliminate simple uses of error_state in parser and lexer
John W. Eaton <jwe@octave.org>
parents: 20535
diff changeset
4522 autoload_map[argv[1]] = nm;
52ce821a52fd eliminate simple uses of error_state in parser and lexer
John W. Eaton <jwe@octave.org>
parents: 20535
diff changeset
4523 else if (nargin == 3)
52ce821a52fd eliminate simple uses of error_state in parser and lexer
John W. Eaton <jwe@octave.org>
parents: 20535
diff changeset
4524 {
21021
a5b99b09f8fd maint: Use comparison operators rather than compare() for strings.
Rik <rik@octave.org>
parents: 20957
diff changeset
4525 if (argv[3] != "remove")
20547
52ce821a52fd eliminate simple uses of error_state in parser and lexer
John W. Eaton <jwe@octave.org>
parents: 20535
diff changeset
4526 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: 20535
diff changeset
4527 "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: 20535
diff changeset
4528
52ce821a52fd eliminate simple uses of error_state in parser and lexer
John W. Eaton <jwe@octave.org>
parents: 20535
diff changeset
4529 // 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: 20535
diff changeset
4530 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: 20535
diff changeset
4531 autoload_map.erase (argv[1]);
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
4532 }
5484
2ff5363a16bd [project @ 2005-10-06 17:12:12 by jwe]
jwe
parents: 5472
diff changeset
4533 }
2ff5363a16bd [project @ 2005-10-06 17:12:12 by jwe]
jwe
parents: 5472
diff changeset
4534
2ff5363a16bd [project @ 2005-10-06 17:12:12 by jwe]
jwe
parents: 5472
diff changeset
4535 return retval;
2ff5363a16bd [project @ 2005-10-06 17:12:12 by jwe]
jwe
parents: 5472
diff changeset
4536 }
2ff5363a16bd [project @ 2005-10-06 17:12:12 by jwe]
jwe
parents: 5472
diff changeset
4537
4486
6ceba1f351fb [project @ 2003-08-22 16:49:46 by jwe]
jwe
parents: 4463
diff changeset
4538 void
7715
5b4d278ec828 parse scripts completely before executing
John W. Eaton <jwe@octave.org>
parents: 7699
diff changeset
4539 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
4540 bool verbose, bool require_file, const std::string& warn_for)
4486
6ceba1f351fb [project @ 2003-08-22 16:49:46 by jwe]
jwe
parents: 4463
diff changeset
4541 {
10578
cb0883127251 limit on recursion via calls to source function
John W. Eaton <jwe@octave.org>
parents: 10570
diff changeset
4542 // 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
4543 // 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
4544 // 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
4545 // written as
cb0883127251 limit on recursion via calls to source function
John W. Eaton <jwe@octave.org>
parents: 10570
diff changeset
4546 //
cb0883127251 limit on recursion via calls to source function
John W. Eaton <jwe@octave.org>
parents: 10570
diff changeset
4547 // foo1.m:
cb0883127251 limit on recursion via calls to source function
John W. Eaton <jwe@octave.org>
parents: 10570
diff changeset
4548 // ------
cb0883127251 limit on recursion via calls to source function
John W. Eaton <jwe@octave.org>
parents: 10570
diff changeset
4549 // foo2
cb0883127251 limit on recursion via calls to source function
John W. Eaton <jwe@octave.org>
parents: 10570
diff changeset
4550 //
cb0883127251 limit on recursion via calls to source function
John W. Eaton <jwe@octave.org>
parents: 10570
diff changeset
4551 // foo2.m:
cb0883127251 limit on recursion via calls to source function
John W. Eaton <jwe@octave.org>
parents: 10570
diff changeset
4552 // ------
cb0883127251 limit on recursion via calls to source function
John W. Eaton <jwe@octave.org>
parents: 10570
diff changeset
4553 // foo1
cb0883127251 limit on recursion via calls to source function
John W. Eaton <jwe@octave.org>
parents: 10570
diff changeset
4554 //
cb0883127251 limit on recursion via calls to source function
John W. Eaton <jwe@octave.org>
parents: 10570
diff changeset
4555 // and called with
cb0883127251 limit on recursion via calls to source function
John W. Eaton <jwe@octave.org>
parents: 10570
diff changeset
4556 //
cb0883127251 limit on recursion via calls to source function
John W. Eaton <jwe@octave.org>
parents: 10570
diff changeset
4557 // foo1
cb0883127251 limit on recursion via calls to source function
John W. Eaton <jwe@octave.org>
parents: 10570
diff changeset
4558 //
cb0883127251 limit on recursion via calls to source function
John W. Eaton <jwe@octave.org>
parents: 10570
diff changeset
4559 // (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
4560 //
cb0883127251 limit on recursion via calls to source function
John W. Eaton <jwe@octave.org>
parents: 10570
diff changeset
4561 // foo1.m:
cb0883127251 limit on recursion via calls to source function
John W. Eaton <jwe@octave.org>
parents: 10570
diff changeset
4562 // ------
cb0883127251 limit on recursion via calls to source function
John W. Eaton <jwe@octave.org>
parents: 10570
diff changeset
4563 // source ("foo2.m")
cb0883127251 limit on recursion via calls to source function
John W. Eaton <jwe@octave.org>
parents: 10570
diff changeset
4564 //
cb0883127251 limit on recursion via calls to source function
John W. Eaton <jwe@octave.org>
parents: 10570
diff changeset
4565 // foo2.m:
cb0883127251 limit on recursion via calls to source function
John W. Eaton <jwe@octave.org>
parents: 10570
diff changeset
4566 // ------
cb0883127251 limit on recursion via calls to source function
John W. Eaton <jwe@octave.org>
parents: 10570
diff changeset
4567 // source ("foo1.m")
cb0883127251 limit on recursion via calls to source function
John W. Eaton <jwe@octave.org>
parents: 10570
diff changeset
4568 //
cb0883127251 limit on recursion via calls to source function
John W. Eaton <jwe@octave.org>
parents: 10570
diff changeset
4569 // and called with
cb0883127251 limit on recursion via calls to source function
John W. Eaton <jwe@octave.org>
parents: 10570
diff changeset
4570 //
cb0883127251 limit on recursion via calls to source function
John W. Eaton <jwe@octave.org>
parents: 10570
diff changeset
4571 // source ("foo1.m")
cb0883127251 limit on recursion via calls to source function
John W. Eaton <jwe@octave.org>
parents: 10570
diff changeset
4572 //
cb0883127251 limit on recursion via calls to source function
John W. Eaton <jwe@octave.org>
parents: 10570
diff changeset
4573 // (for example).
cb0883127251 limit on recursion via calls to source function
John W. Eaton <jwe@octave.org>
parents: 10570
diff changeset
4574
cb0883127251 limit on recursion via calls to source function
John W. Eaton <jwe@octave.org>
parents: 10570
diff changeset
4575 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
4576
4486
6ceba1f351fb [project @ 2003-08-22 16:49:46 by jwe]
jwe
parents: 4463
diff changeset
4577 std::string file_full_name = file_ops::tilde_expand (file_name);
6ceba1f351fb [project @ 2003-08-22 16:49:46 by jwe]
jwe
parents: 4463
diff changeset
4578
10578
cb0883127251 limit on recursion via calls to source function
John W. Eaton <jwe@octave.org>
parents: 10570
diff changeset
4579 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
4580
10067
6f79338c269b omission from last patch
Jaroslav Hajek <highegg@gmail.com>
parents: 9794
diff changeset
4581 unwind_protect frame;
6f79338c269b omission from last patch
Jaroslav Hajek <highegg@gmail.com>
parents: 9794
diff changeset
4582
10578
cb0883127251 limit on recursion via calls to source function
John W. Eaton <jwe@octave.org>
parents: 10570
diff changeset
4583 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
4584 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
4585
cb0883127251 limit on recursion via calls to source function
John W. Eaton <jwe@octave.org>
parents: 10570
diff changeset
4586 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
4587
cb0883127251 limit on recursion via calls to source function
John W. Eaton <jwe@octave.org>
parents: 10570
diff changeset
4588 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
4589
cb0883127251 limit on recursion via calls to source function
John W. Eaton <jwe@octave.org>
parents: 10570
diff changeset
4590 if (source_call_depth[file_full_name] >= Vmax_recursion_depth)
20957
9db35d2042be maint: eliminate special cases of statements after error.
Rik <rik@octave.org>
parents: 20895
diff changeset
4591 error ("max_recursion_depth exceeded");
10578
cb0883127251 limit on recursion via calls to source function
John W. Eaton <jwe@octave.org>
parents: 10570
diff changeset
4592
5975
e64059303a6f [project @ 2006-08-29 16:37:39 by jwe]
jwe
parents: 5932
diff changeset
4593 if (! context.empty ())
e64059303a6f [project @ 2006-08-29 16:37:39 by jwe]
jwe
parents: 5932
diff changeset
4594 {
e64059303a6f [project @ 2006-08-29 16:37:39 by jwe]
jwe
parents: 5932
diff changeset
4595 if (context == "caller")
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
4596 octave_call_stack::goto_caller_frame ();
5975
e64059303a6f [project @ 2006-08-29 16:37:39 by jwe]
jwe
parents: 5932
diff changeset
4597 else if (context == "base")
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
4598 octave_call_stack::goto_base_frame ();
5975
e64059303a6f [project @ 2006-08-29 16:37:39 by jwe]
jwe
parents: 5932
diff changeset
4599 else
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
4600 error ("source: context must be \"caller\" or \"base\"");
7336
745a8299c2b5 [project @ 2007-12-28 20:56:55 by jwe]
jwe
parents: 7017
diff changeset
4601
20547
52ce821a52fd eliminate simple uses of error_state in parser and lexer
John W. Eaton <jwe@octave.org>
parents: 20535
diff changeset
4602 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
4603 }
5975
e64059303a6f [project @ 2006-08-29 16:37:39 by jwe]
jwe
parents: 5932
diff changeset
4604
20555
f90c8372b7ba eliminate many more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20550
diff changeset
4605 octave_function *fcn = 0;
f90c8372b7ba eliminate many more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20550
diff changeset
4606
20547
52ce821a52fd eliminate simple uses of error_state in parser and lexer
John W. Eaton <jwe@octave.org>
parents: 20535
diff changeset
4607 try
5975
e64059303a6f [project @ 2006-08-29 16:37:39 by jwe]
jwe
parents: 5932
diff changeset
4608 {
20555
f90c8372b7ba eliminate many more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20550
diff changeset
4609 fcn = parse_fcn_file (file_full_name, file_name, "", "",
f90c8372b7ba eliminate many more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20550
diff changeset
4610 require_file, true, false, false, warn_for);
20547
52ce821a52fd eliminate simple uses of error_state in parser and lexer
John W. Eaton <jwe@octave.org>
parents: 20535
diff changeset
4611 }
20785
b6f2909e7f94 always throw exception after debugging with debug_on_error
John W. Eaton <jwe@octave.org>
parents: 20769
diff changeset
4612 catch (octave_execution_exception& e)
20547
52ce821a52fd eliminate simple uses of error_state in parser and lexer
John W. Eaton <jwe@octave.org>
parents: 20535
diff changeset
4613 {
20756
200ae1d650b7 propagate octave_execution_exception objects through try/catch blocks
John W. Eaton <jwe@octave.org>
parents: 20713
diff changeset
4614 error (e, "source: error sourcing file '%s'", file_full_name.c_str ());
20547
52ce821a52fd eliminate simple uses of error_state in parser and lexer
John W. Eaton <jwe@octave.org>
parents: 20535
diff changeset
4615 }
52ce821a52fd eliminate simple uses of error_state in parser and lexer
John W. Eaton <jwe@octave.org>
parents: 20535
diff changeset
4616
52ce821a52fd eliminate simple uses of error_state in parser and lexer
John W. Eaton <jwe@octave.org>
parents: 20535
diff changeset
4617 if (fcn && fcn->is_user_script ())
52ce821a52fd eliminate simple uses of error_state in parser and lexer
John W. Eaton <jwe@octave.org>
parents: 20535
diff changeset
4618 {
52ce821a52fd eliminate simple uses of error_state in parser and lexer
John W. Eaton <jwe@octave.org>
parents: 20535
diff changeset
4619 octave_value_list args;
52ce821a52fd eliminate simple uses of error_state in parser and lexer
John W. Eaton <jwe@octave.org>
parents: 20535
diff changeset
4620
52ce821a52fd eliminate simple uses of error_state in parser and lexer
John W. Eaton <jwe@octave.org>
parents: 20535
diff changeset
4621 if (verbose)
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
4622 {
20547
52ce821a52fd eliminate simple uses of error_state in parser and lexer
John W. Eaton <jwe@octave.org>
parents: 20535
diff changeset
4623 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: 20535
diff changeset
4624 reading_startup_message_printed = true;
52ce821a52fd eliminate simple uses of error_state in parser and lexer
John W. Eaton <jwe@octave.org>
parents: 20535
diff changeset
4625 std::cout.flush ();
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
4626 }
20547
52ce821a52fd eliminate simple uses of error_state in parser and lexer
John W. Eaton <jwe@octave.org>
parents: 20535
diff changeset
4627
52ce821a52fd eliminate simple uses of error_state in parser and lexer
John W. Eaton <jwe@octave.org>
parents: 20535
diff changeset
4628 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: 20535
diff changeset
4629
52ce821a52fd eliminate simple uses of error_state in parser and lexer
John W. Eaton <jwe@octave.org>
parents: 20535
diff changeset
4630 if (verbose)
52ce821a52fd eliminate simple uses of error_state in parser and lexer
John W. Eaton <jwe@octave.org>
parents: 20535
diff changeset
4631 std::cout << "done." << std::endl;
52ce821a52fd eliminate simple uses of error_state in parser and lexer
John W. Eaton <jwe@octave.org>
parents: 20535
diff changeset
4632
52ce821a52fd eliminate simple uses of error_state in parser and lexer
John W. Eaton <jwe@octave.org>
parents: 20535
diff changeset
4633 delete fcn;
5975
e64059303a6f [project @ 2006-08-29 16:37:39 by jwe]
jwe
parents: 5932
diff changeset
4634 }
4486
6ceba1f351fb [project @ 2003-08-22 16:49:46 by jwe]
jwe
parents: 4463
diff changeset
4635 }
6ceba1f351fb [project @ 2003-08-22 16:49:46 by jwe]
jwe
parents: 4463
diff changeset
4636
5739
d090d39bb82c [project @ 2006-04-05 06:56:24 by jwe]
jwe
parents: 5667
diff changeset
4637 DEFUN (mfilename, args, ,
d090d39bb82c [project @ 2006-04-05 06:56:24 by jwe]
jwe
parents: 5667
diff changeset
4638 "-*- texinfo -*-\n\
20895
7697a3433e37 doc: Remove class of function from docstring from generated C++ files.
Rik <rik@octave.org>
parents: 20818
diff changeset
4639 @deftypefn {} {} mfilename ()\n\
7697a3433e37 doc: Remove class of function from docstring from generated C++ files.
Rik <rik@octave.org>
parents: 20818
diff changeset
4640 @deftypefnx {} {} mfilename (\"fullpath\")\n\
7697a3433e37 doc: Remove class of function from docstring from generated C++ files.
Rik <rik@octave.org>
parents: 20818
diff changeset
4641 @deftypefnx {} {} mfilename (\"fullpathext\")\n\
18531
04b4fb217b1a doc: Improve documentation strings in parse-tree directory.
Rik <rik@octave.org>
parents: 17796
diff changeset
4642 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
4643 \n\
20163
075a5e2e1ba5 doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents: 20075
diff changeset
4644 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: 20075
diff changeset
4645 \n\
075a5e2e1ba5 doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents: 20075
diff changeset
4646 Given the argument @qcode{\"fullpath\"}, include the directory part of the\n\
20713
2469d78a1d8b Consistently use 'filename' rather than 'file name' throughout code base.
Rik <rik@octave.org>
parents: 20700
diff changeset
4647 filename, but not the extension.\n\
20163
075a5e2e1ba5 doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents: 20075
diff changeset
4648 \n\
075a5e2e1ba5 doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents: 20075
diff changeset
4649 Given the argument @qcode{\"fullpathext\"}, include the directory part of\n\
20713
2469d78a1d8b Consistently use 'filename' rather than 'file name' throughout code base.
Rik <rik@octave.org>
parents: 20700
diff changeset
4650 the filename and the extension.\n\
5774
e7af222e98b0 [project @ 2006-04-24 17:45:31 by jwe]
jwe
parents: 5765
diff changeset
4651 @end deftypefn")
5739
d090d39bb82c [project @ 2006-04-05 06:56:24 by jwe]
jwe
parents: 5667
diff changeset
4652 {
d090d39bb82c [project @ 2006-04-05 06:56:24 by jwe]
jwe
parents: 5667
diff changeset
4653 octave_value retval;
d090d39bb82c [project @ 2006-04-05 06:56:24 by jwe]
jwe
parents: 5667
diff changeset
4654
d090d39bb82c [project @ 2006-04-05 06:56:24 by jwe]
jwe
parents: 5667
diff changeset
4655 int nargin = args.length ();
d090d39bb82c [project @ 2006-04-05 06:56:24 by jwe]
jwe
parents: 5667
diff changeset
4656
d090d39bb82c [project @ 2006-04-05 06:56:24 by jwe]
jwe
parents: 5667
diff changeset
4657 if (nargin > 1)
20798
bb585db6dee2 eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
4658 print_usage ();
5739
d090d39bb82c [project @ 2006-04-05 06:56:24 by jwe]
jwe
parents: 5667
diff changeset
4659
d090d39bb82c [project @ 2006-04-05 06:56:24 by jwe]
jwe
parents: 5667
diff changeset
4660 std::string arg;
d090d39bb82c [project @ 2006-04-05 06:56:24 by jwe]
jwe
parents: 5667
diff changeset
4661
d090d39bb82c [project @ 2006-04-05 06:56:24 by jwe]
jwe
parents: 5667
diff changeset
4662 if (nargin == 1)
20700
68e3a747ca02 rename octave_value value extractors that accept error message args
John W. Eaton <jwe@octave.org>
parents: 20666
diff changeset
4663 arg = args(0).xstring_value ("mfilename: expecting argument to be a character string");
5739
d090d39bb82c [project @ 2006-04-05 06:56:24 by jwe]
jwe
parents: 5667
diff changeset
4664
d090d39bb82c [project @ 2006-04-05 06:56:24 by jwe]
jwe
parents: 5667
diff changeset
4665 std::string fname;
d090d39bb82c [project @ 2006-04-05 06:56:24 by jwe]
jwe
parents: 5667
diff changeset
4666
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
4667 octave_user_code *fcn = octave_call_stack::caller_user_code ();
5743
a527e0f77aa5 [project @ 2006-04-06 08:20:21 by jwe]
jwe
parents: 5739
diff changeset
4668
a527e0f77aa5 [project @ 2006-04-06 08:20:21 by jwe]
jwe
parents: 5739
diff changeset
4669 if (fcn)
a527e0f77aa5 [project @ 2006-04-06 08:20:21 by jwe]
jwe
parents: 5739
diff changeset
4670 {
a527e0f77aa5 [project @ 2006-04-06 08:20:21 by jwe]
jwe
parents: 5739
diff changeset
4671 fname = fcn->fcn_file_name ();
a527e0f77aa5 [project @ 2006-04-06 08:20:21 by jwe]
jwe
parents: 5739
diff changeset
4672
a527e0f77aa5 [project @ 2006-04-06 08:20:21 by jwe]
jwe
parents: 5739
diff changeset
4673 if (fname.empty ())
a527e0f77aa5 [project @ 2006-04-06 08:20:21 by jwe]
jwe
parents: 5739
diff changeset
4674 fname = fcn->name ();
a527e0f77aa5 [project @ 2006-04-06 08:20:21 by jwe]
jwe
parents: 5739
diff changeset
4675 }
5739
d090d39bb82c [project @ 2006-04-05 06:56:24 by jwe]
jwe
parents: 5667
diff changeset
4676
d090d39bb82c [project @ 2006-04-05 06:56:24 by jwe]
jwe
parents: 5667
diff changeset
4677 if (arg == "fullpathext")
d090d39bb82c [project @ 2006-04-05 06:56:24 by jwe]
jwe
parents: 5667
diff changeset
4678 retval = fname;
d090d39bb82c [project @ 2006-04-05 06:56:24 by jwe]
jwe
parents: 5667
diff changeset
4679 else
d090d39bb82c [project @ 2006-04-05 06:56:24 by jwe]
jwe
parents: 5667
diff changeset
4680 {
8007
a2ab20ba78f7 make file_ops a proper singleton class
John W. Eaton <jwe@octave.org>
parents: 8001
diff changeset
4681 size_t dpos = fname.rfind (file_ops::dir_sep_char ());
5747
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5744
diff changeset
4682 size_t epos = fname.rfind ('.');
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5744
diff changeset
4683
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5744
diff changeset
4684 if (epos <= dpos)
8021
85184151822e fix typo in NPOS change
John W. Eaton <jwe@octave.org>
parents: 8019
diff changeset
4685 epos = std::string::npos;
85184151822e fix typo in NPOS change
John W. Eaton <jwe@octave.org>
parents: 8019
diff changeset
4686
85184151822e fix typo in NPOS change
John W. Eaton <jwe@octave.org>
parents: 8019
diff changeset
4687 fname = (epos != std::string::npos) ? fname.substr (0, epos) : fname;
5739
d090d39bb82c [project @ 2006-04-05 06:56:24 by jwe]
jwe
parents: 5667
diff changeset
4688
d090d39bb82c [project @ 2006-04-05 06:56:24 by jwe]
jwe
parents: 5667
diff changeset
4689 if (arg == "fullpath")
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
4690 retval = fname;
5739
d090d39bb82c [project @ 2006-04-05 06:56:24 by jwe]
jwe
parents: 5667
diff changeset
4691 else
8021
85184151822e fix typo in NPOS change
John W. Eaton <jwe@octave.org>
parents: 8019
diff changeset
4692 retval = (dpos != std::string::npos) ? fname.substr (dpos+1) : fname;
5739
d090d39bb82c [project @ 2006-04-05 06:56:24 by jwe]
jwe
parents: 5667
diff changeset
4693 }
d090d39bb82c [project @ 2006-04-05 06:56:24 by jwe]
jwe
parents: 5667
diff changeset
4694
d090d39bb82c [project @ 2006-04-05 06:56:24 by jwe]
jwe
parents: 5667
diff changeset
4695 return retval;
d090d39bb82c [project @ 2006-04-05 06:56:24 by jwe]
jwe
parents: 5667
diff changeset
4696 }
d090d39bb82c [project @ 2006-04-05 06:56:24 by jwe]
jwe
parents: 5667
diff changeset
4697
3021
18d64612e67a [project @ 1997-06-03 22:18:56 by jwe]
jwe
parents: 3016
diff changeset
4698 DEFUN (source, args, ,
3371
86873384cd10 [project @ 1999-11-21 17:31:07 by jwe]
jwe
parents: 3366
diff changeset
4699 "-*- texinfo -*-\n\
20895
7697a3433e37 doc: Remove class of function from docstring from generated C++ files.
Rik <rik@octave.org>
parents: 20818
diff changeset
4700 @deftypefn {} {} source (@var{file})\n\
18531
04b4fb217b1a doc: Improve documentation strings in parse-tree directory.
Rik <rik@octave.org>
parents: 17796
diff changeset
4701 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
4702 \n\
04b4fb217b1a doc: Improve documentation strings in parse-tree directory.
Rik <rik@octave.org>
parents: 17796
diff changeset
4703 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
4704 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
4705 @seealso{run}\n\
3371
86873384cd10 [project @ 1999-11-21 17:31:07 by jwe]
jwe
parents: 3366
diff changeset
4706 @end deftypefn")
3021
18d64612e67a [project @ 1997-06-03 22:18:56 by jwe]
jwe
parents: 3016
diff changeset
4707 {
18d64612e67a [project @ 1997-06-03 22:18:56 by jwe]
jwe
parents: 3016
diff changeset
4708 octave_value_list retval;
18d64612e67a [project @ 1997-06-03 22:18:56 by jwe]
jwe
parents: 3016
diff changeset
4709
18d64612e67a [project @ 1997-06-03 22:18:56 by jwe]
jwe
parents: 3016
diff changeset
4710 int nargin = args.length ();
18d64612e67a [project @ 1997-06-03 22:18:56 by jwe]
jwe
parents: 3016
diff changeset
4711
20798
bb585db6dee2 eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
4712 if (nargin < 1 || nargin > 2)
5823
080c08b192d8 [project @ 2006-05-19 05:32:17 by jwe]
jwe
parents: 5794
diff changeset
4713 print_usage ();
3021
18d64612e67a [project @ 1997-06-03 22:18:56 by jwe]
jwe
parents: 3016
diff changeset
4714
20798
bb585db6dee2 eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
4715 std::string file_name = args(0).xstring_value ("source: expecting filename as argument");
bb585db6dee2 eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
4716
bb585db6dee2 eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
4717 std::string context;
bb585db6dee2 eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
4718
bb585db6dee2 eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
4719 if (nargin == 2)
bb585db6dee2 eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
4720 context = args(1).xstring_value ("source: expecting context to be character string");
bb585db6dee2 eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
4721
bb585db6dee2 eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
4722 source_file (file_name, context);
bb585db6dee2 eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
4723
3021
18d64612e67a [project @ 1997-06-03 22:18:56 by jwe]
jwe
parents: 3016
diff changeset
4724 return retval;
18d64612e67a [project @ 1997-06-03 22:18:56 by jwe]
jwe
parents: 3016
diff changeset
4725 }
18d64612e67a [project @ 1997-06-03 22:18:56 by jwe]
jwe
parents: 3016
diff changeset
4726
3726
b7d997d593d9 [project @ 2000-10-27 17:51:21 by jwe]
jwe
parents: 3712
diff changeset
4727 // Evaluate an Octave function (built-in or interpreted) and return
3844
87f85453b6b7 [project @ 2001-07-23 20:07:45 by jwe]
jwe
parents: 3815
diff changeset
4728 // the list of result values. NAME is the name of the function to
87f85453b6b7 [project @ 2001-07-23 20:07:45 by jwe]
jwe
parents: 3815
diff changeset
4729 // 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
4730 // number of output arguments expected.
3726
b7d997d593d9 [project @ 2000-10-27 17:51:21 by jwe]
jwe
parents: 3712
diff changeset
4731
3021
18d64612e67a [project @ 1997-06-03 22:18:56 by jwe]
jwe
parents: 3016
diff changeset
4732 octave_value_list
3523
b80bbb43a1a9 [project @ 2000-02-02 10:25:52 by jwe]
jwe
parents: 3489
diff changeset
4733 feval (const std::string& name, const octave_value_list& args, int nargout)
3156
a494f93e60ff [project @ 1998-02-20 07:47:48 by jwe]
jwe
parents: 3110
diff changeset
4734 {
a494f93e60ff [project @ 1998-02-20 07:47:48 by jwe]
jwe
parents: 3110
diff changeset
4735 octave_value_list retval;
a494f93e60ff [project @ 1998-02-20 07:47:48 by jwe]
jwe
parents: 3110
diff changeset
4736
7336
745a8299c2b5 [project @ 2007-12-28 20:56:55 by jwe]
jwe
parents: 7017
diff changeset
4737 octave_value fcn = symbol_table::find_function (name, args);
745a8299c2b5 [project @ 2007-12-28 20:56:55 by jwe]
jwe
parents: 7017
diff changeset
4738
745a8299c2b5 [project @ 2007-12-28 20:56:55 by jwe]
jwe
parents: 7017
diff changeset
4739 if (fcn.is_defined ())
745a8299c2b5 [project @ 2007-12-28 20:56:55 by jwe]
jwe
parents: 7017
diff changeset
4740 retval = fcn.do_multi_index_op (nargout, args);
745a8299c2b5 [project @ 2007-12-28 20:56:55 by jwe]
jwe
parents: 7017
diff changeset
4741 else
10443
34e51d4e199b implement smart warnings about missing Matlab functionality
Jaroslav Hajek <highegg@gmail.com>
parents: 10426
diff changeset
4742 {
20547
52ce821a52fd eliminate simple uses of error_state in parser and lexer
John W. Eaton <jwe@octave.org>
parents: 20535
diff changeset
4743 try
52ce821a52fd eliminate simple uses of error_state in parser and lexer
John W. Eaton <jwe@octave.org>
parents: 20535
diff changeset
4744 {
52ce821a52fd eliminate simple uses of error_state in parser and lexer
John W. Eaton <jwe@octave.org>
parents: 20535
diff changeset
4745 maybe_missing_function_hook (name);
52ce821a52fd eliminate simple uses of error_state in parser and lexer
John W. Eaton <jwe@octave.org>
parents: 20535
diff changeset
4746 }
20785
b6f2909e7f94 always throw exception after debugging with debug_on_error
John W. Eaton <jwe@octave.org>
parents: 20769
diff changeset
4747 catch (octave_execution_exception& e)
20547
52ce821a52fd eliminate simple uses of error_state in parser and lexer
John W. Eaton <jwe@octave.org>
parents: 20535
diff changeset
4748 {
20756
200ae1d650b7 propagate octave_execution_exception objects through try/catch blocks
John W. Eaton <jwe@octave.org>
parents: 20713
diff changeset
4749 error (e, "feval: function '%s' not found", name.c_str ());
20547
52ce821a52fd eliminate simple uses of error_state in parser and lexer
John W. Eaton <jwe@octave.org>
parents: 20535
diff changeset
4750 }
10443
34e51d4e199b implement smart warnings about missing Matlab functionality
Jaroslav Hajek <highegg@gmail.com>
parents: 10426
diff changeset
4751 }
3156
a494f93e60ff [project @ 1998-02-20 07:47:48 by jwe]
jwe
parents: 3110
diff changeset
4752
a494f93e60ff [project @ 1998-02-20 07:47:48 by jwe]
jwe
parents: 3110
diff changeset
4753 return retval;
a494f93e60ff [project @ 1998-02-20 07:47:48 by jwe]
jwe
parents: 3110
diff changeset
4754 }
a494f93e60ff [project @ 1998-02-20 07:47:48 by jwe]
jwe
parents: 3110
diff changeset
4755
4342
813effe14ee1 [project @ 2003-02-20 08:35:55 by jwe]
jwe
parents: 4318
diff changeset
4756 octave_value_list
813effe14ee1 [project @ 2003-02-20 08:35:55 by jwe]
jwe
parents: 4318
diff changeset
4757 feval (octave_function *fcn, const octave_value_list& args, int nargout)
813effe14ee1 [project @ 2003-02-20 08:35:55 by jwe]
jwe
parents: 4318
diff changeset
4758 {
813effe14ee1 [project @ 2003-02-20 08:35:55 by jwe]
jwe
parents: 4318
diff changeset
4759 octave_value_list retval;
813effe14ee1 [project @ 2003-02-20 08:35:55 by jwe]
jwe
parents: 4318
diff changeset
4760
813effe14ee1 [project @ 2003-02-20 08:35:55 by jwe]
jwe
parents: 4318
diff changeset
4761 if (fcn)
813effe14ee1 [project @ 2003-02-20 08:35:55 by jwe]
jwe
parents: 4318
diff changeset
4762 retval = fcn->do_multi_index_op (nargout, args);
813effe14ee1 [project @ 2003-02-20 08:35:55 by jwe]
jwe
parents: 4318
diff changeset
4763
813effe14ee1 [project @ 2003-02-20 08:35:55 by jwe]
jwe
parents: 4318
diff changeset
4764 return retval;
813effe14ee1 [project @ 2003-02-20 08:35:55 by jwe]
jwe
parents: 4318
diff changeset
4765 }
813effe14ee1 [project @ 2003-02-20 08:35:55 by jwe]
jwe
parents: 4318
diff changeset
4766
813effe14ee1 [project @ 2003-02-20 08:35:55 by jwe]
jwe
parents: 4318
diff changeset
4767 static octave_value_list
813effe14ee1 [project @ 2003-02-20 08:35:55 by jwe]
jwe
parents: 4318
diff changeset
4768 get_feval_args (const octave_value_list& args)
813effe14ee1 [project @ 2003-02-20 08:35:55 by jwe]
jwe
parents: 4318
diff changeset
4769 {
10659
8baff2aceabc fix slicing value lists with name tags (bug #29960)
Jaroslav Hajek <highegg@gmail.com>
parents: 10578
diff changeset
4770 return args.slice (1, args.length () - 1, true);
4342
813effe14ee1 [project @ 2003-02-20 08:35:55 by jwe]
jwe
parents: 4318
diff changeset
4771 }
813effe14ee1 [project @ 2003-02-20 08:35:55 by jwe]
jwe
parents: 4318
diff changeset
4772
813effe14ee1 [project @ 2003-02-20 08:35:55 by jwe]
jwe
parents: 4318
diff changeset
4773
3726
b7d997d593d9 [project @ 2000-10-27 17:51:21 by jwe]
jwe
parents: 3712
diff changeset
4774 // Evaluate an Octave function (built-in or interpreted) and return
b7d997d593d9 [project @ 2000-10-27 17:51:21 by jwe]
jwe
parents: 3712
diff changeset
4775 // the list of result values. The first element of ARGS should be a
b7d997d593d9 [project @ 2000-10-27 17:51:21 by jwe]
jwe
parents: 3712
diff changeset
4776 // string containing the name of the function to call, then the rest
b7d997d593d9 [project @ 2000-10-27 17:51:21 by jwe]
jwe
parents: 3712
diff changeset
4777 // are the actual arguments to the function. NARGOUT is the number of
b7d997d593d9 [project @ 2000-10-27 17:51:21 by jwe]
jwe
parents: 3712
diff changeset
4778 // output arguments expected.
b7d997d593d9 [project @ 2000-10-27 17:51:21 by jwe]
jwe
parents: 3712
diff changeset
4779
3156
a494f93e60ff [project @ 1998-02-20 07:47:48 by jwe]
jwe
parents: 3110
diff changeset
4780 octave_value_list
3021
18d64612e67a [project @ 1997-06-03 22:18:56 by jwe]
jwe
parents: 3016
diff changeset
4781 feval (const octave_value_list& args, int nargout)
18d64612e67a [project @ 1997-06-03 22:18:56 by jwe]
jwe
parents: 3016
diff changeset
4782 {
18d64612e67a [project @ 1997-06-03 22:18:56 by jwe]
jwe
parents: 3016
diff changeset
4783 octave_value_list retval;
18d64612e67a [project @ 1997-06-03 22:18:56 by jwe]
jwe
parents: 3016
diff changeset
4784
20818
cef0448a6ed2 eliminate unnecessary uses of nargin
John W. Eaton <jwe@octave.org>
parents: 20798
diff changeset
4785 if (args.length () > 0)
3021
18d64612e67a [project @ 1997-06-03 22:18:56 by jwe]
jwe
parents: 3016
diff changeset
4786 {
4342
813effe14ee1 [project @ 2003-02-20 08:35:55 by jwe]
jwe
parents: 4318
diff changeset
4787 octave_value f_arg = args(0);
813effe14ee1 [project @ 2003-02-20 08:35:55 by jwe]
jwe
parents: 4318
diff changeset
4788
813effe14ee1 [project @ 2003-02-20 08:35:55 by jwe]
jwe
parents: 4318
diff changeset
4789 if (f_arg.is_string ())
813effe14ee1 [project @ 2003-02-20 08:35:55 by jwe]
jwe
parents: 4318
diff changeset
4790 {
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
4791 std::string name = f_arg.string_value ();
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
4792
20547
52ce821a52fd eliminate simple uses of error_state in parser and lexer
John W. Eaton <jwe@octave.org>
parents: 20535
diff changeset
4793 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: 20535
diff changeset
4794
52ce821a52fd eliminate simple uses of error_state in parser and lexer
John W. Eaton <jwe@octave.org>
parents: 20535
diff changeset
4795 retval = feval (name, tmp_args, nargout);
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
4796 }
13241
2a8dcb5b3a00 improve default indexing for objects
John W. Eaton <jwe@octave.org>
parents: 13237
diff changeset
4797 else if (f_arg.is_function_handle ()
2a8dcb5b3a00 improve default indexing for objects
John W. Eaton <jwe@octave.org>
parents: 13237
diff changeset
4798 || f_arg.is_anonymous_function ()
2a8dcb5b3a00 improve default indexing for objects
John W. Eaton <jwe@octave.org>
parents: 13237
diff changeset
4799 || f_arg.is_inline_function ())
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
4800 {
10492
a6b64a7a3769 make feval work with overloaded handles
Jaroslav Hajek <highegg@gmail.com>
parents: 10463
diff changeset
4801 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
4802
a6b64a7a3769 make feval work with overloaded handles
Jaroslav Hajek <highegg@gmail.com>
parents: 10463
diff changeset
4803 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
4804 }
10492
a6b64a7a3769 make feval work with overloaded handles
Jaroslav Hajek <highegg@gmail.com>
parents: 10463
diff changeset
4805 else
a6b64a7a3769 make feval work with overloaded handles
Jaroslav Hajek <highegg@gmail.com>
parents: 10463
diff changeset
4806 error ("feval: first argument must be a string, inline function or a function handle");
3021
18d64612e67a [project @ 1997-06-03 22:18:56 by jwe]
jwe
parents: 3016
diff changeset
4807 }
18d64612e67a [project @ 1997-06-03 22:18:56 by jwe]
jwe
parents: 3016
diff changeset
4808
18d64612e67a [project @ 1997-06-03 22:18:56 by jwe]
jwe
parents: 3016
diff changeset
4809 return retval;
18d64612e67a [project @ 1997-06-03 22:18:56 by jwe]
jwe
parents: 3016
diff changeset
4810 }
18d64612e67a [project @ 1997-06-03 22:18:56 by jwe]
jwe
parents: 3016
diff changeset
4811
18d64612e67a [project @ 1997-06-03 22:18:56 by jwe]
jwe
parents: 3016
diff changeset
4812 DEFUN (feval, args, nargout,
3371
86873384cd10 [project @ 1999-11-21 17:31:07 by jwe]
jwe
parents: 3366
diff changeset
4813 "-*- texinfo -*-\n\
20895
7697a3433e37 doc: Remove class of function from docstring from generated C++ files.
Rik <rik@octave.org>
parents: 20818
diff changeset
4814 @deftypefn {} {} feval (@var{name}, @dots{})\n\
20163
075a5e2e1ba5 doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents: 20075
diff changeset
4815 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: 20075
diff changeset
4816 \n\
075a5e2e1ba5 doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents: 20075
diff changeset
4817 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: 20075
diff changeset
4818 For example,\n\
3371
86873384cd10 [project @ 1999-11-21 17:31:07 by jwe]
jwe
parents: 3366
diff changeset
4819 \n\
86873384cd10 [project @ 1999-11-21 17:31:07 by jwe]
jwe
parents: 3366
diff changeset
4820 @example\n\
11572
7d6d8c1e471f Grammarcheck Texinfo for files in src directory.
Rik <octave@nomad.inbox5.com>
parents: 11523
diff changeset
4821 @group\n\
3371
86873384cd10 [project @ 1999-11-21 17:31:07 by jwe]
jwe
parents: 3366
diff changeset
4822 feval (\"acos\", -1)\n\
86873384cd10 [project @ 1999-11-21 17:31:07 by jwe]
jwe
parents: 3366
diff changeset
4823 @result{} 3.1416\n\
11572
7d6d8c1e471f Grammarcheck Texinfo for files in src directory.
Rik <octave@nomad.inbox5.com>
parents: 11523
diff changeset
4824 @end group\n\
3371
86873384cd10 [project @ 1999-11-21 17:31:07 by jwe]
jwe
parents: 3366
diff changeset
4825 @end example\n\
3021
18d64612e67a [project @ 1997-06-03 22:18:56 by jwe]
jwe
parents: 3016
diff changeset
4826 \n\
3371
86873384cd10 [project @ 1999-11-21 17:31:07 by jwe]
jwe
parents: 3366
diff changeset
4827 @noindent\n\
86873384cd10 [project @ 1999-11-21 17:31:07 by jwe]
jwe
parents: 3366
diff changeset
4828 calls the function @code{acos} with the argument @samp{-1}.\n\
86873384cd10 [project @ 1999-11-21 17:31:07 by jwe]
jwe
parents: 3366
diff changeset
4829 \n\
20163
075a5e2e1ba5 doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents: 20075
diff changeset
4830 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: 20075
diff changeset
4831 (@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: 20075
diff changeset
4832 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: 20075
diff changeset
4833 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
4834 \n\
8b5b85e26246 octave-parse.yy (feval): Update docstring to refer to function handles.
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents: 12918
diff changeset
4835 @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
4836 @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
4837 @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
4838 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
4839 @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
4840 @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
4841 @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
4842 @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
4843 @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
4844 \n\
8b5b85e26246 octave-parse.yy (feval): Update docstring to refer to function handles.
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents: 12918
diff changeset
4845 @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
4846 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
4847 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
4848 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
4849 instead.\n\
3371
86873384cd10 [project @ 1999-11-21 17:31:07 by jwe]
jwe
parents: 3366
diff changeset
4850 @end deftypefn")
3021
18d64612e67a [project @ 1997-06-03 22:18:56 by jwe]
jwe
parents: 3016
diff changeset
4851 {
20818
cef0448a6ed2 eliminate unnecessary uses of nargin
John W. Eaton <jwe@octave.org>
parents: 20798
diff changeset
4852 if (args.length () == 0)
5823
080c08b192d8 [project @ 2006-05-19 05:32:17 by jwe]
jwe
parents: 5794
diff changeset
4853 print_usage ();
3021
18d64612e67a [project @ 1997-06-03 22:18:56 by jwe]
jwe
parents: 3016
diff changeset
4854
20798
bb585db6dee2 eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
4855 return feval (args, nargout);
3021
18d64612e67a [project @ 1997-06-03 22:18:56 by jwe]
jwe
parents: 3016
diff changeset
4856 }
18d64612e67a [project @ 1997-06-03 22:18:56 by jwe]
jwe
parents: 3016
diff changeset
4857
11225
8d8e10058df6 move builtin function from dispatch.cc to oct-parse.yy
John W. Eaton <jwe@octave.org>
parents: 11138
diff changeset
4858 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
4859 "-*- texinfo -*-\n\
20895
7697a3433e37 doc: Remove class of function from docstring from generated C++ files.
Rik <rik@octave.org>
parents: 20818
diff changeset
4860 @deftypefn {} {[@dots{}] =} builtin (@var{f}, @dots{})\n\
20163
075a5e2e1ba5 doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents: 20075
diff changeset
4861 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: 20075
diff changeset
4862 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
4863 \n\
20163
075a5e2e1ba5 doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents: 20075
diff changeset
4864 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: 20075
diff changeset
4865 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: 20075
diff changeset
4866 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
4867 \n\
2f63d2f3ff11 doc: Update docstrings in oct-parse.in.yy.
Rik <rik@octave.org>
parents: 16681
diff changeset
4868 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
4869 @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
4870 \n\
2f63d2f3ff11 doc: Update docstrings in oct-parse.in.yy.
Rik <rik@octave.org>
parents: 16681
diff changeset
4871 @example\n\
2f63d2f3ff11 doc: Update docstrings in oct-parse.in.yy.
Rik <rik@octave.org>
parents: 16681
diff changeset
4872 @group\n\
2f63d2f3ff11 doc: Update docstrings in oct-parse.in.yy.
Rik <rik@octave.org>
parents: 16681
diff changeset
4873 sin (0)\n\
2f63d2f3ff11 doc: Update docstrings in oct-parse.in.yy.
Rik <rik@octave.org>
parents: 16681
diff changeset
4874 @result{} 0\n\
2f63d2f3ff11 doc: Update docstrings in oct-parse.in.yy.
Rik <rik@octave.org>
parents: 16681
diff changeset
4875 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
4876 sin (0)\n\
2f63d2f3ff11 doc: Update docstrings in oct-parse.in.yy.
Rik <rik@octave.org>
parents: 16681
diff changeset
4877 @result{} 1\n\
2f63d2f3ff11 doc: Update docstrings in oct-parse.in.yy.
Rik <rik@octave.org>
parents: 16681
diff changeset
4878 builtin (\"sin\", 0)\n\
2f63d2f3ff11 doc: Update docstrings in oct-parse.in.yy.
Rik <rik@octave.org>
parents: 16681
diff changeset
4879 @result{} 0\n\
2f63d2f3ff11 doc: Update docstrings in oct-parse.in.yy.
Rik <rik@octave.org>
parents: 16681
diff changeset
4880 @end group\n\
2f63d2f3ff11 doc: Update docstrings in oct-parse.in.yy.
Rik <rik@octave.org>
parents: 16681
diff changeset
4881 @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
4882 @end deftypefn")
8d8e10058df6 move builtin function from dispatch.cc to oct-parse.yy
John W. Eaton <jwe@octave.org>
parents: 11138
diff changeset
4883 {
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11572
diff changeset
4884 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
4885
20818
cef0448a6ed2 eliminate unnecessary uses of nargin
John W. Eaton <jwe@octave.org>
parents: 20798
diff changeset
4886 if (args.length () == 0)
20798
bb585db6dee2 eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
4887 print_usage ();
bb585db6dee2 eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
4888
bb585db6dee2 eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
4889 const std::string name (args(0).xstring_value ("builtin: function name (F) must be a string"));
bb585db6dee2 eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
4890
bb585db6dee2 eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
4891 octave_value fcn = symbol_table::builtin_find (name);
bb585db6dee2 eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
4892
bb585db6dee2 eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
4893 if (fcn.is_defined ())
bb585db6dee2 eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
4894 retval = feval (fcn.function_value (), args.splice (0, 1), nargout);
11225
8d8e10058df6 move builtin function from dispatch.cc to oct-parse.yy
John W. Eaton <jwe@octave.org>
parents: 11138
diff changeset
4895 else
20798
bb585db6dee2 eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
4896 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
4897
8d8e10058df6 move builtin function from dispatch.cc to oct-parse.yy
John W. Eaton <jwe@octave.org>
parents: 11138
diff changeset
4898 return retval;
8d8e10058df6 move builtin function from dispatch.cc to oct-parse.yy
John W. Eaton <jwe@octave.org>
parents: 11138
diff changeset
4899 }
8d8e10058df6 move builtin function from dispatch.cc to oct-parse.yy
John W. Eaton <jwe@octave.org>
parents: 11138
diff changeset
4900
3099
8ce6fed79320 [project @ 1997-11-14 09:49:28 by jwe]
jwe
parents: 3095
diff changeset
4901 octave_value_list
16195
b52d2f9294b6 use class for reading lexer input
John W. Eaton <jwe@octave.org>
parents: 16187
diff changeset
4902 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
4903 int& parse_status, int nargout)
3021
18d64612e67a [project @ 1997-06-03 22:18:56 by jwe]
jwe
parents: 3016
diff changeset
4904 {
3877
55648fc616c8 [project @ 2002-03-07 23:00:09 by jwe]
jwe
parents: 3844
diff changeset
4905 octave_value_list retval;
55648fc616c8 [project @ 2002-03-07 23:00:09 by jwe]
jwe
parents: 3844
diff changeset
4906
16288
fe3b9a51e625 rename curr_lexer, curr_parser, CURR_LEXER
John W. Eaton <jwe@octave.org>
parents: 16287
diff changeset
4907 octave_parser parser (eval_str);
16195
b52d2f9294b6 use class for reading lexer input
John W. Eaton <jwe@octave.org>
parents: 16187
diff changeset
4908
3877
55648fc616c8 [project @ 2002-03-07 23:00:09 by jwe]
jwe
parents: 3844
diff changeset
4909 do
55648fc616c8 [project @ 2002-03-07 23:00:09 by jwe]
jwe
parents: 3844
diff changeset
4910 {
16288
fe3b9a51e625 rename curr_lexer, curr_parser, CURR_LEXER
John W. Eaton <jwe@octave.org>
parents: 16287
diff changeset
4911 parser.reset ();
fe3b9a51e625 rename curr_lexer, curr_parser, CURR_LEXER
John W. Eaton <jwe@octave.org>
parents: 16287
diff changeset
4912
fe3b9a51e625 rename curr_lexer, curr_parser, CURR_LEXER
John W. Eaton <jwe@octave.org>
parents: 16287
diff changeset
4913 parse_status = parser.run ();
3877
55648fc616c8 [project @ 2002-03-07 23:00:09 by jwe]
jwe
parents: 3844
diff changeset
4914
3883
69b6bd271277 [project @ 2002-04-02 21:05:10 by jwe]
jwe
parents: 3881
diff changeset
4915 if (parse_status == 0)
3877
55648fc616c8 [project @ 2002-03-07 23:00:09 by jwe]
jwe
parents: 3844
diff changeset
4916 {
16288
fe3b9a51e625 rename curr_lexer, curr_parser, CURR_LEXER
John W. Eaton <jwe@octave.org>
parents: 16287
diff changeset
4917 if (parser.stmt_list)
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
4918 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
4919 tree_statement *stmt = 0;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
4920
16288
fe3b9a51e625 rename curr_lexer, curr_parser, CURR_LEXER
John W. Eaton <jwe@octave.org>
parents: 16287
diff changeset
4921 if (parser.stmt_list->length () == 1
fe3b9a51e625 rename curr_lexer, curr_parser, CURR_LEXER
John W. Eaton <jwe@octave.org>
parents: 16287
diff changeset
4922 && (stmt = parser.stmt_list->front ())
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
4923 && stmt->is_expression ())
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
4924 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
4925 tree_expression *expr = stmt->expression ();
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
4926
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
4927 if (silent)
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
4928 expr->set_print_flag (false);
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
4929
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
4930 bool do_bind_ans = false;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
4931
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
4932 if (expr->is_identifier ())
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
4933 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
4934 tree_identifier *id
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
4935 = dynamic_cast<tree_identifier *> (expr);
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
4936
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
4937 do_bind_ans = (! id->is_variable ());
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
4938 }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
4939 else
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
4940 do_bind_ans = (! expr->is_assignment_expression ());
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
4941
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
4942 retval = expr->rvalue (nargout);
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
4943
20547
52ce821a52fd eliminate simple uses of error_state in parser and lexer
John W. Eaton <jwe@octave.org>
parents: 20535
diff changeset
4944 if (do_bind_ans && ! retval.empty ())
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
4945 bind_ans (retval(0), expr->print_result ());
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
4946
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
4947 if (nargout == 0)
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
4948 retval = octave_value_list ();
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
4949 }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
4950 else if (nargout == 0)
16288
fe3b9a51e625 rename curr_lexer, curr_parser, CURR_LEXER
John W. Eaton <jwe@octave.org>
parents: 16287
diff changeset
4951 parser.stmt_list->accept (*current_evaluator);
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
4952 else
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
4953 error ("eval: invalid use of statement list");
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
4954
20547
52ce821a52fd eliminate simple uses of error_state in parser and lexer
John W. Eaton <jwe@octave.org>
parents: 20535
diff changeset
4955 if (tree_return_command::returning
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
4956 || tree_break_command::breaking
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
4957 || tree_continue_command::continuing)
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
4958 break;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
4959 }
16288
fe3b9a51e625 rename curr_lexer, curr_parser, CURR_LEXER
John W. Eaton <jwe@octave.org>
parents: 16287
diff changeset
4960 else if (parser.lexer.end_of_input)
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
4961 break;
3883
69b6bd271277 [project @ 2002-04-02 21:05:10 by jwe]
jwe
parents: 3881
diff changeset
4962 }
3877
55648fc616c8 [project @ 2002-03-07 23:00:09 by jwe]
jwe
parents: 3844
diff changeset
4963 }
55648fc616c8 [project @ 2002-03-07 23:00:09 by jwe]
jwe
parents: 3844
diff changeset
4964 while (parse_status == 0);
3021
18d64612e67a [project @ 1997-06-03 22:18:56 by jwe]
jwe
parents: 3016
diff changeset
4965
18d64612e67a [project @ 1997-06-03 22:18:56 by jwe]
jwe
parents: 3016
diff changeset
4966 return retval;
18d64612e67a [project @ 1997-06-03 22:18:56 by jwe]
jwe
parents: 3016
diff changeset
4967 }
18d64612e67a [project @ 1997-06-03 22:18:56 by jwe]
jwe
parents: 3016
diff changeset
4968
18d64612e67a [project @ 1997-06-03 22:18:56 by jwe]
jwe
parents: 3016
diff changeset
4969 octave_value
16195
b52d2f9294b6 use class for reading lexer input
John W. Eaton <jwe@octave.org>
parents: 16187
diff changeset
4970 eval_string (const std::string& eval_str, bool silent, int& parse_status)
3021
18d64612e67a [project @ 1997-06-03 22:18:56 by jwe]
jwe
parents: 3016
diff changeset
4971 {
18d64612e67a [project @ 1997-06-03 22:18:56 by jwe]
jwe
parents: 3016
diff changeset
4972 octave_value retval;
18d64612e67a [project @ 1997-06-03 22:18:56 by jwe]
jwe
parents: 3016
diff changeset
4973
16195
b52d2f9294b6 use class for reading lexer input
John W. Eaton <jwe@octave.org>
parents: 16187
diff changeset
4974 octave_value_list tmp = eval_string (eval_str, silent, parse_status, 1);
3021
18d64612e67a [project @ 1997-06-03 22:18:56 by jwe]
jwe
parents: 3016
diff changeset
4975
18d64612e67a [project @ 1997-06-03 22:18:56 by jwe]
jwe
parents: 3016
diff changeset
4976 if (! tmp.empty ())
18d64612e67a [project @ 1997-06-03 22:18:56 by jwe]
jwe
parents: 3016
diff changeset
4977 retval = tmp(0);
18d64612e67a [project @ 1997-06-03 22:18:56 by jwe]
jwe
parents: 3016
diff changeset
4978
18d64612e67a [project @ 1997-06-03 22:18:56 by jwe]
jwe
parents: 3016
diff changeset
4979 return retval;
18d64612e67a [project @ 1997-06-03 22:18:56 by jwe]
jwe
parents: 3016
diff changeset
4980 }
18d64612e67a [project @ 1997-06-03 22:18:56 by jwe]
jwe
parents: 3016
diff changeset
4981
18d64612e67a [project @ 1997-06-03 22:18:56 by jwe]
jwe
parents: 3016
diff changeset
4982 static octave_value_list
18d64612e67a [project @ 1997-06-03 22:18:56 by jwe]
jwe
parents: 3016
diff changeset
4983 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
4984 int nargout)
3021
18d64612e67a [project @ 1997-06-03 22:18:56 by jwe]
jwe
parents: 3016
diff changeset
4985 {
20700
68e3a747ca02 rename octave_value value extractors that accept error message args
John W. Eaton <jwe@octave.org>
parents: 20666
diff changeset
4986 std::string s = arg.xstring_value ("eval: expecting std::string argument");
3021
18d64612e67a [project @ 1997-06-03 22:18:56 by jwe]
jwe
parents: 3016
diff changeset
4987
18d64612e67a [project @ 1997-06-03 22:18:56 by jwe]
jwe
parents: 3016
diff changeset
4988 return eval_string (s, silent, parse_status, nargout);
18d64612e67a [project @ 1997-06-03 22:18:56 by jwe]
jwe
parents: 3016
diff changeset
4989 }
18d64612e67a [project @ 1997-06-03 22:18:56 by jwe]
jwe
parents: 3016
diff changeset
4990
13970
c93b953f7d54 plug some memory leaks
John W. Eaton <jwe@octave.org>
parents: 13844
diff changeset
4991 void
c93b953f7d54 plug some memory leaks
John W. Eaton <jwe@octave.org>
parents: 13844
diff changeset
4992 cleanup_statement_list (tree_statement_list **lst)
c93b953f7d54 plug some memory leaks
John W. Eaton <jwe@octave.org>
parents: 13844
diff changeset
4993 {
c93b953f7d54 plug some memory leaks
John W. Eaton <jwe@octave.org>
parents: 13844
diff changeset
4994 if (*lst)
c93b953f7d54 plug some memory leaks
John W. Eaton <jwe@octave.org>
parents: 13844
diff changeset
4995 {
c93b953f7d54 plug some memory leaks
John W. Eaton <jwe@octave.org>
parents: 13844
diff changeset
4996 delete *lst;
c93b953f7d54 plug some memory leaks
John W. Eaton <jwe@octave.org>
parents: 13844
diff changeset
4997 *lst = 0;
c93b953f7d54 plug some memory leaks
John W. Eaton <jwe@octave.org>
parents: 13844
diff changeset
4998 }
c93b953f7d54 plug some memory leaks
John W. Eaton <jwe@octave.org>
parents: 13844
diff changeset
4999 }
c93b953f7d54 plug some memory leaks
John W. Eaton <jwe@octave.org>
parents: 13844
diff changeset
5000
3021
18d64612e67a [project @ 1997-06-03 22:18:56 by jwe]
jwe
parents: 3016
diff changeset
5001 DEFUN (eval, args, nargout,
3371
86873384cd10 [project @ 1999-11-21 17:31:07 by jwe]
jwe
parents: 3366
diff changeset
5002 "-*- texinfo -*-\n\
20895
7697a3433e37 doc: Remove class of function from docstring from generated C++ files.
Rik <rik@octave.org>
parents: 20818
diff changeset
5003 @deftypefn {} {} eval (@var{try})\n\
7697a3433e37 doc: Remove class of function from docstring from generated C++ files.
Rik <rik@octave.org>
parents: 20818
diff changeset
5004 @deftypefnx {} {} eval (@var{try}, @var{catch})\n\
3371
86873384cd10 [project @ 1999-11-21 17:31:07 by jwe]
jwe
parents: 3366
diff changeset
5005 Parse the string @var{try} and evaluate it as if it were an Octave\n\
20163
075a5e2e1ba5 doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents: 20075
diff changeset
5006 program.\n\
075a5e2e1ba5 doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents: 20075
diff changeset
5007 \n\
075a5e2e1ba5 doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents: 20075
diff changeset
5008 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: 20075
diff changeset
5009 \n\
075a5e2e1ba5 doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents: 20075
diff changeset
5010 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: 20075
diff changeset
5011 remain available after @code{eval} returns.\n\
6643
6a7fc4105bcc [project @ 2007-05-21 20:37:43 by jwe]
jwe
parents: 6637
diff changeset
5012 \n\
18531
04b4fb217b1a doc: Improve documentation strings in parse-tree directory.
Rik <rik@octave.org>
parents: 17796
diff changeset
5013 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
5014 value of 3.1416 in the current workspace.\n\
6643
6a7fc4105bcc [project @ 2007-05-21 20:37:43 by jwe]
jwe
parents: 6637
diff changeset
5015 \n\
6a7fc4105bcc [project @ 2007-05-21 20:37:43 by jwe]
jwe
parents: 6637
diff changeset
5016 @example\n\
16789
2f63d2f3ff11 doc: Update docstrings in oct-parse.in.yy.
Rik <rik@octave.org>
parents: 16681
diff changeset
5017 eval (\"A = acos(-1);\");\n\
6643
6a7fc4105bcc [project @ 2007-05-21 20:37:43 by jwe]
jwe
parents: 6637
diff changeset
5018 @end example\n\
6a7fc4105bcc [project @ 2007-05-21 20:37:43 by jwe]
jwe
parents: 6637
diff changeset
5019 \n\
18531
04b4fb217b1a doc: Improve documentation strings in parse-tree directory.
Rik <rik@octave.org>
parents: 17796
diff changeset
5020 If an error occurs during the evaluation of @var{try} then the @var{catch}\n\
8828
8463d1a2e544 Doc fixes.
Brian Gough <bjg@network-theory.co.uk>
parents: 8819
diff changeset
5021 string is evaluated, as the following example shows:\n\
6643
6a7fc4105bcc [project @ 2007-05-21 20:37:43 by jwe]
jwe
parents: 6637
diff changeset
5022 \n\
6a7fc4105bcc [project @ 2007-05-21 20:37:43 by jwe]
jwe
parents: 6637
diff changeset
5023 @example\n\
11572
7d6d8c1e471f Grammarcheck Texinfo for files in src directory.
Rik <octave@nomad.inbox5.com>
parents: 11523
diff changeset
5024 @group\n\
6643
6a7fc4105bcc [project @ 2007-05-21 20:37:43 by jwe]
jwe
parents: 6637
diff changeset
5025 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
5026 'printf (\"This error occurred:\\n%s\\n\", lasterr ());');\n\
7001
8b0cfeb06365 [project @ 2007-10-10 18:02:59 by jwe]
jwe
parents: 6926
diff changeset
5027 @print{} This error occurred:\n\
8015
30629059b72d Update the manual to reflect the changes in error output
sh@sh-laptop
parents: 8007
diff changeset
5028 This is a bad example\n\
11572
7d6d8c1e471f Grammarcheck Texinfo for files in src directory.
Rik <octave@nomad.inbox5.com>
parents: 11523
diff changeset
5029 @end group\n\
6643
6a7fc4105bcc [project @ 2007-05-21 20:37:43 by jwe]
jwe
parents: 6637
diff changeset
5030 @end example\n\
14172
cba1c681f1b7 doc: Update seealso references for eval family of functions.
Rik <octave@nomad.inbox5.com>
parents: 14153
diff changeset
5031 \n\
18531
04b4fb217b1a doc: Improve documentation strings in parse-tree directory.
Rik <rik@octave.org>
parents: 17796
diff changeset
5032 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
5033 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
5034 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
5035 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
5036 the security considerations that the evaluation of arbitrary code does.\n\
21075
5ed379c8decd Add new function evalc to core.
Oliver Heimlich <oheim@posteo.de>
parents: 21073
diff changeset
5037 @seealso{evalin, evalc, assignin, feval}\n\
3371
86873384cd10 [project @ 1999-11-21 17:31:07 by jwe]
jwe
parents: 3366
diff changeset
5038 @end deftypefn")
3021
18d64612e67a [project @ 1997-06-03 22:18:56 by jwe]
jwe
parents: 3016
diff changeset
5039 {
18d64612e67a [project @ 1997-06-03 22:18:56 by jwe]
jwe
parents: 3016
diff changeset
5040 octave_value_list retval;
18d64612e67a [project @ 1997-06-03 22:18:56 by jwe]
jwe
parents: 3016
diff changeset
5041
18d64612e67a [project @ 1997-06-03 22:18:56 by jwe]
jwe
parents: 3016
diff changeset
5042 int nargin = args.length ();
18d64612e67a [project @ 1997-06-03 22:18:56 by jwe]
jwe
parents: 3016
diff changeset
5043
20798
bb585db6dee2 eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
5044 if (nargin == 0)
bb585db6dee2 eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
5045 print_usage ();
bb585db6dee2 eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
5046
bb585db6dee2 eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
5047 unwind_protect frame;
bb585db6dee2 eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
5048
bb585db6dee2 eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
5049 if (nargin > 1)
bb585db6dee2 eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
5050 {
bb585db6dee2 eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
5051 frame.protect_var (buffer_error_messages);
bb585db6dee2 eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
5052 buffer_error_messages++;
bb585db6dee2 eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
5053 }
bb585db6dee2 eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
5054
bb585db6dee2 eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
5055 int parse_status = 0;
bb585db6dee2 eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
5056
bb585db6dee2 eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
5057 bool execution_error = false;
bb585db6dee2 eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
5058
bb585db6dee2 eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
5059 octave_value_list tmp;
bb585db6dee2 eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
5060
bb585db6dee2 eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
5061 try
3021
18d64612e67a [project @ 1997-06-03 22:18:56 by jwe]
jwe
parents: 3016
diff changeset
5062 {
20798
bb585db6dee2 eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
5063 tmp = eval_string (args(0), nargout > 0, parse_status, nargout);
bb585db6dee2 eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
5064 }
bb585db6dee2 eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
5065 catch (const octave_execution_exception&)
bb585db6dee2 eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
5066 {
bb585db6dee2 eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
5067 recover_from_exception ();
bb585db6dee2 eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
5068
bb585db6dee2 eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
5069 execution_error = true;
bb585db6dee2 eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
5070 }
bb585db6dee2 eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
5071
bb585db6dee2 eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
5072 if (nargin > 1 && (parse_status != 0 || execution_error))
bb585db6dee2 eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
5073 {
bb585db6dee2 eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
5074 // Set up for letting the user print any messages from
bb585db6dee2 eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
5075 // errors that occurred in the first part of this eval().
bb585db6dee2 eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
5076
bb585db6dee2 eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
5077 buffer_error_messages--;
bb585db6dee2 eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
5078
bb585db6dee2 eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
5079 tmp = eval_string (args(1), nargout > 0, parse_status, nargout);
bb585db6dee2 eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
5080
bb585db6dee2 eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
5081 if (nargout > 0)
bb585db6dee2 eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
5082 retval = tmp;
3021
18d64612e67a [project @ 1997-06-03 22:18:56 by jwe]
jwe
parents: 3016
diff changeset
5083 }
18d64612e67a [project @ 1997-06-03 22:18:56 by jwe]
jwe
parents: 3016
diff changeset
5084 else
20798
bb585db6dee2 eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
5085 {
bb585db6dee2 eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
5086 if (nargout > 0)
bb585db6dee2 eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
5087 retval = tmp;
bb585db6dee2 eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
5088
bb585db6dee2 eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
5089 // FIXME: we should really be rethrowing whatever exception occurred,
bb585db6dee2 eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
5090 // not just throwing an execution exception.
bb585db6dee2 eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
5091 if (execution_error)
bb585db6dee2 eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
5092 octave_throw_execution_exception ();
bb585db6dee2 eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
5093 }
3021
18d64612e67a [project @ 1997-06-03 22:18:56 by jwe]
jwe
parents: 3016
diff changeset
5094
18d64612e67a [project @ 1997-06-03 22:18:56 by jwe]
jwe
parents: 3016
diff changeset
5095 return retval;
18d64612e67a [project @ 1997-06-03 22:18:56 by jwe]
jwe
parents: 3016
diff changeset
5096 }
18d64612e67a [project @ 1997-06-03 22:18:56 by jwe]
jwe
parents: 3016
diff changeset
5097
7562
c827f5673321 move tests to individual source files
John W. Eaton <jwe@octave.org>
parents: 7351
diff changeset
5098 /*
c827f5673321 move tests to individual source files
John W. Eaton <jwe@octave.org>
parents: 7351
diff changeset
5099
14084
5aba9fa234cf Modernize %!tests for eval()
Rik <octave@nomad.inbox5.com>
parents: 13970
diff changeset
5100 %!shared x
7562
c827f5673321 move tests to individual source files
John W. Eaton <jwe@octave.org>
parents: 7351
diff changeset
5101 %! x = 1;
14084
5aba9fa234cf Modernize %!tests for eval()
Rik <octave@nomad.inbox5.com>
parents: 13970
diff changeset
5102
5aba9fa234cf Modernize %!tests for eval()
Rik <octave@nomad.inbox5.com>
parents: 13970
diff changeset
5103 %!assert (eval ("x"), 1)
5aba9fa234cf Modernize %!tests for eval()
Rik <octave@nomad.inbox5.com>
parents: 13970
diff changeset
5104 %!assert (eval ("x;"))
21317
a4faec57f4c8 maint: remove semicolon after %!assert tests to follow Octave conventions.
Rik <rik@octave.org>
parents: 21301
diff changeset
5105 %!assert (eval ("x;"), 1)
14084
5aba9fa234cf Modernize %!tests for eval()
Rik <octave@nomad.inbox5.com>
parents: 13970
diff changeset
5106
7562
c827f5673321 move tests to individual source files
John W. Eaton <jwe@octave.org>
parents: 7351
diff changeset
5107 %!test
14084
5aba9fa234cf Modernize %!tests for eval()
Rik <octave@nomad.inbox5.com>
parents: 13970
diff changeset
5108 %! y = eval ("x");
5aba9fa234cf Modernize %!tests for eval()
Rik <octave@nomad.inbox5.com>
parents: 13970
diff changeset
5109 %! assert (y, 1);
5aba9fa234cf Modernize %!tests for eval()
Rik <octave@nomad.inbox5.com>
parents: 13970
diff changeset
5110
5aba9fa234cf Modernize %!tests for eval()
Rik <octave@nomad.inbox5.com>
parents: 13970
diff changeset
5111 %!test
5aba9fa234cf Modernize %!tests for eval()
Rik <octave@nomad.inbox5.com>
parents: 13970
diff changeset
5112 %! y = eval ("x;");
5aba9fa234cf Modernize %!tests for eval()
Rik <octave@nomad.inbox5.com>
parents: 13970
diff changeset
5113 %! assert (y, 1);
5aba9fa234cf Modernize %!tests for eval()
Rik <octave@nomad.inbox5.com>
parents: 13970
diff changeset
5114
5aba9fa234cf Modernize %!tests for eval()
Rik <octave@nomad.inbox5.com>
parents: 13970
diff changeset
5115 %!test
5aba9fa234cf Modernize %!tests for eval()
Rik <octave@nomad.inbox5.com>
parents: 13970
diff changeset
5116 %! eval ("x = 1;")
5aba9fa234cf Modernize %!tests for eval()
Rik <octave@nomad.inbox5.com>
parents: 13970
diff changeset
5117 %! assert (x,1);
5aba9fa234cf Modernize %!tests for eval()
Rik <octave@nomad.inbox5.com>
parents: 13970
diff changeset
5118
7562
c827f5673321 move tests to individual source files
John W. Eaton <jwe@octave.org>
parents: 7351
diff changeset
5119 %!test
c827f5673321 move tests to individual source files
John W. Eaton <jwe@octave.org>
parents: 7351
diff changeset
5120 %! eval ("flipud = 2;");
14084
5aba9fa234cf Modernize %!tests for eval()
Rik <octave@nomad.inbox5.com>
parents: 13970
diff changeset
5121 %! assert (flipud, 2);
5aba9fa234cf Modernize %!tests for eval()
Rik <octave@nomad.inbox5.com>
parents: 13970
diff changeset
5122
5aba9fa234cf Modernize %!tests for eval()
Rik <octave@nomad.inbox5.com>
parents: 13970
diff changeset
5123 %!function y = __f ()
7562
c827f5673321 move tests to individual source files
John W. Eaton <jwe@octave.org>
parents: 7351
diff changeset
5124 %! eval ("flipud = 2;");
c827f5673321 move tests to individual source files
John W. Eaton <jwe@octave.org>
parents: 7351
diff changeset
5125 %! y = flipud;
14084
5aba9fa234cf Modernize %!tests for eval()
Rik <octave@nomad.inbox5.com>
parents: 13970
diff changeset
5126 %!endfunction
5aba9fa234cf Modernize %!tests for eval()
Rik <octave@nomad.inbox5.com>
parents: 13970
diff changeset
5127 %!assert (__f(), 2)
7562
c827f5673321 move tests to individual source files
John W. Eaton <jwe@octave.org>
parents: 7351
diff changeset
5128
14533
e6aa044253eb Allow comma at the end of an assignment list (bug #35645)
Max Brister <max@2bass.com>
parents: 14512
diff changeset
5129 % bug #35645
e6aa044253eb Allow comma at the end of an assignment list (bug #35645)
Max Brister <max@2bass.com>
parents: 14512
diff changeset
5130 %!test
e6aa044253eb Allow comma at the end of an assignment list (bug #35645)
Max Brister <max@2bass.com>
parents: 14512
diff changeset
5131 %! [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
5132 %! [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
5133
7562
c827f5673321 move tests to individual source files
John W. Eaton <jwe@octave.org>
parents: 7351
diff changeset
5134 */
c827f5673321 move tests to individual source files
John W. Eaton <jwe@octave.org>
parents: 7351
diff changeset
5135
4661
12b6fbd57436 [project @ 2003-11-25 05:41:35 by jwe]
jwe
parents: 4615
diff changeset
5136 DEFUN (assignin, args, ,
4297
59a2ba0fb205 [project @ 2003-01-11 20:22:09 by jwe]
jwe
parents: 4246
diff changeset
5137 "-*- texinfo -*-\n\
20895
7697a3433e37 doc: Remove class of function from docstring from generated C++ files.
Rik <rik@octave.org>
parents: 20818
diff changeset
5138 @deftypefn {} {} assignin (@var{context}, @var{varname}, @var{value})\n\
4297
59a2ba0fb205 [project @ 2003-01-11 20:22:09 by jwe]
jwe
parents: 4246
diff changeset
5139 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
5140 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
5141 @seealso{evalin}\n\
4297
59a2ba0fb205 [project @ 2003-01-11 20:22:09 by jwe]
jwe
parents: 4246
diff changeset
5142 @end deftypefn")
59a2ba0fb205 [project @ 2003-01-11 20:22:09 by jwe]
jwe
parents: 4246
diff changeset
5143 {
59a2ba0fb205 [project @ 2003-01-11 20:22:09 by jwe]
jwe
parents: 4246
diff changeset
5144 octave_value_list retval;
59a2ba0fb205 [project @ 2003-01-11 20:22:09 by jwe]
jwe
parents: 4246
diff changeset
5145
20818
cef0448a6ed2 eliminate unnecessary uses of nargin
John W. Eaton <jwe@octave.org>
parents: 20798
diff changeset
5146 if (args.length () != 3)
20798
bb585db6dee2 eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
5147 print_usage ();
bb585db6dee2 eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
5148
bb585db6dee2 eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
5149 std::string context = args(0).xstring_value ("assignin: CONTEXT must be a string");
bb585db6dee2 eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
5150
bb585db6dee2 eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
5151 unwind_protect frame;
bb585db6dee2 eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
5152
bb585db6dee2 eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
5153 if (context == "caller")
bb585db6dee2 eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
5154 octave_call_stack::goto_caller_frame ();
bb585db6dee2 eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
5155 else if (context == "base")
bb585db6dee2 eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
5156 octave_call_stack::goto_base_frame ();
4297
59a2ba0fb205 [project @ 2003-01-11 20:22:09 by jwe]
jwe
parents: 4246
diff changeset
5157 else
20798
bb585db6dee2 eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
5158 error ("assignin: CONTEXT must be \"caller\" or \"base\"");
bb585db6dee2 eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
5159
bb585db6dee2 eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
5160 frame.add_fcn (octave_call_stack::pop);
bb585db6dee2 eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
5161
bb585db6dee2 eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
5162 std::string nm = args(1).xstring_value ("assignin: VARNAME must be a string");
bb585db6dee2 eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
5163
bb585db6dee2 eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
5164 if (valid_identifier (nm))
bb585db6dee2 eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
5165 symbol_table::assign (nm, args(2));
bb585db6dee2 eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
5166 else
bb585db6dee2 eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
5167 error ("assignin: invalid variable name in argument VARNAME");
4297
59a2ba0fb205 [project @ 2003-01-11 20:22:09 by jwe]
jwe
parents: 4246
diff changeset
5168
59a2ba0fb205 [project @ 2003-01-11 20:22:09 by jwe]
jwe
parents: 4246
diff changeset
5169 return retval;
59a2ba0fb205 [project @ 2003-01-11 20:22:09 by jwe]
jwe
parents: 4246
diff changeset
5170 }
59a2ba0fb205 [project @ 2003-01-11 20:22:09 by jwe]
jwe
parents: 4246
diff changeset
5171
4245
610671be8792 [project @ 2002-12-28 04:02:31 by jwe]
jwe
parents: 4244
diff changeset
5172 DEFUN (evalin, args, nargout,
610671be8792 [project @ 2002-12-28 04:02:31 by jwe]
jwe
parents: 4244
diff changeset
5173 "-*- texinfo -*-\n\
20895
7697a3433e37 doc: Remove class of function from docstring from generated C++ files.
Rik <rik@octave.org>
parents: 20818
diff changeset
5174 @deftypefn {} {} evalin (@var{context}, @var{try})\n\
7697a3433e37 doc: Remove class of function from docstring from generated C++ files.
Rik <rik@octave.org>
parents: 20818
diff changeset
5175 @deftypefnx {} {} evalin (@var{context}, @var{try}, @var{catch})\n\
20163
075a5e2e1ba5 doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents: 20075
diff changeset
5176 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: 20075
diff changeset
5177 @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
5178 @seealso{eval, assignin}\n\
4245
610671be8792 [project @ 2002-12-28 04:02:31 by jwe]
jwe
parents: 4244
diff changeset
5179 @end deftypefn")
610671be8792 [project @ 2002-12-28 04:02:31 by jwe]
jwe
parents: 4244
diff changeset
5180 {
610671be8792 [project @ 2002-12-28 04:02:31 by jwe]
jwe
parents: 4244
diff changeset
5181 octave_value_list retval;
610671be8792 [project @ 2002-12-28 04:02:31 by jwe]
jwe
parents: 4244
diff changeset
5182
610671be8792 [project @ 2002-12-28 04:02:31 by jwe]
jwe
parents: 4244
diff changeset
5183 int nargin = args.length ();
610671be8792 [project @ 2002-12-28 04:02:31 by jwe]
jwe
parents: 4244
diff changeset
5184
20798
bb585db6dee2 eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
5185 if (nargin < 2)
bb585db6dee2 eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
5186 print_usage ();
bb585db6dee2 eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
5187
bb585db6dee2 eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
5188 std::string context = args(0).xstring_value ("evalin: CONTEXT must be a string");
bb585db6dee2 eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
5189
bb585db6dee2 eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
5190 unwind_protect frame;
bb585db6dee2 eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
5191
bb585db6dee2 eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
5192 if (context == "caller")
bb585db6dee2 eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
5193 octave_call_stack::goto_caller_frame ();
bb585db6dee2 eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
5194 else if (context == "base")
bb585db6dee2 eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
5195 octave_call_stack::goto_base_frame ();
bb585db6dee2 eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
5196 else
bb585db6dee2 eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
5197 error ("evalin: CONTEXT must be \"caller\" or \"base\"");
bb585db6dee2 eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
5198
bb585db6dee2 eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
5199 frame.add_fcn (octave_call_stack::pop);
bb585db6dee2 eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
5200
bb585db6dee2 eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
5201 if (nargin > 2)
4245
610671be8792 [project @ 2002-12-28 04:02:31 by jwe]
jwe
parents: 4244
diff changeset
5202 {
20798
bb585db6dee2 eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
5203 frame.protect_var (buffer_error_messages);
bb585db6dee2 eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
5204 buffer_error_messages++;
bb585db6dee2 eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
5205 }
bb585db6dee2 eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
5206
bb585db6dee2 eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
5207 int parse_status = 0;
bb585db6dee2 eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
5208
bb585db6dee2 eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
5209 bool execution_error = false;
bb585db6dee2 eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
5210
bb585db6dee2 eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
5211 octave_value_list tmp;
bb585db6dee2 eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
5212
bb585db6dee2 eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
5213 try
bb585db6dee2 eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
5214 {
bb585db6dee2 eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
5215 tmp = eval_string (args(1), nargout > 0,
bb585db6dee2 eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
5216 parse_status, nargout);
bb585db6dee2 eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
5217 }
bb585db6dee2 eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
5218 catch (const octave_execution_exception&)
bb585db6dee2 eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
5219 {
bb585db6dee2 eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
5220 recover_from_exception ();
bb585db6dee2 eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
5221
bb585db6dee2 eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
5222 execution_error = true;
bb585db6dee2 eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
5223 }
bb585db6dee2 eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
5224
bb585db6dee2 eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
5225 if (nargin > 2 && (parse_status != 0 || execution_error))
bb585db6dee2 eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
5226 {
bb585db6dee2 eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
5227 // Set up for letting the user print any messages from
bb585db6dee2 eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
5228 // errors that occurred in the first part of this eval().
bb585db6dee2 eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
5229
bb585db6dee2 eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
5230 buffer_error_messages--;
bb585db6dee2 eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
5231
bb585db6dee2 eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
5232 tmp = eval_string (args(2), nargout > 0,
bb585db6dee2 eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
5233 parse_status, nargout);
bb585db6dee2 eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
5234
bb585db6dee2 eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
5235 retval = (nargout > 0) ? tmp : octave_value_list ();
4245
610671be8792 [project @ 2002-12-28 04:02:31 by jwe]
jwe
parents: 4244
diff changeset
5236 }
610671be8792 [project @ 2002-12-28 04:02:31 by jwe]
jwe
parents: 4244
diff changeset
5237 else
20798
bb585db6dee2 eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
5238 {
bb585db6dee2 eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
5239 if (nargout > 0)
bb585db6dee2 eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
5240 retval = tmp;
bb585db6dee2 eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
5241
bb585db6dee2 eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
5242 // FIXME: we should really be rethrowing whatever
bb585db6dee2 eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
5243 // exception occurred, not just throwing an
bb585db6dee2 eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
5244 // execution exception.
bb585db6dee2 eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
5245 if (execution_error)
bb585db6dee2 eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
5246 octave_throw_execution_exception ();
bb585db6dee2 eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
5247 }
4245
610671be8792 [project @ 2002-12-28 04:02:31 by jwe]
jwe
parents: 4244
diff changeset
5248
610671be8792 [project @ 2002-12-28 04:02:31 by jwe]
jwe
parents: 4244
diff changeset
5249 return retval;
610671be8792 [project @ 2002-12-28 04:02:31 by jwe]
jwe
parents: 4244
diff changeset
5250 }
610671be8792 [project @ 2002-12-28 04:02:31 by jwe]
jwe
parents: 4244
diff changeset
5251
21075
5ed379c8decd Add new function evalc to core.
Oliver Heimlich <oheim@posteo.de>
parents: 21073
diff changeset
5252 DEFUN (evalc, args, nargout,
5ed379c8decd Add new function evalc to core.
Oliver Heimlich <oheim@posteo.de>
parents: 21073
diff changeset
5253 "-*- texinfo -*-\n\
5ed379c8decd Add new function evalc to core.
Oliver Heimlich <oheim@posteo.de>
parents: 21073
diff changeset
5254 @deftypefn {} {@var{s} =} evalc (@var{try})\n\
5ed379c8decd Add new function evalc to core.
Oliver Heimlich <oheim@posteo.de>
parents: 21073
diff changeset
5255 @deftypefnx {} {@var{s} =} evalc (@var{try}, @var{catch})\n\
5ed379c8decd Add new function evalc to core.
Oliver Heimlich <oheim@posteo.de>
parents: 21073
diff changeset
5256 Parse and evaluate the string @var{try} as if it were an Octave program,\n\
5ed379c8decd Add new function evalc to core.
Oliver Heimlich <oheim@posteo.de>
parents: 21073
diff changeset
5257 while capturing the output into the return variable @var{s}.\n\
5ed379c8decd Add new function evalc to core.
Oliver Heimlich <oheim@posteo.de>
parents: 21073
diff changeset
5258 \n\
5ed379c8decd Add new function evalc to core.
Oliver Heimlich <oheim@posteo.de>
parents: 21073
diff changeset
5259 If execution fails, evaluate the optional string @var{catch}.\n\
5ed379c8decd Add new function evalc to core.
Oliver Heimlich <oheim@posteo.de>
parents: 21073
diff changeset
5260 \n\
5ed379c8decd Add new function evalc to core.
Oliver Heimlich <oheim@posteo.de>
parents: 21073
diff changeset
5261 This function behaves like @code{eval}, but any output or warning messages\n\
5ed379c8decd Add new function evalc to core.
Oliver Heimlich <oheim@posteo.de>
parents: 21073
diff changeset
5262 which would normally be written to the console are captured and returned in\n\
5ed379c8decd Add new function evalc to core.
Oliver Heimlich <oheim@posteo.de>
parents: 21073
diff changeset
5263 the string @var{s}.\n\
5ed379c8decd Add new function evalc to core.
Oliver Heimlich <oheim@posteo.de>
parents: 21073
diff changeset
5264 \n\
5ed379c8decd Add new function evalc to core.
Oliver Heimlich <oheim@posteo.de>
parents: 21073
diff changeset
5265 The @code{diary} is disabled during the execution of this function. When\n\
5ed379c8decd Add new function evalc to core.
Oliver Heimlich <oheim@posteo.de>
parents: 21073
diff changeset
5266 @code{system} is used, any output produced by external programs is @emph{not}\n\
5ed379c8decd Add new function evalc to core.
Oliver Heimlich <oheim@posteo.de>
parents: 21073
diff changeset
5267 captured, unless their output is captured by the @code{system} function\n\
5ed379c8decd Add new function evalc to core.
Oliver Heimlich <oheim@posteo.de>
parents: 21073
diff changeset
5268 itself.\n\
5ed379c8decd Add new function evalc to core.
Oliver Heimlich <oheim@posteo.de>
parents: 21073
diff changeset
5269 \n\
5ed379c8decd Add new function evalc to core.
Oliver Heimlich <oheim@posteo.de>
parents: 21073
diff changeset
5270 @example\n\
5ed379c8decd Add new function evalc to core.
Oliver Heimlich <oheim@posteo.de>
parents: 21073
diff changeset
5271 @group\n\
5ed379c8decd Add new function evalc to core.
Oliver Heimlich <oheim@posteo.de>
parents: 21073
diff changeset
5272 s = evalc (\"t = 42\"), t\n\
5ed379c8decd Add new function evalc to core.
Oliver Heimlich <oheim@posteo.de>
parents: 21073
diff changeset
5273 @result{} s = t = 42\n\
5ed379c8decd Add new function evalc to core.
Oliver Heimlich <oheim@posteo.de>
parents: 21073
diff changeset
5274 \n\
5ed379c8decd Add new function evalc to core.
Oliver Heimlich <oheim@posteo.de>
parents: 21073
diff changeset
5275 @result{} t = 42\n\
5ed379c8decd Add new function evalc to core.
Oliver Heimlich <oheim@posteo.de>
parents: 21073
diff changeset
5276 @end group\n\
5ed379c8decd Add new function evalc to core.
Oliver Heimlich <oheim@posteo.de>
parents: 21073
diff changeset
5277 @end example\n\
5ed379c8decd Add new function evalc to core.
Oliver Heimlich <oheim@posteo.de>
parents: 21073
diff changeset
5278 @seealso{eval, diary}\n\
5ed379c8decd Add new function evalc to core.
Oliver Heimlich <oheim@posteo.de>
parents: 21073
diff changeset
5279 @end deftypefn")
5ed379c8decd Add new function evalc to core.
Oliver Heimlich <oheim@posteo.de>
parents: 21073
diff changeset
5280 {
5ed379c8decd Add new function evalc to core.
Oliver Heimlich <oheim@posteo.de>
parents: 21073
diff changeset
5281 int nargin = args.length ();
5ed379c8decd Add new function evalc to core.
Oliver Heimlich <oheim@posteo.de>
parents: 21073
diff changeset
5282
5ed379c8decd Add new function evalc to core.
Oliver Heimlich <oheim@posteo.de>
parents: 21073
diff changeset
5283 if (nargin == 0 || nargin > 2)
5ed379c8decd Add new function evalc to core.
Oliver Heimlich <oheim@posteo.de>
parents: 21073
diff changeset
5284 print_usage ();
5ed379c8decd Add new function evalc to core.
Oliver Heimlich <oheim@posteo.de>
parents: 21073
diff changeset
5285
5ed379c8decd Add new function evalc to core.
Oliver Heimlich <oheim@posteo.de>
parents: 21073
diff changeset
5286 // redirect stdout/stderr to capturing buffer
5ed379c8decd Add new function evalc to core.
Oliver Heimlich <oheim@posteo.de>
parents: 21073
diff changeset
5287 std::ostringstream buffer;
5ed379c8decd Add new function evalc to core.
Oliver Heimlich <oheim@posteo.de>
parents: 21073
diff changeset
5288
5ed379c8decd Add new function evalc to core.
Oliver Heimlich <oheim@posteo.de>
parents: 21073
diff changeset
5289 std::ostream& out_stream = octave_stdout;
5ed379c8decd Add new function evalc to core.
Oliver Heimlich <oheim@posteo.de>
parents: 21073
diff changeset
5290 std::ostream& err_stream = std::cerr;
5ed379c8decd Add new function evalc to core.
Oliver Heimlich <oheim@posteo.de>
parents: 21073
diff changeset
5291
5ed379c8decd Add new function evalc to core.
Oliver Heimlich <oheim@posteo.de>
parents: 21073
diff changeset
5292 out_stream.flush ();
5ed379c8decd Add new function evalc to core.
Oliver Heimlich <oheim@posteo.de>
parents: 21073
diff changeset
5293 err_stream.flush ();
5ed379c8decd Add new function evalc to core.
Oliver Heimlich <oheim@posteo.de>
parents: 21073
diff changeset
5294
5ed379c8decd Add new function evalc to core.
Oliver Heimlich <oheim@posteo.de>
parents: 21073
diff changeset
5295 std::streambuf* old_out_buf = out_stream.rdbuf (buffer.rdbuf ());
5ed379c8decd Add new function evalc to core.
Oliver Heimlich <oheim@posteo.de>
parents: 21073
diff changeset
5296 std::streambuf* old_err_buf = err_stream.rdbuf (buffer.rdbuf ());
5ed379c8decd Add new function evalc to core.
Oliver Heimlich <oheim@posteo.de>
parents: 21073
diff changeset
5297
5ed379c8decd Add new function evalc to core.
Oliver Heimlich <oheim@posteo.de>
parents: 21073
diff changeset
5298
5ed379c8decd Add new function evalc to core.
Oliver Heimlich <oheim@posteo.de>
parents: 21073
diff changeset
5299 // call standard eval function
5ed379c8decd Add new function evalc to core.
Oliver Heimlich <oheim@posteo.de>
parents: 21073
diff changeset
5300 octave_value_list retval;
5ed379c8decd Add new function evalc to core.
Oliver Heimlich <oheim@posteo.de>
parents: 21073
diff changeset
5301 int eval_nargout = std::max (0, nargout - 1);
5ed379c8decd Add new function evalc to core.
Oliver Heimlich <oheim@posteo.de>
parents: 21073
diff changeset
5302
5ed379c8decd Add new function evalc to core.
Oliver Heimlich <oheim@posteo.de>
parents: 21073
diff changeset
5303 const octave_execution_exception* eval_exception = 0;
5ed379c8decd Add new function evalc to core.
Oliver Heimlich <oheim@posteo.de>
parents: 21073
diff changeset
5304 try
5ed379c8decd Add new function evalc to core.
Oliver Heimlich <oheim@posteo.de>
parents: 21073
diff changeset
5305 {
5ed379c8decd Add new function evalc to core.
Oliver Heimlich <oheim@posteo.de>
parents: 21073
diff changeset
5306 retval = Feval (args, eval_nargout);
5ed379c8decd Add new function evalc to core.
Oliver Heimlich <oheim@posteo.de>
parents: 21073
diff changeset
5307 }
5ed379c8decd Add new function evalc to core.
Oliver Heimlich <oheim@posteo.de>
parents: 21073
diff changeset
5308 catch (const octave_execution_exception& e)
5ed379c8decd Add new function evalc to core.
Oliver Heimlich <oheim@posteo.de>
parents: 21073
diff changeset
5309 {
5ed379c8decd Add new function evalc to core.
Oliver Heimlich <oheim@posteo.de>
parents: 21073
diff changeset
5310 // hold back exception from eval until we have restored streams
5ed379c8decd Add new function evalc to core.
Oliver Heimlich <oheim@posteo.de>
parents: 21073
diff changeset
5311 eval_exception = &e;
5ed379c8decd Add new function evalc to core.
Oliver Heimlich <oheim@posteo.de>
parents: 21073
diff changeset
5312 }
5ed379c8decd Add new function evalc to core.
Oliver Heimlich <oheim@posteo.de>
parents: 21073
diff changeset
5313
5ed379c8decd Add new function evalc to core.
Oliver Heimlich <oheim@posteo.de>
parents: 21073
diff changeset
5314 // stop capturing buffer and restore stdout/stderr
5ed379c8decd Add new function evalc to core.
Oliver Heimlich <oheim@posteo.de>
parents: 21073
diff changeset
5315 out_stream.flush ();
5ed379c8decd Add new function evalc to core.
Oliver Heimlich <oheim@posteo.de>
parents: 21073
diff changeset
5316 err_stream.flush ();
5ed379c8decd Add new function evalc to core.
Oliver Heimlich <oheim@posteo.de>
parents: 21073
diff changeset
5317
5ed379c8decd Add new function evalc to core.
Oliver Heimlich <oheim@posteo.de>
parents: 21073
diff changeset
5318 out_stream.rdbuf (old_out_buf);
5ed379c8decd Add new function evalc to core.
Oliver Heimlich <oheim@posteo.de>
parents: 21073
diff changeset
5319 err_stream.rdbuf (old_err_buf);
5ed379c8decd Add new function evalc to core.
Oliver Heimlich <oheim@posteo.de>
parents: 21073
diff changeset
5320
5ed379c8decd Add new function evalc to core.
Oliver Heimlich <oheim@posteo.de>
parents: 21073
diff changeset
5321 if (eval_exception)
5ed379c8decd Add new function evalc to core.
Oliver Heimlich <oheim@posteo.de>
parents: 21073
diff changeset
5322 {
5ed379c8decd Add new function evalc to core.
Oliver Heimlich <oheim@posteo.de>
parents: 21073
diff changeset
5323 // Print error message again, which was lost because of the stderr buffer
5ed379c8decd Add new function evalc to core.
Oliver Heimlich <oheim@posteo.de>
parents: 21073
diff changeset
5324 // Note: this keeps error_state and last_error_stack intact
5ed379c8decd Add new function evalc to core.
Oliver Heimlich <oheim@posteo.de>
parents: 21073
diff changeset
5325 message_with_id ("error", last_error_id ().c_str (),
5ed379c8decd Add new function evalc to core.
Oliver Heimlich <oheim@posteo.de>
parents: 21073
diff changeset
5326 last_error_message ().c_str ());
5ed379c8decd Add new function evalc to core.
Oliver Heimlich <oheim@posteo.de>
parents: 21073
diff changeset
5327 // rethrow original exception from above
5ed379c8decd Add new function evalc to core.
Oliver Heimlich <oheim@posteo.de>
parents: 21073
diff changeset
5328 throw *eval_exception;
5ed379c8decd Add new function evalc to core.
Oliver Heimlich <oheim@posteo.de>
parents: 21073
diff changeset
5329 }
5ed379c8decd Add new function evalc to core.
Oliver Heimlich <oheim@posteo.de>
parents: 21073
diff changeset
5330
5ed379c8decd Add new function evalc to core.
Oliver Heimlich <oheim@posteo.de>
parents: 21073
diff changeset
5331 retval.prepend (buffer.str ());
5ed379c8decd Add new function evalc to core.
Oliver Heimlich <oheim@posteo.de>
parents: 21073
diff changeset
5332 return retval;
5ed379c8decd Add new function evalc to core.
Oliver Heimlich <oheim@posteo.de>
parents: 21073
diff changeset
5333 }
5ed379c8decd Add new function evalc to core.
Oliver Heimlich <oheim@posteo.de>
parents: 21073
diff changeset
5334
5ed379c8decd Add new function evalc to core.
Oliver Heimlich <oheim@posteo.de>
parents: 21073
diff changeset
5335 /*
5ed379c8decd Add new function evalc to core.
Oliver Heimlich <oheim@posteo.de>
parents: 21073
diff changeset
5336
5ed379c8decd Add new function evalc to core.
Oliver Heimlich <oheim@posteo.de>
parents: 21073
diff changeset
5337 %!assert (evalc ("1"), "ans = 1\n")
5ed379c8decd Add new function evalc to core.
Oliver Heimlich <oheim@posteo.de>
parents: 21073
diff changeset
5338 %!assert (evalc ("1;"), "")
5ed379c8decd Add new function evalc to core.
Oliver Heimlich <oheim@posteo.de>
parents: 21073
diff changeset
5339
5ed379c8decd Add new function evalc to core.
Oliver Heimlich <oheim@posteo.de>
parents: 21073
diff changeset
5340 %!test
5ed379c8decd Add new function evalc to core.
Oliver Heimlich <oheim@posteo.de>
parents: 21073
diff changeset
5341 %! [s, y] = evalc ("1");
5ed379c8decd Add new function evalc to core.
Oliver Heimlich <oheim@posteo.de>
parents: 21073
diff changeset
5342 %! assert (s, "");
5ed379c8decd Add new function evalc to core.
Oliver Heimlich <oheim@posteo.de>
parents: 21073
diff changeset
5343 %! assert (y, 1);
5ed379c8decd Add new function evalc to core.
Oliver Heimlich <oheim@posteo.de>
parents: 21073
diff changeset
5344
5ed379c8decd Add new function evalc to core.
Oliver Heimlich <oheim@posteo.de>
parents: 21073
diff changeset
5345 %!test
5ed379c8decd Add new function evalc to core.
Oliver Heimlich <oheim@posteo.de>
parents: 21073
diff changeset
5346 %! [s, y] = evalc ("1;");
5ed379c8decd Add new function evalc to core.
Oliver Heimlich <oheim@posteo.de>
parents: 21073
diff changeset
5347 %! assert (s, "");
5ed379c8decd Add new function evalc to core.
Oliver Heimlich <oheim@posteo.de>
parents: 21073
diff changeset
5348 %! assert (y, 1);
5ed379c8decd Add new function evalc to core.
Oliver Heimlich <oheim@posteo.de>
parents: 21073
diff changeset
5349
5ed379c8decd Add new function evalc to core.
Oliver Heimlich <oheim@posteo.de>
parents: 21073
diff changeset
5350 %!test
5ed379c8decd Add new function evalc to core.
Oliver Heimlich <oheim@posteo.de>
parents: 21073
diff changeset
5351 %! assert (evalc ("y = 2"), "y = 2\n");
5ed379c8decd Add new function evalc to core.
Oliver Heimlich <oheim@posteo.de>
parents: 21073
diff changeset
5352 %! assert (y, 2);
5ed379c8decd Add new function evalc to core.
Oliver Heimlich <oheim@posteo.de>
parents: 21073
diff changeset
5353
5ed379c8decd Add new function evalc to core.
Oliver Heimlich <oheim@posteo.de>
parents: 21073
diff changeset
5354 %!test
5ed379c8decd Add new function evalc to core.
Oliver Heimlich <oheim@posteo.de>
parents: 21073
diff changeset
5355 %! assert (evalc ("y = 3;"), "");
5ed379c8decd Add new function evalc to core.
Oliver Heimlich <oheim@posteo.de>
parents: 21073
diff changeset
5356 %! assert (y, 3);
5ed379c8decd Add new function evalc to core.
Oliver Heimlich <oheim@posteo.de>
parents: 21073
diff changeset
5357
5ed379c8decd Add new function evalc to core.
Oliver Heimlich <oheim@posteo.de>
parents: 21073
diff changeset
5358 %!test
5ed379c8decd Add new function evalc to core.
Oliver Heimlich <oheim@posteo.de>
parents: 21073
diff changeset
5359 %! [s, a, b] = evalc ("deal (1, 2)");
5ed379c8decd Add new function evalc to core.
Oliver Heimlich <oheim@posteo.de>
parents: 21073
diff changeset
5360 %! assert (s, "");
5ed379c8decd Add new function evalc to core.
Oliver Heimlich <oheim@posteo.de>
parents: 21073
diff changeset
5361 %! assert (a, 1);
5ed379c8decd Add new function evalc to core.
Oliver Heimlich <oheim@posteo.de>
parents: 21073
diff changeset
5362 %! assert (b, 2);
5ed379c8decd Add new function evalc to core.
Oliver Heimlich <oheim@posteo.de>
parents: 21073
diff changeset
5363
5ed379c8decd Add new function evalc to core.
Oliver Heimlich <oheim@posteo.de>
parents: 21073
diff changeset
5364 %!function [a, b] = __f_evalc ()
5ed379c8decd Add new function evalc to core.
Oliver Heimlich <oheim@posteo.de>
parents: 21073
diff changeset
5365 %! printf ("foo");
5ed379c8decd Add new function evalc to core.
Oliver Heimlich <oheim@posteo.de>
parents: 21073
diff changeset
5366 %! fprintf (stdout, "bar");
5ed379c8decd Add new function evalc to core.
Oliver Heimlich <oheim@posteo.de>
parents: 21073
diff changeset
5367 %! disp (pi)
5ed379c8decd Add new function evalc to core.
Oliver Heimlich <oheim@posteo.de>
parents: 21073
diff changeset
5368 %! a = 1;
5ed379c8decd Add new function evalc to core.
Oliver Heimlich <oheim@posteo.de>
parents: 21073
diff changeset
5369 %! b = 2;
5ed379c8decd Add new function evalc to core.
Oliver Heimlich <oheim@posteo.de>
parents: 21073
diff changeset
5370 %!endfunction
5ed379c8decd Add new function evalc to core.
Oliver Heimlich <oheim@posteo.de>
parents: 21073
diff changeset
5371 %!test
5ed379c8decd Add new function evalc to core.
Oliver Heimlich <oheim@posteo.de>
parents: 21073
diff changeset
5372 %! [s, a, b] = evalc ("__f_evalc ()");
5ed379c8decd Add new function evalc to core.
Oliver Heimlich <oheim@posteo.de>
parents: 21073
diff changeset
5373 %! assert (s, "foobar 3.1416\n");
5ed379c8decd Add new function evalc to core.
Oliver Heimlich <oheim@posteo.de>
parents: 21073
diff changeset
5374 %! assert (a, 1);
5ed379c8decd Add new function evalc to core.
Oliver Heimlich <oheim@posteo.de>
parents: 21073
diff changeset
5375 %! assert (b, 2);
5ed379c8decd Add new function evalc to core.
Oliver Heimlich <oheim@posteo.de>
parents: 21073
diff changeset
5376
5ed379c8decd Add new function evalc to core.
Oliver Heimlich <oheim@posteo.de>
parents: 21073
diff changeset
5377 %!error <foo> (evalc ("error ('foo')"))
5ed379c8decd Add new function evalc to core.
Oliver Heimlich <oheim@posteo.de>
parents: 21073
diff changeset
5378 %!error <bar> (evalc ("error ('foo')", "error ('bar')"))
5ed379c8decd Add new function evalc to core.
Oliver Heimlich <oheim@posteo.de>
parents: 21073
diff changeset
5379
5ed379c8decd Add new function evalc to core.
Oliver Heimlich <oheim@posteo.de>
parents: 21073
diff changeset
5380 %!test
5ed379c8decd Add new function evalc to core.
Oliver Heimlich <oheim@posteo.de>
parents: 21073
diff changeset
5381 %! warning ("off", "quiet", "local");
5ed379c8decd Add new function evalc to core.
Oliver Heimlich <oheim@posteo.de>
parents: 21073
diff changeset
5382 %! assert (evalc ("warning ('foo')"), "warning: foo\n");
5ed379c8decd Add new function evalc to core.
Oliver Heimlich <oheim@posteo.de>
parents: 21073
diff changeset
5383
5ed379c8decd Add new function evalc to core.
Oliver Heimlich <oheim@posteo.de>
parents: 21073
diff changeset
5384 %!test
5ed379c8decd Add new function evalc to core.
Oliver Heimlich <oheim@posteo.de>
parents: 21073
diff changeset
5385 %! warning ("off", "quiet", "local");
5ed379c8decd Add new function evalc to core.
Oliver Heimlich <oheim@posteo.de>
parents: 21073
diff changeset
5386 %! assert (evalc ("error ('foo')", "warning ('bar')"), "warning: bar\n");
5ed379c8decd Add new function evalc to core.
Oliver Heimlich <oheim@posteo.de>
parents: 21073
diff changeset
5387
5ed379c8decd Add new function evalc to core.
Oliver Heimlich <oheim@posteo.de>
parents: 21073
diff changeset
5388 */
5ed379c8decd Add new function evalc to core.
Oliver Heimlich <oheim@posteo.de>
parents: 21073
diff changeset
5389
8311
7124bffc89c7 parse.y (F__parser_debug_flag__): New function.
John W. Eaton <jwe@octave.org>
parents: 8283
diff changeset
5390 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
5391 "-*- texinfo -*-\n\
20895
7697a3433e37 doc: Remove class of function from docstring from generated C++ files.
Rik <rik@octave.org>
parents: 20818
diff changeset
5392 @deftypefn {} {@var{val} =} __parser_debug_flag__ ()\n\
7697a3433e37 doc: Remove class of function from docstring from generated C++ files.
Rik <rik@octave.org>
parents: 20818
diff changeset
5393 @deftypefnx {} {@var{old_val} =} __parser_debug_flag__ (@var{new_val})\n\
18531
04b4fb217b1a doc: Improve documentation strings in parse-tree directory.
Rik <rik@octave.org>
parents: 17796
diff changeset
5394 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
5395 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
5396 @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
5397 @end deftypefn")
8311
7124bffc89c7 parse.y (F__parser_debug_flag__): New function.
John W. Eaton <jwe@octave.org>
parents: 8283
diff changeset
5398 {
7124bffc89c7 parse.y (F__parser_debug_flag__): New function.
John W. Eaton <jwe@octave.org>
parents: 8283
diff changeset
5399 octave_value retval;
7124bffc89c7 parse.y (F__parser_debug_flag__): New function.
John W. Eaton <jwe@octave.org>
parents: 8283
diff changeset
5400
7124bffc89c7 parse.y (F__parser_debug_flag__): New function.
John W. Eaton <jwe@octave.org>
parents: 8283
diff changeset
5401 bool debug_flag = octave_debug;
7124bffc89c7 parse.y (F__parser_debug_flag__): New function.
John W. Eaton <jwe@octave.org>
parents: 8283
diff changeset
5402
7124bffc89c7 parse.y (F__parser_debug_flag__): New function.
John W. Eaton <jwe@octave.org>
parents: 8283
diff changeset
5403 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
5404 "__parser_debug_flag__");
8311
7124bffc89c7 parse.y (F__parser_debug_flag__): New function.
John W. Eaton <jwe@octave.org>
parents: 8283
diff changeset
5405
7124bffc89c7 parse.y (F__parser_debug_flag__): New function.
John W. Eaton <jwe@octave.org>
parents: 8283
diff changeset
5406 octave_debug = debug_flag;
7124bffc89c7 parse.y (F__parser_debug_flag__): New function.
John W. Eaton <jwe@octave.org>
parents: 8283
diff changeset
5407
7124bffc89c7 parse.y (F__parser_debug_flag__): New function.
John W. Eaton <jwe@octave.org>
parents: 8283
diff changeset
5408 return retval;
7124bffc89c7 parse.y (F__parser_debug_flag__): New function.
John W. Eaton <jwe@octave.org>
parents: 8283
diff changeset
5409 }
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
5410
17377
15e2ad6372f7 maint: Tweaks to remove compiler warnings.
Rik <rik@octave.org>
parents: 17342
diff changeset
5411 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
5412 "-*- texinfo -*-\n\
20895
7697a3433e37 doc: Remove class of function from docstring from generated C++ files.
Rik <rik@octave.org>
parents: 20818
diff changeset
5413 @deftypefn {} {} __parse_file__ (@var{file}, @var{verbose})\n\
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
5414 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
5415 @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
5416 {
091e4df179de new function to help with debugging by parsing .m files without executing them
John W. Eaton <jwe@octave.org>
parents: 17326
diff changeset
5417 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
5418
091e4df179de new function to help with debugging by parsing .m files without executing them
John W. Eaton <jwe@octave.org>
parents: 17326
diff changeset
5419 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
5420
20798
bb585db6dee2 eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
5421 if (nargin < 1 || nargin > 2)
bb585db6dee2 eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
5422 print_usage ();
bb585db6dee2 eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
5423
bb585db6dee2 eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
5424 std::string file = args(0).xstring_value ("__parse_file__: expecting filename as argument");
bb585db6dee2 eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
5425
bb585db6dee2 eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
5426 std::string full_file = octave_env::make_absolute (file);
bb585db6dee2 eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
5427
bb585db6dee2 eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
5428 size_t file_len = file.length ();
bb585db6dee2 eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
5429
bb585db6dee2 eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
5430 if ((file_len > 4 && file.substr (file_len-4) == ".oct")
bb585db6dee2 eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
5431 || (file_len > 4 && file.substr (file_len-4) == ".mex")
bb585db6dee2 eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
5432 || (file_len > 2 && file.substr (file_len-2) == ".m"))
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
5433 {
20798
bb585db6dee2 eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
5434 file = octave_env::base_pathname (file);
bb585db6dee2 eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
5435 file = file.substr (0, file.find_last_of ('.'));
bb585db6dee2 eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
5436
bb585db6dee2 eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
5437 size_t pos = file.find_last_of (file_ops::dir_sep_str ());
bb585db6dee2 eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
5438 if (pos != std::string::npos)
bb585db6dee2 eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
5439 file = file.substr (pos+1);
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
5440 }
20798
bb585db6dee2 eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
5441
bb585db6dee2 eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
5442 if (nargin == 2)
bb585db6dee2 eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
5443 octave_stdout << "parsing " << full_file << std::endl;
bb585db6dee2 eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
5444
bb585db6dee2 eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
5445 octave_function *fcn = parse_fcn_file (full_file, file, "", "",
bb585db6dee2 eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
5446 true, false, false,
bb585db6dee2 eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
5447 false, "__parse_file__");
bb585db6dee2 eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
5448
bb585db6dee2 eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
5449 if (fcn)
bb585db6dee2 eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
5450 delete fcn;
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
5451
091e4df179de new function to help with debugging by parsing .m files without executing them
John W. Eaton <jwe@octave.org>
parents: 17326
diff changeset
5452 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
5453 }