annotate libinterp/parse-tree/oct-parse.in.yy @ 18127:d76f790b4eec gui-release

enable do_braindead_shortcircuit_evaluation by default and deprecate * octave.cc (maximum_braindamage): Don't call Fdo_brainded_shortcircuit_evaluation. * pt-exp.h (tree_expression::mark_braindead_shortcircuit): Eliminate file name argument. * pt-binop.h, pt-binop.cc (tree_binary_expression::mark_braindead_shortcircuit): Likewise. * oct-parse.in.yy (if_cmd_list1, elseif_clause, loop_command): Eliminate argument from call to mark_braindead_shortcircuit. * pt-binop.h, pt-binop.cc (Vdo_braindead_shortcircuit_evaluation): Initialize to true. (tree_binary_expression::matlab_style_short_circuit_warning): New function. (tree_binary_expression::rvalue1): Call matlab_style_short_circuit_warning if short circuit evaluation occurs. (Fdo_braindead_shortcircuit_evaluation): Display deprecated warning. Delete tests for do_braindead_shortcircuit_evaluation. (tree_binary_expression::braindead_shortcircuit_warning_issued): New member variable. * NEWS: Mention change in default value and deprecated function.
author John W. Eaton <jwe@octave.org>
date Wed, 11 Dec 2013 20:51:22 -0500
parents 6b51f5f44aea
children c7b68a11074b 4cf930a64fad
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
17744
d63878346099 maint: Update copyright notices for release.
John W. Eaton <jwe@octave.org>
parents: 17743
diff changeset
3 Copyright (C) 1993-2013 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
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
6
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
7 This file is part of Octave.
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
8
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
9 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
10 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
11 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
12 option) any later version.
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
13
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
14 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
15 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
16 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
17 for more details.
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
18
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
19 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
20 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
21 <http://www.gnu.org/licenses/>.
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
22
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 // Parser for Octave.
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
26
767
42731861ee09 [project @ 1994-10-05 21:26:54 by jwe]
jwe
parents: 751
diff changeset
27 // C decarations.
42731861ee09 [project @ 1994-10-05 21:26:54 by jwe]
jwe
parents: 751
diff changeset
28
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
29 %{
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
30 #define YYDEBUG 1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
31
240
a99f28f5e351 [project @ 1993-11-30 20:24:36 by jwe]
jwe
parents: 206
diff changeset
32 #ifdef HAVE_CONFIG_H
1229
7d7c3eaa1d3b [project @ 1995-04-10 01:04:13 by jwe]
jwe
parents: 1162
diff changeset
33 #include <config.h>
240
a99f28f5e351 [project @ 1993-11-30 20:24:36 by jwe]
jwe
parents: 206
diff changeset
34 #endif
a99f28f5e351 [project @ 1993-11-30 20:24:36 by jwe]
jwe
parents: 206
diff changeset
35
3178
09a3064a3a17 [project @ 1998-06-23 03:46:42 by jwe]
jwe
parents: 3165
diff changeset
36 #include <cassert>
10463
bbe99b2a5ba7 undo recent gnulib-related changes
John W. Eaton <jwe@octave.org>
parents: 10447
diff changeset
37 #include <cstdio>
bbe99b2a5ba7 undo recent gnulib-related changes
John W. Eaton <jwe@octave.org>
parents: 10447
diff changeset
38 #include <cstdlib>
2427
2f50b24ce84f [project @ 1996-10-25 06:15:28 by jwe]
jwe
parents: 2375
diff changeset
39
8950
d865363208d6 include <iosfwd> instead of <iostream> in header files
John W. Eaton <jwe@octave.org>
parents: 8920
diff changeset
40 #include <iostream>
5484
2ff5363a16bd [project @ 2005-10-06 17:12:12 by jwe]
jwe
parents: 5472
diff changeset
41 #include <map>
5765
7ba9ad1fec11 [project @ 2006-04-17 05:05:15 by jwe]
jwe
parents: 5760
diff changeset
42 #include <sstream>
5484
2ff5363a16bd [project @ 2005-10-06 17:12:12 by jwe]
jwe
parents: 5472
diff changeset
43
3928
e8627dc4bdf2 [project @ 2002-05-03 19:56:01 by jwe]
jwe
parents: 3903
diff changeset
44 #include "Cell.h"
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
45 #include "Matrix.h"
3021
18d64612e67a [project @ 1997-06-03 22:18:56 by jwe]
jwe
parents: 3016
diff changeset
46 #include "cmd-edit.h"
18d64612e67a [project @ 1997-06-03 22:18:56 by jwe]
jwe
parents: 3016
diff changeset
47 #include "cmd-hist.h"
18d64612e67a [project @ 1997-06-03 22:18:56 by jwe]
jwe
parents: 3016
diff changeset
48 #include "file-ops.h"
18d64612e67a [project @ 1997-06-03 22:18:56 by jwe]
jwe
parents: 3016
diff changeset
49 #include "file-stat.h"
4243
7e4d5b5520e5 [project @ 2002-12-27 05:30:59 by jwe]
jwe
parents: 4240
diff changeset
50 #include "oct-env.h"
3712
7066a8065e7e [project @ 2000-08-22 06:21:20 by jwe]
jwe
parents: 3665
diff changeset
51 #include "oct-time.h"
4171
04694e5b4239 [project @ 2002-11-12 20:27:24 by jwe]
jwe
parents: 4131
diff changeset
52 #include "quit.h"
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
53
3665
0689afb1d001 [project @ 2000-05-11 19:07:56 by jwe]
jwe
parents: 3544
diff changeset
54 #include "comment-list.h"
4243
7e4d5b5520e5 [project @ 2002-12-27 05:30:59 by jwe]
jwe
parents: 4240
diff changeset
55 #include "defaults.h"
2166
d68119516779 [project @ 1996-05-13 13:41:55 by jwe]
jwe
parents: 2124
diff changeset
56 #include "defun.h"
4243
7e4d5b5520e5 [project @ 2002-12-27 05:30:59 by jwe]
jwe
parents: 4240
diff changeset
57 #include "dirfns.h"
3021
18d64612e67a [project @ 1997-06-03 22:18:56 by jwe]
jwe
parents: 3016
diff changeset
58 #include "dynamic-ld.h"
1351
8256c4c57419 [project @ 1995-09-05 08:02:08 by jwe]
jwe
parents: 1315
diff changeset
59 #include "error.h"
8256c4c57419 [project @ 1995-09-05 08:02:08 by jwe]
jwe
parents: 1315
diff changeset
60 #include "input.h"
8256c4c57419 [project @ 1995-09-05 08:02:08 by jwe]
jwe
parents: 1315
diff changeset
61 #include "lex.h"
5832
5e41e06f6a78 [project @ 2006-05-26 21:41:32 by jwe]
jwe
parents: 5823
diff changeset
62 #include "load-path.h"
1743
ab8612a09449 [project @ 1996-01-12 11:25:30 by jwe]
jwe
parents: 1740
diff changeset
63 #include "oct-hist.h"
5626
3236b4d98fde [project @ 2006-02-15 20:25:39 by jwe]
jwe
parents: 5615
diff changeset
64 #include "oct-map.h"
4935
4fc993a4e072 [project @ 2004-08-06 03:17:12 by jwe]
jwe
parents: 4930
diff changeset
65 #include "ov-fcn-handle.h"
2970
b9e64477f703 [project @ 1997-05-15 18:04:21 by jwe]
jwe
parents: 2961
diff changeset
66 #include "ov-usr-fcn.h"
8150
283989f2da9b make null assignment matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents: 8064
diff changeset
67 #include "ov-null-mat.h"
1670
6708c53892c1 [project @ 1995-12-27 04:33:00 by jwe]
jwe
parents: 1623
diff changeset
68 #include "toplev.h"
1351
8256c4c57419 [project @ 1995-09-05 08:02:08 by jwe]
jwe
parents: 1315
diff changeset
69 #include "pager.h"
8256c4c57419 [project @ 1995-09-05 08:02:08 by jwe]
jwe
parents: 1315
diff changeset
70 #include "parse.h"
2987
ae20b3f37f5e [project @ 1997-05-16 07:05:15 by jwe]
jwe
parents: 2982
diff changeset
71 #include "pt-all.h"
8658
73c4516fae10 New evaluator and debugger derived from tree-walker class
John W. Eaton <jwe@octave.org>
parents: 8471
diff changeset
72 #include "pt-eval.h"
1351
8256c4c57419 [project @ 1995-09-05 08:02:08 by jwe]
jwe
parents: 1315
diff changeset
73 #include "symtab.h"
8256c4c57419 [project @ 1995-09-05 08:02:08 by jwe]
jwe
parents: 1315
diff changeset
74 #include "token.h"
3021
18d64612e67a [project @ 1997-06-03 22:18:56 by jwe]
jwe
parents: 3016
diff changeset
75 #include "unwind-prot.h"
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
76 #include "utils.h"
1351
8256c4c57419 [project @ 1995-09-05 08:02:08 by jwe]
jwe
parents: 1315
diff changeset
77 #include "variables.h"
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
78
16149
49dfba4fd3c5 use pure parser and reentrant lexer interfaces
John W. Eaton <jwe@octave.org>
parents: 16147
diff changeset
79 // oct-parse.h must be included after pt-all.h
49dfba4fd3c5 use pure parser and reentrant lexer interfaces
John W. Eaton <jwe@octave.org>
parents: 16147
diff changeset
80 #include <oct-parse.h>
49dfba4fd3c5 use pure parser and reentrant lexer interfaces
John W. Eaton <jwe@octave.org>
parents: 16147
diff changeset
81
49dfba4fd3c5 use pure parser and reentrant lexer interfaces
John W. Eaton <jwe@octave.org>
parents: 16147
diff changeset
82 extern int octave_lex (YYSTYPE *, void *);
49dfba4fd3c5 use pure parser and reentrant lexer interfaces
John W. Eaton <jwe@octave.org>
parents: 16147
diff changeset
83
49dfba4fd3c5 use pure parser and reentrant lexer interfaces
John W. Eaton <jwe@octave.org>
parents: 16147
diff changeset
84 // Global access to currently active lexer.
49dfba4fd3c5 use pure parser and reentrant lexer interfaces
John W. Eaton <jwe@octave.org>
parents: 16147
diff changeset
85 // FIXME -- to be removed after more parser+lexer refactoring.
16293
57e87ddfee14 create base class for lexer
John W. Eaton <jwe@octave.org>
parents: 16288
diff changeset
86 octave_base_lexer *LEXER = 0;
16149
49dfba4fd3c5 use pure parser and reentrant lexer interfaces
John W. Eaton <jwe@octave.org>
parents: 16147
diff changeset
87
10426
4db7beace28e oct-parse.yy, lex.ll: use symbols via gnulib namespace
John W. Eaton <jwe@octave.org>
parents: 10411
diff changeset
88 #if defined (GNULIB_NAMESPACE)
4db7beace28e oct-parse.yy, lex.ll: use symbols via gnulib namespace
John W. Eaton <jwe@octave.org>
parents: 10411
diff changeset
89 // Calls to the following functions appear in the generated output from
4db7beace28e oct-parse.yy, lex.ll: use symbols via gnulib namespace
John W. Eaton <jwe@octave.org>
parents: 10411
diff changeset
90 // Bison without the namespace tag. Redefine them so we will use them
4db7beace28e oct-parse.yy, lex.ll: use symbols via gnulib namespace
John W. Eaton <jwe@octave.org>
parents: 10411
diff changeset
91 // via the gnulib namespace.
4db7beace28e oct-parse.yy, lex.ll: use symbols via gnulib namespace
John W. Eaton <jwe@octave.org>
parents: 10411
diff changeset
92 #define fclose GNULIB_NAMESPACE::fclose
4db7beace28e oct-parse.yy, lex.ll: use symbols via gnulib namespace
John W. Eaton <jwe@octave.org>
parents: 10411
diff changeset
93 #define fprintf GNULIB_NAMESPACE::fprintf
4db7beace28e oct-parse.yy, lex.ll: use symbols via gnulib namespace
John W. Eaton <jwe@octave.org>
parents: 10411
diff changeset
94 #define malloc GNULIB_NAMESPACE::malloc
4db7beace28e oct-parse.yy, lex.ll: use symbols via gnulib namespace
John W. Eaton <jwe@octave.org>
parents: 10411
diff changeset
95 #endif
4db7beace28e oct-parse.yy, lex.ll: use symbols via gnulib namespace
John W. Eaton <jwe@octave.org>
parents: 10411
diff changeset
96
3021
18d64612e67a [project @ 1997-06-03 22:18:56 by jwe]
jwe
parents: 3016
diff changeset
97 // TRUE means we printed messages about reading startup files.
18d64612e67a [project @ 1997-06-03 22:18:56 by jwe]
jwe
parents: 3016
diff changeset
98 bool reading_startup_message_printed = false;
18d64612e67a [project @ 1997-06-03 22:18:56 by jwe]
jwe
parents: 3016
diff changeset
99
5484
2ff5363a16bd [project @ 2005-10-06 17:12:12 by jwe]
jwe
parents: 5472
diff changeset
100 // List of autoloads (function -> file mapping).
2ff5363a16bd [project @ 2005-10-06 17:12:12 by jwe]
jwe
parents: 5472
diff changeset
101 static std::map<std::string, std::string> autoload_map;
2ff5363a16bd [project @ 2005-10-06 17:12:12 by jwe]
jwe
parents: 5472
diff changeset
102
496
e7c5b23b34d3 [project @ 1994-07-06 15:02:26 by jwe]
jwe
parents: 482
diff changeset
103 // 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
104 // the file.
e7c5b23b34d3 [project @ 1994-07-06 15:02:26 by jwe]
jwe
parents: 482
diff changeset
105
16288
fe3b9a51e625 rename curr_lexer, curr_parser, CURR_LEXER
John W. Eaton <jwe@octave.org>
parents: 16287
diff changeset
106 static void yyerror (octave_base_parser& parser, const char *s);
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
107
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
108 #define ABORT_PARSE \
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
109 do \
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
110 { \
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
111 yyerrok; \
16320
09f0cb9cac7d don't modify symbol table scope in the parser
John W. Eaton <jwe@octave.org>
parents: 16302
diff changeset
112 if ((interactive || forced_interactive) \
16288
fe3b9a51e625 rename curr_lexer, curr_parser, CURR_LEXER
John W. Eaton <jwe@octave.org>
parents: 16287
diff changeset
113 && ! lexer.input_from_eval_string ()) \
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
114 YYACCEPT; \
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
115 else \
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
116 YYABORT; \
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
117 } \
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
118 while (0)
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
119
16288
fe3b9a51e625 rename curr_lexer, curr_parser, CURR_LEXER
John W. Eaton <jwe@octave.org>
parents: 16287
diff changeset
120 #define lexer parser.lexer
fe3b9a51e625 rename curr_lexer, curr_parser, CURR_LEXER
John W. Eaton <jwe@octave.org>
parents: 16287
diff changeset
121 #define scanner lexer.scanner
16149
49dfba4fd3c5 use pure parser and reentrant lexer interfaces
John W. Eaton <jwe@octave.org>
parents: 16147
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
4813
fba5c6e96e0f [project @ 2004-03-03 23:35:43 by jwe]
jwe
parents: 4753
diff changeset
132 // Don't add spaces around the = here; it causes some versions of
fba5c6e96e0f [project @ 2004-03-03 23:35:43 by jwe]
jwe
parents: 4753
diff changeset
133 // bison to fail to properly recognize the directive.
fba5c6e96e0f [project @ 2004-03-03 23:35:43 by jwe]
jwe
parents: 4753
diff changeset
134
fba5c6e96e0f [project @ 2004-03-03 23:35:43 by jwe]
jwe
parents: 4753
diff changeset
135 %name-prefix="octave_"
4753
9f0ce1536368 [project @ 2004-02-13 17:55:24 by jwe]
jwe
parents: 4699
diff changeset
136
16149
49dfba4fd3c5 use pure parser and reentrant lexer interfaces
John W. Eaton <jwe@octave.org>
parents: 16147
diff changeset
137 // 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
138 // 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
139 // 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
140 // 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
141 // 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
142 // 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
143 // 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
144 // 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
145
49dfba4fd3c5 use pure parser and reentrant lexer interfaces
John W. Eaton <jwe@octave.org>
parents: 16147
diff changeset
146 %define api.pure
16174
39096b290a2f check syntax used to enable bison push/pull parser
John W. Eaton <jwe@octave.org>
parents: 16167
diff changeset
147 %PUSH_PULL_DECL%
16288
fe3b9a51e625 rename curr_lexer, curr_parser, CURR_LEXER
John W. Eaton <jwe@octave.org>
parents: 16287
diff changeset
148 %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
149 %lex-param { void *scanner }
49dfba4fd3c5 use pure parser and reentrant lexer interfaces
John W. Eaton <jwe@octave.org>
parents: 16147
diff changeset
150
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
151 %union
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
152 {
2891
1a30f46e1870 [project @ 1997-04-28 01:49:00 by jwe]
jwe
parents: 2884
diff changeset
153 // 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
154 token *tok_val;
7849db4b6dbc [project @ 1993-10-04 02:36:45 by jwe]
jwe
parents: 118
diff changeset
155
3665
0689afb1d001 [project @ 2000-05-11 19:07:56 by jwe]
jwe
parents: 3544
diff changeset
156 // 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
157 octave_comment_list *comment_type;
0689afb1d001 [project @ 2000-05-11 19:07:56 by jwe]
jwe
parents: 3544
diff changeset
158
2891
1a30f46e1870 [project @ 1997-04-28 01:49:00 by jwe]
jwe
parents: 2884
diff changeset
159 // Types for the nonterminals we generate.
2525
8561d88be5f2 [project @ 1996-11-17 21:23:31 by jwe]
jwe
parents: 2524
diff changeset
160 char sep_type;
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
161 tree *tree_type;
1829
7d2982b55242 [project @ 1996-02-02 14:12:59 by jwe]
jwe
parents: 1826
diff changeset
162 tree_matrix *tree_matrix_type;
3351
8623649c967c [project @ 1999-11-15 16:17:01 by jwe]
jwe
parents: 3347
diff changeset
163 tree_cell *tree_cell_type;
496
e7c5b23b34d3 [project @ 1994-07-06 15:02:26 by jwe]
jwe
parents: 482
diff changeset
164 tree_expression *tree_expression_type;
2375
7ef24992e290 [project @ 1996-10-12 00:39:52 by jwe]
jwe
parents: 2200
diff changeset
165 tree_constant *tree_constant_type;
4342
813effe14ee1 [project @ 2003-02-20 08:35:55 by jwe]
jwe
parents: 4318
diff changeset
166 tree_fcn_handle *tree_fcn_handle_type;
5861
2a6cb4ed8f1e [project @ 2006-06-16 05:09:41 by jwe]
jwe
parents: 5848
diff changeset
167 tree_anon_fcn_handle *tree_anon_fcn_handle_type;
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
168 tree_identifier *tree_identifier_type;
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
169 tree_index_expression *tree_index_expression_type;
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
170 tree_colon_expression *tree_colon_expression_type;
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
171 tree_argument_list *tree_argument_list_type;
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
172 tree_parameter_list *tree_parameter_list_type;
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
173 tree_command *tree_command_type;
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
174 tree_if_command *tree_if_command_type;
578
d169be9237fb [project @ 1994-08-03 20:06:54 by jwe]
jwe
parents: 572
diff changeset
175 tree_if_clause *tree_if_clause_type;
d169be9237fb [project @ 1994-08-03 20:06:54 by jwe]
jwe
parents: 572
diff changeset
176 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
177 tree_switch_command *tree_switch_command_type;
2c0f259cf83d [project @ 1997-03-01 02:30:26 by jwe]
jwe
parents: 2745
diff changeset
178 tree_switch_case *tree_switch_case_type;
2c0f259cf83d [project @ 1997-03-01 02:30:26 by jwe]
jwe
parents: 2745
diff changeset
179 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
180 tree_decl_elt *tree_decl_elt_type;
52e7c4509983 [project @ 1997-03-26 23:27:35 by jwe]
jwe
parents: 2825
diff changeset
181 tree_decl_init_list *tree_decl_init_list_type;
52e7c4509983 [project @ 1997-03-26 23:27:35 by jwe]
jwe
parents: 2825
diff changeset
182 tree_decl_command *tree_decl_command_type;
578
d169be9237fb [project @ 1994-08-03 20:06:54 by jwe]
jwe
parents: 572
diff changeset
183 tree_statement *tree_statement_type;
d169be9237fb [project @ 1994-08-03 20:06:54 by jwe]
jwe
parents: 572
diff changeset
184 tree_statement_list *tree_statement_list_type;
2891
1a30f46e1870 [project @ 1997-04-28 01:49:00 by jwe]
jwe
parents: 2884
diff changeset
185 octave_user_function *octave_user_function_type;
9476
d9b25c5b8ee5 handle classdef syntax in lexer and parser
Ryan Rusaw
parents: 9474
diff changeset
186 void *dummy_type;
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
187 }
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
188
143
7849db4b6dbc [project @ 1993-10-04 02:36:45 by jwe]
jwe
parents: 118
diff changeset
189 // Tokens with line and column information.
7849db4b6dbc [project @ 1993-10-04 02:36:45 by jwe]
jwe
parents: 118
diff changeset
190 %token <tok_val> '=' ':' '-' '+' '*' '/'
4018
a8621d87fbf5 [project @ 2002-08-05 03:17:25 by jwe]
jwe
parents: 4009
diff changeset
191 %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
192 %token <tok_val> EMUL_EQ EDIV_EQ ELEFTDIV_EQ EPOW_EQ AND_EQ OR_EQ
2899
0d79a8c11a2b [project @ 1997-04-30 03:09:23 by jwe]
jwe
parents: 2891
diff changeset
193 %token <tok_val> LSHIFT_EQ RSHIFT_EQ LSHIFT RSHIFT
428
fa0453b25410 [project @ 1994-05-25 01:06:28 by jwe]
jwe
parents: 341
diff changeset
194 %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
195 %token <tok_val> EXPR_AND EXPR_OR EXPR_NOT
7849db4b6dbc [project @ 1993-10-04 02:36:45 by jwe]
jwe
parents: 118
diff changeset
196 %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
197 %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
198 %token <tok_val> HERMITIAN TRANSPOSE
143
7849db4b6dbc [project @ 1993-10-04 02:36:45 by jwe]
jwe
parents: 118
diff changeset
199 %token <tok_val> PLUS_PLUS MINUS_MINUS POW EPOW
7849db4b6dbc [project @ 1993-10-04 02:36:45 by jwe]
jwe
parents: 118
diff changeset
200 %token <tok_val> NUM IMAG_NUM
2970
b9e64477f703 [project @ 1997-05-15 18:04:21 by jwe]
jwe
parents: 2961
diff changeset
201 %token <tok_val> STRUCT_ELT
2883
0b3954110c77 [project @ 1997-04-24 09:57:05 by jwe]
jwe
parents: 2865
diff changeset
202 %token <tok_val> NAME
143
7849db4b6dbc [project @ 1993-10-04 02:36:45 by jwe]
jwe
parents: 118
diff changeset
203 %token <tok_val> END
5279
bd32f770c09a [project @ 2005-04-12 21:55:31 by jwe]
jwe
parents: 5189
diff changeset
204 %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
205 %token <tok_val> FOR PARFOR WHILE DO UNTIL
1491
893b416bb919 [project @ 1995-09-29 04:03:01 by jwe]
jwe
parents: 1489
diff changeset
206 %token <tok_val> IF ELSEIF ELSE
2764
2c0f259cf83d [project @ 1997-03-01 02:30:26 by jwe]
jwe
parents: 2745
diff changeset
207 %token <tok_val> SWITCH CASE OTHERWISE
1491
893b416bb919 [project @ 1995-09-29 04:03:01 by jwe]
jwe
parents: 1489
diff changeset
208 %token <tok_val> BREAK CONTINUE FUNC_RET
924
8b0920cc1d64 [project @ 1994-11-15 00:40:50 by jwe]
jwe
parents: 922
diff changeset
209 %token <tok_val> UNWIND CLEANUP
1489
3e705c864019 [project @ 1995-09-28 05:38:26 by jwe]
jwe
parents: 1371
diff changeset
210 %token <tok_val> TRY CATCH
14294
9e3983c8963c deprecate the static keyword
John W. Eaton <jwe@octave.org>
parents: 14293
diff changeset
211 %token <tok_val> GLOBAL PERSISTENT
4342
813effe14ee1 [project @ 2003-02-20 08:35:55 by jwe]
jwe
parents: 4318
diff changeset
212 %token <tok_val> FCN_HANDLE
13249
7861a5fd3479 accept enumeration keyword
John W. Eaton <jwe@octave.org>
parents: 13246
diff changeset
213 %token <tok_val> PROPERTIES METHODS EVENTS ENUMERATION
9476
d9b25c5b8ee5 handle classdef syntax in lexer and parser
Ryan Rusaw
parents: 9474
diff changeset
214 %token <tok_val> METAQUERY
d9b25c5b8ee5 handle classdef syntax in lexer and parser
Ryan Rusaw
parents: 9474
diff changeset
215 %token <tok_val> SUPERCLASSREF
d9b25c5b8ee5 handle classdef syntax in lexer and parser
Ryan Rusaw
parents: 9474
diff changeset
216 %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
217 %token <tok_val> FCN
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
218
143
7849db4b6dbc [project @ 1993-10-04 02:36:45 by jwe]
jwe
parents: 118
diff changeset
219 // Other tokens.
2970
b9e64477f703 [project @ 1997-05-15 18:04:21 by jwe]
jwe
parents: 2961
diff changeset
220 %token END_OF_INPUT LEXICAL_ERROR
16627
de91b1621260 adjust location of eof marker for files with subfunctions but no explicit end statements
John W. Eaton <jwe@octave.org>
parents: 16574
diff changeset
221 %token INPUT_FILE CLASSDEF
7587
1f662945c2be handle varargin and varargout without keywords
John W. Eaton <jwe@octave.org>
parents: 7562
diff changeset
222 // %token VARARGIN VARARGOUT
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
223
143
7849db4b6dbc [project @ 1993-10-04 02:36:45 by jwe]
jwe
parents: 118
diff changeset
224 // Nonterminals we construct.
16627
de91b1621260 adjust location of eof marker for files with subfunctions but no explicit end statements
John W. Eaton <jwe@octave.org>
parents: 16574
diff changeset
225 %type <tok_val> function_beg
de91b1621260 adjust location of eof marker for files with subfunctions but no explicit end statements
John W. Eaton <jwe@octave.org>
parents: 16574
diff changeset
226 %type <comment_type> stash_comment classdef_beg
13249
7861a5fd3479 accept enumeration keyword
John W. Eaton <jwe@octave.org>
parents: 13246
diff changeset
227 %type <comment_type> properties_beg methods_beg events_beg enum_beg
16238
38bd5ae8463b new opt_semi non-terminal for parser; use opt_comma in cell_or_matrix_row
John W. Eaton <jwe@octave.org>
parents: 16237
diff changeset
228 %type <sep_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
229 %type <tree_type> input
5861
2a6cb4ed8f1e [project @ 2006-06-16 05:09:41 by jwe]
jwe
parents: 5848
diff changeset
230 %type <tree_constant_type> string constant magic_colon
2a6cb4ed8f1e [project @ 2006-06-16 05:09:41 by jwe]
jwe
parents: 5848
diff changeset
231 %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
232 %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
233 %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
234 %type <tree_cell_type> cell_rows
5102
b04b30d30c66 [project @ 2004-12-28 01:59:05 by jwe]
jwe
parents: 5013
diff changeset
235 %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
236 %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
237 %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
238 %type <tree_identifier_type> identifier fcn_name magic_tilde
9476
d9b25c5b8ee5 handle classdef syntax in lexer and parser
Ryan Rusaw
parents: 9474
diff changeset
239 %type <tree_identifier_type> superclass_identifier meta_identifier
d9b25c5b8ee5 handle classdef syntax in lexer and parser
Ryan Rusaw
parents: 9474
diff changeset
240 %type <octave_user_function_type> function1 function2 classdef1
2970
b9e64477f703 [project @ 1997-05-15 18:04:21 by jwe]
jwe
parents: 2961
diff changeset
241 %type <tree_index_expression_type> word_list_cmd
b9e64477f703 [project @ 1997-05-15 18:04:21 by jwe]
jwe
parents: 2961
diff changeset
242 %type <tree_colon_expression_type> colon_expr1
3351
8623649c967c [project @ 1999-11-15 16:17:01 by jwe]
jwe
parents: 3347
diff changeset
243 %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
244 %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
245 %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
246 %type <tree_parameter_list_type> return_list return_list1
9476
d9b25c5b8ee5 handle classdef syntax in lexer and parser
Ryan Rusaw
parents: 9474
diff changeset
247 %type <tree_parameter_list_type> superclasses opt_superclasses
2970
b9e64477f703 [project @ 1997-05-15 18:04:21 by jwe]
jwe
parents: 2961
diff changeset
248 %type <tree_command_type> command select_command loop_command
9476
d9b25c5b8ee5 handle classdef syntax in lexer and parser
Ryan Rusaw
parents: 9474
diff changeset
249 %type <tree_command_type> jump_command except_command function
16203
127cccb037bf move more global parser and lexer variables to classes
John W. Eaton <jwe@octave.org>
parents: 16199
diff changeset
250 %type <tree_command_type> file classdef
578
d169be9237fb [project @ 1994-08-03 20:06:54 by jwe]
jwe
parents: 572
diff changeset
251 %type <tree_if_command_type> if_command
d169be9237fb [project @ 1994-08-03 20:06:54 by jwe]
jwe
parents: 572
diff changeset
252 %type <tree_if_clause_type> elseif_clause else_clause
d169be9237fb [project @ 1994-08-03 20:06:54 by jwe]
jwe
parents: 572
diff changeset
253 %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
254 %type <tree_switch_command_type> switch_command
2c0f259cf83d [project @ 1997-03-01 02:30:26 by jwe]
jwe
parents: 2745
diff changeset
255 %type <tree_switch_case_type> switch_case default_case
2c0f259cf83d [project @ 1997-03-01 02:30:26 by jwe]
jwe
parents: 2745
diff changeset
256 %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
257 %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
258 %type <tree_decl_init_list_type> decl1
52e7c4509983 [project @ 1997-03-26 23:27:35 by jwe]
jwe
parents: 2825
diff changeset
259 %type <tree_decl_command_type> declaration
9476
d9b25c5b8ee5 handle classdef syntax in lexer and parser
Ryan Rusaw
parents: 9474
diff changeset
260 %type <tree_statement_type> statement function_end classdef_end
627
739d16c30481 [project @ 1994-08-19 13:23:14 by jwe]
jwe
parents: 620
diff changeset
261 %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
262 %type <tree_statement_list_type> opt_list
9476
d9b25c5b8ee5 handle classdef syntax in lexer and parser
Ryan Rusaw
parents: 9474
diff changeset
263 // These types need to be specified.
d9b25c5b8ee5 handle classdef syntax in lexer and parser
Ryan Rusaw
parents: 9474
diff changeset
264 %type <dummy_type> attr
d9b25c5b8ee5 handle classdef syntax in lexer and parser
Ryan Rusaw
parents: 9474
diff changeset
265 %type <dummy_type> class_event
13249
7861a5fd3479 accept enumeration keyword
John W. Eaton <jwe@octave.org>
parents: 13246
diff changeset
266 %type <dummy_type> class_enum
9476
d9b25c5b8ee5 handle classdef syntax in lexer and parser
Ryan Rusaw
parents: 9474
diff changeset
267 %type <dummy_type> class_property
d9b25c5b8ee5 handle classdef syntax in lexer and parser
Ryan Rusaw
parents: 9474
diff changeset
268 %type <dummy_type> properties_list
d9b25c5b8ee5 handle classdef syntax in lexer and parser
Ryan Rusaw
parents: 9474
diff changeset
269 %type <dummy_type> properties_block
d9b25c5b8ee5 handle classdef syntax in lexer and parser
Ryan Rusaw
parents: 9474
diff changeset
270 %type <dummy_type> methods_list
d9b25c5b8ee5 handle classdef syntax in lexer and parser
Ryan Rusaw
parents: 9474
diff changeset
271 %type <dummy_type> methods_block
d9b25c5b8ee5 handle classdef syntax in lexer and parser
Ryan Rusaw
parents: 9474
diff changeset
272 %type <dummy_type> opt_attr_list
d9b25c5b8ee5 handle classdef syntax in lexer and parser
Ryan Rusaw
parents: 9474
diff changeset
273 %type <dummy_type> attr_list
d9b25c5b8ee5 handle classdef syntax in lexer and parser
Ryan Rusaw
parents: 9474
diff changeset
274 %type <dummy_type> events_list
d9b25c5b8ee5 handle classdef syntax in lexer and parser
Ryan Rusaw
parents: 9474
diff changeset
275 %type <dummy_type> events_block
13249
7861a5fd3479 accept enumeration keyword
John W. Eaton <jwe@octave.org>
parents: 13246
diff changeset
276 %type <dummy_type> enum_list
7861a5fd3479 accept enumeration keyword
John W. Eaton <jwe@octave.org>
parents: 13246
diff changeset
277 %type <dummy_type> enum_block
9476
d9b25c5b8ee5 handle classdef syntax in lexer and parser
Ryan Rusaw
parents: 9474
diff changeset
278 %type <dummy_type> class_body
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
279
143
7849db4b6dbc [project @ 1993-10-04 02:36:45 by jwe]
jwe
parents: 118
diff changeset
280 // Precedence and associativity.
4018
a8621d87fbf5 [project @ 2002-08-05 03:17:25 by jwe]
jwe
parents: 4009
diff changeset
281 %right '=' ADD_EQ SUB_EQ MUL_EQ DIV_EQ LEFTDIV_EQ POW_EQ EMUL_EQ EDIV_EQ ELEFTDIV_EQ EPOW_EQ OR_EQ AND_EQ LSHIFT_EQ RSHIFT_EQ
4023
ef3caf27cb9c [project @ 2002-08-07 06:54:41 by jwe]
jwe
parents: 4018
diff changeset
282 %left EXPR_OR_OR
ef3caf27cb9c [project @ 2002-08-07 06:54:41 by jwe]
jwe
parents: 4018
diff changeset
283 %left EXPR_AND_AND
ef3caf27cb9c [project @ 2002-08-07 06:54:41 by jwe]
jwe
parents: 4018
diff changeset
284 %left EXPR_OR
ef3caf27cb9c [project @ 2002-08-07 06:54:41 by jwe]
jwe
parents: 4018
diff changeset
285 %left EXPR_AND
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
286 %left EXPR_LT EXPR_LE EXPR_EQ EXPR_NE EXPR_GE EXPR_GT
2899
0d79a8c11a2b [project @ 1997-04-30 03:09:23 by jwe]
jwe
parents: 2891
diff changeset
287 %left LSHIFT RSHIFT
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
288 %left ':'
1276
cbdf7db98554 [project @ 1995-04-24 15:31:24 by jwe]
jwe
parents: 1266
diff changeset
289 %left '-' '+' EPLUS EMINUS
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
290 %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
291 %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
292 %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
293 %right PLUS_PLUS MINUS_MINUS
3351
8623649c967c [project @ 1999-11-15 16:17:01 by jwe]
jwe
parents: 3347
diff changeset
294 %left '(' '.' '{'
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
295
17629
1e8f8900a041 clean up partially constructed parse tree objects on parse errors (bug #40231)
John W. Eaton <jwe@octave.org>
parents: 17622
diff changeset
296 // 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
297 // 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
298 // 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
299 // 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
300 // 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
301 // here).
0c5f50706ba3 attempt to catch possible memory leaks in parser cleanup
John W. Eaton <jwe@octave.org>
parents: 17632
diff changeset
302
0c5f50706ba3 attempt to catch possible memory leaks in parser cleanup
John W. Eaton <jwe@octave.org>
parents: 17632
diff changeset
303 %destructor { } <sep_type>
0c5f50706ba3 attempt to catch possible memory leaks in parser cleanup
John W. Eaton <jwe@octave.org>
parents: 17632
diff changeset
304 %destructor { } <tok_val>
0c5f50706ba3 attempt to catch possible memory leaks in parser cleanup
John W. Eaton <jwe@octave.org>
parents: 17632
diff changeset
305 %destructor { } <comment_type>
0c5f50706ba3 attempt to catch possible memory leaks in parser cleanup
John W. Eaton <jwe@octave.org>
parents: 17632
diff changeset
306 %destructor { } <dummy_type>
0c5f50706ba3 attempt to catch possible memory leaks in parser cleanup
John W. Eaton <jwe@octave.org>
parents: 17632
diff changeset
307 %destructor { } <>
0c5f50706ba3 attempt to catch possible memory leaks in parser cleanup
John W. Eaton <jwe@octave.org>
parents: 17632
diff changeset
308
0c5f50706ba3 attempt to catch possible memory leaks in parser cleanup
John W. Eaton <jwe@octave.org>
parents: 17632
diff changeset
309 %destructor { delete $$; } <tree_type>
0c5f50706ba3 attempt to catch possible memory leaks in parser cleanup
John W. Eaton <jwe@octave.org>
parents: 17632
diff changeset
310 %destructor { delete $$; } <tree_matrix_type>
0c5f50706ba3 attempt to catch possible memory leaks in parser cleanup
John W. Eaton <jwe@octave.org>
parents: 17632
diff changeset
311 %destructor { delete $$; } <tree_cell_type>
0c5f50706ba3 attempt to catch possible memory leaks in parser cleanup
John W. Eaton <jwe@octave.org>
parents: 17632
diff changeset
312 %destructor { delete $$; } <tree_expression_type>
0c5f50706ba3 attempt to catch possible memory leaks in parser cleanup
John W. Eaton <jwe@octave.org>
parents: 17632
diff changeset
313 %destructor { delete $$; } <tree_constant_type>
0c5f50706ba3 attempt to catch possible memory leaks in parser cleanup
John W. Eaton <jwe@octave.org>
parents: 17632
diff changeset
314 %destructor { delete $$; } <tree_fcn_handle_type>
0c5f50706ba3 attempt to catch possible memory leaks in parser cleanup
John W. Eaton <jwe@octave.org>
parents: 17632
diff changeset
315 %destructor { delete $$; } <tree_anon_fcn_handle_type>
0c5f50706ba3 attempt to catch possible memory leaks in parser cleanup
John W. Eaton <jwe@octave.org>
parents: 17632
diff changeset
316 %destructor { delete $$; } <tree_identifier_type>
0c5f50706ba3 attempt to catch possible memory leaks in parser cleanup
John W. Eaton <jwe@octave.org>
parents: 17632
diff changeset
317 %destructor { delete $$; } <tree_index_expression_type>
0c5f50706ba3 attempt to catch possible memory leaks in parser cleanup
John W. Eaton <jwe@octave.org>
parents: 17632
diff changeset
318 %destructor { delete $$; } <tree_colon_expression_type>
0c5f50706ba3 attempt to catch possible memory leaks in parser cleanup
John W. Eaton <jwe@octave.org>
parents: 17632
diff changeset
319 %destructor { delete $$; } <tree_argument_list_type>
0c5f50706ba3 attempt to catch possible memory leaks in parser cleanup
John W. Eaton <jwe@octave.org>
parents: 17632
diff changeset
320 %destructor { delete $$; } <tree_parameter_list_type>
0c5f50706ba3 attempt to catch possible memory leaks in parser cleanup
John W. Eaton <jwe@octave.org>
parents: 17632
diff changeset
321 %destructor { delete $$; } <tree_command_type>
0c5f50706ba3 attempt to catch possible memory leaks in parser cleanup
John W. Eaton <jwe@octave.org>
parents: 17632
diff changeset
322 %destructor { delete $$; } <tree_if_command_type>
0c5f50706ba3 attempt to catch possible memory leaks in parser cleanup
John W. Eaton <jwe@octave.org>
parents: 17632
diff changeset
323 %destructor { delete $$; } <tree_if_clause_type>
0c5f50706ba3 attempt to catch possible memory leaks in parser cleanup
John W. Eaton <jwe@octave.org>
parents: 17632
diff changeset
324 %destructor { delete $$; } <tree_if_command_list_type>
0c5f50706ba3 attempt to catch possible memory leaks in parser cleanup
John W. Eaton <jwe@octave.org>
parents: 17632
diff changeset
325 %destructor { delete $$; } <tree_switch_command_type>
0c5f50706ba3 attempt to catch possible memory leaks in parser cleanup
John W. Eaton <jwe@octave.org>
parents: 17632
diff changeset
326 %destructor { delete $$; } <tree_switch_case_type>
0c5f50706ba3 attempt to catch possible memory leaks in parser cleanup
John W. Eaton <jwe@octave.org>
parents: 17632
diff changeset
327 %destructor { delete $$; } <tree_switch_case_list_type>
0c5f50706ba3 attempt to catch possible memory leaks in parser cleanup
John W. Eaton <jwe@octave.org>
parents: 17632
diff changeset
328 %destructor { delete $$; } <tree_decl_elt_type>
0c5f50706ba3 attempt to catch possible memory leaks in parser cleanup
John W. Eaton <jwe@octave.org>
parents: 17632
diff changeset
329 %destructor { delete $$; } <tree_decl_init_list_type>
0c5f50706ba3 attempt to catch possible memory leaks in parser cleanup
John W. Eaton <jwe@octave.org>
parents: 17632
diff changeset
330 %destructor { delete $$; } <tree_decl_command_type>
0c5f50706ba3 attempt to catch possible memory leaks in parser cleanup
John W. Eaton <jwe@octave.org>
parents: 17632
diff changeset
331 %destructor { delete $$; } <tree_statement_type>
0c5f50706ba3 attempt to catch possible memory leaks in parser cleanup
John W. Eaton <jwe@octave.org>
parents: 17632
diff changeset
332 %destructor { delete $$; } <tree_statement_list_type>
0c5f50706ba3 attempt to catch possible memory leaks in parser cleanup
John W. Eaton <jwe@octave.org>
parents: 17632
diff changeset
333 %destructor { delete $$; } <octave_user_function_type>
0c5f50706ba3 attempt to catch possible memory leaks in parser cleanup
John W. Eaton <jwe@octave.org>
parents: 17632
diff changeset
334
0c5f50706ba3 attempt to catch possible memory leaks in parser cleanup
John W. Eaton <jwe@octave.org>
parents: 17632
diff changeset
335 %destructor {
0c5f50706ba3 attempt to catch possible memory leaks in parser cleanup
John W. Eaton <jwe@octave.org>
parents: 17632
diff changeset
336 warning_with_id
0c5f50706ba3 attempt to catch possible memory leaks in parser cleanup
John W. Eaton <jwe@octave.org>
parents: 17632
diff changeset
337 ("Octave:parser-destructor",
0c5f50706ba3 attempt to catch possible memory leaks in parser cleanup
John W. Eaton <jwe@octave.org>
parents: 17632
diff changeset
338 "possible memory leak in cleanup following parse error");
0c5f50706ba3 attempt to catch possible memory leaks in parser cleanup
John W. Eaton <jwe@octave.org>
parents: 17632
diff changeset
339 } <*>
17629
1e8f8900a041 clean up partially constructed parse tree objects on parse errors (bug #40231)
John W. Eaton <jwe@octave.org>
parents: 17622
diff changeset
340
143
7849db4b6dbc [project @ 1993-10-04 02:36:45 by jwe]
jwe
parents: 118
diff changeset
341 // Where to start.
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
342 %start input
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
343
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
344 %%
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
345
2970
b9e64477f703 [project @ 1997-05-15 18:04:21 by jwe]
jwe
parents: 2961
diff changeset
346 // ==============================
b9e64477f703 [project @ 1997-05-15 18:04:21 by jwe]
jwe
parents: 2961
diff changeset
347 // Statements and statement lists
b9e64477f703 [project @ 1997-05-15 18:04:21 by jwe]
jwe
parents: 2961
diff changeset
348 // ==============================
b9e64477f703 [project @ 1997-05-15 18:04:21 by jwe]
jwe
parents: 2961
diff changeset
349
17322
4c1ae06111c9 allow parser to accept empty statements (bug #37099)
John W. Eaton <jwe@octave.org>
parents: 17317
diff changeset
350 input : simple_list '\n'
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
351 {
16288
fe3b9a51e625 rename curr_lexer, curr_parser, CURR_LEXER
John W. Eaton <jwe@octave.org>
parents: 16287
diff changeset
352 parser.stmt_list = $1;
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
353 YYACCEPT;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
354 }
17322
4c1ae06111c9 allow parser to accept empty statements (bug #37099)
John W. Eaton <jwe@octave.org>
parents: 17317
diff changeset
355 | simple_list END_OF_INPUT
4c1ae06111c9 allow parser to accept empty statements (bug #37099)
John W. Eaton <jwe@octave.org>
parents: 17317
diff changeset
356 {
4c1ae06111c9 allow parser to accept empty statements (bug #37099)
John W. Eaton <jwe@octave.org>
parents: 17317
diff changeset
357 lexer.end_of_input = true;
4c1ae06111c9 allow parser to accept empty statements (bug #37099)
John W. Eaton <jwe@octave.org>
parents: 17317
diff changeset
358 parser.stmt_list = $1;
4c1ae06111c9 allow parser to accept empty statements (bug #37099)
John W. Eaton <jwe@octave.org>
parents: 17317
diff changeset
359 YYACCEPT;
4c1ae06111c9 allow parser to accept empty statements (bug #37099)
John W. Eaton <jwe@octave.org>
parents: 17317
diff changeset
360 }
17326
f444e4cef9b9 avoid exiting Octave on parse error (bug #39862)
John W. Eaton <jwe@octave.org>
parents: 17322
diff changeset
361 | parse_error
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
362 { ABORT_PARSE; }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
363 ;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
364
17322
4c1ae06111c9 allow parser to accept empty statements (bug #37099)
John W. Eaton <jwe@octave.org>
parents: 17317
diff changeset
365 simple_list : opt_sep_no_nl
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
366 { $$ = 0; }
17322
4c1ae06111c9 allow parser to accept empty statements (bug #37099)
John W. Eaton <jwe@octave.org>
parents: 17317
diff changeset
367 | 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
368 { $$ = 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
369 ;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
370
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
371 simple_list1 : statement
16288
fe3b9a51e625 rename curr_lexer, curr_parser, CURR_LEXER
John W. Eaton <jwe@octave.org>
parents: 16287
diff changeset
372 { $$ = parser.make_statement_list ($1); }
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
373 | 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
374 { $$ = 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
375 ;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
376
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
377 opt_list : // empty
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
378 { $$ = new tree_statement_list (); }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
379 | list
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
380 { $$ = $1; }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
381 ;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
382
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
383 list : list1 opt_sep
16288
fe3b9a51e625 rename curr_lexer, curr_parser, CURR_LEXER
John W. Eaton <jwe@octave.org>
parents: 16287
diff changeset
384 { $$ = 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
385 ;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
386
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
387 list1 : statement
16288
fe3b9a51e625 rename curr_lexer, curr_parser, CURR_LEXER
John W. Eaton <jwe@octave.org>
parents: 16287
diff changeset
388 { $$ = parser.make_statement_list ($1); }
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
389 | list1 sep statement
16288
fe3b9a51e625 rename curr_lexer, curr_parser, CURR_LEXER
John W. Eaton <jwe@octave.org>
parents: 16287
diff changeset
390 { $$ = 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
391 ;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
392
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
393 statement : expression
17693
efbe746f8fa8 eliminate octave_comment_buffer singleton
John W. Eaton <jwe@octave.org>
parents: 17673
diff changeset
394 { $$ = parser.make_statement ($1); }
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
395 | command
17693
efbe746f8fa8 eliminate octave_comment_buffer singleton
John W. Eaton <jwe@octave.org>
parents: 17673
diff changeset
396 { $$ = parser.make_statement ($1); }
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
397 | word_list_cmd
17693
efbe746f8fa8 eliminate octave_comment_buffer singleton
John W. Eaton <jwe@octave.org>
parents: 17673
diff changeset
398 { $$ = parser.make_statement ($1); }
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
399 ;
8746
5dd06f19e9be handle commands in the lexer
John W. Eaton <jwe@octave.org>
parents: 8745
diff changeset
400
5dd06f19e9be handle commands in the lexer
John W. Eaton <jwe@octave.org>
parents: 8745
diff changeset
401 // =================
5dd06f19e9be handle commands in the lexer
John W. Eaton <jwe@octave.org>
parents: 8745
diff changeset
402 // Word-list command
5dd06f19e9be handle commands in the lexer
John W. Eaton <jwe@octave.org>
parents: 8745
diff changeset
403 // =================
5dd06f19e9be handle commands in the lexer
John W. Eaton <jwe@octave.org>
parents: 8745
diff changeset
404
5dd06f19e9be handle commands in the lexer
John W. Eaton <jwe@octave.org>
parents: 8745
diff changeset
405 // 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
406 // 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
407 // WHILE, etc.
5dd06f19e9be handle commands in the lexer
John W. Eaton <jwe@octave.org>
parents: 8745
diff changeset
408
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
409 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
410 {
a4af67e0d22c oct-parse.in.yy: a{~}.b segfaults the interpreter (bug #37804)
Max Brister <max@2bass.com>
parents: 16294
diff changeset
411 $$ = 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
412 if (! $$)
17632
bd0a84de3375 further reduce memory leaks from parse errors (bug #40231)
John W. Eaton <jwe@octave.org>
parents: 17629
diff changeset
413 {
bd0a84de3375 further reduce memory leaks from parse errors (bug #40231)
John W. Eaton <jwe@octave.org>
parents: 17629
diff changeset
414 // make_index_expression deleted $1 and $2.
bd0a84de3375 further reduce memory leaks from parse errors (bug #40231)
John W. Eaton <jwe@octave.org>
parents: 17629
diff changeset
415 ABORT_PARSE;
bd0a84de3375 further reduce memory leaks from parse errors (bug #40231)
John W. Eaton <jwe@octave.org>
parents: 17629
diff changeset
416 }
16302
a4af67e0d22c oct-parse.in.yy: a{~}.b segfaults the interpreter (bug #37804)
Max Brister <max@2bass.com>
parents: 16294
diff changeset
417 }
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
418 ;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
419
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
420 word_list : string
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
421 { $$ = new tree_argument_list ($1); }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
422 | word_list string
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
423 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
424 $1->append ($2);
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
425 $$ = $1;
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 ;
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
428
2970
b9e64477f703 [project @ 1997-05-15 18:04:21 by jwe]
jwe
parents: 2961
diff changeset
429 // ===========
b9e64477f703 [project @ 1997-05-15 18:04:21 by jwe]
jwe
parents: 2961
diff changeset
430 // Expressions
b9e64477f703 [project @ 1997-05-15 18:04:21 by jwe]
jwe
parents: 2961
diff changeset
431 // ===========
b9e64477f703 [project @ 1997-05-15 18:04:21 by jwe]
jwe
parents: 2961
diff changeset
432
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
433 identifier : NAME
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
434 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
435 symbol_table::symbol_record *sr = $1->sym_rec ();
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
436 $$ = new tree_identifier (*sr, $1->line (), $1->column ());
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 ;
2970
b9e64477f703 [project @ 1997-05-15 18:04:21 by jwe]
jwe
parents: 2961
diff changeset
439
9476
d9b25c5b8ee5 handle classdef syntax in lexer and parser
Ryan Rusaw
parents: 9474
diff changeset
440 superclass_identifier
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
441 : SUPERCLASSREF
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
442 { $$ = new tree_identifier ($1->line (), $1->column ()); }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
443 ;
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11572
diff changeset
444
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
445 meta_identifier : METAQUERY
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
446 { $$ = new tree_identifier ($1->line (), $1->column ()); }
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11572
diff changeset
447 ;
10315
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 string : DQ_STRING
16288
fe3b9a51e625 rename curr_lexer, curr_parser, CURR_LEXER
John W. Eaton <jwe@octave.org>
parents: 16287
diff changeset
450 { $$ = parser.make_constant (DQ_STRING, $1); }
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
451 | SQ_STRING
16288
fe3b9a51e625 rename curr_lexer, curr_parser, CURR_LEXER
John W. Eaton <jwe@octave.org>
parents: 16287
diff changeset
452 { $$ = parser.make_constant (SQ_STRING, $1); }
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
453 ;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
454
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
455 constant : NUM
16288
fe3b9a51e625 rename curr_lexer, curr_parser, CURR_LEXER
John W. Eaton <jwe@octave.org>
parents: 16287
diff changeset
456 { $$ = parser.make_constant (NUM, $1); }
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
457 | IMAG_NUM
16288
fe3b9a51e625 rename curr_lexer, curr_parser, CURR_LEXER
John W. Eaton <jwe@octave.org>
parents: 16287
diff changeset
458 { $$ = parser.make_constant (IMAG_NUM, $1); }
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
459 | string
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
460 { $$ = $1; }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
461 ;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
462
16924
aebb54d99dba improve compatibility of parsing of matrices and cell arrays
John W. Eaton <jwe@octave.org>
parents: 16850
diff changeset
463 matrix : '[' matrix_rows ']'
16288
fe3b9a51e625 rename curr_lexer, curr_parser, CURR_LEXER
John W. Eaton <jwe@octave.org>
parents: 16287
diff changeset
464 { $$ = parser.finish_matrix ($2); }
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
465 ;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
466
16924
aebb54d99dba improve compatibility of parsing of matrices and cell arrays
John W. Eaton <jwe@octave.org>
parents: 16850
diff changeset
467 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
468 { $$ = $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
469 | matrix_rows ';' cell_or_matrix_row
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
470 {
16924
aebb54d99dba improve compatibility of parsing of matrices and cell arrays
John W. Eaton <jwe@octave.org>
parents: 16850
diff changeset
471 if ($1)
aebb54d99dba improve compatibility of parsing of matrices and cell arrays
John W. Eaton <jwe@octave.org>
parents: 16850
diff changeset
472 {
aebb54d99dba improve compatibility of parsing of matrices and cell arrays
John W. Eaton <jwe@octave.org>
parents: 16850
diff changeset
473 if ($3)
aebb54d99dba improve compatibility of parsing of matrices and cell arrays
John W. Eaton <jwe@octave.org>
parents: 16850
diff changeset
474 $1->append ($3);
aebb54d99dba improve compatibility of parsing of matrices and cell arrays
John W. Eaton <jwe@octave.org>
parents: 16850
diff changeset
475
aebb54d99dba improve compatibility of parsing of matrices and cell arrays
John W. Eaton <jwe@octave.org>
parents: 16850
diff changeset
476 $$ = $1;
aebb54d99dba improve compatibility of parsing of matrices and cell arrays
John W. Eaton <jwe@octave.org>
parents: 16850
diff changeset
477 }
aebb54d99dba improve compatibility of parsing of matrices and cell arrays
John W. Eaton <jwe@octave.org>
parents: 16850
diff changeset
478 else
aebb54d99dba improve compatibility of parsing of matrices and cell arrays
John W. Eaton <jwe@octave.org>
parents: 16850
diff changeset
479 $$ = $3 ? new tree_matrix ($3) : 0;
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
480 }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
481 ;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
482
16924
aebb54d99dba improve compatibility of parsing of matrices and cell arrays
John W. Eaton <jwe@octave.org>
parents: 16850
diff changeset
483 cell : '{' cell_rows '}'
16288
fe3b9a51e625 rename curr_lexer, curr_parser, CURR_LEXER
John W. Eaton <jwe@octave.org>
parents: 16287
diff changeset
484 { $$ = parser.finish_cell ($2); }
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
485 ;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
486
16924
aebb54d99dba improve compatibility of parsing of matrices and cell arrays
John W. Eaton <jwe@octave.org>
parents: 16850
diff changeset
487 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
488 { $$ = $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
489 | cell_rows ';' cell_or_matrix_row
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
490 {
16924
aebb54d99dba improve compatibility of parsing of matrices and cell arrays
John W. Eaton <jwe@octave.org>
parents: 16850
diff changeset
491 if ($1)
aebb54d99dba improve compatibility of parsing of matrices and cell arrays
John W. Eaton <jwe@octave.org>
parents: 16850
diff changeset
492 {
aebb54d99dba improve compatibility of parsing of matrices and cell arrays
John W. Eaton <jwe@octave.org>
parents: 16850
diff changeset
493 if ($3)
aebb54d99dba improve compatibility of parsing of matrices and cell arrays
John W. Eaton <jwe@octave.org>
parents: 16850
diff changeset
494 $1->append ($3);
aebb54d99dba improve compatibility of parsing of matrices and cell arrays
John W. Eaton <jwe@octave.org>
parents: 16850
diff changeset
495
aebb54d99dba improve compatibility of parsing of matrices and cell arrays
John W. Eaton <jwe@octave.org>
parents: 16850
diff changeset
496 $$ = $1;
aebb54d99dba improve compatibility of parsing of matrices and cell arrays
John W. Eaton <jwe@octave.org>
parents: 16850
diff changeset
497 }
aebb54d99dba improve compatibility of parsing of matrices and cell arrays
John W. Eaton <jwe@octave.org>
parents: 16850
diff changeset
498 else
aebb54d99dba improve compatibility of parsing of matrices and cell arrays
John W. Eaton <jwe@octave.org>
parents: 16850
diff changeset
499 $$ = $3 ? new tree_cell ($3) : 0;
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
500 }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
501 ;
3351
8623649c967c [project @ 1999-11-15 16:17:01 by jwe]
jwe
parents: 3347
diff changeset
502
16924
aebb54d99dba improve compatibility of parsing of matrices and cell arrays
John W. Eaton <jwe@octave.org>
parents: 16850
diff changeset
503 // 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
504 // 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
505
3351
8623649c967c [project @ 1999-11-15 16:17:01 by jwe]
jwe
parents: 3347
diff changeset
506 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
507 : // empty
aebb54d99dba improve compatibility of parsing of matrices and cell arrays
John W. Eaton <jwe@octave.org>
parents: 16850
diff changeset
508 { $$ = 0; }
aebb54d99dba improve compatibility of parsing of matrices and cell arrays
John W. Eaton <jwe@octave.org>
parents: 16850
diff changeset
509 | ','
aebb54d99dba improve compatibility of parsing of matrices and cell arrays
John W. Eaton <jwe@octave.org>
parents: 16850
diff changeset
510 { $$ = 0; }
aebb54d99dba improve compatibility of parsing of matrices and cell arrays
John W. Eaton <jwe@octave.org>
parents: 16850
diff changeset
511 | arg_list
16257
db7f07b22b9b 1/10 commits reworking the lexer
John W. Eaton <jwe@octave.org>
parents: 16251
diff changeset
512 { $$ = $1; }
16924
aebb54d99dba improve compatibility of parsing of matrices and cell arrays
John W. Eaton <jwe@octave.org>
parents: 16850
diff changeset
513 | arg_list ','
16257
db7f07b22b9b 1/10 commits reworking the lexer
John W. Eaton <jwe@octave.org>
parents: 16251
diff changeset
514 { $$ = $1; }
16924
aebb54d99dba improve compatibility of parsing of matrices and cell arrays
John W. Eaton <jwe@octave.org>
parents: 16850
diff changeset
515 | ',' arg_list
aebb54d99dba improve compatibility of parsing of matrices and cell arrays
John W. Eaton <jwe@octave.org>
parents: 16850
diff changeset
516 { $$ = $2; }
aebb54d99dba improve compatibility of parsing of matrices and cell arrays
John W. Eaton <jwe@octave.org>
parents: 16850
diff changeset
517 | ',' arg_list ','
aebb54d99dba improve compatibility of parsing of matrices and cell arrays
John W. Eaton <jwe@octave.org>
parents: 16850
diff changeset
518 { $$ = $2; }
10315
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
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
521 fcn_handle : '@' FCN_HANDLE
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
522 {
16288
fe3b9a51e625 rename curr_lexer, curr_parser, CURR_LEXER
John W. Eaton <jwe@octave.org>
parents: 16287
diff changeset
523 $$ = parser.make_fcn_handle ($2);
fe3b9a51e625 rename curr_lexer, curr_parser, CURR_LEXER
John W. Eaton <jwe@octave.org>
parents: 16287
diff changeset
524 lexer.looking_at_function_handle--;
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
525 }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
526 ;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
527
16681
d3619d4d267c recognize character string at beginning of statement (bug #38926, #38958)
John W. Eaton <jwe@octave.org>
parents: 16627
diff changeset
528 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
529 {
16681
d3619d4d267c recognize character string at beginning of statement (bug #38926, #38958)
John W. Eaton <jwe@octave.org>
parents: 16627
diff changeset
530 $$ = 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
531 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
532 }
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
533 ;
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11572
diff changeset
534
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
535 primary_expr : identifier
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
536 { $$ = $1; }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
537 | constant
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
538 { $$ = $1; }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
539 | fcn_handle
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
540 { $$ = $1; }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
541 | matrix
16257
db7f07b22b9b 1/10 commits reworking the lexer
John W. Eaton <jwe@octave.org>
parents: 16251
diff changeset
542 {
16288
fe3b9a51e625 rename curr_lexer, curr_parser, CURR_LEXER
John W. Eaton <jwe@octave.org>
parents: 16287
diff changeset
543 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
544 $$ = $1;
db7f07b22b9b 1/10 commits reworking the lexer
John W. Eaton <jwe@octave.org>
parents: 16251
diff changeset
545 }
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
546 | cell
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
547 { $$ = $1; }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
548 | meta_identifier
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
549 { $$ = $1; }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
550 | superclass_identifier
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
551 { $$ = $1; }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
552 | '(' expression ')'
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
553 { $$ = $2->mark_in_parens (); }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
554 ;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
555
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
556 magic_colon : ':'
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
557 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
558 octave_value tmp (octave_value::magic_colon_t);
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
559 $$ = new tree_constant (tmp);
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
560 }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
561 ;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
562
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
563 magic_tilde : EXPR_NOT
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
564 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
565 $$ = new tree_black_hole ();
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
566 }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
567 ;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
568
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
569 arg_list : expression
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
570 { $$ = new tree_argument_list ($1); }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
571 | magic_colon
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
572 { $$ = new tree_argument_list ($1); }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
573 | magic_tilde
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
574 { $$ = new tree_argument_list ($1); }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
575 | arg_list ',' magic_colon
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
576 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
577 $1->append ($3);
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
578 $$ = $1;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
579 }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
580 | arg_list ',' magic_tilde
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
581 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
582 $1->append ($3);
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
583 $$ = $1;
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 | arg_list ',' expression
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
586 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
587 $1->append ($3);
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
588 $$ = $1;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
589 }
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 indirect_ref_op : '.'
16288
fe3b9a51e625 rename curr_lexer, curr_parser, CURR_LEXER
John W. Eaton <jwe@octave.org>
parents: 16287
diff changeset
593 { lexer.looking_at_indirect_ref = true; }
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
594 ;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
595
12627
002948ae5bc0 fix precedence level of transpose operators (bug #32533)
John W. Eaton <jwe@octave.org>
parents: 12483
diff changeset
596 oper_expr : primary_expr
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
597 { $$ = $1; }
12627
002948ae5bc0 fix precedence level of transpose operators (bug #32533)
John W. Eaton <jwe@octave.org>
parents: 12483
diff changeset
598 | oper_expr PLUS_PLUS
16288
fe3b9a51e625 rename curr_lexer, curr_parser, CURR_LEXER
John W. Eaton <jwe@octave.org>
parents: 16287
diff changeset
599 { $$ = 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
600 | oper_expr MINUS_MINUS
16288
fe3b9a51e625 rename curr_lexer, curr_parser, CURR_LEXER
John W. Eaton <jwe@octave.org>
parents: 16287
diff changeset
601 { $$ = 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
602 | oper_expr '(' ')'
16302
a4af67e0d22c oct-parse.in.yy: a{~}.b segfaults the interpreter (bug #37804)
Max Brister <max@2bass.com>
parents: 16294
diff changeset
603 {
a4af67e0d22c oct-parse.in.yy: a{~}.b segfaults the interpreter (bug #37804)
Max Brister <max@2bass.com>
parents: 16294
diff changeset
604 $$ = 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
605 if (! $$)
17632
bd0a84de3375 further reduce memory leaks from parse errors (bug #40231)
John W. Eaton <jwe@octave.org>
parents: 17629
diff changeset
606 {
bd0a84de3375 further reduce memory leaks from parse errors (bug #40231)
John W. Eaton <jwe@octave.org>
parents: 17629
diff changeset
607 // make_index_expression deleted $1.
bd0a84de3375 further reduce memory leaks from parse errors (bug #40231)
John W. Eaton <jwe@octave.org>
parents: 17629
diff changeset
608 ABORT_PARSE;
bd0a84de3375 further reduce memory leaks from parse errors (bug #40231)
John W. Eaton <jwe@octave.org>
parents: 17629
diff changeset
609 }
16302
a4af67e0d22c oct-parse.in.yy: a{~}.b segfaults the interpreter (bug #37804)
Max Brister <max@2bass.com>
parents: 16294
diff changeset
610 }
12627
002948ae5bc0 fix precedence level of transpose operators (bug #32533)
John W. Eaton <jwe@octave.org>
parents: 12483
diff changeset
611 | 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
612 {
a4af67e0d22c oct-parse.in.yy: a{~}.b segfaults the interpreter (bug #37804)
Max Brister <max@2bass.com>
parents: 16294
diff changeset
613 $$ = 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
614 if (! $$)
17632
bd0a84de3375 further reduce memory leaks from parse errors (bug #40231)
John W. Eaton <jwe@octave.org>
parents: 17629
diff changeset
615 {
bd0a84de3375 further reduce memory leaks from parse errors (bug #40231)
John W. Eaton <jwe@octave.org>
parents: 17629
diff changeset
616 // make_index_expression deleted $1 and $3.
bd0a84de3375 further reduce memory leaks from parse errors (bug #40231)
John W. Eaton <jwe@octave.org>
parents: 17629
diff changeset
617 ABORT_PARSE;
bd0a84de3375 further reduce memory leaks from parse errors (bug #40231)
John W. Eaton <jwe@octave.org>
parents: 17629
diff changeset
618 }
16302
a4af67e0d22c oct-parse.in.yy: a{~}.b segfaults the interpreter (bug #37804)
Max Brister <max@2bass.com>
parents: 16294
diff changeset
619 }
12627
002948ae5bc0 fix precedence level of transpose operators (bug #32533)
John W. Eaton <jwe@octave.org>
parents: 12483
diff changeset
620 | oper_expr '{' '}'
16302
a4af67e0d22c oct-parse.in.yy: a{~}.b segfaults the interpreter (bug #37804)
Max Brister <max@2bass.com>
parents: 16294
diff changeset
621 {
a4af67e0d22c oct-parse.in.yy: a{~}.b segfaults the interpreter (bug #37804)
Max Brister <max@2bass.com>
parents: 16294
diff changeset
622 $$ = 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
623 if (! $$)
17632
bd0a84de3375 further reduce memory leaks from parse errors (bug #40231)
John W. Eaton <jwe@octave.org>
parents: 17629
diff changeset
624 {
bd0a84de3375 further reduce memory leaks from parse errors (bug #40231)
John W. Eaton <jwe@octave.org>
parents: 17629
diff changeset
625 // make_index_expression deleted $1.
bd0a84de3375 further reduce memory leaks from parse errors (bug #40231)
John W. Eaton <jwe@octave.org>
parents: 17629
diff changeset
626 ABORT_PARSE;
bd0a84de3375 further reduce memory leaks from parse errors (bug #40231)
John W. Eaton <jwe@octave.org>
parents: 17629
diff changeset
627 }
16302
a4af67e0d22c oct-parse.in.yy: a{~}.b segfaults the interpreter (bug #37804)
Max Brister <max@2bass.com>
parents: 16294
diff changeset
628 }
12627
002948ae5bc0 fix precedence level of transpose operators (bug #32533)
John W. Eaton <jwe@octave.org>
parents: 12483
diff changeset
629 | 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
630 {
a4af67e0d22c oct-parse.in.yy: a{~}.b segfaults the interpreter (bug #37804)
Max Brister <max@2bass.com>
parents: 16294
diff changeset
631 $$ = 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
632 if (! $$)
17632
bd0a84de3375 further reduce memory leaks from parse errors (bug #40231)
John W. Eaton <jwe@octave.org>
parents: 17629
diff changeset
633 {
bd0a84de3375 further reduce memory leaks from parse errors (bug #40231)
John W. Eaton <jwe@octave.org>
parents: 17629
diff changeset
634 // make_index_expression deleted $1 and $3.
bd0a84de3375 further reduce memory leaks from parse errors (bug #40231)
John W. Eaton <jwe@octave.org>
parents: 17629
diff changeset
635 ABORT_PARSE;
bd0a84de3375 further reduce memory leaks from parse errors (bug #40231)
John W. Eaton <jwe@octave.org>
parents: 17629
diff changeset
636 }
16302
a4af67e0d22c oct-parse.in.yy: a{~}.b segfaults the interpreter (bug #37804)
Max Brister <max@2bass.com>
parents: 16294
diff changeset
637 }
16284
09881dab3aaf * lex.ll, oct-parse.in.yy (HERMITIAN): Rename token from QUOTE.
John W. Eaton <jwe@octave.org>
parents: 16279
diff changeset
638 | oper_expr HERMITIAN
16288
fe3b9a51e625 rename curr_lexer, curr_parser, CURR_LEXER
John W. Eaton <jwe@octave.org>
parents: 16287
diff changeset
639 { $$ = 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
640 | oper_expr TRANSPOSE
16288
fe3b9a51e625 rename curr_lexer, curr_parser, CURR_LEXER
John W. Eaton <jwe@octave.org>
parents: 16287
diff changeset
641 { $$ = 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
642 | 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
643 { $$ = 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
644 | 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
645 { $$ = 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
646 | 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
647 { $$ = 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
648 | 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
649 { $$ = 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
650 | 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
651 { $$ = 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
652 | '+' oper_expr %prec UNARY
16288
fe3b9a51e625 rename curr_lexer, curr_parser, CURR_LEXER
John W. Eaton <jwe@octave.org>
parents: 16287
diff changeset
653 { $$ = 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
654 | '-' oper_expr %prec UNARY
16288
fe3b9a51e625 rename curr_lexer, curr_parser, CURR_LEXER
John W. Eaton <jwe@octave.org>
parents: 16287
diff changeset
655 { $$ = 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
656 | oper_expr POW power_expr
16288
fe3b9a51e625 rename curr_lexer, curr_parser, CURR_LEXER
John W. Eaton <jwe@octave.org>
parents: 16287
diff changeset
657 { $$ = parser.make_binary_op (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
658 | oper_expr EPOW power_expr
16288
fe3b9a51e625 rename curr_lexer, curr_parser, CURR_LEXER
John W. Eaton <jwe@octave.org>
parents: 16287
diff changeset
659 { $$ = parser.make_binary_op (EPOW, $1, $2, $3); }
12627
002948ae5bc0 fix precedence level of transpose operators (bug #32533)
John W. Eaton <jwe@octave.org>
parents: 12483
diff changeset
660 | oper_expr '+' oper_expr
16288
fe3b9a51e625 rename curr_lexer, curr_parser, CURR_LEXER
John W. Eaton <jwe@octave.org>
parents: 16287
diff changeset
661 { $$ = parser.make_binary_op ('+', $1, $2, $3); }
12627
002948ae5bc0 fix precedence level of transpose operators (bug #32533)
John W. Eaton <jwe@octave.org>
parents: 12483
diff changeset
662 | oper_expr '-' oper_expr
16288
fe3b9a51e625 rename curr_lexer, curr_parser, CURR_LEXER
John W. Eaton <jwe@octave.org>
parents: 16287
diff changeset
663 { $$ = parser.make_binary_op ('-', $1, $2, $3); }
12627
002948ae5bc0 fix precedence level of transpose operators (bug #32533)
John W. Eaton <jwe@octave.org>
parents: 12483
diff changeset
664 | oper_expr '*' oper_expr
16288
fe3b9a51e625 rename curr_lexer, curr_parser, CURR_LEXER
John W. Eaton <jwe@octave.org>
parents: 16287
diff changeset
665 { $$ = parser.make_binary_op ('*', $1, $2, $3); }
12627
002948ae5bc0 fix precedence level of transpose operators (bug #32533)
John W. Eaton <jwe@octave.org>
parents: 12483
diff changeset
666 | oper_expr '/' oper_expr
16288
fe3b9a51e625 rename curr_lexer, curr_parser, CURR_LEXER
John W. Eaton <jwe@octave.org>
parents: 16287
diff changeset
667 { $$ = parser.make_binary_op ('/', $1, $2, $3); }
12627
002948ae5bc0 fix precedence level of transpose operators (bug #32533)
John W. Eaton <jwe@octave.org>
parents: 12483
diff changeset
668 | oper_expr EPLUS oper_expr
16288
fe3b9a51e625 rename curr_lexer, curr_parser, CURR_LEXER
John W. Eaton <jwe@octave.org>
parents: 16287
diff changeset
669 { $$ = 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
670 | oper_expr EMINUS oper_expr
16288
fe3b9a51e625 rename curr_lexer, curr_parser, CURR_LEXER
John W. Eaton <jwe@octave.org>
parents: 16287
diff changeset
671 { $$ = 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
672 | oper_expr EMUL oper_expr
16288
fe3b9a51e625 rename curr_lexer, curr_parser, CURR_LEXER
John W. Eaton <jwe@octave.org>
parents: 16287
diff changeset
673 { $$ = 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
674 | oper_expr EDIV oper_expr
16288
fe3b9a51e625 rename curr_lexer, curr_parser, CURR_LEXER
John W. Eaton <jwe@octave.org>
parents: 16287
diff changeset
675 { $$ = 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
676 | oper_expr LEFTDIV oper_expr
16288
fe3b9a51e625 rename curr_lexer, curr_parser, CURR_LEXER
John W. Eaton <jwe@octave.org>
parents: 16287
diff changeset
677 { $$ = 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
678 | oper_expr ELEFTDIV oper_expr
16288
fe3b9a51e625 rename curr_lexer, curr_parser, CURR_LEXER
John W. Eaton <jwe@octave.org>
parents: 16287
diff changeset
679 { $$ = 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
680 ;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
681
17622
fd712a12fe53 compatibility for power operator precedence and direction (bug #33304)
Axel Mathéi <axel.mathei@gmail.com>
parents: 17618
diff changeset
682 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
683 { $$ = $1; }
fd712a12fe53 compatibility for power operator precedence and direction (bug #33304)
Axel Mathéi <axel.mathei@gmail.com>
parents: 17618
diff changeset
684 | 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
685 { $$ = 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
686 | 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
687 { $$ = 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
688 | power_expr '(' ')'
fd712a12fe53 compatibility for power operator precedence and direction (bug #33304)
Axel Mathéi <axel.mathei@gmail.com>
parents: 17618
diff changeset
689 {
fd712a12fe53 compatibility for power operator precedence and direction (bug #33304)
Axel Mathéi <axel.mathei@gmail.com>
parents: 17618
diff changeset
690 $$ = 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
691 if (! $$)
17632
bd0a84de3375 further reduce memory leaks from parse errors (bug #40231)
John W. Eaton <jwe@octave.org>
parents: 17629
diff changeset
692 {
bd0a84de3375 further reduce memory leaks from parse errors (bug #40231)
John W. Eaton <jwe@octave.org>
parents: 17629
diff changeset
693 // make_index_expression deleted $1.
bd0a84de3375 further reduce memory leaks from parse errors (bug #40231)
John W. Eaton <jwe@octave.org>
parents: 17629
diff changeset
694 ABORT_PARSE;
bd0a84de3375 further reduce memory leaks from parse errors (bug #40231)
John W. Eaton <jwe@octave.org>
parents: 17629
diff changeset
695 }
17622
fd712a12fe53 compatibility for power operator precedence and direction (bug #33304)
Axel Mathéi <axel.mathei@gmail.com>
parents: 17618
diff changeset
696 }
fd712a12fe53 compatibility for power operator precedence and direction (bug #33304)
Axel Mathéi <axel.mathei@gmail.com>
parents: 17618
diff changeset
697 | 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
698 {
fd712a12fe53 compatibility for power operator precedence and direction (bug #33304)
Axel Mathéi <axel.mathei@gmail.com>
parents: 17618
diff changeset
699 $$ = 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
700 if (! $$)
17632
bd0a84de3375 further reduce memory leaks from parse errors (bug #40231)
John W. Eaton <jwe@octave.org>
parents: 17629
diff changeset
701 {
bd0a84de3375 further reduce memory leaks from parse errors (bug #40231)
John W. Eaton <jwe@octave.org>
parents: 17629
diff changeset
702 // make_index_expression deleted $1 and $3.
bd0a84de3375 further reduce memory leaks from parse errors (bug #40231)
John W. Eaton <jwe@octave.org>
parents: 17629
diff changeset
703 ABORT_PARSE;
bd0a84de3375 further reduce memory leaks from parse errors (bug #40231)
John W. Eaton <jwe@octave.org>
parents: 17629
diff changeset
704 }
17622
fd712a12fe53 compatibility for power operator precedence and direction (bug #33304)
Axel Mathéi <axel.mathei@gmail.com>
parents: 17618
diff changeset
705 }
fd712a12fe53 compatibility for power operator precedence and direction (bug #33304)
Axel Mathéi <axel.mathei@gmail.com>
parents: 17618
diff changeset
706 | power_expr '{' '}'
fd712a12fe53 compatibility for power operator precedence and direction (bug #33304)
Axel Mathéi <axel.mathei@gmail.com>
parents: 17618
diff changeset
707 {
fd712a12fe53 compatibility for power operator precedence and direction (bug #33304)
Axel Mathéi <axel.mathei@gmail.com>
parents: 17618
diff changeset
708 $$ = 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
709 if (! $$)
17632
bd0a84de3375 further reduce memory leaks from parse errors (bug #40231)
John W. Eaton <jwe@octave.org>
parents: 17629
diff changeset
710 {
bd0a84de3375 further reduce memory leaks from parse errors (bug #40231)
John W. Eaton <jwe@octave.org>
parents: 17629
diff changeset
711 // make_index_expression deleted $1.
bd0a84de3375 further reduce memory leaks from parse errors (bug #40231)
John W. Eaton <jwe@octave.org>
parents: 17629
diff changeset
712 ABORT_PARSE;
bd0a84de3375 further reduce memory leaks from parse errors (bug #40231)
John W. Eaton <jwe@octave.org>
parents: 17629
diff changeset
713 }
17622
fd712a12fe53 compatibility for power operator precedence and direction (bug #33304)
Axel Mathéi <axel.mathei@gmail.com>
parents: 17618
diff changeset
714 }
fd712a12fe53 compatibility for power operator precedence and direction (bug #33304)
Axel Mathéi <axel.mathei@gmail.com>
parents: 17618
diff changeset
715 | 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
716 {
fd712a12fe53 compatibility for power operator precedence and direction (bug #33304)
Axel Mathéi <axel.mathei@gmail.com>
parents: 17618
diff changeset
717 $$ = 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
718 if (! $$)
17632
bd0a84de3375 further reduce memory leaks from parse errors (bug #40231)
John W. Eaton <jwe@octave.org>
parents: 17629
diff changeset
719 {
bd0a84de3375 further reduce memory leaks from parse errors (bug #40231)
John W. Eaton <jwe@octave.org>
parents: 17629
diff changeset
720 // make_index_expression deleted $1 and $3.
bd0a84de3375 further reduce memory leaks from parse errors (bug #40231)
John W. Eaton <jwe@octave.org>
parents: 17629
diff changeset
721 ABORT_PARSE;
bd0a84de3375 further reduce memory leaks from parse errors (bug #40231)
John W. Eaton <jwe@octave.org>
parents: 17629
diff changeset
722 }
17622
fd712a12fe53 compatibility for power operator precedence and direction (bug #33304)
Axel Mathéi <axel.mathei@gmail.com>
parents: 17618
diff changeset
723 }
fd712a12fe53 compatibility for power operator precedence and direction (bug #33304)
Axel Mathéi <axel.mathei@gmail.com>
parents: 17618
diff changeset
724 | 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
725 { $$ = 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
726 | 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
727 { $$ = 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
728 | 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
729 { $$ = 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
730 | 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
731 { $$ = 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
732 | 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
733 { $$ = 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
734 | '+' 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
735 { $$ = 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
736 | '-' 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
737 { $$ = 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
738 ;
fd712a12fe53 compatibility for power operator precedence and direction (bug #33304)
Axel Mathéi <axel.mathei@gmail.com>
parents: 17618
diff changeset
739
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
740 colon_expr : colon_expr1
16288
fe3b9a51e625 rename curr_lexer, curr_parser, CURR_LEXER
John W. Eaton <jwe@octave.org>
parents: 16287
diff changeset
741 { $$ = parser.finish_colon_expression ($1); }
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
742 ;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
743
12627
002948ae5bc0 fix precedence level of transpose operators (bug #32533)
John W. Eaton <jwe@octave.org>
parents: 12483
diff changeset
744 colon_expr1 : oper_expr
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
745 { $$ = 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
746 | colon_expr1 ':' oper_expr
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
747 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
748 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
749 {
bd0a84de3375 further reduce memory leaks from parse errors (bug #40231)
John W. Eaton <jwe@octave.org>
parents: 17629
diff changeset
750 delete $1;
bd0a84de3375 further reduce memory leaks from parse errors (bug #40231)
John W. Eaton <jwe@octave.org>
parents: 17629
diff changeset
751 delete $3;
bd0a84de3375 further reduce memory leaks from parse errors (bug #40231)
John W. Eaton <jwe@octave.org>
parents: 17629
diff changeset
752 ABORT_PARSE;
bd0a84de3375 further reduce memory leaks from parse errors (bug #40231)
John W. Eaton <jwe@octave.org>
parents: 17629
diff changeset
753 }
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
754 }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
755 ;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
756
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
757 simple_expr : colon_expr
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
758 { $$ = $1; }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
759 | simple_expr LSHIFT simple_expr
16288
fe3b9a51e625 rename curr_lexer, curr_parser, CURR_LEXER
John W. Eaton <jwe@octave.org>
parents: 16287
diff changeset
760 { $$ = parser.make_binary_op (LSHIFT, $1, $2, $3); }
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
761 | simple_expr RSHIFT simple_expr
16288
fe3b9a51e625 rename curr_lexer, curr_parser, CURR_LEXER
John W. Eaton <jwe@octave.org>
parents: 16287
diff changeset
762 { $$ = parser.make_binary_op (RSHIFT, $1, $2, $3); }
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
763 | 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
764 { $$ = 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
765 | 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
766 { $$ = 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
767 | 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
768 { $$ = 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
769 | 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
770 { $$ = 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
771 | 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
772 { $$ = 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
773 | 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
774 { $$ = 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
775 | 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
776 { $$ = 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
777 | 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
778 { $$ = 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
779 | 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
780 { $$ = 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
781 | 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
782 { $$ = 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
783 ;
2970
b9e64477f703 [project @ 1997-05-15 18:04:21 by jwe]
jwe
parents: 2961
diff changeset
784
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
785 assign_lhs : simple_expr
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
786 {
16288
fe3b9a51e625 rename curr_lexer, curr_parser, CURR_LEXER
John W. Eaton <jwe@octave.org>
parents: 16287
diff changeset
787 $$ = parser.validate_matrix_for_assignment ($1);
16273
c5e5f6ccac5d 9/10 commits reworking the lexer
John W. Eaton <jwe@octave.org>
parents: 16265
diff changeset
788
c5e5f6ccac5d 9/10 commits reworking the lexer
John W. Eaton <jwe@octave.org>
parents: 16265
diff changeset
789 if ($$)
16288
fe3b9a51e625 rename curr_lexer, curr_parser, CURR_LEXER
John W. Eaton <jwe@octave.org>
parents: 16287
diff changeset
790 { 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
791 else
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
792 {
16277
8cb65fd72164 eliminate obsolete concepts of "pending local" and "forced" variables
John W. Eaton <jwe@octave.org>
parents: 16273
diff changeset
793 // validate_matrix_for_assignment deleted $1.
16273
c5e5f6ccac5d 9/10 commits reworking the lexer
John W. Eaton <jwe@octave.org>
parents: 16265
diff changeset
794 ABORT_PARSE;
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
795 }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
796 }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
797 ;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
798
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
799 assign_expr : assign_lhs '=' expression
16288
fe3b9a51e625 rename curr_lexer, curr_parser, CURR_LEXER
John W. Eaton <jwe@octave.org>
parents: 16287
diff changeset
800 { $$ = parser.make_assign_op ('=', $1, $2, $3); }
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
801 | assign_lhs ADD_EQ expression
16288
fe3b9a51e625 rename curr_lexer, curr_parser, CURR_LEXER
John W. Eaton <jwe@octave.org>
parents: 16287
diff changeset
802 { $$ = 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
803 | assign_lhs SUB_EQ expression
16288
fe3b9a51e625 rename curr_lexer, curr_parser, CURR_LEXER
John W. Eaton <jwe@octave.org>
parents: 16287
diff changeset
804 { $$ = 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
805 | assign_lhs MUL_EQ expression
16288
fe3b9a51e625 rename curr_lexer, curr_parser, CURR_LEXER
John W. Eaton <jwe@octave.org>
parents: 16287
diff changeset
806 { $$ = 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
807 | assign_lhs DIV_EQ expression
16288
fe3b9a51e625 rename curr_lexer, curr_parser, CURR_LEXER
John W. Eaton <jwe@octave.org>
parents: 16287
diff changeset
808 { $$ = 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
809 | assign_lhs LEFTDIV_EQ expression
16288
fe3b9a51e625 rename curr_lexer, curr_parser, CURR_LEXER
John W. Eaton <jwe@octave.org>
parents: 16287
diff changeset
810 { $$ = 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
811 | assign_lhs POW_EQ expression
16288
fe3b9a51e625 rename curr_lexer, curr_parser, CURR_LEXER
John W. Eaton <jwe@octave.org>
parents: 16287
diff changeset
812 { $$ = 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
813 | assign_lhs LSHIFT_EQ expression
16288
fe3b9a51e625 rename curr_lexer, curr_parser, CURR_LEXER
John W. Eaton <jwe@octave.org>
parents: 16287
diff changeset
814 { $$ = parser.make_assign_op (LSHIFT_EQ, $1, $2, $3); }
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
815 | assign_lhs RSHIFT_EQ expression
16288
fe3b9a51e625 rename curr_lexer, curr_parser, CURR_LEXER
John W. Eaton <jwe@octave.org>
parents: 16287
diff changeset
816 { $$ = parser.make_assign_op (RSHIFT_EQ, $1, $2, $3); }
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
817 | assign_lhs EMUL_EQ expression
16288
fe3b9a51e625 rename curr_lexer, curr_parser, CURR_LEXER
John W. Eaton <jwe@octave.org>
parents: 16287
diff changeset
818 { $$ = 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
819 | assign_lhs EDIV_EQ expression
16288
fe3b9a51e625 rename curr_lexer, curr_parser, CURR_LEXER
John W. Eaton <jwe@octave.org>
parents: 16287
diff changeset
820 { $$ = 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
821 | assign_lhs ELEFTDIV_EQ expression
16288
fe3b9a51e625 rename curr_lexer, curr_parser, CURR_LEXER
John W. Eaton <jwe@octave.org>
parents: 16287
diff changeset
822 { $$ = 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
823 | assign_lhs EPOW_EQ expression
16288
fe3b9a51e625 rename curr_lexer, curr_parser, CURR_LEXER
John W. Eaton <jwe@octave.org>
parents: 16287
diff changeset
824 { $$ = 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
825 | assign_lhs AND_EQ expression
16288
fe3b9a51e625 rename curr_lexer, curr_parser, CURR_LEXER
John W. Eaton <jwe@octave.org>
parents: 16287
diff changeset
826 { $$ = 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
827 | assign_lhs OR_EQ expression
16288
fe3b9a51e625 rename curr_lexer, curr_parser, CURR_LEXER
John W. Eaton <jwe@octave.org>
parents: 16287
diff changeset
828 { $$ = 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
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 expression : simple_expr
16273
c5e5f6ccac5d 9/10 commits reworking the lexer
John W. Eaton <jwe@octave.org>
parents: 16265
diff changeset
832 {
c5e5f6ccac5d 9/10 commits reworking the lexer
John W. Eaton <jwe@octave.org>
parents: 16265
diff changeset
833 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
834 {
16288
fe3b9a51e625 rename curr_lexer, curr_parser, CURR_LEXER
John W. Eaton <jwe@octave.org>
parents: 16287
diff changeset
835 if (parser.validate_array_list ($1))
16273
c5e5f6ccac5d 9/10 commits reworking the lexer
John W. Eaton <jwe@octave.org>
parents: 16265
diff changeset
836 $$ = $1;
c5e5f6ccac5d 9/10 commits reworking the lexer
John W. Eaton <jwe@octave.org>
parents: 16265
diff changeset
837 else
c5e5f6ccac5d 9/10 commits reworking the lexer
John W. Eaton <jwe@octave.org>
parents: 16265
diff changeset
838 {
c5e5f6ccac5d 9/10 commits reworking the lexer
John W. Eaton <jwe@octave.org>
parents: 16265
diff changeset
839 delete $1;
c5e5f6ccac5d 9/10 commits reworking the lexer
John W. Eaton <jwe@octave.org>
parents: 16265
diff changeset
840 ABORT_PARSE;
c5e5f6ccac5d 9/10 commits reworking the lexer
John W. Eaton <jwe@octave.org>
parents: 16265
diff changeset
841 }
c5e5f6ccac5d 9/10 commits reworking the lexer
John W. Eaton <jwe@octave.org>
parents: 16265
diff changeset
842 }
c5e5f6ccac5d 9/10 commits reworking the lexer
John W. Eaton <jwe@octave.org>
parents: 16265
diff changeset
843 else
c5e5f6ccac5d 9/10 commits reworking the lexer
John W. Eaton <jwe@octave.org>
parents: 16265
diff changeset
844 $$ = $1;
c5e5f6ccac5d 9/10 commits reworking the lexer
John W. Eaton <jwe@octave.org>
parents: 16265
diff changeset
845 }
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
846 | assign_expr
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
847 { $$ = $1; }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
848 | anon_fcn_handle
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
849 { $$ = $1; }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
850 ;
2970
b9e64477f703 [project @ 1997-05-15 18:04:21 by jwe]
jwe
parents: 2961
diff changeset
851
b9e64477f703 [project @ 1997-05-15 18:04:21 by jwe]
jwe
parents: 2961
diff changeset
852 // ================================================
b9e64477f703 [project @ 1997-05-15 18:04:21 by jwe]
jwe
parents: 2961
diff changeset
853 // Commands, declarations, and function definitions
b9e64477f703 [project @ 1997-05-15 18:04:21 by jwe]
jwe
parents: 2961
diff changeset
854 // ================================================
b9e64477f703 [project @ 1997-05-15 18:04:21 by jwe]
jwe
parents: 2961
diff changeset
855
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
856 command : declaration
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
857 { $$ = $1; }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
858 | select_command
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
859 { $$ = $1; }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
860 | loop_command
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
861 { $$ = $1; }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
862 | jump_command
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
863 { $$ = $1; }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
864 | except_command
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
865 { $$ = $1; }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
866 | function
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
867 { $$ = $1; }
16203
127cccb037bf move more global parser and lexer variables to classes
John W. Eaton <jwe@octave.org>
parents: 16199
diff changeset
868 | file
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
869 { $$ = $1; }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
870 | classdef
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
871 { $$ = $1; }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
872 ;
2970
b9e64477f703 [project @ 1997-05-15 18:04:21 by jwe]
jwe
parents: 2961
diff changeset
873
b9e64477f703 [project @ 1997-05-15 18:04:21 by jwe]
jwe
parents: 2961
diff changeset
874 // =====================
b9e64477f703 [project @ 1997-05-15 18:04:21 by jwe]
jwe
parents: 2961
diff changeset
875 // Declaration statemnts
b9e64477f703 [project @ 1997-05-15 18:04:21 by jwe]
jwe
parents: 2961
diff changeset
876 // =====================
b9e64477f703 [project @ 1997-05-15 18:04:21 by jwe]
jwe
parents: 2961
diff changeset
877
16263
9acb86e6ac90 4/10 commits reworking the lexer
John W. Eaton <jwe@octave.org>
parents: 16259
diff changeset
878 declaration : GLOBAL decl1
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
879 {
16288
fe3b9a51e625 rename curr_lexer, curr_parser, CURR_LEXER
John W. Eaton <jwe@octave.org>
parents: 16287
diff changeset
880 $$ = 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
881 lexer.looking_at_decl_list = false;
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
882 }
16263
9acb86e6ac90 4/10 commits reworking the lexer
John W. Eaton <jwe@octave.org>
parents: 16259
diff changeset
883 | PERSISTENT decl1
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
884 {
16288
fe3b9a51e625 rename curr_lexer, curr_parser, CURR_LEXER
John W. Eaton <jwe@octave.org>
parents: 16287
diff changeset
885 $$ = 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
886 lexer.looking_at_decl_list = false;
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
887 }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
888 ;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
889
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
890 decl1 : decl2
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
891 { $$ = new tree_decl_init_list ($1); }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
892 | decl1 decl2
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
893 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
894 $1->append ($2);
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
895 $$ = $1;
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 ;
2970
b9e64477f703 [project @ 1997-05-15 18:04:21 by jwe]
jwe
parents: 2961
diff changeset
898
7634
ae90e05ad299 fix parameter list initializer bug
John W. Eaton <jwe@octave.org>
parents: 7587
diff changeset
899 decl_param_init : // empty
16288
fe3b9a51e625 rename curr_lexer, curr_parser, CURR_LEXER
John W. Eaton <jwe@octave.org>
parents: 16287
diff changeset
900 { lexer.looking_at_initializer_expression = true; }
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
901
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
902 decl2 : identifier
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
903 { $$ = new tree_decl_elt ($1); }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
904 | identifier '=' decl_param_init expression
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
905 {
16288
fe3b9a51e625 rename curr_lexer, curr_parser, CURR_LEXER
John W. Eaton <jwe@octave.org>
parents: 16287
diff changeset
906 lexer.looking_at_initializer_expression = false;
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
907 $$ = new tree_decl_elt ($1, $4);
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
908 }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
909 ;
2970
b9e64477f703 [project @ 1997-05-15 18:04:21 by jwe]
jwe
parents: 2961
diff changeset
910
b9e64477f703 [project @ 1997-05-15 18:04:21 by jwe]
jwe
parents: 2961
diff changeset
911 // ====================
b9e64477f703 [project @ 1997-05-15 18:04:21 by jwe]
jwe
parents: 2961
diff changeset
912 // Selection statements
b9e64477f703 [project @ 1997-05-15 18:04:21 by jwe]
jwe
parents: 2961
diff changeset
913 // ====================
b9e64477f703 [project @ 1997-05-15 18:04:21 by jwe]
jwe
parents: 2961
diff changeset
914
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
915 select_command : if_command
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
916 { $$ = $1; }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
917 | switch_command
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
918 { $$ = $1; }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
919 ;
2970
b9e64477f703 [project @ 1997-05-15 18:04:21 by jwe]
jwe
parents: 2961
diff changeset
920
b9e64477f703 [project @ 1997-05-15 18:04:21 by jwe]
jwe
parents: 2961
diff changeset
921 // ============
b9e64477f703 [project @ 1997-05-15 18:04:21 by jwe]
jwe
parents: 2961
diff changeset
922 // If statement
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
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
925 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
926 {
16288
fe3b9a51e625 rename curr_lexer, curr_parser, CURR_LEXER
John W. Eaton <jwe@octave.org>
parents: 16287
diff changeset
927 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
928 {
bd0a84de3375 further reduce memory leaks from parse errors (bug #40231)
John W. Eaton <jwe@octave.org>
parents: 17629
diff changeset
929 // finish_if_command deleted $3.
bd0a84de3375 further reduce memory leaks from parse errors (bug #40231)
John W. Eaton <jwe@octave.org>
parents: 17629
diff changeset
930 ABORT_PARSE;
bd0a84de3375 further reduce memory leaks from parse errors (bug #40231)
John W. Eaton <jwe@octave.org>
parents: 17629
diff changeset
931 }
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
932 }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
933 ;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
934
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
935 if_cmd_list : if_cmd_list1
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 | if_cmd_list1 else_clause
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
938 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
939 $1->append ($2);
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 }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
942 ;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
943
16681
d3619d4d267c recognize character string at beginning of statement (bug #38926, #38958)
John W. Eaton <jwe@octave.org>
parents: 16627
diff changeset
944 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
945 {
18127
d76f790b4eec enable do_braindead_shortcircuit_evaluation by default and deprecate
John W. Eaton <jwe@octave.org>
parents: 17796
diff changeset
946 $1->mark_braindead_shortcircuit ();
16288
fe3b9a51e625 rename curr_lexer, curr_parser, CURR_LEXER
John W. Eaton <jwe@octave.org>
parents: 16287
diff changeset
947
16681
d3619d4d267c recognize character string at beginning of statement (bug #38926, #38958)
John W. Eaton <jwe@octave.org>
parents: 16627
diff changeset
948 $$ = 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
949 }
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
950 | if_cmd_list1 elseif_clause
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
951 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
952 $1->append ($2);
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
953 $$ = $1;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
954 }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
955 ;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
956
16681
d3619d4d267c recognize character string at beginning of statement (bug #38926, #38958)
John W. Eaton <jwe@octave.org>
parents: 16627
diff changeset
957 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
958 {
18127
d76f790b4eec enable do_braindead_shortcircuit_evaluation by default and deprecate
John W. Eaton <jwe@octave.org>
parents: 17796
diff changeset
959 $4->mark_braindead_shortcircuit ();
16288
fe3b9a51e625 rename curr_lexer, curr_parser, CURR_LEXER
John W. Eaton <jwe@octave.org>
parents: 16287
diff changeset
960
16681
d3619d4d267c recognize character string at beginning of statement (bug #38926, #38958)
John W. Eaton <jwe@octave.org>
parents: 16627
diff changeset
961 $$ = 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
962 }
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
963 ;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
964
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
965 else_clause : ELSE stash_comment opt_sep opt_list
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
966 { $$ = new tree_if_clause ($4, $2); }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
967 ;
2970
b9e64477f703 [project @ 1997-05-15 18:04:21 by jwe]
jwe
parents: 2961
diff changeset
968
b9e64477f703 [project @ 1997-05-15 18:04:21 by jwe]
jwe
parents: 2961
diff changeset
969 // ================
b9e64477f703 [project @ 1997-05-15 18:04:21 by jwe]
jwe
parents: 2961
diff changeset
970 // Switch statement
b9e64477f703 [project @ 1997-05-15 18:04:21 by jwe]
jwe
parents: 2961
diff changeset
971 // ================
b9e64477f703 [project @ 1997-05-15 18:04:21 by jwe]
jwe
parents: 2961
diff changeset
972
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
973 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
974 {
16288
fe3b9a51e625 rename curr_lexer, curr_parser, CURR_LEXER
John W. Eaton <jwe@octave.org>
parents: 16287
diff changeset
975 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
976 {
bd0a84de3375 further reduce memory leaks from parse errors (bug #40231)
John W. Eaton <jwe@octave.org>
parents: 17629
diff changeset
977 // finish_switch_command deleted $3 adn $5.
bd0a84de3375 further reduce memory leaks from parse errors (bug #40231)
John W. Eaton <jwe@octave.org>
parents: 17629
diff changeset
978 ABORT_PARSE;
bd0a84de3375 further reduce memory leaks from parse errors (bug #40231)
John W. Eaton <jwe@octave.org>
parents: 17629
diff changeset
979 }
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
980 }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
981 ;
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 case_list : // empty
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
984 { $$ = 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
985 | default_case
2da532d0f41c accept otherwise clause in switch statement without preceding case statements
John W. Eaton <jwe@octave.org>
parents: 11258
diff changeset
986 { $$ = new tree_switch_case_list ($1); }
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
987 | case_list1
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
988 { $$ = $1; }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
989 | case_list1 default_case
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
990 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
991 $1->append ($2);
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
992 $$ = $1;
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11572
diff changeset
993 }
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
994 ;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
995
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
996 case_list1 : switch_case
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
997 { $$ = new tree_switch_case_list ($1); }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
998 | case_list1 switch_case
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
999 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
1000 $1->append ($2);
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
1001 $$ = $1;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
1002 }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
1003 ;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
1004
16681
d3619d4d267c recognize character string at beginning of statement (bug #38926, #38958)
John W. Eaton <jwe@octave.org>
parents: 16627
diff changeset
1005 switch_case : CASE stash_comment opt_sep expression stmt_begin opt_sep opt_list
d3619d4d267c recognize character string at beginning of statement (bug #38926, #38958)
John W. Eaton <jwe@octave.org>
parents: 16627
diff changeset
1006 { $$ = parser.make_switch_case ($1, $4, $7, $2); }
10315
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 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
1010 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
1011 $$ = new tree_switch_case ($4, $2);
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 ;
2970
b9e64477f703 [project @ 1997-05-15 18:04:21 by jwe]
jwe
parents: 2961
diff changeset
1014
b9e64477f703 [project @ 1997-05-15 18:04:21 by jwe]
jwe
parents: 2961
diff changeset
1015 // =======
b9e64477f703 [project @ 1997-05-15 18:04:21 by jwe]
jwe
parents: 2961
diff changeset
1016 // Looping
b9e64477f703 [project @ 1997-05-15 18:04:21 by jwe]
jwe
parents: 2961
diff changeset
1017 // =======
b9e64477f703 [project @ 1997-05-15 18:04:21 by jwe]
jwe
parents: 2961
diff changeset
1018
16681
d3619d4d267c recognize character string at beginning of statement (bug #38926, #38958)
John W. Eaton <jwe@octave.org>
parents: 16627
diff changeset
1019 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
1020 {
18127
d76f790b4eec enable do_braindead_shortcircuit_evaluation by default and deprecate
John W. Eaton <jwe@octave.org>
parents: 17796
diff changeset
1021 $3->mark_braindead_shortcircuit ();
16288
fe3b9a51e625 rename curr_lexer, curr_parser, CURR_LEXER
John W. Eaton <jwe@octave.org>
parents: 16287
diff changeset
1022
16681
d3619d4d267c recognize character string at beginning of statement (bug #38926, #38958)
John W. Eaton <jwe@octave.org>
parents: 16627
diff changeset
1023 if (! ($$ = 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
1024 {
bd0a84de3375 further reduce memory leaks from parse errors (bug #40231)
John W. Eaton <jwe@octave.org>
parents: 17629
diff changeset
1025 // make_while_command deleted $3 and $6.
bd0a84de3375 further reduce memory leaks from parse errors (bug #40231)
John W. Eaton <jwe@octave.org>
parents: 17629
diff changeset
1026 ABORT_PARSE;
bd0a84de3375 further reduce memory leaks from parse errors (bug #40231)
John W. Eaton <jwe@octave.org>
parents: 17629
diff changeset
1027 }
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
1028 }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
1029 | 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
1030 {
17632
bd0a84de3375 further reduce memory leaks from parse errors (bug #40231)
John W. Eaton <jwe@octave.org>
parents: 17629
diff changeset
1031 $$ = 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
1032 }
16681
d3619d4d267c recognize character string at beginning of statement (bug #38926, #38958)
John W. Eaton <jwe@octave.org>
parents: 16627
diff changeset
1033 | 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
1034 {
16288
fe3b9a51e625 rename curr_lexer, curr_parser, CURR_LEXER
John W. Eaton <jwe@octave.org>
parents: 16287
diff changeset
1035 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
1036 $8, $9, $2)))
bd0a84de3375 further reduce memory leaks from parse errors (bug #40231)
John W. Eaton <jwe@octave.org>
parents: 17629
diff changeset
1037 {
bd0a84de3375 further reduce memory leaks from parse errors (bug #40231)
John W. Eaton <jwe@octave.org>
parents: 17629
diff changeset
1038 // make_for_command deleted $3, $5, and $8.
bd0a84de3375 further reduce memory leaks from parse errors (bug #40231)
John W. Eaton <jwe@octave.org>
parents: 17629
diff changeset
1039 ABORT_PARSE;
bd0a84de3375 further reduce memory leaks from parse errors (bug #40231)
John W. Eaton <jwe@octave.org>
parents: 17629
diff changeset
1040 }
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
1041 }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
1042 | 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
1043 {
16288
fe3b9a51e625 rename curr_lexer, curr_parser, CURR_LEXER
John W. Eaton <jwe@octave.org>
parents: 16287
diff changeset
1044 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
1045 $9, $10, $2)))
bd0a84de3375 further reduce memory leaks from parse errors (bug #40231)
John W. Eaton <jwe@octave.org>
parents: 17629
diff changeset
1046 {
bd0a84de3375 further reduce memory leaks from parse errors (bug #40231)
John W. Eaton <jwe@octave.org>
parents: 17629
diff changeset
1047 // make_for_command deleted $4, $6, and $9.
bd0a84de3375 further reduce memory leaks from parse errors (bug #40231)
John W. Eaton <jwe@octave.org>
parents: 17629
diff changeset
1048 ABORT_PARSE;
bd0a84de3375 further reduce memory leaks from parse errors (bug #40231)
John W. Eaton <jwe@octave.org>
parents: 17629
diff changeset
1049 }
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
1050 }
16681
d3619d4d267c recognize character string at beginning of statement (bug #38926, #38958)
John W. Eaton <jwe@octave.org>
parents: 16627
diff changeset
1051 | 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
1052 {
16288
fe3b9a51e625 rename curr_lexer, curr_parser, CURR_LEXER
John W. Eaton <jwe@octave.org>
parents: 16287
diff changeset
1053 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
1054 0, $8, $9, $2)))
bd0a84de3375 further reduce memory leaks from parse errors (bug #40231)
John W. Eaton <jwe@octave.org>
parents: 17629
diff changeset
1055 {
bd0a84de3375 further reduce memory leaks from parse errors (bug #40231)
John W. Eaton <jwe@octave.org>
parents: 17629
diff changeset
1056 // make_for_command deleted $3, $5, and $8.
bd0a84de3375 further reduce memory leaks from parse errors (bug #40231)
John W. Eaton <jwe@octave.org>
parents: 17629
diff changeset
1057 ABORT_PARSE;
bd0a84de3375 further reduce memory leaks from parse errors (bug #40231)
John W. Eaton <jwe@octave.org>
parents: 17629
diff changeset
1058 }
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
1059 }
027a2186cd90 parfor keyword and infrastructure, but handle parfor as normal for loop for now
John W. Eaton <jwe@octave.org>
parents: 13241
diff changeset
1060 | 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
1061 {
16288
fe3b9a51e625 rename curr_lexer, curr_parser, CURR_LEXER
John W. Eaton <jwe@octave.org>
parents: 16287
diff changeset
1062 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
1063 $8, $11, $12, $2)))
bd0a84de3375 further reduce memory leaks from parse errors (bug #40231)
John W. Eaton <jwe@octave.org>
parents: 17629
diff changeset
1064 {
bd0a84de3375 further reduce memory leaks from parse errors (bug #40231)
John W. Eaton <jwe@octave.org>
parents: 17629
diff changeset
1065 // make_for_command deleted $4, $6, $8, and $11.
bd0a84de3375 further reduce memory leaks from parse errors (bug #40231)
John W. Eaton <jwe@octave.org>
parents: 17629
diff changeset
1066 ABORT_PARSE;
bd0a84de3375 further reduce memory leaks from parse errors (bug #40231)
John W. Eaton <jwe@octave.org>
parents: 17629
diff changeset
1067 }
10315
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 ;
2970
b9e64477f703 [project @ 1997-05-15 18:04:21 by jwe]
jwe
parents: 2961
diff changeset
1070
b9e64477f703 [project @ 1997-05-15 18:04:21 by jwe]
jwe
parents: 2961
diff changeset
1071 // =======
b9e64477f703 [project @ 1997-05-15 18:04:21 by jwe]
jwe
parents: 2961
diff changeset
1072 // Jumping
b9e64477f703 [project @ 1997-05-15 18:04:21 by jwe]
jwe
parents: 2961
diff changeset
1073 // =======
b9e64477f703 [project @ 1997-05-15 18:04:21 by jwe]
jwe
parents: 2961
diff changeset
1074
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
1075 jump_command : BREAK
17632
bd0a84de3375 further reduce memory leaks from parse errors (bug #40231)
John W. Eaton <jwe@octave.org>
parents: 17629
diff changeset
1076 { $$ = parser.make_break_command ($1); }
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
1077 | CONTINUE
17632
bd0a84de3375 further reduce memory leaks from parse errors (bug #40231)
John W. Eaton <jwe@octave.org>
parents: 17629
diff changeset
1078 { $$ = parser.make_continue_command ($1); }
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
1079 | FUNC_RET
17632
bd0a84de3375 further reduce memory leaks from parse errors (bug #40231)
John W. Eaton <jwe@octave.org>
parents: 17629
diff changeset
1080 { $$ = parser.make_return_command ($1); }
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
1081 ;
2970
b9e64477f703 [project @ 1997-05-15 18:04:21 by jwe]
jwe
parents: 2961
diff changeset
1082
b9e64477f703 [project @ 1997-05-15 18:04:21 by jwe]
jwe
parents: 2961
diff changeset
1083 // ==========
b9e64477f703 [project @ 1997-05-15 18:04:21 by jwe]
jwe
parents: 2961
diff changeset
1084 // Exceptions
b9e64477f703 [project @ 1997-05-15 18:04:21 by jwe]
jwe
parents: 2961
diff changeset
1085 // ==========
b9e64477f703 [project @ 1997-05-15 18:04:21 by jwe]
jwe
parents: 2961
diff changeset
1086
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
1087 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
1088 stash_comment opt_sep opt_list END
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
1089 {
16288
fe3b9a51e625 rename curr_lexer, curr_parser, CURR_LEXER
John W. Eaton <jwe@octave.org>
parents: 16287
diff changeset
1090 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
1091 {
bd0a84de3375 further reduce memory leaks from parse errors (bug #40231)
John W. Eaton <jwe@octave.org>
parents: 17629
diff changeset
1092 // make_unwind_command deleted $4 and $8.
bd0a84de3375 further reduce memory leaks from parse errors (bug #40231)
John W. Eaton <jwe@octave.org>
parents: 17629
diff changeset
1093 ABORT_PARSE;
bd0a84de3375 further reduce memory leaks from parse errors (bug #40231)
John W. Eaton <jwe@octave.org>
parents: 17629
diff changeset
1094 }
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
1095 }
17283
e6c0ac8ce5b6 eliminate parse conflicts introduced by changeset 923ce8b42db2
John W. Eaton <jwe@octave.org>
parents: 17281
diff changeset
1096 | 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
1097 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
1098 {
17283
e6c0ac8ce5b6 eliminate parse conflicts introduced by changeset 923ce8b42db2
John W. Eaton <jwe@octave.org>
parents: 17281
diff changeset
1099 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
1100 {
bd0a84de3375 further reduce memory leaks from parse errors (bug #40231)
John W. Eaton <jwe@octave.org>
parents: 17629
diff changeset
1101 // make_try_command deleted $4 and $8.
bd0a84de3375 further reduce memory leaks from parse errors (bug #40231)
John W. Eaton <jwe@octave.org>
parents: 17629
diff changeset
1102 ABORT_PARSE;
bd0a84de3375 further reduce memory leaks from parse errors (bug #40231)
John W. Eaton <jwe@octave.org>
parents: 17629
diff changeset
1103 }
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
1104 }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
1105 | TRY stash_comment opt_sep opt_list END
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
1106 {
17249
923ce8b42db2 improve try-catch-statement to save exception to a variable (bug #33217)
Stefan Mahr <dac922@gmx.de>
parents: 17170
diff changeset
1107 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
1108 {
bd0a84de3375 further reduce memory leaks from parse errors (bug #40231)
John W. Eaton <jwe@octave.org>
parents: 17629
diff changeset
1109 // make_try_command deleted $4.
bd0a84de3375 further reduce memory leaks from parse errors (bug #40231)
John W. Eaton <jwe@octave.org>
parents: 17629
diff changeset
1110 ABORT_PARSE;
bd0a84de3375 further reduce memory leaks from parse errors (bug #40231)
John W. Eaton <jwe@octave.org>
parents: 17629
diff changeset
1111 }
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
1112 }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
1113 ;
2970
b9e64477f703 [project @ 1997-05-15 18:04:21 by jwe]
jwe
parents: 2961
diff changeset
1114
b9e64477f703 [project @ 1997-05-15 18:04:21 by jwe]
jwe
parents: 2961
diff changeset
1115 // ===========================================
15466
d174210ce1ec use ' instead of ` in error messages, warnings and most comments
John W. Eaton <jwe@octave.org>
parents: 14189
diff changeset
1116 // Some 'subroutines' for function definitions
2970
b9e64477f703 [project @ 1997-05-15 18:04:21 by jwe]
jwe
parents: 2961
diff changeset
1117 // ===========================================
b9e64477f703 [project @ 1997-05-15 18:04:21 by jwe]
jwe
parents: 2961
diff changeset
1118
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
1119 push_fcn_symtab : // empty
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
1120 {
16288
fe3b9a51e625 rename curr_lexer, curr_parser, CURR_LEXER
John W. Eaton <jwe@octave.org>
parents: 16287
diff changeset
1121 parser.curr_fcn_depth++;
fe3b9a51e625 rename curr_lexer, curr_parser, CURR_LEXER
John W. Eaton <jwe@octave.org>
parents: 16287
diff changeset
1122
fe3b9a51e625 rename curr_lexer, curr_parser, CURR_LEXER
John W. Eaton <jwe@octave.org>
parents: 16287
diff changeset
1123 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
1124 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
1125
16320
09f0cb9cac7d don't modify symbol table scope in the parser
John W. Eaton <jwe@octave.org>
parents: 16302
diff changeset
1126 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
1127
09f0cb9cac7d don't modify symbol table scope in the parser
John W. Eaton <jwe@octave.org>
parents: 16302
diff changeset
1128 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
1129 (lexer.symtab_context.curr_scope ());
16288
fe3b9a51e625 rename curr_lexer, curr_parser, CURR_LEXER
John W. Eaton <jwe@octave.org>
parents: 16287
diff changeset
1130
fe3b9a51e625 rename curr_lexer, curr_parser, CURR_LEXER
John W. Eaton <jwe@octave.org>
parents: 16287
diff changeset
1131 if (! lexer.reading_script_file
fe3b9a51e625 rename curr_lexer, curr_parser, CURR_LEXER
John W. Eaton <jwe@octave.org>
parents: 16287
diff changeset
1132 && parser.curr_fcn_depth == 1
fe3b9a51e625 rename curr_lexer, curr_parser, CURR_LEXER
John W. Eaton <jwe@octave.org>
parents: 16287
diff changeset
1133 && ! parser.parsing_subfunctions)
16320
09f0cb9cac7d don't modify symbol table scope in the parser
John W. Eaton <jwe@octave.org>
parents: 16302
diff changeset
1134 parser.primary_fcn_scope
09f0cb9cac7d don't modify symbol table scope in the parser
John W. Eaton <jwe@octave.org>
parents: 16302
diff changeset
1135 = lexer.symtab_context.curr_scope ();
16288
fe3b9a51e625 rename curr_lexer, curr_parser, CURR_LEXER
John W. Eaton <jwe@octave.org>
parents: 16287
diff changeset
1136
fe3b9a51e625 rename curr_lexer, curr_parser, CURR_LEXER
John W. Eaton <jwe@octave.org>
parents: 16287
diff changeset
1137 if (lexer.reading_script_file
fe3b9a51e625 rename curr_lexer, curr_parser, CURR_LEXER
John W. Eaton <jwe@octave.org>
parents: 16287
diff changeset
1138 && parser.curr_fcn_depth > 1)
fe3b9a51e625 rename curr_lexer, curr_parser, CURR_LEXER
John W. Eaton <jwe@octave.org>
parents: 16287
diff changeset
1139 parser.bison_error ("nested functions not implemented in this context");
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
1140 }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
1141 ;
2970
b9e64477f703 [project @ 1997-05-15 18:04:21 by jwe]
jwe
parents: 2961
diff changeset
1142
b9e64477f703 [project @ 1997-05-15 18:04:21 by jwe]
jwe
parents: 2961
diff changeset
1143 // ===========================
b9e64477f703 [project @ 1997-05-15 18:04:21 by jwe]
jwe
parents: 2961
diff changeset
1144 // List of function parameters
b9e64477f703 [project @ 1997-05-15 18:04:21 by jwe]
jwe
parents: 2961
diff changeset
1145 // ===========================
b9e64477f703 [project @ 1997-05-15 18:04:21 by jwe]
jwe
parents: 2961
diff changeset
1146
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
1147 param_list_beg : '('
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
1148 {
16288
fe3b9a51e625 rename curr_lexer, curr_parser, CURR_LEXER
John W. Eaton <jwe@octave.org>
parents: 16287
diff changeset
1149 lexer.looking_at_parameter_list = true;
fe3b9a51e625 rename curr_lexer, curr_parser, CURR_LEXER
John W. Eaton <jwe@octave.org>
parents: 16287
diff changeset
1150
fe3b9a51e625 rename curr_lexer, curr_parser, CURR_LEXER
John W. Eaton <jwe@octave.org>
parents: 16287
diff changeset
1151 if (lexer.looking_at_function_handle)
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
1152 {
16320
09f0cb9cac7d don't modify symbol table scope in the parser
John W. Eaton <jwe@octave.org>
parents: 16302
diff changeset
1153 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
1154 lexer.looking_at_function_handle--;
fe3b9a51e625 rename curr_lexer, curr_parser, CURR_LEXER
John W. Eaton <jwe@octave.org>
parents: 16287
diff changeset
1155 lexer.looking_at_anon_fcn_args = true;
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
1156 }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
1157 }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
1158 ;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
1159
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
1160 param_list_end : ')'
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
1161 {
16288
fe3b9a51e625 rename curr_lexer, curr_parser, CURR_LEXER
John W. Eaton <jwe@octave.org>
parents: 16287
diff changeset
1162 lexer.looking_at_parameter_list = false;
fe3b9a51e625 rename curr_lexer, curr_parser, CURR_LEXER
John W. Eaton <jwe@octave.org>
parents: 16287
diff changeset
1163 lexer.looking_for_object_index = false;
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
1164 }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
1165 ;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
1166
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
1167 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
1168 {
11115c237231 recognize variables when parsing (bug #38576)
John W. Eaton <jwe@octave.org>
parents: 16320
diff changeset
1169 if ($2)
11115c237231 recognize variables when parsing (bug #38576)
John W. Eaton <jwe@octave.org>
parents: 16320
diff changeset
1170 lexer.mark_as_variables ($2->variable_names ());
11115c237231 recognize variables when parsing (bug #38576)
John W. Eaton <jwe@octave.org>
parents: 16320
diff changeset
1171
11115c237231 recognize variables when parsing (bug #38576)
John W. Eaton <jwe@octave.org>
parents: 16320
diff changeset
1172 $$ = $2;
11115c237231 recognize variables when parsing (bug #38576)
John W. Eaton <jwe@octave.org>
parents: 16320
diff changeset
1173 }
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
1174 | param_list_beg error
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
1175 {
16288
fe3b9a51e625 rename curr_lexer, curr_parser, CURR_LEXER
John W. Eaton <jwe@octave.org>
parents: 16287
diff changeset
1176 parser.bison_error ("invalid parameter list");
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
1177 $$ = 0;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
1178 ABORT_PARSE;
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 ;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
1181
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
1182 param_list1 : // empty
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
1183 { $$ = 0; }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
1184 | param_list2
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
1185 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
1186 $1->mark_as_formal_parameters ();
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
1187 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
1188 {
11115c237231 recognize variables when parsing (bug #38576)
John W. Eaton <jwe@octave.org>
parents: 16320
diff changeset
1189 lexer.mark_as_variables ($1->variable_names ());
11115c237231 recognize variables when parsing (bug #38576)
John W. Eaton <jwe@octave.org>
parents: 16320
diff changeset
1190 $$ = $1;
11115c237231 recognize variables when parsing (bug #38576)
John W. Eaton <jwe@octave.org>
parents: 16320
diff changeset
1191 }
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
1192 else
17632
bd0a84de3375 further reduce memory leaks from parse errors (bug #40231)
John W. Eaton <jwe@octave.org>
parents: 17629
diff changeset
1193 {
bd0a84de3375 further reduce memory leaks from parse errors (bug #40231)
John W. Eaton <jwe@octave.org>
parents: 17629
diff changeset
1194 delete $1;
bd0a84de3375 further reduce memory leaks from parse errors (bug #40231)
John W. Eaton <jwe@octave.org>
parents: 17629
diff changeset
1195 ABORT_PARSE;
bd0a84de3375 further reduce memory leaks from parse errors (bug #40231)
John W. Eaton <jwe@octave.org>
parents: 17629
diff changeset
1196 }
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
1197 }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
1198 ;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
1199
17317
56fe31b248de disallow ~ in global and persistent declaration lists
John W. Eaton <jwe@octave.org>
parents: 17316
diff changeset
1200 param_list2 : param_list_elt
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
1201 { $$ = new tree_parameter_list ($1); }
17317
56fe31b248de disallow ~ in global and persistent declaration lists
John W. Eaton <jwe@octave.org>
parents: 17316
diff changeset
1202 | param_list2 ',' param_list_elt
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
1203 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
1204 $1->append ($3);
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
1205 $$ = $1;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
1206 }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
1207 ;
2970
b9e64477f703 [project @ 1997-05-15 18:04:21 by jwe]
jwe
parents: 2961
diff changeset
1208
17317
56fe31b248de disallow ~ in global and persistent declaration lists
John W. Eaton <jwe@octave.org>
parents: 17316
diff changeset
1209 param_list_elt : decl2
56fe31b248de disallow ~ in global and persistent declaration lists
John W. Eaton <jwe@octave.org>
parents: 17316
diff changeset
1210 { $$ = $1; }
56fe31b248de disallow ~ in global and persistent declaration lists
John W. Eaton <jwe@octave.org>
parents: 17316
diff changeset
1211 | magic_tilde
56fe31b248de disallow ~ in global and persistent declaration lists
John W. Eaton <jwe@octave.org>
parents: 17316
diff changeset
1212 { $$ = new tree_decl_elt ($1); }
56fe31b248de disallow ~ in global and persistent declaration lists
John W. Eaton <jwe@octave.org>
parents: 17316
diff changeset
1213 ;
56fe31b248de disallow ~ in global and persistent declaration lists
John W. Eaton <jwe@octave.org>
parents: 17316
diff changeset
1214
2970
b9e64477f703 [project @ 1997-05-15 18:04:21 by jwe]
jwe
parents: 2961
diff changeset
1215 // ===================================
b9e64477f703 [project @ 1997-05-15 18:04:21 by jwe]
jwe
parents: 2961
diff changeset
1216 // List of function return value names
b9e64477f703 [project @ 1997-05-15 18:04:21 by jwe]
jwe
parents: 2961
diff changeset
1217 // ===================================
b9e64477f703 [project @ 1997-05-15 18:04:21 by jwe]
jwe
parents: 2961
diff changeset
1218
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
1219 return_list : '[' ']'
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
1220 {
16288
fe3b9a51e625 rename curr_lexer, curr_parser, CURR_LEXER
John W. Eaton <jwe@octave.org>
parents: 16287
diff changeset
1221 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
1222
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
1223 $$ = new tree_parameter_list ();
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
1224 }
17316
8e2906e2fb26 avoid reduce/reduce conflict in parser rules
John W. Eaton <jwe@octave.org>
parents: 17283
diff changeset
1225 | identifier
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
1226 {
16288
fe3b9a51e625 rename curr_lexer, curr_parser, CURR_LEXER
John W. Eaton <jwe@octave.org>
parents: 16287
diff changeset
1227 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
1228
8e2906e2fb26 avoid reduce/reduce conflict in parser rules
John W. Eaton <jwe@octave.org>
parents: 17283
diff changeset
1229 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
1230
8e2906e2fb26 avoid reduce/reduce conflict in parser rules
John W. Eaton <jwe@octave.org>
parents: 17283
diff changeset
1231 // 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
1232 // 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
1233 // to check for varargin or varargout.
8e2906e2fb26 avoid reduce/reduce conflict in parser rules
John W. Eaton <jwe@octave.org>
parents: 17283
diff changeset
1234
8e2906e2fb26 avoid reduce/reduce conflict in parser rules
John W. Eaton <jwe@octave.org>
parents: 17283
diff changeset
1235 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
1236 $$ = tmp;
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
1237 else
17632
bd0a84de3375 further reduce memory leaks from parse errors (bug #40231)
John W. Eaton <jwe@octave.org>
parents: 17629
diff changeset
1238 {
bd0a84de3375 further reduce memory leaks from parse errors (bug #40231)
John W. Eaton <jwe@octave.org>
parents: 17629
diff changeset
1239 delete tmp;
bd0a84de3375 further reduce memory leaks from parse errors (bug #40231)
John W. Eaton <jwe@octave.org>
parents: 17629
diff changeset
1240 ABORT_PARSE;
bd0a84de3375 further reduce memory leaks from parse errors (bug #40231)
John W. Eaton <jwe@octave.org>
parents: 17629
diff changeset
1241 }
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
1242 }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
1243 | '[' return_list1 ']'
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
1244 {
16288
fe3b9a51e625 rename curr_lexer, curr_parser, CURR_LEXER
John W. Eaton <jwe@octave.org>
parents: 16287
diff changeset
1245 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
1246
8e2906e2fb26 avoid reduce/reduce conflict in parser rules
John W. Eaton <jwe@octave.org>
parents: 17283
diff changeset
1247 // Check for duplicate parameter names, varargin,
8e2906e2fb26 avoid reduce/reduce conflict in parser rules
John W. Eaton <jwe@octave.org>
parents: 17283
diff changeset
1248 // or varargout.
8e2906e2fb26 avoid reduce/reduce conflict in parser rules
John W. Eaton <jwe@octave.org>
parents: 17283
diff changeset
1249
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
1250 if ($2->validate (tree_parameter_list::out))
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
1251 $$ = $2;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
1252 else
17632
bd0a84de3375 further reduce memory leaks from parse errors (bug #40231)
John W. Eaton <jwe@octave.org>
parents: 17629
diff changeset
1253 {
bd0a84de3375 further reduce memory leaks from parse errors (bug #40231)
John W. Eaton <jwe@octave.org>
parents: 17629
diff changeset
1254 delete $2;
bd0a84de3375 further reduce memory leaks from parse errors (bug #40231)
John W. Eaton <jwe@octave.org>
parents: 17629
diff changeset
1255 ABORT_PARSE;
bd0a84de3375 further reduce memory leaks from parse errors (bug #40231)
John W. Eaton <jwe@octave.org>
parents: 17629
diff changeset
1256 }
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
1257 }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
1258 ;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
1259
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
1260 return_list1 : identifier
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
1261 { $$ = 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
1262 | return_list1 ',' identifier
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
1263 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
1264 $1->append (new tree_decl_elt ($3));
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
1265 $$ = $1;
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
16203
127cccb037bf move more global parser and lexer variables to classes
John W. Eaton <jwe@octave.org>
parents: 16199
diff changeset
1269 // =======================
127cccb037bf move more global parser and lexer variables to classes
John W. Eaton <jwe@octave.org>
parents: 16199
diff changeset
1270 // Script or function file
127cccb037bf move more global parser and lexer variables to classes
John W. Eaton <jwe@octave.org>
parents: 16199
diff changeset
1271 // =======================
127cccb037bf move more global parser and lexer variables to classes
John W. Eaton <jwe@octave.org>
parents: 16199
diff changeset
1272
127cccb037bf move more global parser and lexer variables to classes
John W. Eaton <jwe@octave.org>
parents: 16199
diff changeset
1273 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
1274 {
17618
77eff9c6fb09 avoid memory leak when parsing function files (bug #40218)
John W. Eaton <jwe@octave.org>
parents: 17377
diff changeset
1275 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
1276 {
77eff9c6fb09 avoid memory leak when parsing function files (bug #40218)
John W. Eaton <jwe@octave.org>
parents: 17377
diff changeset
1277 // 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
1278 // 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
1279 // 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
1280 // 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
1281 // 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
1282
77eff9c6fb09 avoid memory leak when parsing function files (bug #40218)
John W. Eaton <jwe@octave.org>
parents: 17377
diff changeset
1283 delete $3;
77eff9c6fb09 avoid memory leak when parsing function files (bug #40218)
John W. Eaton <jwe@octave.org>
parents: 17377
diff changeset
1284 }
77eff9c6fb09 avoid memory leak when parsing function files (bug #40218)
John W. Eaton <jwe@octave.org>
parents: 17377
diff changeset
1285 else
16203
127cccb037bf move more global parser and lexer variables to classes
John W. Eaton <jwe@octave.org>
parents: 16199
diff changeset
1286 {
127cccb037bf move more global parser and lexer variables to classes
John W. Eaton <jwe@octave.org>
parents: 16199
diff changeset
1287 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
1288 = 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
1289 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
1290 lexer.current_input_column);
16288
fe3b9a51e625 rename curr_lexer, curr_parser, CURR_LEXER
John W. Eaton <jwe@octave.org>
parents: 16287
diff changeset
1291
fe3b9a51e625 rename curr_lexer, curr_parser, CURR_LEXER
John W. Eaton <jwe@octave.org>
parents: 16287
diff changeset
1292 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
1293 }
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
1294
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
1295 $$ = 0;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
1296 }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
1297 ;
7715
5b4d278ec828 parse scripts completely before executing
John W. Eaton <jwe@octave.org>
parents: 7699
diff changeset
1298
2970
b9e64477f703 [project @ 1997-05-15 18:04:21 by jwe]
jwe
parents: 2961
diff changeset
1299 // ===================
b9e64477f703 [project @ 1997-05-15 18:04:21 by jwe]
jwe
parents: 2961
diff changeset
1300 // Function definition
b9e64477f703 [project @ 1997-05-15 18:04:21 by jwe]
jwe
parents: 2961
diff changeset
1301 // ===================
b9e64477f703 [project @ 1997-05-15 18:04:21 by jwe]
jwe
parents: 2961
diff changeset
1302
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
1303 function_beg : push_fcn_symtab FCN
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
1304 {
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
1305 $$ = $2;
16288
fe3b9a51e625 rename curr_lexer, curr_parser, CURR_LEXER
John W. Eaton <jwe@octave.org>
parents: 16287
diff changeset
1306 if (lexer.reading_classdef_file
fe3b9a51e625 rename curr_lexer, curr_parser, CURR_LEXER
John W. Eaton <jwe@octave.org>
parents: 16287
diff changeset
1307 || lexer.parsing_classdef)
fe3b9a51e625 rename curr_lexer, curr_parser, CURR_LEXER
John W. Eaton <jwe@octave.org>
parents: 16287
diff changeset
1308 lexer.maybe_classdef_get_set_method = true;
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
1309 }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
1310 ;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
1311
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
1312 function : function_beg stash_comment function1
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
1313 {
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
1314 $$ = 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
1315 $1->column ());
16288
fe3b9a51e625 rename curr_lexer, curr_parser, CURR_LEXER
John W. Eaton <jwe@octave.org>
parents: 16287
diff changeset
1316 parser.recover_from_parsing_function ();
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
1317 }
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
1318 | function_beg stash_comment return_list '=' function1
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
1319 {
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
1320 $$ = 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
1321 $1->column ());
16288
fe3b9a51e625 rename curr_lexer, curr_parser, CURR_LEXER
John W. Eaton <jwe@octave.org>
parents: 16287
diff changeset
1322 parser.recover_from_parsing_function ();
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
1323 }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
1324 ;
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 fcn_name : identifier
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
1327 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
1328 std::string id_name = $1->name ();
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
1329
16288
fe3b9a51e625 rename curr_lexer, curr_parser, CURR_LEXER
John W. Eaton <jwe@octave.org>
parents: 16287
diff changeset
1330 lexer.parsed_function_name.top () = true;
fe3b9a51e625 rename curr_lexer, curr_parser, CURR_LEXER
John W. Eaton <jwe@octave.org>
parents: 16287
diff changeset
1331 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
1332
10315
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 | GET '.' identifier
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
1336 {
16288
fe3b9a51e625 rename curr_lexer, curr_parser, CURR_LEXER
John W. Eaton <jwe@octave.org>
parents: 16287
diff changeset
1337 lexer.parsed_function_name.top () = true;
fe3b9a51e625 rename curr_lexer, curr_parser, CURR_LEXER
John W. Eaton <jwe@octave.org>
parents: 16287
diff changeset
1338 lexer.maybe_classdef_get_set_method = false;
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
1339 $$ = $3;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
1340 }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
1341 | SET '.' identifier
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
1342 {
16288
fe3b9a51e625 rename curr_lexer, curr_parser, CURR_LEXER
John W. Eaton <jwe@octave.org>
parents: 16287
diff changeset
1343 lexer.parsed_function_name.top () = true;
fe3b9a51e625 rename curr_lexer, curr_parser, CURR_LEXER
John W. Eaton <jwe@octave.org>
parents: 16287
diff changeset
1344 lexer.maybe_classdef_get_set_method = false;
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
1345 $$ = $3;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
1346 }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
1347 ;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
1348
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
1349 function1 : fcn_name function2
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
1350 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
1351 std::string fname = $1->name ();
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
1352
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
1353 delete $1;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
1354
17632
bd0a84de3375 further reduce memory leaks from parse errors (bug #40231)
John W. Eaton <jwe@octave.org>
parents: 17629
diff changeset
1355 $$ = parser.frob_function (fname, $2);
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
1356 }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
1357 ;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
1358
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
1359 function2 : param_list opt_sep opt_list function_end
16288
fe3b9a51e625 rename curr_lexer, curr_parser, CURR_LEXER
John W. Eaton <jwe@octave.org>
parents: 16287
diff changeset
1360 { $$ = parser.start_function ($1, $3, $4); }
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
1361 | opt_sep opt_list function_end
16288
fe3b9a51e625 rename curr_lexer, curr_parser, CURR_LEXER
John W. Eaton <jwe@octave.org>
parents: 16287
diff changeset
1362 { $$ = parser.start_function (0, $2, $3); }
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
1363 ;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
1364
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
1365 function_end : END
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
1366 {
16288
fe3b9a51e625 rename curr_lexer, curr_parser, CURR_LEXER
John W. Eaton <jwe@octave.org>
parents: 16287
diff changeset
1367 parser.endfunction_found = true;
fe3b9a51e625 rename curr_lexer, curr_parser, CURR_LEXER
John W. Eaton <jwe@octave.org>
parents: 16287
diff changeset
1368 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
1369 $$ = 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
1370 $1->line (), $1->column ());
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
1371 else
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
1372 ABORT_PARSE;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
1373 }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
1374 | END_OF_INPUT
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
1375 {
9474
25ed2d6aacf6 Parse nested functions more accurately.
David Grundberg <individ@acc.umu.se>
parents: 9471
diff changeset
1376 // 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
1377 // if (lexer.reading_script_file)
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
1378 // {
16288
fe3b9a51e625 rename curr_lexer, curr_parser, CURR_LEXER
John W. Eaton <jwe@octave.org>
parents: 16287
diff changeset
1379 // 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
1380 // YYABORT;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
1381 // }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
1382
16288
fe3b9a51e625 rename curr_lexer, curr_parser, CURR_LEXER
John W. Eaton <jwe@octave.org>
parents: 16287
diff changeset
1383 if (parser.endfunction_found)
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
1384 {
16288
fe3b9a51e625 rename curr_lexer, curr_parser, CURR_LEXER
John W. Eaton <jwe@octave.org>
parents: 16287
diff changeset
1385 parser.bison_error ("inconsistent function endings -- "
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
1386 "if one function is explicitly ended, "
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
1387 "so must all the others");
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
1388 YYABORT;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
1389 }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
1390
16288
fe3b9a51e625 rename curr_lexer, curr_parser, CURR_LEXER
John W. Eaton <jwe@octave.org>
parents: 16287
diff changeset
1391 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
1392 || lexer.input_from_eval_string ()))
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
1393 {
16288
fe3b9a51e625 rename curr_lexer, curr_parser, CURR_LEXER
John W. Eaton <jwe@octave.org>
parents: 16287
diff changeset
1394 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
1395 YYABORT;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
1396 }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
1397
16288
fe3b9a51e625 rename curr_lexer, curr_parser, CURR_LEXER
John W. Eaton <jwe@octave.org>
parents: 16287
diff changeset
1398 if (lexer.reading_classdef_file)
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
1399 {
16288
fe3b9a51e625 rename curr_lexer, curr_parser, CURR_LEXER
John W. Eaton <jwe@octave.org>
parents: 16287
diff changeset
1400 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
1401 YYABORT;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
1402 }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
1403
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
1404 $$ = 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
1405 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
1406 lexer.current_input_column);
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
1407 }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
1408 ;
2970
b9e64477f703 [project @ 1997-05-15 18:04:21 by jwe]
jwe
parents: 2961
diff changeset
1409
9476
d9b25c5b8ee5 handle classdef syntax in lexer and parser
Ryan Rusaw
parents: 9474
diff changeset
1410 // ========
d9b25c5b8ee5 handle classdef syntax in lexer and parser
Ryan Rusaw
parents: 9474
diff changeset
1411 // Classdef
d9b25c5b8ee5 handle classdef syntax in lexer and parser
Ryan Rusaw
parents: 9474
diff changeset
1412 // ========
d9b25c5b8ee5 handle classdef syntax in lexer and parser
Ryan Rusaw
parents: 9474
diff changeset
1413
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
1414 classdef_beg : CLASSDEF stash_comment
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
1415 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
1416 $$ = 0;
16288
fe3b9a51e625 rename curr_lexer, curr_parser, CURR_LEXER
John W. Eaton <jwe@octave.org>
parents: 16287
diff changeset
1417 lexer.parsing_classdef = true;
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
1418 }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
1419 ;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
1420
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
1421 classdef_end : END
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
1422 {
16288
fe3b9a51e625 rename curr_lexer, curr_parser, CURR_LEXER
John W. Eaton <jwe@octave.org>
parents: 16287
diff changeset
1423 lexer.parsing_classdef = false;
fe3b9a51e625 rename curr_lexer, curr_parser, CURR_LEXER
John W. Eaton <jwe@octave.org>
parents: 16287
diff changeset
1424
fe3b9a51e625 rename curr_lexer, curr_parser, CURR_LEXER
John W. Eaton <jwe@octave.org>
parents: 16287
diff changeset
1425 if (parser.end_token_ok ($1, token::classdef_end))
16627
de91b1621260 adjust location of eof marker for files with subfunctions but no explicit end statements
John W. Eaton <jwe@octave.org>
parents: 16574
diff changeset
1426 $$ = parser.make_end ("endclassdef", false,
de91b1621260 adjust location of eof marker for files with subfunctions but no explicit end statements
John W. Eaton <jwe@octave.org>
parents: 16574
diff changeset
1427 $1->line (), $1->column ());
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
1428 else
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
1429 ABORT_PARSE;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
1430 }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
1431 ;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
1432
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
1433 classdef1 : classdef_beg opt_attr_list identifier opt_superclasses
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
1434 { $$ = 0; }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
1435 ;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
1436
13250
f6bbdea030b2 use opt_sep instead of literal '\n' in parser rules for classdef
John W. Eaton <jwe@octave.org>
parents: 13249
diff changeset
1437 classdef : classdef1 opt_sep class_body opt_sep stash_comment classdef_end
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
1438 { $$ = 0; }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
1439 ;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
1440
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
1441 opt_attr_list : // empty
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
1442 { $$ = 0; }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
1443 | '(' attr_list ')'
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
1444 { $$ = 0; }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
1445 ;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
1446
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
1447 attr_list : attr
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
1448 { $$ = 0; }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
1449 | attr_list ',' attr
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
1450 { $$ = 0; }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
1451 ;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
1452
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
1453 attr : identifier
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
1454 { $$ = 0; }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
1455 | identifier '=' decl_param_init expression
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
1456 { $$ = 0; }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
1457 | EXPR_NOT identifier
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
1458 { $$ = 0; }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
1459 ;
9476
d9b25c5b8ee5 handle classdef syntax in lexer and parser
Ryan Rusaw
parents: 9474
diff changeset
1460
d9b25c5b8ee5 handle classdef syntax in lexer and parser
Ryan Rusaw
parents: 9474
diff changeset
1461 opt_superclasses
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
1462 : // empty
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
1463 { $$ = 0; }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
1464 | superclasses
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
1465 { $$ = 0; }
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 superclasses : EXPR_LT identifier '.' identifier
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
1469 { $$ = 0; }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
1470 | EXPR_LT identifier
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
1471 { $$ = 0; }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
1472 | superclasses EXPR_AND identifier '.' identifier
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
1473 { $$ = 0; }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
1474 | superclasses EXPR_AND identifier
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
1475 { $$ = 0; }
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
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
1478 class_body : properties_block
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
1479 { $$ = 0; }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
1480 | methods_block
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
1481 { $$ = 0; }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
1482 | events_block
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
1483 { $$ = 0; }
13249
7861a5fd3479 accept enumeration keyword
John W. Eaton <jwe@octave.org>
parents: 13246
diff changeset
1484 | enum_block
7861a5fd3479 accept enumeration keyword
John W. Eaton <jwe@octave.org>
parents: 13246
diff changeset
1485 { $$ = 0; }
13250
f6bbdea030b2 use opt_sep instead of literal '\n' in parser rules for classdef
John W. Eaton <jwe@octave.org>
parents: 13249
diff changeset
1486 | class_body opt_sep properties_block
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
1487 { $$ = 0; }
13250
f6bbdea030b2 use opt_sep instead of literal '\n' in parser rules for classdef
John W. Eaton <jwe@octave.org>
parents: 13249
diff changeset
1488 | class_body opt_sep methods_block
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
1489 { $$ = 0; }
13250
f6bbdea030b2 use opt_sep instead of literal '\n' in parser rules for classdef
John W. Eaton <jwe@octave.org>
parents: 13249
diff changeset
1490 | class_body opt_sep events_block
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
1491 { $$ = 0; }
13250
f6bbdea030b2 use opt_sep instead of literal '\n' in parser rules for classdef
John W. Eaton <jwe@octave.org>
parents: 13249
diff changeset
1492 | class_body opt_sep enum_block
13249
7861a5fd3479 accept enumeration keyword
John W. Eaton <jwe@octave.org>
parents: 13246
diff changeset
1493 { $$ = 0; }
10315
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 properties_beg : PROPERTIES stash_comment
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
1497 { $$ = 0; }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
1498 ;
9476
d9b25c5b8ee5 handle classdef syntax in lexer and parser
Ryan Rusaw
parents: 9474
diff changeset
1499
d9b25c5b8ee5 handle classdef syntax in lexer and parser
Ryan Rusaw
parents: 9474
diff changeset
1500 properties_block
13250
f6bbdea030b2 use opt_sep instead of literal '\n' in parser rules for classdef
John W. Eaton <jwe@octave.org>
parents: 13249
diff changeset
1501 : properties_beg opt_attr_list opt_sep properties_list opt_sep END
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
1502 { $$ = 0; }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
1503 ;
9476
d9b25c5b8ee5 handle classdef syntax in lexer and parser
Ryan Rusaw
parents: 9474
diff changeset
1504
d9b25c5b8ee5 handle classdef syntax in lexer and parser
Ryan Rusaw
parents: 9474
diff changeset
1505 properties_list
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
1506 : class_property
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
1507 { $$ = 0; }
13250
f6bbdea030b2 use opt_sep instead of literal '\n' in parser rules for classdef
John W. Eaton <jwe@octave.org>
parents: 13249
diff changeset
1508 | properties_list opt_sep class_property
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
1509 { $$ = 0; }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
1510 ;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
1511
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
1512 class_property : identifier
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
1513 { $$ = 0; }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
1514 | identifier '=' decl_param_init expression ';'
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
1515 { $$ = 0; }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
1516 ;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
1517
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
1518 methods_beg : METHODS stash_comment
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
1519 { $$ = 0; }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
1520 ;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
1521
13250
f6bbdea030b2 use opt_sep instead of literal '\n' in parser rules for classdef
John W. Eaton <jwe@octave.org>
parents: 13249
diff changeset
1522 methods_block : methods_beg opt_attr_list opt_sep methods_list opt_sep END
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
1523 { $$ = 0; }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
1524 ;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
1525
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
1526 methods_list : function
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
1527 { $$ = 0; }
13250
f6bbdea030b2 use opt_sep instead of literal '\n' in parser rules for classdef
John W. Eaton <jwe@octave.org>
parents: 13249
diff changeset
1528 | methods_list opt_sep function
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
1529 { $$ = 0; }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
1530 ;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
1531
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
1532 events_beg : EVENTS stash_comment
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
1533 { $$ = 0; }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
1534 ;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
1535
13250
f6bbdea030b2 use opt_sep instead of literal '\n' in parser rules for classdef
John W. Eaton <jwe@octave.org>
parents: 13249
diff changeset
1536 events_block : events_beg opt_attr_list opt_sep events_list opt_sep END
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
1537 { $$ = 0; }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
1538 ;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
1539
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
1540 events_list : class_event
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
1541 { $$ = 0; }
13250
f6bbdea030b2 use opt_sep instead of literal '\n' in parser rules for classdef
John W. Eaton <jwe@octave.org>
parents: 13249
diff changeset
1542 | events_list opt_sep class_event
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
1543 { $$ = 0; }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
1544 ;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
1545
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
1546 class_event : identifier
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
1547 { $$ = 0; }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
1548 ;
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11572
diff changeset
1549
13249
7861a5fd3479 accept enumeration keyword
John W. Eaton <jwe@octave.org>
parents: 13246
diff changeset
1550 enum_beg : ENUMERATION stash_comment
7861a5fd3479 accept enumeration keyword
John W. Eaton <jwe@octave.org>
parents: 13246
diff changeset
1551 { $$ = 0; }
7861a5fd3479 accept enumeration keyword
John W. Eaton <jwe@octave.org>
parents: 13246
diff changeset
1552 ;
7861a5fd3479 accept enumeration keyword
John W. Eaton <jwe@octave.org>
parents: 13246
diff changeset
1553
13250
f6bbdea030b2 use opt_sep instead of literal '\n' in parser rules for classdef
John W. Eaton <jwe@octave.org>
parents: 13249
diff changeset
1554 enum_block : enum_beg opt_attr_list opt_sep enum_list opt_sep END
13249
7861a5fd3479 accept enumeration keyword
John W. Eaton <jwe@octave.org>
parents: 13246
diff changeset
1555 { $$ = 0; }
7861a5fd3479 accept enumeration keyword
John W. Eaton <jwe@octave.org>
parents: 13246
diff changeset
1556 ;
7861a5fd3479 accept enumeration keyword
John W. Eaton <jwe@octave.org>
parents: 13246
diff changeset
1557
7861a5fd3479 accept enumeration keyword
John W. Eaton <jwe@octave.org>
parents: 13246
diff changeset
1558 enum_list : class_enum
7861a5fd3479 accept enumeration keyword
John W. Eaton <jwe@octave.org>
parents: 13246
diff changeset
1559 { $$ = 0; }
13250
f6bbdea030b2 use opt_sep instead of literal '\n' in parser rules for classdef
John W. Eaton <jwe@octave.org>
parents: 13249
diff changeset
1560 | enum_list opt_sep class_enum
13249
7861a5fd3479 accept enumeration keyword
John W. Eaton <jwe@octave.org>
parents: 13246
diff changeset
1561 { $$ = 0; }
7861a5fd3479 accept enumeration keyword
John W. Eaton <jwe@octave.org>
parents: 13246
diff changeset
1562 ;
7861a5fd3479 accept enumeration keyword
John W. Eaton <jwe@octave.org>
parents: 13246
diff changeset
1563
7861a5fd3479 accept enumeration keyword
John W. Eaton <jwe@octave.org>
parents: 13246
diff changeset
1564 class_enum : identifier '(' expression ')'
7861a5fd3479 accept enumeration keyword
John W. Eaton <jwe@octave.org>
parents: 13246
diff changeset
1565 { $$ = 0; }
7861a5fd3479 accept enumeration keyword
John W. Eaton <jwe@octave.org>
parents: 13246
diff changeset
1566 ;
7861a5fd3479 accept enumeration keyword
John W. Eaton <jwe@octave.org>
parents: 13246
diff changeset
1567
2970
b9e64477f703 [project @ 1997-05-15 18:04:21 by jwe]
jwe
parents: 2961
diff changeset
1568 // =============
b9e64477f703 [project @ 1997-05-15 18:04:21 by jwe]
jwe
parents: 2961
diff changeset
1569 // Miscellaneous
b9e64477f703 [project @ 1997-05-15 18:04:21 by jwe]
jwe
parents: 2961
diff changeset
1570 // =============
b9e64477f703 [project @ 1997-05-15 18:04:21 by jwe]
jwe
parents: 2961
diff changeset
1571
16681
d3619d4d267c recognize character string at beginning of statement (bug #38926, #38958)
John W. Eaton <jwe@octave.org>
parents: 16627
diff changeset
1572 stmt_begin : // empty
d3619d4d267c recognize character string at beginning of statement (bug #38926, #38958)
John W. Eaton <jwe@octave.org>
parents: 16627
diff changeset
1573 { lexer.at_beginning_of_statement = true; }
d3619d4d267c recognize character string at beginning of statement (bug #38926, #38958)
John W. Eaton <jwe@octave.org>
parents: 16627
diff changeset
1574 ;
d3619d4d267c recognize character string at beginning of statement (bug #38926, #38958)
John W. Eaton <jwe@octave.org>
parents: 16627
diff changeset
1575
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
1576 stash_comment : // empty
17693
efbe746f8fa8 eliminate octave_comment_buffer singleton
John W. Eaton <jwe@octave.org>
parents: 17673
diff changeset
1577 { $$ = lexer.get_comment (); }
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
1578 ;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
1579
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
1580 parse_error : LEXICAL_ERROR
16288
fe3b9a51e625 rename curr_lexer, curr_parser, CURR_LEXER
John W. Eaton <jwe@octave.org>
parents: 16287
diff changeset
1581 { parser.bison_error ("parse error"); }
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
1582 | error
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
1583 ;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
1584
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
1585 sep_no_nl : ','
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
1586 { $$ = ','; }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
1587 | ';'
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
1588 { $$ = ';'; }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
1589 | sep_no_nl ','
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
1590 { $$ = $1; }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
1591 | sep_no_nl ';'
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
1592 { $$ = $1; }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
1593 ;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
1594
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
1595 opt_sep_no_nl : // empty
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
1596 { $$ = 0; }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
1597 | sep_no_nl
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
1598 { $$ = $1; }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
1599 ;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
1600
16203
127cccb037bf move more global parser and lexer variables to classes
John W. Eaton <jwe@octave.org>
parents: 16199
diff changeset
1601 opt_nl : // empty
127cccb037bf move more global parser and lexer variables to classes
John W. Eaton <jwe@octave.org>
parents: 16199
diff changeset
1602 { $$ = 0; }
127cccb037bf move more global parser and lexer variables to classes
John W. Eaton <jwe@octave.org>
parents: 16199
diff changeset
1603 | nl
127cccb037bf move more global parser and lexer variables to classes
John W. Eaton <jwe@octave.org>
parents: 16199
diff changeset
1604 { $$ = $1; }
127cccb037bf move more global parser and lexer variables to classes
John W. Eaton <jwe@octave.org>
parents: 16199
diff changeset
1605 ;
127cccb037bf move more global parser and lexer variables to classes
John W. Eaton <jwe@octave.org>
parents: 16199
diff changeset
1606
127cccb037bf move more global parser and lexer variables to classes
John W. Eaton <jwe@octave.org>
parents: 16199
diff changeset
1607 nl : '\n'
127cccb037bf move more global parser and lexer variables to classes
John W. Eaton <jwe@octave.org>
parents: 16199
diff changeset
1608 { $$ = '\n'; }
127cccb037bf move more global parser and lexer variables to classes
John W. Eaton <jwe@octave.org>
parents: 16199
diff changeset
1609 | nl '\n'
127cccb037bf move more global parser and lexer variables to classes
John W. Eaton <jwe@octave.org>
parents: 16199
diff changeset
1610 { $$ = $1; }
127cccb037bf move more global parser and lexer variables to classes
John W. Eaton <jwe@octave.org>
parents: 16199
diff changeset
1611 ;
127cccb037bf move more global parser and lexer variables to classes
John W. Eaton <jwe@octave.org>
parents: 16199
diff changeset
1612
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
1613 sep : ','
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
1614 { $$ = ','; }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
1615 | ';'
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
1616 { $$ = ';'; }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
1617 | '\n'
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
1618 { $$ = '\n'; }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
1619 | sep ','
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
1620 { $$ = $1; }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
1621 | sep ';'
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
1622 { $$ = $1; }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
1623 | sep '\n'
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
1624 { $$ = $1; }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
1625 ;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
1626
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
1627 opt_sep : // empty
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
1628 { $$ = 0; }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
1629 | sep
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
1630 { $$ = $1; }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
1631 ;
2525
8561d88be5f2 [project @ 1996-11-17 21:23:31 by jwe]
jwe
parents: 2524
diff changeset
1632
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
1633 %%
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
1634
666
fb4f6556b443 [project @ 1994-09-06 21:22:46 by jwe]
jwe
parents: 627
diff changeset
1635 // Generic error messages.
fb4f6556b443 [project @ 1994-09-06 21:22:46 by jwe]
jwe
parents: 627
diff changeset
1636
16288
fe3b9a51e625 rename curr_lexer, curr_parser, CURR_LEXER
John W. Eaton <jwe@octave.org>
parents: 16287
diff changeset
1637 #undef lexer
16149
49dfba4fd3c5 use pure parser and reentrant lexer interfaces
John W. Eaton <jwe@octave.org>
parents: 16147
diff changeset
1638
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
1639 static void
16288
fe3b9a51e625 rename curr_lexer, curr_parser, CURR_LEXER
John W. Eaton <jwe@octave.org>
parents: 16287
diff changeset
1640 yyerror (octave_base_parser& parser, const char *s)
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
1641 {
16288
fe3b9a51e625 rename curr_lexer, curr_parser, CURR_LEXER
John W. Eaton <jwe@octave.org>
parents: 16287
diff changeset
1642 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
1643 }
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
1644
16287
04a7953496a7 create base class for parser; use reference for curr_lexer
John W. Eaton <jwe@octave.org>
parents: 16285
diff changeset
1645 octave_base_parser::~octave_base_parser (void)
16157
335041cc657a optionally use push parser interface
John W. Eaton <jwe@octave.org>
parents: 16153
diff changeset
1646 {
16177
a7669b4d27f6 eliminate global global_command variable
John W. Eaton <jwe@octave.org>
parents: 16174
diff changeset
1647 delete stmt_list;
a7669b4d27f6 eliminate global global_command variable
John W. Eaton <jwe@octave.org>
parents: 16174
diff changeset
1648
16288
fe3b9a51e625 rename curr_lexer, curr_parser, CURR_LEXER
John W. Eaton <jwe@octave.org>
parents: 16287
diff changeset
1649 delete &lexer;
16157
335041cc657a optionally use push parser interface
John W. Eaton <jwe@octave.org>
parents: 16153
diff changeset
1650 }
16287
04a7953496a7 create base class for parser; use reference for curr_lexer
John W. Eaton <jwe@octave.org>
parents: 16285
diff changeset
1651
16177
a7669b4d27f6 eliminate global global_command variable
John W. Eaton <jwe@octave.org>
parents: 16174
diff changeset
1652 void
16287
04a7953496a7 create base class for parser; use reference for curr_lexer
John W. Eaton <jwe@octave.org>
parents: 16285
diff changeset
1653 octave_base_parser::reset (void)
16177
a7669b4d27f6 eliminate global global_command variable
John W. Eaton <jwe@octave.org>
parents: 16174
diff changeset
1654 {
16574
b678d2d10e53 reset parser state on parse error (bug #38840)
John W. Eaton <jwe@octave.org>
parents: 16442
diff changeset
1655 endfunction_found = false;
b678d2d10e53 reset parser state on parse error (bug #38840)
John W. Eaton <jwe@octave.org>
parents: 16442
diff changeset
1656 autoloading = false;
b678d2d10e53 reset parser state on parse error (bug #38840)
John W. Eaton <jwe@octave.org>
parents: 16442
diff changeset
1657 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
1658 parsing_subfunctions = false;
b678d2d10e53 reset parser state on parse error (bug #38840)
John W. Eaton <jwe@octave.org>
parents: 16442
diff changeset
1659 max_fcn_depth = 0;
b678d2d10e53 reset parser state on parse error (bug #38840)
John W. Eaton <jwe@octave.org>
parents: 16442
diff changeset
1660 curr_fcn_depth = 0;
b678d2d10e53 reset parser state on parse error (bug #38840)
John W. Eaton <jwe@octave.org>
parents: 16442
diff changeset
1661 primary_fcn_scope = -1;
b678d2d10e53 reset parser state on parse error (bug #38840)
John W. Eaton <jwe@octave.org>
parents: 16442
diff changeset
1662 curr_class_name = "";
b678d2d10e53 reset parser state on parse error (bug #38840)
John W. Eaton <jwe@octave.org>
parents: 16442
diff changeset
1663 function_scopes.clear ();
b678d2d10e53 reset parser state on parse error (bug #38840)
John W. Eaton <jwe@octave.org>
parents: 16442
diff changeset
1664 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
1665 subfunction_names.clear ();
16574
b678d2d10e53 reset parser state on parse error (bug #38840)
John W. Eaton <jwe@octave.org>
parents: 16442
diff changeset
1666
16177
a7669b4d27f6 eliminate global global_command variable
John W. Eaton <jwe@octave.org>
parents: 16174
diff changeset
1667 delete stmt_list;
a7669b4d27f6 eliminate global global_command variable
John W. Eaton <jwe@octave.org>
parents: 16174
diff changeset
1668 stmt_list = 0;
a7669b4d27f6 eliminate global global_command variable
John W. Eaton <jwe@octave.org>
parents: 16174
diff changeset
1669
16288
fe3b9a51e625 rename curr_lexer, curr_parser, CURR_LEXER
John W. Eaton <jwe@octave.org>
parents: 16287
diff changeset
1670 lexer.reset ();
16138
284e2ca86ef7 execute parser using member function of octave_parser class
John W. Eaton <jwe@octave.org>
parents: 16136
diff changeset
1671 }
284e2ca86ef7 execute parser using member function of octave_parser class
John W. Eaton <jwe@octave.org>
parents: 16136
diff changeset
1672
666
fb4f6556b443 [project @ 1994-09-06 21:22:46 by jwe]
jwe
parents: 627
diff changeset
1673 // Error mesages for mismatched end tokens.
fb4f6556b443 [project @ 1994-09-06 21:22:46 by jwe]
jwe
parents: 627
diff changeset
1674
16134
ec9c6222ef5a move static parser helper functions to octave_parser class
John W. Eaton <jwe@octave.org>
parents: 16133
diff changeset
1675 void
16287
04a7953496a7 create base class for parser; use reference for curr_lexer
John W. Eaton <jwe@octave.org>
parents: 16285
diff changeset
1676 octave_base_parser::end_error (const char *type, token::end_tok_type ettype,
04a7953496a7 create base class for parser; use reference for curr_lexer
John W. Eaton <jwe@octave.org>
parents: 16285
diff changeset
1677 int l, int c)
496
e7c5b23b34d3 [project @ 1994-07-06 15:02:26 by jwe]
jwe
parents: 482
diff changeset
1678 {
2805
68e6d0c93fc8 [project @ 1997-03-11 04:52:44 by jwe]
jwe
parents: 2791
diff changeset
1679 static const char *fmt
15466
d174210ce1ec use ' instead of ` in error messages, warnings and most comments
John W. Eaton <jwe@octave.org>
parents: 14189
diff changeset
1680 = "'%s' command matched by '%s' near line %d column %d";
496
e7c5b23b34d3 [project @ 1994-07-06 15:02:26 by jwe]
jwe
parents: 482
diff changeset
1681
e7c5b23b34d3 [project @ 1994-07-06 15:02:26 by jwe]
jwe
parents: 482
diff changeset
1682 switch (ettype)
e7c5b23b34d3 [project @ 1994-07-06 15:02:26 by jwe]
jwe
parents: 482
diff changeset
1683 {
e7c5b23b34d3 [project @ 1994-07-06 15:02:26 by jwe]
jwe
parents: 482
diff changeset
1684 case token::simple_end:
e7c5b23b34d3 [project @ 1994-07-06 15:02:26 by jwe]
jwe
parents: 482
diff changeset
1685 error (fmt, type, "end", l, c);
e7c5b23b34d3 [project @ 1994-07-06 15:02:26 by jwe]
jwe
parents: 482
diff changeset
1686 break;
777
a2f9d3fd720c [project @ 1994-10-07 14:01:53 by jwe]
jwe
parents: 773
diff changeset
1687
496
e7c5b23b34d3 [project @ 1994-07-06 15:02:26 by jwe]
jwe
parents: 482
diff changeset
1688 case token::for_end:
e7c5b23b34d3 [project @ 1994-07-06 15:02:26 by jwe]
jwe
parents: 482
diff changeset
1689 error (fmt, type, "endfor", l, c);
e7c5b23b34d3 [project @ 1994-07-06 15:02:26 by jwe]
jwe
parents: 482
diff changeset
1690 break;
777
a2f9d3fd720c [project @ 1994-10-07 14:01:53 by jwe]
jwe
parents: 773
diff changeset
1691
496
e7c5b23b34d3 [project @ 1994-07-06 15:02:26 by jwe]
jwe
parents: 482
diff changeset
1692 case token::function_end:
e7c5b23b34d3 [project @ 1994-07-06 15:02:26 by jwe]
jwe
parents: 482
diff changeset
1693 error (fmt, type, "endfunction", l, c);
e7c5b23b34d3 [project @ 1994-07-06 15:02:26 by jwe]
jwe
parents: 482
diff changeset
1694 break;
777
a2f9d3fd720c [project @ 1994-10-07 14:01:53 by jwe]
jwe
parents: 773
diff changeset
1695
9476
d9b25c5b8ee5 handle classdef syntax in lexer and parser
Ryan Rusaw
parents: 9474
diff changeset
1696 case token::classdef_end:
d9b25c5b8ee5 handle classdef syntax in lexer and parser
Ryan Rusaw
parents: 9474
diff changeset
1697 error (fmt, type, "endclassdef", l, c);
d9b25c5b8ee5 handle classdef syntax in lexer and parser
Ryan Rusaw
parents: 9474
diff changeset
1698 break;
d9b25c5b8ee5 handle classdef syntax in lexer and parser
Ryan Rusaw
parents: 9474
diff changeset
1699
496
e7c5b23b34d3 [project @ 1994-07-06 15:02:26 by jwe]
jwe
parents: 482
diff changeset
1700 case token::if_end:
e7c5b23b34d3 [project @ 1994-07-06 15:02:26 by jwe]
jwe
parents: 482
diff changeset
1701 error (fmt, type, "endif", l, c);
e7c5b23b34d3 [project @ 1994-07-06 15:02:26 by jwe]
jwe
parents: 482
diff changeset
1702 break;
777
a2f9d3fd720c [project @ 1994-10-07 14:01:53 by jwe]
jwe
parents: 773
diff changeset
1703
3233
98d0ee053ba4 [project @ 1999-01-27 20:23:40 by jwe]
jwe
parents: 3216
diff changeset
1704 case token::switch_end:
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11572
diff changeset
1705 error (fmt, type, "endswitch", l, c);
3233
98d0ee053ba4 [project @ 1999-01-27 20:23:40 by jwe]
jwe
parents: 3216
diff changeset
1706 break;
98d0ee053ba4 [project @ 1999-01-27 20:23:40 by jwe]
jwe
parents: 3216
diff changeset
1707
496
e7c5b23b34d3 [project @ 1994-07-06 15:02:26 by jwe]
jwe
parents: 482
diff changeset
1708 case token::while_end:
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11572
diff changeset
1709 error (fmt, type, "endwhile", l, c);
496
e7c5b23b34d3 [project @ 1994-07-06 15:02:26 by jwe]
jwe
parents: 482
diff changeset
1710 break;
777
a2f9d3fd720c [project @ 1994-10-07 14:01:53 by jwe]
jwe
parents: 773
diff changeset
1711
5400
c7e3cf2fce3e [project @ 2005-07-05 15:01:32 by jwe]
jwe
parents: 5397
diff changeset
1712 case token::try_catch_end:
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11572
diff changeset
1713 error (fmt, type, "end_try_catch", l, c);
5400
c7e3cf2fce3e [project @ 2005-07-05 15:01:32 by jwe]
jwe
parents: 5397
diff changeset
1714 break;
c7e3cf2fce3e [project @ 2005-07-05 15:01:32 by jwe]
jwe
parents: 5397
diff changeset
1715
1371
766af9ca8edb [project @ 1995-09-06 21:36:02 by jwe]
jwe
parents: 1351
diff changeset
1716 case token::unwind_protect_end:
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11572
diff changeset
1717 error (fmt, type, "end_unwind_protect", l, c);
1371
766af9ca8edb [project @ 1995-09-06 21:36:02 by jwe]
jwe
parents: 1351
diff changeset
1718 break;
766af9ca8edb [project @ 1995-09-06 21:36:02 by jwe]
jwe
parents: 1351
diff changeset
1719
496
e7c5b23b34d3 [project @ 1994-07-06 15:02:26 by jwe]
jwe
parents: 482
diff changeset
1720 default:
e7c5b23b34d3 [project @ 1994-07-06 15:02:26 by jwe]
jwe
parents: 482
diff changeset
1721 panic_impossible ();
e7c5b23b34d3 [project @ 1994-07-06 15:02:26 by jwe]
jwe
parents: 482
diff changeset
1722 break;
e7c5b23b34d3 [project @ 1994-07-06 15:02:26 by jwe]
jwe
parents: 482
diff changeset
1723 }
e7c5b23b34d3 [project @ 1994-07-06 15:02:26 by jwe]
jwe
parents: 482
diff changeset
1724 }
e7c5b23b34d3 [project @ 1994-07-06 15:02:26 by jwe]
jwe
parents: 482
diff changeset
1725
666
fb4f6556b443 [project @ 1994-09-06 21:22:46 by jwe]
jwe
parents: 627
diff changeset
1726 // Check to see that end tokens are properly matched.
fb4f6556b443 [project @ 1994-09-06 21:22:46 by jwe]
jwe
parents: 627
diff changeset
1727
16134
ec9c6222ef5a move static parser helper functions to octave_parser class
John W. Eaton <jwe@octave.org>
parents: 16133
diff changeset
1728 bool
16287
04a7953496a7 create base class for parser; use reference for curr_lexer
John W. Eaton <jwe@octave.org>
parents: 16285
diff changeset
1729 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
1730 {
2857
5448c8cba402 [project @ 1997-03-31 07:06:10 by jwe]
jwe
parents: 2856
diff changeset
1731 bool retval = true;
5448c8cba402 [project @ 1997-03-31 07:06:10 by jwe]
jwe
parents: 2856
diff changeset
1732
143
7849db4b6dbc [project @ 1993-10-04 02:36:45 by jwe]
jwe
parents: 118
diff changeset
1733 token::end_tok_type ettype = tok->ettype ();
2857
5448c8cba402 [project @ 1997-03-31 07:06:10 by jwe]
jwe
parents: 2856
diff changeset
1734
143
7849db4b6dbc [project @ 1993-10-04 02:36:45 by jwe]
jwe
parents: 118
diff changeset
1735 if (ettype != expected && ettype != token::simple_end)
7849db4b6dbc [project @ 1993-10-04 02:36:45 by jwe]
jwe
parents: 118
diff changeset
1736 {
2857
5448c8cba402 [project @ 1997-03-31 07:06:10 by jwe]
jwe
parents: 2856
diff changeset
1737 retval = false;
5448c8cba402 [project @ 1997-03-31 07:06:10 by jwe]
jwe
parents: 2856
diff changeset
1738
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
1739 bison_error ("parse error");
143
7849db4b6dbc [project @ 1993-10-04 02:36:45 by jwe]
jwe
parents: 118
diff changeset
1740
7849db4b6dbc [project @ 1993-10-04 02:36:45 by jwe]
jwe
parents: 118
diff changeset
1741 int l = tok->line ();
7849db4b6dbc [project @ 1993-10-04 02:36:45 by jwe]
jwe
parents: 118
diff changeset
1742 int c = tok->column ();
7849db4b6dbc [project @ 1993-10-04 02:36:45 by jwe]
jwe
parents: 118
diff changeset
1743
7849db4b6dbc [project @ 1993-10-04 02:36:45 by jwe]
jwe
parents: 118
diff changeset
1744 switch (expected)
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
1745 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
1746 case token::classdef_end:
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
1747 end_error ("classdef", ettype, l, c);
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
1748 break;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
1749
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
1750 case token::for_end:
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
1751 end_error ("for", ettype, l, c);
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
1752 break;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
1753
13249
7861a5fd3479 accept enumeration keyword
John W. Eaton <jwe@octave.org>
parents: 13246
diff changeset
1754 case token::enumeration_end:
7861a5fd3479 accept enumeration keyword
John W. Eaton <jwe@octave.org>
parents: 13246
diff changeset
1755 end_error ("enumeration", ettype, l, c);
7861a5fd3479 accept enumeration keyword
John W. Eaton <jwe@octave.org>
parents: 13246
diff changeset
1756 break;
7861a5fd3479 accept enumeration keyword
John W. Eaton <jwe@octave.org>
parents: 13246
diff changeset
1757
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
1758 case token::function_end:
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
1759 end_error ("function", ettype, l, c);
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
1760 break;
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 case token::if_end:
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
1763 end_error ("if", ettype, l, c);
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
1764 break;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
1765
13246
0c69a564f2be additional parfor changes
John W. Eaton <jwe@octave.org>
parents: 13245
diff changeset
1766 case token::parfor_end:
0c69a564f2be additional parfor changes
John W. Eaton <jwe@octave.org>
parents: 13245
diff changeset
1767 end_error ("parfor", ettype, l, c);
0c69a564f2be additional parfor changes
John W. Eaton <jwe@octave.org>
parents: 13245
diff changeset
1768 break;
0c69a564f2be additional parfor changes
John W. Eaton <jwe@octave.org>
parents: 13245
diff changeset
1769
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
1770 case token::try_catch_end:
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
1771 end_error ("try", ettype, l, c);
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
1772 break;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
1773
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
1774 case token::switch_end:
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
1775 end_error ("switch", ettype, l, c);
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
1776 break;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
1777
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
1778 case token::unwind_protect_end:
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
1779 end_error ("unwind_protect", ettype, l, c);
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
1780 break;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
1781
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
1782 case token::while_end:
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
1783 end_error ("while", ettype, l, c);
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
1784 break;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
1785
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
1786 default:
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
1787 panic_impossible ();
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
1788 break;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
1789 }
143
7849db4b6dbc [project @ 1993-10-04 02:36:45 by jwe]
jwe
parents: 118
diff changeset
1790 }
2857
5448c8cba402 [project @ 1997-03-31 07:06:10 by jwe]
jwe
parents: 2856
diff changeset
1791
5448c8cba402 [project @ 1997-03-31 07:06:10 by jwe]
jwe
parents: 2856
diff changeset
1792 return retval;
143
7849db4b6dbc [project @ 1993-10-04 02:36:45 by jwe]
jwe
parents: 118
diff changeset
1793 }
7849db4b6dbc [project @ 1993-10-04 02:36:45 by jwe]
jwe
parents: 118
diff changeset
1794
666
fb4f6556b443 [project @ 1994-09-06 21:22:46 by jwe]
jwe
parents: 627
diff changeset
1795 // 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
1796 // test in a logical expression.
fb4f6556b443 [project @ 1994-09-06 21:22:46 by jwe]
jwe
parents: 627
diff changeset
1797
16134
ec9c6222ef5a move static parser helper functions to octave_parser class
John W. Eaton <jwe@octave.org>
parents: 16133
diff changeset
1798 void
16287
04a7953496a7 create base class for parser; use reference for curr_lexer
John W. Eaton <jwe@octave.org>
parents: 16285
diff changeset
1799 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
1800 {
5781
faafc2d98b8d [project @ 2006-05-02 19:40:19 by jwe]
jwe
parents: 5775
diff changeset
1801 if (expr->is_assignment_expression ()
2961
8a77d52c9d02 [project @ 1997-05-12 01:36:04 by jwe]
jwe
parents: 2960
diff changeset
1802 && expr->paren_count () < 2)
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
1803 {
16288
fe3b9a51e625 rename curr_lexer, curr_parser, CURR_LEXER
John W. Eaton <jwe@octave.org>
parents: 16287
diff changeset
1804 if (lexer.fcn_file_full_name.empty ())
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
1805 warning_with_id
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
1806 ("Octave:assign-as-truth-value",
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
1807 "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
1808 else
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
1809 warning_with_id
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
1810 ("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
1811 "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
1812 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
1813 }
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
1814 }
578
d169be9237fb [project @ 1994-08-03 20:06:54 by jwe]
jwe
parents: 572
diff changeset
1815
2764
2c0f259cf83d [project @ 1997-03-01 02:30:26 by jwe]
jwe
parents: 2745
diff changeset
1816 // 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
1817
16134
ec9c6222ef5a move static parser helper functions to octave_parser class
John W. Eaton <jwe@octave.org>
parents: 16133
diff changeset
1818 void
16287
04a7953496a7 create base class for parser; use reference for curr_lexer
John W. Eaton <jwe@octave.org>
parents: 16285
diff changeset
1819 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
1820 {
5781
faafc2d98b8d [project @ 2006-05-02 19:40:19 by jwe]
jwe
parents: 5775
diff changeset
1821 if (! expr->is_constant ())
8974
fde2a916b2ac include line and file info in parser warnings
John W. Eaton <jwe@octave.org>
parents: 8950
diff changeset
1822 {
16288
fe3b9a51e625 rename curr_lexer, curr_parser, CURR_LEXER
John W. Eaton <jwe@octave.org>
parents: 16287
diff changeset
1823 if (lexer.fcn_file_full_name.empty ())
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
1824 warning_with_id ("Octave:variable-switch-label",
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
1825 "variable switch label");
8974
fde2a916b2ac include line and file info in parser warnings
John W. Eaton <jwe@octave.org>
parents: 8950
diff changeset
1826 else
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
1827 warning_with_id
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
1828 ("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
1829 "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
1830 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
1831 }
2764
2c0f259cf83d [project @ 1997-03-01 02:30:26 by jwe]
jwe
parents: 2745
diff changeset
1832 }
2c0f259cf83d [project @ 1997-03-01 02:30:26 by jwe]
jwe
parents: 2745
diff changeset
1833
2533
987e934bbb8c [project @ 1996-11-19 18:21:23 by jwe]
jwe
parents: 2525
diff changeset
1834 static tree_expression *
987e934bbb8c [project @ 1996-11-19 18:21:23 by jwe]
jwe
parents: 2525
diff changeset
1835 fold (tree_binary_expression *e)
987e934bbb8c [project @ 1996-11-19 18:21:23 by jwe]
jwe
parents: 2525
diff changeset
1836 {
3110
fe2d1ae8926b [project @ 1997-11-21 02:11:19 by jwe]
jwe
parents: 3099
diff changeset
1837 tree_expression *retval = e;
fe2d1ae8926b [project @ 1997-11-21 02:11:19 by jwe]
jwe
parents: 3099
diff changeset
1838
10067
6f79338c269b omission from last patch
Jaroslav Hajek <highegg@gmail.com>
parents: 9794
diff changeset
1839 unwind_protect frame;
6f79338c269b omission from last patch
Jaroslav Hajek <highegg@gmail.com>
parents: 9794
diff changeset
1840
6f79338c269b omission from last patch
Jaroslav Hajek <highegg@gmail.com>
parents: 9794
diff changeset
1841 frame.protect_var (error_state);
6f79338c269b omission from last patch
Jaroslav Hajek <highegg@gmail.com>
parents: 9794
diff changeset
1842 frame.protect_var (warning_state);
6f79338c269b omission from last patch
Jaroslav Hajek <highegg@gmail.com>
parents: 9794
diff changeset
1843
6f79338c269b omission from last patch
Jaroslav Hajek <highegg@gmail.com>
parents: 9794
diff changeset
1844 frame.protect_var (discard_error_messages);
6f79338c269b omission from last patch
Jaroslav Hajek <highegg@gmail.com>
parents: 9794
diff changeset
1845 frame.protect_var (discard_warning_messages);
4452
f3c21a1d1c62 [project @ 2003-07-09 23:20:18 by jwe]
jwe
parents: 4426
diff changeset
1846
3815
c554ad71bafc [project @ 2001-04-19 19:50:52 by jwe]
jwe
parents: 3802
diff changeset
1847 discard_error_messages = true;
4452
f3c21a1d1c62 [project @ 2003-07-09 23:20:18 by jwe]
jwe
parents: 4426
diff changeset
1848 discard_warning_messages = true;
2533
987e934bbb8c [project @ 1996-11-19 18:21:23 by jwe]
jwe
parents: 2525
diff changeset
1849
987e934bbb8c [project @ 1996-11-19 18:21:23 by jwe]
jwe
parents: 2525
diff changeset
1850 tree_expression *op1 = e->lhs ();
987e934bbb8c [project @ 1996-11-19 18:21:23 by jwe]
jwe
parents: 2525
diff changeset
1851 tree_expression *op2 = e->rhs ();
987e934bbb8c [project @ 1996-11-19 18:21:23 by jwe]
jwe
parents: 2525
diff changeset
1852
13844
e48529b3dbd4 eliminate warnings for changes in operator precedence made years ago
John W. Eaton <jwe@octave.org>
parents: 13250
diff changeset
1853 if (op1->is_constant () && op2->is_constant ())
2533
987e934bbb8c [project @ 1996-11-19 18:21:23 by jwe]
jwe
parents: 2525
diff changeset
1854 {
8658
73c4516fae10 New evaluator and debugger derived from tree-walker class
John W. Eaton <jwe@octave.org>
parents: 8471
diff changeset
1855 octave_value tmp = e->rvalue1 ();
2533
987e934bbb8c [project @ 1996-11-19 18:21:23 by jwe]
jwe
parents: 2525
diff changeset
1856
3489
cbee5fbb696d [project @ 2000-01-28 09:14:32 by jwe]
jwe
parents: 3485
diff changeset
1857 if (! (error_state || warning_state))
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
1858 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
1859 tree_constant *tc_retval
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
1860 = new tree_constant (tmp, op1->line (), op1->column ());
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
1861
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
1862 std::ostringstream buf;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
1863
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
1864 tree_print_code tpc (buf);
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
1865
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
1866 e->accept (tpc);
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
1867
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
1868 tc_retval->stash_original_text (buf.str ());
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
1869
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
1870 delete e;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
1871
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
1872 retval = tc_retval;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
1873 }
2533
987e934bbb8c [project @ 1996-11-19 18:21:23 by jwe]
jwe
parents: 2525
diff changeset
1874 }
3110
fe2d1ae8926b [project @ 1997-11-21 02:11:19 by jwe]
jwe
parents: 3099
diff changeset
1875
3292
ad0d250ebd7e [project @ 1999-10-14 22:52:28 by jwe]
jwe
parents: 3258
diff changeset
1876 return retval;
ad0d250ebd7e [project @ 1999-10-14 22:52:28 by jwe]
jwe
parents: 3258
diff changeset
1877 }
ad0d250ebd7e [project @ 1999-10-14 22:52:28 by jwe]
jwe
parents: 3258
diff changeset
1878
ad0d250ebd7e [project @ 1999-10-14 22:52:28 by jwe]
jwe
parents: 3258
diff changeset
1879 static tree_expression *
ad0d250ebd7e [project @ 1999-10-14 22:52:28 by jwe]
jwe
parents: 3258
diff changeset
1880 fold (tree_unary_expression *e)
ad0d250ebd7e [project @ 1999-10-14 22:52:28 by jwe]
jwe
parents: 3258
diff changeset
1881 {
ad0d250ebd7e [project @ 1999-10-14 22:52:28 by jwe]
jwe
parents: 3258
diff changeset
1882 tree_expression *retval = e;
ad0d250ebd7e [project @ 1999-10-14 22:52:28 by jwe]
jwe
parents: 3258
diff changeset
1883
10067
6f79338c269b omission from last patch
Jaroslav Hajek <highegg@gmail.com>
parents: 9794
diff changeset
1884 unwind_protect frame;
6f79338c269b omission from last patch
Jaroslav Hajek <highegg@gmail.com>
parents: 9794
diff changeset
1885
6f79338c269b omission from last patch
Jaroslav Hajek <highegg@gmail.com>
parents: 9794
diff changeset
1886 frame.protect_var (error_state);
6f79338c269b omission from last patch
Jaroslav Hajek <highegg@gmail.com>
parents: 9794
diff changeset
1887 frame.protect_var (warning_state);
6f79338c269b omission from last patch
Jaroslav Hajek <highegg@gmail.com>
parents: 9794
diff changeset
1888
6f79338c269b omission from last patch
Jaroslav Hajek <highegg@gmail.com>
parents: 9794
diff changeset
1889 frame.protect_var (discard_error_messages);
6f79338c269b omission from last patch
Jaroslav Hajek <highegg@gmail.com>
parents: 9794
diff changeset
1890 frame.protect_var (discard_warning_messages);
4452
f3c21a1d1c62 [project @ 2003-07-09 23:20:18 by jwe]
jwe
parents: 4426
diff changeset
1891
3815
c554ad71bafc [project @ 2001-04-19 19:50:52 by jwe]
jwe
parents: 3802
diff changeset
1892 discard_error_messages = true;
4452
f3c21a1d1c62 [project @ 2003-07-09 23:20:18 by jwe]
jwe
parents: 4426
diff changeset
1893 discard_warning_messages = true;
3292
ad0d250ebd7e [project @ 1999-10-14 22:52:28 by jwe]
jwe
parents: 3258
diff changeset
1894
ad0d250ebd7e [project @ 1999-10-14 22:52:28 by jwe]
jwe
parents: 3258
diff changeset
1895 tree_expression *op = e->operand ();
ad0d250ebd7e [project @ 1999-10-14 22:52:28 by jwe]
jwe
parents: 3258
diff changeset
1896
ad0d250ebd7e [project @ 1999-10-14 22:52:28 by jwe]
jwe
parents: 3258
diff changeset
1897 if (op->is_constant ())
ad0d250ebd7e [project @ 1999-10-14 22:52:28 by jwe]
jwe
parents: 3258
diff changeset
1898 {
8658
73c4516fae10 New evaluator and debugger derived from tree-walker class
John W. Eaton <jwe@octave.org>
parents: 8471
diff changeset
1899 octave_value tmp = e->rvalue1 ();
3292
ad0d250ebd7e [project @ 1999-10-14 22:52:28 by jwe]
jwe
parents: 3258
diff changeset
1900
3489
cbee5fbb696d [project @ 2000-01-28 09:14:32 by jwe]
jwe
parents: 3485
diff changeset
1901 if (! (error_state || warning_state))
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
1902 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
1903 tree_constant *tc_retval
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
1904 = new tree_constant (tmp, op->line (), op->column ());
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
1905
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
1906 std::ostringstream buf;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
1907
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
1908 tree_print_code tpc (buf);
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
1909
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
1910 e->accept (tpc);
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
1911
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
1912 tc_retval->stash_original_text (buf.str ());
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
1913
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
1914 delete e;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
1915
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
1916 retval = tc_retval;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
1917 }
3292
ad0d250ebd7e [project @ 1999-10-14 22:52:28 by jwe]
jwe
parents: 3258
diff changeset
1918 }
ad0d250ebd7e [project @ 1999-10-14 22:52:28 by jwe]
jwe
parents: 3258
diff changeset
1919
2533
987e934bbb8c [project @ 1996-11-19 18:21:23 by jwe]
jwe
parents: 2525
diff changeset
1920 return retval;
987e934bbb8c [project @ 1996-11-19 18:21:23 by jwe]
jwe
parents: 2525
diff changeset
1921 }
987e934bbb8c [project @ 1996-11-19 18:21:23 by jwe]
jwe
parents: 2525
diff changeset
1922
1623
fa7a847f9b92 [project @ 1995-11-06 18:05:09 by jwe]
jwe
parents: 1607
diff changeset
1923 // Finish building a range.
fa7a847f9b92 [project @ 1995-11-06 18:05:09 by jwe]
jwe
parents: 1607
diff changeset
1924
16134
ec9c6222ef5a move static parser helper functions to octave_parser class
John W. Eaton <jwe@octave.org>
parents: 16133
diff changeset
1925 tree_expression *
16287
04a7953496a7 create base class for parser; use reference for curr_lexer
John W. Eaton <jwe@octave.org>
parents: 16285
diff changeset
1926 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
1927 {
3110
fe2d1ae8926b [project @ 1997-11-21 02:11:19 by jwe]
jwe
parents: 3099
diff changeset
1928 tree_expression *retval = e;
fe2d1ae8926b [project @ 1997-11-21 02:11:19 by jwe]
jwe
parents: 3099
diff changeset
1929
10067
6f79338c269b omission from last patch
Jaroslav Hajek <highegg@gmail.com>
parents: 9794
diff changeset
1930 unwind_protect frame;
6f79338c269b omission from last patch
Jaroslav Hajek <highegg@gmail.com>
parents: 9794
diff changeset
1931
6f79338c269b omission from last patch
Jaroslav Hajek <highegg@gmail.com>
parents: 9794
diff changeset
1932 frame.protect_var (error_state);
6f79338c269b omission from last patch
Jaroslav Hajek <highegg@gmail.com>
parents: 9794
diff changeset
1933 frame.protect_var (warning_state);
6f79338c269b omission from last patch
Jaroslav Hajek <highegg@gmail.com>
parents: 9794
diff changeset
1934
6f79338c269b omission from last patch
Jaroslav Hajek <highegg@gmail.com>
parents: 9794
diff changeset
1935 frame.protect_var (discard_error_messages);
6f79338c269b omission from last patch
Jaroslav Hajek <highegg@gmail.com>
parents: 9794
diff changeset
1936 frame.protect_var (discard_warning_messages);
4452
f3c21a1d1c62 [project @ 2003-07-09 23:20:18 by jwe]
jwe
parents: 4426
diff changeset
1937
3815
c554ad71bafc [project @ 2001-04-19 19:50:52 by jwe]
jwe
parents: 3802
diff changeset
1938 discard_error_messages = true;
4452
f3c21a1d1c62 [project @ 2003-07-09 23:20:18 by jwe]
jwe
parents: 4426
diff changeset
1939 discard_warning_messages = true;
1623
fa7a847f9b92 [project @ 1995-11-06 18:05:09 by jwe]
jwe
parents: 1607
diff changeset
1940
2533
987e934bbb8c [project @ 1996-11-19 18:21:23 by jwe]
jwe
parents: 2525
diff changeset
1941 tree_expression *base = e->base ();
987e934bbb8c [project @ 1996-11-19 18:21:23 by jwe]
jwe
parents: 2525
diff changeset
1942 tree_expression *limit = e->limit ();
987e934bbb8c [project @ 1996-11-19 18:21:23 by jwe]
jwe
parents: 2525
diff changeset
1943 tree_expression *incr = e->increment ();
987e934bbb8c [project @ 1996-11-19 18:21:23 by jwe]
jwe
parents: 2525
diff changeset
1944
2970
b9e64477f703 [project @ 1997-05-15 18:04:21 by jwe]
jwe
parents: 2961
diff changeset
1945 if (base)
1623
fa7a847f9b92 [project @ 1995-11-06 18:05:09 by jwe]
jwe
parents: 1607
diff changeset
1946 {
2970
b9e64477f703 [project @ 1997-05-15 18:04:21 by jwe]
jwe
parents: 2961
diff changeset
1947 if (limit)
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
1948 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
1949 if (base->is_constant () && limit->is_constant ()
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
1950 && (! incr || (incr && incr->is_constant ())))
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
1951 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
1952 octave_value tmp = e->rvalue1 ();
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
1953
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
1954 if (! (error_state || warning_state))
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
1955 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
1956 tree_constant *tc_retval
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
1957 = new tree_constant (tmp, base->line (), base->column ());
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
1958
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
1959 std::ostringstream buf;
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 tree_print_code tpc (buf);
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 e->accept (tpc);
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 tc_retval->stash_original_text (buf.str ());
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
1966
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
1967 delete e;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
1968
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
1969 retval = tc_retval;
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 }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
1972 }
2533
987e934bbb8c [project @ 1996-11-19 18:21:23 by jwe]
jwe
parents: 2525
diff changeset
1973 else
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
1974 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
1975 e->preserve_base ();
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
1976 delete e;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
1977
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
1978 // FIXME -- need to attempt constant folding here
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
1979 // too (we need a generic way to do that).
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
1980 retval = base;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
1981 }
1623
fa7a847f9b92 [project @ 1995-11-06 18:05:09 by jwe]
jwe
parents: 1607
diff changeset
1982 }
fa7a847f9b92 [project @ 1995-11-06 18:05:09 by jwe]
jwe
parents: 1607
diff changeset
1983
fa7a847f9b92 [project @ 1995-11-06 18:05:09 by jwe]
jwe
parents: 1607
diff changeset
1984 return retval;
fa7a847f9b92 [project @ 1995-11-06 18:05:09 by jwe]
jwe
parents: 1607
diff changeset
1985 }
fa7a847f9b92 [project @ 1995-11-06 18:05:09 by jwe]
jwe
parents: 1607
diff changeset
1986
1607
795527e9db19 [project @ 1995-11-02 13:03:36 by jwe]
jwe
parents: 1588
diff changeset
1987 // Make a constant.
795527e9db19 [project @ 1995-11-02 13:03:36 by jwe]
jwe
parents: 1588
diff changeset
1988
16134
ec9c6222ef5a move static parser helper functions to octave_parser class
John W. Eaton <jwe@octave.org>
parents: 16133
diff changeset
1989 tree_constant *
16287
04a7953496a7 create base class for parser; use reference for curr_lexer
John W. Eaton <jwe@octave.org>
parents: 16285
diff changeset
1990 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
1991 {
795527e9db19 [project @ 1995-11-02 13:03:36 by jwe]
jwe
parents: 1588
diff changeset
1992 int l = tok_val->line ();
795527e9db19 [project @ 1995-11-02 13:03:36 by jwe]
jwe
parents: 1588
diff changeset
1993 int c = tok_val->column ();
795527e9db19 [project @ 1995-11-02 13:03:36 by jwe]
jwe
parents: 1588
diff changeset
1994
3216
60a89a69a70a [project @ 1998-11-11 20:47:03 by jwe]
jwe
parents: 3208
diff changeset
1995 tree_constant *retval = 0;
1607
795527e9db19 [project @ 1995-11-02 13:03:36 by jwe]
jwe
parents: 1588
diff changeset
1996
795527e9db19 [project @ 1995-11-02 13:03:36 by jwe]
jwe
parents: 1588
diff changeset
1997 switch (op)
795527e9db19 [project @ 1995-11-02 13:03:36 by jwe]
jwe
parents: 1588
diff changeset
1998 {
795527e9db19 [project @ 1995-11-02 13:03:36 by jwe]
jwe
parents: 1588
diff changeset
1999 case NUM:
2533
987e934bbb8c [project @ 1996-11-19 18:21:23 by jwe]
jwe
parents: 2525
diff changeset
2000 {
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
2001 octave_value tmp (tok_val->number ());
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
2002 retval = new tree_constant (tmp, l, c);
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
2003 retval->stash_original_text (tok_val->text_rep ());
2533
987e934bbb8c [project @ 1996-11-19 18:21:23 by jwe]
jwe
parents: 2525
diff changeset
2004 }
1607
795527e9db19 [project @ 1995-11-02 13:03:36 by jwe]
jwe
parents: 1588
diff changeset
2005 break;
795527e9db19 [project @ 1995-11-02 13:03:36 by jwe]
jwe
parents: 1588
diff changeset
2006
795527e9db19 [project @ 1995-11-02 13:03:36 by jwe]
jwe
parents: 1588
diff changeset
2007 case IMAG_NUM:
795527e9db19 [project @ 1995-11-02 13:03:36 by jwe]
jwe
parents: 1588
diff changeset
2008 {
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
2009 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
2010 retval = new tree_constant (tmp, l, c);
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
2011 retval->stash_original_text (tok_val->text_rep ());
1607
795527e9db19 [project @ 1995-11-02 13:03:36 by jwe]
jwe
parents: 1588
diff changeset
2012 }
795527e9db19 [project @ 1995-11-02 13:03:36 by jwe]
jwe
parents: 1588
diff changeset
2013 break;
795527e9db19 [project @ 1995-11-02 13:03:36 by jwe]
jwe
parents: 1588
diff changeset
2014
5279
bd32f770c09a [project @ 2005-04-12 21:55:31 by jwe]
jwe
parents: 5189
diff changeset
2015 case DQ_STRING:
bd32f770c09a [project @ 2005-04-12 21:55:31 by jwe]
jwe
parents: 5189
diff changeset
2016 case SQ_STRING:
2883
0b3954110c77 [project @ 1997-04-24 09:57:05 by jwe]
jwe
parents: 2865
diff changeset
2017 {
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
2018 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
2019
8150
283989f2da9b make null assignment matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents: 8064
diff changeset
2020 char delim = op == DQ_STRING ? '"' : '\'';
283989f2da9b make null assignment matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents: 8064
diff changeset
2021 octave_value tmp (txt, delim);
283989f2da9b make null assignment matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents: 8064
diff changeset
2022
283989f2da9b make null assignment matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents: 8064
diff changeset
2023 if (txt.empty ())
283989f2da9b make null assignment matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents: 8064
diff changeset
2024 {
283989f2da9b make null assignment matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents: 8064
diff changeset
2025 if (op == DQ_STRING)
283989f2da9b make null assignment matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents: 8064
diff changeset
2026 tmp = octave_null_str::instance;
283989f2da9b make null assignment matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents: 8064
diff changeset
2027 else
283989f2da9b make null assignment matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents: 8064
diff changeset
2028 tmp = octave_null_sq_str::instance;
283989f2da9b make null assignment matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents: 8064
diff changeset
2029 }
283989f2da9b make null assignment matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents: 8064
diff changeset
2030
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
2031 retval = new tree_constant (tmp, l, c);
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
2032
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
2033 if (op == DQ_STRING)
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
2034 txt = undo_string_escapes (txt);
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
2035
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
2036 // FIXME -- maybe this should also be handled by
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
2037 // tok_val->text_rep () for character strings?
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
2038 retval->stash_original_text (delim + txt + delim);
2883
0b3954110c77 [project @ 1997-04-24 09:57:05 by jwe]
jwe
parents: 2865
diff changeset
2039 }
1607
795527e9db19 [project @ 1995-11-02 13:03:36 by jwe]
jwe
parents: 1588
diff changeset
2040 break;
795527e9db19 [project @ 1995-11-02 13:03:36 by jwe]
jwe
parents: 1588
diff changeset
2041
795527e9db19 [project @ 1995-11-02 13:03:36 by jwe]
jwe
parents: 1588
diff changeset
2042 default:
795527e9db19 [project @ 1995-11-02 13:03:36 by jwe]
jwe
parents: 1588
diff changeset
2043 panic_impossible ();
795527e9db19 [project @ 1995-11-02 13:03:36 by jwe]
jwe
parents: 1588
diff changeset
2044 break;
795527e9db19 [project @ 1995-11-02 13:03:36 by jwe]
jwe
parents: 1588
diff changeset
2045 }
795527e9db19 [project @ 1995-11-02 13:03:36 by jwe]
jwe
parents: 1588
diff changeset
2046
795527e9db19 [project @ 1995-11-02 13:03:36 by jwe]
jwe
parents: 1588
diff changeset
2047 return retval;
795527e9db19 [project @ 1995-11-02 13:03:36 by jwe]
jwe
parents: 1588
diff changeset
2048 }
795527e9db19 [project @ 1995-11-02 13:03:36 by jwe]
jwe
parents: 1588
diff changeset
2049
4342
813effe14ee1 [project @ 2003-02-20 08:35:55 by jwe]
jwe
parents: 4318
diff changeset
2050 // Make a function handle.
813effe14ee1 [project @ 2003-02-20 08:35:55 by jwe]
jwe
parents: 4318
diff changeset
2051
16134
ec9c6222ef5a move static parser helper functions to octave_parser class
John W. Eaton <jwe@octave.org>
parents: 16133
diff changeset
2052 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
2053 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
2054 {
813effe14ee1 [project @ 2003-02-20 08:35:55 by jwe]
jwe
parents: 4318
diff changeset
2055 int l = tok_val->line ();
813effe14ee1 [project @ 2003-02-20 08:35:55 by jwe]
jwe
parents: 4318
diff changeset
2056 int c = tok_val->column ();
813effe14ee1 [project @ 2003-02-20 08:35:55 by jwe]
jwe
parents: 4318
diff changeset
2057
813effe14ee1 [project @ 2003-02-20 08:35:55 by jwe]
jwe
parents: 4318
diff changeset
2058 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
2059
813effe14ee1 [project @ 2003-02-20 08:35:55 by jwe]
jwe
parents: 4318
diff changeset
2060 return retval;
813effe14ee1 [project @ 2003-02-20 08:35:55 by jwe]
jwe
parents: 4318
diff changeset
2061 }
813effe14ee1 [project @ 2003-02-20 08:35:55 by jwe]
jwe
parents: 4318
diff changeset
2062
4935
4fc993a4e072 [project @ 2004-08-06 03:17:12 by jwe]
jwe
parents: 4930
diff changeset
2063 // Make an anonymous function handle.
4fc993a4e072 [project @ 2004-08-06 03:17:12 by jwe]
jwe
parents: 4930
diff changeset
2064
16134
ec9c6222ef5a move static parser helper functions to octave_parser class
John W. Eaton <jwe@octave.org>
parents: 16133
diff changeset
2065 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
2066 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
2067 tree_statement *stmt)
4935
4fc993a4e072 [project @ 2004-08-06 03:17:12 by jwe]
jwe
parents: 4930
diff changeset
2068 {
5775
ace8d8d26933 [project @ 2006-04-24 19:13:06 by jwe]
jwe
parents: 5774
diff changeset
2069 // 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
2070 int l = lexer.input_line_number;
fe3b9a51e625 rename curr_lexer, curr_parser, CURR_LEXER
John W. Eaton <jwe@octave.org>
parents: 16287
diff changeset
2071 int c = lexer.current_input_column;
4935
4fc993a4e072 [project @ 2004-08-06 03:17:12 by jwe]
jwe
parents: 4930
diff changeset
2072
4fc993a4e072 [project @ 2004-08-06 03:17:12 by jwe]
jwe
parents: 4930
diff changeset
2073 tree_parameter_list *ret_list = 0;
4fc993a4e072 [project @ 2004-08-06 03:17:12 by jwe]
jwe
parents: 4930
diff changeset
2074
16320
09f0cb9cac7d don't modify symbol table scope in the parser
John W. Eaton <jwe@octave.org>
parents: 16302
diff changeset
2075 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
2076
09f0cb9cac7d don't modify symbol table scope in the parser
John W. Eaton <jwe@octave.org>
parents: 16302
diff changeset
2077 lexer.symtab_context.pop ();
5861
2a6cb4ed8f1e [project @ 2006-06-16 05:09:41 by jwe]
jwe
parents: 5848
diff changeset
2078
7351
8470a6b0b769 [project @ 2008-01-07 17:57:24 by jwe]
jwe
parents: 7336
diff changeset
2079 stmt->set_print_flag (false);
4935
4fc993a4e072 [project @ 2004-08-06 03:17:12 by jwe]
jwe
parents: 4930
diff changeset
2080
4fc993a4e072 [project @ 2004-08-06 03:17:12 by jwe]
jwe
parents: 4930
diff changeset
2081 tree_statement_list *body = new tree_statement_list (stmt);
4fc993a4e072 [project @ 2004-08-06 03:17:12 by jwe]
jwe
parents: 4930
diff changeset
2082
8658
73c4516fae10 New evaluator and debugger derived from tree-walker class
John W. Eaton <jwe@octave.org>
parents: 8471
diff changeset
2083 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
2084
5861
2a6cb4ed8f1e [project @ 2006-06-16 05:09:41 by jwe]
jwe
parents: 5848
diff changeset
2085 tree_anon_fcn_handle *retval
7336
745a8299c2b5 [project @ 2007-12-28 20:56:55 by jwe]
jwe
parents: 7017
diff changeset
2086 = 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
2087 // 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
2088 // errors when executed.
16288
fe3b9a51e625 rename curr_lexer, curr_parser, CURR_LEXER
John W. Eaton <jwe@octave.org>
parents: 16287
diff changeset
2089 //retval->stash_file_name (lexer.fcn_file_name);
4935
4fc993a4e072 [project @ 2004-08-06 03:17:12 by jwe]
jwe
parents: 4930
diff changeset
2090
4fc993a4e072 [project @ 2004-08-06 03:17:12 by jwe]
jwe
parents: 4930
diff changeset
2091 return retval;
4fc993a4e072 [project @ 2004-08-06 03:17:12 by jwe]
jwe
parents: 4930
diff changeset
2092 }
4fc993a4e072 [project @ 2004-08-06 03:17:12 by jwe]
jwe
parents: 4930
diff changeset
2093
666
fb4f6556b443 [project @ 1994-09-06 21:22:46 by jwe]
jwe
parents: 627
diff changeset
2094 // Build a binary expression.
fb4f6556b443 [project @ 1994-09-06 21:22:46 by jwe]
jwe
parents: 627
diff changeset
2095
16134
ec9c6222ef5a move static parser helper functions to octave_parser class
John W. Eaton <jwe@octave.org>
parents: 16133
diff changeset
2096 tree_expression *
16287
04a7953496a7 create base class for parser; use reference for curr_lexer
John W. Eaton <jwe@octave.org>
parents: 16285
diff changeset
2097 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
2098 token *tok_val, tree_expression *op2)
578
d169be9237fb [project @ 1994-08-03 20:06:54 by jwe]
jwe
parents: 572
diff changeset
2099 {
2883
0b3954110c77 [project @ 1997-04-24 09:57:05 by jwe]
jwe
parents: 2865
diff changeset
2100 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
2101
578
d169be9237fb [project @ 1994-08-03 20:06:54 by jwe]
jwe
parents: 572
diff changeset
2102 switch (op)
d169be9237fb [project @ 1994-08-03 20:06:54 by jwe]
jwe
parents: 572
diff changeset
2103 {
d169be9237fb [project @ 1994-08-03 20:06:54 by jwe]
jwe
parents: 572
diff changeset
2104 case POW:
3525
6cfa474c5b99 [project @ 2000-02-02 10:48:41 by jwe]
jwe
parents: 3523
diff changeset
2105 t = octave_value::op_pow;
578
d169be9237fb [project @ 1994-08-03 20:06:54 by jwe]
jwe
parents: 572
diff changeset
2106 break;
777
a2f9d3fd720c [project @ 1994-10-07 14:01:53 by jwe]
jwe
parents: 773
diff changeset
2107
578
d169be9237fb [project @ 1994-08-03 20:06:54 by jwe]
jwe
parents: 572
diff changeset
2108 case EPOW:
3525
6cfa474c5b99 [project @ 2000-02-02 10:48:41 by jwe]
jwe
parents: 3523
diff changeset
2109 t = octave_value::op_el_pow;
578
d169be9237fb [project @ 1994-08-03 20:06:54 by jwe]
jwe
parents: 572
diff changeset
2110 break;
777
a2f9d3fd720c [project @ 1994-10-07 14:01:53 by jwe]
jwe
parents: 773
diff changeset
2111
578
d169be9237fb [project @ 1994-08-03 20:06:54 by jwe]
jwe
parents: 572
diff changeset
2112 case '+':
3525
6cfa474c5b99 [project @ 2000-02-02 10:48:41 by jwe]
jwe
parents: 3523
diff changeset
2113 t = octave_value::op_add;
578
d169be9237fb [project @ 1994-08-03 20:06:54 by jwe]
jwe
parents: 572
diff changeset
2114 break;
777
a2f9d3fd720c [project @ 1994-10-07 14:01:53 by jwe]
jwe
parents: 773
diff changeset
2115
578
d169be9237fb [project @ 1994-08-03 20:06:54 by jwe]
jwe
parents: 572
diff changeset
2116 case '-':
3525
6cfa474c5b99 [project @ 2000-02-02 10:48:41 by jwe]
jwe
parents: 3523
diff changeset
2117 t = octave_value::op_sub;
578
d169be9237fb [project @ 1994-08-03 20:06:54 by jwe]
jwe
parents: 572
diff changeset
2118 break;
777
a2f9d3fd720c [project @ 1994-10-07 14:01:53 by jwe]
jwe
parents: 773
diff changeset
2119
578
d169be9237fb [project @ 1994-08-03 20:06:54 by jwe]
jwe
parents: 572
diff changeset
2120 case '*':
3525
6cfa474c5b99 [project @ 2000-02-02 10:48:41 by jwe]
jwe
parents: 3523
diff changeset
2121 t = octave_value::op_mul;
578
d169be9237fb [project @ 1994-08-03 20:06:54 by jwe]
jwe
parents: 572
diff changeset
2122 break;
777
a2f9d3fd720c [project @ 1994-10-07 14:01:53 by jwe]
jwe
parents: 773
diff changeset
2123
578
d169be9237fb [project @ 1994-08-03 20:06:54 by jwe]
jwe
parents: 572
diff changeset
2124 case '/':
3525
6cfa474c5b99 [project @ 2000-02-02 10:48:41 by jwe]
jwe
parents: 3523
diff changeset
2125 t = octave_value::op_div;
578
d169be9237fb [project @ 1994-08-03 20:06:54 by jwe]
jwe
parents: 572
diff changeset
2126 break;
777
a2f9d3fd720c [project @ 1994-10-07 14:01:53 by jwe]
jwe
parents: 773
diff changeset
2127
578
d169be9237fb [project @ 1994-08-03 20:06:54 by jwe]
jwe
parents: 572
diff changeset
2128 case EMUL:
3525
6cfa474c5b99 [project @ 2000-02-02 10:48:41 by jwe]
jwe
parents: 3523
diff changeset
2129 t = octave_value::op_el_mul;
578
d169be9237fb [project @ 1994-08-03 20:06:54 by jwe]
jwe
parents: 572
diff changeset
2130 break;
777
a2f9d3fd720c [project @ 1994-10-07 14:01:53 by jwe]
jwe
parents: 773
diff changeset
2131
578
d169be9237fb [project @ 1994-08-03 20:06:54 by jwe]
jwe
parents: 572
diff changeset
2132 case EDIV:
3525
6cfa474c5b99 [project @ 2000-02-02 10:48:41 by jwe]
jwe
parents: 3523
diff changeset
2133 t = octave_value::op_el_div;
578
d169be9237fb [project @ 1994-08-03 20:06:54 by jwe]
jwe
parents: 572
diff changeset
2134 break;
777
a2f9d3fd720c [project @ 1994-10-07 14:01:53 by jwe]
jwe
parents: 773
diff changeset
2135
578
d169be9237fb [project @ 1994-08-03 20:06:54 by jwe]
jwe
parents: 572
diff changeset
2136 case LEFTDIV:
3525
6cfa474c5b99 [project @ 2000-02-02 10:48:41 by jwe]
jwe
parents: 3523
diff changeset
2137 t = octave_value::op_ldiv;
578
d169be9237fb [project @ 1994-08-03 20:06:54 by jwe]
jwe
parents: 572
diff changeset
2138 break;
777
a2f9d3fd720c [project @ 1994-10-07 14:01:53 by jwe]
jwe
parents: 773
diff changeset
2139
578
d169be9237fb [project @ 1994-08-03 20:06:54 by jwe]
jwe
parents: 572
diff changeset
2140 case ELEFTDIV:
3525
6cfa474c5b99 [project @ 2000-02-02 10:48:41 by jwe]
jwe
parents: 3523
diff changeset
2141 t = octave_value::op_el_ldiv;
578
d169be9237fb [project @ 1994-08-03 20:06:54 by jwe]
jwe
parents: 572
diff changeset
2142 break;
777
a2f9d3fd720c [project @ 1994-10-07 14:01:53 by jwe]
jwe
parents: 773
diff changeset
2143
2899
0d79a8c11a2b [project @ 1997-04-30 03:09:23 by jwe]
jwe
parents: 2891
diff changeset
2144 case LSHIFT:
3525
6cfa474c5b99 [project @ 2000-02-02 10:48:41 by jwe]
jwe
parents: 3523
diff changeset
2145 t = octave_value::op_lshift;
2899
0d79a8c11a2b [project @ 1997-04-30 03:09:23 by jwe]
jwe
parents: 2891
diff changeset
2146 break;
0d79a8c11a2b [project @ 1997-04-30 03:09:23 by jwe]
jwe
parents: 2891
diff changeset
2147
0d79a8c11a2b [project @ 1997-04-30 03:09:23 by jwe]
jwe
parents: 2891
diff changeset
2148 case RSHIFT:
3525
6cfa474c5b99 [project @ 2000-02-02 10:48:41 by jwe]
jwe
parents: 3523
diff changeset
2149 t = octave_value::op_rshift;
2899
0d79a8c11a2b [project @ 1997-04-30 03:09:23 by jwe]
jwe
parents: 2891
diff changeset
2150 break;
0d79a8c11a2b [project @ 1997-04-30 03:09:23 by jwe]
jwe
parents: 2891
diff changeset
2151
578
d169be9237fb [project @ 1994-08-03 20:06:54 by jwe]
jwe
parents: 572
diff changeset
2152 case EXPR_LT:
3525
6cfa474c5b99 [project @ 2000-02-02 10:48:41 by jwe]
jwe
parents: 3523
diff changeset
2153 t = octave_value::op_lt;
578
d169be9237fb [project @ 1994-08-03 20:06:54 by jwe]
jwe
parents: 572
diff changeset
2154 break;
777
a2f9d3fd720c [project @ 1994-10-07 14:01:53 by jwe]
jwe
parents: 773
diff changeset
2155
578
d169be9237fb [project @ 1994-08-03 20:06:54 by jwe]
jwe
parents: 572
diff changeset
2156 case EXPR_LE:
3525
6cfa474c5b99 [project @ 2000-02-02 10:48:41 by jwe]
jwe
parents: 3523
diff changeset
2157 t = octave_value::op_le;
578
d169be9237fb [project @ 1994-08-03 20:06:54 by jwe]
jwe
parents: 572
diff changeset
2158 break;
777
a2f9d3fd720c [project @ 1994-10-07 14:01:53 by jwe]
jwe
parents: 773
diff changeset
2159
578
d169be9237fb [project @ 1994-08-03 20:06:54 by jwe]
jwe
parents: 572
diff changeset
2160 case EXPR_EQ:
3525
6cfa474c5b99 [project @ 2000-02-02 10:48:41 by jwe]
jwe
parents: 3523
diff changeset
2161 t = octave_value::op_eq;
578
d169be9237fb [project @ 1994-08-03 20:06:54 by jwe]
jwe
parents: 572
diff changeset
2162 break;
777
a2f9d3fd720c [project @ 1994-10-07 14:01:53 by jwe]
jwe
parents: 773
diff changeset
2163
578
d169be9237fb [project @ 1994-08-03 20:06:54 by jwe]
jwe
parents: 572
diff changeset
2164 case EXPR_GE:
3525
6cfa474c5b99 [project @ 2000-02-02 10:48:41 by jwe]
jwe
parents: 3523
diff changeset
2165 t = octave_value::op_ge;
578
d169be9237fb [project @ 1994-08-03 20:06:54 by jwe]
jwe
parents: 572
diff changeset
2166 break;
777
a2f9d3fd720c [project @ 1994-10-07 14:01:53 by jwe]
jwe
parents: 773
diff changeset
2167
578
d169be9237fb [project @ 1994-08-03 20:06:54 by jwe]
jwe
parents: 572
diff changeset
2168 case EXPR_GT:
3525
6cfa474c5b99 [project @ 2000-02-02 10:48:41 by jwe]
jwe
parents: 3523
diff changeset
2169 t = octave_value::op_gt;
578
d169be9237fb [project @ 1994-08-03 20:06:54 by jwe]
jwe
parents: 572
diff changeset
2170 break;
777
a2f9d3fd720c [project @ 1994-10-07 14:01:53 by jwe]
jwe
parents: 773
diff changeset
2171
578
d169be9237fb [project @ 1994-08-03 20:06:54 by jwe]
jwe
parents: 572
diff changeset
2172 case EXPR_NE:
3525
6cfa474c5b99 [project @ 2000-02-02 10:48:41 by jwe]
jwe
parents: 3523
diff changeset
2173 t = octave_value::op_ne;
578
d169be9237fb [project @ 1994-08-03 20:06:54 by jwe]
jwe
parents: 572
diff changeset
2174 break;
777
a2f9d3fd720c [project @ 1994-10-07 14:01:53 by jwe]
jwe
parents: 773
diff changeset
2175
578
d169be9237fb [project @ 1994-08-03 20:06:54 by jwe]
jwe
parents: 572
diff changeset
2176 case EXPR_AND:
3525
6cfa474c5b99 [project @ 2000-02-02 10:48:41 by jwe]
jwe
parents: 3523
diff changeset
2177 t = octave_value::op_el_and;
578
d169be9237fb [project @ 1994-08-03 20:06:54 by jwe]
jwe
parents: 572
diff changeset
2178 break;
777
a2f9d3fd720c [project @ 1994-10-07 14:01:53 by jwe]
jwe
parents: 773
diff changeset
2179
578
d169be9237fb [project @ 1994-08-03 20:06:54 by jwe]
jwe
parents: 572
diff changeset
2180 case EXPR_OR:
3525
6cfa474c5b99 [project @ 2000-02-02 10:48:41 by jwe]
jwe
parents: 3523
diff changeset
2181 t = octave_value::op_el_or;
578
d169be9237fb [project @ 1994-08-03 20:06:54 by jwe]
jwe
parents: 572
diff changeset
2182 break;
777
a2f9d3fd720c [project @ 1994-10-07 14:01:53 by jwe]
jwe
parents: 773
diff changeset
2183
578
d169be9237fb [project @ 1994-08-03 20:06:54 by jwe]
jwe
parents: 572
diff changeset
2184 default:
d169be9237fb [project @ 1994-08-03 20:06:54 by jwe]
jwe
parents: 572
diff changeset
2185 panic_impossible ();
d169be9237fb [project @ 1994-08-03 20:06:54 by jwe]
jwe
parents: 572
diff changeset
2186 break;
d169be9237fb [project @ 1994-08-03 20:06:54 by jwe]
jwe
parents: 572
diff changeset
2187 }
d169be9237fb [project @ 1994-08-03 20:06:54 by jwe]
jwe
parents: 572
diff changeset
2188
d169be9237fb [project @ 1994-08-03 20:06:54 by jwe]
jwe
parents: 572
diff changeset
2189 int l = tok_val->line ();
d169be9237fb [project @ 1994-08-03 20:06:54 by jwe]
jwe
parents: 572
diff changeset
2190 int c = tok_val->column ();
d169be9237fb [project @ 1994-08-03 20:06:54 by jwe]
jwe
parents: 572
diff changeset
2191
2533
987e934bbb8c [project @ 1996-11-19 18:21:23 by jwe]
jwe
parents: 2525
diff changeset
2192 tree_binary_expression *e
7800
5861b95e9879 support for compound operators, implement trans_mul, mul_trans, herm_mul and mul_herm
Jaroslav Hajek <highegg@gmail.com>
parents: 7787
diff changeset
2193 = maybe_compound_binary_expression (op1, op2, l, c, t);
1623
fa7a847f9b92 [project @ 1995-11-06 18:05:09 by jwe]
jwe
parents: 1607
diff changeset
2194
2533
987e934bbb8c [project @ 1996-11-19 18:21:23 by jwe]
jwe
parents: 2525
diff changeset
2195 return fold (e);
578
d169be9237fb [project @ 1994-08-03 20:06:54 by jwe]
jwe
parents: 572
diff changeset
2196 }
d169be9237fb [project @ 1994-08-03 20:06:54 by jwe]
jwe
parents: 572
diff changeset
2197
2375
7ef24992e290 [project @ 1996-10-12 00:39:52 by jwe]
jwe
parents: 2200
diff changeset
2198 // Build a boolean expression.
666
fb4f6556b443 [project @ 1994-09-06 21:22:46 by jwe]
jwe
parents: 627
diff changeset
2199
16134
ec9c6222ef5a move static parser helper functions to octave_parser class
John W. Eaton <jwe@octave.org>
parents: 16133
diff changeset
2200 tree_expression *
16287
04a7953496a7 create base class for parser; use reference for curr_lexer
John W. Eaton <jwe@octave.org>
parents: 16285
diff changeset
2201 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
2202 token *tok_val, tree_expression *op2)
578
d169be9237fb [project @ 1994-08-03 20:06:54 by jwe]
jwe
parents: 572
diff changeset
2203 {
2375
7ef24992e290 [project @ 1996-10-12 00:39:52 by jwe]
jwe
parents: 2200
diff changeset
2204 tree_boolean_expression::type t;
7ef24992e290 [project @ 1996-10-12 00:39:52 by jwe]
jwe
parents: 2200
diff changeset
2205
578
d169be9237fb [project @ 1994-08-03 20:06:54 by jwe]
jwe
parents: 572
diff changeset
2206 switch (op)
d169be9237fb [project @ 1994-08-03 20:06:54 by jwe]
jwe
parents: 572
diff changeset
2207 {
2375
7ef24992e290 [project @ 1996-10-12 00:39:52 by jwe]
jwe
parents: 2200
diff changeset
2208 case EXPR_AND_AND:
2805
68e6d0c93fc8 [project @ 1997-03-11 04:52:44 by jwe]
jwe
parents: 2791
diff changeset
2209 t = tree_boolean_expression::bool_and;
578
d169be9237fb [project @ 1994-08-03 20:06:54 by jwe]
jwe
parents: 572
diff changeset
2210 break;
777
a2f9d3fd720c [project @ 1994-10-07 14:01:53 by jwe]
jwe
parents: 773
diff changeset
2211
2375
7ef24992e290 [project @ 1996-10-12 00:39:52 by jwe]
jwe
parents: 2200
diff changeset
2212 case EXPR_OR_OR:
2805
68e6d0c93fc8 [project @ 1997-03-11 04:52:44 by jwe]
jwe
parents: 2791
diff changeset
2213 t = tree_boolean_expression::bool_or;
578
d169be9237fb [project @ 1994-08-03 20:06:54 by jwe]
jwe
parents: 572
diff changeset
2214 break;
777
a2f9d3fd720c [project @ 1994-10-07 14:01:53 by jwe]
jwe
parents: 773
diff changeset
2215
578
d169be9237fb [project @ 1994-08-03 20:06:54 by jwe]
jwe
parents: 572
diff changeset
2216 default:
d169be9237fb [project @ 1994-08-03 20:06:54 by jwe]
jwe
parents: 572
diff changeset
2217 panic_impossible ();
d169be9237fb [project @ 1994-08-03 20:06:54 by jwe]
jwe
parents: 572
diff changeset
2218 break;
d169be9237fb [project @ 1994-08-03 20:06:54 by jwe]
jwe
parents: 572
diff changeset
2219 }
d169be9237fb [project @ 1994-08-03 20:06:54 by jwe]
jwe
parents: 572
diff changeset
2220
d169be9237fb [project @ 1994-08-03 20:06:54 by jwe]
jwe
parents: 572
diff changeset
2221 int l = tok_val->line ();
d169be9237fb [project @ 1994-08-03 20:06:54 by jwe]
jwe
parents: 572
diff changeset
2222 int c = tok_val->column ();
d169be9237fb [project @ 1994-08-03 20:06:54 by jwe]
jwe
parents: 572
diff changeset
2223
2533
987e934bbb8c [project @ 1996-11-19 18:21:23 by jwe]
jwe
parents: 2525
diff changeset
2224 tree_boolean_expression *e
987e934bbb8c [project @ 1996-11-19 18:21:23 by jwe]
jwe
parents: 2525
diff changeset
2225 = new tree_boolean_expression (op1, op2, l, c, t);
2375
7ef24992e290 [project @ 1996-10-12 00:39:52 by jwe]
jwe
parents: 2200
diff changeset
2226
2533
987e934bbb8c [project @ 1996-11-19 18:21:23 by jwe]
jwe
parents: 2525
diff changeset
2227 return fold (e);
578
d169be9237fb [project @ 1994-08-03 20:06:54 by jwe]
jwe
parents: 572
diff changeset
2228 }
d169be9237fb [project @ 1994-08-03 20:06:54 by jwe]
jwe
parents: 572
diff changeset
2229
2375
7ef24992e290 [project @ 1996-10-12 00:39:52 by jwe]
jwe
parents: 2200
diff changeset
2230 // Build a prefix expression.
666
fb4f6556b443 [project @ 1994-09-06 21:22:46 by jwe]
jwe
parents: 627
diff changeset
2231
16134
ec9c6222ef5a move static parser helper functions to octave_parser class
John W. Eaton <jwe@octave.org>
parents: 16133
diff changeset
2232 tree_expression *
16287
04a7953496a7 create base class for parser; use reference for curr_lexer
John W. Eaton <jwe@octave.org>
parents: 16285
diff changeset
2233 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
2234 token *tok_val)
578
d169be9237fb [project @ 1994-08-03 20:06:54 by jwe]
jwe
parents: 572
diff changeset
2235 {
3203
bc61b0e8d60e [project @ 1998-10-30 20:26:27 by jwe]
jwe
parents: 3195
diff changeset
2236 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
2237
578
d169be9237fb [project @ 1994-08-03 20:06:54 by jwe]
jwe
parents: 572
diff changeset
2238 switch (op)
d169be9237fb [project @ 1994-08-03 20:06:54 by jwe]
jwe
parents: 572
diff changeset
2239 {
2960
194b50e4725b [project @ 1997-05-12 00:43:54 by jwe]
jwe
parents: 2899
diff changeset
2240 case EXPR_NOT:
3525
6cfa474c5b99 [project @ 2000-02-02 10:48:41 by jwe]
jwe
parents: 3523
diff changeset
2241 t = octave_value::op_not;
2960
194b50e4725b [project @ 1997-05-12 00:43:54 by jwe]
jwe
parents: 2899
diff changeset
2242 break;
194b50e4725b [project @ 1997-05-12 00:43:54 by jwe]
jwe
parents: 2899
diff changeset
2243
4965
c0d8e8afa82f [project @ 2004-09-06 20:19:57 by jwe]
jwe
parents: 4935
diff changeset
2244 case '+':
c0d8e8afa82f [project @ 2004-09-06 20:19:57 by jwe]
jwe
parents: 4935
diff changeset
2245 t = octave_value::op_uplus;
c0d8e8afa82f [project @ 2004-09-06 20:19:57 by jwe]
jwe
parents: 4935
diff changeset
2246 break;
c0d8e8afa82f [project @ 2004-09-06 20:19:57 by jwe]
jwe
parents: 4935
diff changeset
2247
2960
194b50e4725b [project @ 1997-05-12 00:43:54 by jwe]
jwe
parents: 2899
diff changeset
2248 case '-':
3525
6cfa474c5b99 [project @ 2000-02-02 10:48:41 by jwe]
jwe
parents: 3523
diff changeset
2249 t = octave_value::op_uminus;
2960
194b50e4725b [project @ 1997-05-12 00:43:54 by jwe]
jwe
parents: 2899
diff changeset
2250 break;
194b50e4725b [project @ 1997-05-12 00:43:54 by jwe]
jwe
parents: 2899
diff changeset
2251
578
d169be9237fb [project @ 1994-08-03 20:06:54 by jwe]
jwe
parents: 572
diff changeset
2252 case PLUS_PLUS:
3525
6cfa474c5b99 [project @ 2000-02-02 10:48:41 by jwe]
jwe
parents: 3523
diff changeset
2253 t = octave_value::op_incr;
578
d169be9237fb [project @ 1994-08-03 20:06:54 by jwe]
jwe
parents: 572
diff changeset
2254 break;
777
a2f9d3fd720c [project @ 1994-10-07 14:01:53 by jwe]
jwe
parents: 773
diff changeset
2255
578
d169be9237fb [project @ 1994-08-03 20:06:54 by jwe]
jwe
parents: 572
diff changeset
2256 case MINUS_MINUS:
3525
6cfa474c5b99 [project @ 2000-02-02 10:48:41 by jwe]
jwe
parents: 3523
diff changeset
2257 t = octave_value::op_decr;
578
d169be9237fb [project @ 1994-08-03 20:06:54 by jwe]
jwe
parents: 572
diff changeset
2258 break;
777
a2f9d3fd720c [project @ 1994-10-07 14:01:53 by jwe]
jwe
parents: 773
diff changeset
2259
578
d169be9237fb [project @ 1994-08-03 20:06:54 by jwe]
jwe
parents: 572
diff changeset
2260 default:
d169be9237fb [project @ 1994-08-03 20:06:54 by jwe]
jwe
parents: 572
diff changeset
2261 panic_impossible ();
d169be9237fb [project @ 1994-08-03 20:06:54 by jwe]
jwe
parents: 572
diff changeset
2262 break;
d169be9237fb [project @ 1994-08-03 20:06:54 by jwe]
jwe
parents: 572
diff changeset
2263 }
d169be9237fb [project @ 1994-08-03 20:06:54 by jwe]
jwe
parents: 572
diff changeset
2264
d169be9237fb [project @ 1994-08-03 20:06:54 by jwe]
jwe
parents: 572
diff changeset
2265 int l = tok_val->line ();
d169be9237fb [project @ 1994-08-03 20:06:54 by jwe]
jwe
parents: 572
diff changeset
2266 int c = tok_val->column ();
d169be9237fb [project @ 1994-08-03 20:06:54 by jwe]
jwe
parents: 572
diff changeset
2267
3292
ad0d250ebd7e [project @ 1999-10-14 22:52:28 by jwe]
jwe
parents: 3258
diff changeset
2268 tree_prefix_expression *e
ad0d250ebd7e [project @ 1999-10-14 22:52:28 by jwe]
jwe
parents: 3258
diff changeset
2269 = new tree_prefix_expression (op1, l, c, t);
ad0d250ebd7e [project @ 1999-10-14 22:52:28 by jwe]
jwe
parents: 3258
diff changeset
2270
ad0d250ebd7e [project @ 1999-10-14 22:52:28 by jwe]
jwe
parents: 3258
diff changeset
2271 return fold (e);
578
d169be9237fb [project @ 1994-08-03 20:06:54 by jwe]
jwe
parents: 572
diff changeset
2272 }
d169be9237fb [project @ 1994-08-03 20:06:54 by jwe]
jwe
parents: 572
diff changeset
2273
2375
7ef24992e290 [project @ 1996-10-12 00:39:52 by jwe]
jwe
parents: 2200
diff changeset
2274 // Build a postfix expression.
666
fb4f6556b443 [project @ 1994-09-06 21:22:46 by jwe]
jwe
parents: 627
diff changeset
2275
16134
ec9c6222ef5a move static parser helper functions to octave_parser class
John W. Eaton <jwe@octave.org>
parents: 16133
diff changeset
2276 tree_expression *
16287
04a7953496a7 create base class for parser; use reference for curr_lexer
John W. Eaton <jwe@octave.org>
parents: 16285
diff changeset
2277 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
2278 token *tok_val)
578
d169be9237fb [project @ 1994-08-03 20:06:54 by jwe]
jwe
parents: 572
diff changeset
2279 {
3203
bc61b0e8d60e [project @ 1998-10-30 20:26:27 by jwe]
jwe
parents: 3195
diff changeset
2280 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
2281
578
d169be9237fb [project @ 1994-08-03 20:06:54 by jwe]
jwe
parents: 572
diff changeset
2282 switch (op)
d169be9237fb [project @ 1994-08-03 20:06:54 by jwe]
jwe
parents: 572
diff changeset
2283 {
16284
09881dab3aaf * lex.ll, oct-parse.in.yy (HERMITIAN): Rename token from QUOTE.
John W. Eaton <jwe@octave.org>
parents: 16279
diff changeset
2284 case HERMITIAN:
3525
6cfa474c5b99 [project @ 2000-02-02 10:48:41 by jwe]
jwe
parents: 3523
diff changeset
2285 t = octave_value::op_hermitian;
2960
194b50e4725b [project @ 1997-05-12 00:43:54 by jwe]
jwe
parents: 2899
diff changeset
2286 break;
194b50e4725b [project @ 1997-05-12 00:43:54 by jwe]
jwe
parents: 2899
diff changeset
2287
194b50e4725b [project @ 1997-05-12 00:43:54 by jwe]
jwe
parents: 2899
diff changeset
2288 case TRANSPOSE:
3525
6cfa474c5b99 [project @ 2000-02-02 10:48:41 by jwe]
jwe
parents: 3523
diff changeset
2289 t = octave_value::op_transpose;
2960
194b50e4725b [project @ 1997-05-12 00:43:54 by jwe]
jwe
parents: 2899
diff changeset
2290 break;
194b50e4725b [project @ 1997-05-12 00:43:54 by jwe]
jwe
parents: 2899
diff changeset
2291
2375
7ef24992e290 [project @ 1996-10-12 00:39:52 by jwe]
jwe
parents: 2200
diff changeset
2292 case PLUS_PLUS:
3525
6cfa474c5b99 [project @ 2000-02-02 10:48:41 by jwe]
jwe
parents: 3523
diff changeset
2293 t = octave_value::op_incr;
578
d169be9237fb [project @ 1994-08-03 20:06:54 by jwe]
jwe
parents: 572
diff changeset
2294 break;
777
a2f9d3fd720c [project @ 1994-10-07 14:01:53 by jwe]
jwe
parents: 773
diff changeset
2295
2375
7ef24992e290 [project @ 1996-10-12 00:39:52 by jwe]
jwe
parents: 2200
diff changeset
2296 case MINUS_MINUS:
3525
6cfa474c5b99 [project @ 2000-02-02 10:48:41 by jwe]
jwe
parents: 3523
diff changeset
2297 t = octave_value::op_decr;
578
d169be9237fb [project @ 1994-08-03 20:06:54 by jwe]
jwe
parents: 572
diff changeset
2298 break;
777
a2f9d3fd720c [project @ 1994-10-07 14:01:53 by jwe]
jwe
parents: 773
diff changeset
2299
578
d169be9237fb [project @ 1994-08-03 20:06:54 by jwe]
jwe
parents: 572
diff changeset
2300 default:
d169be9237fb [project @ 1994-08-03 20:06:54 by jwe]
jwe
parents: 572
diff changeset
2301 panic_impossible ();
d169be9237fb [project @ 1994-08-03 20:06:54 by jwe]
jwe
parents: 572
diff changeset
2302 break;
d169be9237fb [project @ 1994-08-03 20:06:54 by jwe]
jwe
parents: 572
diff changeset
2303 }
d169be9237fb [project @ 1994-08-03 20:06:54 by jwe]
jwe
parents: 572
diff changeset
2304
d169be9237fb [project @ 1994-08-03 20:06:54 by jwe]
jwe
parents: 572
diff changeset
2305 int l = tok_val->line ();
d169be9237fb [project @ 1994-08-03 20:06:54 by jwe]
jwe
parents: 572
diff changeset
2306 int c = tok_val->column ();
d169be9237fb [project @ 1994-08-03 20:06:54 by jwe]
jwe
parents: 572
diff changeset
2307
3292
ad0d250ebd7e [project @ 1999-10-14 22:52:28 by jwe]
jwe
parents: 3258
diff changeset
2308 tree_postfix_expression *e
ad0d250ebd7e [project @ 1999-10-14 22:52:28 by jwe]
jwe
parents: 3258
diff changeset
2309 = new tree_postfix_expression (op1, l, c, t);
ad0d250ebd7e [project @ 1999-10-14 22:52:28 by jwe]
jwe
parents: 3258
diff changeset
2310
ad0d250ebd7e [project @ 1999-10-14 22:52:28 by jwe]
jwe
parents: 3258
diff changeset
2311 return fold (e);
1623
fa7a847f9b92 [project @ 1995-11-06 18:05:09 by jwe]
jwe
parents: 1607
diff changeset
2312 }
fa7a847f9b92 [project @ 1995-11-06 18:05:09 by jwe]
jwe
parents: 1607
diff changeset
2313
fa7a847f9b92 [project @ 1995-11-06 18:05:09 by jwe]
jwe
parents: 1607
diff changeset
2314 // Build an unwind-protect command.
fa7a847f9b92 [project @ 1995-11-06 18:05:09 by jwe]
jwe
parents: 1607
diff changeset
2315
16134
ec9c6222ef5a move static parser helper functions to octave_parser class
John W. Eaton <jwe@octave.org>
parents: 16133
diff changeset
2316 tree_command *
16287
04a7953496a7 create base class for parser; use reference for curr_lexer
John W. Eaton <jwe@octave.org>
parents: 16285
diff changeset
2317 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
2318 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
2319 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
2320 token *end_tok,
04a7953496a7 create base class for parser; use reference for curr_lexer
John W. Eaton <jwe@octave.org>
parents: 16285
diff changeset
2321 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
2322 octave_comment_list *mc)
1623
fa7a847f9b92 [project @ 1995-11-06 18:05:09 by jwe]
jwe
parents: 1607
diff changeset
2323 {
fa7a847f9b92 [project @ 1995-11-06 18:05:09 by jwe]
jwe
parents: 1607
diff changeset
2324 tree_command *retval = 0;
fa7a847f9b92 [project @ 1995-11-06 18:05:09 by jwe]
jwe
parents: 1607
diff changeset
2325
2857
5448c8cba402 [project @ 1997-03-31 07:06:10 by jwe]
jwe
parents: 2856
diff changeset
2326 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
2327 {
17693
efbe746f8fa8 eliminate octave_comment_buffer singleton
John W. Eaton <jwe@octave.org>
parents: 17673
diff changeset
2328 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
2329
1623
fa7a847f9b92 [project @ 1995-11-06 18:05:09 by jwe]
jwe
parents: 1607
diff changeset
2330 int l = unwind_tok->line ();
fa7a847f9b92 [project @ 1995-11-06 18:05:09 by jwe]
jwe
parents: 1607
diff changeset
2331 int c = unwind_tok->column ();
fa7a847f9b92 [project @ 1995-11-06 18:05:09 by jwe]
jwe
parents: 1607
diff changeset
2332
16136
ed36d5543b27 don't declare octave_parser member functions static
John W. Eaton <jwe@octave.org>
parents: 16134
diff changeset
2333 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
2334 lc, mc, tc, l, c);
1623
fa7a847f9b92 [project @ 1995-11-06 18:05:09 by jwe]
jwe
parents: 1607
diff changeset
2335 }
17632
bd0a84de3375 further reduce memory leaks from parse errors (bug #40231)
John W. Eaton <jwe@octave.org>
parents: 17629
diff changeset
2336 else
bd0a84de3375 further reduce memory leaks from parse errors (bug #40231)
John W. Eaton <jwe@octave.org>
parents: 17629
diff changeset
2337 {
bd0a84de3375 further reduce memory leaks from parse errors (bug #40231)
John W. Eaton <jwe@octave.org>
parents: 17629
diff changeset
2338 delete body;
bd0a84de3375 further reduce memory leaks from parse errors (bug #40231)
John W. Eaton <jwe@octave.org>
parents: 17629
diff changeset
2339 delete cleanup_stmts;
bd0a84de3375 further reduce memory leaks from parse errors (bug #40231)
John W. Eaton <jwe@octave.org>
parents: 17629
diff changeset
2340 }
1623
fa7a847f9b92 [project @ 1995-11-06 18:05:09 by jwe]
jwe
parents: 1607
diff changeset
2341
fa7a847f9b92 [project @ 1995-11-06 18:05:09 by jwe]
jwe
parents: 1607
diff changeset
2342 return retval;
fa7a847f9b92 [project @ 1995-11-06 18:05:09 by jwe]
jwe
parents: 1607
diff changeset
2343 }
fa7a847f9b92 [project @ 1995-11-06 18:05:09 by jwe]
jwe
parents: 1607
diff changeset
2344
fa7a847f9b92 [project @ 1995-11-06 18:05:09 by jwe]
jwe
parents: 1607
diff changeset
2345 // Build a try-catch command.
fa7a847f9b92 [project @ 1995-11-06 18:05:09 by jwe]
jwe
parents: 1607
diff changeset
2346
16134
ec9c6222ef5a move static parser helper functions to octave_parser class
John W. Eaton <jwe@octave.org>
parents: 16133
diff changeset
2347 tree_command *
16287
04a7953496a7 create base class for parser; use reference for curr_lexer
John W. Eaton <jwe@octave.org>
parents: 16285
diff changeset
2348 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
2349 tree_statement_list *body,
17283
e6c0ac8ce5b6 eliminate parse conflicts introduced by changeset 923ce8b42db2
John W. Eaton <jwe@octave.org>
parents: 17281
diff changeset
2350 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
2351 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
2352 token *end_tok,
04a7953496a7 create base class for parser; use reference for curr_lexer
John W. Eaton <jwe@octave.org>
parents: 16285
diff changeset
2353 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
2354 octave_comment_list *mc)
1623
fa7a847f9b92 [project @ 1995-11-06 18:05:09 by jwe]
jwe
parents: 1607
diff changeset
2355 {
fa7a847f9b92 [project @ 1995-11-06 18:05:09 by jwe]
jwe
parents: 1607
diff changeset
2356 tree_command *retval = 0;
fa7a847f9b92 [project @ 1995-11-06 18:05:09 by jwe]
jwe
parents: 1607
diff changeset
2357
2857
5448c8cba402 [project @ 1997-03-31 07:06:10 by jwe]
jwe
parents: 2856
diff changeset
2358 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
2359 {
17693
efbe746f8fa8 eliminate octave_comment_buffer singleton
John W. Eaton <jwe@octave.org>
parents: 17673
diff changeset
2360 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
2361
1623
fa7a847f9b92 [project @ 1995-11-06 18:05:09 by jwe]
jwe
parents: 1607
diff changeset
2362 int l = try_tok->line ();
fa7a847f9b92 [project @ 1995-11-06 18:05:09 by jwe]
jwe
parents: 1607
diff changeset
2363 int c = try_tok->column ();
fa7a847f9b92 [project @ 1995-11-06 18:05:09 by jwe]
jwe
parents: 1607
diff changeset
2364
17283
e6c0ac8ce5b6 eliminate parse conflicts introduced by changeset 923ce8b42db2
John W. Eaton <jwe@octave.org>
parents: 17281
diff changeset
2365 tree_identifier *id = 0;
e6c0ac8ce5b6 eliminate parse conflicts introduced by changeset 923ce8b42db2
John W. Eaton <jwe@octave.org>
parents: 17281
diff changeset
2366
e6c0ac8ce5b6 eliminate parse conflicts introduced by changeset 923ce8b42db2
John W. Eaton <jwe@octave.org>
parents: 17281
diff changeset
2367 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
2368 {
e6c0ac8ce5b6 eliminate parse conflicts introduced by changeset 923ce8b42db2
John W. Eaton <jwe@octave.org>
parents: 17281
diff changeset
2369 tree_statement *stmt = cleanup_stmts->front ();
e6c0ac8ce5b6 eliminate parse conflicts introduced by changeset 923ce8b42db2
John W. Eaton <jwe@octave.org>
parents: 17281
diff changeset
2370
e6c0ac8ce5b6 eliminate parse conflicts introduced by changeset 923ce8b42db2
John W. Eaton <jwe@octave.org>
parents: 17281
diff changeset
2371 if (stmt)
e6c0ac8ce5b6 eliminate parse conflicts introduced by changeset 923ce8b42db2
John W. Eaton <jwe@octave.org>
parents: 17281
diff changeset
2372 {
e6c0ac8ce5b6 eliminate parse conflicts introduced by changeset 923ce8b42db2
John W. Eaton <jwe@octave.org>
parents: 17281
diff changeset
2373 tree_expression *expr = stmt->expression ();
e6c0ac8ce5b6 eliminate parse conflicts introduced by changeset 923ce8b42db2
John W. Eaton <jwe@octave.org>
parents: 17281
diff changeset
2374
e6c0ac8ce5b6 eliminate parse conflicts introduced by changeset 923ce8b42db2
John W. Eaton <jwe@octave.org>
parents: 17281
diff changeset
2375 if (expr && expr->is_identifier ())
e6c0ac8ce5b6 eliminate parse conflicts introduced by changeset 923ce8b42db2
John W. Eaton <jwe@octave.org>
parents: 17281
diff changeset
2376 {
e6c0ac8ce5b6 eliminate parse conflicts introduced by changeset 923ce8b42db2
John W. Eaton <jwe@octave.org>
parents: 17281
diff changeset
2377 id = dynamic_cast<tree_identifier *> (expr);
e6c0ac8ce5b6 eliminate parse conflicts introduced by changeset 923ce8b42db2
John W. Eaton <jwe@octave.org>
parents: 17281
diff changeset
2378
e6c0ac8ce5b6 eliminate parse conflicts introduced by changeset 923ce8b42db2
John W. Eaton <jwe@octave.org>
parents: 17281
diff changeset
2379 cleanup_stmts->pop_front ();
17673
9f6e4e5c2bac avoid memory leak in parser (bug #40231)
John W. Eaton <jwe@octave.org>
parents: 17658
diff changeset
2380
9f6e4e5c2bac avoid memory leak in parser (bug #40231)
John W. Eaton <jwe@octave.org>
parents: 17658
diff changeset
2381 stmt->set_expression (0);
9f6e4e5c2bac avoid memory leak in parser (bug #40231)
John W. Eaton <jwe@octave.org>
parents: 17658
diff changeset
2382 delete stmt;
17283
e6c0ac8ce5b6 eliminate parse conflicts introduced by changeset 923ce8b42db2
John W. Eaton <jwe@octave.org>
parents: 17281
diff changeset
2383 }
e6c0ac8ce5b6 eliminate parse conflicts introduced by changeset 923ce8b42db2
John W. Eaton <jwe@octave.org>
parents: 17281
diff changeset
2384 }
e6c0ac8ce5b6 eliminate parse conflicts introduced by changeset 923ce8b42db2
John W. Eaton <jwe@octave.org>
parents: 17281
diff changeset
2385 }
e6c0ac8ce5b6 eliminate parse conflicts introduced by changeset 923ce8b42db2
John W. Eaton <jwe@octave.org>
parents: 17281
diff changeset
2386
17249
923ce8b42db2 improve try-catch-statement to save exception to a variable (bug #33217)
Stefan Mahr <dac922@gmx.de>
parents: 17170
diff changeset
2387 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
2388 lc, mc, tc, l, c);
1623
fa7a847f9b92 [project @ 1995-11-06 18:05:09 by jwe]
jwe
parents: 1607
diff changeset
2389 }
17632
bd0a84de3375 further reduce memory leaks from parse errors (bug #40231)
John W. Eaton <jwe@octave.org>
parents: 17629
diff changeset
2390 else
bd0a84de3375 further reduce memory leaks from parse errors (bug #40231)
John W. Eaton <jwe@octave.org>
parents: 17629
diff changeset
2391 {
bd0a84de3375 further reduce memory leaks from parse errors (bug #40231)
John W. Eaton <jwe@octave.org>
parents: 17629
diff changeset
2392 delete body;
bd0a84de3375 further reduce memory leaks from parse errors (bug #40231)
John W. Eaton <jwe@octave.org>
parents: 17629
diff changeset
2393 delete cleanup_stmts;
bd0a84de3375 further reduce memory leaks from parse errors (bug #40231)
John W. Eaton <jwe@octave.org>
parents: 17629
diff changeset
2394 }
1623
fa7a847f9b92 [project @ 1995-11-06 18:05:09 by jwe]
jwe
parents: 1607
diff changeset
2395
fa7a847f9b92 [project @ 1995-11-06 18:05:09 by jwe]
jwe
parents: 1607
diff changeset
2396 return retval;
fa7a847f9b92 [project @ 1995-11-06 18:05:09 by jwe]
jwe
parents: 1607
diff changeset
2397 }
fa7a847f9b92 [project @ 1995-11-06 18:05:09 by jwe]
jwe
parents: 1607
diff changeset
2398
fa7a847f9b92 [project @ 1995-11-06 18:05:09 by jwe]
jwe
parents: 1607
diff changeset
2399 // Build a while command.
fa7a847f9b92 [project @ 1995-11-06 18:05:09 by jwe]
jwe
parents: 1607
diff changeset
2400
16134
ec9c6222ef5a move static parser helper functions to octave_parser class
John W. Eaton <jwe@octave.org>
parents: 16133
diff changeset
2401 tree_command *
16287
04a7953496a7 create base class for parser; use reference for curr_lexer
John W. Eaton <jwe@octave.org>
parents: 16285
diff changeset
2402 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
2403 tree_expression *expr,
04a7953496a7 create base class for parser; use reference for curr_lexer
John W. Eaton <jwe@octave.org>
parents: 16285
diff changeset
2404 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
2405 token *end_tok,
04a7953496a7 create base class for parser; use reference for curr_lexer
John W. Eaton <jwe@octave.org>
parents: 16285
diff changeset
2406 octave_comment_list *lc)
1623
fa7a847f9b92 [project @ 1995-11-06 18:05:09 by jwe]
jwe
parents: 1607
diff changeset
2407 {
fa7a847f9b92 [project @ 1995-11-06 18:05:09 by jwe]
jwe
parents: 1607
diff changeset
2408 tree_command *retval = 0;
fa7a847f9b92 [project @ 1995-11-06 18:05:09 by jwe]
jwe
parents: 1607
diff changeset
2409
fa7a847f9b92 [project @ 1995-11-06 18:05:09 by jwe]
jwe
parents: 1607
diff changeset
2410 maybe_warn_assign_as_truth_value (expr);
fa7a847f9b92 [project @ 1995-11-06 18:05:09 by jwe]
jwe
parents: 1607
diff changeset
2411
2857
5448c8cba402 [project @ 1997-03-31 07:06:10 by jwe]
jwe
parents: 2856
diff changeset
2412 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
2413 {
17693
efbe746f8fa8 eliminate octave_comment_buffer singleton
John W. Eaton <jwe@octave.org>
parents: 17673
diff changeset
2414 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
2415
16288
fe3b9a51e625 rename curr_lexer, curr_parser, CURR_LEXER
John W. Eaton <jwe@octave.org>
parents: 16287
diff changeset
2416 lexer.looping--;
1623
fa7a847f9b92 [project @ 1995-11-06 18:05:09 by jwe]
jwe
parents: 1607
diff changeset
2417
fa7a847f9b92 [project @ 1995-11-06 18:05:09 by jwe]
jwe
parents: 1607
diff changeset
2418 int l = while_tok->line ();
fa7a847f9b92 [project @ 1995-11-06 18:05:09 by jwe]
jwe
parents: 1607
diff changeset
2419 int c = while_tok->column ();
fa7a847f9b92 [project @ 1995-11-06 18:05:09 by jwe]
jwe
parents: 1607
diff changeset
2420
3665
0689afb1d001 [project @ 2000-05-11 19:07:56 by jwe]
jwe
parents: 3544
diff changeset
2421 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
2422 }
17632
bd0a84de3375 further reduce memory leaks from parse errors (bug #40231)
John W. Eaton <jwe@octave.org>
parents: 17629
diff changeset
2423 else
bd0a84de3375 further reduce memory leaks from parse errors (bug #40231)
John W. Eaton <jwe@octave.org>
parents: 17629
diff changeset
2424 {
bd0a84de3375 further reduce memory leaks from parse errors (bug #40231)
John W. Eaton <jwe@octave.org>
parents: 17629
diff changeset
2425 delete expr;
bd0a84de3375 further reduce memory leaks from parse errors (bug #40231)
John W. Eaton <jwe@octave.org>
parents: 17629
diff changeset
2426 delete body;
bd0a84de3375 further reduce memory leaks from parse errors (bug #40231)
John W. Eaton <jwe@octave.org>
parents: 17629
diff changeset
2427 }
1623
fa7a847f9b92 [project @ 1995-11-06 18:05:09 by jwe]
jwe
parents: 1607
diff changeset
2428
fa7a847f9b92 [project @ 1995-11-06 18:05:09 by jwe]
jwe
parents: 1607
diff changeset
2429 return retval;
fa7a847f9b92 [project @ 1995-11-06 18:05:09 by jwe]
jwe
parents: 1607
diff changeset
2430 }
fa7a847f9b92 [project @ 1995-11-06 18:05:09 by jwe]
jwe
parents: 1607
diff changeset
2431
3484
8b1f46ac2b64 [project @ 2000-01-27 23:30:45 by jwe]
jwe
parents: 3446
diff changeset
2432 // Build a do-until command.
8b1f46ac2b64 [project @ 2000-01-27 23:30:45 by jwe]
jwe
parents: 3446
diff changeset
2433
16134
ec9c6222ef5a move static parser helper functions to octave_parser class
John W. Eaton <jwe@octave.org>
parents: 16133
diff changeset
2434 tree_command *
16287
04a7953496a7 create base class for parser; use reference for curr_lexer
John W. Eaton <jwe@octave.org>
parents: 16285
diff changeset
2435 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
2436 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
2437 tree_expression *expr,
04a7953496a7 create base class for parser; use reference for curr_lexer
John W. Eaton <jwe@octave.org>
parents: 16285
diff changeset
2438 octave_comment_list *lc)
3484
8b1f46ac2b64 [project @ 2000-01-27 23:30:45 by jwe]
jwe
parents: 3446
diff changeset
2439 {
8b1f46ac2b64 [project @ 2000-01-27 23:30:45 by jwe]
jwe
parents: 3446
diff changeset
2440 maybe_warn_assign_as_truth_value (expr);
8b1f46ac2b64 [project @ 2000-01-27 23:30:45 by jwe]
jwe
parents: 3446
diff changeset
2441
17693
efbe746f8fa8 eliminate octave_comment_buffer singleton
John W. Eaton <jwe@octave.org>
parents: 17673
diff changeset
2442 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
2443
16288
fe3b9a51e625 rename curr_lexer, curr_parser, CURR_LEXER
John W. Eaton <jwe@octave.org>
parents: 16287
diff changeset
2444 lexer.looping--;
3484
8b1f46ac2b64 [project @ 2000-01-27 23:30:45 by jwe]
jwe
parents: 3446
diff changeset
2445
8658
73c4516fae10 New evaluator and debugger derived from tree-walker class
John W. Eaton <jwe@octave.org>
parents: 8471
diff changeset
2446 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
2447 int c = until_tok->column ();
3484
8b1f46ac2b64 [project @ 2000-01-27 23:30:45 by jwe]
jwe
parents: 3446
diff changeset
2448
17632
bd0a84de3375 further reduce memory leaks from parse errors (bug #40231)
John W. Eaton <jwe@octave.org>
parents: 17629
diff changeset
2449 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
2450 }
8b1f46ac2b64 [project @ 2000-01-27 23:30:45 by jwe]
jwe
parents: 3446
diff changeset
2451
1623
fa7a847f9b92 [project @ 1995-11-06 18:05:09 by jwe]
jwe
parents: 1607
diff changeset
2452 // Build a for command.
fa7a847f9b92 [project @ 1995-11-06 18:05:09 by jwe]
jwe
parents: 1607
diff changeset
2453
16134
ec9c6222ef5a move static parser helper functions to octave_parser class
John W. Eaton <jwe@octave.org>
parents: 16133
diff changeset
2454 tree_command *
16287
04a7953496a7 create base class for parser; use reference for curr_lexer
John W. Eaton <jwe@octave.org>
parents: 16285
diff changeset
2455 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
2456 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
2457 tree_expression *expr,
04a7953496a7 create base class for parser; use reference for curr_lexer
John W. Eaton <jwe@octave.org>
parents: 16285
diff changeset
2458 tree_expression *maxproc,
04a7953496a7 create base class for parser; use reference for curr_lexer
John W. Eaton <jwe@octave.org>
parents: 16285
diff changeset
2459 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
2460 token *end_tok,
04a7953496a7 create base class for parser; use reference for curr_lexer
John W. Eaton <jwe@octave.org>
parents: 16285
diff changeset
2461 octave_comment_list *lc)
1623
fa7a847f9b92 [project @ 1995-11-06 18:05:09 by jwe]
jwe
parents: 1607
diff changeset
2462 {
fa7a847f9b92 [project @ 1995-11-06 18:05:09 by jwe]
jwe
parents: 1607
diff changeset
2463 tree_command *retval = 0;
fa7a847f9b92 [project @ 1995-11-06 18:05:09 by jwe]
jwe
parents: 1607
diff changeset
2464
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
2465 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
2466
027a2186cd90 parfor keyword and infrastructure, but handle parfor as normal for loop for now
John W. Eaton <jwe@octave.org>
parents: 13241
diff changeset
2467 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
2468 {
17693
efbe746f8fa8 eliminate octave_comment_buffer singleton
John W. Eaton <jwe@octave.org>
parents: 17673
diff changeset
2469 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
2470
16288
fe3b9a51e625 rename curr_lexer, curr_parser, CURR_LEXER
John W. Eaton <jwe@octave.org>
parents: 16287
diff changeset
2471 lexer.looping--;
1623
fa7a847f9b92 [project @ 1995-11-06 18:05:09 by jwe]
jwe
parents: 1607
diff changeset
2472
fa7a847f9b92 [project @ 1995-11-06 18:05:09 by jwe]
jwe
parents: 1607
diff changeset
2473 int l = for_tok->line ();
fa7a847f9b92 [project @ 1995-11-06 18:05:09 by jwe]
jwe
parents: 1607
diff changeset
2474 int c = for_tok->column ();
fa7a847f9b92 [project @ 1995-11-06 18:05:09 by jwe]
jwe
parents: 1607
diff changeset
2475
2970
b9e64477f703 [project @ 1997-05-15 18:04:21 by jwe]
jwe
parents: 2961
diff changeset
2476 if (lhs->length () == 1)
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
2477 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
2478 tree_expression *tmp = lhs->remove_front ();
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
2479
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
2480 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
2481 body, lc, tc, l, c);
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
2482
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
2483 delete lhs;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
2484 }
2970
b9e64477f703 [project @ 1997-05-15 18:04:21 by jwe]
jwe
parents: 2961
diff changeset
2485 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
2486 {
027a2186cd90 parfor keyword and infrastructure, but handle parfor as normal for loop for now
John W. Eaton <jwe@octave.org>
parents: 13241
diff changeset
2487 if (parfor)
16142
26d65d677557 rename yyerror to bison_error and make it a member of octave_parser class
John W. Eaton <jwe@octave.org>
parents: 16139
diff changeset
2488 bison_error ("invalid syntax for parfor statement");
13245
027a2186cd90 parfor keyword and infrastructure, but handle parfor as normal for loop for now
John W. Eaton <jwe@octave.org>
parents: 13241
diff changeset
2489 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
2490 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
2491 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
2492 }
1623
fa7a847f9b92 [project @ 1995-11-06 18:05:09 by jwe]
jwe
parents: 1607
diff changeset
2493 }
17632
bd0a84de3375 further reduce memory leaks from parse errors (bug #40231)
John W. Eaton <jwe@octave.org>
parents: 17629
diff changeset
2494 else
bd0a84de3375 further reduce memory leaks from parse errors (bug #40231)
John W. Eaton <jwe@octave.org>
parents: 17629
diff changeset
2495 {
bd0a84de3375 further reduce memory leaks from parse errors (bug #40231)
John W. Eaton <jwe@octave.org>
parents: 17629
diff changeset
2496 delete lhs;
bd0a84de3375 further reduce memory leaks from parse errors (bug #40231)
John W. Eaton <jwe@octave.org>
parents: 17629
diff changeset
2497 delete expr;
bd0a84de3375 further reduce memory leaks from parse errors (bug #40231)
John W. Eaton <jwe@octave.org>
parents: 17629
diff changeset
2498 delete maxproc;
bd0a84de3375 further reduce memory leaks from parse errors (bug #40231)
John W. Eaton <jwe@octave.org>
parents: 17629
diff changeset
2499 delete body;
bd0a84de3375 further reduce memory leaks from parse errors (bug #40231)
John W. Eaton <jwe@octave.org>
parents: 17629
diff changeset
2500 }
1623
fa7a847f9b92 [project @ 1995-11-06 18:05:09 by jwe]
jwe
parents: 1607
diff changeset
2501
fa7a847f9b92 [project @ 1995-11-06 18:05:09 by jwe]
jwe
parents: 1607
diff changeset
2502 return retval;
fa7a847f9b92 [project @ 1995-11-06 18:05:09 by jwe]
jwe
parents: 1607
diff changeset
2503 }
fa7a847f9b92 [project @ 1995-11-06 18:05:09 by jwe]
jwe
parents: 1607
diff changeset
2504
4207
fa3482b34599 [project @ 2002-12-03 18:22:05 by jwe]
jwe
parents: 4186
diff changeset
2505 // Build a break command.
fa3482b34599 [project @ 2002-12-03 18:22:05 by jwe]
jwe
parents: 4186
diff changeset
2506
16134
ec9c6222ef5a move static parser helper functions to octave_parser class
John W. Eaton <jwe@octave.org>
parents: 16133
diff changeset
2507 tree_command *
16287
04a7953496a7 create base class for parser; use reference for curr_lexer
John W. Eaton <jwe@octave.org>
parents: 16285
diff changeset
2508 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
2509 {
2620
5c773d4745d6 [project @ 1997-01-23 16:26:25 by jwe]
jwe
parents: 2542
diff changeset
2510 int l = break_tok->line ();
5c773d4745d6 [project @ 1997-01-23 16:26:25 by jwe]
jwe
parents: 2542
diff changeset
2511 int c = break_tok->column ();
5c773d4745d6 [project @ 1997-01-23 16:26:25 by jwe]
jwe
parents: 2542
diff changeset
2512
17632
bd0a84de3375 further reduce memory leaks from parse errors (bug #40231)
John W. Eaton <jwe@octave.org>
parents: 17629
diff changeset
2513 return new tree_break_command (l, c);
1623
fa7a847f9b92 [project @ 1995-11-06 18:05:09 by jwe]
jwe
parents: 1607
diff changeset
2514 }
fa7a847f9b92 [project @ 1995-11-06 18:05:09 by jwe]
jwe
parents: 1607
diff changeset
2515
4207
fa3482b34599 [project @ 2002-12-03 18:22:05 by jwe]
jwe
parents: 4186
diff changeset
2516 // Build a continue command.
fa3482b34599 [project @ 2002-12-03 18:22:05 by jwe]
jwe
parents: 4186
diff changeset
2517
16134
ec9c6222ef5a move static parser helper functions to octave_parser class
John W. Eaton <jwe@octave.org>
parents: 16133
diff changeset
2518 tree_command *
16287
04a7953496a7 create base class for parser; use reference for curr_lexer
John W. Eaton <jwe@octave.org>
parents: 16285
diff changeset
2519 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
2520 {
2620
5c773d4745d6 [project @ 1997-01-23 16:26:25 by jwe]
jwe
parents: 2542
diff changeset
2521 int l = continue_tok->line ();
5c773d4745d6 [project @ 1997-01-23 16:26:25 by jwe]
jwe
parents: 2542
diff changeset
2522 int c = continue_tok->column ();
5c773d4745d6 [project @ 1997-01-23 16:26:25 by jwe]
jwe
parents: 2542
diff changeset
2523
17632
bd0a84de3375 further reduce memory leaks from parse errors (bug #40231)
John W. Eaton <jwe@octave.org>
parents: 17629
diff changeset
2524 return new tree_continue_command (l, c);
1623
fa7a847f9b92 [project @ 1995-11-06 18:05:09 by jwe]
jwe
parents: 1607
diff changeset
2525 }
fa7a847f9b92 [project @ 1995-11-06 18:05:09 by jwe]
jwe
parents: 1607
diff changeset
2526
4207
fa3482b34599 [project @ 2002-12-03 18:22:05 by jwe]
jwe
parents: 4186
diff changeset
2527 // Build a return command.
fa3482b34599 [project @ 2002-12-03 18:22:05 by jwe]
jwe
parents: 4186
diff changeset
2528
16134
ec9c6222ef5a move static parser helper functions to octave_parser class
John W. Eaton <jwe@octave.org>
parents: 16133
diff changeset
2529 tree_command *
16287
04a7953496a7 create base class for parser; use reference for curr_lexer
John W. Eaton <jwe@octave.org>
parents: 16285
diff changeset
2530 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
2531 {
2620
5c773d4745d6 [project @ 1997-01-23 16:26:25 by jwe]
jwe
parents: 2542
diff changeset
2532 int l = return_tok->line ();
5c773d4745d6 [project @ 1997-01-23 16:26:25 by jwe]
jwe
parents: 2542
diff changeset
2533 int c = return_tok->column ();
5c773d4745d6 [project @ 1997-01-23 16:26:25 by jwe]
jwe
parents: 2542
diff changeset
2534
17632
bd0a84de3375 further reduce memory leaks from parse errors (bug #40231)
John W. Eaton <jwe@octave.org>
parents: 17629
diff changeset
2535 return new tree_return_command (l, c);
1623
fa7a847f9b92 [project @ 1995-11-06 18:05:09 by jwe]
jwe
parents: 1607
diff changeset
2536 }
fa7a847f9b92 [project @ 1995-11-06 18:05:09 by jwe]
jwe
parents: 1607
diff changeset
2537
fa7a847f9b92 [project @ 1995-11-06 18:05:09 by jwe]
jwe
parents: 1607
diff changeset
2538 // Start an if command.
fa7a847f9b92 [project @ 1995-11-06 18:05:09 by jwe]
jwe
parents: 1607
diff changeset
2539
16134
ec9c6222ef5a move static parser helper functions to octave_parser class
John W. Eaton <jwe@octave.org>
parents: 16133
diff changeset
2540 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
2541 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
2542 tree_statement_list *list)
1623
fa7a847f9b92 [project @ 1995-11-06 18:05:09 by jwe]
jwe
parents: 1607
diff changeset
2543 {
fa7a847f9b92 [project @ 1995-11-06 18:05:09 by jwe]
jwe
parents: 1607
diff changeset
2544 maybe_warn_assign_as_truth_value (expr);
fa7a847f9b92 [project @ 1995-11-06 18:05:09 by jwe]
jwe
parents: 1607
diff changeset
2545
fa7a847f9b92 [project @ 1995-11-06 18:05:09 by jwe]
jwe
parents: 1607
diff changeset
2546 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
2547
fa7a847f9b92 [project @ 1995-11-06 18:05:09 by jwe]
jwe
parents: 1607
diff changeset
2548 return new tree_if_command_list (t);
fa7a847f9b92 [project @ 1995-11-06 18:05:09 by jwe]
jwe
parents: 1607
diff changeset
2549 }
fa7a847f9b92 [project @ 1995-11-06 18:05:09 by jwe]
jwe
parents: 1607
diff changeset
2550
fa7a847f9b92 [project @ 1995-11-06 18:05:09 by jwe]
jwe
parents: 1607
diff changeset
2551 // Finish an if command.
fa7a847f9b92 [project @ 1995-11-06 18:05:09 by jwe]
jwe
parents: 1607
diff changeset
2552
16134
ec9c6222ef5a move static parser helper functions to octave_parser class
John W. Eaton <jwe@octave.org>
parents: 16133
diff changeset
2553 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
2554 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
2555 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
2556 token *end_tok,
04a7953496a7 create base class for parser; use reference for curr_lexer
John W. Eaton <jwe@octave.org>
parents: 16285
diff changeset
2557 octave_comment_list *lc)
1623
fa7a847f9b92 [project @ 1995-11-06 18:05:09 by jwe]
jwe
parents: 1607
diff changeset
2558 {
fa7a847f9b92 [project @ 1995-11-06 18:05:09 by jwe]
jwe
parents: 1607
diff changeset
2559 tree_if_command *retval = 0;
fa7a847f9b92 [project @ 1995-11-06 18:05:09 by jwe]
jwe
parents: 1607
diff changeset
2560
2857
5448c8cba402 [project @ 1997-03-31 07:06:10 by jwe]
jwe
parents: 2856
diff changeset
2561 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
2562 {
17693
efbe746f8fa8 eliminate octave_comment_buffer singleton
John W. Eaton <jwe@octave.org>
parents: 17673
diff changeset
2563 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
2564
1623
fa7a847f9b92 [project @ 1995-11-06 18:05:09 by jwe]
jwe
parents: 1607
diff changeset
2565 int l = if_tok->line ();
fa7a847f9b92 [project @ 1995-11-06 18:05:09 by jwe]
jwe
parents: 1607
diff changeset
2566 int c = if_tok->column ();
fa7a847f9b92 [project @ 1995-11-06 18:05:09 by jwe]
jwe
parents: 1607
diff changeset
2567
8842
be7b30a24938 line/column info for switch and if statements
John W. Eaton <jwe@octave.org>
parents: 8828
diff changeset
2568 if (list && ! list->empty ())
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
2569 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
2570 tree_if_clause *elt = list->front ();
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
2571
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
2572 if (elt)
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
2573 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
2574 elt->line (l);
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
2575 elt->column (c);
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
2576 }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
2577 }
8842
be7b30a24938 line/column info for switch and if statements
John W. Eaton <jwe@octave.org>
parents: 8828
diff changeset
2578
3665
0689afb1d001 [project @ 2000-05-11 19:07:56 by jwe]
jwe
parents: 3544
diff changeset
2579 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
2580 }
17632
bd0a84de3375 further reduce memory leaks from parse errors (bug #40231)
John W. Eaton <jwe@octave.org>
parents: 17629
diff changeset
2581 else
bd0a84de3375 further reduce memory leaks from parse errors (bug #40231)
John W. Eaton <jwe@octave.org>
parents: 17629
diff changeset
2582 delete list;
1623
fa7a847f9b92 [project @ 1995-11-06 18:05:09 by jwe]
jwe
parents: 1607
diff changeset
2583
fa7a847f9b92 [project @ 1995-11-06 18:05:09 by jwe]
jwe
parents: 1607
diff changeset
2584 return retval;
fa7a847f9b92 [project @ 1995-11-06 18:05:09 by jwe]
jwe
parents: 1607
diff changeset
2585 }
fa7a847f9b92 [project @ 1995-11-06 18:05:09 by jwe]
jwe
parents: 1607
diff changeset
2586
fa7a847f9b92 [project @ 1995-11-06 18:05:09 by jwe]
jwe
parents: 1607
diff changeset
2587 // Build an elseif clause.
fa7a847f9b92 [project @ 1995-11-06 18:05:09 by jwe]
jwe
parents: 1607
diff changeset
2588
16134
ec9c6222ef5a move static parser helper functions to octave_parser class
John W. Eaton <jwe@octave.org>
parents: 16133
diff changeset
2589 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
2590 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
2591 tree_expression *expr,
04a7953496a7 create base class for parser; use reference for curr_lexer
John W. Eaton <jwe@octave.org>
parents: 16285
diff changeset
2592 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
2593 octave_comment_list *lc)
1623
fa7a847f9b92 [project @ 1995-11-06 18:05:09 by jwe]
jwe
parents: 1607
diff changeset
2594 {
fa7a847f9b92 [project @ 1995-11-06 18:05:09 by jwe]
jwe
parents: 1607
diff changeset
2595 maybe_warn_assign_as_truth_value (expr);
fa7a847f9b92 [project @ 1995-11-06 18:05:09 by jwe]
jwe
parents: 1607
diff changeset
2596
8658
73c4516fae10 New evaluator and debugger derived from tree-walker class
John W. Eaton <jwe@octave.org>
parents: 8471
diff changeset
2597 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
2598 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
2599
73c4516fae10 New evaluator and debugger derived from tree-walker class
John W. Eaton <jwe@octave.org>
parents: 8471
diff changeset
2600 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
2601 }
fa7a847f9b92 [project @ 1995-11-06 18:05:09 by jwe]
jwe
parents: 1607
diff changeset
2602
2764
2c0f259cf83d [project @ 1997-03-01 02:30:26 by jwe]
jwe
parents: 2745
diff changeset
2603 // Finish a switch command.
2c0f259cf83d [project @ 1997-03-01 02:30:26 by jwe]
jwe
parents: 2745
diff changeset
2604
16134
ec9c6222ef5a move static parser helper functions to octave_parser class
John W. Eaton <jwe@octave.org>
parents: 16133
diff changeset
2605 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
2606 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
2607 tree_expression *expr,
04a7953496a7 create base class for parser; use reference for curr_lexer
John W. Eaton <jwe@octave.org>
parents: 16285
diff changeset
2608 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
2609 token *end_tok,
04a7953496a7 create base class for parser; use reference for curr_lexer
John W. Eaton <jwe@octave.org>
parents: 16285
diff changeset
2610 octave_comment_list *lc)
2764
2c0f259cf83d [project @ 1997-03-01 02:30:26 by jwe]
jwe
parents: 2745
diff changeset
2611 {
2c0f259cf83d [project @ 1997-03-01 02:30:26 by jwe]
jwe
parents: 2745
diff changeset
2612 tree_switch_command *retval = 0;
2c0f259cf83d [project @ 1997-03-01 02:30:26 by jwe]
jwe
parents: 2745
diff changeset
2613
2857
5448c8cba402 [project @ 1997-03-31 07:06:10 by jwe]
jwe
parents: 2856
diff changeset
2614 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
2615 {
17693
efbe746f8fa8 eliminate octave_comment_buffer singleton
John W. Eaton <jwe@octave.org>
parents: 17673
diff changeset
2616 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
2617
2764
2c0f259cf83d [project @ 1997-03-01 02:30:26 by jwe]
jwe
parents: 2745
diff changeset
2618 int l = switch_tok->line ();
2c0f259cf83d [project @ 1997-03-01 02:30:26 by jwe]
jwe
parents: 2745
diff changeset
2619 int c = switch_tok->column ();
2c0f259cf83d [project @ 1997-03-01 02:30:26 by jwe]
jwe
parents: 2745
diff changeset
2620
8842
be7b30a24938 line/column info for switch and if statements
John W. Eaton <jwe@octave.org>
parents: 8828
diff changeset
2621 if (list && ! list->empty ())
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
2622 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
2623 tree_switch_case *elt = list->front ();
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
2624
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
2625 if (elt)
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
2626 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
2627 elt->line (l);
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
2628 elt->column (c);
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
2629 }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
2630 }
8842
be7b30a24938 line/column info for switch and if statements
John W. Eaton <jwe@octave.org>
parents: 8828
diff changeset
2631
3665
0689afb1d001 [project @ 2000-05-11 19:07:56 by jwe]
jwe
parents: 3544
diff changeset
2632 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
2633 }
17632
bd0a84de3375 further reduce memory leaks from parse errors (bug #40231)
John W. Eaton <jwe@octave.org>
parents: 17629
diff changeset
2634 else
bd0a84de3375 further reduce memory leaks from parse errors (bug #40231)
John W. Eaton <jwe@octave.org>
parents: 17629
diff changeset
2635 {
bd0a84de3375 further reduce memory leaks from parse errors (bug #40231)
John W. Eaton <jwe@octave.org>
parents: 17629
diff changeset
2636 delete expr;
bd0a84de3375 further reduce memory leaks from parse errors (bug #40231)
John W. Eaton <jwe@octave.org>
parents: 17629
diff changeset
2637 delete list;
bd0a84de3375 further reduce memory leaks from parse errors (bug #40231)
John W. Eaton <jwe@octave.org>
parents: 17629
diff changeset
2638 }
2764
2c0f259cf83d [project @ 1997-03-01 02:30:26 by jwe]
jwe
parents: 2745
diff changeset
2639
2c0f259cf83d [project @ 1997-03-01 02:30:26 by jwe]
jwe
parents: 2745
diff changeset
2640 return retval;
2c0f259cf83d [project @ 1997-03-01 02:30:26 by jwe]
jwe
parents: 2745
diff changeset
2641 }
2c0f259cf83d [project @ 1997-03-01 02:30:26 by jwe]
jwe
parents: 2745
diff changeset
2642
2c0f259cf83d [project @ 1997-03-01 02:30:26 by jwe]
jwe
parents: 2745
diff changeset
2643 // Build a switch case.
2c0f259cf83d [project @ 1997-03-01 02:30:26 by jwe]
jwe
parents: 2745
diff changeset
2644
16134
ec9c6222ef5a move static parser helper functions to octave_parser class
John W. Eaton <jwe@octave.org>
parents: 16133
diff changeset
2645 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
2646 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
2647 tree_expression *expr,
04a7953496a7 create base class for parser; use reference for curr_lexer
John W. Eaton <jwe@octave.org>
parents: 16285
diff changeset
2648 tree_statement_list *list,
04a7953496a7 create base class for parser; use reference for curr_lexer
John W. Eaton <jwe@octave.org>
parents: 16285
diff changeset
2649 octave_comment_list *lc)
2764
2c0f259cf83d [project @ 1997-03-01 02:30:26 by jwe]
jwe
parents: 2745
diff changeset
2650 {
2c0f259cf83d [project @ 1997-03-01 02:30:26 by jwe]
jwe
parents: 2745
diff changeset
2651 maybe_warn_variable_switch_label (expr);
2c0f259cf83d [project @ 1997-03-01 02:30:26 by jwe]
jwe
parents: 2745
diff changeset
2652
8658
73c4516fae10 New evaluator and debugger derived from tree-walker class
John W. Eaton <jwe@octave.org>
parents: 8471
diff changeset
2653 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
2654 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
2655
73c4516fae10 New evaluator and debugger derived from tree-walker class
John W. Eaton <jwe@octave.org>
parents: 8471
diff changeset
2656 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
2657 }
2c0f259cf83d [project @ 1997-03-01 02:30:26 by jwe]
jwe
parents: 2745
diff changeset
2658
1623
fa7a847f9b92 [project @ 1995-11-06 18:05:09 by jwe]
jwe
parents: 1607
diff changeset
2659 // Build an assignment to a variable.
fa7a847f9b92 [project @ 1995-11-06 18:05:09 by jwe]
jwe
parents: 1607
diff changeset
2660
16134
ec9c6222ef5a move static parser helper functions to octave_parser class
John W. Eaton <jwe@octave.org>
parents: 16133
diff changeset
2661 tree_expression *
16287
04a7953496a7 create base class for parser; use reference for curr_lexer
John W. Eaton <jwe@octave.org>
parents: 16285
diff changeset
2662 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
2663 token *eq_tok, tree_expression *rhs)
1623
fa7a847f9b92 [project @ 1995-11-06 18:05:09 by jwe]
jwe
parents: 1607
diff changeset
2664 {
2970
b9e64477f703 [project @ 1997-05-15 18:04:21 by jwe]
jwe
parents: 2961
diff changeset
2665 tree_expression *retval = 0;
b9e64477f703 [project @ 1997-05-15 18:04:21 by jwe]
jwe
parents: 2961
diff changeset
2666
2883
0b3954110c77 [project @ 1997-04-24 09:57:05 by jwe]
jwe
parents: 2865
diff changeset
2667 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
2668
0b3954110c77 [project @ 1997-04-24 09:57:05 by jwe]
jwe
parents: 2865
diff changeset
2669 switch (op)
0b3954110c77 [project @ 1997-04-24 09:57:05 by jwe]
jwe
parents: 2865
diff changeset
2670 {
0b3954110c77 [project @ 1997-04-24 09:57:05 by jwe]
jwe
parents: 2865
diff changeset
2671 case '=':
3525
6cfa474c5b99 [project @ 2000-02-02 10:48:41 by jwe]
jwe
parents: 3523
diff changeset
2672 t = octave_value::op_asn_eq;
2883
0b3954110c77 [project @ 1997-04-24 09:57:05 by jwe]
jwe
parents: 2865
diff changeset
2673 break;
0b3954110c77 [project @ 1997-04-24 09:57:05 by jwe]
jwe
parents: 2865
diff changeset
2674
0b3954110c77 [project @ 1997-04-24 09:57:05 by jwe]
jwe
parents: 2865
diff changeset
2675 case ADD_EQ:
3525
6cfa474c5b99 [project @ 2000-02-02 10:48:41 by jwe]
jwe
parents: 3523
diff changeset
2676 t = octave_value::op_add_eq;
2883
0b3954110c77 [project @ 1997-04-24 09:57:05 by jwe]
jwe
parents: 2865
diff changeset
2677 break;
0b3954110c77 [project @ 1997-04-24 09:57:05 by jwe]
jwe
parents: 2865
diff changeset
2678
0b3954110c77 [project @ 1997-04-24 09:57:05 by jwe]
jwe
parents: 2865
diff changeset
2679 case SUB_EQ:
3525
6cfa474c5b99 [project @ 2000-02-02 10:48:41 by jwe]
jwe
parents: 3523
diff changeset
2680 t = octave_value::op_sub_eq;
2883
0b3954110c77 [project @ 1997-04-24 09:57:05 by jwe]
jwe
parents: 2865
diff changeset
2681 break;
0b3954110c77 [project @ 1997-04-24 09:57:05 by jwe]
jwe
parents: 2865
diff changeset
2682
0b3954110c77 [project @ 1997-04-24 09:57:05 by jwe]
jwe
parents: 2865
diff changeset
2683 case MUL_EQ:
3525
6cfa474c5b99 [project @ 2000-02-02 10:48:41 by jwe]
jwe
parents: 3523
diff changeset
2684 t = octave_value::op_mul_eq;
2883
0b3954110c77 [project @ 1997-04-24 09:57:05 by jwe]
jwe
parents: 2865
diff changeset
2685 break;
0b3954110c77 [project @ 1997-04-24 09:57:05 by jwe]
jwe
parents: 2865
diff changeset
2686
0b3954110c77 [project @ 1997-04-24 09:57:05 by jwe]
jwe
parents: 2865
diff changeset
2687 case DIV_EQ:
3525
6cfa474c5b99 [project @ 2000-02-02 10:48:41 by jwe]
jwe
parents: 3523
diff changeset
2688 t = octave_value::op_div_eq;
2883
0b3954110c77 [project @ 1997-04-24 09:57:05 by jwe]
jwe
parents: 2865
diff changeset
2689 break;
0b3954110c77 [project @ 1997-04-24 09:57:05 by jwe]
jwe
parents: 2865
diff changeset
2690
3204
81738e630f57 [project @ 1998-10-30 23:28:29 by jwe]
jwe
parents: 3203
diff changeset
2691 case LEFTDIV_EQ:
3525
6cfa474c5b99 [project @ 2000-02-02 10:48:41 by jwe]
jwe
parents: 3523
diff changeset
2692 t = octave_value::op_ldiv_eq;
3204
81738e630f57 [project @ 1998-10-30 23:28:29 by jwe]
jwe
parents: 3203
diff changeset
2693 break;
81738e630f57 [project @ 1998-10-30 23:28:29 by jwe]
jwe
parents: 3203
diff changeset
2694
4018
a8621d87fbf5 [project @ 2002-08-05 03:17:25 by jwe]
jwe
parents: 4009
diff changeset
2695 case POW_EQ:
a8621d87fbf5 [project @ 2002-08-05 03:17:25 by jwe]
jwe
parents: 4009
diff changeset
2696 t = octave_value::op_pow_eq;
a8621d87fbf5 [project @ 2002-08-05 03:17:25 by jwe]
jwe
parents: 4009
diff changeset
2697 break;
a8621d87fbf5 [project @ 2002-08-05 03:17:25 by jwe]
jwe
parents: 4009
diff changeset
2698
2899
0d79a8c11a2b [project @ 1997-04-30 03:09:23 by jwe]
jwe
parents: 2891
diff changeset
2699 case LSHIFT_EQ:
3525
6cfa474c5b99 [project @ 2000-02-02 10:48:41 by jwe]
jwe
parents: 3523
diff changeset
2700 t = octave_value::op_lshift_eq;
2899
0d79a8c11a2b [project @ 1997-04-30 03:09:23 by jwe]
jwe
parents: 2891
diff changeset
2701 break;
0d79a8c11a2b [project @ 1997-04-30 03:09:23 by jwe]
jwe
parents: 2891
diff changeset
2702
0d79a8c11a2b [project @ 1997-04-30 03:09:23 by jwe]
jwe
parents: 2891
diff changeset
2703 case RSHIFT_EQ:
3525
6cfa474c5b99 [project @ 2000-02-02 10:48:41 by jwe]
jwe
parents: 3523
diff changeset
2704 t = octave_value::op_rshift_eq;
2899
0d79a8c11a2b [project @ 1997-04-30 03:09:23 by jwe]
jwe
parents: 2891
diff changeset
2705 break;
0d79a8c11a2b [project @ 1997-04-30 03:09:23 by jwe]
jwe
parents: 2891
diff changeset
2706
2883
0b3954110c77 [project @ 1997-04-24 09:57:05 by jwe]
jwe
parents: 2865
diff changeset
2707 case EMUL_EQ:
3525
6cfa474c5b99 [project @ 2000-02-02 10:48:41 by jwe]
jwe
parents: 3523
diff changeset
2708 t = octave_value::op_el_mul_eq;
2883
0b3954110c77 [project @ 1997-04-24 09:57:05 by jwe]
jwe
parents: 2865
diff changeset
2709 break;
0b3954110c77 [project @ 1997-04-24 09:57:05 by jwe]
jwe
parents: 2865
diff changeset
2710
0b3954110c77 [project @ 1997-04-24 09:57:05 by jwe]
jwe
parents: 2865
diff changeset
2711 case EDIV_EQ:
3525
6cfa474c5b99 [project @ 2000-02-02 10:48:41 by jwe]
jwe
parents: 3523
diff changeset
2712 t = octave_value::op_el_div_eq;
2883
0b3954110c77 [project @ 1997-04-24 09:57:05 by jwe]
jwe
parents: 2865
diff changeset
2713 break;
0b3954110c77 [project @ 1997-04-24 09:57:05 by jwe]
jwe
parents: 2865
diff changeset
2714
3204
81738e630f57 [project @ 1998-10-30 23:28:29 by jwe]
jwe
parents: 3203
diff changeset
2715 case ELEFTDIV_EQ:
3525
6cfa474c5b99 [project @ 2000-02-02 10:48:41 by jwe]
jwe
parents: 3523
diff changeset
2716 t = octave_value::op_el_ldiv_eq;
3204
81738e630f57 [project @ 1998-10-30 23:28:29 by jwe]
jwe
parents: 3203
diff changeset
2717 break;
81738e630f57 [project @ 1998-10-30 23:28:29 by jwe]
jwe
parents: 3203
diff changeset
2718
4018
a8621d87fbf5 [project @ 2002-08-05 03:17:25 by jwe]
jwe
parents: 4009
diff changeset
2719 case EPOW_EQ:
a8621d87fbf5 [project @ 2002-08-05 03:17:25 by jwe]
jwe
parents: 4009
diff changeset
2720 t = octave_value::op_el_pow_eq;
a8621d87fbf5 [project @ 2002-08-05 03:17:25 by jwe]
jwe
parents: 4009
diff changeset
2721 break;
a8621d87fbf5 [project @ 2002-08-05 03:17:25 by jwe]
jwe
parents: 4009
diff changeset
2722
2883
0b3954110c77 [project @ 1997-04-24 09:57:05 by jwe]
jwe
parents: 2865
diff changeset
2723 case AND_EQ:
3525
6cfa474c5b99 [project @ 2000-02-02 10:48:41 by jwe]
jwe
parents: 3523
diff changeset
2724 t = octave_value::op_el_and_eq;
2883
0b3954110c77 [project @ 1997-04-24 09:57:05 by jwe]
jwe
parents: 2865
diff changeset
2725 break;
0b3954110c77 [project @ 1997-04-24 09:57:05 by jwe]
jwe
parents: 2865
diff changeset
2726
0b3954110c77 [project @ 1997-04-24 09:57:05 by jwe]
jwe
parents: 2865
diff changeset
2727 case OR_EQ:
3525
6cfa474c5b99 [project @ 2000-02-02 10:48:41 by jwe]
jwe
parents: 3523
diff changeset
2728 t = octave_value::op_el_or_eq;
2883
0b3954110c77 [project @ 1997-04-24 09:57:05 by jwe]
jwe
parents: 2865
diff changeset
2729 break;
0b3954110c77 [project @ 1997-04-24 09:57:05 by jwe]
jwe
parents: 2865
diff changeset
2730
0b3954110c77 [project @ 1997-04-24 09:57:05 by jwe]
jwe
parents: 2865
diff changeset
2731 default:
0b3954110c77 [project @ 1997-04-24 09:57:05 by jwe]
jwe
parents: 2865
diff changeset
2732 panic_impossible ();
0b3954110c77 [project @ 1997-04-24 09:57:05 by jwe]
jwe
parents: 2865
diff changeset
2733 break;
0b3954110c77 [project @ 1997-04-24 09:57:05 by jwe]
jwe
parents: 2865
diff changeset
2734 }
0b3954110c77 [project @ 1997-04-24 09:57:05 by jwe]
jwe
parents: 2865
diff changeset
2735
1623
fa7a847f9b92 [project @ 1995-11-06 18:05:09 by jwe]
jwe
parents: 1607
diff changeset
2736 int l = eq_tok->line ();
fa7a847f9b92 [project @ 1995-11-06 18:05:09 by jwe]
jwe
parents: 1607
diff changeset
2737 int c = eq_tok->column ();
fa7a847f9b92 [project @ 1995-11-06 18:05:09 by jwe]
jwe
parents: 1607
diff changeset
2738
5841
fb4dea2184bf [project @ 2006-06-05 20:59:25 by jwe]
jwe
parents: 5832
diff changeset
2739 if (lhs->is_simple_assign_lhs ())
666
fb4f6556b443 [project @ 1994-09-06 21:22:46 by jwe]
jwe
parents: 627
diff changeset
2740 {
2970
b9e64477f703 [project @ 1997-05-15 18:04:21 by jwe]
jwe
parents: 2961
diff changeset
2741 tree_expression *tmp = lhs->remove_front ();
b9e64477f703 [project @ 1997-05-15 18:04:21 by jwe]
jwe
parents: 2961
diff changeset
2742
b9e64477f703 [project @ 1997-05-15 18:04:21 by jwe]
jwe
parents: 2961
diff changeset
2743 retval = new tree_simple_assignment (tmp, rhs, false, l, c, t);
b9e64477f703 [project @ 1997-05-15 18:04:21 by jwe]
jwe
parents: 2961
diff changeset
2744
b9e64477f703 [project @ 1997-05-15 18:04:21 by jwe]
jwe
parents: 2961
diff changeset
2745 delete lhs;
666
fb4f6556b443 [project @ 1994-09-06 21:22:46 by jwe]
jwe
parents: 627
diff changeset
2746 }
10230
0a5a769b8fc0 disallow computed multiple assignment
Jaroslav Hajek <highegg@gmail.com>
parents: 10207
diff changeset
2747 else if (t == octave_value::op_asn_eq)
0a5a769b8fc0 disallow computed multiple assignment
Jaroslav Hajek <highegg@gmail.com>
parents: 10207
diff changeset
2748 return new tree_multi_assignment (lhs, rhs, false, l, c);
666
fb4f6556b443 [project @ 1994-09-06 21:22:46 by jwe]
jwe
parents: 627
diff changeset
2749 else
16142
26d65d677557 rename yyerror to bison_error and make it a member of octave_parser class
John W. Eaton <jwe@octave.org>
parents: 16139
diff changeset
2750 bison_error ("computed multiple assignment not allowed");
666
fb4f6556b443 [project @ 1994-09-06 21:22:46 by jwe]
jwe
parents: 627
diff changeset
2751
fb4f6556b443 [project @ 1994-09-06 21:22:46 by jwe]
jwe
parents: 627
diff changeset
2752 return retval;
fb4f6556b443 [project @ 1994-09-06 21:22:46 by jwe]
jwe
parents: 627
diff changeset
2753 }
751
c9f3cb77478d [project @ 1994-09-30 18:46:17 by jwe]
jwe
parents: 723
diff changeset
2754
9474
25ed2d6aacf6 Parse nested functions more accurately.
David Grundberg <individ@acc.umu.se>
parents: 9471
diff changeset
2755 // Define a script.
7715
5b4d278ec828 parse scripts completely before executing
John W. Eaton <jwe@octave.org>
parents: 7699
diff changeset
2756
16134
ec9c6222ef5a move static parser helper functions to octave_parser class
John W. Eaton <jwe@octave.org>
parents: 16133
diff changeset
2757 void
16287
04a7953496a7 create base class for parser; use reference for curr_lexer
John W. Eaton <jwe@octave.org>
parents: 16285
diff changeset
2758 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
2759 tree_statement *end_script)
7715
5b4d278ec828 parse scripts completely before executing
John W. Eaton <jwe@octave.org>
parents: 7699
diff changeset
2760 {
8658
73c4516fae10 New evaluator and debugger derived from tree-walker class
John W. Eaton <jwe@octave.org>
parents: 8471
diff changeset
2761 if (! cmds)
73c4516fae10 New evaluator and debugger derived from tree-walker class
John W. Eaton <jwe@octave.org>
parents: 8471
diff changeset
2762 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
2763
73c4516fae10 New evaluator and debugger derived from tree-walker class
John W. Eaton <jwe@octave.org>
parents: 8471
diff changeset
2764 cmds->append (end_script);
73c4516fae10 New evaluator and debugger derived from tree-walker class
John W. Eaton <jwe@octave.org>
parents: 8471
diff changeset
2765
7715
5b4d278ec828 parse scripts completely before executing
John W. Eaton <jwe@octave.org>
parents: 7699
diff changeset
2766 octave_user_script *script
16288
fe3b9a51e625 rename curr_lexer, curr_parser, CURR_LEXER
John W. Eaton <jwe@octave.org>
parents: 16287
diff changeset
2767 = 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
2768 lexer.fcn_file_name,
fe3b9a51e625 rename curr_lexer, curr_parser, CURR_LEXER
John W. Eaton <jwe@octave.org>
parents: 16287
diff changeset
2769 cmds, lexer.help_text);
fe3b9a51e625 rename curr_lexer, curr_parser, CURR_LEXER
John W. Eaton <jwe@octave.org>
parents: 16287
diff changeset
2770
fe3b9a51e625 rename curr_lexer, curr_parser, CURR_LEXER
John W. Eaton <jwe@octave.org>
parents: 16287
diff changeset
2771 lexer.help_text = "";
7715
5b4d278ec828 parse scripts completely before executing
John W. Eaton <jwe@octave.org>
parents: 7699
diff changeset
2772
5b4d278ec828 parse scripts completely before executing
John W. Eaton <jwe@octave.org>
parents: 7699
diff changeset
2773 octave_time now;
5b4d278ec828 parse scripts completely before executing
John W. Eaton <jwe@octave.org>
parents: 7699
diff changeset
2774
5b4d278ec828 parse scripts completely before executing
John W. Eaton <jwe@octave.org>
parents: 7699
diff changeset
2775 script->stash_fcn_file_time (now);
5b4d278ec828 parse scripts completely before executing
John W. Eaton <jwe@octave.org>
parents: 7699
diff changeset
2776
9474
25ed2d6aacf6 Parse nested functions more accurately.
David Grundberg <individ@acc.umu.se>
parents: 9471
diff changeset
2777 primary_fcn_ptr = script;
7715
5b4d278ec828 parse scripts completely before executing
John W. Eaton <jwe@octave.org>
parents: 7699
diff changeset
2778 }
5b4d278ec828 parse scripts completely before executing
John W. Eaton <jwe@octave.org>
parents: 7699
diff changeset
2779
1623
fa7a847f9b92 [project @ 1995-11-06 18:05:09 by jwe]
jwe
parents: 1607
diff changeset
2780 // Begin defining a function.
fa7a847f9b92 [project @ 1995-11-06 18:05:09 by jwe]
jwe
parents: 1607
diff changeset
2781
16134
ec9c6222ef5a move static parser helper functions to octave_parser class
John W. Eaton <jwe@octave.org>
parents: 16133
diff changeset
2782 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
2783 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
2784 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
2785 tree_statement *end_fcn_stmt)
1623
fa7a847f9b92 [project @ 1995-11-06 18:05:09 by jwe]
jwe
parents: 1607
diff changeset
2786 {
2891
1a30f46e1870 [project @ 1997-04-28 01:49:00 by jwe]
jwe
parents: 2884
diff changeset
2787 // We'll fill in the return list later.
1a30f46e1870 [project @ 1997-04-28 01:49:00 by jwe]
jwe
parents: 2884
diff changeset
2788
8658
73c4516fae10 New evaluator and debugger derived from tree-walker class
John W. Eaton <jwe@octave.org>
parents: 8471
diff changeset
2789 if (! body)
73c4516fae10 New evaluator and debugger derived from tree-walker class
John W. Eaton <jwe@octave.org>
parents: 8471
diff changeset
2790 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
2791
73c4516fae10 New evaluator and debugger derived from tree-walker class
John W. Eaton <jwe@octave.org>
parents: 8471
diff changeset
2792 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
2793
2891
1a30f46e1870 [project @ 1997-04-28 01:49:00 by jwe]
jwe
parents: 2884
diff changeset
2794 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
2795 = 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
2796 param_list, 0, body);
1623
fa7a847f9b92 [project @ 1995-11-06 18:05:09 by jwe]
jwe
parents: 1607
diff changeset
2797
3665
0689afb1d001 [project @ 2000-05-11 19:07:56 by jwe]
jwe
parents: 3544
diff changeset
2798 if (fcn)
0689afb1d001 [project @ 2000-05-11 19:07:56 by jwe]
jwe
parents: 3544
diff changeset
2799 {
17693
efbe746f8fa8 eliminate octave_comment_buffer singleton
John W. Eaton <jwe@octave.org>
parents: 17673
diff changeset
2800 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
2801
0689afb1d001 [project @ 2000-05-11 19:07:56 by jwe]
jwe
parents: 3544
diff changeset
2802 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
2803 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
2804 end_fcn_stmt->column ());
3665
0689afb1d001 [project @ 2000-05-11 19:07:56 by jwe]
jwe
parents: 3544
diff changeset
2805 }
0689afb1d001 [project @ 2000-05-11 19:07:56 by jwe]
jwe
parents: 3544
diff changeset
2806
1623
fa7a847f9b92 [project @ 1995-11-06 18:05:09 by jwe]
jwe
parents: 1607
diff changeset
2807 return fcn;
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
16134
ec9c6222ef5a move static parser helper functions to octave_parser class
John W. Eaton <jwe@octave.org>
parents: 16133
diff changeset
2810 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
2811 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
2812 {
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
2813 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
2814 }
73c4516fae10 New evaluator and debugger derived from tree-walker class
John W. Eaton <jwe@octave.org>
parents: 8471
diff changeset
2815
1623
fa7a847f9b92 [project @ 1995-11-06 18:05:09 by jwe]
jwe
parents: 1607
diff changeset
2816 // Do most of the work for defining a function.
fa7a847f9b92 [project @ 1995-11-06 18:05:09 by jwe]
jwe
parents: 1607
diff changeset
2817
16134
ec9c6222ef5a move static parser helper functions to octave_parser class
John W. Eaton <jwe@octave.org>
parents: 16133
diff changeset
2818 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
2819 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
2820 octave_user_function *fcn)
1623
fa7a847f9b92 [project @ 1995-11-06 18:05:09 by jwe]
jwe
parents: 1607
diff changeset
2821 {
4872
fe71c458f438 [project @ 2004-04-21 20:09:32 by jwe]
jwe
parents: 4844
diff changeset
2822 std::string id_name = fname;
1623
fa7a847f9b92 [project @ 1995-11-06 18:05:09 by jwe]
jwe
parents: 1607
diff changeset
2823
fa7a847f9b92 [project @ 1995-11-06 18:05:09 by jwe]
jwe
parents: 1607
diff changeset
2824 // 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
2825 // 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
2826 // 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
2827 // name).
16288
fe3b9a51e625 rename curr_lexer, curr_parser, CURR_LEXER
John W. Eaton <jwe@octave.org>
parents: 16287
diff changeset
2828 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
2829 && curr_fcn_depth == 1 && ! parsing_subfunctions)
9474
25ed2d6aacf6 Parse nested functions more accurately.
David Grundberg <individ@acc.umu.se>
parents: 9471
diff changeset
2830 {
16288
fe3b9a51e625 rename curr_lexer, curr_parser, CURR_LEXER
John W. Eaton <jwe@octave.org>
parents: 16287
diff changeset
2831 // 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
2832 // preprocessed when we get here? It seems to only be a
25ed2d6aacf6 Parse nested functions more accurately.
David Grundberg <individ@acc.umu.se>
parents: 9471
diff changeset
2833 // problem with relative file names.
25ed2d6aacf6 Parse nested functions more accurately.
David Grundberg <individ@acc.umu.se>
parents: 9471
diff changeset
2834
16288
fe3b9a51e625 rename curr_lexer, curr_parser, CURR_LEXER
John W. Eaton <jwe@octave.org>
parents: 16287
diff changeset
2835 std::string nm = lexer.fcn_file_name;
9474
25ed2d6aacf6 Parse nested functions more accurately.
David Grundberg <individ@acc.umu.se>
parents: 9471
diff changeset
2836
25ed2d6aacf6 Parse nested functions more accurately.
David Grundberg <individ@acc.umu.se>
parents: 9471
diff changeset
2837 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
2838
25ed2d6aacf6 Parse nested functions more accurately.
David Grundberg <individ@acc.umu.se>
parents: 9471
diff changeset
2839 if (pos != std::string::npos)
16288
fe3b9a51e625 rename curr_lexer, curr_parser, CURR_LEXER
John W. Eaton <jwe@octave.org>
parents: 16287
diff changeset
2840 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
2841
25ed2d6aacf6 Parse nested functions more accurately.
David Grundberg <individ@acc.umu.se>
parents: 9471
diff changeset
2842 if (nm != id_name)
25ed2d6aacf6 Parse nested functions more accurately.
David Grundberg <individ@acc.umu.se>
parents: 9471
diff changeset
2843 {
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
2844 warning_with_id
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
2845 ("Octave:function-name-clash",
15466
d174210ce1ec use ' instead of ` in error messages, warnings and most comments
John W. Eaton <jwe@octave.org>
parents: 14189
diff changeset
2846 "function name '%s' does not agree with function file name '%s'",
16288
fe3b9a51e625 rename curr_lexer, curr_parser, CURR_LEXER
John W. Eaton <jwe@octave.org>
parents: 16287
diff changeset
2847 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
2848
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
2849 id_name = nm;
9474
25ed2d6aacf6 Parse nested functions more accurately.
David Grundberg <individ@acc.umu.se>
parents: 9471
diff changeset
2850 }
25ed2d6aacf6 Parse nested functions more accurately.
David Grundberg <individ@acc.umu.se>
parents: 9471
diff changeset
2851 }
1623
fa7a847f9b92 [project @ 1995-11-06 18:05:09 by jwe]
jwe
parents: 1607
diff changeset
2852
16288
fe3b9a51e625 rename curr_lexer, curr_parser, CURR_LEXER
John W. Eaton <jwe@octave.org>
parents: 16287
diff changeset
2853 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
2854 {
3712
7066a8065e7e [project @ 2000-08-22 06:21:20 by jwe]
jwe
parents: 3665
diff changeset
2855 octave_time now;
3162
7c96e85c76db [project @ 1998-04-08 18:19:35 by jwe]
jwe
parents: 3156
diff changeset
2856
16288
fe3b9a51e625 rename curr_lexer, curr_parser, CURR_LEXER
John W. Eaton <jwe@octave.org>
parents: 16287
diff changeset
2857 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
2858 fcn->stash_fcn_file_time (now);
1623
fa7a847f9b92 [project @ 1995-11-06 18:05:09 by jwe]
jwe
parents: 1607
diff changeset
2859 fcn->mark_as_system_fcn_file ();
3162
7c96e85c76db [project @ 1998-04-08 18:19:35 by jwe]
jwe
parents: 3156
diff changeset
2860
6323
ea65de49e18e [project @ 2007-02-17 02:51:02 by jwe]
jwe
parents: 6238
diff changeset
2861 if (fcn_file_from_relative_lookup)
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
2862 fcn->mark_relative ();
6323
ea65de49e18e [project @ 2007-02-17 02:51:02 by jwe]
jwe
parents: 6238
diff changeset
2863
16153
a57c2c8c8163 move some variables into the octave_parser class
John W. Eaton <jwe@octave.org>
parents: 16151
diff changeset
2864 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
2865 {
16288
fe3b9a51e625 rename curr_lexer, curr_parser, CURR_LEXER
John W. Eaton <jwe@octave.org>
parents: 16287
diff changeset
2866 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
2867
16153
a57c2c8c8163 move some variables into the octave_parser class
John W. Eaton <jwe@octave.org>
parents: 16151
diff changeset
2868 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
2869 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
2870 else
be18c9e359bf Nested function support (bug #35772)
Max Brister <max@2bass.com>
parents: 14533
diff changeset
2871 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
2872 }
6323
ea65de49e18e [project @ 2007-02-17 02:51:02 by jwe]
jwe
parents: 6238
diff changeset
2873
16288
fe3b9a51e625 rename curr_lexer, curr_parser, CURR_LEXER
John W. Eaton <jwe@octave.org>
parents: 16287
diff changeset
2874 if (lexer.parsing_class_method)
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
2875 {
16153
a57c2c8c8163 move some variables into the octave_parser class
John W. Eaton <jwe@octave.org>
parents: 16151
diff changeset
2876 if (curr_class_name == id_name)
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
2877 fcn->mark_as_class_constructor ();
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
2878 else
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
2879 fcn->mark_as_class_method ();
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
2880
16153
a57c2c8c8163 move some variables into the octave_parser class
John W. Eaton <jwe@octave.org>
parents: 16151
diff changeset
2881 fcn->stash_dispatch_class (curr_class_name);
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
2882 }
7336
745a8299c2b5 [project @ 2007-12-28 20:56:55 by jwe]
jwe
parents: 7017
diff changeset
2883
5781
faafc2d98b8d [project @ 2006-05-02 19:40:19 by jwe]
jwe
parents: 5775
diff changeset
2884 std::string nm = fcn->fcn_file_name ();
faafc2d98b8d [project @ 2006-05-02 19:40:19 by jwe]
jwe
parents: 5775
diff changeset
2885
faafc2d98b8d [project @ 2006-05-02 19:40:19 by jwe]
jwe
parents: 5775
diff changeset
2886 file_stat fs (nm);
faafc2d98b8d [project @ 2006-05-02 19:40:19 by jwe]
jwe
parents: 5775
diff changeset
2887
faafc2d98b8d [project @ 2006-05-02 19:40:19 by jwe]
jwe
parents: 5775
diff changeset
2888 if (fs && fs.is_newer (now))
faafc2d98b8d [project @ 2006-05-02 19:40:19 by jwe]
jwe
parents: 5775
diff changeset
2889 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
2890 "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
2891 }
16203
127cccb037bf move more global parser and lexer variables to classes
John W. Eaton <jwe@octave.org>
parents: 16199
diff changeset
2892 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
2893 && ! lexer.force_script
fe3b9a51e625 rename curr_lexer, curr_parser, CURR_LEXER
John W. Eaton <jwe@octave.org>
parents: 16287
diff changeset
2894 && lexer.reading_script_file
fe3b9a51e625 rename curr_lexer, curr_parser, CURR_LEXER
John W. Eaton <jwe@octave.org>
parents: 16287
diff changeset
2895 && lexer.fcn_file_name == id_name)
1623
fa7a847f9b92 [project @ 1995-11-06 18:05:09 by jwe]
jwe
parents: 1607
diff changeset
2896 {
15466
d174210ce1ec use ' instead of ` in error messages, warnings and most comments
John W. Eaton <jwe@octave.org>
parents: 14189
diff changeset
2897 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
2898 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
2899 }
fa7a847f9b92 [project @ 1995-11-06 18:05:09 by jwe]
jwe
parents: 1607
diff changeset
2900
4872
fe71c458f438 [project @ 2004-04-21 20:09:32 by jwe]
jwe
parents: 4844
diff changeset
2901 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
2902
fe3b9a51e625 rename curr_lexer, curr_parser, CURR_LEXER
John W. Eaton <jwe@octave.org>
parents: 16287
diff changeset
2903 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
2904 && ! parsing_subfunctions)
7336
745a8299c2b5 [project @ 2007-12-28 20:56:55 by jwe]
jwe
parents: 7017
diff changeset
2905 {
16288
fe3b9a51e625 rename curr_lexer, curr_parser, CURR_LEXER
John W. Eaton <jwe@octave.org>
parents: 16287
diff changeset
2906 fcn->document (lexer.help_text);
fe3b9a51e625 rename curr_lexer, curr_parser, CURR_LEXER
John W. Eaton <jwe@octave.org>
parents: 16287
diff changeset
2907
fe3b9a51e625 rename curr_lexer, curr_parser, CURR_LEXER
John W. Eaton <jwe@octave.org>
parents: 16287
diff changeset
2908 lexer.help_text = "";
7336
745a8299c2b5 [project @ 2007-12-28 20:56:55 by jwe]
jwe
parents: 7017
diff changeset
2909 }
745a8299c2b5 [project @ 2007-12-28 20:56:55 by jwe]
jwe
parents: 7017
diff changeset
2910
16288
fe3b9a51e625 rename curr_lexer, curr_parser, CURR_LEXER
John W. Eaton <jwe@octave.org>
parents: 16287
diff changeset
2911 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
2912 && ! parsing_subfunctions)
25ed2d6aacf6 Parse nested functions more accurately.
David Grundberg <individ@acc.umu.se>
parents: 9471
diff changeset
2913 primary_fcn_ptr = fcn;
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11572
diff changeset
2914
1623
fa7a847f9b92 [project @ 1995-11-06 18:05:09 by jwe]
jwe
parents: 1607
diff changeset
2915 return fcn;
fa7a847f9b92 [project @ 1995-11-06 18:05:09 by jwe]
jwe
parents: 1607
diff changeset
2916 }
fa7a847f9b92 [project @ 1995-11-06 18:05:09 by jwe]
jwe
parents: 1607
diff changeset
2917
16134
ec9c6222ef5a move static parser helper functions to octave_parser class
John W. Eaton <jwe@octave.org>
parents: 16133
diff changeset
2918 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
2919 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
2920 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
2921 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
2922 int l, int c)
1623
fa7a847f9b92 [project @ 1995-11-06 18:05:09 by jwe]
jwe
parents: 1607
diff changeset
2923 {
7715
5b4d278ec828 parse scripts completely before executing
John W. Eaton <jwe@octave.org>
parents: 7699
diff changeset
2924 tree_function_def *retval = 0;
5b4d278ec828 parse scripts completely before executing
John W. Eaton <jwe@octave.org>
parents: 7699
diff changeset
2925
5b4d278ec828 parse scripts completely before executing
John W. Eaton <jwe@octave.org>
parents: 7699
diff changeset
2926 if (ret_list)
5b4d278ec828 parse scripts completely before executing
John W. Eaton <jwe@octave.org>
parents: 7699
diff changeset
2927 ret_list->mark_as_formal_parameters ();
5b4d278ec828 parse scripts completely before executing
John W. Eaton <jwe@octave.org>
parents: 7699
diff changeset
2928
5b4d278ec828 parse scripts completely before executing
John W. Eaton <jwe@octave.org>
parents: 7699
diff changeset
2929 if (fcn)
5b4d278ec828 parse scripts completely before executing
John W. Eaton <jwe@octave.org>
parents: 7699
diff changeset
2930 {
7761
5adeea5de26c symbol table reporting functions
John W. Eaton <jwe@octave.org>
parents: 7755
diff changeset
2931 std::string nm = fcn->name ();
5adeea5de26c symbol table reporting functions
John W. Eaton <jwe@octave.org>
parents: 7755
diff changeset
2932 std::string file = fcn->fcn_file_name ();
5adeea5de26c symbol table reporting functions
John W. Eaton <jwe@octave.org>
parents: 7755
diff changeset
2933
5adeea5de26c symbol table reporting functions
John W. Eaton <jwe@octave.org>
parents: 7755
diff changeset
2934 std::string tmp = nm;
5adeea5de26c symbol table reporting functions
John W. Eaton <jwe@octave.org>
parents: 7755
diff changeset
2935 if (! file.empty ())
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
2936 tmp += ": " + file;
7761
5adeea5de26c symbol table reporting functions
John W. Eaton <jwe@octave.org>
parents: 7755
diff changeset
2937
5adeea5de26c symbol table reporting functions
John W. Eaton <jwe@octave.org>
parents: 7755
diff changeset
2938 symbol_table::cache_name (fcn->scope (), tmp);
5adeea5de26c symbol table reporting functions
John W. Eaton <jwe@octave.org>
parents: 7755
diff changeset
2939
7715
5b4d278ec828 parse scripts completely before executing
John W. Eaton <jwe@octave.org>
parents: 7699
diff changeset
2940 if (lc)
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
2941 fcn->stash_leading_comment (lc);
7715
5b4d278ec828 parse scripts completely before executing
John W. Eaton <jwe@octave.org>
parents: 7699
diff changeset
2942
5b4d278ec828 parse scripts completely before executing
John W. Eaton <jwe@octave.org>
parents: 7699
diff changeset
2943 fcn->define_ret_list (ret_list);
7755
ea9cb4d68dbf avoid installing subfunctions twice
John W. Eaton <jwe@octave.org>
parents: 7750
diff changeset
2944
16153
a57c2c8c8163 move some variables into the octave_parser class
John W. Eaton <jwe@octave.org>
parents: 16151
diff changeset
2945 if (curr_fcn_depth > 1 || parsing_subfunctions)
9474
25ed2d6aacf6 Parse nested functions more accurately.
David Grundberg <individ@acc.umu.se>
parents: 9471
diff changeset
2946 {
11461
2b8531a6a3c9 Change mentions of "nested function" to the less misleading "subfunction"
David Grundberg <individ@acc.umu.se>
parents: 11388
diff changeset
2947 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
2948 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
2949
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
2950 subfunction_names.push_back (nm);
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
2951
14544
be18c9e359bf Nested function support (bug #35772)
Max Brister <max@2bass.com>
parents: 14533
diff changeset
2952 if (endfunction_found && function_scopes.size () > 1)
be18c9e359bf Nested function support (bug #35772)
Max Brister <max@2bass.com>
parents: 14533
diff changeset
2953 {
be18c9e359bf Nested function support (bug #35772)
Max Brister <max@2bass.com>
parents: 14533
diff changeset
2954 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
2955 = function_scopes[function_scopes.size ()-2];
14544
be18c9e359bf Nested function support (bug #35772)
Max Brister <max@2bass.com>
parents: 14533
diff changeset
2956
be18c9e359bf Nested function support (bug #35772)
Max Brister <max@2bass.com>
parents: 14533
diff changeset
2957 symbol_table::install_nestfunction (nm, octave_value (fcn),
be18c9e359bf Nested function support (bug #35772)
Max Brister <max@2bass.com>
parents: 14533
diff changeset
2958 pscope);
be18c9e359bf Nested function support (bug #35772)
Max Brister <max@2bass.com>
parents: 14533
diff changeset
2959 }
be18c9e359bf Nested function support (bug #35772)
Max Brister <max@2bass.com>
parents: 14533
diff changeset
2960 else
be18c9e359bf Nested function support (bug #35772)
Max Brister <max@2bass.com>
parents: 14533
diff changeset
2961 symbol_table::install_subfunction (nm, octave_value (fcn),
be18c9e359bf Nested function support (bug #35772)
Max Brister <max@2bass.com>
parents: 14533
diff changeset
2962 primary_fcn_scope);
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
2963 }
9474
25ed2d6aacf6 Parse nested functions more accurately.
David Grundberg <individ@acc.umu.se>
parents: 9471
diff changeset
2964
16153
a57c2c8c8163 move some variables into the octave_parser class
John W. Eaton <jwe@octave.org>
parents: 16151
diff changeset
2965 if (curr_fcn_depth == 1 && fcn)
14544
be18c9e359bf Nested function support (bug #35772)
Max Brister <max@2bass.com>
parents: 14533
diff changeset
2966 symbol_table::update_nest (fcn->scope ());
be18c9e359bf Nested function support (bug #35772)
Max Brister <max@2bass.com>
parents: 14533
diff changeset
2967
16288
fe3b9a51e625 rename curr_lexer, curr_parser, CURR_LEXER
John W. Eaton <jwe@octave.org>
parents: 16287
diff changeset
2968 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
2969 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
2970 // 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
2971 // 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
2972 // 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
2973 // 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
2974 // 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
2975 // 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
2976 // 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
2977 // parse_fcn_file, and
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
2978 // 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
2979
5f8971be8e12 parse.y (finish_function): retrun function object unless parsing function file
John W. Eaton <jwe@octave.org>
parents: 9506
diff changeset
2980 retval = new tree_function_def (fcn);
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
2981 }
7715
5b4d278ec828 parse scripts completely before executing
John W. Eaton <jwe@octave.org>
parents: 7699
diff changeset
2982 }
5b4d278ec828 parse scripts completely before executing
John W. Eaton <jwe@octave.org>
parents: 7699
diff changeset
2983
5b4d278ec828 parse scripts completely before executing
John W. Eaton <jwe@octave.org>
parents: 7699
diff changeset
2984 return retval;
1623
fa7a847f9b92 [project @ 1995-11-06 18:05:09 by jwe]
jwe
parents: 1607
diff changeset
2985 }
fa7a847f9b92 [project @ 1995-11-06 18:05:09 by jwe]
jwe
parents: 1607
diff changeset
2986
16134
ec9c6222ef5a move static parser helper functions to octave_parser class
John W. Eaton <jwe@octave.org>
parents: 16133
diff changeset
2987 void
16287
04a7953496a7 create base class for parser; use reference for curr_lexer
John W. Eaton <jwe@octave.org>
parents: 16285
diff changeset
2988 octave_base_parser::recover_from_parsing_function (void)
2883
0b3954110c77 [project @ 1997-04-24 09:57:05 by jwe]
jwe
parents: 2865
diff changeset
2989 {
16320
09f0cb9cac7d don't modify symbol table scope in the parser
John W. Eaton <jwe@octave.org>
parents: 16302
diff changeset
2990 lexer.symtab_context.pop ();
2883
0b3954110c77 [project @ 1997-04-24 09:57:05 by jwe]
jwe
parents: 2865
diff changeset
2991
16288
fe3b9a51e625 rename curr_lexer, curr_parser, CURR_LEXER
John W. Eaton <jwe@octave.org>
parents: 16287
diff changeset
2992 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
2993 && ! parsing_subfunctions)
25ed2d6aacf6 Parse nested functions more accurately.
David Grundberg <individ@acc.umu.se>
parents: 9471
diff changeset
2994 parsing_subfunctions = true;
25ed2d6aacf6 Parse nested functions more accurately.
David Grundberg <individ@acc.umu.se>
parents: 9471
diff changeset
2995
16153
a57c2c8c8163 move some variables into the octave_parser class
John W. Eaton <jwe@octave.org>
parents: 16151
diff changeset
2996 curr_fcn_depth--;
14544
be18c9e359bf Nested function support (bug #35772)
Max Brister <max@2bass.com>
parents: 14533
diff changeset
2997 function_scopes.pop_back ();
9474
25ed2d6aacf6 Parse nested functions more accurately.
David Grundberg <individ@acc.umu.se>
parents: 9471
diff changeset
2998
16288
fe3b9a51e625 rename curr_lexer, curr_parser, CURR_LEXER
John W. Eaton <jwe@octave.org>
parents: 16287
diff changeset
2999 lexer.defining_func--;
fe3b9a51e625 rename curr_lexer, curr_parser, CURR_LEXER
John W. Eaton <jwe@octave.org>
parents: 16287
diff changeset
3000 lexer.parsed_function_name.pop ();
fe3b9a51e625 rename curr_lexer, curr_parser, CURR_LEXER
John W. Eaton <jwe@octave.org>
parents: 16287
diff changeset
3001 lexer.looking_at_return_list = false;
fe3b9a51e625 rename curr_lexer, curr_parser, CURR_LEXER
John W. Eaton <jwe@octave.org>
parents: 16287
diff changeset
3002 lexer.looking_at_parameter_list = false;
2883
0b3954110c77 [project @ 1997-04-24 09:57:05 by jwe]
jwe
parents: 2865
diff changeset
3003 }
0b3954110c77 [project @ 1997-04-24 09:57:05 by jwe]
jwe
parents: 2865
diff changeset
3004
2846
52e7c4509983 [project @ 1997-03-26 23:27:35 by jwe]
jwe
parents: 2825
diff changeset
3005 // Make an index expression.
52e7c4509983 [project @ 1997-03-26 23:27:35 by jwe]
jwe
parents: 2825
diff changeset
3006
16134
ec9c6222ef5a move static parser helper functions to octave_parser class
John W. Eaton <jwe@octave.org>
parents: 16133
diff changeset
3007 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
3008 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
3009 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
3010 char type)
751
c9f3cb77478d [project @ 1994-09-30 18:46:17 by jwe]
jwe
parents: 723
diff changeset
3011 {
c9f3cb77478d [project @ 1994-09-30 18:46:17 by jwe]
jwe
parents: 723
diff changeset
3012 tree_index_expression *retval = 0;
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11572
diff changeset
3013
10206
37a08e0ce2dc support Matlab-style empty output/input arguments
Jaroslav Hajek <highegg@gmail.com>
parents: 10188
diff changeset
3014 if (args && args->has_magic_tilde ())
37a08e0ce2dc support Matlab-style empty output/input arguments
Jaroslav Hajek <highegg@gmail.com>
parents: 10188
diff changeset
3015 {
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
3016 bison_error ("invalid use of empty argument (~) in index expression");
17632
bd0a84de3375 further reduce memory leaks from parse errors (bug #40231)
John W. Eaton <jwe@octave.org>
parents: 17629
diff changeset
3017
bd0a84de3375 further reduce memory leaks from parse errors (bug #40231)
John W. Eaton <jwe@octave.org>
parents: 17629
diff changeset
3018 delete expr;
bd0a84de3375 further reduce memory leaks from parse errors (bug #40231)
John W. Eaton <jwe@octave.org>
parents: 17629
diff changeset
3019 delete args;
bd0a84de3375 further reduce memory leaks from parse errors (bug #40231)
John W. Eaton <jwe@octave.org>
parents: 17629
diff changeset
3020
10206
37a08e0ce2dc support Matlab-style empty output/input arguments
Jaroslav Hajek <highegg@gmail.com>
parents: 10188
diff changeset
3021 return retval;
37a08e0ce2dc support Matlab-style empty output/input arguments
Jaroslav Hajek <highegg@gmail.com>
parents: 10188
diff changeset
3022 }
751
c9f3cb77478d [project @ 1994-09-30 18:46:17 by jwe]
jwe
parents: 723
diff changeset
3023
2970
b9e64477f703 [project @ 1997-05-15 18:04:21 by jwe]
jwe
parents: 2961
diff changeset
3024 int l = expr->line ();
b9e64477f703 [project @ 1997-05-15 18:04:21 by jwe]
jwe
parents: 2961
diff changeset
3025 int c = expr->column ();
b9e64477f703 [project @ 1997-05-15 18:04:21 by jwe]
jwe
parents: 2961
diff changeset
3026
b9e64477f703 [project @ 1997-05-15 18:04:21 by jwe]
jwe
parents: 2961
diff changeset
3027 expr->mark_postfix_indexed ();
b9e64477f703 [project @ 1997-05-15 18:04:21 by jwe]
jwe
parents: 2961
diff changeset
3028
3933
f9ea3dcf58ee [project @ 2002-05-15 03:21:00 by jwe]
jwe
parents: 3930
diff changeset
3029 if (expr->is_index_expression ())
f9ea3dcf58ee [project @ 2002-05-15 03:21:00 by jwe]
jwe
parents: 3930
diff changeset
3030 {
f9ea3dcf58ee [project @ 2002-05-15 03:21:00 by jwe]
jwe
parents: 3930
diff changeset
3031 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
3032
f9ea3dcf58ee [project @ 2002-05-15 03:21:00 by jwe]
jwe
parents: 3930
diff changeset
3033 tmp->append (args, type);
f9ea3dcf58ee [project @ 2002-05-15 03:21:00 by jwe]
jwe
parents: 3930
diff changeset
3034
f9ea3dcf58ee [project @ 2002-05-15 03:21:00 by jwe]
jwe
parents: 3930
diff changeset
3035 retval = tmp;
f9ea3dcf58ee [project @ 2002-05-15 03:21:00 by jwe]
jwe
parents: 3930
diff changeset
3036 }
f9ea3dcf58ee [project @ 2002-05-15 03:21:00 by jwe]
jwe
parents: 3930
diff changeset
3037 else
f9ea3dcf58ee [project @ 2002-05-15 03:21:00 by jwe]
jwe
parents: 3930
diff changeset
3038 retval = new tree_index_expression (expr, args, l, c, type);
2970
b9e64477f703 [project @ 1997-05-15 18:04:21 by jwe]
jwe
parents: 2961
diff changeset
3039
b9e64477f703 [project @ 1997-05-15 18:04:21 by jwe]
jwe
parents: 2961
diff changeset
3040 return retval;
b9e64477f703 [project @ 1997-05-15 18:04:21 by jwe]
jwe
parents: 2961
diff changeset
3041 }
b9e64477f703 [project @ 1997-05-15 18:04:21 by jwe]
jwe
parents: 2961
diff changeset
3042
b9e64477f703 [project @ 1997-05-15 18:04:21 by jwe]
jwe
parents: 2961
diff changeset
3043 // Make an indirect reference expression.
b9e64477f703 [project @ 1997-05-15 18:04:21 by jwe]
jwe
parents: 2961
diff changeset
3044
16134
ec9c6222ef5a move static parser helper functions to octave_parser class
John W. Eaton <jwe@octave.org>
parents: 16133
diff changeset
3045 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
3046 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
3047 const std::string& elt)
2970
b9e64477f703 [project @ 1997-05-15 18:04:21 by jwe]
jwe
parents: 2961
diff changeset
3048 {
3930
61d4427c016e [project @ 2002-05-07 00:47:31 by jwe]
jwe
parents: 3929
diff changeset
3049 tree_index_expression *retval = 0;
2970
b9e64477f703 [project @ 1997-05-15 18:04:21 by jwe]
jwe
parents: 2961
diff changeset
3050
b9e64477f703 [project @ 1997-05-15 18:04:21 by jwe]
jwe
parents: 2961
diff changeset
3051 int l = expr->line ();
b9e64477f703 [project @ 1997-05-15 18:04:21 by jwe]
jwe
parents: 2961
diff changeset
3052 int c = expr->column ();
b9e64477f703 [project @ 1997-05-15 18:04:21 by jwe]
jwe
parents: 2961
diff changeset
3053
3933
f9ea3dcf58ee [project @ 2002-05-15 03:21:00 by jwe]
jwe
parents: 3930
diff changeset
3054 if (expr->is_index_expression ())
f9ea3dcf58ee [project @ 2002-05-15 03:21:00 by jwe]
jwe
parents: 3930
diff changeset
3055 {
f9ea3dcf58ee [project @ 2002-05-15 03:21:00 by jwe]
jwe
parents: 3930
diff changeset
3056 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
3057
f9ea3dcf58ee [project @ 2002-05-15 03:21:00 by jwe]
jwe
parents: 3930
diff changeset
3058 tmp->append (elt);
f9ea3dcf58ee [project @ 2002-05-15 03:21:00 by jwe]
jwe
parents: 3930
diff changeset
3059
f9ea3dcf58ee [project @ 2002-05-15 03:21:00 by jwe]
jwe
parents: 3930
diff changeset
3060 retval = tmp;
f9ea3dcf58ee [project @ 2002-05-15 03:21:00 by jwe]
jwe
parents: 3930
diff changeset
3061 }
f9ea3dcf58ee [project @ 2002-05-15 03:21:00 by jwe]
jwe
parents: 3930
diff changeset
3062 else
f9ea3dcf58ee [project @ 2002-05-15 03:21:00 by jwe]
jwe
parents: 3930
diff changeset
3063 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
3064
16288
fe3b9a51e625 rename curr_lexer, curr_parser, CURR_LEXER
John W. Eaton <jwe@octave.org>
parents: 16287
diff changeset
3065 lexer.looking_at_indirect_ref = false;
751
c9f3cb77478d [project @ 1994-09-30 18:46:17 by jwe]
jwe
parents: 723
diff changeset
3066
c9f3cb77478d [project @ 1994-09-30 18:46:17 by jwe]
jwe
parents: 723
diff changeset
3067 return retval;
c9f3cb77478d [project @ 1994-09-30 18:46:17 by jwe]
jwe
parents: 723
diff changeset
3068 }
1511
74f9e88a2c12 [project @ 1995-10-03 10:49:31 by jwe]
jwe
parents: 1491
diff changeset
3069
4131
597fbc55ea40 [project @ 2002-10-29 17:12:53 by jwe]
jwe
parents: 4064
diff changeset
3070 // Make an indirect reference expression with dynamic field name.
597fbc55ea40 [project @ 2002-10-29 17:12:53 by jwe]
jwe
parents: 4064
diff changeset
3071
16134
ec9c6222ef5a move static parser helper functions to octave_parser class
John W. Eaton <jwe@octave.org>
parents: 16133
diff changeset
3072 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
3073 octave_base_parser::make_indirect_ref (tree_expression *expr, tree_expression *elt)
4131
597fbc55ea40 [project @ 2002-10-29 17:12:53 by jwe]
jwe
parents: 4064
diff changeset
3074 {
597fbc55ea40 [project @ 2002-10-29 17:12:53 by jwe]
jwe
parents: 4064
diff changeset
3075 tree_index_expression *retval = 0;
597fbc55ea40 [project @ 2002-10-29 17:12:53 by jwe]
jwe
parents: 4064
diff changeset
3076
597fbc55ea40 [project @ 2002-10-29 17:12:53 by jwe]
jwe
parents: 4064
diff changeset
3077 int l = expr->line ();
597fbc55ea40 [project @ 2002-10-29 17:12:53 by jwe]
jwe
parents: 4064
diff changeset
3078 int c = expr->column ();
597fbc55ea40 [project @ 2002-10-29 17:12:53 by jwe]
jwe
parents: 4064
diff changeset
3079
597fbc55ea40 [project @ 2002-10-29 17:12:53 by jwe]
jwe
parents: 4064
diff changeset
3080 if (expr->is_index_expression ())
597fbc55ea40 [project @ 2002-10-29 17:12:53 by jwe]
jwe
parents: 4064
diff changeset
3081 {
597fbc55ea40 [project @ 2002-10-29 17:12:53 by jwe]
jwe
parents: 4064
diff changeset
3082 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
3083
597fbc55ea40 [project @ 2002-10-29 17:12:53 by jwe]
jwe
parents: 4064
diff changeset
3084 tmp->append (elt);
597fbc55ea40 [project @ 2002-10-29 17:12:53 by jwe]
jwe
parents: 4064
diff changeset
3085
597fbc55ea40 [project @ 2002-10-29 17:12:53 by jwe]
jwe
parents: 4064
diff changeset
3086 retval = tmp;
597fbc55ea40 [project @ 2002-10-29 17:12:53 by jwe]
jwe
parents: 4064
diff changeset
3087 }
597fbc55ea40 [project @ 2002-10-29 17:12:53 by jwe]
jwe
parents: 4064
diff changeset
3088 else
597fbc55ea40 [project @ 2002-10-29 17:12:53 by jwe]
jwe
parents: 4064
diff changeset
3089 retval = new tree_index_expression (expr, elt, l, c);
597fbc55ea40 [project @ 2002-10-29 17:12:53 by jwe]
jwe
parents: 4064
diff changeset
3090
16288
fe3b9a51e625 rename curr_lexer, curr_parser, CURR_LEXER
John W. Eaton <jwe@octave.org>
parents: 16287
diff changeset
3091 lexer.looking_at_indirect_ref = false;
4131
597fbc55ea40 [project @ 2002-10-29 17:12:53 by jwe]
jwe
parents: 4064
diff changeset
3092
597fbc55ea40 [project @ 2002-10-29 17:12:53 by jwe]
jwe
parents: 4064
diff changeset
3093 return retval;
597fbc55ea40 [project @ 2002-10-29 17:12:53 by jwe]
jwe
parents: 4064
diff changeset
3094 }
597fbc55ea40 [project @ 2002-10-29 17:12:53 by jwe]
jwe
parents: 4064
diff changeset
3095
2846
52e7c4509983 [project @ 1997-03-26 23:27:35 by jwe]
jwe
parents: 2825
diff changeset
3096 // Make a declaration command.
52e7c4509983 [project @ 1997-03-26 23:27:35 by jwe]
jwe
parents: 2825
diff changeset
3097
16134
ec9c6222ef5a move static parser helper functions to octave_parser class
John W. Eaton <jwe@octave.org>
parents: 16133
diff changeset
3098 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
3099 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
3100 tree_decl_init_list *lst)
2846
52e7c4509983 [project @ 1997-03-26 23:27:35 by jwe]
jwe
parents: 2825
diff changeset
3101 {
52e7c4509983 [project @ 1997-03-26 23:27:35 by jwe]
jwe
parents: 2825
diff changeset
3102 tree_decl_command *retval = 0;
52e7c4509983 [project @ 1997-03-26 23:27:35 by jwe]
jwe
parents: 2825
diff changeset
3103
52e7c4509983 [project @ 1997-03-26 23:27:35 by jwe]
jwe
parents: 2825
diff changeset
3104 int l = tok_val->line ();
52e7c4509983 [project @ 1997-03-26 23:27:35 by jwe]
jwe
parents: 2825
diff changeset
3105 int c = tok_val->column ();
52e7c4509983 [project @ 1997-03-26 23:27:35 by jwe]
jwe
parents: 2825
diff changeset
3106
52e7c4509983 [project @ 1997-03-26 23:27:35 by jwe]
jwe
parents: 2825
diff changeset
3107 switch (tok)
52e7c4509983 [project @ 1997-03-26 23:27:35 by jwe]
jwe
parents: 2825
diff changeset
3108 {
52e7c4509983 [project @ 1997-03-26 23:27:35 by jwe]
jwe
parents: 2825
diff changeset
3109 case GLOBAL:
52e7c4509983 [project @ 1997-03-26 23:27:35 by jwe]
jwe
parents: 2825
diff changeset
3110 retval = new tree_global_command (lst, l, c);
52e7c4509983 [project @ 1997-03-26 23:27:35 by jwe]
jwe
parents: 2825
diff changeset
3111 break;
52e7c4509983 [project @ 1997-03-26 23:27:35 by jwe]
jwe
parents: 2825
diff changeset
3112
14294
9e3983c8963c deprecate the static keyword
John W. Eaton <jwe@octave.org>
parents: 14293
diff changeset
3113 case PERSISTENT:
16153
a57c2c8c8163 move some variables into the octave_parser class
John W. Eaton <jwe@octave.org>
parents: 16151
diff changeset
3114 if (curr_fcn_depth > 0)
14294
9e3983c8963c deprecate the static keyword
John W. Eaton <jwe@octave.org>
parents: 14293
diff changeset
3115 retval = new tree_persistent_command (lst, l, c);
2846
52e7c4509983 [project @ 1997-03-26 23:27:35 by jwe]
jwe
parents: 2825
diff changeset
3116 else
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
3117 {
16288
fe3b9a51e625 rename curr_lexer, curr_parser, CURR_LEXER
John W. Eaton <jwe@octave.org>
parents: 16287
diff changeset
3118 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
3119 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
3120 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
3121 else
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
3122 warning ("ignoring persistent declaration near line %d", l);
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
3123 }
2846
52e7c4509983 [project @ 1997-03-26 23:27:35 by jwe]
jwe
parents: 2825
diff changeset
3124 break;
52e7c4509983 [project @ 1997-03-26 23:27:35 by jwe]
jwe
parents: 2825
diff changeset
3125
52e7c4509983 [project @ 1997-03-26 23:27:35 by jwe]
jwe
parents: 2825
diff changeset
3126 default:
52e7c4509983 [project @ 1997-03-26 23:27:35 by jwe]
jwe
parents: 2825
diff changeset
3127 panic_impossible ();
52e7c4509983 [project @ 1997-03-26 23:27:35 by jwe]
jwe
parents: 2825
diff changeset
3128 break;
52e7c4509983 [project @ 1997-03-26 23:27:35 by jwe]
jwe
parents: 2825
diff changeset
3129 }
52e7c4509983 [project @ 1997-03-26 23:27:35 by jwe]
jwe
parents: 2825
diff changeset
3130
52e7c4509983 [project @ 1997-03-26 23:27:35 by jwe]
jwe
parents: 2825
diff changeset
3131 return retval;
52e7c4509983 [project @ 1997-03-26 23:27:35 by jwe]
jwe
parents: 2825
diff changeset
3132 }
52e7c4509983 [project @ 1997-03-26 23:27:35 by jwe]
jwe
parents: 2825
diff changeset
3133
16273
c5e5f6ccac5d 9/10 commits reworking the lexer
John W. Eaton <jwe@octave.org>
parents: 16265
diff changeset
3134 bool
16287
04a7953496a7 create base class for parser; use reference for curr_lexer
John W. Eaton <jwe@octave.org>
parents: 16285
diff changeset
3135 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
3136 {
c5e5f6ccac5d 9/10 commits reworking the lexer
John W. Eaton <jwe@octave.org>
parents: 16265
diff changeset
3137 bool retval = true;
c5e5f6ccac5d 9/10 commits reworking the lexer
John W. Eaton <jwe@octave.org>
parents: 16265
diff changeset
3138
c5e5f6ccac5d 9/10 commits reworking the lexer
John W. Eaton <jwe@octave.org>
parents: 16265
diff changeset
3139 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
3140
c5e5f6ccac5d 9/10 commits reworking the lexer
John W. Eaton <jwe@octave.org>
parents: 16265
diff changeset
3141 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
3142 {
c5e5f6ccac5d 9/10 commits reworking the lexer
John W. Eaton <jwe@octave.org>
parents: 16265
diff changeset
3143 tree_argument_list *row = *i;
c5e5f6ccac5d 9/10 commits reworking the lexer
John W. Eaton <jwe@octave.org>
parents: 16265
diff changeset
3144
c5e5f6ccac5d 9/10 commits reworking the lexer
John W. Eaton <jwe@octave.org>
parents: 16265
diff changeset
3145 if (row && row->has_magic_tilde ())
c5e5f6ccac5d 9/10 commits reworking the lexer
John W. Eaton <jwe@octave.org>
parents: 16265
diff changeset
3146 {
c5e5f6ccac5d 9/10 commits reworking the lexer
John W. Eaton <jwe@octave.org>
parents: 16265
diff changeset
3147 retval = false;
c5e5f6ccac5d 9/10 commits reworking the lexer
John W. Eaton <jwe@octave.org>
parents: 16265
diff changeset
3148 if (e->is_matrix ())
c5e5f6ccac5d 9/10 commits reworking the lexer
John W. Eaton <jwe@octave.org>
parents: 16265
diff changeset
3149 bison_error ("invalid use of tilde (~) in matrix expression");
c5e5f6ccac5d 9/10 commits reworking the lexer
John W. Eaton <jwe@octave.org>
parents: 16265
diff changeset
3150 else
c5e5f6ccac5d 9/10 commits reworking the lexer
John W. Eaton <jwe@octave.org>
parents: 16265
diff changeset
3151 bison_error ("invalid use of tilde (~) in cell expression");
c5e5f6ccac5d 9/10 commits reworking the lexer
John W. Eaton <jwe@octave.org>
parents: 16265
diff changeset
3152 break;
c5e5f6ccac5d 9/10 commits reworking the lexer
John W. Eaton <jwe@octave.org>
parents: 16265
diff changeset
3153 }
c5e5f6ccac5d 9/10 commits reworking the lexer
John W. Eaton <jwe@octave.org>
parents: 16265
diff changeset
3154 }
c5e5f6ccac5d 9/10 commits reworking the lexer
John W. Eaton <jwe@octave.org>
parents: 16265
diff changeset
3155
c5e5f6ccac5d 9/10 commits reworking the lexer
John W. Eaton <jwe@octave.org>
parents: 16265
diff changeset
3156 return retval;
c5e5f6ccac5d 9/10 commits reworking the lexer
John W. Eaton <jwe@octave.org>
parents: 16265
diff changeset
3157 }
c5e5f6ccac5d 9/10 commits reworking the lexer
John W. Eaton <jwe@octave.org>
parents: 16265
diff changeset
3158
16134
ec9c6222ef5a move static parser helper functions to octave_parser class
John W. Eaton <jwe@octave.org>
parents: 16133
diff changeset
3159 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
3160 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
3161 {
16273
c5e5f6ccac5d 9/10 commits reworking the lexer
John W. Eaton <jwe@octave.org>
parents: 16265
diff changeset
3162 tree_argument_list *retval = 0;
c5e5f6ccac5d 9/10 commits reworking the lexer
John W. Eaton <jwe@octave.org>
parents: 16265
diff changeset
3163
c5e5f6ccac5d 9/10 commits reworking the lexer
John W. Eaton <jwe@octave.org>
parents: 16265
diff changeset
3164 if (e->is_constant ())
c5e5f6ccac5d 9/10 commits reworking the lexer
John W. Eaton <jwe@octave.org>
parents: 16265
diff changeset
3165 {
16285
3389152014ca improve validation of left hand side of assignment expressions in parser
John W. Eaton <jwe@octave.org>
parents: 16284
diff changeset
3166 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
3167
3389152014ca improve validation of left hand side of assignment expressions in parser
John W. Eaton <jwe@octave.org>
parents: 16284
diff changeset
3168 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
3169 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
3170 else
3389152014ca improve validation of left hand side of assignment expressions in parser
John W. Eaton <jwe@octave.org>
parents: 16284
diff changeset
3171 bison_error ("invalid constant left hand side of assignment");
3389152014ca improve validation of left hand side of assignment expressions in parser
John W. Eaton <jwe@octave.org>
parents: 16284
diff changeset
3172
16273
c5e5f6ccac5d 9/10 commits reworking the lexer
John W. Eaton <jwe@octave.org>
parents: 16265
diff changeset
3173 delete e;
c5e5f6ccac5d 9/10 commits reworking the lexer
John W. Eaton <jwe@octave.org>
parents: 16265
diff changeset
3174 }
c5e5f6ccac5d 9/10 commits reworking the lexer
John W. Eaton <jwe@octave.org>
parents: 16265
diff changeset
3175 else
c5e5f6ccac5d 9/10 commits reworking the lexer
John W. Eaton <jwe@octave.org>
parents: 16265
diff changeset
3176 {
16285
3389152014ca improve validation of left hand side of assignment expressions in parser
John W. Eaton <jwe@octave.org>
parents: 16284
diff changeset
3177 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
3178
3389152014ca improve validation of left hand side of assignment expressions in parser
John W. Eaton <jwe@octave.org>
parents: 16284
diff changeset
3179 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
3180
3389152014ca improve validation of left hand side of assignment expressions in parser
John W. Eaton <jwe@octave.org>
parents: 16284
diff changeset
3181 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
3182 {
3389152014ca improve validation of left hand side of assignment expressions in parser
John W. Eaton <jwe@octave.org>
parents: 16284
diff changeset
3183 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
3184
3389152014ca improve validation of left hand side of assignment expressions in parser
John W. Eaton <jwe@octave.org>
parents: 16284
diff changeset
3185 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
3186 {
3389152014ca improve validation of left hand side of assignment expressions in parser
John W. Eaton <jwe@octave.org>
parents: 16284
diff changeset
3187 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
3188 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
3189 delete e;
3389152014ca improve validation of left hand side of assignment expressions in parser
John W. Eaton <jwe@octave.org>
parents: 16284
diff changeset
3190 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
3191 }
3389152014ca improve validation of left hand side of assignment expressions in parser
John W. Eaton <jwe@octave.org>
parents: 16284
diff changeset
3192 }
3389152014ca improve validation of left hand side of assignment expressions in parser
John W. Eaton <jwe@octave.org>
parents: 16284
diff changeset
3193 else
3389152014ca improve validation of left hand side of assignment expressions in parser
John W. Eaton <jwe@octave.org>
parents: 16284
diff changeset
3194 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
3195
3389152014ca improve validation of left hand side of assignment expressions in parser
John W. Eaton <jwe@octave.org>
parents: 16284
diff changeset
3196 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
3197 {
11115c237231 recognize variables when parsing (bug #38576)
John W. Eaton <jwe@octave.org>
parents: 16320
diff changeset
3198 lexer.mark_as_variables (tmp->variable_names ());
11115c237231 recognize variables when parsing (bug #38576)
John W. Eaton <jwe@octave.org>
parents: 16320
diff changeset
3199 retval = tmp;
11115c237231 recognize variables when parsing (bug #38576)
John W. Eaton <jwe@octave.org>
parents: 16320
diff changeset
3200 }
16285
3389152014ca improve validation of left hand side of assignment expressions in parser
John W. Eaton <jwe@octave.org>
parents: 16284
diff changeset
3201 else
3389152014ca improve validation of left hand side of assignment expressions in parser
John W. Eaton <jwe@octave.org>
parents: 16284
diff changeset
3202 {
3389152014ca improve validation of left hand side of assignment expressions in parser
John W. Eaton <jwe@octave.org>
parents: 16284
diff changeset
3203 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
3204 delete tmp;
3389152014ca improve validation of left hand side of assignment expressions in parser
John W. Eaton <jwe@octave.org>
parents: 16284
diff changeset
3205 }
3389152014ca improve validation of left hand side of assignment expressions in parser
John W. Eaton <jwe@octave.org>
parents: 16284
diff changeset
3206
3389152014ca improve validation of left hand side of assignment expressions in parser
John W. Eaton <jwe@octave.org>
parents: 16284
diff changeset
3207 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
3208 retval->mark_as_simple_assign_lhs ();
16273
c5e5f6ccac5d 9/10 commits reworking the lexer
John W. Eaton <jwe@octave.org>
parents: 16265
diff changeset
3209 }
c5e5f6ccac5d 9/10 commits reworking the lexer
John W. Eaton <jwe@octave.org>
parents: 16265
diff changeset
3210
c5e5f6ccac5d 9/10 commits reworking the lexer
John W. Eaton <jwe@octave.org>
parents: 16265
diff changeset
3211 return retval;
10207
76a880a588ce error when using ~ in matrix expression
Jaroslav Hajek <highegg@gmail.com>
parents: 10206
diff changeset
3212 }
76a880a588ce error when using ~ in matrix expression
Jaroslav Hajek <highegg@gmail.com>
parents: 10206
diff changeset
3213
16237
70f465930546 rearrange class heirarchy for tree_cell and tree_matrix
John W. Eaton <jwe@octave.org>
parents: 16210
diff changeset
3214 // Finish building an array_list.
1623
fa7a847f9b92 [project @ 1995-11-06 18:05:09 by jwe]
jwe
parents: 1607
diff changeset
3215
16134
ec9c6222ef5a move static parser helper functions to octave_parser class
John W. Eaton <jwe@octave.org>
parents: 16133
diff changeset
3216 tree_expression *
16287
04a7953496a7 create base class for parser; use reference for curr_lexer
John W. Eaton <jwe@octave.org>
parents: 16285
diff changeset
3217 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
3218 {
16237
70f465930546 rearrange class heirarchy for tree_cell and tree_matrix
John W. Eaton <jwe@octave.org>
parents: 16210
diff changeset
3219 tree_expression *retval = array_list;
3110
fe2d1ae8926b [project @ 1997-11-21 02:11:19 by jwe]
jwe
parents: 3099
diff changeset
3220
10067
6f79338c269b omission from last patch
Jaroslav Hajek <highegg@gmail.com>
parents: 9794
diff changeset
3221 unwind_protect frame;
6f79338c269b omission from last patch
Jaroslav Hajek <highegg@gmail.com>
parents: 9794
diff changeset
3222
6f79338c269b omission from last patch
Jaroslav Hajek <highegg@gmail.com>
parents: 9794
diff changeset
3223 frame.protect_var (error_state);
6f79338c269b omission from last patch
Jaroslav Hajek <highegg@gmail.com>
parents: 9794
diff changeset
3224 frame.protect_var (warning_state);
6f79338c269b omission from last patch
Jaroslav Hajek <highegg@gmail.com>
parents: 9794
diff changeset
3225
6f79338c269b omission from last patch
Jaroslav Hajek <highegg@gmail.com>
parents: 9794
diff changeset
3226 frame.protect_var (discard_error_messages);
6f79338c269b omission from last patch
Jaroslav Hajek <highegg@gmail.com>
parents: 9794
diff changeset
3227 frame.protect_var (discard_warning_messages);
4452
f3c21a1d1c62 [project @ 2003-07-09 23:20:18 by jwe]
jwe
parents: 4426
diff changeset
3228
3815
c554ad71bafc [project @ 2001-04-19 19:50:52 by jwe]
jwe
parents: 3802
diff changeset
3229 discard_error_messages = true;
4452
f3c21a1d1c62 [project @ 2003-07-09 23:20:18 by jwe]
jwe
parents: 4426
diff changeset
3230 discard_warning_messages = true;
1623
fa7a847f9b92 [project @ 1995-11-06 18:05:09 by jwe]
jwe
parents: 1607
diff changeset
3231
16237
70f465930546 rearrange class heirarchy for tree_cell and tree_matrix
John W. Eaton <jwe@octave.org>
parents: 16210
diff changeset
3232 if (array_list->all_elements_are_constant ())
1829
7d2982b55242 [project @ 1996-02-02 14:12:59 by jwe]
jwe
parents: 1826
diff changeset
3233 {
16237
70f465930546 rearrange class heirarchy for tree_cell and tree_matrix
John W. Eaton <jwe@octave.org>
parents: 16210
diff changeset
3234 octave_value tmp = array_list->rvalue1 ();
1623
fa7a847f9b92 [project @ 1995-11-06 18:05:09 by jwe]
jwe
parents: 1607
diff changeset
3235
3489
cbee5fbb696d [project @ 2000-01-28 09:14:32 by jwe]
jwe
parents: 3485
diff changeset
3236 if (! (error_state || warning_state))
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
3237 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
3238 tree_constant *tc_retval
16237
70f465930546 rearrange class heirarchy for tree_cell and tree_matrix
John W. Eaton <jwe@octave.org>
parents: 16210
diff changeset
3239 = new tree_constant (tmp, array_list->line (),
70f465930546 rearrange class heirarchy for tree_cell and tree_matrix
John W. Eaton <jwe@octave.org>
parents: 16210
diff changeset
3240 array_list->column ());
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
3241
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
3242 std::ostringstream buf;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
3243
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
3244 tree_print_code tpc (buf);
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
3245
16237
70f465930546 rearrange class heirarchy for tree_cell and tree_matrix
John W. Eaton <jwe@octave.org>
parents: 16210
diff changeset
3246 array_list->accept (tpc);
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
3247
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
3248 tc_retval->stash_original_text (buf.str ());
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
3249
16237
70f465930546 rearrange class heirarchy for tree_cell and tree_matrix
John W. Eaton <jwe@octave.org>
parents: 16210
diff changeset
3250 delete array_list;
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
3251
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
3252 retval = tc_retval;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
3253 }
1623
fa7a847f9b92 [project @ 1995-11-06 18:05:09 by jwe]
jwe
parents: 1607
diff changeset
3254 }
3110
fe2d1ae8926b [project @ 1997-11-21 02:11:19 by jwe]
jwe
parents: 3099
diff changeset
3255
1623
fa7a847f9b92 [project @ 1995-11-06 18:05:09 by jwe]
jwe
parents: 1607
diff changeset
3256 return retval;
fa7a847f9b92 [project @ 1995-11-06 18:05:09 by jwe]
jwe
parents: 1607
diff changeset
3257 }
fa7a847f9b92 [project @ 1995-11-06 18:05:09 by jwe]
jwe
parents: 1607
diff changeset
3258
16237
70f465930546 rearrange class heirarchy for tree_cell and tree_matrix
John W. Eaton <jwe@octave.org>
parents: 16210
diff changeset
3259 // 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
3260
70f465930546 rearrange class heirarchy for tree_cell and tree_matrix
John W. Eaton <jwe@octave.org>
parents: 16210
diff changeset
3261 tree_expression *
16287
04a7953496a7 create base class for parser; use reference for curr_lexer
John W. Eaton <jwe@octave.org>
parents: 16285
diff changeset
3262 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
3263 {
16924
aebb54d99dba improve compatibility of parsing of matrices and cell arrays
John W. Eaton <jwe@octave.org>
parents: 16850
diff changeset
3264 return (m
aebb54d99dba improve compatibility of parsing of matrices and cell arrays
John W. Eaton <jwe@octave.org>
parents: 16850
diff changeset
3265 ? finish_array_list (m)
aebb54d99dba improve compatibility of parsing of matrices and cell arrays
John W. Eaton <jwe@octave.org>
parents: 16850
diff changeset
3266 : 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
3267 }
70f465930546 rearrange class heirarchy for tree_cell and tree_matrix
John W. Eaton <jwe@octave.org>
parents: 16210
diff changeset
3268
3351
8623649c967c [project @ 1999-11-15 16:17:01 by jwe]
jwe
parents: 3347
diff changeset
3269 // Finish building a cell list.
8623649c967c [project @ 1999-11-15 16:17:01 by jwe]
jwe
parents: 3347
diff changeset
3270
16134
ec9c6222ef5a move static parser helper functions to octave_parser class
John W. Eaton <jwe@octave.org>
parents: 16133
diff changeset
3271 tree_expression *
16287
04a7953496a7 create base class for parser; use reference for curr_lexer
John W. Eaton <jwe@octave.org>
parents: 16285
diff changeset
3272 octave_base_parser::finish_cell (tree_cell *c)
3351
8623649c967c [project @ 1999-11-15 16:17:01 by jwe]
jwe
parents: 3347
diff changeset
3273 {
16924
aebb54d99dba improve compatibility of parsing of matrices and cell arrays
John W. Eaton <jwe@octave.org>
parents: 16850
diff changeset
3274 return (c
aebb54d99dba improve compatibility of parsing of matrices and cell arrays
John W. Eaton <jwe@octave.org>
parents: 16850
diff changeset
3275 ? finish_array_list (c)
aebb54d99dba improve compatibility of parsing of matrices and cell arrays
John W. Eaton <jwe@octave.org>
parents: 16850
diff changeset
3276 : new tree_constant (octave_value (Cell ())));
3351
8623649c967c [project @ 1999-11-15 16:17:01 by jwe]
jwe
parents: 3347
diff changeset
3277 }
8623649c967c [project @ 1999-11-15 16:17:01 by jwe]
jwe
parents: 3347
diff changeset
3278
16134
ec9c6222ef5a move static parser helper functions to octave_parser class
John W. Eaton <jwe@octave.org>
parents: 16133
diff changeset
3279 void
16287
04a7953496a7 create base class for parser; use reference for curr_lexer
John W. Eaton <jwe@octave.org>
parents: 16285
diff changeset
3280 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
3281 {
16153
a57c2c8c8163 move some variables into the octave_parser class
John W. Eaton <jwe@octave.org>
parents: 16151
diff changeset
3282 if (curr_fcn_depth > 0)
1511
74f9e88a2c12 [project @ 1995-10-03 10:49:31 by jwe]
jwe
parents: 1491
diff changeset
3283 {
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
3284 tree_statement *tmp = t->back ();
1607
795527e9db19 [project @ 1995-11-02 13:03:36 by jwe]
jwe
parents: 1588
diff changeset
3285
1511
74f9e88a2c12 [project @ 1995-10-03 10:49:31 by jwe]
jwe
parents: 1491
diff changeset
3286 if (tmp->is_expression ())
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
3287 warning_with_id
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
3288 ("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
3289 "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
3290 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
3291 }
74f9e88a2c12 [project @ 1995-10-03 10:49:31 by jwe]
jwe
parents: 1491
diff changeset
3292 }
1994
c2d20f365b84 [project @ 1996-03-03 01:19:32 by jwe]
jwe
parents: 1884
diff changeset
3293
16134
ec9c6222ef5a move static parser helper functions to octave_parser class
John W. Eaton <jwe@octave.org>
parents: 16133
diff changeset
3294 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
3295 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
3296 char sep, bool warn_missing_semi)
2525
8561d88be5f2 [project @ 1996-11-17 21:23:31 by jwe]
jwe
parents: 2524
diff changeset
3297 {
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
3298 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
3299
2525
8561d88be5f2 [project @ 1996-11-17 21:23:31 by jwe]
jwe
parents: 2524
diff changeset
3300 switch (sep)
8561d88be5f2 [project @ 1996-11-17 21:23:31 by jwe]
jwe
parents: 2524
diff changeset
3301 {
8561d88be5f2 [project @ 1996-11-17 21:23:31 by jwe]
jwe
parents: 2524
diff changeset
3302 case ';':
8658
73c4516fae10 New evaluator and debugger derived from tree-walker class
John W. Eaton <jwe@octave.org>
parents: 8471
diff changeset
3303 tmp->set_print_flag (false);
2525
8561d88be5f2 [project @ 1996-11-17 21:23:31 by jwe]
jwe
parents: 2524
diff changeset
3304 break;
8561d88be5f2 [project @ 1996-11-17 21:23:31 by jwe]
jwe
parents: 2524
diff changeset
3305
8561d88be5f2 [project @ 1996-11-17 21:23:31 by jwe]
jwe
parents: 2524
diff changeset
3306 case 0:
8561d88be5f2 [project @ 1996-11-17 21:23:31 by jwe]
jwe
parents: 2524
diff changeset
3307 case ',':
8561d88be5f2 [project @ 1996-11-17 21:23:31 by jwe]
jwe
parents: 2524
diff changeset
3308 case '\n':
8658
73c4516fae10 New evaluator and debugger derived from tree-walker class
John W. Eaton <jwe@octave.org>
parents: 8471
diff changeset
3309 tmp->set_print_flag (true);
2525
8561d88be5f2 [project @ 1996-11-17 21:23:31 by jwe]
jwe
parents: 2524
diff changeset
3310 if (warn_missing_semi)
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
3311 maybe_warn_missing_semi (list);
2525
8561d88be5f2 [project @ 1996-11-17 21:23:31 by jwe]
jwe
parents: 2524
diff changeset
3312 break;
8561d88be5f2 [project @ 1996-11-17 21:23:31 by jwe]
jwe
parents: 2524
diff changeset
3313
8561d88be5f2 [project @ 1996-11-17 21:23:31 by jwe]
jwe
parents: 2524
diff changeset
3314 default:
8561d88be5f2 [project @ 1996-11-17 21:23:31 by jwe]
jwe
parents: 2524
diff changeset
3315 warning ("unrecognized separator type!");
8561d88be5f2 [project @ 1996-11-17 21:23:31 by jwe]
jwe
parents: 2524
diff changeset
3316 break;
8561d88be5f2 [project @ 1996-11-17 21:23:31 by jwe]
jwe
parents: 2524
diff changeset
3317 }
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
3318
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
3319 // 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
3320 // 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
3321
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
3322 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
3323 {
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
3324 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
3325 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
3326 }
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
3327
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
3328 return list;
2525
8561d88be5f2 [project @ 1996-11-17 21:23:31 by jwe]
jwe
parents: 2524
diff changeset
3329 }
8561d88be5f2 [project @ 1996-11-17 21:23:31 by jwe]
jwe
parents: 2524
diff changeset
3330
17693
efbe746f8fa8 eliminate octave_comment_buffer singleton
John W. Eaton <jwe@octave.org>
parents: 17673
diff changeset
3331 // Finish building a statement.
efbe746f8fa8 eliminate octave_comment_buffer singleton
John W. Eaton <jwe@octave.org>
parents: 17673
diff changeset
3332 template <class T>
efbe746f8fa8 eliminate octave_comment_buffer singleton
John W. Eaton <jwe@octave.org>
parents: 17673
diff changeset
3333 tree_statement *
efbe746f8fa8 eliminate octave_comment_buffer singleton
John W. Eaton <jwe@octave.org>
parents: 17673
diff changeset
3334 octave_base_parser::make_statement (T *arg)
efbe746f8fa8 eliminate octave_comment_buffer singleton
John W. Eaton <jwe@octave.org>
parents: 17673
diff changeset
3335 {
efbe746f8fa8 eliminate octave_comment_buffer singleton
John W. Eaton <jwe@octave.org>
parents: 17673
diff changeset
3336 octave_comment_list *comment = lexer.get_comment ();
efbe746f8fa8 eliminate octave_comment_buffer singleton
John W. Eaton <jwe@octave.org>
parents: 17673
diff changeset
3337
efbe746f8fa8 eliminate octave_comment_buffer singleton
John W. Eaton <jwe@octave.org>
parents: 17673
diff changeset
3338 return new tree_statement (arg, comment);
efbe746f8fa8 eliminate octave_comment_buffer singleton
John W. Eaton <jwe@octave.org>
parents: 17673
diff changeset
3339 }
efbe746f8fa8 eliminate octave_comment_buffer singleton
John W. Eaton <jwe@octave.org>
parents: 17673
diff changeset
3340
16134
ec9c6222ef5a move static parser helper functions to octave_parser class
John W. Eaton <jwe@octave.org>
parents: 16133
diff changeset
3341 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
3342 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
3343 {
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
3344 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
3345 }
d6c0d5f208de parse.y: avoid storing null statements in statement lists
John W. Eaton <jwe@octave.org>
parents: 8447
diff changeset
3346
16134
ec9c6222ef5a move static parser helper functions to octave_parser class
John W. Eaton <jwe@octave.org>
parents: 16133
diff changeset
3347 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
3348 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
3349 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
3350 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
3351 {
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
3352 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
3353
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
3354 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
3355
02de6775f1fe parse.y: always append statements to list, but remove null statements after seeing separator
John W. Eaton <jwe@octave.org>
parents: 8448
diff changeset
3356 return list;
8448
d6c0d5f208de parse.y: avoid storing null statements in statement lists
John W. Eaton <jwe@octave.org>
parents: 8447
diff changeset
3357 }
d6c0d5f208de parse.y: avoid storing null statements in statement lists
John W. Eaton <jwe@octave.org>
parents: 8447
diff changeset
3358
16145
edddf8903f15 maint: reorder functions in oct-parse.yy
John W. Eaton <jwe@octave.org>
parents: 16142
diff changeset
3359 void
16287
04a7953496a7 create base class for parser; use reference for curr_lexer
John W. Eaton <jwe@octave.org>
parents: 16285
diff changeset
3360 octave_base_parser::bison_error (const char *s)
16145
edddf8903f15 maint: reorder functions in oct-parse.yy
John W. Eaton <jwe@octave.org>
parents: 16142
diff changeset
3361 {
16288
fe3b9a51e625 rename curr_lexer, curr_parser, CURR_LEXER
John W. Eaton <jwe@octave.org>
parents: 16287
diff changeset
3362 int err_col = lexer.current_input_column - 1;
16145
edddf8903f15 maint: reorder functions in oct-parse.yy
John W. Eaton <jwe@octave.org>
parents: 16142
diff changeset
3363
edddf8903f15 maint: reorder functions in oct-parse.yy
John W. Eaton <jwe@octave.org>
parents: 16142
diff changeset
3364 std::ostringstream output_buf;
edddf8903f15 maint: reorder functions in oct-parse.yy
John W. Eaton <jwe@octave.org>
parents: 16142
diff changeset
3365
16288
fe3b9a51e625 rename curr_lexer, curr_parser, CURR_LEXER
John W. Eaton <jwe@octave.org>
parents: 16287
diff changeset
3366 if (lexer.reading_fcn_file || lexer.reading_script_file || lexer.reading_classdef_file)
fe3b9a51e625 rename curr_lexer, curr_parser, CURR_LEXER
John W. Eaton <jwe@octave.org>
parents: 16287
diff changeset
3367 output_buf << "parse error near line " << lexer.input_line_number
fe3b9a51e625 rename curr_lexer, curr_parser, CURR_LEXER
John W. Eaton <jwe@octave.org>
parents: 16287
diff changeset
3368 << " 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
3369 else
edddf8903f15 maint: reorder functions in oct-parse.yy
John W. Eaton <jwe@octave.org>
parents: 16142
diff changeset
3370 output_buf << "parse error:";
edddf8903f15 maint: reorder functions in oct-parse.yy
John W. Eaton <jwe@octave.org>
parents: 16142
diff changeset
3371
edddf8903f15 maint: reorder functions in oct-parse.yy
John W. Eaton <jwe@octave.org>
parents: 16142
diff changeset
3372 if (s && strcmp (s, "parse error") != 0)
edddf8903f15 maint: reorder functions in oct-parse.yy
John W. Eaton <jwe@octave.org>
parents: 16142
diff changeset
3373 output_buf << "\n\n " << s;
edddf8903f15 maint: reorder functions in oct-parse.yy
John W. Eaton <jwe@octave.org>
parents: 16142
diff changeset
3374
edddf8903f15 maint: reorder functions in oct-parse.yy
John W. Eaton <jwe@octave.org>
parents: 16142
diff changeset
3375 output_buf << "\n\n";
edddf8903f15 maint: reorder functions in oct-parse.yy
John W. Eaton <jwe@octave.org>
parents: 16142
diff changeset
3376
16288
fe3b9a51e625 rename curr_lexer, curr_parser, CURR_LEXER
John W. Eaton <jwe@octave.org>
parents: 16287
diff changeset
3377 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
3378
0467d68ca891 move current_input_line to lexical_feedback class
John W. Eaton <jwe@octave.org>
parents: 16203
diff changeset
3379 if (! curr_line.empty ())
16145
edddf8903f15 maint: reorder functions in oct-parse.yy
John W. Eaton <jwe@octave.org>
parents: 16142
diff changeset
3380 {
16207
0467d68ca891 move current_input_line to lexical_feedback class
John W. Eaton <jwe@octave.org>
parents: 16203
diff changeset
3381 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
3382
0467d68ca891 move current_input_line to lexical_feedback class
John W. Eaton <jwe@octave.org>
parents: 16203
diff changeset
3383 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
3384 curr_line.resize (len-1);
16145
edddf8903f15 maint: reorder functions in oct-parse.yy
John W. Eaton <jwe@octave.org>
parents: 16142
diff changeset
3385
edddf8903f15 maint: reorder functions in oct-parse.yy
John W. Eaton <jwe@octave.org>
parents: 16142
diff changeset
3386 // 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
3387
16207
0467d68ca891 move current_input_line to lexical_feedback class
John W. Eaton <jwe@octave.org>
parents: 16203
diff changeset
3388 output_buf << ">>> " << curr_line << "\n";
16145
edddf8903f15 maint: reorder functions in oct-parse.yy
John W. Eaton <jwe@octave.org>
parents: 16142
diff changeset
3389
edddf8903f15 maint: reorder functions in oct-parse.yy
John W. Eaton <jwe@octave.org>
parents: 16142
diff changeset
3390 if (err_col == 0)
edddf8903f15 maint: reorder functions in oct-parse.yy
John W. Eaton <jwe@octave.org>
parents: 16142
diff changeset
3391 err_col = len;
edddf8903f15 maint: reorder functions in oct-parse.yy
John W. Eaton <jwe@octave.org>
parents: 16142
diff changeset
3392
edddf8903f15 maint: reorder functions in oct-parse.yy
John W. Eaton <jwe@octave.org>
parents: 16142
diff changeset
3393 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
3394 output_buf << " ";
edddf8903f15 maint: reorder functions in oct-parse.yy
John W. Eaton <jwe@octave.org>
parents: 16142
diff changeset
3395
edddf8903f15 maint: reorder functions in oct-parse.yy
John W. Eaton <jwe@octave.org>
parents: 16142
diff changeset
3396 output_buf << "^";
edddf8903f15 maint: reorder functions in oct-parse.yy
John W. Eaton <jwe@octave.org>
parents: 16142
diff changeset
3397 }
edddf8903f15 maint: reorder functions in oct-parse.yy
John W. Eaton <jwe@octave.org>
parents: 16142
diff changeset
3398
edddf8903f15 maint: reorder functions in oct-parse.yy
John W. Eaton <jwe@octave.org>
parents: 16142
diff changeset
3399 output_buf << "\n";
edddf8903f15 maint: reorder functions in oct-parse.yy
John W. Eaton <jwe@octave.org>
parents: 16142
diff changeset
3400
edddf8903f15 maint: reorder functions in oct-parse.yy
John W. Eaton <jwe@octave.org>
parents: 16142
diff changeset
3401 std::string msg = output_buf.str ();
edddf8903f15 maint: reorder functions in oct-parse.yy
John W. Eaton <jwe@octave.org>
parents: 16142
diff changeset
3402
edddf8903f15 maint: reorder functions in oct-parse.yy
John W. Eaton <jwe@octave.org>
parents: 16142
diff changeset
3403 parse_error ("%s", msg.c_str ());
edddf8903f15 maint: reorder functions in oct-parse.yy
John W. Eaton <jwe@octave.org>
parents: 16142
diff changeset
3404 }
edddf8903f15 maint: reorder functions in oct-parse.yy
John W. Eaton <jwe@octave.org>
parents: 16142
diff changeset
3405
16287
04a7953496a7 create base class for parser; use reference for curr_lexer
John W. Eaton <jwe@octave.org>
parents: 16285
diff changeset
3406 int
04a7953496a7 create base class for parser; use reference for curr_lexer
John W. Eaton <jwe@octave.org>
parents: 16285
diff changeset
3407 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
3408 {
04a7953496a7 create base class for parser; use reference for curr_lexer
John W. Eaton <jwe@octave.org>
parents: 16285
diff changeset
3409 return octave_parse (*this);
04a7953496a7 create base class for parser; use reference for curr_lexer
John W. Eaton <jwe@octave.org>
parents: 16285
diff changeset
3410 }
04a7953496a7 create base class for parser; use reference for curr_lexer
John W. Eaton <jwe@octave.org>
parents: 16285
diff changeset
3411
16294
0925d1f6875e push parser/lexer interface
John W. Eaton <jwe@octave.org>
parents: 16293
diff changeset
3412 octave_push_parser::~octave_push_parser (void)
0925d1f6875e push parser/lexer interface
John W. Eaton <jwe@octave.org>
parents: 16293
diff changeset
3413 {
0925d1f6875e push parser/lexer interface
John W. Eaton <jwe@octave.org>
parents: 16293
diff changeset
3414 yypstate_delete (static_cast<yypstate *> (parser_state));
0925d1f6875e push parser/lexer interface
John W. Eaton <jwe@octave.org>
parents: 16293
diff changeset
3415 }
0925d1f6875e push parser/lexer interface
John W. Eaton <jwe@octave.org>
parents: 16293
diff changeset
3416
0925d1f6875e push parser/lexer interface
John W. Eaton <jwe@octave.org>
parents: 16293
diff changeset
3417 void
0925d1f6875e push parser/lexer interface
John W. Eaton <jwe@octave.org>
parents: 16293
diff changeset
3418 octave_push_parser::init (void)
0925d1f6875e push parser/lexer interface
John W. Eaton <jwe@octave.org>
parents: 16293
diff changeset
3419 {
0925d1f6875e push parser/lexer interface
John W. Eaton <jwe@octave.org>
parents: 16293
diff changeset
3420 parser_state = yypstate_new ();
0925d1f6875e push parser/lexer interface
John W. Eaton <jwe@octave.org>
parents: 16293
diff changeset
3421 }
0925d1f6875e push parser/lexer interface
John W. Eaton <jwe@octave.org>
parents: 16293
diff changeset
3422
0925d1f6875e push parser/lexer interface
John W. Eaton <jwe@octave.org>
parents: 16293
diff changeset
3423 // 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
3424 // finish the parse.
0925d1f6875e push parser/lexer interface
John W. Eaton <jwe@octave.org>
parents: 16293
diff changeset
3425
0925d1f6875e push parser/lexer interface
John W. Eaton <jwe@octave.org>
parents: 16293
diff changeset
3426 int
0925d1f6875e push parser/lexer interface
John W. Eaton <jwe@octave.org>
parents: 16293
diff changeset
3427 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
3428 {
0925d1f6875e push parser/lexer interface
John W. Eaton <jwe@octave.org>
parents: 16293
diff changeset
3429 int status = -1;
0925d1f6875e push parser/lexer interface
John W. Eaton <jwe@octave.org>
parents: 16293
diff changeset
3430
0925d1f6875e push parser/lexer interface
John W. Eaton <jwe@octave.org>
parents: 16293
diff changeset
3431 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
3432
0925d1f6875e push parser/lexer interface
John W. Eaton <jwe@octave.org>
parents: 16293
diff changeset
3433 do
0925d1f6875e push parser/lexer interface
John W. Eaton <jwe@octave.org>
parents: 16293
diff changeset
3434 {
0925d1f6875e push parser/lexer interface
John W. Eaton <jwe@octave.org>
parents: 16293
diff changeset
3435 YYSTYPE lval;
0925d1f6875e push parser/lexer interface
John W. Eaton <jwe@octave.org>
parents: 16293
diff changeset
3436
0925d1f6875e push parser/lexer interface
John W. Eaton <jwe@octave.org>
parents: 16293
diff changeset
3437 int token = octave_lex (&lval, scanner);
0925d1f6875e push parser/lexer interface
John W. Eaton <jwe@octave.org>
parents: 16293
diff changeset
3438
0925d1f6875e push parser/lexer interface
John W. Eaton <jwe@octave.org>
parents: 16293
diff changeset
3439 if (token < 0)
0925d1f6875e push parser/lexer interface
John W. Eaton <jwe@octave.org>
parents: 16293
diff changeset
3440 {
0925d1f6875e push parser/lexer interface
John W. Eaton <jwe@octave.org>
parents: 16293
diff changeset
3441 if (! eof && lexer.at_end_of_buffer ())
0925d1f6875e push parser/lexer interface
John W. Eaton <jwe@octave.org>
parents: 16293
diff changeset
3442 {
0925d1f6875e push parser/lexer interface
John W. Eaton <jwe@octave.org>
parents: 16293
diff changeset
3443 status = -1;
0925d1f6875e push parser/lexer interface
John W. Eaton <jwe@octave.org>
parents: 16293
diff changeset
3444 break;
0925d1f6875e push parser/lexer interface
John W. Eaton <jwe@octave.org>
parents: 16293
diff changeset
3445 }
0925d1f6875e push parser/lexer interface
John W. Eaton <jwe@octave.org>
parents: 16293
diff changeset
3446 }
0925d1f6875e push parser/lexer interface
John W. Eaton <jwe@octave.org>
parents: 16293
diff changeset
3447
0925d1f6875e push parser/lexer interface
John W. Eaton <jwe@octave.org>
parents: 16293
diff changeset
3448 yypstate *pstate = static_cast<yypstate *> (parser_state);
0925d1f6875e push parser/lexer interface
John W. Eaton <jwe@octave.org>
parents: 16293
diff changeset
3449
0925d1f6875e push parser/lexer interface
John W. Eaton <jwe@octave.org>
parents: 16293
diff changeset
3450 status = octave_push_parse (pstate, token, &lval, *this);
0925d1f6875e push parser/lexer interface
John W. Eaton <jwe@octave.org>
parents: 16293
diff changeset
3451 }
0925d1f6875e push parser/lexer interface
John W. Eaton <jwe@octave.org>
parents: 16293
diff changeset
3452 while (status == YYPUSH_MORE);
0925d1f6875e push parser/lexer interface
John W. Eaton <jwe@octave.org>
parents: 16293
diff changeset
3453
0925d1f6875e push parser/lexer interface
John W. Eaton <jwe@octave.org>
parents: 16293
diff changeset
3454 return status;
0925d1f6875e push parser/lexer interface
John W. Eaton <jwe@octave.org>
parents: 16293
diff changeset
3455 }
0925d1f6875e push parser/lexer interface
John W. Eaton <jwe@octave.org>
parents: 16293
diff changeset
3456
3021
18d64612e67a [project @ 1997-06-03 22:18:56 by jwe]
jwe
parents: 3016
diff changeset
3457 static void
10067
6f79338c269b omission from last patch
Jaroslav Hajek <highegg@gmail.com>
parents: 9794
diff changeset
3458 safe_fclose (FILE *f)
3021
18d64612e67a [project @ 1997-06-03 22:18:56 by jwe]
jwe
parents: 3016
diff changeset
3459 {
18d64612e67a [project @ 1997-06-03 22:18:56 by jwe]
jwe
parents: 3016
diff changeset
3460 if (f)
18d64612e67a [project @ 1997-06-03 22:18:56 by jwe]
jwe
parents: 3016
diff changeset
3461 fclose (static_cast<FILE *> (f));
18d64612e67a [project @ 1997-06-03 22:18:56 by jwe]
jwe
parents: 3016
diff changeset
3462 }
18d64612e67a [project @ 1997-06-03 22:18:56 by jwe]
jwe
parents: 3016
diff changeset
3463
7336
745a8299c2b5 [project @ 2007-12-28 20:56:55 by jwe]
jwe
parents: 7017
diff changeset
3464 static octave_function *
16203
127cccb037bf move more global parser and lexer variables to classes
John W. Eaton <jwe@octave.org>
parents: 16199
diff changeset
3465 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
3466 const std::string& dispatch_type,
16153
a57c2c8c8163 move some variables into the octave_parser class
John W. Eaton <jwe@octave.org>
parents: 16151
diff changeset
3467 bool require_file, bool force_script, bool autoload,
a57c2c8c8163 move some variables into the octave_parser class
John W. Eaton <jwe@octave.org>
parents: 16151
diff changeset
3468 bool relative_lookup, const std::string& warn_for)
3021
18d64612e67a [project @ 1997-06-03 22:18:56 by jwe]
jwe
parents: 3016
diff changeset
3469 {
10067
6f79338c269b omission from last patch
Jaroslav Hajek <highegg@gmail.com>
parents: 9794
diff changeset
3470 unwind_protect frame;
3021
18d64612e67a [project @ 1997-06-03 22:18:56 by jwe]
jwe
parents: 3016
diff changeset
3471
7336
745a8299c2b5 [project @ 2007-12-28 20:56:55 by jwe]
jwe
parents: 7017
diff changeset
3472 octave_function *fcn_ptr = 0;
3021
18d64612e67a [project @ 1997-06-03 22:18:56 by jwe]
jwe
parents: 3016
diff changeset
3473
18d64612e67a [project @ 1997-06-03 22:18:56 by jwe]
jwe
parents: 3016
diff changeset
3474 // Open function file and parse.
18d64612e67a [project @ 1997-06-03 22:18:56 by jwe]
jwe
parents: 3016
diff changeset
3475
18d64612e67a [project @ 1997-06-03 22:18:56 by jwe]
jwe
parents: 3016
diff changeset
3476 FILE *in_stream = command_editor::get_input_stream ();
18d64612e67a [project @ 1997-06-03 22:18:56 by jwe]
jwe
parents: 3016
diff changeset
3477
10067
6f79338c269b omission from last patch
Jaroslav Hajek <highegg@gmail.com>
parents: 9794
diff changeset
3478 frame.add_fcn (command_editor::set_input_stream, in_stream);
6f79338c269b omission from last patch
Jaroslav Hajek <highegg@gmail.com>
parents: 9794
diff changeset
3479
12989
00235a6446da eliminate duplication of internal variables controlling command history
John W. Eaton <jwe@octave.org>
parents: 12973
diff changeset
3480 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
3481 command_history::ignoring_entries ());
00235a6446da eliminate duplication of internal variables controlling command history
John W. Eaton <jwe@octave.org>
parents: 12973
diff changeset
3482
7715
5b4d278ec828 parse scripts completely before executing
John W. Eaton <jwe@octave.org>
parents: 7699
diff changeset
3483 command_history::ignore_entries ();
5b4d278ec828 parse scripts completely before executing
John W. Eaton <jwe@octave.org>
parents: 7699
diff changeset
3484
16198
2c5c538be353 clean up input.cc and eliminate ff_instream global variable
John W. Eaton <jwe@octave.org>
parents: 16195
diff changeset
3485 FILE *ffile = 0;
2c5c538be353 clean up input.cc and eliminate ff_instream global variable
John W. Eaton <jwe@octave.org>
parents: 16195
diff changeset
3486
16203
127cccb037bf move more global parser and lexer variables to classes
John W. Eaton <jwe@octave.org>
parents: 16199
diff changeset
3487 if (! full_file.empty ())
127cccb037bf move more global parser and lexer variables to classes
John W. Eaton <jwe@octave.org>
parents: 16199
diff changeset
3488 ffile = gnulib::fopen (full_file.c_str (), "rb");
3021
18d64612e67a [project @ 1997-06-03 22:18:56 by jwe]
jwe
parents: 3016
diff changeset
3489
10067
6f79338c269b omission from last patch
Jaroslav Hajek <highegg@gmail.com>
parents: 9794
diff changeset
3490 frame.add_fcn (safe_fclose, ffile);
3021
18d64612e67a [project @ 1997-06-03 22:18:56 by jwe]
jwe
parents: 3016
diff changeset
3491
18d64612e67a [project @ 1997-06-03 22:18:56 by jwe]
jwe
parents: 3016
diff changeset
3492 if (ffile)
18d64612e67a [project @ 1997-06-03 22:18:56 by jwe]
jwe
parents: 3016
diff changeset
3493 {
16287
04a7953496a7 create base class for parser; use reference for curr_lexer
John W. Eaton <jwe@octave.org>
parents: 16285
diff changeset
3494 // 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
3495 frame.protect_var (LEXER);
fe3b9a51e625 rename curr_lexer, curr_parser, CURR_LEXER
John W. Eaton <jwe@octave.org>
parents: 16287
diff changeset
3496
fe3b9a51e625 rename curr_lexer, curr_parser, CURR_LEXER
John W. Eaton <jwe@octave.org>
parents: 16287
diff changeset
3497 octave_parser parser (ffile);
fe3b9a51e625 rename curr_lexer, curr_parser, CURR_LEXER
John W. Eaton <jwe@octave.org>
parents: 16287
diff changeset
3498
fe3b9a51e625 rename curr_lexer, curr_parser, CURR_LEXER
John W. Eaton <jwe@octave.org>
parents: 16287
diff changeset
3499 parser.curr_class_name = dispatch_type;
fe3b9a51e625 rename curr_lexer, curr_parser, CURR_LEXER
John W. Eaton <jwe@octave.org>
parents: 16287
diff changeset
3500 parser.autoloading = autoload;
fe3b9a51e625 rename curr_lexer, curr_parser, CURR_LEXER
John W. Eaton <jwe@octave.org>
parents: 16287
diff changeset
3501 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
3502
fe3b9a51e625 rename curr_lexer, curr_parser, CURR_LEXER
John W. Eaton <jwe@octave.org>
parents: 16287
diff changeset
3503 parser.lexer.force_script = force_script;
fe3b9a51e625 rename curr_lexer, curr_parser, CURR_LEXER
John W. Eaton <jwe@octave.org>
parents: 16287
diff changeset
3504 parser.lexer.prep_for_file ();
fe3b9a51e625 rename curr_lexer, curr_parser, CURR_LEXER
John W. Eaton <jwe@octave.org>
parents: 16287
diff changeset
3505 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
3506
fe3b9a51e625 rename curr_lexer, curr_parser, CURR_LEXER
John W. Eaton <jwe@octave.org>
parents: 16287
diff changeset
3507 parser.lexer.fcn_file_name = file;
fe3b9a51e625 rename curr_lexer, curr_parser, CURR_LEXER
John W. Eaton <jwe@octave.org>
parents: 16287
diff changeset
3508 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
3509
fe3b9a51e625 rename curr_lexer, curr_parser, CURR_LEXER
John W. Eaton <jwe@octave.org>
parents: 16287
diff changeset
3510 int status = parser.run ();
fe3b9a51e625 rename curr_lexer, curr_parser, CURR_LEXER
John W. Eaton <jwe@octave.org>
parents: 16287
diff changeset
3511
fe3b9a51e625 rename curr_lexer, curr_parser, CURR_LEXER
John W. Eaton <jwe@octave.org>
parents: 16287
diff changeset
3512 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
3513
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
3514 if (fcn_ptr)
de91b1621260 adjust location of eof marker for files with subfunctions but no explicit end statements
John W. Eaton <jwe@octave.org>
parents: 16574
diff changeset
3515 {
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
3516 fcn_ptr->maybe_relocate_end ();
de91b1621260 adjust location of eof marker for files with subfunctions but no explicit end statements
John W. Eaton <jwe@octave.org>
parents: 16574
diff changeset
3517
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
3518 if (parser.parsing_subfunctions)
de91b1621260 adjust location of eof marker for files with subfunctions but no explicit end statements
John W. Eaton <jwe@octave.org>
parents: 16574
diff changeset
3519 {
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
3520 if (! parser.endfunction_found)
de91b1621260 adjust location of eof marker for files with subfunctions but no explicit end statements
John W. Eaton <jwe@octave.org>
parents: 16574
diff changeset
3521 parser.subfunction_names.reverse ();
de91b1621260 adjust location of eof marker for files with subfunctions but no explicit end statements
John W. Eaton <jwe@octave.org>
parents: 16574
diff changeset
3522
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
3523 fcn_ptr->stash_subfunction_names (parser.subfunction_names);
de91b1621260 adjust location of eof marker for files with subfunctions but no explicit end statements
John W. Eaton <jwe@octave.org>
parents: 16574
diff changeset
3524 }
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
3525 }
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
3526
16203
127cccb037bf move more global parser and lexer variables to classes
John W. Eaton <jwe@octave.org>
parents: 16199
diff changeset
3527 if (status != 0)
127cccb037bf move more global parser and lexer variables to classes
John W. Eaton <jwe@octave.org>
parents: 16199
diff changeset
3528 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
3529 }
7715
5b4d278ec828 parse scripts completely before executing
John W. Eaton <jwe@octave.org>
parents: 7699
diff changeset
3530 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
3531 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
3532 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
3533 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
3534 full_file.c_str ());
3021
18d64612e67a [project @ 1997-06-03 22:18:56 by jwe]
jwe
parents: 3016
diff changeset
3535
7336
745a8299c2b5 [project @ 2007-12-28 20:56:55 by jwe]
jwe
parents: 7017
diff changeset
3536 return fcn_ptr;
3021
18d64612e67a [project @ 1997-06-03 22:18:56 by jwe]
jwe
parents: 3016
diff changeset
3537 }
18d64612e67a [project @ 1997-06-03 22:18:56 by jwe]
jwe
parents: 3016
diff changeset
3538
5484
2ff5363a16bd [project @ 2005-10-06 17:12:12 by jwe]
jwe
parents: 5472
diff changeset
3539 std::string
7715
5b4d278ec828 parse scripts completely before executing
John W. Eaton <jwe@octave.org>
parents: 7699
diff changeset
3540 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
3541 std::string& full_file)
7715
5b4d278ec828 parse scripts completely before executing
John W. Eaton <jwe@octave.org>
parents: 7699
diff changeset
3542 {
5b4d278ec828 parse scripts completely before executing
John W. Eaton <jwe@octave.org>
parents: 7699
diff changeset
3543 std::string retval;
5b4d278ec828 parse scripts completely before executing
John W. Eaton <jwe@octave.org>
parents: 7699
diff changeset
3544
16203
127cccb037bf move more global parser and lexer variables to classes
John W. Eaton <jwe@octave.org>
parents: 16199
diff changeset
3545 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
3546
127cccb037bf move more global parser and lexer variables to classes
John W. Eaton <jwe@octave.org>
parents: 16199
diff changeset
3547 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
3548
127cccb037bf move more global parser and lexer variables to classes
John W. Eaton <jwe@octave.org>
parents: 16199
diff changeset
3549 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
3550
127cccb037bf move more global parser and lexer variables to classes
John W. Eaton <jwe@octave.org>
parents: 16199
diff changeset
3551 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
3552 || (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
3553 || (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
3554 {
127cccb037bf move more global parser and lexer variables to classes
John W. Eaton <jwe@octave.org>
parents: 16199
diff changeset
3555 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
3556 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
3557
127cccb037bf move more global parser and lexer variables to classes
John W. Eaton <jwe@octave.org>
parents: 16199
diff changeset
3558 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
3559 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
3560 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
3561 }
7715
5b4d278ec828 parse scripts completely before executing
John W. Eaton <jwe@octave.org>
parents: 7699
diff changeset
3562
5b4d278ec828 parse scripts completely before executing
John W. Eaton <jwe@octave.org>
parents: 7699
diff changeset
3563 if (! file.empty ())
5b4d278ec828 parse scripts completely before executing
John W. Eaton <jwe@octave.org>
parents: 7699
diff changeset
3564 {
5b4d278ec828 parse scripts completely before executing
John W. Eaton <jwe@octave.org>
parents: 7699
diff changeset
3565 symbol_found = true;
5b4d278ec828 parse scripts completely before executing
John W. Eaton <jwe@octave.org>
parents: 7699
diff changeset
3566
16203
127cccb037bf move more global parser and lexer variables to classes
John W. Eaton <jwe@octave.org>
parents: 16199
diff changeset
3567 octave_function *fcn
127cccb037bf move more global parser and lexer variables to classes
John W. Eaton <jwe@octave.org>
parents: 16199
diff changeset
3568 = parse_fcn_file (full_file, file, "", true, false, false, false, "");
127cccb037bf move more global parser and lexer variables to classes
John W. Eaton <jwe@octave.org>
parents: 16199
diff changeset
3569
127cccb037bf move more global parser and lexer variables to classes
John W. Eaton <jwe@octave.org>
parents: 16199
diff changeset
3570 if (fcn)
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
3571 {
16203
127cccb037bf move more global parser and lexer variables to classes
John W. Eaton <jwe@octave.org>
parents: 16199
diff changeset
3572 retval = fcn->doc_string ();
127cccb037bf move more global parser and lexer variables to classes
John W. Eaton <jwe@octave.org>
parents: 16199
diff changeset
3573
127cccb037bf move more global parser and lexer variables to classes
John W. Eaton <jwe@octave.org>
parents: 16199
diff changeset
3574 delete fcn;
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
3575 }
7715
5b4d278ec828 parse scripts completely before executing
John W. Eaton <jwe@octave.org>
parents: 7699
diff changeset
3576 }
5b4d278ec828 parse scripts completely before executing
John W. Eaton <jwe@octave.org>
parents: 7699
diff changeset
3577
5b4d278ec828 parse scripts completely before executing
John W. Eaton <jwe@octave.org>
parents: 7699
diff changeset
3578 return retval;
5b4d278ec828 parse scripts completely before executing
John W. Eaton <jwe@octave.org>
parents: 7699
diff changeset
3579 }
5b4d278ec828 parse scripts completely before executing
John W. Eaton <jwe@octave.org>
parents: 7699
diff changeset
3580
5b4d278ec828 parse scripts completely before executing
John W. Eaton <jwe@octave.org>
parents: 7699
diff changeset
3581 std::string
5b4d278ec828 parse scripts completely before executing
John W. Eaton <jwe@octave.org>
parents: 7699
diff changeset
3582 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
3583 {
5b4d278ec828 parse scripts completely before executing
John W. Eaton <jwe@octave.org>
parents: 7699
diff changeset
3584 std::string file;
5b4d278ec828 parse scripts completely before executing
John W. Eaton <jwe@octave.org>
parents: 7699
diff changeset
3585 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
3586 }
5b4d278ec828 parse scripts completely before executing
John W. Eaton <jwe@octave.org>
parents: 7699
diff changeset
3587
5b4d278ec828 parse scripts completely before executing
John W. Eaton <jwe@octave.org>
parents: 7699
diff changeset
3588 std::string
5484
2ff5363a16bd [project @ 2005-10-06 17:12:12 by jwe]
jwe
parents: 5472
diff changeset
3589 lookup_autoload (const std::string& nm)
2ff5363a16bd [project @ 2005-10-06 17:12:12 by jwe]
jwe
parents: 5472
diff changeset
3590 {
5626
3236b4d98fde [project @ 2006-02-15 20:25:39 by jwe]
jwe
parents: 5615
diff changeset
3591 std::string retval;
3236b4d98fde [project @ 2006-02-15 20:25:39 by jwe]
jwe
parents: 5615
diff changeset
3592
3236b4d98fde [project @ 2006-02-15 20:25:39 by jwe]
jwe
parents: 5615
diff changeset
3593 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
3594
3236b4d98fde [project @ 2006-02-15 20:25:39 by jwe]
jwe
parents: 5615
diff changeset
3595 am_iter p = autoload_map.find (nm);
3236b4d98fde [project @ 2006-02-15 20:25:39 by jwe]
jwe
parents: 5615
diff changeset
3596
3236b4d98fde [project @ 2006-02-15 20:25:39 by jwe]
jwe
parents: 5615
diff changeset
3597 if (p != autoload_map.end ())
6323
ea65de49e18e [project @ 2007-02-17 02:51:02 by jwe]
jwe
parents: 6238
diff changeset
3598 retval = load_path::find_file (p->second);
5626
3236b4d98fde [project @ 2006-02-15 20:25:39 by jwe]
jwe
parents: 5615
diff changeset
3599
3236b4d98fde [project @ 2006-02-15 20:25:39 by jwe]
jwe
parents: 5615
diff changeset
3600 return retval;
5484
2ff5363a16bd [project @ 2005-10-06 17:12:12 by jwe]
jwe
parents: 5472
diff changeset
3601 }
2ff5363a16bd [project @ 2005-10-06 17:12:12 by jwe]
jwe
parents: 5472
diff changeset
3602
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11572
diff changeset
3603 string_vector
5592
61d6cebd243b [project @ 2006-01-12 17:55:22 by dbateman]
dbateman
parents: 5484
diff changeset
3604 autoloaded_functions (void)
61d6cebd243b [project @ 2006-01-12 17:55:22 by dbateman]
dbateman
parents: 5484
diff changeset
3605 {
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
3606 string_vector names (autoload_map.size ());
5592
61d6cebd243b [project @ 2006-01-12 17:55:22 by dbateman]
dbateman
parents: 5484
diff changeset
3607
61d6cebd243b [project @ 2006-01-12 17:55:22 by dbateman]
dbateman
parents: 5484
diff changeset
3608 octave_idx_type i = 0;
5626
3236b4d98fde [project @ 2006-02-15 20:25:39 by jwe]
jwe
parents: 5615
diff changeset
3609 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
3610 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
3611 names[i++] = p->first;
61d6cebd243b [project @ 2006-01-12 17:55:22 by dbateman]
dbateman
parents: 5484
diff changeset
3612
61d6cebd243b [project @ 2006-01-12 17:55:22 by dbateman]
dbateman
parents: 5484
diff changeset
3613 return names;
61d6cebd243b [project @ 2006-01-12 17:55:22 by dbateman]
dbateman
parents: 5484
diff changeset
3614 }
61d6cebd243b [project @ 2006-01-12 17:55:22 by dbateman]
dbateman
parents: 5484
diff changeset
3615
61d6cebd243b [project @ 2006-01-12 17:55:22 by dbateman]
dbateman
parents: 5484
diff changeset
3616 string_vector
61d6cebd243b [project @ 2006-01-12 17:55:22 by dbateman]
dbateman
parents: 5484
diff changeset
3617 reverse_lookup_autoload (const std::string& nm)
61d6cebd243b [project @ 2006-01-12 17:55:22 by dbateman]
dbateman
parents: 5484
diff changeset
3618 {
61d6cebd243b [project @ 2006-01-12 17:55:22 by dbateman]
dbateman
parents: 5484
diff changeset
3619 string_vector names;
61d6cebd243b [project @ 2006-01-12 17:55:22 by dbateman]
dbateman
parents: 5484
diff changeset
3620
5626
3236b4d98fde [project @ 2006-02-15 20:25:39 by jwe]
jwe
parents: 5615
diff changeset
3621 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
3622 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
3623 if (nm == p->second)
61d6cebd243b [project @ 2006-01-12 17:55:22 by dbateman]
dbateman
parents: 5484
diff changeset
3624 names.append (p->first);
61d6cebd243b [project @ 2006-01-12 17:55:22 by dbateman]
dbateman
parents: 5484
diff changeset
3625
61d6cebd243b [project @ 2006-01-12 17:55:22 by dbateman]
dbateman
parents: 5484
diff changeset
3626 return names;
61d6cebd243b [project @ 2006-01-12 17:55:22 by dbateman]
dbateman
parents: 5484
diff changeset
3627 }
61d6cebd243b [project @ 2006-01-12 17:55:22 by dbateman]
dbateman
parents: 5484
diff changeset
3628
7336
745a8299c2b5 [project @ 2007-12-28 20:56:55 by jwe]
jwe
parents: 7017
diff changeset
3629 octave_function *
745a8299c2b5 [project @ 2007-12-28 20:56:55 by jwe]
jwe
parents: 7017
diff changeset
3630 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
3631 const std::string& dispatch_type,
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
3632 const std::string& fcn_name, bool autoload)
3021
18d64612e67a [project @ 1997-06-03 22:18:56 by jwe]
jwe
parents: 3016
diff changeset
3633 {
7336
745a8299c2b5 [project @ 2007-12-28 20:56:55 by jwe]
jwe
parents: 7017
diff changeset
3634 octave_function *retval = 0;
745a8299c2b5 [project @ 2007-12-28 20:56:55 by jwe]
jwe
parents: 7017
diff changeset
3635
10067
6f79338c269b omission from last patch
Jaroslav Hajek <highegg@gmail.com>
parents: 9794
diff changeset
3636 unwind_protect frame;
5484
2ff5363a16bd [project @ 2005-10-06 17:12:12 by jwe]
jwe
parents: 5472
diff changeset
3637
7336
745a8299c2b5 [project @ 2007-12-28 20:56:55 by jwe]
jwe
parents: 7017
diff changeset
3638 std::string nm = file_name;
6238
3ecd8d2c5654 [project @ 2007-01-10 21:13:21 by jwe]
jwe
parents: 6235
diff changeset
3639
3ecd8d2c5654 [project @ 2007-01-10 21:13:21 by jwe]
jwe
parents: 6235
diff changeset
3640 size_t nm_len = nm.length ();
5472
e2f85b298a74 [project @ 2005-09-23 21:10:36 by jwe]
jwe
parents: 5400
diff changeset
3641
e2f85b298a74 [project @ 2005-09-23 21:10:36 by jwe]
jwe
parents: 5400
diff changeset
3642 std::string file;
e2f85b298a74 [project @ 2005-09-23 21:10:36 by jwe]
jwe
parents: 5400
diff changeset
3643
16153
a57c2c8c8163 move some variables into the octave_parser class
John W. Eaton <jwe@octave.org>
parents: 16151
diff changeset
3644 bool relative_lookup = false;
6323
ea65de49e18e [project @ 2007-02-17 02:51:02 by jwe]
jwe
parents: 6238
diff changeset
3645
7336
745a8299c2b5 [project @ 2007-12-28 20:56:55 by jwe]
jwe
parents: 7017
diff changeset
3646 file = nm;
745a8299c2b5 [project @ 2007-12-28 20:56:55 by jwe]
jwe
parents: 7017
diff changeset
3647
745a8299c2b5 [project @ 2007-12-28 20:56:55 by jwe]
jwe
parents: 7017
diff changeset
3648 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
3649 || (nm_len > 4 && nm.substr (nm_len-4) == ".mex")
745a8299c2b5 [project @ 2007-12-28 20:56:55 by jwe]
jwe
parents: 7017
diff changeset
3650 || (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
3651 {
6238
3ecd8d2c5654 [project @ 2007-01-10 21:13:21 by jwe]
jwe
parents: 6235
diff changeset
3652 nm = octave_env::base_pathname (file);
3ecd8d2c5654 [project @ 2007-01-10 21:13:21 by jwe]
jwe
parents: 6235
diff changeset
3653 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
3654
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
3655 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
3656 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
3657 nm = nm.substr (pos+1);
5472
e2f85b298a74 [project @ 2005-09-23 21:10:36 by jwe]
jwe
parents: 5400
diff changeset
3658 }
7336
745a8299c2b5 [project @ 2007-12-28 20:56:55 by jwe]
jwe
parents: 7017
diff changeset
3659
16153
a57c2c8c8163 move some variables into the octave_parser class
John W. Eaton <jwe@octave.org>
parents: 16151
diff changeset
3660 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
3661
10250
2d47356a7a1a use gnulib getcwd module
John W. Eaton <jwe@octave.org>
parents: 10230
diff changeset
3662 file = octave_env::make_absolute (file);
4243
7e4d5b5520e5 [project @ 2002-12-27 05:30:59 by jwe]
jwe
parents: 4240
diff changeset
3663
7e4d5b5520e5 [project @ 2002-12-27 05:30:59 by jwe]
jwe
parents: 4240
diff changeset
3664 int len = file.length ();
7e4d5b5520e5 [project @ 2002-12-27 05:30:59 by jwe]
jwe
parents: 4240
diff changeset
3665
4244
189df16144fc [project @ 2002-12-28 02:00:05 by jwe]
jwe
parents: 4243
diff changeset
3666 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
3667 {
7336
745a8299c2b5 [project @ 2007-12-28 20:56:55 by jwe]
jwe
parents: 7017
diff changeset
3668 if (autoload && ! fcn_name.empty ())
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
3669 nm = fcn_name;
7336
745a8299c2b5 [project @ 2007-12-28 20:56:55 by jwe]
jwe
parents: 7017
diff changeset
3670
16153
a57c2c8c8163 move some variables into the octave_parser class
John W. Eaton <jwe@octave.org>
parents: 16151
diff changeset
3671 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
3672 }
e884ab4f29ee [project @ 2006-06-22 00:57:27 by jwe]
jwe
parents: 5861
diff changeset
3673 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
3674 {
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
3675 // 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
3676 // 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
3677
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11572
diff changeset
3678 octave_function *tmpfcn = parse_fcn_file (file.substr (0, len - 2),
16203
127cccb037bf move more global parser and lexer variables to classes
John W. Eaton <jwe@octave.org>
parents: 16199
diff changeset
3679 nm, dispatch_type, false,
16153
a57c2c8c8163 move some variables into the octave_parser class
John W. Eaton <jwe@octave.org>
parents: 16151
diff changeset
3680 autoload, autoload,
a57c2c8c8163 move some variables into the octave_parser class
John W. Eaton <jwe@octave.org>
parents: 16151
diff changeset
3681 relative_lookup, "");
a57c2c8c8163 move some variables into the octave_parser class
John W. Eaton <jwe@octave.org>
parents: 16151
diff changeset
3682
a57c2c8c8163 move some variables into the octave_parser class
John W. Eaton <jwe@octave.org>
parents: 16151
diff changeset
3683 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
3684
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
3685 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
3686 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
3687 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
3688 }
4244
189df16144fc [project @ 2002-12-28 02:00:05 by jwe]
jwe
parents: 4243
diff changeset
3689 else if (len > 2)
3021
18d64612e67a [project @ 1997-06-03 22:18:56 by jwe]
jwe
parents: 3016
diff changeset
3690 {
16203
127cccb037bf move more global parser and lexer variables to classes
John W. Eaton <jwe@octave.org>
parents: 16199
diff changeset
3691 retval = parse_fcn_file (file, nm, dispatch_type, true, autoload,
16153
a57c2c8c8163 move some variables into the octave_parser class
John W. Eaton <jwe@octave.org>
parents: 16151
diff changeset
3692 autoload, relative_lookup, "");
3021
18d64612e67a [project @ 1997-06-03 22:18:56 by jwe]
jwe
parents: 3016
diff changeset
3693 }
18d64612e67a [project @ 1997-06-03 22:18:56 by jwe]
jwe
parents: 3016
diff changeset
3694
7336
745a8299c2b5 [project @ 2007-12-28 20:56:55 by jwe]
jwe
parents: 7017
diff changeset
3695 if (retval)
8819
96d87674b818 also stash directory name for subfunctions
John W. Eaton <jwe@octave.org>
parents: 8812
diff changeset
3696 {
96d87674b818 also stash directory name for subfunctions
John W. Eaton <jwe@octave.org>
parents: 8812
diff changeset
3697 retval->stash_dir_name (dir_name);
96d87674b818 also stash directory name for subfunctions
John W. Eaton <jwe@octave.org>
parents: 8812
diff changeset
3698
96d87674b818 also stash directory name for subfunctions
John W. Eaton <jwe@octave.org>
parents: 8812
diff changeset
3699 if (retval->is_user_function ())
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
3700 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
3701 symbol_table::scope_id id = retval->scope ();
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
3702
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
3703 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
3704 }
8819
96d87674b818 also stash directory name for subfunctions
John W. Eaton <jwe@octave.org>
parents: 8812
diff changeset
3705 }
7336
745a8299c2b5 [project @ 2007-12-28 20:56:55 by jwe]
jwe
parents: 7017
diff changeset
3706
745a8299c2b5 [project @ 2007-12-28 20:56:55 by jwe]
jwe
parents: 7017
diff changeset
3707 return retval;
5312
80c1aa832cb2 [project @ 2005-04-28 01:54:46 by jwe]
jwe
parents: 5309
diff changeset
3708 }
80c1aa832cb2 [project @ 2005-04-28 01:54:46 by jwe]
jwe
parents: 5309
diff changeset
3709
8746
5dd06f19e9be handle commands in the lexer
John W. Eaton <jwe@octave.org>
parents: 8745
diff changeset
3710 DEFUN (autoload, args, ,
5484
2ff5363a16bd [project @ 2005-10-06 17:12:12 by jwe]
jwe
parents: 5472
diff changeset
3711 "-*- texinfo -*-\n\
17170
d6499c14021c doc: Periodic grammarcheck of documentation.
Rik <rik@octave.org>
parents: 16924
diff changeset
3712 @deftypefn {Built-in Function} {} autoload (@var{function}, @var{file})\n\
16848
77c8aae15908 accept remove option for autoload
Juan Pablo Carbajal <ajuanpi+dev@gmail.com>
parents: 16789
diff changeset
3713 @deftypefnx {Built-in Function} {} autoload (@dots{}, @asis{\"remove\"})\n\
5484
2ff5363a16bd [project @ 2005-10-06 17:12:12 by jwe]
jwe
parents: 5472
diff changeset
3714 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
3715 \n\
6926
c05fbb1b7e1f [project @ 2007-09-26 19:56:54 by dbateman]
dbateman
parents: 6657
diff changeset
3716 The second argument, @var{file}, should be an absolute file name or\n\
c05fbb1b7e1f [project @ 2007-09-26 19:56:54 by dbateman]
dbateman
parents: 6657
diff changeset
3717 a file name in the same directory as the function or script from which\n\
9038
fca0dc2fb042 Cleanup documentation files stmt.texi and func.texi
Rik <rdrider0-list@yahoo.com>
parents: 8974
diff changeset
3718 the autoload command was run. @var{file} should not depend on the\n\
6926
c05fbb1b7e1f [project @ 2007-09-26 19:56:54 by dbateman]
dbateman
parents: 6657
diff changeset
3719 Octave load path.\n\
6380
ac3d67504f85 [project @ 2007-03-02 22:08:06 by jwe]
jwe
parents: 6379
diff changeset
3720 \n\
ac3d67504f85 [project @ 2007-03-02 22:08:06 by jwe]
jwe
parents: 6379
diff changeset
3721 Normally, calls to @code{autoload} appear in PKG_ADD script files that\n\
16789
2f63d2f3ff11 doc: Update docstrings in oct-parse.in.yy.
Rik <rik@octave.org>
parents: 16681
diff changeset
3722 are evaluated when a directory is added to Octave's load path. To\n\
6926
c05fbb1b7e1f [project @ 2007-09-26 19:56:54 by dbateman]
dbateman
parents: 6657
diff changeset
3723 avoid having to hardcode directory names in @var{file}, if @var{file}\n\
c05fbb1b7e1f [project @ 2007-09-26 19:56:54 by dbateman]
dbateman
parents: 6657
diff changeset
3724 is in the same directory as the PKG_ADD script then\n\
6380
ac3d67504f85 [project @ 2007-03-02 22:08:06 by jwe]
jwe
parents: 6379
diff changeset
3725 \n\
ac3d67504f85 [project @ 2007-03-02 22:08:06 by jwe]
jwe
parents: 6379
diff changeset
3726 @example\n\
6926
c05fbb1b7e1f [project @ 2007-09-26 19:56:54 by dbateman]
dbateman
parents: 6657
diff changeset
3727 autoload (\"foo\", \"bar.oct\");\n\
6380
ac3d67504f85 [project @ 2007-03-02 22:08:06 by jwe]
jwe
parents: 6379
diff changeset
3728 @end example\n\
ac3d67504f85 [project @ 2007-03-02 22:08:06 by jwe]
jwe
parents: 6379
diff changeset
3729 \n\
11572
7d6d8c1e471f Grammarcheck Texinfo for files in src directory.
Rik <octave@nomad.inbox5.com>
parents: 11523
diff changeset
3730 @noindent\n\
9038
fca0dc2fb042 Cleanup documentation files stmt.texi and func.texi
Rik <rdrider0-list@yahoo.com>
parents: 8974
diff changeset
3731 will load the function @code{foo} from the file @code{bar.oct}. The above\n\
16789
2f63d2f3ff11 doc: Update docstrings in oct-parse.in.yy.
Rik <rik@octave.org>
parents: 16681
diff changeset
3732 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
3733 \n\
ac3d67504f85 [project @ 2007-03-02 22:08:06 by jwe]
jwe
parents: 6379
diff changeset
3734 @example\n\
6637
c18ed0e7ee41 [project @ 2007-05-21 19:12:46 by jwe]
jwe
parents: 6431
diff changeset
3735 autoload (\"foo\", file_in_loadpath (\"bar.oct\"))\n\
6380
ac3d67504f85 [project @ 2007-03-02 22:08:06 by jwe]
jwe
parents: 6379
diff changeset
3736 @end example\n\
ac3d67504f85 [project @ 2007-03-02 22:08:06 by jwe]
jwe
parents: 6379
diff changeset
3737 \n\
ac3d67504f85 [project @ 2007-03-02 22:08:06 by jwe]
jwe
parents: 6379
diff changeset
3738 @noindent\n\
16789
2f63d2f3ff11 doc: Update docstrings in oct-parse.in.yy.
Rik <rik@octave.org>
parents: 16681
diff changeset
3739 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
3740 \n\
6637
c18ed0e7ee41 [project @ 2007-05-21 19:12:46 by jwe]
jwe
parents: 6431
diff changeset
3741 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
3742 \n\
77c8aae15908 accept remove option for autoload
Juan Pablo Carbajal <ajuanpi+dev@gmail.com>
parents: 16789
diff changeset
3743 If a third argument @asis{'remove'} is given, the function is cleared and\n\
77c8aae15908 accept remove option for autoload
Juan Pablo Carbajal <ajuanpi+dev@gmail.com>
parents: 16789
diff changeset
3744 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
3745 \n\
6380
ac3d67504f85 [project @ 2007-03-02 22:08:06 by jwe]
jwe
parents: 6379
diff changeset
3746 @seealso{PKG_ADD}\n\
5484
2ff5363a16bd [project @ 2005-10-06 17:12:12 by jwe]
jwe
parents: 5472
diff changeset
3747 @end deftypefn")
2ff5363a16bd [project @ 2005-10-06 17:12:12 by jwe]
jwe
parents: 5472
diff changeset
3748 {
5626
3236b4d98fde [project @ 2006-02-15 20:25:39 by jwe]
jwe
parents: 5615
diff changeset
3749 octave_value retval;
5484
2ff5363a16bd [project @ 2005-10-06 17:12:12 by jwe]
jwe
parents: 5472
diff changeset
3750
2ff5363a16bd [project @ 2005-10-06 17:12:12 by jwe]
jwe
parents: 5472
diff changeset
3751 int nargin = args.length ();
2ff5363a16bd [project @ 2005-10-06 17:12:12 by jwe]
jwe
parents: 5472
diff changeset
3752
5626
3236b4d98fde [project @ 2006-02-15 20:25:39 by jwe]
jwe
parents: 5615
diff changeset
3753 if (nargin == 0)
3236b4d98fde [project @ 2006-02-15 20:25:39 by jwe]
jwe
parents: 5615
diff changeset
3754 {
10350
12884915a8e4 merge MArray classes & improve Array interface
Jaroslav Hajek <highegg@gmail.com>
parents: 10315
diff changeset
3755 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
3756 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
3757
3236b4d98fde [project @ 2006-02-15 20:25:39 by jwe]
jwe
parents: 5615
diff changeset
3758 octave_idx_type i = 0;
3236b4d98fde [project @ 2006-02-15 20:25:39 by jwe]
jwe
parents: 5615
diff changeset
3759 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
3760 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
3761 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
3762 func_names(i) = p->first;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
3763 file_names(i) = p->second;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
3764
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
3765 i++;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
3766 }
5626
3236b4d98fde [project @ 2006-02-15 20:25:39 by jwe]
jwe
parents: 5615
diff changeset
3767
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
3768 octave_map m;
5626
3236b4d98fde [project @ 2006-02-15 20:25:39 by jwe]
jwe
parents: 5615
diff changeset
3769
3236b4d98fde [project @ 2006-02-15 20:25:39 by jwe]
jwe
parents: 5615
diff changeset
3770 m.assign ("function", func_names);
3236b4d98fde [project @ 2006-02-15 20:25:39 by jwe]
jwe
parents: 5615
diff changeset
3771 m.assign ("file", file_names);
3236b4d98fde [project @ 2006-02-15 20:25:39 by jwe]
jwe
parents: 5615
diff changeset
3772
3236b4d98fde [project @ 2006-02-15 20:25:39 by jwe]
jwe
parents: 5615
diff changeset
3773 retval = m;
3236b4d98fde [project @ 2006-02-15 20:25:39 by jwe]
jwe
parents: 5615
diff changeset
3774 }
16848
77c8aae15908 accept remove option for autoload
Juan Pablo Carbajal <ajuanpi+dev@gmail.com>
parents: 16789
diff changeset
3775 else if (nargin == 2 || nargin == 3)
5484
2ff5363a16bd [project @ 2005-10-06 17:12:12 by jwe]
jwe
parents: 5472
diff changeset
3776 {
2ff5363a16bd [project @ 2005-10-06 17:12:12 by jwe]
jwe
parents: 5472
diff changeset
3777 string_vector argv = args.make_argv ("autoload");
2ff5363a16bd [project @ 2005-10-06 17:12:12 by jwe]
jwe
parents: 5472
diff changeset
3778
2ff5363a16bd [project @ 2005-10-06 17:12:12 by jwe]
jwe
parents: 5472
diff changeset
3779 if (! error_state)
6380
ac3d67504f85 [project @ 2007-03-02 22:08:06 by jwe]
jwe
parents: 6379
diff changeset
3780 {
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
3781 std::string nm = argv[2];
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
3782
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
3783 if (! octave_env::absolute_pathname (nm))
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
3784 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
3785 octave_user_code *fcn = octave_call_stack::caller_user_code ();
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
3786
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
3787 bool found = false;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
3788
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
3789 if (fcn)
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
3790 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
3791 std::string fname = fcn->fcn_file_name ();
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
3792
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
3793 if (! fname.empty ())
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
3794 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
3795 fname = octave_env::make_absolute (fname);
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
3796 fname = fname.substr (0, fname.find_last_of (file_ops::dir_sep_str ()) + 1);
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
3797
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
3798 file_stat fs (fname + nm);
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
3799
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
3800 if (fs.exists ())
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
3801 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
3802 nm = fname + nm;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
3803 found = true;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
3804 }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
3805 }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
3806 }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
3807 if (! found)
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
3808 warning_with_id ("Octave:autoload-relative-file-name",
15466
d174210ce1ec use ' instead of ` in error messages, warnings and most comments
John W. Eaton <jwe@octave.org>
parents: 14189
diff changeset
3809 "autoload: '%s' is not an absolute file name",
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
3810 nm.c_str ());
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
3811 }
16848
77c8aae15908 accept remove option for autoload
Juan Pablo Carbajal <ajuanpi+dev@gmail.com>
parents: 16789
diff changeset
3812 if (nargin == 2)
77c8aae15908 accept remove option for autoload
Juan Pablo Carbajal <ajuanpi+dev@gmail.com>
parents: 16789
diff changeset
3813 autoload_map[argv[1]] = nm;
77c8aae15908 accept remove option for autoload
Juan Pablo Carbajal <ajuanpi+dev@gmail.com>
parents: 16789
diff changeset
3814 else if (nargin == 3)
77c8aae15908 accept remove option for autoload
Juan Pablo Carbajal <ajuanpi+dev@gmail.com>
parents: 16789
diff changeset
3815 {
77c8aae15908 accept remove option for autoload
Juan Pablo Carbajal <ajuanpi+dev@gmail.com>
parents: 16789
diff changeset
3816 if (argv[3].compare ("remove") != 0)
77c8aae15908 accept remove option for autoload
Juan Pablo Carbajal <ajuanpi+dev@gmail.com>
parents: 16789
diff changeset
3817 error_with_id ("Octave:invalid-input-arg",
77c8aae15908 accept remove option for autoload
Juan Pablo Carbajal <ajuanpi+dev@gmail.com>
parents: 16789
diff changeset
3818 "autoload: third argument can only be 'remove'");
77c8aae15908 accept remove option for autoload
Juan Pablo Carbajal <ajuanpi+dev@gmail.com>
parents: 16789
diff changeset
3819
77c8aae15908 accept remove option for autoload
Juan Pablo Carbajal <ajuanpi+dev@gmail.com>
parents: 16789
diff changeset
3820 // Remove function from symbol table and autoload map.
16850
ec2ac2300ac8 oct-parse-in.yy: Fix error compiling code in cset 77c8aae15908.
Rik <rik@octave.org>
parents: 16848
diff changeset
3821 symbol_table::clear_dld_function (argv[1]);
16848
77c8aae15908 accept remove option for autoload
Juan Pablo Carbajal <ajuanpi+dev@gmail.com>
parents: 16789
diff changeset
3822 autoload_map.erase (argv[1]);
77c8aae15908 accept remove option for autoload
Juan Pablo Carbajal <ajuanpi+dev@gmail.com>
parents: 16789
diff changeset
3823 }
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
3824 }
5484
2ff5363a16bd [project @ 2005-10-06 17:12:12 by jwe]
jwe
parents: 5472
diff changeset
3825 }
2ff5363a16bd [project @ 2005-10-06 17:12:12 by jwe]
jwe
parents: 5472
diff changeset
3826 else
5823
080c08b192d8 [project @ 2006-05-19 05:32:17 by jwe]
jwe
parents: 5794
diff changeset
3827 print_usage ();
5484
2ff5363a16bd [project @ 2005-10-06 17:12:12 by jwe]
jwe
parents: 5472
diff changeset
3828
2ff5363a16bd [project @ 2005-10-06 17:12:12 by jwe]
jwe
parents: 5472
diff changeset
3829 return retval;
2ff5363a16bd [project @ 2005-10-06 17:12:12 by jwe]
jwe
parents: 5472
diff changeset
3830 }
2ff5363a16bd [project @ 2005-10-06 17:12:12 by jwe]
jwe
parents: 5472
diff changeset
3831
4486
6ceba1f351fb [project @ 2003-08-22 16:49:46 by jwe]
jwe
parents: 4463
diff changeset
3832 void
7715
5b4d278ec828 parse scripts completely before executing
John W. Eaton <jwe@octave.org>
parents: 7699
diff changeset
3833 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
3834 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
3835 {
10578
cb0883127251 limit on recursion via calls to source function
John W. Eaton <jwe@octave.org>
parents: 10570
diff changeset
3836 // 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
3837 // 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
3838 // 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
3839 // written as
cb0883127251 limit on recursion via calls to source function
John W. Eaton <jwe@octave.org>
parents: 10570
diff changeset
3840 //
cb0883127251 limit on recursion via calls to source function
John W. Eaton <jwe@octave.org>
parents: 10570
diff changeset
3841 // foo1.m:
cb0883127251 limit on recursion via calls to source function
John W. Eaton <jwe@octave.org>
parents: 10570
diff changeset
3842 // ------
cb0883127251 limit on recursion via calls to source function
John W. Eaton <jwe@octave.org>
parents: 10570
diff changeset
3843 // foo2
cb0883127251 limit on recursion via calls to source function
John W. Eaton <jwe@octave.org>
parents: 10570
diff changeset
3844 //
cb0883127251 limit on recursion via calls to source function
John W. Eaton <jwe@octave.org>
parents: 10570
diff changeset
3845 // foo2.m:
cb0883127251 limit on recursion via calls to source function
John W. Eaton <jwe@octave.org>
parents: 10570
diff changeset
3846 // ------
cb0883127251 limit on recursion via calls to source function
John W. Eaton <jwe@octave.org>
parents: 10570
diff changeset
3847 // foo1
cb0883127251 limit on recursion via calls to source function
John W. Eaton <jwe@octave.org>
parents: 10570
diff changeset
3848 //
cb0883127251 limit on recursion via calls to source function
John W. Eaton <jwe@octave.org>
parents: 10570
diff changeset
3849 // and called with
cb0883127251 limit on recursion via calls to source function
John W. Eaton <jwe@octave.org>
parents: 10570
diff changeset
3850 //
cb0883127251 limit on recursion via calls to source function
John W. Eaton <jwe@octave.org>
parents: 10570
diff changeset
3851 // foo1
cb0883127251 limit on recursion via calls to source function
John W. Eaton <jwe@octave.org>
parents: 10570
diff changeset
3852 //
cb0883127251 limit on recursion via calls to source function
John W. Eaton <jwe@octave.org>
parents: 10570
diff changeset
3853 // (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
3854 //
cb0883127251 limit on recursion via calls to source function
John W. Eaton <jwe@octave.org>
parents: 10570
diff changeset
3855 // foo1.m:
cb0883127251 limit on recursion via calls to source function
John W. Eaton <jwe@octave.org>
parents: 10570
diff changeset
3856 // ------
cb0883127251 limit on recursion via calls to source function
John W. Eaton <jwe@octave.org>
parents: 10570
diff changeset
3857 // source ("foo2.m")
cb0883127251 limit on recursion via calls to source function
John W. Eaton <jwe@octave.org>
parents: 10570
diff changeset
3858 //
cb0883127251 limit on recursion via calls to source function
John W. Eaton <jwe@octave.org>
parents: 10570
diff changeset
3859 // foo2.m:
cb0883127251 limit on recursion via calls to source function
John W. Eaton <jwe@octave.org>
parents: 10570
diff changeset
3860 // ------
cb0883127251 limit on recursion via calls to source function
John W. Eaton <jwe@octave.org>
parents: 10570
diff changeset
3861 // source ("foo1.m")
cb0883127251 limit on recursion via calls to source function
John W. Eaton <jwe@octave.org>
parents: 10570
diff changeset
3862 //
cb0883127251 limit on recursion via calls to source function
John W. Eaton <jwe@octave.org>
parents: 10570
diff changeset
3863 // and called with
cb0883127251 limit on recursion via calls to source function
John W. Eaton <jwe@octave.org>
parents: 10570
diff changeset
3864 //
cb0883127251 limit on recursion via calls to source function
John W. Eaton <jwe@octave.org>
parents: 10570
diff changeset
3865 // source ("foo1.m")
cb0883127251 limit on recursion via calls to source function
John W. Eaton <jwe@octave.org>
parents: 10570
diff changeset
3866 //
cb0883127251 limit on recursion via calls to source function
John W. Eaton <jwe@octave.org>
parents: 10570
diff changeset
3867 // (for example).
cb0883127251 limit on recursion via calls to source function
John W. Eaton <jwe@octave.org>
parents: 10570
diff changeset
3868
cb0883127251 limit on recursion via calls to source function
John W. Eaton <jwe@octave.org>
parents: 10570
diff changeset
3869 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
3870
4486
6ceba1f351fb [project @ 2003-08-22 16:49:46 by jwe]
jwe
parents: 4463
diff changeset
3871 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
3872
10578
cb0883127251 limit on recursion via calls to source function
John W. Eaton <jwe@octave.org>
parents: 10570
diff changeset
3873 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
3874
10067
6f79338c269b omission from last patch
Jaroslav Hajek <highegg@gmail.com>
parents: 9794
diff changeset
3875 unwind_protect frame;
6f79338c269b omission from last patch
Jaroslav Hajek <highegg@gmail.com>
parents: 9794
diff changeset
3876
10578
cb0883127251 limit on recursion via calls to source function
John W. Eaton <jwe@octave.org>
parents: 10570
diff changeset
3877 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
3878 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
3879
cb0883127251 limit on recursion via calls to source function
John W. Eaton <jwe@octave.org>
parents: 10570
diff changeset
3880 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
3881
cb0883127251 limit on recursion via calls to source function
John W. Eaton <jwe@octave.org>
parents: 10570
diff changeset
3882 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
3883
cb0883127251 limit on recursion via calls to source function
John W. Eaton <jwe@octave.org>
parents: 10570
diff changeset
3884 if (source_call_depth[file_full_name] >= Vmax_recursion_depth)
cb0883127251 limit on recursion via calls to source function
John W. Eaton <jwe@octave.org>
parents: 10570
diff changeset
3885 {
cb0883127251 limit on recursion via calls to source function
John W. Eaton <jwe@octave.org>
parents: 10570
diff changeset
3886 error ("max_recursion_depth exceeded");
cb0883127251 limit on recursion via calls to source function
John W. Eaton <jwe@octave.org>
parents: 10570
diff changeset
3887 return;
cb0883127251 limit on recursion via calls to source function
John W. Eaton <jwe@octave.org>
parents: 10570
diff changeset
3888 }
cb0883127251 limit on recursion via calls to source function
John W. Eaton <jwe@octave.org>
parents: 10570
diff changeset
3889
5975
e64059303a6f [project @ 2006-08-29 16:37:39 by jwe]
jwe
parents: 5932
diff changeset
3890 if (! context.empty ())
e64059303a6f [project @ 2006-08-29 16:37:39 by jwe]
jwe
parents: 5932
diff changeset
3891 {
e64059303a6f [project @ 2006-08-29 16:37:39 by jwe]
jwe
parents: 5932
diff changeset
3892 if (context == "caller")
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
3893 octave_call_stack::goto_caller_frame ();
5975
e64059303a6f [project @ 2006-08-29 16:37:39 by jwe]
jwe
parents: 5932
diff changeset
3894 else if (context == "base")
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
3895 octave_call_stack::goto_base_frame ();
5975
e64059303a6f [project @ 2006-08-29 16:37:39 by jwe]
jwe
parents: 5932
diff changeset
3896 else
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
3897 error ("source: context must be \"caller\" or \"base\"");
7336
745a8299c2b5 [project @ 2007-12-28 20:56:55 by jwe]
jwe
parents: 7017
diff changeset
3898
745a8299c2b5 [project @ 2007-12-28 20:56:55 by jwe]
jwe
parents: 7017
diff changeset
3899 if (! error_state)
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
3900 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
3901 }
5975
e64059303a6f [project @ 2006-08-29 16:37:39 by jwe]
jwe
parents: 5932
diff changeset
3902
e64059303a6f [project @ 2006-08-29 16:37:39 by jwe]
jwe
parents: 5932
diff changeset
3903 if (! error_state)
e64059303a6f [project @ 2006-08-29 16:37:39 by jwe]
jwe
parents: 5932
diff changeset
3904 {
16203
127cccb037bf move more global parser and lexer variables to classes
John W. Eaton <jwe@octave.org>
parents: 16199
diff changeset
3905 octave_function *fcn = parse_fcn_file (file_full_name, file_name,
127cccb037bf move more global parser and lexer variables to classes
John W. Eaton <jwe@octave.org>
parents: 16199
diff changeset
3906 "", require_file, true,
127cccb037bf move more global parser and lexer variables to classes
John W. Eaton <jwe@octave.org>
parents: 16199
diff changeset
3907 false, false, warn_for);
7715
5b4d278ec828 parse scripts completely before executing
John W. Eaton <jwe@octave.org>
parents: 7699
diff changeset
3908
5b4d278ec828 parse scripts completely before executing
John W. Eaton <jwe@octave.org>
parents: 7699
diff changeset
3909 if (! error_state)
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
3910 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
3911 if (fcn && fcn->is_user_script ())
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
3912 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
3913 octave_value_list args;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
3914
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
3915 if (verbose)
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
3916 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
3917 std::cout << "executing commands from " << file_full_name << " ... ";
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
3918 reading_startup_message_printed = true;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
3919 std::cout.flush ();
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
3920 }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
3921
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
3922 fcn->do_multi_index_op (0, args);
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
3923
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
3924 if (verbose)
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
3925 std::cout << "done." << std::endl;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
3926
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
3927 delete fcn;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
3928 }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
3929 }
7715
5b4d278ec828 parse scripts completely before executing
John W. Eaton <jwe@octave.org>
parents: 7699
diff changeset
3930 else
15466
d174210ce1ec use ' instead of ` in error messages, warnings and most comments
John W. Eaton <jwe@octave.org>
parents: 14189
diff changeset
3931 error ("source: error sourcing file '%s'",
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
3932 file_full_name.c_str ());
5975
e64059303a6f [project @ 2006-08-29 16:37:39 by jwe]
jwe
parents: 5932
diff changeset
3933 }
4486
6ceba1f351fb [project @ 2003-08-22 16:49:46 by jwe]
jwe
parents: 4463
diff changeset
3934 }
6ceba1f351fb [project @ 2003-08-22 16:49:46 by jwe]
jwe
parents: 4463
diff changeset
3935
5739
d090d39bb82c [project @ 2006-04-05 06:56:24 by jwe]
jwe
parents: 5667
diff changeset
3936 DEFUN (mfilename, args, ,
d090d39bb82c [project @ 2006-04-05 06:56:24 by jwe]
jwe
parents: 5667
diff changeset
3937 "-*- texinfo -*-\n\
11572
7d6d8c1e471f Grammarcheck Texinfo for files in src directory.
Rik <octave@nomad.inbox5.com>
parents: 11523
diff changeset
3938 @deftypefn {Built-in Function} {} mfilename ()\n\
12719
7b5bfd6a8e28 doc: Don't use @code macro within @deftypefn macro
Rik <octave@nomad.inbox5.com>
parents: 12483
diff changeset
3939 @deftypefnx {Built-in Function} {} mfilename (\"fullpath\")\n\
7b5bfd6a8e28 doc: Don't use @code macro within @deftypefn macro
Rik <octave@nomad.inbox5.com>
parents: 12483
diff changeset
3940 @deftypefnx {Built-in Function} {} mfilename (\"fullpathext\")\n\
5739
d090d39bb82c [project @ 2006-04-05 06:56:24 by jwe]
jwe
parents: 5667
diff changeset
3941 Return the name of the currently executing file. At the top-level,\n\
17281
bc924baa2c4e doc: Add new @qcode macro for code samples which are quoted.
Rik <rik@octave.org>
parents: 17249
diff changeset
3942 return the empty string. Given the argument @qcode{\"fullpath\"},\n\
5739
d090d39bb82c [project @ 2006-04-05 06:56:24 by jwe]
jwe
parents: 5667
diff changeset
3943 include the directory part of the file name, but not the extension.\n\
17281
bc924baa2c4e doc: Add new @qcode macro for code samples which are quoted.
Rik <rik@octave.org>
parents: 17249
diff changeset
3944 Given the argument @qcode{\"fullpathext\"}, include the directory part\n\
5739
d090d39bb82c [project @ 2006-04-05 06:56:24 by jwe]
jwe
parents: 5667
diff changeset
3945 of the file name and the extension.\n\
5774
e7af222e98b0 [project @ 2006-04-24 17:45:31 by jwe]
jwe
parents: 5765
diff changeset
3946 @end deftypefn")
5739
d090d39bb82c [project @ 2006-04-05 06:56:24 by jwe]
jwe
parents: 5667
diff changeset
3947 {
d090d39bb82c [project @ 2006-04-05 06:56:24 by jwe]
jwe
parents: 5667
diff changeset
3948 octave_value retval;
d090d39bb82c [project @ 2006-04-05 06:56:24 by jwe]
jwe
parents: 5667
diff changeset
3949
d090d39bb82c [project @ 2006-04-05 06:56:24 by jwe]
jwe
parents: 5667
diff changeset
3950 int nargin = args.length ();
d090d39bb82c [project @ 2006-04-05 06:56:24 by jwe]
jwe
parents: 5667
diff changeset
3951
d090d39bb82c [project @ 2006-04-05 06:56:24 by jwe]
jwe
parents: 5667
diff changeset
3952 if (nargin > 1)
d090d39bb82c [project @ 2006-04-05 06:56:24 by jwe]
jwe
parents: 5667
diff changeset
3953 {
5823
080c08b192d8 [project @ 2006-05-19 05:32:17 by jwe]
jwe
parents: 5794
diff changeset
3954 print_usage ();
5739
d090d39bb82c [project @ 2006-04-05 06:56:24 by jwe]
jwe
parents: 5667
diff changeset
3955 return retval;
d090d39bb82c [project @ 2006-04-05 06:56:24 by jwe]
jwe
parents: 5667
diff changeset
3956 }
d090d39bb82c [project @ 2006-04-05 06:56:24 by jwe]
jwe
parents: 5667
diff changeset
3957
d090d39bb82c [project @ 2006-04-05 06:56:24 by jwe]
jwe
parents: 5667
diff changeset
3958 std::string arg;
d090d39bb82c [project @ 2006-04-05 06:56:24 by jwe]
jwe
parents: 5667
diff changeset
3959
d090d39bb82c [project @ 2006-04-05 06:56:24 by jwe]
jwe
parents: 5667
diff changeset
3960 if (nargin == 1)
d090d39bb82c [project @ 2006-04-05 06:56:24 by jwe]
jwe
parents: 5667
diff changeset
3961 {
d090d39bb82c [project @ 2006-04-05 06:56:24 by jwe]
jwe
parents: 5667
diff changeset
3962 arg = args(0).string_value ();
d090d39bb82c [project @ 2006-04-05 06:56:24 by jwe]
jwe
parents: 5667
diff changeset
3963
d090d39bb82c [project @ 2006-04-05 06:56:24 by jwe]
jwe
parents: 5667
diff changeset
3964 if (error_state)
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
3965 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
3966 error ("mfilename: expecting argument to be a character string");
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
3967 return retval;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
3968 }
5739
d090d39bb82c [project @ 2006-04-05 06:56:24 by jwe]
jwe
parents: 5667
diff changeset
3969 }
d090d39bb82c [project @ 2006-04-05 06:56:24 by jwe]
jwe
parents: 5667
diff changeset
3970
d090d39bb82c [project @ 2006-04-05 06:56:24 by jwe]
jwe
parents: 5667
diff changeset
3971 std::string fname;
d090d39bb82c [project @ 2006-04-05 06:56:24 by jwe]
jwe
parents: 5667
diff changeset
3972
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
3973 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
3974
a527e0f77aa5 [project @ 2006-04-06 08:20:21 by jwe]
jwe
parents: 5739
diff changeset
3975 if (fcn)
a527e0f77aa5 [project @ 2006-04-06 08:20:21 by jwe]
jwe
parents: 5739
diff changeset
3976 {
a527e0f77aa5 [project @ 2006-04-06 08:20:21 by jwe]
jwe
parents: 5739
diff changeset
3977 fname = fcn->fcn_file_name ();
a527e0f77aa5 [project @ 2006-04-06 08:20:21 by jwe]
jwe
parents: 5739
diff changeset
3978
a527e0f77aa5 [project @ 2006-04-06 08:20:21 by jwe]
jwe
parents: 5739
diff changeset
3979 if (fname.empty ())
a527e0f77aa5 [project @ 2006-04-06 08:20:21 by jwe]
jwe
parents: 5739
diff changeset
3980 fname = fcn->name ();
a527e0f77aa5 [project @ 2006-04-06 08:20:21 by jwe]
jwe
parents: 5739
diff changeset
3981 }
5739
d090d39bb82c [project @ 2006-04-05 06:56:24 by jwe]
jwe
parents: 5667
diff changeset
3982
d090d39bb82c [project @ 2006-04-05 06:56:24 by jwe]
jwe
parents: 5667
diff changeset
3983 if (arg == "fullpathext")
d090d39bb82c [project @ 2006-04-05 06:56:24 by jwe]
jwe
parents: 5667
diff changeset
3984 retval = fname;
d090d39bb82c [project @ 2006-04-05 06:56:24 by jwe]
jwe
parents: 5667
diff changeset
3985 else
d090d39bb82c [project @ 2006-04-05 06:56:24 by jwe]
jwe
parents: 5667
diff changeset
3986 {
8007
a2ab20ba78f7 make file_ops a proper singleton class
John W. Eaton <jwe@octave.org>
parents: 8001
diff changeset
3987 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
3988 size_t epos = fname.rfind ('.');
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5744
diff changeset
3989
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5744
diff changeset
3990 if (epos <= dpos)
8021
85184151822e fix typo in NPOS change
John W. Eaton <jwe@octave.org>
parents: 8019
diff changeset
3991 epos = std::string::npos;
85184151822e fix typo in NPOS change
John W. Eaton <jwe@octave.org>
parents: 8019
diff changeset
3992
85184151822e fix typo in NPOS change
John W. Eaton <jwe@octave.org>
parents: 8019
diff changeset
3993 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
3994
d090d39bb82c [project @ 2006-04-05 06:56:24 by jwe]
jwe
parents: 5667
diff changeset
3995 if (arg == "fullpath")
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
3996 retval = fname;
5739
d090d39bb82c [project @ 2006-04-05 06:56:24 by jwe]
jwe
parents: 5667
diff changeset
3997 else
8021
85184151822e fix typo in NPOS change
John W. Eaton <jwe@octave.org>
parents: 8019
diff changeset
3998 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
3999 }
d090d39bb82c [project @ 2006-04-05 06:56:24 by jwe]
jwe
parents: 5667
diff changeset
4000
d090d39bb82c [project @ 2006-04-05 06:56:24 by jwe]
jwe
parents: 5667
diff changeset
4001 return retval;
d090d39bb82c [project @ 2006-04-05 06:56:24 by jwe]
jwe
parents: 5667
diff changeset
4002 }
d090d39bb82c [project @ 2006-04-05 06:56:24 by jwe]
jwe
parents: 5667
diff changeset
4003
3021
18d64612e67a [project @ 1997-06-03 22:18:56 by jwe]
jwe
parents: 3016
diff changeset
4004 DEFUN (source, args, ,
3371
86873384cd10 [project @ 1999-11-21 17:31:07 by jwe]
jwe
parents: 3366
diff changeset
4005 "-*- texinfo -*-\n\
86873384cd10 [project @ 1999-11-21 17:31:07 by jwe]
jwe
parents: 3366
diff changeset
4006 @deftypefn {Built-in Function} {} source (@var{file})\n\
86873384cd10 [project @ 1999-11-21 17:31:07 by jwe]
jwe
parents: 3366
diff changeset
4007 Parse and execute the contents of @var{file}. This is equivalent to\n\
86873384cd10 [project @ 1999-11-21 17:31:07 by jwe]
jwe
parents: 3366
diff changeset
4008 executing commands from a script file, but without requiring the file to\n\
86873384cd10 [project @ 1999-11-21 17:31:07 by jwe]
jwe
parents: 3366
diff changeset
4009 be named @file{@var{file}.m}.\n\
86873384cd10 [project @ 1999-11-21 17:31:07 by jwe]
jwe
parents: 3366
diff changeset
4010 @end deftypefn")
3021
18d64612e67a [project @ 1997-06-03 22:18:56 by jwe]
jwe
parents: 3016
diff changeset
4011 {
18d64612e67a [project @ 1997-06-03 22:18:56 by jwe]
jwe
parents: 3016
diff changeset
4012 octave_value_list retval;
18d64612e67a [project @ 1997-06-03 22:18:56 by jwe]
jwe
parents: 3016
diff changeset
4013
18d64612e67a [project @ 1997-06-03 22:18:56 by jwe]
jwe
parents: 3016
diff changeset
4014 int nargin = args.length ();
18d64612e67a [project @ 1997-06-03 22:18:56 by jwe]
jwe
parents: 3016
diff changeset
4015
5975
e64059303a6f [project @ 2006-08-29 16:37:39 by jwe]
jwe
parents: 5932
diff changeset
4016 if (nargin == 1 || nargin == 2)
3021
18d64612e67a [project @ 1997-06-03 22:18:56 by jwe]
jwe
parents: 3016
diff changeset
4017 {
3523
b80bbb43a1a9 [project @ 2000-02-02 10:25:52 by jwe]
jwe
parents: 3489
diff changeset
4018 std::string file_name = args(0).string_value ();
3021
18d64612e67a [project @ 1997-06-03 22:18:56 by jwe]
jwe
parents: 3016
diff changeset
4019
18d64612e67a [project @ 1997-06-03 22:18:56 by jwe]
jwe
parents: 3016
diff changeset
4020 if (! error_state)
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
4021 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
4022 std::string context;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
4023
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
4024 if (nargin == 2)
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
4025 context = args(1).string_value ();
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
4026
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
4027 if (! error_state)
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
4028 source_file (file_name, context);
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
4029 else
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
4030 error ("source: expecting context to be character string");
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
4031 }
3021
18d64612e67a [project @ 1997-06-03 22:18:56 by jwe]
jwe
parents: 3016
diff changeset
4032 else
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
4033 error ("source: expecting file name as argument");
3021
18d64612e67a [project @ 1997-06-03 22:18:56 by jwe]
jwe
parents: 3016
diff changeset
4034 }
18d64612e67a [project @ 1997-06-03 22:18:56 by jwe]
jwe
parents: 3016
diff changeset
4035 else
5823
080c08b192d8 [project @ 2006-05-19 05:32:17 by jwe]
jwe
parents: 5794
diff changeset
4036 print_usage ();
3021
18d64612e67a [project @ 1997-06-03 22:18:56 by jwe]
jwe
parents: 3016
diff changeset
4037
18d64612e67a [project @ 1997-06-03 22:18:56 by jwe]
jwe
parents: 3016
diff changeset
4038 return retval;
18d64612e67a [project @ 1997-06-03 22:18:56 by jwe]
jwe
parents: 3016
diff changeset
4039 }
18d64612e67a [project @ 1997-06-03 22:18:56 by jwe]
jwe
parents: 3016
diff changeset
4040
3726
b7d997d593d9 [project @ 2000-10-27 17:51:21 by jwe]
jwe
parents: 3712
diff changeset
4041 // 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
4042 // 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
4043 // 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
4044 // number of output arguments expected.
3726
b7d997d593d9 [project @ 2000-10-27 17:51:21 by jwe]
jwe
parents: 3712
diff changeset
4045
3021
18d64612e67a [project @ 1997-06-03 22:18:56 by jwe]
jwe
parents: 3016
diff changeset
4046 octave_value_list
3523
b80bbb43a1a9 [project @ 2000-02-02 10:25:52 by jwe]
jwe
parents: 3489
diff changeset
4047 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
4048 {
a494f93e60ff [project @ 1998-02-20 07:47:48 by jwe]
jwe
parents: 3110
diff changeset
4049 octave_value_list retval;
a494f93e60ff [project @ 1998-02-20 07:47:48 by jwe]
jwe
parents: 3110
diff changeset
4050
7336
745a8299c2b5 [project @ 2007-12-28 20:56:55 by jwe]
jwe
parents: 7017
diff changeset
4051 octave_value fcn = symbol_table::find_function (name, args);
745a8299c2b5 [project @ 2007-12-28 20:56:55 by jwe]
jwe
parents: 7017
diff changeset
4052
745a8299c2b5 [project @ 2007-12-28 20:56:55 by jwe]
jwe
parents: 7017
diff changeset
4053 if (fcn.is_defined ())
745a8299c2b5 [project @ 2007-12-28 20:56:55 by jwe]
jwe
parents: 7017
diff changeset
4054 retval = fcn.do_multi_index_op (nargout, args);
745a8299c2b5 [project @ 2007-12-28 20:56:55 by jwe]
jwe
parents: 7017
diff changeset
4055 else
10443
34e51d4e199b implement smart warnings about missing Matlab functionality
Jaroslav Hajek <highegg@gmail.com>
parents: 10426
diff changeset
4056 {
34e51d4e199b implement smart warnings about missing Matlab functionality
Jaroslav Hajek <highegg@gmail.com>
parents: 10426
diff changeset
4057 maybe_missing_function_hook (name);
34e51d4e199b implement smart warnings about missing Matlab functionality
Jaroslav Hajek <highegg@gmail.com>
parents: 10426
diff changeset
4058 if (! error_state)
15466
d174210ce1ec use ' instead of ` in error messages, warnings and most comments
John W. Eaton <jwe@octave.org>
parents: 14189
diff changeset
4059 error ("feval: function '%s' not found", name.c_str ());
10443
34e51d4e199b implement smart warnings about missing Matlab functionality
Jaroslav Hajek <highegg@gmail.com>
parents: 10426
diff changeset
4060 }
3156
a494f93e60ff [project @ 1998-02-20 07:47:48 by jwe]
jwe
parents: 3110
diff changeset
4061
a494f93e60ff [project @ 1998-02-20 07:47:48 by jwe]
jwe
parents: 3110
diff changeset
4062 return retval;
a494f93e60ff [project @ 1998-02-20 07:47:48 by jwe]
jwe
parents: 3110
diff changeset
4063 }
a494f93e60ff [project @ 1998-02-20 07:47:48 by jwe]
jwe
parents: 3110
diff changeset
4064
4342
813effe14ee1 [project @ 2003-02-20 08:35:55 by jwe]
jwe
parents: 4318
diff changeset
4065 octave_value_list
813effe14ee1 [project @ 2003-02-20 08:35:55 by jwe]
jwe
parents: 4318
diff changeset
4066 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
4067 {
813effe14ee1 [project @ 2003-02-20 08:35:55 by jwe]
jwe
parents: 4318
diff changeset
4068 octave_value_list retval;
813effe14ee1 [project @ 2003-02-20 08:35:55 by jwe]
jwe
parents: 4318
diff changeset
4069
813effe14ee1 [project @ 2003-02-20 08:35:55 by jwe]
jwe
parents: 4318
diff changeset
4070 if (fcn)
813effe14ee1 [project @ 2003-02-20 08:35:55 by jwe]
jwe
parents: 4318
diff changeset
4071 retval = fcn->do_multi_index_op (nargout, args);
813effe14ee1 [project @ 2003-02-20 08:35:55 by jwe]
jwe
parents: 4318
diff changeset
4072
813effe14ee1 [project @ 2003-02-20 08:35:55 by jwe]
jwe
parents: 4318
diff changeset
4073 return retval;
813effe14ee1 [project @ 2003-02-20 08:35:55 by jwe]
jwe
parents: 4318
diff changeset
4074 }
813effe14ee1 [project @ 2003-02-20 08:35:55 by jwe]
jwe
parents: 4318
diff changeset
4075
813effe14ee1 [project @ 2003-02-20 08:35:55 by jwe]
jwe
parents: 4318
diff changeset
4076 static octave_value_list
813effe14ee1 [project @ 2003-02-20 08:35:55 by jwe]
jwe
parents: 4318
diff changeset
4077 get_feval_args (const octave_value_list& args)
813effe14ee1 [project @ 2003-02-20 08:35:55 by jwe]
jwe
parents: 4318
diff changeset
4078 {
10659
8baff2aceabc fix slicing value lists with name tags (bug #29960)
Jaroslav Hajek <highegg@gmail.com>
parents: 10578
diff changeset
4079 return args.slice (1, args.length () - 1, true);
4342
813effe14ee1 [project @ 2003-02-20 08:35:55 by jwe]
jwe
parents: 4318
diff changeset
4080 }
813effe14ee1 [project @ 2003-02-20 08:35:55 by jwe]
jwe
parents: 4318
diff changeset
4081
813effe14ee1 [project @ 2003-02-20 08:35:55 by jwe]
jwe
parents: 4318
diff changeset
4082
3726
b7d997d593d9 [project @ 2000-10-27 17:51:21 by jwe]
jwe
parents: 3712
diff changeset
4083 // 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
4084 // 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
4085 // 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
4086 // 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
4087 // output arguments expected.
b7d997d593d9 [project @ 2000-10-27 17:51:21 by jwe]
jwe
parents: 3712
diff changeset
4088
3156
a494f93e60ff [project @ 1998-02-20 07:47:48 by jwe]
jwe
parents: 3110
diff changeset
4089 octave_value_list
3021
18d64612e67a [project @ 1997-06-03 22:18:56 by jwe]
jwe
parents: 3016
diff changeset
4090 feval (const octave_value_list& args, int nargout)
18d64612e67a [project @ 1997-06-03 22:18:56 by jwe]
jwe
parents: 3016
diff changeset
4091 {
18d64612e67a [project @ 1997-06-03 22:18:56 by jwe]
jwe
parents: 3016
diff changeset
4092 octave_value_list retval;
18d64612e67a [project @ 1997-06-03 22:18:56 by jwe]
jwe
parents: 3016
diff changeset
4093
4342
813effe14ee1 [project @ 2003-02-20 08:35:55 by jwe]
jwe
parents: 4318
diff changeset
4094 int nargin = args.length ();
813effe14ee1 [project @ 2003-02-20 08:35:55 by jwe]
jwe
parents: 4318
diff changeset
4095
813effe14ee1 [project @ 2003-02-20 08:35:55 by jwe]
jwe
parents: 4318
diff changeset
4096 if (nargin > 0)
3021
18d64612e67a [project @ 1997-06-03 22:18:56 by jwe]
jwe
parents: 3016
diff changeset
4097 {
4342
813effe14ee1 [project @ 2003-02-20 08:35:55 by jwe]
jwe
parents: 4318
diff changeset
4098 octave_value f_arg = args(0);
813effe14ee1 [project @ 2003-02-20 08:35:55 by jwe]
jwe
parents: 4318
diff changeset
4099
813effe14ee1 [project @ 2003-02-20 08:35:55 by jwe]
jwe
parents: 4318
diff changeset
4100 if (f_arg.is_string ())
813effe14ee1 [project @ 2003-02-20 08:35:55 by jwe]
jwe
parents: 4318
diff changeset
4101 {
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
4102 std::string name = f_arg.string_value ();
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
4103
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
4104 if (! error_state)
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
4105 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
4106 octave_value_list tmp_args = get_feval_args (args);
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
4107
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
4108 retval = feval (name, tmp_args, nargout);
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
4109 }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
4110 }
13241
2a8dcb5b3a00 improve default indexing for objects
John W. Eaton <jwe@octave.org>
parents: 13237
diff changeset
4111 else if (f_arg.is_function_handle ()
2a8dcb5b3a00 improve default indexing for objects
John W. Eaton <jwe@octave.org>
parents: 13237
diff changeset
4112 || f_arg.is_anonymous_function ()
2a8dcb5b3a00 improve default indexing for objects
John W. Eaton <jwe@octave.org>
parents: 13237
diff changeset
4113 || f_arg.is_inline_function ())
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
4114 {
10492
a6b64a7a3769 make feval work with overloaded handles
Jaroslav Hajek <highegg@gmail.com>
parents: 10463
diff changeset
4115 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
4116
a6b64a7a3769 make feval work with overloaded handles
Jaroslav Hajek <highegg@gmail.com>
parents: 10463
diff changeset
4117 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
4118 }
10492
a6b64a7a3769 make feval work with overloaded handles
Jaroslav Hajek <highegg@gmail.com>
parents: 10463
diff changeset
4119 else
a6b64a7a3769 make feval work with overloaded handles
Jaroslav Hajek <highegg@gmail.com>
parents: 10463
diff changeset
4120 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
4121 }
18d64612e67a [project @ 1997-06-03 22:18:56 by jwe]
jwe
parents: 3016
diff changeset
4122
18d64612e67a [project @ 1997-06-03 22:18:56 by jwe]
jwe
parents: 3016
diff changeset
4123 return retval;
18d64612e67a [project @ 1997-06-03 22:18:56 by jwe]
jwe
parents: 3016
diff changeset
4124 }
18d64612e67a [project @ 1997-06-03 22:18:56 by jwe]
jwe
parents: 3016
diff changeset
4125
18d64612e67a [project @ 1997-06-03 22:18:56 by jwe]
jwe
parents: 3016
diff changeset
4126 DEFUN (feval, args, nargout,
3371
86873384cd10 [project @ 1999-11-21 17:31:07 by jwe]
jwe
parents: 3366
diff changeset
4127 "-*- texinfo -*-\n\
86873384cd10 [project @ 1999-11-21 17:31:07 by jwe]
jwe
parents: 3366
diff changeset
4128 @deftypefn {Built-in Function} {} feval (@var{name}, @dots{})\n\
86873384cd10 [project @ 1999-11-21 17:31:07 by jwe]
jwe
parents: 3366
diff changeset
4129 Evaluate the function named @var{name}. Any arguments after the first\n\
16789
2f63d2f3ff11 doc: Update docstrings in oct-parse.in.yy.
Rik <rik@octave.org>
parents: 16681
diff changeset
4130 are passed as inputs to the named function. For example,\n\
3371
86873384cd10 [project @ 1999-11-21 17:31:07 by jwe]
jwe
parents: 3366
diff changeset
4131 \n\
86873384cd10 [project @ 1999-11-21 17:31:07 by jwe]
jwe
parents: 3366
diff changeset
4132 @example\n\
11572
7d6d8c1e471f Grammarcheck Texinfo for files in src directory.
Rik <octave@nomad.inbox5.com>
parents: 11523
diff changeset
4133 @group\n\
3371
86873384cd10 [project @ 1999-11-21 17:31:07 by jwe]
jwe
parents: 3366
diff changeset
4134 feval (\"acos\", -1)\n\
86873384cd10 [project @ 1999-11-21 17:31:07 by jwe]
jwe
parents: 3366
diff changeset
4135 @result{} 3.1416\n\
11572
7d6d8c1e471f Grammarcheck Texinfo for files in src directory.
Rik <octave@nomad.inbox5.com>
parents: 11523
diff changeset
4136 @end group\n\
3371
86873384cd10 [project @ 1999-11-21 17:31:07 by jwe]
jwe
parents: 3366
diff changeset
4137 @end example\n\
3021
18d64612e67a [project @ 1997-06-03 22:18:56 by jwe]
jwe
parents: 3016
diff changeset
4138 \n\
3371
86873384cd10 [project @ 1999-11-21 17:31:07 by jwe]
jwe
parents: 3366
diff changeset
4139 @noindent\n\
86873384cd10 [project @ 1999-11-21 17:31:07 by jwe]
jwe
parents: 3366
diff changeset
4140 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
4141 \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
4142 The function @code{feval} can also be used with function handles of\n\
13019
1653d3a86fca doc: Fix warnings and errors in Texinfo required for building docs on stable branch.
Rik <octave@nomad.inbox5.com>
parents: 12946
diff changeset
4143 any sort (@pxref{Function Handles}). Historically, @code{feval} was\n\
12946
8b5b85e26246 octave-parse.yy (feval): Update docstring to refer to function handles.
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents: 12918
diff changeset
4144 the only way to call user-supplied functions in strings, but\n\
8b5b85e26246 octave-parse.yy (feval): Update docstring to refer to function handles.
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents: 12918
diff changeset
4145 function handles are now preferred due to the cleaner syntax they\n\
13019
1653d3a86fca doc: Fix warnings and errors in Texinfo required for building docs on stable branch.
Rik <octave@nomad.inbox5.com>
parents: 12946
diff changeset
4146 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
4147 \n\
8b5b85e26246 octave-parse.yy (feval): Update docstring to refer to function handles.
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents: 12918
diff changeset
4148 @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
4149 @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
4150 @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
4151 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
4152 @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
4153 @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
4154 @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
4155 @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
4156 @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
4157 \n\
8b5b85e26246 octave-parse.yy (feval): Update docstring to refer to function handles.
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents: 12918
diff changeset
4158 @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
4159 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
4160 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
4161 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
4162 instead.\n\
3371
86873384cd10 [project @ 1999-11-21 17:31:07 by jwe]
jwe
parents: 3366
diff changeset
4163 @end deftypefn")
3021
18d64612e67a [project @ 1997-06-03 22:18:56 by jwe]
jwe
parents: 3016
diff changeset
4164 {
18d64612e67a [project @ 1997-06-03 22:18:56 by jwe]
jwe
parents: 3016
diff changeset
4165 octave_value_list retval;
18d64612e67a [project @ 1997-06-03 22:18:56 by jwe]
jwe
parents: 3016
diff changeset
4166
18d64612e67a [project @ 1997-06-03 22:18:56 by jwe]
jwe
parents: 3016
diff changeset
4167 int nargin = args.length ();
18d64612e67a [project @ 1997-06-03 22:18:56 by jwe]
jwe
parents: 3016
diff changeset
4168
18d64612e67a [project @ 1997-06-03 22:18:56 by jwe]
jwe
parents: 3016
diff changeset
4169 if (nargin > 0)
18d64612e67a [project @ 1997-06-03 22:18:56 by jwe]
jwe
parents: 3016
diff changeset
4170 retval = feval (args, nargout);
18d64612e67a [project @ 1997-06-03 22:18:56 by jwe]
jwe
parents: 3016
diff changeset
4171 else
5823
080c08b192d8 [project @ 2006-05-19 05:32:17 by jwe]
jwe
parents: 5794
diff changeset
4172 print_usage ();
3021
18d64612e67a [project @ 1997-06-03 22:18:56 by jwe]
jwe
parents: 3016
diff changeset
4173
18d64612e67a [project @ 1997-06-03 22:18:56 by jwe]
jwe
parents: 3016
diff changeset
4174 return retval;
18d64612e67a [project @ 1997-06-03 22:18:56 by jwe]
jwe
parents: 3016
diff changeset
4175 }
18d64612e67a [project @ 1997-06-03 22:18:56 by jwe]
jwe
parents: 3016
diff changeset
4176
11225
8d8e10058df6 move builtin function from dispatch.cc to oct-parse.yy
John W. Eaton <jwe@octave.org>
parents: 11138
diff changeset
4177 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
4178 "-*- texinfo -*-\n\
16789
2f63d2f3ff11 doc: Update docstrings in oct-parse.in.yy.
Rik <rik@octave.org>
parents: 16681
diff changeset
4179 @deftypefn {Loadable Function} {[@dots{}] =} builtin (@var{f}, @dots{})\n\
11225
8d8e10058df6 move builtin function from dispatch.cc to oct-parse.yy
John W. Eaton <jwe@octave.org>
parents: 11138
diff changeset
4180 Call the base function @var{f} even if @var{f} is overloaded to\n\
11388
027fbc389898 Remove seealso reference to deprecated function dispatch.
Rik <octave@nomad.inbox5.com>
parents: 11367
diff changeset
4181 another 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
4182 \n\
2f63d2f3ff11 doc: Update docstrings in oct-parse.in.yy.
Rik <rik@octave.org>
parents: 16681
diff changeset
4183 This is normally useful when doing object-oriented programming and there\n\
2f63d2f3ff11 doc: Update docstrings in oct-parse.in.yy.
Rik <rik@octave.org>
parents: 16681
diff changeset
4184 is a requirement to call one of Octave's base functions rather than\n\
2f63d2f3ff11 doc: Update docstrings in oct-parse.in.yy.
Rik <rik@octave.org>
parents: 16681
diff changeset
4185 the overloaded one of a new class.\n\
2f63d2f3ff11 doc: Update docstrings in oct-parse.in.yy.
Rik <rik@octave.org>
parents: 16681
diff changeset
4186 \n\
2f63d2f3ff11 doc: Update docstrings in oct-parse.in.yy.
Rik <rik@octave.org>
parents: 16681
diff changeset
4187 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
4188 @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
4189 \n\
2f63d2f3ff11 doc: Update docstrings in oct-parse.in.yy.
Rik <rik@octave.org>
parents: 16681
diff changeset
4190 @example\n\
2f63d2f3ff11 doc: Update docstrings in oct-parse.in.yy.
Rik <rik@octave.org>
parents: 16681
diff changeset
4191 @group\n\
2f63d2f3ff11 doc: Update docstrings in oct-parse.in.yy.
Rik <rik@octave.org>
parents: 16681
diff changeset
4192 sin (0)\n\
2f63d2f3ff11 doc: Update docstrings in oct-parse.in.yy.
Rik <rik@octave.org>
parents: 16681
diff changeset
4193 @result{} 0\n\
2f63d2f3ff11 doc: Update docstrings in oct-parse.in.yy.
Rik <rik@octave.org>
parents: 16681
diff changeset
4194 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
4195 sin (0)\n\
2f63d2f3ff11 doc: Update docstrings in oct-parse.in.yy.
Rik <rik@octave.org>
parents: 16681
diff changeset
4196 @result{} 1\n\
2f63d2f3ff11 doc: Update docstrings in oct-parse.in.yy.
Rik <rik@octave.org>
parents: 16681
diff changeset
4197 builtin (\"sin\", 0)\n\
2f63d2f3ff11 doc: Update docstrings in oct-parse.in.yy.
Rik <rik@octave.org>
parents: 16681
diff changeset
4198 @result{} 0\n\
2f63d2f3ff11 doc: Update docstrings in oct-parse.in.yy.
Rik <rik@octave.org>
parents: 16681
diff changeset
4199 @end group\n\
2f63d2f3ff11 doc: Update docstrings in oct-parse.in.yy.
Rik <rik@octave.org>
parents: 16681
diff changeset
4200 @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
4201 @end deftypefn")
8d8e10058df6 move builtin function from dispatch.cc to oct-parse.yy
John W. Eaton <jwe@octave.org>
parents: 11138
diff changeset
4202 {
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11572
diff changeset
4203 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
4204
8d8e10058df6 move builtin function from dispatch.cc to oct-parse.yy
John W. Eaton <jwe@octave.org>
parents: 11138
diff changeset
4205 int nargin = args.length ();
8d8e10058df6 move builtin function from dispatch.cc to oct-parse.yy
John W. Eaton <jwe@octave.org>
parents: 11138
diff changeset
4206
8d8e10058df6 move builtin function from dispatch.cc to oct-parse.yy
John W. Eaton <jwe@octave.org>
parents: 11138
diff changeset
4207 if (nargin > 0)
8d8e10058df6 move builtin function from dispatch.cc to oct-parse.yy
John W. Eaton <jwe@octave.org>
parents: 11138
diff changeset
4208 {
8d8e10058df6 move builtin function from dispatch.cc to oct-parse.yy
John W. Eaton <jwe@octave.org>
parents: 11138
diff changeset
4209 const std::string name (args(0).string_value ());
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11572
diff changeset
4210
11225
8d8e10058df6 move builtin function from dispatch.cc to oct-parse.yy
John W. Eaton <jwe@octave.org>
parents: 11138
diff changeset
4211 if (! error_state)
8d8e10058df6 move builtin function from dispatch.cc to oct-parse.yy
John W. Eaton <jwe@octave.org>
parents: 11138
diff changeset
4212 {
8d8e10058df6 move builtin function from dispatch.cc to oct-parse.yy
John W. Eaton <jwe@octave.org>
parents: 11138
diff changeset
4213 octave_value fcn = symbol_table::builtin_find (name);
8d8e10058df6 move builtin function from dispatch.cc to oct-parse.yy
John W. Eaton <jwe@octave.org>
parents: 11138
diff changeset
4214
8d8e10058df6 move builtin function from dispatch.cc to oct-parse.yy
John W. Eaton <jwe@octave.org>
parents: 11138
diff changeset
4215 if (fcn.is_defined ())
8d8e10058df6 move builtin function from dispatch.cc to oct-parse.yy
John W. Eaton <jwe@octave.org>
parents: 11138
diff changeset
4216 retval = feval (fcn.function_value (), args.splice (0, 1),
8d8e10058df6 move builtin function from dispatch.cc to oct-parse.yy
John W. Eaton <jwe@octave.org>
parents: 11138
diff changeset
4217 nargout);
8d8e10058df6 move builtin function from dispatch.cc to oct-parse.yy
John W. Eaton <jwe@octave.org>
parents: 11138
diff changeset
4218 else
15466
d174210ce1ec use ' instead of ` in error messages, warnings and most comments
John W. Eaton <jwe@octave.org>
parents: 14189
diff changeset
4219 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
4220 }
8d8e10058df6 move builtin function from dispatch.cc to oct-parse.yy
John W. Eaton <jwe@octave.org>
parents: 11138
diff changeset
4221 else
12483
7a5aacf65f81 Rewrite error strings in src/ to use variables named in documentation.
Rik <octave@nomad.inbox5.com>
parents: 12400
diff changeset
4222 error ("builtin: function name (F) must be a string");
11225
8d8e10058df6 move builtin function from dispatch.cc to oct-parse.yy
John W. Eaton <jwe@octave.org>
parents: 11138
diff changeset
4223 }
8d8e10058df6 move builtin function from dispatch.cc to oct-parse.yy
John W. Eaton <jwe@octave.org>
parents: 11138
diff changeset
4224 else
8d8e10058df6 move builtin function from dispatch.cc to oct-parse.yy
John W. Eaton <jwe@octave.org>
parents: 11138
diff changeset
4225 print_usage ();
8d8e10058df6 move builtin function from dispatch.cc to oct-parse.yy
John W. Eaton <jwe@octave.org>
parents: 11138
diff changeset
4226
8d8e10058df6 move builtin function from dispatch.cc to oct-parse.yy
John W. Eaton <jwe@octave.org>
parents: 11138
diff changeset
4227 return retval;
8d8e10058df6 move builtin function from dispatch.cc to oct-parse.yy
John W. Eaton <jwe@octave.org>
parents: 11138
diff changeset
4228 }
8d8e10058df6 move builtin function from dispatch.cc to oct-parse.yy
John W. Eaton <jwe@octave.org>
parents: 11138
diff changeset
4229
3099
8ce6fed79320 [project @ 1997-11-14 09:49:28 by jwe]
jwe
parents: 3095
diff changeset
4230 octave_value_list
16195
b52d2f9294b6 use class for reading lexer input
John W. Eaton <jwe@octave.org>
parents: 16187
diff changeset
4231 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
4232 int& parse_status, int nargout)
3021
18d64612e67a [project @ 1997-06-03 22:18:56 by jwe]
jwe
parents: 3016
diff changeset
4233 {
3877
55648fc616c8 [project @ 2002-03-07 23:00:09 by jwe]
jwe
parents: 3844
diff changeset
4234 octave_value_list retval;
55648fc616c8 [project @ 2002-03-07 23:00:09 by jwe]
jwe
parents: 3844
diff changeset
4235
16288
fe3b9a51e625 rename curr_lexer, curr_parser, CURR_LEXER
John W. Eaton <jwe@octave.org>
parents: 16287
diff changeset
4236 octave_parser parser (eval_str);
16195
b52d2f9294b6 use class for reading lexer input
John W. Eaton <jwe@octave.org>
parents: 16187
diff changeset
4237
3877
55648fc616c8 [project @ 2002-03-07 23:00:09 by jwe]
jwe
parents: 3844
diff changeset
4238 do
55648fc616c8 [project @ 2002-03-07 23:00:09 by jwe]
jwe
parents: 3844
diff changeset
4239 {
16288
fe3b9a51e625 rename curr_lexer, curr_parser, CURR_LEXER
John W. Eaton <jwe@octave.org>
parents: 16287
diff changeset
4240 parser.reset ();
fe3b9a51e625 rename curr_lexer, curr_parser, CURR_LEXER
John W. Eaton <jwe@octave.org>
parents: 16287
diff changeset
4241
fe3b9a51e625 rename curr_lexer, curr_parser, CURR_LEXER
John W. Eaton <jwe@octave.org>
parents: 16287
diff changeset
4242 parse_status = parser.run ();
3877
55648fc616c8 [project @ 2002-03-07 23:00:09 by jwe]
jwe
parents: 3844
diff changeset
4243
3883
69b6bd271277 [project @ 2002-04-02 21:05:10 by jwe]
jwe
parents: 3881
diff changeset
4244 if (parse_status == 0)
3877
55648fc616c8 [project @ 2002-03-07 23:00:09 by jwe]
jwe
parents: 3844
diff changeset
4245 {
16288
fe3b9a51e625 rename curr_lexer, curr_parser, CURR_LEXER
John W. Eaton <jwe@octave.org>
parents: 16287
diff changeset
4246 if (parser.stmt_list)
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
4247 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
4248 tree_statement *stmt = 0;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
4249
16288
fe3b9a51e625 rename curr_lexer, curr_parser, CURR_LEXER
John W. Eaton <jwe@octave.org>
parents: 16287
diff changeset
4250 if (parser.stmt_list->length () == 1
fe3b9a51e625 rename curr_lexer, curr_parser, CURR_LEXER
John W. Eaton <jwe@octave.org>
parents: 16287
diff changeset
4251 && (stmt = parser.stmt_list->front ())
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
4252 && stmt->is_expression ())
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
4253 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
4254 tree_expression *expr = stmt->expression ();
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
4255
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
4256 if (silent)
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
4257 expr->set_print_flag (false);
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
4258
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
4259 bool do_bind_ans = false;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
4260
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
4261 if (expr->is_identifier ())
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
4262 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
4263 tree_identifier *id
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
4264 = dynamic_cast<tree_identifier *> (expr);
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
4265
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
4266 do_bind_ans = (! id->is_variable ());
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
4267 }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
4268 else
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
4269 do_bind_ans = (! expr->is_assignment_expression ());
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
4270
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
4271 retval = expr->rvalue (nargout);
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
4272
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
4273 if (do_bind_ans && ! (error_state || retval.empty ()))
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
4274 bind_ans (retval(0), expr->print_result ());
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
4275
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
4276 if (nargout == 0)
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
4277 retval = octave_value_list ();
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
4278 }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
4279 else if (nargout == 0)
16288
fe3b9a51e625 rename curr_lexer, curr_parser, CURR_LEXER
John W. Eaton <jwe@octave.org>
parents: 16287
diff changeset
4280 parser.stmt_list->accept (*current_evaluator);
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
4281 else
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
4282 error ("eval: invalid use of statement list");
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
4283
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
4284 if (error_state
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
4285 || tree_return_command::returning
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
4286 || tree_break_command::breaking
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
4287 || tree_continue_command::continuing)
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
4288 break;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
4289 }
16288
fe3b9a51e625 rename curr_lexer, curr_parser, CURR_LEXER
John W. Eaton <jwe@octave.org>
parents: 16287
diff changeset
4290 else if (parser.lexer.end_of_input)
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
4291 break;
3883
69b6bd271277 [project @ 2002-04-02 21:05:10 by jwe]
jwe
parents: 3881
diff changeset
4292 }
3877
55648fc616c8 [project @ 2002-03-07 23:00:09 by jwe]
jwe
parents: 3844
diff changeset
4293 }
55648fc616c8 [project @ 2002-03-07 23:00:09 by jwe]
jwe
parents: 3844
diff changeset
4294 while (parse_status == 0);
3021
18d64612e67a [project @ 1997-06-03 22:18:56 by jwe]
jwe
parents: 3016
diff changeset
4295
18d64612e67a [project @ 1997-06-03 22:18:56 by jwe]
jwe
parents: 3016
diff changeset
4296 return retval;
18d64612e67a [project @ 1997-06-03 22:18:56 by jwe]
jwe
parents: 3016
diff changeset
4297 }
18d64612e67a [project @ 1997-06-03 22:18:56 by jwe]
jwe
parents: 3016
diff changeset
4298
18d64612e67a [project @ 1997-06-03 22:18:56 by jwe]
jwe
parents: 3016
diff changeset
4299 octave_value
16195
b52d2f9294b6 use class for reading lexer input
John W. Eaton <jwe@octave.org>
parents: 16187
diff changeset
4300 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
4301 {
18d64612e67a [project @ 1997-06-03 22:18:56 by jwe]
jwe
parents: 3016
diff changeset
4302 octave_value retval;
18d64612e67a [project @ 1997-06-03 22:18:56 by jwe]
jwe
parents: 3016
diff changeset
4303
16195
b52d2f9294b6 use class for reading lexer input
John W. Eaton <jwe@octave.org>
parents: 16187
diff changeset
4304 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
4305
18d64612e67a [project @ 1997-06-03 22:18:56 by jwe]
jwe
parents: 3016
diff changeset
4306 if (! tmp.empty ())
18d64612e67a [project @ 1997-06-03 22:18:56 by jwe]
jwe
parents: 3016
diff changeset
4307 retval = tmp(0);
18d64612e67a [project @ 1997-06-03 22:18:56 by jwe]
jwe
parents: 3016
diff changeset
4308
18d64612e67a [project @ 1997-06-03 22:18:56 by jwe]
jwe
parents: 3016
diff changeset
4309 return retval;
18d64612e67a [project @ 1997-06-03 22:18:56 by jwe]
jwe
parents: 3016
diff changeset
4310 }
18d64612e67a [project @ 1997-06-03 22:18:56 by jwe]
jwe
parents: 3016
diff changeset
4311
18d64612e67a [project @ 1997-06-03 22:18:56 by jwe]
jwe
parents: 3016
diff changeset
4312 static octave_value_list
18d64612e67a [project @ 1997-06-03 22:18:56 by jwe]
jwe
parents: 3016
diff changeset
4313 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
4314 int nargout)
3021
18d64612e67a [project @ 1997-06-03 22:18:56 by jwe]
jwe
parents: 3016
diff changeset
4315 {
3523
b80bbb43a1a9 [project @ 2000-02-02 10:25:52 by jwe]
jwe
parents: 3489
diff changeset
4316 std::string s = arg.string_value ();
3021
18d64612e67a [project @ 1997-06-03 22:18:56 by jwe]
jwe
parents: 3016
diff changeset
4317
18d64612e67a [project @ 1997-06-03 22:18:56 by jwe]
jwe
parents: 3016
diff changeset
4318 if (error_state)
18d64612e67a [project @ 1997-06-03 22:18:56 by jwe]
jwe
parents: 3016
diff changeset
4319 {
3523
b80bbb43a1a9 [project @ 2000-02-02 10:25:52 by jwe]
jwe
parents: 3489
diff changeset
4320 error ("eval: expecting std::string argument");
4233
ccfdb55c8156 [project @ 2002-12-20 22:43:54 by jwe]
jwe
parents: 4219
diff changeset
4321 return octave_value (-1);
3021
18d64612e67a [project @ 1997-06-03 22:18:56 by jwe]
jwe
parents: 3016
diff changeset
4322 }
18d64612e67a [project @ 1997-06-03 22:18:56 by jwe]
jwe
parents: 3016
diff changeset
4323
18d64612e67a [project @ 1997-06-03 22:18:56 by jwe]
jwe
parents: 3016
diff changeset
4324 return eval_string (s, silent, parse_status, nargout);
18d64612e67a [project @ 1997-06-03 22:18:56 by jwe]
jwe
parents: 3016
diff changeset
4325 }
18d64612e67a [project @ 1997-06-03 22:18:56 by jwe]
jwe
parents: 3016
diff changeset
4326
13970
c93b953f7d54 plug some memory leaks
John W. Eaton <jwe@octave.org>
parents: 13844
diff changeset
4327 void
c93b953f7d54 plug some memory leaks
John W. Eaton <jwe@octave.org>
parents: 13844
diff changeset
4328 cleanup_statement_list (tree_statement_list **lst)
c93b953f7d54 plug some memory leaks
John W. Eaton <jwe@octave.org>
parents: 13844
diff changeset
4329 {
c93b953f7d54 plug some memory leaks
John W. Eaton <jwe@octave.org>
parents: 13844
diff changeset
4330 if (*lst)
c93b953f7d54 plug some memory leaks
John W. Eaton <jwe@octave.org>
parents: 13844
diff changeset
4331 {
c93b953f7d54 plug some memory leaks
John W. Eaton <jwe@octave.org>
parents: 13844
diff changeset
4332 delete *lst;
c93b953f7d54 plug some memory leaks
John W. Eaton <jwe@octave.org>
parents: 13844
diff changeset
4333 *lst = 0;
c93b953f7d54 plug some memory leaks
John W. Eaton <jwe@octave.org>
parents: 13844
diff changeset
4334 }
c93b953f7d54 plug some memory leaks
John W. Eaton <jwe@octave.org>
parents: 13844
diff changeset
4335 }
c93b953f7d54 plug some memory leaks
John W. Eaton <jwe@octave.org>
parents: 13844
diff changeset
4336
3021
18d64612e67a [project @ 1997-06-03 22:18:56 by jwe]
jwe
parents: 3016
diff changeset
4337 DEFUN (eval, args, nargout,
3371
86873384cd10 [project @ 1999-11-21 17:31:07 by jwe]
jwe
parents: 3366
diff changeset
4338 "-*- texinfo -*-\n\
14172
cba1c681f1b7 doc: Update seealso references for eval family of functions.
Rik <octave@nomad.inbox5.com>
parents: 14153
diff changeset
4339 @deftypefn {Built-in Function} {} eval (@var{try})\n\
cba1c681f1b7 doc: Update seealso references for eval family of functions.
Rik <octave@nomad.inbox5.com>
parents: 14153
diff changeset
4340 @deftypefnx {Built-in Function} {} eval (@var{try}, @var{catch})\n\
3371
86873384cd10 [project @ 1999-11-21 17:31:07 by jwe]
jwe
parents: 3366
diff changeset
4341 Parse the string @var{try} and evaluate it as if it were an Octave\n\
6643
6a7fc4105bcc [project @ 2007-05-21 20:37:43 by jwe]
jwe
parents: 6637
diff changeset
4342 program. If that fails, evaluate the optional string @var{catch}.\n\
4463
322453495d75 [project @ 2003-07-12 05:03:33 by jwe]
jwe
parents: 4452
diff changeset
4343 The string @var{try} is evaluated in the current context,\n\
322453495d75 [project @ 2003-07-12 05:03:33 by jwe]
jwe
parents: 4452
diff changeset
4344 so any results remain available after @code{eval} returns.\n\
6643
6a7fc4105bcc [project @ 2007-05-21 20:37:43 by jwe]
jwe
parents: 6637
diff changeset
4345 \n\
16789
2f63d2f3ff11 doc: Update docstrings in oct-parse.in.yy.
Rik <rik@octave.org>
parents: 16681
diff changeset
4346 The following example makes the variable @var{A} with the approximate\n\
6643
6a7fc4105bcc [project @ 2007-05-21 20:37:43 by jwe]
jwe
parents: 6637
diff changeset
4347 value 3.1416 available.\n\
6a7fc4105bcc [project @ 2007-05-21 20:37:43 by jwe]
jwe
parents: 6637
diff changeset
4348 \n\
6a7fc4105bcc [project @ 2007-05-21 20:37:43 by jwe]
jwe
parents: 6637
diff changeset
4349 @example\n\
16789
2f63d2f3ff11 doc: Update docstrings in oct-parse.in.yy.
Rik <rik@octave.org>
parents: 16681
diff changeset
4350 eval (\"A = acos(-1);\");\n\
6643
6a7fc4105bcc [project @ 2007-05-21 20:37:43 by jwe]
jwe
parents: 6637
diff changeset
4351 @end example\n\
6a7fc4105bcc [project @ 2007-05-21 20:37:43 by jwe]
jwe
parents: 6637
diff changeset
4352 \n\
6a7fc4105bcc [project @ 2007-05-21 20:37:43 by jwe]
jwe
parents: 6637
diff changeset
4353 If an error occurs during the evaluation of @var{try} the @var{catch}\n\
8828
8463d1a2e544 Doc fixes.
Brian Gough <bjg@network-theory.co.uk>
parents: 8819
diff changeset
4354 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
4355 \n\
6a7fc4105bcc [project @ 2007-05-21 20:37:43 by jwe]
jwe
parents: 6637
diff changeset
4356 @example\n\
11572
7d6d8c1e471f Grammarcheck Texinfo for files in src directory.
Rik <octave@nomad.inbox5.com>
parents: 11523
diff changeset
4357 @group\n\
6643
6a7fc4105bcc [project @ 2007-05-21 20:37:43 by jwe]
jwe
parents: 6637
diff changeset
4358 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
4359 '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
4360 @print{} This error occurred:\n\
8015
30629059b72d Update the manual to reflect the changes in error output
sh@sh-laptop
parents: 8007
diff changeset
4361 This is a bad example\n\
11572
7d6d8c1e471f Grammarcheck Texinfo for files in src directory.
Rik <octave@nomad.inbox5.com>
parents: 11523
diff changeset
4362 @end group\n\
6643
6a7fc4105bcc [project @ 2007-05-21 20:37:43 by jwe]
jwe
parents: 6637
diff changeset
4363 @end example\n\
14172
cba1c681f1b7 doc: Update seealso references for eval family of functions.
Rik <octave@nomad.inbox5.com>
parents: 14153
diff changeset
4364 \n\
cba1c681f1b7 doc: Update seealso references for eval family of functions.
Rik <octave@nomad.inbox5.com>
parents: 14153
diff changeset
4365 Consider using try/catch blocks instead if you are only using @code{eval}\n\
cba1c681f1b7 doc: Update seealso references for eval family of functions.
Rik <octave@nomad.inbox5.com>
parents: 14153
diff changeset
4366 as an error-capturing mechanism rather than for the execution of arbitrary\n\
cba1c681f1b7 doc: Update seealso references for eval family of functions.
Rik <octave@nomad.inbox5.com>
parents: 14153
diff changeset
4367 code strings.\n\
cba1c681f1b7 doc: Update seealso references for eval family of functions.
Rik <octave@nomad.inbox5.com>
parents: 14153
diff changeset
4368 @seealso{evalin}\n\
3371
86873384cd10 [project @ 1999-11-21 17:31:07 by jwe]
jwe
parents: 3366
diff changeset
4369 @end deftypefn")
3021
18d64612e67a [project @ 1997-06-03 22:18:56 by jwe]
jwe
parents: 3016
diff changeset
4370 {
18d64612e67a [project @ 1997-06-03 22:18:56 by jwe]
jwe
parents: 3016
diff changeset
4371 octave_value_list retval;
18d64612e67a [project @ 1997-06-03 22:18:56 by jwe]
jwe
parents: 3016
diff changeset
4372
18d64612e67a [project @ 1997-06-03 22:18:56 by jwe]
jwe
parents: 3016
diff changeset
4373 int nargin = args.length ();
18d64612e67a [project @ 1997-06-03 22:18:56 by jwe]
jwe
parents: 3016
diff changeset
4374
18d64612e67a [project @ 1997-06-03 22:18:56 by jwe]
jwe
parents: 3016
diff changeset
4375 if (nargin > 0)
18d64612e67a [project @ 1997-06-03 22:18:56 by jwe]
jwe
parents: 3016
diff changeset
4376 {
10067
6f79338c269b omission from last patch
Jaroslav Hajek <highegg@gmail.com>
parents: 9794
diff changeset
4377 unwind_protect frame;
3021
18d64612e67a [project @ 1997-06-03 22:18:56 by jwe]
jwe
parents: 3016
diff changeset
4378
18d64612e67a [project @ 1997-06-03 22:18:56 by jwe]
jwe
parents: 3016
diff changeset
4379 if (nargin > 1)
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
4380 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
4381 frame.protect_var (buffer_error_messages);
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
4382 buffer_error_messages++;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
4383 }
3021
18d64612e67a [project @ 1997-06-03 22:18:56 by jwe]
jwe
parents: 3016
diff changeset
4384
18d64612e67a [project @ 1997-06-03 22:18:56 by jwe]
jwe
parents: 3016
diff changeset
4385 int parse_status = 0;
18d64612e67a [project @ 1997-06-03 22:18:56 by jwe]
jwe
parents: 3016
diff changeset
4386
4463
322453495d75 [project @ 2003-07-12 05:03:33 by jwe]
jwe
parents: 4452
diff changeset
4387 octave_value_list tmp = eval_string (args(0), nargout > 0,
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
4388 parse_status, nargout);
4463
322453495d75 [project @ 2003-07-12 05:03:33 by jwe]
jwe
parents: 4452
diff changeset
4389
3021
18d64612e67a [project @ 1997-06-03 22:18:56 by jwe]
jwe
parents: 3016
diff changeset
4390 if (nargin > 1 && (parse_status != 0 || error_state))
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
4391 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
4392 error_state = 0;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
4393
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
4394 // Set up for letting the user print any messages from
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
4395 // errors that occurred in the first part of this eval().
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
4396
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
4397 buffer_error_messages--;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
4398
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
4399 tmp = eval_string (args(1), nargout > 0, parse_status, nargout);
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
4400
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
4401 if (nargout > 0)
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
4402 retval = tmp;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
4403 }
8033
2ad5ba320b93 parse.y (Feval): Return value produced by evaluating CATCH string
John W. Eaton <jwe@octave.org>
parents: 8021
diff changeset
4404 else if (nargout > 0)
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
4405 retval = tmp;
3021
18d64612e67a [project @ 1997-06-03 22:18:56 by jwe]
jwe
parents: 3016
diff changeset
4406 }
18d64612e67a [project @ 1997-06-03 22:18:56 by jwe]
jwe
parents: 3016
diff changeset
4407 else
5823
080c08b192d8 [project @ 2006-05-19 05:32:17 by jwe]
jwe
parents: 5794
diff changeset
4408 print_usage ();
3021
18d64612e67a [project @ 1997-06-03 22:18:56 by jwe]
jwe
parents: 3016
diff changeset
4409
18d64612e67a [project @ 1997-06-03 22:18:56 by jwe]
jwe
parents: 3016
diff changeset
4410 return retval;
18d64612e67a [project @ 1997-06-03 22:18:56 by jwe]
jwe
parents: 3016
diff changeset
4411 }
18d64612e67a [project @ 1997-06-03 22:18:56 by jwe]
jwe
parents: 3016
diff changeset
4412
7562
c827f5673321 move tests to individual source files
John W. Eaton <jwe@octave.org>
parents: 7351
diff changeset
4413 /*
c827f5673321 move tests to individual source files
John W. Eaton <jwe@octave.org>
parents: 7351
diff changeset
4414
14084
5aba9fa234cf Modernize %!tests for eval()
Rik <octave@nomad.inbox5.com>
parents: 13970
diff changeset
4415 %!shared x
7562
c827f5673321 move tests to individual source files
John W. Eaton <jwe@octave.org>
parents: 7351
diff changeset
4416 %! x = 1;
14084
5aba9fa234cf Modernize %!tests for eval()
Rik <octave@nomad.inbox5.com>
parents: 13970
diff changeset
4417
5aba9fa234cf Modernize %!tests for eval()
Rik <octave@nomad.inbox5.com>
parents: 13970
diff changeset
4418 %!assert (eval ("x"), 1)
5aba9fa234cf Modernize %!tests for eval()
Rik <octave@nomad.inbox5.com>
parents: 13970
diff changeset
4419 %!assert (eval ("x;"))
5aba9fa234cf Modernize %!tests for eval()
Rik <octave@nomad.inbox5.com>
parents: 13970
diff changeset
4420 %!assert (eval ("x;"), 1);
5aba9fa234cf Modernize %!tests for eval()
Rik <octave@nomad.inbox5.com>
parents: 13970
diff changeset
4421
7562
c827f5673321 move tests to individual source files
John W. Eaton <jwe@octave.org>
parents: 7351
diff changeset
4422 %!test
14084
5aba9fa234cf Modernize %!tests for eval()
Rik <octave@nomad.inbox5.com>
parents: 13970
diff changeset
4423 %! y = eval ("x");
5aba9fa234cf Modernize %!tests for eval()
Rik <octave@nomad.inbox5.com>
parents: 13970
diff changeset
4424 %! assert (y, 1);
5aba9fa234cf Modernize %!tests for eval()
Rik <octave@nomad.inbox5.com>
parents: 13970
diff changeset
4425
5aba9fa234cf Modernize %!tests for eval()
Rik <octave@nomad.inbox5.com>
parents: 13970
diff changeset
4426 %!test
5aba9fa234cf Modernize %!tests for eval()
Rik <octave@nomad.inbox5.com>
parents: 13970
diff changeset
4427 %! y = eval ("x;");
5aba9fa234cf Modernize %!tests for eval()
Rik <octave@nomad.inbox5.com>
parents: 13970
diff changeset
4428 %! assert (y, 1);
5aba9fa234cf Modernize %!tests for eval()
Rik <octave@nomad.inbox5.com>
parents: 13970
diff changeset
4429
5aba9fa234cf Modernize %!tests for eval()
Rik <octave@nomad.inbox5.com>
parents: 13970
diff changeset
4430 %!test
5aba9fa234cf Modernize %!tests for eval()
Rik <octave@nomad.inbox5.com>
parents: 13970
diff changeset
4431 %! eval ("x = 1;")
5aba9fa234cf Modernize %!tests for eval()
Rik <octave@nomad.inbox5.com>
parents: 13970
diff changeset
4432 %! assert (x,1);
5aba9fa234cf Modernize %!tests for eval()
Rik <octave@nomad.inbox5.com>
parents: 13970
diff changeset
4433
7562
c827f5673321 move tests to individual source files
John W. Eaton <jwe@octave.org>
parents: 7351
diff changeset
4434 %!test
c827f5673321 move tests to individual source files
John W. Eaton <jwe@octave.org>
parents: 7351
diff changeset
4435 %! eval ("flipud = 2;");
14084
5aba9fa234cf Modernize %!tests for eval()
Rik <octave@nomad.inbox5.com>
parents: 13970
diff changeset
4436 %! assert (flipud, 2);
5aba9fa234cf Modernize %!tests for eval()
Rik <octave@nomad.inbox5.com>
parents: 13970
diff changeset
4437
5aba9fa234cf Modernize %!tests for eval()
Rik <octave@nomad.inbox5.com>
parents: 13970
diff changeset
4438 %!function y = __f ()
7562
c827f5673321 move tests to individual source files
John W. Eaton <jwe@octave.org>
parents: 7351
diff changeset
4439 %! eval ("flipud = 2;");
c827f5673321 move tests to individual source files
John W. Eaton <jwe@octave.org>
parents: 7351
diff changeset
4440 %! y = flipud;
14084
5aba9fa234cf Modernize %!tests for eval()
Rik <octave@nomad.inbox5.com>
parents: 13970
diff changeset
4441 %!endfunction
5aba9fa234cf Modernize %!tests for eval()
Rik <octave@nomad.inbox5.com>
parents: 13970
diff changeset
4442 %!assert (__f(), 2)
7562
c827f5673321 move tests to individual source files
John W. Eaton <jwe@octave.org>
parents: 7351
diff changeset
4443
14533
e6aa044253eb Allow comma at the end of an assignment list (bug #35645)
Max Brister <max@2bass.com>
parents: 14512
diff changeset
4444 % bug #35645
e6aa044253eb Allow comma at the end of an assignment list (bug #35645)
Max Brister <max@2bass.com>
parents: 14512
diff changeset
4445 %!test
e6aa044253eb Allow comma at the end of an assignment list (bug #35645)
Max Brister <max@2bass.com>
parents: 14512
diff changeset
4446 %! [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
4447 %! [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
4448
7562
c827f5673321 move tests to individual source files
John W. Eaton <jwe@octave.org>
parents: 7351
diff changeset
4449 */
c827f5673321 move tests to individual source files
John W. Eaton <jwe@octave.org>
parents: 7351
diff changeset
4450
4661
12b6fbd57436 [project @ 2003-11-25 05:41:35 by jwe]
jwe
parents: 4615
diff changeset
4451 DEFUN (assignin, args, ,
4297
59a2ba0fb205 [project @ 2003-01-11 20:22:09 by jwe]
jwe
parents: 4246
diff changeset
4452 "-*- texinfo -*-\n\
59a2ba0fb205 [project @ 2003-01-11 20:22:09 by jwe]
jwe
parents: 4246
diff changeset
4453 @deftypefn {Built-in Function} {} assignin (@var{context}, @var{varname}, @var{value})\n\
59a2ba0fb205 [project @ 2003-01-11 20:22:09 by jwe]
jwe
parents: 4246
diff changeset
4454 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
4455 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
4456 @seealso{evalin}\n\
4297
59a2ba0fb205 [project @ 2003-01-11 20:22:09 by jwe]
jwe
parents: 4246
diff changeset
4457 @end deftypefn")
59a2ba0fb205 [project @ 2003-01-11 20:22:09 by jwe]
jwe
parents: 4246
diff changeset
4458 {
59a2ba0fb205 [project @ 2003-01-11 20:22:09 by jwe]
jwe
parents: 4246
diff changeset
4459 octave_value_list retval;
59a2ba0fb205 [project @ 2003-01-11 20:22:09 by jwe]
jwe
parents: 4246
diff changeset
4460
59a2ba0fb205 [project @ 2003-01-11 20:22:09 by jwe]
jwe
parents: 4246
diff changeset
4461 int nargin = args.length ();
59a2ba0fb205 [project @ 2003-01-11 20:22:09 by jwe]
jwe
parents: 4246
diff changeset
4462
59a2ba0fb205 [project @ 2003-01-11 20:22:09 by jwe]
jwe
parents: 4246
diff changeset
4463 if (nargin == 3)
59a2ba0fb205 [project @ 2003-01-11 20:22:09 by jwe]
jwe
parents: 4246
diff changeset
4464 {
59a2ba0fb205 [project @ 2003-01-11 20:22:09 by jwe]
jwe
parents: 4246
diff changeset
4465 std::string context = args(0).string_value ();
59a2ba0fb205 [project @ 2003-01-11 20:22:09 by jwe]
jwe
parents: 4246
diff changeset
4466
59a2ba0fb205 [project @ 2003-01-11 20:22:09 by jwe]
jwe
parents: 4246
diff changeset
4467 if (! error_state)
59a2ba0fb205 [project @ 2003-01-11 20:22:09 by jwe]
jwe
parents: 4246
diff changeset
4468 {
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
4469 unwind_protect frame;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
4470
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
4471 if (context == "caller")
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
4472 octave_call_stack::goto_caller_frame ();
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
4473 else if (context == "base")
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
4474 octave_call_stack::goto_base_frame ();
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
4475 else
12483
7a5aacf65f81 Rewrite error strings in src/ to use variables named in documentation.
Rik <octave@nomad.inbox5.com>
parents: 12400
diff changeset
4476 error ("assignin: CONTEXT must be \"caller\" or \"base\"");
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
4477
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
4478 if (! error_state)
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
4479 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
4480 frame.add_fcn (octave_call_stack::pop);
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
4481
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
4482 std::string nm = args(1).string_value ();
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
4483
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
4484 if (! error_state)
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
4485 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
4486 if (valid_identifier (nm))
16442
302157614308 deprecate symbol_table::varref functions
John W. Eaton <jwe@octave.org>
parents: 16360
diff changeset
4487 symbol_table::assign (nm, args(2));
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
4488 else
12483
7a5aacf65f81 Rewrite error strings in src/ to use variables named in documentation.
Rik <octave@nomad.inbox5.com>
parents: 12400
diff changeset
4489 error ("assignin: invalid variable name in argument VARNAME");
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
4490 }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
4491 else
12483
7a5aacf65f81 Rewrite error strings in src/ to use variables named in documentation.
Rik <octave@nomad.inbox5.com>
parents: 12400
diff changeset
4492 error ("assignin: VARNAME must be a string");
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
4493 }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
4494 }
4297
59a2ba0fb205 [project @ 2003-01-11 20:22:09 by jwe]
jwe
parents: 4246
diff changeset
4495 else
12483
7a5aacf65f81 Rewrite error strings in src/ to use variables named in documentation.
Rik <octave@nomad.inbox5.com>
parents: 12400
diff changeset
4496 error ("assignin: CONTEXT must be a string");
4297
59a2ba0fb205 [project @ 2003-01-11 20:22:09 by jwe]
jwe
parents: 4246
diff changeset
4497 }
59a2ba0fb205 [project @ 2003-01-11 20:22:09 by jwe]
jwe
parents: 4246
diff changeset
4498 else
5823
080c08b192d8 [project @ 2006-05-19 05:32:17 by jwe]
jwe
parents: 5794
diff changeset
4499 print_usage ();
4297
59a2ba0fb205 [project @ 2003-01-11 20:22:09 by jwe]
jwe
parents: 4246
diff changeset
4500
59a2ba0fb205 [project @ 2003-01-11 20:22:09 by jwe]
jwe
parents: 4246
diff changeset
4501 return retval;
59a2ba0fb205 [project @ 2003-01-11 20:22:09 by jwe]
jwe
parents: 4246
diff changeset
4502 }
59a2ba0fb205 [project @ 2003-01-11 20:22:09 by jwe]
jwe
parents: 4246
diff changeset
4503
4245
610671be8792 [project @ 2002-12-28 04:02:31 by jwe]
jwe
parents: 4244
diff changeset
4504 DEFUN (evalin, args, nargout,
610671be8792 [project @ 2002-12-28 04:02:31 by jwe]
jwe
parents: 4244
diff changeset
4505 "-*- texinfo -*-\n\
14172
cba1c681f1b7 doc: Update seealso references for eval family of functions.
Rik <octave@nomad.inbox5.com>
parents: 14153
diff changeset
4506 @deftypefn {Built-in Function} {} evalin (@var{context}, @var{try})\n\
cba1c681f1b7 doc: Update seealso references for eval family of functions.
Rik <octave@nomad.inbox5.com>
parents: 14153
diff changeset
4507 @deftypefnx {Built-in Function} {} evalin (@var{context}, @var{try}, @var{catch})\n\
4245
610671be8792 [project @ 2002-12-28 04:02:31 by jwe]
jwe
parents: 4244
diff changeset
4508 Like @code{eval}, except that the expressions are evaluated in the\n\
17281
bc924baa2c4e doc: Add new @qcode macro for code samples which are quoted.
Rik <rik@octave.org>
parents: 17249
diff changeset
4509 context @var{context}, which may be either @qcode{\"caller\"} or\n\
bc924baa2c4e doc: Add new @qcode macro for code samples which are quoted.
Rik <rik@octave.org>
parents: 17249
diff changeset
4510 @qcode{\"base\"}.\n\
14172
cba1c681f1b7 doc: Update seealso references for eval family of functions.
Rik <octave@nomad.inbox5.com>
parents: 14153
diff changeset
4511 @seealso{eval, assignin}\n\
4245
610671be8792 [project @ 2002-12-28 04:02:31 by jwe]
jwe
parents: 4244
diff changeset
4512 @end deftypefn")
610671be8792 [project @ 2002-12-28 04:02:31 by jwe]
jwe
parents: 4244
diff changeset
4513 {
610671be8792 [project @ 2002-12-28 04:02:31 by jwe]
jwe
parents: 4244
diff changeset
4514 octave_value_list retval;
610671be8792 [project @ 2002-12-28 04:02:31 by jwe]
jwe
parents: 4244
diff changeset
4515
610671be8792 [project @ 2002-12-28 04:02:31 by jwe]
jwe
parents: 4244
diff changeset
4516 int nargin = args.length ();
610671be8792 [project @ 2002-12-28 04:02:31 by jwe]
jwe
parents: 4244
diff changeset
4517
610671be8792 [project @ 2002-12-28 04:02:31 by jwe]
jwe
parents: 4244
diff changeset
4518 if (nargin > 1)
610671be8792 [project @ 2002-12-28 04:02:31 by jwe]
jwe
parents: 4244
diff changeset
4519 {
610671be8792 [project @ 2002-12-28 04:02:31 by jwe]
jwe
parents: 4244
diff changeset
4520 std::string context = args(0).string_value ();
610671be8792 [project @ 2002-12-28 04:02:31 by jwe]
jwe
parents: 4244
diff changeset
4521
610671be8792 [project @ 2002-12-28 04:02:31 by jwe]
jwe
parents: 4244
diff changeset
4522 if (! error_state)
610671be8792 [project @ 2002-12-28 04:02:31 by jwe]
jwe
parents: 4244
diff changeset
4523 {
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
4524 unwind_protect frame;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
4525
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
4526 if (context == "caller")
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
4527 octave_call_stack::goto_caller_frame ();
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
4528 else if (context == "base")
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
4529 octave_call_stack::goto_base_frame ();
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
4530 else
12483
7a5aacf65f81 Rewrite error strings in src/ to use variables named in documentation.
Rik <octave@nomad.inbox5.com>
parents: 12400
diff changeset
4531 error ("evalin: CONTEXT must be \"caller\" or \"base\"");
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
4532
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
4533 if (! error_state)
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
4534 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
4535 frame.add_fcn (octave_call_stack::pop);
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
4536
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
4537 if (nargin > 2)
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
4538 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
4539 frame.protect_var (buffer_error_messages);
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
4540 buffer_error_messages++;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
4541 }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
4542
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
4543 int parse_status = 0;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
4544
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
4545 octave_value_list tmp = eval_string (args(1), nargout > 0,
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
4546 parse_status, nargout);
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
4547
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
4548 if (nargout > 0)
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
4549 retval = tmp;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
4550
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
4551 if (nargin > 2 && (parse_status != 0 || error_state))
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
4552 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
4553 error_state = 0;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
4554
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
4555 // Set up for letting the user print any messages from
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
4556 // errors that occurred in the first part of this eval().
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
4557
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
4558 buffer_error_messages--;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
4559
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
4560 tmp = eval_string (args(2), nargout > 0,
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
4561 parse_status, nargout);
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
4562
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
4563 retval = (nargout > 0) ? tmp : octave_value_list ();
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
4564 }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
4565 }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
4566 }
4245
610671be8792 [project @ 2002-12-28 04:02:31 by jwe]
jwe
parents: 4244
diff changeset
4567 else
12483
7a5aacf65f81 Rewrite error strings in src/ to use variables named in documentation.
Rik <octave@nomad.inbox5.com>
parents: 12400
diff changeset
4568 error ("evalin: CONTEXT must be a string");
4245
610671be8792 [project @ 2002-12-28 04:02:31 by jwe]
jwe
parents: 4244
diff changeset
4569 }
610671be8792 [project @ 2002-12-28 04:02:31 by jwe]
jwe
parents: 4244
diff changeset
4570 else
5823
080c08b192d8 [project @ 2006-05-19 05:32:17 by jwe]
jwe
parents: 5794
diff changeset
4571 print_usage ();
4245
610671be8792 [project @ 2002-12-28 04:02:31 by jwe]
jwe
parents: 4244
diff changeset
4572
610671be8792 [project @ 2002-12-28 04:02:31 by jwe]
jwe
parents: 4244
diff changeset
4573 return retval;
610671be8792 [project @ 2002-12-28 04:02:31 by jwe]
jwe
parents: 4244
diff changeset
4574 }
610671be8792 [project @ 2002-12-28 04:02:31 by jwe]
jwe
parents: 4244
diff changeset
4575
8311
7124bffc89c7 parse.y (F__parser_debug_flag__): New function.
John W. Eaton <jwe@octave.org>
parents: 8283
diff changeset
4576 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
4577 "-*- texinfo -*-\n\
7d48766c21a5 use consistent format for doc strings of internal functions
John W. Eaton <jwe@octave.org>
parents: 8746
diff changeset
4578 @deftypefn {Built-in Function} {@var{old_val} =} __parser_debug_flag__ (@var{new_val}))\n\
7d48766c21a5 use consistent format for doc strings of internal functions
John W. Eaton <jwe@octave.org>
parents: 8746
diff changeset
4579 Undocumented internal function.\n\
7d48766c21a5 use consistent format for doc strings of internal functions
John W. Eaton <jwe@octave.org>
parents: 8746
diff changeset
4580 @end deftypefn")
8311
7124bffc89c7 parse.y (F__parser_debug_flag__): New function.
John W. Eaton <jwe@octave.org>
parents: 8283
diff changeset
4581 {
7124bffc89c7 parse.y (F__parser_debug_flag__): New function.
John W. Eaton <jwe@octave.org>
parents: 8283
diff changeset
4582 octave_value retval;
7124bffc89c7 parse.y (F__parser_debug_flag__): New function.
John W. Eaton <jwe@octave.org>
parents: 8283
diff changeset
4583
7124bffc89c7 parse.y (F__parser_debug_flag__): New function.
John W. Eaton <jwe@octave.org>
parents: 8283
diff changeset
4584 bool debug_flag = octave_debug;
7124bffc89c7 parse.y (F__parser_debug_flag__): New function.
John W. Eaton <jwe@octave.org>
parents: 8283
diff changeset
4585
7124bffc89c7 parse.y (F__parser_debug_flag__): New function.
John W. Eaton <jwe@octave.org>
parents: 8283
diff changeset
4586 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
4587 "__parser_debug_flag__");
8311
7124bffc89c7 parse.y (F__parser_debug_flag__): New function.
John W. Eaton <jwe@octave.org>
parents: 8283
diff changeset
4588
7124bffc89c7 parse.y (F__parser_debug_flag__): New function.
John W. Eaton <jwe@octave.org>
parents: 8283
diff changeset
4589 octave_debug = debug_flag;
7124bffc89c7 parse.y (F__parser_debug_flag__): New function.
John W. Eaton <jwe@octave.org>
parents: 8283
diff changeset
4590
7124bffc89c7 parse.y (F__parser_debug_flag__): New function.
John W. Eaton <jwe@octave.org>
parents: 8283
diff changeset
4591 return retval;
7124bffc89c7 parse.y (F__parser_debug_flag__): New function.
John W. Eaton <jwe@octave.org>
parents: 8283
diff changeset
4592 }
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
4593
17377
15e2ad6372f7 maint: Tweaks to remove compiler warnings.
Rik <rik@octave.org>
parents: 17342
diff changeset
4594 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
4595 "-*- texinfo -*-\n\
091e4df179de new function to help with debugging by parsing .m files without executing them
John W. Eaton <jwe@octave.org>
parents: 17326
diff changeset
4596 @deftypefn {Built-in Function} {} __parse_file__ (@var{file}, @var{verbose})\n\
091e4df179de new function to help with debugging by parsing .m files without executing them
John W. Eaton <jwe@octave.org>
parents: 17326
diff changeset
4597 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
4598 @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
4599 {
091e4df179de new function to help with debugging by parsing .m files without executing them
John W. Eaton <jwe@octave.org>
parents: 17326
diff changeset
4600 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
4601
091e4df179de new function to help with debugging by parsing .m files without executing them
John W. Eaton <jwe@octave.org>
parents: 17326
diff changeset
4602 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
4603
091e4df179de new function to help with debugging by parsing .m files without executing them
John W. Eaton <jwe@octave.org>
parents: 17326
diff changeset
4604 if (nargin == 1 || nargin == 2)
091e4df179de new function to help with debugging by parsing .m files without executing them
John W. Eaton <jwe@octave.org>
parents: 17326
diff changeset
4605 {
091e4df179de new function to help with debugging by parsing .m files without executing them
John W. Eaton <jwe@octave.org>
parents: 17326
diff changeset
4606 std::string file = args(0).string_value ();
091e4df179de new function to help with debugging by parsing .m files without executing them
John W. Eaton <jwe@octave.org>
parents: 17326
diff changeset
4607
091e4df179de new function to help with debugging by parsing .m files without executing them
John W. Eaton <jwe@octave.org>
parents: 17326
diff changeset
4608 std::string full_file = octave_env::make_absolute (file);
091e4df179de new function to help with debugging by parsing .m files without executing them
John W. Eaton <jwe@octave.org>
parents: 17326
diff changeset
4609
091e4df179de new function to help with debugging by parsing .m files without executing them
John W. Eaton <jwe@octave.org>
parents: 17326
diff changeset
4610 size_t file_len = file.length ();
091e4df179de new function to help with debugging by parsing .m files without executing them
John W. Eaton <jwe@octave.org>
parents: 17326
diff changeset
4611
091e4df179de new function to help with debugging by parsing .m files without executing them
John W. Eaton <jwe@octave.org>
parents: 17326
diff changeset
4612 if ((file_len > 4 && file.substr (file_len-4) == ".oct")
091e4df179de new function to help with debugging by parsing .m files without executing them
John W. Eaton <jwe@octave.org>
parents: 17326
diff changeset
4613 || (file_len > 4 && file.substr (file_len-4) == ".mex")
091e4df179de new function to help with debugging by parsing .m files without executing them
John W. Eaton <jwe@octave.org>
parents: 17326
diff changeset
4614 || (file_len > 2 && file.substr (file_len-2) == ".m"))
091e4df179de new function to help with debugging by parsing .m files without executing them
John W. Eaton <jwe@octave.org>
parents: 17326
diff changeset
4615 {
091e4df179de new function to help with debugging by parsing .m files without executing them
John W. Eaton <jwe@octave.org>
parents: 17326
diff changeset
4616 file = octave_env::base_pathname (file);
091e4df179de new function to help with debugging by parsing .m files without executing them
John W. Eaton <jwe@octave.org>
parents: 17326
diff changeset
4617 file = file.substr (0, file.find_last_of ('.'));
091e4df179de new function to help with debugging by parsing .m files without executing them
John W. Eaton <jwe@octave.org>
parents: 17326
diff changeset
4618
091e4df179de new function to help with debugging by parsing .m files without executing them
John W. Eaton <jwe@octave.org>
parents: 17326
diff changeset
4619 size_t pos = file.find_last_of (file_ops::dir_sep_str ());
091e4df179de new function to help with debugging by parsing .m files without executing them
John W. Eaton <jwe@octave.org>
parents: 17326
diff changeset
4620 if (pos != std::string::npos)
091e4df179de new function to help with debugging by parsing .m files without executing them
John W. Eaton <jwe@octave.org>
parents: 17326
diff changeset
4621 file = file.substr (pos+1);
091e4df179de new function to help with debugging by parsing .m files without executing them
John W. Eaton <jwe@octave.org>
parents: 17326
diff changeset
4622 }
091e4df179de new function to help with debugging by parsing .m files without executing them
John W. Eaton <jwe@octave.org>
parents: 17326
diff changeset
4623
091e4df179de new function to help with debugging by parsing .m files without executing them
John W. Eaton <jwe@octave.org>
parents: 17326
diff changeset
4624 if (! error_state)
091e4df179de new function to help with debugging by parsing .m files without executing them
John W. Eaton <jwe@octave.org>
parents: 17326
diff changeset
4625 {
091e4df179de new function to help with debugging by parsing .m files without executing them
John W. Eaton <jwe@octave.org>
parents: 17326
diff changeset
4626 if (nargin == 2)
091e4df179de new function to help with debugging by parsing .m files without executing them
John W. Eaton <jwe@octave.org>
parents: 17326
diff changeset
4627 octave_stdout << "parsing " << full_file << std::endl;
091e4df179de new function to help with debugging by parsing .m files without executing them
John W. Eaton <jwe@octave.org>
parents: 17326
diff changeset
4628
091e4df179de new function to help with debugging by parsing .m files without executing them
John W. Eaton <jwe@octave.org>
parents: 17326
diff changeset
4629 octave_function *fcn = parse_fcn_file (full_file, file, "",
091e4df179de new function to help with debugging by parsing .m files without executing them
John W. Eaton <jwe@octave.org>
parents: 17326
diff changeset
4630 true, false, false,
091e4df179de new function to help with debugging by parsing .m files without executing them
John W. Eaton <jwe@octave.org>
parents: 17326
diff changeset
4631 false, "__parse_file__");
091e4df179de new function to help with debugging by parsing .m files without executing them
John W. Eaton <jwe@octave.org>
parents: 17326
diff changeset
4632
091e4df179de new function to help with debugging by parsing .m files without executing them
John W. Eaton <jwe@octave.org>
parents: 17326
diff changeset
4633 if (fcn)
091e4df179de new function to help with debugging by parsing .m files without executing them
John W. Eaton <jwe@octave.org>
parents: 17326
diff changeset
4634 delete fcn;
091e4df179de new function to help with debugging by parsing .m files without executing them
John W. Eaton <jwe@octave.org>
parents: 17326
diff changeset
4635 }
091e4df179de new function to help with debugging by parsing .m files without executing them
John W. Eaton <jwe@octave.org>
parents: 17326
diff changeset
4636 else
091e4df179de new function to help with debugging by parsing .m files without executing them
John W. Eaton <jwe@octave.org>
parents: 17326
diff changeset
4637 error ("__parse_file__: expecting file name as argument");
091e4df179de new function to help with debugging by parsing .m files without executing them
John W. Eaton <jwe@octave.org>
parents: 17326
diff changeset
4638 }
091e4df179de new function to help with debugging by parsing .m files without executing them
John W. Eaton <jwe@octave.org>
parents: 17326
diff changeset
4639 else
091e4df179de new function to help with debugging by parsing .m files without executing them
John W. Eaton <jwe@octave.org>
parents: 17326
diff changeset
4640 print_usage ();
091e4df179de new function to help with debugging by parsing .m files without executing them
John W. Eaton <jwe@octave.org>
parents: 17326
diff changeset
4641
091e4df179de new function to help with debugging by parsing .m files without executing them
John W. Eaton <jwe@octave.org>
parents: 17326
diff changeset
4642 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
4643 }