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 "(" { |
1826
|
694 if (lexer_flags.plotting && ! lexer_flags.in_plot_range) |
2857
|
695 lexer_flags.past_plot_range = true; |
1826
|
696 nesting_level.paren (); |
985
|
697 promptflag--; |
967
|
698 TOK_RETURN ('('); |
|
699 } |
|
700 |
|
701 ")" { |
1826
|
702 nesting_level.remove (); |
1001
|
703 |
967
|
704 current_input_column++; |
2857
|
705 lexer_flags.cant_be_identifier = true; |
|
706 lexer_flags.quote_is_transpose = true; |
3351
|
707 lexer_flags.convert_spaces_to_comma = nesting_level.is_bracket (); |
1001
|
708 do_comma_insert_check (); |
967
|
709 return ')'; |
|
710 } |
|
711 |
2066
|
712 "." { |
|
713 TOK_RETURN ('.'); |
|
714 } |
|
715 |
3988
|
716 "@" { |
|
717 current_input_column++; |
|
718 lexer_flags.cant_be_identifier = false; |
|
719 lexer_flags.quote_is_transpose = false; |
|
720 lexer_flags.convert_spaces_to_comma = false; |
|
721 return '@'; |
|
722 } |
|
723 |
4037
|
724 "+=" { XBIN_OP_RETURN (ADD_EQ, false); } |
|
725 "-=" { XBIN_OP_RETURN (SUB_EQ, false); } |
|
726 "*=" { XBIN_OP_RETURN (MUL_EQ, false); } |
|
727 "/=" { XBIN_OP_RETURN (DIV_EQ, false); } |
|
728 "\\=" { XBIN_OP_RETURN (LEFTDIV_EQ, false); } |
|
729 ".+=" { XBIN_OP_RETURN (ADD_EQ, false); } |
|
730 ".-=" { XBIN_OP_RETURN (SUB_EQ, false); } |
|
731 ".*=" { XBIN_OP_RETURN (EMUL_EQ, false); } |
|
732 "./=" { XBIN_OP_RETURN (EDIV_EQ, false); } |
|
733 ".\\=" { XBIN_OP_RETURN (ELEFTDIV_EQ, false); } |
|
734 {POW}= { XBIN_OP_RETURN (POW_EQ, false); } |
|
735 {EPOW}= { XBIN_OP_RETURN (EPOW_EQ, false); } |
|
736 "&=" { XBIN_OP_RETURN (AND_EQ, false); } |
|
737 "|=" { XBIN_OP_RETURN (OR_EQ, false); } |
|
738 "<<=" { XBIN_OP_RETURN (LSHIFT_EQ, false); } |
|
739 ">>=" { XBIN_OP_RETURN (RSHIFT_EQ, false); } |
2877
|
740 |
3351
|
741 "{" { |
|
742 nesting_level.brace (); |
|
743 promptflag--; |
|
744 TOK_RETURN ('{'); |
|
745 } |
|
746 |
|
747 "}" { |
|
748 nesting_level.remove (); |
|
749 |
|
750 current_input_column++; |
|
751 lexer_flags.cant_be_identifier = true; |
|
752 lexer_flags.quote_is_transpose = true; |
|
753 lexer_flags.convert_spaces_to_comma = nesting_level.is_bracket (); |
|
754 do_comma_insert_check (); // Is this really necessary? |
|
755 |
|
756 return '}'; |
|
757 } |
|
758 |
968
|
759 %{ |
2066
|
760 // Unrecognized input is a lexical error. |
968
|
761 %} |
1
|
762 |
2042
|
763 . { |
2066
|
764 current_input_column++; |
|
765 |
3867
|
766 // EOF can't happen here (we catch it above). |
|
767 |
|
768 error ("invalid character `%s' (ASCII %d) near line %d, column %d", |
|
769 undo_string_escape (yytext[0]), static_cast<int> (yytext[0]), |
|
770 input_line_number, current_input_column); |
2066
|
771 |
|
772 return LEXICAL_ERROR; |
|
773 } |
1
|
774 |
|
775 %% |
|
776 |
767
|
777 // GAG. |
|
778 // |
|
779 // If we're reading a matrix and the next character is '[', make sure |
|
780 // that we insert a comma ahead of it. |
|
781 |
146
|
782 void |
1
|
783 do_comma_insert_check (void) |
|
784 { |
1001
|
785 int spc_gobbled = eat_continuation (); |
2970
|
786 |
1
|
787 int c = yyinput (); |
2970
|
788 |
3246
|
789 unput (c); |
2970
|
790 |
1001
|
791 if (spc_gobbled) |
3246
|
792 unput (' '); |
2970
|
793 |
3351
|
794 lexer_flags.do_comma_insert = (lexer_flags.bracketflag && c == '['); |
1
|
795 } |
|
796 |
767
|
797 // Fix things up for errors or interrupts. The parser is never called |
|
798 // recursively, so it is always safe to reinitialize its state before |
|
799 // doing any parsing. |
|
800 |
1
|
801 void |
|
802 reset_parser (void) |
|
803 { |
1826
|
804 // Start off on the right foot. |
1
|
805 BEGIN 0; |
166
|
806 error_state = 0; |
3489
|
807 warning_state = 0; |
3883
|
808 parser_end_of_input = false; |
287
|
809 |
1826
|
810 // We do want a prompt by default. |
1
|
811 promptflag = 1; |
287
|
812 |
3351
|
813 // Error may have occurred inside some brackets, braces, or parentheses. |
985
|
814 nesting_level.clear (); |
287
|
815 |
1826
|
816 // Clear out the stack of token info used to track line and column |
|
817 // numbers. |
143
|
818 while (! token_stack.empty ()) |
|
819 delete token_stack.pop (); |
287
|
820 |
1826
|
821 // Can be reset by defining a function. |
985
|
822 if (! (reading_script_file || reading_fcn_file)) |
|
823 { |
|
824 current_input_column = 1; |
2926
|
825 input_line_number = command_editor::current_command_number () - 1; |
985
|
826 } |
287
|
827 |
1826
|
828 // Only ask for input from stdin if we are expecting interactive |
|
829 // input. |
3174
|
830 if ((interactive || forced_interactive) |
3880
|
831 && ! (reading_fcn_file |
|
832 || reading_script_file |
|
833 || get_input_from_eval_string |
3174
|
834 || input_from_startup_file)) |
287
|
835 yyrestart (stdin); |
991
|
836 |
1826
|
837 // Clear the buffer for help text. |
|
838 help_buf.resize (0); |
1755
|
839 |
1826
|
840 // Reset other flags. |
|
841 lexer_flags.init (); |
1
|
842 } |
|
843 |
767
|
844 // If we read some newlines, we need figure out what column we're |
|
845 // really looking at. |
|
846 |
1
|
847 static void |
|
848 fixup_column_count (char *s) |
|
849 { |
|
850 char c; |
|
851 while ((c = *s++) != '\0') |
|
852 { |
|
853 if (c == '\n') |
143
|
854 current_input_column = 1; |
1
|
855 else |
|
856 current_input_column++; |
|
857 } |
|
858 } |
|
859 |
767
|
860 // Include these so that we don't have to link to libfl.a. |
246
|
861 |
1
|
862 #ifdef yywrap |
|
863 #undef yywrap |
|
864 #endif |
3332
|
865 int |
1
|
866 yywrap (void) |
|
867 { |
287
|
868 return 1; |
1
|
869 } |
|
870 |
767
|
871 // Tell us all what the current buffer is. |
|
872 |
1
|
873 YY_BUFFER_STATE |
|
874 current_buffer (void) |
|
875 { |
|
876 return YY_CURRENT_BUFFER; |
|
877 } |
|
878 |
767
|
879 // Create a new buffer. |
|
880 |
1
|
881 YY_BUFFER_STATE |
|
882 create_buffer (FILE *f) |
|
883 { |
|
884 return yy_create_buffer (f, YY_BUF_SIZE); |
|
885 } |
|
886 |
767
|
887 // Start reading a new buffer. |
|
888 |
1
|
889 void |
|
890 switch_to_buffer (YY_BUFFER_STATE buf) |
|
891 { |
|
892 yy_switch_to_buffer (buf); |
|
893 } |
|
894 |
767
|
895 // Delete a buffer. |
|
896 |
1
|
897 void |
|
898 delete_buffer (YY_BUFFER_STATE buf) |
|
899 { |
|
900 yy_delete_buffer (buf); |
|
901 } |
|
902 |
767
|
903 // Restore a buffer (for unwind-prot). |
|
904 |
1
|
905 void |
|
906 restore_input_buffer (void *buf) |
|
907 { |
2861
|
908 switch_to_buffer (static_cast<YY_BUFFER_STATE> (buf)); |
1
|
909 } |
|
910 |
767
|
911 // Delete a buffer (for unwind-prot). |
|
912 |
1
|
913 void |
|
914 delete_input_buffer (void *buf) |
|
915 { |
2861
|
916 delete_buffer (static_cast<YY_BUFFER_STATE> (buf)); |
1
|
917 } |
|
918 |
767
|
919 // Check to see if a character string matches any of the possible line |
|
920 // styles for plots. |
|
921 |
3536
|
922 static std::string |
3523
|
923 plot_style_token (const std::string& s) |
1
|
924 { |
3523
|
925 std::string retval; |
1823
|
926 |
3575
|
927 // XXX FIXME XXX -- specify minimum match length for these. |
2804
|
928 static const char *plot_styles[] = |
146
|
929 { |
925
|
930 "boxes", |
924
|
931 "boxerrorbars", |
2542
|
932 "boxxyerrorbars", |
|
933 "candlesticks", |
146
|
934 "dots", |
|
935 "errorbars", |
2542
|
936 "financebars", |
|
937 "fsteps", |
|
938 "histeps", |
146
|
939 "impulses", |
|
940 "lines", |
|
941 "linespoints", |
|
942 "points", |
926
|
943 "steps", |
2542
|
944 "vector", |
|
945 "xerrorbars", |
|
946 "xyerrorbars", |
|
947 "yerrorbars", |
522
|
948 0, |
146
|
949 }; |
|
950 |
2804
|
951 const char * const *tmp = plot_styles; |
522
|
952 while (*tmp) |
1
|
953 { |
1823
|
954 if (almost_match (*tmp, s.c_str ())) |
|
955 { |
|
956 retval = *tmp; |
|
957 break; |
|
958 } |
1
|
959 |
|
960 tmp++; |
|
961 } |
|
962 |
1823
|
963 return retval; |
1
|
964 } |
|
965 |
3165
|
966 // Check to see if a character string matches any of the possible axes |
|
967 // tags for plots. |
|
968 |
3536
|
969 static std::string |
3523
|
970 plot_axes_token (const std::string& s) |
3165
|
971 { |
3523
|
972 std::string retval; |
3165
|
973 |
3575
|
974 // XXX FIXME XXX -- specify minimum match length for these. |
3561
|
975 static const char *plot_axes[] = |
3165
|
976 { |
|
977 "x1y1", |
|
978 "x1y2", |
|
979 "x2y1", |
|
980 "x2y2", |
|
981 0, |
|
982 }; |
|
983 |
3561
|
984 const char **tmp = plot_axes; |
3165
|
985 while (*tmp) |
|
986 { |
|
987 if (almost_match (*tmp, s.c_str ())) |
|
988 { |
|
989 retval = *tmp; |
|
990 break; |
|
991 } |
|
992 |
|
993 tmp++; |
|
994 } |
|
995 |
|
996 return retval; |
|
997 } |
|
998 |
767
|
999 // Check to see if a character string matches any one of the plot |
941
|
1000 // option keywords. Don't match abbreviations for clear, since that's |
|
1001 // not a gnuplot keyword (users will probably only expect to be able |
|
1002 // to abbreviate actual gnuplot keywords). |
767
|
1003 |
1
|
1004 static int |
3523
|
1005 is_plot_keyword (const std::string& s) |
1
|
1006 { |
1823
|
1007 const char *t = s.c_str (); |
3575
|
1008 if (almost_match ("title", t, 1)) |
146
|
1009 { |
|
1010 return TITLE; |
|
1011 } |
3575
|
1012 else if (almost_match ("using", t, 1)) |
146
|
1013 { |
2857
|
1014 lexer_flags.in_plot_using = true; |
146
|
1015 return USING; |
|
1016 } |
3575
|
1017 else if (almost_match ("with", t, 1)) |
146
|
1018 { |
2857
|
1019 lexer_flags.in_plot_style = true; |
146
|
1020 return WITH; |
|
1021 } |
3575
|
1022 else if (almost_match ("axes", t, 2) || almost_match ("axis", t, 2)) |
3165
|
1023 { |
|
1024 lexer_flags.in_plot_axes = true; |
|
1025 return AXES; |
|
1026 } |
1823
|
1027 else if (strcmp ("clear", t) == 0) |
883
|
1028 { |
|
1029 return CLEAR; |
|
1030 } |
1
|
1031 else |
146
|
1032 { |
|
1033 return 0; |
|
1034 } |
1
|
1035 } |
|
1036 |
2877
|
1037 // Handle keywords. |
767
|
1038 |
1
|
1039 static int |
3523
|
1040 is_keyword (const std::string& s) |
1
|
1041 { |
3805
|
1042 int l = input_line_number; |
|
1043 int c = current_input_column; |
|
1044 |
3165
|
1045 if (lexer_flags.plotting) |
1
|
1046 { |
3165
|
1047 if (lexer_flags.in_plot_style) |
1
|
1048 { |
3523
|
1049 std::string sty = plot_style_token (s); |
3165
|
1050 |
|
1051 if (! sty.empty ()) |
|
1052 { |
|
1053 lexer_flags.in_plot_style = false; |
3805
|
1054 yylval.tok_val = new token (sty, l, c); |
3165
|
1055 token_stack.push (yylval.tok_val); |
|
1056 return STYLE; |
|
1057 } |
1
|
1058 } |
3165
|
1059 else if (lexer_flags.in_plot_axes) |
|
1060 { |
3523
|
1061 std::string axes = plot_axes_token (s); |
3165
|
1062 |
|
1063 if (! axes.empty ()) |
|
1064 { |
|
1065 lexer_flags.in_plot_axes = false; |
3805
|
1066 yylval.tok_val = new token (axes, l, c); |
3165
|
1067 token_stack.push (yylval.tok_val); |
|
1068 return AXES_TAG; |
|
1069 } |
|
1070 } |
1
|
1071 } |
|
1072 |
1823
|
1073 int len = s.length (); |
922
|
1074 |
1823
|
1075 const octave_kw *kw = octave_kw_lookup (s.c_str (), len); |
191
|
1076 |
1497
|
1077 if (kw) |
143
|
1078 { |
1497
|
1079 yylval.tok_val = 0; |
|
1080 |
|
1081 switch (kw->kw_id) |
|
1082 { |
|
1083 case all_va_args_kw: |
|
1084 case break_kw: |
2764
|
1085 case case_kw: |
1497
|
1086 case catch_kw: |
|
1087 case continue_kw: |
|
1088 case else_kw: |
|
1089 case elseif_kw: |
|
1090 case global_kw: |
2764
|
1091 case otherwise_kw: |
1497
|
1092 case return_kw: |
2846
|
1093 case static_kw: |
3484
|
1094 case until_kw: |
1497
|
1095 case unwind_protect_cleanup_kw: |
|
1096 break; |
|
1097 |
|
1098 case end_kw: |
|
1099 yylval.tok_val = new token (token::simple_end, l, c); |
|
1100 break; |
|
1101 |
|
1102 case end_try_catch_kw: |
|
1103 yylval.tok_val = new token (token::try_catch_end, l, c); |
|
1104 break; |
|
1105 |
|
1106 case end_unwind_protect_kw: |
|
1107 yylval.tok_val = new token (token::unwind_protect_end, l, c); |
|
1108 break; |
|
1109 |
|
1110 case endfor_kw: |
|
1111 yylval.tok_val = new token (token::for_end, l, c); |
|
1112 break; |
|
1113 |
|
1114 case endfunction_kw: |
|
1115 yylval.tok_val = new token (token::function_end, l, c); |
|
1116 break; |
|
1117 |
|
1118 case endif_kw: |
|
1119 yylval.tok_val = new token (token::if_end, l, c); |
|
1120 break; |
|
1121 |
2764
|
1122 case endswitch_kw: |
|
1123 yylval.tok_val = new token (token::switch_end, l, c); |
|
1124 break; |
|
1125 |
1497
|
1126 case endwhile_kw: |
|
1127 yylval.tok_val = new token (token::while_end, l, c); |
|
1128 break; |
|
1129 |
3484
|
1130 case do_kw: |
1497
|
1131 case for_kw: |
|
1132 case while_kw: |
|
1133 promptflag--; |
1826
|
1134 lexer_flags.looping++; |
1497
|
1135 break; |
|
1136 |
|
1137 case if_kw: |
|
1138 case try_kw: |
2764
|
1139 case switch_kw: |
1497
|
1140 case unwind_protect_kw: |
|
1141 promptflag--; |
|
1142 break; |
|
1143 |
|
1144 case gplot_kw: |
2857
|
1145 lexer_flags.plotting = true; |
1497
|
1146 yylval.tok_val = new token (token::two_dee, l, c); |
|
1147 break; |
|
1148 |
|
1149 case gsplot_kw: |
2857
|
1150 lexer_flags.plotting = true; |
1497
|
1151 yylval.tok_val = new token (token::three_dee, l, c); |
|
1152 break; |
|
1153 |
|
1154 case replot_kw: |
2857
|
1155 lexer_flags.plotting = true; |
1497
|
1156 yylval.tok_val = new token (token::replot, l, c); |
|
1157 break; |
|
1158 |
|
1159 case function_kw: |
1826
|
1160 if (lexer_flags.defining_func) |
1497
|
1161 { |
|
1162 error ("function keyword invalid within a function body"); |
|
1163 |
|
1164 if ((reading_fcn_file || reading_script_file) |
1755
|
1165 && ! curr_fcn_file_name.empty ()) |
1497
|
1166 error ("defining new function near line %d of file `%s.m'", |
1755
|
1167 input_line_number, curr_fcn_file_name.c_str ()); |
1497
|
1168 else |
1755
|
1169 error ("defining new function near line %d", |
|
1170 input_line_number); |
1497
|
1171 |
|
1172 return LEXICAL_ERROR; |
|
1173 } |
|
1174 else |
|
1175 { |
2877
|
1176 // Prepare for local symbols. |
|
1177 |
1497
|
1178 tmp_local_sym_tab = new symbol_table (); |
2877
|
1179 |
|
1180 promptflag--; |
|
1181 |
2857
|
1182 lexer_flags.defining_func = true; |
2877
|
1183 lexer_flags.parsed_function_name = false; |
2857
|
1184 lexer_flags.beginning_of_function = true; |
2877
|
1185 |
1497
|
1186 if (! (reading_fcn_file || reading_script_file)) |
|
1187 input_line_number = 1; |
|
1188 } |
|
1189 break; |
|
1190 |
3174
|
1191 case magic_file_kw: |
|
1192 { |
|
1193 if ((reading_fcn_file || reading_script_file) |
|
1194 && ! curr_fcn_file_full_name.empty ()) |
|
1195 yylval.tok_val = new token (curr_fcn_file_full_name, l, c); |
|
1196 else |
|
1197 yylval.tok_val = new token ("stdin", l, c); |
|
1198 } |
|
1199 break; |
|
1200 |
|
1201 case magic_line_kw: |
|
1202 yylval.tok_val = new token (static_cast<double> (l), "", l, c); |
|
1203 break; |
|
1204 |
3974
|
1205 case varargin_kw: |
|
1206 if (! lexer_flags.looking_at_parameter_list) |
|
1207 return 0; |
|
1208 break; |
|
1209 |
|
1210 case varargout_kw: |
|
1211 if (! lexer_flags.looking_at_return_list) |
|
1212 return 0; |
|
1213 break; |
|
1214 |
1497
|
1215 default: |
|
1216 panic_impossible (); |
|
1217 } |
|
1218 |
|
1219 if (! yylval.tok_val) |
|
1220 yylval.tok_val = new token (l, c); |
|
1221 |
476
|
1222 token_stack.push (yylval.tok_val); |
1497
|
1223 |
|
1224 return kw->tok; |
143
|
1225 } |
1
|
1226 |
|
1227 return 0; |
|
1228 } |
|
1229 |
767
|
1230 // Try to find an identifier. All binding to global or builtin |
|
1231 // variables occurs when expressions are evaluated. |
|
1232 |
1
|
1233 static symbol_record * |
3523
|
1234 lookup_identifier (const std::string& name) |
1
|
1235 { |
2856
|
1236 return curr_sym_tab->lookup (name, true); |
1
|
1237 } |
|
1238 |
2702
|
1239 static bool |
3523
|
1240 is_variable (const std::string& name) |
2702
|
1241 { |
2856
|
1242 symbol_record *sr = curr_sym_tab->lookup (name); |
2702
|
1243 |
|
1244 return sr && sr->is_variable (); |
|
1245 } |
|
1246 |
|
1247 static void |
3523
|
1248 force_local_variable (const std::string& name) |
2702
|
1249 { |
2856
|
1250 symbol_record *sr = curr_sym_tab->lookup (name, true); |
2702
|
1251 |
|
1252 if (sr) |
|
1253 sr->define (octave_value ()); |
|
1254 } |
|
1255 |
1019
|
1256 // Grab the help text from an function file. Always overwrites the |
|
1257 // current contents of help_buf. |
767
|
1258 |
3427
|
1259 // XXX FIXME XXX -- gobble_leading_white_space() in parse.y |
2300
|
1260 // duplicates some of this code! |
|
1261 |
1
|
1262 static void |
|
1263 grab_help_text (void) |
|
1264 { |
1755
|
1265 help_buf.resize (0); |
1019
|
1266 |
2300
|
1267 bool begin_comment = true; |
|
1268 bool in_comment = true; |
3427
|
1269 bool discard_space = true; |
3665
|
1270 |
1019
|
1271 int c = 0; |
1
|
1272 |
1019
|
1273 while ((c = yyinput ()) != EOF) |
|
1274 { |
2300
|
1275 if (begin_comment) |
|
1276 { |
|
1277 if (c == '%' || c == '#') |
|
1278 continue; |
3427
|
1279 else if (discard_space && c == ' ') |
|
1280 { |
|
1281 discard_space = false; |
|
1282 continue; |
|
1283 } |
2300
|
1284 else |
|
1285 begin_comment = false; |
|
1286 } |
|
1287 |
1019
|
1288 if (in_comment) |
1
|
1289 { |
3802
|
1290 help_buf += static_cast<char> (c); |
1755
|
1291 |
1019
|
1292 if (c == '\n') |
3427
|
1293 { |
|
1294 in_comment = false; |
|
1295 discard_space = true; |
|
1296 } |
1019
|
1297 } |
|
1298 else |
|
1299 { |
|
1300 switch (c) |
991
|
1301 { |
4037
|
1302 case '#': |
1019
|
1303 case '%': |
4037
|
1304 maybe_gripe_matlab_incompatible_comment (yytext[0]); |
2300
|
1305 in_comment = true; |
|
1306 begin_comment = true; |
1019
|
1307 break; |
777
|
1308 |
1019
|
1309 case ' ': |
|
1310 case '\t': |
|
1311 break; |
777
|
1312 |
1019
|
1313 default: |
|
1314 goto done; |
1
|
1315 } |
|
1316 } |
1019
|
1317 } |
991
|
1318 |
1019
|
1319 done: |
991
|
1320 |
1019
|
1321 if (c) |
3246
|
1322 unput (c); |
1
|
1323 } |
|
1324 |
767
|
1325 // Return 1 if the given character matches any character in the given |
|
1326 // string. |
|
1327 |
2857
|
1328 static bool |
2804
|
1329 match_any (char c, const char *s) |
1
|
1330 { |
|
1331 char tmp; |
|
1332 while ((tmp = *s++) != '\0') |
|
1333 { |
|
1334 if (c == tmp) |
2857
|
1335 return true; |
1
|
1336 } |
2857
|
1337 return false; |
1
|
1338 } |
|
1339 |
767
|
1340 // Given information about the spacing surrounding an operator, |
|
1341 // return 1 if it looks like it should be treated as a binary |
|
1342 // operator. For example, |
|
1343 // |
3774
|
1344 // [ 1 + 2 ] or [ 1+ 2] or [ 1+2 ] ==> binary |
|
1345 // |
|
1346 // [ 1 +2 ] ==> unary |
767
|
1347 |
2857
|
1348 static bool |
3246
|
1349 looks_like_bin_op (bool spc_prev, int next_char) |
1
|
1350 { |
3246
|
1351 bool spc_next = (next_char == ' ' || next_char == '\t'); |
|
1352 |
608
|
1353 return ((spc_prev && spc_next) || ! spc_prev); |
1
|
1354 } |
|
1355 |
3263
|
1356 // Recognize separators. If the separator is a CRLF pair, it is |
|
1357 // replaced by a single LF. |
|
1358 |
|
1359 static bool |
|
1360 next_token_is_sep_op (void) |
|
1361 { |
|
1362 bool retval = false; |
|
1363 |
|
1364 int c1 = yyinput (); |
|
1365 |
|
1366 if (c1 == '\r') |
|
1367 { |
|
1368 int c2 = yyinput (); |
|
1369 |
|
1370 if (c2 == '\n') |
|
1371 { |
|
1372 c1 = '\n'; |
|
1373 |
|
1374 retval = true; |
|
1375 } |
|
1376 else |
|
1377 unput (c2); |
|
1378 } |
|
1379 else |
|
1380 retval = match_any (c1, ",;\n]"); |
|
1381 |
|
1382 unput (c1); |
|
1383 |
|
1384 return retval; |
|
1385 } |
|
1386 |
767
|
1387 // Try to determine if the next token should be treated as a postfix |
|
1388 // unary operator. This is ugly, but it seems to do the right thing. |
|
1389 |
2857
|
1390 static bool |
3246
|
1391 next_token_is_postfix_unary_op (bool spc_prev) |
1
|
1392 { |
2857
|
1393 bool un_op = false; |
1
|
1394 |
|
1395 int c0 = yyinput (); |
|
1396 |
3246
|
1397 if (c0 == '\'' && ! spc_prev) |
|
1398 { |
|
1399 un_op = true; |
|
1400 } |
|
1401 else if (c0 == '.') |
|
1402 { |
|
1403 int c1 = yyinput (); |
|
1404 un_op = (c1 == '\''); |
|
1405 unput (c1); |
|
1406 } |
1
|
1407 |
3246
|
1408 unput (c0); |
1
|
1409 |
|
1410 return un_op; |
|
1411 } |
|
1412 |
767
|
1413 // Try to determine if the next token should be treated as a binary |
3246
|
1414 // operator. |
1521
|
1415 // |
3246
|
1416 // This kluge exists because whitespace is not always ignored inside |
3774
|
1417 // the square brackets that are used to create matrix objects (though |
|
1418 // spacing only really matters in the cases that can be interpreted |
|
1419 // either as binary ops or prefix unary ops: currently just +, -). |
|
1420 // |
3779
|
1421 // Note that a line continuation directly following a + or - operator |
|
1422 // (e.g., the characters '[' 'a' ' ' '+' '\' LFD 'b' ']') will be |
|
1423 // parsed as a binary operator. |
767
|
1424 |
2857
|
1425 static bool |
3246
|
1426 next_token_is_bin_op (bool spc_prev) |
1
|
1427 { |
2857
|
1428 bool bin_op = false; |
1
|
1429 |
|
1430 int c0 = yyinput (); |
|
1431 |
|
1432 switch (c0) |
|
1433 { |
777
|
1434 case '+': |
|
1435 case '-': |
3774
|
1436 { |
|
1437 int c1 = yyinput (); |
|
1438 |
|
1439 switch (c1) |
|
1440 { |
|
1441 case '+': |
|
1442 case '-': |
|
1443 // Unary ops, spacing doesn't matter. |
|
1444 break; |
|
1445 |
|
1446 case '=': |
|
1447 // Binary ops, spacing doesn't matter. |
|
1448 bin_op = true; |
|
1449 break; |
|
1450 |
|
1451 default: |
|
1452 // Could be either, spacing matters. |
|
1453 bin_op = looks_like_bin_op (spc_prev, c1); |
|
1454 break; |
|
1455 } |
|
1456 |
|
1457 unput (c1); |
|
1458 } |
|
1459 break; |
|
1460 |
|
1461 case ':': |
3246
|
1462 case '/': |
|
1463 case '\\': |
|
1464 case '^': |
3774
|
1465 // Always a binary op (may also include /=, \=, and ^=). |
|
1466 bin_op = true; |
1276
|
1467 break; |
|
1468 |
3246
|
1469 // .+ .- ./ .\ .^ .* .** |
1554
|
1470 case '.': |
|
1471 { |
|
1472 int c1 = yyinput (); |
3246
|
1473 |
3774
|
1474 if (match_any (c1, "+-/\\^*")) |
|
1475 // Always a binary op (may also include .+=, .-=, ./=, ...). |
|
1476 bin_op = true; |
3698
|
1477 else if (! isdigit (c1) && c1 != ' ' && c1 != '\t' && c1 != '.') |
3774
|
1478 // A structure element reference is a binary op. |
|
1479 bin_op = true; |
3246
|
1480 |
|
1481 unput (c1); |
1554
|
1482 } |
|
1483 break; |
|
1484 |
3246
|
1485 // = == & && | || * ** |
|
1486 case '=': |
1
|
1487 case '&': |
3246
|
1488 case '|': |
1
|
1489 case '*': |
3774
|
1490 // Always a binary op (may also include ==, &&, ||, **). |
|
1491 bin_op = true; |
3246
|
1492 break; |
|
1493 |
3774
|
1494 // < <= <> > >= |
1
|
1495 case '<': |
|
1496 case '>': |
3774
|
1497 // Always a binary op (may also include <=, <>, >=). |
|
1498 bin_op = true; |
|
1499 break; |
|
1500 |
|
1501 // ~= != |
777
|
1502 case '~': |
|
1503 case '!': |
3246
|
1504 { |
|
1505 int c1 = yyinput (); |
|
1506 |
3774
|
1507 // ~ and ! can be unary ops, so require following =. |
|
1508 if (c1 == '=') |
|
1509 bin_op = true; |
3246
|
1510 |
|
1511 unput (c1); |
|
1512 } |
1
|
1513 break; |
|
1514 |
|
1515 default: |
1276
|
1516 break; |
1
|
1517 } |
|
1518 |
3246
|
1519 unput (c0); |
1
|
1520 |
|
1521 return bin_op; |
|
1522 } |
|
1523 |
767
|
1524 // Used to delete trailing white space from tokens. |
|
1525 |
3536
|
1526 static std::string |
1
|
1527 strip_trailing_whitespace (char *s) |
|
1528 { |
3523
|
1529 std::string retval = s; |
1
|
1530 |
1823
|
1531 size_t pos = retval.find_first_of (" \t"); |
1
|
1532 |
1823
|
1533 if (pos != NPOS) |
|
1534 retval.resize (pos); |
1
|
1535 |
|
1536 return retval; |
|
1537 } |
|
1538 |
3665
|
1539 static void |
|
1540 scan_for_comments (const char *text) |
|
1541 { |
|
1542 std::string comment_buf; |
|
1543 |
|
1544 bool in_comment = false; |
|
1545 bool beginning_of_comment = false; |
|
1546 |
|
1547 int len = strlen (text); |
|
1548 int i = 0; |
|
1549 |
|
1550 while (i < len) |
|
1551 { |
|
1552 char c = text[i++]; |
|
1553 |
|
1554 switch (c) |
|
1555 { |
|
1556 case '%': |
|
1557 case '#': |
|
1558 if (in_comment) |
|
1559 { |
|
1560 if (! beginning_of_comment) |
3802
|
1561 comment_buf += static_cast<char> (c); |
3665
|
1562 } |
|
1563 else |
|
1564 { |
4037
|
1565 maybe_gripe_matlab_incompatible_comment (c); |
3665
|
1566 in_comment = true; |
|
1567 beginning_of_comment = true; |
|
1568 } |
|
1569 break; |
|
1570 |
|
1571 case '\n': |
|
1572 if (in_comment) |
|
1573 { |
3802
|
1574 comment_buf += static_cast<char> (c); |
3665
|
1575 octave_comment_buffer::append (comment_buf); |
|
1576 comment_buf.resize (0); |
|
1577 in_comment = false; |
|
1578 beginning_of_comment = false; |
|
1579 } |
|
1580 break; |
|
1581 |
|
1582 case '\r': |
|
1583 if (in_comment) |
3802
|
1584 comment_buf += static_cast<char> (c); |
3665
|
1585 if (i < len) |
|
1586 { |
|
1587 c = text[i++]; |
|
1588 |
|
1589 if (c == '\n') |
|
1590 { |
|
1591 if (in_comment) |
|
1592 { |
3802
|
1593 comment_buf += static_cast<char> (c); |
3665
|
1594 octave_comment_buffer::append (comment_buf); |
|
1595 in_comment = false; |
|
1596 beginning_of_comment = false; |
|
1597 } |
|
1598 } |
|
1599 } |
|
1600 |
|
1601 default: |
|
1602 if (in_comment) |
|
1603 { |
3802
|
1604 comment_buf += static_cast<char> (c); |
3665
|
1605 beginning_of_comment = false; |
|
1606 } |
|
1607 break; |
|
1608 } |
|
1609 } |
|
1610 |
|
1611 if (! comment_buf.empty ()) |
|
1612 octave_comment_buffer::append (comment_buf); |
|
1613 } |
|
1614 |
1001
|
1615 // Discard whitespace, including comments and continuations. |
1088
|
1616 // |
|
1617 // Return value is logical OR of the following values: |
|
1618 // |
1826
|
1619 // ATE_NOTHING : no spaces to eat |
1088
|
1620 // ATE_SPACE_OR_TAB : space or tab in input |
|
1621 // ATE_NEWLINE : bare new line in input |
1001
|
1622 |
1826
|
1623 static yum_yum |
975
|
1624 eat_whitespace (void) |
|
1625 { |
1826
|
1626 yum_yum retval = ATE_NOTHING; |
3665
|
1627 |
|
1628 std::string comment_buf; |
|
1629 |
2857
|
1630 bool in_comment = false; |
3665
|
1631 bool beginning_of_comment = false; |
|
1632 |
|
1633 int c = 0; |
|
1634 |
975
|
1635 while ((c = yyinput ()) != EOF) |
|
1636 { |
|
1637 current_input_column++; |
|
1638 |
|
1639 switch (c) |
|
1640 { |
|
1641 case ' ': |
|
1642 case '\t': |
3665
|
1643 if (in_comment) |
|
1644 { |
3802
|
1645 comment_buf += static_cast<char> (c); |
3665
|
1646 beginning_of_comment = false; |
|
1647 } |
1088
|
1648 retval |= ATE_SPACE_OR_TAB; |
975
|
1649 break; |
|
1650 |
|
1651 case '\n': |
1088
|
1652 retval |= ATE_NEWLINE; |
3665
|
1653 if (in_comment) |
|
1654 { |
3802
|
1655 comment_buf += static_cast<char> (c); |
3665
|
1656 octave_comment_buffer::append (comment_buf); |
|
1657 comment_buf.resize (0); |
|
1658 in_comment = false; |
|
1659 beginning_of_comment = false; |
|
1660 } |
975
|
1661 current_input_column = 0; |
|
1662 break; |
|
1663 |
|
1664 case '#': |
|
1665 case '%': |
3665
|
1666 if (in_comment) |
|
1667 { |
|
1668 if (! beginning_of_comment) |
3802
|
1669 comment_buf += static_cast<char> (c); |
3665
|
1670 } |
|
1671 else |
|
1672 { |
4037
|
1673 maybe_gripe_matlab_incompatible_comment (c); |
3665
|
1674 in_comment = true; |
|
1675 beginning_of_comment = true; |
|
1676 } |
975
|
1677 break; |
|
1678 |
1001
|
1679 case '.': |
|
1680 if (in_comment) |
3665
|
1681 { |
3802
|
1682 comment_buf += static_cast<char> (c); |
3665
|
1683 beginning_of_comment = false; |
|
1684 break; |
|
1685 } |
1001
|
1686 else |
|
1687 { |
|
1688 if (have_ellipsis_continuation ()) |
|
1689 break; |
|
1690 else |
|
1691 goto done; |
|
1692 } |
|
1693 |
|
1694 case '\\': |
|
1695 if (in_comment) |
3665
|
1696 { |
3802
|
1697 comment_buf += static_cast<char> (c); |
3665
|
1698 beginning_of_comment = false; |
|
1699 break; |
|
1700 } |
1001
|
1701 else |
|
1702 { |
3105
|
1703 if (have_continuation ()) |
1001
|
1704 break; |
|
1705 else |
|
1706 goto done; |
|
1707 } |
|
1708 |
975
|
1709 default: |
|
1710 if (in_comment) |
3665
|
1711 { |
3802
|
1712 comment_buf += static_cast<char> (c); |
3665
|
1713 beginning_of_comment = false; |
|
1714 break; |
|
1715 } |
975
|
1716 else |
|
1717 goto done; |
|
1718 } |
|
1719 } |
|
1720 |
3665
|
1721 if (! comment_buf.empty ()) |
|
1722 octave_comment_buffer::append (comment_buf); |
|
1723 |
975
|
1724 done: |
3246
|
1725 unput (c); |
1082
|
1726 current_input_column--; |
1001
|
1727 return retval; |
975
|
1728 } |
|
1729 |
3220
|
1730 static inline bool |
|
1731 looks_like_hex (const char *s, int len) |
|
1732 { |
|
1733 return (len > 2 && s[0] == '0' && (s[1] == 'x' || s[1] == 'X')); |
|
1734 } |
|
1735 |
975
|
1736 static void |
3246
|
1737 handle_number (void) |
972
|
1738 { |
3220
|
1739 double value = 0.0; |
|
1740 int nread = 0; |
|
1741 |
3598
|
1742 if (looks_like_hex (yytext, strlen (yytext))) |
3220
|
1743 { |
|
1744 unsigned long ival; |
3598
|
1745 |
|
1746 nread = sscanf (yytext, "%lx", &ival); |
|
1747 |
3220
|
1748 value = static_cast<double> (ival); |
|
1749 } |
|
1750 else |
3598
|
1751 { |
|
1752 char *tmp = strsave (yytext); |
|
1753 |
|
1754 char *idx = strpbrk (tmp, "Dd"); |
2621
|
1755 |
3598
|
1756 if (idx) |
|
1757 *idx = 'e'; |
|
1758 |
|
1759 nread = sscanf (tmp, "%lf", &value); |
|
1760 |
|
1761 delete [] tmp; |
|
1762 } |
972
|
1763 |
1826
|
1764 // If yytext doesn't contain a valid number, we are in deep doo doo. |
985
|
1765 |
972
|
1766 assert (nread == 1); |
|
1767 |
3988
|
1768 lexer_flags.quote_is_transpose = true; |
|
1769 lexer_flags.cant_be_identifier = true; |
|
1770 lexer_flags.convert_spaces_to_comma = true; |
972
|
1771 |
1826
|
1772 if (lexer_flags.plotting && ! lexer_flags.in_plot_range) |
3575
|
1773 lexer_flags.past_plot_range = true; |
972
|
1774 |
|
1775 yylval.tok_val = new token (value, yytext, input_line_number, |
|
1776 current_input_column); |
|
1777 |
|
1778 token_stack.push (yylval.tok_val); |
|
1779 |
|
1780 current_input_column += yyleng; |
|
1781 |
|
1782 do_comma_insert_check (); |
|
1783 } |
|
1784 |
1001
|
1785 // We have seen a backslash and need to find out if it should be |
|
1786 // treated as a continuation character. If so, this eats it, up to |
|
1787 // and including the new line character. |
|
1788 // |
973
|
1789 // Match whitespace only, followed by a comment character or newline. |
|
1790 // Once a comment character is found, discard all input until newline. |
|
1791 // If non-whitespace characters are found before comment |
|
1792 // characters, return 0. Otherwise, return 1. |
|
1793 |
2857
|
1794 static bool |
3096
|
1795 have_continuation (bool trailing_comments_ok) |
973
|
1796 { |
4051
|
1797 OSSTREAM buf; |
973
|
1798 |
3665
|
1799 std::string comment_buf; |
|
1800 |
2857
|
1801 bool in_comment = false; |
3665
|
1802 bool beginning_of_comment = false; |
|
1803 |
|
1804 int c = 0; |
|
1805 |
973
|
1806 while ((c = yyinput ()) != EOF) |
|
1807 { |
3802
|
1808 buf << static_cast<char> (c); |
973
|
1809 |
|
1810 switch (c) |
|
1811 { |
|
1812 case ' ': |
|
1813 case '\t': |
3665
|
1814 if (in_comment) |
|
1815 { |
3802
|
1816 comment_buf += static_cast<char> (c); |
3665
|
1817 beginning_of_comment = false; |
|
1818 } |
973
|
1819 break; |
|
1820 |
|
1821 case '%': |
|
1822 case '#': |
1091
|
1823 if (trailing_comments_ok) |
3665
|
1824 { |
|
1825 if (in_comment) |
|
1826 { |
|
1827 if (! beginning_of_comment) |
3802
|
1828 comment_buf += static_cast<char> (c); |
3665
|
1829 } |
|
1830 else |
|
1831 { |
4037
|
1832 maybe_gripe_matlab_incompatible_comment (c); |
3665
|
1833 in_comment = true; |
|
1834 beginning_of_comment = true; |
|
1835 } |
|
1836 } |
1091
|
1837 else |
|
1838 goto cleanup; |
973
|
1839 break; |
|
1840 |
|
1841 case '\n': |
3665
|
1842 if (in_comment) |
|
1843 { |
3802
|
1844 comment_buf += static_cast<char> (c); |
3665
|
1845 octave_comment_buffer::append (comment_buf); |
|
1846 } |
975
|
1847 current_input_column = 0; |
1001
|
1848 promptflag--; |
4037
|
1849 gripe_matlab_incompatible_continuation (); |
2857
|
1850 return true; |
973
|
1851 |
3263
|
1852 case '\r': |
3665
|
1853 if (in_comment) |
3802
|
1854 comment_buf += static_cast<char> (c); |
3263
|
1855 c = yyinput (); |
|
1856 if (c == EOF) |
|
1857 break; |
|
1858 else if (c == '\n') |
|
1859 { |
3665
|
1860 if (in_comment) |
|
1861 { |
3802
|
1862 comment_buf += static_cast<char> (c); |
3665
|
1863 octave_comment_buffer::append (comment_buf); |
|
1864 } |
3263
|
1865 current_input_column = 0; |
|
1866 promptflag--; |
4037
|
1867 gripe_matlab_incompatible_continuation (); |
3263
|
1868 return true; |
3665
|
1869 } |
3263
|
1870 |
3802
|
1871 // Fall through... |
|
1872 |
973
|
1873 default: |
3665
|
1874 if (in_comment) |
|
1875 { |
3802
|
1876 comment_buf += static_cast<char> (c); |
3665
|
1877 beginning_of_comment = false; |
|
1878 } |
|
1879 else |
1091
|
1880 goto cleanup; |
|
1881 break; |
973
|
1882 } |
|
1883 } |
|
1884 |
3246
|
1885 unput (c); |
2857
|
1886 return false; |
973
|
1887 |
3096
|
1888 cleanup: |
4051
|
1889 |
|
1890 buf << OSSTREAM_ENDS; |
|
1891 std::string s = OSSTREAM_STR (buf); |
|
1892 OSSTREAM_FREEZE (buf); |
|
1893 |
|
1894 int len = s.length (); |
|
1895 while (len--) |
|
1896 unput (s[len]); |
3096
|
1897 |
2857
|
1898 return false; |
973
|
1899 } |
|
1900 |
1001
|
1901 // We have seen a `.' and need to see if it is the start of a |
|
1902 // continuation. If so, this eats it, up to and including the new |
|
1903 // line character. |
|
1904 |
2857
|
1905 static bool |
3096
|
1906 have_ellipsis_continuation (bool trailing_comments_ok) |
973
|
1907 { |
|
1908 char c1 = yyinput (); |
|
1909 if (c1 == '.') |
|
1910 { |
|
1911 char c2 = yyinput (); |
1091
|
1912 if (c2 == '.' && have_continuation (trailing_comments_ok)) |
2857
|
1913 return true; |
973
|
1914 else |
|
1915 { |
3246
|
1916 unput (c2); |
|
1917 unput (c1); |
973
|
1918 } |
|
1919 } |
|
1920 else |
3246
|
1921 unput (c1); |
973
|
1922 |
2857
|
1923 return false; |
973
|
1924 } |
|
1925 |
1001
|
1926 // See if we have a continuation line. If so, eat it and the leading |
|
1927 // whitespace on the next line. |
1088
|
1928 // |
|
1929 // Return value is the same as described for eat_whitespace(). |
1001
|
1930 |
1826
|
1931 static yum_yum |
1001
|
1932 eat_continuation (void) |
|
1933 { |
1826
|
1934 int retval = ATE_NOTHING; |
3665
|
1935 |
1001
|
1936 int c = yyinput (); |
3665
|
1937 |
1001
|
1938 if ((c == '.' && have_ellipsis_continuation ()) |
3105
|
1939 || (c == '\\' && have_continuation ())) |
1001
|
1940 retval = eat_whitespace (); |
|
1941 else |
3246
|
1942 unput (c); |
1001
|
1943 |
|
1944 return retval; |
|
1945 } |
|
1946 |
973
|
1947 static int |
975
|
1948 handle_string (char delim, int text_style) |
973
|
1949 { |
4051
|
1950 OSSTREAM buf; |
973
|
1951 |
3805
|
1952 int bos_line = input_line_number; |
|
1953 int bos_col = current_input_column; |
|
1954 |
973
|
1955 int c; |
1031
|
1956 int escape_pending = 0; |
973
|
1957 |
|
1958 while ((c = yyinput ()) != EOF) |
|
1959 { |
|
1960 current_input_column++; |
|
1961 |
3105
|
1962 if (c == '\\') |
973
|
1963 { |
1053
|
1964 if (escape_pending) |
|
1965 { |
3802
|
1966 buf << static_cast<char> (c); |
1053
|
1967 escape_pending = 0; |
|
1968 } |
|
1969 else |
|
1970 { |
3096
|
1971 if (have_continuation (false)) |
1053
|
1972 escape_pending = 0; |
|
1973 else |
|
1974 { |
3802
|
1975 buf << static_cast<char> (c); |
1053
|
1976 escape_pending = 1; |
|
1977 } |
|
1978 } |
1031
|
1979 continue; |
973
|
1980 } |
|
1981 else if (c == '.') |
|
1982 { |
3096
|
1983 if (! have_ellipsis_continuation (false)) |
3802
|
1984 buf << static_cast<char> (c); |
973
|
1985 } |
|
1986 else if (c == '\n') |
|
1987 { |
1053
|
1988 error ("unterminated string constant"); |
973
|
1989 break; |
|
1990 } |
|
1991 else if (c == delim) |
|
1992 { |
1031
|
1993 if (escape_pending) |
3802
|
1994 buf << static_cast<char> (c); |
973
|
1995 else |
|
1996 { |
|
1997 c = yyinput (); |
|
1998 if (c == delim) |
3802
|
1999 buf << static_cast<char> (c); |
973
|
2000 else |
|
2001 { |
3246
|
2002 unput (c); |
4051
|
2003 buf << OSSTREAM_ENDS; |
|
2004 std::string s = do_string_escapes (OSSTREAM_STR (buf)); |
|
2005 OSSTREAM_FREEZE (buf); |
975
|
2006 |
1826
|
2007 if (text_style && lexer_flags.doing_set) |
975
|
2008 { |
3523
|
2009 s = std::string (1, delim) + s + std::string (1, delim); |
975
|
2010 } |
|
2011 else |
|
2012 { |
2857
|
2013 lexer_flags.quote_is_transpose = true; |
|
2014 lexer_flags.cant_be_identifier = true; |
|
2015 lexer_flags.convert_spaces_to_comma = true; |
975
|
2016 } |
|
2017 |
3805
|
2018 yylval.tok_val = new token (s, bos_line, bos_col); |
973
|
2019 token_stack.push (yylval.tok_val); |
3400
|
2020 |
4037
|
2021 if (delim == '"') |
|
2022 gripe_matlab_incompatible ("\" used as string delimiter"); |
|
2023 else if (delim == '\'') |
3400
|
2024 gripe_single_quote_string (); |
|
2025 |
4064
|
2026 return STRING; |
973
|
2027 } |
|
2028 } |
|
2029 } |
|
2030 else |
|
2031 { |
3802
|
2032 buf << static_cast<char> (c); |
973
|
2033 } |
|
2034 |
1031
|
2035 escape_pending = 0; |
973
|
2036 } |
|
2037 |
|
2038 return LEXICAL_ERROR; |
|
2039 } |
|
2040 |
3208
|
2041 static bool |
|
2042 next_token_is_assign_op (void) |
|
2043 { |
|
2044 bool retval = false; |
|
2045 |
|
2046 int c0 = yyinput (); |
|
2047 |
|
2048 switch (c0) |
|
2049 { |
|
2050 case '=': |
|
2051 { |
|
2052 int c1 = yyinput (); |
|
2053 unput (c1); |
|
2054 if (c1 != '=') |
|
2055 retval = true; |
|
2056 } |
|
2057 break; |
|
2058 |
|
2059 case '+': |
|
2060 case '-': |
|
2061 case '*': |
|
2062 case '/': |
|
2063 case '\\': |
|
2064 case '&': |
|
2065 case '|': |
|
2066 { |
|
2067 int c1 = yyinput (); |
|
2068 unput (c1); |
|
2069 if (c1 == '=') |
|
2070 retval = true; |
|
2071 } |
|
2072 break; |
|
2073 |
|
2074 case '.': |
|
2075 { |
|
2076 int c1 = yyinput (); |
|
2077 if (match_any (c1, "+-*/\\")) |
|
2078 { |
|
2079 int c2 = yyinput (); |
|
2080 unput (c2); |
|
2081 if (c2 == '=') |
|
2082 retval = true; |
|
2083 } |
|
2084 unput (c1); |
|
2085 } |
|
2086 break; |
|
2087 |
|
2088 case '>': |
|
2089 { |
|
2090 int c1 = yyinput (); |
|
2091 if (c1 == '>') |
|
2092 { |
|
2093 int c2 = yyinput (); |
|
2094 unput (c2); |
|
2095 if (c2 == '=') |
|
2096 retval = true; |
|
2097 } |
|
2098 unput (c1); |
|
2099 } |
|
2100 break; |
|
2101 |
|
2102 case '<': |
|
2103 { |
|
2104 int c1 = yyinput (); |
|
2105 if (c1 == '<') |
|
2106 { |
|
2107 int c2 = yyinput (); |
|
2108 unput (c2); |
|
2109 if (c2 == '=') |
|
2110 retval = true; |
|
2111 } |
|
2112 unput (c1); |
|
2113 } |
|
2114 break; |
|
2115 |
|
2116 default: |
|
2117 break; |
|
2118 } |
|
2119 |
|
2120 unput (c0); |
|
2121 |
|
2122 return retval; |
|
2123 } |
|
2124 |
971
|
2125 static int |
3351
|
2126 handle_close_bracket (int spc_gobbled) |
971
|
2127 { |
3208
|
2128 int retval = ']'; |
|
2129 |
1826
|
2130 if (! nesting_level.none ()) |
971
|
2131 { |
1826
|
2132 nesting_level.remove (); |
3351
|
2133 lexer_flags.bracketflag--; |
971
|
2134 } |
|
2135 |
3351
|
2136 if (lexer_flags.bracketflag == 0) |
1001
|
2137 BEGIN 0; |
|
2138 |
3208
|
2139 if (next_token_is_assign_op () && ! lexer_flags.looking_at_return_list) |
971
|
2140 { |
3208
|
2141 retval = CLOSE_BRACE; |
971
|
2142 } |
|
2143 else |
|
2144 { |
3208
|
2145 int c1 = yyinput (); |
971
|
2146 unput (c1); |
|
2147 |
3388
|
2148 if (lexer_flags.bracketflag) |
971
|
2149 { |
3246
|
2150 int bin_op = next_token_is_bin_op (spc_gobbled); |
3263
|
2151 |
3246
|
2152 int postfix_un_op = next_token_is_postfix_unary_op (spc_gobbled); |
971
|
2153 |
3263
|
2154 int sep_op = next_token_is_sep_op (); |
971
|
2155 |
3263
|
2156 if (! (postfix_un_op || bin_op || sep_op) |
3351
|
2157 && nesting_level.is_bracket () |
1826
|
2158 && lexer_flags.convert_spaces_to_comma) |
971
|
2159 { |
3388
|
2160 maybe_warn_separator_insert (','); |
|
2161 |
|
2162 if (Vwhitespace_in_literal_matrix != 2) |
|
2163 { |
|
2164 unput (','); |
|
2165 return ']'; |
|
2166 } |
971
|
2167 } |
|
2168 } |
|
2169 } |
|
2170 |
2857
|
2171 lexer_flags.quote_is_transpose = true; |
|
2172 lexer_flags.cant_be_identifier = false; |
|
2173 lexer_flags.convert_spaces_to_comma = true; |
3208
|
2174 |
|
2175 return retval; |
971
|
2176 } |
|
2177 |
1072
|
2178 static void |
|
2179 maybe_unput_comma (int spc_gobbled) |
|
2180 { |
3388
|
2181 if (nesting_level.is_bracket ()) |
1072
|
2182 { |
3246
|
2183 int bin_op = next_token_is_bin_op (spc_gobbled); |
1072
|
2184 |
3246
|
2185 int postfix_un_op = next_token_is_postfix_unary_op (spc_gobbled); |
1072
|
2186 |
|
2187 int c1 = yyinput (); |
|
2188 int c2 = yyinput (); |
2970
|
2189 |
1072
|
2190 unput (c2); |
|
2191 unput (c1); |
2970
|
2192 |
3263
|
2193 int sep_op = next_token_is_sep_op (); |
2970
|
2194 |
1072
|
2195 int dot_op = (c1 == '.' |
|
2196 && (isalpha (c2) || isspace (c2) || c2 == '_')); |
2970
|
2197 |
3388
|
2198 if (postfix_un_op || bin_op || sep_op || dot_op) |
|
2199 return; |
|
2200 |
3985
|
2201 int index_op = (c1 == '(' || c1 == '{'); |
3388
|
2202 |
|
2203 if (index_op) |
|
2204 { |
3985
|
2205 // If there is no space before the indexing op, we don't |
|
2206 // insert a comma. |
3388
|
2207 if (! spc_gobbled) |
|
2208 return; |
|
2209 |
|
2210 maybe_warn_separator_insert (','); |
1072
|
2211 |
3388
|
2212 // If there is a space, we only insert a comma if we are |
|
2213 // trying to be Matlab-like. |
|
2214 if (Vwhitespace_in_literal_matrix == 1) |
|
2215 unput (','); |
|
2216 } |
|
2217 else |
|
2218 { |
|
2219 maybe_warn_separator_insert (','); |
|
2220 |
|
2221 if (Vwhitespace_in_literal_matrix != 2) |
|
2222 unput (','); |
|
2223 } |
1072
|
2224 } |
|
2225 } |
|
2226 |
767
|
2227 // Figure out exactly what kind of token to return when we have seen |
|
2228 // an identifier. Handles keywords. |
|
2229 |
146
|
2230 static int |
3974
|
2231 handle_identifier (void) |
146
|
2232 { |
3974
|
2233 std::string tok = strip_trailing_whitespace (yytext); |
|
2234 |
|
2235 int c = yytext[yyleng-1]; |
|
2236 |
|
2237 int cont_is_spc = eat_continuation (); |
|
2238 |
|
2239 int spc_gobbled = (cont_is_spc || c == ' ' || c == '\t'); |
|
2240 |
1826
|
2241 // It is almost always an error for an identifier to be followed |
|
2242 // directly by another identifier. Special cases are handled |
|
2243 // below. |
883
|
2244 |
2857
|
2245 lexer_flags.cant_be_identifier = true; |
883
|
2246 |
2970
|
2247 // If we are expecting a structure element, avoid recognizing |
|
2248 // keywords and other special names and return STRUCT_ELT, which is |
|
2249 // a string that is also a valid identifier. But first, we have to |
|
2250 // decide whether to insert a comma. |
747
|
2251 |
1826
|
2252 if (lexer_flags.looking_at_indirect_ref) |
1072
|
2253 { |
2970
|
2254 do_comma_insert_check (); |
|
2255 |
1072
|
2256 maybe_unput_comma (spc_gobbled); |
2819
|
2257 |
|
2258 yylval.tok_val = new token (tok, input_line_number, |
|
2259 current_input_column); |
|
2260 |
|
2261 token_stack.push (yylval.tok_val); |
|
2262 |
2857
|
2263 lexer_flags.cant_be_identifier = false; |
|
2264 lexer_flags.quote_is_transpose = true; |
|
2265 lexer_flags.convert_spaces_to_comma = true; |
2819
|
2266 |
|
2267 current_input_column += yyleng; |
|
2268 |
2970
|
2269 return STRUCT_ELT; |
1072
|
2270 } |
747
|
2271 |
1826
|
2272 // If we have a regular keyword, or a plot STYLE, return it. |
|
2273 // Keywords can be followed by identifiers (TOK_RETURN handles |
|
2274 // that). |
146
|
2275 |
|
2276 int kw_token = is_keyword (tok); |
2970
|
2277 |
146
|
2278 if (kw_token) |
|
2279 { |
|
2280 if (kw_token == STYLE) |
|
2281 { |
1060
|
2282 current_input_column += yyleng; |
2857
|
2283 lexer_flags.quote_is_transpose = false; |
|
2284 lexer_flags.convert_spaces_to_comma = true; |
146
|
2285 return kw_token; |
|
2286 } |
|
2287 else |
|
2288 TOK_RETURN (kw_token); |
|
2289 } |
|
2290 |
1826
|
2291 // See if we have a plot keyword (title, using, with, or clear). |
146
|
2292 |
1826
|
2293 if (lexer_flags.plotting) |
941
|
2294 { |
1826
|
2295 // Yes, we really do need both of these plot_range variables. |
|
2296 // One is used to mark when we are past all possiblity of a plot |
|
2297 // range, the other is used to mark when we are actually between |
|
2298 // the square brackets that surround the range. |
146
|
2299 |
1826
|
2300 if (! lexer_flags.in_plot_range) |
2857
|
2301 lexer_flags.past_plot_range = true; |
941
|
2302 |
3351
|
2303 // Option keywords can't appear in brackets, braces, or parentheses. |
1273
|
2304 |
|
2305 int plot_option_kw = 0; |
2970
|
2306 |
1826
|
2307 if (nesting_level.none ()) |
1273
|
2308 plot_option_kw = is_plot_keyword (tok); |
3575
|
2309 |
1826
|
2310 if (lexer_flags.cant_be_identifier && plot_option_kw) |
941
|
2311 TOK_RETURN (plot_option_kw); |
|
2312 } |
146
|
2313 |
3480
|
2314 int c1 = yyinput (); |
|
2315 |
|
2316 bool next_tok_is_dot = (c1 == '.'); |
|
2317 bool next_tok_is_paren = (c1 == '('); |
|
2318 |
|
2319 bool next_tok_is_eq = false; |
|
2320 if (c1 == '=') |
|
2321 { |
|
2322 int c2 = yyinput (); |
|
2323 unput (c2); |
|
2324 |
|
2325 if (c2 != '=') |
|
2326 next_tok_is_eq = true; |
|
2327 } |
|
2328 |
|
2329 unput (c1); |
1001
|
2330 |
1826
|
2331 // Make sure we put the return values of a function in the symbol |
|
2332 // table that is local to the function. |
146
|
2333 |
2877
|
2334 // If we are defining a function and we have not seen the function |
|
2335 // name yet and the next token is `=', then this identifier must be |
|
2336 // the only return value for the function and it belongs in the |
|
2337 // local symbol table. |
|
2338 |
1826
|
2339 if (next_tok_is_eq |
2877
|
2340 && lexer_flags.defining_func |
|
2341 && ! lexer_flags.parsed_function_name) |
146
|
2342 curr_sym_tab = tmp_local_sym_tab; |
|
2343 |
2702
|
2344 // Kluge alert. |
|
2345 // |
|
2346 // If we are looking at a text style function, set up to gobble its |
2745
|
2347 // arguments. |
|
2348 // |
|
2349 // If the following token is `=', or if we are parsing a function |
3189
|
2350 // return list or function parameter list, or if we are looking at |
|
2351 // something like [ab,cd] = foo (), force the symbol to be inserted |
|
2352 // as a variable in the current symbol table. |
2702
|
2353 |
|
2354 if (is_text_function_name (tok) && ! is_variable (tok)) |
|
2355 { |
2745
|
2356 if (next_tok_is_eq |
|
2357 || lexer_flags.looking_at_return_list |
3189
|
2358 || lexer_flags.looking_at_parameter_list |
3246
|
2359 || lexer_flags.looking_at_matrix_or_assign_lhs |
|
2360 || (next_tok_is_dot && next_token_is_bin_op (spc_gobbled))) |
2745
|
2361 { |
|
2362 force_local_variable (tok); |
|
2363 } |
2702
|
2364 else if (! next_tok_is_paren) |
|
2365 { |
|
2366 if (tok == "gset") |
2857
|
2367 lexer_flags.doing_set = true; |
2702
|
2368 |
|
2369 BEGIN TEXT_FCN; |
|
2370 } |
|
2371 } |
|
2372 |
1826
|
2373 // Find the token in the symbol table. |
146
|
2374 |
|
2375 yylval.tok_val = new token (lookup_identifier (tok), |
|
2376 input_line_number, |
|
2377 current_input_column); |
|
2378 |
|
2379 token_stack.push (yylval.tok_val); |
|
2380 |
1826
|
2381 // After seeing an identifer, it is ok to convert spaces to a comma |
|
2382 // (if needed). |
146
|
2383 |
2857
|
2384 lexer_flags.convert_spaces_to_comma = true; |
146
|
2385 |
2877
|
2386 if (! next_tok_is_eq) |
|
2387 { |
|
2388 lexer_flags.quote_is_transpose = true; |
146
|
2389 |
2877
|
2390 do_comma_insert_check (); |
|
2391 |
|
2392 maybe_unput_comma (spc_gobbled); |
146
|
2393 } |
|
2394 |
2877
|
2395 current_input_column += yyleng; |
146
|
2396 |
|
2397 return NAME; |
|
2398 } |
|
2399 |
767
|
2400 // Print a warning if a function file that defines a function has |
|
2401 // anything other than comments and whitespace following the END token |
|
2402 // that matches the FUNCTION statement. |
|
2403 |
1
|
2404 void |
|
2405 check_for_garbage_after_fcn_def (void) |
|
2406 { |
1826
|
2407 // By making a newline be the next character to be read, we will |
|
2408 // force the parser to return after reading the function. Calling |
3246
|
2409 // unput with EOF does not work. |
1
|
2410 |
3665
|
2411 std::string comment_buf; |
|
2412 |
2857
|
2413 bool in_comment = false; |
3665
|
2414 bool beginning_of_comment = true; |
|
2415 |
1
|
2416 int lineno = input_line_number; |
3665
|
2417 |
|
2418 int c = 0; |
|
2419 |
1
|
2420 while ((c = yyinput ()) != EOF) |
|
2421 { |
|
2422 switch (c) |
|
2423 { |
|
2424 case ' ': |
|
2425 case '\t': |
|
2426 case ';': |
|
2427 case ',': |
3665
|
2428 if (in_comment) |
|
2429 { |
3802
|
2430 comment_buf += static_cast<char> (c); |
3665
|
2431 beginning_of_comment = false; |
|
2432 } |
1
|
2433 break; |
777
|
2434 |
1
|
2435 case '%': |
|
2436 case '#': |
3665
|
2437 if (in_comment) |
|
2438 { |
|
2439 if (! beginning_of_comment) |
3802
|
2440 comment_buf += static_cast<char> (c); |
3665
|
2441 } |
|
2442 else |
|
2443 { |
4037
|
2444 maybe_gripe_matlab_incompatible_comment (c); |
3665
|
2445 in_comment = true; |
|
2446 beginning_of_comment = true; |
|
2447 } |
1
|
2448 break; |
777
|
2449 |
3802
|
2450 case '\n': |
|
2451 if (in_comment) |
|
2452 { |
|
2453 comment_buf += static_cast<char> (c); |
|
2454 octave_comment_buffer::append (comment_buf); |
|
2455 comment_buf.resize (0); |
|
2456 in_comment = false; |
|
2457 beginning_of_comment = false; |
|
2458 } |
|
2459 break; |
|
2460 |
|
2461 case '\r': |
|
2462 if (in_comment) |
|
2463 comment_buf += static_cast<char> (c); |
|
2464 c = yyinput (); |
|
2465 if (c == EOF) |
|
2466 break; |
|
2467 else if (c == '\n') |
|
2468 { |
|
2469 if (in_comment) |
|
2470 { |
|
2471 comment_buf += static_cast<char> (c); |
|
2472 octave_comment_buffer::append (comment_buf); |
|
2473 comment_buf.resize (0); |
|
2474 in_comment = false; |
|
2475 beginning_of_comment = false; |
|
2476 } |
|
2477 break; |
|
2478 } |
|
2479 |
|
2480 // Fall through... |
|
2481 |
1
|
2482 default: |
|
2483 if (in_comment) |
3665
|
2484 { |
3802
|
2485 comment_buf += static_cast<char> (c); |
3665
|
2486 beginning_of_comment = false; |
|
2487 break; |
|
2488 } |
1
|
2489 else |
|
2490 { |
|
2491 warning ("ignoring trailing garbage after end of function\n\ |
1755
|
2492 near line %d of file `%s.m'", lineno, curr_fcn_file_name.c_str ()); |
1
|
2493 |
3246
|
2494 unput ('\n'); |
1
|
2495 return; |
|
2496 } |
|
2497 } |
|
2498 } |
3665
|
2499 |
|
2500 if (! comment_buf.empty ()) |
|
2501 octave_comment_buffer::append (comment_buf); |
|
2502 |
3246
|
2503 unput ('\n'); |
1
|
2504 } |
|
2505 |
1826
|
2506 void |
|
2507 lexical_feedback::init (void) |
|
2508 { |
|
2509 // Not initially defining a matrix list. |
3351
|
2510 bracketflag = 0; |
1826
|
2511 |
|
2512 // Not initially inside a loop or if statement. |
|
2513 looping = 0; |
|
2514 |
2857
|
2515 // Not initially defining a function. |
|
2516 beginning_of_function = false; |
|
2517 defining_func = false; |
2877
|
2518 parsed_function_name = false; |
2857
|
2519 |
|
2520 // Not parsing a function return or parameter list. |
|
2521 looking_at_return_list = false; |
|
2522 looking_at_parameter_list = false; |
|
2523 |
3796
|
2524 // Not parsing a matrix or the left hand side of multi-value |
|
2525 // assignment statement. |
|
2526 looking_at_matrix_or_assign_lhs = false; |
|
2527 |
2857
|
2528 // Next token can be identifier. |
|
2529 cant_be_identifier = false; |
|
2530 |
|
2531 // No need to do comma insert or convert spaces to comma at |
|
2532 // beginning of input. |
|
2533 convert_spaces_to_comma = true; |
|
2534 do_comma_insert = false; |
|
2535 |
|
2536 // Not initially doing any plotting or setting of plot attributes. |
|
2537 doing_set = false; |
|
2538 in_plot_range = false; |
|
2539 in_plot_style = false; |
3165
|
2540 in_plot_axes = false; |
2857
|
2541 in_plot_using = false; |
|
2542 past_plot_range = false; |
|
2543 plotting = false; |
|
2544 |
1826
|
2545 // Not initially looking at indirect references. |
2857
|
2546 looking_at_indirect_ref = false; |
1826
|
2547 |
|
2548 // Quote marks strings intially. |
2857
|
2549 quote_is_transpose = false; |
1826
|
2550 } |
|
2551 |
3388
|
2552 static void |
|
2553 maybe_warn_separator_insert (char sep) |
|
2554 { |
3523
|
2555 std::string nm = curr_fcn_file_full_name; |
3388
|
2556 |
|
2557 if (Vwarn_separator_insert) |
|
2558 { |
|
2559 if (nm.empty ()) |
|
2560 warning ("potential auto-insertion of `%c' near line %d", |
|
2561 sep, input_line_number); |
|
2562 else |
|
2563 warning ("potential auto-insertion of `%c' near line %d of file %s", |
|
2564 sep, input_line_number, nm.c_str ()); |
|
2565 } |
|
2566 } |
|
2567 |
3400
|
2568 static void |
|
2569 gripe_single_quote_string (void) |
|
2570 { |
3523
|
2571 std::string nm = curr_fcn_file_full_name; |
3400
|
2572 |
|
2573 if (Vwarn_single_quote_string) |
|
2574 { |
|
2575 if (nm.empty ()) |
|
2576 warning ("single quote delimited string near line %d", |
|
2577 input_line_number); |
|
2578 else |
|
2579 warning ("single quote delimited string near line %d of file %s", |
|
2580 input_line_number, nm.c_str ()); |
|
2581 } |
|
2582 } |
|
2583 |
4037
|
2584 static void |
|
2585 gripe_matlab_incompatible (const std::string& msg) |
|
2586 { |
|
2587 if (Vwarn_matlab_incompatible) |
|
2588 warning ("potential Matlab compatibility problem: %s", msg.c_str ()); |
|
2589 } |
|
2590 |
|
2591 static void |
|
2592 maybe_gripe_matlab_incompatible_comment (char c) |
|
2593 { |
|
2594 if (c == '#') |
|
2595 gripe_matlab_incompatible ("# used as comment character"); |
|
2596 } |
|
2597 |
|
2598 static void |
|
2599 gripe_matlab_incompatible_continuation (void) |
|
2600 { |
|
2601 gripe_matlab_incompatible ("\\ used as line continuation marker"); |
|
2602 } |
|
2603 |
|
2604 static void |
|
2605 gripe_matlab_incompatible_operator (const std::string& op) |
|
2606 { |
|
2607 std::string t = op; |
|
2608 int n = t.length (); |
|
2609 if (t[n-1] == '\n') |
|
2610 t.resize (n-1); |
|
2611 gripe_matlab_incompatible (t + " used as operator"); |
|
2612 } |
|
2613 |
|
2614 static int |
|
2615 warn_matlab_incompatible (void) |
|
2616 { |
|
2617 Vwarn_matlab_incompatible = check_preference ("warn_matlab_incompatible"); |
|
2618 |
|
2619 return 0; |
|
2620 } |
|
2621 |
3388
|
2622 static int |
|
2623 warn_separator_insert (void) |
|
2624 { |
|
2625 Vwarn_separator_insert = check_preference ("warn_separator_insert"); |
|
2626 |
|
2627 return 0; |
|
2628 } |
|
2629 |
3246
|
2630 static int |
3400
|
2631 warn_single_quote_string (void) |
|
2632 { |
|
2633 Vwarn_single_quote_string = check_preference ("warn_single_quote_string"); |
|
2634 |
|
2635 return 0; |
|
2636 } |
|
2637 |
|
2638 static int |
2167
|
2639 whitespace_in_literal_matrix (void) |
|
2640 { |
|
2641 int pref = 0; |
3009
|
2642 |
3523
|
2643 std::string val = builtin_string_variable ("whitespace_in_literal_matrix"); |
3009
|
2644 |
2167
|
2645 if (! val.empty ()) |
|
2646 { |
3565
|
2647 if (val == "ignore") |
2167
|
2648 pref = 2; |
3565
|
2649 else if (val == "traditional") |
2167
|
2650 pref = 1; |
|
2651 } |
3009
|
2652 |
2167
|
2653 Vwhitespace_in_literal_matrix = pref; |
3009
|
2654 |
2167
|
2655 return 0; |
|
2656 } |
|
2657 |
|
2658 void |
|
2659 symbols_of_lex (void) |
|
2660 { |
4037
|
2661 DEFVAR (warn_matlab_incompatible, 0.0, warn_matlab_incompatible, |
|
2662 "-*- texinfo -*-\n\ |
|
2663 @defvr {Built-in Variable} warn_matlab_incompatible\n\ |
|
2664 Print warnings for Octave language features that may cause\n\ |
|
2665 compatibility problems with Matlab.\n\ |
|
2666 @end defvr"); |
|
2667 |
3388
|
2668 DEFVAR (warn_separator_insert, 0.0, warn_separator_insert, |
3428
|
2669 "-*- texinfo -*-\n\ |
|
2670 @defvr {Built-in Variable} warn_separator_insert\n\ |
3567
|
2671 Print warning if commas or semicolons might be inserted\n\ |
3428
|
2672 automatically in literal matrices.\n\ |
|
2673 @end defvr"); |
3388
|
2674 |
3400
|
2675 DEFVAR (warn_single_quote_string, 0.0, warn_single_quote_string, |
3428
|
2676 "-*- texinfo -*-\n\ |
|
2677 @defvr {Built-in Variable} warn_single_quote_string\n\ |
|
2678 Print warning if a signle quote character is used to introduce a\n\ |
|
2679 string constant.\n\ |
|
2680 @end defvr"); |
3400
|
2681 |
3258
|
2682 DEFVAR (whitespace_in_literal_matrix, "", whitespace_in_literal_matrix, |
3428
|
2683 "-*- texinfo -*-\n\ |
|
2684 @defvr {Built-in Variable} whitespace_in_literal_matrix\n\ |
|
2685 Control auto-insertion of commas and semicolons in literal matrices.\n\ |
|
2686 @end defvr"); |
|
2687 |
2167
|
2688 } |
|
2689 |
1994
|
2690 /* |
|
2691 ;;; Local Variables: *** |
|
2692 ;;; mode: C++ *** |
|
2693 ;;; End: *** |
|
2694 */ |