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