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