1994
|
1 /* |
1
|
2 |
2847
|
3 Copyright (C) 1996, 1997 John W. Eaton |
1
|
4 |
|
5 This file is part of Octave. |
|
6 |
|
7 Octave is free software; you can redistribute it and/or modify it |
|
8 under the terms of the GNU General Public License as published by the |
|
9 Free Software Foundation; either version 2, or (at your option) any |
|
10 later version. |
|
11 |
|
12 Octave is distributed in the hope that it will be useful, but WITHOUT |
|
13 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
|
14 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
|
15 for more details. |
|
16 |
|
17 You should have received a copy of the GNU General Public License |
5307
|
18 along with Octavee; see the file COPYING. If not, write to the Free |
|
19 Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA |
|
20 02110-1301, USA. |
1
|
21 |
|
22 */ |
|
23 |
4753
|
24 %option prefix = "octave_" |
|
25 |
4208
|
26 %s COMMAND_START |
|
27 %s MATRIX_START |
4240
|
28 |
|
29 %x NESTED_FUNCTION_END |
|
30 %x NESTED_FUNCTION_BEGIN |
1
|
31 |
|
32 %{ |
240
|
33 #ifdef HAVE_CONFIG_H |
1220
|
34 #include <config.h> |
240
|
35 #endif |
|
36 |
1341
|
37 #include <cctype> |
|
38 #include <cstring> |
|
39 |
5765
|
40 #include <sstream> |
1823
|
41 #include <string> |
4214
|
42 #include <stack> |
1823
|
43 |
4093
|
44 #ifdef HAVE_UNISTD_H |
|
45 #ifdef HAVE_SYS_TYPES_H |
|
46 #include <sys/types.h> |
|
47 #endif |
|
48 #include <unistd.h> |
|
49 #endif |
|
50 |
2926
|
51 #include "cmd-edit.h" |
4153
|
52 #include "quit.h" |
4910
|
53 #include "lo-mappers.h" |
2926
|
54 |
1497
|
55 // These would be alphabetical, but y.tab.h must be included before |
|
56 // oct-gperf.h and y.tab.h must be included after token.h and the tree |
|
57 // class declarations. We can't include y.tab.h in oct-gperf.h |
|
58 // because it may not be protected to allow it to be included multiple |
|
59 // times. |
|
60 |
4264
|
61 #include "Cell.h" |
3665
|
62 #include "comment-list.h" |
2181
|
63 #include "defun.h" |
1355
|
64 #include "error.h" |
4910
|
65 #include "gripes.h" |
1351
|
66 #include "input.h" |
1355
|
67 #include "lex.h" |
2891
|
68 #include "ov.h" |
1355
|
69 #include "parse.h" |
2987
|
70 #include "pt-all.h" |
2891
|
71 #include "symtab.h" |
|
72 #include "token.h" |
|
73 #include "toplev.h" |
1355
|
74 #include "utils.h" |
|
75 #include "variables.h" |
2492
|
76 #include <y.tab.h> |
|
77 #include <oct-gperf.h> |
1
|
78 |
2716
|
79 #if ! (defined (FLEX_SCANNER) \ |
|
80 && defined (YY_FLEX_MAJOR_VERSION) && YY_FLEX_MAJOR_VERSION >= 2 \ |
|
81 && defined (YY_FLEX_MINOR_VERSION) && YY_FLEX_MINOR_VERSION >= 5) |
|
82 #error lex.l requires flex version 2.5.4 or later |
|
83 #endif |
|
84 |
4753
|
85 #define yylval octave_lval |
|
86 |
|
87 // Arrange to get input via readline. |
|
88 |
|
89 #ifdef YY_INPUT |
|
90 #undef YY_INPUT |
|
91 #endif |
|
92 #define YY_INPUT(buf, result, max_size) \ |
|
93 if ((result = octave_read (buf, max_size)) < 0) \ |
|
94 YY_FATAL_ERROR ("octave_read () in flex scanner failed"); |
|
95 |
|
96 // Try to avoid crashing out completely on fatal scanner errors. |
|
97 // The call to yy_fatal_error should never happen, but it avoids a |
|
98 // `static function defined but not used' warning from gcc. |
|
99 |
|
100 #ifdef YY_FATAL_ERROR |
|
101 #undef YY_FATAL_ERROR |
|
102 #endif |
|
103 #define YY_FATAL_ERROR(msg) \ |
|
104 do \ |
|
105 { \ |
|
106 error (msg); \ |
|
107 OCTAVE_QUIT; \ |
|
108 yy_fatal_error (msg); \ |
|
109 } \ |
|
110 while (0) |
|
111 |
4910
|
112 #define COUNT_TOK_AND_RETURN(tok) \ |
|
113 do \ |
|
114 { \ |
|
115 Vtoken_count++; \ |
|
116 return tok; \ |
|
117 } \ |
|
118 while (0) |
|
119 |
4753
|
120 #define TOK_RETURN(tok) \ |
|
121 do \ |
|
122 { \ |
|
123 current_input_column += yyleng; \ |
|
124 lexer_flags.quote_is_transpose = false; \ |
|
125 lexer_flags.convert_spaces_to_comma = true; \ |
4910
|
126 COUNT_TOK_AND_RETURN (tok); \ |
4753
|
127 } \ |
|
128 while (0) |
|
129 |
|
130 #define TOK_PUSH_AND_RETURN(name, tok) \ |
|
131 do \ |
|
132 { \ |
|
133 yylval.tok_val = new token (name, input_line_number, \ |
|
134 current_input_column); \ |
|
135 token_stack.push (yylval.tok_val); \ |
|
136 TOK_RETURN (tok); \ |
|
137 } \ |
|
138 while (0) |
|
139 |
|
140 #define BIN_OP_RETURN(tok, convert) \ |
|
141 do \ |
|
142 { \ |
|
143 yylval.tok_val = new token (input_line_number, current_input_column); \ |
|
144 token_stack.push (yylval.tok_val); \ |
|
145 current_input_column += yyleng; \ |
|
146 lexer_flags.quote_is_transpose = false; \ |
|
147 lexer_flags.convert_spaces_to_comma = convert; \ |
4910
|
148 COUNT_TOK_AND_RETURN (tok); \ |
4753
|
149 } \ |
|
150 while (0) |
|
151 |
|
152 #define XBIN_OP_RETURN(tok, convert) \ |
|
153 do \ |
|
154 { \ |
|
155 gripe_matlab_incompatible_operator (yytext); \ |
|
156 BIN_OP_RETURN (tok, convert); \ |
|
157 } \ |
|
158 while (0) |
|
159 |
3883
|
160 // TRUE means that we have encountered EOF on the input stream. |
|
161 bool parser_end_of_input = false; |
|
162 |
1826
|
163 // Flags that need to be shared between the lexer and parser. |
|
164 lexical_feedback lexer_flags; |
|
165 |
1351
|
166 // Stack to hold tokens so that we can delete them when the parser is |
|
167 // reset and avoid growing forever just because we are stashing some |
|
168 // information. This has to appear before lex.h is included, because |
|
169 // one of the macros defined there uses token_stack. |
2614
|
170 // |
|
171 // XXX FIXME XXX -- this should really be static, but that causes |
|
172 // problems on some systems. |
4214
|
173 std::stack <token*> token_stack; |
1351
|
174 |
1826
|
175 // Did eat_whitespace() eat a space or tab, or a newline, or both? |
1
|
176 |
1826
|
177 typedef int yum_yum; |
1
|
178 |
1826
|
179 const yum_yum ATE_NOTHING = 0; |
|
180 const yum_yum ATE_SPACE_OR_TAB = 1; |
|
181 const yum_yum ATE_NEWLINE = 2; |
1088
|
182 |
3351
|
183 // Is the closest nesting level a square bracket, squiggly brace or a paren? |
1826
|
184 |
4214
|
185 class bracket_brace_paren_nesting_level |
1826
|
186 { |
|
187 public: |
|
188 |
4214
|
189 bracket_brace_paren_nesting_level (void) : context () { } |
1826
|
190 |
3351
|
191 ~bracket_brace_paren_nesting_level (void) { } |
|
192 |
4214
|
193 void bracket (void) { context.push (BRACKET); } |
|
194 bool is_bracket (void) |
|
195 { return ! context.empty () && context.top () == BRACKET; } |
|
196 |
|
197 void brace (void) { context.push (BRACE); } |
|
198 bool is_brace (void) |
|
199 { return ! context.empty () && context.top () == BRACE; } |
|
200 |
|
201 void paren (void) { context.push (PAREN); } |
|
202 bool is_paren (void) |
|
203 { return ! context.empty () && context.top () == PAREN; } |
|
204 |
4608
|
205 bool is_bracket_or_brace (void) |
|
206 { return (! context.empty () |
|
207 && (context.top () == BRACKET || context.top () == BRACE)); } |
|
208 |
4214
|
209 bool none (void) { return context.empty (); } |
|
210 |
|
211 void remove (void) { if (! context.empty ()) context.pop (); } |
|
212 |
|
213 void clear (void) { while (! context.empty ()) context.pop (); } |
1826
|
214 |
|
215 private: |
|
216 |
4214
|
217 std::stack<int> context; |
|
218 |
5225
|
219 static const int BRACKET; |
|
220 static const int BRACE; |
|
221 static const int PAREN; |
1826
|
222 |
3351
|
223 bracket_brace_paren_nesting_level (const bracket_brace_paren_nesting_level&); |
1826
|
224 |
3351
|
225 bracket_brace_paren_nesting_level& |
|
226 operator = (const bracket_brace_paren_nesting_level&); |
1826
|
227 }; |
|
228 |
5225
|
229 const int bracket_brace_paren_nesting_level::BRACKET = 1; |
|
230 const int bracket_brace_paren_nesting_level::BRACE = 2; |
|
231 const int bracket_brace_paren_nesting_level::PAREN = 3; |
|
232 |
3351
|
233 static bracket_brace_paren_nesting_level nesting_level; |
1
|
234 |
4037
|
235 static bool Vwarn_matlab_incompatible = false; |
|
236 |
3388
|
237 static bool Vwarn_separator_insert = false; |
|
238 |
3400
|
239 static bool Vwarn_single_quote_string = false; |
|
240 |
4910
|
241 static unsigned int Vtoken_count = 0; |
|
242 |
146
|
243 // Forward declarations for functions defined at the bottom of this |
|
244 // file. |
|
245 |
1
|
246 static void fixup_column_count (char *s); |
146
|
247 static void do_comma_insert_check (void); |
4867
|
248 static int is_keyword_token (const std::string& s); |
4238
|
249 static void prep_for_function (void); |
|
250 static void prep_for_nested_function (void); |
3523
|
251 static symbol_record *lookup_identifier (const std::string& s); |
4426
|
252 static std::string grab_help_text (void); |
2857
|
253 static bool match_any (char c, const char *s); |
3263
|
254 static bool next_token_is_sep_op (void); |
3246
|
255 static bool next_token_is_bin_op (bool spc_prev); |
|
256 static bool next_token_is_postfix_unary_op (bool spc_prev); |
3523
|
257 static std::string strip_trailing_whitespace (char *s); |
3246
|
258 static void handle_number (void); |
975
|
259 static int handle_string (char delim, int text_style = 0); |
4612
|
260 static int handle_close_bracket (bool spc_gobbled, int bracket_type); |
3974
|
261 static int handle_identifier (void); |
3096
|
262 static bool have_continuation (bool trailing_comments_ok = true); |
|
263 static bool have_ellipsis_continuation (bool trailing_comments_ok = true); |
3665
|
264 static void scan_for_comments (const char *); |
1826
|
265 static yum_yum eat_whitespace (void); |
|
266 static yum_yum eat_continuation (void); |
3388
|
267 static void maybe_warn_separator_insert (char sep); |
3400
|
268 static void gripe_single_quote_string (void); |
4037
|
269 static void gripe_matlab_incompatible (const std::string& msg); |
|
270 static void maybe_gripe_matlab_incompatible_comment (char c); |
|
271 static void gripe_matlab_incompatible_continuation (void); |
|
272 static void gripe_matlab_incompatible_operator (const std::string& op); |
1
|
273 |
|
274 %} |
|
275 |
|
276 D [0-9] |
|
277 S [ \t] |
5570
|
278 NL ((\n)|(\r)|(\r\n)) |
2042
|
279 SNL ({S}|{NL}) |
1
|
280 EL (\.\.\.) |
967
|
281 BS (\\) |
|
282 CONT ({EL}|{BS}) |
1
|
283 Im [iIjJ] |
967
|
284 CCHAR [#%] |
|
285 COMMENT ({CCHAR}.*{NL}) |
|
286 SNLCMT ({SNL}|{COMMENT}) |
|
287 NOT ((\~)|(\!)) |
4037
|
288 POW ((\*\*)|(\^)) |
|
289 EPOW (\.{POW}) |
5290
|
290 IDENT ([_$a-zA-Z][_$a-zA-Z0-9]*) |
1
|
291 EXPON ([DdEe][+-]?{D}+) |
3220
|
292 NUMBER (({D}+\.?{D}*{EXPON}?)|(\.{D}+{EXPON}?)|(0[xX][0-9a-fA-F]+)) |
1
|
293 %% |
|
294 |
4240
|
295 <NESTED_FUNCTION_END>. { |
4323
|
296 BEGIN (NESTED_FUNCTION_BEGIN); |
4410
|
297 yyunput (yytext[0], yytext); |
4910
|
298 COUNT_TOK_AND_RETURN (';'); |
4240
|
299 } |
|
300 |
|
301 <NESTED_FUNCTION_BEGIN>. { |
4323
|
302 BEGIN (INITIAL); |
4410
|
303 yyunput (yytext[0], yytext); |
4238
|
304 prep_for_nested_function (); |
4910
|
305 COUNT_TOK_AND_RETURN (FCN); |
4238
|
306 } |
|
307 |
968
|
308 %{ |
4208
|
309 // Help and other command-style functions are a pain in the ass. This |
968
|
310 // stuff needs to be simplified. May require some changes in the |
|
311 // parser too. |
|
312 %} |
|
313 |
4208
|
314 <COMMAND_START>{NL} { |
4323
|
315 BEGIN (INITIAL); |
967
|
316 current_input_column = 1; |
2857
|
317 lexer_flags.quote_is_transpose = false; |
|
318 lexer_flags.convert_spaces_to_comma = true; |
5212
|
319 lexer_flags.doing_rawcommand = false; |
4910
|
320 COUNT_TOK_AND_RETURN ('\n'); |
967
|
321 } |
1
|
322 |
4208
|
323 <COMMAND_START>[\;\,] { |
5102
|
324 if (lexer_flags.doing_rawcommand) |
5279
|
325 TOK_PUSH_AND_RETURN (yytext, SQ_STRING); |
5102
|
326 |
|
327 BEGIN (INITIAL); |
|
328 |
|
329 if (strcmp (yytext, ",") == 0) |
|
330 TOK_RETURN (','); |
967
|
331 else |
5102
|
332 TOK_RETURN (';'); |
967
|
333 } |
1
|
334 |
4208
|
335 <COMMAND_START>[\"\'] { |
975
|
336 current_input_column++; |
4910
|
337 COUNT_TOK_AND_RETURN (handle_string (yytext[0], true)); |
975
|
338 } |
|
339 |
4923
|
340 <COMMAND_START>[^#% \t\r\n\;\,\"\'][^ \t\r\n\;\,]*{S}* { |
3523
|
341 std::string tok = strip_trailing_whitespace (yytext); |
5279
|
342 TOK_PUSH_AND_RETURN (tok, SQ_STRING); |
967
|
343 } |
1
|
344 |
968
|
345 %{ |
1
|
346 // For this and the next two rules, we're looking at ']', and we |
971
|
347 // need to know if the next token is `=' or `=='. |
1
|
348 // |
|
349 // It would have been so much easier if the delimiters were simply |
|
350 // different for the expression on the left hand side of the equals |
|
351 // operator. |
971
|
352 // |
|
353 // It's also a pain in the ass to decide whether to insert a comma |
|
354 // after seeing a ']' character... |
968
|
355 %} |
|
356 |
4208
|
357 <MATRIX_START>{SNLCMT}*\]{S}* { |
3665
|
358 scan_for_comments (yytext); |
1001
|
359 fixup_column_count (yytext); |
|
360 int c = yytext[yyleng-1]; |
|
361 int cont_is_spc = eat_continuation (); |
4608
|
362 bool spc_gobbled = (cont_is_spc || c == ' ' || c == '\t'); |
5345
|
363 int tok_to_return = handle_close_bracket (spc_gobbled, ']'); |
|
364 if (spc_gobbled) |
|
365 yyunput (' ', yytext); |
|
366 COUNT_TOK_AND_RETURN (tok_to_return); |
4608
|
367 } |
|
368 |
|
369 <MATRIX_START>{SNLCMT}*\}{S}* { |
|
370 scan_for_comments (yytext); |
|
371 fixup_column_count (yytext); |
|
372 int c = yytext[yyleng-1]; |
|
373 int cont_is_spc = eat_continuation (); |
|
374 bool spc_gobbled = (cont_is_spc || c == ' ' || c == '\t'); |
5345
|
375 int tok_to_return = handle_close_bracket (spc_gobbled, '}'); |
|
376 if (spc_gobbled) |
|
377 yyunput (' ', yytext); |
|
378 COUNT_TOK_AND_RETURN (tok_to_return); |
967
|
379 } |
1
|
380 |
968
|
381 %{ |
1088
|
382 // Commas are element separators in matrix constants. If we don't |
|
383 // check for continuations here we can end up inserting too many |
|
384 // commas. |
968
|
385 %} |
|
386 |
4208
|
387 <MATRIX_START>{S}*\,{S}* { |
1088
|
388 current_input_column += yyleng; |
3388
|
389 |
1088
|
390 int tmp = eat_continuation (); |
3388
|
391 |
2857
|
392 lexer_flags.quote_is_transpose = false; |
|
393 lexer_flags.convert_spaces_to_comma = true; |
3388
|
394 |
|
395 if ((tmp & ATE_NEWLINE) == ATE_NEWLINE) |
|
396 { |
|
397 maybe_warn_separator_insert (';'); |
|
398 |
4476
|
399 yyunput (';', yytext); |
3388
|
400 } |
|
401 |
4910
|
402 COUNT_TOK_AND_RETURN (','); |
967
|
403 } |
1
|
404 |
968
|
405 %{ |
|
406 // In some cases, spaces in matrix constants can turn into commas. |
|
407 // If commas are required, spaces are not important in matrix |
1088
|
408 // constants so we just eat them. If we don't check for continuations |
|
409 // here we can end up inserting too many commas. |
968
|
410 %} |
430
|
411 |
4208
|
412 <MATRIX_START>{S}+ { |
1088
|
413 current_input_column += yyleng; |
3388
|
414 |
|
415 int tmp = eat_continuation (); |
|
416 int bin_op = next_token_is_bin_op (true); |
|
417 int postfix_un_op = next_token_is_postfix_unary_op (true); |
|
418 |
|
419 if (! (postfix_un_op || bin_op) |
4608
|
420 && nesting_level.is_bracket_or_brace () |
3388
|
421 && lexer_flags.convert_spaces_to_comma) |
967
|
422 { |
3388
|
423 if ((tmp & ATE_NEWLINE) == ATE_NEWLINE) |
|
424 { |
|
425 maybe_warn_separator_insert (';'); |
967
|
426 |
4476
|
427 yyunput (';', yytext); |
3388
|
428 } |
|
429 |
4476
|
430 lexer_flags.quote_is_transpose = false; |
|
431 lexer_flags.convert_spaces_to_comma = true; |
|
432 |
|
433 maybe_warn_separator_insert (','); |
|
434 |
4910
|
435 COUNT_TOK_AND_RETURN (','); |
967
|
436 } |
|
437 } |
430
|
438 |
968
|
439 %{ |
1088
|
440 // Semicolons are handled as row seprators in matrix constants. If we |
|
441 // don't eat whitespace here we can end up inserting too many |
|
442 // semicolons. |
968
|
443 %} |
|
444 |
4208
|
445 <MATRIX_START>{SNLCMT}*;{SNLCMT}* { |
3665
|
446 scan_for_comments (yytext); |
967
|
447 fixup_column_count (yytext); |
1001
|
448 eat_whitespace (); |
2857
|
449 lexer_flags.quote_is_transpose = false; |
|
450 lexer_flags.convert_spaces_to_comma = true; |
4910
|
451 COUNT_TOK_AND_RETURN (';'); |
967
|
452 } |
|
453 |
968
|
454 %{ |
1088
|
455 // In some cases, new lines can also become row separators. If we |
|
456 // don't eat whitespace here we can end up inserting too many |
|
457 // semicolons. |
985
|
458 %} |
|
459 |
4208
|
460 <MATRIX_START>{S}*{COMMENT}{SNLCMT}* | |
|
461 <MATRIX_START>{S}*{NL}{SNLCMT}* { |
3665
|
462 scan_for_comments (yytext); |
1082
|
463 fixup_column_count (yytext); |
1088
|
464 eat_whitespace (); |
3388
|
465 |
4476
|
466 lexer_flags.quote_is_transpose = false; |
|
467 lexer_flags.convert_spaces_to_comma = true; |
|
468 |
|
469 if (nesting_level.none ()) |
|
470 return LEXICAL_ERROR; |
985
|
471 |
4608
|
472 if (nesting_level.is_bracket_or_brace ()) |
3388
|
473 { |
|
474 maybe_warn_separator_insert (';'); |
|
475 |
4910
|
476 COUNT_TOK_AND_RETURN (';'); |
985
|
477 } |
|
478 } |
|
479 |
967
|
480 \[{S}* { |
3351
|
481 nesting_level.bracket (); |
975
|
482 |
1082
|
483 current_input_column += yyleng; |
2857
|
484 lexer_flags.quote_is_transpose = false; |
|
485 lexer_flags.convert_spaces_to_comma = true; |
975
|
486 |
5615
|
487 if (lexer_flags.defining_func && ! lexer_flags.parsed_function_name) |
|
488 lexer_flags.looking_at_return_list = true; |
|
489 else |
|
490 lexer_flags.looking_at_matrix_or_assign_lhs = true; |
|
491 |
975
|
492 promptflag--; |
|
493 eat_whitespace (); |
|
494 |
5102
|
495 lexer_flags.bracketflag++; |
|
496 BEGIN (MATRIX_START); |
|
497 COUNT_TOK_AND_RETURN ('['); |
967
|
498 } |
1
|
499 |
968
|
500 \] { |
1826
|
501 nesting_level.remove (); |
968
|
502 |
5102
|
503 TOK_RETURN (']'); |
968
|
504 } |
|
505 |
|
506 %{ |
|
507 // Imaginary numbers. |
|
508 %} |
|
509 |
|
510 {NUMBER}{Im} { |
3246
|
511 handle_number (); |
4910
|
512 COUNT_TOK_AND_RETURN (IMAG_NUM); |
968
|
513 } |
|
514 |
|
515 %{ |
|
516 // Real numbers. Don't grab the `.' part of a dot operator as part of |
|
517 // the constant. |
|
518 %} |
|
519 |
|
520 {D}+/\.[\*/\\^'] | |
|
521 {NUMBER} { |
3246
|
522 handle_number (); |
4910
|
523 COUNT_TOK_AND_RETURN (NUM); |
968
|
524 } |
|
525 |
|
526 %{ |
|
527 // Eat whitespace. Whitespace inside matrix constants is handled by |
4208
|
528 // the <MATRIX_START> start state code above. |
968
|
529 %} |
|
530 |
967
|
531 {S}* { |
|
532 current_input_column += yyleng; |
|
533 } |
|
534 |
968
|
535 %{ |
|
536 // Continuation lines. Allow comments after continuations. |
|
537 %} |
|
538 |
967
|
539 {CONT}{S}*{NL} | |
|
540 {CONT}{S}*{COMMENT} { |
4037
|
541 if (yytext[0] == '\\') |
|
542 gripe_matlab_incompatible_continuation (); |
3665
|
543 scan_for_comments (yytext); |
967
|
544 promptflag--; |
|
545 current_input_column = 1; |
|
546 } |
1
|
547 |
968
|
548 %{ |
|
549 // An ellipsis not at the end of a line is not a continuation, but |
|
550 // does have another meaning. |
|
551 %} |
|
552 |
967
|
553 {EL} { |
3973
|
554 if (lexer_flags.looking_at_parameter_list) |
3974
|
555 { |
|
556 warning ("`...' is deprecated; use varargin instead"); |
4910
|
557 COUNT_TOK_AND_RETURN (VARARGIN); |
3974
|
558 } |
3973
|
559 else if (lexer_flags.looking_at_return_list) |
3974
|
560 { |
|
561 warning ("`...' is deprecated; use varargout instead"); |
4910
|
562 COUNT_TOK_AND_RETURN (VARARGOUT); |
3974
|
563 } |
3973
|
564 else |
|
565 return LEXICAL_ERROR; |
967
|
566 } |
1
|
567 |
968
|
568 %{ |
|
569 // End of file. |
|
570 %} |
|
571 |
967
|
572 <<EOF>> { |
|
573 TOK_RETURN (END_OF_INPUT); |
|
574 } |
1
|
575 |
968
|
576 %{ |
970
|
577 // Identifiers. Truncate the token at the first space or tab but |
|
578 // don't write directly on yytext. |
968
|
579 %} |
|
580 |
967
|
581 {IDENT}{S}* { |
4238
|
582 int id_tok = handle_identifier (); |
|
583 |
|
584 if (id_tok >= 0) |
4910
|
585 COUNT_TOK_AND_RETURN (id_tok); |
967
|
586 } |
1
|
587 |
968
|
588 %{ |
4342
|
589 // Function handles. |
|
590 %} |
|
591 |
4930
|
592 "@" { |
|
593 current_input_column++; |
|
594 lexer_flags.quote_is_transpose = false; |
|
595 lexer_flags.convert_spaces_to_comma = false; |
|
596 lexer_flags.looking_at_function_handle++; |
|
597 COUNT_TOK_AND_RETURN ('@'); |
4342
|
598 } |
|
599 |
|
600 %{ |
968
|
601 // A new line character. New line characters inside matrix constants |
4208
|
602 // are handled by the <MATRIX_START> start state code above. If closest |
985
|
603 // nesting is inside parentheses, don't return a row separator. |
968
|
604 %} |
|
605 |
967
|
606 {NL} { |
|
607 current_input_column = 1; |
2857
|
608 lexer_flags.quote_is_transpose = false; |
|
609 lexer_flags.convert_spaces_to_comma = true; |
1826
|
610 if (nesting_level.none ()) |
4910
|
611 COUNT_TOK_AND_RETURN ('\n'); |
4037
|
612 else if (nesting_level.is_paren ()) |
|
613 gripe_matlab_incompatible ("bare newline inside parentheses"); |
4608
|
614 else if (nesting_level.is_bracket_or_brace ()) |
985
|
615 return LEXICAL_ERROR; |
967
|
616 } |
1
|
617 |
968
|
618 %{ |
|
619 // Single quote can either be the beginning of a string or a transpose |
|
620 // operator. |
|
621 %} |
|
622 |
967
|
623 "'" { |
|
624 current_input_column++; |
2857
|
625 lexer_flags.convert_spaces_to_comma = true; |
1
|
626 |
1826
|
627 if (lexer_flags.quote_is_transpose) |
967
|
628 { |
|
629 do_comma_insert_check (); |
4910
|
630 COUNT_TOK_AND_RETURN (QUOTE); |
967
|
631 } |
|
632 else |
4910
|
633 COUNT_TOK_AND_RETURN (handle_string ('\'')); |
967
|
634 } |
1
|
635 |
968
|
636 %{ |
971
|
637 // Double quotes always begin strings. |
|
638 %} |
|
639 |
973
|
640 \" { |
|
641 current_input_column++; |
4910
|
642 COUNT_TOK_AND_RETURN (handle_string ('"')); |
973
|
643 } |
971
|
644 |
|
645 %{ |
985
|
646 // Gobble comments. If closest nesting is inside parentheses, don't |
|
647 // return a new line. |
|
648 %} |
968
|
649 |
967
|
650 {CCHAR} { |
4426
|
651 std::string help_txt; |
|
652 |
|
653 if (! help_buf.empty ()) |
|
654 help_txt = help_buf.top (); |
|
655 |
|
656 if (help_txt.empty () |
1826
|
657 && lexer_flags.beginning_of_function |
|
658 && nesting_level.none ()) |
967
|
659 { |
3665
|
660 lexer_flags.beginning_of_function = false; |
|
661 |
4426
|
662 std::string txt = grab_help_text (); |
|
663 |
|
664 if (! help_buf.empty ()) |
|
665 help_buf.pop (); |
|
666 |
|
667 help_buf.push (txt); |
|
668 |
|
669 octave_comment_buffer::append (txt); |
967
|
670 } |
|
671 else |
|
672 { |
3665
|
673 std::string buf; |
|
674 |
|
675 bool begin_comment = true; |
|
676 |
967
|
677 int c; |
|
678 while ((c = yyinput ()) != EOF && c != '\n') |
3665
|
679 { |
|
680 if (begin_comment && (c == '#' || c == '%')) |
|
681 ; /* Skip leading comment characters. */ |
|
682 else |
3802
|
683 buf += static_cast<char> (c); |
3665
|
684 } |
|
685 |
|
686 octave_comment_buffer::append (buf); |
967
|
687 } |
440
|
688 |
967
|
689 current_input_column = 1; |
2857
|
690 lexer_flags.quote_is_transpose = false; |
|
691 lexer_flags.convert_spaces_to_comma = true; |
985
|
692 |
4037
|
693 maybe_gripe_matlab_incompatible_comment (yytext[0]); |
|
694 |
4323
|
695 if (YY_START == COMMAND_START) |
|
696 BEGIN (INITIAL); |
|
697 |
1826
|
698 if (nesting_level.none ()) |
4910
|
699 COUNT_TOK_AND_RETURN ('\n'); |
4608
|
700 else if (nesting_level.is_bracket_or_brace ()) |
4910
|
701 COUNT_TOK_AND_RETURN (';'); |
967
|
702 } |
440
|
703 |
968
|
704 %{ |
|
705 // Other operators. |
|
706 %} |
|
707 |
5102
|
708 ":" { BIN_OP_RETURN (':', false); } |
|
709 |
4037
|
710 ".+" { XBIN_OP_RETURN (EPLUS, false); } |
|
711 ".-" { XBIN_OP_RETURN (EMINUS, false); } |
2857
|
712 ".*" { BIN_OP_RETURN (EMUL, false); } |
|
713 "./" { BIN_OP_RETURN (EDIV, false); } |
|
714 ".\\" { BIN_OP_RETURN (ELEFTDIV, false); } |
4037
|
715 ".^" { BIN_OP_RETURN (EPOW, false); } |
|
716 ".**" { XBIN_OP_RETURN (EPOW, false); } |
2857
|
717 ".'" { do_comma_insert_check (); BIN_OP_RETURN (TRANSPOSE, true); } |
4037
|
718 "++" { do_comma_insert_check (); XBIN_OP_RETURN (PLUS_PLUS, true); } |
|
719 "--" { do_comma_insert_check (); XBIN_OP_RETURN (MINUS_MINUS, true); } |
2857
|
720 "<=" { BIN_OP_RETURN (EXPR_LE, false); } |
|
721 "==" { BIN_OP_RETURN (EXPR_EQ, false); } |
4037
|
722 "~=" { BIN_OP_RETURN (EXPR_NE, false); } |
|
723 "!=" { XBIN_OP_RETURN (EXPR_NE, false); } |
2857
|
724 ">=" { BIN_OP_RETURN (EXPR_GE, false); } |
2877
|
725 "&" { BIN_OP_RETURN (EXPR_AND, false); } |
2857
|
726 "|" { BIN_OP_RETURN (EXPR_OR, false); } |
|
727 "<" { BIN_OP_RETURN (EXPR_LT, false); } |
|
728 ">" { BIN_OP_RETURN (EXPR_GT, false); } |
5102
|
729 "+" { BIN_OP_RETURN ('+', false); } |
|
730 "-" { BIN_OP_RETURN ('-', false); } |
2857
|
731 "*" { BIN_OP_RETURN ('*', false); } |
|
732 "/" { BIN_OP_RETURN ('/', false); } |
|
733 "\\" { BIN_OP_RETURN (LEFTDIV, false); } |
|
734 ";" { BIN_OP_RETURN (';', true); } |
|
735 "," { BIN_OP_RETURN (',', true); } |
4037
|
736 "^" { BIN_OP_RETURN (POW, false); } |
|
737 "**" { XBIN_OP_RETURN (POW, false); } |
2857
|
738 "=" { BIN_OP_RETURN ('=', true); } |
2877
|
739 "&&" { BIN_OP_RETURN (EXPR_AND_AND, false); } |
2857
|
740 "||" { BIN_OP_RETURN (EXPR_OR_OR, false); } |
4037
|
741 "<<" { XBIN_OP_RETURN (LSHIFT, false); } |
|
742 ">>" { XBIN_OP_RETURN (RSHIFT, false); } |
967
|
743 |
|
744 {NOT} { |
4037
|
745 if (yytext[0] == '~') |
|
746 BIN_OP_RETURN (EXPR_NOT, false); |
|
747 else |
|
748 XBIN_OP_RETURN (EXPR_NOT, false); |
967
|
749 } |
1
|
750 |
967
|
751 "(" { |
4131
|
752 lexer_flags.looking_at_indirect_ref = false; |
1826
|
753 nesting_level.paren (); |
985
|
754 promptflag--; |
967
|
755 TOK_RETURN ('('); |
|
756 } |
|
757 |
|
758 ")" { |
1826
|
759 nesting_level.remove (); |
967
|
760 current_input_column++; |
2857
|
761 lexer_flags.quote_is_transpose = true; |
4608
|
762 lexer_flags.convert_spaces_to_comma = nesting_level.is_bracket_or_brace (); |
1001
|
763 do_comma_insert_check (); |
4910
|
764 COUNT_TOK_AND_RETURN (')'); |
967
|
765 } |
|
766 |
5102
|
767 "." { TOK_RETURN ('.'); } |
2066
|
768 |
4037
|
769 "+=" { XBIN_OP_RETURN (ADD_EQ, false); } |
|
770 "-=" { XBIN_OP_RETURN (SUB_EQ, false); } |
|
771 "*=" { XBIN_OP_RETURN (MUL_EQ, false); } |
|
772 "/=" { XBIN_OP_RETURN (DIV_EQ, false); } |
|
773 "\\=" { XBIN_OP_RETURN (LEFTDIV_EQ, false); } |
|
774 ".+=" { XBIN_OP_RETURN (ADD_EQ, false); } |
|
775 ".-=" { XBIN_OP_RETURN (SUB_EQ, false); } |
|
776 ".*=" { XBIN_OP_RETURN (EMUL_EQ, false); } |
|
777 "./=" { XBIN_OP_RETURN (EDIV_EQ, false); } |
|
778 ".\\=" { XBIN_OP_RETURN (ELEFTDIV_EQ, false); } |
|
779 {POW}= { XBIN_OP_RETURN (POW_EQ, false); } |
|
780 {EPOW}= { XBIN_OP_RETURN (EPOW_EQ, false); } |
|
781 "&=" { XBIN_OP_RETURN (AND_EQ, false); } |
|
782 "|=" { XBIN_OP_RETURN (OR_EQ, false); } |
|
783 "<<=" { XBIN_OP_RETURN (LSHIFT_EQ, false); } |
|
784 ">>=" { XBIN_OP_RETURN (RSHIFT_EQ, false); } |
2877
|
785 |
4608
|
786 \{{S}* { |
3351
|
787 nesting_level.brace (); |
4608
|
788 |
|
789 current_input_column += yyleng; |
|
790 lexer_flags.quote_is_transpose = false; |
|
791 lexer_flags.convert_spaces_to_comma = true; |
|
792 |
3351
|
793 promptflag--; |
4608
|
794 eat_whitespace (); |
|
795 |
4613
|
796 lexer_flags.braceflag++; |
4608
|
797 BEGIN (MATRIX_START); |
4910
|
798 COUNT_TOK_AND_RETURN ('{'); |
3351
|
799 } |
|
800 |
|
801 "}" { |
|
802 nesting_level.remove (); |
|
803 |
4608
|
804 TOK_RETURN ('}'); |
3351
|
805 } |
|
806 |
968
|
807 %{ |
2066
|
808 // Unrecognized input is a lexical error. |
968
|
809 %} |
1
|
810 |
2042
|
811 . { |
4240
|
812 // EOF happens here if we are parsing nested functions. |
|
813 |
4410
|
814 yyunput (yytext[0], yytext); |
4248
|
815 |
|
816 int c = yyinput (); |
|
817 |
|
818 if (c != EOF) |
4240
|
819 { |
|
820 current_input_column++; |
|
821 |
|
822 error ("invalid character `%s' (ASCII %d) near line %d, column %d", |
4248
|
823 undo_string_escape (static_cast<char> (c)), c, |
4240
|
824 input_line_number, current_input_column); |
|
825 |
|
826 return LEXICAL_ERROR; |
|
827 } |
|
828 else |
|
829 TOK_RETURN (END_OF_INPUT); |
2066
|
830 } |
1
|
831 |
|
832 %% |
|
833 |
767
|
834 // GAG. |
|
835 // |
|
836 // If we're reading a matrix and the next character is '[', make sure |
|
837 // that we insert a comma ahead of it. |
|
838 |
146
|
839 void |
1
|
840 do_comma_insert_check (void) |
|
841 { |
1001
|
842 int spc_gobbled = eat_continuation (); |
2970
|
843 |
1
|
844 int c = yyinput (); |
2970
|
845 |
4410
|
846 yyunput (c, yytext); |
2970
|
847 |
1001
|
848 if (spc_gobbled) |
4410
|
849 yyunput (' ', yytext); |
2970
|
850 |
3351
|
851 lexer_flags.do_comma_insert = (lexer_flags.bracketflag && c == '['); |
1
|
852 } |
|
853 |
767
|
854 // Fix things up for errors or interrupts. The parser is never called |
|
855 // recursively, so it is always safe to reinitialize its state before |
|
856 // doing any parsing. |
|
857 |
1
|
858 void |
|
859 reset_parser (void) |
|
860 { |
1826
|
861 // Start off on the right foot. |
4323
|
862 BEGIN (INITIAL); |
4318
|
863 |
3883
|
864 parser_end_of_input = false; |
4238
|
865 end_tokens_expected = 0; |
|
866 |
|
867 while (! symtab_context.empty ()) |
|
868 symtab_context.pop (); |
287
|
869 |
1826
|
870 // We do want a prompt by default. |
1
|
871 promptflag = 1; |
287
|
872 |
3351
|
873 // Error may have occurred inside some brackets, braces, or parentheses. |
985
|
874 nesting_level.clear (); |
287
|
875 |
1826
|
876 // Clear out the stack of token info used to track line and column |
|
877 // numbers. |
143
|
878 while (! token_stack.empty ()) |
4214
|
879 { |
|
880 delete token_stack.top (); |
|
881 token_stack.pop (); |
|
882 } |
287
|
883 |
1826
|
884 // Can be reset by defining a function. |
985
|
885 if (! (reading_script_file || reading_fcn_file)) |
|
886 { |
|
887 current_input_column = 1; |
2926
|
888 input_line_number = command_editor::current_command_number () - 1; |
985
|
889 } |
287
|
890 |
1826
|
891 // Only ask for input from stdin if we are expecting interactive |
|
892 // input. |
3174
|
893 if ((interactive || forced_interactive) |
3880
|
894 && ! (reading_fcn_file |
|
895 || reading_script_file |
|
896 || get_input_from_eval_string |
3174
|
897 || input_from_startup_file)) |
287
|
898 yyrestart (stdin); |
991
|
899 |
1826
|
900 // Clear the buffer for help text. |
4426
|
901 while (! help_buf.empty ()) |
|
902 help_buf.pop (); |
1755
|
903 |
1826
|
904 // Reset other flags. |
|
905 lexer_flags.init (); |
1
|
906 } |
|
907 |
767
|
908 // If we read some newlines, we need figure out what column we're |
|
909 // really looking at. |
|
910 |
1
|
911 static void |
|
912 fixup_column_count (char *s) |
|
913 { |
|
914 char c; |
|
915 while ((c = *s++) != '\0') |
|
916 { |
|
917 if (c == '\n') |
143
|
918 current_input_column = 1; |
1
|
919 else |
|
920 current_input_column++; |
|
921 } |
|
922 } |
|
923 |
767
|
924 // Include these so that we don't have to link to libfl.a. |
246
|
925 |
3332
|
926 int |
1
|
927 yywrap (void) |
|
928 { |
287
|
929 return 1; |
1
|
930 } |
|
931 |
767
|
932 // Tell us all what the current buffer is. |
|
933 |
1
|
934 YY_BUFFER_STATE |
|
935 current_buffer (void) |
|
936 { |
|
937 return YY_CURRENT_BUFFER; |
|
938 } |
|
939 |
767
|
940 // Create a new buffer. |
|
941 |
1
|
942 YY_BUFFER_STATE |
|
943 create_buffer (FILE *f) |
|
944 { |
|
945 return yy_create_buffer (f, YY_BUF_SIZE); |
|
946 } |
|
947 |
767
|
948 // Start reading a new buffer. |
|
949 |
1
|
950 void |
|
951 switch_to_buffer (YY_BUFFER_STATE buf) |
|
952 { |
|
953 yy_switch_to_buffer (buf); |
|
954 } |
|
955 |
767
|
956 // Delete a buffer. |
|
957 |
1
|
958 void |
|
959 delete_buffer (YY_BUFFER_STATE buf) |
|
960 { |
|
961 yy_delete_buffer (buf); |
|
962 } |
|
963 |
767
|
964 // Restore a buffer (for unwind-prot). |
|
965 |
1
|
966 void |
|
967 restore_input_buffer (void *buf) |
|
968 { |
2861
|
969 switch_to_buffer (static_cast<YY_BUFFER_STATE> (buf)); |
1
|
970 } |
|
971 |
767
|
972 // Delete a buffer (for unwind-prot). |
|
973 |
1
|
974 void |
|
975 delete_input_buffer (void *buf) |
|
976 { |
2861
|
977 delete_buffer (static_cast<YY_BUFFER_STATE> (buf)); |
1
|
978 } |
|
979 |
4238
|
980 static void |
|
981 prep_for_function (void) |
|
982 { |
|
983 end_tokens_expected++; |
|
984 |
|
985 // Prepare for local symbols. |
|
986 |
|
987 tmp_local_sym_tab = new symbol_table (); |
|
988 |
|
989 promptflag--; |
|
990 |
|
991 lexer_flags.defining_func = true; |
|
992 lexer_flags.parsed_function_name = false; |
|
993 lexer_flags.beginning_of_function = true; |
|
994 |
|
995 if (! (reading_fcn_file || reading_script_file)) |
|
996 input_line_number = 1; |
|
997 } |
|
998 |
|
999 static void |
|
1000 prep_for_nested_function (void) |
|
1001 { |
4240
|
1002 lexer_flags.parsing_nested_function = 1; |
4426
|
1003 help_buf.push (std::string ()); |
4238
|
1004 prep_for_function (); |
4240
|
1005 // We're still only expecting one end token for this set of functions. |
|
1006 end_tokens_expected--; |
4238
|
1007 yylval.tok_val = new token (input_line_number, current_input_column); |
|
1008 token_stack.push (yylval.tok_val); |
|
1009 } |
|
1010 |
|
1011 // Handle keywords. Return -1 if the keyword should be ignored. |
767
|
1012 |
1
|
1013 static int |
4867
|
1014 is_keyword_token (const std::string& s) |
1
|
1015 { |
3805
|
1016 int l = input_line_number; |
|
1017 int c = current_input_column; |
|
1018 |
1823
|
1019 int len = s.length (); |
922
|
1020 |
5088
|
1021 const octave_kw *kw = octave_kw_hash::in_word_set (s.c_str (), len); |
191
|
1022 |
1497
|
1023 if (kw) |
143
|
1024 { |
1497
|
1025 yylval.tok_val = 0; |
|
1026 |
|
1027 switch (kw->kw_id) |
|
1028 { |
|
1029 case all_va_args_kw: |
|
1030 case break_kw: |
2764
|
1031 case case_kw: |
1497
|
1032 case catch_kw: |
|
1033 case continue_kw: |
|
1034 case else_kw: |
|
1035 case elseif_kw: |
|
1036 case global_kw: |
2764
|
1037 case otherwise_kw: |
1497
|
1038 case return_kw: |
2846
|
1039 case static_kw: |
3484
|
1040 case until_kw: |
1497
|
1041 case unwind_protect_cleanup_kw: |
|
1042 break; |
|
1043 |
|
1044 case end_kw: |
4234
|
1045 if (lexer_flags.looking_at_object_index) |
|
1046 return 0; |
|
1047 else |
4238
|
1048 { |
|
1049 if (reading_fcn_file && end_tokens_expected == 1) |
|
1050 return -1; |
|
1051 else |
|
1052 { |
|
1053 yylval.tok_val = new token (token::simple_end, l, c); |
|
1054 end_tokens_expected--; |
|
1055 } |
|
1056 } |
1497
|
1057 break; |
|
1058 |
|
1059 case end_try_catch_kw: |
4238
|
1060 end_tokens_expected--; |
1497
|
1061 yylval.tok_val = new token (token::try_catch_end, l, c); |
|
1062 break; |
|
1063 |
|
1064 case end_unwind_protect_kw: |
4238
|
1065 end_tokens_expected--; |
1497
|
1066 yylval.tok_val = new token (token::unwind_protect_end, l, c); |
|
1067 break; |
|
1068 |
|
1069 case endfor_kw: |
4238
|
1070 end_tokens_expected--; |
1497
|
1071 yylval.tok_val = new token (token::for_end, l, c); |
|
1072 break; |
|
1073 |
|
1074 case endfunction_kw: |
4238
|
1075 { |
|
1076 if (reading_fcn_file && end_tokens_expected == 1) |
|
1077 return -1; |
|
1078 else |
|
1079 { |
|
1080 yylval.tok_val = new token (token::function_end, l, c); |
|
1081 end_tokens_expected--; |
|
1082 } |
|
1083 } |
1497
|
1084 break; |
|
1085 |
|
1086 case endif_kw: |
4238
|
1087 end_tokens_expected--; |
1497
|
1088 yylval.tok_val = new token (token::if_end, l, c); |
|
1089 break; |
|
1090 |
2764
|
1091 case endswitch_kw: |
4238
|
1092 end_tokens_expected--; |
2764
|
1093 yylval.tok_val = new token (token::switch_end, l, c); |
|
1094 break; |
|
1095 |
1497
|
1096 case endwhile_kw: |
4238
|
1097 end_tokens_expected--; |
1497
|
1098 yylval.tok_val = new token (token::while_end, l, c); |
|
1099 break; |
|
1100 |
|
1101 case for_kw: |
|
1102 case while_kw: |
4238
|
1103 end_tokens_expected++; |
|
1104 // Fall through... |
|
1105 |
|
1106 case do_kw: |
1497
|
1107 promptflag--; |
1826
|
1108 lexer_flags.looping++; |
1497
|
1109 break; |
|
1110 |
|
1111 case if_kw: |
|
1112 case try_kw: |
2764
|
1113 case switch_kw: |
1497
|
1114 case unwind_protect_kw: |
4238
|
1115 end_tokens_expected++; |
1497
|
1116 promptflag--; |
|
1117 break; |
|
1118 |
|
1119 case function_kw: |
4238
|
1120 { |
|
1121 if (lexer_flags.defining_func) |
|
1122 { |
|
1123 if (reading_fcn_file) |
|
1124 { |
|
1125 if (lexer_flags.parsing_nested_function) |
|
1126 { |
4323
|
1127 BEGIN (NESTED_FUNCTION_END); |
4240
|
1128 |
4238
|
1129 yylval.tok_val = new token (token::function_end, l, c); |
4240
|
1130 token_stack.push (yylval.tok_val); |
|
1131 |
|
1132 return END; |
4238
|
1133 } |
|
1134 else |
|
1135 { |
|
1136 prep_for_nested_function (); |
4240
|
1137 |
4238
|
1138 return FCN; |
|
1139 } |
|
1140 } |
|
1141 else |
|
1142 { |
|
1143 error ("nested functions not implemented in this context"); |
|
1144 |
|
1145 if ((reading_fcn_file || reading_script_file) |
|
1146 && ! curr_fcn_file_name.empty ()) |
|
1147 error ("near line %d of file `%s.m'", |
|
1148 input_line_number, curr_fcn_file_name.c_str ()); |
|
1149 else |
|
1150 error ("near line %d", input_line_number); |
|
1151 |
|
1152 return LEXICAL_ERROR; |
|
1153 } |
|
1154 } |
|
1155 else |
|
1156 prep_for_function (); |
|
1157 } |
1497
|
1158 break; |
|
1159 |
3174
|
1160 case magic_file_kw: |
|
1161 { |
|
1162 if ((reading_fcn_file || reading_script_file) |
|
1163 && ! curr_fcn_file_full_name.empty ()) |
|
1164 yylval.tok_val = new token (curr_fcn_file_full_name, l, c); |
|
1165 else |
|
1166 yylval.tok_val = new token ("stdin", l, c); |
|
1167 } |
|
1168 break; |
|
1169 |
|
1170 case magic_line_kw: |
|
1171 yylval.tok_val = new token (static_cast<double> (l), "", l, c); |
|
1172 break; |
|
1173 |
3974
|
1174 case varargin_kw: |
|
1175 if (! lexer_flags.looking_at_parameter_list) |
|
1176 return 0; |
|
1177 break; |
|
1178 |
|
1179 case varargout_kw: |
4678
|
1180 if (! (lexer_flags.looking_at_return_list |
|
1181 || (lexer_flags.defining_func |
|
1182 && ! lexer_flags.parsed_function_name))) |
3974
|
1183 return 0; |
|
1184 break; |
|
1185 |
1497
|
1186 default: |
|
1187 panic_impossible (); |
|
1188 } |
|
1189 |
|
1190 if (! yylval.tok_val) |
|
1191 yylval.tok_val = new token (l, c); |
|
1192 |
476
|
1193 token_stack.push (yylval.tok_val); |
1497
|
1194 |
|
1195 return kw->tok; |
143
|
1196 } |
1
|
1197 |
|
1198 return 0; |
|
1199 } |
|
1200 |
767
|
1201 // Try to find an identifier. All binding to global or builtin |
|
1202 // variables occurs when expressions are evaluated. |
|
1203 |
1
|
1204 static symbol_record * |
3523
|
1205 lookup_identifier (const std::string& name) |
1
|
1206 { |
4238
|
1207 std::string sym_name = name; |
|
1208 |
|
1209 if (curr_sym_tab == fbi_sym_tab |
|
1210 && lexer_flags.parsing_nested_function) |
|
1211 sym_name = parent_function_name + ":" + sym_name; |
|
1212 |
|
1213 return curr_sym_tab->lookup (sym_name, true); |
1
|
1214 } |
|
1215 |
2702
|
1216 static bool |
3523
|
1217 is_variable (const std::string& name) |
2702
|
1218 { |
2856
|
1219 symbol_record *sr = curr_sym_tab->lookup (name); |
2702
|
1220 |
|
1221 return sr && sr->is_variable (); |
|
1222 } |
|
1223 |
|
1224 static void |
3523
|
1225 force_local_variable (const std::string& name) |
2702
|
1226 { |
4101
|
1227 if (! is_variable (name)) |
|
1228 curr_sym_tab->clear (name); |
|
1229 |
2856
|
1230 symbol_record *sr = curr_sym_tab->lookup (name, true); |
2702
|
1231 |
|
1232 if (sr) |
|
1233 sr->define (octave_value ()); |
|
1234 } |
|
1235 |
4426
|
1236 // Grab the help text from an function file. |
767
|
1237 |
3427
|
1238 // XXX FIXME XXX -- gobble_leading_white_space() in parse.y |
2300
|
1239 // duplicates some of this code! |
|
1240 |
4426
|
1241 static std::string |
1
|
1242 grab_help_text (void) |
|
1243 { |
4426
|
1244 std::string buf; |
1019
|
1245 |
2300
|
1246 bool begin_comment = true; |
|
1247 bool in_comment = true; |
3427
|
1248 bool discard_space = true; |
3665
|
1249 |
1019
|
1250 int c = 0; |
1
|
1251 |
1019
|
1252 while ((c = yyinput ()) != EOF) |
|
1253 { |
2300
|
1254 if (begin_comment) |
|
1255 { |
|
1256 if (c == '%' || c == '#') |
|
1257 continue; |
3427
|
1258 else if (discard_space && c == ' ') |
|
1259 { |
|
1260 discard_space = false; |
|
1261 continue; |
|
1262 } |
2300
|
1263 else |
|
1264 begin_comment = false; |
|
1265 } |
|
1266 |
1019
|
1267 if (in_comment) |
1
|
1268 { |
4426
|
1269 buf += static_cast<char> (c); |
1755
|
1270 |
1019
|
1271 if (c == '\n') |
3427
|
1272 { |
|
1273 in_comment = false; |
|
1274 discard_space = true; |
|
1275 } |
1019
|
1276 } |
|
1277 else |
|
1278 { |
|
1279 switch (c) |
991
|
1280 { |
4037
|
1281 case '#': |
1019
|
1282 case '%': |
4037
|
1283 maybe_gripe_matlab_incompatible_comment (yytext[0]); |
2300
|
1284 in_comment = true; |
|
1285 begin_comment = true; |
1019
|
1286 break; |
777
|
1287 |
1019
|
1288 case ' ': |
|
1289 case '\t': |
|
1290 break; |
777
|
1291 |
1019
|
1292 default: |
|
1293 goto done; |
1
|
1294 } |
|
1295 } |
1019
|
1296 } |
991
|
1297 |
1019
|
1298 done: |
991
|
1299 |
1019
|
1300 if (c) |
4410
|
1301 yyunput (c, yytext); |
4426
|
1302 |
|
1303 return buf; |
1
|
1304 } |
|
1305 |
767
|
1306 // Return 1 if the given character matches any character in the given |
|
1307 // string. |
|
1308 |
2857
|
1309 static bool |
2804
|
1310 match_any (char c, const char *s) |
1
|
1311 { |
|
1312 char tmp; |
|
1313 while ((tmp = *s++) != '\0') |
|
1314 { |
|
1315 if (c == tmp) |
2857
|
1316 return true; |
1
|
1317 } |
2857
|
1318 return false; |
1
|
1319 } |
|
1320 |
767
|
1321 // Given information about the spacing surrounding an operator, |
|
1322 // return 1 if it looks like it should be treated as a binary |
|
1323 // operator. For example, |
|
1324 // |
3774
|
1325 // [ 1 + 2 ] or [ 1+ 2] or [ 1+2 ] ==> binary |
|
1326 // |
|
1327 // [ 1 +2 ] ==> unary |
767
|
1328 |
2857
|
1329 static bool |
3246
|
1330 looks_like_bin_op (bool spc_prev, int next_char) |
1
|
1331 { |
3246
|
1332 bool spc_next = (next_char == ' ' || next_char == '\t'); |
|
1333 |
608
|
1334 return ((spc_prev && spc_next) || ! spc_prev); |
1
|
1335 } |
|
1336 |
3263
|
1337 // Recognize separators. If the separator is a CRLF pair, it is |
|
1338 // replaced by a single LF. |
|
1339 |
|
1340 static bool |
|
1341 next_token_is_sep_op (void) |
|
1342 { |
|
1343 bool retval = false; |
|
1344 |
|
1345 int c1 = yyinput (); |
|
1346 |
|
1347 if (c1 == '\r') |
|
1348 { |
|
1349 int c2 = yyinput (); |
|
1350 |
|
1351 if (c2 == '\n') |
|
1352 { |
|
1353 c1 = '\n'; |
|
1354 |
|
1355 retval = true; |
|
1356 } |
|
1357 else |
4410
|
1358 yyunput (c2, yytext); |
3263
|
1359 } |
|
1360 else |
|
1361 retval = match_any (c1, ",;\n]"); |
|
1362 |
4410
|
1363 yyunput (c1, yytext); |
3263
|
1364 |
|
1365 return retval; |
|
1366 } |
|
1367 |
767
|
1368 // Try to determine if the next token should be treated as a postfix |
|
1369 // unary operator. This is ugly, but it seems to do the right thing. |
|
1370 |
2857
|
1371 static bool |
3246
|
1372 next_token_is_postfix_unary_op (bool spc_prev) |
1
|
1373 { |
2857
|
1374 bool un_op = false; |
1
|
1375 |
|
1376 int c0 = yyinput (); |
|
1377 |
3246
|
1378 if (c0 == '\'' && ! spc_prev) |
|
1379 { |
|
1380 un_op = true; |
|
1381 } |
|
1382 else if (c0 == '.') |
|
1383 { |
|
1384 int c1 = yyinput (); |
|
1385 un_op = (c1 == '\''); |
4410
|
1386 yyunput (c1, yytext); |
3246
|
1387 } |
4613
|
1388 else if (c0 == '+') |
|
1389 { |
|
1390 int c1 = yyinput (); |
|
1391 un_op = (c1 == '+'); |
|
1392 yyunput (c1, yytext); |
|
1393 } |
|
1394 else if (c0 == '-') |
|
1395 { |
|
1396 int c1 = yyinput (); |
|
1397 un_op = (c1 == '-'); |
|
1398 yyunput (c1, yytext); |
|
1399 } |
1
|
1400 |
4410
|
1401 yyunput (c0, yytext); |
1
|
1402 |
|
1403 return un_op; |
|
1404 } |
|
1405 |
767
|
1406 // Try to determine if the next token should be treated as a binary |
3246
|
1407 // operator. |
1521
|
1408 // |
3246
|
1409 // This kluge exists because whitespace is not always ignored inside |
3774
|
1410 // the square brackets that are used to create matrix objects (though |
|
1411 // spacing only really matters in the cases that can be interpreted |
|
1412 // either as binary ops or prefix unary ops: currently just +, -). |
|
1413 // |
3779
|
1414 // Note that a line continuation directly following a + or - operator |
|
1415 // (e.g., the characters '[' 'a' ' ' '+' '\' LFD 'b' ']') will be |
|
1416 // parsed as a binary operator. |
767
|
1417 |
2857
|
1418 static bool |
3246
|
1419 next_token_is_bin_op (bool spc_prev) |
1
|
1420 { |
2857
|
1421 bool bin_op = false; |
1
|
1422 |
|
1423 int c0 = yyinput (); |
|
1424 |
|
1425 switch (c0) |
|
1426 { |
777
|
1427 case '+': |
|
1428 case '-': |
3774
|
1429 { |
|
1430 int c1 = yyinput (); |
|
1431 |
|
1432 switch (c1) |
|
1433 { |
|
1434 case '+': |
|
1435 case '-': |
|
1436 // Unary ops, spacing doesn't matter. |
|
1437 break; |
|
1438 |
|
1439 case '=': |
|
1440 // Binary ops, spacing doesn't matter. |
|
1441 bin_op = true; |
|
1442 break; |
|
1443 |
|
1444 default: |
|
1445 // Could be either, spacing matters. |
|
1446 bin_op = looks_like_bin_op (spc_prev, c1); |
|
1447 break; |
|
1448 } |
|
1449 |
4410
|
1450 yyunput (c1, yytext); |
3774
|
1451 } |
|
1452 break; |
|
1453 |
|
1454 case ':': |
3246
|
1455 case '/': |
|
1456 case '\\': |
|
1457 case '^': |
3774
|
1458 // Always a binary op (may also include /=, \=, and ^=). |
|
1459 bin_op = true; |
1276
|
1460 break; |
|
1461 |
3246
|
1462 // .+ .- ./ .\ .^ .* .** |
1554
|
1463 case '.': |
|
1464 { |
|
1465 int c1 = yyinput (); |
3246
|
1466 |
3774
|
1467 if (match_any (c1, "+-/\\^*")) |
|
1468 // Always a binary op (may also include .+=, .-=, ./=, ...). |
|
1469 bin_op = true; |
3698
|
1470 else if (! isdigit (c1) && c1 != ' ' && c1 != '\t' && c1 != '.') |
3774
|
1471 // A structure element reference is a binary op. |
|
1472 bin_op = true; |
3246
|
1473 |
4410
|
1474 yyunput (c1, yytext); |
1554
|
1475 } |
|
1476 break; |
|
1477 |
3246
|
1478 // = == & && | || * ** |
|
1479 case '=': |
1
|
1480 case '&': |
3246
|
1481 case '|': |
1
|
1482 case '*': |
3774
|
1483 // Always a binary op (may also include ==, &&, ||, **). |
|
1484 bin_op = true; |
3246
|
1485 break; |
|
1486 |
3774
|
1487 // < <= <> > >= |
1
|
1488 case '<': |
|
1489 case '>': |
3774
|
1490 // Always a binary op (may also include <=, <>, >=). |
|
1491 bin_op = true; |
|
1492 break; |
|
1493 |
|
1494 // ~= != |
777
|
1495 case '~': |
|
1496 case '!': |
3246
|
1497 { |
|
1498 int c1 = yyinput (); |
|
1499 |
3774
|
1500 // ~ and ! can be unary ops, so require following =. |
|
1501 if (c1 == '=') |
|
1502 bin_op = true; |
3246
|
1503 |
4410
|
1504 yyunput (c1, yytext); |
3246
|
1505 } |
1
|
1506 break; |
|
1507 |
|
1508 default: |
1276
|
1509 break; |
1
|
1510 } |
|
1511 |
4410
|
1512 yyunput (c0, yytext); |
1
|
1513 |
|
1514 return bin_op; |
|
1515 } |
|
1516 |
767
|
1517 // Used to delete trailing white space from tokens. |
|
1518 |
3536
|
1519 static std::string |
1
|
1520 strip_trailing_whitespace (char *s) |
|
1521 { |
3523
|
1522 std::string retval = s; |
1
|
1523 |
1823
|
1524 size_t pos = retval.find_first_of (" \t"); |
1
|
1525 |
1823
|
1526 if (pos != NPOS) |
|
1527 retval.resize (pos); |
1
|
1528 |
|
1529 return retval; |
|
1530 } |
|
1531 |
3665
|
1532 static void |
|
1533 scan_for_comments (const char *text) |
|
1534 { |
|
1535 std::string comment_buf; |
|
1536 |
|
1537 bool in_comment = false; |
|
1538 bool beginning_of_comment = false; |
|
1539 |
|
1540 int len = strlen (text); |
|
1541 int i = 0; |
|
1542 |
|
1543 while (i < len) |
|
1544 { |
|
1545 char c = text[i++]; |
|
1546 |
|
1547 switch (c) |
|
1548 { |
|
1549 case '%': |
|
1550 case '#': |
|
1551 if (in_comment) |
|
1552 { |
|
1553 if (! beginning_of_comment) |
3802
|
1554 comment_buf += static_cast<char> (c); |
3665
|
1555 } |
|
1556 else |
|
1557 { |
4037
|
1558 maybe_gripe_matlab_incompatible_comment (c); |
3665
|
1559 in_comment = true; |
|
1560 beginning_of_comment = true; |
|
1561 } |
|
1562 break; |
|
1563 |
|
1564 case '\n': |
|
1565 if (in_comment) |
|
1566 { |
3802
|
1567 comment_buf += static_cast<char> (c); |
3665
|
1568 octave_comment_buffer::append (comment_buf); |
|
1569 comment_buf.resize (0); |
|
1570 in_comment = false; |
|
1571 beginning_of_comment = false; |
|
1572 } |
|
1573 break; |
|
1574 |
|
1575 case '\r': |
|
1576 if (in_comment) |
3802
|
1577 comment_buf += static_cast<char> (c); |
3665
|
1578 if (i < len) |
|
1579 { |
|
1580 c = text[i++]; |
|
1581 |
|
1582 if (c == '\n') |
|
1583 { |
|
1584 if (in_comment) |
|
1585 { |
3802
|
1586 comment_buf += static_cast<char> (c); |
3665
|
1587 octave_comment_buffer::append (comment_buf); |
|
1588 in_comment = false; |
|
1589 beginning_of_comment = false; |
|
1590 } |
|
1591 } |
|
1592 } |
|
1593 |
|
1594 default: |
|
1595 if (in_comment) |
|
1596 { |
3802
|
1597 comment_buf += static_cast<char> (c); |
3665
|
1598 beginning_of_comment = false; |
|
1599 } |
|
1600 break; |
|
1601 } |
|
1602 } |
|
1603 |
|
1604 if (! comment_buf.empty ()) |
|
1605 octave_comment_buffer::append (comment_buf); |
|
1606 } |
|
1607 |
1001
|
1608 // Discard whitespace, including comments and continuations. |
1088
|
1609 // |
|
1610 // Return value is logical OR of the following values: |
|
1611 // |
1826
|
1612 // ATE_NOTHING : no spaces to eat |
1088
|
1613 // ATE_SPACE_OR_TAB : space or tab in input |
|
1614 // ATE_NEWLINE : bare new line in input |
1001
|
1615 |
1826
|
1616 static yum_yum |
975
|
1617 eat_whitespace (void) |
|
1618 { |
1826
|
1619 yum_yum retval = ATE_NOTHING; |
3665
|
1620 |
|
1621 std::string comment_buf; |
|
1622 |
2857
|
1623 bool in_comment = false; |
3665
|
1624 bool beginning_of_comment = false; |
|
1625 |
|
1626 int c = 0; |
|
1627 |
975
|
1628 while ((c = yyinput ()) != EOF) |
|
1629 { |
|
1630 current_input_column++; |
|
1631 |
|
1632 switch (c) |
|
1633 { |
|
1634 case ' ': |
|
1635 case '\t': |
3665
|
1636 if (in_comment) |
|
1637 { |
3802
|
1638 comment_buf += static_cast<char> (c); |
3665
|
1639 beginning_of_comment = false; |
|
1640 } |
1088
|
1641 retval |= ATE_SPACE_OR_TAB; |
975
|
1642 break; |
|
1643 |
|
1644 case '\n': |
1088
|
1645 retval |= ATE_NEWLINE; |
3665
|
1646 if (in_comment) |
|
1647 { |
3802
|
1648 comment_buf += static_cast<char> (c); |
3665
|
1649 octave_comment_buffer::append (comment_buf); |
|
1650 comment_buf.resize (0); |
|
1651 in_comment = false; |
|
1652 beginning_of_comment = false; |
|
1653 } |
975
|
1654 current_input_column = 0; |
|
1655 break; |
|
1656 |
|
1657 case '#': |
|
1658 case '%': |
3665
|
1659 if (in_comment) |
|
1660 { |
|
1661 if (! beginning_of_comment) |
3802
|
1662 comment_buf += static_cast<char> (c); |
3665
|
1663 } |
|
1664 else |
|
1665 { |
4037
|
1666 maybe_gripe_matlab_incompatible_comment (c); |
3665
|
1667 in_comment = true; |
|
1668 beginning_of_comment = true; |
|
1669 } |
975
|
1670 break; |
|
1671 |
1001
|
1672 case '.': |
|
1673 if (in_comment) |
3665
|
1674 { |
3802
|
1675 comment_buf += static_cast<char> (c); |
3665
|
1676 beginning_of_comment = false; |
|
1677 break; |
|
1678 } |
1001
|
1679 else |
|
1680 { |
|
1681 if (have_ellipsis_continuation ()) |
|
1682 break; |
|
1683 else |
|
1684 goto done; |
|
1685 } |
|
1686 |
|
1687 case '\\': |
|
1688 if (in_comment) |
3665
|
1689 { |
3802
|
1690 comment_buf += static_cast<char> (c); |
3665
|
1691 beginning_of_comment = false; |
|
1692 break; |
|
1693 } |
1001
|
1694 else |
|
1695 { |
3105
|
1696 if (have_continuation ()) |
1001
|
1697 break; |
|
1698 else |
|
1699 goto done; |
|
1700 } |
|
1701 |
975
|
1702 default: |
|
1703 if (in_comment) |
3665
|
1704 { |
3802
|
1705 comment_buf += static_cast<char> (c); |
3665
|
1706 beginning_of_comment = false; |
|
1707 break; |
|
1708 } |
975
|
1709 else |
|
1710 goto done; |
|
1711 } |
|
1712 } |
|
1713 |
3665
|
1714 if (! comment_buf.empty ()) |
|
1715 octave_comment_buffer::append (comment_buf); |
|
1716 |
975
|
1717 done: |
4410
|
1718 yyunput (c, yytext); |
1082
|
1719 current_input_column--; |
1001
|
1720 return retval; |
975
|
1721 } |
|
1722 |
3220
|
1723 static inline bool |
|
1724 looks_like_hex (const char *s, int len) |
|
1725 { |
|
1726 return (len > 2 && s[0] == '0' && (s[1] == 'x' || s[1] == 'X')); |
|
1727 } |
|
1728 |
975
|
1729 static void |
3246
|
1730 handle_number (void) |
972
|
1731 { |
3220
|
1732 double value = 0.0; |
|
1733 int nread = 0; |
|
1734 |
3598
|
1735 if (looks_like_hex (yytext, strlen (yytext))) |
3220
|
1736 { |
|
1737 unsigned long ival; |
3598
|
1738 |
|
1739 nread = sscanf (yytext, "%lx", &ival); |
|
1740 |
3220
|
1741 value = static_cast<double> (ival); |
|
1742 } |
|
1743 else |
3598
|
1744 { |
|
1745 char *tmp = strsave (yytext); |
|
1746 |
|
1747 char *idx = strpbrk (tmp, "Dd"); |
2621
|
1748 |
3598
|
1749 if (idx) |
|
1750 *idx = 'e'; |
|
1751 |
|
1752 nread = sscanf (tmp, "%lf", &value); |
|
1753 |
|
1754 delete [] tmp; |
|
1755 } |
972
|
1756 |
1826
|
1757 // If yytext doesn't contain a valid number, we are in deep doo doo. |
985
|
1758 |
972
|
1759 assert (nread == 1); |
|
1760 |
3988
|
1761 lexer_flags.quote_is_transpose = true; |
|
1762 lexer_flags.convert_spaces_to_comma = true; |
972
|
1763 |
|
1764 yylval.tok_val = new token (value, yytext, input_line_number, |
|
1765 current_input_column); |
|
1766 |
|
1767 token_stack.push (yylval.tok_val); |
|
1768 |
|
1769 current_input_column += yyleng; |
|
1770 |
|
1771 do_comma_insert_check (); |
|
1772 } |
|
1773 |
1001
|
1774 // We have seen a backslash and need to find out if it should be |
|
1775 // treated as a continuation character. If so, this eats it, up to |
|
1776 // and including the new line character. |
|
1777 // |
973
|
1778 // Match whitespace only, followed by a comment character or newline. |
|
1779 // Once a comment character is found, discard all input until newline. |
|
1780 // If non-whitespace characters are found before comment |
|
1781 // characters, return 0. Otherwise, return 1. |
|
1782 |
2857
|
1783 static bool |
3096
|
1784 have_continuation (bool trailing_comments_ok) |
973
|
1785 { |
5765
|
1786 std::ostringstream buf; |
973
|
1787 |
3665
|
1788 std::string comment_buf; |
|
1789 |
2857
|
1790 bool in_comment = false; |
3665
|
1791 bool beginning_of_comment = false; |
|
1792 |
|
1793 int c = 0; |
|
1794 |
973
|
1795 while ((c = yyinput ()) != EOF) |
|
1796 { |
3802
|
1797 buf << static_cast<char> (c); |
973
|
1798 |
|
1799 switch (c) |
|
1800 { |
|
1801 case ' ': |
|
1802 case '\t': |
3665
|
1803 if (in_comment) |
|
1804 { |
3802
|
1805 comment_buf += static_cast<char> (c); |
3665
|
1806 beginning_of_comment = false; |
|
1807 } |
973
|
1808 break; |
|
1809 |
|
1810 case '%': |
|
1811 case '#': |
1091
|
1812 if (trailing_comments_ok) |
3665
|
1813 { |
|
1814 if (in_comment) |
|
1815 { |
|
1816 if (! beginning_of_comment) |
3802
|
1817 comment_buf += static_cast<char> (c); |
3665
|
1818 } |
|
1819 else |
|
1820 { |
4037
|
1821 maybe_gripe_matlab_incompatible_comment (c); |
3665
|
1822 in_comment = true; |
|
1823 beginning_of_comment = true; |
|
1824 } |
|
1825 } |
1091
|
1826 else |
|
1827 goto cleanup; |
973
|
1828 break; |
|
1829 |
|
1830 case '\n': |
3665
|
1831 if (in_comment) |
|
1832 { |
3802
|
1833 comment_buf += static_cast<char> (c); |
3665
|
1834 octave_comment_buffer::append (comment_buf); |
|
1835 } |
975
|
1836 current_input_column = 0; |
1001
|
1837 promptflag--; |
4037
|
1838 gripe_matlab_incompatible_continuation (); |
2857
|
1839 return true; |
973
|
1840 |
3263
|
1841 case '\r': |
3665
|
1842 if (in_comment) |
3802
|
1843 comment_buf += static_cast<char> (c); |
3263
|
1844 c = yyinput (); |
|
1845 if (c == EOF) |
|
1846 break; |
|
1847 else if (c == '\n') |
|
1848 { |
3665
|
1849 if (in_comment) |
|
1850 { |
3802
|
1851 comment_buf += static_cast<char> (c); |
3665
|
1852 octave_comment_buffer::append (comment_buf); |
|
1853 } |
3263
|
1854 current_input_column = 0; |
|
1855 promptflag--; |
4037
|
1856 gripe_matlab_incompatible_continuation (); |
3263
|
1857 return true; |
3665
|
1858 } |
3263
|
1859 |
3802
|
1860 // Fall through... |
|
1861 |
973
|
1862 default: |
3665
|
1863 if (in_comment) |
|
1864 { |
3802
|
1865 comment_buf += static_cast<char> (c); |
3665
|
1866 beginning_of_comment = false; |
|
1867 } |
|
1868 else |
1091
|
1869 goto cleanup; |
|
1870 break; |
973
|
1871 } |
|
1872 } |
|
1873 |
4410
|
1874 yyunput (c, yytext); |
2857
|
1875 return false; |
973
|
1876 |
3096
|
1877 cleanup: |
4051
|
1878 |
5765
|
1879 std::string s = buf.str (); |
4051
|
1880 |
|
1881 int len = s.length (); |
|
1882 while (len--) |
4410
|
1883 yyunput (s[len], yytext); |
3096
|
1884 |
2857
|
1885 return false; |
973
|
1886 } |
|
1887 |
1001
|
1888 // We have seen a `.' and need to see if it is the start of a |
|
1889 // continuation. If so, this eats it, up to and including the new |
|
1890 // line character. |
|
1891 |
2857
|
1892 static bool |
3096
|
1893 have_ellipsis_continuation (bool trailing_comments_ok) |
973
|
1894 { |
|
1895 char c1 = yyinput (); |
|
1896 if (c1 == '.') |
|
1897 { |
|
1898 char c2 = yyinput (); |
1091
|
1899 if (c2 == '.' && have_continuation (trailing_comments_ok)) |
2857
|
1900 return true; |
973
|
1901 else |
|
1902 { |
4410
|
1903 yyunput (c2, yytext); |
|
1904 yyunput (c1, yytext); |
973
|
1905 } |
|
1906 } |
|
1907 else |
4410
|
1908 yyunput (c1, yytext); |
973
|
1909 |
2857
|
1910 return false; |
973
|
1911 } |
|
1912 |
1001
|
1913 // See if we have a continuation line. If so, eat it and the leading |
|
1914 // whitespace on the next line. |
1088
|
1915 // |
|
1916 // Return value is the same as described for eat_whitespace(). |
1001
|
1917 |
1826
|
1918 static yum_yum |
1001
|
1919 eat_continuation (void) |
|
1920 { |
1826
|
1921 int retval = ATE_NOTHING; |
3665
|
1922 |
1001
|
1923 int c = yyinput (); |
3665
|
1924 |
1001
|
1925 if ((c == '.' && have_ellipsis_continuation ()) |
3105
|
1926 || (c == '\\' && have_continuation ())) |
1001
|
1927 retval = eat_whitespace (); |
|
1928 else |
4410
|
1929 yyunput (c, yytext); |
1001
|
1930 |
|
1931 return retval; |
|
1932 } |
|
1933 |
973
|
1934 static int |
975
|
1935 handle_string (char delim, int text_style) |
973
|
1936 { |
5765
|
1937 std::ostringstream buf; |
973
|
1938 |
3805
|
1939 int bos_line = input_line_number; |
|
1940 int bos_col = current_input_column; |
|
1941 |
973
|
1942 int c; |
1031
|
1943 int escape_pending = 0; |
973
|
1944 |
|
1945 while ((c = yyinput ()) != EOF) |
|
1946 { |
|
1947 current_input_column++; |
|
1948 |
3105
|
1949 if (c == '\\') |
973
|
1950 { |
5359
|
1951 if (delim == '\'' || escape_pending) |
1053
|
1952 { |
3802
|
1953 buf << static_cast<char> (c); |
1053
|
1954 escape_pending = 0; |
|
1955 } |
|
1956 else |
|
1957 { |
3096
|
1958 if (have_continuation (false)) |
1053
|
1959 escape_pending = 0; |
|
1960 else |
|
1961 { |
3802
|
1962 buf << static_cast<char> (c); |
1053
|
1963 escape_pending = 1; |
|
1964 } |
|
1965 } |
1031
|
1966 continue; |
973
|
1967 } |
|
1968 else if (c == '.') |
|
1969 { |
5359
|
1970 if (delim == '\'' || ! have_ellipsis_continuation (false)) |
3802
|
1971 buf << static_cast<char> (c); |
973
|
1972 } |
|
1973 else if (c == '\n') |
|
1974 { |
1053
|
1975 error ("unterminated string constant"); |
973
|
1976 break; |
|
1977 } |
|
1978 else if (c == delim) |
|
1979 { |
1031
|
1980 if (escape_pending) |
3802
|
1981 buf << static_cast<char> (c); |
973
|
1982 else |
|
1983 { |
|
1984 c = yyinput (); |
|
1985 if (c == delim) |
5102
|
1986 { |
|
1987 buf << static_cast<char> (c); |
|
1988 if (lexer_flags.doing_rawcommand) |
|
1989 buf << static_cast<char> (c); |
|
1990 } |
973
|
1991 else |
|
1992 { |
5102
|
1993 std::string s; |
4410
|
1994 yyunput (c, yytext); |
5765
|
1995 |
5279
|
1996 if (lexer_flags.doing_rawcommand || delim == '\'') |
5765
|
1997 s = buf.str (); |
5102
|
1998 else |
5765
|
1999 s = do_string_escapes (buf.str ()); |
975
|
2000 |
5102
|
2001 if (text_style && lexer_flags.doing_rawcommand) |
|
2002 s = std::string (1, delim) + s + std::string (1, delim); |
975
|
2003 else |
|
2004 { |
2857
|
2005 lexer_flags.quote_is_transpose = true; |
|
2006 lexer_flags.convert_spaces_to_comma = true; |
975
|
2007 } |
|
2008 |
3805
|
2009 yylval.tok_val = new token (s, bos_line, bos_col); |
973
|
2010 token_stack.push (yylval.tok_val); |
3400
|
2011 |
4037
|
2012 if (delim == '"') |
|
2013 gripe_matlab_incompatible ("\" used as string delimiter"); |
|
2014 else if (delim == '\'') |
3400
|
2015 gripe_single_quote_string (); |
|
2016 |
5279
|
2017 return delim == '"' ? DQ_STRING : SQ_STRING; |
973
|
2018 } |
|
2019 } |
|
2020 } |
|
2021 else |
|
2022 { |
3802
|
2023 buf << static_cast<char> (c); |
973
|
2024 } |
|
2025 |
1031
|
2026 escape_pending = 0; |
973
|
2027 } |
|
2028 |
|
2029 return LEXICAL_ERROR; |
|
2030 } |
|
2031 |
3208
|
2032 static bool |
|
2033 next_token_is_assign_op (void) |
|
2034 { |
|
2035 bool retval = false; |
|
2036 |
|
2037 int c0 = yyinput (); |
|
2038 |
|
2039 switch (c0) |
|
2040 { |
|
2041 case '=': |
|
2042 { |
|
2043 int c1 = yyinput (); |
4410
|
2044 yyunput (c1, yytext); |
3208
|
2045 if (c1 != '=') |
|
2046 retval = true; |
|
2047 } |
|
2048 break; |
|
2049 |
|
2050 case '+': |
|
2051 case '-': |
|
2052 case '*': |
|
2053 case '/': |
|
2054 case '\\': |
|
2055 case '&': |
|
2056 case '|': |
|
2057 { |
|
2058 int c1 = yyinput (); |
4410
|
2059 yyunput (c1, yytext); |
3208
|
2060 if (c1 == '=') |
|
2061 retval = true; |
|
2062 } |
|
2063 break; |
|
2064 |
|
2065 case '.': |
|
2066 { |
|
2067 int c1 = yyinput (); |
|
2068 if (match_any (c1, "+-*/\\")) |
|
2069 { |
|
2070 int c2 = yyinput (); |
4410
|
2071 yyunput (c2, yytext); |
3208
|
2072 if (c2 == '=') |
|
2073 retval = true; |
|
2074 } |
4410
|
2075 yyunput (c1, yytext); |
3208
|
2076 } |
|
2077 break; |
|
2078 |
|
2079 case '>': |
|
2080 { |
|
2081 int c1 = yyinput (); |
|
2082 if (c1 == '>') |
|
2083 { |
|
2084 int c2 = yyinput (); |
4410
|
2085 yyunput (c2, yytext); |
3208
|
2086 if (c2 == '=') |
|
2087 retval = true; |
|
2088 } |
4410
|
2089 yyunput (c1, yytext); |
3208
|
2090 } |
|
2091 break; |
|
2092 |
|
2093 case '<': |
|
2094 { |
|
2095 int c1 = yyinput (); |
|
2096 if (c1 == '<') |
|
2097 { |
|
2098 int c2 = yyinput (); |
4410
|
2099 yyunput (c2, yytext); |
3208
|
2100 if (c2 == '=') |
|
2101 retval = true; |
|
2102 } |
4410
|
2103 yyunput (c1, yytext); |
3208
|
2104 } |
|
2105 break; |
|
2106 |
|
2107 default: |
|
2108 break; |
|
2109 } |
|
2110 |
4410
|
2111 yyunput (c0, yytext); |
3208
|
2112 |
|
2113 return retval; |
|
2114 } |
|
2115 |
4633
|
2116 static bool |
|
2117 next_token_is_index_op (void) |
|
2118 { |
|
2119 int c = yyinput (); |
|
2120 yyunput (c, yytext); |
|
2121 return c == '(' || c == '{'; |
|
2122 } |
|
2123 |
4612
|
2124 static int |
|
2125 handle_close_bracket (bool spc_gobbled, int bracket_type) |
971
|
2126 { |
4612
|
2127 int retval = bracket_type; |
3208
|
2128 |
1826
|
2129 if (! nesting_level.none ()) |
971
|
2130 { |
1826
|
2131 nesting_level.remove (); |
4613
|
2132 |
|
2133 if (bracket_type == ']') |
|
2134 lexer_flags.bracketflag--; |
|
2135 else if (bracket_type == '}') |
|
2136 lexer_flags.braceflag--; |
|
2137 else |
|
2138 panic_impossible (); |
971
|
2139 } |
|
2140 |
4613
|
2141 if (lexer_flags.bracketflag == 0 && lexer_flags.braceflag == 0) |
4323
|
2142 BEGIN (INITIAL); |
1001
|
2143 |
4608
|
2144 if (bracket_type == ']' |
|
2145 && next_token_is_assign_op () |
|
2146 && ! lexer_flags.looking_at_return_list) |
971
|
2147 { |
3208
|
2148 retval = CLOSE_BRACE; |
971
|
2149 } |
4613
|
2150 else if ((lexer_flags.bracketflag || lexer_flags.braceflag) |
|
2151 && lexer_flags.convert_spaces_to_comma |
|
2152 && (nesting_level.is_bracket () |
|
2153 || (nesting_level.is_brace () |
|
2154 && ! lexer_flags.looking_at_object_index))) |
971
|
2155 { |
4633
|
2156 bool index_op = next_token_is_index_op (); |
|
2157 |
|
2158 // Don't insert comma if we are looking at something like |
|
2159 // |
|
2160 // [x{i}{j}] or [x{i}(j)] |
|
2161 // |
|
2162 // but do if we are looking at |
|
2163 // |
|
2164 // [x{i} {j}] or [x{i} (j)] |
|
2165 |
|
2166 if (spc_gobbled || ! (bracket_type == '}' && index_op)) |
971
|
2167 { |
4633
|
2168 bool bin_op = next_token_is_bin_op (spc_gobbled); |
|
2169 |
|
2170 bool postfix_un_op = next_token_is_postfix_unary_op (spc_gobbled); |
|
2171 |
|
2172 bool sep_op = next_token_is_sep_op (); |
|
2173 |
|
2174 if (! (postfix_un_op || bin_op || sep_op)) |
|
2175 { |
|
2176 maybe_warn_separator_insert (','); |
|
2177 |
|
2178 yyunput (',', yytext); |
|
2179 return retval; |
|
2180 } |
971
|
2181 } |
|
2182 } |
|
2183 |
2857
|
2184 lexer_flags.quote_is_transpose = true; |
|
2185 lexer_flags.convert_spaces_to_comma = true; |
3208
|
2186 |
|
2187 return retval; |
971
|
2188 } |
|
2189 |
1072
|
2190 static void |
|
2191 maybe_unput_comma (int spc_gobbled) |
|
2192 { |
4613
|
2193 if (nesting_level.is_bracket () |
|
2194 || (nesting_level.is_brace () |
|
2195 && ! lexer_flags.looking_at_object_index)) |
1072
|
2196 { |
3246
|
2197 int bin_op = next_token_is_bin_op (spc_gobbled); |
1072
|
2198 |
3246
|
2199 int postfix_un_op = next_token_is_postfix_unary_op (spc_gobbled); |
1072
|
2200 |
|
2201 int c1 = yyinput (); |
|
2202 int c2 = yyinput (); |
2970
|
2203 |
4410
|
2204 yyunput (c2, yytext); |
|
2205 yyunput (c1, yytext); |
2970
|
2206 |
3263
|
2207 int sep_op = next_token_is_sep_op (); |
2970
|
2208 |
1072
|
2209 int dot_op = (c1 == '.' |
|
2210 && (isalpha (c2) || isspace (c2) || c2 == '_')); |
2970
|
2211 |
3388
|
2212 if (postfix_un_op || bin_op || sep_op || dot_op) |
|
2213 return; |
|
2214 |
3985
|
2215 int index_op = (c1 == '(' || c1 == '{'); |
3388
|
2216 |
4476
|
2217 // If there is no space before the indexing op, we don't insert |
|
2218 // a comma. |
|
2219 |
|
2220 if (index_op && ! spc_gobbled) |
|
2221 return; |
|
2222 |
|
2223 maybe_warn_separator_insert (','); |
|
2224 |
|
2225 yyunput (',', yytext); |
1072
|
2226 } |
|
2227 } |
|
2228 |
767
|
2229 // Figure out exactly what kind of token to return when we have seen |
4238
|
2230 // an identifier. Handles keywords. Return -1 if the identifier |
|
2231 // should be ignored. |
767
|
2232 |
146
|
2233 static int |
3974
|
2234 handle_identifier (void) |
146
|
2235 { |
3974
|
2236 std::string tok = strip_trailing_whitespace (yytext); |
|
2237 |
|
2238 int c = yytext[yyleng-1]; |
|
2239 |
|
2240 int cont_is_spc = eat_continuation (); |
|
2241 |
|
2242 int spc_gobbled = (cont_is_spc || c == ' ' || c == '\t'); |
|
2243 |
2970
|
2244 // If we are expecting a structure element, avoid recognizing |
|
2245 // keywords and other special names and return STRUCT_ELT, which is |
|
2246 // a string that is also a valid identifier. But first, we have to |
|
2247 // decide whether to insert a comma. |
747
|
2248 |
1826
|
2249 if (lexer_flags.looking_at_indirect_ref) |
1072
|
2250 { |
2970
|
2251 do_comma_insert_check (); |
|
2252 |
1072
|
2253 maybe_unput_comma (spc_gobbled); |
2819
|
2254 |
|
2255 yylval.tok_val = new token (tok, input_line_number, |
|
2256 current_input_column); |
|
2257 |
|
2258 token_stack.push (yylval.tok_val); |
|
2259 |
2857
|
2260 lexer_flags.quote_is_transpose = true; |
|
2261 lexer_flags.convert_spaces_to_comma = true; |
2819
|
2262 |
|
2263 current_input_column += yyleng; |
|
2264 |
2970
|
2265 return STRUCT_ELT; |
1072
|
2266 } |
747
|
2267 |
4930
|
2268 int kw_token = is_keyword_token (tok); |
|
2269 |
|
2270 if (lexer_flags.looking_at_function_handle) |
|
2271 { |
|
2272 if (kw_token) |
|
2273 { |
|
2274 error ("function handles may not refer to keywords"); |
|
2275 |
|
2276 return LEXICAL_ERROR; |
|
2277 } |
|
2278 else |
|
2279 TOK_PUSH_AND_RETURN (tok, FCN_HANDLE); |
|
2280 } |
|
2281 |
5102
|
2282 // If we have a regular keyword, return it. |
1826
|
2283 // Keywords can be followed by identifiers (TOK_RETURN handles |
|
2284 // that). |
146
|
2285 |
|
2286 if (kw_token) |
|
2287 { |
4238
|
2288 if (kw_token < 0) |
|
2289 return kw_token; |
146
|
2290 else |
|
2291 TOK_RETURN (kw_token); |
|
2292 } |
|
2293 |
1826
|
2294 // See if we have a plot keyword (title, using, with, or clear). |
146
|
2295 |
3480
|
2296 int c1 = yyinput (); |
|
2297 |
|
2298 bool next_tok_is_paren = (c1 == '('); |
|
2299 |
|
2300 bool next_tok_is_eq = false; |
|
2301 if (c1 == '=') |
|
2302 { |
|
2303 int c2 = yyinput (); |
4410
|
2304 yyunput (c2, yytext); |
3480
|
2305 |
|
2306 if (c2 != '=') |
|
2307 next_tok_is_eq = true; |
|
2308 } |
|
2309 |
4410
|
2310 yyunput (c1, yytext); |
1001
|
2311 |
1826
|
2312 // Make sure we put the return values of a function in the symbol |
|
2313 // table that is local to the function. |
146
|
2314 |
2877
|
2315 // If we are defining a function and we have not seen the function |
|
2316 // name yet and the next token is `=', then this identifier must be |
|
2317 // the only return value for the function and it belongs in the |
|
2318 // local symbol table. |
|
2319 |
1826
|
2320 if (next_tok_is_eq |
2877
|
2321 && lexer_flags.defining_func |
|
2322 && ! lexer_flags.parsed_function_name) |
146
|
2323 curr_sym_tab = tmp_local_sym_tab; |
|
2324 |
2702
|
2325 // Kluge alert. |
|
2326 // |
|
2327 // If we are looking at a text style function, set up to gobble its |
2745
|
2328 // arguments. |
|
2329 // |
|
2330 // If the following token is `=', or if we are parsing a function |
3189
|
2331 // return list or function parameter list, or if we are looking at |
|
2332 // something like [ab,cd] = foo (), force the symbol to be inserted |
|
2333 // as a variable in the current symbol table. |
2702
|
2334 |
4208
|
2335 if (is_command_name (tok) && ! is_variable (tok)) |
2702
|
2336 { |
2745
|
2337 if (next_tok_is_eq |
|
2338 || lexer_flags.looking_at_return_list |
3189
|
2339 || lexer_flags.looking_at_parameter_list |
4101
|
2340 || lexer_flags.looking_at_matrix_or_assign_lhs) |
2745
|
2341 { |
|
2342 force_local_variable (tok); |
|
2343 } |
2702
|
2344 else if (! next_tok_is_paren) |
|
2345 { |
5102
|
2346 BEGIN (COMMAND_START); |
|
2347 } |
|
2348 |
|
2349 if (is_rawcommand_name (tok)) |
|
2350 { |
|
2351 lexer_flags.doing_rawcommand = true; |
4323
|
2352 BEGIN (COMMAND_START); |
2702
|
2353 } |
|
2354 } |
|
2355 |
4234
|
2356 // Find the token in the symbol table. Beware the magic |
|
2357 // transformation of the end keyword... |
|
2358 |
|
2359 if (tok == "end") |
|
2360 tok = "__end__"; |
146
|
2361 |
|
2362 yylval.tok_val = new token (lookup_identifier (tok), |
|
2363 input_line_number, |
|
2364 current_input_column); |
|
2365 |
|
2366 token_stack.push (yylval.tok_val); |
|
2367 |
1826
|
2368 // After seeing an identifer, it is ok to convert spaces to a comma |
|
2369 // (if needed). |
146
|
2370 |
2857
|
2371 lexer_flags.convert_spaces_to_comma = true; |
146
|
2372 |
2877
|
2373 if (! next_tok_is_eq) |
|
2374 { |
|
2375 lexer_flags.quote_is_transpose = true; |
146
|
2376 |
2877
|
2377 do_comma_insert_check (); |
|
2378 |
|
2379 maybe_unput_comma (spc_gobbled); |
146
|
2380 } |
|
2381 |
2877
|
2382 current_input_column += yyleng; |
146
|
2383 |
|
2384 return NAME; |
|
2385 } |
|
2386 |
1826
|
2387 void |
|
2388 lexical_feedback::init (void) |
|
2389 { |
|
2390 // Not initially defining a matrix list. |
3351
|
2391 bracketflag = 0; |
1826
|
2392 |
4613
|
2393 // Not initially defining a cell array list. |
|
2394 braceflag = 0; |
|
2395 |
1826
|
2396 // Not initially inside a loop or if statement. |
|
2397 looping = 0; |
|
2398 |
2857
|
2399 // Not initially defining a function. |
|
2400 beginning_of_function = false; |
|
2401 defining_func = false; |
2877
|
2402 parsed_function_name = false; |
4240
|
2403 parsing_nested_function = 0; |
2857
|
2404 |
4930
|
2405 // Not initiallly looking at a function handle. |
|
2406 looking_at_function_handle = 0; |
|
2407 |
2857
|
2408 // Not parsing a function return or parameter list. |
|
2409 looking_at_return_list = false; |
|
2410 looking_at_parameter_list = false; |
|
2411 |
3796
|
2412 // Not parsing a matrix or the left hand side of multi-value |
|
2413 // assignment statement. |
|
2414 looking_at_matrix_or_assign_lhs = false; |
|
2415 |
4234
|
2416 // Not parsing an object index. |
4237
|
2417 looking_at_object_index = 0; |
4234
|
2418 |
2857
|
2419 // No need to do comma insert or convert spaces to comma at |
|
2420 // beginning of input. |
|
2421 convert_spaces_to_comma = true; |
|
2422 do_comma_insert = false; |
|
2423 |
|
2424 // Not initially doing any plotting or setting of plot attributes. |
5102
|
2425 doing_rawcommand = false; |
2857
|
2426 |
1826
|
2427 // Not initially looking at indirect references. |
2857
|
2428 looking_at_indirect_ref = false; |
1826
|
2429 |
|
2430 // Quote marks strings intially. |
2857
|
2431 quote_is_transpose = false; |
1826
|
2432 } |
|
2433 |
4867
|
2434 bool |
|
2435 is_keyword (const std::string& s) |
|
2436 { |
5088
|
2437 return octave_kw_hash::in_word_set (s.c_str (), s.length ()) != 0; |
4867
|
2438 } |
|
2439 |
4264
|
2440 DEFCMD (iskeyword, args, , |
|
2441 "-*- texinfo -*-\n\ |
|
2442 @deftypefn {Built-in Function} {} iskeyword (@var{name})\n\ |
|
2443 Return true if @var{name} is an Octave keyword. If @var{name}\n\ |
|
2444 is omitted, return a list of keywords.\n\ |
|
2445 @end deftypefn") |
|
2446 { |
|
2447 octave_value retval; |
|
2448 |
|
2449 int argc = args.length () + 1; |
|
2450 |
4867
|
2451 string_vector argv = args.make_argv ("iskeyword"); |
4264
|
2452 |
|
2453 if (error_state) |
|
2454 return retval; |
|
2455 |
|
2456 if (argc == 1) |
|
2457 { |
|
2458 string_vector lst (TOTAL_KEYWORDS); |
|
2459 |
|
2460 for (int i = 0; i < TOTAL_KEYWORDS; i++) |
|
2461 lst[i] = wordlist[i].name; |
|
2462 |
|
2463 retval = Cell (lst.qsort ()); |
|
2464 } |
|
2465 else if (argc == 2) |
|
2466 { |
4867
|
2467 retval = is_keyword (argv[1]); |
4264
|
2468 } |
|
2469 else |
|
2470 print_usage ("iskeyword"); |
|
2471 |
|
2472 return retval; |
|
2473 } |
|
2474 |
|
2475 |
3388
|
2476 static void |
|
2477 maybe_warn_separator_insert (char sep) |
|
2478 { |
3523
|
2479 std::string nm = curr_fcn_file_full_name; |
3388
|
2480 |
|
2481 if (Vwarn_separator_insert) |
|
2482 { |
|
2483 if (nm.empty ()) |
|
2484 warning ("potential auto-insertion of `%c' near line %d", |
|
2485 sep, input_line_number); |
|
2486 else |
|
2487 warning ("potential auto-insertion of `%c' near line %d of file %s", |
|
2488 sep, input_line_number, nm.c_str ()); |
|
2489 } |
|
2490 } |
|
2491 |
3400
|
2492 static void |
|
2493 gripe_single_quote_string (void) |
|
2494 { |
3523
|
2495 std::string nm = curr_fcn_file_full_name; |
3400
|
2496 |
|
2497 if (Vwarn_single_quote_string) |
|
2498 { |
|
2499 if (nm.empty ()) |
|
2500 warning ("single quote delimited string near line %d", |
|
2501 input_line_number); |
|
2502 else |
|
2503 warning ("single quote delimited string near line %d of file %s", |
|
2504 input_line_number, nm.c_str ()); |
|
2505 } |
|
2506 } |
|
2507 |
4037
|
2508 static void |
|
2509 gripe_matlab_incompatible (const std::string& msg) |
|
2510 { |
|
2511 if (Vwarn_matlab_incompatible) |
|
2512 warning ("potential Matlab compatibility problem: %s", msg.c_str ()); |
|
2513 } |
|
2514 |
|
2515 static void |
|
2516 maybe_gripe_matlab_incompatible_comment (char c) |
|
2517 { |
|
2518 if (c == '#') |
|
2519 gripe_matlab_incompatible ("# used as comment character"); |
|
2520 } |
|
2521 |
|
2522 static void |
|
2523 gripe_matlab_incompatible_continuation (void) |
|
2524 { |
|
2525 gripe_matlab_incompatible ("\\ used as line continuation marker"); |
|
2526 } |
|
2527 |
|
2528 static void |
|
2529 gripe_matlab_incompatible_operator (const std::string& op) |
|
2530 { |
|
2531 std::string t = op; |
|
2532 int n = t.length (); |
|
2533 if (t[n-1] == '\n') |
|
2534 t.resize (n-1); |
|
2535 gripe_matlab_incompatible (t + " used as operator"); |
|
2536 } |
|
2537 |
4910
|
2538 DEFUN (__token_count__, , , |
|
2539 "-*- texinfo -*-\n\ |
|
2540 @deftypefn {Built-in Function} {} __token_count__\n\ |
|
2541 Number of language tokens processed since Octave startup.\n\ |
|
2542 @end deftypefn") |
|
2543 { |
|
2544 return octave_value (Vtoken_count); |
|
2545 } |
|
2546 |
4037
|
2547 static int |
|
2548 warn_matlab_incompatible (void) |
|
2549 { |
|
2550 Vwarn_matlab_incompatible = check_preference ("warn_matlab_incompatible"); |
|
2551 |
|
2552 return 0; |
|
2553 } |
|
2554 |
3388
|
2555 static int |
|
2556 warn_separator_insert (void) |
|
2557 { |
|
2558 Vwarn_separator_insert = check_preference ("warn_separator_insert"); |
|
2559 |
|
2560 return 0; |
|
2561 } |
|
2562 |
3246
|
2563 static int |
3400
|
2564 warn_single_quote_string (void) |
|
2565 { |
|
2566 Vwarn_single_quote_string = check_preference ("warn_single_quote_string"); |
|
2567 |
|
2568 return 0; |
|
2569 } |
|
2570 |
2167
|
2571 void |
|
2572 symbols_of_lex (void) |
|
2573 { |
4233
|
2574 DEFVAR (warn_matlab_incompatible, false, warn_matlab_incompatible, |
4037
|
2575 "-*- texinfo -*-\n\ |
|
2576 @defvr {Built-in Variable} warn_matlab_incompatible\n\ |
|
2577 Print warnings for Octave language features that may cause\n\ |
|
2578 compatibility problems with Matlab.\n\ |
|
2579 @end defvr"); |
|
2580 |
4233
|
2581 DEFVAR (warn_separator_insert, false, warn_separator_insert, |
3428
|
2582 "-*- texinfo -*-\n\ |
|
2583 @defvr {Built-in Variable} warn_separator_insert\n\ |
3567
|
2584 Print warning if commas or semicolons might be inserted\n\ |
3428
|
2585 automatically in literal matrices.\n\ |
|
2586 @end defvr"); |
3388
|
2587 |
4233
|
2588 DEFVAR (warn_single_quote_string, false, warn_single_quote_string, |
3428
|
2589 "-*- texinfo -*-\n\ |
|
2590 @defvr {Built-in Variable} warn_single_quote_string\n\ |
|
2591 Print warning if a signle quote character is used to introduce a\n\ |
|
2592 string constant.\n\ |
|
2593 @end defvr"); |
2167
|
2594 } |
|
2595 |
1994
|
2596 /* |
|
2597 ;;; Local Variables: *** |
|
2598 ;;; mode: C++ *** |
|
2599 ;;; End: *** |
|
2600 */ |