Mercurial > octave
annotate src/lex.l @ 8536:de1b944d5306
lex.l: finish previous change
author | John W. Eaton <jwe@octave.org> |
---|---|
date | Mon, 19 Jan 2009 19:37:34 -0500 |
parents | 75e6ab186761 |
children | 17ef48c699a5 |
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; |
1670 } | |
1019 | 1671 } |
1672 else | |
1673 { | |
1674 switch (c) | |
991 | 1675 { |
7720
4e2eafef689c
unify comment and help text processing in lex.l and parse.y
John W. Eaton <jwe@octave.org>
parents:
7715
diff
changeset
|
1676 case ' ': |
4e2eafef689c
unify comment and help text processing in lex.l and parse.y
John W. Eaton <jwe@octave.org>
parents:
7715
diff
changeset
|
1677 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
|
1678 break; |
4e2eafef689c
unify comment and help text processing in lex.l and parse.y
John W. Eaton <jwe@octave.org>
parents:
7715
diff
changeset
|
1679 |
4037 | 1680 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
|
1681 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
|
1682 { |
4e2eafef689c
unify comment and help text processing in lex.l and parse.y
John W. Eaton <jwe@octave.org>
parents:
7715
diff
changeset
|
1683 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
|
1684 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
|
1685 } |
4e2eafef689c
unify comment and help text processing in lex.l and parse.y
John W. Eaton <jwe@octave.org>
parents:
7715
diff
changeset
|
1686 // 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
|
1687 |
1019 | 1688 case '%': |
2300 | 1689 in_comment = true; |
1690 begin_comment = true; | |
1019 | 1691 break; |
777 | 1692 |
1019 | 1693 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
|
1694 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
|
1695 reader.ungetc (c); |
1019 | 1696 goto done; |
1 | 1697 } |
1698 } | |
1019 | 1699 } |
991 | 1700 |
1019 | 1701 done: |
991 | 1702 |
7715
5b4d278ec828
parse scripts completely before executing
John W. Eaton <jwe@octave.org>
parents:
7634
diff
changeset
|
1703 if (c == EOF) |
5b4d278ec828
parse scripts completely before executing
John W. Eaton <jwe@octave.org>
parents:
7634
diff
changeset
|
1704 eof = true; |
5b4d278ec828
parse scripts completely before executing
John W. Eaton <jwe@octave.org>
parents:
7634
diff
changeset
|
1705 |
4426 | 1706 return buf; |
1 | 1707 } |
1708 | |
7720
4e2eafef689c
unify comment and help text processing in lex.l and parse.y
John W. Eaton <jwe@octave.org>
parents:
7715
diff
changeset
|
1709 class |
4e2eafef689c
unify comment and help text processing in lex.l and parse.y
John W. Eaton <jwe@octave.org>
parents:
7715
diff
changeset
|
1710 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
|
1711 { |
4e2eafef689c
unify comment and help text processing in lex.l and parse.y
John W. Eaton <jwe@octave.org>
parents:
7715
diff
changeset
|
1712 public: |
4e2eafef689c
unify comment and help text processing in lex.l and parse.y
John W. Eaton <jwe@octave.org>
parents:
7715
diff
changeset
|
1713 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
|
1714 |
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
|
1715 int getc (void) { return ::text_yyinput (); } |
8447
adab48231a03
make input_line_number work again
John W. Eaton <jwe@octave.org>
parents:
8312
diff
changeset
|
1716 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
|
1717 |
4e2eafef689c
unify comment and help text processing in lex.l and parse.y
John W. Eaton <jwe@octave.org>
parents:
7715
diff
changeset
|
1718 private: |
4e2eafef689c
unify comment and help text processing in lex.l and parse.y
John W. Eaton <jwe@octave.org>
parents:
7715
diff
changeset
|
1719 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
|
1720 }; |
4e2eafef689c
unify comment and help text processing in lex.l and parse.y
John W. Eaton <jwe@octave.org>
parents:
7715
diff
changeset
|
1721 |
7715
5b4d278ec828
parse scripts completely before executing
John W. Eaton <jwe@octave.org>
parents:
7634
diff
changeset
|
1722 static int |
7723
74f5e0c7de9e
first pass at handling block comments
John W. Eaton <jwe@octave.org>
parents:
7722
diff
changeset
|
1723 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
|
1724 { |
5b4d278ec828
parse scripts completely before executing
John W. Eaton <jwe@octave.org>
parents:
7634
diff
changeset
|
1725 eof = false; |
5b4d278ec828
parse scripts completely before executing
John W. Eaton <jwe@octave.org>
parents:
7634
diff
changeset
|
1726 |
5b4d278ec828
parse scripts completely before executing
John W. Eaton <jwe@octave.org>
parents:
7634
diff
changeset
|
1727 std::string help_txt; |
5b4d278ec828
parse scripts completely before executing
John W. Eaton <jwe@octave.org>
parents:
7634
diff
changeset
|
1728 |
5b4d278ec828
parse scripts completely before executing
John W. Eaton <jwe@octave.org>
parents:
7634
diff
changeset
|
1729 if (! help_buf.empty ()) |
5b4d278ec828
parse scripts completely before executing
John W. Eaton <jwe@octave.org>
parents:
7634
diff
changeset
|
1730 help_txt = help_buf.top (); |
5b4d278ec828
parse scripts completely before executing
John W. Eaton <jwe@octave.org>
parents:
7634
diff
changeset
|
1731 |
7720
4e2eafef689c
unify comment and help text processing in lex.l and parse.y
John W. Eaton <jwe@octave.org>
parents:
7715
diff
changeset
|
1732 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
|
1733 |
7723
74f5e0c7de9e
first pass at handling block comments
John W. Eaton <jwe@octave.org>
parents:
7722
diff
changeset
|
1734 // 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
|
1735 // initially looking at a block comment. |
74f5e0c7de9e
first pass at handling block comments
John W. Eaton <jwe@octave.org>
parents:
7722
diff
changeset
|
1736 |
74f5e0c7de9e
first pass at handling block comments
John W. Eaton <jwe@octave.org>
parents:
7722
diff
changeset
|
1737 std::string txt = start_in_block |
74f5e0c7de9e
first pass at handling block comments
John W. Eaton <jwe@octave.org>
parents:
7722
diff
changeset
|
1738 ? grab_block_comment (flex_reader, eof) |
74f5e0c7de9e
first pass at handling block comments
John W. Eaton <jwe@octave.org>
parents:
7722
diff
changeset
|
1739 : 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
|
1740 |
8535 | 1741 if (lexer_debug_flag) |
8536
de1b944d5306
lex.l: finish previous change
John W. Eaton <jwe@octave.org>
parents:
8535
diff
changeset
|
1742 std::cerr << "C: " << txt << std::endl; |
8535 | 1743 |
7715
5b4d278ec828
parse scripts completely before executing
John W. Eaton <jwe@octave.org>
parents:
7634
diff
changeset
|
1744 if (help_txt.empty () && nesting_level.none ()) |
5b4d278ec828
parse scripts completely before executing
John W. Eaton <jwe@octave.org>
parents:
7634
diff
changeset
|
1745 { |
5b4d278ec828
parse scripts completely before executing
John W. Eaton <jwe@octave.org>
parents:
7634
diff
changeset
|
1746 if (! help_buf.empty ()) |
5b4d278ec828
parse scripts completely before executing
John W. Eaton <jwe@octave.org>
parents:
7634
diff
changeset
|
1747 help_buf.pop (); |
5b4d278ec828
parse scripts completely before executing
John W. Eaton <jwe@octave.org>
parents:
7634
diff
changeset
|
1748 |
5b4d278ec828
parse scripts completely before executing
John W. Eaton <jwe@octave.org>
parents:
7634
diff
changeset
|
1749 help_buf.push (txt); |
5b4d278ec828
parse scripts completely before executing
John W. Eaton <jwe@octave.org>
parents:
7634
diff
changeset
|
1750 } |
7720
4e2eafef689c
unify comment and help text processing in lex.l and parse.y
John W. Eaton <jwe@octave.org>
parents:
7715
diff
changeset
|
1751 |
4e2eafef689c
unify comment and help text processing in lex.l and parse.y
John W. Eaton <jwe@octave.org>
parents:
7715
diff
changeset
|
1752 octave_comment_buffer::append (txt); |
7715
5b4d278ec828
parse scripts completely before executing
John W. Eaton <jwe@octave.org>
parents:
7634
diff
changeset
|
1753 |
5b4d278ec828
parse scripts completely before executing
John W. Eaton <jwe@octave.org>
parents:
7634
diff
changeset
|
1754 current_input_column = 1; |
5b4d278ec828
parse scripts completely before executing
John W. Eaton <jwe@octave.org>
parents:
7634
diff
changeset
|
1755 lexer_flags.quote_is_transpose = false; |
5b4d278ec828
parse scripts completely before executing
John W. Eaton <jwe@octave.org>
parents:
7634
diff
changeset
|
1756 lexer_flags.convert_spaces_to_comma = true; |
5b4d278ec828
parse scripts completely before executing
John W. Eaton <jwe@octave.org>
parents:
7634
diff
changeset
|
1757 |
5b4d278ec828
parse scripts completely before executing
John W. Eaton <jwe@octave.org>
parents:
7634
diff
changeset
|
1758 if (YY_START == COMMAND_START) |
5b4d278ec828
parse scripts completely before executing
John W. Eaton <jwe@octave.org>
parents:
7634
diff
changeset
|
1759 BEGIN (INITIAL); |
5b4d278ec828
parse scripts completely before executing
John W. Eaton <jwe@octave.org>
parents:
7634
diff
changeset
|
1760 |
5b4d278ec828
parse scripts completely before executing
John W. Eaton <jwe@octave.org>
parents:
7634
diff
changeset
|
1761 if (nesting_level.none ()) |
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 lexer_flags.doing_rawcommand = false; |
5b4d278ec828
parse scripts completely before executing
John W. Eaton <jwe@octave.org>
parents:
7634
diff
changeset
|
1764 return '\n'; |
5b4d278ec828
parse scripts completely before executing
John W. Eaton <jwe@octave.org>
parents:
7634
diff
changeset
|
1765 } |
5b4d278ec828
parse scripts completely before executing
John W. Eaton <jwe@octave.org>
parents:
7634
diff
changeset
|
1766 else if (nesting_level.is_bracket_or_brace ()) |
5b4d278ec828
parse scripts completely before executing
John W. Eaton <jwe@octave.org>
parents:
7634
diff
changeset
|
1767 return ';'; |
5b4d278ec828
parse scripts completely before executing
John W. Eaton <jwe@octave.org>
parents:
7634
diff
changeset
|
1768 else |
5b4d278ec828
parse scripts completely before executing
John W. Eaton <jwe@octave.org>
parents:
7634
diff
changeset
|
1769 return 0; |
5b4d278ec828
parse scripts completely before executing
John W. Eaton <jwe@octave.org>
parents:
7634
diff
changeset
|
1770 } |
5b4d278ec828
parse scripts completely before executing
John W. Eaton <jwe@octave.org>
parents:
7634
diff
changeset
|
1771 |
767 | 1772 // Return 1 if the given character matches any character in the given |
1773 // string. | |
1774 | |
2857 | 1775 static bool |
2804 | 1776 match_any (char c, const char *s) |
1 | 1777 { |
1778 char tmp; | |
1779 while ((tmp = *s++) != '\0') | |
1780 { | |
1781 if (c == tmp) | |
2857 | 1782 return true; |
1 | 1783 } |
2857 | 1784 return false; |
1 | 1785 } |
1786 | |
767 | 1787 // Given information about the spacing surrounding an operator, |
1788 // return 1 if it looks like it should be treated as a binary | |
1789 // operator. For example, | |
1790 // | |
3774 | 1791 // [ 1 + 2 ] or [ 1+ 2] or [ 1+2 ] ==> binary |
1792 // | |
1793 // [ 1 +2 ] ==> unary | |
767 | 1794 |
2857 | 1795 static bool |
3246 | 1796 looks_like_bin_op (bool spc_prev, int next_char) |
1 | 1797 { |
3246 | 1798 bool spc_next = (next_char == ' ' || next_char == '\t'); |
1799 | |
608 | 1800 return ((spc_prev && spc_next) || ! spc_prev); |
1 | 1801 } |
1802 | |
3263 | 1803 // Recognize separators. If the separator is a CRLF pair, it is |
1804 // replaced by a single LF. | |
1805 | |
1806 static bool | |
1807 next_token_is_sep_op (void) | |
1808 { | |
1809 bool retval = false; | |
1810 | |
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
|
1811 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
|
1812 |
13820b9f5fd9
more consistent handling of CR/CRLF/LF line endings in lexer and parser
John W. Eaton <jwe@octave.org>
parents:
7723
diff
changeset
|
1813 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
|
1814 |
8447
adab48231a03
make input_line_number work again
John W. Eaton <jwe@octave.org>
parents:
8312
diff
changeset
|
1815 xunput (c, yytext); |
3263 | 1816 |
1817 return retval; | |
1818 } | |
1819 | |
767 | 1820 // Try to determine if the next token should be treated as a postfix |
1821 // unary operator. This is ugly, but it seems to do the right thing. | |
1822 | |
2857 | 1823 static bool |
3246 | 1824 next_token_is_postfix_unary_op (bool spc_prev) |
1 | 1825 { |
2857 | 1826 bool un_op = false; |
1 | 1827 |
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
|
1828 int c0 = text_yyinput (); |
1 | 1829 |
3246 | 1830 if (c0 == '\'' && ! spc_prev) |
1831 { | |
1832 un_op = true; | |
1833 } | |
1834 else if (c0 == '.') | |
1835 { | |
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
|
1836 int c1 = text_yyinput (); |
3246 | 1837 un_op = (c1 == '\''); |
8447
adab48231a03
make input_line_number work again
John W. Eaton <jwe@octave.org>
parents:
8312
diff
changeset
|
1838 xunput (c1, yytext); |
3246 | 1839 } |
4613 | 1840 else if (c0 == '+') |
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 c1 = text_yyinput (); |
4613 | 1843 un_op = (c1 == '+'); |
8447
adab48231a03
make input_line_number work again
John W. Eaton <jwe@octave.org>
parents:
8312
diff
changeset
|
1844 xunput (c1, yytext); |
4613 | 1845 } |
1846 else if (c0 == '-') | |
1847 { | |
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
|
1848 int c1 = text_yyinput (); |
4613 | 1849 un_op = (c1 == '-'); |
8447
adab48231a03
make input_line_number work again
John W. Eaton <jwe@octave.org>
parents:
8312
diff
changeset
|
1850 xunput (c1, yytext); |
4613 | 1851 } |
1 | 1852 |
8447
adab48231a03
make input_line_number work again
John W. Eaton <jwe@octave.org>
parents:
8312
diff
changeset
|
1853 xunput (c0, yytext); |
1 | 1854 |
1855 return un_op; | |
1856 } | |
1857 | |
767 | 1858 // Try to determine if the next token should be treated as a binary |
3246 | 1859 // operator. |
1521 | 1860 // |
3246 | 1861 // This kluge exists because whitespace is not always ignored inside |
3774 | 1862 // the square brackets that are used to create matrix objects (though |
1863 // spacing only really matters in the cases that can be interpreted | |
1864 // either as binary ops or prefix unary ops: currently just +, -). | |
1865 // | |
3779 | 1866 // Note that a line continuation directly following a + or - operator |
1867 // (e.g., the characters '[' 'a' ' ' '+' '\' LFD 'b' ']') will be | |
1868 // parsed as a binary operator. | |
767 | 1869 |
2857 | 1870 static bool |
3246 | 1871 next_token_is_bin_op (bool spc_prev) |
1 | 1872 { |
2857 | 1873 bool bin_op = false; |
1 | 1874 |
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
|
1875 int c0 = text_yyinput (); |
1 | 1876 |
1877 switch (c0) | |
1878 { | |
777 | 1879 case '+': |
1880 case '-': | |
3774 | 1881 { |
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
|
1882 int c1 = text_yyinput (); |
3774 | 1883 |
1884 switch (c1) | |
1885 { | |
1886 case '+': | |
1887 case '-': | |
1888 // Unary ops, spacing doesn't matter. | |
1889 break; | |
1890 | |
1891 case '=': | |
1892 // Binary ops, spacing doesn't matter. | |
1893 bin_op = true; | |
1894 break; | |
1895 | |
1896 default: | |
1897 // Could be either, spacing matters. | |
1898 bin_op = looks_like_bin_op (spc_prev, c1); | |
1899 break; | |
1900 } | |
1901 | |
8447
adab48231a03
make input_line_number work again
John W. Eaton <jwe@octave.org>
parents:
8312
diff
changeset
|
1902 xunput (c1, yytext); |
3774 | 1903 } |
1904 break; | |
1905 | |
1906 case ':': | |
3246 | 1907 case '/': |
1908 case '\\': | |
1909 case '^': | |
3774 | 1910 // Always a binary op (may also include /=, \=, and ^=). |
1911 bin_op = true; | |
1276 | 1912 break; |
1913 | |
3246 | 1914 // .+ .- ./ .\ .^ .* .** |
1554 | 1915 case '.': |
1916 { | |
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
|
1917 int c1 = text_yyinput (); |
3246 | 1918 |
3774 | 1919 if (match_any (c1, "+-/\\^*")) |
1920 // Always a binary op (may also include .+=, .-=, ./=, ...). | |
1921 bin_op = true; | |
3698 | 1922 else if (! isdigit (c1) && c1 != ' ' && c1 != '\t' && c1 != '.') |
3774 | 1923 // A structure element reference is a binary op. |
1924 bin_op = true; | |
3246 | 1925 |
8447
adab48231a03
make input_line_number work again
John W. Eaton <jwe@octave.org>
parents:
8312
diff
changeset
|
1926 xunput (c1, yytext); |
1554 | 1927 } |
1928 break; | |
1929 | |
3246 | 1930 // = == & && | || * ** |
1931 case '=': | |
1 | 1932 case '&': |
3246 | 1933 case '|': |
1 | 1934 case '*': |
3774 | 1935 // Always a binary op (may also include ==, &&, ||, **). |
1936 bin_op = true; | |
3246 | 1937 break; |
1938 | |
3774 | 1939 // < <= <> > >= |
1 | 1940 case '<': |
1941 case '>': | |
3774 | 1942 // Always a binary op (may also include <=, <>, >=). |
1943 bin_op = true; | |
1944 break; | |
1945 | |
1946 // ~= != | |
777 | 1947 case '~': |
1948 case '!': | |
3246 | 1949 { |
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
|
1950 int c1 = text_yyinput (); |
3246 | 1951 |
3774 | 1952 // ~ and ! can be unary ops, so require following =. |
1953 if (c1 == '=') | |
1954 bin_op = true; | |
3246 | 1955 |
8447
adab48231a03
make input_line_number work again
John W. Eaton <jwe@octave.org>
parents:
8312
diff
changeset
|
1956 xunput (c1, yytext); |
3246 | 1957 } |
1 | 1958 break; |
1959 | |
1960 default: | |
1276 | 1961 break; |
1 | 1962 } |
1963 | |
8447
adab48231a03
make input_line_number work again
John W. Eaton <jwe@octave.org>
parents:
8312
diff
changeset
|
1964 xunput (c0, yytext); |
1 | 1965 |
1966 return bin_op; | |
1967 } | |
1968 | |
767 | 1969 // Used to delete trailing white space from tokens. |
1970 | |
3536 | 1971 static std::string |
1 | 1972 strip_trailing_whitespace (char *s) |
1973 { | |
3523 | 1974 std::string retval = s; |
1 | 1975 |
1823 | 1976 size_t pos = retval.find_first_of (" \t"); |
1 | 1977 |
8021 | 1978 if (pos != std::string::npos) |
1823 | 1979 retval.resize (pos); |
1 | 1980 |
1981 return retval; | |
1982 } | |
1983 | |
7723
74f5e0c7de9e
first pass at handling block comments
John W. Eaton <jwe@octave.org>
parents:
7722
diff
changeset
|
1984 // 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
|
1985 |
3665 | 1986 static void |
1987 scan_for_comments (const char *text) | |
1988 { | |
1989 std::string comment_buf; | |
1990 | |
1991 bool in_comment = false; | |
1992 bool beginning_of_comment = false; | |
1993 | |
1994 int len = strlen (text); | |
1995 int i = 0; | |
1996 | |
1997 while (i < len) | |
1998 { | |
1999 char c = text[i++]; | |
2000 | |
2001 switch (c) | |
2002 { | |
2003 case '%': | |
2004 case '#': | |
2005 if (in_comment) | |
2006 { | |
2007 if (! beginning_of_comment) | |
3802 | 2008 comment_buf += static_cast<char> (c); |
3665 | 2009 } |
2010 else | |
2011 { | |
4037 | 2012 maybe_gripe_matlab_incompatible_comment (c); |
3665 | 2013 in_comment = true; |
2014 beginning_of_comment = true; | |
2015 } | |
2016 break; | |
2017 | |
2018 case '\n': | |
2019 if (in_comment) | |
2020 { | |
3802 | 2021 comment_buf += static_cast<char> (c); |
3665 | 2022 octave_comment_buffer::append (comment_buf); |
2023 comment_buf.resize (0); | |
2024 in_comment = false; | |
2025 beginning_of_comment = false; | |
2026 } | |
2027 break; | |
2028 | |
2029 default: | |
2030 if (in_comment) | |
2031 { | |
3802 | 2032 comment_buf += static_cast<char> (c); |
3665 | 2033 beginning_of_comment = false; |
2034 } | |
2035 break; | |
2036 } | |
2037 } | |
2038 | |
2039 if (! comment_buf.empty ()) | |
2040 octave_comment_buffer::append (comment_buf); | |
2041 } | |
2042 | |
1001 | 2043 // Discard whitespace, including comments and continuations. |
1088 | 2044 // |
2045 // Return value is logical OR of the following values: | |
2046 // | |
1826 | 2047 // ATE_NOTHING : no spaces to eat |
1088 | 2048 // ATE_SPACE_OR_TAB : space or tab in input |
2049 // ATE_NEWLINE : bare new line in input | |
1001 | 2050 |
7723
74f5e0c7de9e
first pass at handling block comments
John W. Eaton <jwe@octave.org>
parents:
7722
diff
changeset
|
2051 // 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
|
2052 |
1826 | 2053 static yum_yum |
975 | 2054 eat_whitespace (void) |
2055 { | |
1826 | 2056 yum_yum retval = ATE_NOTHING; |
3665 | 2057 |
2058 std::string comment_buf; | |
2059 | |
2857 | 2060 bool in_comment = false; |
3665 | 2061 bool beginning_of_comment = false; |
2062 | |
2063 int c = 0; | |
2064 | |
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
|
2065 while ((c = text_yyinput ()) != EOF) |
975 | 2066 { |
2067 current_input_column++; | |
2068 | |
2069 switch (c) | |
2070 { | |
2071 case ' ': | |
2072 case '\t': | |
3665 | 2073 if (in_comment) |
2074 { | |
3802 | 2075 comment_buf += static_cast<char> (c); |
3665 | 2076 beginning_of_comment = false; |
2077 } | |
1088 | 2078 retval |= ATE_SPACE_OR_TAB; |
975 | 2079 break; |
2080 | |
2081 case '\n': | |
1088 | 2082 retval |= ATE_NEWLINE; |
3665 | 2083 if (in_comment) |
2084 { | |
3802 | 2085 comment_buf += static_cast<char> (c); |
3665 | 2086 octave_comment_buffer::append (comment_buf); |
2087 comment_buf.resize (0); | |
2088 in_comment = false; | |
2089 beginning_of_comment = false; | |
2090 } | |
975 | 2091 current_input_column = 0; |
2092 break; | |
2093 | |
2094 case '#': | |
2095 case '%': | |
3665 | 2096 if (in_comment) |
2097 { | |
2098 if (! beginning_of_comment) | |
3802 | 2099 comment_buf += static_cast<char> (c); |
3665 | 2100 } |
2101 else | |
2102 { | |
4037 | 2103 maybe_gripe_matlab_incompatible_comment (c); |
3665 | 2104 in_comment = true; |
2105 beginning_of_comment = true; | |
2106 } | |
975 | 2107 break; |
2108 | |
1001 | 2109 case '.': |
2110 if (in_comment) | |
3665 | 2111 { |
3802 | 2112 comment_buf += static_cast<char> (c); |
3665 | 2113 beginning_of_comment = false; |
2114 break; | |
2115 } | |
1001 | 2116 else |
2117 { | |
2118 if (have_ellipsis_continuation ()) | |
2119 break; | |
2120 else | |
2121 goto done; | |
2122 } | |
2123 | |
2124 case '\\': | |
2125 if (in_comment) | |
3665 | 2126 { |
3802 | 2127 comment_buf += static_cast<char> (c); |
3665 | 2128 beginning_of_comment = false; |
2129 break; | |
2130 } | |
1001 | 2131 else |
2132 { | |
3105 | 2133 if (have_continuation ()) |
1001 | 2134 break; |
2135 else | |
2136 goto done; | |
2137 } | |
2138 | |
975 | 2139 default: |
2140 if (in_comment) | |
3665 | 2141 { |
3802 | 2142 comment_buf += static_cast<char> (c); |
3665 | 2143 beginning_of_comment = false; |
2144 break; | |
2145 } | |
975 | 2146 else |
2147 goto done; | |
2148 } | |
2149 } | |
2150 | |
3665 | 2151 if (! comment_buf.empty ()) |
2152 octave_comment_buffer::append (comment_buf); | |
2153 | |
975 | 2154 done: |
8447
adab48231a03
make input_line_number work again
John W. Eaton <jwe@octave.org>
parents:
8312
diff
changeset
|
2155 xunput (c, yytext); |
1082 | 2156 current_input_column--; |
1001 | 2157 return retval; |
975 | 2158 } |
2159 | |
3220 | 2160 static inline bool |
2161 looks_like_hex (const char *s, int len) | |
2162 { | |
2163 return (len > 2 && s[0] == '0' && (s[1] == 'x' || s[1] == 'X')); | |
2164 } | |
2165 | |
975 | 2166 static void |
3246 | 2167 handle_number (void) |
972 | 2168 { |
3220 | 2169 double value = 0.0; |
2170 int nread = 0; | |
2171 | |
3598 | 2172 if (looks_like_hex (yytext, strlen (yytext))) |
3220 | 2173 { |
2174 unsigned long ival; | |
3598 | 2175 |
2176 nread = sscanf (yytext, "%lx", &ival); | |
2177 | |
3220 | 2178 value = static_cast<double> (ival); |
2179 } | |
2180 else | |
3598 | 2181 { |
2182 char *tmp = strsave (yytext); | |
2183 | |
2184 char *idx = strpbrk (tmp, "Dd"); | |
2621 | 2185 |
3598 | 2186 if (idx) |
2187 *idx = 'e'; | |
2188 | |
2189 nread = sscanf (tmp, "%lf", &value); | |
2190 | |
2191 delete [] tmp; | |
2192 } | |
972 | 2193 |
1826 | 2194 // If yytext doesn't contain a valid number, we are in deep doo doo. |
985 | 2195 |
972 | 2196 assert (nread == 1); |
2197 | |
3988 | 2198 lexer_flags.quote_is_transpose = true; |
2199 lexer_flags.convert_spaces_to_comma = true; | |
972 | 2200 |
2201 yylval.tok_val = new token (value, yytext, input_line_number, | |
2202 current_input_column); | |
2203 | |
2204 token_stack.push (yylval.tok_val); | |
2205 | |
2206 current_input_column += yyleng; | |
2207 | |
2208 do_comma_insert_check (); | |
2209 } | |
2210 | |
1001 | 2211 // We have seen a backslash and need to find out if it should be |
2212 // treated as a continuation character. If so, this eats it, up to | |
2213 // and including the new line character. | |
2214 // | |
973 | 2215 // Match whitespace only, followed by a comment character or newline. |
2216 // Once a comment character is found, discard all input until newline. | |
2217 // If non-whitespace characters are found before comment | |
2218 // characters, return 0. Otherwise, return 1. | |
2219 | |
7723
74f5e0c7de9e
first pass at handling block comments
John W. Eaton <jwe@octave.org>
parents:
7722
diff
changeset
|
2220 // 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
|
2221 |
2857 | 2222 static bool |
3096 | 2223 have_continuation (bool trailing_comments_ok) |
973 | 2224 { |
5765 | 2225 std::ostringstream buf; |
973 | 2226 |
3665 | 2227 std::string comment_buf; |
2228 | |
2857 | 2229 bool in_comment = false; |
3665 | 2230 bool beginning_of_comment = false; |
2231 | |
2232 int c = 0; | |
2233 | |
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
|
2234 while ((c = text_yyinput ()) != EOF) |
973 | 2235 { |
3802 | 2236 buf << static_cast<char> (c); |
973 | 2237 |
2238 switch (c) | |
2239 { | |
2240 case ' ': | |
2241 case '\t': | |
3665 | 2242 if (in_comment) |
2243 { | |
3802 | 2244 comment_buf += static_cast<char> (c); |
3665 | 2245 beginning_of_comment = false; |
2246 } | |
973 | 2247 break; |
2248 | |
2249 case '%': | |
2250 case '#': | |
1091 | 2251 if (trailing_comments_ok) |
3665 | 2252 { |
2253 if (in_comment) | |
2254 { | |
2255 if (! beginning_of_comment) | |
3802 | 2256 comment_buf += static_cast<char> (c); |
3665 | 2257 } |
2258 else | |
2259 { | |
4037 | 2260 maybe_gripe_matlab_incompatible_comment (c); |
3665 | 2261 in_comment = true; |
2262 beginning_of_comment = true; | |
2263 } | |
2264 } | |
1091 | 2265 else |
2266 goto cleanup; | |
973 | 2267 break; |
2268 | |
2269 case '\n': | |
3665 | 2270 if (in_comment) |
2271 { | |
3802 | 2272 comment_buf += static_cast<char> (c); |
3665 | 2273 octave_comment_buffer::append (comment_buf); |
2274 } | |
975 | 2275 current_input_column = 0; |
1001 | 2276 promptflag--; |
4037 | 2277 gripe_matlab_incompatible_continuation (); |
2857 | 2278 return true; |
973 | 2279 |
2280 default: | |
3665 | 2281 if (in_comment) |
2282 { | |
3802 | 2283 comment_buf += static_cast<char> (c); |
3665 | 2284 beginning_of_comment = false; |
2285 } | |
2286 else | |
1091 | 2287 goto cleanup; |
2288 break; | |
973 | 2289 } |
2290 } | |
2291 | |
8447
adab48231a03
make input_line_number work again
John W. Eaton <jwe@octave.org>
parents:
8312
diff
changeset
|
2292 xunput (c, yytext); |
2857 | 2293 return false; |
973 | 2294 |
3096 | 2295 cleanup: |
4051 | 2296 |
5765 | 2297 std::string s = buf.str (); |
4051 | 2298 |
2299 int len = s.length (); | |
2300 while (len--) | |
8447
adab48231a03
make input_line_number work again
John W. Eaton <jwe@octave.org>
parents:
8312
diff
changeset
|
2301 xunput (s[len], yytext); |
3096 | 2302 |
2857 | 2303 return false; |
973 | 2304 } |
2305 | |
1001 | 2306 // We have seen a `.' and need to see if it is the start of a |
2307 // continuation. If so, this eats it, up to and including the new | |
2308 // line character. | |
2309 | |
2857 | 2310 static bool |
3096 | 2311 have_ellipsis_continuation (bool trailing_comments_ok) |
973 | 2312 { |
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
|
2313 char c1 = text_yyinput (); |
973 | 2314 if (c1 == '.') |
2315 { | |
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
|
2316 char c2 = text_yyinput (); |
1091 | 2317 if (c2 == '.' && have_continuation (trailing_comments_ok)) |
2857 | 2318 return true; |
973 | 2319 else |
2320 { | |
8447
adab48231a03
make input_line_number work again
John W. Eaton <jwe@octave.org>
parents:
8312
diff
changeset
|
2321 xunput (c2, yytext); |
adab48231a03
make input_line_number work again
John W. Eaton <jwe@octave.org>
parents:
8312
diff
changeset
|
2322 xunput (c1, yytext); |
973 | 2323 } |
2324 } | |
2325 else | |
8447
adab48231a03
make input_line_number work again
John W. Eaton <jwe@octave.org>
parents:
8312
diff
changeset
|
2326 xunput (c1, yytext); |
973 | 2327 |
2857 | 2328 return false; |
973 | 2329 } |
2330 | |
1001 | 2331 // See if we have a continuation line. If so, eat it and the leading |
2332 // whitespace on the next line. | |
1088 | 2333 // |
2334 // Return value is the same as described for eat_whitespace(). | |
1001 | 2335 |
1826 | 2336 static yum_yum |
1001 | 2337 eat_continuation (void) |
2338 { | |
1826 | 2339 int retval = ATE_NOTHING; |
3665 | 2340 |
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
|
2341 int c = text_yyinput (); |
3665 | 2342 |
1001 | 2343 if ((c == '.' && have_ellipsis_continuation ()) |
3105 | 2344 || (c == '\\' && have_continuation ())) |
1001 | 2345 retval = eat_whitespace (); |
2346 else | |
8447
adab48231a03
make input_line_number work again
John W. Eaton <jwe@octave.org>
parents:
8312
diff
changeset
|
2347 xunput (c, yytext); |
1001 | 2348 |
2349 return retval; | |
2350 } | |
2351 | |
973 | 2352 static int |
975 | 2353 handle_string (char delim, int text_style) |
973 | 2354 { |
5765 | 2355 std::ostringstream buf; |
973 | 2356 |
3805 | 2357 int bos_line = input_line_number; |
2358 int bos_col = current_input_column; | |
2359 | |
973 | 2360 int c; |
1031 | 2361 int escape_pending = 0; |
973 | 2362 |
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
|
2363 while ((c = text_yyinput ()) != EOF) |
973 | 2364 { |
2365 current_input_column++; | |
2366 | |
3105 | 2367 if (c == '\\') |
973 | 2368 { |
5359 | 2369 if (delim == '\'' || escape_pending) |
1053 | 2370 { |
3802 | 2371 buf << static_cast<char> (c); |
1053 | 2372 escape_pending = 0; |
2373 } | |
2374 else | |
2375 { | |
3096 | 2376 if (have_continuation (false)) |
1053 | 2377 escape_pending = 0; |
2378 else | |
2379 { | |
3802 | 2380 buf << static_cast<char> (c); |
1053 | 2381 escape_pending = 1; |
2382 } | |
2383 } | |
1031 | 2384 continue; |
973 | 2385 } |
2386 else if (c == '.') | |
2387 { | |
5359 | 2388 if (delim == '\'' || ! have_ellipsis_continuation (false)) |
3802 | 2389 buf << static_cast<char> (c); |
973 | 2390 } |
2391 else if (c == '\n') | |
2392 { | |
1053 | 2393 error ("unterminated string constant"); |
973 | 2394 break; |
2395 } | |
2396 else if (c == delim) | |
2397 { | |
1031 | 2398 if (escape_pending) |
3802 | 2399 buf << static_cast<char> (c); |
973 | 2400 else |
2401 { | |
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
|
2402 c = text_yyinput (); |
973 | 2403 if (c == delim) |
5102 | 2404 { |
2405 buf << static_cast<char> (c); | |
2406 if (lexer_flags.doing_rawcommand) | |
2407 buf << static_cast<char> (c); | |
2408 } | |
973 | 2409 else |
2410 { | |
5102 | 2411 std::string s; |
8447
adab48231a03
make input_line_number work again
John W. Eaton <jwe@octave.org>
parents:
8312
diff
changeset
|
2412 xunput (c, yytext); |
5765 | 2413 |
5279 | 2414 if (lexer_flags.doing_rawcommand || delim == '\'') |
5765 | 2415 s = buf.str (); |
5102 | 2416 else |
5765 | 2417 s = do_string_escapes (buf.str ()); |
975 | 2418 |
5102 | 2419 if (text_style && lexer_flags.doing_rawcommand) |
2420 s = std::string (1, delim) + s + std::string (1, delim); | |
975 | 2421 else |
2422 { | |
2857 | 2423 lexer_flags.quote_is_transpose = true; |
2424 lexer_flags.convert_spaces_to_comma = true; | |
975 | 2425 } |
2426 | |
3805 | 2427 yylval.tok_val = new token (s, bos_line, bos_col); |
973 | 2428 token_stack.push (yylval.tok_val); |
3400 | 2429 |
4037 | 2430 if (delim == '"') |
2431 gripe_matlab_incompatible ("\" used as string delimiter"); | |
2432 else if (delim == '\'') | |
3400 | 2433 gripe_single_quote_string (); |
2434 | |
5279 | 2435 return delim == '"' ? DQ_STRING : SQ_STRING; |
973 | 2436 } |
2437 } | |
2438 } | |
2439 else | |
2440 { | |
3802 | 2441 buf << static_cast<char> (c); |
973 | 2442 } |
2443 | |
1031 | 2444 escape_pending = 0; |
973 | 2445 } |
2446 | |
2447 return LEXICAL_ERROR; | |
2448 } | |
2449 | |
3208 | 2450 static bool |
2451 next_token_is_assign_op (void) | |
2452 { | |
2453 bool retval = false; | |
2454 | |
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
|
2455 int c0 = text_yyinput (); |
3208 | 2456 |
2457 switch (c0) | |
2458 { | |
2459 case '=': | |
2460 { | |
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
|
2461 int c1 = text_yyinput (); |
8447
adab48231a03
make input_line_number work again
John W. Eaton <jwe@octave.org>
parents:
8312
diff
changeset
|
2462 xunput (c1, yytext); |
3208 | 2463 if (c1 != '=') |
2464 retval = true; | |
2465 } | |
2466 break; | |
2467 | |
2468 case '+': | |
2469 case '-': | |
2470 case '*': | |
2471 case '/': | |
2472 case '\\': | |
2473 case '&': | |
2474 case '|': | |
2475 { | |
7728
13820b9f5fd9
more consistent handling of CR/CRLF/LF line endings in lexer and parser
John W. Eaton <jwe@octave.org>
parents:
7723
diff
changeset
|
2476 int c1 = text_yyinput (); |
8447
adab48231a03
make input_line_number work again
John W. Eaton <jwe@octave.org>
parents:
8312
diff
changeset
|
2477 xunput (c1, yytext); |
3208 | 2478 if (c1 == '=') |
2479 retval = true; | |
2480 } | |
2481 break; | |
2482 | |
2483 case '.': | |
2484 { | |
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
|
2485 int c1 = text_yyinput (); |
3208 | 2486 if (match_any (c1, "+-*/\\")) |
2487 { | |
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
|
2488 int c2 = text_yyinput (); |
8447
adab48231a03
make input_line_number work again
John W. Eaton <jwe@octave.org>
parents:
8312
diff
changeset
|
2489 xunput (c2, yytext); |
3208 | 2490 if (c2 == '=') |
2491 retval = true; | |
2492 } | |
8447
adab48231a03
make input_line_number work again
John W. Eaton <jwe@octave.org>
parents:
8312
diff
changeset
|
2493 xunput (c1, yytext); |
3208 | 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 (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 default: | |
2526 break; | |
2527 } | |
2528 | |
8447
adab48231a03
make input_line_number work again
John W. Eaton <jwe@octave.org>
parents:
8312
diff
changeset
|
2529 xunput (c0, yytext); |
3208 | 2530 |
2531 return retval; | |
2532 } | |
2533 | |
4633 | 2534 static bool |
2535 next_token_is_index_op (void) | |
2536 { | |
7728
13820b9f5fd9
more consistent handling of CR/CRLF/LF line endings in lexer and parser
John W. Eaton <jwe@octave.org>
parents:
7723
diff
changeset
|
2537 int c = text_yyinput (); |
8447
adab48231a03
make input_line_number work again
John W. Eaton <jwe@octave.org>
parents:
8312
diff
changeset
|
2538 xunput (c, yytext); |
4633 | 2539 return c == '(' || c == '{'; |
2540 } | |
2541 | |
4612 | 2542 static int |
2543 handle_close_bracket (bool spc_gobbled, int bracket_type) | |
971 | 2544 { |
4612 | 2545 int retval = bracket_type; |
3208 | 2546 |
1826 | 2547 if (! nesting_level.none ()) |
971 | 2548 { |
1826 | 2549 nesting_level.remove (); |
4613 | 2550 |
2551 if (bracket_type == ']') | |
2552 lexer_flags.bracketflag--; | |
2553 else if (bracket_type == '}') | |
2554 lexer_flags.braceflag--; | |
2555 else | |
2556 panic_impossible (); | |
971 | 2557 } |
2558 | |
4613 | 2559 if (lexer_flags.bracketflag == 0 && lexer_flags.braceflag == 0) |
4323 | 2560 BEGIN (INITIAL); |
1001 | 2561 |
4608 | 2562 if (bracket_type == ']' |
2563 && next_token_is_assign_op () | |
2564 && ! lexer_flags.looking_at_return_list) | |
971 | 2565 { |
3208 | 2566 retval = CLOSE_BRACE; |
971 | 2567 } |
4613 | 2568 else if ((lexer_flags.bracketflag || lexer_flags.braceflag) |
2569 && lexer_flags.convert_spaces_to_comma | |
2570 && (nesting_level.is_bracket () | |
2571 || (nesting_level.is_brace () | |
2572 && ! lexer_flags.looking_at_object_index))) | |
971 | 2573 { |
4633 | 2574 bool index_op = next_token_is_index_op (); |
2575 | |
2576 // Don't insert comma if we are looking at something like | |
2577 // | |
2578 // [x{i}{j}] or [x{i}(j)] | |
2579 // | |
2580 // but do if we are looking at | |
2581 // | |
2582 // [x{i} {j}] or [x{i} (j)] | |
2583 | |
2584 if (spc_gobbled || ! (bracket_type == '}' && index_op)) | |
971 | 2585 { |
4633 | 2586 bool bin_op = next_token_is_bin_op (spc_gobbled); |
2587 | |
2588 bool postfix_un_op = next_token_is_postfix_unary_op (spc_gobbled); | |
2589 | |
2590 bool sep_op = next_token_is_sep_op (); | |
2591 | |
2592 if (! (postfix_un_op || bin_op || sep_op)) | |
2593 { | |
2594 maybe_warn_separator_insert (','); | |
2595 | |
2596 yyunput (',', yytext); | |
2597 return retval; | |
2598 } | |
971 | 2599 } |
2600 } | |
2601 | |
2857 | 2602 lexer_flags.quote_is_transpose = true; |
2603 lexer_flags.convert_spaces_to_comma = true; | |
3208 | 2604 |
2605 return retval; | |
971 | 2606 } |
2607 | |
1072 | 2608 static void |
2609 maybe_unput_comma (int spc_gobbled) | |
2610 { | |
4613 | 2611 if (nesting_level.is_bracket () |
2612 || (nesting_level.is_brace () | |
2613 && ! lexer_flags.looking_at_object_index)) | |
1072 | 2614 { |
3246 | 2615 int bin_op = next_token_is_bin_op (spc_gobbled); |
1072 | 2616 |
3246 | 2617 int postfix_un_op = next_token_is_postfix_unary_op (spc_gobbled); |
1072 | 2618 |
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
|
2619 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
|
2620 int c2 = text_yyinput (); |
2970 | 2621 |
8447
adab48231a03
make input_line_number work again
John W. Eaton <jwe@octave.org>
parents:
8312
diff
changeset
|
2622 xunput (c2, yytext); |
adab48231a03
make input_line_number work again
John W. Eaton <jwe@octave.org>
parents:
8312
diff
changeset
|
2623 xunput (c1, yytext); |
2970 | 2624 |
3263 | 2625 int sep_op = next_token_is_sep_op (); |
2970 | 2626 |
1072 | 2627 int dot_op = (c1 == '.' |
2628 && (isalpha (c2) || isspace (c2) || c2 == '_')); | |
2970 | 2629 |
3388 | 2630 if (postfix_un_op || bin_op || sep_op || dot_op) |
2631 return; | |
2632 | |
3985 | 2633 int index_op = (c1 == '(' || c1 == '{'); |
3388 | 2634 |
4476 | 2635 // If there is no space before the indexing op, we don't insert |
2636 // a comma. | |
2637 | |
2638 if (index_op && ! spc_gobbled) | |
2639 return; | |
2640 | |
2641 maybe_warn_separator_insert (','); | |
2642 | |
2643 yyunput (',', yytext); | |
1072 | 2644 } |
2645 } | |
2646 | |
767 | 2647 // Figure out exactly what kind of token to return when we have seen |
4238 | 2648 // an identifier. Handles keywords. Return -1 if the identifier |
2649 // should be ignored. | |
767 | 2650 |
146 | 2651 static int |
3974 | 2652 handle_identifier (void) |
146 | 2653 { |
3974 | 2654 std::string tok = strip_trailing_whitespace (yytext); |
2655 | |
2656 int c = yytext[yyleng-1]; | |
2657 | |
2658 int cont_is_spc = eat_continuation (); | |
2659 | |
2660 int spc_gobbled = (cont_is_spc || c == ' ' || c == '\t'); | |
2661 | |
2970 | 2662 // If we are expecting a structure element, avoid recognizing |
2663 // keywords and other special names and return STRUCT_ELT, which is | |
2664 // a string that is also a valid identifier. But first, we have to | |
2665 // decide whether to insert a comma. | |
747 | 2666 |
1826 | 2667 if (lexer_flags.looking_at_indirect_ref) |
1072 | 2668 { |
2970 | 2669 do_comma_insert_check (); |
2670 | |
1072 | 2671 maybe_unput_comma (spc_gobbled); |
2819 | 2672 |
2673 yylval.tok_val = new token (tok, input_line_number, | |
2674 current_input_column); | |
2675 | |
2676 token_stack.push (yylval.tok_val); | |
2677 | |
2857 | 2678 lexer_flags.quote_is_transpose = true; |
2679 lexer_flags.convert_spaces_to_comma = true; | |
2819 | 2680 |
2681 current_input_column += yyleng; | |
2682 | |
2970 | 2683 return STRUCT_ELT; |
1072 | 2684 } |
747 | 2685 |
4930 | 2686 int kw_token = is_keyword_token (tok); |
2687 | |
2688 if (lexer_flags.looking_at_function_handle) | |
2689 { | |
2690 if (kw_token) | |
2691 { | |
2692 error ("function handles may not refer to keywords"); | |
2693 | |
2694 return LEXICAL_ERROR; | |
2695 } | |
2696 else | |
7722
c3bb0b7a4261
lex.l: allow tokens to be displayed when parsed
John W. Eaton <jwe@octave.org>
parents:
7720
diff
changeset
|
2697 { |
c3bb0b7a4261
lex.l: allow tokens to be displayed when parsed
John W. Eaton <jwe@octave.org>
parents:
7720
diff
changeset
|
2698 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
|
2699 current_input_column); |
c3bb0b7a4261
lex.l: allow tokens to be displayed when parsed
John W. Eaton <jwe@octave.org>
parents:
7720
diff
changeset
|
2700 |
c3bb0b7a4261
lex.l: allow tokens to be displayed when parsed
John W. Eaton <jwe@octave.org>
parents:
7720
diff
changeset
|
2701 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
|
2702 |
c3bb0b7a4261
lex.l: allow tokens to be displayed when parsed
John W. Eaton <jwe@octave.org>
parents:
7720
diff
changeset
|
2703 current_input_column += yyleng; |
c3bb0b7a4261
lex.l: allow tokens to be displayed when parsed
John W. Eaton <jwe@octave.org>
parents:
7720
diff
changeset
|
2704 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
|
2705 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
|
2706 |
c3bb0b7a4261
lex.l: allow tokens to be displayed when parsed
John W. Eaton <jwe@octave.org>
parents:
7720
diff
changeset
|
2707 return FCN_HANDLE; |
c3bb0b7a4261
lex.l: allow tokens to be displayed when parsed
John W. Eaton <jwe@octave.org>
parents:
7720
diff
changeset
|
2708 } |
4930 | 2709 } |
2710 | |
5102 | 2711 // 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
|
2712 // Keywords can be followed by identifiers. |
146 | 2713 |
2714 if (kw_token) | |
2715 { | |
7722
c3bb0b7a4261
lex.l: allow tokens to be displayed when parsed
John W. Eaton <jwe@octave.org>
parents:
7720
diff
changeset
|
2716 if (kw_token >= 0) |
c3bb0b7a4261
lex.l: allow tokens to be displayed when parsed
John W. Eaton <jwe@octave.org>
parents:
7720
diff
changeset
|
2717 { |
c3bb0b7a4261
lex.l: allow tokens to be displayed when parsed
John W. Eaton <jwe@octave.org>
parents:
7720
diff
changeset
|
2718 current_input_column += yyleng; |
c3bb0b7a4261
lex.l: allow tokens to be displayed when parsed
John W. Eaton <jwe@octave.org>
parents:
7720
diff
changeset
|
2719 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
|
2720 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
|
2721 } |
c3bb0b7a4261
lex.l: allow tokens to be displayed when parsed
John W. Eaton <jwe@octave.org>
parents:
7720
diff
changeset
|
2722 |
c3bb0b7a4261
lex.l: allow tokens to be displayed when parsed
John W. Eaton <jwe@octave.org>
parents:
7720
diff
changeset
|
2723 return kw_token; |
146 | 2724 } |
2725 | |
1826 | 2726 // See if we have a plot keyword (title, using, with, or clear). |
146 | 2727 |
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
|
2728 int c1 = text_yyinput (); |
3480 | 2729 |
2730 bool next_tok_is_paren = (c1 == '('); | |
2731 | |
2732 bool next_tok_is_eq = false; | |
2733 if (c1 == '=') | |
2734 { | |
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
|
2735 int c2 = text_yyinput (); |
8447
adab48231a03
make input_line_number work again
John W. Eaton <jwe@octave.org>
parents:
8312
diff
changeset
|
2736 xunput (c2, yytext); |
3480 | 2737 |
2738 if (c2 != '=') | |
2739 next_tok_is_eq = true; | |
2740 } | |
2741 | |
8447
adab48231a03
make input_line_number work again
John W. Eaton <jwe@octave.org>
parents:
8312
diff
changeset
|
2742 xunput (c1, yytext); |
1001 | 2743 |
2702 | 2744 // Kluge alert. |
2745 // | |
2746 // If we are looking at a text style function, set up to gobble its | |
2745 | 2747 // arguments. |
2748 // | |
2749 // If the following token is `=', or if we are parsing a function | |
3189 | 2750 // return list or function parameter list, or if we are looking at |
2751 // something like [ab,cd] = foo (), force the symbol to be inserted | |
2752 // as a variable in the current symbol table. | |
2702 | 2753 |
4208 | 2754 if (is_command_name (tok) && ! is_variable (tok)) |
2702 | 2755 { |
2745 | 2756 if (next_tok_is_eq |
2757 || lexer_flags.looking_at_return_list | |
7634
ae90e05ad299
fix parameter list initializer bug
John W. Eaton <jwe@octave.org>
parents:
7587
diff
changeset
|
2758 || (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
|
2759 && ! lexer_flags.looking_at_initializer_expression)) |
2745 | 2760 { |
2761 force_local_variable (tok); | |
2762 } | |
8001
ff9e7873f8ea
improve handling of command-style names in matrix_or_assign_lhs context
John W. Eaton <jwe@octave.org>
parents:
7898
diff
changeset
|
2763 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
|
2764 { |
ff9e7873f8ea
improve handling of command-style names in matrix_or_assign_lhs context
John W. Eaton <jwe@octave.org>
parents:
7898
diff
changeset
|
2765 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
|
2766 } |
6067 | 2767 else if (! (next_tok_is_paren || lexer_flags.looking_at_object_index)) |
2702 | 2768 { |
5102 | 2769 BEGIN (COMMAND_START); |
2770 } | |
2771 | |
6067 | 2772 if (is_rawcommand_name (tok) && ! lexer_flags.looking_at_object_index) |
5102 | 2773 { |
2774 lexer_flags.doing_rawcommand = true; | |
4323 | 2775 BEGIN (COMMAND_START); |
2702 | 2776 } |
2777 } | |
2778 | |
4234 | 2779 // Find the token in the symbol table. Beware the magic |
2780 // transformation of the end keyword... | |
2781 | |
2782 if (tok == "end") | |
2783 tok = "__end__"; | |
146 | 2784 |
7336 | 2785 yylval.tok_val = new token (&(symbol_table::insert (tok)), |
2786 input_line_number, current_input_column); | |
2787 | |
146 | 2788 token_stack.push (yylval.tok_val); |
2789 | |
1826 | 2790 // After seeing an identifer, it is ok to convert spaces to a comma |
2791 // (if needed). | |
146 | 2792 |
2857 | 2793 lexer_flags.convert_spaces_to_comma = true; |
146 | 2794 |
2877 | 2795 if (! next_tok_is_eq) |
2796 { | |
2797 lexer_flags.quote_is_transpose = true; | |
146 | 2798 |
2877 | 2799 do_comma_insert_check (); |
2800 | |
2801 maybe_unput_comma (spc_gobbled); | |
146 | 2802 } |
2803 | |
2877 | 2804 current_input_column += yyleng; |
146 | 2805 |
2806 return NAME; | |
2807 } | |
2808 | |
1826 | 2809 void |
2810 lexical_feedback::init (void) | |
2811 { | |
2812 // Not initially defining a matrix list. | |
3351 | 2813 bracketflag = 0; |
1826 | 2814 |
4613 | 2815 // Not initially defining a cell array list. |
2816 braceflag = 0; | |
2817 | |
1826 | 2818 // Not initially inside a loop or if statement. |
2819 looping = 0; | |
2820 | |
2857 | 2821 // Not initially defining a function. |
2822 defining_func = false; | |
2877 | 2823 parsed_function_name = false; |
4240 | 2824 parsing_nested_function = 0; |
7336 | 2825 parsing_class_method = false; |
2857 | 2826 |
4930 | 2827 // Not initiallly looking at a function handle. |
2828 looking_at_function_handle = 0; | |
2829 | |
2857 | 2830 // Not parsing a function return or parameter list. |
2831 looking_at_return_list = false; | |
2832 looking_at_parameter_list = false; | |
2833 | |
7634
ae90e05ad299
fix parameter list initializer bug
John W. Eaton <jwe@octave.org>
parents:
7587
diff
changeset
|
2834 // Not looking at an argument list initializer expression. |
ae90e05ad299
fix parameter list initializer bug
John W. Eaton <jwe@octave.org>
parents:
7587
diff
changeset
|
2835 looking_at_initializer_expression = false; |
ae90e05ad299
fix parameter list initializer bug
John W. Eaton <jwe@octave.org>
parents:
7587
diff
changeset
|
2836 |
3796 | 2837 // Not parsing a matrix or the left hand side of multi-value |
2838 // assignment statement. | |
2839 looking_at_matrix_or_assign_lhs = false; | |
2840 | |
4234 | 2841 // Not parsing an object index. |
4237 | 2842 looking_at_object_index = 0; |
4234 | 2843 |
2857 | 2844 // No need to do comma insert or convert spaces to comma at |
2845 // beginning of input. | |
2846 convert_spaces_to_comma = true; | |
2847 do_comma_insert = false; | |
2848 | |
2849 // Not initially doing any plotting or setting of plot attributes. | |
5102 | 2850 doing_rawcommand = false; |
2857 | 2851 |
1826 | 2852 // Not initially looking at indirect references. |
2857 | 2853 looking_at_indirect_ref = false; |
1826 | 2854 |
2855 // Quote marks strings intially. | |
2857 | 2856 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
|
2857 |
ff9e7873f8ea
improve handling of command-style names in matrix_or_assign_lhs context
John W. Eaton <jwe@octave.org>
parents:
7898
diff
changeset
|
2858 // 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
|
2859 pending_local_variables.clear (); |
1826 | 2860 } |
2861 | |
4867 | 2862 bool |
2863 is_keyword (const std::string& s) | |
2864 { | |
5088 | 2865 return octave_kw_hash::in_word_set (s.c_str (), s.length ()) != 0; |
4867 | 2866 } |
2867 | |
4264 | 2868 DEFCMD (iskeyword, args, , |
2869 "-*- texinfo -*-\n\ | |
2870 @deftypefn {Built-in Function} {} iskeyword (@var{name})\n\ | |
2871 Return true if @var{name} is an Octave keyword. If @var{name}\n\ | |
2872 is omitted, return a list of keywords.\n\ | |
2873 @end deftypefn") | |
2874 { | |
2875 octave_value retval; | |
2876 | |
2877 int argc = args.length () + 1; | |
2878 | |
4867 | 2879 string_vector argv = args.make_argv ("iskeyword"); |
4264 | 2880 |
2881 if (error_state) | |
2882 return retval; | |
2883 | |
2884 if (argc == 1) | |
2885 { | |
2886 string_vector lst (TOTAL_KEYWORDS); | |
2887 | |
2888 for (int i = 0; i < TOTAL_KEYWORDS; i++) | |
2889 lst[i] = wordlist[i].name; | |
2890 | |
8504
0e0bd07e6ae2
omission from last patch
Jaroslav Hajek <highegg@gmail.com>
parents:
8447
diff
changeset
|
2891 retval = Cell (lst.sort ()); |
4264 | 2892 } |
2893 else if (argc == 2) | |
2894 { | |
4867 | 2895 retval = is_keyword (argv[1]); |
4264 | 2896 } |
2897 else | |
5823 | 2898 print_usage (); |
4264 | 2899 |
2900 return retval; | |
2901 } | |
2902 | |
7715
5b4d278ec828
parse scripts completely before executing
John W. Eaton <jwe@octave.org>
parents:
7634
diff
changeset
|
2903 void |
5b4d278ec828
parse scripts completely before executing
John W. Eaton <jwe@octave.org>
parents:
7634
diff
changeset
|
2904 prep_lexer_for_script (void) |
5b4d278ec828
parse scripts completely before executing
John W. Eaton <jwe@octave.org>
parents:
7634
diff
changeset
|
2905 { |
5b4d278ec828
parse scripts completely before executing
John W. Eaton <jwe@octave.org>
parents:
7634
diff
changeset
|
2906 BEGIN (SCRIPT_FILE_BEGIN); |
5b4d278ec828
parse scripts completely before executing
John W. Eaton <jwe@octave.org>
parents:
7634
diff
changeset
|
2907 } |
4264 | 2908 |
3388 | 2909 static void |
2910 maybe_warn_separator_insert (char sep) | |
2911 { | |
3523 | 2912 std::string nm = curr_fcn_file_full_name; |
3388 | 2913 |
5794 | 2914 if (nm.empty ()) |
2915 warning_with_id ("Octave:separator-insert", | |
2916 "potential auto-insertion of `%c' near line %d", | |
2917 sep, input_line_number); | |
2918 else | |
2919 warning_with_id ("Octave:separator-insert", | |
2920 "potential auto-insertion of `%c' near line %d of file %s", | |
2921 sep, input_line_number, nm.c_str ()); | |
3388 | 2922 } |
2923 | |
3400 | 2924 static void |
2925 gripe_single_quote_string (void) | |
2926 { | |
3523 | 2927 std::string nm = curr_fcn_file_full_name; |
3400 | 2928 |
5794 | 2929 if (nm.empty ()) |
2930 warning_with_id ("Octave:single-quote-string", | |
2931 "single quote delimited string near line %d", | |
2932 input_line_number); | |
2933 else | |
2934 warning_with_id ("Octave:single-quote-string", | |
2935 "single quote delimited string near line %d of file %s", | |
2936 input_line_number, nm.c_str ()); | |
3400 | 2937 } |
2938 | |
4037 | 2939 static void |
2940 gripe_matlab_incompatible (const std::string& msg) | |
2941 { | |
5794 | 2942 warning_with_id ("Octave:matlab-incompatible", |
2943 "potential Matlab compatibility problem: %s", | |
2944 msg.c_str ()); | |
4037 | 2945 } |
2946 | |
2947 static void | |
2948 maybe_gripe_matlab_incompatible_comment (char c) | |
2949 { | |
2950 if (c == '#') | |
2951 gripe_matlab_incompatible ("# used as comment character"); | |
2952 } | |
2953 | |
2954 static void | |
2955 gripe_matlab_incompatible_continuation (void) | |
2956 { | |
2957 gripe_matlab_incompatible ("\\ used as line continuation marker"); | |
2958 } | |
2959 | |
2960 static void | |
2961 gripe_matlab_incompatible_operator (const std::string& op) | |
2962 { | |
2963 std::string t = op; | |
2964 int n = t.length (); | |
2965 if (t[n-1] == '\n') | |
2966 t.resize (n-1); | |
2967 gripe_matlab_incompatible (t + " used as operator"); | |
2968 } | |
2969 | |
7722
c3bb0b7a4261
lex.l: allow tokens to be displayed when parsed
John W. Eaton <jwe@octave.org>
parents:
7720
diff
changeset
|
2970 static void |
c3bb0b7a4261
lex.l: allow tokens to be displayed when parsed
John W. Eaton <jwe@octave.org>
parents:
7720
diff
changeset
|
2971 display_token (int tok) |
c3bb0b7a4261
lex.l: allow tokens to be displayed when parsed
John W. Eaton <jwe@octave.org>
parents:
7720
diff
changeset
|
2972 { |
c3bb0b7a4261
lex.l: allow tokens to be displayed when parsed
John W. Eaton <jwe@octave.org>
parents:
7720
diff
changeset
|
2973 switch (tok) |
c3bb0b7a4261
lex.l: allow tokens to be displayed when parsed
John W. Eaton <jwe@octave.org>
parents:
7720
diff
changeset
|
2974 { |
c3bb0b7a4261
lex.l: allow tokens to be displayed when parsed
John W. Eaton <jwe@octave.org>
parents:
7720
diff
changeset
|
2975 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
|
2976 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
|
2977 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
|
2978 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
|
2979 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
|
2980 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
|
2981 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
|
2982 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
|
2983 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
|
2984 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
|
2985 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
|
2986 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
|
2987 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
|
2988 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
|
2989 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
|
2990 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
|
2991 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
|
2992 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
|
2993 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
|
2994 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
|
2995 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
|
2996 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
|
2997 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
|
2998 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
|
2999 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
|
3000 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
|
3001 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
|
3002 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
|
3003 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
|
3004 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
|
3005 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
|
3006 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
|
3007 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
|
3008 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
|
3009 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
|
3010 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
|
3011 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
|
3012 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
|
3013 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
|
3014 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
|
3015 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
|
3016 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
|
3017 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
|
3018 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
|
3019 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
|
3020 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
|
3021 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
|
3022 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
|
3023 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
|
3024 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
|
3025 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
|
3026 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
|
3027 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
|
3028 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
|
3029 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
|
3030 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
|
3031 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
|
3032 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
|
3033 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
|
3034 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
|
3035 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
|
3036 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
|
3037 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
|
3038 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
|
3039 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
|
3040 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
|
3041 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
|
3042 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
|
3043 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
|
3044 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
|
3045 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
|
3046 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
|
3047 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
|
3048 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
|
3049 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
|
3050 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
|
3051 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
|
3052 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
|
3053 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
|
3054 default: |
c3bb0b7a4261
lex.l: allow tokens to be displayed when parsed
John W. Eaton <jwe@octave.org>
parents:
7720
diff
changeset
|
3055 { |
c3bb0b7a4261
lex.l: allow tokens to be displayed when parsed
John W. Eaton <jwe@octave.org>
parents:
7720
diff
changeset
|
3056 if (tok < 256) |
c3bb0b7a4261
lex.l: allow tokens to be displayed when parsed
John W. Eaton <jwe@octave.org>
parents:
7720
diff
changeset
|
3057 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
|
3058 else |
c3bb0b7a4261
lex.l: allow tokens to be displayed when parsed
John W. Eaton <jwe@octave.org>
parents:
7720
diff
changeset
|
3059 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
|
3060 } |
c3bb0b7a4261
lex.l: allow tokens to be displayed when parsed
John W. Eaton <jwe@octave.org>
parents:
7720
diff
changeset
|
3061 break; |
c3bb0b7a4261
lex.l: allow tokens to be displayed when parsed
John W. Eaton <jwe@octave.org>
parents:
7720
diff
changeset
|
3062 } |
c3bb0b7a4261
lex.l: allow tokens to be displayed when parsed
John W. Eaton <jwe@octave.org>
parents:
7720
diff
changeset
|
3063 } |
c3bb0b7a4261
lex.l: allow tokens to be displayed when parsed
John W. Eaton <jwe@octave.org>
parents:
7720
diff
changeset
|
3064 |
8535 | 3065 static void |
3066 display_state (void) | |
3067 { | |
3068 std::cerr << "S: "; | |
3069 | |
3070 switch (YY_START) | |
3071 { | |
3072 case INITIAL: | |
3073 std::cerr << "INITIAL" << std::endl; | |
3074 break; | |
3075 | |
3076 case COMMAND_START: | |
3077 std::cerr << "COMMAND_START" << std::endl; | |
3078 break; | |
3079 | |
3080 case MATRIX_START: | |
3081 std::cerr << "MATRIX_START" << std::endl; | |
3082 break; | |
3083 | |
3084 case SCRIPT_FILE_BEGIN: | |
3085 std::cerr << "SCRIPT_FILE_BEGIN" << std::endl; | |
3086 break; | |
3087 | |
3088 case NESTED_FUNCTION_END: | |
3089 std::cerr << "NESTED_FUNCTION_END" << std::endl; | |
3090 break; | |
3091 | |
3092 case NESTED_FUNCTION_BEGIN: | |
3093 std::cerr << "NESTED_FUNCTION_BEGIN" << std::endl; | |
3094 break; | |
3095 | |
3096 default: | |
3097 std::cerr << "UNKNOWN START STATE!" << std::endl; | |
3098 break; | |
3099 } | |
3100 } | |
3101 | |
3102 static void | |
3103 lexer_debug (const char *pattern, const char *text) | |
3104 { | |
3105 std::cerr << std::endl; | |
3106 | |
3107 display_state (); | |
3108 | |
3109 std::cerr << "P: " << pattern << std::endl; | |
3110 std::cerr << "T: " << text << std::endl; | |
3111 } | |
3112 | |
7722
c3bb0b7a4261
lex.l: allow tokens to be displayed when parsed
John W. Eaton <jwe@octave.org>
parents:
7720
diff
changeset
|
3113 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
|
3114 "-*- texinfo -*-\n\ |
c3bb0b7a4261
lex.l: allow tokens to be displayed when parsed
John W. Eaton <jwe@octave.org>
parents:
7720
diff
changeset
|
3115 @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
|
3116 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
|
3117 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
|
3118 @end deftypefn") |
c3bb0b7a4261
lex.l: allow tokens to be displayed when parsed
John W. Eaton <jwe@octave.org>
parents:
7720
diff
changeset
|
3119 { |
c3bb0b7a4261
lex.l: allow tokens to be displayed when parsed
John W. Eaton <jwe@octave.org>
parents:
7720
diff
changeset
|
3120 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
|
3121 } |
c3bb0b7a4261
lex.l: allow tokens to be displayed when parsed
John W. Eaton <jwe@octave.org>
parents:
7720
diff
changeset
|
3122 |
4910 | 3123 DEFUN (__token_count__, , , |
3124 "-*- texinfo -*-\n\ | |
3125 @deftypefn {Built-in Function} {} __token_count__\n\ | |
3126 Number of language tokens processed since Octave startup.\n\ | |
3127 @end deftypefn") | |
3128 { | |
3129 return octave_value (Vtoken_count); | |
3130 } | |
3131 | |
8535 | 3132 DEFUN (__lexer_debug_flag__, args, nargout, |
3133 "Undocumented internal function.") | |
3134 { | |
3135 octave_value retval; | |
3136 | |
3137 retval = set_internal_variable (lexer_debug_flag, args, nargout, | |
3138 "__lexer_debug_flag__"); | |
3139 | |
3140 return retval; | |
3141 } | |
3142 | |
1994 | 3143 /* |
3144 ;;; Local Variables: *** | |
3145 ;;; mode: C++ *** | |
3146 ;;; End: *** | |
3147 */ |