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