annotate src/parse.y @ 8874:bd1b1fe9c6e9 ss-3-1-53

bump version info for snapshot
author John W. Eaton <jwe@octave.org>
date Wed, 25 Feb 2009 18:35:47 -0500
parents be7b30a24938
children 8ed42c679af5
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
7017
a1dbe9d80eee [project @ 2007-10-12 21:27:11 by jwe]
jwe
parents: 7016
diff changeset
3 Copyright (C) 1993, 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001,
8746
5dd06f19e9be handle commands in the lexer
John W. Eaton <jwe@octave.org>
parents: 8745
diff changeset
4 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009 John W. Eaton
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
5
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
6 This file is part of Octave.
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
7
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
8 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
9 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
10 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
11 option) any later version.
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
12
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
13 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
14 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
15 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
16 for more details.
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
17
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
18 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
19 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
20 <http://www.gnu.org/licenses/>.
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
21
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 // Parser for Octave.
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
25
767
42731861ee09 [project @ 1994-10-05 21:26:54 by jwe]
jwe
parents: 751
diff changeset
26 // C decarations.
42731861ee09 [project @ 1994-10-05 21:26:54 by jwe]
jwe
parents: 751
diff changeset
27
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
28 %{
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
29 #define YYDEBUG 1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
30
240
a99f28f5e351 [project @ 1993-11-30 20:24:36 by jwe]
jwe
parents: 206
diff changeset
31 #ifdef HAVE_CONFIG_H
1229
7d7c3eaa1d3b [project @ 1995-04-10 01:04:13 by jwe]
jwe
parents: 1162
diff changeset
32 #include <config.h>
240
a99f28f5e351 [project @ 1993-11-30 20:24:36 by jwe]
jwe
parents: 206
diff changeset
33 #endif
a99f28f5e351 [project @ 1993-11-30 20:24:36 by jwe]
jwe
parents: 206
diff changeset
34
3178
09a3064a3a17 [project @ 1998-06-23 03:46:42 by jwe]
jwe
parents: 3165
diff changeset
35 #include <cassert>
3156
a494f93e60ff [project @ 1998-02-20 07:47:48 by jwe]
jwe
parents: 3110
diff changeset
36 #include <cstdio>
a494f93e60ff [project @ 1998-02-20 07:47:48 by jwe]
jwe
parents: 3110
diff changeset
37
2427
2f50b24ce84f [project @ 1996-10-25 06:15:28 by jwe]
jwe
parents: 2375
diff changeset
38 #ifdef YYBYACC
2f50b24ce84f [project @ 1996-10-25 06:15:28 by jwe]
jwe
parents: 2375
diff changeset
39 #include <cstdlib>
2f50b24ce84f [project @ 1996-10-25 06:15:28 by jwe]
jwe
parents: 2375
diff changeset
40 #endif
2f50b24ce84f [project @ 1996-10-25 06:15:28 by jwe]
jwe
parents: 2375
diff changeset
41
5484
2ff5363a16bd [project @ 2005-10-06 17:12:12 by jwe]
jwe
parents: 5472
diff changeset
42 #include <map>
5765
7ba9ad1fec11 [project @ 2006-04-17 05:05:15 by jwe]
jwe
parents: 5760
diff changeset
43 #include <sstream>
5484
2ff5363a16bd [project @ 2005-10-06 17:12:12 by jwe]
jwe
parents: 5472
diff changeset
44
3928
e8627dc4bdf2 [project @ 2002-05-03 19:56:01 by jwe]
jwe
parents: 3903
diff changeset
45 #include "Cell.h"
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
46 #include "Matrix.h"
3021
18d64612e67a [project @ 1997-06-03 22:18:56 by jwe]
jwe
parents: 3016
diff changeset
47 #include "cmd-edit.h"
18d64612e67a [project @ 1997-06-03 22:18:56 by jwe]
jwe
parents: 3016
diff changeset
48 #include "cmd-hist.h"
18d64612e67a [project @ 1997-06-03 22:18:56 by jwe]
jwe
parents: 3016
diff changeset
49 #include "file-ops.h"
18d64612e67a [project @ 1997-06-03 22:18:56 by jwe]
jwe
parents: 3016
diff changeset
50 #include "file-stat.h"
4243
7e4d5b5520e5 [project @ 2002-12-27 05:30:59 by jwe]
jwe
parents: 4240
diff changeset
51 #include "oct-env.h"
3712
7066a8065e7e [project @ 2000-08-22 06:21:20 by jwe]
jwe
parents: 3665
diff changeset
52 #include "oct-time.h"
4171
04694e5b4239 [project @ 2002-11-12 20:27:24 by jwe]
jwe
parents: 4131
diff changeset
53 #include "quit.h"
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
54
3665
0689afb1d001 [project @ 2000-05-11 19:07:56 by jwe]
jwe
parents: 3544
diff changeset
55 #include "comment-list.h"
4243
7e4d5b5520e5 [project @ 2002-12-27 05:30:59 by jwe]
jwe
parents: 4240
diff changeset
56 #include "defaults.h"
2166
d68119516779 [project @ 1996-05-13 13:41:55 by jwe]
jwe
parents: 2124
diff changeset
57 #include "defun.h"
4243
7e4d5b5520e5 [project @ 2002-12-27 05:30:59 by jwe]
jwe
parents: 4240
diff changeset
58 #include "dirfns.h"
3021
18d64612e67a [project @ 1997-06-03 22:18:56 by jwe]
jwe
parents: 3016
diff changeset
59 #include "dynamic-ld.h"
1351
8256c4c57419 [project @ 1995-09-05 08:02:08 by jwe]
jwe
parents: 1315
diff changeset
60 #include "error.h"
8256c4c57419 [project @ 1995-09-05 08:02:08 by jwe]
jwe
parents: 1315
diff changeset
61 #include "input.h"
8256c4c57419 [project @ 1995-09-05 08:02:08 by jwe]
jwe
parents: 1315
diff changeset
62 #include "lex.h"
5832
5e41e06f6a78 [project @ 2006-05-26 21:41:32 by jwe]
jwe
parents: 5823
diff changeset
63 #include "load-path.h"
1743
ab8612a09449 [project @ 1996-01-12 11:25:30 by jwe]
jwe
parents: 1740
diff changeset
64 #include "oct-hist.h"
5626
3236b4d98fde [project @ 2006-02-15 20:25:39 by jwe]
jwe
parents: 5615
diff changeset
65 #include "oct-map.h"
4935
4fc993a4e072 [project @ 2004-08-06 03:17:12 by jwe]
jwe
parents: 4930
diff changeset
66 #include "ov-fcn-handle.h"
2970
b9e64477f703 [project @ 1997-05-15 18:04:21 by jwe]
jwe
parents: 2961
diff changeset
67 #include "ov-usr-fcn.h"
8150
283989f2da9b make null assignment matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents: 8064
diff changeset
68 #include "ov-null-mat.h"
1670
6708c53892c1 [project @ 1995-12-27 04:33:00 by jwe]
jwe
parents: 1623
diff changeset
69 #include "toplev.h"
1351
8256c4c57419 [project @ 1995-09-05 08:02:08 by jwe]
jwe
parents: 1315
diff changeset
70 #include "pager.h"
8256c4c57419 [project @ 1995-09-05 08:02:08 by jwe]
jwe
parents: 1315
diff changeset
71 #include "parse.h"
2987
ae20b3f37f5e [project @ 1997-05-16 07:05:15 by jwe]
jwe
parents: 2982
diff changeset
72 #include "pt-all.h"
8658
73c4516fae10 New evaluator and debugger derived from tree-walker class
John W. Eaton <jwe@octave.org>
parents: 8471
diff changeset
73 #include "pt-eval.h"
1351
8256c4c57419 [project @ 1995-09-05 08:02:08 by jwe]
jwe
parents: 1315
diff changeset
74 #include "symtab.h"
8256c4c57419 [project @ 1995-09-05 08:02:08 by jwe]
jwe
parents: 1315
diff changeset
75 #include "token.h"
3021
18d64612e67a [project @ 1997-06-03 22:18:56 by jwe]
jwe
parents: 3016
diff changeset
76 #include "unwind-prot.h"
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
77 #include "utils.h"
1351
8256c4c57419 [project @ 1995-09-05 08:02:08 by jwe]
jwe
parents: 1315
diff changeset
78 #include "variables.h"
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
79
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
80 // The current input line number.
8447
adab48231a03 make input_line_number work again
John W. Eaton <jwe@octave.org>
parents: 8311
diff changeset
81 int input_line_number = 1;
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
82
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
83 // The column of the current token.
143
7849db4b6dbc [project @ 1993-10-04 02:36:45 by jwe]
jwe
parents: 118
diff changeset
84 int current_input_column = 1;
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
85
338
82d30a23c979 [project @ 1994-02-07 07:09:33 by jwe]
jwe
parents: 336
diff changeset
86 // Buffer for help text snagged from function files.
4426
51a0dcde8778 [project @ 2003-06-13 19:16:37 by jwe]
jwe
parents: 4343
diff changeset
87 std::stack<std::string> help_buf;
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
88
3665
0689afb1d001 [project @ 2000-05-11 19:07:56 by jwe]
jwe
parents: 3544
diff changeset
89 // Buffer for comments appearing before a function statement.
0689afb1d001 [project @ 2000-05-11 19:07:56 by jwe]
jwe
parents: 3544
diff changeset
90 static std::string fcn_comment_header;
0689afb1d001 [project @ 2000-05-11 19:07:56 by jwe]
jwe
parents: 3544
diff changeset
91
3021
18d64612e67a [project @ 1997-06-03 22:18:56 by jwe]
jwe
parents: 3016
diff changeset
92 // TRUE means we are using readline.
18d64612e67a [project @ 1997-06-03 22:18:56 by jwe]
jwe
parents: 3016
diff changeset
93 // (--no-line-editing)
18d64612e67a [project @ 1997-06-03 22:18:56 by jwe]
jwe
parents: 3016
diff changeset
94 bool line_editing = true;
18d64612e67a [project @ 1997-06-03 22:18:56 by jwe]
jwe
parents: 3016
diff changeset
95
18d64612e67a [project @ 1997-06-03 22:18:56 by jwe]
jwe
parents: 3016
diff changeset
96 // TRUE means we printed messages about reading startup files.
18d64612e67a [project @ 1997-06-03 22:18:56 by jwe]
jwe
parents: 3016
diff changeset
97 bool reading_startup_message_printed = false;
18d64612e67a [project @ 1997-06-03 22:18:56 by jwe]
jwe
parents: 3016
diff changeset
98
18d64612e67a [project @ 1997-06-03 22:18:56 by jwe]
jwe
parents: 3016
diff changeset
99 // TRUE means input is coming from startup file.
18d64612e67a [project @ 1997-06-03 22:18:56 by jwe]
jwe
parents: 3016
diff changeset
100 bool input_from_startup_file = false;
18d64612e67a [project @ 1997-06-03 22:18:56 by jwe]
jwe
parents: 3016
diff changeset
101
4238
a5a68c0afe56 [project @ 2002-12-25 21:04:33 by jwe]
jwe
parents: 4237
diff changeset
102 // Keep a count of how many END tokens we expect.
a5a68c0afe56 [project @ 2002-12-25 21:04:33 by jwe]
jwe
parents: 4237
diff changeset
103 int end_tokens_expected = 0;
a5a68c0afe56 [project @ 2002-12-25 21:04:33 by jwe]
jwe
parents: 4237
diff changeset
104
3903
1dbe160ea0d1 [project @ 2002-04-23 03:40:25 by jwe]
jwe
parents: 3883
diff changeset
105 // Keep track of symbol table information when parsing functions.
7336
745a8299c2b5 [project @ 2007-12-28 20:56:55 by jwe]
jwe
parents: 7017
diff changeset
106 std::stack<symbol_table::scope_id> symtab_context;
4238
a5a68c0afe56 [project @ 2002-12-25 21:04:33 by jwe]
jwe
parents: 4237
diff changeset
107
a5a68c0afe56 [project @ 2002-12-25 21:04:33 by jwe]
jwe
parents: 4237
diff changeset
108 // Name of parent function when parsing function files that might
a5a68c0afe56 [project @ 2002-12-25 21:04:33 by jwe]
jwe
parents: 4237
diff changeset
109 // contain nested functions.
a5a68c0afe56 [project @ 2002-12-25 21:04:33 by jwe]
jwe
parents: 4237
diff changeset
110 std::string parent_function_name;
3903
1dbe160ea0d1 [project @ 2002-04-23 03:40:25 by jwe]
jwe
parents: 3883
diff changeset
111
7336
745a8299c2b5 [project @ 2007-12-28 20:56:55 by jwe]
jwe
parents: 7017
diff changeset
112 // Name of the current class when we are parsing class methods or
745a8299c2b5 [project @ 2007-12-28 20:56:55 by jwe]
jwe
parents: 7017
diff changeset
113 // constructors.
745a8299c2b5 [project @ 2007-12-28 20:56:55 by jwe]
jwe
parents: 7017
diff changeset
114 std::string current_class_name;
745a8299c2b5 [project @ 2007-12-28 20:56:55 by jwe]
jwe
parents: 7017
diff changeset
115
5484
2ff5363a16bd [project @ 2005-10-06 17:12:12 by jwe]
jwe
parents: 5472
diff changeset
116 // TRUE means we are in the process of autoloading a function.
2ff5363a16bd [project @ 2005-10-06 17:12:12 by jwe]
jwe
parents: 5472
diff changeset
117 static bool autoloading = false;
2ff5363a16bd [project @ 2005-10-06 17:12:12 by jwe]
jwe
parents: 5472
diff changeset
118
6323
ea65de49e18e [project @ 2007-02-17 02:51:02 by jwe]
jwe
parents: 6238
diff changeset
119 // TRUE means the current function file was found in a relative path
ea65de49e18e [project @ 2007-02-17 02:51:02 by jwe]
jwe
parents: 6238
diff changeset
120 // element.
ea65de49e18e [project @ 2007-02-17 02:51:02 by jwe]
jwe
parents: 6238
diff changeset
121 static bool fcn_file_from_relative_lookup = false;
ea65de49e18e [project @ 2007-02-17 02:51:02 by jwe]
jwe
parents: 6238
diff changeset
122
7336
745a8299c2b5 [project @ 2007-12-28 20:56:55 by jwe]
jwe
parents: 7017
diff changeset
123 // If nonzero, this is a pointer to the function we just finished
745a8299c2b5 [project @ 2007-12-28 20:56:55 by jwe]
jwe
parents: 7017
diff changeset
124 // parsing.
745a8299c2b5 [project @ 2007-12-28 20:56:55 by jwe]
jwe
parents: 7017
diff changeset
125 static octave_function *curr_fcn_ptr = 0;
745a8299c2b5 [project @ 2007-12-28 20:56:55 by jwe]
jwe
parents: 7017
diff changeset
126
5484
2ff5363a16bd [project @ 2005-10-06 17:12:12 by jwe]
jwe
parents: 5472
diff changeset
127 // List of autoloads (function -> file mapping).
2ff5363a16bd [project @ 2005-10-06 17:12:12 by jwe]
jwe
parents: 5472
diff changeset
128 static std::map<std::string, std::string> autoload_map;
2ff5363a16bd [project @ 2005-10-06 17:12:12 by jwe]
jwe
parents: 5472
diff changeset
129
496
e7c5b23b34d3 [project @ 1994-07-06 15:02:26 by jwe]
jwe
parents: 482
diff changeset
130 // 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
131 // the file.
e7c5b23b34d3 [project @ 1994-07-06 15:02:26 by jwe]
jwe
parents: 482
diff changeset
132
e7c5b23b34d3 [project @ 1994-07-06 15:02:26 by jwe]
jwe
parents: 482
diff changeset
133 // Generic error messages.
2970
b9e64477f703 [project @ 1997-05-15 18:04:21 by jwe]
jwe
parents: 2961
diff changeset
134 static void
b9e64477f703 [project @ 1997-05-15 18:04:21 by jwe]
jwe
parents: 2961
diff changeset
135 yyerror (const char *s);
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
136
578
d169be9237fb [project @ 1994-08-03 20:06:54 by jwe]
jwe
parents: 572
diff changeset
137 // Error mesages for mismatched end tokens.
2970
b9e64477f703 [project @ 1997-05-15 18:04:21 by jwe]
jwe
parents: 2961
diff changeset
138 static void
b9e64477f703 [project @ 1997-05-15 18:04:21 by jwe]
jwe
parents: 2961
diff changeset
139 end_error (const char *type, token::end_tok_type ettype, int l, int c);
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
140
578
d169be9237fb [project @ 1994-08-03 20:06:54 by jwe]
jwe
parents: 572
diff changeset
141 // Check to see that end tokens are properly matched.
2970
b9e64477f703 [project @ 1997-05-15 18:04:21 by jwe]
jwe
parents: 2961
diff changeset
142 static bool
b9e64477f703 [project @ 1997-05-15 18:04:21 by jwe]
jwe
parents: 2961
diff changeset
143 end_token_ok (token *tok, token::end_tok_type expected);
496
e7c5b23b34d3 [project @ 1994-07-06 15:02:26 by jwe]
jwe
parents: 482
diff changeset
144
e7c5b23b34d3 [project @ 1994-07-06 15:02:26 by jwe]
jwe
parents: 482
diff changeset
145 // Maybe print a warning if an assignment expression is used as the
e7c5b23b34d3 [project @ 1994-07-06 15:02:26 by jwe]
jwe
parents: 482
diff changeset
146 // test in a logical expression.
2970
b9e64477f703 [project @ 1997-05-15 18:04:21 by jwe]
jwe
parents: 2961
diff changeset
147 static void
b9e64477f703 [project @ 1997-05-15 18:04:21 by jwe]
jwe
parents: 2961
diff changeset
148 maybe_warn_assign_as_truth_value (tree_expression *expr);
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
149
2764
2c0f259cf83d [project @ 1997-03-01 02:30:26 by jwe]
jwe
parents: 2745
diff changeset
150 // Maybe print a warning about switch labels that aren't constants.
2970
b9e64477f703 [project @ 1997-05-15 18:04:21 by jwe]
jwe
parents: 2961
diff changeset
151 static void
b9e64477f703 [project @ 1997-05-15 18:04:21 by jwe]
jwe
parents: 2961
diff changeset
152 maybe_warn_variable_switch_label (tree_expression *expr);
2764
2c0f259cf83d [project @ 1997-03-01 02:30:26 by jwe]
jwe
parents: 2745
diff changeset
153
1623
fa7a847f9b92 [project @ 1995-11-06 18:05:09 by jwe]
jwe
parents: 1607
diff changeset
154 // Finish building a range.
2970
b9e64477f703 [project @ 1997-05-15 18:04:21 by jwe]
jwe
parents: 2961
diff changeset
155 static tree_expression *
b9e64477f703 [project @ 1997-05-15 18:04:21 by jwe]
jwe
parents: 2961
diff changeset
156 finish_colon_expression (tree_colon_expression *e);
1623
fa7a847f9b92 [project @ 1995-11-06 18:05:09 by jwe]
jwe
parents: 1607
diff changeset
157
1607
795527e9db19 [project @ 1995-11-02 13:03:36 by jwe]
jwe
parents: 1588
diff changeset
158 // Build a constant.
2970
b9e64477f703 [project @ 1997-05-15 18:04:21 by jwe]
jwe
parents: 2961
diff changeset
159 static tree_constant *
b9e64477f703 [project @ 1997-05-15 18:04:21 by jwe]
jwe
parents: 2961
diff changeset
160 make_constant (int op, token *tok_val);
1607
795527e9db19 [project @ 1995-11-02 13:03:36 by jwe]
jwe
parents: 1588
diff changeset
161
4342
813effe14ee1 [project @ 2003-02-20 08:35:55 by jwe]
jwe
parents: 4318
diff changeset
162 // Build a function handle.
813effe14ee1 [project @ 2003-02-20 08:35:55 by jwe]
jwe
parents: 4318
diff changeset
163 static tree_fcn_handle *
813effe14ee1 [project @ 2003-02-20 08:35:55 by jwe]
jwe
parents: 4318
diff changeset
164 make_fcn_handle (token *tok_val);
813effe14ee1 [project @ 2003-02-20 08:35:55 by jwe]
jwe
parents: 4318
diff changeset
165
4935
4fc993a4e072 [project @ 2004-08-06 03:17:12 by jwe]
jwe
parents: 4930
diff changeset
166 // Build an anonymous function handle.
5861
2a6cb4ed8f1e [project @ 2006-06-16 05:09:41 by jwe]
jwe
parents: 5848
diff changeset
167 static tree_anon_fcn_handle *
4935
4fc993a4e072 [project @ 2004-08-06 03:17:12 by jwe]
jwe
parents: 4930
diff changeset
168 make_anon_fcn_handle (tree_parameter_list *param_list, tree_statement *stmt);
4fc993a4e072 [project @ 2004-08-06 03:17:12 by jwe]
jwe
parents: 4930
diff changeset
169
578
d169be9237fb [project @ 1994-08-03 20:06:54 by jwe]
jwe
parents: 572
diff changeset
170 // Build a binary expression.
2970
b9e64477f703 [project @ 1997-05-15 18:04:21 by jwe]
jwe
parents: 2961
diff changeset
171 static tree_expression *
b9e64477f703 [project @ 1997-05-15 18:04:21 by jwe]
jwe
parents: 2961
diff changeset
172 make_binary_op (int op, tree_expression *op1, token *tok_val,
b9e64477f703 [project @ 1997-05-15 18:04:21 by jwe]
jwe
parents: 2961
diff changeset
173 tree_expression *op2);
578
d169be9237fb [project @ 1994-08-03 20:06:54 by jwe]
jwe
parents: 572
diff changeset
174
2375
7ef24992e290 [project @ 1996-10-12 00:39:52 by jwe]
jwe
parents: 2200
diff changeset
175 // Build a boolean expression.
2970
b9e64477f703 [project @ 1997-05-15 18:04:21 by jwe]
jwe
parents: 2961
diff changeset
176 static tree_expression *
b9e64477f703 [project @ 1997-05-15 18:04:21 by jwe]
jwe
parents: 2961
diff changeset
177 make_boolean_op (int op, tree_expression *op1, token *tok_val,
b9e64477f703 [project @ 1997-05-15 18:04:21 by jwe]
jwe
parents: 2961
diff changeset
178 tree_expression *op2);
2375
7ef24992e290 [project @ 1996-10-12 00:39:52 by jwe]
jwe
parents: 2200
diff changeset
179
578
d169be9237fb [project @ 1994-08-03 20:06:54 by jwe]
jwe
parents: 572
diff changeset
180 // Build a prefix expression.
2970
b9e64477f703 [project @ 1997-05-15 18:04:21 by jwe]
jwe
parents: 2961
diff changeset
181 static tree_expression *
b9e64477f703 [project @ 1997-05-15 18:04:21 by jwe]
jwe
parents: 2961
diff changeset
182 make_prefix_op (int op, tree_expression *op1, token *tok_val);
578
d169be9237fb [project @ 1994-08-03 20:06:54 by jwe]
jwe
parents: 572
diff changeset
183
d169be9237fb [project @ 1994-08-03 20:06:54 by jwe]
jwe
parents: 572
diff changeset
184 // Build a postfix expression.
2970
b9e64477f703 [project @ 1997-05-15 18:04:21 by jwe]
jwe
parents: 2961
diff changeset
185 static tree_expression *
b9e64477f703 [project @ 1997-05-15 18:04:21 by jwe]
jwe
parents: 2961
diff changeset
186 make_postfix_op (int op, tree_expression *op1, token *tok_val);
578
d169be9237fb [project @ 1994-08-03 20:06:54 by jwe]
jwe
parents: 572
diff changeset
187
1623
fa7a847f9b92 [project @ 1995-11-06 18:05:09 by jwe]
jwe
parents: 1607
diff changeset
188 // Build an unwind-protect command.
2970
b9e64477f703 [project @ 1997-05-15 18:04:21 by jwe]
jwe
parents: 2961
diff changeset
189 static tree_command *
b9e64477f703 [project @ 1997-05-15 18:04:21 by jwe]
jwe
parents: 2961
diff changeset
190 make_unwind_command (token *unwind_tok, tree_statement_list *body,
3665
0689afb1d001 [project @ 2000-05-11 19:07:56 by jwe]
jwe
parents: 3544
diff changeset
191 tree_statement_list *cleanup, token *end_tok,
0689afb1d001 [project @ 2000-05-11 19:07:56 by jwe]
jwe
parents: 3544
diff changeset
192 octave_comment_list *lc, octave_comment_list *mc);
1623
fa7a847f9b92 [project @ 1995-11-06 18:05:09 by jwe]
jwe
parents: 1607
diff changeset
193
fa7a847f9b92 [project @ 1995-11-06 18:05:09 by jwe]
jwe
parents: 1607
diff changeset
194 // Build a try-catch command.
2970
b9e64477f703 [project @ 1997-05-15 18:04:21 by jwe]
jwe
parents: 2961
diff changeset
195 static tree_command *
b9e64477f703 [project @ 1997-05-15 18:04:21 by jwe]
jwe
parents: 2961
diff changeset
196 make_try_command (token *try_tok, tree_statement_list *body,
3665
0689afb1d001 [project @ 2000-05-11 19:07:56 by jwe]
jwe
parents: 3544
diff changeset
197 tree_statement_list *cleanup, token *end_tok,
0689afb1d001 [project @ 2000-05-11 19:07:56 by jwe]
jwe
parents: 3544
diff changeset
198 octave_comment_list *lc, octave_comment_list *mc);
1623
fa7a847f9b92 [project @ 1995-11-06 18:05:09 by jwe]
jwe
parents: 1607
diff changeset
199
fa7a847f9b92 [project @ 1995-11-06 18:05:09 by jwe]
jwe
parents: 1607
diff changeset
200 // Build a while command.
2970
b9e64477f703 [project @ 1997-05-15 18:04:21 by jwe]
jwe
parents: 2961
diff changeset
201 static tree_command *
b9e64477f703 [project @ 1997-05-15 18:04:21 by jwe]
jwe
parents: 2961
diff changeset
202 make_while_command (token *while_tok, tree_expression *expr,
3665
0689afb1d001 [project @ 2000-05-11 19:07:56 by jwe]
jwe
parents: 3544
diff changeset
203 tree_statement_list *body, token *end_tok,
0689afb1d001 [project @ 2000-05-11 19:07:56 by jwe]
jwe
parents: 3544
diff changeset
204 octave_comment_list *lc);
1623
fa7a847f9b92 [project @ 1995-11-06 18:05:09 by jwe]
jwe
parents: 1607
diff changeset
205
3484
8b1f46ac2b64 [project @ 2000-01-27 23:30:45 by jwe]
jwe
parents: 3446
diff changeset
206 // Build a do-until command.
8b1f46ac2b64 [project @ 2000-01-27 23:30:45 by jwe]
jwe
parents: 3446
diff changeset
207 static tree_command *
8658
73c4516fae10 New evaluator and debugger derived from tree-walker class
John W. Eaton <jwe@octave.org>
parents: 8471
diff changeset
208 make_do_until_command (token *until_tok, tree_statement_list *body,
3665
0689afb1d001 [project @ 2000-05-11 19:07:56 by jwe]
jwe
parents: 3544
diff changeset
209 tree_expression *expr, octave_comment_list *lc);
3484
8b1f46ac2b64 [project @ 2000-01-27 23:30:45 by jwe]
jwe
parents: 3446
diff changeset
210
1623
fa7a847f9b92 [project @ 1995-11-06 18:05:09 by jwe]
jwe
parents: 1607
diff changeset
211 // Build a for command.
2970
b9e64477f703 [project @ 1997-05-15 18:04:21 by jwe]
jwe
parents: 2961
diff changeset
212 static tree_command *
b9e64477f703 [project @ 1997-05-15 18:04:21 by jwe]
jwe
parents: 2961
diff changeset
213 make_for_command (token *for_tok, tree_argument_list *lhs,
b9e64477f703 [project @ 1997-05-15 18:04:21 by jwe]
jwe
parents: 2961
diff changeset
214 tree_expression *expr, tree_statement_list *body,
3665
0689afb1d001 [project @ 2000-05-11 19:07:56 by jwe]
jwe
parents: 3544
diff changeset
215 token *end_tok, octave_comment_list *lc);
1623
fa7a847f9b92 [project @ 1995-11-06 18:05:09 by jwe]
jwe
parents: 1607
diff changeset
216
4207
fa3482b34599 [project @ 2002-12-03 18:22:05 by jwe]
jwe
parents: 4186
diff changeset
217 // Build a break command.
fa3482b34599 [project @ 2002-12-03 18:22:05 by jwe]
jwe
parents: 4186
diff changeset
218 static tree_command *
fa3482b34599 [project @ 2002-12-03 18:22:05 by jwe]
jwe
parents: 4186
diff changeset
219 make_break_command (token *break_tok);
fa3482b34599 [project @ 2002-12-03 18:22:05 by jwe]
jwe
parents: 4186
diff changeset
220
fa3482b34599 [project @ 2002-12-03 18:22:05 by jwe]
jwe
parents: 4186
diff changeset
221 // Build a continue command.
fa3482b34599 [project @ 2002-12-03 18:22:05 by jwe]
jwe
parents: 4186
diff changeset
222 static tree_command *
fa3482b34599 [project @ 2002-12-03 18:22:05 by jwe]
jwe
parents: 4186
diff changeset
223 make_continue_command (token *continue_tok);
fa3482b34599 [project @ 2002-12-03 18:22:05 by jwe]
jwe
parents: 4186
diff changeset
224
fa3482b34599 [project @ 2002-12-03 18:22:05 by jwe]
jwe
parents: 4186
diff changeset
225 // Build a return command.
fa3482b34599 [project @ 2002-12-03 18:22:05 by jwe]
jwe
parents: 4186
diff changeset
226 static tree_command *
fa3482b34599 [project @ 2002-12-03 18:22:05 by jwe]
jwe
parents: 4186
diff changeset
227 make_return_command (token *return_tok);
1623
fa7a847f9b92 [project @ 1995-11-06 18:05:09 by jwe]
jwe
parents: 1607
diff changeset
228
fa7a847f9b92 [project @ 1995-11-06 18:05:09 by jwe]
jwe
parents: 1607
diff changeset
229 // Start an if command.
2970
b9e64477f703 [project @ 1997-05-15 18:04:21 by jwe]
jwe
parents: 2961
diff changeset
230 static tree_if_command_list *
b9e64477f703 [project @ 1997-05-15 18:04:21 by jwe]
jwe
parents: 2961
diff changeset
231 start_if_command (tree_expression *expr, tree_statement_list *list);
1623
fa7a847f9b92 [project @ 1995-11-06 18:05:09 by jwe]
jwe
parents: 1607
diff changeset
232
fa7a847f9b92 [project @ 1995-11-06 18:05:09 by jwe]
jwe
parents: 1607
diff changeset
233 // Finish an if command.
2970
b9e64477f703 [project @ 1997-05-15 18:04:21 by jwe]
jwe
parents: 2961
diff changeset
234 static tree_if_command *
3665
0689afb1d001 [project @ 2000-05-11 19:07:56 by jwe]
jwe
parents: 3544
diff changeset
235 finish_if_command (token *if_tok, tree_if_command_list *list,
0689afb1d001 [project @ 2000-05-11 19:07:56 by jwe]
jwe
parents: 3544
diff changeset
236 token *end_tok, octave_comment_list *lc);
1623
fa7a847f9b92 [project @ 1995-11-06 18:05:09 by jwe]
jwe
parents: 1607
diff changeset
237
fa7a847f9b92 [project @ 1995-11-06 18:05:09 by jwe]
jwe
parents: 1607
diff changeset
238 // Build an elseif clause.
2970
b9e64477f703 [project @ 1997-05-15 18:04:21 by jwe]
jwe
parents: 2961
diff changeset
239 static tree_if_clause *
8658
73c4516fae10 New evaluator and debugger derived from tree-walker class
John W. Eaton <jwe@octave.org>
parents: 8471
diff changeset
240 make_elseif_clause (token *elseif_tok, tree_expression *expr,
73c4516fae10 New evaluator and debugger derived from tree-walker class
John W. Eaton <jwe@octave.org>
parents: 8471
diff changeset
241 tree_statement_list *list, octave_comment_list *lc);
1623
fa7a847f9b92 [project @ 1995-11-06 18:05:09 by jwe]
jwe
parents: 1607
diff changeset
242
2764
2c0f259cf83d [project @ 1997-03-01 02:30:26 by jwe]
jwe
parents: 2745
diff changeset
243 // Finish a switch command.
2970
b9e64477f703 [project @ 1997-05-15 18:04:21 by jwe]
jwe
parents: 2961
diff changeset
244 static tree_switch_command *
b9e64477f703 [project @ 1997-05-15 18:04:21 by jwe]
jwe
parents: 2961
diff changeset
245 finish_switch_command (token *switch_tok, tree_expression *expr,
3665
0689afb1d001 [project @ 2000-05-11 19:07:56 by jwe]
jwe
parents: 3544
diff changeset
246 tree_switch_case_list *list, token *end_tok,
0689afb1d001 [project @ 2000-05-11 19:07:56 by jwe]
jwe
parents: 3544
diff changeset
247 octave_comment_list *lc);
2764
2c0f259cf83d [project @ 1997-03-01 02:30:26 by jwe]
jwe
parents: 2745
diff changeset
248
2c0f259cf83d [project @ 1997-03-01 02:30:26 by jwe]
jwe
parents: 2745
diff changeset
249 // Build a switch case.
2970
b9e64477f703 [project @ 1997-05-15 18:04:21 by jwe]
jwe
parents: 2961
diff changeset
250 static tree_switch_case *
8658
73c4516fae10 New evaluator and debugger derived from tree-walker class
John W. Eaton <jwe@octave.org>
parents: 8471
diff changeset
251 make_switch_case (token *case_tok, tree_expression *expr,
73c4516fae10 New evaluator and debugger derived from tree-walker class
John W. Eaton <jwe@octave.org>
parents: 8471
diff changeset
252 tree_statement_list *list, octave_comment_list *lc);
2764
2c0f259cf83d [project @ 1997-03-01 02:30:26 by jwe]
jwe
parents: 2745
diff changeset
253
1623
fa7a847f9b92 [project @ 1995-11-06 18:05:09 by jwe]
jwe
parents: 1607
diff changeset
254 // Build an assignment to a variable.
2970
b9e64477f703 [project @ 1997-05-15 18:04:21 by jwe]
jwe
parents: 2961
diff changeset
255 static tree_expression *
b9e64477f703 [project @ 1997-05-15 18:04:21 by jwe]
jwe
parents: 2961
diff changeset
256 make_assign_op (int op, tree_argument_list *lhs, token *eq_tok,
b9e64477f703 [project @ 1997-05-15 18:04:21 by jwe]
jwe
parents: 2961
diff changeset
257 tree_expression *rhs);
1623
fa7a847f9b92 [project @ 1995-11-06 18:05:09 by jwe]
jwe
parents: 1607
diff changeset
258
7715
5b4d278ec828 parse scripts completely before executing
John W. Eaton <jwe@octave.org>
parents: 7699
diff changeset
259 // Define a script.
5b4d278ec828 parse scripts completely before executing
John W. Eaton <jwe@octave.org>
parents: 7699
diff changeset
260 static void
8658
73c4516fae10 New evaluator and debugger derived from tree-walker class
John W. Eaton <jwe@octave.org>
parents: 8471
diff changeset
261 make_script (tree_statement_list *cmds, tree_statement *end_script);
7715
5b4d278ec828 parse scripts completely before executing
John W. Eaton <jwe@octave.org>
parents: 7699
diff changeset
262
1623
fa7a847f9b92 [project @ 1995-11-06 18:05:09 by jwe]
jwe
parents: 1607
diff changeset
263 // Begin defining a function.
2970
b9e64477f703 [project @ 1997-05-15 18:04:21 by jwe]
jwe
parents: 2961
diff changeset
264 static octave_user_function *
8658
73c4516fae10 New evaluator and debugger derived from tree-walker class
John W. Eaton <jwe@octave.org>
parents: 8471
diff changeset
265 start_function (tree_parameter_list *param_list, tree_statement_list *body,
73c4516fae10 New evaluator and debugger derived from tree-walker class
John W. Eaton <jwe@octave.org>
parents: 8471
diff changeset
266 tree_statement *end_function);
73c4516fae10 New evaluator and debugger derived from tree-walker class
John W. Eaton <jwe@octave.org>
parents: 8471
diff changeset
267
73c4516fae10 New evaluator and debugger derived from tree-walker class
John W. Eaton <jwe@octave.org>
parents: 8471
diff changeset
268 // Create a no-op statement for end_function.
73c4516fae10 New evaluator and debugger derived from tree-walker class
John W. Eaton <jwe@octave.org>
parents: 8471
diff changeset
269 static tree_statement *
73c4516fae10 New evaluator and debugger derived from tree-walker class
John W. Eaton <jwe@octave.org>
parents: 8471
diff changeset
270 make_end (const std::string& type, int l, int c);
1623
fa7a847f9b92 [project @ 1995-11-06 18:05:09 by jwe]
jwe
parents: 1607
diff changeset
271
fa7a847f9b92 [project @ 1995-11-06 18:05:09 by jwe]
jwe
parents: 1607
diff changeset
272 // Do most of the work for defining a function.
2970
b9e64477f703 [project @ 1997-05-15 18:04:21 by jwe]
jwe
parents: 2961
diff changeset
273 static octave_user_function *
4872
fe71c458f438 [project @ 2004-04-21 20:09:32 by jwe]
jwe
parents: 4844
diff changeset
274 frob_function (const std::string& fname, octave_user_function *fcn);
1623
fa7a847f9b92 [project @ 1995-11-06 18:05:09 by jwe]
jwe
parents: 1607
diff changeset
275
fa7a847f9b92 [project @ 1995-11-06 18:05:09 by jwe]
jwe
parents: 1607
diff changeset
276 // Finish defining a function.
7715
5b4d278ec828 parse scripts completely before executing
John W. Eaton <jwe@octave.org>
parents: 7699
diff changeset
277 static tree_function_def *
3665
0689afb1d001 [project @ 2000-05-11 19:07:56 by jwe]
jwe
parents: 3544
diff changeset
278 finish_function (tree_parameter_list *ret_list,
0689afb1d001 [project @ 2000-05-11 19:07:56 by jwe]
jwe
parents: 3544
diff changeset
279 octave_user_function *fcn, octave_comment_list *lc);
751
c9f3cb77478d [project @ 1994-09-30 18:46:17 by jwe]
jwe
parents: 723
diff changeset
280
2883
0b3954110c77 [project @ 1997-04-24 09:57:05 by jwe]
jwe
parents: 2865
diff changeset
281 // Reset state after parsing function.
2970
b9e64477f703 [project @ 1997-05-15 18:04:21 by jwe]
jwe
parents: 2961
diff changeset
282 static void
b9e64477f703 [project @ 1997-05-15 18:04:21 by jwe]
jwe
parents: 2961
diff changeset
283 recover_from_parsing_function (void);
2883
0b3954110c77 [project @ 1997-04-24 09:57:05 by jwe]
jwe
parents: 2865
diff changeset
284
751
c9f3cb77478d [project @ 1994-09-30 18:46:17 by jwe]
jwe
parents: 723
diff changeset
285 // Make an index expression.
2970
b9e64477f703 [project @ 1997-05-15 18:04:21 by jwe]
jwe
parents: 2961
diff changeset
286 static tree_index_expression *
3933
f9ea3dcf58ee [project @ 2002-05-15 03:21:00 by jwe]
jwe
parents: 3930
diff changeset
287 make_index_expression (tree_expression *expr,
f9ea3dcf58ee [project @ 2002-05-15 03:21:00 by jwe]
jwe
parents: 3930
diff changeset
288 tree_argument_list *args, char type);
2970
b9e64477f703 [project @ 1997-05-15 18:04:21 by jwe]
jwe
parents: 2961
diff changeset
289
b9e64477f703 [project @ 1997-05-15 18:04:21 by jwe]
jwe
parents: 2961
diff changeset
290 // Make an indirect reference expression.
3930
61d4427c016e [project @ 2002-05-07 00:47:31 by jwe]
jwe
parents: 3929
diff changeset
291 static tree_index_expression *
3523
b80bbb43a1a9 [project @ 2000-02-02 10:25:52 by jwe]
jwe
parents: 3489
diff changeset
292 make_indirect_ref (tree_expression *expr, const std::string&);
666
fb4f6556b443 [project @ 1994-09-06 21:22:46 by jwe]
jwe
parents: 627
diff changeset
293
4131
597fbc55ea40 [project @ 2002-10-29 17:12:53 by jwe]
jwe
parents: 4064
diff changeset
294 // Make an indirect reference expression with dynamic field name.
597fbc55ea40 [project @ 2002-10-29 17:12:53 by jwe]
jwe
parents: 4064
diff changeset
295 static tree_index_expression *
597fbc55ea40 [project @ 2002-10-29 17:12:53 by jwe]
jwe
parents: 4064
diff changeset
296 make_indirect_ref (tree_expression *expr, tree_expression *field);
597fbc55ea40 [project @ 2002-10-29 17:12:53 by jwe]
jwe
parents: 4064
diff changeset
297
2846
52e7c4509983 [project @ 1997-03-26 23:27:35 by jwe]
jwe
parents: 2825
diff changeset
298 // Make a declaration command.
2970
b9e64477f703 [project @ 1997-05-15 18:04:21 by jwe]
jwe
parents: 2961
diff changeset
299 static tree_decl_command *
b9e64477f703 [project @ 1997-05-15 18:04:21 by jwe]
jwe
parents: 2961
diff changeset
300 make_decl_command (int tok, token *tok_val, tree_decl_init_list *lst);
2846
52e7c4509983 [project @ 1997-03-26 23:27:35 by jwe]
jwe
parents: 2825
diff changeset
301
1623
fa7a847f9b92 [project @ 1995-11-06 18:05:09 by jwe]
jwe
parents: 1607
diff changeset
302 // Finish building a matrix list.
2970
b9e64477f703 [project @ 1997-05-15 18:04:21 by jwe]
jwe
parents: 2961
diff changeset
303 static tree_expression *
b9e64477f703 [project @ 1997-05-15 18:04:21 by jwe]
jwe
parents: 2961
diff changeset
304 finish_matrix (tree_matrix *m);
1623
fa7a847f9b92 [project @ 1995-11-06 18:05:09 by jwe]
jwe
parents: 1607
diff changeset
305
3351
8623649c967c [project @ 1999-11-15 16:17:01 by jwe]
jwe
parents: 3347
diff changeset
306 // Finish building a cell list.
8623649c967c [project @ 1999-11-15 16:17:01 by jwe]
jwe
parents: 3347
diff changeset
307 static tree_expression *
8623649c967c [project @ 1999-11-15 16:17:01 by jwe]
jwe
parents: 3347
diff changeset
308 finish_cell (tree_cell *c);
8623649c967c [project @ 1999-11-15 16:17:01 by jwe]
jwe
parents: 3347
diff changeset
309
1511
74f9e88a2c12 [project @ 1995-10-03 10:49:31 by jwe]
jwe
parents: 1491
diff changeset
310 // Maybe print a warning. Duh.
2970
b9e64477f703 [project @ 1997-05-15 18:04:21 by jwe]
jwe
parents: 2961
diff changeset
311 static void
b9e64477f703 [project @ 1997-05-15 18:04:21 by jwe]
jwe
parents: 2961
diff changeset
312 maybe_warn_missing_semi (tree_statement_list *);
1511
74f9e88a2c12 [project @ 1995-10-03 10:49:31 by jwe]
jwe
parents: 1491
diff changeset
313
2525
8561d88be5f2 [project @ 1996-11-17 21:23:31 by jwe]
jwe
parents: 2524
diff changeset
314 // Set the print flag for a statement based on the separator type.
8471
02de6775f1fe parse.y: always append statements to list, but remove null statements after seeing separator
John W. Eaton <jwe@octave.org>
parents: 8448
diff changeset
315 static tree_statement_list *
2970
b9e64477f703 [project @ 1997-05-15 18:04:21 by jwe]
jwe
parents: 2961
diff changeset
316 set_stmt_print_flag (tree_statement_list *, char, bool);
2525
8561d88be5f2 [project @ 1996-11-17 21:23:31 by jwe]
jwe
parents: 2524
diff changeset
317
8448
d6c0d5f208de parse.y: avoid storing null statements in statement lists
John W. Eaton <jwe@octave.org>
parents: 8447
diff changeset
318 // Create a statement list.
d6c0d5f208de parse.y: avoid storing null statements in statement lists
John W. Eaton <jwe@octave.org>
parents: 8447
diff changeset
319 static tree_statement_list *make_statement_list (tree_statement *stmt);
d6c0d5f208de parse.y: avoid storing null statements in statement lists
John W. Eaton <jwe@octave.org>
parents: 8447
diff changeset
320
d6c0d5f208de parse.y: avoid storing null statements in statement lists
John W. Eaton <jwe@octave.org>
parents: 8447
diff changeset
321 // Append a statement to an existing statement list.
d6c0d5f208de parse.y: avoid storing null statements in statement lists
John W. Eaton <jwe@octave.org>
parents: 8447
diff changeset
322 static tree_statement_list *
d6c0d5f208de parse.y: avoid storing null statements in statement lists
John W. Eaton <jwe@octave.org>
parents: 8447
diff changeset
323 append_statement_list (tree_statement_list *list, char sep,
d6c0d5f208de parse.y: avoid storing null statements in statement lists
John W. Eaton <jwe@octave.org>
parents: 8447
diff changeset
324 tree_statement *stmt, bool warn_missing_semi);
d6c0d5f208de parse.y: avoid storing null statements in statement lists
John W. Eaton <jwe@octave.org>
parents: 8447
diff changeset
325
d6c0d5f208de parse.y: avoid storing null statements in statement lists
John W. Eaton <jwe@octave.org>
parents: 8447
diff changeset
326 // Finish building a statement.
d6c0d5f208de parse.y: avoid storing null statements in statement lists
John W. Eaton <jwe@octave.org>
parents: 8447
diff changeset
327 template <class T>
d6c0d5f208de parse.y: avoid storing null statements in statement lists
John W. Eaton <jwe@octave.org>
parents: 8447
diff changeset
328 static tree_statement *
d6c0d5f208de parse.y: avoid storing null statements in statement lists
John W. Eaton <jwe@octave.org>
parents: 8447
diff changeset
329 make_statement (T *arg)
d6c0d5f208de parse.y: avoid storing null statements in statement lists
John W. Eaton <jwe@octave.org>
parents: 8447
diff changeset
330 {
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
331 octave_comment_list *comment = octave_comment_buffer::get_comment ();
02de6775f1fe parse.y: always append statements to list, but remove null statements after seeing separator
John W. Eaton <jwe@octave.org>
parents: 8448
diff changeset
332
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
333 return new tree_statement (arg, comment);
8448
d6c0d5f208de parse.y: avoid storing null statements in statement lists
John W. Eaton <jwe@octave.org>
parents: 8447
diff changeset
334 }
d6c0d5f208de parse.y: avoid storing null statements in statement lists
John W. Eaton <jwe@octave.org>
parents: 8447
diff changeset
335
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
336 #define ABORT_PARSE \
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
337 do \
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
338 { \
522
2dba380d2d85 [project @ 1994-07-20 18:31:40 by jwe]
jwe
parents: 504
diff changeset
339 global_command = 0; \
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
340 yyerrok; \
4238
a5a68c0afe56 [project @ 2002-12-25 21:04:33 by jwe]
jwe
parents: 4237
diff changeset
341 if (! symtab_context.empty ()) \
3929
cc8ae49d6e79 [project @ 2002-05-04 02:47:14 by jwe]
jwe
parents: 3928
diff changeset
342 { \
7336
745a8299c2b5 [project @ 2007-12-28 20:56:55 by jwe]
jwe
parents: 7017
diff changeset
343 symbol_table::set_scope (symtab_context.top ()); \
4238
a5a68c0afe56 [project @ 2002-12-25 21:04:33 by jwe]
jwe
parents: 4237
diff changeset
344 symtab_context.pop (); \
3929
cc8ae49d6e79 [project @ 2002-05-04 02:47:14 by jwe]
jwe
parents: 3928
diff changeset
345 } \
2865
2d9047854387 [project @ 1997-04-17 18:13:10 by jwe]
jwe
parents: 2862
diff changeset
346 if (interactive || forced_interactive) \
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
347 YYACCEPT; \
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
348 else \
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
349 YYABORT; \
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
350 } \
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
351 while (0)
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
352
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
353 %}
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
354
666
fb4f6556b443 [project @ 1994-09-06 21:22:46 by jwe]
jwe
parents: 627
diff changeset
355 // Bison declarations.
fb4f6556b443 [project @ 1994-09-06 21:22:46 by jwe]
jwe
parents: 627
diff changeset
356
4813
fba5c6e96e0f [project @ 2004-03-03 23:35:43 by jwe]
jwe
parents: 4753
diff changeset
357 // 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
358 // bison to fail to properly recognize the directive.
fba5c6e96e0f [project @ 2004-03-03 23:35:43 by jwe]
jwe
parents: 4753
diff changeset
359
fba5c6e96e0f [project @ 2004-03-03 23:35:43 by jwe]
jwe
parents: 4753
diff changeset
360 %name-prefix="octave_"
4753
9f0ce1536368 [project @ 2004-02-13 17:55:24 by jwe]
jwe
parents: 4699
diff changeset
361
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
362 %union
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
363 {
2891
1a30f46e1870 [project @ 1997-04-28 01:49:00 by jwe]
jwe
parents: 2884
diff changeset
364 // 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
365 token *tok_val;
7849db4b6dbc [project @ 1993-10-04 02:36:45 by jwe]
jwe
parents: 118
diff changeset
366
3665
0689afb1d001 [project @ 2000-05-11 19:07:56 by jwe]
jwe
parents: 3544
diff changeset
367 // 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
368 octave_comment_list *comment_type;
0689afb1d001 [project @ 2000-05-11 19:07:56 by jwe]
jwe
parents: 3544
diff changeset
369
2891
1a30f46e1870 [project @ 1997-04-28 01:49:00 by jwe]
jwe
parents: 2884
diff changeset
370 // Types for the nonterminals we generate.
2525
8561d88be5f2 [project @ 1996-11-17 21:23:31 by jwe]
jwe
parents: 2524
diff changeset
371 char sep_type;
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
372 tree *tree_type;
1829
7d2982b55242 [project @ 1996-02-02 14:12:59 by jwe]
jwe
parents: 1826
diff changeset
373 tree_matrix *tree_matrix_type;
3351
8623649c967c [project @ 1999-11-15 16:17:01 by jwe]
jwe
parents: 3347
diff changeset
374 tree_cell *tree_cell_type;
496
e7c5b23b34d3 [project @ 1994-07-06 15:02:26 by jwe]
jwe
parents: 482
diff changeset
375 tree_expression *tree_expression_type;
2375
7ef24992e290 [project @ 1996-10-12 00:39:52 by jwe]
jwe
parents: 2200
diff changeset
376 tree_constant *tree_constant_type;
4342
813effe14ee1 [project @ 2003-02-20 08:35:55 by jwe]
jwe
parents: 4318
diff changeset
377 tree_fcn_handle *tree_fcn_handle_type;
5861
2a6cb4ed8f1e [project @ 2006-06-16 05:09:41 by jwe]
jwe
parents: 5848
diff changeset
378 tree_anon_fcn_handle *tree_anon_fcn_handle_type;
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
379 tree_identifier *tree_identifier_type;
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
380 tree_index_expression *tree_index_expression_type;
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
381 tree_colon_expression *tree_colon_expression_type;
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
382 tree_argument_list *tree_argument_list_type;
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
383 tree_parameter_list *tree_parameter_list_type;
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
384 tree_command *tree_command_type;
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
385 tree_if_command *tree_if_command_type;
578
d169be9237fb [project @ 1994-08-03 20:06:54 by jwe]
jwe
parents: 572
diff changeset
386 tree_if_clause *tree_if_clause_type;
d169be9237fb [project @ 1994-08-03 20:06:54 by jwe]
jwe
parents: 572
diff changeset
387 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
388 tree_switch_command *tree_switch_command_type;
2c0f259cf83d [project @ 1997-03-01 02:30:26 by jwe]
jwe
parents: 2745
diff changeset
389 tree_switch_case *tree_switch_case_type;
2c0f259cf83d [project @ 1997-03-01 02:30:26 by jwe]
jwe
parents: 2745
diff changeset
390 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
391 tree_decl_elt *tree_decl_elt_type;
52e7c4509983 [project @ 1997-03-26 23:27:35 by jwe]
jwe
parents: 2825
diff changeset
392 tree_decl_init_list *tree_decl_init_list_type;
52e7c4509983 [project @ 1997-03-26 23:27:35 by jwe]
jwe
parents: 2825
diff changeset
393 tree_decl_command *tree_decl_command_type;
578
d169be9237fb [project @ 1994-08-03 20:06:54 by jwe]
jwe
parents: 572
diff changeset
394 tree_statement *tree_statement_type;
d169be9237fb [project @ 1994-08-03 20:06:54 by jwe]
jwe
parents: 572
diff changeset
395 tree_statement_list *tree_statement_list_type;
2891
1a30f46e1870 [project @ 1997-04-28 01:49:00 by jwe]
jwe
parents: 2884
diff changeset
396 octave_user_function *octave_user_function_type;
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
397 }
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
398
143
7849db4b6dbc [project @ 1993-10-04 02:36:45 by jwe]
jwe
parents: 118
diff changeset
399 // Tokens with line and column information.
7849db4b6dbc [project @ 1993-10-04 02:36:45 by jwe]
jwe
parents: 118
diff changeset
400 %token <tok_val> '=' ':' '-' '+' '*' '/'
4018
a8621d87fbf5 [project @ 2002-08-05 03:17:25 by jwe]
jwe
parents: 4009
diff changeset
401 %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
402 %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
403 %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
404 %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
405 %token <tok_val> EXPR_AND EXPR_OR EXPR_NOT
7849db4b6dbc [project @ 1993-10-04 02:36:45 by jwe]
jwe
parents: 118
diff changeset
406 %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
407 %token <tok_val> LEFTDIV EMUL EDIV ELEFTDIV EPLUS EMINUS
cbdf7db98554 [project @ 1995-04-24 15:31:24 by jwe]
jwe
parents: 1266
diff changeset
408 %token <tok_val> QUOTE TRANSPOSE
143
7849db4b6dbc [project @ 1993-10-04 02:36:45 by jwe]
jwe
parents: 118
diff changeset
409 %token <tok_val> PLUS_PLUS MINUS_MINUS POW EPOW
7849db4b6dbc [project @ 1993-10-04 02:36:45 by jwe]
jwe
parents: 118
diff changeset
410 %token <tok_val> NUM IMAG_NUM
2970
b9e64477f703 [project @ 1997-05-15 18:04:21 by jwe]
jwe
parents: 2961
diff changeset
411 %token <tok_val> STRUCT_ELT
2883
0b3954110c77 [project @ 1997-04-24 09:57:05 by jwe]
jwe
parents: 2865
diff changeset
412 %token <tok_val> NAME
143
7849db4b6dbc [project @ 1993-10-04 02:36:45 by jwe]
jwe
parents: 118
diff changeset
413 %token <tok_val> END
5279
bd32f770c09a [project @ 2005-04-12 21:55:31 by jwe]
jwe
parents: 5189
diff changeset
414 %token <tok_val> DQ_STRING SQ_STRING
3484
8b1f46ac2b64 [project @ 2000-01-27 23:30:45 by jwe]
jwe
parents: 3446
diff changeset
415 %token <tok_val> FOR WHILE DO UNTIL
1491
893b416bb919 [project @ 1995-09-29 04:03:01 by jwe]
jwe
parents: 1489
diff changeset
416 %token <tok_val> IF ELSEIF ELSE
2764
2c0f259cf83d [project @ 1997-03-01 02:30:26 by jwe]
jwe
parents: 2745
diff changeset
417 %token <tok_val> SWITCH CASE OTHERWISE
1491
893b416bb919 [project @ 1995-09-29 04:03:01 by jwe]
jwe
parents: 1489
diff changeset
418 %token <tok_val> BREAK CONTINUE FUNC_RET
924
8b0920cc1d64 [project @ 1994-11-15 00:40:50 by jwe]
jwe
parents: 922
diff changeset
419 %token <tok_val> UNWIND CLEANUP
1489
3e705c864019 [project @ 1995-09-28 05:38:26 by jwe]
jwe
parents: 1371
diff changeset
420 %token <tok_val> TRY CATCH
2846
52e7c4509983 [project @ 1997-03-26 23:27:35 by jwe]
jwe
parents: 2825
diff changeset
421 %token <tok_val> GLOBAL STATIC
4342
813effe14ee1 [project @ 2003-02-20 08:35:55 by jwe]
jwe
parents: 4318
diff changeset
422 %token <tok_val> FCN_HANDLE
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
423
143
7849db4b6dbc [project @ 1993-10-04 02:36:45 by jwe]
jwe
parents: 118
diff changeset
424 // Other tokens.
2970
b9e64477f703 [project @ 1997-05-15 18:04:21 by jwe]
jwe
parents: 2961
diff changeset
425 %token END_OF_INPUT LEXICAL_ERROR
7715
5b4d278ec828 parse scripts completely before executing
John W. Eaton <jwe@octave.org>
parents: 7699
diff changeset
426 %token FCN SCRIPT
7587
1f662945c2be handle varargin and varargout without keywords
John W. Eaton <jwe@octave.org>
parents: 7562
diff changeset
427 // %token VARARGIN VARARGOUT
5296
4e753a157ed2 [project @ 2005-04-21 17:52:41 by jwe]
jwe
parents: 5279
diff changeset
428 %token CLOSE_BRACE
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
429
143
7849db4b6dbc [project @ 1993-10-04 02:36:45 by jwe]
jwe
parents: 118
diff changeset
430 // Nonterminals we construct.
3665
0689afb1d001 [project @ 2000-05-11 19:07:56 by jwe]
jwe
parents: 3544
diff changeset
431 %type <comment_type> stash_comment function_beg
2525
8561d88be5f2 [project @ 1996-11-17 21:23:31 by jwe]
jwe
parents: 2524
diff changeset
432 %type <sep_type> sep_no_nl opt_sep_no_nl sep opt_sep
578
d169be9237fb [project @ 1994-08-03 20:06:54 by jwe]
jwe
parents: 572
diff changeset
433 %type <tree_type> input
5861
2a6cb4ed8f1e [project @ 2006-06-16 05:09:41 by jwe]
jwe
parents: 5848
diff changeset
434 %type <tree_constant_type> string constant magic_colon
2a6cb4ed8f1e [project @ 2006-06-16 05:09:41 by jwe]
jwe
parents: 5848
diff changeset
435 %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
436 %type <tree_fcn_handle_type> fcn_handle
3351
8623649c967c [project @ 1999-11-15 16:17:01 by jwe]
jwe
parents: 3347
diff changeset
437 %type <tree_matrix_type> matrix_rows matrix_rows1
8623649c967c [project @ 1999-11-15 16:17:01 by jwe]
jwe
parents: 3347
diff changeset
438 %type <tree_cell_type> cell_rows cell_rows1
5102
b04b30d30c66 [project @ 2004-12-28 01:59:05 by jwe]
jwe
parents: 5013
diff changeset
439 %type <tree_expression_type> matrix cell
4207
fa3482b34599 [project @ 2002-12-03 18:22:05 by jwe]
jwe
parents: 4186
diff changeset
440 %type <tree_expression_type> primary_expr postfix_expr prefix_expr binary_expr
fa3482b34599 [project @ 2002-12-03 18:22:05 by jwe]
jwe
parents: 4186
diff changeset
441 %type <tree_expression_type> simple_expr colon_expr assign_expr expression
4238
a5a68c0afe56 [project @ 2002-12-25 21:04:33 by jwe]
jwe
parents: 4237
diff changeset
442 %type <tree_identifier_type> identifier fcn_name
7336
745a8299c2b5 [project @ 2007-12-28 20:56:55 by jwe]
jwe
parents: 7017
diff changeset
443 %type <octave_user_function_type> function1 function2
2970
b9e64477f703 [project @ 1997-05-15 18:04:21 by jwe]
jwe
parents: 2961
diff changeset
444 %type <tree_index_expression_type> word_list_cmd
b9e64477f703 [project @ 1997-05-15 18:04:21 by jwe]
jwe
parents: 2961
diff changeset
445 %type <tree_colon_expression_type> colon_expr1
3351
8623649c967c [project @ 1999-11-15 16:17:01 by jwe]
jwe
parents: 3347
diff changeset
446 %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
447 %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
448 %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
449 %type <tree_parameter_list_type> return_list return_list1
2970
b9e64477f703 [project @ 1997-05-15 18:04:21 by jwe]
jwe
parents: 2961
diff changeset
450 %type <tree_command_type> command select_command loop_command
7715
5b4d278ec828 parse scripts completely before executing
John W. Eaton <jwe@octave.org>
parents: 7699
diff changeset
451 %type <tree_command_type> jump_command except_command function script
578
d169be9237fb [project @ 1994-08-03 20:06:54 by jwe]
jwe
parents: 572
diff changeset
452 %type <tree_if_command_type> if_command
d169be9237fb [project @ 1994-08-03 20:06:54 by jwe]
jwe
parents: 572
diff changeset
453 %type <tree_if_clause_type> elseif_clause else_clause
d169be9237fb [project @ 1994-08-03 20:06:54 by jwe]
jwe
parents: 572
diff changeset
454 %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
455 %type <tree_switch_command_type> switch_command
2c0f259cf83d [project @ 1997-03-01 02:30:26 by jwe]
jwe
parents: 2745
diff changeset
456 %type <tree_switch_case_type> switch_case default_case
2c0f259cf83d [project @ 1997-03-01 02:30:26 by jwe]
jwe
parents: 2745
diff changeset
457 %type <tree_switch_case_list_type> case_list1 case_list
2846
52e7c4509983 [project @ 1997-03-26 23:27:35 by jwe]
jwe
parents: 2825
diff changeset
458 %type <tree_decl_elt_type> decl2
52e7c4509983 [project @ 1997-03-26 23:27:35 by jwe]
jwe
parents: 2825
diff changeset
459 %type <tree_decl_init_list_type> decl1
52e7c4509983 [project @ 1997-03-26 23:27:35 by jwe]
jwe
parents: 2825
diff changeset
460 %type <tree_decl_command_type> declaration
8658
73c4516fae10 New evaluator and debugger derived from tree-walker class
John W. Eaton <jwe@octave.org>
parents: 8471
diff changeset
461 %type <tree_statement_type> statement function_end
627
739d16c30481 [project @ 1994-08-19 13:23:14 by jwe]
jwe
parents: 620
diff changeset
462 %type <tree_statement_list_type> simple_list simple_list1 list list1
7336
745a8299c2b5 [project @ 2007-12-28 20:56:55 by jwe]
jwe
parents: 7017
diff changeset
463 %type <tree_statement_list_type> opt_list input1
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
464
143
7849db4b6dbc [project @ 1993-10-04 02:36:45 by jwe]
jwe
parents: 118
diff changeset
465 // Precedence and associativity.
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
466 %left ';' ',' '\n'
4018
a8621d87fbf5 [project @ 2002-08-05 03:17:25 by jwe]
jwe
parents: 4009
diff changeset
467 %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
468 %left EXPR_OR_OR
ef3caf27cb9c [project @ 2002-08-07 06:54:41 by jwe]
jwe
parents: 4018
diff changeset
469 %left EXPR_AND_AND
ef3caf27cb9c [project @ 2002-08-07 06:54:41 by jwe]
jwe
parents: 4018
diff changeset
470 %left EXPR_OR
ef3caf27cb9c [project @ 2002-08-07 06:54:41 by jwe]
jwe
parents: 4018
diff changeset
471 %left EXPR_AND
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
472 %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
473 %left LSHIFT RSHIFT
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
474 %left ':'
1276
cbdf7db98554 [project @ 1995-04-24 15:31:24 by jwe]
jwe
parents: 1266
diff changeset
475 %left '-' '+' EPLUS EMINUS
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
476 %left '*' '/' LEFTDIV EMUL EDIV ELEFTDIV
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
477 %left UNARY PLUS_PLUS MINUS_MINUS EXPR_NOT
5667
ec3ffbf9982b [project @ 2006-03-15 02:51:39 by jwe]
jwe
parents: 5626
diff changeset
478 %left POW EPOW QUOTE TRANSPOSE
3351
8623649c967c [project @ 1999-11-15 16:17:01 by jwe]
jwe
parents: 3347
diff changeset
479 %left '(' '.' '{'
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
480
143
7849db4b6dbc [project @ 1993-10-04 02:36:45 by jwe]
jwe
parents: 118
diff changeset
481 // Where to start.
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
482 %start input
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
483
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
484 %%
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
485
2970
b9e64477f703 [project @ 1997-05-15 18:04:21 by jwe]
jwe
parents: 2961
diff changeset
486 // ==============================
b9e64477f703 [project @ 1997-05-15 18:04:21 by jwe]
jwe
parents: 2961
diff changeset
487 // Statements and statement lists
b9e64477f703 [project @ 1997-05-15 18:04:21 by jwe]
jwe
parents: 2961
diff changeset
488 // ==============================
b9e64477f703 [project @ 1997-05-15 18:04:21 by jwe]
jwe
parents: 2961
diff changeset
489
627
739d16c30481 [project @ 1994-08-19 13:23:14 by jwe]
jwe
parents: 620
diff changeset
490 input : input1
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
491 {
627
739d16c30481 [project @ 1994-08-19 13:23:14 by jwe]
jwe
parents: 620
diff changeset
492 global_command = $1;
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
493 promptflag = 1;
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
494 YYACCEPT;
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
495 }
627
739d16c30481 [project @ 1994-08-19 13:23:14 by jwe]
jwe
parents: 620
diff changeset
496 | simple_list parse_error
1091
54abf1b3a8e9 [project @ 1995-02-02 00:30:14 by jwe]
jwe
parents: 1090
diff changeset
497 { ABORT_PARSE; }
627
739d16c30481 [project @ 1994-08-19 13:23:14 by jwe]
jwe
parents: 620
diff changeset
498 | parse_error
1091
54abf1b3a8e9 [project @ 1995-02-02 00:30:14 by jwe]
jwe
parents: 1090
diff changeset
499 { ABORT_PARSE; }
627
739d16c30481 [project @ 1994-08-19 13:23:14 by jwe]
jwe
parents: 620
diff changeset
500 ;
739d16c30481 [project @ 1994-08-19 13:23:14 by jwe]
jwe
parents: 620
diff changeset
501
739d16c30481 [project @ 1994-08-19 13:23:14 by jwe]
jwe
parents: 620
diff changeset
502 input1 : '\n'
739d16c30481 [project @ 1994-08-19 13:23:14 by jwe]
jwe
parents: 620
diff changeset
503 { $$ = 0; }
3883
69b6bd271277 [project @ 2002-04-02 21:05:10 by jwe]
jwe
parents: 3881
diff changeset
504 | END_OF_INPUT
69b6bd271277 [project @ 2002-04-02 21:05:10 by jwe]
jwe
parents: 3881
diff changeset
505 {
69b6bd271277 [project @ 2002-04-02 21:05:10 by jwe]
jwe
parents: 3881
diff changeset
506 parser_end_of_input = 1;
69b6bd271277 [project @ 2002-04-02 21:05:10 by jwe]
jwe
parents: 3881
diff changeset
507 $$ = 0;
69b6bd271277 [project @ 2002-04-02 21:05:10 by jwe]
jwe
parents: 3881
diff changeset
508 }
327
62ba7bbb62e3 [project @ 1994-02-04 04:01:59 by jwe]
jwe
parents: 315
diff changeset
509 | simple_list
627
739d16c30481 [project @ 1994-08-19 13:23:14 by jwe]
jwe
parents: 620
diff changeset
510 { $$ = $1; }
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
511 | simple_list '\n'
627
739d16c30481 [project @ 1994-08-19 13:23:14 by jwe]
jwe
parents: 620
diff changeset
512 { $$ = $1; }
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
513 | simple_list END_OF_INPUT
627
739d16c30481 [project @ 1994-08-19 13:23:14 by jwe]
jwe
parents: 620
diff changeset
514 { $$ = $1; }
739d16c30481 [project @ 1994-08-19 13:23:14 by jwe]
jwe
parents: 620
diff changeset
515 ;
739d16c30481 [project @ 1994-08-19 13:23:14 by jwe]
jwe
parents: 620
diff changeset
516
2525
8561d88be5f2 [project @ 1996-11-17 21:23:31 by jwe]
jwe
parents: 2524
diff changeset
517 simple_list : simple_list1 opt_sep_no_nl
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
518 { $$ = set_stmt_print_flag ($1, $2, false); }
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
519 ;
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
520
578
d169be9237fb [project @ 1994-08-03 20:06:54 by jwe]
jwe
parents: 572
diff changeset
521 simple_list1 : statement
8448
d6c0d5f208de parse.y: avoid storing null statements in statement lists
John W. Eaton <jwe@octave.org>
parents: 8447
diff changeset
522 { $$ = make_statement_list ($1); }
2525
8561d88be5f2 [project @ 1996-11-17 21:23:31 by jwe]
jwe
parents: 2524
diff changeset
523 | simple_list1 sep_no_nl statement
8448
d6c0d5f208de parse.y: avoid storing null statements in statement lists
John W. Eaton <jwe@octave.org>
parents: 8447
diff changeset
524 { $$ = append_statement_list ($1, $2, $3, false); }
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
525 ;
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
526
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
527 opt_list : // empty
578
d169be9237fb [project @ 1994-08-03 20:06:54 by jwe]
jwe
parents: 572
diff changeset
528 { $$ = new tree_statement_list (); }
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
529 | list
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
530 { $$ = $1; }
496
e7c5b23b34d3 [project @ 1994-07-06 15:02:26 by jwe]
jwe
parents: 482
diff changeset
531 ;
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
532
2525
8561d88be5f2 [project @ 1996-11-17 21:23:31 by jwe]
jwe
parents: 2524
diff changeset
533 list : list1 opt_sep
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
534 { $$ = set_stmt_print_flag ($1, $2, true); }
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
535 ;
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
536
578
d169be9237fb [project @ 1994-08-03 20:06:54 by jwe]
jwe
parents: 572
diff changeset
537 list1 : statement
8448
d6c0d5f208de parse.y: avoid storing null statements in statement lists
John W. Eaton <jwe@octave.org>
parents: 8447
diff changeset
538 { $$ = make_statement_list ($1); }
2525
8561d88be5f2 [project @ 1996-11-17 21:23:31 by jwe]
jwe
parents: 2524
diff changeset
539 | list1 sep statement
8448
d6c0d5f208de parse.y: avoid storing null statements in statement lists
John W. Eaton <jwe@octave.org>
parents: 8447
diff changeset
540 { $$ = append_statement_list ($1, $2, $3, true); }
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
541 ;
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
542
2970
b9e64477f703 [project @ 1997-05-15 18:04:21 by jwe]
jwe
parents: 2961
diff changeset
543 statement : expression
8448
d6c0d5f208de parse.y: avoid storing null statements in statement lists
John W. Eaton <jwe@octave.org>
parents: 8447
diff changeset
544 { $$ = make_statement ($1); }
2970
b9e64477f703 [project @ 1997-05-15 18:04:21 by jwe]
jwe
parents: 2961
diff changeset
545 | command
8448
d6c0d5f208de parse.y: avoid storing null statements in statement lists
John W. Eaton <jwe@octave.org>
parents: 8447
diff changeset
546 { $$ = make_statement ($1); }
8746
5dd06f19e9be handle commands in the lexer
John W. Eaton <jwe@octave.org>
parents: 8745
diff changeset
547 | word_list_cmd
5dd06f19e9be handle commands in the lexer
John W. Eaton <jwe@octave.org>
parents: 8745
diff changeset
548 { $$ = make_statement ($1); }
5dd06f19e9be handle commands in the lexer
John W. Eaton <jwe@octave.org>
parents: 8745
diff changeset
549 ;
5dd06f19e9be handle commands in the lexer
John W. Eaton <jwe@octave.org>
parents: 8745
diff changeset
550
5dd06f19e9be handle commands in the lexer
John W. Eaton <jwe@octave.org>
parents: 8745
diff changeset
551 // =================
5dd06f19e9be handle commands in the lexer
John W. Eaton <jwe@octave.org>
parents: 8745
diff changeset
552 // Word-list command
5dd06f19e9be handle commands in the lexer
John W. Eaton <jwe@octave.org>
parents: 8745
diff changeset
553 // =================
5dd06f19e9be handle commands in the lexer
John W. Eaton <jwe@octave.org>
parents: 8745
diff changeset
554
5dd06f19e9be handle commands in the lexer
John W. Eaton <jwe@octave.org>
parents: 8745
diff changeset
555 // 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
556 // 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
557 // WHILE, etc.
5dd06f19e9be handle commands in the lexer
John W. Eaton <jwe@octave.org>
parents: 8745
diff changeset
558
5dd06f19e9be handle commands in the lexer
John W. Eaton <jwe@octave.org>
parents: 8745
diff changeset
559 word_list_cmd : identifier word_list
5dd06f19e9be handle commands in the lexer
John W. Eaton <jwe@octave.org>
parents: 8745
diff changeset
560 { $$ = make_index_expression ($1, $2, '('); }
5dd06f19e9be handle commands in the lexer
John W. Eaton <jwe@octave.org>
parents: 8745
diff changeset
561 ;
5dd06f19e9be handle commands in the lexer
John W. Eaton <jwe@octave.org>
parents: 8745
diff changeset
562
5dd06f19e9be handle commands in the lexer
John W. Eaton <jwe@octave.org>
parents: 8745
diff changeset
563 word_list : string
5dd06f19e9be handle commands in the lexer
John W. Eaton <jwe@octave.org>
parents: 8745
diff changeset
564 { $$ = new tree_argument_list ($1); }
5dd06f19e9be handle commands in the lexer
John W. Eaton <jwe@octave.org>
parents: 8745
diff changeset
565 | word_list string
5dd06f19e9be handle commands in the lexer
John W. Eaton <jwe@octave.org>
parents: 8745
diff changeset
566 {
5dd06f19e9be handle commands in the lexer
John W. Eaton <jwe@octave.org>
parents: 8745
diff changeset
567 $1->append ($2);
5dd06f19e9be handle commands in the lexer
John W. Eaton <jwe@octave.org>
parents: 8745
diff changeset
568 $$ = $1;
5dd06f19e9be handle commands in the lexer
John W. Eaton <jwe@octave.org>
parents: 8745
diff changeset
569 }
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
570 ;
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
571
2970
b9e64477f703 [project @ 1997-05-15 18:04:21 by jwe]
jwe
parents: 2961
diff changeset
572 // ===========
b9e64477f703 [project @ 1997-05-15 18:04:21 by jwe]
jwe
parents: 2961
diff changeset
573 // Expressions
b9e64477f703 [project @ 1997-05-15 18:04:21 by jwe]
jwe
parents: 2961
diff changeset
574 // ===========
b9e64477f703 [project @ 1997-05-15 18:04:21 by jwe]
jwe
parents: 2961
diff changeset
575
b9e64477f703 [project @ 1997-05-15 18:04:21 by jwe]
jwe
parents: 2961
diff changeset
576 identifier : NAME
b9e64477f703 [project @ 1997-05-15 18:04:21 by jwe]
jwe
parents: 2961
diff changeset
577 {
7336
745a8299c2b5 [project @ 2007-12-28 20:56:55 by jwe]
jwe
parents: 7017
diff changeset
578 symbol_table::symbol_record *sr = $1->sym_rec ();
745a8299c2b5 [project @ 2007-12-28 20:56:55 by jwe]
jwe
parents: 7017
diff changeset
579 $$ = new tree_identifier (*sr, $1->line (), $1->column ());
2970
b9e64477f703 [project @ 1997-05-15 18:04:21 by jwe]
jwe
parents: 2961
diff changeset
580 }
b9e64477f703 [project @ 1997-05-15 18:04:21 by jwe]
jwe
parents: 2961
diff changeset
581 ;
b9e64477f703 [project @ 1997-05-15 18:04:21 by jwe]
jwe
parents: 2961
diff changeset
582
5279
bd32f770c09a [project @ 2005-04-12 21:55:31 by jwe]
jwe
parents: 5189
diff changeset
583 string : DQ_STRING
bd32f770c09a [project @ 2005-04-12 21:55:31 by jwe]
jwe
parents: 5189
diff changeset
584 { $$ = make_constant (DQ_STRING, $1); }
bd32f770c09a [project @ 2005-04-12 21:55:31 by jwe]
jwe
parents: 5189
diff changeset
585 | SQ_STRING
bd32f770c09a [project @ 2005-04-12 21:55:31 by jwe]
jwe
parents: 5189
diff changeset
586 { $$ = make_constant (SQ_STRING, $1); }
bd32f770c09a [project @ 2005-04-12 21:55:31 by jwe]
jwe
parents: 5189
diff changeset
587 ;
bd32f770c09a [project @ 2005-04-12 21:55:31 by jwe]
jwe
parents: 5189
diff changeset
588
2970
b9e64477f703 [project @ 1997-05-15 18:04:21 by jwe]
jwe
parents: 2961
diff changeset
589 constant : NUM
b9e64477f703 [project @ 1997-05-15 18:04:21 by jwe]
jwe
parents: 2961
diff changeset
590 { $$ = make_constant (NUM, $1); }
b9e64477f703 [project @ 1997-05-15 18:04:21 by jwe]
jwe
parents: 2961
diff changeset
591 | IMAG_NUM
b9e64477f703 [project @ 1997-05-15 18:04:21 by jwe]
jwe
parents: 2961
diff changeset
592 { $$ = make_constant (IMAG_NUM, $1); }
5279
bd32f770c09a [project @ 2005-04-12 21:55:31 by jwe]
jwe
parents: 5189
diff changeset
593 | string
bd32f770c09a [project @ 2005-04-12 21:55:31 by jwe]
jwe
parents: 5189
diff changeset
594 { $$ = $1; }
2970
b9e64477f703 [project @ 1997-05-15 18:04:21 by jwe]
jwe
parents: 2961
diff changeset
595 ;
b9e64477f703 [project @ 1997-05-15 18:04:21 by jwe]
jwe
parents: 2961
diff changeset
596
b9e64477f703 [project @ 1997-05-15 18:04:21 by jwe]
jwe
parents: 2961
diff changeset
597 matrix : '[' ']'
5615
d01f07aeaec5 [project @ 2006-02-10 21:30:41 by jwe]
jwe
parents: 5609
diff changeset
598 {
8150
283989f2da9b make null assignment matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents: 8064
diff changeset
599 $$ = new tree_constant (octave_null_matrix::instance);
5615
d01f07aeaec5 [project @ 2006-02-10 21:30:41 by jwe]
jwe
parents: 5609
diff changeset
600 lexer_flags.looking_at_matrix_or_assign_lhs = false;
8001
ff9e7873f8ea improve handling of command-style names in matrix_or_assign_lhs context
John W. Eaton <jwe@octave.org>
parents: 7968
diff changeset
601 lexer_flags.pending_local_variables.clear ();
5615
d01f07aeaec5 [project @ 2006-02-10 21:30:41 by jwe]
jwe
parents: 5609
diff changeset
602 }
2970
b9e64477f703 [project @ 1997-05-15 18:04:21 by jwe]
jwe
parents: 2961
diff changeset
603 | '[' ';' ']'
3203
bc61b0e8d60e [project @ 1998-10-30 20:26:27 by jwe]
jwe
parents: 3195
diff changeset
604 {
8150
283989f2da9b make null assignment matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents: 8064
diff changeset
605 $$ = new tree_constant (octave_null_matrix::instance);
283989f2da9b make null assignment matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents: 8064
diff changeset
606 lexer_flags.looking_at_matrix_or_assign_lhs = false;
283989f2da9b make null assignment matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents: 8064
diff changeset
607 lexer_flags.pending_local_variables.clear ();
283989f2da9b make null assignment matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents: 8064
diff changeset
608 }
283989f2da9b make null assignment matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents: 8064
diff changeset
609 | '[' ',' ']'
283989f2da9b make null assignment matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents: 8064
diff changeset
610 {
283989f2da9b make null assignment matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents: 8064
diff changeset
611 $$ = new tree_constant (octave_null_matrix::instance);
5615
d01f07aeaec5 [project @ 2006-02-10 21:30:41 by jwe]
jwe
parents: 5609
diff changeset
612 lexer_flags.looking_at_matrix_or_assign_lhs = false;
8001
ff9e7873f8ea improve handling of command-style names in matrix_or_assign_lhs context
John W. Eaton <jwe@octave.org>
parents: 7968
diff changeset
613 lexer_flags.pending_local_variables.clear ();
5615
d01f07aeaec5 [project @ 2006-02-10 21:30:41 by jwe]
jwe
parents: 5609
diff changeset
614 }
d01f07aeaec5 [project @ 2006-02-10 21:30:41 by jwe]
jwe
parents: 5609
diff changeset
615 | '[' matrix_rows ']'
d01f07aeaec5 [project @ 2006-02-10 21:30:41 by jwe]
jwe
parents: 5609
diff changeset
616 {
d01f07aeaec5 [project @ 2006-02-10 21:30:41 by jwe]
jwe
parents: 5609
diff changeset
617 $$ = finish_matrix ($2);
3203
bc61b0e8d60e [project @ 1998-10-30 20:26:27 by jwe]
jwe
parents: 3195
diff changeset
618 lexer_flags.looking_at_matrix_or_assign_lhs = false;
8001
ff9e7873f8ea improve handling of command-style names in matrix_or_assign_lhs context
John W. Eaton <jwe@octave.org>
parents: 7968
diff changeset
619 lexer_flags.pending_local_variables.clear ();
3203
bc61b0e8d60e [project @ 1998-10-30 20:26:27 by jwe]
jwe
parents: 3195
diff changeset
620 }
2970
b9e64477f703 [project @ 1997-05-15 18:04:21 by jwe]
jwe
parents: 2961
diff changeset
621 ;
b9e64477f703 [project @ 1997-05-15 18:04:21 by jwe]
jwe
parents: 2961
diff changeset
622
3351
8623649c967c [project @ 1999-11-15 16:17:01 by jwe]
jwe
parents: 3347
diff changeset
623 matrix_rows : matrix_rows1
2970
b9e64477f703 [project @ 1997-05-15 18:04:21 by jwe]
jwe
parents: 2961
diff changeset
624 { $$ = $1; }
3351
8623649c967c [project @ 1999-11-15 16:17:01 by jwe]
jwe
parents: 3347
diff changeset
625 | matrix_rows1 ';' // Ignore trailing semicolon.
2970
b9e64477f703 [project @ 1997-05-15 18:04:21 by jwe]
jwe
parents: 2961
diff changeset
626 { $$ = $1; }
b9e64477f703 [project @ 1997-05-15 18:04:21 by jwe]
jwe
parents: 2961
diff changeset
627 ;
b9e64477f703 [project @ 1997-05-15 18:04:21 by jwe]
jwe
parents: 2961
diff changeset
628
3351
8623649c967c [project @ 1999-11-15 16:17:01 by jwe]
jwe
parents: 3347
diff changeset
629 matrix_rows1 : cell_or_matrix_row
2970
b9e64477f703 [project @ 1997-05-15 18:04:21 by jwe]
jwe
parents: 2961
diff changeset
630 { $$ = new tree_matrix ($1); }
3351
8623649c967c [project @ 1999-11-15 16:17:01 by jwe]
jwe
parents: 3347
diff changeset
631 | matrix_rows1 ';' cell_or_matrix_row
2970
b9e64477f703 [project @ 1997-05-15 18:04:21 by jwe]
jwe
parents: 2961
diff changeset
632 {
b9e64477f703 [project @ 1997-05-15 18:04:21 by jwe]
jwe
parents: 2961
diff changeset
633 $1->append ($3);
b9e64477f703 [project @ 1997-05-15 18:04:21 by jwe]
jwe
parents: 2961
diff changeset
634 $$ = $1;
b9e64477f703 [project @ 1997-05-15 18:04:21 by jwe]
jwe
parents: 2961
diff changeset
635 }
b9e64477f703 [project @ 1997-05-15 18:04:21 by jwe]
jwe
parents: 2961
diff changeset
636 ;
b9e64477f703 [project @ 1997-05-15 18:04:21 by jwe]
jwe
parents: 2961
diff changeset
637
3351
8623649c967c [project @ 1999-11-15 16:17:01 by jwe]
jwe
parents: 3347
diff changeset
638 cell : '{' '}'
3928
e8627dc4bdf2 [project @ 2002-05-03 19:56:01 by jwe]
jwe
parents: 3903
diff changeset
639 { $$ = new tree_constant (octave_value (Cell ())); }
3351
8623649c967c [project @ 1999-11-15 16:17:01 by jwe]
jwe
parents: 3347
diff changeset
640 | '{' ';' '}'
3928
e8627dc4bdf2 [project @ 2002-05-03 19:56:01 by jwe]
jwe
parents: 3903
diff changeset
641 { $$ = new tree_constant (octave_value (Cell ())); }
3351
8623649c967c [project @ 1999-11-15 16:17:01 by jwe]
jwe
parents: 3347
diff changeset
642 | '{' cell_rows '}'
8623649c967c [project @ 1999-11-15 16:17:01 by jwe]
jwe
parents: 3347
diff changeset
643 { $$ = finish_cell ($2); }
8623649c967c [project @ 1999-11-15 16:17:01 by jwe]
jwe
parents: 3347
diff changeset
644 ;
8623649c967c [project @ 1999-11-15 16:17:01 by jwe]
jwe
parents: 3347
diff changeset
645
8623649c967c [project @ 1999-11-15 16:17:01 by jwe]
jwe
parents: 3347
diff changeset
646 cell_rows : cell_rows1
8623649c967c [project @ 1999-11-15 16:17:01 by jwe]
jwe
parents: 3347
diff changeset
647 { $$ = $1; }
8623649c967c [project @ 1999-11-15 16:17:01 by jwe]
jwe
parents: 3347
diff changeset
648 | cell_rows1 ';' // Ignore trailing semicolon.
8623649c967c [project @ 1999-11-15 16:17:01 by jwe]
jwe
parents: 3347
diff changeset
649 { $$ = $1; }
8623649c967c [project @ 1999-11-15 16:17:01 by jwe]
jwe
parents: 3347
diff changeset
650 ;
8623649c967c [project @ 1999-11-15 16:17:01 by jwe]
jwe
parents: 3347
diff changeset
651
8623649c967c [project @ 1999-11-15 16:17:01 by jwe]
jwe
parents: 3347
diff changeset
652 cell_rows1 : cell_or_matrix_row
8623649c967c [project @ 1999-11-15 16:17:01 by jwe]
jwe
parents: 3347
diff changeset
653 { $$ = new tree_cell ($1); }
8623649c967c [project @ 1999-11-15 16:17:01 by jwe]
jwe
parents: 3347
diff changeset
654 | cell_rows1 ';' cell_or_matrix_row
8623649c967c [project @ 1999-11-15 16:17:01 by jwe]
jwe
parents: 3347
diff changeset
655 {
8623649c967c [project @ 1999-11-15 16:17:01 by jwe]
jwe
parents: 3347
diff changeset
656 $1->append ($3);
8623649c967c [project @ 1999-11-15 16:17:01 by jwe]
jwe
parents: 3347
diff changeset
657 $$ = $1;
8623649c967c [project @ 1999-11-15 16:17:01 by jwe]
jwe
parents: 3347
diff changeset
658 }
8623649c967c [project @ 1999-11-15 16:17:01 by jwe]
jwe
parents: 3347
diff changeset
659 ;
8623649c967c [project @ 1999-11-15 16:17:01 by jwe]
jwe
parents: 3347
diff changeset
660
8623649c967c [project @ 1999-11-15 16:17:01 by jwe]
jwe
parents: 3347
diff changeset
661 cell_or_matrix_row
8623649c967c [project @ 1999-11-15 16:17:01 by jwe]
jwe
parents: 3347
diff changeset
662 : arg_list
2970
b9e64477f703 [project @ 1997-05-15 18:04:21 by jwe]
jwe
parents: 2961
diff changeset
663 { $$ = $1; }
b9e64477f703 [project @ 1997-05-15 18:04:21 by jwe]
jwe
parents: 2961
diff changeset
664 | arg_list ',' // Ignore trailing comma.
b9e64477f703 [project @ 1997-05-15 18:04:21 by jwe]
jwe
parents: 2961
diff changeset
665 { $$ = $1; }
b9e64477f703 [project @ 1997-05-15 18:04:21 by jwe]
jwe
parents: 2961
diff changeset
666 ;
b9e64477f703 [project @ 1997-05-15 18:04:21 by jwe]
jwe
parents: 2961
diff changeset
667
4930
bdb307dc8613 [project @ 2004-08-05 04:55:26 by jwe]
jwe
parents: 4872
diff changeset
668 fcn_handle : '@' FCN_HANDLE
bdb307dc8613 [project @ 2004-08-05 04:55:26 by jwe]
jwe
parents: 4872
diff changeset
669 {
bdb307dc8613 [project @ 2004-08-05 04:55:26 by jwe]
jwe
parents: 4872
diff changeset
670 $$ = make_fcn_handle ($2);
bdb307dc8613 [project @ 2004-08-05 04:55:26 by jwe]
jwe
parents: 4872
diff changeset
671 lexer_flags.looking_at_function_handle--;
bdb307dc8613 [project @ 2004-08-05 04:55:26 by jwe]
jwe
parents: 4872
diff changeset
672 }
bdb307dc8613 [project @ 2004-08-05 04:55:26 by jwe]
jwe
parents: 4872
diff changeset
673 ;
bdb307dc8613 [project @ 2004-08-05 04:55:26 by jwe]
jwe
parents: 4872
diff changeset
674
4935
4fc993a4e072 [project @ 2004-08-06 03:17:12 by jwe]
jwe
parents: 4930
diff changeset
675 anon_fcn_handle : '@' param_list statement
4fc993a4e072 [project @ 2004-08-06 03:17:12 by jwe]
jwe
parents: 4930
diff changeset
676 { $$ = make_anon_fcn_handle ($2, $3); }
4342
813effe14ee1 [project @ 2003-02-20 08:35:55 by jwe]
jwe
parents: 4318
diff changeset
677 ;
813effe14ee1 [project @ 2003-02-20 08:35:55 by jwe]
jwe
parents: 4318
diff changeset
678
2970
b9e64477f703 [project @ 1997-05-15 18:04:21 by jwe]
jwe
parents: 2961
diff changeset
679 primary_expr : identifier
b9e64477f703 [project @ 1997-05-15 18:04:21 by jwe]
jwe
parents: 2961
diff changeset
680 { $$ = $1; }
b9e64477f703 [project @ 1997-05-15 18:04:21 by jwe]
jwe
parents: 2961
diff changeset
681 | constant
b9e64477f703 [project @ 1997-05-15 18:04:21 by jwe]
jwe
parents: 2961
diff changeset
682 { $$ = $1; }
4342
813effe14ee1 [project @ 2003-02-20 08:35:55 by jwe]
jwe
parents: 4318
diff changeset
683 | fcn_handle
813effe14ee1 [project @ 2003-02-20 08:35:55 by jwe]
jwe
parents: 4318
diff changeset
684 { $$ = $1; }
2970
b9e64477f703 [project @ 1997-05-15 18:04:21 by jwe]
jwe
parents: 2961
diff changeset
685 | matrix
b9e64477f703 [project @ 1997-05-15 18:04:21 by jwe]
jwe
parents: 2961
diff changeset
686 { $$ = $1; }
3351
8623649c967c [project @ 1999-11-15 16:17:01 by jwe]
jwe
parents: 3347
diff changeset
687 | cell
8623649c967c [project @ 1999-11-15 16:17:01 by jwe]
jwe
parents: 3347
diff changeset
688 { $$ = $1; }
2970
b9e64477f703 [project @ 1997-05-15 18:04:21 by jwe]
jwe
parents: 2961
diff changeset
689 | '(' expression ')'
b9e64477f703 [project @ 1997-05-15 18:04:21 by jwe]
jwe
parents: 2961
diff changeset
690 { $$ = $2->mark_in_parens (); }
b9e64477f703 [project @ 1997-05-15 18:04:21 by jwe]
jwe
parents: 2961
diff changeset
691 ;
b9e64477f703 [project @ 1997-05-15 18:04:21 by jwe]
jwe
parents: 2961
diff changeset
692
b9e64477f703 [project @ 1997-05-15 18:04:21 by jwe]
jwe
parents: 2961
diff changeset
693 magic_colon : ':'
b9e64477f703 [project @ 1997-05-15 18:04:21 by jwe]
jwe
parents: 2961
diff changeset
694 {
b9e64477f703 [project @ 1997-05-15 18:04:21 by jwe]
jwe
parents: 2961
diff changeset
695 octave_value tmp (octave_value::magic_colon_t);
b9e64477f703 [project @ 1997-05-15 18:04:21 by jwe]
jwe
parents: 2961
diff changeset
696 $$ = new tree_constant (tmp);
b9e64477f703 [project @ 1997-05-15 18:04:21 by jwe]
jwe
parents: 2961
diff changeset
697 }
b9e64477f703 [project @ 1997-05-15 18:04:21 by jwe]
jwe
parents: 2961
diff changeset
698 ;
b9e64477f703 [project @ 1997-05-15 18:04:21 by jwe]
jwe
parents: 2961
diff changeset
699
b9e64477f703 [project @ 1997-05-15 18:04:21 by jwe]
jwe
parents: 2961
diff changeset
700 arg_list : expression
b9e64477f703 [project @ 1997-05-15 18:04:21 by jwe]
jwe
parents: 2961
diff changeset
701 { $$ = new tree_argument_list ($1); }
b9e64477f703 [project @ 1997-05-15 18:04:21 by jwe]
jwe
parents: 2961
diff changeset
702 | magic_colon
b9e64477f703 [project @ 1997-05-15 18:04:21 by jwe]
jwe
parents: 2961
diff changeset
703 { $$ = new tree_argument_list ($1); }
b9e64477f703 [project @ 1997-05-15 18:04:21 by jwe]
jwe
parents: 2961
diff changeset
704 | arg_list ',' magic_colon
b9e64477f703 [project @ 1997-05-15 18:04:21 by jwe]
jwe
parents: 2961
diff changeset
705 {
b9e64477f703 [project @ 1997-05-15 18:04:21 by jwe]
jwe
parents: 2961
diff changeset
706 $1->append ($3);
b9e64477f703 [project @ 1997-05-15 18:04:21 by jwe]
jwe
parents: 2961
diff changeset
707 $$ = $1;
b9e64477f703 [project @ 1997-05-15 18:04:21 by jwe]
jwe
parents: 2961
diff changeset
708 }
b9e64477f703 [project @ 1997-05-15 18:04:21 by jwe]
jwe
parents: 2961
diff changeset
709 | arg_list ',' expression
b9e64477f703 [project @ 1997-05-15 18:04:21 by jwe]
jwe
parents: 2961
diff changeset
710 {
b9e64477f703 [project @ 1997-05-15 18:04:21 by jwe]
jwe
parents: 2961
diff changeset
711 $1->append ($3);
b9e64477f703 [project @ 1997-05-15 18:04:21 by jwe]
jwe
parents: 2961
diff changeset
712 $$ = $1;
b9e64477f703 [project @ 1997-05-15 18:04:21 by jwe]
jwe
parents: 2961
diff changeset
713 }
b9e64477f703 [project @ 1997-05-15 18:04:21 by jwe]
jwe
parents: 2961
diff changeset
714 ;
b9e64477f703 [project @ 1997-05-15 18:04:21 by jwe]
jwe
parents: 2961
diff changeset
715
4131
597fbc55ea40 [project @ 2002-10-29 17:12:53 by jwe]
jwe
parents: 4064
diff changeset
716 indirect_ref_op : '.'
2970
b9e64477f703 [project @ 1997-05-15 18:04:21 by jwe]
jwe
parents: 2961
diff changeset
717 { lexer_flags.looking_at_indirect_ref = true; }
b9e64477f703 [project @ 1997-05-15 18:04:21 by jwe]
jwe
parents: 2961
diff changeset
718 ;
b9e64477f703 [project @ 1997-05-15 18:04:21 by jwe]
jwe
parents: 2961
diff changeset
719
b9e64477f703 [project @ 1997-05-15 18:04:21 by jwe]
jwe
parents: 2961
diff changeset
720 postfix_expr : primary_expr
b9e64477f703 [project @ 1997-05-15 18:04:21 by jwe]
jwe
parents: 2961
diff changeset
721 { $$ = $1; }
8745
6dc61981d18b better handling of object indexing in lexer
John W. Eaton <jwe@octave.org>
parents: 8701
diff changeset
722 | postfix_expr '(' ')'
6dc61981d18b better handling of object indexing in lexer
John W. Eaton <jwe@octave.org>
parents: 8701
diff changeset
723 { $$ = make_index_expression ($1, 0, '('); }
6dc61981d18b better handling of object indexing in lexer
John W. Eaton <jwe@octave.org>
parents: 8701
diff changeset
724 | postfix_expr '(' arg_list ')'
6dc61981d18b better handling of object indexing in lexer
John W. Eaton <jwe@octave.org>
parents: 8701
diff changeset
725 { $$ = make_index_expression ($1, $3, '('); }
6dc61981d18b better handling of object indexing in lexer
John W. Eaton <jwe@octave.org>
parents: 8701
diff changeset
726 | postfix_expr '{' '}'
6dc61981d18b better handling of object indexing in lexer
John W. Eaton <jwe@octave.org>
parents: 8701
diff changeset
727 { $$ = make_index_expression ($1, 0, '{'); }
6dc61981d18b better handling of object indexing in lexer
John W. Eaton <jwe@octave.org>
parents: 8701
diff changeset
728 | postfix_expr '{' arg_list '}'
6dc61981d18b better handling of object indexing in lexer
John W. Eaton <jwe@octave.org>
parents: 8701
diff changeset
729 { $$ = make_index_expression ($1, $3, '{'); }
6dc61981d18b better handling of object indexing in lexer
John W. Eaton <jwe@octave.org>
parents: 8701
diff changeset
730 | postfix_expr PLUS_PLUS
6dc61981d18b better handling of object indexing in lexer
John W. Eaton <jwe@octave.org>
parents: 8701
diff changeset
731 { $$ = make_postfix_op (PLUS_PLUS, $1, $2); }
6dc61981d18b better handling of object indexing in lexer
John W. Eaton <jwe@octave.org>
parents: 8701
diff changeset
732 | postfix_expr MINUS_MINUS
6dc61981d18b better handling of object indexing in lexer
John W. Eaton <jwe@octave.org>
parents: 8701
diff changeset
733 { $$ = make_postfix_op (MINUS_MINUS, $1, $2); }
6dc61981d18b better handling of object indexing in lexer
John W. Eaton <jwe@octave.org>
parents: 8701
diff changeset
734 | postfix_expr QUOTE
6dc61981d18b better handling of object indexing in lexer
John W. Eaton <jwe@octave.org>
parents: 8701
diff changeset
735 { $$ = make_postfix_op (QUOTE, $1, $2); }
6dc61981d18b better handling of object indexing in lexer
John W. Eaton <jwe@octave.org>
parents: 8701
diff changeset
736 | postfix_expr TRANSPOSE
6dc61981d18b better handling of object indexing in lexer
John W. Eaton <jwe@octave.org>
parents: 8701
diff changeset
737 { $$ = make_postfix_op (TRANSPOSE, $1, $2); }
6dc61981d18b better handling of object indexing in lexer
John W. Eaton <jwe@octave.org>
parents: 8701
diff changeset
738 | postfix_expr indirect_ref_op STRUCT_ELT
6dc61981d18b better handling of object indexing in lexer
John W. Eaton <jwe@octave.org>
parents: 8701
diff changeset
739 { $$ = make_indirect_ref ($1, $3->text ()); }
6dc61981d18b better handling of object indexing in lexer
John W. Eaton <jwe@octave.org>
parents: 8701
diff changeset
740 | postfix_expr indirect_ref_op '(' expression ')'
6dc61981d18b better handling of object indexing in lexer
John W. Eaton <jwe@octave.org>
parents: 8701
diff changeset
741 { $$ = make_indirect_ref ($1, $4); }
2970
b9e64477f703 [project @ 1997-05-15 18:04:21 by jwe]
jwe
parents: 2961
diff changeset
742 ;
b9e64477f703 [project @ 1997-05-15 18:04:21 by jwe]
jwe
parents: 2961
diff changeset
743
8745
6dc61981d18b better handling of object indexing in lexer
John W. Eaton <jwe@octave.org>
parents: 8701
diff changeset
744 prefix_expr : postfix_expr
2970
b9e64477f703 [project @ 1997-05-15 18:04:21 by jwe]
jwe
parents: 2961
diff changeset
745 { $$ = $1; }
3178
09a3064a3a17 [project @ 1998-06-23 03:46:42 by jwe]
jwe
parents: 3165
diff changeset
746 | binary_expr
09a3064a3a17 [project @ 1998-06-23 03:46:42 by jwe]
jwe
parents: 3165
diff changeset
747 { $$ = $1; }
2970
b9e64477f703 [project @ 1997-05-15 18:04:21 by jwe]
jwe
parents: 2961
diff changeset
748 | PLUS_PLUS prefix_expr %prec UNARY
b9e64477f703 [project @ 1997-05-15 18:04:21 by jwe]
jwe
parents: 2961
diff changeset
749 { $$ = make_prefix_op (PLUS_PLUS, $2, $1); }
b9e64477f703 [project @ 1997-05-15 18:04:21 by jwe]
jwe
parents: 2961
diff changeset
750 | MINUS_MINUS prefix_expr %prec UNARY
b9e64477f703 [project @ 1997-05-15 18:04:21 by jwe]
jwe
parents: 2961
diff changeset
751 { $$ = make_prefix_op (MINUS_MINUS, $2, $1); }
b9e64477f703 [project @ 1997-05-15 18:04:21 by jwe]
jwe
parents: 2961
diff changeset
752 | EXPR_NOT prefix_expr %prec UNARY
b9e64477f703 [project @ 1997-05-15 18:04:21 by jwe]
jwe
parents: 2961
diff changeset
753 { $$ = make_prefix_op (EXPR_NOT, $2, $1); }
b9e64477f703 [project @ 1997-05-15 18:04:21 by jwe]
jwe
parents: 2961
diff changeset
754 | '+' prefix_expr %prec UNARY
4965
c0d8e8afa82f [project @ 2004-09-06 20:19:57 by jwe]
jwe
parents: 4935
diff changeset
755 { $$ = make_prefix_op ('+', $2, $1); }
2970
b9e64477f703 [project @ 1997-05-15 18:04:21 by jwe]
jwe
parents: 2961
diff changeset
756 | '-' prefix_expr %prec UNARY
b9e64477f703 [project @ 1997-05-15 18:04:21 by jwe]
jwe
parents: 2961
diff changeset
757 { $$ = make_prefix_op ('-', $2, $1); }
b9e64477f703 [project @ 1997-05-15 18:04:21 by jwe]
jwe
parents: 2961
diff changeset
758 ;
b9e64477f703 [project @ 1997-05-15 18:04:21 by jwe]
jwe
parents: 2961
diff changeset
759
3178
09a3064a3a17 [project @ 1998-06-23 03:46:42 by jwe]
jwe
parents: 3165
diff changeset
760 binary_expr : prefix_expr POW prefix_expr
2970
b9e64477f703 [project @ 1997-05-15 18:04:21 by jwe]
jwe
parents: 2961
diff changeset
761 { $$ = make_binary_op (POW, $1, $2, $3); }
3178
09a3064a3a17 [project @ 1998-06-23 03:46:42 by jwe]
jwe
parents: 3165
diff changeset
762 | prefix_expr EPOW prefix_expr
2970
b9e64477f703 [project @ 1997-05-15 18:04:21 by jwe]
jwe
parents: 2961
diff changeset
763 { $$ = make_binary_op (EPOW, $1, $2, $3); }
3178
09a3064a3a17 [project @ 1998-06-23 03:46:42 by jwe]
jwe
parents: 3165
diff changeset
764 | prefix_expr '+' prefix_expr
2970
b9e64477f703 [project @ 1997-05-15 18:04:21 by jwe]
jwe
parents: 2961
diff changeset
765 { $$ = make_binary_op ('+', $1, $2, $3); }
3178
09a3064a3a17 [project @ 1998-06-23 03:46:42 by jwe]
jwe
parents: 3165
diff changeset
766 | prefix_expr '-' prefix_expr
2970
b9e64477f703 [project @ 1997-05-15 18:04:21 by jwe]
jwe
parents: 2961
diff changeset
767 { $$ = make_binary_op ('-', $1, $2, $3); }
3178
09a3064a3a17 [project @ 1998-06-23 03:46:42 by jwe]
jwe
parents: 3165
diff changeset
768 | prefix_expr '*' prefix_expr
2970
b9e64477f703 [project @ 1997-05-15 18:04:21 by jwe]
jwe
parents: 2961
diff changeset
769 { $$ = make_binary_op ('*', $1, $2, $3); }
3178
09a3064a3a17 [project @ 1998-06-23 03:46:42 by jwe]
jwe
parents: 3165
diff changeset
770 | prefix_expr '/' prefix_expr
2970
b9e64477f703 [project @ 1997-05-15 18:04:21 by jwe]
jwe
parents: 2961
diff changeset
771 { $$ = make_binary_op ('/', $1, $2, $3); }
3178
09a3064a3a17 [project @ 1998-06-23 03:46:42 by jwe]
jwe
parents: 3165
diff changeset
772 | prefix_expr EPLUS prefix_expr
2970
b9e64477f703 [project @ 1997-05-15 18:04:21 by jwe]
jwe
parents: 2961
diff changeset
773 { $$ = make_binary_op ('+', $1, $2, $3); }
3178
09a3064a3a17 [project @ 1998-06-23 03:46:42 by jwe]
jwe
parents: 3165
diff changeset
774 | prefix_expr EMINUS prefix_expr
2970
b9e64477f703 [project @ 1997-05-15 18:04:21 by jwe]
jwe
parents: 2961
diff changeset
775 { $$ = make_binary_op ('-', $1, $2, $3); }
3178
09a3064a3a17 [project @ 1998-06-23 03:46:42 by jwe]
jwe
parents: 3165
diff changeset
776 | prefix_expr EMUL prefix_expr
2970
b9e64477f703 [project @ 1997-05-15 18:04:21 by jwe]
jwe
parents: 2961
diff changeset
777 { $$ = make_binary_op (EMUL, $1, $2, $3); }
3178
09a3064a3a17 [project @ 1998-06-23 03:46:42 by jwe]
jwe
parents: 3165
diff changeset
778 | prefix_expr EDIV prefix_expr
2970
b9e64477f703 [project @ 1997-05-15 18:04:21 by jwe]
jwe
parents: 2961
diff changeset
779 { $$ = make_binary_op (EDIV, $1, $2, $3); }
3178
09a3064a3a17 [project @ 1998-06-23 03:46:42 by jwe]
jwe
parents: 3165
diff changeset
780 | prefix_expr LEFTDIV prefix_expr
2970
b9e64477f703 [project @ 1997-05-15 18:04:21 by jwe]
jwe
parents: 2961
diff changeset
781 { $$ = make_binary_op (LEFTDIV, $1, $2, $3); }
3178
09a3064a3a17 [project @ 1998-06-23 03:46:42 by jwe]
jwe
parents: 3165
diff changeset
782 | prefix_expr ELEFTDIV prefix_expr
2970
b9e64477f703 [project @ 1997-05-15 18:04:21 by jwe]
jwe
parents: 2961
diff changeset
783 { $$ = make_binary_op (ELEFTDIV, $1, $2, $3); }
b9e64477f703 [project @ 1997-05-15 18:04:21 by jwe]
jwe
parents: 2961
diff changeset
784 ;
b9e64477f703 [project @ 1997-05-15 18:04:21 by jwe]
jwe
parents: 2961
diff changeset
785
b9e64477f703 [project @ 1997-05-15 18:04:21 by jwe]
jwe
parents: 2961
diff changeset
786 colon_expr : colon_expr1
b9e64477f703 [project @ 1997-05-15 18:04:21 by jwe]
jwe
parents: 2961
diff changeset
787 { $$ = finish_colon_expression ($1); }
b9e64477f703 [project @ 1997-05-15 18:04:21 by jwe]
jwe
parents: 2961
diff changeset
788 ;
b9e64477f703 [project @ 1997-05-15 18:04:21 by jwe]
jwe
parents: 2961
diff changeset
789
3178
09a3064a3a17 [project @ 1998-06-23 03:46:42 by jwe]
jwe
parents: 3165
diff changeset
790 colon_expr1 : prefix_expr
2970
b9e64477f703 [project @ 1997-05-15 18:04:21 by jwe]
jwe
parents: 2961
diff changeset
791 { $$ = new tree_colon_expression ($1); }
3178
09a3064a3a17 [project @ 1998-06-23 03:46:42 by jwe]
jwe
parents: 3165
diff changeset
792 | colon_expr1 ':' prefix_expr
2970
b9e64477f703 [project @ 1997-05-15 18:04:21 by jwe]
jwe
parents: 2961
diff changeset
793 {
b9e64477f703 [project @ 1997-05-15 18:04:21 by jwe]
jwe
parents: 2961
diff changeset
794 if (! ($$ = $1->append ($3)))
b9e64477f703 [project @ 1997-05-15 18:04:21 by jwe]
jwe
parents: 2961
diff changeset
795 ABORT_PARSE;
b9e64477f703 [project @ 1997-05-15 18:04:21 by jwe]
jwe
parents: 2961
diff changeset
796 }
b9e64477f703 [project @ 1997-05-15 18:04:21 by jwe]
jwe
parents: 2961
diff changeset
797 ;
b9e64477f703 [project @ 1997-05-15 18:04:21 by jwe]
jwe
parents: 2961
diff changeset
798
b9e64477f703 [project @ 1997-05-15 18:04:21 by jwe]
jwe
parents: 2961
diff changeset
799 simple_expr : colon_expr
b9e64477f703 [project @ 1997-05-15 18:04:21 by jwe]
jwe
parents: 2961
diff changeset
800 { $$ = $1; }
b9e64477f703 [project @ 1997-05-15 18:04:21 by jwe]
jwe
parents: 2961
diff changeset
801 | simple_expr LSHIFT simple_expr
b9e64477f703 [project @ 1997-05-15 18:04:21 by jwe]
jwe
parents: 2961
diff changeset
802 { $$ = make_binary_op (LSHIFT, $1, $2, $3); }
b9e64477f703 [project @ 1997-05-15 18:04:21 by jwe]
jwe
parents: 2961
diff changeset
803 | simple_expr RSHIFT simple_expr
b9e64477f703 [project @ 1997-05-15 18:04:21 by jwe]
jwe
parents: 2961
diff changeset
804 { $$ = make_binary_op (RSHIFT, $1, $2, $3); }
b9e64477f703 [project @ 1997-05-15 18:04:21 by jwe]
jwe
parents: 2961
diff changeset
805 | simple_expr EXPR_LT simple_expr
b9e64477f703 [project @ 1997-05-15 18:04:21 by jwe]
jwe
parents: 2961
diff changeset
806 { $$ = make_binary_op (EXPR_LT, $1, $2, $3); }
b9e64477f703 [project @ 1997-05-15 18:04:21 by jwe]
jwe
parents: 2961
diff changeset
807 | simple_expr EXPR_LE simple_expr
b9e64477f703 [project @ 1997-05-15 18:04:21 by jwe]
jwe
parents: 2961
diff changeset
808 { $$ = make_binary_op (EXPR_LE, $1, $2, $3); }
b9e64477f703 [project @ 1997-05-15 18:04:21 by jwe]
jwe
parents: 2961
diff changeset
809 | simple_expr EXPR_EQ simple_expr
b9e64477f703 [project @ 1997-05-15 18:04:21 by jwe]
jwe
parents: 2961
diff changeset
810 { $$ = make_binary_op (EXPR_EQ, $1, $2, $3); }
b9e64477f703 [project @ 1997-05-15 18:04:21 by jwe]
jwe
parents: 2961
diff changeset
811 | simple_expr EXPR_GE simple_expr
b9e64477f703 [project @ 1997-05-15 18:04:21 by jwe]
jwe
parents: 2961
diff changeset
812 { $$ = make_binary_op (EXPR_GE, $1, $2, $3); }
b9e64477f703 [project @ 1997-05-15 18:04:21 by jwe]
jwe
parents: 2961
diff changeset
813 | simple_expr EXPR_GT simple_expr
b9e64477f703 [project @ 1997-05-15 18:04:21 by jwe]
jwe
parents: 2961
diff changeset
814 { $$ = make_binary_op (EXPR_GT, $1, $2, $3); }
b9e64477f703 [project @ 1997-05-15 18:04:21 by jwe]
jwe
parents: 2961
diff changeset
815 | simple_expr EXPR_NE simple_expr
b9e64477f703 [project @ 1997-05-15 18:04:21 by jwe]
jwe
parents: 2961
diff changeset
816 { $$ = make_binary_op (EXPR_NE, $1, $2, $3); }
b9e64477f703 [project @ 1997-05-15 18:04:21 by jwe]
jwe
parents: 2961
diff changeset
817 | simple_expr EXPR_AND simple_expr
b9e64477f703 [project @ 1997-05-15 18:04:21 by jwe]
jwe
parents: 2961
diff changeset
818 { $$ = make_binary_op (EXPR_AND, $1, $2, $3); }
b9e64477f703 [project @ 1997-05-15 18:04:21 by jwe]
jwe
parents: 2961
diff changeset
819 | simple_expr EXPR_OR simple_expr
b9e64477f703 [project @ 1997-05-15 18:04:21 by jwe]
jwe
parents: 2961
diff changeset
820 { $$ = make_binary_op (EXPR_OR, $1, $2, $3); }
b9e64477f703 [project @ 1997-05-15 18:04:21 by jwe]
jwe
parents: 2961
diff changeset
821 | simple_expr EXPR_AND_AND simple_expr
b9e64477f703 [project @ 1997-05-15 18:04:21 by jwe]
jwe
parents: 2961
diff changeset
822 { $$ = make_boolean_op (EXPR_AND_AND, $1, $2, $3); }
b9e64477f703 [project @ 1997-05-15 18:04:21 by jwe]
jwe
parents: 2961
diff changeset
823 | simple_expr EXPR_OR_OR simple_expr
b9e64477f703 [project @ 1997-05-15 18:04:21 by jwe]
jwe
parents: 2961
diff changeset
824 { $$ = make_boolean_op (EXPR_OR_OR, $1, $2, $3); }
b9e64477f703 [project @ 1997-05-15 18:04:21 by jwe]
jwe
parents: 2961
diff changeset
825 ;
b9e64477f703 [project @ 1997-05-15 18:04:21 by jwe]
jwe
parents: 2961
diff changeset
826
b9e64477f703 [project @ 1997-05-15 18:04:21 by jwe]
jwe
parents: 2961
diff changeset
827 // Arrange for the lexer to return CLOSE_BRACE for `]' by looking ahead
b9e64477f703 [project @ 1997-05-15 18:04:21 by jwe]
jwe
parents: 2961
diff changeset
828 // one token for an assignment op.
b9e64477f703 [project @ 1997-05-15 18:04:21 by jwe]
jwe
parents: 2961
diff changeset
829
b9e64477f703 [project @ 1997-05-15 18:04:21 by jwe]
jwe
parents: 2961
diff changeset
830 assign_lhs : simple_expr
5841
fb4dea2184bf [project @ 2006-06-05 20:59:25 by jwe]
jwe
parents: 5832
diff changeset
831 {
fb4dea2184bf [project @ 2006-06-05 20:59:25 by jwe]
jwe
parents: 5832
diff changeset
832 $$ = new tree_argument_list ($1);
fb4dea2184bf [project @ 2006-06-05 20:59:25 by jwe]
jwe
parents: 5832
diff changeset
833 $$->mark_as_simple_assign_lhs ();
fb4dea2184bf [project @ 2006-06-05 20:59:25 by jwe]
jwe
parents: 5832
diff changeset
834 }
5615
d01f07aeaec5 [project @ 2006-02-10 21:30:41 by jwe]
jwe
parents: 5609
diff changeset
835 | '[' arg_list CLOSE_BRACE
3189
bef7b73c0724 [project @ 1998-10-16 18:05:26 by jwe]
jwe
parents: 3180
diff changeset
836 {
5615
d01f07aeaec5 [project @ 2006-02-10 21:30:41 by jwe]
jwe
parents: 5609
diff changeset
837 $$ = $2;
3189
bef7b73c0724 [project @ 1998-10-16 18:05:26 by jwe]
jwe
parents: 3180
diff changeset
838 lexer_flags.looking_at_matrix_or_assign_lhs = false;
8001
ff9e7873f8ea improve handling of command-style names in matrix_or_assign_lhs context
John W. Eaton <jwe@octave.org>
parents: 7968
diff changeset
839 for (std::set<std::string>::const_iterator p = lexer_flags.pending_local_variables.begin ();
ff9e7873f8ea improve handling of command-style names in matrix_or_assign_lhs context
John W. Eaton <jwe@octave.org>
parents: 7968
diff changeset
840 p != lexer_flags.pending_local_variables.end ();
ff9e7873f8ea improve handling of command-style names in matrix_or_assign_lhs context
John W. Eaton <jwe@octave.org>
parents: 7968
diff changeset
841 p++)
ff9e7873f8ea improve handling of command-style names in matrix_or_assign_lhs context
John W. Eaton <jwe@octave.org>
parents: 7968
diff changeset
842 {
ff9e7873f8ea improve handling of command-style names in matrix_or_assign_lhs context
John W. Eaton <jwe@octave.org>
parents: 7968
diff changeset
843 force_local_variable (*p);
ff9e7873f8ea improve handling of command-style names in matrix_or_assign_lhs context
John W. Eaton <jwe@octave.org>
parents: 7968
diff changeset
844 }
ff9e7873f8ea improve handling of command-style names in matrix_or_assign_lhs context
John W. Eaton <jwe@octave.org>
parents: 7968
diff changeset
845 lexer_flags.pending_local_variables.clear ();
3189
bef7b73c0724 [project @ 1998-10-16 18:05:26 by jwe]
jwe
parents: 3180
diff changeset
846 }
2970
b9e64477f703 [project @ 1997-05-15 18:04:21 by jwe]
jwe
parents: 2961
diff changeset
847 ;
b9e64477f703 [project @ 1997-05-15 18:04:21 by jwe]
jwe
parents: 2961
diff changeset
848
b9e64477f703 [project @ 1997-05-15 18:04:21 by jwe]
jwe
parents: 2961
diff changeset
849 assign_expr : assign_lhs '=' expression
b9e64477f703 [project @ 1997-05-15 18:04:21 by jwe]
jwe
parents: 2961
diff changeset
850 { $$ = make_assign_op ('=', $1, $2, $3); }
b9e64477f703 [project @ 1997-05-15 18:04:21 by jwe]
jwe
parents: 2961
diff changeset
851 | assign_lhs ADD_EQ expression
b9e64477f703 [project @ 1997-05-15 18:04:21 by jwe]
jwe
parents: 2961
diff changeset
852 { $$ = make_assign_op (ADD_EQ, $1, $2, $3); }
b9e64477f703 [project @ 1997-05-15 18:04:21 by jwe]
jwe
parents: 2961
diff changeset
853 | assign_lhs SUB_EQ expression
b9e64477f703 [project @ 1997-05-15 18:04:21 by jwe]
jwe
parents: 2961
diff changeset
854 { $$ = make_assign_op (SUB_EQ, $1, $2, $3); }
b9e64477f703 [project @ 1997-05-15 18:04:21 by jwe]
jwe
parents: 2961
diff changeset
855 | assign_lhs MUL_EQ expression
b9e64477f703 [project @ 1997-05-15 18:04:21 by jwe]
jwe
parents: 2961
diff changeset
856 { $$ = make_assign_op (MUL_EQ, $1, $2, $3); }
b9e64477f703 [project @ 1997-05-15 18:04:21 by jwe]
jwe
parents: 2961
diff changeset
857 | assign_lhs DIV_EQ expression
b9e64477f703 [project @ 1997-05-15 18:04:21 by jwe]
jwe
parents: 2961
diff changeset
858 { $$ = make_assign_op (DIV_EQ, $1, $2, $3); }
3204
81738e630f57 [project @ 1998-10-30 23:28:29 by jwe]
jwe
parents: 3203
diff changeset
859 | assign_lhs LEFTDIV_EQ expression
81738e630f57 [project @ 1998-10-30 23:28:29 by jwe]
jwe
parents: 3203
diff changeset
860 { $$ = make_assign_op (LEFTDIV_EQ, $1, $2, $3); }
4018
a8621d87fbf5 [project @ 2002-08-05 03:17:25 by jwe]
jwe
parents: 4009
diff changeset
861 | assign_lhs POW_EQ expression
a8621d87fbf5 [project @ 2002-08-05 03:17:25 by jwe]
jwe
parents: 4009
diff changeset
862 { $$ = make_assign_op (POW_EQ, $1, $2, $3); }
2970
b9e64477f703 [project @ 1997-05-15 18:04:21 by jwe]
jwe
parents: 2961
diff changeset
863 | assign_lhs LSHIFT_EQ expression
b9e64477f703 [project @ 1997-05-15 18:04:21 by jwe]
jwe
parents: 2961
diff changeset
864 { $$ = make_assign_op (LSHIFT_EQ, $1, $2, $3); }
b9e64477f703 [project @ 1997-05-15 18:04:21 by jwe]
jwe
parents: 2961
diff changeset
865 | assign_lhs RSHIFT_EQ expression
b9e64477f703 [project @ 1997-05-15 18:04:21 by jwe]
jwe
parents: 2961
diff changeset
866 { $$ = make_assign_op (RSHIFT_EQ, $1, $2, $3); }
b9e64477f703 [project @ 1997-05-15 18:04:21 by jwe]
jwe
parents: 2961
diff changeset
867 | assign_lhs EMUL_EQ expression
b9e64477f703 [project @ 1997-05-15 18:04:21 by jwe]
jwe
parents: 2961
diff changeset
868 { $$ = make_assign_op (EMUL_EQ, $1, $2, $3); }
b9e64477f703 [project @ 1997-05-15 18:04:21 by jwe]
jwe
parents: 2961
diff changeset
869 | assign_lhs EDIV_EQ expression
b9e64477f703 [project @ 1997-05-15 18:04:21 by jwe]
jwe
parents: 2961
diff changeset
870 { $$ = make_assign_op (EDIV_EQ, $1, $2, $3); }
3204
81738e630f57 [project @ 1998-10-30 23:28:29 by jwe]
jwe
parents: 3203
diff changeset
871 | assign_lhs ELEFTDIV_EQ expression
81738e630f57 [project @ 1998-10-30 23:28:29 by jwe]
jwe
parents: 3203
diff changeset
872 { $$ = make_assign_op (ELEFTDIV_EQ, $1, $2, $3); }
4018
a8621d87fbf5 [project @ 2002-08-05 03:17:25 by jwe]
jwe
parents: 4009
diff changeset
873 | assign_lhs EPOW_EQ expression
a8621d87fbf5 [project @ 2002-08-05 03:17:25 by jwe]
jwe
parents: 4009
diff changeset
874 { $$ = make_assign_op (EPOW_EQ, $1, $2, $3); }
2970
b9e64477f703 [project @ 1997-05-15 18:04:21 by jwe]
jwe
parents: 2961
diff changeset
875 | assign_lhs AND_EQ expression
b9e64477f703 [project @ 1997-05-15 18:04:21 by jwe]
jwe
parents: 2961
diff changeset
876 { $$ = make_assign_op (AND_EQ, $1, $2, $3); }
b9e64477f703 [project @ 1997-05-15 18:04:21 by jwe]
jwe
parents: 2961
diff changeset
877 | assign_lhs OR_EQ expression
b9e64477f703 [project @ 1997-05-15 18:04:21 by jwe]
jwe
parents: 2961
diff changeset
878 { $$ = make_assign_op (OR_EQ, $1, $2, $3); }
b9e64477f703 [project @ 1997-05-15 18:04:21 by jwe]
jwe
parents: 2961
diff changeset
879 ;
b9e64477f703 [project @ 1997-05-15 18:04:21 by jwe]
jwe
parents: 2961
diff changeset
880
b9e64477f703 [project @ 1997-05-15 18:04:21 by jwe]
jwe
parents: 2961
diff changeset
881 expression : simple_expr
b9e64477f703 [project @ 1997-05-15 18:04:21 by jwe]
jwe
parents: 2961
diff changeset
882 { $$ = $1; }
b9e64477f703 [project @ 1997-05-15 18:04:21 by jwe]
jwe
parents: 2961
diff changeset
883 | assign_expr
b9e64477f703 [project @ 1997-05-15 18:04:21 by jwe]
jwe
parents: 2961
diff changeset
884 { $$ = $1; }
4935
4fc993a4e072 [project @ 2004-08-06 03:17:12 by jwe]
jwe
parents: 4930
diff changeset
885 | anon_fcn_handle
4fc993a4e072 [project @ 2004-08-06 03:17:12 by jwe]
jwe
parents: 4930
diff changeset
886 { $$ = $1; }
2970
b9e64477f703 [project @ 1997-05-15 18:04:21 by jwe]
jwe
parents: 2961
diff changeset
887 ;
b9e64477f703 [project @ 1997-05-15 18:04:21 by jwe]
jwe
parents: 2961
diff changeset
888
b9e64477f703 [project @ 1997-05-15 18:04:21 by jwe]
jwe
parents: 2961
diff changeset
889 // ================================================
b9e64477f703 [project @ 1997-05-15 18:04:21 by jwe]
jwe
parents: 2961
diff changeset
890 // Commands, declarations, and function definitions
b9e64477f703 [project @ 1997-05-15 18:04:21 by jwe]
jwe
parents: 2961
diff changeset
891 // ================================================
b9e64477f703 [project @ 1997-05-15 18:04:21 by jwe]
jwe
parents: 2961
diff changeset
892
b9e64477f703 [project @ 1997-05-15 18:04:21 by jwe]
jwe
parents: 2961
diff changeset
893 command : declaration
b9e64477f703 [project @ 1997-05-15 18:04:21 by jwe]
jwe
parents: 2961
diff changeset
894 { $$ = $1; }
b9e64477f703 [project @ 1997-05-15 18:04:21 by jwe]
jwe
parents: 2961
diff changeset
895 | select_command
b9e64477f703 [project @ 1997-05-15 18:04:21 by jwe]
jwe
parents: 2961
diff changeset
896 { $$ = $1; }
b9e64477f703 [project @ 1997-05-15 18:04:21 by jwe]
jwe
parents: 2961
diff changeset
897 | loop_command
b9e64477f703 [project @ 1997-05-15 18:04:21 by jwe]
jwe
parents: 2961
diff changeset
898 { $$ = $1; }
4207
fa3482b34599 [project @ 2002-12-03 18:22:05 by jwe]
jwe
parents: 4186
diff changeset
899 | jump_command
fa3482b34599 [project @ 2002-12-03 18:22:05 by jwe]
jwe
parents: 4186
diff changeset
900 { $$ = $1; }
2970
b9e64477f703 [project @ 1997-05-15 18:04:21 by jwe]
jwe
parents: 2961
diff changeset
901 | except_command
b9e64477f703 [project @ 1997-05-15 18:04:21 by jwe]
jwe
parents: 2961
diff changeset
902 { $$ = $1; }
b9e64477f703 [project @ 1997-05-15 18:04:21 by jwe]
jwe
parents: 2961
diff changeset
903 | function
b9e64477f703 [project @ 1997-05-15 18:04:21 by jwe]
jwe
parents: 2961
diff changeset
904 { $$ = $1; }
7715
5b4d278ec828 parse scripts completely before executing
John W. Eaton <jwe@octave.org>
parents: 7699
diff changeset
905 | script
5b4d278ec828 parse scripts completely before executing
John W. Eaton <jwe@octave.org>
parents: 7699
diff changeset
906 { $$ = $1; }
2970
b9e64477f703 [project @ 1997-05-15 18:04:21 by jwe]
jwe
parents: 2961
diff changeset
907 ;
b9e64477f703 [project @ 1997-05-15 18:04:21 by jwe]
jwe
parents: 2961
diff changeset
908
b9e64477f703 [project @ 1997-05-15 18:04:21 by jwe]
jwe
parents: 2961
diff changeset
909 // =====================
b9e64477f703 [project @ 1997-05-15 18:04:21 by jwe]
jwe
parents: 2961
diff changeset
910 // Declaration statemnts
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
8701
1652e39b934e handle command names in declaration lists
John W. Eaton <jwe@octave.org>
parents: 8697
diff changeset
913 parsing_decl_list
1652e39b934e handle command names in declaration lists
John W. Eaton <jwe@octave.org>
parents: 8697
diff changeset
914 : // empty
1652e39b934e handle command names in declaration lists
John W. Eaton <jwe@octave.org>
parents: 8697
diff changeset
915 { lexer_flags.looking_at_decl_list = true; }
1652e39b934e handle command names in declaration lists
John W. Eaton <jwe@octave.org>
parents: 8697
diff changeset
916
1652e39b934e handle command names in declaration lists
John W. Eaton <jwe@octave.org>
parents: 8697
diff changeset
917 declaration : GLOBAL parsing_decl_list decl1
1652e39b934e handle command names in declaration lists
John W. Eaton <jwe@octave.org>
parents: 8697
diff changeset
918 {
1652e39b934e handle command names in declaration lists
John W. Eaton <jwe@octave.org>
parents: 8697
diff changeset
919 $$ = make_decl_command (GLOBAL, $1, $3);
1652e39b934e handle command names in declaration lists
John W. Eaton <jwe@octave.org>
parents: 8697
diff changeset
920 lexer_flags.looking_at_decl_list = false;
1652e39b934e handle command names in declaration lists
John W. Eaton <jwe@octave.org>
parents: 8697
diff changeset
921 }
1652e39b934e handle command names in declaration lists
John W. Eaton <jwe@octave.org>
parents: 8697
diff changeset
922 | STATIC parsing_decl_list decl1
1652e39b934e handle command names in declaration lists
John W. Eaton <jwe@octave.org>
parents: 8697
diff changeset
923 {
1652e39b934e handle command names in declaration lists
John W. Eaton <jwe@octave.org>
parents: 8697
diff changeset
924 $$ = make_decl_command (STATIC, $1, $3);
1652e39b934e handle command names in declaration lists
John W. Eaton <jwe@octave.org>
parents: 8697
diff changeset
925 lexer_flags.looking_at_decl_list = false;
1652e39b934e handle command names in declaration lists
John W. Eaton <jwe@octave.org>
parents: 8697
diff changeset
926 }
2970
b9e64477f703 [project @ 1997-05-15 18:04:21 by jwe]
jwe
parents: 2961
diff changeset
927 ;
b9e64477f703 [project @ 1997-05-15 18:04:21 by jwe]
jwe
parents: 2961
diff changeset
928
b9e64477f703 [project @ 1997-05-15 18:04:21 by jwe]
jwe
parents: 2961
diff changeset
929 decl1 : decl2
b9e64477f703 [project @ 1997-05-15 18:04:21 by jwe]
jwe
parents: 2961
diff changeset
930 { $$ = new tree_decl_init_list ($1); }
b9e64477f703 [project @ 1997-05-15 18:04:21 by jwe]
jwe
parents: 2961
diff changeset
931 | decl1 decl2
b9e64477f703 [project @ 1997-05-15 18:04:21 by jwe]
jwe
parents: 2961
diff changeset
932 {
b9e64477f703 [project @ 1997-05-15 18:04:21 by jwe]
jwe
parents: 2961
diff changeset
933 $1->append ($2);
b9e64477f703 [project @ 1997-05-15 18:04:21 by jwe]
jwe
parents: 2961
diff changeset
934 $$ = $1;
b9e64477f703 [project @ 1997-05-15 18:04:21 by jwe]
jwe
parents: 2961
diff changeset
935 }
b9e64477f703 [project @ 1997-05-15 18:04:21 by jwe]
jwe
parents: 2961
diff changeset
936 ;
b9e64477f703 [project @ 1997-05-15 18:04:21 by jwe]
jwe
parents: 2961
diff changeset
937
7634
ae90e05ad299 fix parameter list initializer bug
John W. Eaton <jwe@octave.org>
parents: 7587
diff changeset
938 decl_param_init : // empty
ae90e05ad299 fix parameter list initializer bug
John W. Eaton <jwe@octave.org>
parents: 7587
diff changeset
939 { lexer_flags.looking_at_initializer_expression = true; }
ae90e05ad299 fix parameter list initializer bug
John W. Eaton <jwe@octave.org>
parents: 7587
diff changeset
940
2970
b9e64477f703 [project @ 1997-05-15 18:04:21 by jwe]
jwe
parents: 2961
diff changeset
941 decl2 : identifier
b9e64477f703 [project @ 1997-05-15 18:04:21 by jwe]
jwe
parents: 2961
diff changeset
942 { $$ = new tree_decl_elt ($1); }
7634
ae90e05ad299 fix parameter list initializer bug
John W. Eaton <jwe@octave.org>
parents: 7587
diff changeset
943 | identifier '=' decl_param_init expression
ae90e05ad299 fix parameter list initializer bug
John W. Eaton <jwe@octave.org>
parents: 7587
diff changeset
944 {
ae90e05ad299 fix parameter list initializer bug
John W. Eaton <jwe@octave.org>
parents: 7587
diff changeset
945 lexer_flags.looking_at_initializer_expression = false;
ae90e05ad299 fix parameter list initializer bug
John W. Eaton <jwe@octave.org>
parents: 7587
diff changeset
946 $$ = new tree_decl_elt ($1, $4);
ae90e05ad299 fix parameter list initializer bug
John W. Eaton <jwe@octave.org>
parents: 7587
diff changeset
947 }
2970
b9e64477f703 [project @ 1997-05-15 18:04:21 by jwe]
jwe
parents: 2961
diff changeset
948 ;
b9e64477f703 [project @ 1997-05-15 18:04:21 by jwe]
jwe
parents: 2961
diff changeset
949
b9e64477f703 [project @ 1997-05-15 18:04:21 by jwe]
jwe
parents: 2961
diff changeset
950 // ====================
b9e64477f703 [project @ 1997-05-15 18:04:21 by jwe]
jwe
parents: 2961
diff changeset
951 // Selection statements
b9e64477f703 [project @ 1997-05-15 18:04:21 by jwe]
jwe
parents: 2961
diff changeset
952 // ====================
b9e64477f703 [project @ 1997-05-15 18:04:21 by jwe]
jwe
parents: 2961
diff changeset
953
b9e64477f703 [project @ 1997-05-15 18:04:21 by jwe]
jwe
parents: 2961
diff changeset
954 select_command : if_command
b9e64477f703 [project @ 1997-05-15 18:04:21 by jwe]
jwe
parents: 2961
diff changeset
955 { $$ = $1; }
b9e64477f703 [project @ 1997-05-15 18:04:21 by jwe]
jwe
parents: 2961
diff changeset
956 | switch_command
b9e64477f703 [project @ 1997-05-15 18:04:21 by jwe]
jwe
parents: 2961
diff changeset
957 { $$ = $1; }
b9e64477f703 [project @ 1997-05-15 18:04:21 by jwe]
jwe
parents: 2961
diff changeset
958 ;
b9e64477f703 [project @ 1997-05-15 18:04:21 by jwe]
jwe
parents: 2961
diff changeset
959
b9e64477f703 [project @ 1997-05-15 18:04:21 by jwe]
jwe
parents: 2961
diff changeset
960 // ============
b9e64477f703 [project @ 1997-05-15 18:04:21 by jwe]
jwe
parents: 2961
diff changeset
961 // If statement
b9e64477f703 [project @ 1997-05-15 18:04:21 by jwe]
jwe
parents: 2961
diff changeset
962 // ============
b9e64477f703 [project @ 1997-05-15 18:04:21 by jwe]
jwe
parents: 2961
diff changeset
963
3665
0689afb1d001 [project @ 2000-05-11 19:07:56 by jwe]
jwe
parents: 3544
diff changeset
964 if_command : IF stash_comment if_cmd_list END
2970
b9e64477f703 [project @ 1997-05-15 18:04:21 by jwe]
jwe
parents: 2961
diff changeset
965 {
3665
0689afb1d001 [project @ 2000-05-11 19:07:56 by jwe]
jwe
parents: 3544
diff changeset
966 if (! ($$ = finish_if_command ($1, $3, $4, $2)))
2970
b9e64477f703 [project @ 1997-05-15 18:04:21 by jwe]
jwe
parents: 2961
diff changeset
967 ABORT_PARSE;
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
b9e64477f703 [project @ 1997-05-15 18:04:21 by jwe]
jwe
parents: 2961
diff changeset
971 if_cmd_list : if_cmd_list1
b9e64477f703 [project @ 1997-05-15 18:04:21 by jwe]
jwe
parents: 2961
diff changeset
972 { $$ = $1; }
b9e64477f703 [project @ 1997-05-15 18:04:21 by jwe]
jwe
parents: 2961
diff changeset
973 | if_cmd_list1 else_clause
b9e64477f703 [project @ 1997-05-15 18:04:21 by jwe]
jwe
parents: 2961
diff changeset
974 {
b9e64477f703 [project @ 1997-05-15 18:04:21 by jwe]
jwe
parents: 2961
diff changeset
975 $1->append ($2);
b9e64477f703 [project @ 1997-05-15 18:04:21 by jwe]
jwe
parents: 2961
diff changeset
976 $$ = $1;
b9e64477f703 [project @ 1997-05-15 18:04:21 by jwe]
jwe
parents: 2961
diff changeset
977 }
b9e64477f703 [project @ 1997-05-15 18:04:21 by jwe]
jwe
parents: 2961
diff changeset
978 ;
b9e64477f703 [project @ 1997-05-15 18:04:21 by jwe]
jwe
parents: 2961
diff changeset
979
b9e64477f703 [project @ 1997-05-15 18:04:21 by jwe]
jwe
parents: 2961
diff changeset
980 if_cmd_list1 : expression opt_sep opt_list
b9e64477f703 [project @ 1997-05-15 18:04:21 by jwe]
jwe
parents: 2961
diff changeset
981 { $$ = start_if_command ($1, $3); }
b9e64477f703 [project @ 1997-05-15 18:04:21 by jwe]
jwe
parents: 2961
diff changeset
982 | if_cmd_list1 elseif_clause
b9e64477f703 [project @ 1997-05-15 18:04:21 by jwe]
jwe
parents: 2961
diff changeset
983 {
b9e64477f703 [project @ 1997-05-15 18:04:21 by jwe]
jwe
parents: 2961
diff changeset
984 $1->append ($2);
b9e64477f703 [project @ 1997-05-15 18:04:21 by jwe]
jwe
parents: 2961
diff changeset
985 $$ = $1;
b9e64477f703 [project @ 1997-05-15 18:04:21 by jwe]
jwe
parents: 2961
diff changeset
986 }
b9e64477f703 [project @ 1997-05-15 18:04:21 by jwe]
jwe
parents: 2961
diff changeset
987 ;
b9e64477f703 [project @ 1997-05-15 18:04:21 by jwe]
jwe
parents: 2961
diff changeset
988
3665
0689afb1d001 [project @ 2000-05-11 19:07:56 by jwe]
jwe
parents: 3544
diff changeset
989 elseif_clause : ELSEIF stash_comment opt_sep expression opt_sep opt_list
8658
73c4516fae10 New evaluator and debugger derived from tree-walker class
John W. Eaton <jwe@octave.org>
parents: 8471
diff changeset
990 { $$ = make_elseif_clause ($1, $4, $6, $2); }
2970
b9e64477f703 [project @ 1997-05-15 18:04:21 by jwe]
jwe
parents: 2961
diff changeset
991 ;
b9e64477f703 [project @ 1997-05-15 18:04:21 by jwe]
jwe
parents: 2961
diff changeset
992
3665
0689afb1d001 [project @ 2000-05-11 19:07:56 by jwe]
jwe
parents: 3544
diff changeset
993 else_clause : ELSE stash_comment opt_sep opt_list
8658
73c4516fae10 New evaluator and debugger derived from tree-walker class
John W. Eaton <jwe@octave.org>
parents: 8471
diff changeset
994 { $$ = new tree_if_clause ($4, $2); }
2970
b9e64477f703 [project @ 1997-05-15 18:04:21 by jwe]
jwe
parents: 2961
diff changeset
995 ;
b9e64477f703 [project @ 1997-05-15 18:04:21 by jwe]
jwe
parents: 2961
diff changeset
996
b9e64477f703 [project @ 1997-05-15 18:04:21 by jwe]
jwe
parents: 2961
diff changeset
997 // ================
b9e64477f703 [project @ 1997-05-15 18:04:21 by jwe]
jwe
parents: 2961
diff changeset
998 // Switch statement
b9e64477f703 [project @ 1997-05-15 18:04:21 by jwe]
jwe
parents: 2961
diff changeset
999 // ================
b9e64477f703 [project @ 1997-05-15 18:04:21 by jwe]
jwe
parents: 2961
diff changeset
1000
3665
0689afb1d001 [project @ 2000-05-11 19:07:56 by jwe]
jwe
parents: 3544
diff changeset
1001 switch_command : SWITCH stash_comment expression opt_sep case_list END
2970
b9e64477f703 [project @ 1997-05-15 18:04:21 by jwe]
jwe
parents: 2961
diff changeset
1002 {
3665
0689afb1d001 [project @ 2000-05-11 19:07:56 by jwe]
jwe
parents: 3544
diff changeset
1003 if (! ($$ = finish_switch_command ($1, $3, $5, $6, $2)))
2970
b9e64477f703 [project @ 1997-05-15 18:04:21 by jwe]
jwe
parents: 2961
diff changeset
1004 ABORT_PARSE;
b9e64477f703 [project @ 1997-05-15 18:04:21 by jwe]
jwe
parents: 2961
diff changeset
1005 }
b9e64477f703 [project @ 1997-05-15 18:04:21 by jwe]
jwe
parents: 2961
diff changeset
1006 ;
b9e64477f703 [project @ 1997-05-15 18:04:21 by jwe]
jwe
parents: 2961
diff changeset
1007
4044
9678c5526190 [project @ 2002-08-15 16:54:55 by jwe]
jwe
parents: 4025
diff changeset
1008 case_list : // empty
9678c5526190 [project @ 2002-08-15 16:54:55 by jwe]
jwe
parents: 4025
diff changeset
1009 { $$ = new tree_switch_case_list (); }
9678c5526190 [project @ 2002-08-15 16:54:55 by jwe]
jwe
parents: 4025
diff changeset
1010 | case_list1
2970
b9e64477f703 [project @ 1997-05-15 18:04:21 by jwe]
jwe
parents: 2961
diff changeset
1011 { $$ = $1; }
b9e64477f703 [project @ 1997-05-15 18:04:21 by jwe]
jwe
parents: 2961
diff changeset
1012 | case_list1 default_case
b9e64477f703 [project @ 1997-05-15 18:04:21 by jwe]
jwe
parents: 2961
diff changeset
1013 {
b9e64477f703 [project @ 1997-05-15 18:04:21 by jwe]
jwe
parents: 2961
diff changeset
1014 $1->append ($2);
b9e64477f703 [project @ 1997-05-15 18:04:21 by jwe]
jwe
parents: 2961
diff changeset
1015 $$ = $1;
b9e64477f703 [project @ 1997-05-15 18:04:21 by jwe]
jwe
parents: 2961
diff changeset
1016 }
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
b9e64477f703 [project @ 1997-05-15 18:04:21 by jwe]
jwe
parents: 2961
diff changeset
1019 case_list1 : switch_case
b9e64477f703 [project @ 1997-05-15 18:04:21 by jwe]
jwe
parents: 2961
diff changeset
1020 { $$ = new tree_switch_case_list ($1); }
b9e64477f703 [project @ 1997-05-15 18:04:21 by jwe]
jwe
parents: 2961
diff changeset
1021 | case_list1 switch_case
b9e64477f703 [project @ 1997-05-15 18:04:21 by jwe]
jwe
parents: 2961
diff changeset
1022 {
b9e64477f703 [project @ 1997-05-15 18:04:21 by jwe]
jwe
parents: 2961
diff changeset
1023 $1->append ($2);
b9e64477f703 [project @ 1997-05-15 18:04:21 by jwe]
jwe
parents: 2961
diff changeset
1024 $$ = $1;
b9e64477f703 [project @ 1997-05-15 18:04:21 by jwe]
jwe
parents: 2961
diff changeset
1025 }
b9e64477f703 [project @ 1997-05-15 18:04:21 by jwe]
jwe
parents: 2961
diff changeset
1026 ;
b9e64477f703 [project @ 1997-05-15 18:04:21 by jwe]
jwe
parents: 2961
diff changeset
1027
4025
cfb762dc9259 [project @ 2002-08-09 06:32:15 by jwe]
jwe
parents: 4024
diff changeset
1028 switch_case : CASE stash_comment opt_sep expression opt_sep opt_list
8658
73c4516fae10 New evaluator and debugger derived from tree-walker class
John W. Eaton <jwe@octave.org>
parents: 8471
diff changeset
1029 { $$ = make_switch_case ($1, $4, $6, $2); }
2970
b9e64477f703 [project @ 1997-05-15 18:04:21 by jwe]
jwe
parents: 2961
diff changeset
1030 ;
b9e64477f703 [project @ 1997-05-15 18:04:21 by jwe]
jwe
parents: 2961
diff changeset
1031
3665
0689afb1d001 [project @ 2000-05-11 19:07:56 by jwe]
jwe
parents: 3544
diff changeset
1032 default_case : OTHERWISE stash_comment opt_sep opt_list
0689afb1d001 [project @ 2000-05-11 19:07:56 by jwe]
jwe
parents: 3544
diff changeset
1033 {
0689afb1d001 [project @ 2000-05-11 19:07:56 by jwe]
jwe
parents: 3544
diff changeset
1034 $$ = new tree_switch_case ($4, $2);
0689afb1d001 [project @ 2000-05-11 19:07:56 by jwe]
jwe
parents: 3544
diff changeset
1035 }
2970
b9e64477f703 [project @ 1997-05-15 18:04:21 by jwe]
jwe
parents: 2961
diff changeset
1036 ;
b9e64477f703 [project @ 1997-05-15 18:04:21 by jwe]
jwe
parents: 2961
diff changeset
1037
b9e64477f703 [project @ 1997-05-15 18:04:21 by jwe]
jwe
parents: 2961
diff changeset
1038 // =======
b9e64477f703 [project @ 1997-05-15 18:04:21 by jwe]
jwe
parents: 2961
diff changeset
1039 // Looping
b9e64477f703 [project @ 1997-05-15 18:04:21 by jwe]
jwe
parents: 2961
diff changeset
1040 // =======
b9e64477f703 [project @ 1997-05-15 18:04:21 by jwe]
jwe
parents: 2961
diff changeset
1041
3665
0689afb1d001 [project @ 2000-05-11 19:07:56 by jwe]
jwe
parents: 3544
diff changeset
1042 loop_command : WHILE stash_comment expression opt_sep opt_list END
2970
b9e64477f703 [project @ 1997-05-15 18:04:21 by jwe]
jwe
parents: 2961
diff changeset
1043 {
3665
0689afb1d001 [project @ 2000-05-11 19:07:56 by jwe]
jwe
parents: 3544
diff changeset
1044 if (! ($$ = make_while_command ($1, $3, $5, $6, $2)))
2970
b9e64477f703 [project @ 1997-05-15 18:04:21 by jwe]
jwe
parents: 2961
diff changeset
1045 ABORT_PARSE;
b9e64477f703 [project @ 1997-05-15 18:04:21 by jwe]
jwe
parents: 2961
diff changeset
1046 }
3665
0689afb1d001 [project @ 2000-05-11 19:07:56 by jwe]
jwe
parents: 3544
diff changeset
1047 | DO stash_comment opt_sep opt_list UNTIL expression
3484
8b1f46ac2b64 [project @ 2000-01-27 23:30:45 by jwe]
jwe
parents: 3446
diff changeset
1048 {
8658
73c4516fae10 New evaluator and debugger derived from tree-walker class
John W. Eaton <jwe@octave.org>
parents: 8471
diff changeset
1049 if (! ($$ = make_do_until_command ($5, $4, $6, $2)))
3484
8b1f46ac2b64 [project @ 2000-01-27 23:30:45 by jwe]
jwe
parents: 3446
diff changeset
1050 ABORT_PARSE;
8b1f46ac2b64 [project @ 2000-01-27 23:30:45 by jwe]
jwe
parents: 3446
diff changeset
1051 }
3665
0689afb1d001 [project @ 2000-05-11 19:07:56 by jwe]
jwe
parents: 3544
diff changeset
1052 | FOR stash_comment assign_lhs '=' expression opt_sep opt_list END
2970
b9e64477f703 [project @ 1997-05-15 18:04:21 by jwe]
jwe
parents: 2961
diff changeset
1053 {
3665
0689afb1d001 [project @ 2000-05-11 19:07:56 by jwe]
jwe
parents: 3544
diff changeset
1054 if (! ($$ = make_for_command ($1, $3, $5, $7, $8, $2)))
2970
b9e64477f703 [project @ 1997-05-15 18:04:21 by jwe]
jwe
parents: 2961
diff changeset
1055 ABORT_PARSE;
b9e64477f703 [project @ 1997-05-15 18:04:21 by jwe]
jwe
parents: 2961
diff changeset
1056 }
5127
7f4a3e4bc58a [project @ 2005-02-02 22:08:49 by jwe]
jwe
parents: 5102
diff changeset
1057 | FOR stash_comment '(' assign_lhs '=' expression ')' opt_sep opt_list END
7f4a3e4bc58a [project @ 2005-02-02 22:08:49 by jwe]
jwe
parents: 5102
diff changeset
1058 {
7f4a3e4bc58a [project @ 2005-02-02 22:08:49 by jwe]
jwe
parents: 5102
diff changeset
1059 if (! ($$ = make_for_command ($1, $4, $6, $9, $10, $2)))
7f4a3e4bc58a [project @ 2005-02-02 22:08:49 by jwe]
jwe
parents: 5102
diff changeset
1060 ABORT_PARSE;
7f4a3e4bc58a [project @ 2005-02-02 22:08:49 by jwe]
jwe
parents: 5102
diff changeset
1061 }
2970
b9e64477f703 [project @ 1997-05-15 18:04:21 by jwe]
jwe
parents: 2961
diff changeset
1062 ;
b9e64477f703 [project @ 1997-05-15 18:04:21 by jwe]
jwe
parents: 2961
diff changeset
1063
b9e64477f703 [project @ 1997-05-15 18:04:21 by jwe]
jwe
parents: 2961
diff changeset
1064 // =======
b9e64477f703 [project @ 1997-05-15 18:04:21 by jwe]
jwe
parents: 2961
diff changeset
1065 // Jumping
b9e64477f703 [project @ 1997-05-15 18:04:21 by jwe]
jwe
parents: 2961
diff changeset
1066 // =======
b9e64477f703 [project @ 1997-05-15 18:04:21 by jwe]
jwe
parents: 2961
diff changeset
1067
4207
fa3482b34599 [project @ 2002-12-03 18:22:05 by jwe]
jwe
parents: 4186
diff changeset
1068 jump_command : BREAK
2970
b9e64477f703 [project @ 1997-05-15 18:04:21 by jwe]
jwe
parents: 2961
diff changeset
1069 {
4207
fa3482b34599 [project @ 2002-12-03 18:22:05 by jwe]
jwe
parents: 4186
diff changeset
1070 if (! ($$ = make_break_command ($1)))
2970
b9e64477f703 [project @ 1997-05-15 18:04:21 by jwe]
jwe
parents: 2961
diff changeset
1071 ABORT_PARSE;
b9e64477f703 [project @ 1997-05-15 18:04:21 by jwe]
jwe
parents: 2961
diff changeset
1072 }
b9e64477f703 [project @ 1997-05-15 18:04:21 by jwe]
jwe
parents: 2961
diff changeset
1073 | CONTINUE
b9e64477f703 [project @ 1997-05-15 18:04:21 by jwe]
jwe
parents: 2961
diff changeset
1074 {
4207
fa3482b34599 [project @ 2002-12-03 18:22:05 by jwe]
jwe
parents: 4186
diff changeset
1075 if (! ($$ = make_continue_command ($1)))
2970
b9e64477f703 [project @ 1997-05-15 18:04:21 by jwe]
jwe
parents: 2961
diff changeset
1076 ABORT_PARSE;
b9e64477f703 [project @ 1997-05-15 18:04:21 by jwe]
jwe
parents: 2961
diff changeset
1077 }
b9e64477f703 [project @ 1997-05-15 18:04:21 by jwe]
jwe
parents: 2961
diff changeset
1078 | FUNC_RET
b9e64477f703 [project @ 1997-05-15 18:04:21 by jwe]
jwe
parents: 2961
diff changeset
1079 {
4207
fa3482b34599 [project @ 2002-12-03 18:22:05 by jwe]
jwe
parents: 4186
diff changeset
1080 if (! ($$ = make_return_command ($1)))
2970
b9e64477f703 [project @ 1997-05-15 18:04:21 by jwe]
jwe
parents: 2961
diff changeset
1081 ABORT_PARSE;
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
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 // Exceptions
b9e64477f703 [project @ 1997-05-15 18:04:21 by jwe]
jwe
parents: 2961
diff changeset
1087 // ==========
b9e64477f703 [project @ 1997-05-15 18:04:21 by jwe]
jwe
parents: 2961
diff changeset
1088
3665
0689afb1d001 [project @ 2000-05-11 19:07:56 by jwe]
jwe
parents: 3544
diff changeset
1089 except_command : UNWIND stash_comment opt_sep opt_list CLEANUP
0689afb1d001 [project @ 2000-05-11 19:07:56 by jwe]
jwe
parents: 3544
diff changeset
1090 stash_comment opt_sep opt_list END
2970
b9e64477f703 [project @ 1997-05-15 18:04:21 by jwe]
jwe
parents: 2961
diff changeset
1091 {
3665
0689afb1d001 [project @ 2000-05-11 19:07:56 by jwe]
jwe
parents: 3544
diff changeset
1092 if (! ($$ = make_unwind_command ($1, $4, $8, $9, $2, $6)))
2970
b9e64477f703 [project @ 1997-05-15 18:04:21 by jwe]
jwe
parents: 2961
diff changeset
1093 ABORT_PARSE;
b9e64477f703 [project @ 1997-05-15 18:04:21 by jwe]
jwe
parents: 2961
diff changeset
1094 }
3665
0689afb1d001 [project @ 2000-05-11 19:07:56 by jwe]
jwe
parents: 3544
diff changeset
1095 | TRY stash_comment opt_sep opt_list CATCH
0689afb1d001 [project @ 2000-05-11 19:07:56 by jwe]
jwe
parents: 3544
diff changeset
1096 stash_comment opt_sep opt_list END
2970
b9e64477f703 [project @ 1997-05-15 18:04:21 by jwe]
jwe
parents: 2961
diff changeset
1097 {
3665
0689afb1d001 [project @ 2000-05-11 19:07:56 by jwe]
jwe
parents: 3544
diff changeset
1098 if (! ($$ = make_try_command ($1, $4, $8, $9, $2, $6)))
2970
b9e64477f703 [project @ 1997-05-15 18:04:21 by jwe]
jwe
parents: 2961
diff changeset
1099 ABORT_PARSE;
b9e64477f703 [project @ 1997-05-15 18:04:21 by jwe]
jwe
parents: 2961
diff changeset
1100 }
5344
b427cca320b8 [project @ 2005-05-09 19:03:02 by jwe]
jwe
parents: 5312
diff changeset
1101 | TRY stash_comment opt_sep opt_list END
b427cca320b8 [project @ 2005-05-09 19:03:02 by jwe]
jwe
parents: 5312
diff changeset
1102 {
b427cca320b8 [project @ 2005-05-09 19:03:02 by jwe]
jwe
parents: 5312
diff changeset
1103 if (! ($$ = make_try_command ($1, $4, 0, $5, $2, 0)))
b427cca320b8 [project @ 2005-05-09 19:03:02 by jwe]
jwe
parents: 5312
diff changeset
1104 ABORT_PARSE;
b427cca320b8 [project @ 2005-05-09 19:03:02 by jwe]
jwe
parents: 5312
diff changeset
1105 }
2970
b9e64477f703 [project @ 1997-05-15 18:04:21 by jwe]
jwe
parents: 2961
diff changeset
1106 ;
b9e64477f703 [project @ 1997-05-15 18:04:21 by jwe]
jwe
parents: 2961
diff changeset
1107
b9e64477f703 [project @ 1997-05-15 18:04:21 by jwe]
jwe
parents: 2961
diff changeset
1108 // ===========================================
b9e64477f703 [project @ 1997-05-15 18:04:21 by jwe]
jwe
parents: 2961
diff changeset
1109 // Some `subroutines' for function definitions
b9e64477f703 [project @ 1997-05-15 18:04:21 by jwe]
jwe
parents: 2961
diff changeset
1110 // ===========================================
b9e64477f703 [project @ 1997-05-15 18:04:21 by jwe]
jwe
parents: 2961
diff changeset
1111
7336
745a8299c2b5 [project @ 2007-12-28 20:56:55 by jwe]
jwe
parents: 7017
diff changeset
1112 push_fcn_symtab : // empty
745a8299c2b5 [project @ 2007-12-28 20:56:55 by jwe]
jwe
parents: 7017
diff changeset
1113 {
745a8299c2b5 [project @ 2007-12-28 20:56:55 by jwe]
jwe
parents: 7017
diff changeset
1114 symtab_context.push (symbol_table::current_scope ());
745a8299c2b5 [project @ 2007-12-28 20:56:55 by jwe]
jwe
parents: 7017
diff changeset
1115 symbol_table::set_scope (symbol_table::alloc_scope ());
745a8299c2b5 [project @ 2007-12-28 20:56:55 by jwe]
jwe
parents: 7017
diff changeset
1116
745a8299c2b5 [project @ 2007-12-28 20:56:55 by jwe]
jwe
parents: 7017
diff changeset
1117 if (! lexer_flags.parsing_nested_function)
745a8299c2b5 [project @ 2007-12-28 20:56:55 by jwe]
jwe
parents: 7017
diff changeset
1118 symbol_table::set_parent_scope (symbol_table::current_scope ());
745a8299c2b5 [project @ 2007-12-28 20:56:55 by jwe]
jwe
parents: 7017
diff changeset
1119 }
2970
b9e64477f703 [project @ 1997-05-15 18:04:21 by jwe]
jwe
parents: 2961
diff changeset
1120 ;
b9e64477f703 [project @ 1997-05-15 18:04:21 by jwe]
jwe
parents: 2961
diff changeset
1121
b9e64477f703 [project @ 1997-05-15 18:04:21 by jwe]
jwe
parents: 2961
diff changeset
1122 // ===========================
b9e64477f703 [project @ 1997-05-15 18:04:21 by jwe]
jwe
parents: 2961
diff changeset
1123 // List of function parameters
b9e64477f703 [project @ 1997-05-15 18:04:21 by jwe]
jwe
parents: 2961
diff changeset
1124 // ===========================
b9e64477f703 [project @ 1997-05-15 18:04:21 by jwe]
jwe
parents: 2961
diff changeset
1125
b9e64477f703 [project @ 1997-05-15 18:04:21 by jwe]
jwe
parents: 2961
diff changeset
1126 param_list_beg : '('
4935
4fc993a4e072 [project @ 2004-08-06 03:17:12 by jwe]
jwe
parents: 4930
diff changeset
1127 {
4fc993a4e072 [project @ 2004-08-06 03:17:12 by jwe]
jwe
parents: 4930
diff changeset
1128 lexer_flags.looking_at_parameter_list = true;
4fc993a4e072 [project @ 2004-08-06 03:17:12 by jwe]
jwe
parents: 4930
diff changeset
1129
4fc993a4e072 [project @ 2004-08-06 03:17:12 by jwe]
jwe
parents: 4930
diff changeset
1130 if (lexer_flags.looking_at_function_handle)
4fc993a4e072 [project @ 2004-08-06 03:17:12 by jwe]
jwe
parents: 4930
diff changeset
1131 {
7336
745a8299c2b5 [project @ 2007-12-28 20:56:55 by jwe]
jwe
parents: 7017
diff changeset
1132 symtab_context.push (symbol_table::current_scope ());
745a8299c2b5 [project @ 2007-12-28 20:56:55 by jwe]
jwe
parents: 7017
diff changeset
1133 symbol_table::set_scope (symbol_table::alloc_scope ());
4935
4fc993a4e072 [project @ 2004-08-06 03:17:12 by jwe]
jwe
parents: 4930
diff changeset
1134 lexer_flags.looking_at_function_handle--;
4fc993a4e072 [project @ 2004-08-06 03:17:12 by jwe]
jwe
parents: 4930
diff changeset
1135 }
4fc993a4e072 [project @ 2004-08-06 03:17:12 by jwe]
jwe
parents: 4930
diff changeset
1136 }
2970
b9e64477f703 [project @ 1997-05-15 18:04:21 by jwe]
jwe
parents: 2961
diff changeset
1137 ;
b9e64477f703 [project @ 1997-05-15 18:04:21 by jwe]
jwe
parents: 2961
diff changeset
1138
b9e64477f703 [project @ 1997-05-15 18:04:21 by jwe]
jwe
parents: 2961
diff changeset
1139 param_list_end : ')'
b9e64477f703 [project @ 1997-05-15 18:04:21 by jwe]
jwe
parents: 2961
diff changeset
1140 { lexer_flags.looking_at_parameter_list = false; }
b9e64477f703 [project @ 1997-05-15 18:04:21 by jwe]
jwe
parents: 2961
diff changeset
1141 ;
b9e64477f703 [project @ 1997-05-15 18:04:21 by jwe]
jwe
parents: 2961
diff changeset
1142
4935
4fc993a4e072 [project @ 2004-08-06 03:17:12 by jwe]
jwe
parents: 4930
diff changeset
1143 param_list : param_list_beg param_list1 param_list_end
2970
b9e64477f703 [project @ 1997-05-15 18:04:21 by jwe]
jwe
parents: 2961
diff changeset
1144 {
b9e64477f703 [project @ 1997-05-15 18:04:21 by jwe]
jwe
parents: 2961
diff changeset
1145 lexer_flags.quote_is_transpose = false;
4935
4fc993a4e072 [project @ 2004-08-06 03:17:12 by jwe]
jwe
parents: 4930
diff changeset
1146 $$ = $2;
2970
b9e64477f703 [project @ 1997-05-15 18:04:21 by jwe]
jwe
parents: 2961
diff changeset
1147 }
b9e64477f703 [project @ 1997-05-15 18:04:21 by jwe]
jwe
parents: 2961
diff changeset
1148 | param_list_beg error
b9e64477f703 [project @ 1997-05-15 18:04:21 by jwe]
jwe
parents: 2961
diff changeset
1149 {
b9e64477f703 [project @ 1997-05-15 18:04:21 by jwe]
jwe
parents: 2961
diff changeset
1150 yyerror ("invalid parameter list");
b9e64477f703 [project @ 1997-05-15 18:04:21 by jwe]
jwe
parents: 2961
diff changeset
1151 $$ = 0;
b9e64477f703 [project @ 1997-05-15 18:04:21 by jwe]
jwe
parents: 2961
diff changeset
1152 ABORT_PARSE;
b9e64477f703 [project @ 1997-05-15 18:04:21 by jwe]
jwe
parents: 2961
diff changeset
1153 }
4935
4fc993a4e072 [project @ 2004-08-06 03:17:12 by jwe]
jwe
parents: 4930
diff changeset
1154 ;
4fc993a4e072 [project @ 2004-08-06 03:17:12 by jwe]
jwe
parents: 4930
diff changeset
1155
4fc993a4e072 [project @ 2004-08-06 03:17:12 by jwe]
jwe
parents: 4930
diff changeset
1156 param_list1 : // empty
4fc993a4e072 [project @ 2004-08-06 03:17:12 by jwe]
jwe
parents: 4930
diff changeset
1157 { $$ = 0; }
4fc993a4e072 [project @ 2004-08-06 03:17:12 by jwe]
jwe
parents: 4930
diff changeset
1158 | param_list2
4fc993a4e072 [project @ 2004-08-06 03:17:12 by jwe]
jwe
parents: 4930
diff changeset
1159 {
4fc993a4e072 [project @ 2004-08-06 03:17:12 by jwe]
jwe
parents: 4930
diff changeset
1160 $1->mark_as_formal_parameters ();
7587
1f662945c2be handle varargin and varargout without keywords
John W. Eaton <jwe@octave.org>
parents: 7562
diff changeset
1161 if ($1->validate (tree_parameter_list::in))
1f662945c2be handle varargin and varargout without keywords
John W. Eaton <jwe@octave.org>
parents: 7562
diff changeset
1162 $$ = $1;
1f662945c2be handle varargin and varargout without keywords
John W. Eaton <jwe@octave.org>
parents: 7562
diff changeset
1163 else
1f662945c2be handle varargin and varargout without keywords
John W. Eaton <jwe@octave.org>
parents: 7562
diff changeset
1164 ABORT_PARSE;
4935
4fc993a4e072 [project @ 2004-08-06 03:17:12 by jwe]
jwe
parents: 4930
diff changeset
1165 }
4fc993a4e072 [project @ 2004-08-06 03:17:12 by jwe]
jwe
parents: 4930
diff changeset
1166 ;
4fc993a4e072 [project @ 2004-08-06 03:17:12 by jwe]
jwe
parents: 4930
diff changeset
1167
6215
516d3071b34c [project @ 2006-12-15 03:24:12 by jwe]
jwe
parents: 5975
diff changeset
1168 param_list2 : decl2
4935
4fc993a4e072 [project @ 2004-08-06 03:17:12 by jwe]
jwe
parents: 4930
diff changeset
1169 { $$ = new tree_parameter_list ($1); }
6215
516d3071b34c [project @ 2006-12-15 03:24:12 by jwe]
jwe
parents: 5975
diff changeset
1170 | param_list2 ',' decl2
4935
4fc993a4e072 [project @ 2004-08-06 03:17:12 by jwe]
jwe
parents: 4930
diff changeset
1171 {
4fc993a4e072 [project @ 2004-08-06 03:17:12 by jwe]
jwe
parents: 4930
diff changeset
1172 $1->append ($3);
4fc993a4e072 [project @ 2004-08-06 03:17:12 by jwe]
jwe
parents: 4930
diff changeset
1173 $$ = $1;
2970
b9e64477f703 [project @ 1997-05-15 18:04:21 by jwe]
jwe
parents: 2961
diff changeset
1174 }
b9e64477f703 [project @ 1997-05-15 18:04:21 by jwe]
jwe
parents: 2961
diff changeset
1175 ;
b9e64477f703 [project @ 1997-05-15 18:04:21 by jwe]
jwe
parents: 2961
diff changeset
1176
b9e64477f703 [project @ 1997-05-15 18:04:21 by jwe]
jwe
parents: 2961
diff changeset
1177 // ===================================
b9e64477f703 [project @ 1997-05-15 18:04:21 by jwe]
jwe
parents: 2961
diff changeset
1178 // List of function return value names
b9e64477f703 [project @ 1997-05-15 18:04:21 by jwe]
jwe
parents: 2961
diff changeset
1179 // ===================================
b9e64477f703 [project @ 1997-05-15 18:04:21 by jwe]
jwe
parents: 2961
diff changeset
1180
7336
745a8299c2b5 [project @ 2007-12-28 20:56:55 by jwe]
jwe
parents: 7017
diff changeset
1181 return_list : '[' ']'
2970
b9e64477f703 [project @ 1997-05-15 18:04:21 by jwe]
jwe
parents: 2961
diff changeset
1182 {
b9e64477f703 [project @ 1997-05-15 18:04:21 by jwe]
jwe
parents: 2961
diff changeset
1183 lexer_flags.looking_at_return_list = false;
b9e64477f703 [project @ 1997-05-15 18:04:21 by jwe]
jwe
parents: 2961
diff changeset
1184 $$ = new tree_parameter_list ();
b9e64477f703 [project @ 1997-05-15 18:04:21 by jwe]
jwe
parents: 2961
diff changeset
1185 }
7336
745a8299c2b5 [project @ 2007-12-28 20:56:55 by jwe]
jwe
parents: 7017
diff changeset
1186 | return_list1
745a8299c2b5 [project @ 2007-12-28 20:56:55 by jwe]
jwe
parents: 7017
diff changeset
1187 {
745a8299c2b5 [project @ 2007-12-28 20:56:55 by jwe]
jwe
parents: 7017
diff changeset
1188 lexer_flags.looking_at_return_list = false;
7587
1f662945c2be handle varargin and varargout without keywords
John W. Eaton <jwe@octave.org>
parents: 7562
diff changeset
1189 if ($1->validate (tree_parameter_list::out))
1f662945c2be handle varargin and varargout without keywords
John W. Eaton <jwe@octave.org>
parents: 7562
diff changeset
1190 $$ = $1;
1f662945c2be handle varargin and varargout without keywords
John W. Eaton <jwe@octave.org>
parents: 7562
diff changeset
1191 else
1f662945c2be handle varargin and varargout without keywords
John W. Eaton <jwe@octave.org>
parents: 7562
diff changeset
1192 ABORT_PARSE;
7336
745a8299c2b5 [project @ 2007-12-28 20:56:55 by jwe]
jwe
parents: 7017
diff changeset
1193 }
745a8299c2b5 [project @ 2007-12-28 20:56:55 by jwe]
jwe
parents: 7017
diff changeset
1194 | '[' return_list1 ']'
2970
b9e64477f703 [project @ 1997-05-15 18:04:21 by jwe]
jwe
parents: 2961
diff changeset
1195 {
b9e64477f703 [project @ 1997-05-15 18:04:21 by jwe]
jwe
parents: 2961
diff changeset
1196 lexer_flags.looking_at_return_list = false;
7587
1f662945c2be handle varargin and varargout without keywords
John W. Eaton <jwe@octave.org>
parents: 7562
diff changeset
1197 if ($2->validate (tree_parameter_list::out))
1f662945c2be handle varargin and varargout without keywords
John W. Eaton <jwe@octave.org>
parents: 7562
diff changeset
1198 $$ = $2;
1f662945c2be handle varargin and varargout without keywords
John W. Eaton <jwe@octave.org>
parents: 7562
diff changeset
1199 else
1f662945c2be handle varargin and varargout without keywords
John W. Eaton <jwe@octave.org>
parents: 7562
diff changeset
1200 ABORT_PARSE;
2970
b9e64477f703 [project @ 1997-05-15 18:04:21 by jwe]
jwe
parents: 2961
diff changeset
1201 }
b9e64477f703 [project @ 1997-05-15 18:04:21 by jwe]
jwe
parents: 2961
diff changeset
1202 ;
b9e64477f703 [project @ 1997-05-15 18:04:21 by jwe]
jwe
parents: 2961
diff changeset
1203
b9e64477f703 [project @ 1997-05-15 18:04:21 by jwe]
jwe
parents: 2961
diff changeset
1204 return_list1 : identifier
6215
516d3071b34c [project @ 2006-12-15 03:24:12 by jwe]
jwe
parents: 5975
diff changeset
1205 { $$ = new tree_parameter_list (new tree_decl_elt ($1)); }
2970
b9e64477f703 [project @ 1997-05-15 18:04:21 by jwe]
jwe
parents: 2961
diff changeset
1206 | return_list1 ',' identifier
b9e64477f703 [project @ 1997-05-15 18:04:21 by jwe]
jwe
parents: 2961
diff changeset
1207 {
6215
516d3071b34c [project @ 2006-12-15 03:24:12 by jwe]
jwe
parents: 5975
diff changeset
1208 $1->append (new tree_decl_elt ($3));
2970
b9e64477f703 [project @ 1997-05-15 18:04:21 by jwe]
jwe
parents: 2961
diff changeset
1209 $$ = $1;
b9e64477f703 [project @ 1997-05-15 18:04:21 by jwe]
jwe
parents: 2961
diff changeset
1210 }
b9e64477f703 [project @ 1997-05-15 18:04:21 by jwe]
jwe
parents: 2961
diff changeset
1211 ;
b9e64477f703 [project @ 1997-05-15 18:04:21 by jwe]
jwe
parents: 2961
diff changeset
1212
7715
5b4d278ec828 parse scripts completely before executing
John W. Eaton <jwe@octave.org>
parents: 7699
diff changeset
1213 // ===========
5b4d278ec828 parse scripts completely before executing
John W. Eaton <jwe@octave.org>
parents: 7699
diff changeset
1214 // Script file
5b4d278ec828 parse scripts completely before executing
John W. Eaton <jwe@octave.org>
parents: 7699
diff changeset
1215 // ===========
5b4d278ec828 parse scripts completely before executing
John W. Eaton <jwe@octave.org>
parents: 7699
diff changeset
1216
5b4d278ec828 parse scripts completely before executing
John W. Eaton <jwe@octave.org>
parents: 7699
diff changeset
1217 script : SCRIPT opt_list END_OF_INPUT
5b4d278ec828 parse scripts completely before executing
John W. Eaton <jwe@octave.org>
parents: 7699
diff changeset
1218 {
8658
73c4516fae10 New evaluator and debugger derived from tree-walker class
John W. Eaton <jwe@octave.org>
parents: 8471
diff changeset
1219 tree_statement *end_of_script
73c4516fae10 New evaluator and debugger derived from tree-walker class
John W. Eaton <jwe@octave.org>
parents: 8471
diff changeset
1220 = make_end ("endscript", input_line_number,
73c4516fae10 New evaluator and debugger derived from tree-walker class
John W. Eaton <jwe@octave.org>
parents: 8471
diff changeset
1221 current_input_column);
73c4516fae10 New evaluator and debugger derived from tree-walker class
John W. Eaton <jwe@octave.org>
parents: 8471
diff changeset
1222
73c4516fae10 New evaluator and debugger derived from tree-walker class
John W. Eaton <jwe@octave.org>
parents: 8471
diff changeset
1223 make_script ($2, end_of_script);
73c4516fae10 New evaluator and debugger derived from tree-walker class
John W. Eaton <jwe@octave.org>
parents: 8471
diff changeset
1224
7715
5b4d278ec828 parse scripts completely before executing
John W. Eaton <jwe@octave.org>
parents: 7699
diff changeset
1225 $$ = 0;
5b4d278ec828 parse scripts completely before executing
John W. Eaton <jwe@octave.org>
parents: 7699
diff changeset
1226 }
5b4d278ec828 parse scripts completely before executing
John W. Eaton <jwe@octave.org>
parents: 7699
diff changeset
1227 ;
5b4d278ec828 parse scripts completely before executing
John W. Eaton <jwe@octave.org>
parents: 7699
diff changeset
1228
2970
b9e64477f703 [project @ 1997-05-15 18:04:21 by jwe]
jwe
parents: 2961
diff changeset
1229 // ===================
b9e64477f703 [project @ 1997-05-15 18:04:21 by jwe]
jwe
parents: 2961
diff changeset
1230 // Function definition
b9e64477f703 [project @ 1997-05-15 18:04:21 by jwe]
jwe
parents: 2961
diff changeset
1231 // ===================
b9e64477f703 [project @ 1997-05-15 18:04:21 by jwe]
jwe
parents: 2961
diff changeset
1232
7336
745a8299c2b5 [project @ 2007-12-28 20:56:55 by jwe]
jwe
parents: 7017
diff changeset
1233 function_beg : push_fcn_symtab FCN stash_comment
745a8299c2b5 [project @ 2007-12-28 20:56:55 by jwe]
jwe
parents: 7017
diff changeset
1234 { $$ = $3; }
2970
b9e64477f703 [project @ 1997-05-15 18:04:21 by jwe]
jwe
parents: 2961
diff changeset
1235 ;
b9e64477f703 [project @ 1997-05-15 18:04:21 by jwe]
jwe
parents: 2961
diff changeset
1236
7336
745a8299c2b5 [project @ 2007-12-28 20:56:55 by jwe]
jwe
parents: 7017
diff changeset
1237 function : function_beg function1
2970
b9e64477f703 [project @ 1997-05-15 18:04:21 by jwe]
jwe
parents: 2961
diff changeset
1238 {
7715
5b4d278ec828 parse scripts completely before executing
John W. Eaton <jwe@octave.org>
parents: 7699
diff changeset
1239 $$ = finish_function (0, $2, $1);
2970
b9e64477f703 [project @ 1997-05-15 18:04:21 by jwe]
jwe
parents: 2961
diff changeset
1240 recover_from_parsing_function ();
b9e64477f703 [project @ 1997-05-15 18:04:21 by jwe]
jwe
parents: 2961
diff changeset
1241 }
7336
745a8299c2b5 [project @ 2007-12-28 20:56:55 by jwe]
jwe
parents: 7017
diff changeset
1242 | function_beg return_list '=' function1
2970
b9e64477f703 [project @ 1997-05-15 18:04:21 by jwe]
jwe
parents: 2961
diff changeset
1243 {
7715
5b4d278ec828 parse scripts completely before executing
John W. Eaton <jwe@octave.org>
parents: 7699
diff changeset
1244 $$ = finish_function ($2, $4, $1);
2970
b9e64477f703 [project @ 1997-05-15 18:04:21 by jwe]
jwe
parents: 2961
diff changeset
1245 recover_from_parsing_function ();
b9e64477f703 [project @ 1997-05-15 18:04:21 by jwe]
jwe
parents: 2961
diff changeset
1246 }
b9e64477f703 [project @ 1997-05-15 18:04:21 by jwe]
jwe
parents: 2961
diff changeset
1247 ;
b9e64477f703 [project @ 1997-05-15 18:04:21 by jwe]
jwe
parents: 2961
diff changeset
1248
7336
745a8299c2b5 [project @ 2007-12-28 20:56:55 by jwe]
jwe
parents: 7017
diff changeset
1249 fcn_name : identifier
2970
b9e64477f703 [project @ 1997-05-15 18:04:21 by jwe]
jwe
parents: 2961
diff changeset
1250 {
4238
a5a68c0afe56 [project @ 2002-12-25 21:04:33 by jwe]
jwe
parents: 4237
diff changeset
1251 std::string id_name = $1->name ();
a5a68c0afe56 [project @ 2002-12-25 21:04:33 by jwe]
jwe
parents: 4237
diff changeset
1252
a5a68c0afe56 [project @ 2002-12-25 21:04:33 by jwe]
jwe
parents: 4237
diff changeset
1253 if (reading_fcn_file
a5a68c0afe56 [project @ 2002-12-25 21:04:33 by jwe]
jwe
parents: 4237
diff changeset
1254 && ! lexer_flags.parsing_nested_function)
a5a68c0afe56 [project @ 2002-12-25 21:04:33 by jwe]
jwe
parents: 4237
diff changeset
1255 parent_function_name = (curr_fcn_file_name == id_name)
a5a68c0afe56 [project @ 2002-12-25 21:04:33 by jwe]
jwe
parents: 4237
diff changeset
1256 ? id_name : curr_fcn_file_name;
a5a68c0afe56 [project @ 2002-12-25 21:04:33 by jwe]
jwe
parents: 4237
diff changeset
1257
a5a68c0afe56 [project @ 2002-12-25 21:04:33 by jwe]
jwe
parents: 4237
diff changeset
1258 lexer_flags.parsed_function_name = true;
a5a68c0afe56 [project @ 2002-12-25 21:04:33 by jwe]
jwe
parents: 4237
diff changeset
1259
a5a68c0afe56 [project @ 2002-12-25 21:04:33 by jwe]
jwe
parents: 4237
diff changeset
1260 $$ = $1;
a5a68c0afe56 [project @ 2002-12-25 21:04:33 by jwe]
jwe
parents: 4237
diff changeset
1261 }
a5a68c0afe56 [project @ 2002-12-25 21:04:33 by jwe]
jwe
parents: 4237
diff changeset
1262 ;
a5a68c0afe56 [project @ 2002-12-25 21:04:33 by jwe]
jwe
parents: 4237
diff changeset
1263
7336
745a8299c2b5 [project @ 2007-12-28 20:56:55 by jwe]
jwe
parents: 7017
diff changeset
1264 function1 : fcn_name function2
4238
a5a68c0afe56 [project @ 2002-12-25 21:04:33 by jwe]
jwe
parents: 4237
diff changeset
1265 {
4872
fe71c458f438 [project @ 2004-04-21 20:09:32 by jwe]
jwe
parents: 4844
diff changeset
1266 std::string fname = $1->name ();
fe71c458f438 [project @ 2004-04-21 20:09:32 by jwe]
jwe
parents: 4844
diff changeset
1267
fe71c458f438 [project @ 2004-04-21 20:09:32 by jwe]
jwe
parents: 4844
diff changeset
1268 delete $1;
fe71c458f438 [project @ 2004-04-21 20:09:32 by jwe]
jwe
parents: 4844
diff changeset
1269
fe71c458f438 [project @ 2004-04-21 20:09:32 by jwe]
jwe
parents: 4844
diff changeset
1270 if (! ($$ = frob_function (fname, $2)))
2970
b9e64477f703 [project @ 1997-05-15 18:04:21 by jwe]
jwe
parents: 2961
diff changeset
1271 ABORT_PARSE;
b9e64477f703 [project @ 1997-05-15 18:04:21 by jwe]
jwe
parents: 2961
diff changeset
1272 }
b9e64477f703 [project @ 1997-05-15 18:04:21 by jwe]
jwe
parents: 2961
diff changeset
1273 ;
b9e64477f703 [project @ 1997-05-15 18:04:21 by jwe]
jwe
parents: 2961
diff changeset
1274
7336
745a8299c2b5 [project @ 2007-12-28 20:56:55 by jwe]
jwe
parents: 7017
diff changeset
1275 function2 : param_list opt_sep opt_list function_end
8658
73c4516fae10 New evaluator and debugger derived from tree-walker class
John W. Eaton <jwe@octave.org>
parents: 8471
diff changeset
1276 { $$ = start_function ($1, $3, $4); }
7336
745a8299c2b5 [project @ 2007-12-28 20:56:55 by jwe]
jwe
parents: 7017
diff changeset
1277 | opt_sep opt_list function_end
8658
73c4516fae10 New evaluator and debugger derived from tree-walker class
John W. Eaton <jwe@octave.org>
parents: 8471
diff changeset
1278 { $$ = start_function (0, $2, $3); }
2970
b9e64477f703 [project @ 1997-05-15 18:04:21 by jwe]
jwe
parents: 2961
diff changeset
1279 ;
b9e64477f703 [project @ 1997-05-15 18:04:21 by jwe]
jwe
parents: 2961
diff changeset
1280
b9e64477f703 [project @ 1997-05-15 18:04:21 by jwe]
jwe
parents: 2961
diff changeset
1281 function_end : END
b9e64477f703 [project @ 1997-05-15 18:04:21 by jwe]
jwe
parents: 2961
diff changeset
1282 {
8658
73c4516fae10 New evaluator and debugger derived from tree-walker class
John W. Eaton <jwe@octave.org>
parents: 8471
diff changeset
1283 if (end_token_ok ($1, token::function_end))
73c4516fae10 New evaluator and debugger derived from tree-walker class
John W. Eaton <jwe@octave.org>
parents: 8471
diff changeset
1284 $$ = make_end ("endfunction", $1->line (), $1->column ());
73c4516fae10 New evaluator and debugger derived from tree-walker class
John W. Eaton <jwe@octave.org>
parents: 8471
diff changeset
1285 else
2970
b9e64477f703 [project @ 1997-05-15 18:04:21 by jwe]
jwe
parents: 2961
diff changeset
1286 ABORT_PARSE;
b9e64477f703 [project @ 1997-05-15 18:04:21 by jwe]
jwe
parents: 2961
diff changeset
1287 }
b9e64477f703 [project @ 1997-05-15 18:04:21 by jwe]
jwe
parents: 2961
diff changeset
1288 | END_OF_INPUT
b9e64477f703 [project @ 1997-05-15 18:04:21 by jwe]
jwe
parents: 2961
diff changeset
1289 {
4240
8627d992beb8 [project @ 2002-12-25 23:07:03 by jwe]
jwe
parents: 4238
diff changeset
1290 if (lexer_flags.parsing_nested_function)
8627d992beb8 [project @ 2002-12-25 23:07:03 by jwe]
jwe
parents: 4238
diff changeset
1291 lexer_flags.parsing_nested_function = -1;
4238
a5a68c0afe56 [project @ 2002-12-25 21:04:33 by jwe]
jwe
parents: 4237
diff changeset
1292
8658
73c4516fae10 New evaluator and debugger derived from tree-walker class
John W. Eaton <jwe@octave.org>
parents: 8471
diff changeset
1293 if (reading_fcn_file || reading_script_file
73c4516fae10 New evaluator and debugger derived from tree-walker class
John W. Eaton <jwe@octave.org>
parents: 8471
diff changeset
1294 || get_input_from_eval_string)
73c4516fae10 New evaluator and debugger derived from tree-walker class
John W. Eaton <jwe@octave.org>
parents: 8471
diff changeset
1295 $$ = make_end ("endfunction", input_line_number,
73c4516fae10 New evaluator and debugger derived from tree-walker class
John W. Eaton <jwe@octave.org>
parents: 8471
diff changeset
1296 current_input_column);
73c4516fae10 New evaluator and debugger derived from tree-walker class
John W. Eaton <jwe@octave.org>
parents: 8471
diff changeset
1297 else
2970
b9e64477f703 [project @ 1997-05-15 18:04:21 by jwe]
jwe
parents: 2961
diff changeset
1298 YYABORT;
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 ;
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 // =============
b9e64477f703 [project @ 1997-05-15 18:04:21 by jwe]
jwe
parents: 2961
diff changeset
1303 // Miscellaneous
b9e64477f703 [project @ 1997-05-15 18:04:21 by jwe]
jwe
parents: 2961
diff changeset
1304 // =============
b9e64477f703 [project @ 1997-05-15 18:04:21 by jwe]
jwe
parents: 2961
diff changeset
1305
3665
0689afb1d001 [project @ 2000-05-11 19:07:56 by jwe]
jwe
parents: 3544
diff changeset
1306 stash_comment : // empty
0689afb1d001 [project @ 2000-05-11 19:07:56 by jwe]
jwe
parents: 3544
diff changeset
1307 { $$ = octave_comment_buffer::get_comment (); }
0689afb1d001 [project @ 2000-05-11 19:07:56 by jwe]
jwe
parents: 3544
diff changeset
1308 ;
0689afb1d001 [project @ 2000-05-11 19:07:56 by jwe]
jwe
parents: 3544
diff changeset
1309
2970
b9e64477f703 [project @ 1997-05-15 18:04:21 by jwe]
jwe
parents: 2961
diff changeset
1310 parse_error : LEXICAL_ERROR
b9e64477f703 [project @ 1997-05-15 18:04:21 by jwe]
jwe
parents: 2961
diff changeset
1311 { yyerror ("parse error"); }
b9e64477f703 [project @ 1997-05-15 18:04:21 by jwe]
jwe
parents: 2961
diff changeset
1312 | error
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
1313 ;
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
1314
2525
8561d88be5f2 [project @ 1996-11-17 21:23:31 by jwe]
jwe
parents: 2524
diff changeset
1315 sep_no_nl : ','
8561d88be5f2 [project @ 1996-11-17 21:23:31 by jwe]
jwe
parents: 2524
diff changeset
1316 { $$ = ','; }
8561d88be5f2 [project @ 1996-11-17 21:23:31 by jwe]
jwe
parents: 2524
diff changeset
1317 | ';'
8561d88be5f2 [project @ 1996-11-17 21:23:31 by jwe]
jwe
parents: 2524
diff changeset
1318 { $$ = ';'; }
8561d88be5f2 [project @ 1996-11-17 21:23:31 by jwe]
jwe
parents: 2524
diff changeset
1319 | sep_no_nl ','
8561d88be5f2 [project @ 1996-11-17 21:23:31 by jwe]
jwe
parents: 2524
diff changeset
1320 { $$ = $1; }
8561d88be5f2 [project @ 1996-11-17 21:23:31 by jwe]
jwe
parents: 2524
diff changeset
1321 | sep_no_nl ';'
8561d88be5f2 [project @ 1996-11-17 21:23:31 by jwe]
jwe
parents: 2524
diff changeset
1322 { $$ = $1; }
8561d88be5f2 [project @ 1996-11-17 21:23:31 by jwe]
jwe
parents: 2524
diff changeset
1323 ;
8561d88be5f2 [project @ 1996-11-17 21:23:31 by jwe]
jwe
parents: 2524
diff changeset
1324
8561d88be5f2 [project @ 1996-11-17 21:23:31 by jwe]
jwe
parents: 2524
diff changeset
1325 opt_sep_no_nl : // empty
8561d88be5f2 [project @ 1996-11-17 21:23:31 by jwe]
jwe
parents: 2524
diff changeset
1326 { $$ = 0; }
8561d88be5f2 [project @ 1996-11-17 21:23:31 by jwe]
jwe
parents: 2524
diff changeset
1327 | sep_no_nl
8561d88be5f2 [project @ 1996-11-17 21:23:31 by jwe]
jwe
parents: 2524
diff changeset
1328 { $$ = $1; }
8561d88be5f2 [project @ 1996-11-17 21:23:31 by jwe]
jwe
parents: 2524
diff changeset
1329 ;
8561d88be5f2 [project @ 1996-11-17 21:23:31 by jwe]
jwe
parents: 2524
diff changeset
1330
8561d88be5f2 [project @ 1996-11-17 21:23:31 by jwe]
jwe
parents: 2524
diff changeset
1331 sep : ','
8561d88be5f2 [project @ 1996-11-17 21:23:31 by jwe]
jwe
parents: 2524
diff changeset
1332 { $$ = ','; }
8561d88be5f2 [project @ 1996-11-17 21:23:31 by jwe]
jwe
parents: 2524
diff changeset
1333 | ';'
8561d88be5f2 [project @ 1996-11-17 21:23:31 by jwe]
jwe
parents: 2524
diff changeset
1334 { $$ = ';'; }
8561d88be5f2 [project @ 1996-11-17 21:23:31 by jwe]
jwe
parents: 2524
diff changeset
1335 | '\n'
8561d88be5f2 [project @ 1996-11-17 21:23:31 by jwe]
jwe
parents: 2524
diff changeset
1336 { $$ = '\n'; }
8561d88be5f2 [project @ 1996-11-17 21:23:31 by jwe]
jwe
parents: 2524
diff changeset
1337 | sep ','
8561d88be5f2 [project @ 1996-11-17 21:23:31 by jwe]
jwe
parents: 2524
diff changeset
1338 { $$ = $1; }
8561d88be5f2 [project @ 1996-11-17 21:23:31 by jwe]
jwe
parents: 2524
diff changeset
1339 | sep ';'
8561d88be5f2 [project @ 1996-11-17 21:23:31 by jwe]
jwe
parents: 2524
diff changeset
1340 { $$ = $1; }
8561d88be5f2 [project @ 1996-11-17 21:23:31 by jwe]
jwe
parents: 2524
diff changeset
1341 | sep '\n'
8561d88be5f2 [project @ 1996-11-17 21:23:31 by jwe]
jwe
parents: 2524
diff changeset
1342 { $$ = $1; }
8561d88be5f2 [project @ 1996-11-17 21:23:31 by jwe]
jwe
parents: 2524
diff changeset
1343 ;
8561d88be5f2 [project @ 1996-11-17 21:23:31 by jwe]
jwe
parents: 2524
diff changeset
1344
8561d88be5f2 [project @ 1996-11-17 21:23:31 by jwe]
jwe
parents: 2524
diff changeset
1345 opt_sep : // empty
8561d88be5f2 [project @ 1996-11-17 21:23:31 by jwe]
jwe
parents: 2524
diff changeset
1346 { $$ = 0; }
8561d88be5f2 [project @ 1996-11-17 21:23:31 by jwe]
jwe
parents: 2524
diff changeset
1347 | sep
8561d88be5f2 [project @ 1996-11-17 21:23:31 by jwe]
jwe
parents: 2524
diff changeset
1348 { $$ = $1; }
8561d88be5f2 [project @ 1996-11-17 21:23:31 by jwe]
jwe
parents: 2524
diff changeset
1349 ;
8561d88be5f2 [project @ 1996-11-17 21:23:31 by jwe]
jwe
parents: 2524
diff changeset
1350
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
1351 %%
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
1352
666
fb4f6556b443 [project @ 1994-09-06 21:22:46 by jwe]
jwe
parents: 627
diff changeset
1353 // Generic error messages.
fb4f6556b443 [project @ 1994-09-06 21:22:46 by jwe]
jwe
parents: 627
diff changeset
1354
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
1355 static void
2805
68e6d0c93fc8 [project @ 1997-03-11 04:52:44 by jwe]
jwe
parents: 2791
diff changeset
1356 yyerror (const char *s)
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
1357 {
143
7849db4b6dbc [project @ 1993-10-04 02:36:45 by jwe]
jwe
parents: 118
diff changeset
1358 int err_col = current_input_column - 1;
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
1359
5765
7ba9ad1fec11 [project @ 2006-04-17 05:05:15 by jwe]
jwe
parents: 5760
diff changeset
1360 std::ostringstream output_buf;
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
1361
1005
46a2983cb297 [project @ 1995-01-03 02:08:32 by jwe]
jwe
parents: 991
diff changeset
1362 if (reading_fcn_file || reading_script_file)
46a2983cb297 [project @ 1995-01-03 02:08:32 by jwe]
jwe
parents: 991
diff changeset
1363 output_buf << "parse error near line " << input_line_number
1607
795527e9db19 [project @ 1995-11-02 13:03:36 by jwe]
jwe
parents: 1588
diff changeset
1364 << " of file " << curr_fcn_file_full_name;
1005
46a2983cb297 [project @ 1995-01-03 02:08:32 by jwe]
jwe
parents: 991
diff changeset
1365 else
46a2983cb297 [project @ 1995-01-03 02:08:32 by jwe]
jwe
parents: 991
diff changeset
1366 output_buf << "parse error:";
581
bc813f5eb025 [project @ 1994-08-07 01:02:15 by jwe]
jwe
parents: 578
diff changeset
1367
1005
46a2983cb297 [project @ 1995-01-03 02:08:32 by jwe]
jwe
parents: 991
diff changeset
1368 if (s && strcmp (s, "parse error") != 0)
46a2983cb297 [project @ 1995-01-03 02:08:32 by jwe]
jwe
parents: 991
diff changeset
1369 output_buf << "\n\n " << s;
46a2983cb297 [project @ 1995-01-03 02:08:32 by jwe]
jwe
parents: 991
diff changeset
1370
46a2983cb297 [project @ 1995-01-03 02:08:32 by jwe]
jwe
parents: 991
diff changeset
1371 output_buf << "\n\n";
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
1372
1755
3a9462b655f1 [project @ 1996-01-22 04:47:22 by jwe]
jwe
parents: 1743
diff changeset
1373 if (! current_input_line.empty ())
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
1374 {
1755
3a9462b655f1 [project @ 1996-01-22 04:47:22 by jwe]
jwe
parents: 1743
diff changeset
1375 size_t len = current_input_line.length ();
1060
8c1a25cdfa81 [project @ 1995-01-23 00:10:03 by jwe]
jwe
parents: 1054
diff changeset
1376
1755
3a9462b655f1 [project @ 1996-01-22 04:47:22 by jwe]
jwe
parents: 1743
diff changeset
1377 if (current_input_line[len-1] == '\n')
3a9462b655f1 [project @ 1996-01-22 04:47:22 by jwe]
jwe
parents: 1743
diff changeset
1378 current_input_line.resize (len-1);
1005
46a2983cb297 [project @ 1995-01-03 02:08:32 by jwe]
jwe
parents: 991
diff changeset
1379
4051
b79da8779a0e [project @ 2002-08-17 19:38:32 by jwe]
jwe
parents: 4044
diff changeset
1380 // Print the line, maybe with a pointer near the error token.
1005
46a2983cb297 [project @ 1995-01-03 02:08:32 by jwe]
jwe
parents: 991
diff changeset
1381
1755
3a9462b655f1 [project @ 1996-01-22 04:47:22 by jwe]
jwe
parents: 1743
diff changeset
1382 output_buf << ">>> " << current_input_line << "\n";
1060
8c1a25cdfa81 [project @ 1995-01-23 00:10:03 by jwe]
jwe
parents: 1054
diff changeset
1383
8c1a25cdfa81 [project @ 1995-01-23 00:10:03 by jwe]
jwe
parents: 1054
diff changeset
1384 if (err_col == 0)
8c1a25cdfa81 [project @ 1995-01-23 00:10:03 by jwe]
jwe
parents: 1054
diff changeset
1385 err_col = len;
8c1a25cdfa81 [project @ 1995-01-23 00:10:03 by jwe]
jwe
parents: 1054
diff changeset
1386
8c1a25cdfa81 [project @ 1995-01-23 00:10:03 by jwe]
jwe
parents: 1054
diff changeset
1387 for (int i = 0; i < err_col + 3; i++)
8c1a25cdfa81 [project @ 1995-01-23 00:10:03 by jwe]
jwe
parents: 1054
diff changeset
1388 output_buf << " ";
8c1a25cdfa81 [project @ 1995-01-23 00:10:03 by jwe]
jwe
parents: 1054
diff changeset
1389
8c1a25cdfa81 [project @ 1995-01-23 00:10:03 by jwe]
jwe
parents: 1054
diff changeset
1390 output_buf << "^";
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
1391 }
1005
46a2983cb297 [project @ 1995-01-03 02:08:32 by jwe]
jwe
parents: 991
diff changeset
1392
5765
7ba9ad1fec11 [project @ 2006-04-17 05:05:15 by jwe]
jwe
parents: 5760
diff changeset
1393 output_buf << "\n";
7ba9ad1fec11 [project @ 2006-04-17 05:05:15 by jwe]
jwe
parents: 5760
diff changeset
1394
7ba9ad1fec11 [project @ 2006-04-17 05:05:15 by jwe]
jwe
parents: 5760
diff changeset
1395 std::string msg = output_buf.str ();
7ba9ad1fec11 [project @ 2006-04-17 05:05:15 by jwe]
jwe
parents: 5760
diff changeset
1396
7ba9ad1fec11 [project @ 2006-04-17 05:05:15 by jwe]
jwe
parents: 5760
diff changeset
1397 parse_error ("%s", msg.c_str ());
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
1398 }
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
1399
666
fb4f6556b443 [project @ 1994-09-06 21:22:46 by jwe]
jwe
parents: 627
diff changeset
1400 // Error mesages for mismatched end tokens.
fb4f6556b443 [project @ 1994-09-06 21:22:46 by jwe]
jwe
parents: 627
diff changeset
1401
496
e7c5b23b34d3 [project @ 1994-07-06 15:02:26 by jwe]
jwe
parents: 482
diff changeset
1402 static void
2805
68e6d0c93fc8 [project @ 1997-03-11 04:52:44 by jwe]
jwe
parents: 2791
diff changeset
1403 end_error (const char *type, token::end_tok_type ettype, int l, int c)
496
e7c5b23b34d3 [project @ 1994-07-06 15:02:26 by jwe]
jwe
parents: 482
diff changeset
1404 {
2805
68e6d0c93fc8 [project @ 1997-03-11 04:52:44 by jwe]
jwe
parents: 2791
diff changeset
1405 static const char *fmt
68e6d0c93fc8 [project @ 1997-03-11 04:52:44 by jwe]
jwe
parents: 2791
diff changeset
1406 = "`%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
1407
e7c5b23b34d3 [project @ 1994-07-06 15:02:26 by jwe]
jwe
parents: 482
diff changeset
1408 switch (ettype)
e7c5b23b34d3 [project @ 1994-07-06 15:02:26 by jwe]
jwe
parents: 482
diff changeset
1409 {
e7c5b23b34d3 [project @ 1994-07-06 15:02:26 by jwe]
jwe
parents: 482
diff changeset
1410 case token::simple_end:
e7c5b23b34d3 [project @ 1994-07-06 15:02:26 by jwe]
jwe
parents: 482
diff changeset
1411 error (fmt, type, "end", l, c);
e7c5b23b34d3 [project @ 1994-07-06 15:02:26 by jwe]
jwe
parents: 482
diff changeset
1412 break;
777
a2f9d3fd720c [project @ 1994-10-07 14:01:53 by jwe]
jwe
parents: 773
diff changeset
1413
496
e7c5b23b34d3 [project @ 1994-07-06 15:02:26 by jwe]
jwe
parents: 482
diff changeset
1414 case token::for_end:
e7c5b23b34d3 [project @ 1994-07-06 15:02:26 by jwe]
jwe
parents: 482
diff changeset
1415 error (fmt, type, "endfor", l, c);
e7c5b23b34d3 [project @ 1994-07-06 15:02:26 by jwe]
jwe
parents: 482
diff changeset
1416 break;
777
a2f9d3fd720c [project @ 1994-10-07 14:01:53 by jwe]
jwe
parents: 773
diff changeset
1417
496
e7c5b23b34d3 [project @ 1994-07-06 15:02:26 by jwe]
jwe
parents: 482
diff changeset
1418 case token::function_end:
e7c5b23b34d3 [project @ 1994-07-06 15:02:26 by jwe]
jwe
parents: 482
diff changeset
1419 error (fmt, type, "endfunction", l, c);
e7c5b23b34d3 [project @ 1994-07-06 15:02:26 by jwe]
jwe
parents: 482
diff changeset
1420 break;
777
a2f9d3fd720c [project @ 1994-10-07 14:01:53 by jwe]
jwe
parents: 773
diff changeset
1421
496
e7c5b23b34d3 [project @ 1994-07-06 15:02:26 by jwe]
jwe
parents: 482
diff changeset
1422 case token::if_end:
e7c5b23b34d3 [project @ 1994-07-06 15:02:26 by jwe]
jwe
parents: 482
diff changeset
1423 error (fmt, type, "endif", l, c);
e7c5b23b34d3 [project @ 1994-07-06 15:02:26 by jwe]
jwe
parents: 482
diff changeset
1424 break;
777
a2f9d3fd720c [project @ 1994-10-07 14:01:53 by jwe]
jwe
parents: 773
diff changeset
1425
3233
98d0ee053ba4 [project @ 1999-01-27 20:23:40 by jwe]
jwe
parents: 3216
diff changeset
1426 case token::switch_end:
98d0ee053ba4 [project @ 1999-01-27 20:23:40 by jwe]
jwe
parents: 3216
diff changeset
1427 error (fmt, type, "endswitch", l, c);
98d0ee053ba4 [project @ 1999-01-27 20:23:40 by jwe]
jwe
parents: 3216
diff changeset
1428 break;
98d0ee053ba4 [project @ 1999-01-27 20:23:40 by jwe]
jwe
parents: 3216
diff changeset
1429
496
e7c5b23b34d3 [project @ 1994-07-06 15:02:26 by jwe]
jwe
parents: 482
diff changeset
1430 case token::while_end:
e7c5b23b34d3 [project @ 1994-07-06 15:02:26 by jwe]
jwe
parents: 482
diff changeset
1431 error (fmt, type, "endwhile", l, c);
e7c5b23b34d3 [project @ 1994-07-06 15:02:26 by jwe]
jwe
parents: 482
diff changeset
1432 break;
777
a2f9d3fd720c [project @ 1994-10-07 14:01:53 by jwe]
jwe
parents: 773
diff changeset
1433
5400
c7e3cf2fce3e [project @ 2005-07-05 15:01:32 by jwe]
jwe
parents: 5397
diff changeset
1434 case token::try_catch_end:
c7e3cf2fce3e [project @ 2005-07-05 15:01:32 by jwe]
jwe
parents: 5397
diff changeset
1435 error (fmt, type, "end_try_catch", l, c);
c7e3cf2fce3e [project @ 2005-07-05 15:01:32 by jwe]
jwe
parents: 5397
diff changeset
1436 break;
c7e3cf2fce3e [project @ 2005-07-05 15:01:32 by jwe]
jwe
parents: 5397
diff changeset
1437
1371
766af9ca8edb [project @ 1995-09-06 21:36:02 by jwe]
jwe
parents: 1351
diff changeset
1438 case token::unwind_protect_end:
766af9ca8edb [project @ 1995-09-06 21:36:02 by jwe]
jwe
parents: 1351
diff changeset
1439 error (fmt, type, "end_unwind_protect", l, c);
766af9ca8edb [project @ 1995-09-06 21:36:02 by jwe]
jwe
parents: 1351
diff changeset
1440 break;
766af9ca8edb [project @ 1995-09-06 21:36:02 by jwe]
jwe
parents: 1351
diff changeset
1441
496
e7c5b23b34d3 [project @ 1994-07-06 15:02:26 by jwe]
jwe
parents: 482
diff changeset
1442 default:
e7c5b23b34d3 [project @ 1994-07-06 15:02:26 by jwe]
jwe
parents: 482
diff changeset
1443 panic_impossible ();
e7c5b23b34d3 [project @ 1994-07-06 15:02:26 by jwe]
jwe
parents: 482
diff changeset
1444 break;
e7c5b23b34d3 [project @ 1994-07-06 15:02:26 by jwe]
jwe
parents: 482
diff changeset
1445 }
e7c5b23b34d3 [project @ 1994-07-06 15:02:26 by jwe]
jwe
parents: 482
diff changeset
1446 }
e7c5b23b34d3 [project @ 1994-07-06 15:02:26 by jwe]
jwe
parents: 482
diff changeset
1447
666
fb4f6556b443 [project @ 1994-09-06 21:22:46 by jwe]
jwe
parents: 627
diff changeset
1448 // Check to see that end tokens are properly matched.
fb4f6556b443 [project @ 1994-09-06 21:22:46 by jwe]
jwe
parents: 627
diff changeset
1449
2857
5448c8cba402 [project @ 1997-03-31 07:06:10 by jwe]
jwe
parents: 2856
diff changeset
1450 static bool
5448c8cba402 [project @ 1997-03-31 07:06:10 by jwe]
jwe
parents: 2856
diff changeset
1451 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
1452 {
2857
5448c8cba402 [project @ 1997-03-31 07:06:10 by jwe]
jwe
parents: 2856
diff changeset
1453 bool retval = true;
5448c8cba402 [project @ 1997-03-31 07:06:10 by jwe]
jwe
parents: 2856
diff changeset
1454
143
7849db4b6dbc [project @ 1993-10-04 02:36:45 by jwe]
jwe
parents: 118
diff changeset
1455 token::end_tok_type ettype = tok->ettype ();
2857
5448c8cba402 [project @ 1997-03-31 07:06:10 by jwe]
jwe
parents: 2856
diff changeset
1456
143
7849db4b6dbc [project @ 1993-10-04 02:36:45 by jwe]
jwe
parents: 118
diff changeset
1457 if (ettype != expected && ettype != token::simple_end)
7849db4b6dbc [project @ 1993-10-04 02:36:45 by jwe]
jwe
parents: 118
diff changeset
1458 {
2857
5448c8cba402 [project @ 1997-03-31 07:06:10 by jwe]
jwe
parents: 2856
diff changeset
1459 retval = false;
5448c8cba402 [project @ 1997-03-31 07:06:10 by jwe]
jwe
parents: 2856
diff changeset
1460
143
7849db4b6dbc [project @ 1993-10-04 02:36:45 by jwe]
jwe
parents: 118
diff changeset
1461 yyerror ("parse error");
7849db4b6dbc [project @ 1993-10-04 02:36:45 by jwe]
jwe
parents: 118
diff changeset
1462
7849db4b6dbc [project @ 1993-10-04 02:36:45 by jwe]
jwe
parents: 118
diff changeset
1463 int l = tok->line ();
7849db4b6dbc [project @ 1993-10-04 02:36:45 by jwe]
jwe
parents: 118
diff changeset
1464 int c = tok->column ();
7849db4b6dbc [project @ 1993-10-04 02:36:45 by jwe]
jwe
parents: 118
diff changeset
1465
7849db4b6dbc [project @ 1993-10-04 02:36:45 by jwe]
jwe
parents: 118
diff changeset
1466 switch (expected)
7849db4b6dbc [project @ 1993-10-04 02:36:45 by jwe]
jwe
parents: 118
diff changeset
1467 {
7849db4b6dbc [project @ 1993-10-04 02:36:45 by jwe]
jwe
parents: 118
diff changeset
1468 case token::for_end:
7849db4b6dbc [project @ 1993-10-04 02:36:45 by jwe]
jwe
parents: 118
diff changeset
1469 end_error ("for", ettype, l, c);
7849db4b6dbc [project @ 1993-10-04 02:36:45 by jwe]
jwe
parents: 118
diff changeset
1470 break;
777
a2f9d3fd720c [project @ 1994-10-07 14:01:53 by jwe]
jwe
parents: 773
diff changeset
1471
143
7849db4b6dbc [project @ 1993-10-04 02:36:45 by jwe]
jwe
parents: 118
diff changeset
1472 case token::function_end:
7849db4b6dbc [project @ 1993-10-04 02:36:45 by jwe]
jwe
parents: 118
diff changeset
1473 end_error ("function", ettype, l, c);
7849db4b6dbc [project @ 1993-10-04 02:36:45 by jwe]
jwe
parents: 118
diff changeset
1474 break;
777
a2f9d3fd720c [project @ 1994-10-07 14:01:53 by jwe]
jwe
parents: 773
diff changeset
1475
143
7849db4b6dbc [project @ 1993-10-04 02:36:45 by jwe]
jwe
parents: 118
diff changeset
1476 case token::if_end:
7849db4b6dbc [project @ 1993-10-04 02:36:45 by jwe]
jwe
parents: 118
diff changeset
1477 end_error ("if", ettype, l, c);
7849db4b6dbc [project @ 1993-10-04 02:36:45 by jwe]
jwe
parents: 118
diff changeset
1478 break;
777
a2f9d3fd720c [project @ 1994-10-07 14:01:53 by jwe]
jwe
parents: 773
diff changeset
1479
1489
3e705c864019 [project @ 1995-09-28 05:38:26 by jwe]
jwe
parents: 1371
diff changeset
1480 case token::try_catch_end:
3e705c864019 [project @ 1995-09-28 05:38:26 by jwe]
jwe
parents: 1371
diff changeset
1481 end_error ("try", ettype, l, c);
3e705c864019 [project @ 1995-09-28 05:38:26 by jwe]
jwe
parents: 1371
diff changeset
1482 break;
3e705c864019 [project @ 1995-09-28 05:38:26 by jwe]
jwe
parents: 1371
diff changeset
1483
2764
2c0f259cf83d [project @ 1997-03-01 02:30:26 by jwe]
jwe
parents: 2745
diff changeset
1484 case token::switch_end:
2c0f259cf83d [project @ 1997-03-01 02:30:26 by jwe]
jwe
parents: 2745
diff changeset
1485 end_error ("switch", ettype, l, c);
2c0f259cf83d [project @ 1997-03-01 02:30:26 by jwe]
jwe
parents: 2745
diff changeset
1486 break;
2c0f259cf83d [project @ 1997-03-01 02:30:26 by jwe]
jwe
parents: 2745
diff changeset
1487
1489
3e705c864019 [project @ 1995-09-28 05:38:26 by jwe]
jwe
parents: 1371
diff changeset
1488 case token::unwind_protect_end:
3e705c864019 [project @ 1995-09-28 05:38:26 by jwe]
jwe
parents: 1371
diff changeset
1489 end_error ("unwind_protect", ettype, l, c);
3e705c864019 [project @ 1995-09-28 05:38:26 by jwe]
jwe
parents: 1371
diff changeset
1490 break;
3e705c864019 [project @ 1995-09-28 05:38:26 by jwe]
jwe
parents: 1371
diff changeset
1491
143
7849db4b6dbc [project @ 1993-10-04 02:36:45 by jwe]
jwe
parents: 118
diff changeset
1492 case token::while_end:
7849db4b6dbc [project @ 1993-10-04 02:36:45 by jwe]
jwe
parents: 118
diff changeset
1493 end_error ("while", ettype, l, c);
7849db4b6dbc [project @ 1993-10-04 02:36:45 by jwe]
jwe
parents: 118
diff changeset
1494 break;
777
a2f9d3fd720c [project @ 1994-10-07 14:01:53 by jwe]
jwe
parents: 773
diff changeset
1495
143
7849db4b6dbc [project @ 1993-10-04 02:36:45 by jwe]
jwe
parents: 118
diff changeset
1496 default:
7849db4b6dbc [project @ 1993-10-04 02:36:45 by jwe]
jwe
parents: 118
diff changeset
1497 panic_impossible ();
7849db4b6dbc [project @ 1993-10-04 02:36:45 by jwe]
jwe
parents: 118
diff changeset
1498 break;
7849db4b6dbc [project @ 1993-10-04 02:36:45 by jwe]
jwe
parents: 118
diff changeset
1499 }
7849db4b6dbc [project @ 1993-10-04 02:36:45 by jwe]
jwe
parents: 118
diff changeset
1500 }
2857
5448c8cba402 [project @ 1997-03-31 07:06:10 by jwe]
jwe
parents: 2856
diff changeset
1501
5448c8cba402 [project @ 1997-03-31 07:06:10 by jwe]
jwe
parents: 2856
diff changeset
1502 return retval;
143
7849db4b6dbc [project @ 1993-10-04 02:36:45 by jwe]
jwe
parents: 118
diff changeset
1503 }
7849db4b6dbc [project @ 1993-10-04 02:36:45 by jwe]
jwe
parents: 118
diff changeset
1504
666
fb4f6556b443 [project @ 1994-09-06 21:22:46 by jwe]
jwe
parents: 627
diff changeset
1505 // 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
1506 // test in a logical expression.
fb4f6556b443 [project @ 1994-09-06 21:22:46 by jwe]
jwe
parents: 627
diff changeset
1507
496
e7c5b23b34d3 [project @ 1994-07-06 15:02:26 by jwe]
jwe
parents: 482
diff changeset
1508 static void
e7c5b23b34d3 [project @ 1994-07-06 15:02:26 by jwe]
jwe
parents: 482
diff changeset
1509 maybe_warn_assign_as_truth_value (tree_expression *expr)
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
1510 {
5781
faafc2d98b8d [project @ 2006-05-02 19:40:19 by jwe]
jwe
parents: 5775
diff changeset
1511 if (expr->is_assignment_expression ()
2961
8a77d52c9d02 [project @ 1997-05-12 01:36:04 by jwe]
jwe
parents: 2960
diff changeset
1512 && expr->paren_count () < 2)
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
1513 {
5781
faafc2d98b8d [project @ 2006-05-02 19:40:19 by jwe]
jwe
parents: 5775
diff changeset
1514 warning_with_id
faafc2d98b8d [project @ 2006-05-02 19:40:19 by jwe]
jwe
parents: 5775
diff changeset
1515 ("Octave:assign-as-truth-value",
faafc2d98b8d [project @ 2006-05-02 19:40:19 by jwe]
jwe
parents: 5775
diff changeset
1516 "suggest parenthesis around assignment used as truth value");
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
1517 }
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
1518 }
578
d169be9237fb [project @ 1994-08-03 20:06:54 by jwe]
jwe
parents: 572
diff changeset
1519
2764
2c0f259cf83d [project @ 1997-03-01 02:30:26 by jwe]
jwe
parents: 2745
diff changeset
1520 // 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
1521
2c0f259cf83d [project @ 1997-03-01 02:30:26 by jwe]
jwe
parents: 2745
diff changeset
1522 static void
2c0f259cf83d [project @ 1997-03-01 02:30:26 by jwe]
jwe
parents: 2745
diff changeset
1523 maybe_warn_variable_switch_label (tree_expression *expr)
2c0f259cf83d [project @ 1997-03-01 02:30:26 by jwe]
jwe
parents: 2745
diff changeset
1524 {
5781
faafc2d98b8d [project @ 2006-05-02 19:40:19 by jwe]
jwe
parents: 5775
diff changeset
1525 if (! expr->is_constant ())
5878
27771d9cd4f4 [project @ 2006-07-02 18:45:11 by jwe]
jwe
parents: 5875
diff changeset
1526 warning_with_id ("Octave:variable-switch-label",
5781
faafc2d98b8d [project @ 2006-05-02 19:40:19 by jwe]
jwe
parents: 5775
diff changeset
1527 "variable switch label");
2764
2c0f259cf83d [project @ 1997-03-01 02:30:26 by jwe]
jwe
parents: 2745
diff changeset
1528 }
2c0f259cf83d [project @ 1997-03-01 02:30:26 by jwe]
jwe
parents: 2745
diff changeset
1529
2533
987e934bbb8c [project @ 1996-11-19 18:21:23 by jwe]
jwe
parents: 2525
diff changeset
1530 static tree_expression *
987e934bbb8c [project @ 1996-11-19 18:21:23 by jwe]
jwe
parents: 2525
diff changeset
1531 fold (tree_binary_expression *e)
987e934bbb8c [project @ 1996-11-19 18:21:23 by jwe]
jwe
parents: 2525
diff changeset
1532 {
3110
fe2d1ae8926b [project @ 1997-11-21 02:11:19 by jwe]
jwe
parents: 3099
diff changeset
1533 tree_expression *retval = e;
fe2d1ae8926b [project @ 1997-11-21 02:11:19 by jwe]
jwe
parents: 3099
diff changeset
1534
3292
ad0d250ebd7e [project @ 1999-10-14 22:52:28 by jwe]
jwe
parents: 3258
diff changeset
1535 unwind_protect::begin_frame ("fold_binary_expression");
3110
fe2d1ae8926b [project @ 1997-11-21 02:11:19 by jwe]
jwe
parents: 3099
diff changeset
1536
fe2d1ae8926b [project @ 1997-11-21 02:11:19 by jwe]
jwe
parents: 3099
diff changeset
1537 unwind_protect_int (error_state);
4452
f3c21a1d1c62 [project @ 2003-07-09 23:20:18 by jwe]
jwe
parents: 4426
diff changeset
1538 unwind_protect_int (warning_state);
3110
fe2d1ae8926b [project @ 1997-11-21 02:11:19 by jwe]
jwe
parents: 3099
diff changeset
1539
3815
c554ad71bafc [project @ 2001-04-19 19:50:52 by jwe]
jwe
parents: 3802
diff changeset
1540 unwind_protect_bool (discard_error_messages);
4452
f3c21a1d1c62 [project @ 2003-07-09 23:20:18 by jwe]
jwe
parents: 4426
diff changeset
1541 unwind_protect_bool (discard_warning_messages);
f3c21a1d1c62 [project @ 2003-07-09 23:20:18 by jwe]
jwe
parents: 4426
diff changeset
1542
3815
c554ad71bafc [project @ 2001-04-19 19:50:52 by jwe]
jwe
parents: 3802
diff changeset
1543 discard_error_messages = true;
4452
f3c21a1d1c62 [project @ 2003-07-09 23:20:18 by jwe]
jwe
parents: 4426
diff changeset
1544 discard_warning_messages = true;
2533
987e934bbb8c [project @ 1996-11-19 18:21:23 by jwe]
jwe
parents: 2525
diff changeset
1545
987e934bbb8c [project @ 1996-11-19 18:21:23 by jwe]
jwe
parents: 2525
diff changeset
1546 tree_expression *op1 = e->lhs ();
987e934bbb8c [project @ 1996-11-19 18:21:23 by jwe]
jwe
parents: 2525
diff changeset
1547 tree_expression *op2 = e->rhs ();
987e934bbb8c [project @ 1996-11-19 18:21:23 by jwe]
jwe
parents: 2525
diff changeset
1548
5161
3cdcddfab90b [project @ 2005-02-23 16:44:59 by jwe]
jwe
parents: 5160
diff changeset
1549 octave_value::binary_op op_type = e->op_type ();
3cdcddfab90b [project @ 2005-02-23 16:44:59 by jwe]
jwe
parents: 5160
diff changeset
1550
3cdcddfab90b [project @ 2005-02-23 16:44:59 by jwe]
jwe
parents: 5160
diff changeset
1551 if (op1->is_constant () && op2->is_constant ()
5781
faafc2d98b8d [project @ 2006-05-02 19:40:19 by jwe]
jwe
parents: 5775
diff changeset
1552 && (! ((warning_enabled ("Octave:associativity-change")
5161
3cdcddfab90b [project @ 2005-02-23 16:44:59 by jwe]
jwe
parents: 5160
diff changeset
1553 && (op_type == POW || op_type == EPOW))
5781
faafc2d98b8d [project @ 2006-05-02 19:40:19 by jwe]
jwe
parents: 5775
diff changeset
1554 || (warning_enabled ("Octave:precedence-change")
5161
3cdcddfab90b [project @ 2005-02-23 16:44:59 by jwe]
jwe
parents: 5160
diff changeset
1555 && (op_type == EXPR_OR || op_type == EXPR_OR_OR)))))
2533
987e934bbb8c [project @ 1996-11-19 18:21:23 by jwe]
jwe
parents: 2525
diff changeset
1556 {
8658
73c4516fae10 New evaluator and debugger derived from tree-walker class
John W. Eaton <jwe@octave.org>
parents: 8471
diff changeset
1557 octave_value tmp = e->rvalue1 ();
2533
987e934bbb8c [project @ 1996-11-19 18:21:23 by jwe]
jwe
parents: 2525
diff changeset
1558
3489
cbee5fbb696d [project @ 2000-01-28 09:14:32 by jwe]
jwe
parents: 3485
diff changeset
1559 if (! (error_state || warning_state))
2533
987e934bbb8c [project @ 1996-11-19 18:21:23 by jwe]
jwe
parents: 2525
diff changeset
1560 {
8658
73c4516fae10 New evaluator and debugger derived from tree-walker class
John W. Eaton <jwe@octave.org>
parents: 8471
diff changeset
1561 tree_constant *tc_retval
73c4516fae10 New evaluator and debugger derived from tree-walker class
John W. Eaton <jwe@octave.org>
parents: 8471
diff changeset
1562 = new tree_constant (tmp, op1->line (), op1->column ());
2533
987e934bbb8c [project @ 1996-11-19 18:21:23 by jwe]
jwe
parents: 2525
diff changeset
1563
5765
7ba9ad1fec11 [project @ 2006-04-17 05:05:15 by jwe]
jwe
parents: 5760
diff changeset
1564 std::ostringstream buf;
2533
987e934bbb8c [project @ 1996-11-19 18:21:23 by jwe]
jwe
parents: 2525
diff changeset
1565
987e934bbb8c [project @ 1996-11-19 18:21:23 by jwe]
jwe
parents: 2525
diff changeset
1566 tree_print_code tpc (buf);
987e934bbb8c [project @ 1996-11-19 18:21:23 by jwe]
jwe
parents: 2525
diff changeset
1567
987e934bbb8c [project @ 1996-11-19 18:21:23 by jwe]
jwe
parents: 2525
diff changeset
1568 e->accept (tpc);
987e934bbb8c [project @ 1996-11-19 18:21:23 by jwe]
jwe
parents: 2525
diff changeset
1569
5765
7ba9ad1fec11 [project @ 2006-04-17 05:05:15 by jwe]
jwe
parents: 5760
diff changeset
1570 tc_retval->stash_original_text (buf.str ());
2533
987e934bbb8c [project @ 1996-11-19 18:21:23 by jwe]
jwe
parents: 2525
diff changeset
1571
987e934bbb8c [project @ 1996-11-19 18:21:23 by jwe]
jwe
parents: 2525
diff changeset
1572 delete e;
987e934bbb8c [project @ 1996-11-19 18:21:23 by jwe]
jwe
parents: 2525
diff changeset
1573
987e934bbb8c [project @ 1996-11-19 18:21:23 by jwe]
jwe
parents: 2525
diff changeset
1574 retval = tc_retval;
987e934bbb8c [project @ 1996-11-19 18:21:23 by jwe]
jwe
parents: 2525
diff changeset
1575 }
987e934bbb8c [project @ 1996-11-19 18:21:23 by jwe]
jwe
parents: 2525
diff changeset
1576 }
3110
fe2d1ae8926b [project @ 1997-11-21 02:11:19 by jwe]
jwe
parents: 3099
diff changeset
1577
3292
ad0d250ebd7e [project @ 1999-10-14 22:52:28 by jwe]
jwe
parents: 3258
diff changeset
1578 unwind_protect::run_frame ("fold_binary_expression");
ad0d250ebd7e [project @ 1999-10-14 22:52:28 by jwe]
jwe
parents: 3258
diff changeset
1579
ad0d250ebd7e [project @ 1999-10-14 22:52:28 by jwe]
jwe
parents: 3258
diff changeset
1580 return retval;
ad0d250ebd7e [project @ 1999-10-14 22:52:28 by jwe]
jwe
parents: 3258
diff changeset
1581 }
ad0d250ebd7e [project @ 1999-10-14 22:52:28 by jwe]
jwe
parents: 3258
diff changeset
1582
ad0d250ebd7e [project @ 1999-10-14 22:52:28 by jwe]
jwe
parents: 3258
diff changeset
1583 static tree_expression *
ad0d250ebd7e [project @ 1999-10-14 22:52:28 by jwe]
jwe
parents: 3258
diff changeset
1584 fold (tree_unary_expression *e)
ad0d250ebd7e [project @ 1999-10-14 22:52:28 by jwe]
jwe
parents: 3258
diff changeset
1585 {
ad0d250ebd7e [project @ 1999-10-14 22:52:28 by jwe]
jwe
parents: 3258
diff changeset
1586 tree_expression *retval = e;
ad0d250ebd7e [project @ 1999-10-14 22:52:28 by jwe]
jwe
parents: 3258
diff changeset
1587
ad0d250ebd7e [project @ 1999-10-14 22:52:28 by jwe]
jwe
parents: 3258
diff changeset
1588 unwind_protect::begin_frame ("fold_unary_expression");
ad0d250ebd7e [project @ 1999-10-14 22:52:28 by jwe]
jwe
parents: 3258
diff changeset
1589
ad0d250ebd7e [project @ 1999-10-14 22:52:28 by jwe]
jwe
parents: 3258
diff changeset
1590 unwind_protect_int (error_state);
4452
f3c21a1d1c62 [project @ 2003-07-09 23:20:18 by jwe]
jwe
parents: 4426
diff changeset
1591 unwind_protect_int (warning_state);
3292
ad0d250ebd7e [project @ 1999-10-14 22:52:28 by jwe]
jwe
parents: 3258
diff changeset
1592
3815
c554ad71bafc [project @ 2001-04-19 19:50:52 by jwe]
jwe
parents: 3802
diff changeset
1593 unwind_protect_bool (discard_error_messages);
4452
f3c21a1d1c62 [project @ 2003-07-09 23:20:18 by jwe]
jwe
parents: 4426
diff changeset
1594 unwind_protect_bool (discard_warning_messages);
f3c21a1d1c62 [project @ 2003-07-09 23:20:18 by jwe]
jwe
parents: 4426
diff changeset
1595
3815
c554ad71bafc [project @ 2001-04-19 19:50:52 by jwe]
jwe
parents: 3802
diff changeset
1596 discard_error_messages = true;
4452
f3c21a1d1c62 [project @ 2003-07-09 23:20:18 by jwe]
jwe
parents: 4426
diff changeset
1597 discard_warning_messages = true;
3292
ad0d250ebd7e [project @ 1999-10-14 22:52:28 by jwe]
jwe
parents: 3258
diff changeset
1598
ad0d250ebd7e [project @ 1999-10-14 22:52:28 by jwe]
jwe
parents: 3258
diff changeset
1599 tree_expression *op = e->operand ();
ad0d250ebd7e [project @ 1999-10-14 22:52:28 by jwe]
jwe
parents: 3258
diff changeset
1600
ad0d250ebd7e [project @ 1999-10-14 22:52:28 by jwe]
jwe
parents: 3258
diff changeset
1601 if (op->is_constant ())
ad0d250ebd7e [project @ 1999-10-14 22:52:28 by jwe]
jwe
parents: 3258
diff changeset
1602 {
8658
73c4516fae10 New evaluator and debugger derived from tree-walker class
John W. Eaton <jwe@octave.org>
parents: 8471
diff changeset
1603 octave_value tmp = e->rvalue1 ();
3292
ad0d250ebd7e [project @ 1999-10-14 22:52:28 by jwe]
jwe
parents: 3258
diff changeset
1604
3489
cbee5fbb696d [project @ 2000-01-28 09:14:32 by jwe]
jwe
parents: 3485
diff changeset
1605 if (! (error_state || warning_state))
3292
ad0d250ebd7e [project @ 1999-10-14 22:52:28 by jwe]
jwe
parents: 3258
diff changeset
1606 {
8658
73c4516fae10 New evaluator and debugger derived from tree-walker class
John W. Eaton <jwe@octave.org>
parents: 8471
diff changeset
1607 tree_constant *tc_retval
73c4516fae10 New evaluator and debugger derived from tree-walker class
John W. Eaton <jwe@octave.org>
parents: 8471
diff changeset
1608 = new tree_constant (tmp, op->line (), op->column ());
3292
ad0d250ebd7e [project @ 1999-10-14 22:52:28 by jwe]
jwe
parents: 3258
diff changeset
1609
5765
7ba9ad1fec11 [project @ 2006-04-17 05:05:15 by jwe]
jwe
parents: 5760
diff changeset
1610 std::ostringstream buf;
3292
ad0d250ebd7e [project @ 1999-10-14 22:52:28 by jwe]
jwe
parents: 3258
diff changeset
1611
ad0d250ebd7e [project @ 1999-10-14 22:52:28 by jwe]
jwe
parents: 3258
diff changeset
1612 tree_print_code tpc (buf);
ad0d250ebd7e [project @ 1999-10-14 22:52:28 by jwe]
jwe
parents: 3258
diff changeset
1613
ad0d250ebd7e [project @ 1999-10-14 22:52:28 by jwe]
jwe
parents: 3258
diff changeset
1614 e->accept (tpc);
ad0d250ebd7e [project @ 1999-10-14 22:52:28 by jwe]
jwe
parents: 3258
diff changeset
1615
5765
7ba9ad1fec11 [project @ 2006-04-17 05:05:15 by jwe]
jwe
parents: 5760
diff changeset
1616 tc_retval->stash_original_text (buf.str ());
3292
ad0d250ebd7e [project @ 1999-10-14 22:52:28 by jwe]
jwe
parents: 3258
diff changeset
1617
ad0d250ebd7e [project @ 1999-10-14 22:52:28 by jwe]
jwe
parents: 3258
diff changeset
1618 delete e;
ad0d250ebd7e [project @ 1999-10-14 22:52:28 by jwe]
jwe
parents: 3258
diff changeset
1619
ad0d250ebd7e [project @ 1999-10-14 22:52:28 by jwe]
jwe
parents: 3258
diff changeset
1620 retval = tc_retval;
ad0d250ebd7e [project @ 1999-10-14 22:52:28 by jwe]
jwe
parents: 3258
diff changeset
1621 }
ad0d250ebd7e [project @ 1999-10-14 22:52:28 by jwe]
jwe
parents: 3258
diff changeset
1622 }
ad0d250ebd7e [project @ 1999-10-14 22:52:28 by jwe]
jwe
parents: 3258
diff changeset
1623
ad0d250ebd7e [project @ 1999-10-14 22:52:28 by jwe]
jwe
parents: 3258
diff changeset
1624 unwind_protect::run_frame ("fold_unary_expression");
2533
987e934bbb8c [project @ 1996-11-19 18:21:23 by jwe]
jwe
parents: 2525
diff changeset
1625
987e934bbb8c [project @ 1996-11-19 18:21:23 by jwe]
jwe
parents: 2525
diff changeset
1626 return retval;
987e934bbb8c [project @ 1996-11-19 18:21:23 by jwe]
jwe
parents: 2525
diff changeset
1627 }
987e934bbb8c [project @ 1996-11-19 18:21:23 by jwe]
jwe
parents: 2525
diff changeset
1628
1623
fa7a847f9b92 [project @ 1995-11-06 18:05:09 by jwe]
jwe
parents: 1607
diff changeset
1629 // Finish building a range.
fa7a847f9b92 [project @ 1995-11-06 18:05:09 by jwe]
jwe
parents: 1607
diff changeset
1630
fa7a847f9b92 [project @ 1995-11-06 18:05:09 by jwe]
jwe
parents: 1607
diff changeset
1631 static tree_expression *
fa7a847f9b92 [project @ 1995-11-06 18:05:09 by jwe]
jwe
parents: 1607
diff changeset
1632 finish_colon_expression (tree_colon_expression *e)
fa7a847f9b92 [project @ 1995-11-06 18:05:09 by jwe]
jwe
parents: 1607
diff changeset
1633 {
3110
fe2d1ae8926b [project @ 1997-11-21 02:11:19 by jwe]
jwe
parents: 3099
diff changeset
1634 tree_expression *retval = e;
fe2d1ae8926b [project @ 1997-11-21 02:11:19 by jwe]
jwe
parents: 3099
diff changeset
1635
fe2d1ae8926b [project @ 1997-11-21 02:11:19 by jwe]
jwe
parents: 3099
diff changeset
1636 unwind_protect::begin_frame ("finish_colon_expression");
fe2d1ae8926b [project @ 1997-11-21 02:11:19 by jwe]
jwe
parents: 3099
diff changeset
1637
fe2d1ae8926b [project @ 1997-11-21 02:11:19 by jwe]
jwe
parents: 3099
diff changeset
1638 unwind_protect_int (error_state);
4452
f3c21a1d1c62 [project @ 2003-07-09 23:20:18 by jwe]
jwe
parents: 4426
diff changeset
1639 unwind_protect_int (warning_state);
3110
fe2d1ae8926b [project @ 1997-11-21 02:11:19 by jwe]
jwe
parents: 3099
diff changeset
1640
3815
c554ad71bafc [project @ 2001-04-19 19:50:52 by jwe]
jwe
parents: 3802
diff changeset
1641 unwind_protect_bool (discard_error_messages);
4452
f3c21a1d1c62 [project @ 2003-07-09 23:20:18 by jwe]
jwe
parents: 4426
diff changeset
1642 unwind_protect_bool (discard_warning_messages);
f3c21a1d1c62 [project @ 2003-07-09 23:20:18 by jwe]
jwe
parents: 4426
diff changeset
1643
3815
c554ad71bafc [project @ 2001-04-19 19:50:52 by jwe]
jwe
parents: 3802
diff changeset
1644 discard_error_messages = true;
4452
f3c21a1d1c62 [project @ 2003-07-09 23:20:18 by jwe]
jwe
parents: 4426
diff changeset
1645 discard_warning_messages = true;
1623
fa7a847f9b92 [project @ 1995-11-06 18:05:09 by jwe]
jwe
parents: 1607
diff changeset
1646
2533
987e934bbb8c [project @ 1996-11-19 18:21:23 by jwe]
jwe
parents: 2525
diff changeset
1647 tree_expression *base = e->base ();
987e934bbb8c [project @ 1996-11-19 18:21:23 by jwe]
jwe
parents: 2525
diff changeset
1648 tree_expression *limit = e->limit ();
987e934bbb8c [project @ 1996-11-19 18:21:23 by jwe]
jwe
parents: 2525
diff changeset
1649 tree_expression *incr = e->increment ();
987e934bbb8c [project @ 1996-11-19 18:21:23 by jwe]
jwe
parents: 2525
diff changeset
1650
2970
b9e64477f703 [project @ 1997-05-15 18:04:21 by jwe]
jwe
parents: 2961
diff changeset
1651 if (base)
1623
fa7a847f9b92 [project @ 1995-11-06 18:05:09 by jwe]
jwe
parents: 1607
diff changeset
1652 {
2970
b9e64477f703 [project @ 1997-05-15 18:04:21 by jwe]
jwe
parents: 2961
diff changeset
1653 if (limit)
2533
987e934bbb8c [project @ 1996-11-19 18:21:23 by jwe]
jwe
parents: 2525
diff changeset
1654 {
2970
b9e64477f703 [project @ 1997-05-15 18:04:21 by jwe]
jwe
parents: 2961
diff changeset
1655 if (base->is_constant () && limit->is_constant ()
b9e64477f703 [project @ 1997-05-15 18:04:21 by jwe]
jwe
parents: 2961
diff changeset
1656 && (! incr || (incr && incr->is_constant ())))
b9e64477f703 [project @ 1997-05-15 18:04:21 by jwe]
jwe
parents: 2961
diff changeset
1657 {
8658
73c4516fae10 New evaluator and debugger derived from tree-walker class
John W. Eaton <jwe@octave.org>
parents: 8471
diff changeset
1658 octave_value tmp = e->rvalue1 ();
2970
b9e64477f703 [project @ 1997-05-15 18:04:21 by jwe]
jwe
parents: 2961
diff changeset
1659
3489
cbee5fbb696d [project @ 2000-01-28 09:14:32 by jwe]
jwe
parents: 3485
diff changeset
1660 if (! (error_state || warning_state))
2970
b9e64477f703 [project @ 1997-05-15 18:04:21 by jwe]
jwe
parents: 2961
diff changeset
1661 {
8658
73c4516fae10 New evaluator and debugger derived from tree-walker class
John W. Eaton <jwe@octave.org>
parents: 8471
diff changeset
1662 tree_constant *tc_retval
73c4516fae10 New evaluator and debugger derived from tree-walker class
John W. Eaton <jwe@octave.org>
parents: 8471
diff changeset
1663 = new tree_constant (tmp, base->line (), base->column ());
2970
b9e64477f703 [project @ 1997-05-15 18:04:21 by jwe]
jwe
parents: 2961
diff changeset
1664
5765
7ba9ad1fec11 [project @ 2006-04-17 05:05:15 by jwe]
jwe
parents: 5760
diff changeset
1665 std::ostringstream buf;
2970
b9e64477f703 [project @ 1997-05-15 18:04:21 by jwe]
jwe
parents: 2961
diff changeset
1666
b9e64477f703 [project @ 1997-05-15 18:04:21 by jwe]
jwe
parents: 2961
diff changeset
1667 tree_print_code tpc (buf);
b9e64477f703 [project @ 1997-05-15 18:04:21 by jwe]
jwe
parents: 2961
diff changeset
1668
b9e64477f703 [project @ 1997-05-15 18:04:21 by jwe]
jwe
parents: 2961
diff changeset
1669 e->accept (tpc);
b9e64477f703 [project @ 1997-05-15 18:04:21 by jwe]
jwe
parents: 2961
diff changeset
1670
5765
7ba9ad1fec11 [project @ 2006-04-17 05:05:15 by jwe]
jwe
parents: 5760
diff changeset
1671 tc_retval->stash_original_text (buf.str ());
2970
b9e64477f703 [project @ 1997-05-15 18:04:21 by jwe]
jwe
parents: 2961
diff changeset
1672
b9e64477f703 [project @ 1997-05-15 18:04:21 by jwe]
jwe
parents: 2961
diff changeset
1673 delete e;
b9e64477f703 [project @ 1997-05-15 18:04:21 by jwe]
jwe
parents: 2961
diff changeset
1674
b9e64477f703 [project @ 1997-05-15 18:04:21 by jwe]
jwe
parents: 2961
diff changeset
1675 retval = tc_retval;
b9e64477f703 [project @ 1997-05-15 18:04:21 by jwe]
jwe
parents: 2961
diff changeset
1676 }
b9e64477f703 [project @ 1997-05-15 18:04:21 by jwe]
jwe
parents: 2961
diff changeset
1677 }
2533
987e934bbb8c [project @ 1996-11-19 18:21:23 by jwe]
jwe
parents: 2525
diff changeset
1678 }
987e934bbb8c [project @ 1996-11-19 18:21:23 by jwe]
jwe
parents: 2525
diff changeset
1679 else
2970
b9e64477f703 [project @ 1997-05-15 18:04:21 by jwe]
jwe
parents: 2961
diff changeset
1680 {
2990
35bd1b05cfbe [project @ 1997-05-16 09:19:11 by jwe]
jwe
parents: 2987
diff changeset
1681 e->preserve_base ();
35bd1b05cfbe [project @ 1997-05-16 09:19:11 by jwe]
jwe
parents: 2987
diff changeset
1682 delete e;
2970
b9e64477f703 [project @ 1997-05-15 18:04:21 by jwe]
jwe
parents: 2961
diff changeset
1683
5775
ace8d8d26933 [project @ 2006-04-24 19:13:06 by jwe]
jwe
parents: 5774
diff changeset
1684 // FIXME -- need to attempt constant folding here
2970
b9e64477f703 [project @ 1997-05-15 18:04:21 by jwe]
jwe
parents: 2961
diff changeset
1685 // too (we need a generic way to do that).
b9e64477f703 [project @ 1997-05-15 18:04:21 by jwe]
jwe
parents: 2961
diff changeset
1686 retval = base;
b9e64477f703 [project @ 1997-05-15 18:04:21 by jwe]
jwe
parents: 2961
diff changeset
1687 }
1623
fa7a847f9b92 [project @ 1995-11-06 18:05:09 by jwe]
jwe
parents: 1607
diff changeset
1688 }
fa7a847f9b92 [project @ 1995-11-06 18:05:09 by jwe]
jwe
parents: 1607
diff changeset
1689
3110
fe2d1ae8926b [project @ 1997-11-21 02:11:19 by jwe]
jwe
parents: 3099
diff changeset
1690 unwind_protect::run_frame ("finish_colon_expression");
fe2d1ae8926b [project @ 1997-11-21 02:11:19 by jwe]
jwe
parents: 3099
diff changeset
1691
1623
fa7a847f9b92 [project @ 1995-11-06 18:05:09 by jwe]
jwe
parents: 1607
diff changeset
1692 return retval;
fa7a847f9b92 [project @ 1995-11-06 18:05:09 by jwe]
jwe
parents: 1607
diff changeset
1693 }
fa7a847f9b92 [project @ 1995-11-06 18:05:09 by jwe]
jwe
parents: 1607
diff changeset
1694
1607
795527e9db19 [project @ 1995-11-02 13:03:36 by jwe]
jwe
parents: 1588
diff changeset
1695 // Make a constant.
795527e9db19 [project @ 1995-11-02 13:03:36 by jwe]
jwe
parents: 1588
diff changeset
1696
2375
7ef24992e290 [project @ 1996-10-12 00:39:52 by jwe]
jwe
parents: 2200
diff changeset
1697 static tree_constant *
1607
795527e9db19 [project @ 1995-11-02 13:03:36 by jwe]
jwe
parents: 1588
diff changeset
1698 make_constant (int op, token *tok_val)
795527e9db19 [project @ 1995-11-02 13:03:36 by jwe]
jwe
parents: 1588
diff changeset
1699 {
795527e9db19 [project @ 1995-11-02 13:03:36 by jwe]
jwe
parents: 1588
diff changeset
1700 int l = tok_val->line ();
795527e9db19 [project @ 1995-11-02 13:03:36 by jwe]
jwe
parents: 1588
diff changeset
1701 int c = tok_val->column ();
795527e9db19 [project @ 1995-11-02 13:03:36 by jwe]
jwe
parents: 1588
diff changeset
1702
3216
60a89a69a70a [project @ 1998-11-11 20:47:03 by jwe]
jwe
parents: 3208
diff changeset
1703 tree_constant *retval = 0;
1607
795527e9db19 [project @ 1995-11-02 13:03:36 by jwe]
jwe
parents: 1588
diff changeset
1704
795527e9db19 [project @ 1995-11-02 13:03:36 by jwe]
jwe
parents: 1588
diff changeset
1705 switch (op)
795527e9db19 [project @ 1995-11-02 13:03:36 by jwe]
jwe
parents: 1588
diff changeset
1706 {
795527e9db19 [project @ 1995-11-02 13:03:36 by jwe]
jwe
parents: 1588
diff changeset
1707 case NUM:
2533
987e934bbb8c [project @ 1996-11-19 18:21:23 by jwe]
jwe
parents: 2525
diff changeset
1708 {
2883
0b3954110c77 [project @ 1997-04-24 09:57:05 by jwe]
jwe
parents: 2865
diff changeset
1709 octave_value tmp (tok_val->number ());
0b3954110c77 [project @ 1997-04-24 09:57:05 by jwe]
jwe
parents: 2865
diff changeset
1710 retval = new tree_constant (tmp, l, c);
2533
987e934bbb8c [project @ 1996-11-19 18:21:23 by jwe]
jwe
parents: 2525
diff changeset
1711 retval->stash_original_text (tok_val->text_rep ());
987e934bbb8c [project @ 1996-11-19 18:21:23 by jwe]
jwe
parents: 2525
diff changeset
1712 }
1607
795527e9db19 [project @ 1995-11-02 13:03:36 by jwe]
jwe
parents: 1588
diff changeset
1713 break;
795527e9db19 [project @ 1995-11-02 13:03:36 by jwe]
jwe
parents: 1588
diff changeset
1714
795527e9db19 [project @ 1995-11-02 13:03:36 by jwe]
jwe
parents: 1588
diff changeset
1715 case IMAG_NUM:
795527e9db19 [project @ 1995-11-02 13:03:36 by jwe]
jwe
parents: 1588
diff changeset
1716 {
2883
0b3954110c77 [project @ 1997-04-24 09:57:05 by jwe]
jwe
parents: 2865
diff changeset
1717 octave_value tmp (Complex (0.0, tok_val->number ()));
0b3954110c77 [project @ 1997-04-24 09:57:05 by jwe]
jwe
parents: 2865
diff changeset
1718 retval = new tree_constant (tmp, l, c);
1607
795527e9db19 [project @ 1995-11-02 13:03:36 by jwe]
jwe
parents: 1588
diff changeset
1719 retval->stash_original_text (tok_val->text_rep ());
795527e9db19 [project @ 1995-11-02 13:03:36 by jwe]
jwe
parents: 1588
diff changeset
1720 }
795527e9db19 [project @ 1995-11-02 13:03:36 by jwe]
jwe
parents: 1588
diff changeset
1721 break;
795527e9db19 [project @ 1995-11-02 13:03:36 by jwe]
jwe
parents: 1588
diff changeset
1722
5279
bd32f770c09a [project @ 2005-04-12 21:55:31 by jwe]
jwe
parents: 5189
diff changeset
1723 case DQ_STRING:
bd32f770c09a [project @ 2005-04-12 21:55:31 by jwe]
jwe
parents: 5189
diff changeset
1724 case SQ_STRING:
2883
0b3954110c77 [project @ 1997-04-24 09:57:05 by jwe]
jwe
parents: 2865
diff changeset
1725 {
7699
27a5f578750c make_constant: handle escape sequences in dq-strings
John W. Eaton <jwe@octave.org>
parents: 7690
diff changeset
1726 std::string txt = tok_val->text ();
27a5f578750c make_constant: handle escape sequences in dq-strings
John W. Eaton <jwe@octave.org>
parents: 7690
diff changeset
1727
8150
283989f2da9b make null assignment matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents: 8064
diff changeset
1728 char delim = op == DQ_STRING ? '"' : '\'';
283989f2da9b make null assignment matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents: 8064
diff changeset
1729 octave_value tmp (txt, delim);
283989f2da9b make null assignment matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents: 8064
diff changeset
1730
283989f2da9b make null assignment matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents: 8064
diff changeset
1731 if (txt.empty ())
283989f2da9b make null assignment matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents: 8064
diff changeset
1732 {
283989f2da9b make null assignment matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents: 8064
diff changeset
1733 if (op == DQ_STRING)
283989f2da9b make null assignment matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents: 8064
diff changeset
1734 tmp = octave_null_str::instance;
283989f2da9b make null assignment matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents: 8064
diff changeset
1735 else
283989f2da9b make null assignment matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents: 8064
diff changeset
1736 tmp = octave_null_sq_str::instance;
283989f2da9b make null assignment matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents: 8064
diff changeset
1737 }
283989f2da9b make null assignment matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents: 8064
diff changeset
1738
2883
0b3954110c77 [project @ 1997-04-24 09:57:05 by jwe]
jwe
parents: 2865
diff changeset
1739 retval = new tree_constant (tmp, l, c);
7699
27a5f578750c make_constant: handle escape sequences in dq-strings
John W. Eaton <jwe@octave.org>
parents: 7690
diff changeset
1740
27a5f578750c make_constant: handle escape sequences in dq-strings
John W. Eaton <jwe@octave.org>
parents: 7690
diff changeset
1741 if (op == DQ_STRING)
27a5f578750c make_constant: handle escape sequences in dq-strings
John W. Eaton <jwe@octave.org>
parents: 7690
diff changeset
1742 txt = undo_string_escapes (txt);
27a5f578750c make_constant: handle escape sequences in dq-strings
John W. Eaton <jwe@octave.org>
parents: 7690
diff changeset
1743
7690
97e535ec65db make_constant: stash original text for strings
John W. Eaton <jwe@octave.org>
parents: 7634
diff changeset
1744 // FIXME -- maybe this should also be handled by
97e535ec65db make_constant: stash original text for strings
John W. Eaton <jwe@octave.org>
parents: 7634
diff changeset
1745 // tok_val->text_rep () for character strings?
7699
27a5f578750c make_constant: handle escape sequences in dq-strings
John W. Eaton <jwe@octave.org>
parents: 7690
diff changeset
1746 retval->stash_original_text (delim + txt + delim);
2883
0b3954110c77 [project @ 1997-04-24 09:57:05 by jwe]
jwe
parents: 2865
diff changeset
1747 }
1607
795527e9db19 [project @ 1995-11-02 13:03:36 by jwe]
jwe
parents: 1588
diff changeset
1748 break;
795527e9db19 [project @ 1995-11-02 13:03:36 by jwe]
jwe
parents: 1588
diff changeset
1749
795527e9db19 [project @ 1995-11-02 13:03:36 by jwe]
jwe
parents: 1588
diff changeset
1750 default:
795527e9db19 [project @ 1995-11-02 13:03:36 by jwe]
jwe
parents: 1588
diff changeset
1751 panic_impossible ();
795527e9db19 [project @ 1995-11-02 13:03:36 by jwe]
jwe
parents: 1588
diff changeset
1752 break;
795527e9db19 [project @ 1995-11-02 13:03:36 by jwe]
jwe
parents: 1588
diff changeset
1753 }
795527e9db19 [project @ 1995-11-02 13:03:36 by jwe]
jwe
parents: 1588
diff changeset
1754
795527e9db19 [project @ 1995-11-02 13:03:36 by jwe]
jwe
parents: 1588
diff changeset
1755 return retval;
795527e9db19 [project @ 1995-11-02 13:03:36 by jwe]
jwe
parents: 1588
diff changeset
1756 }
795527e9db19 [project @ 1995-11-02 13:03:36 by jwe]
jwe
parents: 1588
diff changeset
1757
4342
813effe14ee1 [project @ 2003-02-20 08:35:55 by jwe]
jwe
parents: 4318
diff changeset
1758 // Make a function handle.
813effe14ee1 [project @ 2003-02-20 08:35:55 by jwe]
jwe
parents: 4318
diff changeset
1759
813effe14ee1 [project @ 2003-02-20 08:35:55 by jwe]
jwe
parents: 4318
diff changeset
1760 static tree_fcn_handle *
813effe14ee1 [project @ 2003-02-20 08:35:55 by jwe]
jwe
parents: 4318
diff changeset
1761 make_fcn_handle (token *tok_val)
813effe14ee1 [project @ 2003-02-20 08:35:55 by jwe]
jwe
parents: 4318
diff changeset
1762 {
813effe14ee1 [project @ 2003-02-20 08:35:55 by jwe]
jwe
parents: 4318
diff changeset
1763 int l = tok_val->line ();
813effe14ee1 [project @ 2003-02-20 08:35:55 by jwe]
jwe
parents: 4318
diff changeset
1764 int c = tok_val->column ();
813effe14ee1 [project @ 2003-02-20 08:35:55 by jwe]
jwe
parents: 4318
diff changeset
1765
813effe14ee1 [project @ 2003-02-20 08:35:55 by jwe]
jwe
parents: 4318
diff changeset
1766 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
1767
813effe14ee1 [project @ 2003-02-20 08:35:55 by jwe]
jwe
parents: 4318
diff changeset
1768 return retval;
813effe14ee1 [project @ 2003-02-20 08:35:55 by jwe]
jwe
parents: 4318
diff changeset
1769 }
813effe14ee1 [project @ 2003-02-20 08:35:55 by jwe]
jwe
parents: 4318
diff changeset
1770
4935
4fc993a4e072 [project @ 2004-08-06 03:17:12 by jwe]
jwe
parents: 4930
diff changeset
1771 // Make an anonymous function handle.
4fc993a4e072 [project @ 2004-08-06 03:17:12 by jwe]
jwe
parents: 4930
diff changeset
1772
5861
2a6cb4ed8f1e [project @ 2006-06-16 05:09:41 by jwe]
jwe
parents: 5848
diff changeset
1773 static tree_anon_fcn_handle *
4935
4fc993a4e072 [project @ 2004-08-06 03:17:12 by jwe]
jwe
parents: 4930
diff changeset
1774 make_anon_fcn_handle (tree_parameter_list *param_list, tree_statement *stmt)
4fc993a4e072 [project @ 2004-08-06 03:17:12 by jwe]
jwe
parents: 4930
diff changeset
1775 {
5775
ace8d8d26933 [project @ 2006-04-24 19:13:06 by jwe]
jwe
parents: 5774
diff changeset
1776 // FIXME -- need to get these from the location of the @ symbol.
4935
4fc993a4e072 [project @ 2004-08-06 03:17:12 by jwe]
jwe
parents: 4930
diff changeset
1777
4fc993a4e072 [project @ 2004-08-06 03:17:12 by jwe]
jwe
parents: 4930
diff changeset
1778 int l = -1;
4fc993a4e072 [project @ 2004-08-06 03:17:12 by jwe]
jwe
parents: 4930
diff changeset
1779 int c = -1;
4fc993a4e072 [project @ 2004-08-06 03:17:12 by jwe]
jwe
parents: 4930
diff changeset
1780
4fc993a4e072 [project @ 2004-08-06 03:17:12 by jwe]
jwe
parents: 4930
diff changeset
1781 tree_parameter_list *ret_list = 0;
4fc993a4e072 [project @ 2004-08-06 03:17:12 by jwe]
jwe
parents: 4930
diff changeset
1782
7336
745a8299c2b5 [project @ 2007-12-28 20:56:55 by jwe]
jwe
parents: 7017
diff changeset
1783 symbol_table::scope_id fcn_scope = symbol_table::current_scope ();
5861
2a6cb4ed8f1e [project @ 2006-06-16 05:09:41 by jwe]
jwe
parents: 5848
diff changeset
1784
2a6cb4ed8f1e [project @ 2006-06-16 05:09:41 by jwe]
jwe
parents: 5848
diff changeset
1785 if (symtab_context.empty ())
2a6cb4ed8f1e [project @ 2006-06-16 05:09:41 by jwe]
jwe
parents: 5848
diff changeset
1786 panic_impossible ();
2a6cb4ed8f1e [project @ 2006-06-16 05:09:41 by jwe]
jwe
parents: 5848
diff changeset
1787
7336
745a8299c2b5 [project @ 2007-12-28 20:56:55 by jwe]
jwe
parents: 7017
diff changeset
1788 symbol_table::set_scope (symtab_context.top ());
5861
2a6cb4ed8f1e [project @ 2006-06-16 05:09:41 by jwe]
jwe
parents: 5848
diff changeset
1789
2a6cb4ed8f1e [project @ 2006-06-16 05:09:41 by jwe]
jwe
parents: 5848
diff changeset
1790 symtab_context.pop ();
2a6cb4ed8f1e [project @ 2006-06-16 05:09:41 by jwe]
jwe
parents: 5848
diff changeset
1791
7351
8470a6b0b769 [project @ 2008-01-07 17:57:24 by jwe]
jwe
parents: 7336
diff changeset
1792 stmt->set_print_flag (false);
4935
4fc993a4e072 [project @ 2004-08-06 03:17:12 by jwe]
jwe
parents: 4930
diff changeset
1793
4fc993a4e072 [project @ 2004-08-06 03:17:12 by jwe]
jwe
parents: 4930
diff changeset
1794 tree_statement_list *body = new tree_statement_list (stmt);
4fc993a4e072 [project @ 2004-08-06 03:17:12 by jwe]
jwe
parents: 4930
diff changeset
1795
8658
73c4516fae10 New evaluator and debugger derived from tree-walker class
John W. Eaton <jwe@octave.org>
parents: 8471
diff changeset
1796 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
1797
5861
2a6cb4ed8f1e [project @ 2006-06-16 05:09:41 by jwe]
jwe
parents: 5848
diff changeset
1798 tree_anon_fcn_handle *retval
7336
745a8299c2b5 [project @ 2007-12-28 20:56:55 by jwe]
jwe
parents: 7017
diff changeset
1799 = new tree_anon_fcn_handle (param_list, ret_list, body, fcn_scope, l, c);
4935
4fc993a4e072 [project @ 2004-08-06 03:17:12 by jwe]
jwe
parents: 4930
diff changeset
1800
4fc993a4e072 [project @ 2004-08-06 03:17:12 by jwe]
jwe
parents: 4930
diff changeset
1801 return retval;
4fc993a4e072 [project @ 2004-08-06 03:17:12 by jwe]
jwe
parents: 4930
diff changeset
1802 }
4fc993a4e072 [project @ 2004-08-06 03:17:12 by jwe]
jwe
parents: 4930
diff changeset
1803
5161
3cdcddfab90b [project @ 2005-02-23 16:44:59 by jwe]
jwe
parents: 5160
diff changeset
1804 static void
3cdcddfab90b [project @ 2005-02-23 16:44:59 by jwe]
jwe
parents: 5160
diff changeset
1805 maybe_warn_associativity_change (tree_expression *op)
3cdcddfab90b [project @ 2005-02-23 16:44:59 by jwe]
jwe
parents: 5160
diff changeset
1806 {
5781
faafc2d98b8d [project @ 2006-05-02 19:40:19 by jwe]
jwe
parents: 5775
diff changeset
1807 if (op->paren_count () == 0 && op->is_binary_expression ())
5161
3cdcddfab90b [project @ 2005-02-23 16:44:59 by jwe]
jwe
parents: 5160
diff changeset
1808 {
3cdcddfab90b [project @ 2005-02-23 16:44:59 by jwe]
jwe
parents: 5160
diff changeset
1809 tree_binary_expression *e
3cdcddfab90b [project @ 2005-02-23 16:44:59 by jwe]
jwe
parents: 5160
diff changeset
1810 = dynamic_cast<tree_binary_expression *> (op);
3cdcddfab90b [project @ 2005-02-23 16:44:59 by jwe]
jwe
parents: 5160
diff changeset
1811
3cdcddfab90b [project @ 2005-02-23 16:44:59 by jwe]
jwe
parents: 5160
diff changeset
1812 octave_value::binary_op op_type = e->op_type ();
3cdcddfab90b [project @ 2005-02-23 16:44:59 by jwe]
jwe
parents: 5160
diff changeset
1813
3cdcddfab90b [project @ 2005-02-23 16:44:59 by jwe]
jwe
parents: 5160
diff changeset
1814 if (op_type == octave_value::op_pow
3cdcddfab90b [project @ 2005-02-23 16:44:59 by jwe]
jwe
parents: 5160
diff changeset
1815 || op_type == octave_value::op_el_pow)
3cdcddfab90b [project @ 2005-02-23 16:44:59 by jwe]
jwe
parents: 5160
diff changeset
1816 {
3cdcddfab90b [project @ 2005-02-23 16:44:59 by jwe]
jwe
parents: 5160
diff changeset
1817 std::string op_str = octave_value::binary_op_as_string (op_type);
3cdcddfab90b [project @ 2005-02-23 16:44:59 by jwe]
jwe
parents: 5160
diff changeset
1818
5781
faafc2d98b8d [project @ 2006-05-02 19:40:19 by jwe]
jwe
parents: 5775
diff changeset
1819 warning_with_id
faafc2d98b8d [project @ 2006-05-02 19:40:19 by jwe]
jwe
parents: 5775
diff changeset
1820 ("Octave:associativity-change",
faafc2d98b8d [project @ 2006-05-02 19:40:19 by jwe]
jwe
parents: 5775
diff changeset
1821 "meaning may have changed due to change in associativity for %s operator", op_str.c_str ());
5161
3cdcddfab90b [project @ 2005-02-23 16:44:59 by jwe]
jwe
parents: 5160
diff changeset
1822 }
3cdcddfab90b [project @ 2005-02-23 16:44:59 by jwe]
jwe
parents: 5160
diff changeset
1823 }
3cdcddfab90b [project @ 2005-02-23 16:44:59 by jwe]
jwe
parents: 5160
diff changeset
1824 }
3cdcddfab90b [project @ 2005-02-23 16:44:59 by jwe]
jwe
parents: 5160
diff changeset
1825
666
fb4f6556b443 [project @ 1994-09-06 21:22:46 by jwe]
jwe
parents: 627
diff changeset
1826 // Build a binary expression.
fb4f6556b443 [project @ 1994-09-06 21:22:46 by jwe]
jwe
parents: 627
diff changeset
1827
578
d169be9237fb [project @ 1994-08-03 20:06:54 by jwe]
jwe
parents: 572
diff changeset
1828 static tree_expression *
d169be9237fb [project @ 1994-08-03 20:06:54 by jwe]
jwe
parents: 572
diff changeset
1829 make_binary_op (int op, tree_expression *op1, token *tok_val,
d169be9237fb [project @ 1994-08-03 20:06:54 by jwe]
jwe
parents: 572
diff changeset
1830 tree_expression *op2)
d169be9237fb [project @ 1994-08-03 20:06:54 by jwe]
jwe
parents: 572
diff changeset
1831 {
2883
0b3954110c77 [project @ 1997-04-24 09:57:05 by jwe]
jwe
parents: 2865
diff changeset
1832 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
1833
578
d169be9237fb [project @ 1994-08-03 20:06:54 by jwe]
jwe
parents: 572
diff changeset
1834 switch (op)
d169be9237fb [project @ 1994-08-03 20:06:54 by jwe]
jwe
parents: 572
diff changeset
1835 {
d169be9237fb [project @ 1994-08-03 20:06:54 by jwe]
jwe
parents: 572
diff changeset
1836 case POW:
3525
6cfa474c5b99 [project @ 2000-02-02 10:48:41 by jwe]
jwe
parents: 3523
diff changeset
1837 t = octave_value::op_pow;
5161
3cdcddfab90b [project @ 2005-02-23 16:44:59 by jwe]
jwe
parents: 5160
diff changeset
1838 maybe_warn_associativity_change (op1);
578
d169be9237fb [project @ 1994-08-03 20:06:54 by jwe]
jwe
parents: 572
diff changeset
1839 break;
777
a2f9d3fd720c [project @ 1994-10-07 14:01:53 by jwe]
jwe
parents: 773
diff changeset
1840
578
d169be9237fb [project @ 1994-08-03 20:06:54 by jwe]
jwe
parents: 572
diff changeset
1841 case EPOW:
3525
6cfa474c5b99 [project @ 2000-02-02 10:48:41 by jwe]
jwe
parents: 3523
diff changeset
1842 t = octave_value::op_el_pow;
5161
3cdcddfab90b [project @ 2005-02-23 16:44:59 by jwe]
jwe
parents: 5160
diff changeset
1843 maybe_warn_associativity_change (op1);
578
d169be9237fb [project @ 1994-08-03 20:06:54 by jwe]
jwe
parents: 572
diff changeset
1844 break;
777
a2f9d3fd720c [project @ 1994-10-07 14:01:53 by jwe]
jwe
parents: 773
diff changeset
1845
578
d169be9237fb [project @ 1994-08-03 20:06:54 by jwe]
jwe
parents: 572
diff changeset
1846 case '+':
3525
6cfa474c5b99 [project @ 2000-02-02 10:48:41 by jwe]
jwe
parents: 3523
diff changeset
1847 t = octave_value::op_add;
578
d169be9237fb [project @ 1994-08-03 20:06:54 by jwe]
jwe
parents: 572
diff changeset
1848 break;
777
a2f9d3fd720c [project @ 1994-10-07 14:01:53 by jwe]
jwe
parents: 773
diff changeset
1849
578
d169be9237fb [project @ 1994-08-03 20:06:54 by jwe]
jwe
parents: 572
diff changeset
1850 case '-':
3525
6cfa474c5b99 [project @ 2000-02-02 10:48:41 by jwe]
jwe
parents: 3523
diff changeset
1851 t = octave_value::op_sub;
578
d169be9237fb [project @ 1994-08-03 20:06:54 by jwe]
jwe
parents: 572
diff changeset
1852 break;
777
a2f9d3fd720c [project @ 1994-10-07 14:01:53 by jwe]
jwe
parents: 773
diff changeset
1853
578
d169be9237fb [project @ 1994-08-03 20:06:54 by jwe]
jwe
parents: 572
diff changeset
1854 case '*':
3525
6cfa474c5b99 [project @ 2000-02-02 10:48:41 by jwe]
jwe
parents: 3523
diff changeset
1855 t = octave_value::op_mul;
578
d169be9237fb [project @ 1994-08-03 20:06:54 by jwe]
jwe
parents: 572
diff changeset
1856 break;
777
a2f9d3fd720c [project @ 1994-10-07 14:01:53 by jwe]
jwe
parents: 773
diff changeset
1857
578
d169be9237fb [project @ 1994-08-03 20:06:54 by jwe]
jwe
parents: 572
diff changeset
1858 case '/':
3525
6cfa474c5b99 [project @ 2000-02-02 10:48:41 by jwe]
jwe
parents: 3523
diff changeset
1859 t = octave_value::op_div;
578
d169be9237fb [project @ 1994-08-03 20:06:54 by jwe]
jwe
parents: 572
diff changeset
1860 break;
777
a2f9d3fd720c [project @ 1994-10-07 14:01:53 by jwe]
jwe
parents: 773
diff changeset
1861
578
d169be9237fb [project @ 1994-08-03 20:06:54 by jwe]
jwe
parents: 572
diff changeset
1862 case EMUL:
3525
6cfa474c5b99 [project @ 2000-02-02 10:48:41 by jwe]
jwe
parents: 3523
diff changeset
1863 t = octave_value::op_el_mul;
578
d169be9237fb [project @ 1994-08-03 20:06:54 by jwe]
jwe
parents: 572
diff changeset
1864 break;
777
a2f9d3fd720c [project @ 1994-10-07 14:01:53 by jwe]
jwe
parents: 773
diff changeset
1865
578
d169be9237fb [project @ 1994-08-03 20:06:54 by jwe]
jwe
parents: 572
diff changeset
1866 case EDIV:
3525
6cfa474c5b99 [project @ 2000-02-02 10:48:41 by jwe]
jwe
parents: 3523
diff changeset
1867 t = octave_value::op_el_div;
578
d169be9237fb [project @ 1994-08-03 20:06:54 by jwe]
jwe
parents: 572
diff changeset
1868 break;
777
a2f9d3fd720c [project @ 1994-10-07 14:01:53 by jwe]
jwe
parents: 773
diff changeset
1869
578
d169be9237fb [project @ 1994-08-03 20:06:54 by jwe]
jwe
parents: 572
diff changeset
1870 case LEFTDIV:
3525
6cfa474c5b99 [project @ 2000-02-02 10:48:41 by jwe]
jwe
parents: 3523
diff changeset
1871 t = octave_value::op_ldiv;
578
d169be9237fb [project @ 1994-08-03 20:06:54 by jwe]
jwe
parents: 572
diff changeset
1872 break;
777
a2f9d3fd720c [project @ 1994-10-07 14:01:53 by jwe]
jwe
parents: 773
diff changeset
1873
578
d169be9237fb [project @ 1994-08-03 20:06:54 by jwe]
jwe
parents: 572
diff changeset
1874 case ELEFTDIV:
3525
6cfa474c5b99 [project @ 2000-02-02 10:48:41 by jwe]
jwe
parents: 3523
diff changeset
1875 t = octave_value::op_el_ldiv;
578
d169be9237fb [project @ 1994-08-03 20:06:54 by jwe]
jwe
parents: 572
diff changeset
1876 break;
777
a2f9d3fd720c [project @ 1994-10-07 14:01:53 by jwe]
jwe
parents: 773
diff changeset
1877
2899
0d79a8c11a2b [project @ 1997-04-30 03:09:23 by jwe]
jwe
parents: 2891
diff changeset
1878 case LSHIFT:
3525
6cfa474c5b99 [project @ 2000-02-02 10:48:41 by jwe]
jwe
parents: 3523
diff changeset
1879 t = octave_value::op_lshift;
2899
0d79a8c11a2b [project @ 1997-04-30 03:09:23 by jwe]
jwe
parents: 2891
diff changeset
1880 break;
0d79a8c11a2b [project @ 1997-04-30 03:09:23 by jwe]
jwe
parents: 2891
diff changeset
1881
0d79a8c11a2b [project @ 1997-04-30 03:09:23 by jwe]
jwe
parents: 2891
diff changeset
1882 case RSHIFT:
3525
6cfa474c5b99 [project @ 2000-02-02 10:48:41 by jwe]
jwe
parents: 3523
diff changeset
1883 t = octave_value::op_rshift;
2899
0d79a8c11a2b [project @ 1997-04-30 03:09:23 by jwe]
jwe
parents: 2891
diff changeset
1884 break;
0d79a8c11a2b [project @ 1997-04-30 03:09:23 by jwe]
jwe
parents: 2891
diff changeset
1885
578
d169be9237fb [project @ 1994-08-03 20:06:54 by jwe]
jwe
parents: 572
diff changeset
1886 case EXPR_LT:
3525
6cfa474c5b99 [project @ 2000-02-02 10:48:41 by jwe]
jwe
parents: 3523
diff changeset
1887 t = octave_value::op_lt;
578
d169be9237fb [project @ 1994-08-03 20:06:54 by jwe]
jwe
parents: 572
diff changeset
1888 break;
777
a2f9d3fd720c [project @ 1994-10-07 14:01:53 by jwe]
jwe
parents: 773
diff changeset
1889
578
d169be9237fb [project @ 1994-08-03 20:06:54 by jwe]
jwe
parents: 572
diff changeset
1890 case EXPR_LE:
3525
6cfa474c5b99 [project @ 2000-02-02 10:48:41 by jwe]
jwe
parents: 3523
diff changeset
1891 t = octave_value::op_le;
578
d169be9237fb [project @ 1994-08-03 20:06:54 by jwe]
jwe
parents: 572
diff changeset
1892 break;
777
a2f9d3fd720c [project @ 1994-10-07 14:01:53 by jwe]
jwe
parents: 773
diff changeset
1893
578
d169be9237fb [project @ 1994-08-03 20:06:54 by jwe]
jwe
parents: 572
diff changeset
1894 case EXPR_EQ:
3525
6cfa474c5b99 [project @ 2000-02-02 10:48:41 by jwe]
jwe
parents: 3523
diff changeset
1895 t = octave_value::op_eq;
578
d169be9237fb [project @ 1994-08-03 20:06:54 by jwe]
jwe
parents: 572
diff changeset
1896 break;
777
a2f9d3fd720c [project @ 1994-10-07 14:01:53 by jwe]
jwe
parents: 773
diff changeset
1897
578
d169be9237fb [project @ 1994-08-03 20:06:54 by jwe]
jwe
parents: 572
diff changeset
1898 case EXPR_GE:
3525
6cfa474c5b99 [project @ 2000-02-02 10:48:41 by jwe]
jwe
parents: 3523
diff changeset
1899 t = octave_value::op_ge;
578
d169be9237fb [project @ 1994-08-03 20:06:54 by jwe]
jwe
parents: 572
diff changeset
1900 break;
777
a2f9d3fd720c [project @ 1994-10-07 14:01:53 by jwe]
jwe
parents: 773
diff changeset
1901
578
d169be9237fb [project @ 1994-08-03 20:06:54 by jwe]
jwe
parents: 572
diff changeset
1902 case EXPR_GT:
3525
6cfa474c5b99 [project @ 2000-02-02 10:48:41 by jwe]
jwe
parents: 3523
diff changeset
1903 t = octave_value::op_gt;
578
d169be9237fb [project @ 1994-08-03 20:06:54 by jwe]
jwe
parents: 572
diff changeset
1904 break;
777
a2f9d3fd720c [project @ 1994-10-07 14:01:53 by jwe]
jwe
parents: 773
diff changeset
1905
578
d169be9237fb [project @ 1994-08-03 20:06:54 by jwe]
jwe
parents: 572
diff changeset
1906 case EXPR_NE:
3525
6cfa474c5b99 [project @ 2000-02-02 10:48:41 by jwe]
jwe
parents: 3523
diff changeset
1907 t = octave_value::op_ne;
578
d169be9237fb [project @ 1994-08-03 20:06:54 by jwe]
jwe
parents: 572
diff changeset
1908 break;
777
a2f9d3fd720c [project @ 1994-10-07 14:01:53 by jwe]
jwe
parents: 773
diff changeset
1909
578
d169be9237fb [project @ 1994-08-03 20:06:54 by jwe]
jwe
parents: 572
diff changeset
1910 case EXPR_AND:
3525
6cfa474c5b99 [project @ 2000-02-02 10:48:41 by jwe]
jwe
parents: 3523
diff changeset
1911 t = octave_value::op_el_and;
578
d169be9237fb [project @ 1994-08-03 20:06:54 by jwe]
jwe
parents: 572
diff changeset
1912 break;
777
a2f9d3fd720c [project @ 1994-10-07 14:01:53 by jwe]
jwe
parents: 773
diff changeset
1913
578
d169be9237fb [project @ 1994-08-03 20:06:54 by jwe]
jwe
parents: 572
diff changeset
1914 case EXPR_OR:
3525
6cfa474c5b99 [project @ 2000-02-02 10:48:41 by jwe]
jwe
parents: 3523
diff changeset
1915 t = octave_value::op_el_or;
5781
faafc2d98b8d [project @ 2006-05-02 19:40:19 by jwe]
jwe
parents: 5775
diff changeset
1916 if (op2->paren_count () == 0 && op2->is_binary_expression ())
4023
ef3caf27cb9c [project @ 2002-08-07 06:54:41 by jwe]
jwe
parents: 4018
diff changeset
1917 {
ef3caf27cb9c [project @ 2002-08-07 06:54:41 by jwe]
jwe
parents: 4018
diff changeset
1918 tree_binary_expression *e
ef3caf27cb9c [project @ 2002-08-07 06:54:41 by jwe]
jwe
parents: 4018
diff changeset
1919 = dynamic_cast<tree_binary_expression *> (op2);
ef3caf27cb9c [project @ 2002-08-07 06:54:41 by jwe]
jwe
parents: 4018
diff changeset
1920
ef3caf27cb9c [project @ 2002-08-07 06:54:41 by jwe]
jwe
parents: 4018
diff changeset
1921 if (e->op_type () == octave_value::op_el_and)
5781
faafc2d98b8d [project @ 2006-05-02 19:40:19 by jwe]
jwe
parents: 5775
diff changeset
1922 warning_with_id
faafc2d98b8d [project @ 2006-05-02 19:40:19 by jwe]
jwe
parents: 5775
diff changeset
1923 ("Octave:precedence-change",
faafc2d98b8d [project @ 2006-05-02 19:40:19 by jwe]
jwe
parents: 5775
diff changeset
1924 "meaning may have changed due to change in precedence for & and | operators");
4023
ef3caf27cb9c [project @ 2002-08-07 06:54:41 by jwe]
jwe
parents: 4018
diff changeset
1925 }
578
d169be9237fb [project @ 1994-08-03 20:06:54 by jwe]
jwe
parents: 572
diff changeset
1926 break;
777
a2f9d3fd720c [project @ 1994-10-07 14:01:53 by jwe]
jwe
parents: 773
diff changeset
1927
578
d169be9237fb [project @ 1994-08-03 20:06:54 by jwe]
jwe
parents: 572
diff changeset
1928 default:
d169be9237fb [project @ 1994-08-03 20:06:54 by jwe]
jwe
parents: 572
diff changeset
1929 panic_impossible ();
d169be9237fb [project @ 1994-08-03 20:06:54 by jwe]
jwe
parents: 572
diff changeset
1930 break;
d169be9237fb [project @ 1994-08-03 20:06:54 by jwe]
jwe
parents: 572
diff changeset
1931 }
d169be9237fb [project @ 1994-08-03 20:06:54 by jwe]
jwe
parents: 572
diff changeset
1932
d169be9237fb [project @ 1994-08-03 20:06:54 by jwe]
jwe
parents: 572
diff changeset
1933 int l = tok_val->line ();
d169be9237fb [project @ 1994-08-03 20:06:54 by jwe]
jwe
parents: 572
diff changeset
1934 int c = tok_val->column ();
d169be9237fb [project @ 1994-08-03 20:06:54 by jwe]
jwe
parents: 572
diff changeset
1935
2533
987e934bbb8c [project @ 1996-11-19 18:21:23 by jwe]
jwe
parents: 2525
diff changeset
1936 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
1937 = 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
1938
2533
987e934bbb8c [project @ 1996-11-19 18:21:23 by jwe]
jwe
parents: 2525
diff changeset
1939 return fold (e);
578
d169be9237fb [project @ 1994-08-03 20:06:54 by jwe]
jwe
parents: 572
diff changeset
1940 }
d169be9237fb [project @ 1994-08-03 20:06:54 by jwe]
jwe
parents: 572
diff changeset
1941
2375
7ef24992e290 [project @ 1996-10-12 00:39:52 by jwe]
jwe
parents: 2200
diff changeset
1942 // Build a boolean expression.
666
fb4f6556b443 [project @ 1994-09-06 21:22:46 by jwe]
jwe
parents: 627
diff changeset
1943
578
d169be9237fb [project @ 1994-08-03 20:06:54 by jwe]
jwe
parents: 572
diff changeset
1944 static tree_expression *
2375
7ef24992e290 [project @ 1996-10-12 00:39:52 by jwe]
jwe
parents: 2200
diff changeset
1945 make_boolean_op (int op, tree_expression *op1, token *tok_val,
7ef24992e290 [project @ 1996-10-12 00:39:52 by jwe]
jwe
parents: 2200
diff changeset
1946 tree_expression *op2)
578
d169be9237fb [project @ 1994-08-03 20:06:54 by jwe]
jwe
parents: 572
diff changeset
1947 {
2375
7ef24992e290 [project @ 1996-10-12 00:39:52 by jwe]
jwe
parents: 2200
diff changeset
1948 tree_boolean_expression::type t;
7ef24992e290 [project @ 1996-10-12 00:39:52 by jwe]
jwe
parents: 2200
diff changeset
1949
578
d169be9237fb [project @ 1994-08-03 20:06:54 by jwe]
jwe
parents: 572
diff changeset
1950 switch (op)
d169be9237fb [project @ 1994-08-03 20:06:54 by jwe]
jwe
parents: 572
diff changeset
1951 {
2375
7ef24992e290 [project @ 1996-10-12 00:39:52 by jwe]
jwe
parents: 2200
diff changeset
1952 case EXPR_AND_AND:
2805
68e6d0c93fc8 [project @ 1997-03-11 04:52:44 by jwe]
jwe
parents: 2791
diff changeset
1953 t = tree_boolean_expression::bool_and;
578
d169be9237fb [project @ 1994-08-03 20:06:54 by jwe]
jwe
parents: 572
diff changeset
1954 break;
777
a2f9d3fd720c [project @ 1994-10-07 14:01:53 by jwe]
jwe
parents: 773
diff changeset
1955
2375
7ef24992e290 [project @ 1996-10-12 00:39:52 by jwe]
jwe
parents: 2200
diff changeset
1956 case EXPR_OR_OR:
2805
68e6d0c93fc8 [project @ 1997-03-11 04:52:44 by jwe]
jwe
parents: 2791
diff changeset
1957 t = tree_boolean_expression::bool_or;
5781
faafc2d98b8d [project @ 2006-05-02 19:40:19 by jwe]
jwe
parents: 5775
diff changeset
1958 if (op2->paren_count () == 0 && op2->is_boolean_expression ())
4023
ef3caf27cb9c [project @ 2002-08-07 06:54:41 by jwe]
jwe
parents: 4018
diff changeset
1959 {
ef3caf27cb9c [project @ 2002-08-07 06:54:41 by jwe]
jwe
parents: 4018
diff changeset
1960 tree_boolean_expression *e
ef3caf27cb9c [project @ 2002-08-07 06:54:41 by jwe]
jwe
parents: 4018
diff changeset
1961 = dynamic_cast<tree_boolean_expression *> (op2);
ef3caf27cb9c [project @ 2002-08-07 06:54:41 by jwe]
jwe
parents: 4018
diff changeset
1962
ef3caf27cb9c [project @ 2002-08-07 06:54:41 by jwe]
jwe
parents: 4018
diff changeset
1963 if (e->op_type () == tree_boolean_expression::bool_and)
5781
faafc2d98b8d [project @ 2006-05-02 19:40:19 by jwe]
jwe
parents: 5775
diff changeset
1964 warning_with_id
faafc2d98b8d [project @ 2006-05-02 19:40:19 by jwe]
jwe
parents: 5775
diff changeset
1965 ("Octave:precedence-change",
faafc2d98b8d [project @ 2006-05-02 19:40:19 by jwe]
jwe
parents: 5775
diff changeset
1966 "meaning may have changed due to change in precedence for && and || operators");
4023
ef3caf27cb9c [project @ 2002-08-07 06:54:41 by jwe]
jwe
parents: 4018
diff changeset
1967 }
578
d169be9237fb [project @ 1994-08-03 20:06:54 by jwe]
jwe
parents: 572
diff changeset
1968 break;
777
a2f9d3fd720c [project @ 1994-10-07 14:01:53 by jwe]
jwe
parents: 773
diff changeset
1969
578
d169be9237fb [project @ 1994-08-03 20:06:54 by jwe]
jwe
parents: 572
diff changeset
1970 default:
d169be9237fb [project @ 1994-08-03 20:06:54 by jwe]
jwe
parents: 572
diff changeset
1971 panic_impossible ();
d169be9237fb [project @ 1994-08-03 20:06:54 by jwe]
jwe
parents: 572
diff changeset
1972 break;
d169be9237fb [project @ 1994-08-03 20:06:54 by jwe]
jwe
parents: 572
diff changeset
1973 }
d169be9237fb [project @ 1994-08-03 20:06:54 by jwe]
jwe
parents: 572
diff changeset
1974
d169be9237fb [project @ 1994-08-03 20:06:54 by jwe]
jwe
parents: 572
diff changeset
1975 int l = tok_val->line ();
d169be9237fb [project @ 1994-08-03 20:06:54 by jwe]
jwe
parents: 572
diff changeset
1976 int c = tok_val->column ();
d169be9237fb [project @ 1994-08-03 20:06:54 by jwe]
jwe
parents: 572
diff changeset
1977
2533
987e934bbb8c [project @ 1996-11-19 18:21:23 by jwe]
jwe
parents: 2525
diff changeset
1978 tree_boolean_expression *e
987e934bbb8c [project @ 1996-11-19 18:21:23 by jwe]
jwe
parents: 2525
diff changeset
1979 = 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
1980
2533
987e934bbb8c [project @ 1996-11-19 18:21:23 by jwe]
jwe
parents: 2525
diff changeset
1981 return fold (e);
578
d169be9237fb [project @ 1994-08-03 20:06:54 by jwe]
jwe
parents: 572
diff changeset
1982 }
d169be9237fb [project @ 1994-08-03 20:06:54 by jwe]
jwe
parents: 572
diff changeset
1983
2375
7ef24992e290 [project @ 1996-10-12 00:39:52 by jwe]
jwe
parents: 2200
diff changeset
1984 // Build a prefix expression.
666
fb4f6556b443 [project @ 1994-09-06 21:22:46 by jwe]
jwe
parents: 627
diff changeset
1985
578
d169be9237fb [project @ 1994-08-03 20:06:54 by jwe]
jwe
parents: 572
diff changeset
1986 static tree_expression *
2960
194b50e4725b [project @ 1997-05-12 00:43:54 by jwe]
jwe
parents: 2899
diff changeset
1987 make_prefix_op (int op, tree_expression *op1, token *tok_val)
578
d169be9237fb [project @ 1994-08-03 20:06:54 by jwe]
jwe
parents: 572
diff changeset
1988 {
3203
bc61b0e8d60e [project @ 1998-10-30 20:26:27 by jwe]
jwe
parents: 3195
diff changeset
1989 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
1990
578
d169be9237fb [project @ 1994-08-03 20:06:54 by jwe]
jwe
parents: 572
diff changeset
1991 switch (op)
d169be9237fb [project @ 1994-08-03 20:06:54 by jwe]
jwe
parents: 572
diff changeset
1992 {
2960
194b50e4725b [project @ 1997-05-12 00:43:54 by jwe]
jwe
parents: 2899
diff changeset
1993 case EXPR_NOT:
3525
6cfa474c5b99 [project @ 2000-02-02 10:48:41 by jwe]
jwe
parents: 3523
diff changeset
1994 t = octave_value::op_not;
2960
194b50e4725b [project @ 1997-05-12 00:43:54 by jwe]
jwe
parents: 2899
diff changeset
1995 break;
194b50e4725b [project @ 1997-05-12 00:43:54 by jwe]
jwe
parents: 2899
diff changeset
1996
4965
c0d8e8afa82f [project @ 2004-09-06 20:19:57 by jwe]
jwe
parents: 4935
diff changeset
1997 case '+':
c0d8e8afa82f [project @ 2004-09-06 20:19:57 by jwe]
jwe
parents: 4935
diff changeset
1998 t = octave_value::op_uplus;
c0d8e8afa82f [project @ 2004-09-06 20:19:57 by jwe]
jwe
parents: 4935
diff changeset
1999 break;
c0d8e8afa82f [project @ 2004-09-06 20:19:57 by jwe]
jwe
parents: 4935
diff changeset
2000
2960
194b50e4725b [project @ 1997-05-12 00:43:54 by jwe]
jwe
parents: 2899
diff changeset
2001 case '-':
3525
6cfa474c5b99 [project @ 2000-02-02 10:48:41 by jwe]
jwe
parents: 3523
diff changeset
2002 t = octave_value::op_uminus;
2960
194b50e4725b [project @ 1997-05-12 00:43:54 by jwe]
jwe
parents: 2899
diff changeset
2003 break;
194b50e4725b [project @ 1997-05-12 00:43:54 by jwe]
jwe
parents: 2899
diff changeset
2004
578
d169be9237fb [project @ 1994-08-03 20:06:54 by jwe]
jwe
parents: 572
diff changeset
2005 case PLUS_PLUS:
3525
6cfa474c5b99 [project @ 2000-02-02 10:48:41 by jwe]
jwe
parents: 3523
diff changeset
2006 t = octave_value::op_incr;
578
d169be9237fb [project @ 1994-08-03 20:06:54 by jwe]
jwe
parents: 572
diff changeset
2007 break;
777
a2f9d3fd720c [project @ 1994-10-07 14:01:53 by jwe]
jwe
parents: 773
diff changeset
2008
578
d169be9237fb [project @ 1994-08-03 20:06:54 by jwe]
jwe
parents: 572
diff changeset
2009 case MINUS_MINUS:
3525
6cfa474c5b99 [project @ 2000-02-02 10:48:41 by jwe]
jwe
parents: 3523
diff changeset
2010 t = octave_value::op_decr;
578
d169be9237fb [project @ 1994-08-03 20:06:54 by jwe]
jwe
parents: 572
diff changeset
2011 break;
777
a2f9d3fd720c [project @ 1994-10-07 14:01:53 by jwe]
jwe
parents: 773
diff changeset
2012
578
d169be9237fb [project @ 1994-08-03 20:06:54 by jwe]
jwe
parents: 572
diff changeset
2013 default:
d169be9237fb [project @ 1994-08-03 20:06:54 by jwe]
jwe
parents: 572
diff changeset
2014 panic_impossible ();
d169be9237fb [project @ 1994-08-03 20:06:54 by jwe]
jwe
parents: 572
diff changeset
2015 break;
d169be9237fb [project @ 1994-08-03 20:06:54 by jwe]
jwe
parents: 572
diff changeset
2016 }
d169be9237fb [project @ 1994-08-03 20:06:54 by jwe]
jwe
parents: 572
diff changeset
2017
d169be9237fb [project @ 1994-08-03 20:06:54 by jwe]
jwe
parents: 572
diff changeset
2018 int l = tok_val->line ();
d169be9237fb [project @ 1994-08-03 20:06:54 by jwe]
jwe
parents: 572
diff changeset
2019 int c = tok_val->column ();
d169be9237fb [project @ 1994-08-03 20:06:54 by jwe]
jwe
parents: 572
diff changeset
2020
3292
ad0d250ebd7e [project @ 1999-10-14 22:52:28 by jwe]
jwe
parents: 3258
diff changeset
2021 tree_prefix_expression *e
ad0d250ebd7e [project @ 1999-10-14 22:52:28 by jwe]
jwe
parents: 3258
diff changeset
2022 = new tree_prefix_expression (op1, l, c, t);
ad0d250ebd7e [project @ 1999-10-14 22:52:28 by jwe]
jwe
parents: 3258
diff changeset
2023
ad0d250ebd7e [project @ 1999-10-14 22:52:28 by jwe]
jwe
parents: 3258
diff changeset
2024 return fold (e);
578
d169be9237fb [project @ 1994-08-03 20:06:54 by jwe]
jwe
parents: 572
diff changeset
2025 }
d169be9237fb [project @ 1994-08-03 20:06:54 by jwe]
jwe
parents: 572
diff changeset
2026
2375
7ef24992e290 [project @ 1996-10-12 00:39:52 by jwe]
jwe
parents: 2200
diff changeset
2027 // Build a postfix expression.
666
fb4f6556b443 [project @ 1994-09-06 21:22:46 by jwe]
jwe
parents: 627
diff changeset
2028
578
d169be9237fb [project @ 1994-08-03 20:06:54 by jwe]
jwe
parents: 572
diff changeset
2029 static tree_expression *
2960
194b50e4725b [project @ 1997-05-12 00:43:54 by jwe]
jwe
parents: 2899
diff changeset
2030 make_postfix_op (int op, tree_expression *op1, token *tok_val)
578
d169be9237fb [project @ 1994-08-03 20:06:54 by jwe]
jwe
parents: 572
diff changeset
2031 {
3203
bc61b0e8d60e [project @ 1998-10-30 20:26:27 by jwe]
jwe
parents: 3195
diff changeset
2032 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
2033
578
d169be9237fb [project @ 1994-08-03 20:06:54 by jwe]
jwe
parents: 572
diff changeset
2034 switch (op)
d169be9237fb [project @ 1994-08-03 20:06:54 by jwe]
jwe
parents: 572
diff changeset
2035 {
2960
194b50e4725b [project @ 1997-05-12 00:43:54 by jwe]
jwe
parents: 2899
diff changeset
2036 case QUOTE:
3525
6cfa474c5b99 [project @ 2000-02-02 10:48:41 by jwe]
jwe
parents: 3523
diff changeset
2037 t = octave_value::op_hermitian;
2960
194b50e4725b [project @ 1997-05-12 00:43:54 by jwe]
jwe
parents: 2899
diff changeset
2038 break;
194b50e4725b [project @ 1997-05-12 00:43:54 by jwe]
jwe
parents: 2899
diff changeset
2039
194b50e4725b [project @ 1997-05-12 00:43:54 by jwe]
jwe
parents: 2899
diff changeset
2040 case TRANSPOSE:
3525
6cfa474c5b99 [project @ 2000-02-02 10:48:41 by jwe]
jwe
parents: 3523
diff changeset
2041 t = octave_value::op_transpose;
2960
194b50e4725b [project @ 1997-05-12 00:43:54 by jwe]
jwe
parents: 2899
diff changeset
2042 break;
194b50e4725b [project @ 1997-05-12 00:43:54 by jwe]
jwe
parents: 2899
diff changeset
2043
2375
7ef24992e290 [project @ 1996-10-12 00:39:52 by jwe]
jwe
parents: 2200
diff changeset
2044 case PLUS_PLUS:
3525
6cfa474c5b99 [project @ 2000-02-02 10:48:41 by jwe]
jwe
parents: 3523
diff changeset
2045 t = octave_value::op_incr;
578
d169be9237fb [project @ 1994-08-03 20:06:54 by jwe]
jwe
parents: 572
diff changeset
2046 break;
777
a2f9d3fd720c [project @ 1994-10-07 14:01:53 by jwe]
jwe
parents: 773
diff changeset
2047
2375
7ef24992e290 [project @ 1996-10-12 00:39:52 by jwe]
jwe
parents: 2200
diff changeset
2048 case MINUS_MINUS:
3525
6cfa474c5b99 [project @ 2000-02-02 10:48:41 by jwe]
jwe
parents: 3523
diff changeset
2049 t = octave_value::op_decr;
578
d169be9237fb [project @ 1994-08-03 20:06:54 by jwe]
jwe
parents: 572
diff changeset
2050 break;
777
a2f9d3fd720c [project @ 1994-10-07 14:01:53 by jwe]
jwe
parents: 773
diff changeset
2051
578
d169be9237fb [project @ 1994-08-03 20:06:54 by jwe]
jwe
parents: 572
diff changeset
2052 default:
d169be9237fb [project @ 1994-08-03 20:06:54 by jwe]
jwe
parents: 572
diff changeset
2053 panic_impossible ();
d169be9237fb [project @ 1994-08-03 20:06:54 by jwe]
jwe
parents: 572
diff changeset
2054 break;
d169be9237fb [project @ 1994-08-03 20:06:54 by jwe]
jwe
parents: 572
diff changeset
2055 }
d169be9237fb [project @ 1994-08-03 20:06:54 by jwe]
jwe
parents: 572
diff changeset
2056
d169be9237fb [project @ 1994-08-03 20:06:54 by jwe]
jwe
parents: 572
diff changeset
2057 int l = tok_val->line ();
d169be9237fb [project @ 1994-08-03 20:06:54 by jwe]
jwe
parents: 572
diff changeset
2058 int c = tok_val->column ();
d169be9237fb [project @ 1994-08-03 20:06:54 by jwe]
jwe
parents: 572
diff changeset
2059
3292
ad0d250ebd7e [project @ 1999-10-14 22:52:28 by jwe]
jwe
parents: 3258
diff changeset
2060 tree_postfix_expression *e
ad0d250ebd7e [project @ 1999-10-14 22:52:28 by jwe]
jwe
parents: 3258
diff changeset
2061 = new tree_postfix_expression (op1, l, c, t);
ad0d250ebd7e [project @ 1999-10-14 22:52:28 by jwe]
jwe
parents: 3258
diff changeset
2062
ad0d250ebd7e [project @ 1999-10-14 22:52:28 by jwe]
jwe
parents: 3258
diff changeset
2063 return fold (e);
1623
fa7a847f9b92 [project @ 1995-11-06 18:05:09 by jwe]
jwe
parents: 1607
diff changeset
2064 }
fa7a847f9b92 [project @ 1995-11-06 18:05:09 by jwe]
jwe
parents: 1607
diff changeset
2065
fa7a847f9b92 [project @ 1995-11-06 18:05:09 by jwe]
jwe
parents: 1607
diff changeset
2066 // Build an unwind-protect command.
fa7a847f9b92 [project @ 1995-11-06 18:05:09 by jwe]
jwe
parents: 1607
diff changeset
2067
fa7a847f9b92 [project @ 1995-11-06 18:05:09 by jwe]
jwe
parents: 1607
diff changeset
2068 static tree_command *
fa7a847f9b92 [project @ 1995-11-06 18:05:09 by jwe]
jwe
parents: 1607
diff changeset
2069 make_unwind_command (token *unwind_tok, tree_statement_list *body,
3665
0689afb1d001 [project @ 2000-05-11 19:07:56 by jwe]
jwe
parents: 3544
diff changeset
2070 tree_statement_list *cleanup, token *end_tok,
0689afb1d001 [project @ 2000-05-11 19:07:56 by jwe]
jwe
parents: 3544
diff changeset
2071 octave_comment_list *lc, octave_comment_list *mc)
1623
fa7a847f9b92 [project @ 1995-11-06 18:05:09 by jwe]
jwe
parents: 1607
diff changeset
2072 {
fa7a847f9b92 [project @ 1995-11-06 18:05:09 by jwe]
jwe
parents: 1607
diff changeset
2073 tree_command *retval = 0;
fa7a847f9b92 [project @ 1995-11-06 18:05:09 by jwe]
jwe
parents: 1607
diff changeset
2074
2857
5448c8cba402 [project @ 1997-03-31 07:06:10 by jwe]
jwe
parents: 2856
diff changeset
2075 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
2076 {
3665
0689afb1d001 [project @ 2000-05-11 19:07:56 by jwe]
jwe
parents: 3544
diff changeset
2077 octave_comment_list *tc = octave_comment_buffer::get_comment ();
0689afb1d001 [project @ 2000-05-11 19:07:56 by jwe]
jwe
parents: 3544
diff changeset
2078
1623
fa7a847f9b92 [project @ 1995-11-06 18:05:09 by jwe]
jwe
parents: 1607
diff changeset
2079 int l = unwind_tok->line ();
fa7a847f9b92 [project @ 1995-11-06 18:05:09 by jwe]
jwe
parents: 1607
diff changeset
2080 int c = unwind_tok->column ();
fa7a847f9b92 [project @ 1995-11-06 18:05:09 by jwe]
jwe
parents: 1607
diff changeset
2081
3665
0689afb1d001 [project @ 2000-05-11 19:07:56 by jwe]
jwe
parents: 3544
diff changeset
2082 retval = new tree_unwind_protect_command (body, cleanup,
0689afb1d001 [project @ 2000-05-11 19:07:56 by jwe]
jwe
parents: 3544
diff changeset
2083 lc, mc, tc, l, c);
1623
fa7a847f9b92 [project @ 1995-11-06 18:05:09 by jwe]
jwe
parents: 1607
diff changeset
2084 }
fa7a847f9b92 [project @ 1995-11-06 18:05:09 by jwe]
jwe
parents: 1607
diff changeset
2085
fa7a847f9b92 [project @ 1995-11-06 18:05:09 by jwe]
jwe
parents: 1607
diff changeset
2086 return retval;
fa7a847f9b92 [project @ 1995-11-06 18:05:09 by jwe]
jwe
parents: 1607
diff changeset
2087 }
fa7a847f9b92 [project @ 1995-11-06 18:05:09 by jwe]
jwe
parents: 1607
diff changeset
2088
fa7a847f9b92 [project @ 1995-11-06 18:05:09 by jwe]
jwe
parents: 1607
diff changeset
2089 // Build a try-catch command.
fa7a847f9b92 [project @ 1995-11-06 18:05:09 by jwe]
jwe
parents: 1607
diff changeset
2090
fa7a847f9b92 [project @ 1995-11-06 18:05:09 by jwe]
jwe
parents: 1607
diff changeset
2091 static tree_command *
fa7a847f9b92 [project @ 1995-11-06 18:05:09 by jwe]
jwe
parents: 1607
diff changeset
2092 make_try_command (token *try_tok, tree_statement_list *body,
3665
0689afb1d001 [project @ 2000-05-11 19:07:56 by jwe]
jwe
parents: 3544
diff changeset
2093 tree_statement_list *cleanup, token *end_tok,
0689afb1d001 [project @ 2000-05-11 19:07:56 by jwe]
jwe
parents: 3544
diff changeset
2094 octave_comment_list *lc, octave_comment_list *mc)
1623
fa7a847f9b92 [project @ 1995-11-06 18:05:09 by jwe]
jwe
parents: 1607
diff changeset
2095 {
fa7a847f9b92 [project @ 1995-11-06 18:05:09 by jwe]
jwe
parents: 1607
diff changeset
2096 tree_command *retval = 0;
fa7a847f9b92 [project @ 1995-11-06 18:05:09 by jwe]
jwe
parents: 1607
diff changeset
2097
2857
5448c8cba402 [project @ 1997-03-31 07:06:10 by jwe]
jwe
parents: 2856
diff changeset
2098 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
2099 {
3665
0689afb1d001 [project @ 2000-05-11 19:07:56 by jwe]
jwe
parents: 3544
diff changeset
2100 octave_comment_list *tc = octave_comment_buffer::get_comment ();
0689afb1d001 [project @ 2000-05-11 19:07:56 by jwe]
jwe
parents: 3544
diff changeset
2101
1623
fa7a847f9b92 [project @ 1995-11-06 18:05:09 by jwe]
jwe
parents: 1607
diff changeset
2102 int l = try_tok->line ();
fa7a847f9b92 [project @ 1995-11-06 18:05:09 by jwe]
jwe
parents: 1607
diff changeset
2103 int c = try_tok->column ();
fa7a847f9b92 [project @ 1995-11-06 18:05:09 by jwe]
jwe
parents: 1607
diff changeset
2104
3665
0689afb1d001 [project @ 2000-05-11 19:07:56 by jwe]
jwe
parents: 3544
diff changeset
2105 retval = new tree_try_catch_command (body, cleanup,
0689afb1d001 [project @ 2000-05-11 19:07:56 by jwe]
jwe
parents: 3544
diff changeset
2106 lc, mc, tc, l, c);
1623
fa7a847f9b92 [project @ 1995-11-06 18:05:09 by jwe]
jwe
parents: 1607
diff changeset
2107 }
fa7a847f9b92 [project @ 1995-11-06 18:05:09 by jwe]
jwe
parents: 1607
diff changeset
2108
fa7a847f9b92 [project @ 1995-11-06 18:05:09 by jwe]
jwe
parents: 1607
diff changeset
2109 return retval;
fa7a847f9b92 [project @ 1995-11-06 18:05:09 by jwe]
jwe
parents: 1607
diff changeset
2110 }
fa7a847f9b92 [project @ 1995-11-06 18:05:09 by jwe]
jwe
parents: 1607
diff changeset
2111
fa7a847f9b92 [project @ 1995-11-06 18:05:09 by jwe]
jwe
parents: 1607
diff changeset
2112 // Build a while command.
fa7a847f9b92 [project @ 1995-11-06 18:05:09 by jwe]
jwe
parents: 1607
diff changeset
2113
fa7a847f9b92 [project @ 1995-11-06 18:05:09 by jwe]
jwe
parents: 1607
diff changeset
2114 static tree_command *
fa7a847f9b92 [project @ 1995-11-06 18:05:09 by jwe]
jwe
parents: 1607
diff changeset
2115 make_while_command (token *while_tok, tree_expression *expr,
3665
0689afb1d001 [project @ 2000-05-11 19:07:56 by jwe]
jwe
parents: 3544
diff changeset
2116 tree_statement_list *body, token *end_tok,
0689afb1d001 [project @ 2000-05-11 19:07:56 by jwe]
jwe
parents: 3544
diff changeset
2117 octave_comment_list *lc)
1623
fa7a847f9b92 [project @ 1995-11-06 18:05:09 by jwe]
jwe
parents: 1607
diff changeset
2118 {
fa7a847f9b92 [project @ 1995-11-06 18:05:09 by jwe]
jwe
parents: 1607
diff changeset
2119 tree_command *retval = 0;
fa7a847f9b92 [project @ 1995-11-06 18:05:09 by jwe]
jwe
parents: 1607
diff changeset
2120
fa7a847f9b92 [project @ 1995-11-06 18:05:09 by jwe]
jwe
parents: 1607
diff changeset
2121 maybe_warn_assign_as_truth_value (expr);
fa7a847f9b92 [project @ 1995-11-06 18:05:09 by jwe]
jwe
parents: 1607
diff changeset
2122
2857
5448c8cba402 [project @ 1997-03-31 07:06:10 by jwe]
jwe
parents: 2856
diff changeset
2123 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
2124 {
3665
0689afb1d001 [project @ 2000-05-11 19:07:56 by jwe]
jwe
parents: 3544
diff changeset
2125 octave_comment_list *tc = octave_comment_buffer::get_comment ();
0689afb1d001 [project @ 2000-05-11 19:07:56 by jwe]
jwe
parents: 3544
diff changeset
2126
1826
b14829582cc4 [project @ 1996-02-02 03:05:07 by jwe]
jwe
parents: 1755
diff changeset
2127 lexer_flags.looping--;
1623
fa7a847f9b92 [project @ 1995-11-06 18:05:09 by jwe]
jwe
parents: 1607
diff changeset
2128
fa7a847f9b92 [project @ 1995-11-06 18:05:09 by jwe]
jwe
parents: 1607
diff changeset
2129 int l = while_tok->line ();
fa7a847f9b92 [project @ 1995-11-06 18:05:09 by jwe]
jwe
parents: 1607
diff changeset
2130 int c = while_tok->column ();
fa7a847f9b92 [project @ 1995-11-06 18:05:09 by jwe]
jwe
parents: 1607
diff changeset
2131
3665
0689afb1d001 [project @ 2000-05-11 19:07:56 by jwe]
jwe
parents: 3544
diff changeset
2132 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
2133 }
fa7a847f9b92 [project @ 1995-11-06 18:05:09 by jwe]
jwe
parents: 1607
diff changeset
2134
fa7a847f9b92 [project @ 1995-11-06 18:05:09 by jwe]
jwe
parents: 1607
diff changeset
2135 return retval;
fa7a847f9b92 [project @ 1995-11-06 18:05:09 by jwe]
jwe
parents: 1607
diff changeset
2136 }
fa7a847f9b92 [project @ 1995-11-06 18:05:09 by jwe]
jwe
parents: 1607
diff changeset
2137
3484
8b1f46ac2b64 [project @ 2000-01-27 23:30:45 by jwe]
jwe
parents: 3446
diff changeset
2138 // Build a do-until command.
8b1f46ac2b64 [project @ 2000-01-27 23:30:45 by jwe]
jwe
parents: 3446
diff changeset
2139
8b1f46ac2b64 [project @ 2000-01-27 23:30:45 by jwe]
jwe
parents: 3446
diff changeset
2140 static tree_command *
8658
73c4516fae10 New evaluator and debugger derived from tree-walker class
John W. Eaton <jwe@octave.org>
parents: 8471
diff changeset
2141 make_do_until_command (token *until_tok, tree_statement_list *body,
3665
0689afb1d001 [project @ 2000-05-11 19:07:56 by jwe]
jwe
parents: 3544
diff changeset
2142 tree_expression *expr, octave_comment_list *lc)
3484
8b1f46ac2b64 [project @ 2000-01-27 23:30:45 by jwe]
jwe
parents: 3446
diff changeset
2143 {
8b1f46ac2b64 [project @ 2000-01-27 23:30:45 by jwe]
jwe
parents: 3446
diff changeset
2144 tree_command *retval = 0;
8b1f46ac2b64 [project @ 2000-01-27 23:30:45 by jwe]
jwe
parents: 3446
diff changeset
2145
8b1f46ac2b64 [project @ 2000-01-27 23:30:45 by jwe]
jwe
parents: 3446
diff changeset
2146 maybe_warn_assign_as_truth_value (expr);
8b1f46ac2b64 [project @ 2000-01-27 23:30:45 by jwe]
jwe
parents: 3446
diff changeset
2147
3665
0689afb1d001 [project @ 2000-05-11 19:07:56 by jwe]
jwe
parents: 3544
diff changeset
2148 octave_comment_list *tc = octave_comment_buffer::get_comment ();
0689afb1d001 [project @ 2000-05-11 19:07:56 by jwe]
jwe
parents: 3544
diff changeset
2149
3484
8b1f46ac2b64 [project @ 2000-01-27 23:30:45 by jwe]
jwe
parents: 3446
diff changeset
2150 lexer_flags.looping--;
8b1f46ac2b64 [project @ 2000-01-27 23:30:45 by jwe]
jwe
parents: 3446
diff changeset
2151
8658
73c4516fae10 New evaluator and debugger derived from tree-walker class
John W. Eaton <jwe@octave.org>
parents: 8471
diff changeset
2152 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
2153 int c = until_tok->column ();
3484
8b1f46ac2b64 [project @ 2000-01-27 23:30:45 by jwe]
jwe
parents: 3446
diff changeset
2154
3665
0689afb1d001 [project @ 2000-05-11 19:07:56 by jwe]
jwe
parents: 3544
diff changeset
2155 retval = 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
2156
8b1f46ac2b64 [project @ 2000-01-27 23:30:45 by jwe]
jwe
parents: 3446
diff changeset
2157 return retval;
8b1f46ac2b64 [project @ 2000-01-27 23:30:45 by jwe]
jwe
parents: 3446
diff changeset
2158 }
8b1f46ac2b64 [project @ 2000-01-27 23:30:45 by jwe]
jwe
parents: 3446
diff changeset
2159
1623
fa7a847f9b92 [project @ 1995-11-06 18:05:09 by jwe]
jwe
parents: 1607
diff changeset
2160 // Build a for command.
fa7a847f9b92 [project @ 1995-11-06 18:05:09 by jwe]
jwe
parents: 1607
diff changeset
2161
fa7a847f9b92 [project @ 1995-11-06 18:05:09 by jwe]
jwe
parents: 1607
diff changeset
2162 static tree_command *
2970
b9e64477f703 [project @ 1997-05-15 18:04:21 by jwe]
jwe
parents: 2961
diff changeset
2163 make_for_command (token *for_tok, tree_argument_list *lhs,
1623
fa7a847f9b92 [project @ 1995-11-06 18:05:09 by jwe]
jwe
parents: 1607
diff changeset
2164 tree_expression *expr, tree_statement_list *body,
3665
0689afb1d001 [project @ 2000-05-11 19:07:56 by jwe]
jwe
parents: 3544
diff changeset
2165 token *end_tok, octave_comment_list *lc)
1623
fa7a847f9b92 [project @ 1995-11-06 18:05:09 by jwe]
jwe
parents: 1607
diff changeset
2166 {
fa7a847f9b92 [project @ 1995-11-06 18:05:09 by jwe]
jwe
parents: 1607
diff changeset
2167 tree_command *retval = 0;
fa7a847f9b92 [project @ 1995-11-06 18:05:09 by jwe]
jwe
parents: 1607
diff changeset
2168
2857
5448c8cba402 [project @ 1997-03-31 07:06:10 by jwe]
jwe
parents: 2856
diff changeset
2169 if (end_token_ok (end_tok, token::for_end))
1623
fa7a847f9b92 [project @ 1995-11-06 18:05:09 by jwe]
jwe
parents: 1607
diff changeset
2170 {
3665
0689afb1d001 [project @ 2000-05-11 19:07:56 by jwe]
jwe
parents: 3544
diff changeset
2171 octave_comment_list *tc = octave_comment_buffer::get_comment ();
0689afb1d001 [project @ 2000-05-11 19:07:56 by jwe]
jwe
parents: 3544
diff changeset
2172
1826
b14829582cc4 [project @ 1996-02-02 03:05:07 by jwe]
jwe
parents: 1755
diff changeset
2173 lexer_flags.looping--;
1623
fa7a847f9b92 [project @ 1995-11-06 18:05:09 by jwe]
jwe
parents: 1607
diff changeset
2174
fa7a847f9b92 [project @ 1995-11-06 18:05:09 by jwe]
jwe
parents: 1607
diff changeset
2175 int l = for_tok->line ();
fa7a847f9b92 [project @ 1995-11-06 18:05:09 by jwe]
jwe
parents: 1607
diff changeset
2176 int c = for_tok->column ();
fa7a847f9b92 [project @ 1995-11-06 18:05:09 by jwe]
jwe
parents: 1607
diff changeset
2177
2970
b9e64477f703 [project @ 1997-05-15 18:04:21 by jwe]
jwe
parents: 2961
diff changeset
2178 if (lhs->length () == 1)
b9e64477f703 [project @ 1997-05-15 18:04:21 by jwe]
jwe
parents: 2961
diff changeset
2179 {
b9e64477f703 [project @ 1997-05-15 18:04:21 by jwe]
jwe
parents: 2961
diff changeset
2180 tree_expression *tmp = lhs->remove_front ();
b9e64477f703 [project @ 1997-05-15 18:04:21 by jwe]
jwe
parents: 2961
diff changeset
2181
3665
0689afb1d001 [project @ 2000-05-11 19:07:56 by jwe]
jwe
parents: 3544
diff changeset
2182 retval = new tree_simple_for_command (tmp, expr, body,
0689afb1d001 [project @ 2000-05-11 19:07:56 by jwe]
jwe
parents: 3544
diff changeset
2183 lc, tc, l, c);
2970
b9e64477f703 [project @ 1997-05-15 18:04:21 by jwe]
jwe
parents: 2961
diff changeset
2184
b9e64477f703 [project @ 1997-05-15 18:04:21 by jwe]
jwe
parents: 2961
diff changeset
2185 delete lhs;
b9e64477f703 [project @ 1997-05-15 18:04:21 by jwe]
jwe
parents: 2961
diff changeset
2186 }
b9e64477f703 [project @ 1997-05-15 18:04:21 by jwe]
jwe
parents: 2961
diff changeset
2187 else
3665
0689afb1d001 [project @ 2000-05-11 19:07:56 by jwe]
jwe
parents: 3544
diff changeset
2188 retval = new tree_complex_for_command (lhs, expr, body,
0689afb1d001 [project @ 2000-05-11 19:07:56 by jwe]
jwe
parents: 3544
diff changeset
2189 lc, tc, l, c);
1623
fa7a847f9b92 [project @ 1995-11-06 18:05:09 by jwe]
jwe
parents: 1607
diff changeset
2190 }
fa7a847f9b92 [project @ 1995-11-06 18:05:09 by jwe]
jwe
parents: 1607
diff changeset
2191
fa7a847f9b92 [project @ 1995-11-06 18:05:09 by jwe]
jwe
parents: 1607
diff changeset
2192 return retval;
fa7a847f9b92 [project @ 1995-11-06 18:05:09 by jwe]
jwe
parents: 1607
diff changeset
2193 }
fa7a847f9b92 [project @ 1995-11-06 18:05:09 by jwe]
jwe
parents: 1607
diff changeset
2194
4207
fa3482b34599 [project @ 2002-12-03 18:22:05 by jwe]
jwe
parents: 4186
diff changeset
2195 // Build a break command.
fa3482b34599 [project @ 2002-12-03 18:22:05 by jwe]
jwe
parents: 4186
diff changeset
2196
fa3482b34599 [project @ 2002-12-03 18:22:05 by jwe]
jwe
parents: 4186
diff changeset
2197 static tree_command *
fa3482b34599 [project @ 2002-12-03 18:22:05 by jwe]
jwe
parents: 4186
diff changeset
2198 make_break_command (token *break_tok)
1623
fa7a847f9b92 [project @ 1995-11-06 18:05:09 by jwe]
jwe
parents: 1607
diff changeset
2199 {
4207
fa3482b34599 [project @ 2002-12-03 18:22:05 by jwe]
jwe
parents: 4186
diff changeset
2200 tree_command *retval = 0;
1623
fa7a847f9b92 [project @ 1995-11-06 18:05:09 by jwe]
jwe
parents: 1607
diff changeset
2201
2620
5c773d4745d6 [project @ 1997-01-23 16:26:25 by jwe]
jwe
parents: 2542
diff changeset
2202 int l = break_tok->line ();
5c773d4745d6 [project @ 1997-01-23 16:26:25 by jwe]
jwe
parents: 2542
diff changeset
2203 int c = break_tok->column ();
5c773d4745d6 [project @ 1997-01-23 16:26:25 by jwe]
jwe
parents: 2542
diff changeset
2204
8669
33783e94fb16 line number fixes and other evaluator tweaks
John W. Eaton <jwe@octave.org>
parents: 8658
diff changeset
2205 // We check to see if we are evaluating a function, script, or loop
33783e94fb16 line number fixes and other evaluator tweaks
John W. Eaton <jwe@octave.org>
parents: 8658
diff changeset
2206 // so that we don't turn eval ("break;") inside a function, script,
33783e94fb16 line number fixes and other evaluator tweaks
John W. Eaton <jwe@octave.org>
parents: 8658
diff changeset
2207 // or loop into a no-op command.
33783e94fb16 line number fixes and other evaluator tweaks
John W. Eaton <jwe@octave.org>
parents: 8658
diff changeset
2208
3489
cbee5fbb696d [project @ 2000-01-28 09:14:32 by jwe]
jwe
parents: 3485
diff changeset
2209 if (lexer_flags.looping || lexer_flags.defining_func
8669
33783e94fb16 line number fixes and other evaluator tweaks
John W. Eaton <jwe@octave.org>
parents: 8658
diff changeset
2210 || reading_script_file || tree_evaluator::in_fcn_or_script_body
33783e94fb16 line number fixes and other evaluator tweaks
John W. Eaton <jwe@octave.org>
parents: 8658
diff changeset
2211 || tree_evaluator::in_loop_command)
4207
fa3482b34599 [project @ 2002-12-03 18:22:05 by jwe]
jwe
parents: 4186
diff changeset
2212 retval = new tree_break_command (l, c);
1623
fa7a847f9b92 [project @ 1995-11-06 18:05:09 by jwe]
jwe
parents: 1607
diff changeset
2213 else
4207
fa3482b34599 [project @ 2002-12-03 18:22:05 by jwe]
jwe
parents: 4186
diff changeset
2214 retval = new tree_no_op_command ("break", l, c);
1623
fa7a847f9b92 [project @ 1995-11-06 18:05:09 by jwe]
jwe
parents: 1607
diff changeset
2215
fa7a847f9b92 [project @ 1995-11-06 18:05:09 by jwe]
jwe
parents: 1607
diff changeset
2216 return retval;
fa7a847f9b92 [project @ 1995-11-06 18:05:09 by jwe]
jwe
parents: 1607
diff changeset
2217 }
fa7a847f9b92 [project @ 1995-11-06 18:05:09 by jwe]
jwe
parents: 1607
diff changeset
2218
4207
fa3482b34599 [project @ 2002-12-03 18:22:05 by jwe]
jwe
parents: 4186
diff changeset
2219 // Build a continue command.
fa3482b34599 [project @ 2002-12-03 18:22:05 by jwe]
jwe
parents: 4186
diff changeset
2220
fa3482b34599 [project @ 2002-12-03 18:22:05 by jwe]
jwe
parents: 4186
diff changeset
2221 static tree_command *
fa3482b34599 [project @ 2002-12-03 18:22:05 by jwe]
jwe
parents: 4186
diff changeset
2222 make_continue_command (token *continue_tok)
1623
fa7a847f9b92 [project @ 1995-11-06 18:05:09 by jwe]
jwe
parents: 1607
diff changeset
2223 {
4207
fa3482b34599 [project @ 2002-12-03 18:22:05 by jwe]
jwe
parents: 4186
diff changeset
2224 tree_command *retval = 0;
1623
fa7a847f9b92 [project @ 1995-11-06 18:05:09 by jwe]
jwe
parents: 1607
diff changeset
2225
2620
5c773d4745d6 [project @ 1997-01-23 16:26:25 by jwe]
jwe
parents: 2542
diff changeset
2226 int l = continue_tok->line ();
5c773d4745d6 [project @ 1997-01-23 16:26:25 by jwe]
jwe
parents: 2542
diff changeset
2227 int c = continue_tok->column ();
5c773d4745d6 [project @ 1997-01-23 16:26:25 by jwe]
jwe
parents: 2542
diff changeset
2228
8669
33783e94fb16 line number fixes and other evaluator tweaks
John W. Eaton <jwe@octave.org>
parents: 8658
diff changeset
2229 // We check to see if we are evaluating a loop so that we don't turn
33783e94fb16 line number fixes and other evaluator tweaks
John W. Eaton <jwe@octave.org>
parents: 8658
diff changeset
2230 // eval ("continue;") into a no-op command inside a loop.
33783e94fb16 line number fixes and other evaluator tweaks
John W. Eaton <jwe@octave.org>
parents: 8658
diff changeset
2231
33783e94fb16 line number fixes and other evaluator tweaks
John W. Eaton <jwe@octave.org>
parents: 8658
diff changeset
2232 if (lexer_flags.looping || tree_evaluator::in_loop_command)
4207
fa3482b34599 [project @ 2002-12-03 18:22:05 by jwe]
jwe
parents: 4186
diff changeset
2233 retval = new tree_continue_command (l, c);
1623
fa7a847f9b92 [project @ 1995-11-06 18:05:09 by jwe]
jwe
parents: 1607
diff changeset
2234 else
4207
fa3482b34599 [project @ 2002-12-03 18:22:05 by jwe]
jwe
parents: 4186
diff changeset
2235 retval = new tree_no_op_command ("continue", l, c);
1623
fa7a847f9b92 [project @ 1995-11-06 18:05:09 by jwe]
jwe
parents: 1607
diff changeset
2236
fa7a847f9b92 [project @ 1995-11-06 18:05:09 by jwe]
jwe
parents: 1607
diff changeset
2237 return retval;
fa7a847f9b92 [project @ 1995-11-06 18:05:09 by jwe]
jwe
parents: 1607
diff changeset
2238 }
fa7a847f9b92 [project @ 1995-11-06 18:05:09 by jwe]
jwe
parents: 1607
diff changeset
2239
4207
fa3482b34599 [project @ 2002-12-03 18:22:05 by jwe]
jwe
parents: 4186
diff changeset
2240 // Build a return command.
fa3482b34599 [project @ 2002-12-03 18:22:05 by jwe]
jwe
parents: 4186
diff changeset
2241
fa3482b34599 [project @ 2002-12-03 18:22:05 by jwe]
jwe
parents: 4186
diff changeset
2242 static tree_command *
fa3482b34599 [project @ 2002-12-03 18:22:05 by jwe]
jwe
parents: 4186
diff changeset
2243 make_return_command (token *return_tok)
1623
fa7a847f9b92 [project @ 1995-11-06 18:05:09 by jwe]
jwe
parents: 1607
diff changeset
2244 {
4207
fa3482b34599 [project @ 2002-12-03 18:22:05 by jwe]
jwe
parents: 4186
diff changeset
2245 tree_command *retval = 0;
1623
fa7a847f9b92 [project @ 1995-11-06 18:05:09 by jwe]
jwe
parents: 1607
diff changeset
2246
2620
5c773d4745d6 [project @ 1997-01-23 16:26:25 by jwe]
jwe
parents: 2542
diff changeset
2247 int l = return_tok->line ();
5c773d4745d6 [project @ 1997-01-23 16:26:25 by jwe]
jwe
parents: 2542
diff changeset
2248 int c = return_tok->column ();
5c773d4745d6 [project @ 1997-01-23 16:26:25 by jwe]
jwe
parents: 2542
diff changeset
2249
7787
6b521b1e3631 Add dbquit and make dbstep compatible. Use parser in debug mode to handle multi-line input
David Bateman <dbateman@free.fr>
parents: 7761
diff changeset
2250 if (Vdebugging)
6b521b1e3631 Add dbquit and make dbstep compatible. Use parser in debug mode to handle multi-line input
David Bateman <dbateman@free.fr>
parents: 7761
diff changeset
2251 {
6b521b1e3631 Add dbquit and make dbstep compatible. Use parser in debug mode to handle multi-line input
David Bateman <dbateman@free.fr>
parents: 7761
diff changeset
2252 Vdebugging = false;
6b521b1e3631 Add dbquit and make dbstep compatible. Use parser in debug mode to handle multi-line input
David Bateman <dbateman@free.fr>
parents: 7761
diff changeset
2253
6b521b1e3631 Add dbquit and make dbstep compatible. Use parser in debug mode to handle multi-line input
David Bateman <dbateman@free.fr>
parents: 7761
diff changeset
2254 retval = new tree_no_op_command ("return", l, c);
6b521b1e3631 Add dbquit and make dbstep compatible. Use parser in debug mode to handle multi-line input
David Bateman <dbateman@free.fr>
parents: 7761
diff changeset
2255 }
1623
fa7a847f9b92 [project @ 1995-11-06 18:05:09 by jwe]
jwe
parents: 1607
diff changeset
2256 else
7787
6b521b1e3631 Add dbquit and make dbstep compatible. Use parser in debug mode to handle multi-line input
David Bateman <dbateman@free.fr>
parents: 7761
diff changeset
2257 {
8669
33783e94fb16 line number fixes and other evaluator tweaks
John W. Eaton <jwe@octave.org>
parents: 8658
diff changeset
2258 // We check to see if we are evaluating a function or script so
33783e94fb16 line number fixes and other evaluator tweaks
John W. Eaton <jwe@octave.org>
parents: 8658
diff changeset
2259 // that we don't turn eval ("return;") inside a function, script,
33783e94fb16 line number fixes and other evaluator tweaks
John W. Eaton <jwe@octave.org>
parents: 8658
diff changeset
2260 // or loop into a no-op command.
33783e94fb16 line number fixes and other evaluator tweaks
John W. Eaton <jwe@octave.org>
parents: 8658
diff changeset
2261
7787
6b521b1e3631 Add dbquit and make dbstep compatible. Use parser in debug mode to handle multi-line input
David Bateman <dbateman@free.fr>
parents: 7761
diff changeset
2262 if (lexer_flags.defining_func || reading_script_file
8669
33783e94fb16 line number fixes and other evaluator tweaks
John W. Eaton <jwe@octave.org>
parents: 8658
diff changeset
2263 || tree_evaluator::in_fcn_or_script_body)
7787
6b521b1e3631 Add dbquit and make dbstep compatible. Use parser in debug mode to handle multi-line input
David Bateman <dbateman@free.fr>
parents: 7761
diff changeset
2264 retval = new tree_return_command (l, c);
6b521b1e3631 Add dbquit and make dbstep compatible. Use parser in debug mode to handle multi-line input
David Bateman <dbateman@free.fr>
parents: 7761
diff changeset
2265 else
6b521b1e3631 Add dbquit and make dbstep compatible. Use parser in debug mode to handle multi-line input
David Bateman <dbateman@free.fr>
parents: 7761
diff changeset
2266 retval = new tree_no_op_command ("return", l, c);
6b521b1e3631 Add dbquit and make dbstep compatible. Use parser in debug mode to handle multi-line input
David Bateman <dbateman@free.fr>
parents: 7761
diff changeset
2267 }
1623
fa7a847f9b92 [project @ 1995-11-06 18:05:09 by jwe]
jwe
parents: 1607
diff changeset
2268
fa7a847f9b92 [project @ 1995-11-06 18:05:09 by jwe]
jwe
parents: 1607
diff changeset
2269 return retval;
fa7a847f9b92 [project @ 1995-11-06 18:05:09 by jwe]
jwe
parents: 1607
diff changeset
2270 }
fa7a847f9b92 [project @ 1995-11-06 18:05:09 by jwe]
jwe
parents: 1607
diff changeset
2271
fa7a847f9b92 [project @ 1995-11-06 18:05:09 by jwe]
jwe
parents: 1607
diff changeset
2272 // Start an if command.
fa7a847f9b92 [project @ 1995-11-06 18:05:09 by jwe]
jwe
parents: 1607
diff changeset
2273
fa7a847f9b92 [project @ 1995-11-06 18:05:09 by jwe]
jwe
parents: 1607
diff changeset
2274 static tree_if_command_list *
fa7a847f9b92 [project @ 1995-11-06 18:05:09 by jwe]
jwe
parents: 1607
diff changeset
2275 start_if_command (tree_expression *expr, tree_statement_list *list)
fa7a847f9b92 [project @ 1995-11-06 18:05:09 by jwe]
jwe
parents: 1607
diff changeset
2276 {
fa7a847f9b92 [project @ 1995-11-06 18:05:09 by jwe]
jwe
parents: 1607
diff changeset
2277 maybe_warn_assign_as_truth_value (expr);
fa7a847f9b92 [project @ 1995-11-06 18:05:09 by jwe]
jwe
parents: 1607
diff changeset
2278
fa7a847f9b92 [project @ 1995-11-06 18:05:09 by jwe]
jwe
parents: 1607
diff changeset
2279 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
2280
fa7a847f9b92 [project @ 1995-11-06 18:05:09 by jwe]
jwe
parents: 1607
diff changeset
2281 return new tree_if_command_list (t);
fa7a847f9b92 [project @ 1995-11-06 18:05:09 by jwe]
jwe
parents: 1607
diff changeset
2282 }
fa7a847f9b92 [project @ 1995-11-06 18:05:09 by jwe]
jwe
parents: 1607
diff changeset
2283
fa7a847f9b92 [project @ 1995-11-06 18:05:09 by jwe]
jwe
parents: 1607
diff changeset
2284 // Finish an if command.
fa7a847f9b92 [project @ 1995-11-06 18:05:09 by jwe]
jwe
parents: 1607
diff changeset
2285
fa7a847f9b92 [project @ 1995-11-06 18:05:09 by jwe]
jwe
parents: 1607
diff changeset
2286 static tree_if_command *
fa7a847f9b92 [project @ 1995-11-06 18:05:09 by jwe]
jwe
parents: 1607
diff changeset
2287 finish_if_command (token *if_tok, tree_if_command_list *list,
3665
0689afb1d001 [project @ 2000-05-11 19:07:56 by jwe]
jwe
parents: 3544
diff changeset
2288 token *end_tok, octave_comment_list *lc)
1623
fa7a847f9b92 [project @ 1995-11-06 18:05:09 by jwe]
jwe
parents: 1607
diff changeset
2289 {
fa7a847f9b92 [project @ 1995-11-06 18:05:09 by jwe]
jwe
parents: 1607
diff changeset
2290 tree_if_command *retval = 0;
fa7a847f9b92 [project @ 1995-11-06 18:05:09 by jwe]
jwe
parents: 1607
diff changeset
2291
2857
5448c8cba402 [project @ 1997-03-31 07:06:10 by jwe]
jwe
parents: 2856
diff changeset
2292 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
2293 {
3665
0689afb1d001 [project @ 2000-05-11 19:07:56 by jwe]
jwe
parents: 3544
diff changeset
2294 octave_comment_list *tc = octave_comment_buffer::get_comment ();
0689afb1d001 [project @ 2000-05-11 19:07:56 by jwe]
jwe
parents: 3544
diff changeset
2295
1623
fa7a847f9b92 [project @ 1995-11-06 18:05:09 by jwe]
jwe
parents: 1607
diff changeset
2296 int l = if_tok->line ();
fa7a847f9b92 [project @ 1995-11-06 18:05:09 by jwe]
jwe
parents: 1607
diff changeset
2297 int c = if_tok->column ();
fa7a847f9b92 [project @ 1995-11-06 18:05:09 by jwe]
jwe
parents: 1607
diff changeset
2298
8842
be7b30a24938 line/column info for switch and if statements
John W. Eaton <jwe@octave.org>
parents: 8828
diff changeset
2299 if (list && ! list->empty ())
be7b30a24938 line/column info for switch and if statements
John W. Eaton <jwe@octave.org>
parents: 8828
diff changeset
2300 {
be7b30a24938 line/column info for switch and if statements
John W. Eaton <jwe@octave.org>
parents: 8828
diff changeset
2301 tree_if_clause *elt = list->front ();
be7b30a24938 line/column info for switch and if statements
John W. Eaton <jwe@octave.org>
parents: 8828
diff changeset
2302
be7b30a24938 line/column info for switch and if statements
John W. Eaton <jwe@octave.org>
parents: 8828
diff changeset
2303 if (elt)
be7b30a24938 line/column info for switch and if statements
John W. Eaton <jwe@octave.org>
parents: 8828
diff changeset
2304 {
be7b30a24938 line/column info for switch and if statements
John W. Eaton <jwe@octave.org>
parents: 8828
diff changeset
2305 elt->line (l);
be7b30a24938 line/column info for switch and if statements
John W. Eaton <jwe@octave.org>
parents: 8828
diff changeset
2306 elt->column (c);
be7b30a24938 line/column info for switch and if statements
John W. Eaton <jwe@octave.org>
parents: 8828
diff changeset
2307 }
be7b30a24938 line/column info for switch and if statements
John W. Eaton <jwe@octave.org>
parents: 8828
diff changeset
2308 }
be7b30a24938 line/column info for switch and if statements
John W. Eaton <jwe@octave.org>
parents: 8828
diff changeset
2309
3665
0689afb1d001 [project @ 2000-05-11 19:07:56 by jwe]
jwe
parents: 3544
diff changeset
2310 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
2311 }
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 return retval;
fa7a847f9b92 [project @ 1995-11-06 18:05:09 by jwe]
jwe
parents: 1607
diff changeset
2314 }
fa7a847f9b92 [project @ 1995-11-06 18:05:09 by jwe]
jwe
parents: 1607
diff changeset
2315
fa7a847f9b92 [project @ 1995-11-06 18:05:09 by jwe]
jwe
parents: 1607
diff changeset
2316 // Build an elseif clause.
fa7a847f9b92 [project @ 1995-11-06 18:05:09 by jwe]
jwe
parents: 1607
diff changeset
2317
fa7a847f9b92 [project @ 1995-11-06 18:05:09 by jwe]
jwe
parents: 1607
diff changeset
2318 static tree_if_clause *
8658
73c4516fae10 New evaluator and debugger derived from tree-walker class
John W. Eaton <jwe@octave.org>
parents: 8471
diff changeset
2319 make_elseif_clause (token *elseif_tok, tree_expression *expr,
73c4516fae10 New evaluator and debugger derived from tree-walker class
John W. Eaton <jwe@octave.org>
parents: 8471
diff changeset
2320 tree_statement_list *list, octave_comment_list *lc)
1623
fa7a847f9b92 [project @ 1995-11-06 18:05:09 by jwe]
jwe
parents: 1607
diff changeset
2321 {
fa7a847f9b92 [project @ 1995-11-06 18:05:09 by jwe]
jwe
parents: 1607
diff changeset
2322 maybe_warn_assign_as_truth_value (expr);
fa7a847f9b92 [project @ 1995-11-06 18:05:09 by jwe]
jwe
parents: 1607
diff changeset
2323
8658
73c4516fae10 New evaluator and debugger derived from tree-walker class
John W. Eaton <jwe@octave.org>
parents: 8471
diff changeset
2324 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
2325 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
2326
73c4516fae10 New evaluator and debugger derived from tree-walker class
John W. Eaton <jwe@octave.org>
parents: 8471
diff changeset
2327 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
2328 }
fa7a847f9b92 [project @ 1995-11-06 18:05:09 by jwe]
jwe
parents: 1607
diff changeset
2329
2764
2c0f259cf83d [project @ 1997-03-01 02:30:26 by jwe]
jwe
parents: 2745
diff changeset
2330 // Finish a switch command.
2c0f259cf83d [project @ 1997-03-01 02:30:26 by jwe]
jwe
parents: 2745
diff changeset
2331
2c0f259cf83d [project @ 1997-03-01 02:30:26 by jwe]
jwe
parents: 2745
diff changeset
2332 static tree_switch_command *
2c0f259cf83d [project @ 1997-03-01 02:30:26 by jwe]
jwe
parents: 2745
diff changeset
2333 finish_switch_command (token *switch_tok, tree_expression *expr,
3665
0689afb1d001 [project @ 2000-05-11 19:07:56 by jwe]
jwe
parents: 3544
diff changeset
2334 tree_switch_case_list *list, token *end_tok,
0689afb1d001 [project @ 2000-05-11 19:07:56 by jwe]
jwe
parents: 3544
diff changeset
2335 octave_comment_list *lc)
2764
2c0f259cf83d [project @ 1997-03-01 02:30:26 by jwe]
jwe
parents: 2745
diff changeset
2336 {
2c0f259cf83d [project @ 1997-03-01 02:30:26 by jwe]
jwe
parents: 2745
diff changeset
2337 tree_switch_command *retval = 0;
2c0f259cf83d [project @ 1997-03-01 02:30:26 by jwe]
jwe
parents: 2745
diff changeset
2338
2857
5448c8cba402 [project @ 1997-03-31 07:06:10 by jwe]
jwe
parents: 2856
diff changeset
2339 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
2340 {
3665
0689afb1d001 [project @ 2000-05-11 19:07:56 by jwe]
jwe
parents: 3544
diff changeset
2341 octave_comment_list *tc = octave_comment_buffer::get_comment ();
0689afb1d001 [project @ 2000-05-11 19:07:56 by jwe]
jwe
parents: 3544
diff changeset
2342
2764
2c0f259cf83d [project @ 1997-03-01 02:30:26 by jwe]
jwe
parents: 2745
diff changeset
2343 int l = switch_tok->line ();
2c0f259cf83d [project @ 1997-03-01 02:30:26 by jwe]
jwe
parents: 2745
diff changeset
2344 int c = switch_tok->column ();
2c0f259cf83d [project @ 1997-03-01 02:30:26 by jwe]
jwe
parents: 2745
diff changeset
2345
8842
be7b30a24938 line/column info for switch and if statements
John W. Eaton <jwe@octave.org>
parents: 8828
diff changeset
2346 if (list && ! list->empty ())
be7b30a24938 line/column info for switch and if statements
John W. Eaton <jwe@octave.org>
parents: 8828
diff changeset
2347 {
be7b30a24938 line/column info for switch and if statements
John W. Eaton <jwe@octave.org>
parents: 8828
diff changeset
2348 tree_switch_case *elt = list->front ();
be7b30a24938 line/column info for switch and if statements
John W. Eaton <jwe@octave.org>
parents: 8828
diff changeset
2349
be7b30a24938 line/column info for switch and if statements
John W. Eaton <jwe@octave.org>
parents: 8828
diff changeset
2350 if (elt)
be7b30a24938 line/column info for switch and if statements
John W. Eaton <jwe@octave.org>
parents: 8828
diff changeset
2351 {
be7b30a24938 line/column info for switch and if statements
John W. Eaton <jwe@octave.org>
parents: 8828
diff changeset
2352 elt->line (l);
be7b30a24938 line/column info for switch and if statements
John W. Eaton <jwe@octave.org>
parents: 8828
diff changeset
2353 elt->column (c);
be7b30a24938 line/column info for switch and if statements
John W. Eaton <jwe@octave.org>
parents: 8828
diff changeset
2354 }
be7b30a24938 line/column info for switch and if statements
John W. Eaton <jwe@octave.org>
parents: 8828
diff changeset
2355 }
be7b30a24938 line/column info for switch and if statements
John W. Eaton <jwe@octave.org>
parents: 8828
diff changeset
2356
3665
0689afb1d001 [project @ 2000-05-11 19:07:56 by jwe]
jwe
parents: 3544
diff changeset
2357 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
2358 }
2c0f259cf83d [project @ 1997-03-01 02:30:26 by jwe]
jwe
parents: 2745
diff changeset
2359
2c0f259cf83d [project @ 1997-03-01 02:30:26 by jwe]
jwe
parents: 2745
diff changeset
2360 return retval;
2c0f259cf83d [project @ 1997-03-01 02:30:26 by jwe]
jwe
parents: 2745
diff changeset
2361 }
2c0f259cf83d [project @ 1997-03-01 02:30:26 by jwe]
jwe
parents: 2745
diff changeset
2362
2c0f259cf83d [project @ 1997-03-01 02:30:26 by jwe]
jwe
parents: 2745
diff changeset
2363 // Build a switch case.
2c0f259cf83d [project @ 1997-03-01 02:30:26 by jwe]
jwe
parents: 2745
diff changeset
2364
2c0f259cf83d [project @ 1997-03-01 02:30:26 by jwe]
jwe
parents: 2745
diff changeset
2365 static tree_switch_case *
8658
73c4516fae10 New evaluator and debugger derived from tree-walker class
John W. Eaton <jwe@octave.org>
parents: 8471
diff changeset
2366 make_switch_case (token *case_tok, tree_expression *expr,
73c4516fae10 New evaluator and debugger derived from tree-walker class
John W. Eaton <jwe@octave.org>
parents: 8471
diff changeset
2367 tree_statement_list *list, octave_comment_list *lc)
2764
2c0f259cf83d [project @ 1997-03-01 02:30:26 by jwe]
jwe
parents: 2745
diff changeset
2368 {
2c0f259cf83d [project @ 1997-03-01 02:30:26 by jwe]
jwe
parents: 2745
diff changeset
2369 maybe_warn_variable_switch_label (expr);
2c0f259cf83d [project @ 1997-03-01 02:30:26 by jwe]
jwe
parents: 2745
diff changeset
2370
8658
73c4516fae10 New evaluator and debugger derived from tree-walker class
John W. Eaton <jwe@octave.org>
parents: 8471
diff changeset
2371 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
2372 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
2373
73c4516fae10 New evaluator and debugger derived from tree-walker class
John W. Eaton <jwe@octave.org>
parents: 8471
diff changeset
2374 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
2375 }
2c0f259cf83d [project @ 1997-03-01 02:30:26 by jwe]
jwe
parents: 2745
diff changeset
2376
1623
fa7a847f9b92 [project @ 1995-11-06 18:05:09 by jwe]
jwe
parents: 1607
diff changeset
2377 // Build an assignment to a variable.
fa7a847f9b92 [project @ 1995-11-06 18:05:09 by jwe]
jwe
parents: 1607
diff changeset
2378
fa7a847f9b92 [project @ 1995-11-06 18:05:09 by jwe]
jwe
parents: 1607
diff changeset
2379 static tree_expression *
2970
b9e64477f703 [project @ 1997-05-15 18:04:21 by jwe]
jwe
parents: 2961
diff changeset
2380 make_assign_op (int op, tree_argument_list *lhs, token *eq_tok,
b9e64477f703 [project @ 1997-05-15 18:04:21 by jwe]
jwe
parents: 2961
diff changeset
2381 tree_expression *rhs)
1623
fa7a847f9b92 [project @ 1995-11-06 18:05:09 by jwe]
jwe
parents: 1607
diff changeset
2382 {
2970
b9e64477f703 [project @ 1997-05-15 18:04:21 by jwe]
jwe
parents: 2961
diff changeset
2383 tree_expression *retval = 0;
b9e64477f703 [project @ 1997-05-15 18:04:21 by jwe]
jwe
parents: 2961
diff changeset
2384
2883
0b3954110c77 [project @ 1997-04-24 09:57:05 by jwe]
jwe
parents: 2865
diff changeset
2385 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
2386
0b3954110c77 [project @ 1997-04-24 09:57:05 by jwe]
jwe
parents: 2865
diff changeset
2387 switch (op)
0b3954110c77 [project @ 1997-04-24 09:57:05 by jwe]
jwe
parents: 2865
diff changeset
2388 {
0b3954110c77 [project @ 1997-04-24 09:57:05 by jwe]
jwe
parents: 2865
diff changeset
2389 case '=':
3525
6cfa474c5b99 [project @ 2000-02-02 10:48:41 by jwe]
jwe
parents: 3523
diff changeset
2390 t = octave_value::op_asn_eq;
2883
0b3954110c77 [project @ 1997-04-24 09:57:05 by jwe]
jwe
parents: 2865
diff changeset
2391 break;
0b3954110c77 [project @ 1997-04-24 09:57:05 by jwe]
jwe
parents: 2865
diff changeset
2392
0b3954110c77 [project @ 1997-04-24 09:57:05 by jwe]
jwe
parents: 2865
diff changeset
2393 case ADD_EQ:
3525
6cfa474c5b99 [project @ 2000-02-02 10:48:41 by jwe]
jwe
parents: 3523
diff changeset
2394 t = octave_value::op_add_eq;
2883
0b3954110c77 [project @ 1997-04-24 09:57:05 by jwe]
jwe
parents: 2865
diff changeset
2395 break;
0b3954110c77 [project @ 1997-04-24 09:57:05 by jwe]
jwe
parents: 2865
diff changeset
2396
0b3954110c77 [project @ 1997-04-24 09:57:05 by jwe]
jwe
parents: 2865
diff changeset
2397 case SUB_EQ:
3525
6cfa474c5b99 [project @ 2000-02-02 10:48:41 by jwe]
jwe
parents: 3523
diff changeset
2398 t = octave_value::op_sub_eq;
2883
0b3954110c77 [project @ 1997-04-24 09:57:05 by jwe]
jwe
parents: 2865
diff changeset
2399 break;
0b3954110c77 [project @ 1997-04-24 09:57:05 by jwe]
jwe
parents: 2865
diff changeset
2400
0b3954110c77 [project @ 1997-04-24 09:57:05 by jwe]
jwe
parents: 2865
diff changeset
2401 case MUL_EQ:
3525
6cfa474c5b99 [project @ 2000-02-02 10:48:41 by jwe]
jwe
parents: 3523
diff changeset
2402 t = octave_value::op_mul_eq;
2883
0b3954110c77 [project @ 1997-04-24 09:57:05 by jwe]
jwe
parents: 2865
diff changeset
2403 break;
0b3954110c77 [project @ 1997-04-24 09:57:05 by jwe]
jwe
parents: 2865
diff changeset
2404
0b3954110c77 [project @ 1997-04-24 09:57:05 by jwe]
jwe
parents: 2865
diff changeset
2405 case DIV_EQ:
3525
6cfa474c5b99 [project @ 2000-02-02 10:48:41 by jwe]
jwe
parents: 3523
diff changeset
2406 t = octave_value::op_div_eq;
2883
0b3954110c77 [project @ 1997-04-24 09:57:05 by jwe]
jwe
parents: 2865
diff changeset
2407 break;
0b3954110c77 [project @ 1997-04-24 09:57:05 by jwe]
jwe
parents: 2865
diff changeset
2408
3204
81738e630f57 [project @ 1998-10-30 23:28:29 by jwe]
jwe
parents: 3203
diff changeset
2409 case LEFTDIV_EQ:
3525
6cfa474c5b99 [project @ 2000-02-02 10:48:41 by jwe]
jwe
parents: 3523
diff changeset
2410 t = octave_value::op_ldiv_eq;
3204
81738e630f57 [project @ 1998-10-30 23:28:29 by jwe]
jwe
parents: 3203
diff changeset
2411 break;
81738e630f57 [project @ 1998-10-30 23:28:29 by jwe]
jwe
parents: 3203
diff changeset
2412
4018
a8621d87fbf5 [project @ 2002-08-05 03:17:25 by jwe]
jwe
parents: 4009
diff changeset
2413 case POW_EQ:
a8621d87fbf5 [project @ 2002-08-05 03:17:25 by jwe]
jwe
parents: 4009
diff changeset
2414 t = octave_value::op_pow_eq;
a8621d87fbf5 [project @ 2002-08-05 03:17:25 by jwe]
jwe
parents: 4009
diff changeset
2415 break;
a8621d87fbf5 [project @ 2002-08-05 03:17:25 by jwe]
jwe
parents: 4009
diff changeset
2416
2899
0d79a8c11a2b [project @ 1997-04-30 03:09:23 by jwe]
jwe
parents: 2891
diff changeset
2417 case LSHIFT_EQ:
3525
6cfa474c5b99 [project @ 2000-02-02 10:48:41 by jwe]
jwe
parents: 3523
diff changeset
2418 t = octave_value::op_lshift_eq;
2899
0d79a8c11a2b [project @ 1997-04-30 03:09:23 by jwe]
jwe
parents: 2891
diff changeset
2419 break;
0d79a8c11a2b [project @ 1997-04-30 03:09:23 by jwe]
jwe
parents: 2891
diff changeset
2420
0d79a8c11a2b [project @ 1997-04-30 03:09:23 by jwe]
jwe
parents: 2891
diff changeset
2421 case RSHIFT_EQ:
3525
6cfa474c5b99 [project @ 2000-02-02 10:48:41 by jwe]
jwe
parents: 3523
diff changeset
2422 t = octave_value::op_rshift_eq;
2899
0d79a8c11a2b [project @ 1997-04-30 03:09:23 by jwe]
jwe
parents: 2891
diff changeset
2423 break;
0d79a8c11a2b [project @ 1997-04-30 03:09:23 by jwe]
jwe
parents: 2891
diff changeset
2424
2883
0b3954110c77 [project @ 1997-04-24 09:57:05 by jwe]
jwe
parents: 2865
diff changeset
2425 case EMUL_EQ:
3525
6cfa474c5b99 [project @ 2000-02-02 10:48:41 by jwe]
jwe
parents: 3523
diff changeset
2426 t = octave_value::op_el_mul_eq;
2883
0b3954110c77 [project @ 1997-04-24 09:57:05 by jwe]
jwe
parents: 2865
diff changeset
2427 break;
0b3954110c77 [project @ 1997-04-24 09:57:05 by jwe]
jwe
parents: 2865
diff changeset
2428
0b3954110c77 [project @ 1997-04-24 09:57:05 by jwe]
jwe
parents: 2865
diff changeset
2429 case EDIV_EQ:
3525
6cfa474c5b99 [project @ 2000-02-02 10:48:41 by jwe]
jwe
parents: 3523
diff changeset
2430 t = octave_value::op_el_div_eq;
2883
0b3954110c77 [project @ 1997-04-24 09:57:05 by jwe]
jwe
parents: 2865
diff changeset
2431 break;
0b3954110c77 [project @ 1997-04-24 09:57:05 by jwe]
jwe
parents: 2865
diff changeset
2432
3204
81738e630f57 [project @ 1998-10-30 23:28:29 by jwe]
jwe
parents: 3203
diff changeset
2433 case ELEFTDIV_EQ:
3525
6cfa474c5b99 [project @ 2000-02-02 10:48:41 by jwe]
jwe
parents: 3523
diff changeset
2434 t = octave_value::op_el_ldiv_eq;
3204
81738e630f57 [project @ 1998-10-30 23:28:29 by jwe]
jwe
parents: 3203
diff changeset
2435 break;
81738e630f57 [project @ 1998-10-30 23:28:29 by jwe]
jwe
parents: 3203
diff changeset
2436
4018
a8621d87fbf5 [project @ 2002-08-05 03:17:25 by jwe]
jwe
parents: 4009
diff changeset
2437 case EPOW_EQ:
a8621d87fbf5 [project @ 2002-08-05 03:17:25 by jwe]
jwe
parents: 4009
diff changeset
2438 t = octave_value::op_el_pow_eq;
a8621d87fbf5 [project @ 2002-08-05 03:17:25 by jwe]
jwe
parents: 4009
diff changeset
2439 break;
a8621d87fbf5 [project @ 2002-08-05 03:17:25 by jwe]
jwe
parents: 4009
diff changeset
2440
2883
0b3954110c77 [project @ 1997-04-24 09:57:05 by jwe]
jwe
parents: 2865
diff changeset
2441 case AND_EQ:
3525
6cfa474c5b99 [project @ 2000-02-02 10:48:41 by jwe]
jwe
parents: 3523
diff changeset
2442 t = octave_value::op_el_and_eq;
2883
0b3954110c77 [project @ 1997-04-24 09:57:05 by jwe]
jwe
parents: 2865
diff changeset
2443 break;
0b3954110c77 [project @ 1997-04-24 09:57:05 by jwe]
jwe
parents: 2865
diff changeset
2444
0b3954110c77 [project @ 1997-04-24 09:57:05 by jwe]
jwe
parents: 2865
diff changeset
2445 case OR_EQ:
3525
6cfa474c5b99 [project @ 2000-02-02 10:48:41 by jwe]
jwe
parents: 3523
diff changeset
2446 t = octave_value::op_el_or_eq;
2883
0b3954110c77 [project @ 1997-04-24 09:57:05 by jwe]
jwe
parents: 2865
diff changeset
2447 break;
0b3954110c77 [project @ 1997-04-24 09:57:05 by jwe]
jwe
parents: 2865
diff changeset
2448
0b3954110c77 [project @ 1997-04-24 09:57:05 by jwe]
jwe
parents: 2865
diff changeset
2449 default:
0b3954110c77 [project @ 1997-04-24 09:57:05 by jwe]
jwe
parents: 2865
diff changeset
2450 panic_impossible ();
0b3954110c77 [project @ 1997-04-24 09:57:05 by jwe]
jwe
parents: 2865
diff changeset
2451 break;
0b3954110c77 [project @ 1997-04-24 09:57:05 by jwe]
jwe
parents: 2865
diff changeset
2452 }
0b3954110c77 [project @ 1997-04-24 09:57:05 by jwe]
jwe
parents: 2865
diff changeset
2453
1623
fa7a847f9b92 [project @ 1995-11-06 18:05:09 by jwe]
jwe
parents: 1607
diff changeset
2454 int l = eq_tok->line ();
fa7a847f9b92 [project @ 1995-11-06 18:05:09 by jwe]
jwe
parents: 1607
diff changeset
2455 int c = eq_tok->column ();
fa7a847f9b92 [project @ 1995-11-06 18:05:09 by jwe]
jwe
parents: 1607
diff changeset
2456
5841
fb4dea2184bf [project @ 2006-06-05 20:59:25 by jwe]
jwe
parents: 5832
diff changeset
2457 if (lhs->is_simple_assign_lhs ())
666
fb4f6556b443 [project @ 1994-09-06 21:22:46 by jwe]
jwe
parents: 627
diff changeset
2458 {
2970
b9e64477f703 [project @ 1997-05-15 18:04:21 by jwe]
jwe
parents: 2961
diff changeset
2459 tree_expression *tmp = lhs->remove_front ();
b9e64477f703 [project @ 1997-05-15 18:04:21 by jwe]
jwe
parents: 2961
diff changeset
2460
b9e64477f703 [project @ 1997-05-15 18:04:21 by jwe]
jwe
parents: 2961
diff changeset
2461 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
2462
b9e64477f703 [project @ 1997-05-15 18:04:21 by jwe]
jwe
parents: 2961
diff changeset
2463 delete lhs;
666
fb4f6556b443 [project @ 1994-09-06 21:22:46 by jwe]
jwe
parents: 627
diff changeset
2464 }
fb4f6556b443 [project @ 1994-09-06 21:22:46 by jwe]
jwe
parents: 627
diff changeset
2465 else
3208
e8a7163701be [project @ 1998-11-03 05:12:47 by jwe]
jwe
parents: 3204
diff changeset
2466 return new tree_multi_assignment (lhs, rhs, false, l, c, t);
666
fb4f6556b443 [project @ 1994-09-06 21:22:46 by jwe]
jwe
parents: 627
diff changeset
2467
fb4f6556b443 [project @ 1994-09-06 21:22:46 by jwe]
jwe
parents: 627
diff changeset
2468 return retval;
fb4f6556b443 [project @ 1994-09-06 21:22:46 by jwe]
jwe
parents: 627
diff changeset
2469 }
751
c9f3cb77478d [project @ 1994-09-30 18:46:17 by jwe]
jwe
parents: 723
diff changeset
2470
7715
5b4d278ec828 parse scripts completely before executing
John W. Eaton <jwe@octave.org>
parents: 7699
diff changeset
2471 // Define a function.
5b4d278ec828 parse scripts completely before executing
John W. Eaton <jwe@octave.org>
parents: 7699
diff changeset
2472
5b4d278ec828 parse scripts completely before executing
John W. Eaton <jwe@octave.org>
parents: 7699
diff changeset
2473 static void
8658
73c4516fae10 New evaluator and debugger derived from tree-walker class
John W. Eaton <jwe@octave.org>
parents: 8471
diff changeset
2474 make_script (tree_statement_list *cmds, tree_statement *end_script)
7715
5b4d278ec828 parse scripts completely before executing
John W. Eaton <jwe@octave.org>
parents: 7699
diff changeset
2475 {
5b4d278ec828 parse scripts completely before executing
John W. Eaton <jwe@octave.org>
parents: 7699
diff changeset
2476 std::string doc_string;
5b4d278ec828 parse scripts completely before executing
John W. Eaton <jwe@octave.org>
parents: 7699
diff changeset
2477
5b4d278ec828 parse scripts completely before executing
John W. Eaton <jwe@octave.org>
parents: 7699
diff changeset
2478 if (! help_buf.empty ())
5b4d278ec828 parse scripts completely before executing
John W. Eaton <jwe@octave.org>
parents: 7699
diff changeset
2479 {
5b4d278ec828 parse scripts completely before executing
John W. Eaton <jwe@octave.org>
parents: 7699
diff changeset
2480 doc_string = help_buf.top ();
5b4d278ec828 parse scripts completely before executing
John W. Eaton <jwe@octave.org>
parents: 7699
diff changeset
2481 help_buf.pop ();
5b4d278ec828 parse scripts completely before executing
John W. Eaton <jwe@octave.org>
parents: 7699
diff changeset
2482 }
5b4d278ec828 parse scripts completely before executing
John W. Eaton <jwe@octave.org>
parents: 7699
diff changeset
2483
8658
73c4516fae10 New evaluator and debugger derived from tree-walker class
John W. Eaton <jwe@octave.org>
parents: 8471
diff changeset
2484 if (! cmds)
73c4516fae10 New evaluator and debugger derived from tree-walker class
John W. Eaton <jwe@octave.org>
parents: 8471
diff changeset
2485 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
2486
73c4516fae10 New evaluator and debugger derived from tree-walker class
John W. Eaton <jwe@octave.org>
parents: 8471
diff changeset
2487 cmds->append (end_script);
73c4516fae10 New evaluator and debugger derived from tree-walker class
John W. Eaton <jwe@octave.org>
parents: 8471
diff changeset
2488
7715
5b4d278ec828 parse scripts completely before executing
John W. Eaton <jwe@octave.org>
parents: 7699
diff changeset
2489 octave_user_script *script
5b4d278ec828 parse scripts completely before executing
John W. Eaton <jwe@octave.org>
parents: 7699
diff changeset
2490 = new octave_user_script (curr_fcn_file_full_name, curr_fcn_file_name,
5b4d278ec828 parse scripts completely before executing
John W. Eaton <jwe@octave.org>
parents: 7699
diff changeset
2491 cmds, doc_string);
5b4d278ec828 parse scripts completely before executing
John W. Eaton <jwe@octave.org>
parents: 7699
diff changeset
2492
5b4d278ec828 parse scripts completely before executing
John W. Eaton <jwe@octave.org>
parents: 7699
diff changeset
2493 octave_time now;
5b4d278ec828 parse scripts completely before executing
John W. Eaton <jwe@octave.org>
parents: 7699
diff changeset
2494
5b4d278ec828 parse scripts completely before executing
John W. Eaton <jwe@octave.org>
parents: 7699
diff changeset
2495 script->stash_fcn_file_time (now);
5b4d278ec828 parse scripts completely before executing
John W. Eaton <jwe@octave.org>
parents: 7699
diff changeset
2496
5b4d278ec828 parse scripts completely before executing
John W. Eaton <jwe@octave.org>
parents: 7699
diff changeset
2497 curr_fcn_ptr = script;
5b4d278ec828 parse scripts completely before executing
John W. Eaton <jwe@octave.org>
parents: 7699
diff changeset
2498 }
5b4d278ec828 parse scripts completely before executing
John W. Eaton <jwe@octave.org>
parents: 7699
diff changeset
2499
1623
fa7a847f9b92 [project @ 1995-11-06 18:05:09 by jwe]
jwe
parents: 1607
diff changeset
2500 // Begin defining a function.
fa7a847f9b92 [project @ 1995-11-06 18:05:09 by jwe]
jwe
parents: 1607
diff changeset
2501
2891
1a30f46e1870 [project @ 1997-04-28 01:49:00 by jwe]
jwe
parents: 2884
diff changeset
2502 static octave_user_function *
8658
73c4516fae10 New evaluator and debugger derived from tree-walker class
John W. Eaton <jwe@octave.org>
parents: 8471
diff changeset
2503 start_function (tree_parameter_list *param_list, tree_statement_list *body,
73c4516fae10 New evaluator and debugger derived from tree-walker class
John W. Eaton <jwe@octave.org>
parents: 8471
diff changeset
2504 tree_statement *end_fcn_stmt)
1623
fa7a847f9b92 [project @ 1995-11-06 18:05:09 by jwe]
jwe
parents: 1607
diff changeset
2505 {
2891
1a30f46e1870 [project @ 1997-04-28 01:49:00 by jwe]
jwe
parents: 2884
diff changeset
2506 // We'll fill in the return list later.
1a30f46e1870 [project @ 1997-04-28 01:49:00 by jwe]
jwe
parents: 2884
diff changeset
2507
8658
73c4516fae10 New evaluator and debugger derived from tree-walker class
John W. Eaton <jwe@octave.org>
parents: 8471
diff changeset
2508 if (! body)
73c4516fae10 New evaluator and debugger derived from tree-walker class
John W. Eaton <jwe@octave.org>
parents: 8471
diff changeset
2509 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
2510
73c4516fae10 New evaluator and debugger derived from tree-walker class
John W. Eaton <jwe@octave.org>
parents: 8471
diff changeset
2511 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
2512
2891
1a30f46e1870 [project @ 1997-04-28 01:49:00 by jwe]
jwe
parents: 2884
diff changeset
2513 octave_user_function *fcn
7336
745a8299c2b5 [project @ 2007-12-28 20:56:55 by jwe]
jwe
parents: 7017
diff changeset
2514 = new octave_user_function (symbol_table::current_scope (),
745a8299c2b5 [project @ 2007-12-28 20:56:55 by jwe]
jwe
parents: 7017
diff changeset
2515 param_list, 0, body);
1623
fa7a847f9b92 [project @ 1995-11-06 18:05:09 by jwe]
jwe
parents: 1607
diff changeset
2516
3665
0689afb1d001 [project @ 2000-05-11 19:07:56 by jwe]
jwe
parents: 3544
diff changeset
2517 if (fcn)
0689afb1d001 [project @ 2000-05-11 19:07:56 by jwe]
jwe
parents: 3544
diff changeset
2518 {
0689afb1d001 [project @ 2000-05-11 19:07:56 by jwe]
jwe
parents: 3544
diff changeset
2519 octave_comment_list *tc = octave_comment_buffer::get_comment ();
0689afb1d001 [project @ 2000-05-11 19:07:56 by jwe]
jwe
parents: 3544
diff changeset
2520
0689afb1d001 [project @ 2000-05-11 19:07:56 by jwe]
jwe
parents: 3544
diff changeset
2521 fcn->stash_trailing_comment (tc);
0689afb1d001 [project @ 2000-05-11 19:07:56 by jwe]
jwe
parents: 3544
diff changeset
2522 }
0689afb1d001 [project @ 2000-05-11 19:07:56 by jwe]
jwe
parents: 3544
diff changeset
2523
1623
fa7a847f9b92 [project @ 1995-11-06 18:05:09 by jwe]
jwe
parents: 1607
diff changeset
2524 return fcn;
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
8658
73c4516fae10 New evaluator and debugger derived from tree-walker class
John W. Eaton <jwe@octave.org>
parents: 8471
diff changeset
2527 static tree_statement *
73c4516fae10 New evaluator and debugger derived from tree-walker class
John W. Eaton <jwe@octave.org>
parents: 8471
diff changeset
2528 make_end (const std::string& type, int l, int c)
73c4516fae10 New evaluator and debugger derived from tree-walker class
John W. Eaton <jwe@octave.org>
parents: 8471
diff changeset
2529 {
73c4516fae10 New evaluator and debugger derived from tree-walker class
John W. Eaton <jwe@octave.org>
parents: 8471
diff changeset
2530 return make_statement (new tree_no_op_command (type, l, c));
73c4516fae10 New evaluator and debugger derived from tree-walker class
John W. Eaton <jwe@octave.org>
parents: 8471
diff changeset
2531 }
73c4516fae10 New evaluator and debugger derived from tree-walker class
John W. Eaton <jwe@octave.org>
parents: 8471
diff changeset
2532
1623
fa7a847f9b92 [project @ 1995-11-06 18:05:09 by jwe]
jwe
parents: 1607
diff changeset
2533 // Do most of the work for defining a function.
fa7a847f9b92 [project @ 1995-11-06 18:05:09 by jwe]
jwe
parents: 1607
diff changeset
2534
2891
1a30f46e1870 [project @ 1997-04-28 01:49:00 by jwe]
jwe
parents: 2884
diff changeset
2535 static octave_user_function *
4872
fe71c458f438 [project @ 2004-04-21 20:09:32 by jwe]
jwe
parents: 4844
diff changeset
2536 frob_function (const std::string& fname, octave_user_function *fcn)
1623
fa7a847f9b92 [project @ 1995-11-06 18:05:09 by jwe]
jwe
parents: 1607
diff changeset
2537 {
4872
fe71c458f438 [project @ 2004-04-21 20:09:32 by jwe]
jwe
parents: 4844
diff changeset
2538 std::string id_name = fname;
1623
fa7a847f9b92 [project @ 1995-11-06 18:05:09 by jwe]
jwe
parents: 1607
diff changeset
2539
fa7a847f9b92 [project @ 1995-11-06 18:05:09 by jwe]
jwe
parents: 1607
diff changeset
2540 // 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
2541 // 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
2542 // 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
2543 // name).
fa7a847f9b92 [project @ 1995-11-06 18:05:09 by jwe]
jwe
parents: 1607
diff changeset
2544
5484
2ff5363a16bd [project @ 2005-10-06 17:12:12 by jwe]
jwe
parents: 5472
diff changeset
2545 if (reading_fcn_file || autoloading)
1623
fa7a847f9b92 [project @ 1995-11-06 18:05:09 by jwe]
jwe
parents: 1607
diff changeset
2546 {
7336
745a8299c2b5 [project @ 2007-12-28 20:56:55 by jwe]
jwe
parents: 7017
diff changeset
2547 if (! (autoloading
745a8299c2b5 [project @ 2007-12-28 20:56:55 by jwe]
jwe
parents: 7017
diff changeset
2548 || lexer_flags.parsing_nested_function
745a8299c2b5 [project @ 2007-12-28 20:56:55 by jwe]
jwe
parents: 7017
diff changeset
2549 || lexer_flags.parsing_class_method))
1623
fa7a847f9b92 [project @ 1995-11-06 18:05:09 by jwe]
jwe
parents: 1607
diff changeset
2550 {
7336
745a8299c2b5 [project @ 2007-12-28 20:56:55 by jwe]
jwe
parents: 7017
diff changeset
2551 // FIXME -- should curr_fcn_file_name already be
745a8299c2b5 [project @ 2007-12-28 20:56:55 by jwe]
jwe
parents: 7017
diff changeset
2552 // preprocessed when we get here? It seems to only be a
745a8299c2b5 [project @ 2007-12-28 20:56:55 by jwe]
jwe
parents: 7017
diff changeset
2553 // problem with relative file names.
745a8299c2b5 [project @ 2007-12-28 20:56:55 by jwe]
jwe
parents: 7017
diff changeset
2554
745a8299c2b5 [project @ 2007-12-28 20:56:55 by jwe]
jwe
parents: 7017
diff changeset
2555 std::string nm = curr_fcn_file_name;
745a8299c2b5 [project @ 2007-12-28 20:56:55 by jwe]
jwe
parents: 7017
diff changeset
2556
8007
a2ab20ba78f7 make file_ops a proper singleton class
John W. Eaton <jwe@octave.org>
parents: 8001
diff changeset
2557 size_t pos = nm.find_last_of (file_ops::dir_sep_chars ());
7336
745a8299c2b5 [project @ 2007-12-28 20:56:55 by jwe]
jwe
parents: 7017
diff changeset
2558
8021
85184151822e fix typo in NPOS change
John W. Eaton <jwe@octave.org>
parents: 8019
diff changeset
2559 if (pos != std::string::npos)
7336
745a8299c2b5 [project @ 2007-12-28 20:56:55 by jwe]
jwe
parents: 7017
diff changeset
2560 nm = curr_fcn_file_name.substr (pos+1);
745a8299c2b5 [project @ 2007-12-28 20:56:55 by jwe]
jwe
parents: 7017
diff changeset
2561
745a8299c2b5 [project @ 2007-12-28 20:56:55 by jwe]
jwe
parents: 7017
diff changeset
2562 if (nm != id_name)
745a8299c2b5 [project @ 2007-12-28 20:56:55 by jwe]
jwe
parents: 7017
diff changeset
2563 {
745a8299c2b5 [project @ 2007-12-28 20:56:55 by jwe]
jwe
parents: 7017
diff changeset
2564 warning_with_id
745a8299c2b5 [project @ 2007-12-28 20:56:55 by jwe]
jwe
parents: 7017
diff changeset
2565 ("Octave:function-name-clash",
745a8299c2b5 [project @ 2007-12-28 20:56:55 by jwe]
jwe
parents: 7017
diff changeset
2566 "function name `%s' does not agree with function file name `%s'",
745a8299c2b5 [project @ 2007-12-28 20:56:55 by jwe]
jwe
parents: 7017
diff changeset
2567 id_name.c_str (), curr_fcn_file_full_name.c_str ());
745a8299c2b5 [project @ 2007-12-28 20:56:55 by jwe]
jwe
parents: 7017
diff changeset
2568
745a8299c2b5 [project @ 2007-12-28 20:56:55 by jwe]
jwe
parents: 7017
diff changeset
2569 id_name = nm;
745a8299c2b5 [project @ 2007-12-28 20:56:55 by jwe]
jwe
parents: 7017
diff changeset
2570 }
1623
fa7a847f9b92 [project @ 1995-11-06 18:05:09 by jwe]
jwe
parents: 1607
diff changeset
2571 }
fa7a847f9b92 [project @ 1995-11-06 18:05:09 by jwe]
jwe
parents: 1607
diff changeset
2572
3712
7066a8065e7e [project @ 2000-08-22 06:21:20 by jwe]
jwe
parents: 3665
diff changeset
2573 octave_time now;
3162
7c96e85c76db [project @ 1998-04-08 18:19:35 by jwe]
jwe
parents: 3156
diff changeset
2574
4343
db5e0814277a [project @ 2003-02-20 16:44:16 by jwe]
jwe
parents: 4342
diff changeset
2575 fcn->stash_fcn_file_name (curr_fcn_file_full_name);
3162
7c96e85c76db [project @ 1998-04-08 18:19:35 by jwe]
jwe
parents: 3156
diff changeset
2576 fcn->stash_fcn_file_time (now);
1623
fa7a847f9b92 [project @ 1995-11-06 18:05:09 by jwe]
jwe
parents: 1607
diff changeset
2577 fcn->mark_as_system_fcn_file ();
3162
7c96e85c76db [project @ 1998-04-08 18:19:35 by jwe]
jwe
parents: 3156
diff changeset
2578
6323
ea65de49e18e [project @ 2007-02-17 02:51:02 by jwe]
jwe
parents: 6238
diff changeset
2579 if (fcn_file_from_relative_lookup)
ea65de49e18e [project @ 2007-02-17 02:51:02 by jwe]
jwe
parents: 6238
diff changeset
2580 fcn->mark_relative ();
ea65de49e18e [project @ 2007-02-17 02:51:02 by jwe]
jwe
parents: 6238
diff changeset
2581
ea65de49e18e [project @ 2007-02-17 02:51:02 by jwe]
jwe
parents: 6238
diff changeset
2582 if (lexer_flags.parsing_nested_function)
7968
0d607e8dbbfa eliminate curr_parent_function; fix subfunction lookup
John W. Eaton <jwe@octave.org>
parents: 7903
diff changeset
2583 {
0d607e8dbbfa eliminate curr_parent_function; fix subfunction lookup
John W. Eaton <jwe@octave.org>
parents: 7903
diff changeset
2584 fcn->stash_parent_fcn_name (parent_function_name);
0d607e8dbbfa eliminate curr_parent_function; fix subfunction lookup
John W. Eaton <jwe@octave.org>
parents: 7903
diff changeset
2585 fcn->stash_parent_fcn_scope (symbol_table::parent_scope ());
0d607e8dbbfa eliminate curr_parent_function; fix subfunction lookup
John W. Eaton <jwe@octave.org>
parents: 7903
diff changeset
2586 }
6323
ea65de49e18e [project @ 2007-02-17 02:51:02 by jwe]
jwe
parents: 6238
diff changeset
2587
7336
745a8299c2b5 [project @ 2007-12-28 20:56:55 by jwe]
jwe
parents: 7017
diff changeset
2588 if (lexer_flags.parsing_class_method)
745a8299c2b5 [project @ 2007-12-28 20:56:55 by jwe]
jwe
parents: 7017
diff changeset
2589 {
745a8299c2b5 [project @ 2007-12-28 20:56:55 by jwe]
jwe
parents: 7017
diff changeset
2590 if (current_class_name == id_name)
745a8299c2b5 [project @ 2007-12-28 20:56:55 by jwe]
jwe
parents: 7017
diff changeset
2591 fcn->mark_as_class_constructor ();
745a8299c2b5 [project @ 2007-12-28 20:56:55 by jwe]
jwe
parents: 7017
diff changeset
2592 else
745a8299c2b5 [project @ 2007-12-28 20:56:55 by jwe]
jwe
parents: 7017
diff changeset
2593 fcn->mark_as_class_method ();
745a8299c2b5 [project @ 2007-12-28 20:56:55 by jwe]
jwe
parents: 7017
diff changeset
2594
745a8299c2b5 [project @ 2007-12-28 20:56:55 by jwe]
jwe
parents: 7017
diff changeset
2595 fcn->stash_dispatch_class (current_class_name);
745a8299c2b5 [project @ 2007-12-28 20:56:55 by jwe]
jwe
parents: 7017
diff changeset
2596 }
745a8299c2b5 [project @ 2007-12-28 20:56:55 by jwe]
jwe
parents: 7017
diff changeset
2597
5781
faafc2d98b8d [project @ 2006-05-02 19:40:19 by jwe]
jwe
parents: 5775
diff changeset
2598 std::string nm = fcn->fcn_file_name ();
faafc2d98b8d [project @ 2006-05-02 19:40:19 by jwe]
jwe
parents: 5775
diff changeset
2599
faafc2d98b8d [project @ 2006-05-02 19:40:19 by jwe]
jwe
parents: 5775
diff changeset
2600 file_stat fs (nm);
faafc2d98b8d [project @ 2006-05-02 19:40:19 by jwe]
jwe
parents: 5775
diff changeset
2601
faafc2d98b8d [project @ 2006-05-02 19:40:19 by jwe]
jwe
parents: 5775
diff changeset
2602 if (fs && fs.is_newer (now))
faafc2d98b8d [project @ 2006-05-02 19:40:19 by jwe]
jwe
parents: 5775
diff changeset
2603 warning_with_id ("Octave:future-time-stamp",
faafc2d98b8d [project @ 2006-05-02 19:40:19 by jwe]
jwe
parents: 5775
diff changeset
2604 "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
2605 }
fa7a847f9b92 [project @ 1995-11-06 18:05:09 by jwe]
jwe
parents: 1607
diff changeset
2606 else if (! (input_from_tmp_history_file || input_from_startup_file)
fa7a847f9b92 [project @ 1995-11-06 18:05:09 by jwe]
jwe
parents: 1607
diff changeset
2607 && reading_script_file
1755
3a9462b655f1 [project @ 1996-01-22 04:47:22 by jwe]
jwe
parents: 1743
diff changeset
2608 && curr_fcn_file_name == id_name)
1623
fa7a847f9b92 [project @ 1995-11-06 18:05:09 by jwe]
jwe
parents: 1607
diff changeset
2609 {
fa7a847f9b92 [project @ 1995-11-06 18:05:09 by jwe]
jwe
parents: 1607
diff changeset
2610 warning ("function `%s' defined within script file `%s'",
1755
3a9462b655f1 [project @ 1996-01-22 04:47:22 by jwe]
jwe
parents: 1743
diff changeset
2611 id_name.c_str (), curr_fcn_file_full_name.c_str ());
1623
fa7a847f9b92 [project @ 1995-11-06 18:05:09 by jwe]
jwe
parents: 1607
diff changeset
2612 }
fa7a847f9b92 [project @ 1995-11-06 18:05:09 by jwe]
jwe
parents: 1607
diff changeset
2613
4872
fe71c458f438 [project @ 2004-04-21 20:09:32 by jwe]
jwe
parents: 4844
diff changeset
2614 fcn->stash_function_name (id_name);
fe71c458f438 [project @ 2004-04-21 20:09:32 by jwe]
jwe
parents: 4844
diff changeset
2615
7336
745a8299c2b5 [project @ 2007-12-28 20:56:55 by jwe]
jwe
parents: 7017
diff changeset
2616 if (! help_buf.empty ())
745a8299c2b5 [project @ 2007-12-28 20:56:55 by jwe]
jwe
parents: 7017
diff changeset
2617 {
745a8299c2b5 [project @ 2007-12-28 20:56:55 by jwe]
jwe
parents: 7017
diff changeset
2618 fcn->document (help_buf.top ());
745a8299c2b5 [project @ 2007-12-28 20:56:55 by jwe]
jwe
parents: 7017
diff changeset
2619
745a8299c2b5 [project @ 2007-12-28 20:56:55 by jwe]
jwe
parents: 7017
diff changeset
2620 help_buf.pop ();
745a8299c2b5 [project @ 2007-12-28 20:56:55 by jwe]
jwe
parents: 7017
diff changeset
2621 }
745a8299c2b5 [project @ 2007-12-28 20:56:55 by jwe]
jwe
parents: 7017
diff changeset
2622
7755
ea9cb4d68dbf avoid installing subfunctions twice
John W. Eaton <jwe@octave.org>
parents: 7750
diff changeset
2623 if (reading_fcn_file && ! lexer_flags.parsing_nested_function)
7715
5b4d278ec828 parse scripts completely before executing
John W. Eaton <jwe@octave.org>
parents: 7699
diff changeset
2624 curr_fcn_ptr = fcn;
7336
745a8299c2b5 [project @ 2007-12-28 20:56:55 by jwe]
jwe
parents: 7017
diff changeset
2625 else
7715
5b4d278ec828 parse scripts completely before executing
John W. Eaton <jwe@octave.org>
parents: 7699
diff changeset
2626 curr_fcn_ptr = 0;
4426
51a0dcde8778 [project @ 2003-06-13 19:16:37 by jwe]
jwe
parents: 4343
diff changeset
2627
1623
fa7a847f9b92 [project @ 1995-11-06 18:05:09 by jwe]
jwe
parents: 1607
diff changeset
2628 return fcn;
fa7a847f9b92 [project @ 1995-11-06 18:05:09 by jwe]
jwe
parents: 1607
diff changeset
2629 }
fa7a847f9b92 [project @ 1995-11-06 18:05:09 by jwe]
jwe
parents: 1607
diff changeset
2630
7715
5b4d278ec828 parse scripts completely before executing
John W. Eaton <jwe@octave.org>
parents: 7699
diff changeset
2631 static tree_function_def *
3665
0689afb1d001 [project @ 2000-05-11 19:07:56 by jwe]
jwe
parents: 3544
diff changeset
2632 finish_function (tree_parameter_list *ret_list,
0689afb1d001 [project @ 2000-05-11 19:07:56 by jwe]
jwe
parents: 3544
diff changeset
2633 octave_user_function *fcn, octave_comment_list *lc)
1623
fa7a847f9b92 [project @ 1995-11-06 18:05:09 by jwe]
jwe
parents: 1607
diff changeset
2634 {
7715
5b4d278ec828 parse scripts completely before executing
John W. Eaton <jwe@octave.org>
parents: 7699
diff changeset
2635 tree_function_def *retval = 0;
5b4d278ec828 parse scripts completely before executing
John W. Eaton <jwe@octave.org>
parents: 7699
diff changeset
2636
5b4d278ec828 parse scripts completely before executing
John W. Eaton <jwe@octave.org>
parents: 7699
diff changeset
2637 if (ret_list)
5b4d278ec828 parse scripts completely before executing
John W. Eaton <jwe@octave.org>
parents: 7699
diff changeset
2638 ret_list->mark_as_formal_parameters ();
5b4d278ec828 parse scripts completely before executing
John W. Eaton <jwe@octave.org>
parents: 7699
diff changeset
2639
5b4d278ec828 parse scripts completely before executing
John W. Eaton <jwe@octave.org>
parents: 7699
diff changeset
2640 if (fcn)
5b4d278ec828 parse scripts completely before executing
John W. Eaton <jwe@octave.org>
parents: 7699
diff changeset
2641 {
7761
5adeea5de26c symbol table reporting functions
John W. Eaton <jwe@octave.org>
parents: 7755
diff changeset
2642 std::string nm = fcn->name ();
5adeea5de26c symbol table reporting functions
John W. Eaton <jwe@octave.org>
parents: 7755
diff changeset
2643 std::string file = fcn->fcn_file_name ();
5adeea5de26c symbol table reporting functions
John W. Eaton <jwe@octave.org>
parents: 7755
diff changeset
2644
5adeea5de26c symbol table reporting functions
John W. Eaton <jwe@octave.org>
parents: 7755
diff changeset
2645 std::string tmp = nm;
5adeea5de26c symbol table reporting functions
John W. Eaton <jwe@octave.org>
parents: 7755
diff changeset
2646 if (! file.empty ())
5adeea5de26c symbol table reporting functions
John W. Eaton <jwe@octave.org>
parents: 7755
diff changeset
2647 tmp += ": " + file;
5adeea5de26c symbol table reporting functions
John W. Eaton <jwe@octave.org>
parents: 7755
diff changeset
2648
5adeea5de26c symbol table reporting functions
John W. Eaton <jwe@octave.org>
parents: 7755
diff changeset
2649 symbol_table::cache_name (fcn->scope (), tmp);
5adeea5de26c symbol table reporting functions
John W. Eaton <jwe@octave.org>
parents: 7755
diff changeset
2650
7715
5b4d278ec828 parse scripts completely before executing
John W. Eaton <jwe@octave.org>
parents: 7699
diff changeset
2651 if (lc)
5b4d278ec828 parse scripts completely before executing
John W. Eaton <jwe@octave.org>
parents: 7699
diff changeset
2652 fcn->stash_leading_comment (lc);
5b4d278ec828 parse scripts completely before executing
John W. Eaton <jwe@octave.org>
parents: 7699
diff changeset
2653
5b4d278ec828 parse scripts completely before executing
John W. Eaton <jwe@octave.org>
parents: 7699
diff changeset
2654 fcn->define_ret_list (ret_list);
7755
ea9cb4d68dbf avoid installing subfunctions twice
John W. Eaton <jwe@octave.org>
parents: 7750
diff changeset
2655
ea9cb4d68dbf avoid installing subfunctions twice
John W. Eaton <jwe@octave.org>
parents: 7750
diff changeset
2656 if (lexer_flags.parsing_nested_function)
ea9cb4d68dbf avoid installing subfunctions twice
John W. Eaton <jwe@octave.org>
parents: 7750
diff changeset
2657 {
ea9cb4d68dbf avoid installing subfunctions twice
John W. Eaton <jwe@octave.org>
parents: 7750
diff changeset
2658 fcn->mark_as_nested_function ();
ea9cb4d68dbf avoid installing subfunctions twice
John W. Eaton <jwe@octave.org>
parents: 7750
diff changeset
2659
ea9cb4d68dbf avoid installing subfunctions twice
John W. Eaton <jwe@octave.org>
parents: 7750
diff changeset
2660 symbol_table::install_subfunction (nm, octave_value (fcn));
ea9cb4d68dbf avoid installing subfunctions twice
John W. Eaton <jwe@octave.org>
parents: 7750
diff changeset
2661
ea9cb4d68dbf avoid installing subfunctions twice
John W. Eaton <jwe@octave.org>
parents: 7750
diff changeset
2662 if (lexer_flags.parsing_nested_function < 0)
ea9cb4d68dbf avoid installing subfunctions twice
John W. Eaton <jwe@octave.org>
parents: 7750
diff changeset
2663 {
ea9cb4d68dbf avoid installing subfunctions twice
John W. Eaton <jwe@octave.org>
parents: 7750
diff changeset
2664 lexer_flags.parsing_nested_function = 0;
ea9cb4d68dbf avoid installing subfunctions twice
John W. Eaton <jwe@octave.org>
parents: 7750
diff changeset
2665 symbol_table::reset_parent_scope ();
ea9cb4d68dbf avoid installing subfunctions twice
John W. Eaton <jwe@octave.org>
parents: 7750
diff changeset
2666 }
ea9cb4d68dbf avoid installing subfunctions twice
John W. Eaton <jwe@octave.org>
parents: 7750
diff changeset
2667 }
ea9cb4d68dbf avoid installing subfunctions twice
John W. Eaton <jwe@octave.org>
parents: 7750
diff changeset
2668 else if (! curr_fcn_ptr)
ea9cb4d68dbf avoid installing subfunctions twice
John W. Eaton <jwe@octave.org>
parents: 7750
diff changeset
2669 {
ea9cb4d68dbf avoid installing subfunctions twice
John W. Eaton <jwe@octave.org>
parents: 7750
diff changeset
2670 // FIXME -- there should be a better way to indicate that we
ea9cb4d68dbf avoid installing subfunctions twice
John W. Eaton <jwe@octave.org>
parents: 7750
diff changeset
2671 // should create a tree_function_def object other than
ea9cb4d68dbf avoid installing subfunctions twice
John W. Eaton <jwe@octave.org>
parents: 7750
diff changeset
2672 // looking at curr_fcn_ptr...
ea9cb4d68dbf avoid installing subfunctions twice
John W. Eaton <jwe@octave.org>
parents: 7750
diff changeset
2673
ea9cb4d68dbf avoid installing subfunctions twice
John W. Eaton <jwe@octave.org>
parents: 7750
diff changeset
2674 retval = new tree_function_def (fcn);
ea9cb4d68dbf avoid installing subfunctions twice
John W. Eaton <jwe@octave.org>
parents: 7750
diff changeset
2675 }
8282
47a3d2f829e4 clear local symbol table after parsing function
John W. Eaton <jwe@octave.org>
parents: 8150
diff changeset
2676
8283
54c25dc5b17d parse.y: fix comment
John W. Eaton <jwe@octave.org>
parents: 8282
diff changeset
2677 // Clear any local variables that may have been added while
54c25dc5b17d parse.y: fix comment
John W. Eaton <jwe@octave.org>
parents: 8282
diff changeset
2678 // parsing (for example, by force_local_variable in lex.l).
8282
47a3d2f829e4 clear local symbol table after parsing function
John W. Eaton <jwe@octave.org>
parents: 8150
diff changeset
2679
47a3d2f829e4 clear local symbol table after parsing function
John W. Eaton <jwe@octave.org>
parents: 8150
diff changeset
2680 symbol_table::clear_variables (fcn->scope ());
7715
5b4d278ec828 parse scripts completely before executing
John W. Eaton <jwe@octave.org>
parents: 7699
diff changeset
2681 }
5b4d278ec828 parse scripts completely before executing
John W. Eaton <jwe@octave.org>
parents: 7699
diff changeset
2682
5b4d278ec828 parse scripts completely before executing
John W. Eaton <jwe@octave.org>
parents: 7699
diff changeset
2683 return retval;
1623
fa7a847f9b92 [project @ 1995-11-06 18:05:09 by jwe]
jwe
parents: 1607
diff changeset
2684 }
fa7a847f9b92 [project @ 1995-11-06 18:05:09 by jwe]
jwe
parents: 1607
diff changeset
2685
2883
0b3954110c77 [project @ 1997-04-24 09:57:05 by jwe]
jwe
parents: 2865
diff changeset
2686 static void
0b3954110c77 [project @ 1997-04-24 09:57:05 by jwe]
jwe
parents: 2865
diff changeset
2687 recover_from_parsing_function (void)
0b3954110c77 [project @ 1997-04-24 09:57:05 by jwe]
jwe
parents: 2865
diff changeset
2688 {
4238
a5a68c0afe56 [project @ 2002-12-25 21:04:33 by jwe]
jwe
parents: 4237
diff changeset
2689 if (symtab_context.empty ())
3903
1dbe160ea0d1 [project @ 2002-04-23 03:40:25 by jwe]
jwe
parents: 3883
diff changeset
2690 panic_impossible ();
1dbe160ea0d1 [project @ 2002-04-23 03:40:25 by jwe]
jwe
parents: 3883
diff changeset
2691
7336
745a8299c2b5 [project @ 2007-12-28 20:56:55 by jwe]
jwe
parents: 7017
diff changeset
2692 symbol_table::set_scope (symtab_context.top ());
4238
a5a68c0afe56 [project @ 2002-12-25 21:04:33 by jwe]
jwe
parents: 4237
diff changeset
2693 symtab_context.pop ();
2883
0b3954110c77 [project @ 1997-04-24 09:57:05 by jwe]
jwe
parents: 2865
diff changeset
2694
0b3954110c77 [project @ 1997-04-24 09:57:05 by jwe]
jwe
parents: 2865
diff changeset
2695 lexer_flags.defining_func = false;
0b3954110c77 [project @ 1997-04-24 09:57:05 by jwe]
jwe
parents: 2865
diff changeset
2696 lexer_flags.parsed_function_name = false;
0b3954110c77 [project @ 1997-04-24 09:57:05 by jwe]
jwe
parents: 2865
diff changeset
2697 lexer_flags.looking_at_return_list = false;
0b3954110c77 [project @ 1997-04-24 09:57:05 by jwe]
jwe
parents: 2865
diff changeset
2698 lexer_flags.looking_at_parameter_list = false;
0b3954110c77 [project @ 1997-04-24 09:57:05 by jwe]
jwe
parents: 2865
diff changeset
2699 }
0b3954110c77 [project @ 1997-04-24 09:57:05 by jwe]
jwe
parents: 2865
diff changeset
2700
2846
52e7c4509983 [project @ 1997-03-26 23:27:35 by jwe]
jwe
parents: 2825
diff changeset
2701 // Make an index expression.
52e7c4509983 [project @ 1997-03-26 23:27:35 by jwe]
jwe
parents: 2825
diff changeset
2702
751
c9f3cb77478d [project @ 1994-09-30 18:46:17 by jwe]
jwe
parents: 723
diff changeset
2703 static tree_index_expression *
3929
cc8ae49d6e79 [project @ 2002-05-04 02:47:14 by jwe]
jwe
parents: 3928
diff changeset
2704 make_index_expression (tree_expression *expr, tree_argument_list *args,
3933
f9ea3dcf58ee [project @ 2002-05-15 03:21:00 by jwe]
jwe
parents: 3930
diff changeset
2705 char type)
751
c9f3cb77478d [project @ 1994-09-30 18:46:17 by jwe]
jwe
parents: 723
diff changeset
2706 {
c9f3cb77478d [project @ 1994-09-30 18:46:17 by jwe]
jwe
parents: 723
diff changeset
2707 tree_index_expression *retval = 0;
c9f3cb77478d [project @ 1994-09-30 18:46:17 by jwe]
jwe
parents: 723
diff changeset
2708
2970
b9e64477f703 [project @ 1997-05-15 18:04:21 by jwe]
jwe
parents: 2961
diff changeset
2709 int l = expr->line ();
b9e64477f703 [project @ 1997-05-15 18:04:21 by jwe]
jwe
parents: 2961
diff changeset
2710 int c = expr->column ();
b9e64477f703 [project @ 1997-05-15 18:04:21 by jwe]
jwe
parents: 2961
diff changeset
2711
b9e64477f703 [project @ 1997-05-15 18:04:21 by jwe]
jwe
parents: 2961
diff changeset
2712 expr->mark_postfix_indexed ();
b9e64477f703 [project @ 1997-05-15 18:04:21 by jwe]
jwe
parents: 2961
diff changeset
2713
3933
f9ea3dcf58ee [project @ 2002-05-15 03:21:00 by jwe]
jwe
parents: 3930
diff changeset
2714 if (expr->is_index_expression ())
f9ea3dcf58ee [project @ 2002-05-15 03:21:00 by jwe]
jwe
parents: 3930
diff changeset
2715 {
f9ea3dcf58ee [project @ 2002-05-15 03:21:00 by jwe]
jwe
parents: 3930
diff changeset
2716 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
2717
f9ea3dcf58ee [project @ 2002-05-15 03:21:00 by jwe]
jwe
parents: 3930
diff changeset
2718 tmp->append (args, type);
f9ea3dcf58ee [project @ 2002-05-15 03:21:00 by jwe]
jwe
parents: 3930
diff changeset
2719
f9ea3dcf58ee [project @ 2002-05-15 03:21:00 by jwe]
jwe
parents: 3930
diff changeset
2720 retval = tmp;
f9ea3dcf58ee [project @ 2002-05-15 03:21:00 by jwe]
jwe
parents: 3930
diff changeset
2721 }
f9ea3dcf58ee [project @ 2002-05-15 03:21:00 by jwe]
jwe
parents: 3930
diff changeset
2722 else
f9ea3dcf58ee [project @ 2002-05-15 03:21:00 by jwe]
jwe
parents: 3930
diff changeset
2723 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
2724
b9e64477f703 [project @ 1997-05-15 18:04:21 by jwe]
jwe
parents: 2961
diff changeset
2725 return retval;
b9e64477f703 [project @ 1997-05-15 18:04:21 by jwe]
jwe
parents: 2961
diff changeset
2726 }
b9e64477f703 [project @ 1997-05-15 18:04:21 by jwe]
jwe
parents: 2961
diff changeset
2727
b9e64477f703 [project @ 1997-05-15 18:04:21 by jwe]
jwe
parents: 2961
diff changeset
2728 // Make an indirect reference expression.
b9e64477f703 [project @ 1997-05-15 18:04:21 by jwe]
jwe
parents: 2961
diff changeset
2729
3930
61d4427c016e [project @ 2002-05-07 00:47:31 by jwe]
jwe
parents: 3929
diff changeset
2730 static tree_index_expression *
3523
b80bbb43a1a9 [project @ 2000-02-02 10:25:52 by jwe]
jwe
parents: 3489
diff changeset
2731 make_indirect_ref (tree_expression *expr, const std::string& elt)
2970
b9e64477f703 [project @ 1997-05-15 18:04:21 by jwe]
jwe
parents: 2961
diff changeset
2732 {
3930
61d4427c016e [project @ 2002-05-07 00:47:31 by jwe]
jwe
parents: 3929
diff changeset
2733 tree_index_expression *retval = 0;
2970
b9e64477f703 [project @ 1997-05-15 18:04:21 by jwe]
jwe
parents: 2961
diff changeset
2734
b9e64477f703 [project @ 1997-05-15 18:04:21 by jwe]
jwe
parents: 2961
diff changeset
2735 int l = expr->line ();
b9e64477f703 [project @ 1997-05-15 18:04:21 by jwe]
jwe
parents: 2961
diff changeset
2736 int c = expr->column ();
b9e64477f703 [project @ 1997-05-15 18:04:21 by jwe]
jwe
parents: 2961
diff changeset
2737
3933
f9ea3dcf58ee [project @ 2002-05-15 03:21:00 by jwe]
jwe
parents: 3930
diff changeset
2738 if (expr->is_index_expression ())
f9ea3dcf58ee [project @ 2002-05-15 03:21:00 by jwe]
jwe
parents: 3930
diff changeset
2739 {
f9ea3dcf58ee [project @ 2002-05-15 03:21:00 by jwe]
jwe
parents: 3930
diff changeset
2740 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
2741
f9ea3dcf58ee [project @ 2002-05-15 03:21:00 by jwe]
jwe
parents: 3930
diff changeset
2742 tmp->append (elt);
f9ea3dcf58ee [project @ 2002-05-15 03:21:00 by jwe]
jwe
parents: 3930
diff changeset
2743
f9ea3dcf58ee [project @ 2002-05-15 03:21:00 by jwe]
jwe
parents: 3930
diff changeset
2744 retval = tmp;
f9ea3dcf58ee [project @ 2002-05-15 03:21:00 by jwe]
jwe
parents: 3930
diff changeset
2745 }
f9ea3dcf58ee [project @ 2002-05-15 03:21:00 by jwe]
jwe
parents: 3930
diff changeset
2746 else
f9ea3dcf58ee [project @ 2002-05-15 03:21:00 by jwe]
jwe
parents: 3930
diff changeset
2747 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
2748
b9e64477f703 [project @ 1997-05-15 18:04:21 by jwe]
jwe
parents: 2961
diff changeset
2749 lexer_flags.looking_at_indirect_ref = false;
751
c9f3cb77478d [project @ 1994-09-30 18:46:17 by jwe]
jwe
parents: 723
diff changeset
2750
c9f3cb77478d [project @ 1994-09-30 18:46:17 by jwe]
jwe
parents: 723
diff changeset
2751 return retval;
c9f3cb77478d [project @ 1994-09-30 18:46:17 by jwe]
jwe
parents: 723
diff changeset
2752 }
1511
74f9e88a2c12 [project @ 1995-10-03 10:49:31 by jwe]
jwe
parents: 1491
diff changeset
2753
4131
597fbc55ea40 [project @ 2002-10-29 17:12:53 by jwe]
jwe
parents: 4064
diff changeset
2754 // Make an indirect reference expression with dynamic field name.
597fbc55ea40 [project @ 2002-10-29 17:12:53 by jwe]
jwe
parents: 4064
diff changeset
2755
597fbc55ea40 [project @ 2002-10-29 17:12:53 by jwe]
jwe
parents: 4064
diff changeset
2756 static tree_index_expression *
597fbc55ea40 [project @ 2002-10-29 17:12:53 by jwe]
jwe
parents: 4064
diff changeset
2757 make_indirect_ref (tree_expression *expr, tree_expression *elt)
597fbc55ea40 [project @ 2002-10-29 17:12:53 by jwe]
jwe
parents: 4064
diff changeset
2758 {
597fbc55ea40 [project @ 2002-10-29 17:12:53 by jwe]
jwe
parents: 4064
diff changeset
2759 tree_index_expression *retval = 0;
597fbc55ea40 [project @ 2002-10-29 17:12:53 by jwe]
jwe
parents: 4064
diff changeset
2760
597fbc55ea40 [project @ 2002-10-29 17:12:53 by jwe]
jwe
parents: 4064
diff changeset
2761 int l = expr->line ();
597fbc55ea40 [project @ 2002-10-29 17:12:53 by jwe]
jwe
parents: 4064
diff changeset
2762 int c = expr->column ();
597fbc55ea40 [project @ 2002-10-29 17:12:53 by jwe]
jwe
parents: 4064
diff changeset
2763
597fbc55ea40 [project @ 2002-10-29 17:12:53 by jwe]
jwe
parents: 4064
diff changeset
2764 if (expr->is_index_expression ())
597fbc55ea40 [project @ 2002-10-29 17:12:53 by jwe]
jwe
parents: 4064
diff changeset
2765 {
597fbc55ea40 [project @ 2002-10-29 17:12:53 by jwe]
jwe
parents: 4064
diff changeset
2766 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
2767
597fbc55ea40 [project @ 2002-10-29 17:12:53 by jwe]
jwe
parents: 4064
diff changeset
2768 tmp->append (elt);
597fbc55ea40 [project @ 2002-10-29 17:12:53 by jwe]
jwe
parents: 4064
diff changeset
2769
597fbc55ea40 [project @ 2002-10-29 17:12:53 by jwe]
jwe
parents: 4064
diff changeset
2770 retval = tmp;
597fbc55ea40 [project @ 2002-10-29 17:12:53 by jwe]
jwe
parents: 4064
diff changeset
2771 }
597fbc55ea40 [project @ 2002-10-29 17:12:53 by jwe]
jwe
parents: 4064
diff changeset
2772 else
597fbc55ea40 [project @ 2002-10-29 17:12:53 by jwe]
jwe
parents: 4064
diff changeset
2773 retval = new tree_index_expression (expr, elt, l, c);
597fbc55ea40 [project @ 2002-10-29 17:12:53 by jwe]
jwe
parents: 4064
diff changeset
2774
597fbc55ea40 [project @ 2002-10-29 17:12:53 by jwe]
jwe
parents: 4064
diff changeset
2775 lexer_flags.looking_at_indirect_ref = false;
597fbc55ea40 [project @ 2002-10-29 17:12:53 by jwe]
jwe
parents: 4064
diff changeset
2776
597fbc55ea40 [project @ 2002-10-29 17:12:53 by jwe]
jwe
parents: 4064
diff changeset
2777 return retval;
597fbc55ea40 [project @ 2002-10-29 17:12:53 by jwe]
jwe
parents: 4064
diff changeset
2778 }
597fbc55ea40 [project @ 2002-10-29 17:12:53 by jwe]
jwe
parents: 4064
diff changeset
2779
2846
52e7c4509983 [project @ 1997-03-26 23:27:35 by jwe]
jwe
parents: 2825
diff changeset
2780 // Make a declaration command.
52e7c4509983 [project @ 1997-03-26 23:27:35 by jwe]
jwe
parents: 2825
diff changeset
2781
52e7c4509983 [project @ 1997-03-26 23:27:35 by jwe]
jwe
parents: 2825
diff changeset
2782 static tree_decl_command *
52e7c4509983 [project @ 1997-03-26 23:27:35 by jwe]
jwe
parents: 2825
diff changeset
2783 make_decl_command (int tok, token *tok_val, tree_decl_init_list *lst)
52e7c4509983 [project @ 1997-03-26 23:27:35 by jwe]
jwe
parents: 2825
diff changeset
2784 {
52e7c4509983 [project @ 1997-03-26 23:27:35 by jwe]
jwe
parents: 2825
diff changeset
2785 tree_decl_command *retval = 0;
52e7c4509983 [project @ 1997-03-26 23:27:35 by jwe]
jwe
parents: 2825
diff changeset
2786
52e7c4509983 [project @ 1997-03-26 23:27:35 by jwe]
jwe
parents: 2825
diff changeset
2787 int l = tok_val->line ();
52e7c4509983 [project @ 1997-03-26 23:27:35 by jwe]
jwe
parents: 2825
diff changeset
2788 int c = tok_val->column ();
52e7c4509983 [project @ 1997-03-26 23:27:35 by jwe]
jwe
parents: 2825
diff changeset
2789
52e7c4509983 [project @ 1997-03-26 23:27:35 by jwe]
jwe
parents: 2825
diff changeset
2790 switch (tok)
52e7c4509983 [project @ 1997-03-26 23:27:35 by jwe]
jwe
parents: 2825
diff changeset
2791 {
52e7c4509983 [project @ 1997-03-26 23:27:35 by jwe]
jwe
parents: 2825
diff changeset
2792 case GLOBAL:
52e7c4509983 [project @ 1997-03-26 23:27:35 by jwe]
jwe
parents: 2825
diff changeset
2793 retval = new tree_global_command (lst, l, c);
52e7c4509983 [project @ 1997-03-26 23:27:35 by jwe]
jwe
parents: 2825
diff changeset
2794 break;
52e7c4509983 [project @ 1997-03-26 23:27:35 by jwe]
jwe
parents: 2825
diff changeset
2795
52e7c4509983 [project @ 1997-03-26 23:27:35 by jwe]
jwe
parents: 2825
diff changeset
2796 case STATIC:
52e7c4509983 [project @ 1997-03-26 23:27:35 by jwe]
jwe
parents: 2825
diff changeset
2797 if (lexer_flags.defining_func)
52e7c4509983 [project @ 1997-03-26 23:27:35 by jwe]
jwe
parents: 2825
diff changeset
2798 retval = new tree_static_command (lst, l, c);
52e7c4509983 [project @ 1997-03-26 23:27:35 by jwe]
jwe
parents: 2825
diff changeset
2799 else
52e7c4509983 [project @ 1997-03-26 23:27:35 by jwe]
jwe
parents: 2825
diff changeset
2800 {
52e7c4509983 [project @ 1997-03-26 23:27:35 by jwe]
jwe
parents: 2825
diff changeset
2801 if (reading_script_file)
4844
9f7ef92b50b0 [project @ 2004-04-02 17:26:53 by jwe]
jwe
parents: 4813
diff changeset
2802 warning ("ignoring persistent declaration near line %d of file `%s'",
2846
52e7c4509983 [project @ 1997-03-26 23:27:35 by jwe]
jwe
parents: 2825
diff changeset
2803 l, curr_fcn_file_full_name.c_str ());
52e7c4509983 [project @ 1997-03-26 23:27:35 by jwe]
jwe
parents: 2825
diff changeset
2804 else
4844
9f7ef92b50b0 [project @ 2004-04-02 17:26:53 by jwe]
jwe
parents: 4813
diff changeset
2805 warning ("ignoring persistent declaration near line %d", l);
2846
52e7c4509983 [project @ 1997-03-26 23:27:35 by jwe]
jwe
parents: 2825
diff changeset
2806 }
52e7c4509983 [project @ 1997-03-26 23:27:35 by jwe]
jwe
parents: 2825
diff changeset
2807 break;
52e7c4509983 [project @ 1997-03-26 23:27:35 by jwe]
jwe
parents: 2825
diff changeset
2808
52e7c4509983 [project @ 1997-03-26 23:27:35 by jwe]
jwe
parents: 2825
diff changeset
2809 default:
52e7c4509983 [project @ 1997-03-26 23:27:35 by jwe]
jwe
parents: 2825
diff changeset
2810 panic_impossible ();
52e7c4509983 [project @ 1997-03-26 23:27:35 by jwe]
jwe
parents: 2825
diff changeset
2811 break;
52e7c4509983 [project @ 1997-03-26 23:27:35 by jwe]
jwe
parents: 2825
diff changeset
2812 }
52e7c4509983 [project @ 1997-03-26 23:27:35 by jwe]
jwe
parents: 2825
diff changeset
2813
52e7c4509983 [project @ 1997-03-26 23:27:35 by jwe]
jwe
parents: 2825
diff changeset
2814 return retval;
52e7c4509983 [project @ 1997-03-26 23:27:35 by jwe]
jwe
parents: 2825
diff changeset
2815 }
52e7c4509983 [project @ 1997-03-26 23:27:35 by jwe]
jwe
parents: 2825
diff changeset
2816
1623
fa7a847f9b92 [project @ 1995-11-06 18:05:09 by jwe]
jwe
parents: 1607
diff changeset
2817 // Finish building a matrix list.
fa7a847f9b92 [project @ 1995-11-06 18:05:09 by jwe]
jwe
parents: 1607
diff changeset
2818
fa7a847f9b92 [project @ 1995-11-06 18:05:09 by jwe]
jwe
parents: 1607
diff changeset
2819 static tree_expression *
1829
7d2982b55242 [project @ 1996-02-02 14:12:59 by jwe]
jwe
parents: 1826
diff changeset
2820 finish_matrix (tree_matrix *m)
1623
fa7a847f9b92 [project @ 1995-11-06 18:05:09 by jwe]
jwe
parents: 1607
diff changeset
2821 {
3110
fe2d1ae8926b [project @ 1997-11-21 02:11:19 by jwe]
jwe
parents: 3099
diff changeset
2822 tree_expression *retval = m;
fe2d1ae8926b [project @ 1997-11-21 02:11:19 by jwe]
jwe
parents: 3099
diff changeset
2823
fe2d1ae8926b [project @ 1997-11-21 02:11:19 by jwe]
jwe
parents: 3099
diff changeset
2824 unwind_protect::begin_frame ("finish_matrix");
fe2d1ae8926b [project @ 1997-11-21 02:11:19 by jwe]
jwe
parents: 3099
diff changeset
2825
fe2d1ae8926b [project @ 1997-11-21 02:11:19 by jwe]
jwe
parents: 3099
diff changeset
2826 unwind_protect_int (error_state);
4452
f3c21a1d1c62 [project @ 2003-07-09 23:20:18 by jwe]
jwe
parents: 4426
diff changeset
2827 unwind_protect_int (warning_state);
3110
fe2d1ae8926b [project @ 1997-11-21 02:11:19 by jwe]
jwe
parents: 3099
diff changeset
2828
3815
c554ad71bafc [project @ 2001-04-19 19:50:52 by jwe]
jwe
parents: 3802
diff changeset
2829 unwind_protect_bool (discard_error_messages);
4452
f3c21a1d1c62 [project @ 2003-07-09 23:20:18 by jwe]
jwe
parents: 4426
diff changeset
2830 unwind_protect_bool (discard_warning_messages);
f3c21a1d1c62 [project @ 2003-07-09 23:20:18 by jwe]
jwe
parents: 4426
diff changeset
2831
3815
c554ad71bafc [project @ 2001-04-19 19:50:52 by jwe]
jwe
parents: 3802
diff changeset
2832 discard_error_messages = true;
4452
f3c21a1d1c62 [project @ 2003-07-09 23:20:18 by jwe]
jwe
parents: 4426
diff changeset
2833 discard_warning_messages = true;
1623
fa7a847f9b92 [project @ 1995-11-06 18:05:09 by jwe]
jwe
parents: 1607
diff changeset
2834
2533
987e934bbb8c [project @ 1996-11-19 18:21:23 by jwe]
jwe
parents: 2525
diff changeset
2835 if (m->all_elements_are_constant ())
1829
7d2982b55242 [project @ 1996-02-02 14:12:59 by jwe]
jwe
parents: 1826
diff changeset
2836 {
8658
73c4516fae10 New evaluator and debugger derived from tree-walker class
John W. Eaton <jwe@octave.org>
parents: 8471
diff changeset
2837 octave_value tmp = m->rvalue1 ();
1623
fa7a847f9b92 [project @ 1995-11-06 18:05:09 by jwe]
jwe
parents: 1607
diff changeset
2838
3489
cbee5fbb696d [project @ 2000-01-28 09:14:32 by jwe]
jwe
parents: 3485
diff changeset
2839 if (! (error_state || warning_state))
2533
987e934bbb8c [project @ 1996-11-19 18:21:23 by jwe]
jwe
parents: 2525
diff changeset
2840 {
8658
73c4516fae10 New evaluator and debugger derived from tree-walker class
John W. Eaton <jwe@octave.org>
parents: 8471
diff changeset
2841 tree_constant *tc_retval
73c4516fae10 New evaluator and debugger derived from tree-walker class
John W. Eaton <jwe@octave.org>
parents: 8471
diff changeset
2842 = new tree_constant (tmp, m->line (), m->column ());
2533
987e934bbb8c [project @ 1996-11-19 18:21:23 by jwe]
jwe
parents: 2525
diff changeset
2843
5765
7ba9ad1fec11 [project @ 2006-04-17 05:05:15 by jwe]
jwe
parents: 5760
diff changeset
2844 std::ostringstream buf;
2533
987e934bbb8c [project @ 1996-11-19 18:21:23 by jwe]
jwe
parents: 2525
diff changeset
2845
987e934bbb8c [project @ 1996-11-19 18:21:23 by jwe]
jwe
parents: 2525
diff changeset
2846 tree_print_code tpc (buf);
987e934bbb8c [project @ 1996-11-19 18:21:23 by jwe]
jwe
parents: 2525
diff changeset
2847
987e934bbb8c [project @ 1996-11-19 18:21:23 by jwe]
jwe
parents: 2525
diff changeset
2848 m->accept (tpc);
987e934bbb8c [project @ 1996-11-19 18:21:23 by jwe]
jwe
parents: 2525
diff changeset
2849
5765
7ba9ad1fec11 [project @ 2006-04-17 05:05:15 by jwe]
jwe
parents: 5760
diff changeset
2850 tc_retval->stash_original_text (buf.str ());
2533
987e934bbb8c [project @ 1996-11-19 18:21:23 by jwe]
jwe
parents: 2525
diff changeset
2851
987e934bbb8c [project @ 1996-11-19 18:21:23 by jwe]
jwe
parents: 2525
diff changeset
2852 delete m;
987e934bbb8c [project @ 1996-11-19 18:21:23 by jwe]
jwe
parents: 2525
diff changeset
2853
987e934bbb8c [project @ 1996-11-19 18:21:23 by jwe]
jwe
parents: 2525
diff changeset
2854 retval = tc_retval;
987e934bbb8c [project @ 1996-11-19 18:21:23 by jwe]
jwe
parents: 2525
diff changeset
2855 }
1623
fa7a847f9b92 [project @ 1995-11-06 18:05:09 by jwe]
jwe
parents: 1607
diff changeset
2856 }
3110
fe2d1ae8926b [project @ 1997-11-21 02:11:19 by jwe]
jwe
parents: 3099
diff changeset
2857
fe2d1ae8926b [project @ 1997-11-21 02:11:19 by jwe]
jwe
parents: 3099
diff changeset
2858 unwind_protect::run_frame ("finish_matrix");
1623
fa7a847f9b92 [project @ 1995-11-06 18:05:09 by jwe]
jwe
parents: 1607
diff changeset
2859
fa7a847f9b92 [project @ 1995-11-06 18:05:09 by jwe]
jwe
parents: 1607
diff changeset
2860 return retval;
fa7a847f9b92 [project @ 1995-11-06 18:05:09 by jwe]
jwe
parents: 1607
diff changeset
2861 }
fa7a847f9b92 [project @ 1995-11-06 18:05:09 by jwe]
jwe
parents: 1607
diff changeset
2862
3351
8623649c967c [project @ 1999-11-15 16:17:01 by jwe]
jwe
parents: 3347
diff changeset
2863 // Finish building a cell list.
8623649c967c [project @ 1999-11-15 16:17:01 by jwe]
jwe
parents: 3347
diff changeset
2864
8623649c967c [project @ 1999-11-15 16:17:01 by jwe]
jwe
parents: 3347
diff changeset
2865 static tree_expression *
8623649c967c [project @ 1999-11-15 16:17:01 by jwe]
jwe
parents: 3347
diff changeset
2866 finish_cell (tree_cell *c)
8623649c967c [project @ 1999-11-15 16:17:01 by jwe]
jwe
parents: 3347
diff changeset
2867 {
5875
f6ddc0ee2315 [project @ 2006-07-01 15:24:44 by jwe]
jwe
parents: 5864
diff changeset
2868 return finish_matrix (c);
3351
8623649c967c [project @ 1999-11-15 16:17:01 by jwe]
jwe
parents: 3347
diff changeset
2869 }
8623649c967c [project @ 1999-11-15 16:17:01 by jwe]
jwe
parents: 3347
diff changeset
2870
1511
74f9e88a2c12 [project @ 1995-10-03 10:49:31 by jwe]
jwe
parents: 1491
diff changeset
2871 static void
74f9e88a2c12 [project @ 1995-10-03 10:49:31 by jwe]
jwe
parents: 1491
diff changeset
2872 maybe_warn_missing_semi (tree_statement_list *t)
74f9e88a2c12 [project @ 1995-10-03 10:49:31 by jwe]
jwe
parents: 1491
diff changeset
2873 {
5781
faafc2d98b8d [project @ 2006-05-02 19:40:19 by jwe]
jwe
parents: 5775
diff changeset
2874 if (lexer_flags.defining_func)
1511
74f9e88a2c12 [project @ 1995-10-03 10:49:31 by jwe]
jwe
parents: 1491
diff changeset
2875 {
4219
23d06c9e1edd [project @ 2002-12-06 21:29:17 by jwe]
jwe
parents: 4207
diff changeset
2876 tree_statement *tmp = t->back();
1607
795527e9db19 [project @ 1995-11-02 13:03:36 by jwe]
jwe
parents: 1588
diff changeset
2877
1511
74f9e88a2c12 [project @ 1995-10-03 10:49:31 by jwe]
jwe
parents: 1491
diff changeset
2878 if (tmp->is_expression ())
5781
faafc2d98b8d [project @ 2006-05-02 19:40:19 by jwe]
jwe
parents: 5775
diff changeset
2879 warning_with_id
faafc2d98b8d [project @ 2006-05-02 19:40:19 by jwe]
jwe
parents: 5775
diff changeset
2880 ("Octave:missing-semicolon",
faafc2d98b8d [project @ 2006-05-02 19:40:19 by jwe]
jwe
parents: 5775
diff changeset
2881 "missing semicolon near line %d, column %d in file `%s'",
faafc2d98b8d [project @ 2006-05-02 19:40:19 by jwe]
jwe
parents: 5775
diff changeset
2882 tmp->line (), tmp->column (), curr_fcn_file_full_name.c_str ());
1511
74f9e88a2c12 [project @ 1995-10-03 10:49:31 by jwe]
jwe
parents: 1491
diff changeset
2883 }
74f9e88a2c12 [project @ 1995-10-03 10:49:31 by jwe]
jwe
parents: 1491
diff changeset
2884 }
1994
c2d20f365b84 [project @ 1996-03-03 01:19:32 by jwe]
jwe
parents: 1884
diff changeset
2885
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
2886 static tree_statement_list *
2525
8561d88be5f2 [project @ 1996-11-17 21:23:31 by jwe]
jwe
parents: 2524
diff changeset
2887 set_stmt_print_flag (tree_statement_list *list, char sep,
8561d88be5f2 [project @ 1996-11-17 21:23:31 by jwe]
jwe
parents: 2524
diff changeset
2888 bool warn_missing_semi)
8561d88be5f2 [project @ 1996-11-17 21:23:31 by jwe]
jwe
parents: 2524
diff changeset
2889 {
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
2890 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
2891
2525
8561d88be5f2 [project @ 1996-11-17 21:23:31 by jwe]
jwe
parents: 2524
diff changeset
2892 switch (sep)
8561d88be5f2 [project @ 1996-11-17 21:23:31 by jwe]
jwe
parents: 2524
diff changeset
2893 {
8561d88be5f2 [project @ 1996-11-17 21:23:31 by jwe]
jwe
parents: 2524
diff changeset
2894 case ';':
8658
73c4516fae10 New evaluator and debugger derived from tree-walker class
John W. Eaton <jwe@octave.org>
parents: 8471
diff changeset
2895 tmp->set_print_flag (false);
2525
8561d88be5f2 [project @ 1996-11-17 21:23:31 by jwe]
jwe
parents: 2524
diff changeset
2896 break;
8561d88be5f2 [project @ 1996-11-17 21:23:31 by jwe]
jwe
parents: 2524
diff changeset
2897
8561d88be5f2 [project @ 1996-11-17 21:23:31 by jwe]
jwe
parents: 2524
diff changeset
2898 case 0:
8561d88be5f2 [project @ 1996-11-17 21:23:31 by jwe]
jwe
parents: 2524
diff changeset
2899 case ',':
8561d88be5f2 [project @ 1996-11-17 21:23:31 by jwe]
jwe
parents: 2524
diff changeset
2900 case '\n':
8658
73c4516fae10 New evaluator and debugger derived from tree-walker class
John W. Eaton <jwe@octave.org>
parents: 8471
diff changeset
2901 tmp->set_print_flag (true);
2525
8561d88be5f2 [project @ 1996-11-17 21:23:31 by jwe]
jwe
parents: 2524
diff changeset
2902 if (warn_missing_semi)
8561d88be5f2 [project @ 1996-11-17 21:23:31 by jwe]
jwe
parents: 2524
diff changeset
2903 maybe_warn_missing_semi (list);
8561d88be5f2 [project @ 1996-11-17 21:23:31 by jwe]
jwe
parents: 2524
diff changeset
2904 break;
8561d88be5f2 [project @ 1996-11-17 21:23:31 by jwe]
jwe
parents: 2524
diff changeset
2905
8561d88be5f2 [project @ 1996-11-17 21:23:31 by jwe]
jwe
parents: 2524
diff changeset
2906 default:
8561d88be5f2 [project @ 1996-11-17 21:23:31 by jwe]
jwe
parents: 2524
diff changeset
2907 warning ("unrecognized separator type!");
8561d88be5f2 [project @ 1996-11-17 21:23:31 by jwe]
jwe
parents: 2524
diff changeset
2908 break;
8561d88be5f2 [project @ 1996-11-17 21:23:31 by jwe]
jwe
parents: 2524
diff changeset
2909 }
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
2910
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
2911 // 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
2912 // 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
2913
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
2914 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
2915 {
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
2916 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
2917 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
2918 }
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
2919
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
2920 return list;
2525
8561d88be5f2 [project @ 1996-11-17 21:23:31 by jwe]
jwe
parents: 2524
diff changeset
2921 }
8561d88be5f2 [project @ 1996-11-17 21:23:31 by jwe]
jwe
parents: 2524
diff changeset
2922
8448
d6c0d5f208de parse.y: avoid storing null statements in statement lists
John W. Eaton <jwe@octave.org>
parents: 8447
diff changeset
2923 static tree_statement_list *
d6c0d5f208de parse.y: avoid storing null statements in statement lists
John W. Eaton <jwe@octave.org>
parents: 8447
diff changeset
2924 make_statement_list (tree_statement *stmt)
d6c0d5f208de parse.y: avoid storing null statements in statement lists
John W. Eaton <jwe@octave.org>
parents: 8447
diff changeset
2925 {
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
2926 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
2927 }
d6c0d5f208de parse.y: avoid storing null statements in statement lists
John W. Eaton <jwe@octave.org>
parents: 8447
diff changeset
2928
d6c0d5f208de parse.y: avoid storing null statements in statement lists
John W. Eaton <jwe@octave.org>
parents: 8447
diff changeset
2929 static tree_statement_list *
d6c0d5f208de parse.y: avoid storing null statements in statement lists
John W. Eaton <jwe@octave.org>
parents: 8447
diff changeset
2930 append_statement_list (tree_statement_list *list, char sep,
d6c0d5f208de parse.y: avoid storing null statements in statement lists
John W. Eaton <jwe@octave.org>
parents: 8447
diff changeset
2931 tree_statement *stmt, bool warn_missing_semi)
d6c0d5f208de parse.y: avoid storing null statements in statement lists
John W. Eaton <jwe@octave.org>
parents: 8447
diff changeset
2932 {
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
2933 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
2934
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
2935 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
2936
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
2937 return list;
8448
d6c0d5f208de parse.y: avoid storing null statements in statement lists
John W. Eaton <jwe@octave.org>
parents: 8447
diff changeset
2938 }
d6c0d5f208de parse.y: avoid storing null statements in statement lists
John W. Eaton <jwe@octave.org>
parents: 8447
diff changeset
2939
3021
18d64612e67a [project @ 1997-06-03 22:18:56 by jwe]
jwe
parents: 3016
diff changeset
2940 static void
18d64612e67a [project @ 1997-06-03 22:18:56 by jwe]
jwe
parents: 3016
diff changeset
2941 safe_fclose (void *f)
18d64612e67a [project @ 1997-06-03 22:18:56 by jwe]
jwe
parents: 3016
diff changeset
2942 {
5775
ace8d8d26933 [project @ 2006-04-24 19:13:06 by jwe]
jwe
parents: 5774
diff changeset
2943 // FIXME -- comments at the end of an input file are
3765
e10451597802 [project @ 2001-01-17 18:41:29 by jwe]
jwe
parents: 3726
diff changeset
2944 // discarded (otherwise, they would be appended to the next
e10451597802 [project @ 2001-01-17 18:41:29 by jwe]
jwe
parents: 3726
diff changeset
2945 // statement, possibly from the command line or another file, which
e10451597802 [project @ 2001-01-17 18:41:29 by jwe]
jwe
parents: 3726
diff changeset
2946 // can be quite confusing).
e10451597802 [project @ 2001-01-17 18:41:29 by jwe]
jwe
parents: 3726
diff changeset
2947
5308
bc8d6ebb6ee1 [project @ 2005-04-27 05:08:19 by jwe]
jwe
parents: 5307
diff changeset
2948 octave_comment_list *tc = octave_comment_buffer::get_comment ();
bc8d6ebb6ee1 [project @ 2005-04-27 05:08:19 by jwe]
jwe
parents: 5307
diff changeset
2949
bc8d6ebb6ee1 [project @ 2005-04-27 05:08:19 by jwe]
jwe
parents: 5307
diff changeset
2950 delete tc;
3765
e10451597802 [project @ 2001-01-17 18:41:29 by jwe]
jwe
parents: 3726
diff changeset
2951
3021
18d64612e67a [project @ 1997-06-03 22:18:56 by jwe]
jwe
parents: 3016
diff changeset
2952 if (f)
18d64612e67a [project @ 1997-06-03 22:18:56 by jwe]
jwe
parents: 3016
diff changeset
2953 fclose (static_cast<FILE *> (f));
18d64612e67a [project @ 1997-06-03 22:18:56 by jwe]
jwe
parents: 3016
diff changeset
2954 }
18d64612e67a [project @ 1997-06-03 22:18:56 by jwe]
jwe
parents: 3016
diff changeset
2955
18d64612e67a [project @ 1997-06-03 22:18:56 by jwe]
jwe
parents: 3016
diff changeset
2956 static bool
5175
7a25bb94ef65 [project @ 2005-03-02 17:38:32 by jwe]
jwe
parents: 5161
diff changeset
2957 looks_like_copyright (const std::string& s)
3021
18d64612e67a [project @ 1997-06-03 22:18:56 by jwe]
jwe
parents: 3016
diff changeset
2958 {
7720
4e2eafef689c unify comment and help text processing in lex.l and parse.y
John W. Eaton <jwe@octave.org>
parents: 7719
diff changeset
2959 bool retval = false;
4e2eafef689c unify comment and help text processing in lex.l and parse.y
John W. Eaton <jwe@octave.org>
parents: 7719
diff changeset
2960
4e2eafef689c unify comment and help text processing in lex.l and parse.y
John W. Eaton <jwe@octave.org>
parents: 7719
diff changeset
2961 if (! s.empty ())
4e2eafef689c unify comment and help text processing in lex.l and parse.y
John W. Eaton <jwe@octave.org>
parents: 7719
diff changeset
2962 {
4e2eafef689c unify comment and help text processing in lex.l and parse.y
John W. Eaton <jwe@octave.org>
parents: 7719
diff changeset
2963 size_t offset = s.find_first_not_of (" \t");
4e2eafef689c unify comment and help text processing in lex.l and parse.y
John W. Eaton <jwe@octave.org>
parents: 7719
diff changeset
2964
4e2eafef689c unify comment and help text processing in lex.l and parse.y
John W. Eaton <jwe@octave.org>
parents: 7719
diff changeset
2965 retval = (s.substr (offset, 9) == "Copyright");
4e2eafef689c unify comment and help text processing in lex.l and parse.y
John W. Eaton <jwe@octave.org>
parents: 7719
diff changeset
2966 }
4e2eafef689c unify comment and help text processing in lex.l and parse.y
John W. Eaton <jwe@octave.org>
parents: 7719
diff changeset
2967
4e2eafef689c unify comment and help text processing in lex.l and parse.y
John W. Eaton <jwe@octave.org>
parents: 7719
diff changeset
2968 return retval;
3021
18d64612e67a [project @ 1997-06-03 22:18:56 by jwe]
jwe
parents: 3016
diff changeset
2969 }
18d64612e67a [project @ 1997-06-03 22:18:56 by jwe]
jwe
parents: 3016
diff changeset
2970
4540
491ac5f9d120 [project @ 2003-10-16 17:34:07 by jwe]
jwe
parents: 4486
diff changeset
2971 static int
491ac5f9d120 [project @ 2003-10-16 17:34:07 by jwe]
jwe
parents: 4486
diff changeset
2972 text_getc (FILE *f)
491ac5f9d120 [project @ 2003-10-16 17:34:07 by jwe]
jwe
parents: 4486
diff changeset
2973 {
491ac5f9d120 [project @ 2003-10-16 17:34:07 by jwe]
jwe
parents: 4486
diff changeset
2974 int c = getc (f);
491ac5f9d120 [project @ 2003-10-16 17:34:07 by jwe]
jwe
parents: 4486
diff changeset
2975
7728
13820b9f5fd9 more consistent handling of CR/CRLF/LF line endings in lexer and parser
John W. Eaton <jwe@octave.org>
parents: 7723
diff changeset
2976 // Convert CRLF into just LF and single CR into LF.
4540
491ac5f9d120 [project @ 2003-10-16 17:34:07 by jwe]
jwe
parents: 4486
diff changeset
2977
491ac5f9d120 [project @ 2003-10-16 17:34:07 by jwe]
jwe
parents: 4486
diff changeset
2978 if (c == '\r')
491ac5f9d120 [project @ 2003-10-16 17:34:07 by jwe]
jwe
parents: 4486
diff changeset
2979 {
491ac5f9d120 [project @ 2003-10-16 17:34:07 by jwe]
jwe
parents: 4486
diff changeset
2980 c = getc (f);
491ac5f9d120 [project @ 2003-10-16 17:34:07 by jwe]
jwe
parents: 4486
diff changeset
2981
8447
adab48231a03 make input_line_number work again
John W. Eaton <jwe@octave.org>
parents: 8311
diff changeset
2982 if (c != '\n')
4540
491ac5f9d120 [project @ 2003-10-16 17:34:07 by jwe]
jwe
parents: 4486
diff changeset
2983 {
491ac5f9d120 [project @ 2003-10-16 17:34:07 by jwe]
jwe
parents: 4486
diff changeset
2984 ungetc (c, f);
7728
13820b9f5fd9 more consistent handling of CR/CRLF/LF line endings in lexer and parser
John W. Eaton <jwe@octave.org>
parents: 7723
diff changeset
2985 c = '\n';
4540
491ac5f9d120 [project @ 2003-10-16 17:34:07 by jwe]
jwe
parents: 4486
diff changeset
2986 }
491ac5f9d120 [project @ 2003-10-16 17:34:07 by jwe]
jwe
parents: 4486
diff changeset
2987 }
8447
adab48231a03 make input_line_number work again
John W. Eaton <jwe@octave.org>
parents: 8311
diff changeset
2988
adab48231a03 make input_line_number work again
John W. Eaton <jwe@octave.org>
parents: 8311
diff changeset
2989 if (c == '\n')
7723
74f5e0c7de9e first pass at handling block comments
John W. Eaton <jwe@octave.org>
parents: 7720
diff changeset
2990 input_line_number++;
4540
491ac5f9d120 [project @ 2003-10-16 17:34:07 by jwe]
jwe
parents: 4486
diff changeset
2991
491ac5f9d120 [project @ 2003-10-16 17:34:07 by jwe]
jwe
parents: 4486
diff changeset
2992 return c;
491ac5f9d120 [project @ 2003-10-16 17:34:07 by jwe]
jwe
parents: 4486
diff changeset
2993 }
491ac5f9d120 [project @ 2003-10-16 17:34:07 by jwe]
jwe
parents: 4486
diff changeset
2994
7720
4e2eafef689c unify comment and help text processing in lex.l and parse.y
John W. Eaton <jwe@octave.org>
parents: 7719
diff changeset
2995 class
4e2eafef689c unify comment and help text processing in lex.l and parse.y
John W. Eaton <jwe@octave.org>
parents: 7719
diff changeset
2996 stdio_stream_reader : public stream_reader
3021
18d64612e67a [project @ 1997-06-03 22:18:56 by jwe]
jwe
parents: 3016
diff changeset
2997 {
7720
4e2eafef689c unify comment and help text processing in lex.l and parse.y
John W. Eaton <jwe@octave.org>
parents: 7719
diff changeset
2998 public:
4e2eafef689c unify comment and help text processing in lex.l and parse.y
John W. Eaton <jwe@octave.org>
parents: 7719
diff changeset
2999 stdio_stream_reader (FILE *f_arg) : stream_reader (), f (f_arg) { }
4e2eafef689c unify comment and help text processing in lex.l and parse.y
John W. Eaton <jwe@octave.org>
parents: 7719
diff changeset
3000
4e2eafef689c unify comment and help text processing in lex.l and parse.y
John W. Eaton <jwe@octave.org>
parents: 7719
diff changeset
3001 int getc (void) { return ::text_getc (f); }
8447
adab48231a03 make input_line_number work again
John W. Eaton <jwe@octave.org>
parents: 8311
diff changeset
3002 int ungetc (int c)
adab48231a03 make input_line_number work again
John W. Eaton <jwe@octave.org>
parents: 8311
diff changeset
3003 {
adab48231a03 make input_line_number work again
John W. Eaton <jwe@octave.org>
parents: 8311
diff changeset
3004 if (c == '\n')
adab48231a03 make input_line_number work again
John W. Eaton <jwe@octave.org>
parents: 8311
diff changeset
3005 input_line_number--;
adab48231a03 make input_line_number work again
John W. Eaton <jwe@octave.org>
parents: 8311
diff changeset
3006
adab48231a03 make input_line_number work again
John W. Eaton <jwe@octave.org>
parents: 8311
diff changeset
3007 return ::ungetc (c, f);
adab48231a03 make input_line_number work again
John W. Eaton <jwe@octave.org>
parents: 8311
diff changeset
3008 }
7720
4e2eafef689c unify comment and help text processing in lex.l and parse.y
John W. Eaton <jwe@octave.org>
parents: 7719
diff changeset
3009
4e2eafef689c unify comment and help text processing in lex.l and parse.y
John W. Eaton <jwe@octave.org>
parents: 7719
diff changeset
3010 private:
4e2eafef689c unify comment and help text processing in lex.l and parse.y
John W. Eaton <jwe@octave.org>
parents: 7719
diff changeset
3011 FILE *f;
4e2eafef689c unify comment and help text processing in lex.l and parse.y
John W. Eaton <jwe@octave.org>
parents: 7719
diff changeset
3012 };
4e2eafef689c unify comment and help text processing in lex.l and parse.y
John W. Eaton <jwe@octave.org>
parents: 7719
diff changeset
3013
4e2eafef689c unify comment and help text processing in lex.l and parse.y
John W. Eaton <jwe@octave.org>
parents: 7719
diff changeset
3014 static bool
4e2eafef689c unify comment and help text processing in lex.l and parse.y
John W. Eaton <jwe@octave.org>
parents: 7719
diff changeset
3015 skip_white_space (stream_reader& reader)
4e2eafef689c unify comment and help text processing in lex.l and parse.y
John W. Eaton <jwe@octave.org>
parents: 7719
diff changeset
3016 {
4e2eafef689c unify comment and help text processing in lex.l and parse.y
John W. Eaton <jwe@octave.org>
parents: 7719
diff changeset
3017 int c = 0;
4e2eafef689c unify comment and help text processing in lex.l and parse.y
John W. Eaton <jwe@octave.org>
parents: 7719
diff changeset
3018
4e2eafef689c unify comment and help text processing in lex.l and parse.y
John W. Eaton <jwe@octave.org>
parents: 7719
diff changeset
3019 while ((c = reader.getc ()) != EOF)
3021
18d64612e67a [project @ 1997-06-03 22:18:56 by jwe]
jwe
parents: 3016
diff changeset
3020 {
7720
4e2eafef689c unify comment and help text processing in lex.l and parse.y
John W. Eaton <jwe@octave.org>
parents: 7719
diff changeset
3021 switch (c)
3021
18d64612e67a [project @ 1997-06-03 22:18:56 by jwe]
jwe
parents: 3016
diff changeset
3022 {
7720
4e2eafef689c unify comment and help text processing in lex.l and parse.y
John W. Eaton <jwe@octave.org>
parents: 7719
diff changeset
3023 case ' ':
4e2eafef689c unify comment and help text processing in lex.l and parse.y
John W. Eaton <jwe@octave.org>
parents: 7719
diff changeset
3024 case '\t':
4e2eafef689c unify comment and help text processing in lex.l and parse.y
John W. Eaton <jwe@octave.org>
parents: 7719
diff changeset
3025 current_input_column++;
4e2eafef689c unify comment and help text processing in lex.l and parse.y
John W. Eaton <jwe@octave.org>
parents: 7719
diff changeset
3026 break;
4e2eafef689c unify comment and help text processing in lex.l and parse.y
John W. Eaton <jwe@octave.org>
parents: 7719
diff changeset
3027
4e2eafef689c unify comment and help text processing in lex.l and parse.y
John W. Eaton <jwe@octave.org>
parents: 7719
diff changeset
3028 case '\n':
4e2eafef689c unify comment and help text processing in lex.l and parse.y
John W. Eaton <jwe@octave.org>
parents: 7719
diff changeset
3029 current_input_column = 0;
4e2eafef689c unify comment and help text processing in lex.l and parse.y
John W. Eaton <jwe@octave.org>
parents: 7719
diff changeset
3030 break;
4e2eafef689c unify comment and help text processing in lex.l and parse.y
John W. Eaton <jwe@octave.org>
parents: 7719
diff changeset
3031
4e2eafef689c unify comment and help text processing in lex.l and parse.y
John W. Eaton <jwe@octave.org>
parents: 7719
diff changeset
3032 default:
4e2eafef689c unify comment and help text processing in lex.l and parse.y
John W. Eaton <jwe@octave.org>
parents: 7719
diff changeset
3033 current_input_column--;
4e2eafef689c unify comment and help text processing in lex.l and parse.y
John W. Eaton <jwe@octave.org>
parents: 7719
diff changeset
3034 reader.ungetc (c);
4e2eafef689c unify comment and help text processing in lex.l and parse.y
John W. Eaton <jwe@octave.org>
parents: 7719
diff changeset
3035 goto done;
3021
18d64612e67a [project @ 1997-06-03 22:18:56 by jwe]
jwe
parents: 3016
diff changeset
3036 }
18d64612e67a [project @ 1997-06-03 22:18:56 by jwe]
jwe
parents: 3016
diff changeset
3037 }
18d64612e67a [project @ 1997-06-03 22:18:56 by jwe]
jwe
parents: 3016
diff changeset
3038
18d64612e67a [project @ 1997-06-03 22:18:56 by jwe]
jwe
parents: 3016
diff changeset
3039 done:
18d64612e67a [project @ 1997-06-03 22:18:56 by jwe]
jwe
parents: 3016
diff changeset
3040
7720
4e2eafef689c unify comment and help text processing in lex.l and parse.y
John W. Eaton <jwe@octave.org>
parents: 7719
diff changeset
3041 return (c == EOF);
3021
18d64612e67a [project @ 1997-06-03 22:18:56 by jwe]
jwe
parents: 3016
diff changeset
3042 }
18d64612e67a [project @ 1997-06-03 22:18:56 by jwe]
jwe
parents: 3016
diff changeset
3043
7720
4e2eafef689c unify comment and help text processing in lex.l and parse.y
John W. Eaton <jwe@octave.org>
parents: 7719
diff changeset
3044 static std::string
4e2eafef689c unify comment and help text processing in lex.l and parse.y
John W. Eaton <jwe@octave.org>
parents: 7719
diff changeset
3045 gobble_leading_white_space (FILE *ffile, bool& eof)
3021
18d64612e67a [project @ 1997-06-03 22:18:56 by jwe]
jwe
parents: 3016
diff changeset
3046 {
7720
4e2eafef689c unify comment and help text processing in lex.l and parse.y
John W. Eaton <jwe@octave.org>
parents: 7719
diff changeset
3047 std::string help_txt;
4e2eafef689c unify comment and help text processing in lex.l and parse.y
John W. Eaton <jwe@octave.org>
parents: 7719
diff changeset
3048
4e2eafef689c unify comment and help text processing in lex.l and parse.y
John W. Eaton <jwe@octave.org>
parents: 7719
diff changeset
3049 eof = false;
4e2eafef689c unify comment and help text processing in lex.l and parse.y
John W. Eaton <jwe@octave.org>
parents: 7719
diff changeset
3050
4e2eafef689c unify comment and help text processing in lex.l and parse.y
John W. Eaton <jwe@octave.org>
parents: 7719
diff changeset
3051 // TRUE means we have already cached the help text.
4e2eafef689c unify comment and help text processing in lex.l and parse.y
John W. Eaton <jwe@octave.org>
parents: 7719
diff changeset
3052 bool have_help_text = false;
4e2eafef689c unify comment and help text processing in lex.l and parse.y
John W. Eaton <jwe@octave.org>
parents: 7719
diff changeset
3053
4e2eafef689c unify comment and help text processing in lex.l and parse.y
John W. Eaton <jwe@octave.org>
parents: 7719
diff changeset
3054 std::string txt;
4e2eafef689c unify comment and help text processing in lex.l and parse.y
John W. Eaton <jwe@octave.org>
parents: 7719
diff changeset
3055
4e2eafef689c unify comment and help text processing in lex.l and parse.y
John W. Eaton <jwe@octave.org>
parents: 7719
diff changeset
3056 stdio_stream_reader stdio_reader (ffile);
4e2eafef689c unify comment and help text processing in lex.l and parse.y
John W. Eaton <jwe@octave.org>
parents: 7719
diff changeset
3057
4e2eafef689c unify comment and help text processing in lex.l and parse.y
John W. Eaton <jwe@octave.org>
parents: 7719
diff changeset
3058 while (true)
4e2eafef689c unify comment and help text processing in lex.l and parse.y
John W. Eaton <jwe@octave.org>
parents: 7719
diff changeset
3059 {
4e2eafef689c unify comment and help text processing in lex.l and parse.y
John W. Eaton <jwe@octave.org>
parents: 7719
diff changeset
3060 eof = skip_white_space (stdio_reader);
4e2eafef689c unify comment and help text processing in lex.l and parse.y
John W. Eaton <jwe@octave.org>
parents: 7719
diff changeset
3061
4e2eafef689c unify comment and help text processing in lex.l and parse.y
John W. Eaton <jwe@octave.org>
parents: 7719
diff changeset
3062 if (eof)
4e2eafef689c unify comment and help text processing in lex.l and parse.y
John W. Eaton <jwe@octave.org>
parents: 7719
diff changeset
3063 break;
4e2eafef689c unify comment and help text processing in lex.l and parse.y
John W. Eaton <jwe@octave.org>
parents: 7719
diff changeset
3064
7723
74f5e0c7de9e first pass at handling block comments
John W. Eaton <jwe@octave.org>
parents: 7720
diff changeset
3065 txt = grab_comment_block (stdio_reader, true, eof);
7720
4e2eafef689c unify comment and help text processing in lex.l and parse.y
John W. Eaton <jwe@octave.org>
parents: 7719
diff changeset
3066
4e2eafef689c unify comment and help text processing in lex.l and parse.y
John W. Eaton <jwe@octave.org>
parents: 7719
diff changeset
3067 if (txt.empty ())
4e2eafef689c unify comment and help text processing in lex.l and parse.y
John W. Eaton <jwe@octave.org>
parents: 7719
diff changeset
3068 break;
4e2eafef689c unify comment and help text processing in lex.l and parse.y
John W. Eaton <jwe@octave.org>
parents: 7719
diff changeset
3069
4e2eafef689c unify comment and help text processing in lex.l and parse.y
John W. Eaton <jwe@octave.org>
parents: 7719
diff changeset
3070 if (! (have_help_text || looks_like_copyright (txt)))
4e2eafef689c unify comment and help text processing in lex.l and parse.y
John W. Eaton <jwe@octave.org>
parents: 7719
diff changeset
3071 {
4e2eafef689c unify comment and help text processing in lex.l and parse.y
John W. Eaton <jwe@octave.org>
parents: 7719
diff changeset
3072 help_txt = txt;
4e2eafef689c unify comment and help text processing in lex.l and parse.y
John W. Eaton <jwe@octave.org>
parents: 7719
diff changeset
3073 have_help_text = true;
4e2eafef689c unify comment and help text processing in lex.l and parse.y
John W. Eaton <jwe@octave.org>
parents: 7719
diff changeset
3074 }
4e2eafef689c unify comment and help text processing in lex.l and parse.y
John W. Eaton <jwe@octave.org>
parents: 7719
diff changeset
3075
4e2eafef689c unify comment and help text processing in lex.l and parse.y
John W. Eaton <jwe@octave.org>
parents: 7719
diff changeset
3076 octave_comment_buffer::append (txt);
4e2eafef689c unify comment and help text processing in lex.l and parse.y
John W. Eaton <jwe@octave.org>
parents: 7719
diff changeset
3077
4e2eafef689c unify comment and help text processing in lex.l and parse.y
John W. Eaton <jwe@octave.org>
parents: 7719
diff changeset
3078 if (eof)
4e2eafef689c unify comment and help text processing in lex.l and parse.y
John W. Eaton <jwe@octave.org>
parents: 7719
diff changeset
3079 break;
4e2eafef689c unify comment and help text processing in lex.l and parse.y
John W. Eaton <jwe@octave.org>
parents: 7719
diff changeset
3080 }
4e2eafef689c unify comment and help text processing in lex.l and parse.y
John W. Eaton <jwe@octave.org>
parents: 7719
diff changeset
3081
4e2eafef689c unify comment and help text processing in lex.l and parse.y
John W. Eaton <jwe@octave.org>
parents: 7719
diff changeset
3082 return help_txt;
3021
18d64612e67a [project @ 1997-06-03 22:18:56 by jwe]
jwe
parents: 3016
diff changeset
3083 }
18d64612e67a [project @ 1997-06-03 22:18:56 by jwe]
jwe
parents: 3016
diff changeset
3084
7715
5b4d278ec828 parse scripts completely before executing
John W. Eaton <jwe@octave.org>
parents: 7699
diff changeset
3085 static bool
5b4d278ec828 parse scripts completely before executing
John W. Eaton <jwe@octave.org>
parents: 7699
diff changeset
3086 looking_at_function_keyword (FILE *ffile)
5931
25da9a7d5f6d [project @ 2006-08-16 06:52:19 by jwe]
jwe
parents: 5878
diff changeset
3087 {
7715
5b4d278ec828 parse scripts completely before executing
John W. Eaton <jwe@octave.org>
parents: 7699
diff changeset
3088 bool status = false;
3021
18d64612e67a [project @ 1997-06-03 22:18:56 by jwe]
jwe
parents: 3016
diff changeset
3089
18d64612e67a [project @ 1997-06-03 22:18:56 by jwe]
jwe
parents: 3016
diff changeset
3090 long pos = ftell (ffile);
18d64612e67a [project @ 1997-06-03 22:18:56 by jwe]
jwe
parents: 3016
diff changeset
3091
18d64612e67a [project @ 1997-06-03 22:18:56 by jwe]
jwe
parents: 3016
diff changeset
3092 char buf [10];
18d64612e67a [project @ 1997-06-03 22:18:56 by jwe]
jwe
parents: 3016
diff changeset
3093 fgets (buf, 10, ffile);
7715
5b4d278ec828 parse scripts completely before executing
John W. Eaton <jwe@octave.org>
parents: 7699
diff changeset
3094 size_t len = strlen (buf);
3021
18d64612e67a [project @ 1997-06-03 22:18:56 by jwe]
jwe
parents: 3016
diff changeset
3095 if (len > 8 && strncmp (buf, "function", 8) == 0
18d64612e67a [project @ 1997-06-03 22:18:56 by jwe]
jwe
parents: 3016
diff changeset
3096 && ! (isalnum (buf[8]) || buf[8] == '_'))
7715
5b4d278ec828 parse scripts completely before executing
John W. Eaton <jwe@octave.org>
parents: 7699
diff changeset
3097 status = true;
3021
18d64612e67a [project @ 1997-06-03 22:18:56 by jwe]
jwe
parents: 3016
diff changeset
3098
18d64612e67a [project @ 1997-06-03 22:18:56 by jwe]
jwe
parents: 3016
diff changeset
3099 fseek (ffile, pos, SEEK_SET);
18d64612e67a [project @ 1997-06-03 22:18:56 by jwe]
jwe
parents: 3016
diff changeset
3100
18d64612e67a [project @ 1997-06-03 22:18:56 by jwe]
jwe
parents: 3016
diff changeset
3101 return status;
18d64612e67a [project @ 1997-06-03 22:18:56 by jwe]
jwe
parents: 3016
diff changeset
3102 }
18d64612e67a [project @ 1997-06-03 22:18:56 by jwe]
jwe
parents: 3016
diff changeset
3103
18d64612e67a [project @ 1997-06-03 22:18:56 by jwe]
jwe
parents: 3016
diff changeset
3104 static void
18d64612e67a [project @ 1997-06-03 22:18:56 by jwe]
jwe
parents: 3016
diff changeset
3105 restore_command_history (void *)
18d64612e67a [project @ 1997-06-03 22:18:56 by jwe]
jwe
parents: 3016
diff changeset
3106 {
18d64612e67a [project @ 1997-06-03 22:18:56 by jwe]
jwe
parents: 3016
diff changeset
3107 command_history::ignore_entries (! Vsaving_history);
18d64612e67a [project @ 1997-06-03 22:18:56 by jwe]
jwe
parents: 3016
diff changeset
3108 }
18d64612e67a [project @ 1997-06-03 22:18:56 by jwe]
jwe
parents: 3016
diff changeset
3109
18d64612e67a [project @ 1997-06-03 22:18:56 by jwe]
jwe
parents: 3016
diff changeset
3110 static void
18d64612e67a [project @ 1997-06-03 22:18:56 by jwe]
jwe
parents: 3016
diff changeset
3111 restore_input_stream (void *f)
18d64612e67a [project @ 1997-06-03 22:18:56 by jwe]
jwe
parents: 3016
diff changeset
3112 {
18d64612e67a [project @ 1997-06-03 22:18:56 by jwe]
jwe
parents: 3016
diff changeset
3113 command_editor::set_input_stream (static_cast<FILE *> (f));
18d64612e67a [project @ 1997-06-03 22:18:56 by jwe]
jwe
parents: 3016
diff changeset
3114 }
18d64612e67a [project @ 1997-06-03 22:18:56 by jwe]
jwe
parents: 3016
diff changeset
3115
7336
745a8299c2b5 [project @ 2007-12-28 20:56:55 by jwe]
jwe
parents: 7017
diff changeset
3116 static octave_function *
745a8299c2b5 [project @ 2007-12-28 20:56:55 by jwe]
jwe
parents: 7017
diff changeset
3117 parse_fcn_file (const std::string& ff, const std::string& dispatch_type,
7715
5b4d278ec828 parse scripts completely before executing
John W. Eaton <jwe@octave.org>
parents: 7699
diff changeset
3118 bool force_script = false, bool require_file = true,
5b4d278ec828 parse scripts completely before executing
John W. Eaton <jwe@octave.org>
parents: 7699
diff changeset
3119 const std::string& warn_for = std::string ())
3021
18d64612e67a [project @ 1997-06-03 22:18:56 by jwe]
jwe
parents: 3016
diff changeset
3120 {
18d64612e67a [project @ 1997-06-03 22:18:56 by jwe]
jwe
parents: 3016
diff changeset
3121 unwind_protect::begin_frame ("parse_fcn_file");
18d64612e67a [project @ 1997-06-03 22:18:56 by jwe]
jwe
parents: 3016
diff changeset
3122
7336
745a8299c2b5 [project @ 2007-12-28 20:56:55 by jwe]
jwe
parents: 7017
diff changeset
3123 octave_function *fcn_ptr = 0;
3021
18d64612e67a [project @ 1997-06-03 22:18:56 by jwe]
jwe
parents: 3016
diff changeset
3124
18d64612e67a [project @ 1997-06-03 22:18:56 by jwe]
jwe
parents: 3016
diff changeset
3125 // Open function file and parse.
18d64612e67a [project @ 1997-06-03 22:18:56 by jwe]
jwe
parents: 3016
diff changeset
3126
18d64612e67a [project @ 1997-06-03 22:18:56 by jwe]
jwe
parents: 3016
diff changeset
3127 bool old_reading_fcn_file_state = reading_fcn_file;
18d64612e67a [project @ 1997-06-03 22:18:56 by jwe]
jwe
parents: 3016
diff changeset
3128
18d64612e67a [project @ 1997-06-03 22:18:56 by jwe]
jwe
parents: 3016
diff changeset
3129 FILE *in_stream = command_editor::get_input_stream ();
18d64612e67a [project @ 1997-06-03 22:18:56 by jwe]
jwe
parents: 3016
diff changeset
3130
18d64612e67a [project @ 1997-06-03 22:18:56 by jwe]
jwe
parents: 3016
diff changeset
3131 unwind_protect::add (restore_input_stream, in_stream);
18d64612e67a [project @ 1997-06-03 22:18:56 by jwe]
jwe
parents: 3016
diff changeset
3132
18d64612e67a [project @ 1997-06-03 22:18:56 by jwe]
jwe
parents: 3016
diff changeset
3133 unwind_protect_ptr (ff_instream);
18d64612e67a [project @ 1997-06-03 22:18:56 by jwe]
jwe
parents: 3016
diff changeset
3134
18d64612e67a [project @ 1997-06-03 22:18:56 by jwe]
jwe
parents: 3016
diff changeset
3135 unwind_protect_int (input_line_number);
18d64612e67a [project @ 1997-06-03 22:18:56 by jwe]
jwe
parents: 3016
diff changeset
3136 unwind_protect_int (current_input_column);
4238
a5a68c0afe56 [project @ 2002-12-25 21:04:33 by jwe]
jwe
parents: 4237
diff changeset
3137 unwind_protect_int (end_tokens_expected);
3021
18d64612e67a [project @ 1997-06-03 22:18:56 by jwe]
jwe
parents: 3016
diff changeset
3138 unwind_protect_bool (reading_fcn_file);
18d64612e67a [project @ 1997-06-03 22:18:56 by jwe]
jwe
parents: 3016
diff changeset
3139 unwind_protect_bool (line_editing);
4238
a5a68c0afe56 [project @ 2002-12-25 21:04:33 by jwe]
jwe
parents: 4237
diff changeset
3140 unwind_protect_str (parent_function_name);
7336
745a8299c2b5 [project @ 2007-12-28 20:56:55 by jwe]
jwe
parents: 7017
diff changeset
3141 unwind_protect_str (current_class_name);
3021
18d64612e67a [project @ 1997-06-03 22:18:56 by jwe]
jwe
parents: 3016
diff changeset
3142
8447
adab48231a03 make input_line_number work again
John W. Eaton <jwe@octave.org>
parents: 8311
diff changeset
3143 input_line_number = 1;
3021
18d64612e67a [project @ 1997-06-03 22:18:56 by jwe]
jwe
parents: 3016
diff changeset
3144 current_input_column = 1;
4238
a5a68c0afe56 [project @ 2002-12-25 21:04:33 by jwe]
jwe
parents: 4237
diff changeset
3145 end_tokens_expected = 0;
3021
18d64612e67a [project @ 1997-06-03 22:18:56 by jwe]
jwe
parents: 3016
diff changeset
3146 reading_fcn_file = true;
18d64612e67a [project @ 1997-06-03 22:18:56 by jwe]
jwe
parents: 3016
diff changeset
3147 line_editing = false;
4238
a5a68c0afe56 [project @ 2002-12-25 21:04:33 by jwe]
jwe
parents: 4237
diff changeset
3148 parent_function_name = "";
7336
745a8299c2b5 [project @ 2007-12-28 20:56:55 by jwe]
jwe
parents: 7017
diff changeset
3149 current_class_name = dispatch_type;
3021
18d64612e67a [project @ 1997-06-03 22:18:56 by jwe]
jwe
parents: 3016
diff changeset
3150
7715
5b4d278ec828 parse scripts completely before executing
John W. Eaton <jwe@octave.org>
parents: 7699
diff changeset
3151 // The next four lines must be in this order.
5b4d278ec828 parse scripts completely before executing
John W. Eaton <jwe@octave.org>
parents: 7699
diff changeset
3152 unwind_protect::add (restore_command_history, 0);
5b4d278ec828 parse scripts completely before executing
John W. Eaton <jwe@octave.org>
parents: 7699
diff changeset
3153
5b4d278ec828 parse scripts completely before executing
John W. Eaton <jwe@octave.org>
parents: 7699
diff changeset
3154 // FIXME -- we shouldn't need both the
5b4d278ec828 parse scripts completely before executing
John W. Eaton <jwe@octave.org>
parents: 7699
diff changeset
3155 // command_history object and the
5b4d278ec828 parse scripts completely before executing
John W. Eaton <jwe@octave.org>
parents: 7699
diff changeset
3156 // Vsaving_history variable...
5b4d278ec828 parse scripts completely before executing
John W. Eaton <jwe@octave.org>
parents: 7699
diff changeset
3157 command_history::ignore_entries ();
5b4d278ec828 parse scripts completely before executing
John W. Eaton <jwe@octave.org>
parents: 7699
diff changeset
3158
5b4d278ec828 parse scripts completely before executing
John W. Eaton <jwe@octave.org>
parents: 7699
diff changeset
3159 unwind_protect_bool (Vsaving_history);
5b4d278ec828 parse scripts completely before executing
John W. Eaton <jwe@octave.org>
parents: 7699
diff changeset
3160
5b4d278ec828 parse scripts completely before executing
John W. Eaton <jwe@octave.org>
parents: 7699
diff changeset
3161 Vsaving_history = false;
5b4d278ec828 parse scripts completely before executing
John W. Eaton <jwe@octave.org>
parents: 7699
diff changeset
3162
3021
18d64612e67a [project @ 1997-06-03 22:18:56 by jwe]
jwe
parents: 3016
diff changeset
3163 FILE *ffile = get_input_from_file (ff, 0);
18d64612e67a [project @ 1997-06-03 22:18:56 by jwe]
jwe
parents: 3016
diff changeset
3164
18d64612e67a [project @ 1997-06-03 22:18:56 by jwe]
jwe
parents: 3016
diff changeset
3165 unwind_protect::add (safe_fclose, ffile);
18d64612e67a [project @ 1997-06-03 22:18:56 by jwe]
jwe
parents: 3016
diff changeset
3166
18d64612e67a [project @ 1997-06-03 22:18:56 by jwe]
jwe
parents: 3016
diff changeset
3167 if (ffile)
18d64612e67a [project @ 1997-06-03 22:18:56 by jwe]
jwe
parents: 3016
diff changeset
3168 {
7720
4e2eafef689c unify comment and help text processing in lex.l and parse.y
John W. Eaton <jwe@octave.org>
parents: 7719
diff changeset
3169 bool eof;
4e2eafef689c unify comment and help text processing in lex.l and parse.y
John W. Eaton <jwe@octave.org>
parents: 7719
diff changeset
3170
4e2eafef689c unify comment and help text processing in lex.l and parse.y
John W. Eaton <jwe@octave.org>
parents: 7719
diff changeset
3171 std::string help_txt = gobble_leading_white_space (ffile, eof);
4e2eafef689c unify comment and help text processing in lex.l and parse.y
John W. Eaton <jwe@octave.org>
parents: 7719
diff changeset
3172
4e2eafef689c unify comment and help text processing in lex.l and parse.y
John W. Eaton <jwe@octave.org>
parents: 7719
diff changeset
3173 if (! eof)
3021
18d64612e67a [project @ 1997-06-03 22:18:56 by jwe]
jwe
parents: 3016
diff changeset
3174 {
7720
4e2eafef689c unify comment and help text processing in lex.l and parse.y
John W. Eaton <jwe@octave.org>
parents: 7719
diff changeset
3175 std::string file_type;
4e2eafef689c unify comment and help text processing in lex.l and parse.y
John W. Eaton <jwe@octave.org>
parents: 7719
diff changeset
3176
4e2eafef689c unify comment and help text processing in lex.l and parse.y
John W. Eaton <jwe@octave.org>
parents: 7719
diff changeset
3177 bool parsing_script = false;
4e2eafef689c unify comment and help text processing in lex.l and parse.y
John W. Eaton <jwe@octave.org>
parents: 7719
diff changeset
3178
7750
5c6c6f4803c8 make eval('script') to work again
John W. Eaton <jwe@octave.org>
parents: 7749
diff changeset
3179 unwind_protect_bool (get_input_from_eval_string);
5c6c6f4803c8 make eval('script') to work again
John W. Eaton <jwe@octave.org>
parents: 7749
diff changeset
3180 unwind_protect_bool (parser_end_of_input);
5c6c6f4803c8 make eval('script') to work again
John W. Eaton <jwe@octave.org>
parents: 7749
diff changeset
3181
5c6c6f4803c8 make eval('script') to work again
John W. Eaton <jwe@octave.org>
parents: 7749
diff changeset
3182 get_input_from_eval_string = false;
5c6c6f4803c8 make eval('script') to work again
John W. Eaton <jwe@octave.org>
parents: 7749
diff changeset
3183 parser_end_of_input = false;
5c6c6f4803c8 make eval('script') to work again
John W. Eaton <jwe@octave.org>
parents: 7749
diff changeset
3184
7720
4e2eafef689c unify comment and help text processing in lex.l and parse.y
John W. Eaton <jwe@octave.org>
parents: 7719
diff changeset
3185 if (! force_script && looking_at_function_keyword (ffile))
4e2eafef689c unify comment and help text processing in lex.l and parse.y
John W. Eaton <jwe@octave.org>
parents: 7719
diff changeset
3186 {
4e2eafef689c unify comment and help text processing in lex.l and parse.y
John W. Eaton <jwe@octave.org>
parents: 7719
diff changeset
3187 file_type = "function";
4e2eafef689c unify comment and help text processing in lex.l and parse.y
John W. Eaton <jwe@octave.org>
parents: 7719
diff changeset
3188
4e2eafef689c unify comment and help text processing in lex.l and parse.y
John W. Eaton <jwe@octave.org>
parents: 7719
diff changeset
3189 unwind_protect_int (Vecho_executing_commands);
4e2eafef689c unify comment and help text processing in lex.l and parse.y
John W. Eaton <jwe@octave.org>
parents: 7719
diff changeset
3190 unwind_protect_bool (reading_fcn_file);
4e2eafef689c unify comment and help text processing in lex.l and parse.y
John W. Eaton <jwe@octave.org>
parents: 7719
diff changeset
3191
4e2eafef689c unify comment and help text processing in lex.l and parse.y
John W. Eaton <jwe@octave.org>
parents: 7719
diff changeset
3192 Vecho_executing_commands = ECHO_OFF;
4e2eafef689c unify comment and help text processing in lex.l and parse.y
John W. Eaton <jwe@octave.org>
parents: 7719
diff changeset
3193 reading_fcn_file = true;
4e2eafef689c unify comment and help text processing in lex.l and parse.y
John W. Eaton <jwe@octave.org>
parents: 7719
diff changeset
3194 }
4e2eafef689c unify comment and help text processing in lex.l and parse.y
John W. Eaton <jwe@octave.org>
parents: 7719
diff changeset
3195 else
4e2eafef689c unify comment and help text processing in lex.l and parse.y
John W. Eaton <jwe@octave.org>
parents: 7719
diff changeset
3196 {
4e2eafef689c unify comment and help text processing in lex.l and parse.y
John W. Eaton <jwe@octave.org>
parents: 7719
diff changeset
3197 file_type = "script";
4e2eafef689c unify comment and help text processing in lex.l and parse.y
John W. Eaton <jwe@octave.org>
parents: 7719
diff changeset
3198
4e2eafef689c unify comment and help text processing in lex.l and parse.y
John W. Eaton <jwe@octave.org>
parents: 7719
diff changeset
3199 // The value of `reading_fcn_file' will be restored to the
4e2eafef689c unify comment and help text processing in lex.l and parse.y
John W. Eaton <jwe@octave.org>
parents: 7719
diff changeset
3200 // proper value when we unwind from this frame.
4e2eafef689c unify comment and help text processing in lex.l and parse.y
John W. Eaton <jwe@octave.org>
parents: 7719
diff changeset
3201 reading_fcn_file = old_reading_fcn_file_state;
4e2eafef689c unify comment and help text processing in lex.l and parse.y
John W. Eaton <jwe@octave.org>
parents: 7719
diff changeset
3202
4e2eafef689c unify comment and help text processing in lex.l and parse.y
John W. Eaton <jwe@octave.org>
parents: 7719
diff changeset
3203 unwind_protect_bool (reading_script_file);
4e2eafef689c unify comment and help text processing in lex.l and parse.y
John W. Eaton <jwe@octave.org>
parents: 7719
diff changeset
3204
4e2eafef689c unify comment and help text processing in lex.l and parse.y
John W. Eaton <jwe@octave.org>
parents: 7719
diff changeset
3205 reading_script_file = true;
4e2eafef689c unify comment and help text processing in lex.l and parse.y
John W. Eaton <jwe@octave.org>
parents: 7719
diff changeset
3206
4e2eafef689c unify comment and help text processing in lex.l and parse.y
John W. Eaton <jwe@octave.org>
parents: 7719
diff changeset
3207 parsing_script = true;
4e2eafef689c unify comment and help text processing in lex.l and parse.y
John W. Eaton <jwe@octave.org>
parents: 7719
diff changeset
3208 }
4e2eafef689c unify comment and help text processing in lex.l and parse.y
John W. Eaton <jwe@octave.org>
parents: 7719
diff changeset
3209
4e2eafef689c unify comment and help text processing in lex.l and parse.y
John W. Eaton <jwe@octave.org>
parents: 7719
diff changeset
3210 YY_BUFFER_STATE old_buf = current_buffer ();
4e2eafef689c unify comment and help text processing in lex.l and parse.y
John W. Eaton <jwe@octave.org>
parents: 7719
diff changeset
3211 YY_BUFFER_STATE new_buf = create_buffer (ffile);
4e2eafef689c unify comment and help text processing in lex.l and parse.y
John W. Eaton <jwe@octave.org>
parents: 7719
diff changeset
3212
4e2eafef689c unify comment and help text processing in lex.l and parse.y
John W. Eaton <jwe@octave.org>
parents: 7719
diff changeset
3213 unwind_protect::add (restore_input_buffer, old_buf);
4e2eafef689c unify comment and help text processing in lex.l and parse.y
John W. Eaton <jwe@octave.org>
parents: 7719
diff changeset
3214 unwind_protect::add (delete_input_buffer, new_buf);
4e2eafef689c unify comment and help text processing in lex.l and parse.y
John W. Eaton <jwe@octave.org>
parents: 7719
diff changeset
3215
4e2eafef689c unify comment and help text processing in lex.l and parse.y
John W. Eaton <jwe@octave.org>
parents: 7719
diff changeset
3216 switch_to_buffer (new_buf);
4e2eafef689c unify comment and help text processing in lex.l and parse.y
John W. Eaton <jwe@octave.org>
parents: 7719
diff changeset
3217
4e2eafef689c unify comment and help text processing in lex.l and parse.y
John W. Eaton <jwe@octave.org>
parents: 7719
diff changeset
3218 unwind_protect_ptr (curr_fcn_ptr);
4e2eafef689c unify comment and help text processing in lex.l and parse.y
John W. Eaton <jwe@octave.org>
parents: 7719
diff changeset
3219 curr_fcn_ptr = 0;
4e2eafef689c unify comment and help text processing in lex.l and parse.y
John W. Eaton <jwe@octave.org>
parents: 7719
diff changeset
3220
4e2eafef689c unify comment and help text processing in lex.l and parse.y
John W. Eaton <jwe@octave.org>
parents: 7719
diff changeset
3221 reset_parser ();
4e2eafef689c unify comment and help text processing in lex.l and parse.y
John W. Eaton <jwe@octave.org>
parents: 7719
diff changeset
3222
7723
74f5e0c7de9e first pass at handling block comments
John W. Eaton <jwe@octave.org>
parents: 7720
diff changeset
3223 if (! help_txt.empty ())
74f5e0c7de9e first pass at handling block comments
John W. Eaton <jwe@octave.org>
parents: 7720
diff changeset
3224 help_buf.push (help_txt);
74f5e0c7de9e first pass at handling block comments
John W. Eaton <jwe@octave.org>
parents: 7720
diff changeset
3225
7720
4e2eafef689c unify comment and help text processing in lex.l and parse.y
John W. Eaton <jwe@octave.org>
parents: 7719
diff changeset
3226 if (parsing_script)
4e2eafef689c unify comment and help text processing in lex.l and parse.y
John W. Eaton <jwe@octave.org>
parents: 7719
diff changeset
3227 prep_lexer_for_script ();
4e2eafef689c unify comment and help text processing in lex.l and parse.y
John W. Eaton <jwe@octave.org>
parents: 7719
diff changeset
3228
4e2eafef689c unify comment and help text processing in lex.l and parse.y
John W. Eaton <jwe@octave.org>
parents: 7719
diff changeset
3229 lexer_flags.parsing_class_method = ! dispatch_type.empty ();
4e2eafef689c unify comment and help text processing in lex.l and parse.y
John W. Eaton <jwe@octave.org>
parents: 7719
diff changeset
3230
4e2eafef689c unify comment and help text processing in lex.l and parse.y
John W. Eaton <jwe@octave.org>
parents: 7719
diff changeset
3231 int status = yyparse ();
4e2eafef689c unify comment and help text processing in lex.l and parse.y
John W. Eaton <jwe@octave.org>
parents: 7719
diff changeset
3232
4e2eafef689c unify comment and help text processing in lex.l and parse.y
John W. Eaton <jwe@octave.org>
parents: 7719
diff changeset
3233 fcn_ptr = curr_fcn_ptr;
4e2eafef689c unify comment and help text processing in lex.l and parse.y
John W. Eaton <jwe@octave.org>
parents: 7719
diff changeset
3234
4e2eafef689c unify comment and help text processing in lex.l and parse.y
John W. Eaton <jwe@octave.org>
parents: 7719
diff changeset
3235 if (status != 0)
4e2eafef689c unify comment and help text processing in lex.l and parse.y
John W. Eaton <jwe@octave.org>
parents: 7719
diff changeset
3236 error ("parse error while reading %s file %s",
4e2eafef689c unify comment and help text processing in lex.l and parse.y
John W. Eaton <jwe@octave.org>
parents: 7719
diff changeset
3237 file_type.c_str(), ff.c_str ());
3021
18d64612e67a [project @ 1997-06-03 22:18:56 by jwe]
jwe
parents: 3016
diff changeset
3238 }
18d64612e67a [project @ 1997-06-03 22:18:56 by jwe]
jwe
parents: 3016
diff changeset
3239 }
7715
5b4d278ec828 parse scripts completely before executing
John W. Eaton <jwe@octave.org>
parents: 7699
diff changeset
3240 else if (require_file)
3880
c21ae2c5840f [project @ 2002-03-26 02:23:06 by jwe]
jwe
parents: 3877
diff changeset
3241 error ("no such file, `%s'", ff.c_str ());
7715
5b4d278ec828 parse scripts completely before executing
John W. Eaton <jwe@octave.org>
parents: 7699
diff changeset
3242 else if (! warn_for.empty ())
5b4d278ec828 parse scripts completely before executing
John W. Eaton <jwe@octave.org>
parents: 7699
diff changeset
3243 error ("%s: unable to open file `%s'", warn_for.c_str (), ff.c_str ());
3021
18d64612e67a [project @ 1997-06-03 22:18:56 by jwe]
jwe
parents: 3016
diff changeset
3244
18d64612e67a [project @ 1997-06-03 22:18:56 by jwe]
jwe
parents: 3016
diff changeset
3245 unwind_protect::run_frame ("parse_fcn_file");
18d64612e67a [project @ 1997-06-03 22:18:56 by jwe]
jwe
parents: 3016
diff changeset
3246
7336
745a8299c2b5 [project @ 2007-12-28 20:56:55 by jwe]
jwe
parents: 7017
diff changeset
3247 return fcn_ptr;
3021
18d64612e67a [project @ 1997-06-03 22:18:56 by jwe]
jwe
parents: 3016
diff changeset
3248 }
18d64612e67a [project @ 1997-06-03 22:18:56 by jwe]
jwe
parents: 3016
diff changeset
3249
5484
2ff5363a16bd [project @ 2005-10-06 17:12:12 by jwe]
jwe
parents: 5472
diff changeset
3250 std::string
7715
5b4d278ec828 parse scripts completely before executing
John W. Eaton <jwe@octave.org>
parents: 7699
diff changeset
3251 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
3252 std::string& file)
5b4d278ec828 parse scripts completely before executing
John W. Eaton <jwe@octave.org>
parents: 7699
diff changeset
3253 {
5b4d278ec828 parse scripts completely before executing
John W. Eaton <jwe@octave.org>
parents: 7699
diff changeset
3254 std::string retval;
5b4d278ec828 parse scripts completely before executing
John W. Eaton <jwe@octave.org>
parents: 7699
diff changeset
3255
5b4d278ec828 parse scripts completely before executing
John W. Eaton <jwe@octave.org>
parents: 7699
diff changeset
3256 file = fcn_file_in_path (nm);
5b4d278ec828 parse scripts completely before executing
John W. Eaton <jwe@octave.org>
parents: 7699
diff changeset
3257
5b4d278ec828 parse scripts completely before executing
John W. Eaton <jwe@octave.org>
parents: 7699
diff changeset
3258 if (! file.empty ())
5b4d278ec828 parse scripts completely before executing
John W. Eaton <jwe@octave.org>
parents: 7699
diff changeset
3259 {
5b4d278ec828 parse scripts completely before executing
John W. Eaton <jwe@octave.org>
parents: 7699
diff changeset
3260 symbol_found = true;
5b4d278ec828 parse scripts completely before executing
John W. Eaton <jwe@octave.org>
parents: 7699
diff changeset
3261
5b4d278ec828 parse scripts completely before executing
John W. Eaton <jwe@octave.org>
parents: 7699
diff changeset
3262 FILE *fptr = fopen (file.c_str (), "r");
5b4d278ec828 parse scripts completely before executing
John W. Eaton <jwe@octave.org>
parents: 7699
diff changeset
3263
5b4d278ec828 parse scripts completely before executing
John W. Eaton <jwe@octave.org>
parents: 7699
diff changeset
3264 if (fptr)
5b4d278ec828 parse scripts completely before executing
John W. Eaton <jwe@octave.org>
parents: 7699
diff changeset
3265 {
5b4d278ec828 parse scripts completely before executing
John W. Eaton <jwe@octave.org>
parents: 7699
diff changeset
3266 unwind_protect::add (safe_fclose, fptr);
5b4d278ec828 parse scripts completely before executing
John W. Eaton <jwe@octave.org>
parents: 7699
diff changeset
3267
7720
4e2eafef689c unify comment and help text processing in lex.l and parse.y
John W. Eaton <jwe@octave.org>
parents: 7719
diff changeset
3268 bool eof;
4e2eafef689c unify comment and help text processing in lex.l and parse.y
John W. Eaton <jwe@octave.org>
parents: 7719
diff changeset
3269 retval = gobble_leading_white_space (fptr, eof);
7715
5b4d278ec828 parse scripts completely before executing
John W. Eaton <jwe@octave.org>
parents: 7699
diff changeset
3270
5b4d278ec828 parse scripts completely before executing
John W. Eaton <jwe@octave.org>
parents: 7699
diff changeset
3271 if (retval.empty ())
5b4d278ec828 parse scripts completely before executing
John W. Eaton <jwe@octave.org>
parents: 7699
diff changeset
3272 {
5b4d278ec828 parse scripts completely before executing
John W. Eaton <jwe@octave.org>
parents: 7699
diff changeset
3273 octave_function *fcn = parse_fcn_file (file, "");
5b4d278ec828 parse scripts completely before executing
John W. Eaton <jwe@octave.org>
parents: 7699
diff changeset
3274
5b4d278ec828 parse scripts completely before executing
John W. Eaton <jwe@octave.org>
parents: 7699
diff changeset
3275 if (fcn)
5b4d278ec828 parse scripts completely before executing
John W. Eaton <jwe@octave.org>
parents: 7699
diff changeset
3276 {
5b4d278ec828 parse scripts completely before executing
John W. Eaton <jwe@octave.org>
parents: 7699
diff changeset
3277 retval = fcn->doc_string ();
5b4d278ec828 parse scripts completely before executing
John W. Eaton <jwe@octave.org>
parents: 7699
diff changeset
3278
5b4d278ec828 parse scripts completely before executing
John W. Eaton <jwe@octave.org>
parents: 7699
diff changeset
3279 delete fcn;
5b4d278ec828 parse scripts completely before executing
John W. Eaton <jwe@octave.org>
parents: 7699
diff changeset
3280 }
5b4d278ec828 parse scripts completely before executing
John W. Eaton <jwe@octave.org>
parents: 7699
diff changeset
3281 }
5b4d278ec828 parse scripts completely before executing
John W. Eaton <jwe@octave.org>
parents: 7699
diff changeset
3282
5b4d278ec828 parse scripts completely before executing
John W. Eaton <jwe@octave.org>
parents: 7699
diff changeset
3283 unwind_protect::run ();
5b4d278ec828 parse scripts completely before executing
John W. Eaton <jwe@octave.org>
parents: 7699
diff changeset
3284 }
5b4d278ec828 parse scripts completely before executing
John W. Eaton <jwe@octave.org>
parents: 7699
diff changeset
3285 }
5b4d278ec828 parse scripts completely before executing
John W. Eaton <jwe@octave.org>
parents: 7699
diff changeset
3286
5b4d278ec828 parse scripts completely before executing
John W. Eaton <jwe@octave.org>
parents: 7699
diff changeset
3287 return retval;
5b4d278ec828 parse scripts completely before executing
John W. Eaton <jwe@octave.org>
parents: 7699
diff changeset
3288 }
5b4d278ec828 parse scripts completely before executing
John W. Eaton <jwe@octave.org>
parents: 7699
diff changeset
3289
5b4d278ec828 parse scripts completely before executing
John W. Eaton <jwe@octave.org>
parents: 7699
diff changeset
3290 std::string
5b4d278ec828 parse scripts completely before executing
John W. Eaton <jwe@octave.org>
parents: 7699
diff changeset
3291 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
3292 {
5b4d278ec828 parse scripts completely before executing
John W. Eaton <jwe@octave.org>
parents: 7699
diff changeset
3293 std::string file;
5b4d278ec828 parse scripts completely before executing
John W. Eaton <jwe@octave.org>
parents: 7699
diff changeset
3294 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
3295 }
5b4d278ec828 parse scripts completely before executing
John W. Eaton <jwe@octave.org>
parents: 7699
diff changeset
3296
5b4d278ec828 parse scripts completely before executing
John W. Eaton <jwe@octave.org>
parents: 7699
diff changeset
3297 std::string
5484
2ff5363a16bd [project @ 2005-10-06 17:12:12 by jwe]
jwe
parents: 5472
diff changeset
3298 lookup_autoload (const std::string& nm)
2ff5363a16bd [project @ 2005-10-06 17:12:12 by jwe]
jwe
parents: 5472
diff changeset
3299 {
5626
3236b4d98fde [project @ 2006-02-15 20:25:39 by jwe]
jwe
parents: 5615
diff changeset
3300 std::string retval;
3236b4d98fde [project @ 2006-02-15 20:25:39 by jwe]
jwe
parents: 5615
diff changeset
3301
3236b4d98fde [project @ 2006-02-15 20:25:39 by jwe]
jwe
parents: 5615
diff changeset
3302 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
3303
3236b4d98fde [project @ 2006-02-15 20:25:39 by jwe]
jwe
parents: 5615
diff changeset
3304 am_iter p = autoload_map.find (nm);
3236b4d98fde [project @ 2006-02-15 20:25:39 by jwe]
jwe
parents: 5615
diff changeset
3305
3236b4d98fde [project @ 2006-02-15 20:25:39 by jwe]
jwe
parents: 5615
diff changeset
3306 if (p != autoload_map.end ())
6323
ea65de49e18e [project @ 2007-02-17 02:51:02 by jwe]
jwe
parents: 6238
diff changeset
3307 retval = load_path::find_file (p->second);
5626
3236b4d98fde [project @ 2006-02-15 20:25:39 by jwe]
jwe
parents: 5615
diff changeset
3308
3236b4d98fde [project @ 2006-02-15 20:25:39 by jwe]
jwe
parents: 5615
diff changeset
3309 return retval;
5484
2ff5363a16bd [project @ 2005-10-06 17:12:12 by jwe]
jwe
parents: 5472
diff changeset
3310 }
2ff5363a16bd [project @ 2005-10-06 17:12:12 by jwe]
jwe
parents: 5472
diff changeset
3311
5592
61d6cebd243b [project @ 2006-01-12 17:55:22 by dbateman]
dbateman
parents: 5484
diff changeset
3312 string_vector
61d6cebd243b [project @ 2006-01-12 17:55:22 by dbateman]
dbateman
parents: 5484
diff changeset
3313 autoloaded_functions (void)
61d6cebd243b [project @ 2006-01-12 17:55:22 by dbateman]
dbateman
parents: 5484
diff changeset
3314 {
61d6cebd243b [project @ 2006-01-12 17:55:22 by dbateman]
dbateman
parents: 5484
diff changeset
3315 string_vector names (autoload_map.size());
61d6cebd243b [project @ 2006-01-12 17:55:22 by dbateman]
dbateman
parents: 5484
diff changeset
3316
61d6cebd243b [project @ 2006-01-12 17:55:22 by dbateman]
dbateman
parents: 5484
diff changeset
3317 octave_idx_type i = 0;
5626
3236b4d98fde [project @ 2006-02-15 20:25:39 by jwe]
jwe
parents: 5615
diff changeset
3318 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
3319 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
3320 names[i++] = p->first;
61d6cebd243b [project @ 2006-01-12 17:55:22 by dbateman]
dbateman
parents: 5484
diff changeset
3321
61d6cebd243b [project @ 2006-01-12 17:55:22 by dbateman]
dbateman
parents: 5484
diff changeset
3322 return names;
61d6cebd243b [project @ 2006-01-12 17:55:22 by dbateman]
dbateman
parents: 5484
diff changeset
3323 }
61d6cebd243b [project @ 2006-01-12 17:55:22 by dbateman]
dbateman
parents: 5484
diff changeset
3324
61d6cebd243b [project @ 2006-01-12 17:55:22 by dbateman]
dbateman
parents: 5484
diff changeset
3325 string_vector
61d6cebd243b [project @ 2006-01-12 17:55:22 by dbateman]
dbateman
parents: 5484
diff changeset
3326 reverse_lookup_autoload (const std::string& nm)
61d6cebd243b [project @ 2006-01-12 17:55:22 by dbateman]
dbateman
parents: 5484
diff changeset
3327 {
61d6cebd243b [project @ 2006-01-12 17:55:22 by dbateman]
dbateman
parents: 5484
diff changeset
3328 string_vector names;
61d6cebd243b [project @ 2006-01-12 17:55:22 by dbateman]
dbateman
parents: 5484
diff changeset
3329
5626
3236b4d98fde [project @ 2006-02-15 20:25:39 by jwe]
jwe
parents: 5615
diff changeset
3330 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
3331 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
3332 if (nm == p->second)
61d6cebd243b [project @ 2006-01-12 17:55:22 by dbateman]
dbateman
parents: 5484
diff changeset
3333 names.append (p->first);
61d6cebd243b [project @ 2006-01-12 17:55:22 by dbateman]
dbateman
parents: 5484
diff changeset
3334
61d6cebd243b [project @ 2006-01-12 17:55:22 by dbateman]
dbateman
parents: 5484
diff changeset
3335 return names;
61d6cebd243b [project @ 2006-01-12 17:55:22 by dbateman]
dbateman
parents: 5484
diff changeset
3336 }
61d6cebd243b [project @ 2006-01-12 17:55:22 by dbateman]
dbateman
parents: 5484
diff changeset
3337
7336
745a8299c2b5 [project @ 2007-12-28 20:56:55 by jwe]
jwe
parents: 7017
diff changeset
3338 octave_function *
745a8299c2b5 [project @ 2007-12-28 20:56:55 by jwe]
jwe
parents: 7017
diff changeset
3339 load_fcn_from_file (const std::string& file_name, const std::string& dir_name,
745a8299c2b5 [project @ 2007-12-28 20:56:55 by jwe]
jwe
parents: 7017
diff changeset
3340 const std::string& dispatch_type,
745a8299c2b5 [project @ 2007-12-28 20:56:55 by jwe]
jwe
parents: 7017
diff changeset
3341 const std::string& fcn_name, bool autoload)
3021
18d64612e67a [project @ 1997-06-03 22:18:56 by jwe]
jwe
parents: 3016
diff changeset
3342 {
7336
745a8299c2b5 [project @ 2007-12-28 20:56:55 by jwe]
jwe
parents: 7017
diff changeset
3343 octave_function *retval = 0;
745a8299c2b5 [project @ 2007-12-28 20:56:55 by jwe]
jwe
parents: 7017
diff changeset
3344
5484
2ff5363a16bd [project @ 2005-10-06 17:12:12 by jwe]
jwe
parents: 5472
diff changeset
3345 unwind_protect::begin_frame ("load_fcn_from_file");
2ff5363a16bd [project @ 2005-10-06 17:12:12 by jwe]
jwe
parents: 5472
diff changeset
3346
7336
745a8299c2b5 [project @ 2007-12-28 20:56:55 by jwe]
jwe
parents: 7017
diff changeset
3347 std::string nm = file_name;
6238
3ecd8d2c5654 [project @ 2007-01-10 21:13:21 by jwe]
jwe
parents: 6235
diff changeset
3348
3ecd8d2c5654 [project @ 2007-01-10 21:13:21 by jwe]
jwe
parents: 6235
diff changeset
3349 size_t nm_len = nm.length ();
5472
e2f85b298a74 [project @ 2005-09-23 21:10:36 by jwe]
jwe
parents: 5400
diff changeset
3350
e2f85b298a74 [project @ 2005-09-23 21:10:36 by jwe]
jwe
parents: 5400
diff changeset
3351 std::string file;
e2f85b298a74 [project @ 2005-09-23 21:10:36 by jwe]
jwe
parents: 5400
diff changeset
3352
6323
ea65de49e18e [project @ 2007-02-17 02:51:02 by jwe]
jwe
parents: 6238
diff changeset
3353 unwind_protect_bool (fcn_file_from_relative_lookup);
ea65de49e18e [project @ 2007-02-17 02:51:02 by jwe]
jwe
parents: 6238
diff changeset
3354
ea65de49e18e [project @ 2007-02-17 02:51:02 by jwe]
jwe
parents: 6238
diff changeset
3355 fcn_file_from_relative_lookup = false;
ea65de49e18e [project @ 2007-02-17 02:51:02 by jwe]
jwe
parents: 6238
diff changeset
3356
7336
745a8299c2b5 [project @ 2007-12-28 20:56:55 by jwe]
jwe
parents: 7017
diff changeset
3357 file = nm;
745a8299c2b5 [project @ 2007-12-28 20:56:55 by jwe]
jwe
parents: 7017
diff changeset
3358
745a8299c2b5 [project @ 2007-12-28 20:56:55 by jwe]
jwe
parents: 7017
diff changeset
3359 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
3360 || (nm_len > 4 && nm.substr (nm_len-4) == ".mex")
745a8299c2b5 [project @ 2007-12-28 20:56:55 by jwe]
jwe
parents: 7017
diff changeset
3361 || (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
3362 {
6238
3ecd8d2c5654 [project @ 2007-01-10 21:13:21 by jwe]
jwe
parents: 6235
diff changeset
3363 nm = octave_env::base_pathname (file);
3ecd8d2c5654 [project @ 2007-01-10 21:13:21 by jwe]
jwe
parents: 6235
diff changeset
3364 nm = nm.substr (0, nm.find_last_of ('.'));
5472
e2f85b298a74 [project @ 2005-09-23 21:10:36 by jwe]
jwe
parents: 5400
diff changeset
3365 }
7336
745a8299c2b5 [project @ 2007-12-28 20:56:55 by jwe]
jwe
parents: 7017
diff changeset
3366
745a8299c2b5 [project @ 2007-12-28 20:56:55 by jwe]
jwe
parents: 7017
diff changeset
3367 if (autoload)
5472
e2f85b298a74 [project @ 2005-09-23 21:10:36 by jwe]
jwe
parents: 5400
diff changeset
3368 {
7336
745a8299c2b5 [project @ 2007-12-28 20:56:55 by jwe]
jwe
parents: 7017
diff changeset
3369 unwind_protect_bool (autoloading);
745a8299c2b5 [project @ 2007-12-28 20:56:55 by jwe]
jwe
parents: 7017
diff changeset
3370 autoloading = true;
745a8299c2b5 [project @ 2007-12-28 20:56:55 by jwe]
jwe
parents: 7017
diff changeset
3371 }
745a8299c2b5 [project @ 2007-12-28 20:56:55 by jwe]
jwe
parents: 7017
diff changeset
3372
7749
14e05160b99f reference counting for functions loaded from shared libraries
John W. Eaton <jwe@octave.org>
parents: 7736
diff changeset
3373 fcn_file_from_relative_lookup = ! octave_env::absolute_pathname (file);
14e05160b99f reference counting for functions loaded from shared libraries
John W. Eaton <jwe@octave.org>
parents: 7736
diff changeset
3374
14e05160b99f reference counting for functions loaded from shared libraries
John W. Eaton <jwe@octave.org>
parents: 7736
diff changeset
3375 file = octave_env::make_absolute (file, octave_env::getcwd ());
4243
7e4d5b5520e5 [project @ 2002-12-27 05:30:59 by jwe]
jwe
parents: 4240
diff changeset
3376
7e4d5b5520e5 [project @ 2002-12-27 05:30:59 by jwe]
jwe
parents: 4240
diff changeset
3377 int len = file.length ();
7e4d5b5520e5 [project @ 2002-12-27 05:30:59 by jwe]
jwe
parents: 4240
diff changeset
3378
4244
189df16144fc [project @ 2002-12-28 02:00:05 by jwe]
jwe
parents: 4243
diff changeset
3379 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
3380 {
7336
745a8299c2b5 [project @ 2007-12-28 20:56:55 by jwe]
jwe
parents: 7017
diff changeset
3381 if (autoload && ! fcn_name.empty ())
745a8299c2b5 [project @ 2007-12-28 20:56:55 by jwe]
jwe
parents: 7017
diff changeset
3382 nm = fcn_name;
745a8299c2b5 [project @ 2007-12-28 20:56:55 by jwe]
jwe
parents: 7017
diff changeset
3383
745a8299c2b5 [project @ 2007-12-28 20:56:55 by jwe]
jwe
parents: 7017
diff changeset
3384 retval = octave_dynamic_loader::load_oct (nm, file, fcn_file_from_relative_lookup);
5864
e884ab4f29ee [project @ 2006-06-22 00:57:27 by jwe]
jwe
parents: 5861
diff changeset
3385 }
e884ab4f29ee [project @ 2006-06-22 00:57:27 by jwe]
jwe
parents: 5861
diff changeset
3386 else if (len > 4 && file.substr (len-4, len-1) == ".mex")
7336
745a8299c2b5 [project @ 2007-12-28 20:56:55 by jwe]
jwe
parents: 7017
diff changeset
3387 retval = octave_dynamic_loader::load_mex (nm, file, fcn_file_from_relative_lookup);
4244
189df16144fc [project @ 2002-12-28 02:00:05 by jwe]
jwe
parents: 4243
diff changeset
3388 else if (len > 2)
3021
18d64612e67a [project @ 1997-06-03 22:18:56 by jwe]
jwe
parents: 3016
diff changeset
3389 {
7715
5b4d278ec828 parse scripts completely before executing
John W. Eaton <jwe@octave.org>
parents: 7699
diff changeset
3390 // These are needed by yyparse.
5b4d278ec828 parse scripts completely before executing
John W. Eaton <jwe@octave.org>
parents: 7699
diff changeset
3391
5b4d278ec828 parse scripts completely before executing
John W. Eaton <jwe@octave.org>
parents: 7699
diff changeset
3392 unwind_protect_str (curr_fcn_file_name);
5b4d278ec828 parse scripts completely before executing
John W. Eaton <jwe@octave.org>
parents: 7699
diff changeset
3393 unwind_protect_str (curr_fcn_file_full_name);
5b4d278ec828 parse scripts completely before executing
John W. Eaton <jwe@octave.org>
parents: 7699
diff changeset
3394
5b4d278ec828 parse scripts completely before executing
John W. Eaton <jwe@octave.org>
parents: 7699
diff changeset
3395 curr_fcn_file_name = nm;
5b4d278ec828 parse scripts completely before executing
John W. Eaton <jwe@octave.org>
parents: 7699
diff changeset
3396 curr_fcn_file_full_name = file;
5b4d278ec828 parse scripts completely before executing
John W. Eaton <jwe@octave.org>
parents: 7699
diff changeset
3397
5b4d278ec828 parse scripts completely before executing
John W. Eaton <jwe@octave.org>
parents: 7699
diff changeset
3398 retval = parse_fcn_file (file, dispatch_type, autoloading);
3021
18d64612e67a [project @ 1997-06-03 22:18:56 by jwe]
jwe
parents: 3016
diff changeset
3399 }
18d64612e67a [project @ 1997-06-03 22:18:56 by jwe]
jwe
parents: 3016
diff changeset
3400
7336
745a8299c2b5 [project @ 2007-12-28 20:56:55 by jwe]
jwe
parents: 7017
diff changeset
3401 if (retval)
8819
96d87674b818 also stash directory name for subfunctions
John W. Eaton <jwe@octave.org>
parents: 8812
diff changeset
3402 {
96d87674b818 also stash directory name for subfunctions
John W. Eaton <jwe@octave.org>
parents: 8812
diff changeset
3403 retval->stash_dir_name (dir_name);
96d87674b818 also stash directory name for subfunctions
John W. Eaton <jwe@octave.org>
parents: 8812
diff changeset
3404
96d87674b818 also stash directory name for subfunctions
John W. Eaton <jwe@octave.org>
parents: 8812
diff changeset
3405 if (retval->is_user_function ())
96d87674b818 also stash directory name for subfunctions
John W. Eaton <jwe@octave.org>
parents: 8812
diff changeset
3406 {
96d87674b818 also stash directory name for subfunctions
John W. Eaton <jwe@octave.org>
parents: 8812
diff changeset
3407 symbol_table::scope_id id = retval->scope ();
96d87674b818 also stash directory name for subfunctions
John W. Eaton <jwe@octave.org>
parents: 8812
diff changeset
3408
96d87674b818 also stash directory name for subfunctions
John W. Eaton <jwe@octave.org>
parents: 8812
diff changeset
3409 symbol_table::stash_dir_name_for_subfunctions (id, dir_name);
96d87674b818 also stash directory name for subfunctions
John W. Eaton <jwe@octave.org>
parents: 8812
diff changeset
3410 }
96d87674b818 also stash directory name for subfunctions
John W. Eaton <jwe@octave.org>
parents: 8812
diff changeset
3411 }
7336
745a8299c2b5 [project @ 2007-12-28 20:56:55 by jwe]
jwe
parents: 7017
diff changeset
3412
5484
2ff5363a16bd [project @ 2005-10-06 17:12:12 by jwe]
jwe
parents: 5472
diff changeset
3413 unwind_protect::run_frame ("load_fcn_from_file");
2ff5363a16bd [project @ 2005-10-06 17:12:12 by jwe]
jwe
parents: 5472
diff changeset
3414
7336
745a8299c2b5 [project @ 2007-12-28 20:56:55 by jwe]
jwe
parents: 7017
diff changeset
3415 return retval;
5312
80c1aa832cb2 [project @ 2005-04-28 01:54:46 by jwe]
jwe
parents: 5309
diff changeset
3416 }
80c1aa832cb2 [project @ 2005-04-28 01:54:46 by jwe]
jwe
parents: 5309
diff changeset
3417
8746
5dd06f19e9be handle commands in the lexer
John W. Eaton <jwe@octave.org>
parents: 8745
diff changeset
3418 DEFUN (autoload, args, ,
5484
2ff5363a16bd [project @ 2005-10-06 17:12:12 by jwe]
jwe
parents: 5472
diff changeset
3419 "-*- texinfo -*-\n\
2ff5363a16bd [project @ 2005-10-06 17:12:12 by jwe]
jwe
parents: 5472
diff changeset
3420 @deftypefn {Built-in Function} {} autoload (@var{function}, @var{file})\n\
2ff5363a16bd [project @ 2005-10-06 17:12:12 by jwe]
jwe
parents: 5472
diff changeset
3421 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
3422 \n\
6926
c05fbb1b7e1f [project @ 2007-09-26 19:56:54 by dbateman]
dbateman
parents: 6657
diff changeset
3423 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
3424 a file name in the same directory as the function or script from which\n\
c05fbb1b7e1f [project @ 2007-09-26 19:56:54 by dbateman]
dbateman
parents: 6657
diff changeset
3425 the autoload command was run. @var{file} should not depend on the\n\
c05fbb1b7e1f [project @ 2007-09-26 19:56:54 by dbateman]
dbateman
parents: 6657
diff changeset
3426 Octave load path.\n\
6380
ac3d67504f85 [project @ 2007-03-02 22:08:06 by jwe]
jwe
parents: 6379
diff changeset
3427 \n\
ac3d67504f85 [project @ 2007-03-02 22:08:06 by jwe]
jwe
parents: 6379
diff changeset
3428 Normally, calls to @code{autoload} appear in PKG_ADD script files that\n\
ac3d67504f85 [project @ 2007-03-02 22:08:06 by jwe]
jwe
parents: 6379
diff changeset
3429 are evaluated when a directory is added to the Octave's load path. To\n\
6926
c05fbb1b7e1f [project @ 2007-09-26 19:56:54 by dbateman]
dbateman
parents: 6657
diff changeset
3430 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
3431 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
3432 \n\
ac3d67504f85 [project @ 2007-03-02 22:08:06 by jwe]
jwe
parents: 6379
diff changeset
3433 @example\n\
6926
c05fbb1b7e1f [project @ 2007-09-26 19:56:54 by dbateman]
dbateman
parents: 6657
diff changeset
3434 autoload (\"foo\", \"bar.oct\");\n\
6380
ac3d67504f85 [project @ 2007-03-02 22:08:06 by jwe]
jwe
parents: 6379
diff changeset
3435 @end example\n\
ac3d67504f85 [project @ 2007-03-02 22:08:06 by jwe]
jwe
parents: 6379
diff changeset
3436 \n\
6926
c05fbb1b7e1f [project @ 2007-09-26 19:56:54 by dbateman]
dbateman
parents: 6657
diff changeset
3437 will load the function @code{foo} from the file @code{bar.oct}. The above\n\
c05fbb1b7e1f [project @ 2007-09-26 19:56:54 by dbateman]
dbateman
parents: 6657
diff changeset
3438 when @code{bar.oct} is not in the same directory or uses like\n\
6380
ac3d67504f85 [project @ 2007-03-02 22:08:06 by jwe]
jwe
parents: 6379
diff changeset
3439 \n\
ac3d67504f85 [project @ 2007-03-02 22:08:06 by jwe]
jwe
parents: 6379
diff changeset
3440 @example\n\
6637
c18ed0e7ee41 [project @ 2007-05-21 19:12:46 by jwe]
jwe
parents: 6431
diff changeset
3441 autoload (\"foo\", file_in_loadpath (\"bar.oct\"))\n\
6380
ac3d67504f85 [project @ 2007-03-02 22:08:06 by jwe]
jwe
parents: 6379
diff changeset
3442 @end example\n\
ac3d67504f85 [project @ 2007-03-02 22:08:06 by jwe]
jwe
parents: 6379
diff changeset
3443 \n\
ac3d67504f85 [project @ 2007-03-02 22:08:06 by jwe]
jwe
parents: 6379
diff changeset
3444 @noindent\n\
6926
c05fbb1b7e1f [project @ 2007-09-26 19:56:54 by dbateman]
dbateman
parents: 6657
diff changeset
3445 are strongly discouraged, as their behavior might be unpredictable.\n\
6380
ac3d67504f85 [project @ 2007-03-02 22:08:06 by jwe]
jwe
parents: 6379
diff changeset
3446 \n\
6637
c18ed0e7ee41 [project @ 2007-05-21 19:12:46 by jwe]
jwe
parents: 6431
diff changeset
3447 With no arguments, return a structure containing the current autoload map.\n\
6380
ac3d67504f85 [project @ 2007-03-02 22:08:06 by jwe]
jwe
parents: 6379
diff changeset
3448 @seealso{PKG_ADD}\n\
5484
2ff5363a16bd [project @ 2005-10-06 17:12:12 by jwe]
jwe
parents: 5472
diff changeset
3449 @end deftypefn")
2ff5363a16bd [project @ 2005-10-06 17:12:12 by jwe]
jwe
parents: 5472
diff changeset
3450 {
5626
3236b4d98fde [project @ 2006-02-15 20:25:39 by jwe]
jwe
parents: 5615
diff changeset
3451 octave_value retval;
5484
2ff5363a16bd [project @ 2005-10-06 17:12:12 by jwe]
jwe
parents: 5472
diff changeset
3452
2ff5363a16bd [project @ 2005-10-06 17:12:12 by jwe]
jwe
parents: 5472
diff changeset
3453 int nargin = args.length ();
2ff5363a16bd [project @ 2005-10-06 17:12:12 by jwe]
jwe
parents: 5472
diff changeset
3454
5626
3236b4d98fde [project @ 2006-02-15 20:25:39 by jwe]
jwe
parents: 5615
diff changeset
3455 if (nargin == 0)
3236b4d98fde [project @ 2006-02-15 20:25:39 by jwe]
jwe
parents: 5615
diff changeset
3456 {
3236b4d98fde [project @ 2006-02-15 20:25:39 by jwe]
jwe
parents: 5615
diff changeset
3457 Cell func_names (dim_vector (autoload_map.size ()), 1);
3236b4d98fde [project @ 2006-02-15 20:25:39 by jwe]
jwe
parents: 5615
diff changeset
3458 Cell file_names (dim_vector (autoload_map.size ()), 1);
3236b4d98fde [project @ 2006-02-15 20:25:39 by jwe]
jwe
parents: 5615
diff changeset
3459
3236b4d98fde [project @ 2006-02-15 20:25:39 by jwe]
jwe
parents: 5615
diff changeset
3460 octave_idx_type i = 0;
3236b4d98fde [project @ 2006-02-15 20:25:39 by jwe]
jwe
parents: 5615
diff changeset
3461 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
3462 for (am_iter p = autoload_map.begin (); p != autoload_map.end (); p++)
3236b4d98fde [project @ 2006-02-15 20:25:39 by jwe]
jwe
parents: 5615
diff changeset
3463 {
3236b4d98fde [project @ 2006-02-15 20:25:39 by jwe]
jwe
parents: 5615
diff changeset
3464 func_names(i) = p->first;
3236b4d98fde [project @ 2006-02-15 20:25:39 by jwe]
jwe
parents: 5615
diff changeset
3465 file_names(i) = p->second;
3236b4d98fde [project @ 2006-02-15 20:25:39 by jwe]
jwe
parents: 5615
diff changeset
3466
3236b4d98fde [project @ 2006-02-15 20:25:39 by jwe]
jwe
parents: 5615
diff changeset
3467 i++;
3236b4d98fde [project @ 2006-02-15 20:25:39 by jwe]
jwe
parents: 5615
diff changeset
3468 }
3236b4d98fde [project @ 2006-02-15 20:25:39 by jwe]
jwe
parents: 5615
diff changeset
3469
3236b4d98fde [project @ 2006-02-15 20:25:39 by jwe]
jwe
parents: 5615
diff changeset
3470 Octave_map m;
3236b4d98fde [project @ 2006-02-15 20:25:39 by jwe]
jwe
parents: 5615
diff changeset
3471
3236b4d98fde [project @ 2006-02-15 20:25:39 by jwe]
jwe
parents: 5615
diff changeset
3472 m.assign ("function", func_names);
3236b4d98fde [project @ 2006-02-15 20:25:39 by jwe]
jwe
parents: 5615
diff changeset
3473 m.assign ("file", file_names);
3236b4d98fde [project @ 2006-02-15 20:25:39 by jwe]
jwe
parents: 5615
diff changeset
3474
3236b4d98fde [project @ 2006-02-15 20:25:39 by jwe]
jwe
parents: 5615
diff changeset
3475 retval = m;
3236b4d98fde [project @ 2006-02-15 20:25:39 by jwe]
jwe
parents: 5615
diff changeset
3476 }
3236b4d98fde [project @ 2006-02-15 20:25:39 by jwe]
jwe
parents: 5615
diff changeset
3477 else if (nargin == 2)
5484
2ff5363a16bd [project @ 2005-10-06 17:12:12 by jwe]
jwe
parents: 5472
diff changeset
3478 {
2ff5363a16bd [project @ 2005-10-06 17:12:12 by jwe]
jwe
parents: 5472
diff changeset
3479 string_vector argv = args.make_argv ("autoload");
2ff5363a16bd [project @ 2005-10-06 17:12:12 by jwe]
jwe
parents: 5472
diff changeset
3480
2ff5363a16bd [project @ 2005-10-06 17:12:12 by jwe]
jwe
parents: 5472
diff changeset
3481 if (! error_state)
6380
ac3d67504f85 [project @ 2007-03-02 22:08:06 by jwe]
jwe
parents: 6379
diff changeset
3482 {
ac3d67504f85 [project @ 2007-03-02 22:08:06 by jwe]
jwe
parents: 6379
diff changeset
3483 std::string nm = argv[2];
ac3d67504f85 [project @ 2007-03-02 22:08:06 by jwe]
jwe
parents: 6379
diff changeset
3484
ac3d67504f85 [project @ 2007-03-02 22:08:06 by jwe]
jwe
parents: 6379
diff changeset
3485 if (! octave_env::absolute_pathname (nm))
6926
c05fbb1b7e1f [project @ 2007-09-26 19:56:54 by dbateman]
dbateman
parents: 6657
diff changeset
3486 {
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
3487 octave_user_code *fcn = octave_call_stack::caller_user_code ();
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
3488
6926
c05fbb1b7e1f [project @ 2007-09-26 19:56:54 by dbateman]
dbateman
parents: 6657
diff changeset
3489 bool found = false;
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
3490
6926
c05fbb1b7e1f [project @ 2007-09-26 19:56:54 by dbateman]
dbateman
parents: 6657
diff changeset
3491 if (fcn)
c05fbb1b7e1f [project @ 2007-09-26 19:56:54 by dbateman]
dbateman
parents: 6657
diff changeset
3492 {
c05fbb1b7e1f [project @ 2007-09-26 19:56:54 by dbateman]
dbateman
parents: 6657
diff changeset
3493 std::string fname = fcn->fcn_file_name ();
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
3494
6926
c05fbb1b7e1f [project @ 2007-09-26 19:56:54 by dbateman]
dbateman
parents: 6657
diff changeset
3495 if (! fname.empty ())
c05fbb1b7e1f [project @ 2007-09-26 19:56:54 by dbateman]
dbateman
parents: 6657
diff changeset
3496 {
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
3497 fname = octave_env::make_absolute (fname, octave_env::getcwd ());
8007
a2ab20ba78f7 make file_ops a proper singleton class
John W. Eaton <jwe@octave.org>
parents: 8001
diff changeset
3498 fname = fname.substr (0, fname.find_last_of (file_ops::dir_sep_str ()) + 1);
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
3499
6926
c05fbb1b7e1f [project @ 2007-09-26 19:56:54 by dbateman]
dbateman
parents: 6657
diff changeset
3500 file_stat fs (fname + nm);
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
3501
6926
c05fbb1b7e1f [project @ 2007-09-26 19:56:54 by dbateman]
dbateman
parents: 6657
diff changeset
3502 if (fs.exists ())
c05fbb1b7e1f [project @ 2007-09-26 19:56:54 by dbateman]
dbateman
parents: 6657
diff changeset
3503 {
c05fbb1b7e1f [project @ 2007-09-26 19:56:54 by dbateman]
dbateman
parents: 6657
diff changeset
3504 nm = fname + nm;
c05fbb1b7e1f [project @ 2007-09-26 19:56:54 by dbateman]
dbateman
parents: 6657
diff changeset
3505 found = true;
c05fbb1b7e1f [project @ 2007-09-26 19:56:54 by dbateman]
dbateman
parents: 6657
diff changeset
3506 }
c05fbb1b7e1f [project @ 2007-09-26 19:56:54 by dbateman]
dbateman
parents: 6657
diff changeset
3507 }
c05fbb1b7e1f [project @ 2007-09-26 19:56:54 by dbateman]
dbateman
parents: 6657
diff changeset
3508 }
c05fbb1b7e1f [project @ 2007-09-26 19:56:54 by dbateman]
dbateman
parents: 6657
diff changeset
3509 if (! found)
c05fbb1b7e1f [project @ 2007-09-26 19:56:54 by dbateman]
dbateman
parents: 6657
diff changeset
3510 warning_with_id ("Octave:autoload-relative-file-name",
c05fbb1b7e1f [project @ 2007-09-26 19:56:54 by dbateman]
dbateman
parents: 6657
diff changeset
3511 "autoload: `%s' is not an absolute file name",
c05fbb1b7e1f [project @ 2007-09-26 19:56:54 by dbateman]
dbateman
parents: 6657
diff changeset
3512 nm.c_str ());
c05fbb1b7e1f [project @ 2007-09-26 19:56:54 by dbateman]
dbateman
parents: 6657
diff changeset
3513 }
6380
ac3d67504f85 [project @ 2007-03-02 22:08:06 by jwe]
jwe
parents: 6379
diff changeset
3514 autoload_map[argv[1]] = nm;
ac3d67504f85 [project @ 2007-03-02 22:08:06 by jwe]
jwe
parents: 6379
diff changeset
3515 }
5484
2ff5363a16bd [project @ 2005-10-06 17:12:12 by jwe]
jwe
parents: 5472
diff changeset
3516 }
2ff5363a16bd [project @ 2005-10-06 17:12:12 by jwe]
jwe
parents: 5472
diff changeset
3517 else
5823
080c08b192d8 [project @ 2006-05-19 05:32:17 by jwe]
jwe
parents: 5794
diff changeset
3518 print_usage ();
5484
2ff5363a16bd [project @ 2005-10-06 17:12:12 by jwe]
jwe
parents: 5472
diff changeset
3519
2ff5363a16bd [project @ 2005-10-06 17:12:12 by jwe]
jwe
parents: 5472
diff changeset
3520 return retval;
2ff5363a16bd [project @ 2005-10-06 17:12:12 by jwe]
jwe
parents: 5472
diff changeset
3521 }
2ff5363a16bd [project @ 2005-10-06 17:12:12 by jwe]
jwe
parents: 5472
diff changeset
3522
4486
6ceba1f351fb [project @ 2003-08-22 16:49:46 by jwe]
jwe
parents: 4463
diff changeset
3523 void
7715
5b4d278ec828 parse scripts completely before executing
John W. Eaton <jwe@octave.org>
parents: 7699
diff changeset
3524 source_file (const std::string& file_name, const std::string& context,
5b4d278ec828 parse scripts completely before executing
John W. Eaton <jwe@octave.org>
parents: 7699
diff changeset
3525 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
3526 {
6ceba1f351fb [project @ 2003-08-22 16:49:46 by jwe]
jwe
parents: 4463
diff changeset
3527 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
3528
6ceba1f351fb [project @ 2003-08-22 16:49:46 by jwe]
jwe
parents: 4463
diff changeset
3529 unwind_protect::begin_frame ("source_file");
6ceba1f351fb [project @ 2003-08-22 16:49:46 by jwe]
jwe
parents: 4463
diff changeset
3530
6ceba1f351fb [project @ 2003-08-22 16:49:46 by jwe]
jwe
parents: 4463
diff changeset
3531 unwind_protect_str (curr_fcn_file_name);
6ceba1f351fb [project @ 2003-08-22 16:49:46 by jwe]
jwe
parents: 4463
diff changeset
3532 unwind_protect_str (curr_fcn_file_full_name);
6ceba1f351fb [project @ 2003-08-22 16:49:46 by jwe]
jwe
parents: 4463
diff changeset
3533
6ceba1f351fb [project @ 2003-08-22 16:49:46 by jwe]
jwe
parents: 4463
diff changeset
3534 curr_fcn_file_name = file_name;
6ceba1f351fb [project @ 2003-08-22 16:49:46 by jwe]
jwe
parents: 4463
diff changeset
3535 curr_fcn_file_full_name = file_full_name;
6ceba1f351fb [project @ 2003-08-22 16:49:46 by jwe]
jwe
parents: 4463
diff changeset
3536
5975
e64059303a6f [project @ 2006-08-29 16:37:39 by jwe]
jwe
parents: 5932
diff changeset
3537 if (! context.empty ())
e64059303a6f [project @ 2006-08-29 16:37:39 by jwe]
jwe
parents: 5932
diff changeset
3538 {
e64059303a6f [project @ 2006-08-29 16:37:39 by jwe]
jwe
parents: 5932
diff changeset
3539 if (context == "caller")
7901
3e4c9b69069d call stack changes
John W. Eaton <jwe@octave.org>
parents: 7800
diff changeset
3540 octave_call_stack::goto_caller_frame ();
5975
e64059303a6f [project @ 2006-08-29 16:37:39 by jwe]
jwe
parents: 5932
diff changeset
3541 else if (context == "base")
7901
3e4c9b69069d call stack changes
John W. Eaton <jwe@octave.org>
parents: 7800
diff changeset
3542 octave_call_stack::goto_base_frame ();
5975
e64059303a6f [project @ 2006-08-29 16:37:39 by jwe]
jwe
parents: 5932
diff changeset
3543 else
e64059303a6f [project @ 2006-08-29 16:37:39 by jwe]
jwe
parents: 5932
diff changeset
3544 error ("source: context must be \"caller\" or \"base\"");
7336
745a8299c2b5 [project @ 2007-12-28 20:56:55 by jwe]
jwe
parents: 7017
diff changeset
3545
745a8299c2b5 [project @ 2007-12-28 20:56:55 by jwe]
jwe
parents: 7017
diff changeset
3546 if (! error_state)
7901
3e4c9b69069d call stack changes
John W. Eaton <jwe@octave.org>
parents: 7800
diff changeset
3547 unwind_protect::add (octave_call_stack::unwind_pop);
5975
e64059303a6f [project @ 2006-08-29 16:37:39 by jwe]
jwe
parents: 5932
diff changeset
3548 }
e64059303a6f [project @ 2006-08-29 16:37:39 by jwe]
jwe
parents: 5932
diff changeset
3549
e64059303a6f [project @ 2006-08-29 16:37:39 by jwe]
jwe
parents: 5932
diff changeset
3550 if (! error_state)
e64059303a6f [project @ 2006-08-29 16:37:39 by jwe]
jwe
parents: 5932
diff changeset
3551 {
7715
5b4d278ec828 parse scripts completely before executing
John W. Eaton <jwe@octave.org>
parents: 7699
diff changeset
3552 octave_function *fcn = parse_fcn_file (file_full_name, "", true,
5b4d278ec828 parse scripts completely before executing
John W. Eaton <jwe@octave.org>
parents: 7699
diff changeset
3553 require_file, warn_for);
5b4d278ec828 parse scripts completely before executing
John W. Eaton <jwe@octave.org>
parents: 7699
diff changeset
3554
5b4d278ec828 parse scripts completely before executing
John W. Eaton <jwe@octave.org>
parents: 7699
diff changeset
3555 if (! error_state)
5b4d278ec828 parse scripts completely before executing
John W. Eaton <jwe@octave.org>
parents: 7699
diff changeset
3556 {
5b4d278ec828 parse scripts completely before executing
John W. Eaton <jwe@octave.org>
parents: 7699
diff changeset
3557 if (fcn && fcn->is_user_script ())
5b4d278ec828 parse scripts completely before executing
John W. Eaton <jwe@octave.org>
parents: 7699
diff changeset
3558 {
5b4d278ec828 parse scripts completely before executing
John W. Eaton <jwe@octave.org>
parents: 7699
diff changeset
3559 octave_value_list args;
5b4d278ec828 parse scripts completely before executing
John W. Eaton <jwe@octave.org>
parents: 7699
diff changeset
3560
5b4d278ec828 parse scripts completely before executing
John W. Eaton <jwe@octave.org>
parents: 7699
diff changeset
3561 if (verbose)
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 std::cout << "executing commands from " << file_full_name << " ... ";
5b4d278ec828 parse scripts completely before executing
John W. Eaton <jwe@octave.org>
parents: 7699
diff changeset
3564 reading_startup_message_printed = true;
5b4d278ec828 parse scripts completely before executing
John W. Eaton <jwe@octave.org>
parents: 7699
diff changeset
3565 std::cout.flush ();
5b4d278ec828 parse scripts completely before executing
John W. Eaton <jwe@octave.org>
parents: 7699
diff changeset
3566 }
5b4d278ec828 parse scripts completely before executing
John W. Eaton <jwe@octave.org>
parents: 7699
diff changeset
3567
5b4d278ec828 parse scripts completely before executing
John W. Eaton <jwe@octave.org>
parents: 7699
diff changeset
3568 fcn->do_multi_index_op (0, args);
5b4d278ec828 parse scripts completely before executing
John W. Eaton <jwe@octave.org>
parents: 7699
diff changeset
3569
5b4d278ec828 parse scripts completely before executing
John W. Eaton <jwe@octave.org>
parents: 7699
diff changeset
3570 if (verbose)
5b4d278ec828 parse scripts completely before executing
John W. Eaton <jwe@octave.org>
parents: 7699
diff changeset
3571 std::cout << "done." << std::endl;
5b4d278ec828 parse scripts completely before executing
John W. Eaton <jwe@octave.org>
parents: 7699
diff changeset
3572
5b4d278ec828 parse scripts completely before executing
John W. Eaton <jwe@octave.org>
parents: 7699
diff changeset
3573 delete fcn;
5b4d278ec828 parse scripts completely before executing
John W. Eaton <jwe@octave.org>
parents: 7699
diff changeset
3574 }
5b4d278ec828 parse scripts completely before executing
John W. Eaton <jwe@octave.org>
parents: 7699
diff changeset
3575 }
5b4d278ec828 parse scripts completely before executing
John W. Eaton <jwe@octave.org>
parents: 7699
diff changeset
3576 else
5975
e64059303a6f [project @ 2006-08-29 16:37:39 by jwe]
jwe
parents: 5932
diff changeset
3577 error ("source: error sourcing file `%s'",
e64059303a6f [project @ 2006-08-29 16:37:39 by jwe]
jwe
parents: 5932
diff changeset
3578 file_full_name.c_str ());
e64059303a6f [project @ 2006-08-29 16:37:39 by jwe]
jwe
parents: 5932
diff changeset
3579 }
4486
6ceba1f351fb [project @ 2003-08-22 16:49:46 by jwe]
jwe
parents: 4463
diff changeset
3580
6ceba1f351fb [project @ 2003-08-22 16:49:46 by jwe]
jwe
parents: 4463
diff changeset
3581 unwind_protect::run_frame ("source_file");
6ceba1f351fb [project @ 2003-08-22 16:49:46 by jwe]
jwe
parents: 4463
diff changeset
3582 }
6ceba1f351fb [project @ 2003-08-22 16:49:46 by jwe]
jwe
parents: 4463
diff changeset
3583
5739
d090d39bb82c [project @ 2006-04-05 06:56:24 by jwe]
jwe
parents: 5667
diff changeset
3584 DEFUN (mfilename, args, ,
d090d39bb82c [project @ 2006-04-05 06:56:24 by jwe]
jwe
parents: 5667
diff changeset
3585 "-*- texinfo -*-\n\
d090d39bb82c [project @ 2006-04-05 06:56:24 by jwe]
jwe
parents: 5667
diff changeset
3586 @deftypefn {Built-in Function} {} mfilename ()\n\
d090d39bb82c [project @ 2006-04-05 06:56:24 by jwe]
jwe
parents: 5667
diff changeset
3587 @deftypefnx {Built-in Function} {} mfilename (@code{\"fullpath\"})\n\
d090d39bb82c [project @ 2006-04-05 06:56:24 by jwe]
jwe
parents: 5667
diff changeset
3588 @deftypefnx {Built-in Function} {} mfilename (@code{\"fullpathext\"})\n\
d090d39bb82c [project @ 2006-04-05 06:56:24 by jwe]
jwe
parents: 5667
diff changeset
3589 Return the name of the currently executing file. At the top-level,\n\
d090d39bb82c [project @ 2006-04-05 06:56:24 by jwe]
jwe
parents: 5667
diff changeset
3590 return the empty string. Given the argument @code{\"fullpath\"},\n\
d090d39bb82c [project @ 2006-04-05 06:56:24 by jwe]
jwe
parents: 5667
diff changeset
3591 include the directory part of the file name, but not the extension.\n\
d090d39bb82c [project @ 2006-04-05 06:56:24 by jwe]
jwe
parents: 5667
diff changeset
3592 Given the argument @code{\"fullpathext\"}, include the directory part\n\
d090d39bb82c [project @ 2006-04-05 06:56:24 by jwe]
jwe
parents: 5667
diff changeset
3593 of the file name and the extension.\n\
5774
e7af222e98b0 [project @ 2006-04-24 17:45:31 by jwe]
jwe
parents: 5765
diff changeset
3594 @end deftypefn")
5739
d090d39bb82c [project @ 2006-04-05 06:56:24 by jwe]
jwe
parents: 5667
diff changeset
3595 {
d090d39bb82c [project @ 2006-04-05 06:56:24 by jwe]
jwe
parents: 5667
diff changeset
3596 octave_value retval;
d090d39bb82c [project @ 2006-04-05 06:56:24 by jwe]
jwe
parents: 5667
diff changeset
3597
d090d39bb82c [project @ 2006-04-05 06:56:24 by jwe]
jwe
parents: 5667
diff changeset
3598 int nargin = args.length ();
d090d39bb82c [project @ 2006-04-05 06:56:24 by jwe]
jwe
parents: 5667
diff changeset
3599
d090d39bb82c [project @ 2006-04-05 06:56:24 by jwe]
jwe
parents: 5667
diff changeset
3600 if (nargin > 1)
d090d39bb82c [project @ 2006-04-05 06:56:24 by jwe]
jwe
parents: 5667
diff changeset
3601 {
5823
080c08b192d8 [project @ 2006-05-19 05:32:17 by jwe]
jwe
parents: 5794
diff changeset
3602 print_usage ();
5739
d090d39bb82c [project @ 2006-04-05 06:56:24 by jwe]
jwe
parents: 5667
diff changeset
3603 return retval;
d090d39bb82c [project @ 2006-04-05 06:56:24 by jwe]
jwe
parents: 5667
diff changeset
3604 }
d090d39bb82c [project @ 2006-04-05 06:56:24 by jwe]
jwe
parents: 5667
diff changeset
3605
d090d39bb82c [project @ 2006-04-05 06:56:24 by jwe]
jwe
parents: 5667
diff changeset
3606 std::string arg;
d090d39bb82c [project @ 2006-04-05 06:56:24 by jwe]
jwe
parents: 5667
diff changeset
3607
d090d39bb82c [project @ 2006-04-05 06:56:24 by jwe]
jwe
parents: 5667
diff changeset
3608 if (nargin == 1)
d090d39bb82c [project @ 2006-04-05 06:56:24 by jwe]
jwe
parents: 5667
diff changeset
3609 {
d090d39bb82c [project @ 2006-04-05 06:56:24 by jwe]
jwe
parents: 5667
diff changeset
3610 arg = args(0).string_value ();
d090d39bb82c [project @ 2006-04-05 06:56:24 by jwe]
jwe
parents: 5667
diff changeset
3611
d090d39bb82c [project @ 2006-04-05 06:56:24 by jwe]
jwe
parents: 5667
diff changeset
3612 if (error_state)
d090d39bb82c [project @ 2006-04-05 06:56:24 by jwe]
jwe
parents: 5667
diff changeset
3613 {
d090d39bb82c [project @ 2006-04-05 06:56:24 by jwe]
jwe
parents: 5667
diff changeset
3614 error ("mfilename: expecting argument to be a character string");
d090d39bb82c [project @ 2006-04-05 06:56:24 by jwe]
jwe
parents: 5667
diff changeset
3615 return retval;
d090d39bb82c [project @ 2006-04-05 06:56:24 by jwe]
jwe
parents: 5667
diff changeset
3616 }
d090d39bb82c [project @ 2006-04-05 06:56:24 by jwe]
jwe
parents: 5667
diff changeset
3617 }
d090d39bb82c [project @ 2006-04-05 06:56:24 by jwe]
jwe
parents: 5667
diff changeset
3618
d090d39bb82c [project @ 2006-04-05 06:56:24 by jwe]
jwe
parents: 5667
diff changeset
3619 std::string fname;
d090d39bb82c [project @ 2006-04-05 06:56:24 by jwe]
jwe
parents: 5667
diff changeset
3620
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
3621 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
3622
a527e0f77aa5 [project @ 2006-04-06 08:20:21 by jwe]
jwe
parents: 5739
diff changeset
3623 if (fcn)
a527e0f77aa5 [project @ 2006-04-06 08:20:21 by jwe]
jwe
parents: 5739
diff changeset
3624 {
a527e0f77aa5 [project @ 2006-04-06 08:20:21 by jwe]
jwe
parents: 5739
diff changeset
3625 fname = fcn->fcn_file_name ();
a527e0f77aa5 [project @ 2006-04-06 08:20:21 by jwe]
jwe
parents: 5739
diff changeset
3626
a527e0f77aa5 [project @ 2006-04-06 08:20:21 by jwe]
jwe
parents: 5739
diff changeset
3627 if (fname.empty ())
a527e0f77aa5 [project @ 2006-04-06 08:20:21 by jwe]
jwe
parents: 5739
diff changeset
3628 fname = fcn->name ();
a527e0f77aa5 [project @ 2006-04-06 08:20:21 by jwe]
jwe
parents: 5739
diff changeset
3629 }
5739
d090d39bb82c [project @ 2006-04-05 06:56:24 by jwe]
jwe
parents: 5667
diff changeset
3630
d090d39bb82c [project @ 2006-04-05 06:56:24 by jwe]
jwe
parents: 5667
diff changeset
3631 if (arg == "fullpathext")
d090d39bb82c [project @ 2006-04-05 06:56:24 by jwe]
jwe
parents: 5667
diff changeset
3632 retval = fname;
d090d39bb82c [project @ 2006-04-05 06:56:24 by jwe]
jwe
parents: 5667
diff changeset
3633 else
d090d39bb82c [project @ 2006-04-05 06:56:24 by jwe]
jwe
parents: 5667
diff changeset
3634 {
8007
a2ab20ba78f7 make file_ops a proper singleton class
John W. Eaton <jwe@octave.org>
parents: 8001
diff changeset
3635 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
3636 size_t epos = fname.rfind ('.');
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5744
diff changeset
3637
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5744
diff changeset
3638 if (epos <= dpos)
8021
85184151822e fix typo in NPOS change
John W. Eaton <jwe@octave.org>
parents: 8019
diff changeset
3639 epos = std::string::npos;
85184151822e fix typo in NPOS change
John W. Eaton <jwe@octave.org>
parents: 8019
diff changeset
3640
85184151822e fix typo in NPOS change
John W. Eaton <jwe@octave.org>
parents: 8019
diff changeset
3641 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
3642
d090d39bb82c [project @ 2006-04-05 06:56:24 by jwe]
jwe
parents: 5667
diff changeset
3643 if (arg == "fullpath")
d090d39bb82c [project @ 2006-04-05 06:56:24 by jwe]
jwe
parents: 5667
diff changeset
3644 retval = fname;
d090d39bb82c [project @ 2006-04-05 06:56:24 by jwe]
jwe
parents: 5667
diff changeset
3645 else
8021
85184151822e fix typo in NPOS change
John W. Eaton <jwe@octave.org>
parents: 8019
diff changeset
3646 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
3647 }
d090d39bb82c [project @ 2006-04-05 06:56:24 by jwe]
jwe
parents: 5667
diff changeset
3648
d090d39bb82c [project @ 2006-04-05 06:56:24 by jwe]
jwe
parents: 5667
diff changeset
3649 return retval;
d090d39bb82c [project @ 2006-04-05 06:56:24 by jwe]
jwe
parents: 5667
diff changeset
3650 }
d090d39bb82c [project @ 2006-04-05 06:56:24 by jwe]
jwe
parents: 5667
diff changeset
3651
d090d39bb82c [project @ 2006-04-05 06:56:24 by jwe]
jwe
parents: 5667
diff changeset
3652
3021
18d64612e67a [project @ 1997-06-03 22:18:56 by jwe]
jwe
parents: 3016
diff changeset
3653 DEFUN (source, args, ,
3371
86873384cd10 [project @ 1999-11-21 17:31:07 by jwe]
jwe
parents: 3366
diff changeset
3654 "-*- texinfo -*-\n\
86873384cd10 [project @ 1999-11-21 17:31:07 by jwe]
jwe
parents: 3366
diff changeset
3655 @deftypefn {Built-in Function} {} source (@var{file})\n\
86873384cd10 [project @ 1999-11-21 17:31:07 by jwe]
jwe
parents: 3366
diff changeset
3656 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
3657 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
3658 be named @file{@var{file}.m}.\n\
86873384cd10 [project @ 1999-11-21 17:31:07 by jwe]
jwe
parents: 3366
diff changeset
3659 @end deftypefn")
3021
18d64612e67a [project @ 1997-06-03 22:18:56 by jwe]
jwe
parents: 3016
diff changeset
3660 {
18d64612e67a [project @ 1997-06-03 22:18:56 by jwe]
jwe
parents: 3016
diff changeset
3661 octave_value_list retval;
18d64612e67a [project @ 1997-06-03 22:18:56 by jwe]
jwe
parents: 3016
diff changeset
3662
18d64612e67a [project @ 1997-06-03 22:18:56 by jwe]
jwe
parents: 3016
diff changeset
3663 int nargin = args.length ();
18d64612e67a [project @ 1997-06-03 22:18:56 by jwe]
jwe
parents: 3016
diff changeset
3664
5975
e64059303a6f [project @ 2006-08-29 16:37:39 by jwe]
jwe
parents: 5932
diff changeset
3665 if (nargin == 1 || nargin == 2)
3021
18d64612e67a [project @ 1997-06-03 22:18:56 by jwe]
jwe
parents: 3016
diff changeset
3666 {
3523
b80bbb43a1a9 [project @ 2000-02-02 10:25:52 by jwe]
jwe
parents: 3489
diff changeset
3667 std::string file_name = args(0).string_value ();
3021
18d64612e67a [project @ 1997-06-03 22:18:56 by jwe]
jwe
parents: 3016
diff changeset
3668
18d64612e67a [project @ 1997-06-03 22:18:56 by jwe]
jwe
parents: 3016
diff changeset
3669 if (! error_state)
5975
e64059303a6f [project @ 2006-08-29 16:37:39 by jwe]
jwe
parents: 5932
diff changeset
3670 {
e64059303a6f [project @ 2006-08-29 16:37:39 by jwe]
jwe
parents: 5932
diff changeset
3671 std::string context;
e64059303a6f [project @ 2006-08-29 16:37:39 by jwe]
jwe
parents: 5932
diff changeset
3672
e64059303a6f [project @ 2006-08-29 16:37:39 by jwe]
jwe
parents: 5932
diff changeset
3673 if (nargin == 2)
e64059303a6f [project @ 2006-08-29 16:37:39 by jwe]
jwe
parents: 5932
diff changeset
3674 context = args(1).string_value ();
e64059303a6f [project @ 2006-08-29 16:37:39 by jwe]
jwe
parents: 5932
diff changeset
3675
e64059303a6f [project @ 2006-08-29 16:37:39 by jwe]
jwe
parents: 5932
diff changeset
3676 if (! error_state)
e64059303a6f [project @ 2006-08-29 16:37:39 by jwe]
jwe
parents: 5932
diff changeset
3677 source_file (file_name, context);
e64059303a6f [project @ 2006-08-29 16:37:39 by jwe]
jwe
parents: 5932
diff changeset
3678 else
e64059303a6f [project @ 2006-08-29 16:37:39 by jwe]
jwe
parents: 5932
diff changeset
3679 error ("source: expecting context to be character string");
e64059303a6f [project @ 2006-08-29 16:37:39 by jwe]
jwe
parents: 5932
diff changeset
3680 }
3021
18d64612e67a [project @ 1997-06-03 22:18:56 by jwe]
jwe
parents: 3016
diff changeset
3681 else
18d64612e67a [project @ 1997-06-03 22:18:56 by jwe]
jwe
parents: 3016
diff changeset
3682 error ("source: expecting file name as argument");
18d64612e67a [project @ 1997-06-03 22:18:56 by jwe]
jwe
parents: 3016
diff changeset
3683 }
18d64612e67a [project @ 1997-06-03 22:18:56 by jwe]
jwe
parents: 3016
diff changeset
3684 else
5823
080c08b192d8 [project @ 2006-05-19 05:32:17 by jwe]
jwe
parents: 5794
diff changeset
3685 print_usage ();
3021
18d64612e67a [project @ 1997-06-03 22:18:56 by jwe]
jwe
parents: 3016
diff changeset
3686
18d64612e67a [project @ 1997-06-03 22:18:56 by jwe]
jwe
parents: 3016
diff changeset
3687 return retval;
18d64612e67a [project @ 1997-06-03 22:18:56 by jwe]
jwe
parents: 3016
diff changeset
3688 }
18d64612e67a [project @ 1997-06-03 22:18:56 by jwe]
jwe
parents: 3016
diff changeset
3689
3726
b7d997d593d9 [project @ 2000-10-27 17:51:21 by jwe]
jwe
parents: 3712
diff changeset
3690 // 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
3691 // 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
3692 // call. ARGS are the arguments to the function. NARGOUT is the
87f85453b6b7 [project @ 2001-07-23 20:07:45 by jwe]
jwe
parents: 3815
diff changeset
3693 // number of output arguments expected.
3726
b7d997d593d9 [project @ 2000-10-27 17:51:21 by jwe]
jwe
parents: 3712
diff changeset
3694
3021
18d64612e67a [project @ 1997-06-03 22:18:56 by jwe]
jwe
parents: 3016
diff changeset
3695 octave_value_list
3523
b80bbb43a1a9 [project @ 2000-02-02 10:25:52 by jwe]
jwe
parents: 3489
diff changeset
3696 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
3697 {
a494f93e60ff [project @ 1998-02-20 07:47:48 by jwe]
jwe
parents: 3110
diff changeset
3698 octave_value_list retval;
a494f93e60ff [project @ 1998-02-20 07:47:48 by jwe]
jwe
parents: 3110
diff changeset
3699
7336
745a8299c2b5 [project @ 2007-12-28 20:56:55 by jwe]
jwe
parents: 7017
diff changeset
3700 octave_value fcn = symbol_table::find_function (name, args);
745a8299c2b5 [project @ 2007-12-28 20:56:55 by jwe]
jwe
parents: 7017
diff changeset
3701
745a8299c2b5 [project @ 2007-12-28 20:56:55 by jwe]
jwe
parents: 7017
diff changeset
3702 if (fcn.is_defined ())
745a8299c2b5 [project @ 2007-12-28 20:56:55 by jwe]
jwe
parents: 7017
diff changeset
3703 retval = fcn.do_multi_index_op (nargout, args);
745a8299c2b5 [project @ 2007-12-28 20:56:55 by jwe]
jwe
parents: 7017
diff changeset
3704 else
745a8299c2b5 [project @ 2007-12-28 20:56:55 by jwe]
jwe
parents: 7017
diff changeset
3705 error ("feval: function `%s' not found", name.c_str ());
3156
a494f93e60ff [project @ 1998-02-20 07:47:48 by jwe]
jwe
parents: 3110
diff changeset
3706
a494f93e60ff [project @ 1998-02-20 07:47:48 by jwe]
jwe
parents: 3110
diff changeset
3707 return retval;
a494f93e60ff [project @ 1998-02-20 07:47:48 by jwe]
jwe
parents: 3110
diff changeset
3708 }
a494f93e60ff [project @ 1998-02-20 07:47:48 by jwe]
jwe
parents: 3110
diff changeset
3709
4342
813effe14ee1 [project @ 2003-02-20 08:35:55 by jwe]
jwe
parents: 4318
diff changeset
3710 octave_value_list
813effe14ee1 [project @ 2003-02-20 08:35:55 by jwe]
jwe
parents: 4318
diff changeset
3711 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
3712 {
813effe14ee1 [project @ 2003-02-20 08:35:55 by jwe]
jwe
parents: 4318
diff changeset
3713 octave_value_list retval;
813effe14ee1 [project @ 2003-02-20 08:35:55 by jwe]
jwe
parents: 4318
diff changeset
3714
813effe14ee1 [project @ 2003-02-20 08:35:55 by jwe]
jwe
parents: 4318
diff changeset
3715 if (fcn)
813effe14ee1 [project @ 2003-02-20 08:35:55 by jwe]
jwe
parents: 4318
diff changeset
3716 retval = fcn->do_multi_index_op (nargout, args);
813effe14ee1 [project @ 2003-02-20 08:35:55 by jwe]
jwe
parents: 4318
diff changeset
3717
813effe14ee1 [project @ 2003-02-20 08:35:55 by jwe]
jwe
parents: 4318
diff changeset
3718 return retval;
813effe14ee1 [project @ 2003-02-20 08:35:55 by jwe]
jwe
parents: 4318
diff changeset
3719 }
813effe14ee1 [project @ 2003-02-20 08:35:55 by jwe]
jwe
parents: 4318
diff changeset
3720
813effe14ee1 [project @ 2003-02-20 08:35:55 by jwe]
jwe
parents: 4318
diff changeset
3721 static octave_value_list
813effe14ee1 [project @ 2003-02-20 08:35:55 by jwe]
jwe
parents: 4318
diff changeset
3722 get_feval_args (const octave_value_list& args)
813effe14ee1 [project @ 2003-02-20 08:35:55 by jwe]
jwe
parents: 4318
diff changeset
3723 {
813effe14ee1 [project @ 2003-02-20 08:35:55 by jwe]
jwe
parents: 4318
diff changeset
3724 int tmp_nargin = args.length () - 1;
813effe14ee1 [project @ 2003-02-20 08:35:55 by jwe]
jwe
parents: 4318
diff changeset
3725
813effe14ee1 [project @ 2003-02-20 08:35:55 by jwe]
jwe
parents: 4318
diff changeset
3726 octave_value_list retval (tmp_nargin, octave_value ());
813effe14ee1 [project @ 2003-02-20 08:35:55 by jwe]
jwe
parents: 4318
diff changeset
3727
813effe14ee1 [project @ 2003-02-20 08:35:55 by jwe]
jwe
parents: 4318
diff changeset
3728 for (int i = 0; i < tmp_nargin; i++)
813effe14ee1 [project @ 2003-02-20 08:35:55 by jwe]
jwe
parents: 4318
diff changeset
3729 retval(i) = args(i+1);
813effe14ee1 [project @ 2003-02-20 08:35:55 by jwe]
jwe
parents: 4318
diff changeset
3730
813effe14ee1 [project @ 2003-02-20 08:35:55 by jwe]
jwe
parents: 4318
diff changeset
3731 string_vector arg_names = args.name_tags ();
813effe14ee1 [project @ 2003-02-20 08:35:55 by jwe]
jwe
parents: 4318
diff changeset
3732
813effe14ee1 [project @ 2003-02-20 08:35:55 by jwe]
jwe
parents: 4318
diff changeset
3733 if (! arg_names.empty ())
813effe14ee1 [project @ 2003-02-20 08:35:55 by jwe]
jwe
parents: 4318
diff changeset
3734 {
813effe14ee1 [project @ 2003-02-20 08:35:55 by jwe]
jwe
parents: 4318
diff changeset
3735 // tmp_nargin and arg_names.length () - 1 may differ if
813effe14ee1 [project @ 2003-02-20 08:35:55 by jwe]
jwe
parents: 4318
diff changeset
3736 // we are passed all_va_args.
813effe14ee1 [project @ 2003-02-20 08:35:55 by jwe]
jwe
parents: 4318
diff changeset
3737
813effe14ee1 [project @ 2003-02-20 08:35:55 by jwe]
jwe
parents: 4318
diff changeset
3738 int n = arg_names.length () - 1;
813effe14ee1 [project @ 2003-02-20 08:35:55 by jwe]
jwe
parents: 4318
diff changeset
3739
813effe14ee1 [project @ 2003-02-20 08:35:55 by jwe]
jwe
parents: 4318
diff changeset
3740 int len = n > tmp_nargin ? tmp_nargin : n;
813effe14ee1 [project @ 2003-02-20 08:35:55 by jwe]
jwe
parents: 4318
diff changeset
3741
813effe14ee1 [project @ 2003-02-20 08:35:55 by jwe]
jwe
parents: 4318
diff changeset
3742 string_vector tmp_arg_names (len);
813effe14ee1 [project @ 2003-02-20 08:35:55 by jwe]
jwe
parents: 4318
diff changeset
3743
813effe14ee1 [project @ 2003-02-20 08:35:55 by jwe]
jwe
parents: 4318
diff changeset
3744 for (int i = 0; i < len; i++)
813effe14ee1 [project @ 2003-02-20 08:35:55 by jwe]
jwe
parents: 4318
diff changeset
3745 tmp_arg_names(i) = arg_names(i+1);
813effe14ee1 [project @ 2003-02-20 08:35:55 by jwe]
jwe
parents: 4318
diff changeset
3746
813effe14ee1 [project @ 2003-02-20 08:35:55 by jwe]
jwe
parents: 4318
diff changeset
3747 retval.stash_name_tags (tmp_arg_names);
813effe14ee1 [project @ 2003-02-20 08:35:55 by jwe]
jwe
parents: 4318
diff changeset
3748 }
813effe14ee1 [project @ 2003-02-20 08:35:55 by jwe]
jwe
parents: 4318
diff changeset
3749
813effe14ee1 [project @ 2003-02-20 08:35:55 by jwe]
jwe
parents: 4318
diff changeset
3750 return retval;
813effe14ee1 [project @ 2003-02-20 08:35:55 by jwe]
jwe
parents: 4318
diff changeset
3751 }
813effe14ee1 [project @ 2003-02-20 08:35:55 by jwe]
jwe
parents: 4318
diff changeset
3752
813effe14ee1 [project @ 2003-02-20 08:35:55 by jwe]
jwe
parents: 4318
diff changeset
3753
3726
b7d997d593d9 [project @ 2000-10-27 17:51:21 by jwe]
jwe
parents: 3712
diff changeset
3754 // 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
3755 // 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
3756 // 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
3757 // 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
3758 // output arguments expected.
b7d997d593d9 [project @ 2000-10-27 17:51:21 by jwe]
jwe
parents: 3712
diff changeset
3759
3156
a494f93e60ff [project @ 1998-02-20 07:47:48 by jwe]
jwe
parents: 3110
diff changeset
3760 octave_value_list
3021
18d64612e67a [project @ 1997-06-03 22:18:56 by jwe]
jwe
parents: 3016
diff changeset
3761 feval (const octave_value_list& args, int nargout)
18d64612e67a [project @ 1997-06-03 22:18:56 by jwe]
jwe
parents: 3016
diff changeset
3762 {
18d64612e67a [project @ 1997-06-03 22:18:56 by jwe]
jwe
parents: 3016
diff changeset
3763 octave_value_list retval;
18d64612e67a [project @ 1997-06-03 22:18:56 by jwe]
jwe
parents: 3016
diff changeset
3764
4342
813effe14ee1 [project @ 2003-02-20 08:35:55 by jwe]
jwe
parents: 4318
diff changeset
3765 int nargin = args.length ();
813effe14ee1 [project @ 2003-02-20 08:35:55 by jwe]
jwe
parents: 4318
diff changeset
3766
813effe14ee1 [project @ 2003-02-20 08:35:55 by jwe]
jwe
parents: 4318
diff changeset
3767 if (nargin > 0)
3021
18d64612e67a [project @ 1997-06-03 22:18:56 by jwe]
jwe
parents: 3016
diff changeset
3768 {
4342
813effe14ee1 [project @ 2003-02-20 08:35:55 by jwe]
jwe
parents: 4318
diff changeset
3769 octave_value f_arg = args(0);
813effe14ee1 [project @ 2003-02-20 08:35:55 by jwe]
jwe
parents: 4318
diff changeset
3770
813effe14ee1 [project @ 2003-02-20 08:35:55 by jwe]
jwe
parents: 4318
diff changeset
3771 if (f_arg.is_string ())
813effe14ee1 [project @ 2003-02-20 08:35:55 by jwe]
jwe
parents: 4318
diff changeset
3772 {
813effe14ee1 [project @ 2003-02-20 08:35:55 by jwe]
jwe
parents: 4318
diff changeset
3773 std::string name = f_arg.string_value ();
813effe14ee1 [project @ 2003-02-20 08:35:55 by jwe]
jwe
parents: 4318
diff changeset
3774
813effe14ee1 [project @ 2003-02-20 08:35:55 by jwe]
jwe
parents: 4318
diff changeset
3775 if (! error_state)
3156
a494f93e60ff [project @ 1998-02-20 07:47:48 by jwe]
jwe
parents: 3110
diff changeset
3776 {
4342
813effe14ee1 [project @ 2003-02-20 08:35:55 by jwe]
jwe
parents: 4318
diff changeset
3777 octave_value_list tmp_args = get_feval_args (args);
813effe14ee1 [project @ 2003-02-20 08:35:55 by jwe]
jwe
parents: 4318
diff changeset
3778
813effe14ee1 [project @ 2003-02-20 08:35:55 by jwe]
jwe
parents: 4318
diff changeset
3779 retval = feval (name, tmp_args, nargout);
3156
a494f93e60ff [project @ 1998-02-20 07:47:48 by jwe]
jwe
parents: 3110
diff changeset
3780 }
4342
813effe14ee1 [project @ 2003-02-20 08:35:55 by jwe]
jwe
parents: 4318
diff changeset
3781 }
813effe14ee1 [project @ 2003-02-20 08:35:55 by jwe]
jwe
parents: 4318
diff changeset
3782 else
813effe14ee1 [project @ 2003-02-20 08:35:55 by jwe]
jwe
parents: 4318
diff changeset
3783 {
813effe14ee1 [project @ 2003-02-20 08:35:55 by jwe]
jwe
parents: 4318
diff changeset
3784 octave_function *fcn = f_arg.function_value ();
813effe14ee1 [project @ 2003-02-20 08:35:55 by jwe]
jwe
parents: 4318
diff changeset
3785
813effe14ee1 [project @ 2003-02-20 08:35:55 by jwe]
jwe
parents: 4318
diff changeset
3786 if (fcn)
813effe14ee1 [project @ 2003-02-20 08:35:55 by jwe]
jwe
parents: 4318
diff changeset
3787 {
813effe14ee1 [project @ 2003-02-20 08:35:55 by jwe]
jwe
parents: 4318
diff changeset
3788 octave_value_list tmp_args = get_feval_args (args);
813effe14ee1 [project @ 2003-02-20 08:35:55 by jwe]
jwe
parents: 4318
diff changeset
3789
813effe14ee1 [project @ 2003-02-20 08:35:55 by jwe]
jwe
parents: 4318
diff changeset
3790 retval = feval (fcn, tmp_args, nargout);
813effe14ee1 [project @ 2003-02-20 08:35:55 by jwe]
jwe
parents: 4318
diff changeset
3791 }
3021
18d64612e67a [project @ 1997-06-03 22:18:56 by jwe]
jwe
parents: 3016
diff changeset
3792 }
18d64612e67a [project @ 1997-06-03 22:18:56 by jwe]
jwe
parents: 3016
diff changeset
3793 }
18d64612e67a [project @ 1997-06-03 22:18:56 by jwe]
jwe
parents: 3016
diff changeset
3794
18d64612e67a [project @ 1997-06-03 22:18:56 by jwe]
jwe
parents: 3016
diff changeset
3795 return retval;
18d64612e67a [project @ 1997-06-03 22:18:56 by jwe]
jwe
parents: 3016
diff changeset
3796 }
18d64612e67a [project @ 1997-06-03 22:18:56 by jwe]
jwe
parents: 3016
diff changeset
3797
18d64612e67a [project @ 1997-06-03 22:18:56 by jwe]
jwe
parents: 3016
diff changeset
3798 DEFUN (feval, args, nargout,
3371
86873384cd10 [project @ 1999-11-21 17:31:07 by jwe]
jwe
parents: 3366
diff changeset
3799 "-*- texinfo -*-\n\
86873384cd10 [project @ 1999-11-21 17:31:07 by jwe]
jwe
parents: 3366
diff changeset
3800 @deftypefn {Built-in Function} {} feval (@var{name}, @dots{})\n\
86873384cd10 [project @ 1999-11-21 17:31:07 by jwe]
jwe
parents: 3366
diff changeset
3801 Evaluate the function named @var{name}. Any arguments after the first\n\
86873384cd10 [project @ 1999-11-21 17:31:07 by jwe]
jwe
parents: 3366
diff changeset
3802 are passed on to the named function. For example,\n\
86873384cd10 [project @ 1999-11-21 17:31:07 by jwe]
jwe
parents: 3366
diff changeset
3803 \n\
86873384cd10 [project @ 1999-11-21 17:31:07 by jwe]
jwe
parents: 3366
diff changeset
3804 @example\n\
86873384cd10 [project @ 1999-11-21 17:31:07 by jwe]
jwe
parents: 3366
diff changeset
3805 feval (\"acos\", -1)\n\
86873384cd10 [project @ 1999-11-21 17:31:07 by jwe]
jwe
parents: 3366
diff changeset
3806 @result{} 3.1416\n\
86873384cd10 [project @ 1999-11-21 17:31:07 by jwe]
jwe
parents: 3366
diff changeset
3807 @end example\n\
3021
18d64612e67a [project @ 1997-06-03 22:18:56 by jwe]
jwe
parents: 3016
diff changeset
3808 \n\
3371
86873384cd10 [project @ 1999-11-21 17:31:07 by jwe]
jwe
parents: 3366
diff changeset
3809 @noindent\n\
86873384cd10 [project @ 1999-11-21 17:31:07 by jwe]
jwe
parents: 3366
diff changeset
3810 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
3811 \n\
86873384cd10 [project @ 1999-11-21 17:31:07 by jwe]
jwe
parents: 3366
diff changeset
3812 The function @code{feval} is necessary in order to be able to write\n\
86873384cd10 [project @ 1999-11-21 17:31:07 by jwe]
jwe
parents: 3366
diff changeset
3813 functions that call user-supplied functions, because Octave does not\n\
86873384cd10 [project @ 1999-11-21 17:31:07 by jwe]
jwe
parents: 3366
diff changeset
3814 have a way to declare a pointer to a function (like C) or to declare a\n\
86873384cd10 [project @ 1999-11-21 17:31:07 by jwe]
jwe
parents: 3366
diff changeset
3815 special kind of variable that can be used to hold the name of a function\n\
86873384cd10 [project @ 1999-11-21 17:31:07 by jwe]
jwe
parents: 3366
diff changeset
3816 (like @code{EXTERNAL} in Fortran). Instead, you must refer to functions\n\
86873384cd10 [project @ 1999-11-21 17:31:07 by jwe]
jwe
parents: 3366
diff changeset
3817 by name, and use @code{feval} to call them.\n\
86873384cd10 [project @ 1999-11-21 17:31:07 by jwe]
jwe
parents: 3366
diff changeset
3818 @end deftypefn")
3021
18d64612e67a [project @ 1997-06-03 22:18:56 by jwe]
jwe
parents: 3016
diff changeset
3819 {
18d64612e67a [project @ 1997-06-03 22:18:56 by jwe]
jwe
parents: 3016
diff changeset
3820 octave_value_list retval;
18d64612e67a [project @ 1997-06-03 22:18:56 by jwe]
jwe
parents: 3016
diff changeset
3821
18d64612e67a [project @ 1997-06-03 22:18:56 by jwe]
jwe
parents: 3016
diff changeset
3822 int nargin = args.length ();
18d64612e67a [project @ 1997-06-03 22:18:56 by jwe]
jwe
parents: 3016
diff changeset
3823
18d64612e67a [project @ 1997-06-03 22:18:56 by jwe]
jwe
parents: 3016
diff changeset
3824 if (nargin > 0)
18d64612e67a [project @ 1997-06-03 22:18:56 by jwe]
jwe
parents: 3016
diff changeset
3825 retval = feval (args, nargout);
18d64612e67a [project @ 1997-06-03 22:18:56 by jwe]
jwe
parents: 3016
diff changeset
3826 else
5823
080c08b192d8 [project @ 2006-05-19 05:32:17 by jwe]
jwe
parents: 5794
diff changeset
3827 print_usage ();
3021
18d64612e67a [project @ 1997-06-03 22:18:56 by jwe]
jwe
parents: 3016
diff changeset
3828
18d64612e67a [project @ 1997-06-03 22:18:56 by jwe]
jwe
parents: 3016
diff changeset
3829 return retval;
18d64612e67a [project @ 1997-06-03 22:18:56 by jwe]
jwe
parents: 3016
diff changeset
3830 }
18d64612e67a [project @ 1997-06-03 22:18:56 by jwe]
jwe
parents: 3016
diff changeset
3831
3099
8ce6fed79320 [project @ 1997-11-14 09:49:28 by jwe]
jwe
parents: 3095
diff changeset
3832 octave_value_list
3523
b80bbb43a1a9 [project @ 2000-02-02 10:25:52 by jwe]
jwe
parents: 3489
diff changeset
3833 eval_string (const std::string& s, bool silent, int& parse_status, int nargout)
3021
18d64612e67a [project @ 1997-06-03 22:18:56 by jwe]
jwe
parents: 3016
diff changeset
3834 {
3877
55648fc616c8 [project @ 2002-03-07 23:00:09 by jwe]
jwe
parents: 3844
diff changeset
3835 octave_value_list retval;
55648fc616c8 [project @ 2002-03-07 23:00:09 by jwe]
jwe
parents: 3844
diff changeset
3836
3021
18d64612e67a [project @ 1997-06-03 22:18:56 by jwe]
jwe
parents: 3016
diff changeset
3837 unwind_protect::begin_frame ("eval_string");
18d64612e67a [project @ 1997-06-03 22:18:56 by jwe]
jwe
parents: 3016
diff changeset
3838
8447
adab48231a03 make input_line_number work again
John W. Eaton <jwe@octave.org>
parents: 8311
diff changeset
3839 unwind_protect_int (input_line_number);
adab48231a03 make input_line_number work again
John W. Eaton <jwe@octave.org>
parents: 8311
diff changeset
3840 unwind_protect_int (current_input_column);
3021
18d64612e67a [project @ 1997-06-03 22:18:56 by jwe]
jwe
parents: 3016
diff changeset
3841 unwind_protect_bool (get_input_from_eval_string);
3877
55648fc616c8 [project @ 2002-03-07 23:00:09 by jwe]
jwe
parents: 3844
diff changeset
3842 unwind_protect_bool (input_from_eval_string_pending);
3883
69b6bd271277 [project @ 2002-04-02 21:05:10 by jwe]
jwe
parents: 3881
diff changeset
3843 unwind_protect_bool (parser_end_of_input);
5189
85b315ad5f7d [project @ 2005-03-04 02:46:08 by jwe]
jwe
parents: 5180
diff changeset
3844 unwind_protect_bool (line_editing);
3021
18d64612e67a [project @ 1997-06-03 22:18:56 by jwe]
jwe
parents: 3016
diff changeset
3845 unwind_protect_str (current_eval_string);
18d64612e67a [project @ 1997-06-03 22:18:56 by jwe]
jwe
parents: 3016
diff changeset
3846
8447
adab48231a03 make input_line_number work again
John W. Eaton <jwe@octave.org>
parents: 8311
diff changeset
3847 input_line_number = 1;
adab48231a03 make input_line_number work again
John W. Eaton <jwe@octave.org>
parents: 8311
diff changeset
3848 current_input_column = 1;
3021
18d64612e67a [project @ 1997-06-03 22:18:56 by jwe]
jwe
parents: 3016
diff changeset
3849 get_input_from_eval_string = true;
3877
55648fc616c8 [project @ 2002-03-07 23:00:09 by jwe]
jwe
parents: 3844
diff changeset
3850 input_from_eval_string_pending = true;
3883
69b6bd271277 [project @ 2002-04-02 21:05:10 by jwe]
jwe
parents: 3881
diff changeset
3851 parser_end_of_input = false;
5189
85b315ad5f7d [project @ 2005-03-04 02:46:08 by jwe]
jwe
parents: 5180
diff changeset
3852 line_editing = false;
85b315ad5f7d [project @ 2005-03-04 02:46:08 by jwe]
jwe
parents: 5180
diff changeset
3853
3021
18d64612e67a [project @ 1997-06-03 22:18:56 by jwe]
jwe
parents: 3016
diff changeset
3854 current_eval_string = s;
18d64612e67a [project @ 1997-06-03 22:18:56 by jwe]
jwe
parents: 3016
diff changeset
3855
18d64612e67a [project @ 1997-06-03 22:18:56 by jwe]
jwe
parents: 3016
diff changeset
3856 YY_BUFFER_STATE old_buf = current_buffer ();
18d64612e67a [project @ 1997-06-03 22:18:56 by jwe]
jwe
parents: 3016
diff changeset
3857 YY_BUFFER_STATE new_buf = create_buffer (0);
18d64612e67a [project @ 1997-06-03 22:18:56 by jwe]
jwe
parents: 3016
diff changeset
3858
18d64612e67a [project @ 1997-06-03 22:18:56 by jwe]
jwe
parents: 3016
diff changeset
3859 unwind_protect::add (restore_input_buffer, old_buf);
18d64612e67a [project @ 1997-06-03 22:18:56 by jwe]
jwe
parents: 3016
diff changeset
3860 unwind_protect::add (delete_input_buffer, new_buf);
18d64612e67a [project @ 1997-06-03 22:18:56 by jwe]
jwe
parents: 3016
diff changeset
3861
18d64612e67a [project @ 1997-06-03 22:18:56 by jwe]
jwe
parents: 3016
diff changeset
3862 switch_to_buffer (new_buf);
18d64612e67a [project @ 1997-06-03 22:18:56 by jwe]
jwe
parents: 3016
diff changeset
3863
3877
55648fc616c8 [project @ 2002-03-07 23:00:09 by jwe]
jwe
parents: 3844
diff changeset
3864 do
55648fc616c8 [project @ 2002-03-07 23:00:09 by jwe]
jwe
parents: 3844
diff changeset
3865 {
4318
115bffcecfd3 [project @ 2003-02-13 05:52:16 by jwe]
jwe
parents: 4297
diff changeset
3866 reset_parser ();
115bffcecfd3 [project @ 2003-02-13 05:52:16 by jwe]
jwe
parents: 4297
diff changeset
3867
7903
8018e10d2b87 save and restore global_command as needed
John W. Eaton <jwe@octave.org>
parents: 7901
diff changeset
3868 unwind_protect_ptr (global_command);
8018e10d2b87 save and restore global_command as needed
John W. Eaton <jwe@octave.org>
parents: 7901
diff changeset
3869
3877
55648fc616c8 [project @ 2002-03-07 23:00:09 by jwe]
jwe
parents: 3844
diff changeset
3870 parse_status = yyparse ();
55648fc616c8 [project @ 2002-03-07 23:00:09 by jwe]
jwe
parents: 3844
diff changeset
3871
8658
73c4516fae10 New evaluator and debugger derived from tree-walker class
John W. Eaton <jwe@octave.org>
parents: 8471
diff changeset
3872 tree_statement_list *command_list = global_command;
3877
55648fc616c8 [project @ 2002-03-07 23:00:09 by jwe]
jwe
parents: 3844
diff changeset
3873
7903
8018e10d2b87 save and restore global_command as needed
John W. Eaton <jwe@octave.org>
parents: 7901
diff changeset
3874 // Restore previous value of global_command.
8018e10d2b87 save and restore global_command as needed
John W. Eaton <jwe@octave.org>
parents: 7901
diff changeset
3875 unwind_protect::run ();
8018e10d2b87 save and restore global_command as needed
John W. Eaton <jwe@octave.org>
parents: 7901
diff changeset
3876
3883
69b6bd271277 [project @ 2002-04-02 21:05:10 by jwe]
jwe
parents: 3881
diff changeset
3877 if (parse_status == 0)
3877
55648fc616c8 [project @ 2002-03-07 23:00:09 by jwe]
jwe
parents: 3844
diff changeset
3878 {
8658
73c4516fae10 New evaluator and debugger derived from tree-walker class
John W. Eaton <jwe@octave.org>
parents: 8471
diff changeset
3879 if (command_list)
3883
69b6bd271277 [project @ 2002-04-02 21:05:10 by jwe]
jwe
parents: 3881
diff changeset
3880 {
8658
73c4516fae10 New evaluator and debugger derived from tree-walker class
John W. Eaton <jwe@octave.org>
parents: 8471
diff changeset
3881 tree_statement *stmt = 0;
73c4516fae10 New evaluator and debugger derived from tree-walker class
John W. Eaton <jwe@octave.org>
parents: 8471
diff changeset
3882
73c4516fae10 New evaluator and debugger derived from tree-walker class
John W. Eaton <jwe@octave.org>
parents: 8471
diff changeset
3883 if (command_list->length () == 1
73c4516fae10 New evaluator and debugger derived from tree-walker class
John W. Eaton <jwe@octave.org>
parents: 8471
diff changeset
3884 && (stmt = command_list->front ())
73c4516fae10 New evaluator and debugger derived from tree-walker class
John W. Eaton <jwe@octave.org>
parents: 8471
diff changeset
3885 && stmt->is_expression ())
73c4516fae10 New evaluator and debugger derived from tree-walker class
John W. Eaton <jwe@octave.org>
parents: 8471
diff changeset
3886 {
73c4516fae10 New evaluator and debugger derived from tree-walker class
John W. Eaton <jwe@octave.org>
parents: 8471
diff changeset
3887 tree_expression *expr = stmt->expression ();
73c4516fae10 New evaluator and debugger derived from tree-walker class
John W. Eaton <jwe@octave.org>
parents: 8471
diff changeset
3888
73c4516fae10 New evaluator and debugger derived from tree-walker class
John W. Eaton <jwe@octave.org>
parents: 8471
diff changeset
3889 if (silent)
73c4516fae10 New evaluator and debugger derived from tree-walker class
John W. Eaton <jwe@octave.org>
parents: 8471
diff changeset
3890 expr->set_print_flag (false);
73c4516fae10 New evaluator and debugger derived from tree-walker class
John W. Eaton <jwe@octave.org>
parents: 8471
diff changeset
3891
73c4516fae10 New evaluator and debugger derived from tree-walker class
John W. Eaton <jwe@octave.org>
parents: 8471
diff changeset
3892 bool do_bind_ans = false;
73c4516fae10 New evaluator and debugger derived from tree-walker class
John W. Eaton <jwe@octave.org>
parents: 8471
diff changeset
3893
73c4516fae10 New evaluator and debugger derived from tree-walker class
John W. Eaton <jwe@octave.org>
parents: 8471
diff changeset
3894 if (expr->is_identifier ())
73c4516fae10 New evaluator and debugger derived from tree-walker class
John W. Eaton <jwe@octave.org>
parents: 8471
diff changeset
3895 {
73c4516fae10 New evaluator and debugger derived from tree-walker class
John W. Eaton <jwe@octave.org>
parents: 8471
diff changeset
3896 tree_identifier *id
73c4516fae10 New evaluator and debugger derived from tree-walker class
John W. Eaton <jwe@octave.org>
parents: 8471
diff changeset
3897 = dynamic_cast<tree_identifier *> (expr);
73c4516fae10 New evaluator and debugger derived from tree-walker class
John W. Eaton <jwe@octave.org>
parents: 8471
diff changeset
3898
73c4516fae10 New evaluator and debugger derived from tree-walker class
John W. Eaton <jwe@octave.org>
parents: 8471
diff changeset
3899 do_bind_ans = (! id->is_variable ());
73c4516fae10 New evaluator and debugger derived from tree-walker class
John W. Eaton <jwe@octave.org>
parents: 8471
diff changeset
3900 }
73c4516fae10 New evaluator and debugger derived from tree-walker class
John W. Eaton <jwe@octave.org>
parents: 8471
diff changeset
3901 else
73c4516fae10 New evaluator and debugger derived from tree-walker class
John W. Eaton <jwe@octave.org>
parents: 8471
diff changeset
3902 do_bind_ans = (! expr->is_assignment_expression ());
73c4516fae10 New evaluator and debugger derived from tree-walker class
John W. Eaton <jwe@octave.org>
parents: 8471
diff changeset
3903
73c4516fae10 New evaluator and debugger derived from tree-walker class
John W. Eaton <jwe@octave.org>
parents: 8471
diff changeset
3904 retval = expr->rvalue (nargout);
73c4516fae10 New evaluator and debugger derived from tree-walker class
John W. Eaton <jwe@octave.org>
parents: 8471
diff changeset
3905
73c4516fae10 New evaluator and debugger derived from tree-walker class
John W. Eaton <jwe@octave.org>
parents: 8471
diff changeset
3906 if (do_bind_ans && ! (error_state || retval.empty ()))
73c4516fae10 New evaluator and debugger derived from tree-walker class
John W. Eaton <jwe@octave.org>
parents: 8471
diff changeset
3907 bind_ans (retval(0), expr->print_result ());
73c4516fae10 New evaluator and debugger derived from tree-walker class
John W. Eaton <jwe@octave.org>
parents: 8471
diff changeset
3908
73c4516fae10 New evaluator and debugger derived from tree-walker class
John W. Eaton <jwe@octave.org>
parents: 8471
diff changeset
3909 if (nargout == 0)
73c4516fae10 New evaluator and debugger derived from tree-walker class
John W. Eaton <jwe@octave.org>
parents: 8471
diff changeset
3910 retval = octave_value_list ();
73c4516fae10 New evaluator and debugger derived from tree-walker class
John W. Eaton <jwe@octave.org>
parents: 8471
diff changeset
3911 }
73c4516fae10 New evaluator and debugger derived from tree-walker class
John W. Eaton <jwe@octave.org>
parents: 8471
diff changeset
3912 else if (nargout == 0)
8697
b227213a70c3 parse.y (eval_string): use the one true evaluator
John W. Eaton <jwe@octave.org>
parents: 8669
diff changeset
3913 command_list->accept (*current_evaluator);
8658
73c4516fae10 New evaluator and debugger derived from tree-walker class
John W. Eaton <jwe@octave.org>
parents: 8471
diff changeset
3914 else
73c4516fae10 New evaluator and debugger derived from tree-walker class
John W. Eaton <jwe@octave.org>
parents: 8471
diff changeset
3915 error ("eval: invalid use of statement list");
73c4516fae10 New evaluator and debugger derived from tree-walker class
John W. Eaton <jwe@octave.org>
parents: 8471
diff changeset
3916
73c4516fae10 New evaluator and debugger derived from tree-walker class
John W. Eaton <jwe@octave.org>
parents: 8471
diff changeset
3917 delete command_list;
73c4516fae10 New evaluator and debugger derived from tree-walker class
John W. Eaton <jwe@octave.org>
parents: 8471
diff changeset
3918
73c4516fae10 New evaluator and debugger derived from tree-walker class
John W. Eaton <jwe@octave.org>
parents: 8471
diff changeset
3919 command_list = 0;
3883
69b6bd271277 [project @ 2002-04-02 21:05:10 by jwe]
jwe
parents: 3881
diff changeset
3920
69b6bd271277 [project @ 2002-04-02 21:05:10 by jwe]
jwe
parents: 3881
diff changeset
3921 if (error_state
4207
fa3482b34599 [project @ 2002-12-03 18:22:05 by jwe]
jwe
parents: 4186
diff changeset
3922 || tree_return_command::returning
fa3482b34599 [project @ 2002-12-03 18:22:05 by jwe]
jwe
parents: 4186
diff changeset
3923 || tree_break_command::breaking
fa3482b34599 [project @ 2002-12-03 18:22:05 by jwe]
jwe
parents: 4186
diff changeset
3924 || tree_continue_command::continuing)
3883
69b6bd271277 [project @ 2002-04-02 21:05:10 by jwe]
jwe
parents: 3881
diff changeset
3925 break;
69b6bd271277 [project @ 2002-04-02 21:05:10 by jwe]
jwe
parents: 3881
diff changeset
3926 }
69b6bd271277 [project @ 2002-04-02 21:05:10 by jwe]
jwe
parents: 3881
diff changeset
3927 else if (parser_end_of_input)
3877
55648fc616c8 [project @ 2002-03-07 23:00:09 by jwe]
jwe
parents: 3844
diff changeset
3928 break;
3883
69b6bd271277 [project @ 2002-04-02 21:05:10 by jwe]
jwe
parents: 3881
diff changeset
3929 }
3877
55648fc616c8 [project @ 2002-03-07 23:00:09 by jwe]
jwe
parents: 3844
diff changeset
3930 }
55648fc616c8 [project @ 2002-03-07 23:00:09 by jwe]
jwe
parents: 3844
diff changeset
3931 while (parse_status == 0);
3021
18d64612e67a [project @ 1997-06-03 22:18:56 by jwe]
jwe
parents: 3016
diff changeset
3932
18d64612e67a [project @ 1997-06-03 22:18:56 by jwe]
jwe
parents: 3016
diff changeset
3933 unwind_protect::run_frame ("eval_string");
18d64612e67a [project @ 1997-06-03 22:18:56 by jwe]
jwe
parents: 3016
diff changeset
3934
18d64612e67a [project @ 1997-06-03 22:18:56 by jwe]
jwe
parents: 3016
diff changeset
3935 return retval;
18d64612e67a [project @ 1997-06-03 22:18:56 by jwe]
jwe
parents: 3016
diff changeset
3936 }
18d64612e67a [project @ 1997-06-03 22:18:56 by jwe]
jwe
parents: 3016
diff changeset
3937
18d64612e67a [project @ 1997-06-03 22:18:56 by jwe]
jwe
parents: 3016
diff changeset
3938 octave_value
3523
b80bbb43a1a9 [project @ 2000-02-02 10:25:52 by jwe]
jwe
parents: 3489
diff changeset
3939 eval_string (const std::string& s, bool silent, int& parse_status)
3021
18d64612e67a [project @ 1997-06-03 22:18:56 by jwe]
jwe
parents: 3016
diff changeset
3940 {
18d64612e67a [project @ 1997-06-03 22:18:56 by jwe]
jwe
parents: 3016
diff changeset
3941 octave_value retval;
18d64612e67a [project @ 1997-06-03 22:18:56 by jwe]
jwe
parents: 3016
diff changeset
3942
18d64612e67a [project @ 1997-06-03 22:18:56 by jwe]
jwe
parents: 3016
diff changeset
3943 octave_value_list tmp = eval_string (s, silent, parse_status, 1);
18d64612e67a [project @ 1997-06-03 22:18:56 by jwe]
jwe
parents: 3016
diff changeset
3944
18d64612e67a [project @ 1997-06-03 22:18:56 by jwe]
jwe
parents: 3016
diff changeset
3945 if (! tmp.empty ())
18d64612e67a [project @ 1997-06-03 22:18:56 by jwe]
jwe
parents: 3016
diff changeset
3946 retval = tmp(0);
18d64612e67a [project @ 1997-06-03 22:18:56 by jwe]
jwe
parents: 3016
diff changeset
3947
18d64612e67a [project @ 1997-06-03 22:18:56 by jwe]
jwe
parents: 3016
diff changeset
3948 return retval;
18d64612e67a [project @ 1997-06-03 22:18:56 by jwe]
jwe
parents: 3016
diff changeset
3949 }
18d64612e67a [project @ 1997-06-03 22:18:56 by jwe]
jwe
parents: 3016
diff changeset
3950
18d64612e67a [project @ 1997-06-03 22:18:56 by jwe]
jwe
parents: 3016
diff changeset
3951 static octave_value_list
18d64612e67a [project @ 1997-06-03 22:18:56 by jwe]
jwe
parents: 3016
diff changeset
3952 eval_string (const octave_value& arg, bool silent, int& parse_status,
18d64612e67a [project @ 1997-06-03 22:18:56 by jwe]
jwe
parents: 3016
diff changeset
3953 int nargout)
18d64612e67a [project @ 1997-06-03 22:18:56 by jwe]
jwe
parents: 3016
diff changeset
3954 {
3523
b80bbb43a1a9 [project @ 2000-02-02 10:25:52 by jwe]
jwe
parents: 3489
diff changeset
3955 std::string s = arg.string_value ();
3021
18d64612e67a [project @ 1997-06-03 22:18:56 by jwe]
jwe
parents: 3016
diff changeset
3956
18d64612e67a [project @ 1997-06-03 22:18:56 by jwe]
jwe
parents: 3016
diff changeset
3957 if (error_state)
18d64612e67a [project @ 1997-06-03 22:18:56 by jwe]
jwe
parents: 3016
diff changeset
3958 {
3523
b80bbb43a1a9 [project @ 2000-02-02 10:25:52 by jwe]
jwe
parents: 3489
diff changeset
3959 error ("eval: expecting std::string argument");
4233
ccfdb55c8156 [project @ 2002-12-20 22:43:54 by jwe]
jwe
parents: 4219
diff changeset
3960 return octave_value (-1);
3021
18d64612e67a [project @ 1997-06-03 22:18:56 by jwe]
jwe
parents: 3016
diff changeset
3961 }
18d64612e67a [project @ 1997-06-03 22:18:56 by jwe]
jwe
parents: 3016
diff changeset
3962
18d64612e67a [project @ 1997-06-03 22:18:56 by jwe]
jwe
parents: 3016
diff changeset
3963 return eval_string (s, silent, parse_status, nargout);
18d64612e67a [project @ 1997-06-03 22:18:56 by jwe]
jwe
parents: 3016
diff changeset
3964 }
18d64612e67a [project @ 1997-06-03 22:18:56 by jwe]
jwe
parents: 3016
diff changeset
3965
18d64612e67a [project @ 1997-06-03 22:18:56 by jwe]
jwe
parents: 3016
diff changeset
3966 DEFUN (eval, args, nargout,
3371
86873384cd10 [project @ 1999-11-21 17:31:07 by jwe]
jwe
parents: 3366
diff changeset
3967 "-*- texinfo -*-\n\
86873384cd10 [project @ 1999-11-21 17:31:07 by jwe]
jwe
parents: 3366
diff changeset
3968 @deftypefn {Built-in Function} {} eval (@var{try}, @var{catch})\n\
86873384cd10 [project @ 1999-11-21 17:31:07 by jwe]
jwe
parents: 3366
diff changeset
3969 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
3970 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
3971 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
3972 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
3973 \n\
6a7fc4105bcc [project @ 2007-05-21 20:37:43 by jwe]
jwe
parents: 6637
diff changeset
3974 The following example makes the variable @var{a} with the approximate\n\
6a7fc4105bcc [project @ 2007-05-21 20:37:43 by jwe]
jwe
parents: 6637
diff changeset
3975 value 3.1416 available.\n\
6a7fc4105bcc [project @ 2007-05-21 20:37:43 by jwe]
jwe
parents: 6637
diff changeset
3976 \n\
6a7fc4105bcc [project @ 2007-05-21 20:37:43 by jwe]
jwe
parents: 6637
diff changeset
3977 @example\n\
6a7fc4105bcc [project @ 2007-05-21 20:37:43 by jwe]
jwe
parents: 6637
diff changeset
3978 eval(\"a = acos(-1);\");\n\
6a7fc4105bcc [project @ 2007-05-21 20:37:43 by jwe]
jwe
parents: 6637
diff changeset
3979 @end example\n\
6a7fc4105bcc [project @ 2007-05-21 20:37:43 by jwe]
jwe
parents: 6637
diff changeset
3980 \n\
6a7fc4105bcc [project @ 2007-05-21 20:37:43 by jwe]
jwe
parents: 6637
diff changeset
3981 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
3982 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
3983 \n\
6a7fc4105bcc [project @ 2007-05-21 20:37:43 by jwe]
jwe
parents: 6637
diff changeset
3984 @example\n\
6a7fc4105bcc [project @ 2007-05-21 20:37:43 by jwe]
jwe
parents: 6637
diff changeset
3985 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
3986 '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
3987 @print{} This error occurred:\n\
8015
30629059b72d Update the manual to reflect the changes in error output
sh@sh-laptop
parents: 8007
diff changeset
3988 This is a bad example\n\
6643
6a7fc4105bcc [project @ 2007-05-21 20:37:43 by jwe]
jwe
parents: 6637
diff changeset
3989 @end example\n\
3371
86873384cd10 [project @ 1999-11-21 17:31:07 by jwe]
jwe
parents: 3366
diff changeset
3990 @end deftypefn")
3021
18d64612e67a [project @ 1997-06-03 22:18:56 by jwe]
jwe
parents: 3016
diff changeset
3991 {
18d64612e67a [project @ 1997-06-03 22:18:56 by jwe]
jwe
parents: 3016
diff changeset
3992 octave_value_list retval;
18d64612e67a [project @ 1997-06-03 22:18:56 by jwe]
jwe
parents: 3016
diff changeset
3993
18d64612e67a [project @ 1997-06-03 22:18:56 by jwe]
jwe
parents: 3016
diff changeset
3994 int nargin = args.length ();
18d64612e67a [project @ 1997-06-03 22:18:56 by jwe]
jwe
parents: 3016
diff changeset
3995
18d64612e67a [project @ 1997-06-03 22:18:56 by jwe]
jwe
parents: 3016
diff changeset
3996 if (nargin > 0)
18d64612e67a [project @ 1997-06-03 22:18:56 by jwe]
jwe
parents: 3016
diff changeset
3997 {
18d64612e67a [project @ 1997-06-03 22:18:56 by jwe]
jwe
parents: 3016
diff changeset
3998 unwind_protect::begin_frame ("Feval");
18d64612e67a [project @ 1997-06-03 22:18:56 by jwe]
jwe
parents: 3016
diff changeset
3999
18d64612e67a [project @ 1997-06-03 22:18:56 by jwe]
jwe
parents: 3016
diff changeset
4000 if (nargin > 1)
18d64612e67a [project @ 1997-06-03 22:18:56 by jwe]
jwe
parents: 3016
diff changeset
4001 {
4699
5e2c68946f30 [project @ 2004-01-20 23:04:46 by jwe]
jwe
parents: 4678
diff changeset
4002 unwind_protect_int (buffer_error_messages);
5e2c68946f30 [project @ 2004-01-20 23:04:46 by jwe]
jwe
parents: 4678
diff changeset
4003 buffer_error_messages++;
3021
18d64612e67a [project @ 1997-06-03 22:18:56 by jwe]
jwe
parents: 3016
diff changeset
4004 }
18d64612e67a [project @ 1997-06-03 22:18:56 by jwe]
jwe
parents: 3016
diff changeset
4005
18d64612e67a [project @ 1997-06-03 22:18:56 by jwe]
jwe
parents: 3016
diff changeset
4006 int parse_status = 0;
18d64612e67a [project @ 1997-06-03 22:18:56 by jwe]
jwe
parents: 3016
diff changeset
4007
4463
322453495d75 [project @ 2003-07-12 05:03:33 by jwe]
jwe
parents: 4452
diff changeset
4008 octave_value_list tmp = eval_string (args(0), nargout > 0,
322453495d75 [project @ 2003-07-12 05:03:33 by jwe]
jwe
parents: 4452
diff changeset
4009 parse_status, nargout);
322453495d75 [project @ 2003-07-12 05:03:33 by jwe]
jwe
parents: 4452
diff changeset
4010
3021
18d64612e67a [project @ 1997-06-03 22:18:56 by jwe]
jwe
parents: 3016
diff changeset
4011 if (nargin > 1 && (parse_status != 0 || error_state))
18d64612e67a [project @ 1997-06-03 22:18:56 by jwe]
jwe
parents: 3016
diff changeset
4012 {
18d64612e67a [project @ 1997-06-03 22:18:56 by jwe]
jwe
parents: 3016
diff changeset
4013 error_state = 0;
18d64612e67a [project @ 1997-06-03 22:18:56 by jwe]
jwe
parents: 3016
diff changeset
4014
18d64612e67a [project @ 1997-06-03 22:18:56 by jwe]
jwe
parents: 3016
diff changeset
4015 // Set up for letting the user print any messages from
18d64612e67a [project @ 1997-06-03 22:18:56 by jwe]
jwe
parents: 3016
diff changeset
4016 // errors that occurred in the first part of this eval().
18d64612e67a [project @ 1997-06-03 22:18:56 by jwe]
jwe
parents: 3016
diff changeset
4017
4699
5e2c68946f30 [project @ 2004-01-20 23:04:46 by jwe]
jwe
parents: 4678
diff changeset
4018 buffer_error_messages--;
3021
18d64612e67a [project @ 1997-06-03 22:18:56 by jwe]
jwe
parents: 3016
diff changeset
4019
8033
2ad5ba320b93 parse.y (Feval): Return value produced by evaluating CATCH string
John W. Eaton <jwe@octave.org>
parents: 8021
diff changeset
4020 tmp = eval_string (args(1), nargout > 0, parse_status, nargout);
2ad5ba320b93 parse.y (Feval): Return value produced by evaluating CATCH string
John W. Eaton <jwe@octave.org>
parents: 8021
diff changeset
4021
2ad5ba320b93 parse.y (Feval): Return value produced by evaluating CATCH string
John W. Eaton <jwe@octave.org>
parents: 8021
diff changeset
4022 if (nargout > 0)
2ad5ba320b93 parse.y (Feval): Return value produced by evaluating CATCH string
John W. Eaton <jwe@octave.org>
parents: 8021
diff changeset
4023 retval = tmp;
3021
18d64612e67a [project @ 1997-06-03 22:18:56 by jwe]
jwe
parents: 3016
diff changeset
4024 }
8033
2ad5ba320b93 parse.y (Feval): Return value produced by evaluating CATCH string
John W. Eaton <jwe@octave.org>
parents: 8021
diff changeset
4025 else if (nargout > 0)
2ad5ba320b93 parse.y (Feval): Return value produced by evaluating CATCH string
John W. Eaton <jwe@octave.org>
parents: 8021
diff changeset
4026 retval = tmp;
3021
18d64612e67a [project @ 1997-06-03 22:18:56 by jwe]
jwe
parents: 3016
diff changeset
4027
18d64612e67a [project @ 1997-06-03 22:18:56 by jwe]
jwe
parents: 3016
diff changeset
4028 unwind_protect::run_frame ("Feval");
18d64612e67a [project @ 1997-06-03 22:18:56 by jwe]
jwe
parents: 3016
diff changeset
4029 }
18d64612e67a [project @ 1997-06-03 22:18:56 by jwe]
jwe
parents: 3016
diff changeset
4030 else
5823
080c08b192d8 [project @ 2006-05-19 05:32:17 by jwe]
jwe
parents: 5794
diff changeset
4031 print_usage ();
3021
18d64612e67a [project @ 1997-06-03 22:18:56 by jwe]
jwe
parents: 3016
diff changeset
4032
18d64612e67a [project @ 1997-06-03 22:18:56 by jwe]
jwe
parents: 3016
diff changeset
4033 return retval;
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
7562
c827f5673321 move tests to individual source files
John W. Eaton <jwe@octave.org>
parents: 7351
diff changeset
4036 /*
c827f5673321 move tests to individual source files
John W. Eaton <jwe@octave.org>
parents: 7351
diff changeset
4037
c827f5673321 move tests to individual source files
John W. Eaton <jwe@octave.org>
parents: 7351
diff changeset
4038 %% test/octave.test/eval/eval-1.m
c827f5673321 move tests to individual source files
John W. Eaton <jwe@octave.org>
parents: 7351
diff changeset
4039 %!#test
c827f5673321 move tests to individual source files
John W. Eaton <jwe@octave.org>
parents: 7351
diff changeset
4040 %! x = 1;
c827f5673321 move tests to individual source files
John W. Eaton <jwe@octave.org>
parents: 7351
diff changeset
4041 %! assert(eval ("x"),1);
c827f5673321 move tests to individual source files
John W. Eaton <jwe@octave.org>
parents: 7351
diff changeset
4042
c827f5673321 move tests to individual source files
John W. Eaton <jwe@octave.org>
parents: 7351
diff changeset
4043 %% test/octave.test/eval/eval-2.m
c827f5673321 move tests to individual source files
John W. Eaton <jwe@octave.org>
parents: 7351
diff changeset
4044 %!test
c827f5673321 move tests to individual source files
John W. Eaton <jwe@octave.org>
parents: 7351
diff changeset
4045 %! x = 1;
c827f5673321 move tests to individual source files
John W. Eaton <jwe@octave.org>
parents: 7351
diff changeset
4046 %! assert(eval ("x;"));
c827f5673321 move tests to individual source files
John W. Eaton <jwe@octave.org>
parents: 7351
diff changeset
4047
c827f5673321 move tests to individual source files
John W. Eaton <jwe@octave.org>
parents: 7351
diff changeset
4048 %% test/octave.test/eval/eval-3.m
c827f5673321 move tests to individual source files
John W. Eaton <jwe@octave.org>
parents: 7351
diff changeset
4049 %!test
c827f5673321 move tests to individual source files
John W. Eaton <jwe@octave.org>
parents: 7351
diff changeset
4050 %! x = 1;
c827f5673321 move tests to individual source files
John W. Eaton <jwe@octave.org>
parents: 7351
diff changeset
4051 %! assert(eval ("x;"),1);
c827f5673321 move tests to individual source files
John W. Eaton <jwe@octave.org>
parents: 7351
diff changeset
4052
c827f5673321 move tests to individual source files
John W. Eaton <jwe@octave.org>
parents: 7351
diff changeset
4053 %% FIXME
c827f5673321 move tests to individual source files
John W. Eaton <jwe@octave.org>
parents: 7351
diff changeset
4054 %% Disable this test as adding the ";" is redundant with eval-1 and
c827f5673321 move tests to individual source files
John W. Eaton <jwe@octave.org>
parents: 7351
diff changeset
4055 %% in any case is a syntax error with assert
c827f5673321 move tests to individual source files
John W. Eaton <jwe@octave.org>
parents: 7351
diff changeset
4056 %% test/octave.test/eval/eval-4.m
c827f5673321 move tests to individual source files
John W. Eaton <jwe@octave.org>
parents: 7351
diff changeset
4057 %!#test
c827f5673321 move tests to individual source files
John W. Eaton <jwe@octave.org>
parents: 7351
diff changeset
4058 %! x = 1;
c827f5673321 move tests to individual source files
John W. Eaton <jwe@octave.org>
parents: 7351
diff changeset
4059 %! assert(eval ("x");,1);
c827f5673321 move tests to individual source files
John W. Eaton <jwe@octave.org>
parents: 7351
diff changeset
4060
c827f5673321 move tests to individual source files
John W. Eaton <jwe@octave.org>
parents: 7351
diff changeset
4061 %% test/octave.test/eval/eval-5.m
c827f5673321 move tests to individual source files
John W. Eaton <jwe@octave.org>
parents: 7351
diff changeset
4062 %!test
c827f5673321 move tests to individual source files
John W. Eaton <jwe@octave.org>
parents: 7351
diff changeset
4063 %! eval ("flipud = 2;");
c827f5673321 move tests to individual source files
John W. Eaton <jwe@octave.org>
parents: 7351
diff changeset
4064 %! assert(flipud,2);
c827f5673321 move tests to individual source files
John W. Eaton <jwe@octave.org>
parents: 7351
diff changeset
4065
c827f5673321 move tests to individual source files
John W. Eaton <jwe@octave.org>
parents: 7351
diff changeset
4066 %% test/octave.test/eval/eval-6.m
c827f5673321 move tests to individual source files
John W. Eaton <jwe@octave.org>
parents: 7351
diff changeset
4067 %!function y = f ()
c827f5673321 move tests to individual source files
John W. Eaton <jwe@octave.org>
parents: 7351
diff changeset
4068 %! eval ("flipud = 2;");
c827f5673321 move tests to individual source files
John W. Eaton <jwe@octave.org>
parents: 7351
diff changeset
4069 %! y = flipud;
c827f5673321 move tests to individual source files
John W. Eaton <jwe@octave.org>
parents: 7351
diff changeset
4070 %!test
c827f5673321 move tests to individual source files
John W. Eaton <jwe@octave.org>
parents: 7351
diff changeset
4071 %! assert(f,2);
c827f5673321 move tests to individual source files
John W. Eaton <jwe@octave.org>
parents: 7351
diff changeset
4072
c827f5673321 move tests to individual source files
John W. Eaton <jwe@octave.org>
parents: 7351
diff changeset
4073 %% test/octave.test/eval/eval-7.m
c827f5673321 move tests to individual source files
John W. Eaton <jwe@octave.org>
parents: 7351
diff changeset
4074 %!#test
c827f5673321 move tests to individual source files
John W. Eaton <jwe@octave.org>
parents: 7351
diff changeset
4075 %! eval ("x = 1");
c827f5673321 move tests to individual source files
John W. Eaton <jwe@octave.org>
parents: 7351
diff changeset
4076 %! assert(x,1);
c827f5673321 move tests to individual source files
John W. Eaton <jwe@octave.org>
parents: 7351
diff changeset
4077
c827f5673321 move tests to individual source files
John W. Eaton <jwe@octave.org>
parents: 7351
diff changeset
4078 %% test/octave.test/eval/eval-8.m
c827f5673321 move tests to individual source files
John W. Eaton <jwe@octave.org>
parents: 7351
diff changeset
4079 %!test
c827f5673321 move tests to individual source files
John W. Eaton <jwe@octave.org>
parents: 7351
diff changeset
4080 %! eval ("x = 1;")
c827f5673321 move tests to individual source files
John W. Eaton <jwe@octave.org>
parents: 7351
diff changeset
4081 %! assert(x,1);
c827f5673321 move tests to individual source files
John W. Eaton <jwe@octave.org>
parents: 7351
diff changeset
4082
c827f5673321 move tests to individual source files
John W. Eaton <jwe@octave.org>
parents: 7351
diff changeset
4083 %% test/octave.test/eval/eval-9.m
c827f5673321 move tests to individual source files
John W. Eaton <jwe@octave.org>
parents: 7351
diff changeset
4084 %!test
c827f5673321 move tests to individual source files
John W. Eaton <jwe@octave.org>
parents: 7351
diff changeset
4085 %! eval ("x = 1;");
c827f5673321 move tests to individual source files
John W. Eaton <jwe@octave.org>
parents: 7351
diff changeset
4086 %! assert(x,1);
c827f5673321 move tests to individual source files
John W. Eaton <jwe@octave.org>
parents: 7351
diff changeset
4087
c827f5673321 move tests to individual source files
John W. Eaton <jwe@octave.org>
parents: 7351
diff changeset
4088 %% test/octave.test/eval/eval-10.m
c827f5673321 move tests to individual source files
John W. Eaton <jwe@octave.org>
parents: 7351
diff changeset
4089 %!#test
c827f5673321 move tests to individual source files
John W. Eaton <jwe@octave.org>
parents: 7351
diff changeset
4090 %! eval ("x = 1")
c827f5673321 move tests to individual source files
John W. Eaton <jwe@octave.org>
parents: 7351
diff changeset
4091 %! assert(x,1);
c827f5673321 move tests to individual source files
John W. Eaton <jwe@octave.org>
parents: 7351
diff changeset
4092
c827f5673321 move tests to individual source files
John W. Eaton <jwe@octave.org>
parents: 7351
diff changeset
4093 %% test/octave.test/eval/eval-11.m
c827f5673321 move tests to individual source files
John W. Eaton <jwe@octave.org>
parents: 7351
diff changeset
4094 %!test
c827f5673321 move tests to individual source files
John W. Eaton <jwe@octave.org>
parents: 7351
diff changeset
4095 %! x = 1;
c827f5673321 move tests to individual source files
John W. Eaton <jwe@octave.org>
parents: 7351
diff changeset
4096 %! y = eval ("x");
c827f5673321 move tests to individual source files
John W. Eaton <jwe@octave.org>
parents: 7351
diff changeset
4097 %! assert(y,1);
c827f5673321 move tests to individual source files
John W. Eaton <jwe@octave.org>
parents: 7351
diff changeset
4098
c827f5673321 move tests to individual source files
John W. Eaton <jwe@octave.org>
parents: 7351
diff changeset
4099 %% test/octave.test/eval/eval-12.m
c827f5673321 move tests to individual source files
John W. Eaton <jwe@octave.org>
parents: 7351
diff changeset
4100 %!test
c827f5673321 move tests to individual source files
John W. Eaton <jwe@octave.org>
parents: 7351
diff changeset
4101 %! x = 1;
c827f5673321 move tests to individual source files
John W. Eaton <jwe@octave.org>
parents: 7351
diff changeset
4102 %! y = eval ("x;");
c827f5673321 move tests to individual source files
John W. Eaton <jwe@octave.org>
parents: 7351
diff changeset
4103 %! assert(y,1);
c827f5673321 move tests to individual source files
John W. Eaton <jwe@octave.org>
parents: 7351
diff changeset
4104
c827f5673321 move tests to individual source files
John W. Eaton <jwe@octave.org>
parents: 7351
diff changeset
4105 %% test/octave.test/eval/eval-13.m
c827f5673321 move tests to individual source files
John W. Eaton <jwe@octave.org>
parents: 7351
diff changeset
4106 %!test
c827f5673321 move tests to individual source files
John W. Eaton <jwe@octave.org>
parents: 7351
diff changeset
4107 %! x = 1;
c827f5673321 move tests to individual source files
John W. Eaton <jwe@octave.org>
parents: 7351
diff changeset
4108 %! y = eval ("x;");
c827f5673321 move tests to individual source files
John W. Eaton <jwe@octave.org>
parents: 7351
diff changeset
4109 %! assert(y,1);
c827f5673321 move tests to individual source files
John W. Eaton <jwe@octave.org>
parents: 7351
diff changeset
4110
c827f5673321 move tests to individual source files
John W. Eaton <jwe@octave.org>
parents: 7351
diff changeset
4111 %% test/octave.test/eval/eval-14.m
c827f5673321 move tests to individual source files
John W. Eaton <jwe@octave.org>
parents: 7351
diff changeset
4112 %!test
c827f5673321 move tests to individual source files
John W. Eaton <jwe@octave.org>
parents: 7351
diff changeset
4113 %! x = 1;
c827f5673321 move tests to individual source files
John W. Eaton <jwe@octave.org>
parents: 7351
diff changeset
4114 %! y = eval ("x");
c827f5673321 move tests to individual source files
John W. Eaton <jwe@octave.org>
parents: 7351
diff changeset
4115 %! assert(y,1);
c827f5673321 move tests to individual source files
John W. Eaton <jwe@octave.org>
parents: 7351
diff changeset
4116
c827f5673321 move tests to individual source files
John W. Eaton <jwe@octave.org>
parents: 7351
diff changeset
4117 */
c827f5673321 move tests to individual source files
John W. Eaton <jwe@octave.org>
parents: 7351
diff changeset
4118
4661
12b6fbd57436 [project @ 2003-11-25 05:41:35 by jwe]
jwe
parents: 4615
diff changeset
4119 DEFUN (assignin, args, ,
4297
59a2ba0fb205 [project @ 2003-01-11 20:22:09 by jwe]
jwe
parents: 4246
diff changeset
4120 "-*- texinfo -*-\n\
59a2ba0fb205 [project @ 2003-01-11 20:22:09 by jwe]
jwe
parents: 4246
diff changeset
4121 @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
4122 Assign @var{value} to @var{varname} in context @var{context}, which\n\
59a2ba0fb205 [project @ 2003-01-11 20:22:09 by jwe]
jwe
parents: 4246
diff changeset
4123 may be either @code{\"base\"} or @code{\"caller\"}.\n\
59a2ba0fb205 [project @ 2003-01-11 20:22:09 by jwe]
jwe
parents: 4246
diff changeset
4124 @end deftypefn")
59a2ba0fb205 [project @ 2003-01-11 20:22:09 by jwe]
jwe
parents: 4246
diff changeset
4125 {
59a2ba0fb205 [project @ 2003-01-11 20:22:09 by jwe]
jwe
parents: 4246
diff changeset
4126 octave_value_list retval;
59a2ba0fb205 [project @ 2003-01-11 20:22:09 by jwe]
jwe
parents: 4246
diff changeset
4127
59a2ba0fb205 [project @ 2003-01-11 20:22:09 by jwe]
jwe
parents: 4246
diff changeset
4128 int nargin = args.length ();
59a2ba0fb205 [project @ 2003-01-11 20:22:09 by jwe]
jwe
parents: 4246
diff changeset
4129
59a2ba0fb205 [project @ 2003-01-11 20:22:09 by jwe]
jwe
parents: 4246
diff changeset
4130 if (nargin == 3)
59a2ba0fb205 [project @ 2003-01-11 20:22:09 by jwe]
jwe
parents: 4246
diff changeset
4131 {
59a2ba0fb205 [project @ 2003-01-11 20:22:09 by jwe]
jwe
parents: 4246
diff changeset
4132 std::string context = args(0).string_value ();
59a2ba0fb205 [project @ 2003-01-11 20:22:09 by jwe]
jwe
parents: 4246
diff changeset
4133
59a2ba0fb205 [project @ 2003-01-11 20:22:09 by jwe]
jwe
parents: 4246
diff changeset
4134 if (! error_state)
59a2ba0fb205 [project @ 2003-01-11 20:22:09 by jwe]
jwe
parents: 4246
diff changeset
4135 {
59a2ba0fb205 [project @ 2003-01-11 20:22:09 by jwe]
jwe
parents: 4246
diff changeset
4136 if (context == "caller")
7901
3e4c9b69069d call stack changes
John W. Eaton <jwe@octave.org>
parents: 7800
diff changeset
4137 octave_call_stack::goto_caller_frame ();
4297
59a2ba0fb205 [project @ 2003-01-11 20:22:09 by jwe]
jwe
parents: 4246
diff changeset
4138 else if (context == "base")
7901
3e4c9b69069d call stack changes
John W. Eaton <jwe@octave.org>
parents: 7800
diff changeset
4139 octave_call_stack::goto_base_frame ();
4297
59a2ba0fb205 [project @ 2003-01-11 20:22:09 by jwe]
jwe
parents: 4246
diff changeset
4140 else
59a2ba0fb205 [project @ 2003-01-11 20:22:09 by jwe]
jwe
parents: 4246
diff changeset
4141 error ("assignin: context must be \"caller\" or \"base\"");
59a2ba0fb205 [project @ 2003-01-11 20:22:09 by jwe]
jwe
parents: 4246
diff changeset
4142
59a2ba0fb205 [project @ 2003-01-11 20:22:09 by jwe]
jwe
parents: 4246
diff changeset
4143 if (! error_state)
59a2ba0fb205 [project @ 2003-01-11 20:22:09 by jwe]
jwe
parents: 4246
diff changeset
4144 {
7901
3e4c9b69069d call stack changes
John W. Eaton <jwe@octave.org>
parents: 7800
diff changeset
4145 unwind_protect::add (octave_call_stack::unwind_pop);
3e4c9b69069d call stack changes
John W. Eaton <jwe@octave.org>
parents: 7800
diff changeset
4146
4297
59a2ba0fb205 [project @ 2003-01-11 20:22:09 by jwe]
jwe
parents: 4246
diff changeset
4147 std::string nm = args(1).string_value ();
59a2ba0fb205 [project @ 2003-01-11 20:22:09 by jwe]
jwe
parents: 4246
diff changeset
4148
59a2ba0fb205 [project @ 2003-01-11 20:22:09 by jwe]
jwe
parents: 4246
diff changeset
4149 if (! error_state)
59a2ba0fb205 [project @ 2003-01-11 20:22:09 by jwe]
jwe
parents: 4246
diff changeset
4150 {
59a2ba0fb205 [project @ 2003-01-11 20:22:09 by jwe]
jwe
parents: 4246
diff changeset
4151 if (valid_identifier (nm))
8064
4f1ebb704545 fix invalid scope use in assignin
Jaroslav Hajek <highegg@gmail.com>
parents: 8033
diff changeset
4152 symbol_table::varref (nm) = args(2);
4297
59a2ba0fb205 [project @ 2003-01-11 20:22:09 by jwe]
jwe
parents: 4246
diff changeset
4153 else
59a2ba0fb205 [project @ 2003-01-11 20:22:09 by jwe]
jwe
parents: 4246
diff changeset
4154 error ("assignin: invalid variable name");
59a2ba0fb205 [project @ 2003-01-11 20:22:09 by jwe]
jwe
parents: 4246
diff changeset
4155 }
59a2ba0fb205 [project @ 2003-01-11 20:22:09 by jwe]
jwe
parents: 4246
diff changeset
4156 else
59a2ba0fb205 [project @ 2003-01-11 20:22:09 by jwe]
jwe
parents: 4246
diff changeset
4157 error ("assignin: expecting variable name as second argument");
59a2ba0fb205 [project @ 2003-01-11 20:22:09 by jwe]
jwe
parents: 4246
diff changeset
4158 }
59a2ba0fb205 [project @ 2003-01-11 20:22:09 by jwe]
jwe
parents: 4246
diff changeset
4159 }
59a2ba0fb205 [project @ 2003-01-11 20:22:09 by jwe]
jwe
parents: 4246
diff changeset
4160 else
59a2ba0fb205 [project @ 2003-01-11 20:22:09 by jwe]
jwe
parents: 4246
diff changeset
4161 error ("assignin: expecting string as first argument");
59a2ba0fb205 [project @ 2003-01-11 20:22:09 by jwe]
jwe
parents: 4246
diff changeset
4162 }
59a2ba0fb205 [project @ 2003-01-11 20:22:09 by jwe]
jwe
parents: 4246
diff changeset
4163 else
5823
080c08b192d8 [project @ 2006-05-19 05:32:17 by jwe]
jwe
parents: 5794
diff changeset
4164 print_usage ();
4297
59a2ba0fb205 [project @ 2003-01-11 20:22:09 by jwe]
jwe
parents: 4246
diff changeset
4165
59a2ba0fb205 [project @ 2003-01-11 20:22:09 by jwe]
jwe
parents: 4246
diff changeset
4166 return retval;
59a2ba0fb205 [project @ 2003-01-11 20:22:09 by jwe]
jwe
parents: 4246
diff changeset
4167 }
59a2ba0fb205 [project @ 2003-01-11 20:22:09 by jwe]
jwe
parents: 4246
diff changeset
4168
4245
610671be8792 [project @ 2002-12-28 04:02:31 by jwe]
jwe
parents: 4244
diff changeset
4169 DEFUN (evalin, args, nargout,
610671be8792 [project @ 2002-12-28 04:02:31 by jwe]
jwe
parents: 4244
diff changeset
4170 "-*- texinfo -*-\n\
610671be8792 [project @ 2002-12-28 04:02:31 by jwe]
jwe
parents: 4244
diff changeset
4171 @deftypefn {Built-in Function} {} evalin (@var{context}, @var{try}, @var{catch})\n\
610671be8792 [project @ 2002-12-28 04:02:31 by jwe]
jwe
parents: 4244
diff changeset
4172 Like @code{eval}, except that the expressions are evaluated in the\n\
610671be8792 [project @ 2002-12-28 04:02:31 by jwe]
jwe
parents: 4244
diff changeset
4173 context @var{context}, which may be either @code{\"caller\"} or\n\
4246
0253850a08d7 [project @ 2002-12-30 17:57:36 by jwe]
jwe
parents: 4245
diff changeset
4174 @code{\"base\"}.\n\
4245
610671be8792 [project @ 2002-12-28 04:02:31 by jwe]
jwe
parents: 4244
diff changeset
4175 @end deftypefn")
610671be8792 [project @ 2002-12-28 04:02:31 by jwe]
jwe
parents: 4244
diff changeset
4176 {
610671be8792 [project @ 2002-12-28 04:02:31 by jwe]
jwe
parents: 4244
diff changeset
4177 octave_value_list retval;
610671be8792 [project @ 2002-12-28 04:02:31 by jwe]
jwe
parents: 4244
diff changeset
4178
610671be8792 [project @ 2002-12-28 04:02:31 by jwe]
jwe
parents: 4244
diff changeset
4179 int nargin = args.length ();
610671be8792 [project @ 2002-12-28 04:02:31 by jwe]
jwe
parents: 4244
diff changeset
4180
610671be8792 [project @ 2002-12-28 04:02:31 by jwe]
jwe
parents: 4244
diff changeset
4181 if (nargin > 1)
610671be8792 [project @ 2002-12-28 04:02:31 by jwe]
jwe
parents: 4244
diff changeset
4182 {
610671be8792 [project @ 2002-12-28 04:02:31 by jwe]
jwe
parents: 4244
diff changeset
4183 std::string context = args(0).string_value ();
610671be8792 [project @ 2002-12-28 04:02:31 by jwe]
jwe
parents: 4244
diff changeset
4184
610671be8792 [project @ 2002-12-28 04:02:31 by jwe]
jwe
parents: 4244
diff changeset
4185 if (! error_state)
610671be8792 [project @ 2002-12-28 04:02:31 by jwe]
jwe
parents: 4244
diff changeset
4186 {
610671be8792 [project @ 2002-12-28 04:02:31 by jwe]
jwe
parents: 4244
diff changeset
4187 unwind_protect::begin_frame ("Fevalin");
610671be8792 [project @ 2002-12-28 04:02:31 by jwe]
jwe
parents: 4244
diff changeset
4188
610671be8792 [project @ 2002-12-28 04:02:31 by jwe]
jwe
parents: 4244
diff changeset
4189 if (context == "caller")
7901
3e4c9b69069d call stack changes
John W. Eaton <jwe@octave.org>
parents: 7800
diff changeset
4190 octave_call_stack::goto_caller_frame ();
4245
610671be8792 [project @ 2002-12-28 04:02:31 by jwe]
jwe
parents: 4244
diff changeset
4191 else if (context == "base")
7901
3e4c9b69069d call stack changes
John W. Eaton <jwe@octave.org>
parents: 7800
diff changeset
4192 octave_call_stack::goto_base_frame ();
4245
610671be8792 [project @ 2002-12-28 04:02:31 by jwe]
jwe
parents: 4244
diff changeset
4193 else
610671be8792 [project @ 2002-12-28 04:02:31 by jwe]
jwe
parents: 4244
diff changeset
4194 error ("evalin: context must be \"caller\" or \"base\"");
610671be8792 [project @ 2002-12-28 04:02:31 by jwe]
jwe
parents: 4244
diff changeset
4195
4297
59a2ba0fb205 [project @ 2003-01-11 20:22:09 by jwe]
jwe
parents: 4246
diff changeset
4196 if (! error_state)
4245
610671be8792 [project @ 2002-12-28 04:02:31 by jwe]
jwe
parents: 4244
diff changeset
4197 {
7901
3e4c9b69069d call stack changes
John W. Eaton <jwe@octave.org>
parents: 7800
diff changeset
4198 unwind_protect::add (octave_call_stack::unwind_pop);
7336
745a8299c2b5 [project @ 2007-12-28 20:56:55 by jwe]
jwe
parents: 7017
diff changeset
4199
4297
59a2ba0fb205 [project @ 2003-01-11 20:22:09 by jwe]
jwe
parents: 4246
diff changeset
4200 if (nargin > 2)
59a2ba0fb205 [project @ 2003-01-11 20:22:09 by jwe]
jwe
parents: 4246
diff changeset
4201 {
4699
5e2c68946f30 [project @ 2004-01-20 23:04:46 by jwe]
jwe
parents: 4678
diff changeset
4202 unwind_protect_int (buffer_error_messages);
5e2c68946f30 [project @ 2004-01-20 23:04:46 by jwe]
jwe
parents: 4678
diff changeset
4203 buffer_error_messages++;
4297
59a2ba0fb205 [project @ 2003-01-11 20:22:09 by jwe]
jwe
parents: 4246
diff changeset
4204 }
59a2ba0fb205 [project @ 2003-01-11 20:22:09 by jwe]
jwe
parents: 4246
diff changeset
4205
59a2ba0fb205 [project @ 2003-01-11 20:22:09 by jwe]
jwe
parents: 4246
diff changeset
4206 int parse_status = 0;
59a2ba0fb205 [project @ 2003-01-11 20:22:09 by jwe]
jwe
parents: 4246
diff changeset
4207
4463
322453495d75 [project @ 2003-07-12 05:03:33 by jwe]
jwe
parents: 4452
diff changeset
4208 octave_value_list tmp = eval_string (args(1), nargout > 0,
322453495d75 [project @ 2003-07-12 05:03:33 by jwe]
jwe
parents: 4452
diff changeset
4209 parse_status, nargout);
322453495d75 [project @ 2003-07-12 05:03:33 by jwe]
jwe
parents: 4452
diff changeset
4210
322453495d75 [project @ 2003-07-12 05:03:33 by jwe]
jwe
parents: 4452
diff changeset
4211 if (nargout > 0)
322453495d75 [project @ 2003-07-12 05:03:33 by jwe]
jwe
parents: 4452
diff changeset
4212 retval = tmp;
4297
59a2ba0fb205 [project @ 2003-01-11 20:22:09 by jwe]
jwe
parents: 4246
diff changeset
4213
59a2ba0fb205 [project @ 2003-01-11 20:22:09 by jwe]
jwe
parents: 4246
diff changeset
4214 if (nargin > 2 && (parse_status != 0 || error_state))
59a2ba0fb205 [project @ 2003-01-11 20:22:09 by jwe]
jwe
parents: 4246
diff changeset
4215 {
59a2ba0fb205 [project @ 2003-01-11 20:22:09 by jwe]
jwe
parents: 4246
diff changeset
4216 error_state = 0;
59a2ba0fb205 [project @ 2003-01-11 20:22:09 by jwe]
jwe
parents: 4246
diff changeset
4217
59a2ba0fb205 [project @ 2003-01-11 20:22:09 by jwe]
jwe
parents: 4246
diff changeset
4218 // Set up for letting the user print any messages from
59a2ba0fb205 [project @ 2003-01-11 20:22:09 by jwe]
jwe
parents: 4246
diff changeset
4219 // errors that occurred in the first part of this eval().
59a2ba0fb205 [project @ 2003-01-11 20:22:09 by jwe]
jwe
parents: 4246
diff changeset
4220
4699
5e2c68946f30 [project @ 2004-01-20 23:04:46 by jwe]
jwe
parents: 4678
diff changeset
4221 buffer_error_messages--;
4297
59a2ba0fb205 [project @ 2003-01-11 20:22:09 by jwe]
jwe
parents: 4246
diff changeset
4222
59a2ba0fb205 [project @ 2003-01-11 20:22:09 by jwe]
jwe
parents: 4246
diff changeset
4223 eval_string (args(2), 0, parse_status, nargout);
59a2ba0fb205 [project @ 2003-01-11 20:22:09 by jwe]
jwe
parents: 4246
diff changeset
4224
59a2ba0fb205 [project @ 2003-01-11 20:22:09 by jwe]
jwe
parents: 4246
diff changeset
4225 retval = octave_value_list ();
59a2ba0fb205 [project @ 2003-01-11 20:22:09 by jwe]
jwe
parents: 4246
diff changeset
4226 }
4245
610671be8792 [project @ 2002-12-28 04:02:31 by jwe]
jwe
parents: 4244
diff changeset
4227 }
610671be8792 [project @ 2002-12-28 04:02:31 by jwe]
jwe
parents: 4244
diff changeset
4228
610671be8792 [project @ 2002-12-28 04:02:31 by jwe]
jwe
parents: 4244
diff changeset
4229 unwind_protect::run_frame ("Fevalin");
610671be8792 [project @ 2002-12-28 04:02:31 by jwe]
jwe
parents: 4244
diff changeset
4230 }
610671be8792 [project @ 2002-12-28 04:02:31 by jwe]
jwe
parents: 4244
diff changeset
4231 else
610671be8792 [project @ 2002-12-28 04:02:31 by jwe]
jwe
parents: 4244
diff changeset
4232 error ("evalin: expecting string as first argument");
610671be8792 [project @ 2002-12-28 04:02:31 by jwe]
jwe
parents: 4244
diff changeset
4233 }
610671be8792 [project @ 2002-12-28 04:02:31 by jwe]
jwe
parents: 4244
diff changeset
4234 else
5823
080c08b192d8 [project @ 2006-05-19 05:32:17 by jwe]
jwe
parents: 5794
diff changeset
4235 print_usage ();
4245
610671be8792 [project @ 2002-12-28 04:02:31 by jwe]
jwe
parents: 4244
diff changeset
4236
610671be8792 [project @ 2002-12-28 04:02:31 by jwe]
jwe
parents: 4244
diff changeset
4237 return retval;
610671be8792 [project @ 2002-12-28 04:02:31 by jwe]
jwe
parents: 4244
diff changeset
4238 }
610671be8792 [project @ 2002-12-28 04:02:31 by jwe]
jwe
parents: 4244
diff changeset
4239
8311
7124bffc89c7 parse.y (F__parser_debug_flag__): New function.
John W. Eaton <jwe@octave.org>
parents: 8283
diff changeset
4240 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
4241 "-*- texinfo -*-\n\
7d48766c21a5 use consistent format for doc strings of internal functions
John W. Eaton <jwe@octave.org>
parents: 8746
diff changeset
4242 @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
4243 Undocumented internal function.\n\
7d48766c21a5 use consistent format for doc strings of internal functions
John W. Eaton <jwe@octave.org>
parents: 8746
diff changeset
4244 @end deftypefn")
8311
7124bffc89c7 parse.y (F__parser_debug_flag__): New function.
John W. Eaton <jwe@octave.org>
parents: 8283
diff changeset
4245 {
7124bffc89c7 parse.y (F__parser_debug_flag__): New function.
John W. Eaton <jwe@octave.org>
parents: 8283
diff changeset
4246 octave_value retval;
7124bffc89c7 parse.y (F__parser_debug_flag__): New function.
John W. Eaton <jwe@octave.org>
parents: 8283
diff changeset
4247
7124bffc89c7 parse.y (F__parser_debug_flag__): New function.
John W. Eaton <jwe@octave.org>
parents: 8283
diff changeset
4248 bool debug_flag = octave_debug;
7124bffc89c7 parse.y (F__parser_debug_flag__): New function.
John W. Eaton <jwe@octave.org>
parents: 8283
diff changeset
4249
7124bffc89c7 parse.y (F__parser_debug_flag__): New function.
John W. Eaton <jwe@octave.org>
parents: 8283
diff changeset
4250 retval = set_internal_variable (debug_flag, args, nargout,
7124bffc89c7 parse.y (F__parser_debug_flag__): New function.
John W. Eaton <jwe@octave.org>
parents: 8283
diff changeset
4251 "__parser_debug_flag__");
7124bffc89c7 parse.y (F__parser_debug_flag__): New function.
John W. Eaton <jwe@octave.org>
parents: 8283
diff changeset
4252
7124bffc89c7 parse.y (F__parser_debug_flag__): New function.
John W. Eaton <jwe@octave.org>
parents: 8283
diff changeset
4253 octave_debug = debug_flag;
7124bffc89c7 parse.y (F__parser_debug_flag__): New function.
John W. Eaton <jwe@octave.org>
parents: 8283
diff changeset
4254
7124bffc89c7 parse.y (F__parser_debug_flag__): New function.
John W. Eaton <jwe@octave.org>
parents: 8283
diff changeset
4255 return retval;
7124bffc89c7 parse.y (F__parser_debug_flag__): New function.
John W. Eaton <jwe@octave.org>
parents: 8283
diff changeset
4256 }
7124bffc89c7 parse.y (F__parser_debug_flag__): New function.
John W. Eaton <jwe@octave.org>
parents: 8283
diff changeset
4257
1994
c2d20f365b84 [project @ 1996-03-03 01:19:32 by jwe]
jwe
parents: 1884
diff changeset
4258 /*
c2d20f365b84 [project @ 1996-03-03 01:19:32 by jwe]
jwe
parents: 1884
diff changeset
4259 ;;; Local Variables: ***
c2d20f365b84 [project @ 1996-03-03 01:19:32 by jwe]
jwe
parents: 1884
diff changeset
4260 ;;; mode: text ***
c2d20f365b84 [project @ 1996-03-03 01:19:32 by jwe]
jwe
parents: 1884
diff changeset
4261 ;;; End: ***
c2d20f365b84 [project @ 1996-03-03 01:19:32 by jwe]
jwe
parents: 1884
diff changeset
4262 */