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