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