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