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