Mercurial > octave-nkf
annotate src/lex.l @ 9474:25ed2d6aacf6
Parse nested functions more accurately.
author | David Grundberg <individ@acc.umu.se> |
---|---|
date | Thu, 30 Jul 2009 11:52:58 -0400 |
parents | 29563379fa9b |
children | d9b25c5b8ee5 |
rev | line source |
---|---|
1994 | 1 /* |
1 | 2 |
7017 | 3 Copyright (C) 1993, 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001, |
8920 | 4 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009 |
5 John W. Eaton | |
1 | 6 |
7 This file is part of Octave. | |
8 | |
9 Octave is free software; you can redistribute it and/or modify it | |
10 under the terms of the GNU General Public License as published by the | |
7016 | 11 Free Software Foundation; either version 3 of the License, or (at your |
12 option) any later version. | |
1 | 13 |
14 Octave is distributed in the hope that it will be useful, but WITHOUT | |
15 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | |
16 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License | |
17 for more details. | |
18 | |
19 You should have received a copy of the GNU General Public License | |
7016 | 20 along with Octave; see the file COPYING. If not, see |
21 <http://www.gnu.org/licenses/>. | |
1 | 22 |
23 */ | |
24 | |
4753 | 25 %option prefix = "octave_" |
26 | |
4208 | 27 %s COMMAND_START |
28 %s MATRIX_START | |
4240 | 29 |
7715
5b4d278ec828
parse scripts completely before executing
John W. Eaton <jwe@octave.org>
parents:
7634
diff
changeset
|
30 %x SCRIPT_FILE_BEGIN |
9474
25ed2d6aacf6
Parse nested functions more accurately.
David Grundberg <individ@acc.umu.se>
parents:
9324
diff
changeset
|
31 %x FUNCTION_FILE_BEGIN |
1 | 32 |
33 %{ | |
240 | 34 #ifdef HAVE_CONFIG_H |
1220 | 35 #include <config.h> |
240 | 36 #endif |
37 | |
1341 | 38 #include <cctype> |
39 #include <cstring> | |
40 | |
8950
d865363208d6
include <iosfwd> instead of <iostream> in header files
John W. Eaton <jwe@octave.org>
parents:
8920
diff
changeset
|
41 #include <iostream> |
8001
ff9e7873f8ea
improve handling of command-style names in matrix_or_assign_lhs context
John W. Eaton <jwe@octave.org>
parents:
7898
diff
changeset
|
42 #include <set> |
5765 | 43 #include <sstream> |
1823 | 44 #include <string> |
4214 | 45 #include <stack> |
1823 | 46 |
4093 | 47 #ifdef HAVE_UNISTD_H |
48 #ifdef HAVE_SYS_TYPES_H | |
49 #include <sys/types.h> | |
50 #endif | |
51 #include <unistd.h> | |
52 #endif | |
53 | |
2926 | 54 #include "cmd-edit.h" |
4153 | 55 #include "quit.h" |
4910 | 56 #include "lo-mappers.h" |
2926 | 57 |
1497 | 58 // These would be alphabetical, but y.tab.h must be included before |
59 // oct-gperf.h and y.tab.h must be included after token.h and the tree | |
60 // class declarations. We can't include y.tab.h in oct-gperf.h | |
61 // because it may not be protected to allow it to be included multiple | |
62 // times. | |
63 | |
4264 | 64 #include "Cell.h" |
3665 | 65 #include "comment-list.h" |
2181 | 66 #include "defun.h" |
1355 | 67 #include "error.h" |
4910 | 68 #include "gripes.h" |
1351 | 69 #include "input.h" |
1355 | 70 #include "lex.h" |
2891 | 71 #include "ov.h" |
1355 | 72 #include "parse.h" |
2987 | 73 #include "pt-all.h" |
2891 | 74 #include "symtab.h" |
75 #include "token.h" | |
76 #include "toplev.h" | |
1355 | 77 #include "utils.h" |
78 #include "variables.h" | |
2492 | 79 #include <y.tab.h> |
80 #include <oct-gperf.h> | |
1 | 81 |
2716 | 82 #if ! (defined (FLEX_SCANNER) \ |
83 && defined (YY_FLEX_MAJOR_VERSION) && YY_FLEX_MAJOR_VERSION >= 2 \ | |
84 && defined (YY_FLEX_MINOR_VERSION) && YY_FLEX_MINOR_VERSION >= 5) | |
85 #error lex.l requires flex version 2.5.4 or later | |
86 #endif | |
87 | |
4753 | 88 #define yylval octave_lval |
89 | |
90 // Arrange to get input via readline. | |
91 | |
92 #ifdef YY_INPUT | |
93 #undef YY_INPUT | |
94 #endif | |
95 #define YY_INPUT(buf, result, max_size) \ | |
96 if ((result = octave_read (buf, max_size)) < 0) \ | |
97 YY_FATAL_ERROR ("octave_read () in flex scanner failed"); | |
98 | |
99 // Try to avoid crashing out completely on fatal scanner errors. | |
100 // The call to yy_fatal_error should never happen, but it avoids a | |
101 // `static function defined but not used' warning from gcc. | |
102 | |
103 #ifdef YY_FATAL_ERROR | |
104 #undef YY_FATAL_ERROR | |
105 #endif | |
106 #define YY_FATAL_ERROR(msg) \ | |
107 do \ | |
108 { \ | |
109 error (msg); \ | |
110 OCTAVE_QUIT; \ | |
111 yy_fatal_error (msg); \ | |
112 } \ | |
113 while (0) | |
114 | |
7722
c3bb0b7a4261
lex.l: allow tokens to be displayed when parsed
John W. Eaton <jwe@octave.org>
parents:
7720
diff
changeset
|
115 #define DISPLAY_TOK_AND_RETURN(tok) \ |
c3bb0b7a4261
lex.l: allow tokens to be displayed when parsed
John W. Eaton <jwe@octave.org>
parents:
7720
diff
changeset
|
116 do \ |
c3bb0b7a4261
lex.l: allow tokens to be displayed when parsed
John W. Eaton <jwe@octave.org>
parents:
7720
diff
changeset
|
117 { \ |
c3bb0b7a4261
lex.l: allow tokens to be displayed when parsed
John W. Eaton <jwe@octave.org>
parents:
7720
diff
changeset
|
118 int tok_val = tok; \ |
c3bb0b7a4261
lex.l: allow tokens to be displayed when parsed
John W. Eaton <jwe@octave.org>
parents:
7720
diff
changeset
|
119 if (Vdisplay_tokens) \ |
c3bb0b7a4261
lex.l: allow tokens to be displayed when parsed
John W. Eaton <jwe@octave.org>
parents:
7720
diff
changeset
|
120 display_token (tok_val); \ |
8535 | 121 if (lexer_debug_flag) \ |
122 { \ | |
123 std::cerr << "R: "; \ | |
124 display_token (tok_val); \ | |
125 std::cerr << std::endl; \ | |
126 } \ | |
7722
c3bb0b7a4261
lex.l: allow tokens to be displayed when parsed
John W. Eaton <jwe@octave.org>
parents:
7720
diff
changeset
|
127 return tok_val; \ |
c3bb0b7a4261
lex.l: allow tokens to be displayed when parsed
John W. Eaton <jwe@octave.org>
parents:
7720
diff
changeset
|
128 } \ |
c3bb0b7a4261
lex.l: allow tokens to be displayed when parsed
John W. Eaton <jwe@octave.org>
parents:
7720
diff
changeset
|
129 while (0) |
c3bb0b7a4261
lex.l: allow tokens to be displayed when parsed
John W. Eaton <jwe@octave.org>
parents:
7720
diff
changeset
|
130 |
4910 | 131 #define COUNT_TOK_AND_RETURN(tok) \ |
132 do \ | |
133 { \ | |
134 Vtoken_count++; \ | |
7722
c3bb0b7a4261
lex.l: allow tokens to be displayed when parsed
John W. Eaton <jwe@octave.org>
parents:
7720
diff
changeset
|
135 DISPLAY_TOK_AND_RETURN (tok); \ |
4910 | 136 } \ |
137 while (0) | |
138 | |
4753 | 139 #define TOK_RETURN(tok) \ |
140 do \ | |
141 { \ | |
142 current_input_column += yyleng; \ | |
143 lexer_flags.quote_is_transpose = false; \ | |
144 lexer_flags.convert_spaces_to_comma = true; \ | |
4910 | 145 COUNT_TOK_AND_RETURN (tok); \ |
4753 | 146 } \ |
147 while (0) | |
148 | |
149 #define TOK_PUSH_AND_RETURN(name, tok) \ | |
150 do \ | |
151 { \ | |
152 yylval.tok_val = new token (name, input_line_number, \ | |
153 current_input_column); \ | |
154 token_stack.push (yylval.tok_val); \ | |
155 TOK_RETURN (tok); \ | |
156 } \ | |
157 while (0) | |
158 | |
8746
5dd06f19e9be
handle commands in the lexer
John W. Eaton <jwe@octave.org>
parents:
8745
diff
changeset
|
159 #define BIN_OP_RETURN(tok, convert, bos) \ |
4753 | 160 do \ |
161 { \ | |
162 yylval.tok_val = new token (input_line_number, current_input_column); \ | |
163 token_stack.push (yylval.tok_val); \ | |
164 current_input_column += yyleng; \ | |
165 lexer_flags.quote_is_transpose = false; \ | |
166 lexer_flags.convert_spaces_to_comma = convert; \ | |
8745
6dc61981d18b
better handling of object indexing in lexer
John W. Eaton <jwe@octave.org>
parents:
8701
diff
changeset
|
167 lexer_flags.looking_for_object_index = false; \ |
8746
5dd06f19e9be
handle commands in the lexer
John W. Eaton <jwe@octave.org>
parents:
8745
diff
changeset
|
168 lexer_flags.at_beginning_of_statement = bos; \ |
4910 | 169 COUNT_TOK_AND_RETURN (tok); \ |
4753 | 170 } \ |
171 while (0) | |
172 | |
8746
5dd06f19e9be
handle commands in the lexer
John W. Eaton <jwe@octave.org>
parents:
8745
diff
changeset
|
173 #define XBIN_OP_RETURN(tok, convert, bos) \ |
4753 | 174 do \ |
175 { \ | |
8745
6dc61981d18b
better handling of object indexing in lexer
John W. Eaton <jwe@octave.org>
parents:
8701
diff
changeset
|
176 gripe_matlab_incompatible_operator (yytext); \ |
8746
5dd06f19e9be
handle commands in the lexer
John W. Eaton <jwe@octave.org>
parents:
8745
diff
changeset
|
177 BIN_OP_RETURN (tok, convert, bos); \ |
4753 | 178 } \ |
179 while (0) | |
180 | |
8535 | 181 #define LEXER_DEBUG(pattern) \ |
182 do \ | |
183 { \ | |
184 if (lexer_debug_flag) \ | |
185 lexer_debug (pattern, yytext); \ | |
186 } \ | |
187 while (0) | |
188 | |
3883 | 189 // TRUE means that we have encountered EOF on the input stream. |
190 bool parser_end_of_input = false; | |
191 | |
1826 | 192 // Flags that need to be shared between the lexer and parser. |
193 lexical_feedback lexer_flags; | |
194 | |
1351 | 195 // Stack to hold tokens so that we can delete them when the parser is |
196 // reset and avoid growing forever just because we are stashing some | |
197 // information. This has to appear before lex.h is included, because | |
198 // one of the macros defined there uses token_stack. | |
2614 | 199 // |
5775 | 200 // FIXME -- this should really be static, but that causes |
2614 | 201 // problems on some systems. |
4214 | 202 std::stack <token*> token_stack; |
1351 | 203 |
1826 | 204 // Did eat_whitespace() eat a space or tab, or a newline, or both? |
1 | 205 |
1826 | 206 typedef int yum_yum; |
1 | 207 |
1826 | 208 const yum_yum ATE_NOTHING = 0; |
209 const yum_yum ATE_SPACE_OR_TAB = 1; | |
210 const yum_yum ATE_NEWLINE = 2; | |
1088 | 211 |
3351 | 212 // Is the closest nesting level a square bracket, squiggly brace or a paren? |
1826 | 213 |
4214 | 214 class bracket_brace_paren_nesting_level |
1826 | 215 { |
216 public: | |
217 | |
4214 | 218 bracket_brace_paren_nesting_level (void) : context () { } |
1826 | 219 |
3351 | 220 ~bracket_brace_paren_nesting_level (void) { } |
221 | |
4214 | 222 void bracket (void) { context.push (BRACKET); } |
223 bool is_bracket (void) | |
224 { return ! context.empty () && context.top () == BRACKET; } | |
225 | |
226 void brace (void) { context.push (BRACE); } | |
227 bool is_brace (void) | |
228 { return ! context.empty () && context.top () == BRACE; } | |
229 | |
230 void paren (void) { context.push (PAREN); } | |
231 bool is_paren (void) | |
232 { return ! context.empty () && context.top () == PAREN; } | |
233 | |
4608 | 234 bool is_bracket_or_brace (void) |
235 { return (! context.empty () | |
236 && (context.top () == BRACKET || context.top () == BRACE)); } | |
237 | |
4214 | 238 bool none (void) { return context.empty (); } |
239 | |
240 void remove (void) { if (! context.empty ()) context.pop (); } | |
241 | |
242 void clear (void) { while (! context.empty ()) context.pop (); } | |
1826 | 243 |
244 private: | |
245 | |
4214 | 246 std::stack<int> context; |
247 | |
5225 | 248 static const int BRACKET; |
249 static const int BRACE; | |
250 static const int PAREN; | |
1826 | 251 |
3351 | 252 bracket_brace_paren_nesting_level (const bracket_brace_paren_nesting_level&); |
1826 | 253 |
3351 | 254 bracket_brace_paren_nesting_level& |
255 operator = (const bracket_brace_paren_nesting_level&); | |
1826 | 256 }; |
257 | |
5225 | 258 const int bracket_brace_paren_nesting_level::BRACKET = 1; |
259 const int bracket_brace_paren_nesting_level::BRACE = 2; | |
260 const int bracket_brace_paren_nesting_level::PAREN = 3; | |
261 | |
3351 | 262 static bracket_brace_paren_nesting_level nesting_level; |
1 | 263 |
7722
c3bb0b7a4261
lex.l: allow tokens to be displayed when parsed
John W. Eaton <jwe@octave.org>
parents:
7720
diff
changeset
|
264 static bool Vdisplay_tokens = false; |
c3bb0b7a4261
lex.l: allow tokens to be displayed when parsed
John W. Eaton <jwe@octave.org>
parents:
7720
diff
changeset
|
265 |
4910 | 266 static unsigned int Vtoken_count = 0; |
267 | |
7723
74f5e0c7de9e
first pass at handling block comments
John W. Eaton <jwe@octave.org>
parents:
7722
diff
changeset
|
268 // The start state that was in effect when the beginning of a block |
74f5e0c7de9e
first pass at handling block comments
John W. Eaton <jwe@octave.org>
parents:
7722
diff
changeset
|
269 // comment was noticed. |
74f5e0c7de9e
first pass at handling block comments
John W. Eaton <jwe@octave.org>
parents:
7722
diff
changeset
|
270 static int block_comment_nesting_level = 0; |
74f5e0c7de9e
first pass at handling block comments
John W. Eaton <jwe@octave.org>
parents:
7722
diff
changeset
|
271 |
8535 | 272 // Internal variable for lexer debugging state. |
273 static bool lexer_debug_flag = false; | |
274 | |
146 | 275 // Forward declarations for functions defined at the bottom of this |
276 // file. | |
277 | |
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
|
278 static int text_yyinput (void); |
8447
adab48231a03
make input_line_number work again
John W. Eaton <jwe@octave.org>
parents:
8312
diff
changeset
|
279 static void xunput (char c, char *buf); |
1 | 280 static void fixup_column_count (char *s); |
146 | 281 static void do_comma_insert_check (void); |
4867 | 282 static int is_keyword_token (const std::string& s); |
7723
74f5e0c7de9e
first pass at handling block comments
John W. Eaton <jwe@octave.org>
parents:
7722
diff
changeset
|
283 static int process_comment (bool start_in_block, bool& eof); |
2857 | 284 static bool match_any (char c, const char *s); |
3263 | 285 static bool next_token_is_sep_op (void); |
3246 | 286 static bool next_token_is_bin_op (bool spc_prev); |
287 static bool next_token_is_postfix_unary_op (bool spc_prev); | |
3523 | 288 static std::string strip_trailing_whitespace (char *s); |
3246 | 289 static void handle_number (void); |
8746
5dd06f19e9be
handle commands in the lexer
John W. Eaton <jwe@octave.org>
parents:
8745
diff
changeset
|
290 static int handle_string (char delim); |
4612 | 291 static int handle_close_bracket (bool spc_gobbled, int bracket_type); |
3974 | 292 static int handle_identifier (void); |
3096 | 293 static bool have_continuation (bool trailing_comments_ok = true); |
294 static bool have_ellipsis_continuation (bool trailing_comments_ok = true); | |
3665 | 295 static void scan_for_comments (const char *); |
1826 | 296 static yum_yum eat_whitespace (void); |
297 static yum_yum eat_continuation (void); | |
3388 | 298 static void maybe_warn_separator_insert (char sep); |
3400 | 299 static void gripe_single_quote_string (void); |
4037 | 300 static void gripe_matlab_incompatible (const std::string& msg); |
301 static void maybe_gripe_matlab_incompatible_comment (char c); | |
302 static void gripe_matlab_incompatible_continuation (void); | |
303 static void gripe_matlab_incompatible_operator (const std::string& op); | |
7722
c3bb0b7a4261
lex.l: allow tokens to be displayed when parsed
John W. Eaton <jwe@octave.org>
parents:
7720
diff
changeset
|
304 static void display_token (int tok); |
8535 | 305 static void lexer_debug (const char *pattern, const char *text); |
1 | 306 |
307 %} | |
308 | |
309 D [0-9] | |
310 S [ \t] | |
5570 | 311 NL ((\n)|(\r)|(\r\n)) |
2042 | 312 SNL ({S}|{NL}) |
1 | 313 EL (\.\.\.) |
967 | 314 BS (\\) |
315 CONT ({EL}|{BS}) | |
1 | 316 Im [iIjJ] |
967 | 317 CCHAR [#%] |
318 COMMENT ({CCHAR}.*{NL}) | |
319 SNLCMT ({SNL}|{COMMENT}) | |
320 NOT ((\~)|(\!)) | |
4037 | 321 POW ((\*\*)|(\^)) |
322 EPOW (\.{POW}) | |
5290 | 323 IDENT ([_$a-zA-Z][_$a-zA-Z0-9]*) |
1 | 324 EXPON ([DdEe][+-]?{D}+) |
3220 | 325 NUMBER (({D}+\.?{D}*{EXPON}?)|(\.{D}+{EXPON}?)|(0[xX][0-9a-fA-F]+)) |
1 | 326 %% |
327 | |
9474
25ed2d6aacf6
Parse nested functions more accurately.
David Grundberg <individ@acc.umu.se>
parents:
9324
diff
changeset
|
328 %{ |
25ed2d6aacf6
Parse nested functions more accurately.
David Grundberg <individ@acc.umu.se>
parents:
9324
diff
changeset
|
329 // Make script and function files start with a bogus token. This makes |
25ed2d6aacf6
Parse nested functions more accurately.
David Grundberg <individ@acc.umu.se>
parents:
9324
diff
changeset
|
330 // the parser go down a special path. |
25ed2d6aacf6
Parse nested functions more accurately.
David Grundberg <individ@acc.umu.se>
parents:
9324
diff
changeset
|
331 %} |
25ed2d6aacf6
Parse nested functions more accurately.
David Grundberg <individ@acc.umu.se>
parents:
9324
diff
changeset
|
332 |
7715
5b4d278ec828
parse scripts completely before executing
John W. Eaton <jwe@octave.org>
parents:
7634
diff
changeset
|
333 <SCRIPT_FILE_BEGIN>. { |
8535 | 334 LEXER_DEBUG ("<SCRIPT_FILE_BEGIN>."); |
335 | |
7715
5b4d278ec828
parse scripts completely before executing
John W. Eaton <jwe@octave.org>
parents:
7634
diff
changeset
|
336 BEGIN (INITIAL); |
8447
adab48231a03
make input_line_number work again
John W. Eaton <jwe@octave.org>
parents:
8312
diff
changeset
|
337 xunput (yytext[0], yytext); |
9474
25ed2d6aacf6
Parse nested functions more accurately.
David Grundberg <individ@acc.umu.se>
parents:
9324
diff
changeset
|
338 COUNT_TOK_AND_RETURN (SCRIPT_FILE); |
7715
5b4d278ec828
parse scripts completely before executing
John W. Eaton <jwe@octave.org>
parents:
7634
diff
changeset
|
339 } |
5b4d278ec828
parse scripts completely before executing
John W. Eaton <jwe@octave.org>
parents:
7634
diff
changeset
|
340 |
9474
25ed2d6aacf6
Parse nested functions more accurately.
David Grundberg <individ@acc.umu.se>
parents:
9324
diff
changeset
|
341 <FUNCTION_FILE_BEGIN>. { |
25ed2d6aacf6
Parse nested functions more accurately.
David Grundberg <individ@acc.umu.se>
parents:
9324
diff
changeset
|
342 LEXER_DEBUG ("<FUNCTION_FILE_BEGIN>."); |
8535 | 343 |
4323 | 344 BEGIN (INITIAL); |
8447
adab48231a03
make input_line_number work again
John W. Eaton <jwe@octave.org>
parents:
8312
diff
changeset
|
345 xunput (yytext[0], yytext); |
9474
25ed2d6aacf6
Parse nested functions more accurately.
David Grundberg <individ@acc.umu.se>
parents:
9324
diff
changeset
|
346 COUNT_TOK_AND_RETURN (FUNCTION_FILE); |
4238 | 347 } |
348 | |
968 | 349 %{ |
8746
5dd06f19e9be
handle commands in the lexer
John W. Eaton <jwe@octave.org>
parents:
8745
diff
changeset
|
350 // Help and other command-style functions. |
968 | 351 %} |
352 | |
4208 | 353 <COMMAND_START>{NL} { |
8535 | 354 LEXER_DEBUG ("<COMMAND_START>{NL}"); |
355 | |
4323 | 356 BEGIN (INITIAL); |
8447
adab48231a03
make input_line_number work again
John W. Eaton <jwe@octave.org>
parents:
8312
diff
changeset
|
357 input_line_number++; |
967 | 358 current_input_column = 1; |
8745
6dc61981d18b
better handling of object indexing in lexer
John W. Eaton <jwe@octave.org>
parents:
8701
diff
changeset
|
359 |
2857 | 360 lexer_flags.quote_is_transpose = false; |
361 lexer_flags.convert_spaces_to_comma = true; | |
8745
6dc61981d18b
better handling of object indexing in lexer
John W. Eaton <jwe@octave.org>
parents:
8701
diff
changeset
|
362 lexer_flags.looking_for_object_index = false; |
8746
5dd06f19e9be
handle commands in the lexer
John W. Eaton <jwe@octave.org>
parents:
8745
diff
changeset
|
363 lexer_flags.at_beginning_of_statement = true; |
8745
6dc61981d18b
better handling of object indexing in lexer
John W. Eaton <jwe@octave.org>
parents:
8701
diff
changeset
|
364 |
4910 | 365 COUNT_TOK_AND_RETURN ('\n'); |
967 | 366 } |
1 | 367 |
4208 | 368 <COMMAND_START>[\;\,] { |
8535 | 369 LEXER_DEBUG ("<COMMAND_START>[\\;\\,]"); |
370 | |
8745
6dc61981d18b
better handling of object indexing in lexer
John W. Eaton <jwe@octave.org>
parents:
8701
diff
changeset
|
371 lexer_flags.looking_for_object_index = false; |
8746
5dd06f19e9be
handle commands in the lexer
John W. Eaton <jwe@octave.org>
parents:
8745
diff
changeset
|
372 lexer_flags.at_beginning_of_statement = true; |
5102 | 373 |
374 BEGIN (INITIAL); | |
375 | |
376 if (strcmp (yytext, ",") == 0) | |
377 TOK_RETURN (','); | |
967 | 378 else |
5102 | 379 TOK_RETURN (';'); |
967 | 380 } |
1 | 381 |
4208 | 382 <COMMAND_START>[\"\'] { |
8535 | 383 LEXER_DEBUG ("<COMMAND_START>[\\\"\\']"); |
384 | |
8746
5dd06f19e9be
handle commands in the lexer
John W. Eaton <jwe@octave.org>
parents:
8745
diff
changeset
|
385 lexer_flags.at_beginning_of_statement = false; |
5dd06f19e9be
handle commands in the lexer
John W. Eaton <jwe@octave.org>
parents:
8745
diff
changeset
|
386 |
975 | 387 current_input_column++; |
8746
5dd06f19e9be
handle commands in the lexer
John W. Eaton <jwe@octave.org>
parents:
8745
diff
changeset
|
388 int tok = handle_string (yytext[0]); |
8745
6dc61981d18b
better handling of object indexing in lexer
John W. Eaton <jwe@octave.org>
parents:
8701
diff
changeset
|
389 |
7722
c3bb0b7a4261
lex.l: allow tokens to be displayed when parsed
John W. Eaton <jwe@octave.org>
parents:
7720
diff
changeset
|
390 COUNT_TOK_AND_RETURN (tok); |
975 | 391 } |
392 | |
4923 | 393 <COMMAND_START>[^#% \t\r\n\;\,\"\'][^ \t\r\n\;\,]*{S}* { |
8535 | 394 LEXER_DEBUG ("<COMMAND_START>[^#% \\t\\r\\n\\;\\,\\\"\\'][^ \\t\\r\\n\\;\\,]*{S}*"); |
395 | |
3523 | 396 std::string tok = strip_trailing_whitespace (yytext); |
8745
6dc61981d18b
better handling of object indexing in lexer
John W. Eaton <jwe@octave.org>
parents:
8701
diff
changeset
|
397 |
6dc61981d18b
better handling of object indexing in lexer
John W. Eaton <jwe@octave.org>
parents:
8701
diff
changeset
|
398 lexer_flags.looking_for_object_index = false; |
8746
5dd06f19e9be
handle commands in the lexer
John W. Eaton <jwe@octave.org>
parents:
8745
diff
changeset
|
399 lexer_flags.at_beginning_of_statement = false; |
8745
6dc61981d18b
better handling of object indexing in lexer
John W. Eaton <jwe@octave.org>
parents:
8701
diff
changeset
|
400 |
5279 | 401 TOK_PUSH_AND_RETURN (tok, SQ_STRING); |
967 | 402 } |
1 | 403 |
968 | 404 %{ |
1 | 405 // For this and the next two rules, we're looking at ']', and we |
971 | 406 // need to know if the next token is `=' or `=='. |
1 | 407 // |
408 // It would have been so much easier if the delimiters were simply | |
409 // different for the expression on the left hand side of the equals | |
410 // operator. | |
971 | 411 // |
412 // It's also a pain in the ass to decide whether to insert a comma | |
413 // after seeing a ']' character... | |
7723
74f5e0c7de9e
first pass at handling block comments
John W. Eaton <jwe@octave.org>
parents:
7722
diff
changeset
|
414 |
74f5e0c7de9e
first pass at handling block comments
John W. Eaton <jwe@octave.org>
parents:
7722
diff
changeset
|
415 // FIXME -- we need to handle block comments here. |
968 | 416 %} |
417 | |
4208 | 418 <MATRIX_START>{SNLCMT}*\]{S}* { |
8535 | 419 LEXER_DEBUG ("<MATRIX_START>{SNLCMT}*\\]{S}*"); |
420 | |
3665 | 421 scan_for_comments (yytext); |
1001 | 422 fixup_column_count (yytext); |
8745
6dc61981d18b
better handling of object indexing in lexer
John W. Eaton <jwe@octave.org>
parents:
8701
diff
changeset
|
423 |
6dc61981d18b
better handling of object indexing in lexer
John W. Eaton <jwe@octave.org>
parents:
8701
diff
changeset
|
424 lexer_flags.looking_at_object_index.pop_front (); |
6dc61981d18b
better handling of object indexing in lexer
John W. Eaton <jwe@octave.org>
parents:
8701
diff
changeset
|
425 |
6dc61981d18b
better handling of object indexing in lexer
John W. Eaton <jwe@octave.org>
parents:
8701
diff
changeset
|
426 lexer_flags.looking_for_object_index = true; |
8746
5dd06f19e9be
handle commands in the lexer
John W. Eaton <jwe@octave.org>
parents:
8745
diff
changeset
|
427 lexer_flags.at_beginning_of_statement = false; |
8745
6dc61981d18b
better handling of object indexing in lexer
John W. Eaton <jwe@octave.org>
parents:
8701
diff
changeset
|
428 |
1001 | 429 int c = yytext[yyleng-1]; |
430 int cont_is_spc = eat_continuation (); | |
4608 | 431 bool spc_gobbled = (cont_is_spc || c == ' ' || c == '\t'); |
5345 | 432 int tok_to_return = handle_close_bracket (spc_gobbled, ']'); |
8745
6dc61981d18b
better handling of object indexing in lexer
John W. Eaton <jwe@octave.org>
parents:
8701
diff
changeset
|
433 |
5345 | 434 if (spc_gobbled) |
8745
6dc61981d18b
better handling of object indexing in lexer
John W. Eaton <jwe@octave.org>
parents:
8701
diff
changeset
|
435 xunput (' ', yytext); |
6dc61981d18b
better handling of object indexing in lexer
John W. Eaton <jwe@octave.org>
parents:
8701
diff
changeset
|
436 |
5345 | 437 COUNT_TOK_AND_RETURN (tok_to_return); |
4608 | 438 } |
439 | |
7723
74f5e0c7de9e
first pass at handling block comments
John W. Eaton <jwe@octave.org>
parents:
7722
diff
changeset
|
440 %{ |
74f5e0c7de9e
first pass at handling block comments
John W. Eaton <jwe@octave.org>
parents:
7722
diff
changeset
|
441 // FIXME -- we need to handle block comments here. |
74f5e0c7de9e
first pass at handling block comments
John W. Eaton <jwe@octave.org>
parents:
7722
diff
changeset
|
442 %} |
74f5e0c7de9e
first pass at handling block comments
John W. Eaton <jwe@octave.org>
parents:
7722
diff
changeset
|
443 |
4608 | 444 <MATRIX_START>{SNLCMT}*\}{S}* { |
8535 | 445 LEXER_DEBUG ("<MATRIX_START>{SNLCMT}*\\}{S}*"); |
446 | |
4608 | 447 scan_for_comments (yytext); |
448 fixup_column_count (yytext); | |
8745
6dc61981d18b
better handling of object indexing in lexer
John W. Eaton <jwe@octave.org>
parents:
8701
diff
changeset
|
449 |
6dc61981d18b
better handling of object indexing in lexer
John W. Eaton <jwe@octave.org>
parents:
8701
diff
changeset
|
450 lexer_flags.looking_at_object_index.pop_front (); |
6dc61981d18b
better handling of object indexing in lexer
John W. Eaton <jwe@octave.org>
parents:
8701
diff
changeset
|
451 |
6dc61981d18b
better handling of object indexing in lexer
John W. Eaton <jwe@octave.org>
parents:
8701
diff
changeset
|
452 lexer_flags.looking_for_object_index = true; |
8746
5dd06f19e9be
handle commands in the lexer
John W. Eaton <jwe@octave.org>
parents:
8745
diff
changeset
|
453 lexer_flags.at_beginning_of_statement = false; |
8745
6dc61981d18b
better handling of object indexing in lexer
John W. Eaton <jwe@octave.org>
parents:
8701
diff
changeset
|
454 |
4608 | 455 int c = yytext[yyleng-1]; |
456 int cont_is_spc = eat_continuation (); | |
457 bool spc_gobbled = (cont_is_spc || c == ' ' || c == '\t'); | |
5345 | 458 int tok_to_return = handle_close_bracket (spc_gobbled, '}'); |
8745
6dc61981d18b
better handling of object indexing in lexer
John W. Eaton <jwe@octave.org>
parents:
8701
diff
changeset
|
459 |
5345 | 460 if (spc_gobbled) |
8745
6dc61981d18b
better handling of object indexing in lexer
John W. Eaton <jwe@octave.org>
parents:
8701
diff
changeset
|
461 xunput (' ', yytext); |
6dc61981d18b
better handling of object indexing in lexer
John W. Eaton <jwe@octave.org>
parents:
8701
diff
changeset
|
462 |
5345 | 463 COUNT_TOK_AND_RETURN (tok_to_return); |
967 | 464 } |
1 | 465 |
968 | 466 %{ |
1088 | 467 // Commas are element separators in matrix constants. If we don't |
468 // check for continuations here we can end up inserting too many | |
469 // commas. | |
968 | 470 %} |
471 | |
4208 | 472 <MATRIX_START>{S}*\,{S}* { |
8535 | 473 LEXER_DEBUG ("<MATRIX_START>{S}*\\,{S}*"); |
474 | |
1088 | 475 current_input_column += yyleng; |
3388 | 476 |
1088 | 477 int tmp = eat_continuation (); |
3388 | 478 |
2857 | 479 lexer_flags.quote_is_transpose = false; |
480 lexer_flags.convert_spaces_to_comma = true; | |
8745
6dc61981d18b
better handling of object indexing in lexer
John W. Eaton <jwe@octave.org>
parents:
8701
diff
changeset
|
481 lexer_flags.looking_for_object_index = false; |
8746
5dd06f19e9be
handle commands in the lexer
John W. Eaton <jwe@octave.org>
parents:
8745
diff
changeset
|
482 lexer_flags.at_beginning_of_statement = false; |
8745
6dc61981d18b
better handling of object indexing in lexer
John W. Eaton <jwe@octave.org>
parents:
8701
diff
changeset
|
483 |
6dc61981d18b
better handling of object indexing in lexer
John W. Eaton <jwe@octave.org>
parents:
8701
diff
changeset
|
484 if (! lexer_flags.looking_at_object_index.front ()) |
3388 | 485 { |
8745
6dc61981d18b
better handling of object indexing in lexer
John W. Eaton <jwe@octave.org>
parents:
8701
diff
changeset
|
486 if ((tmp & ATE_NEWLINE) == ATE_NEWLINE) |
6dc61981d18b
better handling of object indexing in lexer
John W. Eaton <jwe@octave.org>
parents:
8701
diff
changeset
|
487 { |
6dc61981d18b
better handling of object indexing in lexer
John W. Eaton <jwe@octave.org>
parents:
8701
diff
changeset
|
488 maybe_warn_separator_insert (';'); |
6dc61981d18b
better handling of object indexing in lexer
John W. Eaton <jwe@octave.org>
parents:
8701
diff
changeset
|
489 |
6dc61981d18b
better handling of object indexing in lexer
John W. Eaton <jwe@octave.org>
parents:
8701
diff
changeset
|
490 xunput (';', yytext); |
6dc61981d18b
better handling of object indexing in lexer
John W. Eaton <jwe@octave.org>
parents:
8701
diff
changeset
|
491 } |
3388 | 492 } |
493 | |
4910 | 494 COUNT_TOK_AND_RETURN (','); |
967 | 495 } |
1 | 496 |
968 | 497 %{ |
498 // In some cases, spaces in matrix constants can turn into commas. | |
499 // If commas are required, spaces are not important in matrix | |
1088 | 500 // constants so we just eat them. If we don't check for continuations |
501 // here we can end up inserting too many commas. | |
968 | 502 %} |
430 | 503 |
4208 | 504 <MATRIX_START>{S}+ { |
8535 | 505 LEXER_DEBUG ("<MATRIX_START>{S}+"); |
506 | |
1088 | 507 current_input_column += yyleng; |
3388 | 508 |
8746
5dd06f19e9be
handle commands in the lexer
John W. Eaton <jwe@octave.org>
parents:
8745
diff
changeset
|
509 lexer_flags.at_beginning_of_statement = false; |
5dd06f19e9be
handle commands in the lexer
John W. Eaton <jwe@octave.org>
parents:
8745
diff
changeset
|
510 |
3388 | 511 int tmp = eat_continuation (); |
8745
6dc61981d18b
better handling of object indexing in lexer
John W. Eaton <jwe@octave.org>
parents:
8701
diff
changeset
|
512 |
6dc61981d18b
better handling of object indexing in lexer
John W. Eaton <jwe@octave.org>
parents:
8701
diff
changeset
|
513 if (! lexer_flags.looking_at_object_index.front ()) |
967 | 514 { |
8745
6dc61981d18b
better handling of object indexing in lexer
John W. Eaton <jwe@octave.org>
parents:
8701
diff
changeset
|
515 bool bin_op = next_token_is_bin_op (true); |
6dc61981d18b
better handling of object indexing in lexer
John W. Eaton <jwe@octave.org>
parents:
8701
diff
changeset
|
516 bool postfix_un_op = next_token_is_postfix_unary_op (true); |
6dc61981d18b
better handling of object indexing in lexer
John W. Eaton <jwe@octave.org>
parents:
8701
diff
changeset
|
517 bool sep_op = next_token_is_sep_op (); |
6dc61981d18b
better handling of object indexing in lexer
John W. Eaton <jwe@octave.org>
parents:
8701
diff
changeset
|
518 |
6dc61981d18b
better handling of object indexing in lexer
John W. Eaton <jwe@octave.org>
parents:
8701
diff
changeset
|
519 if (! (postfix_un_op || bin_op || sep_op) |
6dc61981d18b
better handling of object indexing in lexer
John W. Eaton <jwe@octave.org>
parents:
8701
diff
changeset
|
520 && nesting_level.is_bracket_or_brace () |
6dc61981d18b
better handling of object indexing in lexer
John W. Eaton <jwe@octave.org>
parents:
8701
diff
changeset
|
521 && lexer_flags.convert_spaces_to_comma) |
3388 | 522 { |
8745
6dc61981d18b
better handling of object indexing in lexer
John W. Eaton <jwe@octave.org>
parents:
8701
diff
changeset
|
523 if ((tmp & ATE_NEWLINE) == ATE_NEWLINE) |
6dc61981d18b
better handling of object indexing in lexer
John W. Eaton <jwe@octave.org>
parents:
8701
diff
changeset
|
524 { |
6dc61981d18b
better handling of object indexing in lexer
John W. Eaton <jwe@octave.org>
parents:
8701
diff
changeset
|
525 maybe_warn_separator_insert (';'); |
6dc61981d18b
better handling of object indexing in lexer
John W. Eaton <jwe@octave.org>
parents:
8701
diff
changeset
|
526 |
6dc61981d18b
better handling of object indexing in lexer
John W. Eaton <jwe@octave.org>
parents:
8701
diff
changeset
|
527 xunput (';', yytext); |
6dc61981d18b
better handling of object indexing in lexer
John W. Eaton <jwe@octave.org>
parents:
8701
diff
changeset
|
528 } |
6dc61981d18b
better handling of object indexing in lexer
John W. Eaton <jwe@octave.org>
parents:
8701
diff
changeset
|
529 |
6dc61981d18b
better handling of object indexing in lexer
John W. Eaton <jwe@octave.org>
parents:
8701
diff
changeset
|
530 lexer_flags.quote_is_transpose = false; |
6dc61981d18b
better handling of object indexing in lexer
John W. Eaton <jwe@octave.org>
parents:
8701
diff
changeset
|
531 lexer_flags.convert_spaces_to_comma = true; |
6dc61981d18b
better handling of object indexing in lexer
John W. Eaton <jwe@octave.org>
parents:
8701
diff
changeset
|
532 |
6dc61981d18b
better handling of object indexing in lexer
John W. Eaton <jwe@octave.org>
parents:
8701
diff
changeset
|
533 maybe_warn_separator_insert (','); |
6dc61981d18b
better handling of object indexing in lexer
John W. Eaton <jwe@octave.org>
parents:
8701
diff
changeset
|
534 |
6dc61981d18b
better handling of object indexing in lexer
John W. Eaton <jwe@octave.org>
parents:
8701
diff
changeset
|
535 COUNT_TOK_AND_RETURN (','); |
3388 | 536 } |
967 | 537 } |
538 } | |
430 | 539 |
968 | 540 %{ |
1088 | 541 // Semicolons are handled as row seprators in matrix constants. If we |
542 // don't eat whitespace here we can end up inserting too many | |
543 // semicolons. | |
7723
74f5e0c7de9e
first pass at handling block comments
John W. Eaton <jwe@octave.org>
parents:
7722
diff
changeset
|
544 |
74f5e0c7de9e
first pass at handling block comments
John W. Eaton <jwe@octave.org>
parents:
7722
diff
changeset
|
545 // FIXME -- we need to handle block comments here. |
968 | 546 %} |
547 | |
4208 | 548 <MATRIX_START>{SNLCMT}*;{SNLCMT}* { |
8535 | 549 LEXER_DEBUG ("<MATRIX_START>{SNLCMT}*;{SNLCMT}*"); |
550 | |
3665 | 551 scan_for_comments (yytext); |
967 | 552 fixup_column_count (yytext); |
1001 | 553 eat_whitespace (); |
8745
6dc61981d18b
better handling of object indexing in lexer
John W. Eaton <jwe@octave.org>
parents:
8701
diff
changeset
|
554 |
2857 | 555 lexer_flags.quote_is_transpose = false; |
556 lexer_flags.convert_spaces_to_comma = true; | |
8745
6dc61981d18b
better handling of object indexing in lexer
John W. Eaton <jwe@octave.org>
parents:
8701
diff
changeset
|
557 lexer_flags.looking_for_object_index = false; |
8746
5dd06f19e9be
handle commands in the lexer
John W. Eaton <jwe@octave.org>
parents:
8745
diff
changeset
|
558 lexer_flags.at_beginning_of_statement = false; |
8745
6dc61981d18b
better handling of object indexing in lexer
John W. Eaton <jwe@octave.org>
parents:
8701
diff
changeset
|
559 |
4910 | 560 COUNT_TOK_AND_RETURN (';'); |
967 | 561 } |
562 | |
968 | 563 %{ |
1088 | 564 // In some cases, new lines can also become row separators. If we |
565 // don't eat whitespace here we can end up inserting too many | |
566 // semicolons. | |
7723
74f5e0c7de9e
first pass at handling block comments
John W. Eaton <jwe@octave.org>
parents:
7722
diff
changeset
|
567 |
74f5e0c7de9e
first pass at handling block comments
John W. Eaton <jwe@octave.org>
parents:
7722
diff
changeset
|
568 // FIXME -- we need to handle block comments here. |
985 | 569 %} |
570 | |
4208 | 571 <MATRIX_START>{S}*{COMMENT}{SNLCMT}* | |
572 <MATRIX_START>{S}*{NL}{SNLCMT}* { | |
8535 | 573 LEXER_DEBUG ("<MATRIX_START>{S}*{COMMENT}{SNLCMT}*|<MATRIX_START>{S}*{NL}{SNLCMT}*"); |
574 | |
3665 | 575 scan_for_comments (yytext); |
1082 | 576 fixup_column_count (yytext); |
1088 | 577 eat_whitespace (); |
3388 | 578 |
4476 | 579 lexer_flags.quote_is_transpose = false; |
580 lexer_flags.convert_spaces_to_comma = true; | |
8746
5dd06f19e9be
handle commands in the lexer
John W. Eaton <jwe@octave.org>
parents:
8745
diff
changeset
|
581 lexer_flags.at_beginning_of_statement = false; |
4476 | 582 |
583 if (nesting_level.none ()) | |
584 return LEXICAL_ERROR; | |
985 | 585 |
8745
6dc61981d18b
better handling of object indexing in lexer
John W. Eaton <jwe@octave.org>
parents:
8701
diff
changeset
|
586 if (! lexer_flags.looking_at_object_index.front () |
6dc61981d18b
better handling of object indexing in lexer
John W. Eaton <jwe@octave.org>
parents:
8701
diff
changeset
|
587 && nesting_level.is_bracket_or_brace ()) |
3388 | 588 { |
589 maybe_warn_separator_insert (';'); | |
590 | |
4910 | 591 COUNT_TOK_AND_RETURN (';'); |
985 | 592 } |
593 } | |
594 | |
967 | 595 \[{S}* { |
8535 | 596 LEXER_DEBUG ("\\[{S}*"); |
597 | |
3351 | 598 nesting_level.bracket (); |
975 | 599 |
8745
6dc61981d18b
better handling of object indexing in lexer
John W. Eaton <jwe@octave.org>
parents:
8701
diff
changeset
|
600 lexer_flags.looking_at_object_index.push_front (false); |
6dc61981d18b
better handling of object indexing in lexer
John W. Eaton <jwe@octave.org>
parents:
8701
diff
changeset
|
601 |
1082 | 602 current_input_column += yyleng; |
2857 | 603 lexer_flags.quote_is_transpose = false; |
604 lexer_flags.convert_spaces_to_comma = true; | |
8745
6dc61981d18b
better handling of object indexing in lexer
John W. Eaton <jwe@octave.org>
parents:
8701
diff
changeset
|
605 lexer_flags.looking_for_object_index = false; |
8746
5dd06f19e9be
handle commands in the lexer
John W. Eaton <jwe@octave.org>
parents:
8745
diff
changeset
|
606 lexer_flags.at_beginning_of_statement = false; |
975 | 607 |
5615 | 608 if (lexer_flags.defining_func && ! lexer_flags.parsed_function_name) |
609 lexer_flags.looking_at_return_list = true; | |
610 else | |
611 lexer_flags.looking_at_matrix_or_assign_lhs = true; | |
612 | |
975 | 613 promptflag--; |
614 eat_whitespace (); | |
615 | |
5102 | 616 lexer_flags.bracketflag++; |
617 BEGIN (MATRIX_START); | |
618 COUNT_TOK_AND_RETURN ('['); | |
967 | 619 } |
1 | 620 |
968 | 621 \] { |
8535 | 622 LEXER_DEBUG ("\\]"); |
623 | |
1826 | 624 nesting_level.remove (); |
968 | 625 |
8745
6dc61981d18b
better handling of object indexing in lexer
John W. Eaton <jwe@octave.org>
parents:
8701
diff
changeset
|
626 lexer_flags.looking_at_object_index.pop_front (); |
6dc61981d18b
better handling of object indexing in lexer
John W. Eaton <jwe@octave.org>
parents:
8701
diff
changeset
|
627 |
6dc61981d18b
better handling of object indexing in lexer
John W. Eaton <jwe@octave.org>
parents:
8701
diff
changeset
|
628 lexer_flags.looking_for_object_index = true; |
8746
5dd06f19e9be
handle commands in the lexer
John W. Eaton <jwe@octave.org>
parents:
8745
diff
changeset
|
629 lexer_flags.at_beginning_of_statement = false; |
8745
6dc61981d18b
better handling of object indexing in lexer
John W. Eaton <jwe@octave.org>
parents:
8701
diff
changeset
|
630 |
5102 | 631 TOK_RETURN (']'); |
968 | 632 } |
633 | |
634 %{ | |
635 // Imaginary numbers. | |
636 %} | |
637 | |
638 {NUMBER}{Im} { | |
8535 | 639 LEXER_DEBUG ("{NUMBER}{Im}"); |
640 | |
3246 | 641 handle_number (); |
4910 | 642 COUNT_TOK_AND_RETURN (IMAG_NUM); |
968 | 643 } |
644 | |
645 %{ | |
646 // Real numbers. Don't grab the `.' part of a dot operator as part of | |
647 // the constant. | |
648 %} | |
649 | |
8535 | 650 {D}+/\.[\*/\\^\'] | |
968 | 651 {NUMBER} { |
8535 | 652 LEXER_DEBUG ("{D}+/\\.[\\*/\\^\\']|{NUMBER}"); |
3246 | 653 handle_number (); |
4910 | 654 COUNT_TOK_AND_RETURN (NUM); |
968 | 655 } |
656 | |
657 %{ | |
658 // Eat whitespace. Whitespace inside matrix constants is handled by | |
4208 | 659 // the <MATRIX_START> start state code above. |
968 | 660 %} |
661 | |
967 | 662 {S}* { |
663 current_input_column += yyleng; | |
664 } | |
665 | |
968 | 666 %{ |
667 // Continuation lines. Allow comments after continuations. | |
668 %} | |
669 | |
967 | 670 {CONT}{S}*{NL} | |
671 {CONT}{S}*{COMMENT} { | |
8535 | 672 LEXER_DEBUG ("{CONT}{S}*{NL}|{CONT}{S}*{COMMENT}"); |
673 | |
4037 | 674 if (yytext[0] == '\\') |
675 gripe_matlab_incompatible_continuation (); | |
3665 | 676 scan_for_comments (yytext); |
967 | 677 promptflag--; |
8447
adab48231a03
make input_line_number work again
John W. Eaton <jwe@octave.org>
parents:
8312
diff
changeset
|
678 input_line_number++; |
967 | 679 current_input_column = 1; |
680 } | |
1 | 681 |
968 | 682 %{ |
683 // End of file. | |
684 %} | |
685 | |
967 | 686 <<EOF>> { |
8535 | 687 LEXER_DEBUG ("<<EOF>>"); |
688 | |
7723
74f5e0c7de9e
first pass at handling block comments
John W. Eaton <jwe@octave.org>
parents:
7722
diff
changeset
|
689 if (block_comment_nesting_level != 0) |
74f5e0c7de9e
first pass at handling block comments
John W. Eaton <jwe@octave.org>
parents:
7722
diff
changeset
|
690 { |
74f5e0c7de9e
first pass at handling block comments
John W. Eaton <jwe@octave.org>
parents:
7722
diff
changeset
|
691 warning ("block comment open at end of input"); |
74f5e0c7de9e
first pass at handling block comments
John W. Eaton <jwe@octave.org>
parents:
7722
diff
changeset
|
692 |
74f5e0c7de9e
first pass at handling block comments
John W. Eaton <jwe@octave.org>
parents:
7722
diff
changeset
|
693 if ((reading_fcn_file || reading_script_file) |
74f5e0c7de9e
first pass at handling block comments
John W. Eaton <jwe@octave.org>
parents:
7722
diff
changeset
|
694 && ! curr_fcn_file_name.empty ()) |
74f5e0c7de9e
first pass at handling block comments
John W. Eaton <jwe@octave.org>
parents:
7722
diff
changeset
|
695 warning ("near line %d of file `%s.m'", |
74f5e0c7de9e
first pass at handling block comments
John W. Eaton <jwe@octave.org>
parents:
7722
diff
changeset
|
696 input_line_number, curr_fcn_file_name.c_str ()); |
74f5e0c7de9e
first pass at handling block comments
John W. Eaton <jwe@octave.org>
parents:
7722
diff
changeset
|
697 } |
74f5e0c7de9e
first pass at handling block comments
John W. Eaton <jwe@octave.org>
parents:
7722
diff
changeset
|
698 |
967 | 699 TOK_RETURN (END_OF_INPUT); |
700 } | |
1 | 701 |
968 | 702 %{ |
970 | 703 // Identifiers. Truncate the token at the first space or tab but |
704 // don't write directly on yytext. | |
968 | 705 %} |
706 | |
967 | 707 {IDENT}{S}* { |
8535 | 708 LEXER_DEBUG ("{IDENT}{S}*"); |
709 | |
4238 | 710 int id_tok = handle_identifier (); |
711 | |
712 if (id_tok >= 0) | |
9324
29563379fa9b
don't look for object index after keyword
John W. Eaton <jwe@octave.org>
parents:
8974
diff
changeset
|
713 COUNT_TOK_AND_RETURN (id_tok); |
967 | 714 } |
1 | 715 |
968 | 716 %{ |
4342 | 717 // Function handles. |
718 %} | |
719 | |
4930 | 720 "@" { |
8535 | 721 LEXER_DEBUG ("@"); |
722 | |
4930 | 723 current_input_column++; |
8745
6dc61981d18b
better handling of object indexing in lexer
John W. Eaton <jwe@octave.org>
parents:
8701
diff
changeset
|
724 |
4930 | 725 lexer_flags.quote_is_transpose = false; |
726 lexer_flags.convert_spaces_to_comma = false; | |
727 lexer_flags.looking_at_function_handle++; | |
8745
6dc61981d18b
better handling of object indexing in lexer
John W. Eaton <jwe@octave.org>
parents:
8701
diff
changeset
|
728 lexer_flags.looking_for_object_index = false; |
8746
5dd06f19e9be
handle commands in the lexer
John W. Eaton <jwe@octave.org>
parents:
8745
diff
changeset
|
729 lexer_flags.at_beginning_of_statement = false; |
8745
6dc61981d18b
better handling of object indexing in lexer
John W. Eaton <jwe@octave.org>
parents:
8701
diff
changeset
|
730 |
4930 | 731 COUNT_TOK_AND_RETURN ('@'); |
4342 | 732 } |
733 | |
734 %{ | |
968 | 735 // A new line character. New line characters inside matrix constants |
4208 | 736 // are handled by the <MATRIX_START> start state code above. If closest |
985 | 737 // nesting is inside parentheses, don't return a row separator. |
968 | 738 %} |
739 | |
967 | 740 {NL} { |
8535 | 741 LEXER_DEBUG ("{NL}"); |
742 | |
8447
adab48231a03
make input_line_number work again
John W. Eaton <jwe@octave.org>
parents:
8312
diff
changeset
|
743 input_line_number++; |
967 | 744 current_input_column = 1; |
8746
5dd06f19e9be
handle commands in the lexer
John W. Eaton <jwe@octave.org>
parents:
8745
diff
changeset
|
745 |
2857 | 746 lexer_flags.quote_is_transpose = false; |
747 lexer_flags.convert_spaces_to_comma = true; | |
8746
5dd06f19e9be
handle commands in the lexer
John W. Eaton <jwe@octave.org>
parents:
8745
diff
changeset
|
748 |
1826 | 749 if (nesting_level.none ()) |
8746
5dd06f19e9be
handle commands in the lexer
John W. Eaton <jwe@octave.org>
parents:
8745
diff
changeset
|
750 { |
5dd06f19e9be
handle commands in the lexer
John W. Eaton <jwe@octave.org>
parents:
8745
diff
changeset
|
751 lexer_flags.at_beginning_of_statement = true; |
5dd06f19e9be
handle commands in the lexer
John W. Eaton <jwe@octave.org>
parents:
8745
diff
changeset
|
752 COUNT_TOK_AND_RETURN ('\n'); |
5dd06f19e9be
handle commands in the lexer
John W. Eaton <jwe@octave.org>
parents:
8745
diff
changeset
|
753 } |
4037 | 754 else if (nesting_level.is_paren ()) |
8746
5dd06f19e9be
handle commands in the lexer
John W. Eaton <jwe@octave.org>
parents:
8745
diff
changeset
|
755 { |
5dd06f19e9be
handle commands in the lexer
John W. Eaton <jwe@octave.org>
parents:
8745
diff
changeset
|
756 lexer_flags.at_beginning_of_statement = false; |
5dd06f19e9be
handle commands in the lexer
John W. Eaton <jwe@octave.org>
parents:
8745
diff
changeset
|
757 gripe_matlab_incompatible ("bare newline inside parentheses"); |
5dd06f19e9be
handle commands in the lexer
John W. Eaton <jwe@octave.org>
parents:
8745
diff
changeset
|
758 } |
4608 | 759 else if (nesting_level.is_bracket_or_brace ()) |
985 | 760 return LEXICAL_ERROR; |
967 | 761 } |
1 | 762 |
968 | 763 %{ |
764 // Single quote can either be the beginning of a string or a transpose | |
765 // operator. | |
766 %} | |
767 | |
967 | 768 "'" { |
8535 | 769 LEXER_DEBUG ("'"); |
770 | |
967 | 771 current_input_column++; |
2857 | 772 lexer_flags.convert_spaces_to_comma = true; |
1 | 773 |
1826 | 774 if (lexer_flags.quote_is_transpose) |
967 | 775 { |
776 do_comma_insert_check (); | |
4910 | 777 COUNT_TOK_AND_RETURN (QUOTE); |
967 | 778 } |
779 else | |
7722
c3bb0b7a4261
lex.l: allow tokens to be displayed when parsed
John W. Eaton <jwe@octave.org>
parents:
7720
diff
changeset
|
780 { |
c3bb0b7a4261
lex.l: allow tokens to be displayed when parsed
John W. Eaton <jwe@octave.org>
parents:
7720
diff
changeset
|
781 int tok = handle_string ('\''); |
c3bb0b7a4261
lex.l: allow tokens to be displayed when parsed
John W. Eaton <jwe@octave.org>
parents:
7720
diff
changeset
|
782 COUNT_TOK_AND_RETURN (tok); |
c3bb0b7a4261
lex.l: allow tokens to be displayed when parsed
John W. Eaton <jwe@octave.org>
parents:
7720
diff
changeset
|
783 } |
967 | 784 } |
1 | 785 |
968 | 786 %{ |
971 | 787 // Double quotes always begin strings. |
788 %} | |
789 | |
973 | 790 \" { |
8535 | 791 LEXER_DEBUG ("\""); |
792 | |
973 | 793 current_input_column++; |
7722
c3bb0b7a4261
lex.l: allow tokens to be displayed when parsed
John W. Eaton <jwe@octave.org>
parents:
7720
diff
changeset
|
794 int tok = handle_string ('"'); |
8745
6dc61981d18b
better handling of object indexing in lexer
John W. Eaton <jwe@octave.org>
parents:
8701
diff
changeset
|
795 |
7722
c3bb0b7a4261
lex.l: allow tokens to be displayed when parsed
John W. Eaton <jwe@octave.org>
parents:
7720
diff
changeset
|
796 COUNT_TOK_AND_RETURN (tok); |
973 | 797 } |
971 | 798 |
799 %{ | |
8536
de1b944d5306
lex.l: finish previous change
John W. Eaton <jwe@octave.org>
parents:
8535
diff
changeset
|
800 // Gobble comments. |
985 | 801 %} |
968 | 802 |
967 | 803 {CCHAR} { |
8535 | 804 LEXER_DEBUG ("{CCHAR}"); |
805 | |
8745
6dc61981d18b
better handling of object indexing in lexer
John W. Eaton <jwe@octave.org>
parents:
8701
diff
changeset
|
806 lexer_flags.looking_for_object_index = false; |
6dc61981d18b
better handling of object indexing in lexer
John W. Eaton <jwe@octave.org>
parents:
8701
diff
changeset
|
807 |
8447
adab48231a03
make input_line_number work again
John W. Eaton <jwe@octave.org>
parents:
8312
diff
changeset
|
808 xunput (yytext[0], yytext); |
7723
74f5e0c7de9e
first pass at handling block comments
John W. Eaton <jwe@octave.org>
parents:
7722
diff
changeset
|
809 |
7715
5b4d278ec828
parse scripts completely before executing
John W. Eaton <jwe@octave.org>
parents:
7634
diff
changeset
|
810 bool eof = false; |
7723
74f5e0c7de9e
first pass at handling block comments
John W. Eaton <jwe@octave.org>
parents:
7722
diff
changeset
|
811 int tok = process_comment (false, eof); |
74f5e0c7de9e
first pass at handling block comments
John W. Eaton <jwe@octave.org>
parents:
7722
diff
changeset
|
812 |
7715
5b4d278ec828
parse scripts completely before executing
John W. Eaton <jwe@octave.org>
parents:
7634
diff
changeset
|
813 if (eof) |
5b4d278ec828
parse scripts completely before executing
John W. Eaton <jwe@octave.org>
parents:
7634
diff
changeset
|
814 TOK_RETURN (END_OF_INPUT); |
5b4d278ec828
parse scripts completely before executing
John W. Eaton <jwe@octave.org>
parents:
7634
diff
changeset
|
815 else if (tok > 0) |
5b4d278ec828
parse scripts completely before executing
John W. Eaton <jwe@octave.org>
parents:
7634
diff
changeset
|
816 COUNT_TOK_AND_RETURN (tok); |
967 | 817 } |
440 | 818 |
968 | 819 %{ |
7723
74f5e0c7de9e
first pass at handling block comments
John W. Eaton <jwe@octave.org>
parents:
7722
diff
changeset
|
820 // Block comments. |
74f5e0c7de9e
first pass at handling block comments
John W. Eaton <jwe@octave.org>
parents:
7722
diff
changeset
|
821 %} |
74f5e0c7de9e
first pass at handling block comments
John W. Eaton <jwe@octave.org>
parents:
7722
diff
changeset
|
822 |
74f5e0c7de9e
first pass at handling block comments
John W. Eaton <jwe@octave.org>
parents:
7722
diff
changeset
|
823 ^{S}*{CCHAR}\{{S}*{NL} { |
8535 | 824 LEXER_DEBUG ("^{S}*{CCHAR}\\{{S}*{NL}"); |
825 | |
8745
6dc61981d18b
better handling of object indexing in lexer
John W. Eaton <jwe@octave.org>
parents:
8701
diff
changeset
|
826 lexer_flags.looking_for_object_index = false; |
6dc61981d18b
better handling of object indexing in lexer
John W. Eaton <jwe@octave.org>
parents:
8701
diff
changeset
|
827 |
8447
adab48231a03
make input_line_number work again
John W. Eaton <jwe@octave.org>
parents:
8312
diff
changeset
|
828 input_line_number++; |
7723
74f5e0c7de9e
first pass at handling block comments
John W. Eaton <jwe@octave.org>
parents:
7722
diff
changeset
|
829 current_input_column = 1; |
74f5e0c7de9e
first pass at handling block comments
John W. Eaton <jwe@octave.org>
parents:
7722
diff
changeset
|
830 block_comment_nesting_level++; |
74f5e0c7de9e
first pass at handling block comments
John W. Eaton <jwe@octave.org>
parents:
7722
diff
changeset
|
831 promptflag--; |
8746
5dd06f19e9be
handle commands in the lexer
John W. Eaton <jwe@octave.org>
parents:
8745
diff
changeset
|
832 |
7723
74f5e0c7de9e
first pass at handling block comments
John W. Eaton <jwe@octave.org>
parents:
7722
diff
changeset
|
833 bool eof = false; |
74f5e0c7de9e
first pass at handling block comments
John W. Eaton <jwe@octave.org>
parents:
7722
diff
changeset
|
834 process_comment (true, eof); |
74f5e0c7de9e
first pass at handling block comments
John W. Eaton <jwe@octave.org>
parents:
7722
diff
changeset
|
835 } |
74f5e0c7de9e
first pass at handling block comments
John W. Eaton <jwe@octave.org>
parents:
7722
diff
changeset
|
836 |
74f5e0c7de9e
first pass at handling block comments
John W. Eaton <jwe@octave.org>
parents:
7722
diff
changeset
|
837 %{ |
968 | 838 // Other operators. |
839 %} | |
840 | |
8746
5dd06f19e9be
handle commands in the lexer
John W. Eaton <jwe@octave.org>
parents:
8745
diff
changeset
|
841 ":" { LEXER_DEBUG (":"); BIN_OP_RETURN (':', false, false); } |
5dd06f19e9be
handle commands in the lexer
John W. Eaton <jwe@octave.org>
parents:
8745
diff
changeset
|
842 |
5dd06f19e9be
handle commands in the lexer
John W. Eaton <jwe@octave.org>
parents:
8745
diff
changeset
|
843 ".+" { LEXER_DEBUG (".+"); XBIN_OP_RETURN (EPLUS, false, false); } |
5dd06f19e9be
handle commands in the lexer
John W. Eaton <jwe@octave.org>
parents:
8745
diff
changeset
|
844 ".-" { LEXER_DEBUG (".-"); XBIN_OP_RETURN (EMINUS, false, false); } |
5dd06f19e9be
handle commands in the lexer
John W. Eaton <jwe@octave.org>
parents:
8745
diff
changeset
|
845 ".*" { LEXER_DEBUG (".*"); BIN_OP_RETURN (EMUL, false, false); } |
5dd06f19e9be
handle commands in the lexer
John W. Eaton <jwe@octave.org>
parents:
8745
diff
changeset
|
846 "./" { LEXER_DEBUG ("./"); BIN_OP_RETURN (EDIV, false, false); } |
5dd06f19e9be
handle commands in the lexer
John W. Eaton <jwe@octave.org>
parents:
8745
diff
changeset
|
847 ".\\" { LEXER_DEBUG (".\\"); BIN_OP_RETURN (ELEFTDIV, false, false); } |
5dd06f19e9be
handle commands in the lexer
John W. Eaton <jwe@octave.org>
parents:
8745
diff
changeset
|
848 ".^" { LEXER_DEBUG (".^"); BIN_OP_RETURN (EPOW, false, false); } |
5dd06f19e9be
handle commands in the lexer
John W. Eaton <jwe@octave.org>
parents:
8745
diff
changeset
|
849 ".**" { LEXER_DEBUG (".**"); XBIN_OP_RETURN (EPOW, false, false); } |
5dd06f19e9be
handle commands in the lexer
John W. Eaton <jwe@octave.org>
parents:
8745
diff
changeset
|
850 ".'" { LEXER_DEBUG (".'"); do_comma_insert_check (); BIN_OP_RETURN (TRANSPOSE, true, false); } |
5dd06f19e9be
handle commands in the lexer
John W. Eaton <jwe@octave.org>
parents:
8745
diff
changeset
|
851 "++" { LEXER_DEBUG ("++"); do_comma_insert_check (); XBIN_OP_RETURN (PLUS_PLUS, true, false); } |
5dd06f19e9be
handle commands in the lexer
John W. Eaton <jwe@octave.org>
parents:
8745
diff
changeset
|
852 "--" { LEXER_DEBUG ("--"); do_comma_insert_check (); XBIN_OP_RETURN (MINUS_MINUS, true, false); } |
5dd06f19e9be
handle commands in the lexer
John W. Eaton <jwe@octave.org>
parents:
8745
diff
changeset
|
853 "<=" { LEXER_DEBUG ("<="); BIN_OP_RETURN (EXPR_LE, false, false); } |
5dd06f19e9be
handle commands in the lexer
John W. Eaton <jwe@octave.org>
parents:
8745
diff
changeset
|
854 "==" { LEXER_DEBUG ("=="); BIN_OP_RETURN (EXPR_EQ, false, false); } |
5dd06f19e9be
handle commands in the lexer
John W. Eaton <jwe@octave.org>
parents:
8745
diff
changeset
|
855 "~=" { LEXER_DEBUG ("~="); BIN_OP_RETURN (EXPR_NE, false, false); } |
5dd06f19e9be
handle commands in the lexer
John W. Eaton <jwe@octave.org>
parents:
8745
diff
changeset
|
856 "!=" { LEXER_DEBUG ("!="); XBIN_OP_RETURN (EXPR_NE, false, false); } |
5dd06f19e9be
handle commands in the lexer
John W. Eaton <jwe@octave.org>
parents:
8745
diff
changeset
|
857 ">=" { LEXER_DEBUG (">="); BIN_OP_RETURN (EXPR_GE, false, false); } |
5dd06f19e9be
handle commands in the lexer
John W. Eaton <jwe@octave.org>
parents:
8745
diff
changeset
|
858 "&" { LEXER_DEBUG ("&"); BIN_OP_RETURN (EXPR_AND, false, false); } |
5dd06f19e9be
handle commands in the lexer
John W. Eaton <jwe@octave.org>
parents:
8745
diff
changeset
|
859 "|" { LEXER_DEBUG ("|"); BIN_OP_RETURN (EXPR_OR, false, false); } |
5dd06f19e9be
handle commands in the lexer
John W. Eaton <jwe@octave.org>
parents:
8745
diff
changeset
|
860 "<" { LEXER_DEBUG ("<"); BIN_OP_RETURN (EXPR_LT, false, false); } |
5dd06f19e9be
handle commands in the lexer
John W. Eaton <jwe@octave.org>
parents:
8745
diff
changeset
|
861 ">" { LEXER_DEBUG (">"); BIN_OP_RETURN (EXPR_GT, false, false); } |
5dd06f19e9be
handle commands in the lexer
John W. Eaton <jwe@octave.org>
parents:
8745
diff
changeset
|
862 "+" { LEXER_DEBUG ("+"); BIN_OP_RETURN ('+', false, false); } |
5dd06f19e9be
handle commands in the lexer
John W. Eaton <jwe@octave.org>
parents:
8745
diff
changeset
|
863 "-" { LEXER_DEBUG ("-"); BIN_OP_RETURN ('-', false, false); } |
5dd06f19e9be
handle commands in the lexer
John W. Eaton <jwe@octave.org>
parents:
8745
diff
changeset
|
864 "*" { LEXER_DEBUG ("*"); BIN_OP_RETURN ('*', false, false); } |
5dd06f19e9be
handle commands in the lexer
John W. Eaton <jwe@octave.org>
parents:
8745
diff
changeset
|
865 "/" { LEXER_DEBUG ("/"); BIN_OP_RETURN ('/', false, false); } |
5dd06f19e9be
handle commands in the lexer
John W. Eaton <jwe@octave.org>
parents:
8745
diff
changeset
|
866 "\\" { LEXER_DEBUG ("\\"); BIN_OP_RETURN (LEFTDIV, false, false); } |
5dd06f19e9be
handle commands in the lexer
John W. Eaton <jwe@octave.org>
parents:
8745
diff
changeset
|
867 ";" { LEXER_DEBUG (";"); BIN_OP_RETURN (';', true, true); } |
5dd06f19e9be
handle commands in the lexer
John W. Eaton <jwe@octave.org>
parents:
8745
diff
changeset
|
868 "," { LEXER_DEBUG (","); BIN_OP_RETURN (',', true, ! lexer_flags.looking_at_object_index.front ()); } |
5dd06f19e9be
handle commands in the lexer
John W. Eaton <jwe@octave.org>
parents:
8745
diff
changeset
|
869 "^" { LEXER_DEBUG ("^"); BIN_OP_RETURN (POW, false, false); } |
5dd06f19e9be
handle commands in the lexer
John W. Eaton <jwe@octave.org>
parents:
8745
diff
changeset
|
870 "**" { LEXER_DEBUG ("**"); XBIN_OP_RETURN (POW, false, false); } |
5dd06f19e9be
handle commands in the lexer
John W. Eaton <jwe@octave.org>
parents:
8745
diff
changeset
|
871 "=" { LEXER_DEBUG ("="); BIN_OP_RETURN ('=', true, false); } |
5dd06f19e9be
handle commands in the lexer
John W. Eaton <jwe@octave.org>
parents:
8745
diff
changeset
|
872 "&&" { LEXER_DEBUG ("&&"); BIN_OP_RETURN (EXPR_AND_AND, false, false); } |
5dd06f19e9be
handle commands in the lexer
John W. Eaton <jwe@octave.org>
parents:
8745
diff
changeset
|
873 "||" { LEXER_DEBUG ("||"); BIN_OP_RETURN (EXPR_OR_OR, false, false); } |
5dd06f19e9be
handle commands in the lexer
John W. Eaton <jwe@octave.org>
parents:
8745
diff
changeset
|
874 "<<" { LEXER_DEBUG ("<<"); XBIN_OP_RETURN (LSHIFT, false, false); } |
5dd06f19e9be
handle commands in the lexer
John W. Eaton <jwe@octave.org>
parents:
8745
diff
changeset
|
875 ">>" { LEXER_DEBUG (">>"); XBIN_OP_RETURN (RSHIFT, false, false); } |
5dd06f19e9be
handle commands in the lexer
John W. Eaton <jwe@octave.org>
parents:
8745
diff
changeset
|
876 |
967 | 877 |
878 {NOT} { | |
8535 | 879 LEXER_DEBUG ("{NOT}"); |
880 | |
4037 | 881 if (yytext[0] == '~') |
8746
5dd06f19e9be
handle commands in the lexer
John W. Eaton <jwe@octave.org>
parents:
8745
diff
changeset
|
882 BIN_OP_RETURN (EXPR_NOT, false, false); |
4037 | 883 else |
8746
5dd06f19e9be
handle commands in the lexer
John W. Eaton <jwe@octave.org>
parents:
8745
diff
changeset
|
884 XBIN_OP_RETURN (EXPR_NOT, false, false); |
967 | 885 } |
1 | 886 |
967 | 887 "(" { |
8535 | 888 LEXER_DEBUG ("("); |
889 | |
8745
6dc61981d18b
better handling of object indexing in lexer
John W. Eaton <jwe@octave.org>
parents:
8701
diff
changeset
|
890 // If we are looking for an object index, then push TRUE for |
6dc61981d18b
better handling of object indexing in lexer
John W. Eaton <jwe@octave.org>
parents:
8701
diff
changeset
|
891 // looking_at_object_index. Otherwise, just push whatever state |
6dc61981d18b
better handling of object indexing in lexer
John W. Eaton <jwe@octave.org>
parents:
8701
diff
changeset
|
892 // is current (so that we can pop it off the stack when we find |
6dc61981d18b
better handling of object indexing in lexer
John W. Eaton <jwe@octave.org>
parents:
8701
diff
changeset
|
893 // the matching close paren). |
6dc61981d18b
better handling of object indexing in lexer
John W. Eaton <jwe@octave.org>
parents:
8701
diff
changeset
|
894 |
6dc61981d18b
better handling of object indexing in lexer
John W. Eaton <jwe@octave.org>
parents:
8701
diff
changeset
|
895 lexer_flags.looking_at_object_index.push_front |
6dc61981d18b
better handling of object indexing in lexer
John W. Eaton <jwe@octave.org>
parents:
8701
diff
changeset
|
896 (lexer_flags.looking_for_object_index); |
6dc61981d18b
better handling of object indexing in lexer
John W. Eaton <jwe@octave.org>
parents:
8701
diff
changeset
|
897 |
4131 | 898 lexer_flags.looking_at_indirect_ref = false; |
8745
6dc61981d18b
better handling of object indexing in lexer
John W. Eaton <jwe@octave.org>
parents:
8701
diff
changeset
|
899 lexer_flags.looking_for_object_index = false; |
8746
5dd06f19e9be
handle commands in the lexer
John W. Eaton <jwe@octave.org>
parents:
8745
diff
changeset
|
900 lexer_flags.at_beginning_of_statement = false; |
8745
6dc61981d18b
better handling of object indexing in lexer
John W. Eaton <jwe@octave.org>
parents:
8701
diff
changeset
|
901 |
1826 | 902 nesting_level.paren (); |
985 | 903 promptflag--; |
8745
6dc61981d18b
better handling of object indexing in lexer
John W. Eaton <jwe@octave.org>
parents:
8701
diff
changeset
|
904 |
967 | 905 TOK_RETURN ('('); |
906 } | |
907 | |
908 ")" { | |
8535 | 909 LEXER_DEBUG (")"); |
910 | |
1826 | 911 nesting_level.remove (); |
967 | 912 current_input_column++; |
8745
6dc61981d18b
better handling of object indexing in lexer
John W. Eaton <jwe@octave.org>
parents:
8701
diff
changeset
|
913 |
6dc61981d18b
better handling of object indexing in lexer
John W. Eaton <jwe@octave.org>
parents:
8701
diff
changeset
|
914 lexer_flags.looking_at_object_index.pop_front (); |
6dc61981d18b
better handling of object indexing in lexer
John W. Eaton <jwe@octave.org>
parents:
8701
diff
changeset
|
915 |
2857 | 916 lexer_flags.quote_is_transpose = true; |
4608 | 917 lexer_flags.convert_spaces_to_comma = nesting_level.is_bracket_or_brace (); |
8745
6dc61981d18b
better handling of object indexing in lexer
John W. Eaton <jwe@octave.org>
parents:
8701
diff
changeset
|
918 lexer_flags.looking_for_object_index = true; |
8746
5dd06f19e9be
handle commands in the lexer
John W. Eaton <jwe@octave.org>
parents:
8745
diff
changeset
|
919 lexer_flags.at_beginning_of_statement = false; |
8745
6dc61981d18b
better handling of object indexing in lexer
John W. Eaton <jwe@octave.org>
parents:
8701
diff
changeset
|
920 |
1001 | 921 do_comma_insert_check (); |
8745
6dc61981d18b
better handling of object indexing in lexer
John W. Eaton <jwe@octave.org>
parents:
8701
diff
changeset
|
922 |
4910 | 923 COUNT_TOK_AND_RETURN (')'); |
967 | 924 } |
925 | |
8745
6dc61981d18b
better handling of object indexing in lexer
John W. Eaton <jwe@octave.org>
parents:
8701
diff
changeset
|
926 "." { |
6dc61981d18b
better handling of object indexing in lexer
John W. Eaton <jwe@octave.org>
parents:
8701
diff
changeset
|
927 LEXER_DEBUG ("."); |
6dc61981d18b
better handling of object indexing in lexer
John W. Eaton <jwe@octave.org>
parents:
8701
diff
changeset
|
928 |
6dc61981d18b
better handling of object indexing in lexer
John W. Eaton <jwe@octave.org>
parents:
8701
diff
changeset
|
929 lexer_flags.looking_for_object_index = false; |
8746
5dd06f19e9be
handle commands in the lexer
John W. Eaton <jwe@octave.org>
parents:
8745
diff
changeset
|
930 lexer_flags.at_beginning_of_statement = false; |
8745
6dc61981d18b
better handling of object indexing in lexer
John W. Eaton <jwe@octave.org>
parents:
8701
diff
changeset
|
931 |
6dc61981d18b
better handling of object indexing in lexer
John W. Eaton <jwe@octave.org>
parents:
8701
diff
changeset
|
932 TOK_RETURN ('.'); |
6dc61981d18b
better handling of object indexing in lexer
John W. Eaton <jwe@octave.org>
parents:
8701
diff
changeset
|
933 } |
8535 | 934 |
8746
5dd06f19e9be
handle commands in the lexer
John W. Eaton <jwe@octave.org>
parents:
8745
diff
changeset
|
935 "+=" { LEXER_DEBUG ("+="); XBIN_OP_RETURN (ADD_EQ, false, false); } |
5dd06f19e9be
handle commands in the lexer
John W. Eaton <jwe@octave.org>
parents:
8745
diff
changeset
|
936 "-=" { LEXER_DEBUG ("-="); XBIN_OP_RETURN (SUB_EQ, false, false); } |
5dd06f19e9be
handle commands in the lexer
John W. Eaton <jwe@octave.org>
parents:
8745
diff
changeset
|
937 "*=" { LEXER_DEBUG ("*="); XBIN_OP_RETURN (MUL_EQ, false, false); } |
5dd06f19e9be
handle commands in the lexer
John W. Eaton <jwe@octave.org>
parents:
8745
diff
changeset
|
938 "/=" { LEXER_DEBUG ("/="); XBIN_OP_RETURN (DIV_EQ, false, false); } |
5dd06f19e9be
handle commands in the lexer
John W. Eaton <jwe@octave.org>
parents:
8745
diff
changeset
|
939 "\\=" { LEXER_DEBUG ("\\="); XBIN_OP_RETURN (LEFTDIV_EQ, false, false); } |
5dd06f19e9be
handle commands in the lexer
John W. Eaton <jwe@octave.org>
parents:
8745
diff
changeset
|
940 ".+=" { LEXER_DEBUG (".+="); XBIN_OP_RETURN (ADD_EQ, false, false); } |
5dd06f19e9be
handle commands in the lexer
John W. Eaton <jwe@octave.org>
parents:
8745
diff
changeset
|
941 ".-=" { LEXER_DEBUG (".-="); XBIN_OP_RETURN (SUB_EQ, false, false); } |
5dd06f19e9be
handle commands in the lexer
John W. Eaton <jwe@octave.org>
parents:
8745
diff
changeset
|
942 ".*=" { LEXER_DEBUG (".*="); XBIN_OP_RETURN (EMUL_EQ, false, false); } |
5dd06f19e9be
handle commands in the lexer
John W. Eaton <jwe@octave.org>
parents:
8745
diff
changeset
|
943 "./=" { LEXER_DEBUG ("./="); XBIN_OP_RETURN (EDIV_EQ, false, false); } |
5dd06f19e9be
handle commands in the lexer
John W. Eaton <jwe@octave.org>
parents:
8745
diff
changeset
|
944 ".\\=" { LEXER_DEBUG (".\\="); XBIN_OP_RETURN (ELEFTDIV_EQ, false, false); } |
5dd06f19e9be
handle commands in the lexer
John W. Eaton <jwe@octave.org>
parents:
8745
diff
changeset
|
945 {POW}= { LEXER_DEBUG ("{POW}="); XBIN_OP_RETURN (POW_EQ, false, false); } |
5dd06f19e9be
handle commands in the lexer
John W. Eaton <jwe@octave.org>
parents:
8745
diff
changeset
|
946 {EPOW}= { LEXER_DEBUG ("{EPOW}="); XBIN_OP_RETURN (EPOW_EQ, false, false); } |
5dd06f19e9be
handle commands in the lexer
John W. Eaton <jwe@octave.org>
parents:
8745
diff
changeset
|
947 "&=" { LEXER_DEBUG ("&="); XBIN_OP_RETURN (AND_EQ, false, false); } |
5dd06f19e9be
handle commands in the lexer
John W. Eaton <jwe@octave.org>
parents:
8745
diff
changeset
|
948 "|=" { LEXER_DEBUG ("|="); XBIN_OP_RETURN (OR_EQ, false, false); } |
5dd06f19e9be
handle commands in the lexer
John W. Eaton <jwe@octave.org>
parents:
8745
diff
changeset
|
949 "<<=" { LEXER_DEBUG ("<<="); XBIN_OP_RETURN (LSHIFT_EQ, false, false); } |
5dd06f19e9be
handle commands in the lexer
John W. Eaton <jwe@octave.org>
parents:
8745
diff
changeset
|
950 ">>=" { LEXER_DEBUG (">>="); XBIN_OP_RETURN (RSHIFT_EQ, false, false); } |
2877 | 951 |
4608 | 952 \{{S}* { |
8535 | 953 LEXER_DEBUG ("\\{{S}*"); |
954 | |
3351 | 955 nesting_level.brace (); |
4608 | 956 |
8745
6dc61981d18b
better handling of object indexing in lexer
John W. Eaton <jwe@octave.org>
parents:
8701
diff
changeset
|
957 lexer_flags.looking_at_object_index.push_front |
6dc61981d18b
better handling of object indexing in lexer
John W. Eaton <jwe@octave.org>
parents:
8701
diff
changeset
|
958 (lexer_flags.looking_for_object_index); |
6dc61981d18b
better handling of object indexing in lexer
John W. Eaton <jwe@octave.org>
parents:
8701
diff
changeset
|
959 |
4608 | 960 current_input_column += yyleng; |
961 lexer_flags.quote_is_transpose = false; | |
962 lexer_flags.convert_spaces_to_comma = true; | |
8745
6dc61981d18b
better handling of object indexing in lexer
John W. Eaton <jwe@octave.org>
parents:
8701
diff
changeset
|
963 lexer_flags.looking_for_object_index = false; |
8746
5dd06f19e9be
handle commands in the lexer
John W. Eaton <jwe@octave.org>
parents:
8745
diff
changeset
|
964 lexer_flags.at_beginning_of_statement = false; |
4608 | 965 |
3351 | 966 promptflag--; |
4608 | 967 eat_whitespace (); |
968 | |
4613 | 969 lexer_flags.braceflag++; |
4608 | 970 BEGIN (MATRIX_START); |
4910 | 971 COUNT_TOK_AND_RETURN ('{'); |
3351 | 972 } |
973 | |
974 "}" { | |
8535 | 975 LEXER_DEBUG ("}"); |
976 | |
8745
6dc61981d18b
better handling of object indexing in lexer
John W. Eaton <jwe@octave.org>
parents:
8701
diff
changeset
|
977 lexer_flags.looking_at_object_index.pop_front (); |
6dc61981d18b
better handling of object indexing in lexer
John W. Eaton <jwe@octave.org>
parents:
8701
diff
changeset
|
978 |
6dc61981d18b
better handling of object indexing in lexer
John W. Eaton <jwe@octave.org>
parents:
8701
diff
changeset
|
979 lexer_flags.looking_for_object_index = true; |
8746
5dd06f19e9be
handle commands in the lexer
John W. Eaton <jwe@octave.org>
parents:
8745
diff
changeset
|
980 lexer_flags.at_beginning_of_statement = false; |
8745
6dc61981d18b
better handling of object indexing in lexer
John W. Eaton <jwe@octave.org>
parents:
8701
diff
changeset
|
981 |
3351 | 982 nesting_level.remove (); |
983 | |
4608 | 984 TOK_RETURN ('}'); |
3351 | 985 } |
986 | |
968 | 987 %{ |
2066 | 988 // Unrecognized input is a lexical error. |
968 | 989 %} |
1 | 990 |
2042 | 991 . { |
8535 | 992 LEXER_DEBUG ("."); |
993 | |
8447
adab48231a03
make input_line_number work again
John W. Eaton <jwe@octave.org>
parents:
8312
diff
changeset
|
994 xunput (yytext[0], yytext); |
4248 | 995 |
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
|
996 int c = text_yyinput (); |
4248 | 997 |
998 if (c != EOF) | |
4240 | 999 { |
1000 current_input_column++; | |
1001 | |
1002 error ("invalid character `%s' (ASCII %d) near line %d, column %d", | |
4248 | 1003 undo_string_escape (static_cast<char> (c)), c, |
4240 | 1004 input_line_number, current_input_column); |
1005 | |
1006 return LEXICAL_ERROR; | |
1007 } | |
1008 else | |
1009 TOK_RETURN (END_OF_INPUT); | |
2066 | 1010 } |
1 | 1011 |
1012 %% | |
1013 | |
767 | 1014 // GAG. |
1015 // | |
1016 // If we're reading a matrix and the next character is '[', make sure | |
1017 // that we insert a comma ahead of it. | |
1018 | |
146 | 1019 void |
1 | 1020 do_comma_insert_check (void) |
1021 { | |
1001 | 1022 int spc_gobbled = eat_continuation (); |
2970 | 1023 |
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
|
1024 int c = text_yyinput (); |
2970 | 1025 |
8447
adab48231a03
make input_line_number work again
John W. Eaton <jwe@octave.org>
parents:
8312
diff
changeset
|
1026 xunput (c, yytext); |
2970 | 1027 |
1001 | 1028 if (spc_gobbled) |
8745
6dc61981d18b
better handling of object indexing in lexer
John W. Eaton <jwe@octave.org>
parents:
8701
diff
changeset
|
1029 xunput (' ', yytext); |
6dc61981d18b
better handling of object indexing in lexer
John W. Eaton <jwe@octave.org>
parents:
8701
diff
changeset
|
1030 |
6dc61981d18b
better handling of object indexing in lexer
John W. Eaton <jwe@octave.org>
parents:
8701
diff
changeset
|
1031 lexer_flags.do_comma_insert = (! lexer_flags.looking_at_object_index.front () |
6dc61981d18b
better handling of object indexing in lexer
John W. Eaton <jwe@octave.org>
parents:
8701
diff
changeset
|
1032 && lexer_flags.bracketflag && c == '['); |
1 | 1033 } |
1034 | |
767 | 1035 // Fix things up for errors or interrupts. The parser is never called |
1036 // recursively, so it is always safe to reinitialize its state before | |
1037 // doing any parsing. | |
1038 | |
1 | 1039 void |
1040 reset_parser (void) | |
1041 { | |
1826 | 1042 // Start off on the right foot. |
4323 | 1043 BEGIN (INITIAL); |
4318 | 1044 |
3883 | 1045 parser_end_of_input = false; |
4238 | 1046 |
1047 while (! symtab_context.empty ()) | |
1048 symtab_context.pop (); | |
287 | 1049 |
1826 | 1050 // We do want a prompt by default. |
1 | 1051 promptflag = 1; |
287 | 1052 |
7723
74f5e0c7de9e
first pass at handling block comments
John W. Eaton <jwe@octave.org>
parents:
7722
diff
changeset
|
1053 // We are not in a block comment. |
74f5e0c7de9e
first pass at handling block comments
John W. Eaton <jwe@octave.org>
parents:
7722
diff
changeset
|
1054 block_comment_nesting_level = 0; |
74f5e0c7de9e
first pass at handling block comments
John W. Eaton <jwe@octave.org>
parents:
7722
diff
changeset
|
1055 |
3351 | 1056 // Error may have occurred inside some brackets, braces, or parentheses. |
985 | 1057 nesting_level.clear (); |
287 | 1058 |
1826 | 1059 // Clear out the stack of token info used to track line and column |
1060 // numbers. | |
143 | 1061 while (! token_stack.empty ()) |
4214 | 1062 { |
1063 delete token_stack.top (); | |
1064 token_stack.pop (); | |
1065 } | |
287 | 1066 |
1826 | 1067 // Can be reset by defining a function. |
985 | 1068 if (! (reading_script_file || reading_fcn_file)) |
1069 { | |
1070 current_input_column = 1; | |
8447
adab48231a03
make input_line_number work again
John W. Eaton <jwe@octave.org>
parents:
8312
diff
changeset
|
1071 input_line_number = command_editor::current_command_number (); |
985 | 1072 } |
287 | 1073 |
1826 | 1074 // Only ask for input from stdin if we are expecting interactive |
1075 // input. | |
3174 | 1076 if ((interactive || forced_interactive) |
3880 | 1077 && ! (reading_fcn_file |
1078 || reading_script_file | |
1079 || get_input_from_eval_string | |
3174 | 1080 || input_from_startup_file)) |
287 | 1081 yyrestart (stdin); |
991 | 1082 |
1826 | 1083 // Clear the buffer for help text. |
4426 | 1084 while (! help_buf.empty ()) |
1085 help_buf.pop (); | |
1755 | 1086 |
1826 | 1087 // Reset other flags. |
1088 lexer_flags.init (); | |
1 | 1089 } |
1090 | |
8447
adab48231a03
make input_line_number work again
John W. Eaton <jwe@octave.org>
parents:
8312
diff
changeset
|
1091 static void |
8535 | 1092 display_character (char c) |
1093 { | |
1094 if (isgraph (c)) | |
1095 std::cerr << c; | |
1096 else | |
1097 switch (c) | |
1098 { | |
1099 case 0: | |
1100 std::cerr << "NUL"; | |
1101 break; | |
1102 | |
1103 case 1: | |
1104 std::cerr << "SOH"; | |
1105 break; | |
1106 | |
1107 case 2: | |
1108 std::cerr << "STX"; | |
1109 break; | |
1110 | |
1111 case 3: | |
1112 std::cerr << "ETX"; | |
1113 break; | |
1114 | |
1115 case 4: | |
1116 std::cerr << "EOT"; | |
1117 break; | |
1118 | |
1119 case 5: | |
1120 std::cerr << "ENQ"; | |
1121 break; | |
1122 | |
1123 case 6: | |
1124 std::cerr << "ACK"; | |
1125 break; | |
1126 | |
1127 case 7: | |
1128 std::cerr << "\\a"; | |
1129 break; | |
1130 | |
1131 case 8: | |
1132 std::cerr << "\\b"; | |
1133 break; | |
1134 | |
1135 case 9: | |
1136 std::cerr << "\\t"; | |
1137 break; | |
1138 | |
1139 case 10: | |
1140 std::cerr << "\\n"; | |
1141 break; | |
1142 | |
1143 case 11: | |
1144 std::cerr << "\\v"; | |
1145 break; | |
1146 | |
1147 case 12: | |
1148 std::cerr << "\\f"; | |
1149 break; | |
1150 | |
1151 case 13: | |
1152 std::cerr << "\\r"; | |
1153 break; | |
1154 | |
1155 case 14: | |
1156 std::cerr << "SO"; | |
1157 break; | |
1158 | |
1159 case 15: | |
1160 std::cerr << "SI"; | |
1161 break; | |
1162 | |
1163 case 16: | |
1164 std::cerr << "DLE"; | |
1165 break; | |
1166 | |
1167 case 17: | |
1168 std::cerr << "DC1"; | |
1169 break; | |
1170 | |
1171 case 18: | |
1172 std::cerr << "DC2"; | |
1173 break; | |
1174 | |
1175 case 19: | |
1176 std::cerr << "DC3"; | |
1177 break; | |
1178 | |
1179 case 20: | |
1180 std::cerr << "DC4"; | |
1181 break; | |
1182 | |
1183 case 21: | |
1184 std::cerr << "NAK"; | |
1185 break; | |
1186 | |
1187 case 22: | |
1188 std::cerr << "SYN"; | |
1189 break; | |
1190 | |
1191 case 23: | |
1192 std::cerr << "ETB"; | |
1193 break; | |
1194 | |
1195 case 24: | |
1196 std::cerr << "CAN"; | |
1197 break; | |
1198 | |
1199 case 25: | |
1200 std::cerr << "EM"; | |
1201 break; | |
1202 | |
1203 case 26: | |
1204 std::cerr << "SUB"; | |
1205 break; | |
1206 | |
1207 case 27: | |
1208 std::cerr << "ESC"; | |
1209 break; | |
1210 | |
1211 case 28: | |
1212 std::cerr << "FS"; | |
1213 break; | |
1214 | |
1215 case 29: | |
1216 std::cerr << "GS"; | |
1217 break; | |
1218 | |
1219 case 30: | |
1220 std::cerr << "RS"; | |
1221 break; | |
1222 | |
1223 case 31: | |
1224 std::cerr << "US"; | |
1225 break; | |
1226 | |
1227 case 32: | |
1228 std::cerr << "SPACE"; | |
1229 break; | |
1230 | |
1231 case 127: | |
1232 std::cerr << "DEL"; | |
1233 break; | |
1234 } | |
1235 } | |
8745
6dc61981d18b
better handling of object indexing in lexer
John W. Eaton <jwe@octave.org>
parents:
8701
diff
changeset
|
1236 |
6dc61981d18b
better handling of object indexing in lexer
John W. Eaton <jwe@octave.org>
parents:
8701
diff
changeset
|
1237 static int |
6dc61981d18b
better handling of object indexing in lexer
John W. Eaton <jwe@octave.org>
parents:
8701
diff
changeset
|
1238 text_yyinput (void) |
6dc61981d18b
better handling of object indexing in lexer
John W. Eaton <jwe@octave.org>
parents:
8701
diff
changeset
|
1239 { |
6dc61981d18b
better handling of object indexing in lexer
John W. Eaton <jwe@octave.org>
parents:
8701
diff
changeset
|
1240 int c = yyinput (); |
6dc61981d18b
better handling of object indexing in lexer
John W. Eaton <jwe@octave.org>
parents:
8701
diff
changeset
|
1241 |
6dc61981d18b
better handling of object indexing in lexer
John W. Eaton <jwe@octave.org>
parents:
8701
diff
changeset
|
1242 if (lexer_debug_flag) |
6dc61981d18b
better handling of object indexing in lexer
John W. Eaton <jwe@octave.org>
parents:
8701
diff
changeset
|
1243 { |
6dc61981d18b
better handling of object indexing in lexer
John W. Eaton <jwe@octave.org>
parents:
8701
diff
changeset
|
1244 std::cerr << "I: "; |
6dc61981d18b
better handling of object indexing in lexer
John W. Eaton <jwe@octave.org>
parents:
8701
diff
changeset
|
1245 display_character (c); |
6dc61981d18b
better handling of object indexing in lexer
John W. Eaton <jwe@octave.org>
parents:
8701
diff
changeset
|
1246 std::cerr << std::endl; |
6dc61981d18b
better handling of object indexing in lexer
John W. Eaton <jwe@octave.org>
parents:
8701
diff
changeset
|
1247 } |
6dc61981d18b
better handling of object indexing in lexer
John W. Eaton <jwe@octave.org>
parents:
8701
diff
changeset
|
1248 |
6dc61981d18b
better handling of object indexing in lexer
John W. Eaton <jwe@octave.org>
parents:
8701
diff
changeset
|
1249 // Convert CRLF into just LF and single CR into LF. |
6dc61981d18b
better handling of object indexing in lexer
John W. Eaton <jwe@octave.org>
parents:
8701
diff
changeset
|
1250 |
6dc61981d18b
better handling of object indexing in lexer
John W. Eaton <jwe@octave.org>
parents:
8701
diff
changeset
|
1251 if (c == '\r') |
6dc61981d18b
better handling of object indexing in lexer
John W. Eaton <jwe@octave.org>
parents:
8701
diff
changeset
|
1252 { |
6dc61981d18b
better handling of object indexing in lexer
John W. Eaton <jwe@octave.org>
parents:
8701
diff
changeset
|
1253 c = yyinput (); |
6dc61981d18b
better handling of object indexing in lexer
John W. Eaton <jwe@octave.org>
parents:
8701
diff
changeset
|
1254 |
6dc61981d18b
better handling of object indexing in lexer
John W. Eaton <jwe@octave.org>
parents:
8701
diff
changeset
|
1255 if (lexer_debug_flag) |
6dc61981d18b
better handling of object indexing in lexer
John W. Eaton <jwe@octave.org>
parents:
8701
diff
changeset
|
1256 { |
6dc61981d18b
better handling of object indexing in lexer
John W. Eaton <jwe@octave.org>
parents:
8701
diff
changeset
|
1257 std::cerr << "I: "; |
6dc61981d18b
better handling of object indexing in lexer
John W. Eaton <jwe@octave.org>
parents:
8701
diff
changeset
|
1258 display_character (c); |
6dc61981d18b
better handling of object indexing in lexer
John W. Eaton <jwe@octave.org>
parents:
8701
diff
changeset
|
1259 std::cerr << std::endl; |
6dc61981d18b
better handling of object indexing in lexer
John W. Eaton <jwe@octave.org>
parents:
8701
diff
changeset
|
1260 } |
6dc61981d18b
better handling of object indexing in lexer
John W. Eaton <jwe@octave.org>
parents:
8701
diff
changeset
|
1261 |
6dc61981d18b
better handling of object indexing in lexer
John W. Eaton <jwe@octave.org>
parents:
8701
diff
changeset
|
1262 if (c != '\n') |
6dc61981d18b
better handling of object indexing in lexer
John W. Eaton <jwe@octave.org>
parents:
8701
diff
changeset
|
1263 { |
6dc61981d18b
better handling of object indexing in lexer
John W. Eaton <jwe@octave.org>
parents:
8701
diff
changeset
|
1264 xunput (c, yytext); |
6dc61981d18b
better handling of object indexing in lexer
John W. Eaton <jwe@octave.org>
parents:
8701
diff
changeset
|
1265 c = '\n'; |
6dc61981d18b
better handling of object indexing in lexer
John W. Eaton <jwe@octave.org>
parents:
8701
diff
changeset
|
1266 } |
6dc61981d18b
better handling of object indexing in lexer
John W. Eaton <jwe@octave.org>
parents:
8701
diff
changeset
|
1267 } |
6dc61981d18b
better handling of object indexing in lexer
John W. Eaton <jwe@octave.org>
parents:
8701
diff
changeset
|
1268 |
6dc61981d18b
better handling of object indexing in lexer
John W. Eaton <jwe@octave.org>
parents:
8701
diff
changeset
|
1269 if (c == '\n') |
6dc61981d18b
better handling of object indexing in lexer
John W. Eaton <jwe@octave.org>
parents:
8701
diff
changeset
|
1270 input_line_number++; |
6dc61981d18b
better handling of object indexing in lexer
John W. Eaton <jwe@octave.org>
parents:
8701
diff
changeset
|
1271 |
6dc61981d18b
better handling of object indexing in lexer
John W. Eaton <jwe@octave.org>
parents:
8701
diff
changeset
|
1272 return c; |
6dc61981d18b
better handling of object indexing in lexer
John W. Eaton <jwe@octave.org>
parents:
8701
diff
changeset
|
1273 } |
6dc61981d18b
better handling of object indexing in lexer
John W. Eaton <jwe@octave.org>
parents:
8701
diff
changeset
|
1274 |
8535 | 1275 static void |
8447
adab48231a03
make input_line_number work again
John W. Eaton <jwe@octave.org>
parents:
8312
diff
changeset
|
1276 xunput (char c, char *buf) |
adab48231a03
make input_line_number work again
John W. Eaton <jwe@octave.org>
parents:
8312
diff
changeset
|
1277 { |
8535 | 1278 if (lexer_debug_flag) |
1279 { | |
1280 std::cerr << "U: "; | |
1281 display_character (c); | |
1282 std::cerr << std::endl; | |
1283 } | |
1284 | |
8447
adab48231a03
make input_line_number work again
John W. Eaton <jwe@octave.org>
parents:
8312
diff
changeset
|
1285 if (c == '\n') |
adab48231a03
make input_line_number work again
John W. Eaton <jwe@octave.org>
parents:
8312
diff
changeset
|
1286 input_line_number--; |
adab48231a03
make input_line_number work again
John W. Eaton <jwe@octave.org>
parents:
8312
diff
changeset
|
1287 |
adab48231a03
make input_line_number work again
John W. Eaton <jwe@octave.org>
parents:
8312
diff
changeset
|
1288 yyunput (c, buf); |
adab48231a03
make input_line_number work again
John W. Eaton <jwe@octave.org>
parents:
8312
diff
changeset
|
1289 } |
adab48231a03
make input_line_number work again
John W. Eaton <jwe@octave.org>
parents:
8312
diff
changeset
|
1290 |
767 | 1291 // If we read some newlines, we need figure out what column we're |
1292 // really looking at. | |
1293 | |
1 | 1294 static void |
1295 fixup_column_count (char *s) | |
1296 { | |
1297 char c; | |
1298 while ((c = *s++) != '\0') | |
1299 { | |
1300 if (c == '\n') | |
8447
adab48231a03
make input_line_number work again
John W. Eaton <jwe@octave.org>
parents:
8312
diff
changeset
|
1301 { |
adab48231a03
make input_line_number work again
John W. Eaton <jwe@octave.org>
parents:
8312
diff
changeset
|
1302 input_line_number++; |
adab48231a03
make input_line_number work again
John W. Eaton <jwe@octave.org>
parents:
8312
diff
changeset
|
1303 current_input_column = 1; |
adab48231a03
make input_line_number work again
John W. Eaton <jwe@octave.org>
parents:
8312
diff
changeset
|
1304 } |
1 | 1305 else |
1306 current_input_column++; | |
1307 } | |
1308 } | |
1309 | |
767 | 1310 // Include these so that we don't have to link to libfl.a. |
246 | 1311 |
3332 | 1312 int |
1 | 1313 yywrap (void) |
1314 { | |
287 | 1315 return 1; |
1 | 1316 } |
1317 | |
767 | 1318 // Tell us all what the current buffer is. |
1319 | |
1 | 1320 YY_BUFFER_STATE |
1321 current_buffer (void) | |
1322 { | |
1323 return YY_CURRENT_BUFFER; | |
1324 } | |
1325 | |
767 | 1326 // Create a new buffer. |
1327 | |
1 | 1328 YY_BUFFER_STATE |
1329 create_buffer (FILE *f) | |
1330 { | |
1331 return yy_create_buffer (f, YY_BUF_SIZE); | |
1332 } | |
1333 | |
767 | 1334 // Start reading a new buffer. |
1335 | |
1 | 1336 void |
1337 switch_to_buffer (YY_BUFFER_STATE buf) | |
1338 { | |
1339 yy_switch_to_buffer (buf); | |
1340 } | |
1341 | |
767 | 1342 // Delete a buffer. |
1343 | |
1 | 1344 void |
1345 delete_buffer (YY_BUFFER_STATE buf) | |
1346 { | |
1347 yy_delete_buffer (buf); | |
1348 } | |
1349 | |
767 | 1350 // Restore a buffer (for unwind-prot). |
1351 | |
1 | 1352 void |
1353 restore_input_buffer (void *buf) | |
1354 { | |
2861 | 1355 switch_to_buffer (static_cast<YY_BUFFER_STATE> (buf)); |
1 | 1356 } |
1357 | |
767 | 1358 // Delete a buffer (for unwind-prot). |
1359 | |
1 | 1360 void |
1361 delete_input_buffer (void *buf) | |
1362 { | |
2861 | 1363 delete_buffer (static_cast<YY_BUFFER_STATE> (buf)); |
1 | 1364 } |
1365 | |
8745
6dc61981d18b
better handling of object indexing in lexer
John W. Eaton <jwe@octave.org>
parents:
8701
diff
changeset
|
1366 static bool |
6dc61981d18b
better handling of object indexing in lexer
John W. Eaton <jwe@octave.org>
parents:
8701
diff
changeset
|
1367 inside_any_object_index (void) |
6dc61981d18b
better handling of object indexing in lexer
John W. Eaton <jwe@octave.org>
parents:
8701
diff
changeset
|
1368 { |
6dc61981d18b
better handling of object indexing in lexer
John W. Eaton <jwe@octave.org>
parents:
8701
diff
changeset
|
1369 bool retval = false; |
6dc61981d18b
better handling of object indexing in lexer
John W. Eaton <jwe@octave.org>
parents:
8701
diff
changeset
|
1370 |
6dc61981d18b
better handling of object indexing in lexer
John W. Eaton <jwe@octave.org>
parents:
8701
diff
changeset
|
1371 for (std::list<bool>::const_iterator i = lexer_flags.looking_at_object_index.begin (); |
6dc61981d18b
better handling of object indexing in lexer
John W. Eaton <jwe@octave.org>
parents:
8701
diff
changeset
|
1372 i != lexer_flags.looking_at_object_index.end (); i++) |
6dc61981d18b
better handling of object indexing in lexer
John W. Eaton <jwe@octave.org>
parents:
8701
diff
changeset
|
1373 { |
6dc61981d18b
better handling of object indexing in lexer
John W. Eaton <jwe@octave.org>
parents:
8701
diff
changeset
|
1374 if (*i) |
6dc61981d18b
better handling of object indexing in lexer
John W. Eaton <jwe@octave.org>
parents:
8701
diff
changeset
|
1375 { |
6dc61981d18b
better handling of object indexing in lexer
John W. Eaton <jwe@octave.org>
parents:
8701
diff
changeset
|
1376 retval = true; |
6dc61981d18b
better handling of object indexing in lexer
John W. Eaton <jwe@octave.org>
parents:
8701
diff
changeset
|
1377 break; |
6dc61981d18b
better handling of object indexing in lexer
John W. Eaton <jwe@octave.org>
parents:
8701
diff
changeset
|
1378 } |
6dc61981d18b
better handling of object indexing in lexer
John W. Eaton <jwe@octave.org>
parents:
8701
diff
changeset
|
1379 } |
6dc61981d18b
better handling of object indexing in lexer
John W. Eaton <jwe@octave.org>
parents:
8701
diff
changeset
|
1380 |
6dc61981d18b
better handling of object indexing in lexer
John W. Eaton <jwe@octave.org>
parents:
8701
diff
changeset
|
1381 return retval; |
6dc61981d18b
better handling of object indexing in lexer
John W. Eaton <jwe@octave.org>
parents:
8701
diff
changeset
|
1382 } |
6dc61981d18b
better handling of object indexing in lexer
John W. Eaton <jwe@octave.org>
parents:
8701
diff
changeset
|
1383 |
4238 | 1384 // Handle keywords. Return -1 if the keyword should be ignored. |
767 | 1385 |
1 | 1386 static int |
4867 | 1387 is_keyword_token (const std::string& s) |
1 | 1388 { |
3805 | 1389 int l = input_line_number; |
1390 int c = current_input_column; | |
1391 | |
1823 | 1392 int len = s.length (); |
922 | 1393 |
5088 | 1394 const octave_kw *kw = octave_kw_hash::in_word_set (s.c_str (), len); |
191 | 1395 |
1497 | 1396 if (kw) |
143 | 1397 { |
1497 | 1398 yylval.tok_val = 0; |
1399 | |
1400 switch (kw->kw_id) | |
1401 { | |
1402 case break_kw: | |
1403 case catch_kw: | |
1404 case continue_kw: | |
1405 case else_kw: | |
2764 | 1406 case otherwise_kw: |
1497 | 1407 case return_kw: |
8746
5dd06f19e9be
handle commands in the lexer
John W. Eaton <jwe@octave.org>
parents:
8745
diff
changeset
|
1408 case unwind_protect_cleanup_kw: |
5dd06f19e9be
handle commands in the lexer
John W. Eaton <jwe@octave.org>
parents:
8745
diff
changeset
|
1409 lexer_flags.at_beginning_of_statement = true; |
5dd06f19e9be
handle commands in the lexer
John W. Eaton <jwe@octave.org>
parents:
8745
diff
changeset
|
1410 break; |
5dd06f19e9be
handle commands in the lexer
John W. Eaton <jwe@octave.org>
parents:
8745
diff
changeset
|
1411 |
5dd06f19e9be
handle commands in the lexer
John W. Eaton <jwe@octave.org>
parents:
8745
diff
changeset
|
1412 case case_kw: |
5dd06f19e9be
handle commands in the lexer
John W. Eaton <jwe@octave.org>
parents:
8745
diff
changeset
|
1413 case elseif_kw: |
5dd06f19e9be
handle commands in the lexer
John W. Eaton <jwe@octave.org>
parents:
8745
diff
changeset
|
1414 case global_kw: |
2846 | 1415 case static_kw: |
3484 | 1416 case until_kw: |
8746
5dd06f19e9be
handle commands in the lexer
John W. Eaton <jwe@octave.org>
parents:
8745
diff
changeset
|
1417 break; |
1497 | 1418 |
1419 case end_kw: | |
8745
6dc61981d18b
better handling of object indexing in lexer
John W. Eaton <jwe@octave.org>
parents:
8701
diff
changeset
|
1420 if (inside_any_object_index () |
8136
2b2ca62f8ab6
dispatch to user-defined end function for classes if one is defined
John W. Eaton <jwe@octave.org>
parents:
8021
diff
changeset
|
1421 || (lexer_flags.defining_func |
2b2ca62f8ab6
dispatch to user-defined end function for classes if one is defined
John W. Eaton <jwe@octave.org>
parents:
8021
diff
changeset
|
1422 && ! (lexer_flags.looking_at_return_list |
2b2ca62f8ab6
dispatch to user-defined end function for classes if one is defined
John W. Eaton <jwe@octave.org>
parents:
8021
diff
changeset
|
1423 || lexer_flags.parsed_function_name))) |
4234 | 1424 return 0; |
9474
25ed2d6aacf6
Parse nested functions more accurately.
David Grundberg <individ@acc.umu.se>
parents:
9324
diff
changeset
|
1425 |
25ed2d6aacf6
Parse nested functions more accurately.
David Grundberg <individ@acc.umu.se>
parents:
9324
diff
changeset
|
1426 yylval.tok_val = new token (token::simple_end, l, c); |
25ed2d6aacf6
Parse nested functions more accurately.
David Grundberg <individ@acc.umu.se>
parents:
9324
diff
changeset
|
1427 lexer_flags.at_beginning_of_statement = true; |
1497 | 1428 break; |
1429 | |
1430 case end_try_catch_kw: | |
8746
5dd06f19e9be
handle commands in the lexer
John W. Eaton <jwe@octave.org>
parents:
8745
diff
changeset
|
1431 yylval.tok_val = new token (token::try_catch_end, l, c); |
5dd06f19e9be
handle commands in the lexer
John W. Eaton <jwe@octave.org>
parents:
8745
diff
changeset
|
1432 lexer_flags.at_beginning_of_statement = true; |
1497 | 1433 break; |
1434 | |
1435 case end_unwind_protect_kw: | |
8746
5dd06f19e9be
handle commands in the lexer
John W. Eaton <jwe@octave.org>
parents:
8745
diff
changeset
|
1436 yylval.tok_val = new token (token::unwind_protect_end, l, c); |
5dd06f19e9be
handle commands in the lexer
John W. Eaton <jwe@octave.org>
parents:
8745
diff
changeset
|
1437 lexer_flags.at_beginning_of_statement = true; |
1497 | 1438 break; |
1439 | |
1440 case endfor_kw: | |
8746
5dd06f19e9be
handle commands in the lexer
John W. Eaton <jwe@octave.org>
parents:
8745
diff
changeset
|
1441 yylval.tok_val = new token (token::for_end, l, c); |
5dd06f19e9be
handle commands in the lexer
John W. Eaton <jwe@octave.org>
parents:
8745
diff
changeset
|
1442 lexer_flags.at_beginning_of_statement = true; |
1497 | 1443 break; |
1444 | |
1445 case endfunction_kw: | |
9474
25ed2d6aacf6
Parse nested functions more accurately.
David Grundberg <individ@acc.umu.se>
parents:
9324
diff
changeset
|
1446 yylval.tok_val = new token (token::function_end, l, c); |
25ed2d6aacf6
Parse nested functions more accurately.
David Grundberg <individ@acc.umu.se>
parents:
9324
diff
changeset
|
1447 lexer_flags.at_beginning_of_statement = true; |
1497 | 1448 break; |
1449 | |
1450 case endif_kw: | |
8746
5dd06f19e9be
handle commands in the lexer
John W. Eaton <jwe@octave.org>
parents:
8745
diff
changeset
|
1451 yylval.tok_val = new token (token::if_end, l, c); |
5dd06f19e9be
handle commands in the lexer
John W. Eaton <jwe@octave.org>
parents:
8745
diff
changeset
|
1452 lexer_flags.at_beginning_of_statement = true; |
1497 | 1453 break; |
1454 | |
2764 | 1455 case endswitch_kw: |
8746
5dd06f19e9be
handle commands in the lexer
John W. Eaton <jwe@octave.org>
parents:
8745
diff
changeset
|
1456 yylval.tok_val = new token (token::switch_end, l, c); |
5dd06f19e9be
handle commands in the lexer
John W. Eaton <jwe@octave.org>
parents:
8745
diff
changeset
|
1457 lexer_flags.at_beginning_of_statement = true; |
2764 | 1458 break; |
1459 | |
1497 | 1460 case endwhile_kw: |
8746
5dd06f19e9be
handle commands in the lexer
John W. Eaton <jwe@octave.org>
parents:
8745
diff
changeset
|
1461 yylval.tok_val = new token (token::while_end, l, c); |
5dd06f19e9be
handle commands in the lexer
John W. Eaton <jwe@octave.org>
parents:
8745
diff
changeset
|
1462 lexer_flags.at_beginning_of_statement = true; |
1497 | 1463 break; |
1464 | |
1465 case for_kw: | |
1466 case while_kw: | |
8746
5dd06f19e9be
handle commands in the lexer
John W. Eaton <jwe@octave.org>
parents:
8745
diff
changeset
|
1467 promptflag--; |
5dd06f19e9be
handle commands in the lexer
John W. Eaton <jwe@octave.org>
parents:
8745
diff
changeset
|
1468 lexer_flags.looping++; |
5dd06f19e9be
handle commands in the lexer
John W. Eaton <jwe@octave.org>
parents:
8745
diff
changeset
|
1469 break; |
4238 | 1470 |
1471 case do_kw: | |
8746
5dd06f19e9be
handle commands in the lexer
John W. Eaton <jwe@octave.org>
parents:
8745
diff
changeset
|
1472 lexer_flags.at_beginning_of_statement = true; |
1497 | 1473 promptflag--; |
1826 | 1474 lexer_flags.looping++; |
1497 | 1475 break; |
1476 | |
8746
5dd06f19e9be
handle commands in the lexer
John W. Eaton <jwe@octave.org>
parents:
8745
diff
changeset
|
1477 case try_kw: |
5dd06f19e9be
handle commands in the lexer
John W. Eaton <jwe@octave.org>
parents:
8745
diff
changeset
|
1478 case unwind_protect_kw: |
5dd06f19e9be
handle commands in the lexer
John W. Eaton <jwe@octave.org>
parents:
8745
diff
changeset
|
1479 lexer_flags.at_beginning_of_statement = true; |
5dd06f19e9be
handle commands in the lexer
John W. Eaton <jwe@octave.org>
parents:
8745
diff
changeset
|
1480 promptflag--; |
5dd06f19e9be
handle commands in the lexer
John W. Eaton <jwe@octave.org>
parents:
8745
diff
changeset
|
1481 break; |
5dd06f19e9be
handle commands in the lexer
John W. Eaton <jwe@octave.org>
parents:
8745
diff
changeset
|
1482 |
1497 | 1483 case if_kw: |
2764 | 1484 case switch_kw: |
1497 | 1485 promptflag--; |
1486 break; | |
1487 | |
1488 case function_kw: | |
9474
25ed2d6aacf6
Parse nested functions more accurately.
David Grundberg <individ@acc.umu.se>
parents:
9324
diff
changeset
|
1489 promptflag--; |
25ed2d6aacf6
Parse nested functions more accurately.
David Grundberg <individ@acc.umu.se>
parents:
9324
diff
changeset
|
1490 |
25ed2d6aacf6
Parse nested functions more accurately.
David Grundberg <individ@acc.umu.se>
parents:
9324
diff
changeset
|
1491 lexer_flags.defining_func = true; |
25ed2d6aacf6
Parse nested functions more accurately.
David Grundberg <individ@acc.umu.se>
parents:
9324
diff
changeset
|
1492 lexer_flags.parsed_function_name = false; |
25ed2d6aacf6
Parse nested functions more accurately.
David Grundberg <individ@acc.umu.se>
parents:
9324
diff
changeset
|
1493 |
25ed2d6aacf6
Parse nested functions more accurately.
David Grundberg <individ@acc.umu.se>
parents:
9324
diff
changeset
|
1494 if (! (reading_fcn_file || reading_script_file)) |
25ed2d6aacf6
Parse nested functions more accurately.
David Grundberg <individ@acc.umu.se>
parents:
9324
diff
changeset
|
1495 input_line_number = 1; |
1497 | 1496 break; |
1497 | |
3174 | 1498 case magic_file_kw: |
1499 { | |
1500 if ((reading_fcn_file || reading_script_file) | |
1501 && ! curr_fcn_file_full_name.empty ()) | |
1502 yylval.tok_val = new token (curr_fcn_file_full_name, l, c); | |
1503 else | |
1504 yylval.tok_val = new token ("stdin", l, c); | |
1505 } | |
1506 break; | |
1507 | |
1508 case magic_line_kw: | |
1509 yylval.tok_val = new token (static_cast<double> (l), "", l, c); | |
1510 break; | |
1511 | |
1497 | 1512 default: |
1513 panic_impossible (); | |
1514 } | |
1515 | |
1516 if (! yylval.tok_val) | |
1517 yylval.tok_val = new token (l, c); | |
1518 | |
476 | 1519 token_stack.push (yylval.tok_val); |
1497 | 1520 |
1521 return kw->tok; | |
143 | 1522 } |
1 | 1523 |
1524 return 0; | |
1525 } | |
1526 | |
2702 | 1527 static bool |
3523 | 1528 is_variable (const std::string& name) |
2702 | 1529 { |
8001
ff9e7873f8ea
improve handling of command-style names in matrix_or_assign_lhs context
John W. Eaton <jwe@octave.org>
parents:
7898
diff
changeset
|
1530 return (symbol_table::is_variable (name) |
ff9e7873f8ea
improve handling of command-style names in matrix_or_assign_lhs context
John W. Eaton <jwe@octave.org>
parents:
7898
diff
changeset
|
1531 || (lexer_flags.pending_local_variables.find (name) |
ff9e7873f8ea
improve handling of command-style names in matrix_or_assign_lhs context
John W. Eaton <jwe@octave.org>
parents:
7898
diff
changeset
|
1532 != lexer_flags.pending_local_variables.end ())); |
2702 | 1533 } |
1534 | |
7723
74f5e0c7de9e
first pass at handling block comments
John W. Eaton <jwe@octave.org>
parents:
7722
diff
changeset
|
1535 static std::string |
74f5e0c7de9e
first pass at handling block comments
John W. Eaton <jwe@octave.org>
parents:
7722
diff
changeset
|
1536 grab_block_comment (stream_reader& reader, bool& eof) |
74f5e0c7de9e
first pass at handling block comments
John W. Eaton <jwe@octave.org>
parents:
7722
diff
changeset
|
1537 { |
74f5e0c7de9e
first pass at handling block comments
John W. Eaton <jwe@octave.org>
parents:
7722
diff
changeset
|
1538 std::string buf; |
74f5e0c7de9e
first pass at handling block comments
John W. Eaton <jwe@octave.org>
parents:
7722
diff
changeset
|
1539 |
74f5e0c7de9e
first pass at handling block comments
John W. Eaton <jwe@octave.org>
parents:
7722
diff
changeset
|
1540 bool at_bol = true; |
74f5e0c7de9e
first pass at handling block comments
John W. Eaton <jwe@octave.org>
parents:
7722
diff
changeset
|
1541 bool look_for_marker = false; |
74f5e0c7de9e
first pass at handling block comments
John W. Eaton <jwe@octave.org>
parents:
7722
diff
changeset
|
1542 |
74f5e0c7de9e
first pass at handling block comments
John W. Eaton <jwe@octave.org>
parents:
7722
diff
changeset
|
1543 bool warned_incompatible = false; |
74f5e0c7de9e
first pass at handling block comments
John W. Eaton <jwe@octave.org>
parents:
7722
diff
changeset
|
1544 |
74f5e0c7de9e
first pass at handling block comments
John W. Eaton <jwe@octave.org>
parents:
7722
diff
changeset
|
1545 int c = 0; |
74f5e0c7de9e
first pass at handling block comments
John W. Eaton <jwe@octave.org>
parents:
7722
diff
changeset
|
1546 |
74f5e0c7de9e
first pass at handling block comments
John W. Eaton <jwe@octave.org>
parents:
7722
diff
changeset
|
1547 while ((c = reader.getc ()) != EOF) |
74f5e0c7de9e
first pass at handling block comments
John W. Eaton <jwe@octave.org>
parents:
7722
diff
changeset
|
1548 { |
74f5e0c7de9e
first pass at handling block comments
John W. Eaton <jwe@octave.org>
parents:
7722
diff
changeset
|
1549 current_input_column++; |
74f5e0c7de9e
first pass at handling block comments
John W. Eaton <jwe@octave.org>
parents:
7722
diff
changeset
|
1550 |
74f5e0c7de9e
first pass at handling block comments
John W. Eaton <jwe@octave.org>
parents:
7722
diff
changeset
|
1551 if (look_for_marker) |
74f5e0c7de9e
first pass at handling block comments
John W. Eaton <jwe@octave.org>
parents:
7722
diff
changeset
|
1552 { |
74f5e0c7de9e
first pass at handling block comments
John W. Eaton <jwe@octave.org>
parents:
7722
diff
changeset
|
1553 at_bol = false; |
74f5e0c7de9e
first pass at handling block comments
John W. Eaton <jwe@octave.org>
parents:
7722
diff
changeset
|
1554 look_for_marker = false; |
74f5e0c7de9e
first pass at handling block comments
John W. Eaton <jwe@octave.org>
parents:
7722
diff
changeset
|
1555 |
74f5e0c7de9e
first pass at handling block comments
John W. Eaton <jwe@octave.org>
parents:
7722
diff
changeset
|
1556 if (c == '{' || c == '}') |
74f5e0c7de9e
first pass at handling block comments
John W. Eaton <jwe@octave.org>
parents:
7722
diff
changeset
|
1557 { |
74f5e0c7de9e
first pass at handling block comments
John W. Eaton <jwe@octave.org>
parents:
7722
diff
changeset
|
1558 std::string tmp_buf (1, static_cast<char> (c)); |
74f5e0c7de9e
first pass at handling block comments
John W. Eaton <jwe@octave.org>
parents:
7722
diff
changeset
|
1559 |
74f5e0c7de9e
first pass at handling block comments
John W. Eaton <jwe@octave.org>
parents:
7722
diff
changeset
|
1560 int type = c; |
74f5e0c7de9e
first pass at handling block comments
John W. Eaton <jwe@octave.org>
parents:
7722
diff
changeset
|
1561 |
74f5e0c7de9e
first pass at handling block comments
John W. Eaton <jwe@octave.org>
parents:
7722
diff
changeset
|
1562 bool done = false; |
74f5e0c7de9e
first pass at handling block comments
John W. Eaton <jwe@octave.org>
parents:
7722
diff
changeset
|
1563 |
74f5e0c7de9e
first pass at handling block comments
John W. Eaton <jwe@octave.org>
parents:
7722
diff
changeset
|
1564 while ((c = reader.getc ()) != EOF && ! done) |
74f5e0c7de9e
first pass at handling block comments
John W. Eaton <jwe@octave.org>
parents:
7722
diff
changeset
|
1565 { |
74f5e0c7de9e
first pass at handling block comments
John W. Eaton <jwe@octave.org>
parents:
7722
diff
changeset
|
1566 current_input_column++; |
74f5e0c7de9e
first pass at handling block comments
John W. Eaton <jwe@octave.org>
parents:
7722
diff
changeset
|
1567 |
74f5e0c7de9e
first pass at handling block comments
John W. Eaton <jwe@octave.org>
parents:
7722
diff
changeset
|
1568 switch (c) |
74f5e0c7de9e
first pass at handling block comments
John W. Eaton <jwe@octave.org>
parents:
7722
diff
changeset
|
1569 { |
74f5e0c7de9e
first pass at handling block comments
John W. Eaton <jwe@octave.org>
parents:
7722
diff
changeset
|
1570 case ' ': |
74f5e0c7de9e
first pass at handling block comments
John W. Eaton <jwe@octave.org>
parents:
7722
diff
changeset
|
1571 case '\t': |
74f5e0c7de9e
first pass at handling block comments
John W. Eaton <jwe@octave.org>
parents:
7722
diff
changeset
|
1572 tmp_buf += static_cast<char> (c); |
74f5e0c7de9e
first pass at handling block comments
John W. Eaton <jwe@octave.org>
parents:
7722
diff
changeset
|
1573 break; |
74f5e0c7de9e
first pass at handling block comments
John W. Eaton <jwe@octave.org>
parents:
7722
diff
changeset
|
1574 |
74f5e0c7de9e
first pass at handling block comments
John W. Eaton <jwe@octave.org>
parents:
7722
diff
changeset
|
1575 case '\n': |
74f5e0c7de9e
first pass at handling block comments
John W. Eaton <jwe@octave.org>
parents:
7722
diff
changeset
|
1576 { |
74f5e0c7de9e
first pass at handling block comments
John W. Eaton <jwe@octave.org>
parents:
7722
diff
changeset
|
1577 current_input_column = 0; |
74f5e0c7de9e
first pass at handling block comments
John W. Eaton <jwe@octave.org>
parents:
7722
diff
changeset
|
1578 at_bol = true; |
74f5e0c7de9e
first pass at handling block comments
John W. Eaton <jwe@octave.org>
parents:
7722
diff
changeset
|
1579 done = true; |
74f5e0c7de9e
first pass at handling block comments
John W. Eaton <jwe@octave.org>
parents:
7722
diff
changeset
|
1580 |
74f5e0c7de9e
first pass at handling block comments
John W. Eaton <jwe@octave.org>
parents:
7722
diff
changeset
|
1581 if (type == '{') |
74f5e0c7de9e
first pass at handling block comments
John W. Eaton <jwe@octave.org>
parents:
7722
diff
changeset
|
1582 { |
74f5e0c7de9e
first pass at handling block comments
John W. Eaton <jwe@octave.org>
parents:
7722
diff
changeset
|
1583 block_comment_nesting_level++; |
74f5e0c7de9e
first pass at handling block comments
John W. Eaton <jwe@octave.org>
parents:
7722
diff
changeset
|
1584 promptflag--; |
74f5e0c7de9e
first pass at handling block comments
John W. Eaton <jwe@octave.org>
parents:
7722
diff
changeset
|
1585 } |
74f5e0c7de9e
first pass at handling block comments
John W. Eaton <jwe@octave.org>
parents:
7722
diff
changeset
|
1586 else |
74f5e0c7de9e
first pass at handling block comments
John W. Eaton <jwe@octave.org>
parents:
7722
diff
changeset
|
1587 { |
74f5e0c7de9e
first pass at handling block comments
John W. Eaton <jwe@octave.org>
parents:
7722
diff
changeset
|
1588 block_comment_nesting_level--; |
74f5e0c7de9e
first pass at handling block comments
John W. Eaton <jwe@octave.org>
parents:
7722
diff
changeset
|
1589 promptflag++; |
74f5e0c7de9e
first pass at handling block comments
John W. Eaton <jwe@octave.org>
parents:
7722
diff
changeset
|
1590 |
74f5e0c7de9e
first pass at handling block comments
John W. Eaton <jwe@octave.org>
parents:
7722
diff
changeset
|
1591 if (block_comment_nesting_level == 0) |
74f5e0c7de9e
first pass at handling block comments
John W. Eaton <jwe@octave.org>
parents:
7722
diff
changeset
|
1592 { |
74f5e0c7de9e
first pass at handling block comments
John W. Eaton <jwe@octave.org>
parents:
7722
diff
changeset
|
1593 buf += grab_comment_block (reader, true, eof); |
74f5e0c7de9e
first pass at handling block comments
John W. Eaton <jwe@octave.org>
parents:
7722
diff
changeset
|
1594 |
74f5e0c7de9e
first pass at handling block comments
John W. Eaton <jwe@octave.org>
parents:
7722
diff
changeset
|
1595 return buf; |
74f5e0c7de9e
first pass at handling block comments
John W. Eaton <jwe@octave.org>
parents:
7722
diff
changeset
|
1596 } |
74f5e0c7de9e
first pass at handling block comments
John W. Eaton <jwe@octave.org>
parents:
7722
diff
changeset
|
1597 } |
74f5e0c7de9e
first pass at handling block comments
John W. Eaton <jwe@octave.org>
parents:
7722
diff
changeset
|
1598 } |
74f5e0c7de9e
first pass at handling block comments
John W. Eaton <jwe@octave.org>
parents:
7722
diff
changeset
|
1599 break; |
74f5e0c7de9e
first pass at handling block comments
John W. Eaton <jwe@octave.org>
parents:
7722
diff
changeset
|
1600 |
74f5e0c7de9e
first pass at handling block comments
John W. Eaton <jwe@octave.org>
parents:
7722
diff
changeset
|
1601 default: |
74f5e0c7de9e
first pass at handling block comments
John W. Eaton <jwe@octave.org>
parents:
7722
diff
changeset
|
1602 at_bol = false; |
74f5e0c7de9e
first pass at handling block comments
John W. Eaton <jwe@octave.org>
parents:
7722
diff
changeset
|
1603 tmp_buf += static_cast<char> (c); |
74f5e0c7de9e
first pass at handling block comments
John W. Eaton <jwe@octave.org>
parents:
7722
diff
changeset
|
1604 buf += tmp_buf; |
74f5e0c7de9e
first pass at handling block comments
John W. Eaton <jwe@octave.org>
parents:
7722
diff
changeset
|
1605 done = true; |
74f5e0c7de9e
first pass at handling block comments
John W. Eaton <jwe@octave.org>
parents:
7722
diff
changeset
|
1606 break; |
74f5e0c7de9e
first pass at handling block comments
John W. Eaton <jwe@octave.org>
parents:
7722
diff
changeset
|
1607 } |
74f5e0c7de9e
first pass at handling block comments
John W. Eaton <jwe@octave.org>
parents:
7722
diff
changeset
|
1608 } |
74f5e0c7de9e
first pass at handling block comments
John W. Eaton <jwe@octave.org>
parents:
7722
diff
changeset
|
1609 } |
74f5e0c7de9e
first pass at handling block comments
John W. Eaton <jwe@octave.org>
parents:
7722
diff
changeset
|
1610 } |
74f5e0c7de9e
first pass at handling block comments
John W. Eaton <jwe@octave.org>
parents:
7722
diff
changeset
|
1611 |
7898
cce16b4e0970
lex.l (grab_block_comment): Use parens around || expression within && expression
John W. Eaton <jwe@octave.org>
parents:
7728
diff
changeset
|
1612 if (at_bol && (c == '%' || c == '#')) |
7723
74f5e0c7de9e
first pass at handling block comments
John W. Eaton <jwe@octave.org>
parents:
7722
diff
changeset
|
1613 { |
74f5e0c7de9e
first pass at handling block comments
John W. Eaton <jwe@octave.org>
parents:
7722
diff
changeset
|
1614 if (c == '#' && ! warned_incompatible) |
74f5e0c7de9e
first pass at handling block comments
John W. Eaton <jwe@octave.org>
parents:
7722
diff
changeset
|
1615 { |
74f5e0c7de9e
first pass at handling block comments
John W. Eaton <jwe@octave.org>
parents:
7722
diff
changeset
|
1616 warned_incompatible = true; |
74f5e0c7de9e
first pass at handling block comments
John W. Eaton <jwe@octave.org>
parents:
7722
diff
changeset
|
1617 maybe_gripe_matlab_incompatible_comment (c); |
74f5e0c7de9e
first pass at handling block comments
John W. Eaton <jwe@octave.org>
parents:
7722
diff
changeset
|
1618 } |
74f5e0c7de9e
first pass at handling block comments
John W. Eaton <jwe@octave.org>
parents:
7722
diff
changeset
|
1619 |
74f5e0c7de9e
first pass at handling block comments
John W. Eaton <jwe@octave.org>
parents:
7722
diff
changeset
|
1620 at_bol = false; |
74f5e0c7de9e
first pass at handling block comments
John W. Eaton <jwe@octave.org>
parents:
7722
diff
changeset
|
1621 look_for_marker = true; |
74f5e0c7de9e
first pass at handling block comments
John W. Eaton <jwe@octave.org>
parents:
7722
diff
changeset
|
1622 } |
74f5e0c7de9e
first pass at handling block comments
John W. Eaton <jwe@octave.org>
parents:
7722
diff
changeset
|
1623 else |
74f5e0c7de9e
first pass at handling block comments
John W. Eaton <jwe@octave.org>
parents:
7722
diff
changeset
|
1624 { |
74f5e0c7de9e
first pass at handling block comments
John W. Eaton <jwe@octave.org>
parents:
7722
diff
changeset
|
1625 buf += static_cast<char> (c); |
74f5e0c7de9e
first pass at handling block comments
John W. Eaton <jwe@octave.org>
parents:
7722
diff
changeset
|
1626 |
74f5e0c7de9e
first pass at handling block comments
John W. Eaton <jwe@octave.org>
parents:
7722
diff
changeset
|
1627 if (c == '\n') |
74f5e0c7de9e
first pass at handling block comments
John W. Eaton <jwe@octave.org>
parents:
7722
diff
changeset
|
1628 { |
74f5e0c7de9e
first pass at handling block comments
John W. Eaton <jwe@octave.org>
parents:
7722
diff
changeset
|
1629 current_input_column = 0; |
74f5e0c7de9e
first pass at handling block comments
John W. Eaton <jwe@octave.org>
parents:
7722
diff
changeset
|
1630 at_bol = true; |
74f5e0c7de9e
first pass at handling block comments
John W. Eaton <jwe@octave.org>
parents:
7722
diff
changeset
|
1631 } |
74f5e0c7de9e
first pass at handling block comments
John W. Eaton <jwe@octave.org>
parents:
7722
diff
changeset
|
1632 } |
74f5e0c7de9e
first pass at handling block comments
John W. Eaton <jwe@octave.org>
parents:
7722
diff
changeset
|
1633 } |
74f5e0c7de9e
first pass at handling block comments
John W. Eaton <jwe@octave.org>
parents:
7722
diff
changeset
|
1634 |
74f5e0c7de9e
first pass at handling block comments
John W. Eaton <jwe@octave.org>
parents:
7722
diff
changeset
|
1635 if (c == EOF) |
74f5e0c7de9e
first pass at handling block comments
John W. Eaton <jwe@octave.org>
parents:
7722
diff
changeset
|
1636 eof = true; |
74f5e0c7de9e
first pass at handling block comments
John W. Eaton <jwe@octave.org>
parents:
7722
diff
changeset
|
1637 |
74f5e0c7de9e
first pass at handling block comments
John W. Eaton <jwe@octave.org>
parents:
7722
diff
changeset
|
1638 return buf; |
74f5e0c7de9e
first pass at handling block comments
John W. Eaton <jwe@octave.org>
parents:
7722
diff
changeset
|
1639 } |
74f5e0c7de9e
first pass at handling block comments
John W. Eaton <jwe@octave.org>
parents:
7722
diff
changeset
|
1640 |
7720
4e2eafef689c
unify comment and help text processing in lex.l and parse.y
John W. Eaton <jwe@octave.org>
parents:
7715
diff
changeset
|
1641 std::string |
7723
74f5e0c7de9e
first pass at handling block comments
John W. Eaton <jwe@octave.org>
parents:
7722
diff
changeset
|
1642 grab_comment_block (stream_reader& reader, bool at_bol, |
74f5e0c7de9e
first pass at handling block comments
John W. Eaton <jwe@octave.org>
parents:
7722
diff
changeset
|
1643 bool& eof) |
1 | 1644 { |
4426 | 1645 std::string buf; |
1019 | 1646 |
7720
4e2eafef689c
unify comment and help text processing in lex.l and parse.y
John W. Eaton <jwe@octave.org>
parents:
7715
diff
changeset
|
1647 // TRUE means we are at the beginning of a comment block. |
4e2eafef689c
unify comment and help text processing in lex.l and parse.y
John W. Eaton <jwe@octave.org>
parents:
7715
diff
changeset
|
1648 bool begin_comment = false; |
4e2eafef689c
unify comment and help text processing in lex.l and parse.y
John W. Eaton <jwe@octave.org>
parents:
7715
diff
changeset
|
1649 |
4e2eafef689c
unify comment and help text processing in lex.l and parse.y
John W. Eaton <jwe@octave.org>
parents:
7715
diff
changeset
|
1650 // TRUE means we are currently reading a comment block. |
4e2eafef689c
unify comment and help text processing in lex.l and parse.y
John W. Eaton <jwe@octave.org>
parents:
7715
diff
changeset
|
1651 bool in_comment = false; |
4e2eafef689c
unify comment and help text processing in lex.l and parse.y
John W. Eaton <jwe@octave.org>
parents:
7715
diff
changeset
|
1652 |
4e2eafef689c
unify comment and help text processing in lex.l and parse.y
John W. Eaton <jwe@octave.org>
parents:
7715
diff
changeset
|
1653 bool warned_incompatible = false; |
3665 | 1654 |
1019 | 1655 int c = 0; |
1 | 1656 |
7720
4e2eafef689c
unify comment and help text processing in lex.l and parse.y
John W. Eaton <jwe@octave.org>
parents:
7715
diff
changeset
|
1657 while ((c = reader.getc ()) != EOF) |
1019 | 1658 { |
7720
4e2eafef689c
unify comment and help text processing in lex.l and parse.y
John W. Eaton <jwe@octave.org>
parents:
7715
diff
changeset
|
1659 current_input_column++; |
4e2eafef689c
unify comment and help text processing in lex.l and parse.y
John W. Eaton <jwe@octave.org>
parents:
7715
diff
changeset
|
1660 |
2300 | 1661 if (begin_comment) |
1662 { | |
1663 if (c == '%' || c == '#') | |
7723
74f5e0c7de9e
first pass at handling block comments
John W. Eaton <jwe@octave.org>
parents:
7722
diff
changeset
|
1664 { |
74f5e0c7de9e
first pass at handling block comments
John W. Eaton <jwe@octave.org>
parents:
7722
diff
changeset
|
1665 at_bol = false; |
74f5e0c7de9e
first pass at handling block comments
John W. Eaton <jwe@octave.org>
parents:
7722
diff
changeset
|
1666 continue; |
74f5e0c7de9e
first pass at handling block comments
John W. Eaton <jwe@octave.org>
parents:
7722
diff
changeset
|
1667 } |
74f5e0c7de9e
first pass at handling block comments
John W. Eaton <jwe@octave.org>
parents:
7722
diff
changeset
|
1668 else if (at_bol && c == '{') |
74f5e0c7de9e
first pass at handling block comments
John W. Eaton <jwe@octave.org>
parents:
7722
diff
changeset
|
1669 { |
74f5e0c7de9e
first pass at handling block comments
John W. Eaton <jwe@octave.org>
parents:
7722
diff
changeset
|
1670 std::string tmp_buf (1, static_cast<char> (c)); |
74f5e0c7de9e
first pass at handling block comments
John W. Eaton <jwe@octave.org>
parents:
7722
diff
changeset
|
1671 |
74f5e0c7de9e
first pass at handling block comments
John W. Eaton <jwe@octave.org>
parents:
7722
diff
changeset
|
1672 bool done = false; |
74f5e0c7de9e
first pass at handling block comments
John W. Eaton <jwe@octave.org>
parents:
7722
diff
changeset
|
1673 |
74f5e0c7de9e
first pass at handling block comments
John W. Eaton <jwe@octave.org>
parents:
7722
diff
changeset
|
1674 while ((c = reader.getc ()) != EOF && ! done) |
74f5e0c7de9e
first pass at handling block comments
John W. Eaton <jwe@octave.org>
parents:
7722
diff
changeset
|
1675 { |
74f5e0c7de9e
first pass at handling block comments
John W. Eaton <jwe@octave.org>
parents:
7722
diff
changeset
|
1676 current_input_column++; |
74f5e0c7de9e
first pass at handling block comments
John W. Eaton <jwe@octave.org>
parents:
7722
diff
changeset
|
1677 |
74f5e0c7de9e
first pass at handling block comments
John W. Eaton <jwe@octave.org>
parents:
7722
diff
changeset
|
1678 switch (c) |
74f5e0c7de9e
first pass at handling block comments
John W. Eaton <jwe@octave.org>
parents:
7722
diff
changeset
|
1679 { |
74f5e0c7de9e
first pass at handling block comments
John W. Eaton <jwe@octave.org>
parents:
7722
diff
changeset
|
1680 case ' ': |
74f5e0c7de9e
first pass at handling block comments
John W. Eaton <jwe@octave.org>
parents:
7722
diff
changeset
|
1681 case '\t': |
74f5e0c7de9e
first pass at handling block comments
John W. Eaton <jwe@octave.org>
parents:
7722
diff
changeset
|
1682 tmp_buf += static_cast<char> (c); |
74f5e0c7de9e
first pass at handling block comments
John W. Eaton <jwe@octave.org>
parents:
7722
diff
changeset
|
1683 break; |
74f5e0c7de9e
first pass at handling block comments
John W. Eaton <jwe@octave.org>
parents:
7722
diff
changeset
|
1684 |
74f5e0c7de9e
first pass at handling block comments
John W. Eaton <jwe@octave.org>
parents:
7722
diff
changeset
|
1685 case '\n': |
74f5e0c7de9e
first pass at handling block comments
John W. Eaton <jwe@octave.org>
parents:
7722
diff
changeset
|
1686 { |
74f5e0c7de9e
first pass at handling block comments
John W. Eaton <jwe@octave.org>
parents:
7722
diff
changeset
|
1687 current_input_column = 0; |
74f5e0c7de9e
first pass at handling block comments
John W. Eaton <jwe@octave.org>
parents:
7722
diff
changeset
|
1688 at_bol = true; |
74f5e0c7de9e
first pass at handling block comments
John W. Eaton <jwe@octave.org>
parents:
7722
diff
changeset
|
1689 done = true; |
74f5e0c7de9e
first pass at handling block comments
John W. Eaton <jwe@octave.org>
parents:
7722
diff
changeset
|
1690 |
74f5e0c7de9e
first pass at handling block comments
John W. Eaton <jwe@octave.org>
parents:
7722
diff
changeset
|
1691 block_comment_nesting_level++; |
74f5e0c7de9e
first pass at handling block comments
John W. Eaton <jwe@octave.org>
parents:
7722
diff
changeset
|
1692 promptflag--; |
74f5e0c7de9e
first pass at handling block comments
John W. Eaton <jwe@octave.org>
parents:
7722
diff
changeset
|
1693 |
74f5e0c7de9e
first pass at handling block comments
John W. Eaton <jwe@octave.org>
parents:
7722
diff
changeset
|
1694 buf += grab_block_comment (reader, eof); |
74f5e0c7de9e
first pass at handling block comments
John W. Eaton <jwe@octave.org>
parents:
7722
diff
changeset
|
1695 |
74f5e0c7de9e
first pass at handling block comments
John W. Eaton <jwe@octave.org>
parents:
7722
diff
changeset
|
1696 in_comment = false; |
74f5e0c7de9e
first pass at handling block comments
John W. Eaton <jwe@octave.org>
parents:
7722
diff
changeset
|
1697 |
74f5e0c7de9e
first pass at handling block comments
John W. Eaton <jwe@octave.org>
parents:
7722
diff
changeset
|
1698 if (eof) |
74f5e0c7de9e
first pass at handling block comments
John W. Eaton <jwe@octave.org>
parents:
7722
diff
changeset
|
1699 goto done; |
74f5e0c7de9e
first pass at handling block comments
John W. Eaton <jwe@octave.org>
parents:
7722
diff
changeset
|
1700 } |
74f5e0c7de9e
first pass at handling block comments
John W. Eaton <jwe@octave.org>
parents:
7722
diff
changeset
|
1701 break; |
74f5e0c7de9e
first pass at handling block comments
John W. Eaton <jwe@octave.org>
parents:
7722
diff
changeset
|
1702 |
74f5e0c7de9e
first pass at handling block comments
John W. Eaton <jwe@octave.org>
parents:
7722
diff
changeset
|
1703 default: |
74f5e0c7de9e
first pass at handling block comments
John W. Eaton <jwe@octave.org>
parents:
7722
diff
changeset
|
1704 at_bol = false; |
74f5e0c7de9e
first pass at handling block comments
John W. Eaton <jwe@octave.org>
parents:
7722
diff
changeset
|
1705 tmp_buf += static_cast<char> (c); |
74f5e0c7de9e
first pass at handling block comments
John W. Eaton <jwe@octave.org>
parents:
7722
diff
changeset
|
1706 buf += tmp_buf; |
74f5e0c7de9e
first pass at handling block comments
John W. Eaton <jwe@octave.org>
parents:
7722
diff
changeset
|
1707 done = true; |
74f5e0c7de9e
first pass at handling block comments
John W. Eaton <jwe@octave.org>
parents:
7722
diff
changeset
|
1708 break; |
74f5e0c7de9e
first pass at handling block comments
John W. Eaton <jwe@octave.org>
parents:
7722
diff
changeset
|
1709 } |
74f5e0c7de9e
first pass at handling block comments
John W. Eaton <jwe@octave.org>
parents:
7722
diff
changeset
|
1710 } |
74f5e0c7de9e
first pass at handling block comments
John W. Eaton <jwe@octave.org>
parents:
7722
diff
changeset
|
1711 } |
2300 | 1712 else |
7723
74f5e0c7de9e
first pass at handling block comments
John W. Eaton <jwe@octave.org>
parents:
7722
diff
changeset
|
1713 { |
74f5e0c7de9e
first pass at handling block comments
John W. Eaton <jwe@octave.org>
parents:
7722
diff
changeset
|
1714 at_bol = false; |
74f5e0c7de9e
first pass at handling block comments
John W. Eaton <jwe@octave.org>
parents:
7722
diff
changeset
|
1715 begin_comment = false; |
74f5e0c7de9e
first pass at handling block comments
John W. Eaton <jwe@octave.org>
parents:
7722
diff
changeset
|
1716 } |
2300 | 1717 } |
1718 | |
1019 | 1719 if (in_comment) |
1 | 1720 { |
4426 | 1721 buf += static_cast<char> (c); |
1755 | 1722 |
1019 | 1723 if (c == '\n') |
3427 | 1724 { |
7723
74f5e0c7de9e
first pass at handling block comments
John W. Eaton <jwe@octave.org>
parents:
7722
diff
changeset
|
1725 at_bol = true; |
7720
4e2eafef689c
unify comment and help text processing in lex.l and parse.y
John W. Eaton <jwe@octave.org>
parents:
7715
diff
changeset
|
1726 current_input_column = 0; |
3427 | 1727 in_comment = false; |
8537
17ef48c699a5
lex.l (grab_comment_block): if not reading from a file, bail at first newline inside a comment:
John W. Eaton <jwe@octave.org>
parents:
8536
diff
changeset
|
1728 |
17ef48c699a5
lex.l (grab_comment_block): if not reading from a file, bail at first newline inside a comment:
John W. Eaton <jwe@octave.org>
parents:
8536
diff
changeset
|
1729 // FIXME -- bailing out here prevents things like |
17ef48c699a5
lex.l (grab_comment_block): if not reading from a file, bail at first newline inside a comment:
John W. Eaton <jwe@octave.org>
parents:
8536
diff
changeset
|
1730 // |
17ef48c699a5
lex.l (grab_comment_block): if not reading from a file, bail at first newline inside a comment:
John W. Eaton <jwe@octave.org>
parents:
8536
diff
changeset
|
1731 // octave> # comment |
17ef48c699a5
lex.l (grab_comment_block): if not reading from a file, bail at first newline inside a comment:
John W. Eaton <jwe@octave.org>
parents:
8536
diff
changeset
|
1732 // octave> x = 1 |
17ef48c699a5
lex.l (grab_comment_block): if not reading from a file, bail at first newline inside a comment:
John W. Eaton <jwe@octave.org>
parents:
8536
diff
changeset
|
1733 // |
17ef48c699a5
lex.l (grab_comment_block): if not reading from a file, bail at first newline inside a comment:
John W. Eaton <jwe@octave.org>
parents:
8536
diff
changeset
|
1734 // from failing at the command line, while still |
17ef48c699a5
lex.l (grab_comment_block): if not reading from a file, bail at first newline inside a comment:
John W. Eaton <jwe@octave.org>
parents:
8536
diff
changeset
|
1735 // allowing blocks of comments to be grabbed properly |
17ef48c699a5
lex.l (grab_comment_block): if not reading from a file, bail at first newline inside a comment:
John W. Eaton <jwe@octave.org>
parents:
8536
diff
changeset
|
1736 // for function doc strings. But only the first line of |
17ef48c699a5
lex.l (grab_comment_block): if not reading from a file, bail at first newline inside a comment:
John W. Eaton <jwe@octave.org>
parents:
8536
diff
changeset
|
1737 // a mult-line doc string will be picked up for |
17ef48c699a5
lex.l (grab_comment_block): if not reading from a file, bail at first newline inside a comment:
John W. Eaton <jwe@octave.org>
parents:
8536
diff
changeset
|
1738 // functions defined on the command line. We need a |
17ef48c699a5
lex.l (grab_comment_block): if not reading from a file, bail at first newline inside a comment:
John W. Eaton <jwe@octave.org>
parents:
8536
diff
changeset
|
1739 // better way of collecting these comments... |
17ef48c699a5
lex.l (grab_comment_block): if not reading from a file, bail at first newline inside a comment:
John W. Eaton <jwe@octave.org>
parents:
8536
diff
changeset
|
1740 if (! (reading_fcn_file || reading_script_file)) |
17ef48c699a5
lex.l (grab_comment_block): if not reading from a file, bail at first newline inside a comment:
John W. Eaton <jwe@octave.org>
parents:
8536
diff
changeset
|
1741 goto done; |
3427 | 1742 } |
1019 | 1743 } |
1744 else | |
1745 { | |
1746 switch (c) | |
991 | 1747 { |
7720
4e2eafef689c
unify comment and help text processing in lex.l and parse.y
John W. Eaton <jwe@octave.org>
parents:
7715
diff
changeset
|
1748 case ' ': |
4e2eafef689c
unify comment and help text processing in lex.l and parse.y
John W. Eaton <jwe@octave.org>
parents:
7715
diff
changeset
|
1749 case '\t': |
4e2eafef689c
unify comment and help text processing in lex.l and parse.y
John W. Eaton <jwe@octave.org>
parents:
7715
diff
changeset
|
1750 break; |
4e2eafef689c
unify comment and help text processing in lex.l and parse.y
John W. Eaton <jwe@octave.org>
parents:
7715
diff
changeset
|
1751 |
4037 | 1752 case '#': |
7720
4e2eafef689c
unify comment and help text processing in lex.l and parse.y
John W. Eaton <jwe@octave.org>
parents:
7715
diff
changeset
|
1753 if (! warned_incompatible) |
4e2eafef689c
unify comment and help text processing in lex.l and parse.y
John W. Eaton <jwe@octave.org>
parents:
7715
diff
changeset
|
1754 { |
4e2eafef689c
unify comment and help text processing in lex.l and parse.y
John W. Eaton <jwe@octave.org>
parents:
7715
diff
changeset
|
1755 warned_incompatible = true; |
4e2eafef689c
unify comment and help text processing in lex.l and parse.y
John W. Eaton <jwe@octave.org>
parents:
7715
diff
changeset
|
1756 maybe_gripe_matlab_incompatible_comment (c); |
4e2eafef689c
unify comment and help text processing in lex.l and parse.y
John W. Eaton <jwe@octave.org>
parents:
7715
diff
changeset
|
1757 } |
4e2eafef689c
unify comment and help text processing in lex.l and parse.y
John W. Eaton <jwe@octave.org>
parents:
7715
diff
changeset
|
1758 // fall through... |
4e2eafef689c
unify comment and help text processing in lex.l and parse.y
John W. Eaton <jwe@octave.org>
parents:
7715
diff
changeset
|
1759 |
1019 | 1760 case '%': |
2300 | 1761 in_comment = true; |
1762 begin_comment = true; | |
1019 | 1763 break; |
777 | 1764 |
1019 | 1765 default: |
7720
4e2eafef689c
unify comment and help text processing in lex.l and parse.y
John W. Eaton <jwe@octave.org>
parents:
7715
diff
changeset
|
1766 current_input_column--; |
4e2eafef689c
unify comment and help text processing in lex.l and parse.y
John W. Eaton <jwe@octave.org>
parents:
7715
diff
changeset
|
1767 reader.ungetc (c); |
1019 | 1768 goto done; |
1 | 1769 } |
1770 } | |
1019 | 1771 } |
991 | 1772 |
1019 | 1773 done: |
991 | 1774 |
7715
5b4d278ec828
parse scripts completely before executing
John W. Eaton <jwe@octave.org>
parents:
7634
diff
changeset
|
1775 if (c == EOF) |
5b4d278ec828
parse scripts completely before executing
John W. Eaton <jwe@octave.org>
parents:
7634
diff
changeset
|
1776 eof = true; |
5b4d278ec828
parse scripts completely before executing
John W. Eaton <jwe@octave.org>
parents:
7634
diff
changeset
|
1777 |
4426 | 1778 return buf; |
1 | 1779 } |
1780 | |
7720
4e2eafef689c
unify comment and help text processing in lex.l and parse.y
John W. Eaton <jwe@octave.org>
parents:
7715
diff
changeset
|
1781 class |
4e2eafef689c
unify comment and help text processing in lex.l and parse.y
John W. Eaton <jwe@octave.org>
parents:
7715
diff
changeset
|
1782 flex_stream_reader : public stream_reader |
4e2eafef689c
unify comment and help text processing in lex.l and parse.y
John W. Eaton <jwe@octave.org>
parents:
7715
diff
changeset
|
1783 { |
4e2eafef689c
unify comment and help text processing in lex.l and parse.y
John W. Eaton <jwe@octave.org>
parents:
7715
diff
changeset
|
1784 public: |
4e2eafef689c
unify comment and help text processing in lex.l and parse.y
John W. Eaton <jwe@octave.org>
parents:
7715
diff
changeset
|
1785 flex_stream_reader (char *buf_arg) : stream_reader (), buf (buf_arg) { } |
4e2eafef689c
unify comment and help text processing in lex.l and parse.y
John W. Eaton <jwe@octave.org>
parents:
7715
diff
changeset
|
1786 |
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
|
1787 int getc (void) { return ::text_yyinput (); } |
8447
adab48231a03
make input_line_number work again
John W. Eaton <jwe@octave.org>
parents:
8312
diff
changeset
|
1788 int ungetc (int c) { ::xunput (c, buf); return 0; } |
7720
4e2eafef689c
unify comment and help text processing in lex.l and parse.y
John W. Eaton <jwe@octave.org>
parents:
7715
diff
changeset
|
1789 |
4e2eafef689c
unify comment and help text processing in lex.l and parse.y
John W. Eaton <jwe@octave.org>
parents:
7715
diff
changeset
|
1790 private: |
4e2eafef689c
unify comment and help text processing in lex.l and parse.y
John W. Eaton <jwe@octave.org>
parents:
7715
diff
changeset
|
1791 char *buf; |
4e2eafef689c
unify comment and help text processing in lex.l and parse.y
John W. Eaton <jwe@octave.org>
parents:
7715
diff
changeset
|
1792 }; |
4e2eafef689c
unify comment and help text processing in lex.l and parse.y
John W. Eaton <jwe@octave.org>
parents:
7715
diff
changeset
|
1793 |
7715
5b4d278ec828
parse scripts completely before executing
John W. Eaton <jwe@octave.org>
parents:
7634
diff
changeset
|
1794 static int |
7723
74f5e0c7de9e
first pass at handling block comments
John W. Eaton <jwe@octave.org>
parents:
7722
diff
changeset
|
1795 process_comment (bool start_in_block, bool& eof) |
7715
5b4d278ec828
parse scripts completely before executing
John W. Eaton <jwe@octave.org>
parents:
7634
diff
changeset
|
1796 { |
5b4d278ec828
parse scripts completely before executing
John W. Eaton <jwe@octave.org>
parents:
7634
diff
changeset
|
1797 eof = false; |
5b4d278ec828
parse scripts completely before executing
John W. Eaton <jwe@octave.org>
parents:
7634
diff
changeset
|
1798 |
5b4d278ec828
parse scripts completely before executing
John W. Eaton <jwe@octave.org>
parents:
7634
diff
changeset
|
1799 std::string help_txt; |
5b4d278ec828
parse scripts completely before executing
John W. Eaton <jwe@octave.org>
parents:
7634
diff
changeset
|
1800 |
5b4d278ec828
parse scripts completely before executing
John W. Eaton <jwe@octave.org>
parents:
7634
diff
changeset
|
1801 if (! help_buf.empty ()) |
5b4d278ec828
parse scripts completely before executing
John W. Eaton <jwe@octave.org>
parents:
7634
diff
changeset
|
1802 help_txt = help_buf.top (); |
5b4d278ec828
parse scripts completely before executing
John W. Eaton <jwe@octave.org>
parents:
7634
diff
changeset
|
1803 |
7720
4e2eafef689c
unify comment and help text processing in lex.l and parse.y
John W. Eaton <jwe@octave.org>
parents:
7715
diff
changeset
|
1804 flex_stream_reader flex_reader (yytext); |
4e2eafef689c
unify comment and help text processing in lex.l and parse.y
John W. Eaton <jwe@octave.org>
parents:
7715
diff
changeset
|
1805 |
7723
74f5e0c7de9e
first pass at handling block comments
John W. Eaton <jwe@octave.org>
parents:
7722
diff
changeset
|
1806 // process_comment is only supposed to be called when we are not |
74f5e0c7de9e
first pass at handling block comments
John W. Eaton <jwe@octave.org>
parents:
7722
diff
changeset
|
1807 // initially looking at a block comment. |
74f5e0c7de9e
first pass at handling block comments
John W. Eaton <jwe@octave.org>
parents:
7722
diff
changeset
|
1808 |
74f5e0c7de9e
first pass at handling block comments
John W. Eaton <jwe@octave.org>
parents:
7722
diff
changeset
|
1809 std::string txt = start_in_block |
74f5e0c7de9e
first pass at handling block comments
John W. Eaton <jwe@octave.org>
parents:
7722
diff
changeset
|
1810 ? grab_block_comment (flex_reader, eof) |
74f5e0c7de9e
first pass at handling block comments
John W. Eaton <jwe@octave.org>
parents:
7722
diff
changeset
|
1811 : grab_comment_block (flex_reader, false, eof); |
7720
4e2eafef689c
unify comment and help text processing in lex.l and parse.y
John W. Eaton <jwe@octave.org>
parents:
7715
diff
changeset
|
1812 |
8535 | 1813 if (lexer_debug_flag) |
8536
de1b944d5306
lex.l: finish previous change
John W. Eaton <jwe@octave.org>
parents:
8535
diff
changeset
|
1814 std::cerr << "C: " << txt << std::endl; |
8535 | 1815 |
7715
5b4d278ec828
parse scripts completely before executing
John W. Eaton <jwe@octave.org>
parents:
7634
diff
changeset
|
1816 if (help_txt.empty () && nesting_level.none ()) |
5b4d278ec828
parse scripts completely before executing
John W. Eaton <jwe@octave.org>
parents:
7634
diff
changeset
|
1817 { |
5b4d278ec828
parse scripts completely before executing
John W. Eaton <jwe@octave.org>
parents:
7634
diff
changeset
|
1818 if (! help_buf.empty ()) |
5b4d278ec828
parse scripts completely before executing
John W. Eaton <jwe@octave.org>
parents:
7634
diff
changeset
|
1819 help_buf.pop (); |
5b4d278ec828
parse scripts completely before executing
John W. Eaton <jwe@octave.org>
parents:
7634
diff
changeset
|
1820 |
5b4d278ec828
parse scripts completely before executing
John W. Eaton <jwe@octave.org>
parents:
7634
diff
changeset
|
1821 help_buf.push (txt); |
5b4d278ec828
parse scripts completely before executing
John W. Eaton <jwe@octave.org>
parents:
7634
diff
changeset
|
1822 } |
7720
4e2eafef689c
unify comment and help text processing in lex.l and parse.y
John W. Eaton <jwe@octave.org>
parents:
7715
diff
changeset
|
1823 |
4e2eafef689c
unify comment and help text processing in lex.l and parse.y
John W. Eaton <jwe@octave.org>
parents:
7715
diff
changeset
|
1824 octave_comment_buffer::append (txt); |
7715
5b4d278ec828
parse scripts completely before executing
John W. Eaton <jwe@octave.org>
parents:
7634
diff
changeset
|
1825 |
5b4d278ec828
parse scripts completely before executing
John W. Eaton <jwe@octave.org>
parents:
7634
diff
changeset
|
1826 current_input_column = 1; |
5b4d278ec828
parse scripts completely before executing
John W. Eaton <jwe@octave.org>
parents:
7634
diff
changeset
|
1827 lexer_flags.quote_is_transpose = false; |
5b4d278ec828
parse scripts completely before executing
John W. Eaton <jwe@octave.org>
parents:
7634
diff
changeset
|
1828 lexer_flags.convert_spaces_to_comma = true; |
8746
5dd06f19e9be
handle commands in the lexer
John W. Eaton <jwe@octave.org>
parents:
8745
diff
changeset
|
1829 lexer_flags.at_beginning_of_statement = true; |
7715
5b4d278ec828
parse scripts completely before executing
John W. Eaton <jwe@octave.org>
parents:
7634
diff
changeset
|
1830 |
5b4d278ec828
parse scripts completely before executing
John W. Eaton <jwe@octave.org>
parents:
7634
diff
changeset
|
1831 if (YY_START == COMMAND_START) |
5b4d278ec828
parse scripts completely before executing
John W. Eaton <jwe@octave.org>
parents:
7634
diff
changeset
|
1832 BEGIN (INITIAL); |
5b4d278ec828
parse scripts completely before executing
John W. Eaton <jwe@octave.org>
parents:
7634
diff
changeset
|
1833 |
5b4d278ec828
parse scripts completely before executing
John W. Eaton <jwe@octave.org>
parents:
7634
diff
changeset
|
1834 if (nesting_level.none ()) |
8746
5dd06f19e9be
handle commands in the lexer
John W. Eaton <jwe@octave.org>
parents:
8745
diff
changeset
|
1835 return '\n'; |
7715
5b4d278ec828
parse scripts completely before executing
John W. Eaton <jwe@octave.org>
parents:
7634
diff
changeset
|
1836 else if (nesting_level.is_bracket_or_brace ()) |
5b4d278ec828
parse scripts completely before executing
John W. Eaton <jwe@octave.org>
parents:
7634
diff
changeset
|
1837 return ';'; |
5b4d278ec828
parse scripts completely before executing
John W. Eaton <jwe@octave.org>
parents:
7634
diff
changeset
|
1838 else |
5b4d278ec828
parse scripts completely before executing
John W. Eaton <jwe@octave.org>
parents:
7634
diff
changeset
|
1839 return 0; |
5b4d278ec828
parse scripts completely before executing
John W. Eaton <jwe@octave.org>
parents:
7634
diff
changeset
|
1840 } |
5b4d278ec828
parse scripts completely before executing
John W. Eaton <jwe@octave.org>
parents:
7634
diff
changeset
|
1841 |
767 | 1842 // Return 1 if the given character matches any character in the given |
1843 // string. | |
1844 | |
2857 | 1845 static bool |
2804 | 1846 match_any (char c, const char *s) |
1 | 1847 { |
1848 char tmp; | |
1849 while ((tmp = *s++) != '\0') | |
1850 { | |
1851 if (c == tmp) | |
2857 | 1852 return true; |
1 | 1853 } |
2857 | 1854 return false; |
1 | 1855 } |
1856 | |
767 | 1857 // Given information about the spacing surrounding an operator, |
1858 // return 1 if it looks like it should be treated as a binary | |
1859 // operator. For example, | |
1860 // | |
3774 | 1861 // [ 1 + 2 ] or [ 1+ 2] or [ 1+2 ] ==> binary |
1862 // | |
1863 // [ 1 +2 ] ==> unary | |
767 | 1864 |
2857 | 1865 static bool |
3246 | 1866 looks_like_bin_op (bool spc_prev, int next_char) |
1 | 1867 { |
3246 | 1868 bool spc_next = (next_char == ' ' || next_char == '\t'); |
1869 | |
608 | 1870 return ((spc_prev && spc_next) || ! spc_prev); |
1 | 1871 } |
1872 | |
3263 | 1873 // Recognize separators. If the separator is a CRLF pair, it is |
1874 // replaced by a single LF. | |
1875 | |
1876 static bool | |
1877 next_token_is_sep_op (void) | |
1878 { | |
1879 bool retval = false; | |
1880 | |
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
|
1881 int c = text_yyinput (); |
13820b9f5fd9
more consistent handling of CR/CRLF/LF line endings in lexer and parser
John W. Eaton <jwe@octave.org>
parents:
7723
diff
changeset
|
1882 |
13820b9f5fd9
more consistent handling of CR/CRLF/LF line endings in lexer and parser
John W. Eaton <jwe@octave.org>
parents:
7723
diff
changeset
|
1883 retval = match_any (c, ",;\n]"); |
13820b9f5fd9
more consistent handling of CR/CRLF/LF line endings in lexer and parser
John W. Eaton <jwe@octave.org>
parents:
7723
diff
changeset
|
1884 |
8447
adab48231a03
make input_line_number work again
John W. Eaton <jwe@octave.org>
parents:
8312
diff
changeset
|
1885 xunput (c, yytext); |
3263 | 1886 |
1887 return retval; | |
1888 } | |
1889 | |
767 | 1890 // Try to determine if the next token should be treated as a postfix |
1891 // unary operator. This is ugly, but it seems to do the right thing. | |
1892 | |
2857 | 1893 static bool |
3246 | 1894 next_token_is_postfix_unary_op (bool spc_prev) |
1 | 1895 { |
2857 | 1896 bool un_op = false; |
1 | 1897 |
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
|
1898 int c0 = text_yyinput (); |
1 | 1899 |
3246 | 1900 if (c0 == '\'' && ! spc_prev) |
1901 { | |
1902 un_op = true; | |
1903 } | |
1904 else if (c0 == '.') | |
1905 { | |
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
|
1906 int c1 = text_yyinput (); |
3246 | 1907 un_op = (c1 == '\''); |
8447
adab48231a03
make input_line_number work again
John W. Eaton <jwe@octave.org>
parents:
8312
diff
changeset
|
1908 xunput (c1, yytext); |
3246 | 1909 } |
4613 | 1910 else if (c0 == '+') |
1911 { | |
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
|
1912 int c1 = text_yyinput (); |
4613 | 1913 un_op = (c1 == '+'); |
8447
adab48231a03
make input_line_number work again
John W. Eaton <jwe@octave.org>
parents:
8312
diff
changeset
|
1914 xunput (c1, yytext); |
4613 | 1915 } |
1916 else if (c0 == '-') | |
1917 { | |
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
|
1918 int c1 = text_yyinput (); |
4613 | 1919 un_op = (c1 == '-'); |
8447
adab48231a03
make input_line_number work again
John W. Eaton <jwe@octave.org>
parents:
8312
diff
changeset
|
1920 xunput (c1, yytext); |
4613 | 1921 } |
1 | 1922 |
8447
adab48231a03
make input_line_number work again
John W. Eaton <jwe@octave.org>
parents:
8312
diff
changeset
|
1923 xunput (c0, yytext); |
1 | 1924 |
1925 return un_op; | |
1926 } | |
1927 | |
767 | 1928 // Try to determine if the next token should be treated as a binary |
3246 | 1929 // operator. |
1521 | 1930 // |
3246 | 1931 // This kluge exists because whitespace is not always ignored inside |
3774 | 1932 // the square brackets that are used to create matrix objects (though |
1933 // spacing only really matters in the cases that can be interpreted | |
1934 // either as binary ops or prefix unary ops: currently just +, -). | |
1935 // | |
3779 | 1936 // Note that a line continuation directly following a + or - operator |
1937 // (e.g., the characters '[' 'a' ' ' '+' '\' LFD 'b' ']') will be | |
1938 // parsed as a binary operator. | |
767 | 1939 |
2857 | 1940 static bool |
3246 | 1941 next_token_is_bin_op (bool spc_prev) |
1 | 1942 { |
2857 | 1943 bool bin_op = false; |
1 | 1944 |
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
|
1945 int c0 = text_yyinput (); |
1 | 1946 |
1947 switch (c0) | |
1948 { | |
777 | 1949 case '+': |
1950 case '-': | |
3774 | 1951 { |
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
|
1952 int c1 = text_yyinput (); |
3774 | 1953 |
1954 switch (c1) | |
1955 { | |
1956 case '+': | |
1957 case '-': | |
1958 // Unary ops, spacing doesn't matter. | |
1959 break; | |
1960 | |
1961 case '=': | |
1962 // Binary ops, spacing doesn't matter. | |
1963 bin_op = true; | |
1964 break; | |
1965 | |
1966 default: | |
1967 // Could be either, spacing matters. | |
1968 bin_op = looks_like_bin_op (spc_prev, c1); | |
1969 break; | |
1970 } | |
1971 | |
8447
adab48231a03
make input_line_number work again
John W. Eaton <jwe@octave.org>
parents:
8312
diff
changeset
|
1972 xunput (c1, yytext); |
3774 | 1973 } |
1974 break; | |
1975 | |
1976 case ':': | |
3246 | 1977 case '/': |
1978 case '\\': | |
1979 case '^': | |
3774 | 1980 // Always a binary op (may also include /=, \=, and ^=). |
1981 bin_op = true; | |
1276 | 1982 break; |
1983 | |
3246 | 1984 // .+ .- ./ .\ .^ .* .** |
1554 | 1985 case '.': |
1986 { | |
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
|
1987 int c1 = text_yyinput (); |
3246 | 1988 |
3774 | 1989 if (match_any (c1, "+-/\\^*")) |
1990 // Always a binary op (may also include .+=, .-=, ./=, ...). | |
1991 bin_op = true; | |
3698 | 1992 else if (! isdigit (c1) && c1 != ' ' && c1 != '\t' && c1 != '.') |
3774 | 1993 // A structure element reference is a binary op. |
1994 bin_op = true; | |
3246 | 1995 |
8447
adab48231a03
make input_line_number work again
John W. Eaton <jwe@octave.org>
parents:
8312
diff
changeset
|
1996 xunput (c1, yytext); |
1554 | 1997 } |
1998 break; | |
1999 | |
3246 | 2000 // = == & && | || * ** |
2001 case '=': | |
1 | 2002 case '&': |
3246 | 2003 case '|': |
1 | 2004 case '*': |
3774 | 2005 // Always a binary op (may also include ==, &&, ||, **). |
2006 bin_op = true; | |
3246 | 2007 break; |
2008 | |
3774 | 2009 // < <= <> > >= |
1 | 2010 case '<': |
2011 case '>': | |
3774 | 2012 // Always a binary op (may also include <=, <>, >=). |
2013 bin_op = true; | |
2014 break; | |
2015 | |
2016 // ~= != | |
777 | 2017 case '~': |
2018 case '!': | |
3246 | 2019 { |
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
|
2020 int c1 = text_yyinput (); |
3246 | 2021 |
3774 | 2022 // ~ and ! can be unary ops, so require following =. |
2023 if (c1 == '=') | |
2024 bin_op = true; | |
3246 | 2025 |
8447
adab48231a03
make input_line_number work again
John W. Eaton <jwe@octave.org>
parents:
8312
diff
changeset
|
2026 xunput (c1, yytext); |
3246 | 2027 } |
1 | 2028 break; |
2029 | |
2030 default: | |
1276 | 2031 break; |
1 | 2032 } |
2033 | |
8447
adab48231a03
make input_line_number work again
John W. Eaton <jwe@octave.org>
parents:
8312
diff
changeset
|
2034 xunput (c0, yytext); |
1 | 2035 |
2036 return bin_op; | |
2037 } | |
2038 | |
767 | 2039 // Used to delete trailing white space from tokens. |
2040 | |
3536 | 2041 static std::string |
1 | 2042 strip_trailing_whitespace (char *s) |
2043 { | |
3523 | 2044 std::string retval = s; |
1 | 2045 |
1823 | 2046 size_t pos = retval.find_first_of (" \t"); |
1 | 2047 |
8021 | 2048 if (pos != std::string::npos) |
1823 | 2049 retval.resize (pos); |
1 | 2050 |
2051 return retval; | |
2052 } | |
2053 | |
7723
74f5e0c7de9e
first pass at handling block comments
John W. Eaton <jwe@octave.org>
parents:
7722
diff
changeset
|
2054 // FIXME -- we need to handle block comments here. |
74f5e0c7de9e
first pass at handling block comments
John W. Eaton <jwe@octave.org>
parents:
7722
diff
changeset
|
2055 |
3665 | 2056 static void |
2057 scan_for_comments (const char *text) | |
2058 { | |
2059 std::string comment_buf; | |
2060 | |
2061 bool in_comment = false; | |
2062 bool beginning_of_comment = false; | |
2063 | |
2064 int len = strlen (text); | |
2065 int i = 0; | |
2066 | |
2067 while (i < len) | |
2068 { | |
2069 char c = text[i++]; | |
2070 | |
2071 switch (c) | |
2072 { | |
2073 case '%': | |
2074 case '#': | |
2075 if (in_comment) | |
2076 { | |
2077 if (! beginning_of_comment) | |
3802 | 2078 comment_buf += static_cast<char> (c); |
3665 | 2079 } |
2080 else | |
2081 { | |
4037 | 2082 maybe_gripe_matlab_incompatible_comment (c); |
3665 | 2083 in_comment = true; |
2084 beginning_of_comment = true; | |
2085 } | |
2086 break; | |
2087 | |
2088 case '\n': | |
2089 if (in_comment) | |
2090 { | |
3802 | 2091 comment_buf += static_cast<char> (c); |
3665 | 2092 octave_comment_buffer::append (comment_buf); |
2093 comment_buf.resize (0); | |
2094 in_comment = false; | |
2095 beginning_of_comment = false; | |
2096 } | |
2097 break; | |
2098 | |
2099 default: | |
2100 if (in_comment) | |
2101 { | |
3802 | 2102 comment_buf += static_cast<char> (c); |
3665 | 2103 beginning_of_comment = false; |
2104 } | |
2105 break; | |
2106 } | |
2107 } | |
2108 | |
2109 if (! comment_buf.empty ()) | |
2110 octave_comment_buffer::append (comment_buf); | |
2111 } | |
2112 | |
1001 | 2113 // Discard whitespace, including comments and continuations. |
1088 | 2114 // |
2115 // Return value is logical OR of the following values: | |
2116 // | |
1826 | 2117 // ATE_NOTHING : no spaces to eat |
1088 | 2118 // ATE_SPACE_OR_TAB : space or tab in input |
2119 // ATE_NEWLINE : bare new line in input | |
1001 | 2120 |
7723
74f5e0c7de9e
first pass at handling block comments
John W. Eaton <jwe@octave.org>
parents:
7722
diff
changeset
|
2121 // FIXME -- we need to handle block comments here. |
74f5e0c7de9e
first pass at handling block comments
John W. Eaton <jwe@octave.org>
parents:
7722
diff
changeset
|
2122 |
1826 | 2123 static yum_yum |
975 | 2124 eat_whitespace (void) |
2125 { | |
1826 | 2126 yum_yum retval = ATE_NOTHING; |
3665 | 2127 |
2128 std::string comment_buf; | |
2129 | |
2857 | 2130 bool in_comment = false; |
3665 | 2131 bool beginning_of_comment = false; |
2132 | |
2133 int c = 0; | |
2134 | |
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
|
2135 while ((c = text_yyinput ()) != EOF) |
975 | 2136 { |
2137 current_input_column++; | |
2138 | |
2139 switch (c) | |
2140 { | |
2141 case ' ': | |
2142 case '\t': | |
3665 | 2143 if (in_comment) |
2144 { | |
3802 | 2145 comment_buf += static_cast<char> (c); |
3665 | 2146 beginning_of_comment = false; |
2147 } | |
1088 | 2148 retval |= ATE_SPACE_OR_TAB; |
975 | 2149 break; |
2150 | |
2151 case '\n': | |
1088 | 2152 retval |= ATE_NEWLINE; |
3665 | 2153 if (in_comment) |
2154 { | |
3802 | 2155 comment_buf += static_cast<char> (c); |
3665 | 2156 octave_comment_buffer::append (comment_buf); |
2157 comment_buf.resize (0); | |
2158 in_comment = false; | |
2159 beginning_of_comment = false; | |
2160 } | |
975 | 2161 current_input_column = 0; |
2162 break; | |
2163 | |
2164 case '#': | |
2165 case '%': | |
3665 | 2166 if (in_comment) |
2167 { | |
2168 if (! beginning_of_comment) | |
3802 | 2169 comment_buf += static_cast<char> (c); |
3665 | 2170 } |
2171 else | |
2172 { | |
4037 | 2173 maybe_gripe_matlab_incompatible_comment (c); |
3665 | 2174 in_comment = true; |
2175 beginning_of_comment = true; | |
2176 } | |
975 | 2177 break; |
2178 | |
1001 | 2179 case '.': |
2180 if (in_comment) | |
3665 | 2181 { |
3802 | 2182 comment_buf += static_cast<char> (c); |
3665 | 2183 beginning_of_comment = false; |
2184 break; | |
2185 } | |
1001 | 2186 else |
2187 { | |
2188 if (have_ellipsis_continuation ()) | |
2189 break; | |
2190 else | |
2191 goto done; | |
2192 } | |
2193 | |
2194 case '\\': | |
2195 if (in_comment) | |
3665 | 2196 { |
3802 | 2197 comment_buf += static_cast<char> (c); |
3665 | 2198 beginning_of_comment = false; |
2199 break; | |
2200 } | |
1001 | 2201 else |
2202 { | |
3105 | 2203 if (have_continuation ()) |
1001 | 2204 break; |
2205 else | |
2206 goto done; | |
2207 } | |
2208 | |
975 | 2209 default: |
2210 if (in_comment) | |
3665 | 2211 { |
3802 | 2212 comment_buf += static_cast<char> (c); |
3665 | 2213 beginning_of_comment = false; |
2214 break; | |
2215 } | |
975 | 2216 else |
2217 goto done; | |
2218 } | |
2219 } | |
2220 | |
3665 | 2221 if (! comment_buf.empty ()) |
2222 octave_comment_buffer::append (comment_buf); | |
2223 | |
975 | 2224 done: |
8447
adab48231a03
make input_line_number work again
John W. Eaton <jwe@octave.org>
parents:
8312
diff
changeset
|
2225 xunput (c, yytext); |
1082 | 2226 current_input_column--; |
1001 | 2227 return retval; |
975 | 2228 } |
2229 | |
3220 | 2230 static inline bool |
2231 looks_like_hex (const char *s, int len) | |
2232 { | |
2233 return (len > 2 && s[0] == '0' && (s[1] == 'x' || s[1] == 'X')); | |
2234 } | |
2235 | |
975 | 2236 static void |
3246 | 2237 handle_number (void) |
972 | 2238 { |
3220 | 2239 double value = 0.0; |
2240 int nread = 0; | |
2241 | |
3598 | 2242 if (looks_like_hex (yytext, strlen (yytext))) |
3220 | 2243 { |
2244 unsigned long ival; | |
3598 | 2245 |
2246 nread = sscanf (yytext, "%lx", &ival); | |
2247 | |
3220 | 2248 value = static_cast<double> (ival); |
2249 } | |
2250 else | |
3598 | 2251 { |
2252 char *tmp = strsave (yytext); | |
2253 | |
2254 char *idx = strpbrk (tmp, "Dd"); | |
2621 | 2255 |
3598 | 2256 if (idx) |
2257 *idx = 'e'; | |
2258 | |
2259 nread = sscanf (tmp, "%lf", &value); | |
2260 | |
2261 delete [] tmp; | |
2262 } | |
972 | 2263 |
1826 | 2264 // If yytext doesn't contain a valid number, we are in deep doo doo. |
985 | 2265 |
972 | 2266 assert (nread == 1); |
2267 | |
3988 | 2268 lexer_flags.quote_is_transpose = true; |
2269 lexer_flags.convert_spaces_to_comma = true; | |
8745
6dc61981d18b
better handling of object indexing in lexer
John W. Eaton <jwe@octave.org>
parents:
8701
diff
changeset
|
2270 lexer_flags.looking_for_object_index = true; |
8746
5dd06f19e9be
handle commands in the lexer
John W. Eaton <jwe@octave.org>
parents:
8745
diff
changeset
|
2271 lexer_flags.at_beginning_of_statement = false; |
972 | 2272 |
2273 yylval.tok_val = new token (value, yytext, input_line_number, | |
2274 current_input_column); | |
2275 | |
2276 token_stack.push (yylval.tok_val); | |
2277 | |
2278 current_input_column += yyleng; | |
2279 | |
2280 do_comma_insert_check (); | |
2281 } | |
2282 | |
1001 | 2283 // We have seen a backslash and need to find out if it should be |
2284 // treated as a continuation character. If so, this eats it, up to | |
2285 // and including the new line character. | |
2286 // | |
973 | 2287 // Match whitespace only, followed by a comment character or newline. |
2288 // Once a comment character is found, discard all input until newline. | |
2289 // If non-whitespace characters are found before comment | |
2290 // characters, return 0. Otherwise, return 1. | |
2291 | |
7723
74f5e0c7de9e
first pass at handling block comments
John W. Eaton <jwe@octave.org>
parents:
7722
diff
changeset
|
2292 // FIXME -- we need to handle block comments here. |
74f5e0c7de9e
first pass at handling block comments
John W. Eaton <jwe@octave.org>
parents:
7722
diff
changeset
|
2293 |
2857 | 2294 static bool |
3096 | 2295 have_continuation (bool trailing_comments_ok) |
973 | 2296 { |
5765 | 2297 std::ostringstream buf; |
973 | 2298 |
3665 | 2299 std::string comment_buf; |
2300 | |
2857 | 2301 bool in_comment = false; |
3665 | 2302 bool beginning_of_comment = false; |
2303 | |
2304 int c = 0; | |
2305 | |
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
|
2306 while ((c = text_yyinput ()) != EOF) |
973 | 2307 { |
3802 | 2308 buf << static_cast<char> (c); |
973 | 2309 |
2310 switch (c) | |
2311 { | |
2312 case ' ': | |
2313 case '\t': | |
3665 | 2314 if (in_comment) |
2315 { | |
3802 | 2316 comment_buf += static_cast<char> (c); |
3665 | 2317 beginning_of_comment = false; |
2318 } | |
973 | 2319 break; |
2320 | |
2321 case '%': | |
2322 case '#': | |
1091 | 2323 if (trailing_comments_ok) |
3665 | 2324 { |
2325 if (in_comment) | |
2326 { | |
2327 if (! beginning_of_comment) | |
3802 | 2328 comment_buf += static_cast<char> (c); |
3665 | 2329 } |
2330 else | |
2331 { | |
4037 | 2332 maybe_gripe_matlab_incompatible_comment (c); |
3665 | 2333 in_comment = true; |
2334 beginning_of_comment = true; | |
2335 } | |
2336 } | |
1091 | 2337 else |
2338 goto cleanup; | |
973 | 2339 break; |
2340 | |
2341 case '\n': | |
3665 | 2342 if (in_comment) |
2343 { | |
3802 | 2344 comment_buf += static_cast<char> (c); |
3665 | 2345 octave_comment_buffer::append (comment_buf); |
2346 } | |
975 | 2347 current_input_column = 0; |
1001 | 2348 promptflag--; |
4037 | 2349 gripe_matlab_incompatible_continuation (); |
2857 | 2350 return true; |
973 | 2351 |
2352 default: | |
3665 | 2353 if (in_comment) |
2354 { | |
3802 | 2355 comment_buf += static_cast<char> (c); |
3665 | 2356 beginning_of_comment = false; |
2357 } | |
2358 else | |
1091 | 2359 goto cleanup; |
2360 break; | |
973 | 2361 } |
2362 } | |
2363 | |
8447
adab48231a03
make input_line_number work again
John W. Eaton <jwe@octave.org>
parents:
8312
diff
changeset
|
2364 xunput (c, yytext); |
2857 | 2365 return false; |
973 | 2366 |
3096 | 2367 cleanup: |
4051 | 2368 |
5765 | 2369 std::string s = buf.str (); |
4051 | 2370 |
2371 int len = s.length (); | |
2372 while (len--) | |
8447
adab48231a03
make input_line_number work again
John W. Eaton <jwe@octave.org>
parents:
8312
diff
changeset
|
2373 xunput (s[len], yytext); |
3096 | 2374 |
2857 | 2375 return false; |
973 | 2376 } |
2377 | |
1001 | 2378 // We have seen a `.' and need to see if it is the start of a |
2379 // continuation. If so, this eats it, up to and including the new | |
2380 // line character. | |
2381 | |
2857 | 2382 static bool |
3096 | 2383 have_ellipsis_continuation (bool trailing_comments_ok) |
973 | 2384 { |
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
|
2385 char c1 = text_yyinput (); |
973 | 2386 if (c1 == '.') |
2387 { | |
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
|
2388 char c2 = text_yyinput (); |
1091 | 2389 if (c2 == '.' && have_continuation (trailing_comments_ok)) |
2857 | 2390 return true; |
973 | 2391 else |
2392 { | |
8447
adab48231a03
make input_line_number work again
John W. Eaton <jwe@octave.org>
parents:
8312
diff
changeset
|
2393 xunput (c2, yytext); |
adab48231a03
make input_line_number work again
John W. Eaton <jwe@octave.org>
parents:
8312
diff
changeset
|
2394 xunput (c1, yytext); |
973 | 2395 } |
2396 } | |
2397 else | |
8447
adab48231a03
make input_line_number work again
John W. Eaton <jwe@octave.org>
parents:
8312
diff
changeset
|
2398 xunput (c1, yytext); |
973 | 2399 |
2857 | 2400 return false; |
973 | 2401 } |
2402 | |
1001 | 2403 // See if we have a continuation line. If so, eat it and the leading |
2404 // whitespace on the next line. | |
1088 | 2405 // |
2406 // Return value is the same as described for eat_whitespace(). | |
1001 | 2407 |
1826 | 2408 static yum_yum |
1001 | 2409 eat_continuation (void) |
2410 { | |
1826 | 2411 int retval = ATE_NOTHING; |
3665 | 2412 |
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
|
2413 int c = text_yyinput (); |
3665 | 2414 |
1001 | 2415 if ((c == '.' && have_ellipsis_continuation ()) |
3105 | 2416 || (c == '\\' && have_continuation ())) |
1001 | 2417 retval = eat_whitespace (); |
2418 else | |
8447
adab48231a03
make input_line_number work again
John W. Eaton <jwe@octave.org>
parents:
8312
diff
changeset
|
2419 xunput (c, yytext); |
1001 | 2420 |
2421 return retval; | |
2422 } | |
2423 | |
973 | 2424 static int |
8746
5dd06f19e9be
handle commands in the lexer
John W. Eaton <jwe@octave.org>
parents:
8745
diff
changeset
|
2425 handle_string (char delim) |
973 | 2426 { |
5765 | 2427 std::ostringstream buf; |
973 | 2428 |
3805 | 2429 int bos_line = input_line_number; |
2430 int bos_col = current_input_column; | |
2431 | |
973 | 2432 int c; |
1031 | 2433 int escape_pending = 0; |
973 | 2434 |
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
|
2435 while ((c = text_yyinput ()) != EOF) |
973 | 2436 { |
2437 current_input_column++; | |
2438 | |
3105 | 2439 if (c == '\\') |
973 | 2440 { |
5359 | 2441 if (delim == '\'' || escape_pending) |
1053 | 2442 { |
3802 | 2443 buf << static_cast<char> (c); |
1053 | 2444 escape_pending = 0; |
2445 } | |
2446 else | |
2447 { | |
3096 | 2448 if (have_continuation (false)) |
1053 | 2449 escape_pending = 0; |
2450 else | |
2451 { | |
3802 | 2452 buf << static_cast<char> (c); |
1053 | 2453 escape_pending = 1; |
2454 } | |
2455 } | |
1031 | 2456 continue; |
973 | 2457 } |
2458 else if (c == '.') | |
2459 { | |
5359 | 2460 if (delim == '\'' || ! have_ellipsis_continuation (false)) |
3802 | 2461 buf << static_cast<char> (c); |
973 | 2462 } |
2463 else if (c == '\n') | |
2464 { | |
1053 | 2465 error ("unterminated string constant"); |
973 | 2466 break; |
2467 } | |
2468 else if (c == delim) | |
2469 { | |
1031 | 2470 if (escape_pending) |
3802 | 2471 buf << static_cast<char> (c); |
973 | 2472 else |
2473 { | |
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
|
2474 c = text_yyinput (); |
973 | 2475 if (c == delim) |
5102 | 2476 { |
2477 buf << static_cast<char> (c); | |
2478 } | |
973 | 2479 else |
2480 { | |
5102 | 2481 std::string s; |
8447
adab48231a03
make input_line_number work again
John W. Eaton <jwe@octave.org>
parents:
8312
diff
changeset
|
2482 xunput (c, yytext); |
5765 | 2483 |
8746
5dd06f19e9be
handle commands in the lexer
John W. Eaton <jwe@octave.org>
parents:
8745
diff
changeset
|
2484 if (delim == '\'') |
5765 | 2485 s = buf.str (); |
5102 | 2486 else |
5765 | 2487 s = do_string_escapes (buf.str ()); |
975 | 2488 |
8746
5dd06f19e9be
handle commands in the lexer
John W. Eaton <jwe@octave.org>
parents:
8745
diff
changeset
|
2489 lexer_flags.quote_is_transpose = true; |
5dd06f19e9be
handle commands in the lexer
John W. Eaton <jwe@octave.org>
parents:
8745
diff
changeset
|
2490 lexer_flags.convert_spaces_to_comma = true; |
975 | 2491 |
3805 | 2492 yylval.tok_val = new token (s, bos_line, bos_col); |
973 | 2493 token_stack.push (yylval.tok_val); |
3400 | 2494 |
4037 | 2495 if (delim == '"') |
2496 gripe_matlab_incompatible ("\" used as string delimiter"); | |
2497 else if (delim == '\'') | |
3400 | 2498 gripe_single_quote_string (); |
2499 | |
8745
6dc61981d18b
better handling of object indexing in lexer
John W. Eaton <jwe@octave.org>
parents:
8701
diff
changeset
|
2500 lexer_flags.looking_for_object_index = true; |
8746
5dd06f19e9be
handle commands in the lexer
John W. Eaton <jwe@octave.org>
parents:
8745
diff
changeset
|
2501 lexer_flags.at_beginning_of_statement = false; |
8745
6dc61981d18b
better handling of object indexing in lexer
John W. Eaton <jwe@octave.org>
parents:
8701
diff
changeset
|
2502 |
5279 | 2503 return delim == '"' ? DQ_STRING : SQ_STRING; |
973 | 2504 } |
2505 } | |
2506 } | |
2507 else | |
2508 { | |
3802 | 2509 buf << static_cast<char> (c); |
973 | 2510 } |
2511 | |
1031 | 2512 escape_pending = 0; |
973 | 2513 } |
2514 | |
2515 return LEXICAL_ERROR; | |
2516 } | |
2517 | |
3208 | 2518 static bool |
2519 next_token_is_assign_op (void) | |
2520 { | |
2521 bool retval = false; | |
2522 | |
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
|
2523 int c0 = text_yyinput (); |
3208 | 2524 |
2525 switch (c0) | |
2526 { | |
2527 case '=': | |
2528 { | |
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
|
2529 int c1 = text_yyinput (); |
8447
adab48231a03
make input_line_number work again
John W. Eaton <jwe@octave.org>
parents:
8312
diff
changeset
|
2530 xunput (c1, yytext); |
3208 | 2531 if (c1 != '=') |
2532 retval = true; | |
2533 } | |
2534 break; | |
2535 | |
2536 case '+': | |
2537 case '-': | |
2538 case '*': | |
2539 case '/': | |
2540 case '\\': | |
2541 case '&': | |
2542 case '|': | |
2543 { | |
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
|
2544 int c1 = text_yyinput (); |
8447
adab48231a03
make input_line_number work again
John W. Eaton <jwe@octave.org>
parents:
8312
diff
changeset
|
2545 xunput (c1, yytext); |
3208 | 2546 if (c1 == '=') |
2547 retval = true; | |
2548 } | |
2549 break; | |
2550 | |
2551 case '.': | |
2552 { | |
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
|
2553 int c1 = text_yyinput (); |
3208 | 2554 if (match_any (c1, "+-*/\\")) |
2555 { | |
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
|
2556 int c2 = text_yyinput (); |
8447
adab48231a03
make input_line_number work again
John W. Eaton <jwe@octave.org>
parents:
8312
diff
changeset
|
2557 xunput (c2, yytext); |
3208 | 2558 if (c2 == '=') |
2559 retval = true; | |
2560 } | |
8447
adab48231a03
make input_line_number work again
John W. Eaton <jwe@octave.org>
parents:
8312
diff
changeset
|
2561 xunput (c1, yytext); |
3208 | 2562 } |
2563 break; | |
2564 | |
2565 case '>': | |
2566 { | |
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
|
2567 int c1 = text_yyinput (); |
3208 | 2568 if (c1 == '>') |
2569 { | |
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
|
2570 int c2 = text_yyinput (); |
8447
adab48231a03
make input_line_number work again
John W. Eaton <jwe@octave.org>
parents:
8312
diff
changeset
|
2571 xunput (c2, yytext); |
3208 | 2572 if (c2 == '=') |
2573 retval = true; | |
2574 } | |
8447
adab48231a03
make input_line_number work again
John W. Eaton <jwe@octave.org>
parents:
8312
diff
changeset
|
2575 xunput (c1, yytext); |
3208 | 2576 } |
2577 break; | |
2578 | |
2579 case '<': | |
2580 { | |
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
|
2581 int c1 = text_yyinput (); |
3208 | 2582 if (c1 == '<') |
2583 { | |
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
|
2584 int c2 = text_yyinput (); |
8447
adab48231a03
make input_line_number work again
John W. Eaton <jwe@octave.org>
parents:
8312
diff
changeset
|
2585 xunput (c2, yytext); |
3208 | 2586 if (c2 == '=') |
2587 retval = true; | |
2588 } | |
8447
adab48231a03
make input_line_number work again
John W. Eaton <jwe@octave.org>
parents:
8312
diff
changeset
|
2589 xunput (c1, yytext); |
3208 | 2590 } |
2591 break; | |
2592 | |
2593 default: | |
2594 break; | |
2595 } | |
2596 | |
8447
adab48231a03
make input_line_number work again
John W. Eaton <jwe@octave.org>
parents:
8312
diff
changeset
|
2597 xunput (c0, yytext); |
3208 | 2598 |
2599 return retval; | |
2600 } | |
2601 | |
4633 | 2602 static bool |
2603 next_token_is_index_op (void) | |
2604 { | |
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
|
2605 int c = text_yyinput (); |
8447
adab48231a03
make input_line_number work again
John W. Eaton <jwe@octave.org>
parents:
8312
diff
changeset
|
2606 xunput (c, yytext); |
4633 | 2607 return c == '(' || c == '{'; |
2608 } | |
2609 | |
4612 | 2610 static int |
2611 handle_close_bracket (bool spc_gobbled, int bracket_type) | |
971 | 2612 { |
4612 | 2613 int retval = bracket_type; |
3208 | 2614 |
1826 | 2615 if (! nesting_level.none ()) |
971 | 2616 { |
1826 | 2617 nesting_level.remove (); |
4613 | 2618 |
2619 if (bracket_type == ']') | |
2620 lexer_flags.bracketflag--; | |
2621 else if (bracket_type == '}') | |
2622 lexer_flags.braceflag--; | |
2623 else | |
2624 panic_impossible (); | |
971 | 2625 } |
2626 | |
4613 | 2627 if (lexer_flags.bracketflag == 0 && lexer_flags.braceflag == 0) |
4323 | 2628 BEGIN (INITIAL); |
1001 | 2629 |
4608 | 2630 if (bracket_type == ']' |
2631 && next_token_is_assign_op () | |
2632 && ! lexer_flags.looking_at_return_list) | |
971 | 2633 { |
3208 | 2634 retval = CLOSE_BRACE; |
971 | 2635 } |
4613 | 2636 else if ((lexer_flags.bracketflag || lexer_flags.braceflag) |
2637 && lexer_flags.convert_spaces_to_comma | |
2638 && (nesting_level.is_bracket () | |
2639 || (nesting_level.is_brace () | |
8745
6dc61981d18b
better handling of object indexing in lexer
John W. Eaton <jwe@octave.org>
parents:
8701
diff
changeset
|
2640 && ! lexer_flags.looking_at_object_index.front ()))) |
971 | 2641 { |
4633 | 2642 bool index_op = next_token_is_index_op (); |
2643 | |
2644 // Don't insert comma if we are looking at something like | |
2645 // | |
2646 // [x{i}{j}] or [x{i}(j)] | |
2647 // | |
2648 // but do if we are looking at | |
2649 // | |
2650 // [x{i} {j}] or [x{i} (j)] | |
2651 | |
2652 if (spc_gobbled || ! (bracket_type == '}' && index_op)) | |
971 | 2653 { |
4633 | 2654 bool bin_op = next_token_is_bin_op (spc_gobbled); |
2655 | |
2656 bool postfix_un_op = next_token_is_postfix_unary_op (spc_gobbled); | |
2657 | |
2658 bool sep_op = next_token_is_sep_op (); | |
2659 | |
2660 if (! (postfix_un_op || bin_op || sep_op)) | |
2661 { | |
2662 maybe_warn_separator_insert (','); | |
2663 | |
8745
6dc61981d18b
better handling of object indexing in lexer
John W. Eaton <jwe@octave.org>
parents:
8701
diff
changeset
|
2664 xunput (',', yytext); |
4633 | 2665 return retval; |
2666 } | |
971 | 2667 } |
2668 } | |
2669 | |
2857 | 2670 lexer_flags.quote_is_transpose = true; |
2671 lexer_flags.convert_spaces_to_comma = true; | |
3208 | 2672 |
2673 return retval; | |
971 | 2674 } |
2675 | |
1072 | 2676 static void |
2677 maybe_unput_comma (int spc_gobbled) | |
2678 { | |
4613 | 2679 if (nesting_level.is_bracket () |
2680 || (nesting_level.is_brace () | |
8745
6dc61981d18b
better handling of object indexing in lexer
John W. Eaton <jwe@octave.org>
parents:
8701
diff
changeset
|
2681 && ! lexer_flags.looking_at_object_index.front ())) |
1072 | 2682 { |
3246 | 2683 int bin_op = next_token_is_bin_op (spc_gobbled); |
1072 | 2684 |
3246 | 2685 int postfix_un_op = next_token_is_postfix_unary_op (spc_gobbled); |
1072 | 2686 |
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
|
2687 int c1 = text_yyinput (); |
13820b9f5fd9
more consistent handling of CR/CRLF/LF line endings in lexer and parser
John W. Eaton <jwe@octave.org>
parents:
7723
diff
changeset
|
2688 int c2 = text_yyinput (); |
2970 | 2689 |
8447
adab48231a03
make input_line_number work again
John W. Eaton <jwe@octave.org>
parents:
8312
diff
changeset
|
2690 xunput (c2, yytext); |
adab48231a03
make input_line_number work again
John W. Eaton <jwe@octave.org>
parents:
8312
diff
changeset
|
2691 xunput (c1, yytext); |
2970 | 2692 |
3263 | 2693 int sep_op = next_token_is_sep_op (); |
2970 | 2694 |
1072 | 2695 int dot_op = (c1 == '.' |
2696 && (isalpha (c2) || isspace (c2) || c2 == '_')); | |
2970 | 2697 |
3388 | 2698 if (postfix_un_op || bin_op || sep_op || dot_op) |
2699 return; | |
2700 | |
3985 | 2701 int index_op = (c1 == '(' || c1 == '{'); |
3388 | 2702 |
4476 | 2703 // If there is no space before the indexing op, we don't insert |
2704 // a comma. | |
2705 | |
2706 if (index_op && ! spc_gobbled) | |
2707 return; | |
2708 | |
2709 maybe_warn_separator_insert (','); | |
2710 | |
8745
6dc61981d18b
better handling of object indexing in lexer
John W. Eaton <jwe@octave.org>
parents:
8701
diff
changeset
|
2711 xunput (',', yytext); |
1072 | 2712 } |
2713 } | |
2714 | |
8746
5dd06f19e9be
handle commands in the lexer
John W. Eaton <jwe@octave.org>
parents:
8745
diff
changeset
|
2715 static bool |
5dd06f19e9be
handle commands in the lexer
John W. Eaton <jwe@octave.org>
parents:
8745
diff
changeset
|
2716 next_token_can_follow_bin_op (void) |
5dd06f19e9be
handle commands in the lexer
John W. Eaton <jwe@octave.org>
parents:
8745
diff
changeset
|
2717 { |
5dd06f19e9be
handle commands in the lexer
John W. Eaton <jwe@octave.org>
parents:
8745
diff
changeset
|
2718 std::stack<char> buf; |
5dd06f19e9be
handle commands in the lexer
John W. Eaton <jwe@octave.org>
parents:
8745
diff
changeset
|
2719 |
5dd06f19e9be
handle commands in the lexer
John W. Eaton <jwe@octave.org>
parents:
8745
diff
changeset
|
2720 int c = EOF; |
5dd06f19e9be
handle commands in the lexer
John W. Eaton <jwe@octave.org>
parents:
8745
diff
changeset
|
2721 |
5dd06f19e9be
handle commands in the lexer
John W. Eaton <jwe@octave.org>
parents:
8745
diff
changeset
|
2722 // Skip whitespace in current statement on current line |
5dd06f19e9be
handle commands in the lexer
John W. Eaton <jwe@octave.org>
parents:
8745
diff
changeset
|
2723 while (true) |
5dd06f19e9be
handle commands in the lexer
John W. Eaton <jwe@octave.org>
parents:
8745
diff
changeset
|
2724 { |
5dd06f19e9be
handle commands in the lexer
John W. Eaton <jwe@octave.org>
parents:
8745
diff
changeset
|
2725 c = text_yyinput (); |
5dd06f19e9be
handle commands in the lexer
John W. Eaton <jwe@octave.org>
parents:
8745
diff
changeset
|
2726 |
8767
026c6732ec7a
lex.l (next_token_can_follow_bin_op): push all characters read on to buffer stack
John W. Eaton <jwe@octave.org>
parents:
8746
diff
changeset
|
2727 buf.push (c); |
026c6732ec7a
lex.l (next_token_can_follow_bin_op): push all characters read on to buffer stack
John W. Eaton <jwe@octave.org>
parents:
8746
diff
changeset
|
2728 |
026c6732ec7a
lex.l (next_token_can_follow_bin_op): push all characters read on to buffer stack
John W. Eaton <jwe@octave.org>
parents:
8746
diff
changeset
|
2729 if (match_any (c, ",;\n") || (c != ' ' && c != '\t')) |
8746
5dd06f19e9be
handle commands in the lexer
John W. Eaton <jwe@octave.org>
parents:
8745
diff
changeset
|
2730 break; |
5dd06f19e9be
handle commands in the lexer
John W. Eaton <jwe@octave.org>
parents:
8745
diff
changeset
|
2731 } |
5dd06f19e9be
handle commands in the lexer
John W. Eaton <jwe@octave.org>
parents:
8745
diff
changeset
|
2732 |
5dd06f19e9be
handle commands in the lexer
John W. Eaton <jwe@octave.org>
parents:
8745
diff
changeset
|
2733 // Restore input. |
5dd06f19e9be
handle commands in the lexer
John W. Eaton <jwe@octave.org>
parents:
8745
diff
changeset
|
2734 while (! buf.empty ()) |
5dd06f19e9be
handle commands in the lexer
John W. Eaton <jwe@octave.org>
parents:
8745
diff
changeset
|
2735 { |
5dd06f19e9be
handle commands in the lexer
John W. Eaton <jwe@octave.org>
parents:
8745
diff
changeset
|
2736 xunput (buf.top (), yytext); |
5dd06f19e9be
handle commands in the lexer
John W. Eaton <jwe@octave.org>
parents:
8745
diff
changeset
|
2737 |
5dd06f19e9be
handle commands in the lexer
John W. Eaton <jwe@octave.org>
parents:
8745
diff
changeset
|
2738 buf.pop (); |
5dd06f19e9be
handle commands in the lexer
John W. Eaton <jwe@octave.org>
parents:
8745
diff
changeset
|
2739 } |
5dd06f19e9be
handle commands in the lexer
John W. Eaton <jwe@octave.org>
parents:
8745
diff
changeset
|
2740 |
5dd06f19e9be
handle commands in the lexer
John W. Eaton <jwe@octave.org>
parents:
8745
diff
changeset
|
2741 return (isalnum (c) || match_any (c, "!\"'(-[_{~")); |
5dd06f19e9be
handle commands in the lexer
John W. Eaton <jwe@octave.org>
parents:
8745
diff
changeset
|
2742 } |
5dd06f19e9be
handle commands in the lexer
John W. Eaton <jwe@octave.org>
parents:
8745
diff
changeset
|
2743 |
5dd06f19e9be
handle commands in the lexer
John W. Eaton <jwe@octave.org>
parents:
8745
diff
changeset
|
2744 static bool |
5dd06f19e9be
handle commands in the lexer
John W. Eaton <jwe@octave.org>
parents:
8745
diff
changeset
|
2745 looks_like_command_arg (void) |
5dd06f19e9be
handle commands in the lexer
John W. Eaton <jwe@octave.org>
parents:
8745
diff
changeset
|
2746 { |
5dd06f19e9be
handle commands in the lexer
John W. Eaton <jwe@octave.org>
parents:
8745
diff
changeset
|
2747 bool retval = true; |
5dd06f19e9be
handle commands in the lexer
John W. Eaton <jwe@octave.org>
parents:
8745
diff
changeset
|
2748 |
5dd06f19e9be
handle commands in the lexer
John W. Eaton <jwe@octave.org>
parents:
8745
diff
changeset
|
2749 int c0 = text_yyinput (); |
5dd06f19e9be
handle commands in the lexer
John W. Eaton <jwe@octave.org>
parents:
8745
diff
changeset
|
2750 |
5dd06f19e9be
handle commands in the lexer
John W. Eaton <jwe@octave.org>
parents:
8745
diff
changeset
|
2751 switch (c0) |
5dd06f19e9be
handle commands in the lexer
John W. Eaton <jwe@octave.org>
parents:
8745
diff
changeset
|
2752 { |
5dd06f19e9be
handle commands in the lexer
John W. Eaton <jwe@octave.org>
parents:
8745
diff
changeset
|
2753 // = == |
5dd06f19e9be
handle commands in the lexer
John W. Eaton <jwe@octave.org>
parents:
8745
diff
changeset
|
2754 case '=': |
5dd06f19e9be
handle commands in the lexer
John W. Eaton <jwe@octave.org>
parents:
8745
diff
changeset
|
2755 { |
5dd06f19e9be
handle commands in the lexer
John W. Eaton <jwe@octave.org>
parents:
8745
diff
changeset
|
2756 int c1 = text_yyinput (); |
5dd06f19e9be
handle commands in the lexer
John W. Eaton <jwe@octave.org>
parents:
8745
diff
changeset
|
2757 |
5dd06f19e9be
handle commands in the lexer
John W. Eaton <jwe@octave.org>
parents:
8745
diff
changeset
|
2758 if (c1 == '=') |
5dd06f19e9be
handle commands in the lexer
John W. Eaton <jwe@octave.org>
parents:
8745
diff
changeset
|
2759 { |
5dd06f19e9be
handle commands in the lexer
John W. Eaton <jwe@octave.org>
parents:
8745
diff
changeset
|
2760 int c2 = text_yyinput (); |
5dd06f19e9be
handle commands in the lexer
John W. Eaton <jwe@octave.org>
parents:
8745
diff
changeset
|
2761 |
5dd06f19e9be
handle commands in the lexer
John W. Eaton <jwe@octave.org>
parents:
8745
diff
changeset
|
2762 if (! match_any (c2, ",;\n") && (c2 == ' ' || c2 == '\t') |
5dd06f19e9be
handle commands in the lexer
John W. Eaton <jwe@octave.org>
parents:
8745
diff
changeset
|
2763 && next_token_can_follow_bin_op ()) |
5dd06f19e9be
handle commands in the lexer
John W. Eaton <jwe@octave.org>
parents:
8745
diff
changeset
|
2764 retval = false; |
5dd06f19e9be
handle commands in the lexer
John W. Eaton <jwe@octave.org>
parents:
8745
diff
changeset
|
2765 |
5dd06f19e9be
handle commands in the lexer
John W. Eaton <jwe@octave.org>
parents:
8745
diff
changeset
|
2766 xunput (c2, yytext); |
5dd06f19e9be
handle commands in the lexer
John W. Eaton <jwe@octave.org>
parents:
8745
diff
changeset
|
2767 } |
5dd06f19e9be
handle commands in the lexer
John W. Eaton <jwe@octave.org>
parents:
8745
diff
changeset
|
2768 else |
5dd06f19e9be
handle commands in the lexer
John W. Eaton <jwe@octave.org>
parents:
8745
diff
changeset
|
2769 retval = false; |
5dd06f19e9be
handle commands in the lexer
John W. Eaton <jwe@octave.org>
parents:
8745
diff
changeset
|
2770 |
5dd06f19e9be
handle commands in the lexer
John W. Eaton <jwe@octave.org>
parents:
8745
diff
changeset
|
2771 xunput (c1, yytext); |
5dd06f19e9be
handle commands in the lexer
John W. Eaton <jwe@octave.org>
parents:
8745
diff
changeset
|
2772 } |
5dd06f19e9be
handle commands in the lexer
John W. Eaton <jwe@octave.org>
parents:
8745
diff
changeset
|
2773 break; |
5dd06f19e9be
handle commands in the lexer
John W. Eaton <jwe@octave.org>
parents:
8745
diff
changeset
|
2774 |
5dd06f19e9be
handle commands in the lexer
John W. Eaton <jwe@octave.org>
parents:
8745
diff
changeset
|
2775 case '(': |
5dd06f19e9be
handle commands in the lexer
John W. Eaton <jwe@octave.org>
parents:
8745
diff
changeset
|
2776 case '{': |
5dd06f19e9be
handle commands in the lexer
John W. Eaton <jwe@octave.org>
parents:
8745
diff
changeset
|
2777 // Indexing. |
5dd06f19e9be
handle commands in the lexer
John W. Eaton <jwe@octave.org>
parents:
8745
diff
changeset
|
2778 retval = false; |
5dd06f19e9be
handle commands in the lexer
John W. Eaton <jwe@octave.org>
parents:
8745
diff
changeset
|
2779 break; |
5dd06f19e9be
handle commands in the lexer
John W. Eaton <jwe@octave.org>
parents:
8745
diff
changeset
|
2780 |
5dd06f19e9be
handle commands in the lexer
John W. Eaton <jwe@octave.org>
parents:
8745
diff
changeset
|
2781 case '\n': |
5dd06f19e9be
handle commands in the lexer
John W. Eaton <jwe@octave.org>
parents:
8745
diff
changeset
|
2782 // EOL. |
5dd06f19e9be
handle commands in the lexer
John W. Eaton <jwe@octave.org>
parents:
8745
diff
changeset
|
2783 break; |
5dd06f19e9be
handle commands in the lexer
John W. Eaton <jwe@octave.org>
parents:
8745
diff
changeset
|
2784 |
5dd06f19e9be
handle commands in the lexer
John W. Eaton <jwe@octave.org>
parents:
8745
diff
changeset
|
2785 case '\'': |
5dd06f19e9be
handle commands in the lexer
John W. Eaton <jwe@octave.org>
parents:
8745
diff
changeset
|
2786 case '"': |
5dd06f19e9be
handle commands in the lexer
John W. Eaton <jwe@octave.org>
parents:
8745
diff
changeset
|
2787 // Beginning of a character string. |
5dd06f19e9be
handle commands in the lexer
John W. Eaton <jwe@octave.org>
parents:
8745
diff
changeset
|
2788 break; |
5dd06f19e9be
handle commands in the lexer
John W. Eaton <jwe@octave.org>
parents:
8745
diff
changeset
|
2789 |
5dd06f19e9be
handle commands in the lexer
John W. Eaton <jwe@octave.org>
parents:
8745
diff
changeset
|
2790 // + - ++ -- += -= |
5dd06f19e9be
handle commands in the lexer
John W. Eaton <jwe@octave.org>
parents:
8745
diff
changeset
|
2791 case '+': |
5dd06f19e9be
handle commands in the lexer
John W. Eaton <jwe@octave.org>
parents:
8745
diff
changeset
|
2792 case '-': |
5dd06f19e9be
handle commands in the lexer
John W. Eaton <jwe@octave.org>
parents:
8745
diff
changeset
|
2793 { |
5dd06f19e9be
handle commands in the lexer
John W. Eaton <jwe@octave.org>
parents:
8745
diff
changeset
|
2794 int c1 = text_yyinput (); |
5dd06f19e9be
handle commands in the lexer
John W. Eaton <jwe@octave.org>
parents:
8745
diff
changeset
|
2795 |
5dd06f19e9be
handle commands in the lexer
John W. Eaton <jwe@octave.org>
parents:
8745
diff
changeset
|
2796 switch (c1) |
5dd06f19e9be
handle commands in the lexer
John W. Eaton <jwe@octave.org>
parents:
8745
diff
changeset
|
2797 { |
5dd06f19e9be
handle commands in the lexer
John W. Eaton <jwe@octave.org>
parents:
8745
diff
changeset
|
2798 case '\n': |
5dd06f19e9be
handle commands in the lexer
John W. Eaton <jwe@octave.org>
parents:
8745
diff
changeset
|
2799 // EOL. |
5dd06f19e9be
handle commands in the lexer
John W. Eaton <jwe@octave.org>
parents:
8745
diff
changeset
|
2800 case '+': |
5dd06f19e9be
handle commands in the lexer
John W. Eaton <jwe@octave.org>
parents:
8745
diff
changeset
|
2801 case '-': |
5dd06f19e9be
handle commands in the lexer
John W. Eaton <jwe@octave.org>
parents:
8745
diff
changeset
|
2802 // Unary ops, spacing doesn't matter. |
5dd06f19e9be
handle commands in the lexer
John W. Eaton <jwe@octave.org>
parents:
8745
diff
changeset
|
2803 break; |
5dd06f19e9be
handle commands in the lexer
John W. Eaton <jwe@octave.org>
parents:
8745
diff
changeset
|
2804 |
5dd06f19e9be
handle commands in the lexer
John W. Eaton <jwe@octave.org>
parents:
8745
diff
changeset
|
2805 case '\t': |
5dd06f19e9be
handle commands in the lexer
John W. Eaton <jwe@octave.org>
parents:
8745
diff
changeset
|
2806 case ' ': |
5dd06f19e9be
handle commands in the lexer
John W. Eaton <jwe@octave.org>
parents:
8745
diff
changeset
|
2807 { |
5dd06f19e9be
handle commands in the lexer
John W. Eaton <jwe@octave.org>
parents:
8745
diff
changeset
|
2808 if (next_token_can_follow_bin_op ()) |
5dd06f19e9be
handle commands in the lexer
John W. Eaton <jwe@octave.org>
parents:
8745
diff
changeset
|
2809 retval = false; |
5dd06f19e9be
handle commands in the lexer
John W. Eaton <jwe@octave.org>
parents:
8745
diff
changeset
|
2810 } |
5dd06f19e9be
handle commands in the lexer
John W. Eaton <jwe@octave.org>
parents:
8745
diff
changeset
|
2811 break; |
5dd06f19e9be
handle commands in the lexer
John W. Eaton <jwe@octave.org>
parents:
8745
diff
changeset
|
2812 |
5dd06f19e9be
handle commands in the lexer
John W. Eaton <jwe@octave.org>
parents:
8745
diff
changeset
|
2813 case '=': |
5dd06f19e9be
handle commands in the lexer
John W. Eaton <jwe@octave.org>
parents:
8745
diff
changeset
|
2814 { |
5dd06f19e9be
handle commands in the lexer
John W. Eaton <jwe@octave.org>
parents:
8745
diff
changeset
|
2815 int c2 = text_yyinput (); |
5dd06f19e9be
handle commands in the lexer
John W. Eaton <jwe@octave.org>
parents:
8745
diff
changeset
|
2816 |
5dd06f19e9be
handle commands in the lexer
John W. Eaton <jwe@octave.org>
parents:
8745
diff
changeset
|
2817 if (! match_any (c2, ",;\n") && (c2 == ' ' || c2 == '\t') |
5dd06f19e9be
handle commands in the lexer
John W. Eaton <jwe@octave.org>
parents:
8745
diff
changeset
|
2818 && next_token_can_follow_bin_op ()) |
5dd06f19e9be
handle commands in the lexer
John W. Eaton <jwe@octave.org>
parents:
8745
diff
changeset
|
2819 retval = false; |
5dd06f19e9be
handle commands in the lexer
John W. Eaton <jwe@octave.org>
parents:
8745
diff
changeset
|
2820 |
5dd06f19e9be
handle commands in the lexer
John W. Eaton <jwe@octave.org>
parents:
8745
diff
changeset
|
2821 xunput (c2, yytext); |
5dd06f19e9be
handle commands in the lexer
John W. Eaton <jwe@octave.org>
parents:
8745
diff
changeset
|
2822 } |
5dd06f19e9be
handle commands in the lexer
John W. Eaton <jwe@octave.org>
parents:
8745
diff
changeset
|
2823 break; |
5dd06f19e9be
handle commands in the lexer
John W. Eaton <jwe@octave.org>
parents:
8745
diff
changeset
|
2824 } |
5dd06f19e9be
handle commands in the lexer
John W. Eaton <jwe@octave.org>
parents:
8745
diff
changeset
|
2825 |
5dd06f19e9be
handle commands in the lexer
John W. Eaton <jwe@octave.org>
parents:
8745
diff
changeset
|
2826 xunput (c1, yytext); |
5dd06f19e9be
handle commands in the lexer
John W. Eaton <jwe@octave.org>
parents:
8745
diff
changeset
|
2827 } |
5dd06f19e9be
handle commands in the lexer
John W. Eaton <jwe@octave.org>
parents:
8745
diff
changeset
|
2828 break; |
5dd06f19e9be
handle commands in the lexer
John W. Eaton <jwe@octave.org>
parents:
8745
diff
changeset
|
2829 |
5dd06f19e9be
handle commands in the lexer
John W. Eaton <jwe@octave.org>
parents:
8745
diff
changeset
|
2830 case ':': |
5dd06f19e9be
handle commands in the lexer
John W. Eaton <jwe@octave.org>
parents:
8745
diff
changeset
|
2831 case '/': |
5dd06f19e9be
handle commands in the lexer
John W. Eaton <jwe@octave.org>
parents:
8745
diff
changeset
|
2832 case '\\': |
5dd06f19e9be
handle commands in the lexer
John W. Eaton <jwe@octave.org>
parents:
8745
diff
changeset
|
2833 case '^': |
5dd06f19e9be
handle commands in the lexer
John W. Eaton <jwe@octave.org>
parents:
8745
diff
changeset
|
2834 { |
5dd06f19e9be
handle commands in the lexer
John W. Eaton <jwe@octave.org>
parents:
8745
diff
changeset
|
2835 int c1 = text_yyinput (); |
5dd06f19e9be
handle commands in the lexer
John W. Eaton <jwe@octave.org>
parents:
8745
diff
changeset
|
2836 |
5dd06f19e9be
handle commands in the lexer
John W. Eaton <jwe@octave.org>
parents:
8745
diff
changeset
|
2837 if (! match_any (c1, ",;\n") && (c1 == ' ' || c1 == '\t') |
5dd06f19e9be
handle commands in the lexer
John W. Eaton <jwe@octave.org>
parents:
8745
diff
changeset
|
2838 && next_token_can_follow_bin_op ()) |
5dd06f19e9be
handle commands in the lexer
John W. Eaton <jwe@octave.org>
parents:
8745
diff
changeset
|
2839 retval = false; |
5dd06f19e9be
handle commands in the lexer
John W. Eaton <jwe@octave.org>
parents:
8745
diff
changeset
|
2840 |
5dd06f19e9be
handle commands in the lexer
John W. Eaton <jwe@octave.org>
parents:
8745
diff
changeset
|
2841 xunput (c1, yytext); |
5dd06f19e9be
handle commands in the lexer
John W. Eaton <jwe@octave.org>
parents:
8745
diff
changeset
|
2842 } |
5dd06f19e9be
handle commands in the lexer
John W. Eaton <jwe@octave.org>
parents:
8745
diff
changeset
|
2843 break; |
5dd06f19e9be
handle commands in the lexer
John W. Eaton <jwe@octave.org>
parents:
8745
diff
changeset
|
2844 |
5dd06f19e9be
handle commands in the lexer
John W. Eaton <jwe@octave.org>
parents:
8745
diff
changeset
|
2845 // .+ .- ./ .\ .^ .* .** |
5dd06f19e9be
handle commands in the lexer
John W. Eaton <jwe@octave.org>
parents:
8745
diff
changeset
|
2846 case '.': |
5dd06f19e9be
handle commands in the lexer
John W. Eaton <jwe@octave.org>
parents:
8745
diff
changeset
|
2847 { |
5dd06f19e9be
handle commands in the lexer
John W. Eaton <jwe@octave.org>
parents:
8745
diff
changeset
|
2848 int c1 = text_yyinput (); |
5dd06f19e9be
handle commands in the lexer
John W. Eaton <jwe@octave.org>
parents:
8745
diff
changeset
|
2849 |
5dd06f19e9be
handle commands in the lexer
John W. Eaton <jwe@octave.org>
parents:
8745
diff
changeset
|
2850 if (match_any (c1, "+-/\\^*")) |
5dd06f19e9be
handle commands in the lexer
John W. Eaton <jwe@octave.org>
parents:
8745
diff
changeset
|
2851 { |
5dd06f19e9be
handle commands in the lexer
John W. Eaton <jwe@octave.org>
parents:
8745
diff
changeset
|
2852 int c2 = text_yyinput (); |
5dd06f19e9be
handle commands in the lexer
John W. Eaton <jwe@octave.org>
parents:
8745
diff
changeset
|
2853 |
5dd06f19e9be
handle commands in the lexer
John W. Eaton <jwe@octave.org>
parents:
8745
diff
changeset
|
2854 if (c2 == '=') |
5dd06f19e9be
handle commands in the lexer
John W. Eaton <jwe@octave.org>
parents:
8745
diff
changeset
|
2855 { |
5dd06f19e9be
handle commands in the lexer
John W. Eaton <jwe@octave.org>
parents:
8745
diff
changeset
|
2856 int c3 = text_yyinput (); |
5dd06f19e9be
handle commands in the lexer
John W. Eaton <jwe@octave.org>
parents:
8745
diff
changeset
|
2857 |
5dd06f19e9be
handle commands in the lexer
John W. Eaton <jwe@octave.org>
parents:
8745
diff
changeset
|
2858 if (! match_any (c3, ",;\n") && (c3 == ' ' || c3 == '\t') |
5dd06f19e9be
handle commands in the lexer
John W. Eaton <jwe@octave.org>
parents:
8745
diff
changeset
|
2859 && next_token_can_follow_bin_op ()) |
5dd06f19e9be
handle commands in the lexer
John W. Eaton <jwe@octave.org>
parents:
8745
diff
changeset
|
2860 retval = false; |
5dd06f19e9be
handle commands in the lexer
John W. Eaton <jwe@octave.org>
parents:
8745
diff
changeset
|
2861 |
5dd06f19e9be
handle commands in the lexer
John W. Eaton <jwe@octave.org>
parents:
8745
diff
changeset
|
2862 xunput (c3, yytext); |
5dd06f19e9be
handle commands in the lexer
John W. Eaton <jwe@octave.org>
parents:
8745
diff
changeset
|
2863 } |
5dd06f19e9be
handle commands in the lexer
John W. Eaton <jwe@octave.org>
parents:
8745
diff
changeset
|
2864 else if (! match_any (c2, ",;\n") && (c2 == ' ' || c2 == '\t') |
5dd06f19e9be
handle commands in the lexer
John W. Eaton <jwe@octave.org>
parents:
8745
diff
changeset
|
2865 && next_token_can_follow_bin_op ()) |
5dd06f19e9be
handle commands in the lexer
John W. Eaton <jwe@octave.org>
parents:
8745
diff
changeset
|
2866 retval = false; |
5dd06f19e9be
handle commands in the lexer
John W. Eaton <jwe@octave.org>
parents:
8745
diff
changeset
|
2867 |
5dd06f19e9be
handle commands in the lexer
John W. Eaton <jwe@octave.org>
parents:
8745
diff
changeset
|
2868 xunput (c2, yytext); |
5dd06f19e9be
handle commands in the lexer
John W. Eaton <jwe@octave.org>
parents:
8745
diff
changeset
|
2869 } |
5dd06f19e9be
handle commands in the lexer
John W. Eaton <jwe@octave.org>
parents:
8745
diff
changeset
|
2870 else if (! match_any (c1, ",;\n") |
5dd06f19e9be
handle commands in the lexer
John W. Eaton <jwe@octave.org>
parents:
8745
diff
changeset
|
2871 && (! isdigit (c1) && c1 != ' ' && c1 != '\t' |
5dd06f19e9be
handle commands in the lexer
John W. Eaton <jwe@octave.org>
parents:
8745
diff
changeset
|
2872 && c1 != '.')) |
5dd06f19e9be
handle commands in the lexer
John W. Eaton <jwe@octave.org>
parents:
8745
diff
changeset
|
2873 { |
5dd06f19e9be
handle commands in the lexer
John W. Eaton <jwe@octave.org>
parents:
8745
diff
changeset
|
2874 // Structure reference. FIXME -- is this a complete check? |
5dd06f19e9be
handle commands in the lexer
John W. Eaton <jwe@octave.org>
parents:
8745
diff
changeset
|
2875 |
5dd06f19e9be
handle commands in the lexer
John W. Eaton <jwe@octave.org>
parents:
8745
diff
changeset
|
2876 retval = false; |
5dd06f19e9be
handle commands in the lexer
John W. Eaton <jwe@octave.org>
parents:
8745
diff
changeset
|
2877 } |
5dd06f19e9be
handle commands in the lexer
John W. Eaton <jwe@octave.org>
parents:
8745
diff
changeset
|
2878 |
5dd06f19e9be
handle commands in the lexer
John W. Eaton <jwe@octave.org>
parents:
8745
diff
changeset
|
2879 xunput (c1, yytext); |
5dd06f19e9be
handle commands in the lexer
John W. Eaton <jwe@octave.org>
parents:
8745
diff
changeset
|
2880 } |
5dd06f19e9be
handle commands in the lexer
John W. Eaton <jwe@octave.org>
parents:
8745
diff
changeset
|
2881 break; |
5dd06f19e9be
handle commands in the lexer
John W. Eaton <jwe@octave.org>
parents:
8745
diff
changeset
|
2882 |
5dd06f19e9be
handle commands in the lexer
John W. Eaton <jwe@octave.org>
parents:
8745
diff
changeset
|
2883 // & && | || * ** |
5dd06f19e9be
handle commands in the lexer
John W. Eaton <jwe@octave.org>
parents:
8745
diff
changeset
|
2884 case '&': |
5dd06f19e9be
handle commands in the lexer
John W. Eaton <jwe@octave.org>
parents:
8745
diff
changeset
|
2885 case '|': |
5dd06f19e9be
handle commands in the lexer
John W. Eaton <jwe@octave.org>
parents:
8745
diff
changeset
|
2886 case '*': |
5dd06f19e9be
handle commands in the lexer
John W. Eaton <jwe@octave.org>
parents:
8745
diff
changeset
|
2887 { |
5dd06f19e9be
handle commands in the lexer
John W. Eaton <jwe@octave.org>
parents:
8745
diff
changeset
|
2888 int c1 = text_yyinput (); |
5dd06f19e9be
handle commands in the lexer
John W. Eaton <jwe@octave.org>
parents:
8745
diff
changeset
|
2889 |
5dd06f19e9be
handle commands in the lexer
John W. Eaton <jwe@octave.org>
parents:
8745
diff
changeset
|
2890 if (c1 == c0) |
5dd06f19e9be
handle commands in the lexer
John W. Eaton <jwe@octave.org>
parents:
8745
diff
changeset
|
2891 { |
5dd06f19e9be
handle commands in the lexer
John W. Eaton <jwe@octave.org>
parents:
8745
diff
changeset
|
2892 int c2 = text_yyinput (); |
5dd06f19e9be
handle commands in the lexer
John W. Eaton <jwe@octave.org>
parents:
8745
diff
changeset
|
2893 |
5dd06f19e9be
handle commands in the lexer
John W. Eaton <jwe@octave.org>
parents:
8745
diff
changeset
|
2894 if (! match_any (c2, ",;\n") && (c2 == ' ' || c2 == '\t') |
5dd06f19e9be
handle commands in the lexer
John W. Eaton <jwe@octave.org>
parents:
8745
diff
changeset
|
2895 && next_token_can_follow_bin_op ()) |
5dd06f19e9be
handle commands in the lexer
John W. Eaton <jwe@octave.org>
parents:
8745
diff
changeset
|
2896 retval = false; |
5dd06f19e9be
handle commands in the lexer
John W. Eaton <jwe@octave.org>
parents:
8745
diff
changeset
|
2897 |
5dd06f19e9be
handle commands in the lexer
John W. Eaton <jwe@octave.org>
parents:
8745
diff
changeset
|
2898 xunput (c2, yytext); |
5dd06f19e9be
handle commands in the lexer
John W. Eaton <jwe@octave.org>
parents:
8745
diff
changeset
|
2899 } |
5dd06f19e9be
handle commands in the lexer
John W. Eaton <jwe@octave.org>
parents:
8745
diff
changeset
|
2900 else if (! match_any (c1, ",;\n") && (c1 == ' ' || c1 == '\t') |
5dd06f19e9be
handle commands in the lexer
John W. Eaton <jwe@octave.org>
parents:
8745
diff
changeset
|
2901 && next_token_can_follow_bin_op ()) |
5dd06f19e9be
handle commands in the lexer
John W. Eaton <jwe@octave.org>
parents:
8745
diff
changeset
|
2902 retval = false; |
5dd06f19e9be
handle commands in the lexer
John W. Eaton <jwe@octave.org>
parents:
8745
diff
changeset
|
2903 |
5dd06f19e9be
handle commands in the lexer
John W. Eaton <jwe@octave.org>
parents:
8745
diff
changeset
|
2904 xunput (c1, yytext); |
5dd06f19e9be
handle commands in the lexer
John W. Eaton <jwe@octave.org>
parents:
8745
diff
changeset
|
2905 } |
5dd06f19e9be
handle commands in the lexer
John W. Eaton <jwe@octave.org>
parents:
8745
diff
changeset
|
2906 break; |
5dd06f19e9be
handle commands in the lexer
John W. Eaton <jwe@octave.org>
parents:
8745
diff
changeset
|
2907 |
5dd06f19e9be
handle commands in the lexer
John W. Eaton <jwe@octave.org>
parents:
8745
diff
changeset
|
2908 // < <= > >= |
5dd06f19e9be
handle commands in the lexer
John W. Eaton <jwe@octave.org>
parents:
8745
diff
changeset
|
2909 case '<': |
5dd06f19e9be
handle commands in the lexer
John W. Eaton <jwe@octave.org>
parents:
8745
diff
changeset
|
2910 case '>': |
5dd06f19e9be
handle commands in the lexer
John W. Eaton <jwe@octave.org>
parents:
8745
diff
changeset
|
2911 { |
5dd06f19e9be
handle commands in the lexer
John W. Eaton <jwe@octave.org>
parents:
8745
diff
changeset
|
2912 int c1 = text_yyinput (); |
5dd06f19e9be
handle commands in the lexer
John W. Eaton <jwe@octave.org>
parents:
8745
diff
changeset
|
2913 |
5dd06f19e9be
handle commands in the lexer
John W. Eaton <jwe@octave.org>
parents:
8745
diff
changeset
|
2914 if (c1 == '=') |
5dd06f19e9be
handle commands in the lexer
John W. Eaton <jwe@octave.org>
parents:
8745
diff
changeset
|
2915 { |
5dd06f19e9be
handle commands in the lexer
John W. Eaton <jwe@octave.org>
parents:
8745
diff
changeset
|
2916 int c2 = text_yyinput (); |
5dd06f19e9be
handle commands in the lexer
John W. Eaton <jwe@octave.org>
parents:
8745
diff
changeset
|
2917 |
5dd06f19e9be
handle commands in the lexer
John W. Eaton <jwe@octave.org>
parents:
8745
diff
changeset
|
2918 if (! match_any (c2, ",;\n") && (c2 == ' ' || c2 == '\t') |
5dd06f19e9be
handle commands in the lexer
John W. Eaton <jwe@octave.org>
parents:
8745
diff
changeset
|
2919 && next_token_can_follow_bin_op ()) |
5dd06f19e9be
handle commands in the lexer
John W. Eaton <jwe@octave.org>
parents:
8745
diff
changeset
|
2920 retval = false; |
5dd06f19e9be
handle commands in the lexer
John W. Eaton <jwe@octave.org>
parents:
8745
diff
changeset
|
2921 |
5dd06f19e9be
handle commands in the lexer
John W. Eaton <jwe@octave.org>
parents:
8745
diff
changeset
|
2922 xunput (c2, yytext); |
5dd06f19e9be
handle commands in the lexer
John W. Eaton <jwe@octave.org>
parents:
8745
diff
changeset
|
2923 } |
5dd06f19e9be
handle commands in the lexer
John W. Eaton <jwe@octave.org>
parents:
8745
diff
changeset
|
2924 else if (! match_any (c1, ",;\n") && (c1 == ' ' || c1 == '\t') |
5dd06f19e9be
handle commands in the lexer
John W. Eaton <jwe@octave.org>
parents:
8745
diff
changeset
|
2925 && next_token_can_follow_bin_op ()) |
5dd06f19e9be
handle commands in the lexer
John W. Eaton <jwe@octave.org>
parents:
8745
diff
changeset
|
2926 retval = false; |
5dd06f19e9be
handle commands in the lexer
John W. Eaton <jwe@octave.org>
parents:
8745
diff
changeset
|
2927 |
5dd06f19e9be
handle commands in the lexer
John W. Eaton <jwe@octave.org>
parents:
8745
diff
changeset
|
2928 xunput (c1, yytext); |
5dd06f19e9be
handle commands in the lexer
John W. Eaton <jwe@octave.org>
parents:
8745
diff
changeset
|
2929 } |
5dd06f19e9be
handle commands in the lexer
John W. Eaton <jwe@octave.org>
parents:
8745
diff
changeset
|
2930 break; |
5dd06f19e9be
handle commands in the lexer
John W. Eaton <jwe@octave.org>
parents:
8745
diff
changeset
|
2931 |
5dd06f19e9be
handle commands in the lexer
John W. Eaton <jwe@octave.org>
parents:
8745
diff
changeset
|
2932 // ~= != |
5dd06f19e9be
handle commands in the lexer
John W. Eaton <jwe@octave.org>
parents:
8745
diff
changeset
|
2933 case '~': |
5dd06f19e9be
handle commands in the lexer
John W. Eaton <jwe@octave.org>
parents:
8745
diff
changeset
|
2934 case '!': |
5dd06f19e9be
handle commands in the lexer
John W. Eaton <jwe@octave.org>
parents:
8745
diff
changeset
|
2935 { |
5dd06f19e9be
handle commands in the lexer
John W. Eaton <jwe@octave.org>
parents:
8745
diff
changeset
|
2936 int c1 = text_yyinput (); |
5dd06f19e9be
handle commands in the lexer
John W. Eaton <jwe@octave.org>
parents:
8745
diff
changeset
|
2937 |
5dd06f19e9be
handle commands in the lexer
John W. Eaton <jwe@octave.org>
parents:
8745
diff
changeset
|
2938 // ~ and ! can be unary ops, so require following =. |
5dd06f19e9be
handle commands in the lexer
John W. Eaton <jwe@octave.org>
parents:
8745
diff
changeset
|
2939 if (c1 == '=') |
5dd06f19e9be
handle commands in the lexer
John W. Eaton <jwe@octave.org>
parents:
8745
diff
changeset
|
2940 { |
5dd06f19e9be
handle commands in the lexer
John W. Eaton <jwe@octave.org>
parents:
8745
diff
changeset
|
2941 int c2 = text_yyinput (); |
5dd06f19e9be
handle commands in the lexer
John W. Eaton <jwe@octave.org>
parents:
8745
diff
changeset
|
2942 |
5dd06f19e9be
handle commands in the lexer
John W. Eaton <jwe@octave.org>
parents:
8745
diff
changeset
|
2943 if (! match_any (c2, ",;\n") && (c2 == ' ' || c2 == '\t') |
5dd06f19e9be
handle commands in the lexer
John W. Eaton <jwe@octave.org>
parents:
8745
diff
changeset
|
2944 && next_token_can_follow_bin_op ()) |
5dd06f19e9be
handle commands in the lexer
John W. Eaton <jwe@octave.org>
parents:
8745
diff
changeset
|
2945 retval = false; |
5dd06f19e9be
handle commands in the lexer
John W. Eaton <jwe@octave.org>
parents:
8745
diff
changeset
|
2946 |
5dd06f19e9be
handle commands in the lexer
John W. Eaton <jwe@octave.org>
parents:
8745
diff
changeset
|
2947 xunput (c2, yytext); |
5dd06f19e9be
handle commands in the lexer
John W. Eaton <jwe@octave.org>
parents:
8745
diff
changeset
|
2948 } |
5dd06f19e9be
handle commands in the lexer
John W. Eaton <jwe@octave.org>
parents:
8745
diff
changeset
|
2949 else if (! match_any (c1, ",;\n") && (c1 == ' ' || c1 == '\t') |
5dd06f19e9be
handle commands in the lexer
John W. Eaton <jwe@octave.org>
parents:
8745
diff
changeset
|
2950 && next_token_can_follow_bin_op ()) |
5dd06f19e9be
handle commands in the lexer
John W. Eaton <jwe@octave.org>
parents:
8745
diff
changeset
|
2951 retval = false; |
5dd06f19e9be
handle commands in the lexer
John W. Eaton <jwe@octave.org>
parents:
8745
diff
changeset
|
2952 |
5dd06f19e9be
handle commands in the lexer
John W. Eaton <jwe@octave.org>
parents:
8745
diff
changeset
|
2953 xunput (c1, yytext); |
5dd06f19e9be
handle commands in the lexer
John W. Eaton <jwe@octave.org>
parents:
8745
diff
changeset
|
2954 } |
5dd06f19e9be
handle commands in the lexer
John W. Eaton <jwe@octave.org>
parents:
8745
diff
changeset
|
2955 break; |
5dd06f19e9be
handle commands in the lexer
John W. Eaton <jwe@octave.org>
parents:
8745
diff
changeset
|
2956 |
5dd06f19e9be
handle commands in the lexer
John W. Eaton <jwe@octave.org>
parents:
8745
diff
changeset
|
2957 default: |
5dd06f19e9be
handle commands in the lexer
John W. Eaton <jwe@octave.org>
parents:
8745
diff
changeset
|
2958 break; |
5dd06f19e9be
handle commands in the lexer
John W. Eaton <jwe@octave.org>
parents:
8745
diff
changeset
|
2959 } |
5dd06f19e9be
handle commands in the lexer
John W. Eaton <jwe@octave.org>
parents:
8745
diff
changeset
|
2960 |
5dd06f19e9be
handle commands in the lexer
John W. Eaton <jwe@octave.org>
parents:
8745
diff
changeset
|
2961 xunput (c0, yytext); |
5dd06f19e9be
handle commands in the lexer
John W. Eaton <jwe@octave.org>
parents:
8745
diff
changeset
|
2962 |
5dd06f19e9be
handle commands in the lexer
John W. Eaton <jwe@octave.org>
parents:
8745
diff
changeset
|
2963 return retval; |
5dd06f19e9be
handle commands in the lexer
John W. Eaton <jwe@octave.org>
parents:
8745
diff
changeset
|
2964 } |
5dd06f19e9be
handle commands in the lexer
John W. Eaton <jwe@octave.org>
parents:
8745
diff
changeset
|
2965 |
767 | 2966 // Figure out exactly what kind of token to return when we have seen |
4238 | 2967 // an identifier. Handles keywords. Return -1 if the identifier |
2968 // should be ignored. | |
767 | 2969 |
146 | 2970 static int |
3974 | 2971 handle_identifier (void) |
146 | 2972 { |
8746
5dd06f19e9be
handle commands in the lexer
John W. Eaton <jwe@octave.org>
parents:
8745
diff
changeset
|
2973 bool at_bos = lexer_flags.at_beginning_of_statement; |
5dd06f19e9be
handle commands in the lexer
John W. Eaton <jwe@octave.org>
parents:
8745
diff
changeset
|
2974 |
3974 | 2975 std::string tok = strip_trailing_whitespace (yytext); |
2976 | |
2977 int c = yytext[yyleng-1]; | |
2978 | |
2979 int cont_is_spc = eat_continuation (); | |
2980 | |
2981 int spc_gobbled = (cont_is_spc || c == ' ' || c == '\t'); | |
2982 | |
2970 | 2983 // If we are expecting a structure element, avoid recognizing |
2984 // keywords and other special names and return STRUCT_ELT, which is | |
2985 // a string that is also a valid identifier. But first, we have to | |
2986 // decide whether to insert a comma. | |
747 | 2987 |
1826 | 2988 if (lexer_flags.looking_at_indirect_ref) |
1072 | 2989 { |
2970 | 2990 do_comma_insert_check (); |
2991 | |
1072 | 2992 maybe_unput_comma (spc_gobbled); |
2819 | 2993 |
2994 yylval.tok_val = new token (tok, input_line_number, | |
2995 current_input_column); | |
2996 | |
2997 token_stack.push (yylval.tok_val); | |
2998 | |
2857 | 2999 lexer_flags.quote_is_transpose = true; |
3000 lexer_flags.convert_spaces_to_comma = true; | |
9324
29563379fa9b
don't look for object index after keyword
John W. Eaton <jwe@octave.org>
parents:
8974
diff
changeset
|
3001 lexer_flags.looking_for_object_index = true; |
2819 | 3002 |
3003 current_input_column += yyleng; | |
3004 | |
2970 | 3005 return STRUCT_ELT; |
1072 | 3006 } |
747 | 3007 |
8746
5dd06f19e9be
handle commands in the lexer
John W. Eaton <jwe@octave.org>
parents:
8745
diff
changeset
|
3008 lexer_flags.at_beginning_of_statement = false; |
5dd06f19e9be
handle commands in the lexer
John W. Eaton <jwe@octave.org>
parents:
8745
diff
changeset
|
3009 |
5dd06f19e9be
handle commands in the lexer
John W. Eaton <jwe@octave.org>
parents:
8745
diff
changeset
|
3010 // The is_keyword_token may reset |
5dd06f19e9be
handle commands in the lexer
John W. Eaton <jwe@octave.org>
parents:
8745
diff
changeset
|
3011 // lexer_flags.at_beginning_of_statement. For example, if it sees |
5dd06f19e9be
handle commands in the lexer
John W. Eaton <jwe@octave.org>
parents:
8745
diff
changeset
|
3012 // an else token, then the next token is at the beginning of a |
5dd06f19e9be
handle commands in the lexer
John W. Eaton <jwe@octave.org>
parents:
8745
diff
changeset
|
3013 // statement. |
5dd06f19e9be
handle commands in the lexer
John W. Eaton <jwe@octave.org>
parents:
8745
diff
changeset
|
3014 |
4930 | 3015 int kw_token = is_keyword_token (tok); |
3016 | |
8746
5dd06f19e9be
handle commands in the lexer
John W. Eaton <jwe@octave.org>
parents:
8745
diff
changeset
|
3017 // If we found a keyword token, then the beginning_of_statement flag |
5dd06f19e9be
handle commands in the lexer
John W. Eaton <jwe@octave.org>
parents:
8745
diff
changeset
|
3018 // is already set. Otherwise, we won't be at the beginning of a |
5dd06f19e9be
handle commands in the lexer
John W. Eaton <jwe@octave.org>
parents:
8745
diff
changeset
|
3019 // statement. |
5dd06f19e9be
handle commands in the lexer
John W. Eaton <jwe@octave.org>
parents:
8745
diff
changeset
|
3020 |
4930 | 3021 if (lexer_flags.looking_at_function_handle) |
3022 { | |
3023 if (kw_token) | |
3024 { | |
3025 error ("function handles may not refer to keywords"); | |
3026 | |
3027 return LEXICAL_ERROR; | |
3028 } | |
3029 else | |
7722
c3bb0b7a4261
lex.l: allow tokens to be displayed when parsed
John W. Eaton <jwe@octave.org>
parents:
7720
diff
changeset
|
3030 { |
c3bb0b7a4261
lex.l: allow tokens to be displayed when parsed
John W. Eaton <jwe@octave.org>
parents:
7720
diff
changeset
|
3031 yylval.tok_val = new token (tok, input_line_number, |
c3bb0b7a4261
lex.l: allow tokens to be displayed when parsed
John W. Eaton <jwe@octave.org>
parents:
7720
diff
changeset
|
3032 current_input_column); |
c3bb0b7a4261
lex.l: allow tokens to be displayed when parsed
John W. Eaton <jwe@octave.org>
parents:
7720
diff
changeset
|
3033 |
c3bb0b7a4261
lex.l: allow tokens to be displayed when parsed
John W. Eaton <jwe@octave.org>
parents:
7720
diff
changeset
|
3034 token_stack.push (yylval.tok_val); |
c3bb0b7a4261
lex.l: allow tokens to be displayed when parsed
John W. Eaton <jwe@octave.org>
parents:
7720
diff
changeset
|
3035 |
c3bb0b7a4261
lex.l: allow tokens to be displayed when parsed
John W. Eaton <jwe@octave.org>
parents:
7720
diff
changeset
|
3036 current_input_column += yyleng; |
c3bb0b7a4261
lex.l: allow tokens to be displayed when parsed
John W. Eaton <jwe@octave.org>
parents:
7720
diff
changeset
|
3037 lexer_flags.quote_is_transpose = false; |
c3bb0b7a4261
lex.l: allow tokens to be displayed when parsed
John W. Eaton <jwe@octave.org>
parents:
7720
diff
changeset
|
3038 lexer_flags.convert_spaces_to_comma = true; |
9324
29563379fa9b
don't look for object index after keyword
John W. Eaton <jwe@octave.org>
parents:
8974
diff
changeset
|
3039 lexer_flags.looking_for_object_index = true; |
7722
c3bb0b7a4261
lex.l: allow tokens to be displayed when parsed
John W. Eaton <jwe@octave.org>
parents:
7720
diff
changeset
|
3040 |
c3bb0b7a4261
lex.l: allow tokens to be displayed when parsed
John W. Eaton <jwe@octave.org>
parents:
7720
diff
changeset
|
3041 return FCN_HANDLE; |
c3bb0b7a4261
lex.l: allow tokens to be displayed when parsed
John W. Eaton <jwe@octave.org>
parents:
7720
diff
changeset
|
3042 } |
4930 | 3043 } |
3044 | |
5102 | 3045 // If we have a regular keyword, return it. |
7722
c3bb0b7a4261
lex.l: allow tokens to be displayed when parsed
John W. Eaton <jwe@octave.org>
parents:
7720
diff
changeset
|
3046 // Keywords can be followed by identifiers. |
146 | 3047 |
3048 if (kw_token) | |
3049 { | |
7722
c3bb0b7a4261
lex.l: allow tokens to be displayed when parsed
John W. Eaton <jwe@octave.org>
parents:
7720
diff
changeset
|
3050 if (kw_token >= 0) |
c3bb0b7a4261
lex.l: allow tokens to be displayed when parsed
John W. Eaton <jwe@octave.org>
parents:
7720
diff
changeset
|
3051 { |
c3bb0b7a4261
lex.l: allow tokens to be displayed when parsed
John W. Eaton <jwe@octave.org>
parents:
7720
diff
changeset
|
3052 current_input_column += yyleng; |
c3bb0b7a4261
lex.l: allow tokens to be displayed when parsed
John W. Eaton <jwe@octave.org>
parents:
7720
diff
changeset
|
3053 lexer_flags.quote_is_transpose = false; |
c3bb0b7a4261
lex.l: allow tokens to be displayed when parsed
John W. Eaton <jwe@octave.org>
parents:
7720
diff
changeset
|
3054 lexer_flags.convert_spaces_to_comma = true; |
9324
29563379fa9b
don't look for object index after keyword
John W. Eaton <jwe@octave.org>
parents:
8974
diff
changeset
|
3055 lexer_flags.looking_for_object_index = false; |
7722
c3bb0b7a4261
lex.l: allow tokens to be displayed when parsed
John W. Eaton <jwe@octave.org>
parents:
7720
diff
changeset
|
3056 } |
c3bb0b7a4261
lex.l: allow tokens to be displayed when parsed
John W. Eaton <jwe@octave.org>
parents:
7720
diff
changeset
|
3057 |
c3bb0b7a4261
lex.l: allow tokens to be displayed when parsed
John W. Eaton <jwe@octave.org>
parents:
7720
diff
changeset
|
3058 return kw_token; |
146 | 3059 } |
3060 | |
1826 | 3061 // See if we have a plot keyword (title, using, with, or clear). |
146 | 3062 |
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
|
3063 int c1 = text_yyinput (); |
3480 | 3064 |
3065 bool next_tok_is_eq = false; | |
3066 if (c1 == '=') | |
3067 { | |
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
|
3068 int c2 = text_yyinput (); |
8447
adab48231a03
make input_line_number work again
John W. Eaton <jwe@octave.org>
parents:
8312
diff
changeset
|
3069 xunput (c2, yytext); |
3480 | 3070 |
3071 if (c2 != '=') | |
3072 next_tok_is_eq = true; | |
3073 } | |
3074 | |
8447
adab48231a03
make input_line_number work again
John W. Eaton <jwe@octave.org>
parents:
8312
diff
changeset
|
3075 xunput (c1, yytext); |
1001 | 3076 |
2702 | 3077 // Kluge alert. |
3078 // | |
3079 // If we are looking at a text style function, set up to gobble its | |
2745 | 3080 // arguments. |
3081 // | |
3082 // If the following token is `=', or if we are parsing a function | |
3189 | 3083 // return list or function parameter list, or if we are looking at |
3084 // something like [ab,cd] = foo (), force the symbol to be inserted | |
3085 // as a variable in the current symbol table. | |
2702 | 3086 |
8746
5dd06f19e9be
handle commands in the lexer
John W. Eaton <jwe@octave.org>
parents:
8745
diff
changeset
|
3087 if (! is_variable (tok)) |
2702 | 3088 { |
8746
5dd06f19e9be
handle commands in the lexer
John W. Eaton <jwe@octave.org>
parents:
8745
diff
changeset
|
3089 if (at_bos && spc_gobbled && looks_like_command_arg ()) |
5dd06f19e9be
handle commands in the lexer
John W. Eaton <jwe@octave.org>
parents:
8745
diff
changeset
|
3090 { |
5dd06f19e9be
handle commands in the lexer
John W. Eaton <jwe@octave.org>
parents:
8745
diff
changeset
|
3091 BEGIN (COMMAND_START); |
5dd06f19e9be
handle commands in the lexer
John W. Eaton <jwe@octave.org>
parents:
8745
diff
changeset
|
3092 } |
5dd06f19e9be
handle commands in the lexer
John W. Eaton <jwe@octave.org>
parents:
8745
diff
changeset
|
3093 else if (next_tok_is_eq |
5dd06f19e9be
handle commands in the lexer
John W. Eaton <jwe@octave.org>
parents:
8745
diff
changeset
|
3094 || lexer_flags.looking_at_decl_list |
5dd06f19e9be
handle commands in the lexer
John W. Eaton <jwe@octave.org>
parents:
8745
diff
changeset
|
3095 || lexer_flags.looking_at_return_list |
5dd06f19e9be
handle commands in the lexer
John W. Eaton <jwe@octave.org>
parents:
8745
diff
changeset
|
3096 || (lexer_flags.looking_at_parameter_list |
5dd06f19e9be
handle commands in the lexer
John W. Eaton <jwe@octave.org>
parents:
8745
diff
changeset
|
3097 && ! lexer_flags.looking_at_initializer_expression)) |
2745 | 3098 { |
8881
8ed42c679af5
after defining a script or function, clear local variables created for parsing
John W. Eaton <jwe@octave.org>
parents:
8812
diff
changeset
|
3099 symbol_table::force_variable (tok); |
2745 | 3100 } |
8001
ff9e7873f8ea
improve handling of command-style names in matrix_or_assign_lhs context
John W. Eaton <jwe@octave.org>
parents:
7898
diff
changeset
|
3101 else if (lexer_flags.looking_at_matrix_or_assign_lhs) |
ff9e7873f8ea
improve handling of command-style names in matrix_or_assign_lhs context
John W. Eaton <jwe@octave.org>
parents:
7898
diff
changeset
|
3102 { |
ff9e7873f8ea
improve handling of command-style names in matrix_or_assign_lhs context
John W. Eaton <jwe@octave.org>
parents:
7898
diff
changeset
|
3103 lexer_flags.pending_local_variables.insert (tok); |
ff9e7873f8ea
improve handling of command-style names in matrix_or_assign_lhs context
John W. Eaton <jwe@octave.org>
parents:
7898
diff
changeset
|
3104 } |
2702 | 3105 } |
3106 | |
4234 | 3107 // Find the token in the symbol table. Beware the magic |
3108 // transformation of the end keyword... | |
3109 | |
3110 if (tok == "end") | |
3111 tok = "__end__"; | |
146 | 3112 |
7336 | 3113 yylval.tok_val = new token (&(symbol_table::insert (tok)), |
3114 input_line_number, current_input_column); | |
3115 | |
146 | 3116 token_stack.push (yylval.tok_val); |
3117 | |
1826 | 3118 // After seeing an identifer, it is ok to convert spaces to a comma |
3119 // (if needed). | |
146 | 3120 |
2857 | 3121 lexer_flags.convert_spaces_to_comma = true; |
146 | 3122 |
8746
5dd06f19e9be
handle commands in the lexer
John W. Eaton <jwe@octave.org>
parents:
8745
diff
changeset
|
3123 if (! (next_tok_is_eq || YY_START == COMMAND_START)) |
2877 | 3124 { |
3125 lexer_flags.quote_is_transpose = true; | |
146 | 3126 |
2877 | 3127 do_comma_insert_check (); |
3128 | |
3129 maybe_unput_comma (spc_gobbled); | |
146 | 3130 } |
3131 | |
2877 | 3132 current_input_column += yyleng; |
146 | 3133 |
9324
29563379fa9b
don't look for object index after keyword
John W. Eaton <jwe@octave.org>
parents:
8974
diff
changeset
|
3134 if (tok != "__end__") |
29563379fa9b
don't look for object index after keyword
John W. Eaton <jwe@octave.org>
parents:
8974
diff
changeset
|
3135 lexer_flags.looking_for_object_index = true; |
29563379fa9b
don't look for object index after keyword
John W. Eaton <jwe@octave.org>
parents:
8974
diff
changeset
|
3136 |
146 | 3137 return NAME; |
3138 } | |
3139 | |
1826 | 3140 void |
3141 lexical_feedback::init (void) | |
3142 { | |
3143 // Not initially defining a matrix list. | |
3351 | 3144 bracketflag = 0; |
1826 | 3145 |
4613 | 3146 // Not initially defining a cell array list. |
3147 braceflag = 0; | |
3148 | |
1826 | 3149 // Not initially inside a loop or if statement. |
3150 looping = 0; | |
3151 | |
2857 | 3152 // Not initially defining a function. |
3153 defining_func = false; | |
2877 | 3154 parsed_function_name = false; |
7336 | 3155 parsing_class_method = false; |
2857 | 3156 |
4930 | 3157 // Not initiallly looking at a function handle. |
3158 looking_at_function_handle = 0; | |
3159 | |
8701
1652e39b934e
handle command names in declaration lists
John W. Eaton <jwe@octave.org>
parents:
8537
diff
changeset
|
3160 // Not parsing a function return, parameter, or declaration list. |
2857 | 3161 looking_at_return_list = false; |
3162 looking_at_parameter_list = false; | |
8701
1652e39b934e
handle command names in declaration lists
John W. Eaton <jwe@octave.org>
parents:
8537
diff
changeset
|
3163 looking_at_decl_list = false; |
2857 | 3164 |
7634
ae90e05ad299
fix parameter list initializer bug
John W. Eaton <jwe@octave.org>
parents:
7587
diff
changeset
|
3165 // Not looking at an argument list initializer expression. |
ae90e05ad299
fix parameter list initializer bug
John W. Eaton <jwe@octave.org>
parents:
7587
diff
changeset
|
3166 looking_at_initializer_expression = false; |
ae90e05ad299
fix parameter list initializer bug
John W. Eaton <jwe@octave.org>
parents:
7587
diff
changeset
|
3167 |
3796 | 3168 // Not parsing a matrix or the left hand side of multi-value |
3169 // assignment statement. | |
3170 looking_at_matrix_or_assign_lhs = false; | |
3171 | |
4234 | 3172 // Not parsing an object index. |
8745
6dc61981d18b
better handling of object indexing in lexer
John W. Eaton <jwe@octave.org>
parents:
8701
diff
changeset
|
3173 while (! looking_at_object_index.empty ()) |
6dc61981d18b
better handling of object indexing in lexer
John W. Eaton <jwe@octave.org>
parents:
8701
diff
changeset
|
3174 looking_at_object_index.pop_front (); |
6dc61981d18b
better handling of object indexing in lexer
John W. Eaton <jwe@octave.org>
parents:
8701
diff
changeset
|
3175 |
6dc61981d18b
better handling of object indexing in lexer
John W. Eaton <jwe@octave.org>
parents:
8701
diff
changeset
|
3176 looking_at_object_index.push_front (false); |
6dc61981d18b
better handling of object indexing in lexer
John W. Eaton <jwe@octave.org>
parents:
8701
diff
changeset
|
3177 |
6dc61981d18b
better handling of object indexing in lexer
John W. Eaton <jwe@octave.org>
parents:
8701
diff
changeset
|
3178 // Object index not possible until we've seen something. |
6dc61981d18b
better handling of object indexing in lexer
John W. Eaton <jwe@octave.org>
parents:
8701
diff
changeset
|
3179 looking_for_object_index = false; |
4234 | 3180 |
8746
5dd06f19e9be
handle commands in the lexer
John W. Eaton <jwe@octave.org>
parents:
8745
diff
changeset
|
3181 // Yes, we are at the beginning of a statement. |
5dd06f19e9be
handle commands in the lexer
John W. Eaton <jwe@octave.org>
parents:
8745
diff
changeset
|
3182 at_beginning_of_statement = true; |
5dd06f19e9be
handle commands in the lexer
John W. Eaton <jwe@octave.org>
parents:
8745
diff
changeset
|
3183 |
2857 | 3184 // No need to do comma insert or convert spaces to comma at |
3185 // beginning of input. | |
3186 convert_spaces_to_comma = true; | |
3187 do_comma_insert = false; | |
3188 | |
1826 | 3189 // Not initially looking at indirect references. |
2857 | 3190 looking_at_indirect_ref = false; |
1826 | 3191 |
3192 // Quote marks strings intially. | |
2857 | 3193 quote_is_transpose = false; |
8001
ff9e7873f8ea
improve handling of command-style names in matrix_or_assign_lhs context
John W. Eaton <jwe@octave.org>
parents:
7898
diff
changeset
|
3194 |
ff9e7873f8ea
improve handling of command-style names in matrix_or_assign_lhs context
John W. Eaton <jwe@octave.org>
parents:
7898
diff
changeset
|
3195 // Set of identifiers that might be local variable names is empty. |
ff9e7873f8ea
improve handling of command-style names in matrix_or_assign_lhs context
John W. Eaton <jwe@octave.org>
parents:
7898
diff
changeset
|
3196 pending_local_variables.clear (); |
1826 | 3197 } |
3198 | |
4867 | 3199 bool |
3200 is_keyword (const std::string& s) | |
3201 { | |
5088 | 3202 return octave_kw_hash::in_word_set (s.c_str (), s.length ()) != 0; |
4867 | 3203 } |
3204 | |
8746
5dd06f19e9be
handle commands in the lexer
John W. Eaton <jwe@octave.org>
parents:
8745
diff
changeset
|
3205 DEFUN (iskeyword, args, , |
4264 | 3206 "-*- texinfo -*-\n\ |
3207 @deftypefn {Built-in Function} {} iskeyword (@var{name})\n\ | |
3208 Return true if @var{name} is an Octave keyword. If @var{name}\n\ | |
3209 is omitted, return a list of keywords.\n\ | |
3210 @end deftypefn") | |
3211 { | |
3212 octave_value retval; | |
3213 | |
3214 int argc = args.length () + 1; | |
3215 | |
4867 | 3216 string_vector argv = args.make_argv ("iskeyword"); |
4264 | 3217 |
3218 if (error_state) | |
3219 return retval; | |
3220 | |
3221 if (argc == 1) | |
3222 { | |
3223 string_vector lst (TOTAL_KEYWORDS); | |
3224 | |
3225 for (int i = 0; i < TOTAL_KEYWORDS; i++) | |
3226 lst[i] = wordlist[i].name; | |
3227 | |
8504
0e0bd07e6ae2
omission from last patch
Jaroslav Hajek <highegg@gmail.com>
parents:
8447
diff
changeset
|
3228 retval = Cell (lst.sort ()); |
4264 | 3229 } |
3230 else if (argc == 2) | |
3231 { | |
4867 | 3232 retval = is_keyword (argv[1]); |
4264 | 3233 } |
3234 else | |
5823 | 3235 print_usage (); |
4264 | 3236 |
3237 return retval; | |
3238 } | |
3239 | |
7715
5b4d278ec828
parse scripts completely before executing
John W. Eaton <jwe@octave.org>
parents:
7634
diff
changeset
|
3240 void |
9474
25ed2d6aacf6
Parse nested functions more accurately.
David Grundberg <individ@acc.umu.se>
parents:
9324
diff
changeset
|
3241 prep_lexer_for_script_file (void) |
7715
5b4d278ec828
parse scripts completely before executing
John W. Eaton <jwe@octave.org>
parents:
7634
diff
changeset
|
3242 { |
5b4d278ec828
parse scripts completely before executing
John W. Eaton <jwe@octave.org>
parents:
7634
diff
changeset
|
3243 BEGIN (SCRIPT_FILE_BEGIN); |
5b4d278ec828
parse scripts completely before executing
John W. Eaton <jwe@octave.org>
parents:
7634
diff
changeset
|
3244 } |
4264 | 3245 |
9474
25ed2d6aacf6
Parse nested functions more accurately.
David Grundberg <individ@acc.umu.se>
parents:
9324
diff
changeset
|
3246 void |
25ed2d6aacf6
Parse nested functions more accurately.
David Grundberg <individ@acc.umu.se>
parents:
9324
diff
changeset
|
3247 prep_lexer_for_function_file (void) |
25ed2d6aacf6
Parse nested functions more accurately.
David Grundberg <individ@acc.umu.se>
parents:
9324
diff
changeset
|
3248 { |
25ed2d6aacf6
Parse nested functions more accurately.
David Grundberg <individ@acc.umu.se>
parents:
9324
diff
changeset
|
3249 BEGIN (FUNCTION_FILE_BEGIN); |
25ed2d6aacf6
Parse nested functions more accurately.
David Grundberg <individ@acc.umu.se>
parents:
9324
diff
changeset
|
3250 } |
25ed2d6aacf6
Parse nested functions more accurately.
David Grundberg <individ@acc.umu.se>
parents:
9324
diff
changeset
|
3251 |
3388 | 3252 static void |
3253 maybe_warn_separator_insert (char sep) | |
3254 { | |
3523 | 3255 std::string nm = curr_fcn_file_full_name; |
3388 | 3256 |
5794 | 3257 if (nm.empty ()) |
3258 warning_with_id ("Octave:separator-insert", | |
3259 "potential auto-insertion of `%c' near line %d", | |
3260 sep, input_line_number); | |
3261 else | |
3262 warning_with_id ("Octave:separator-insert", | |
3263 "potential auto-insertion of `%c' near line %d of file %s", | |
3264 sep, input_line_number, nm.c_str ()); | |
3388 | 3265 } |
3266 | |
3400 | 3267 static void |
3268 gripe_single_quote_string (void) | |
3269 { | |
3523 | 3270 std::string nm = curr_fcn_file_full_name; |
3400 | 3271 |
5794 | 3272 if (nm.empty ()) |
3273 warning_with_id ("Octave:single-quote-string", | |
3274 "single quote delimited string near line %d", | |
3275 input_line_number); | |
3276 else | |
3277 warning_with_id ("Octave:single-quote-string", | |
3278 "single quote delimited string near line %d of file %s", | |
3279 input_line_number, nm.c_str ()); | |
3400 | 3280 } |
3281 | |
4037 | 3282 static void |
3283 gripe_matlab_incompatible (const std::string& msg) | |
3284 { | |
8974
fde2a916b2ac
include line and file info in parser warnings
John W. Eaton <jwe@octave.org>
parents:
8950
diff
changeset
|
3285 std::string nm = curr_fcn_file_full_name; |
fde2a916b2ac
include line and file info in parser warnings
John W. Eaton <jwe@octave.org>
parents:
8950
diff
changeset
|
3286 |
fde2a916b2ac
include line and file info in parser warnings
John W. Eaton <jwe@octave.org>
parents:
8950
diff
changeset
|
3287 if (nm.empty ()) |
fde2a916b2ac
include line and file info in parser warnings
John W. Eaton <jwe@octave.org>
parents:
8950
diff
changeset
|
3288 warning_with_id ("Octave:matlab-incompatible", |
fde2a916b2ac
include line and file info in parser warnings
John W. Eaton <jwe@octave.org>
parents:
8950
diff
changeset
|
3289 "potential Matlab compatibility problem: %s", |
fde2a916b2ac
include line and file info in parser warnings
John W. Eaton <jwe@octave.org>
parents:
8950
diff
changeset
|
3290 msg.c_str ()); |
fde2a916b2ac
include line and file info in parser warnings
John W. Eaton <jwe@octave.org>
parents:
8950
diff
changeset
|
3291 else |
fde2a916b2ac
include line and file info in parser warnings
John W. Eaton <jwe@octave.org>
parents:
8950
diff
changeset
|
3292 warning_with_id ("Octave:matlab-incompatible", |
fde2a916b2ac
include line and file info in parser warnings
John W. Eaton <jwe@octave.org>
parents:
8950
diff
changeset
|
3293 "potential Matlab compatibility problem: %s near line %d offile %s", |
fde2a916b2ac
include line and file info in parser warnings
John W. Eaton <jwe@octave.org>
parents:
8950
diff
changeset
|
3294 msg.c_str (), input_line_number, nm.c_str ()); |
4037 | 3295 } |
3296 | |
3297 static void | |
3298 maybe_gripe_matlab_incompatible_comment (char c) | |
3299 { | |
3300 if (c == '#') | |
3301 gripe_matlab_incompatible ("# used as comment character"); | |
3302 } | |
3303 | |
3304 static void | |
3305 gripe_matlab_incompatible_continuation (void) | |
3306 { | |
3307 gripe_matlab_incompatible ("\\ used as line continuation marker"); | |
3308 } | |
3309 | |
3310 static void | |
3311 gripe_matlab_incompatible_operator (const std::string& op) | |
3312 { | |
3313 std::string t = op; | |
3314 int n = t.length (); | |
3315 if (t[n-1] == '\n') | |
3316 t.resize (n-1); | |
3317 gripe_matlab_incompatible (t + " used as operator"); | |
3318 } | |
3319 | |
7722
c3bb0b7a4261
lex.l: allow tokens to be displayed when parsed
John W. Eaton <jwe@octave.org>
parents:
7720
diff
changeset
|
3320 static void |
c3bb0b7a4261
lex.l: allow tokens to be displayed when parsed
John W. Eaton <jwe@octave.org>
parents:
7720
diff
changeset
|
3321 display_token (int tok) |
c3bb0b7a4261
lex.l: allow tokens to be displayed when parsed
John W. Eaton <jwe@octave.org>
parents:
7720
diff
changeset
|
3322 { |
c3bb0b7a4261
lex.l: allow tokens to be displayed when parsed
John W. Eaton <jwe@octave.org>
parents:
7720
diff
changeset
|
3323 switch (tok) |
c3bb0b7a4261
lex.l: allow tokens to be displayed when parsed
John W. Eaton <jwe@octave.org>
parents:
7720
diff
changeset
|
3324 { |
c3bb0b7a4261
lex.l: allow tokens to be displayed when parsed
John W. Eaton <jwe@octave.org>
parents:
7720
diff
changeset
|
3325 case '=': std::cerr << "'='\n"; break; |
c3bb0b7a4261
lex.l: allow tokens to be displayed when parsed
John W. Eaton <jwe@octave.org>
parents:
7720
diff
changeset
|
3326 case ':': std::cerr << "':'\n"; break; |
c3bb0b7a4261
lex.l: allow tokens to be displayed when parsed
John W. Eaton <jwe@octave.org>
parents:
7720
diff
changeset
|
3327 case '-': std::cerr << "'-'\n"; break; |
c3bb0b7a4261
lex.l: allow tokens to be displayed when parsed
John W. Eaton <jwe@octave.org>
parents:
7720
diff
changeset
|
3328 case '+': std::cerr << "'+'\n"; break; |
c3bb0b7a4261
lex.l: allow tokens to be displayed when parsed
John W. Eaton <jwe@octave.org>
parents:
7720
diff
changeset
|
3329 case '*': std::cerr << "'*'\n"; break; |
c3bb0b7a4261
lex.l: allow tokens to be displayed when parsed
John W. Eaton <jwe@octave.org>
parents:
7720
diff
changeset
|
3330 case '/': std::cerr << "'/'\n"; break; |
c3bb0b7a4261
lex.l: allow tokens to be displayed when parsed
John W. Eaton <jwe@octave.org>
parents:
7720
diff
changeset
|
3331 case ADD_EQ: std::cerr << "ADD_EQ\n"; break; |
c3bb0b7a4261
lex.l: allow tokens to be displayed when parsed
John W. Eaton <jwe@octave.org>
parents:
7720
diff
changeset
|
3332 case SUB_EQ: std::cerr << "SUB_EQ\n"; break; |
c3bb0b7a4261
lex.l: allow tokens to be displayed when parsed
John W. Eaton <jwe@octave.org>
parents:
7720
diff
changeset
|
3333 case MUL_EQ: std::cerr << "MUL_EQ\n"; break; |
c3bb0b7a4261
lex.l: allow tokens to be displayed when parsed
John W. Eaton <jwe@octave.org>
parents:
7720
diff
changeset
|
3334 case DIV_EQ: std::cerr << "DIV_EQ\n"; break; |
c3bb0b7a4261
lex.l: allow tokens to be displayed when parsed
John W. Eaton <jwe@octave.org>
parents:
7720
diff
changeset
|
3335 case LEFTDIV_EQ: std::cerr << "LEFTDIV_EQ\n"; break; |
c3bb0b7a4261
lex.l: allow tokens to be displayed when parsed
John W. Eaton <jwe@octave.org>
parents:
7720
diff
changeset
|
3336 case POW_EQ: std::cerr << "POW_EQ\n"; break; |
c3bb0b7a4261
lex.l: allow tokens to be displayed when parsed
John W. Eaton <jwe@octave.org>
parents:
7720
diff
changeset
|
3337 case EMUL_EQ: std::cerr << "EMUL_EQ\n"; break; |
c3bb0b7a4261
lex.l: allow tokens to be displayed when parsed
John W. Eaton <jwe@octave.org>
parents:
7720
diff
changeset
|
3338 case EDIV_EQ: std::cerr << "EDIV_EQ\n"; break; |
c3bb0b7a4261
lex.l: allow tokens to be displayed when parsed
John W. Eaton <jwe@octave.org>
parents:
7720
diff
changeset
|
3339 case ELEFTDIV_EQ: std::cerr << "ELEFTDIV_EQ\n"; break; |
c3bb0b7a4261
lex.l: allow tokens to be displayed when parsed
John W. Eaton <jwe@octave.org>
parents:
7720
diff
changeset
|
3340 case EPOW_EQ: std::cerr << "EPOW_EQ\n"; break; |
c3bb0b7a4261
lex.l: allow tokens to be displayed when parsed
John W. Eaton <jwe@octave.org>
parents:
7720
diff
changeset
|
3341 case AND_EQ: std::cerr << "AND_EQ\n"; break; |
c3bb0b7a4261
lex.l: allow tokens to be displayed when parsed
John W. Eaton <jwe@octave.org>
parents:
7720
diff
changeset
|
3342 case OR_EQ: std::cerr << "OR_EQ\n"; break; |
c3bb0b7a4261
lex.l: allow tokens to be displayed when parsed
John W. Eaton <jwe@octave.org>
parents:
7720
diff
changeset
|
3343 case LSHIFT_EQ: std::cerr << "LSHIFT_EQ\n"; break; |
c3bb0b7a4261
lex.l: allow tokens to be displayed when parsed
John W. Eaton <jwe@octave.org>
parents:
7720
diff
changeset
|
3344 case RSHIFT_EQ: std::cerr << "RSHIFT_EQ\n"; break; |
c3bb0b7a4261
lex.l: allow tokens to be displayed when parsed
John W. Eaton <jwe@octave.org>
parents:
7720
diff
changeset
|
3345 case LSHIFT: std::cerr << "LSHIFT\n"; break; |
c3bb0b7a4261
lex.l: allow tokens to be displayed when parsed
John W. Eaton <jwe@octave.org>
parents:
7720
diff
changeset
|
3346 case RSHIFT: std::cerr << "RSHIFT\n"; break; |
c3bb0b7a4261
lex.l: allow tokens to be displayed when parsed
John W. Eaton <jwe@octave.org>
parents:
7720
diff
changeset
|
3347 case EXPR_AND_AND: std::cerr << "EXPR_AND_AND\n"; break; |
c3bb0b7a4261
lex.l: allow tokens to be displayed when parsed
John W. Eaton <jwe@octave.org>
parents:
7720
diff
changeset
|
3348 case EXPR_OR_OR: std::cerr << "EXPR_OR_OR\n"; break; |
c3bb0b7a4261
lex.l: allow tokens to be displayed when parsed
John W. Eaton <jwe@octave.org>
parents:
7720
diff
changeset
|
3349 case EXPR_AND: std::cerr << "EXPR_AND\n"; break; |
c3bb0b7a4261
lex.l: allow tokens to be displayed when parsed
John W. Eaton <jwe@octave.org>
parents:
7720
diff
changeset
|
3350 case EXPR_OR: std::cerr << "EXPR_OR\n"; break; |
c3bb0b7a4261
lex.l: allow tokens to be displayed when parsed
John W. Eaton <jwe@octave.org>
parents:
7720
diff
changeset
|
3351 case EXPR_NOT: std::cerr << "EXPR_NOT\n"; break; |
c3bb0b7a4261
lex.l: allow tokens to be displayed when parsed
John W. Eaton <jwe@octave.org>
parents:
7720
diff
changeset
|
3352 case EXPR_LT: std::cerr << "EXPR_LT\n"; break; |
c3bb0b7a4261
lex.l: allow tokens to be displayed when parsed
John W. Eaton <jwe@octave.org>
parents:
7720
diff
changeset
|
3353 case EXPR_LE: std::cerr << "EXPR_LE\n"; break; |
c3bb0b7a4261
lex.l: allow tokens to be displayed when parsed
John W. Eaton <jwe@octave.org>
parents:
7720
diff
changeset
|
3354 case EXPR_EQ: std::cerr << "EXPR_EQ\n"; break; |
c3bb0b7a4261
lex.l: allow tokens to be displayed when parsed
John W. Eaton <jwe@octave.org>
parents:
7720
diff
changeset
|
3355 case EXPR_NE: std::cerr << "EXPR_NE\n"; break; |
c3bb0b7a4261
lex.l: allow tokens to be displayed when parsed
John W. Eaton <jwe@octave.org>
parents:
7720
diff
changeset
|
3356 case EXPR_GE: std::cerr << "EXPR_GE\n"; break; |
c3bb0b7a4261
lex.l: allow tokens to be displayed when parsed
John W. Eaton <jwe@octave.org>
parents:
7720
diff
changeset
|
3357 case EXPR_GT: std::cerr << "EXPR_GT\n"; break; |
c3bb0b7a4261
lex.l: allow tokens to be displayed when parsed
John W. Eaton <jwe@octave.org>
parents:
7720
diff
changeset
|
3358 case LEFTDIV: std::cerr << "LEFTDIV\n"; break; |
c3bb0b7a4261
lex.l: allow tokens to be displayed when parsed
John W. Eaton <jwe@octave.org>
parents:
7720
diff
changeset
|
3359 case EMUL: std::cerr << "EMUL\n"; break; |
c3bb0b7a4261
lex.l: allow tokens to be displayed when parsed
John W. Eaton <jwe@octave.org>
parents:
7720
diff
changeset
|
3360 case EDIV: std::cerr << "EDIV\n"; break; |
c3bb0b7a4261
lex.l: allow tokens to be displayed when parsed
John W. Eaton <jwe@octave.org>
parents:
7720
diff
changeset
|
3361 case ELEFTDIV: std::cerr << "ELEFTDIV\n"; break; |
c3bb0b7a4261
lex.l: allow tokens to be displayed when parsed
John W. Eaton <jwe@octave.org>
parents:
7720
diff
changeset
|
3362 case EPLUS: std::cerr << "EPLUS\n"; break; |
c3bb0b7a4261
lex.l: allow tokens to be displayed when parsed
John W. Eaton <jwe@octave.org>
parents:
7720
diff
changeset
|
3363 case EMINUS: std::cerr << "EMINUS\n"; break; |
c3bb0b7a4261
lex.l: allow tokens to be displayed when parsed
John W. Eaton <jwe@octave.org>
parents:
7720
diff
changeset
|
3364 case QUOTE: std::cerr << "QUOTE\n"; break; |
c3bb0b7a4261
lex.l: allow tokens to be displayed when parsed
John W. Eaton <jwe@octave.org>
parents:
7720
diff
changeset
|
3365 case TRANSPOSE: std::cerr << "TRANSPOSE\n"; break; |
c3bb0b7a4261
lex.l: allow tokens to be displayed when parsed
John W. Eaton <jwe@octave.org>
parents:
7720
diff
changeset
|
3366 case PLUS_PLUS: std::cerr << "PLUS_PLUS\n"; break; |
c3bb0b7a4261
lex.l: allow tokens to be displayed when parsed
John W. Eaton <jwe@octave.org>
parents:
7720
diff
changeset
|
3367 case MINUS_MINUS: std::cerr << "MINUS_MINUS\n"; break; |
c3bb0b7a4261
lex.l: allow tokens to be displayed when parsed
John W. Eaton <jwe@octave.org>
parents:
7720
diff
changeset
|
3368 case POW: std::cerr << "POW\n"; break; |
c3bb0b7a4261
lex.l: allow tokens to be displayed when parsed
John W. Eaton <jwe@octave.org>
parents:
7720
diff
changeset
|
3369 case EPOW: std::cerr << "EPOW\n"; break; |
c3bb0b7a4261
lex.l: allow tokens to be displayed when parsed
John W. Eaton <jwe@octave.org>
parents:
7720
diff
changeset
|
3370 case NUM: std::cerr << "NUM\n"; break; |
c3bb0b7a4261
lex.l: allow tokens to be displayed when parsed
John W. Eaton <jwe@octave.org>
parents:
7720
diff
changeset
|
3371 case IMAG_NUM: std::cerr << "IMAG_NUM\n"; break; |
c3bb0b7a4261
lex.l: allow tokens to be displayed when parsed
John W. Eaton <jwe@octave.org>
parents:
7720
diff
changeset
|
3372 case STRUCT_ELT: std::cerr << "STRUCT_ELT\n"; break; |
c3bb0b7a4261
lex.l: allow tokens to be displayed when parsed
John W. Eaton <jwe@octave.org>
parents:
7720
diff
changeset
|
3373 case NAME: std::cerr << "NAME\n"; break; |
c3bb0b7a4261
lex.l: allow tokens to be displayed when parsed
John W. Eaton <jwe@octave.org>
parents:
7720
diff
changeset
|
3374 case END: std::cerr << "END\n"; break; |
c3bb0b7a4261
lex.l: allow tokens to be displayed when parsed
John W. Eaton <jwe@octave.org>
parents:
7720
diff
changeset
|
3375 case DQ_STRING: std::cerr << "DQ_STRING\n"; break; |
c3bb0b7a4261
lex.l: allow tokens to be displayed when parsed
John W. Eaton <jwe@octave.org>
parents:
7720
diff
changeset
|
3376 case SQ_STRING: std::cerr << "SQ_STRING\n"; break; |
c3bb0b7a4261
lex.l: allow tokens to be displayed when parsed
John W. Eaton <jwe@octave.org>
parents:
7720
diff
changeset
|
3377 case FOR: std::cerr << "FOR\n"; break; |
c3bb0b7a4261
lex.l: allow tokens to be displayed when parsed
John W. Eaton <jwe@octave.org>
parents:
7720
diff
changeset
|
3378 case WHILE: std::cerr << "WHILE\n"; break; |
c3bb0b7a4261
lex.l: allow tokens to be displayed when parsed
John W. Eaton <jwe@octave.org>
parents:
7720
diff
changeset
|
3379 case DO: std::cerr << "DO\n"; break; |
c3bb0b7a4261
lex.l: allow tokens to be displayed when parsed
John W. Eaton <jwe@octave.org>
parents:
7720
diff
changeset
|
3380 case UNTIL: std::cerr << "UNTIL\n"; break; |
c3bb0b7a4261
lex.l: allow tokens to be displayed when parsed
John W. Eaton <jwe@octave.org>
parents:
7720
diff
changeset
|
3381 case IF: std::cerr << "IF\n"; break; |
c3bb0b7a4261
lex.l: allow tokens to be displayed when parsed
John W. Eaton <jwe@octave.org>
parents:
7720
diff
changeset
|
3382 case ELSEIF: std::cerr << "ELSEIF\n"; break; |
c3bb0b7a4261
lex.l: allow tokens to be displayed when parsed
John W. Eaton <jwe@octave.org>
parents:
7720
diff
changeset
|
3383 case ELSE: std::cerr << "ELSE\n"; break; |
c3bb0b7a4261
lex.l: allow tokens to be displayed when parsed
John W. Eaton <jwe@octave.org>
parents:
7720
diff
changeset
|
3384 case SWITCH: std::cerr << "SWITCH\n"; break; |
c3bb0b7a4261
lex.l: allow tokens to be displayed when parsed
John W. Eaton <jwe@octave.org>
parents:
7720
diff
changeset
|
3385 case CASE: std::cerr << "CASE\n"; break; |
c3bb0b7a4261
lex.l: allow tokens to be displayed when parsed
John W. Eaton <jwe@octave.org>
parents:
7720
diff
changeset
|
3386 case OTHERWISE: std::cerr << "OTHERWISE\n"; break; |
c3bb0b7a4261
lex.l: allow tokens to be displayed when parsed
John W. Eaton <jwe@octave.org>
parents:
7720
diff
changeset
|
3387 case BREAK: std::cerr << "BREAK\n"; break; |
c3bb0b7a4261
lex.l: allow tokens to be displayed when parsed
John W. Eaton <jwe@octave.org>
parents:
7720
diff
changeset
|
3388 case CONTINUE: std::cerr << "CONTINUE\n"; break; |
c3bb0b7a4261
lex.l: allow tokens to be displayed when parsed
John W. Eaton <jwe@octave.org>
parents:
7720
diff
changeset
|
3389 case FUNC_RET: std::cerr << "FUNC_RET\n"; break; |
c3bb0b7a4261
lex.l: allow tokens to be displayed when parsed
John W. Eaton <jwe@octave.org>
parents:
7720
diff
changeset
|
3390 case UNWIND: std::cerr << "UNWIND\n"; break; |
c3bb0b7a4261
lex.l: allow tokens to be displayed when parsed
John W. Eaton <jwe@octave.org>
parents:
7720
diff
changeset
|
3391 case CLEANUP: std::cerr << "CLEANUP\n"; break; |
c3bb0b7a4261
lex.l: allow tokens to be displayed when parsed
John W. Eaton <jwe@octave.org>
parents:
7720
diff
changeset
|
3392 case TRY: std::cerr << "TRY\n"; break; |
c3bb0b7a4261
lex.l: allow tokens to be displayed when parsed
John W. Eaton <jwe@octave.org>
parents:
7720
diff
changeset
|
3393 case CATCH: std::cerr << "CATCH\n"; break; |
c3bb0b7a4261
lex.l: allow tokens to be displayed when parsed
John W. Eaton <jwe@octave.org>
parents:
7720
diff
changeset
|
3394 case GLOBAL: std::cerr << "GLOBAL\n"; break; |
c3bb0b7a4261
lex.l: allow tokens to be displayed when parsed
John W. Eaton <jwe@octave.org>
parents:
7720
diff
changeset
|
3395 case STATIC: std::cerr << "STATIC\n"; break; |
c3bb0b7a4261
lex.l: allow tokens to be displayed when parsed
John W. Eaton <jwe@octave.org>
parents:
7720
diff
changeset
|
3396 case FCN_HANDLE: std::cerr << "FCN_HANDLE\n"; break; |
c3bb0b7a4261
lex.l: allow tokens to be displayed when parsed
John W. Eaton <jwe@octave.org>
parents:
7720
diff
changeset
|
3397 case END_OF_INPUT: std::cerr << "END_OF_INPUT\n\n"; break; |
c3bb0b7a4261
lex.l: allow tokens to be displayed when parsed
John W. Eaton <jwe@octave.org>
parents:
7720
diff
changeset
|
3398 case LEXICAL_ERROR: std::cerr << "LEXICAL_ERROR\n\n"; break; |
c3bb0b7a4261
lex.l: allow tokens to be displayed when parsed
John W. Eaton <jwe@octave.org>
parents:
7720
diff
changeset
|
3399 case FCN: std::cerr << "FCN\n"; break; |
c3bb0b7a4261
lex.l: allow tokens to be displayed when parsed
John W. Eaton <jwe@octave.org>
parents:
7720
diff
changeset
|
3400 case CLOSE_BRACE: std::cerr << "CLOSE_BRACE\n"; break; |
9474
25ed2d6aacf6
Parse nested functions more accurately.
David Grundberg <individ@acc.umu.se>
parents:
9324
diff
changeset
|
3401 case SCRIPT_FILE: std::cerr << "SCRIPT_FILE\n"; break; |
25ed2d6aacf6
Parse nested functions more accurately.
David Grundberg <individ@acc.umu.se>
parents:
9324
diff
changeset
|
3402 case FUNCTION_FILE: std::cerr << "FUNCTION_FILE\n"; break; |
7722
c3bb0b7a4261
lex.l: allow tokens to be displayed when parsed
John W. Eaton <jwe@octave.org>
parents:
7720
diff
changeset
|
3403 case '\n': std::cerr << "\\n\n"; break; |
c3bb0b7a4261
lex.l: allow tokens to be displayed when parsed
John W. Eaton <jwe@octave.org>
parents:
7720
diff
changeset
|
3404 case '\r': std::cerr << "\\r\n"; break; |
c3bb0b7a4261
lex.l: allow tokens to be displayed when parsed
John W. Eaton <jwe@octave.org>
parents:
7720
diff
changeset
|
3405 case '\t': std::cerr << "TAB\n"; break; |
c3bb0b7a4261
lex.l: allow tokens to be displayed when parsed
John W. Eaton <jwe@octave.org>
parents:
7720
diff
changeset
|
3406 default: |
c3bb0b7a4261
lex.l: allow tokens to be displayed when parsed
John W. Eaton <jwe@octave.org>
parents:
7720
diff
changeset
|
3407 { |
c3bb0b7a4261
lex.l: allow tokens to be displayed when parsed
John W. Eaton <jwe@octave.org>
parents:
7720
diff
changeset
|
3408 if (tok < 256) |
c3bb0b7a4261
lex.l: allow tokens to be displayed when parsed
John W. Eaton <jwe@octave.org>
parents:
7720
diff
changeset
|
3409 std::cerr << static_cast<char> (tok) << "\n"; |
c3bb0b7a4261
lex.l: allow tokens to be displayed when parsed
John W. Eaton <jwe@octave.org>
parents:
7720
diff
changeset
|
3410 else |
c3bb0b7a4261
lex.l: allow tokens to be displayed when parsed
John W. Eaton <jwe@octave.org>
parents:
7720
diff
changeset
|
3411 std::cerr << "UNKNOWN(" << tok << ")\n"; |
c3bb0b7a4261
lex.l: allow tokens to be displayed when parsed
John W. Eaton <jwe@octave.org>
parents:
7720
diff
changeset
|
3412 } |
c3bb0b7a4261
lex.l: allow tokens to be displayed when parsed
John W. Eaton <jwe@octave.org>
parents:
7720
diff
changeset
|
3413 break; |
c3bb0b7a4261
lex.l: allow tokens to be displayed when parsed
John W. Eaton <jwe@octave.org>
parents:
7720
diff
changeset
|
3414 } |
c3bb0b7a4261
lex.l: allow tokens to be displayed when parsed
John W. Eaton <jwe@octave.org>
parents:
7720
diff
changeset
|
3415 } |
c3bb0b7a4261
lex.l: allow tokens to be displayed when parsed
John W. Eaton <jwe@octave.org>
parents:
7720
diff
changeset
|
3416 |
8535 | 3417 static void |
3418 display_state (void) | |
3419 { | |
3420 std::cerr << "S: "; | |
3421 | |
3422 switch (YY_START) | |
3423 { | |
3424 case INITIAL: | |
3425 std::cerr << "INITIAL" << std::endl; | |
3426 break; | |
3427 | |
3428 case COMMAND_START: | |
3429 std::cerr << "COMMAND_START" << std::endl; | |
3430 break; | |
3431 | |
3432 case MATRIX_START: | |
3433 std::cerr << "MATRIX_START" << std::endl; | |
3434 break; | |
3435 | |
3436 case SCRIPT_FILE_BEGIN: | |
3437 std::cerr << "SCRIPT_FILE_BEGIN" << std::endl; | |
3438 break; | |
3439 | |
9474
25ed2d6aacf6
Parse nested functions more accurately.
David Grundberg <individ@acc.umu.se>
parents:
9324
diff
changeset
|
3440 case FUNCTION_FILE_BEGIN: |
25ed2d6aacf6
Parse nested functions more accurately.
David Grundberg <individ@acc.umu.se>
parents:
9324
diff
changeset
|
3441 std::cerr << "FUNCTION_FILE_BEGIN" << std::endl; |
8535 | 3442 break; |
3443 | |
3444 default: | |
3445 std::cerr << "UNKNOWN START STATE!" << std::endl; | |
3446 break; | |
3447 } | |
3448 } | |
3449 | |
3450 static void | |
3451 lexer_debug (const char *pattern, const char *text) | |
3452 { | |
3453 std::cerr << std::endl; | |
3454 | |
3455 display_state (); | |
3456 | |
3457 std::cerr << "P: " << pattern << std::endl; | |
3458 std::cerr << "T: " << text << std::endl; | |
3459 } | |
3460 | |
7722
c3bb0b7a4261
lex.l: allow tokens to be displayed when parsed
John W. Eaton <jwe@octave.org>
parents:
7720
diff
changeset
|
3461 DEFUN (__display_tokens__, args, nargout, |
c3bb0b7a4261
lex.l: allow tokens to be displayed when parsed
John W. Eaton <jwe@octave.org>
parents:
7720
diff
changeset
|
3462 "-*- texinfo -*-\n\ |
8812
7d48766c21a5
use consistent format for doc strings of internal functions
John W. Eaton <jwe@octave.org>
parents:
8767
diff
changeset
|
3463 @deftypefn {Built-in Function} {} __display_tokens__ ()\n\ |
7722
c3bb0b7a4261
lex.l: allow tokens to be displayed when parsed
John W. Eaton <jwe@octave.org>
parents:
7720
diff
changeset
|
3464 Query or set the internal variable that determines whether Octave's\n\ |
c3bb0b7a4261
lex.l: allow tokens to be displayed when parsed
John W. Eaton <jwe@octave.org>
parents:
7720
diff
changeset
|
3465 lexer displays tokens as they are read.\n\ |
c3bb0b7a4261
lex.l: allow tokens to be displayed when parsed
John W. Eaton <jwe@octave.org>
parents:
7720
diff
changeset
|
3466 @end deftypefn") |
c3bb0b7a4261
lex.l: allow tokens to be displayed when parsed
John W. Eaton <jwe@octave.org>
parents:
7720
diff
changeset
|
3467 { |
c3bb0b7a4261
lex.l: allow tokens to be displayed when parsed
John W. Eaton <jwe@octave.org>
parents:
7720
diff
changeset
|
3468 return SET_INTERNAL_VARIABLE (display_tokens); |
c3bb0b7a4261
lex.l: allow tokens to be displayed when parsed
John W. Eaton <jwe@octave.org>
parents:
7720
diff
changeset
|
3469 } |
c3bb0b7a4261
lex.l: allow tokens to be displayed when parsed
John W. Eaton <jwe@octave.org>
parents:
7720
diff
changeset
|
3470 |
4910 | 3471 DEFUN (__token_count__, , , |
3472 "-*- texinfo -*-\n\ | |
8812
7d48766c21a5
use consistent format for doc strings of internal functions
John W. Eaton <jwe@octave.org>
parents:
8767
diff
changeset
|
3473 @deftypefn {Built-in Function} {} __token_count__ ()\n\ |
4910 | 3474 Number of language tokens processed since Octave startup.\n\ |
3475 @end deftypefn") | |
3476 { | |
3477 return octave_value (Vtoken_count); | |
3478 } | |
3479 | |
8535 | 3480 DEFUN (__lexer_debug_flag__, args, nargout, |
8812
7d48766c21a5
use consistent format for doc strings of internal functions
John W. Eaton <jwe@octave.org>
parents:
8767
diff
changeset
|
3481 "-*- texinfo -*-\n\ |
7d48766c21a5
use consistent format for doc strings of internal functions
John W. Eaton <jwe@octave.org>
parents:
8767
diff
changeset
|
3482 @deftypefn {Built-in Function} {@var{old_val} =} __lexer_debug_flag__ (@var{new_val}))\n\ |
7d48766c21a5
use consistent format for doc strings of internal functions
John W. Eaton <jwe@octave.org>
parents:
8767
diff
changeset
|
3483 Undocumented internal function.\n\ |
7d48766c21a5
use consistent format for doc strings of internal functions
John W. Eaton <jwe@octave.org>
parents:
8767
diff
changeset
|
3484 @end deftypefn") |
8535 | 3485 { |
3486 octave_value retval; | |
3487 | |
3488 retval = set_internal_variable (lexer_debug_flag, args, nargout, | |
3489 "__lexer_debug_flag__"); | |
3490 | |
3491 return retval; | |
3492 } | |
3493 | |
1994 | 3494 /* |
3495 ;;; Local Variables: *** | |
3496 ;;; mode: C++ *** | |
3497 ;;; End: *** | |
3498 */ |