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