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