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