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 |
973
|
36 #include <strstream.h> |
522
|
37 |
1
|
38 #include "SLStack.h" |
|
39 |
1497
|
40 // These would be alphabetical, but y.tab.h must be included before |
|
41 // oct-gperf.h and y.tab.h must be included after token.h and the tree |
|
42 // class declarations. We can't include y.tab.h in oct-gperf.h |
|
43 // because it may not be protected to allow it to be included multiple |
|
44 // times. |
|
45 |
2181
|
46 #include "defun.h" |
1355
|
47 #include "error.h" |
1351
|
48 #include "input.h" |
1355
|
49 #include "lex.h" |
2891
|
50 #include "ov.h" |
1355
|
51 #include "parse.h" |
1740
|
52 #include "pt-base.h" |
|
53 #include "pt-cmd.h" |
2891
|
54 #include "pt-const.h" |
1740
|
55 #include "pt-exp.h" |
1829
|
56 #include "pt-mat.h" |
1740
|
57 #include "pt-misc.h" |
|
58 #include "pt-plot.h" |
2891
|
59 #include "symtab.h" |
|
60 #include "token.h" |
|
61 #include "toplev.h" |
1355
|
62 #include "utils.h" |
|
63 #include "variables.h" |
2492
|
64 #include <y.tab.h> |
|
65 #include <oct-gperf.h> |
1
|
66 |
2716
|
67 #if ! (defined (FLEX_SCANNER) \ |
|
68 && defined (YY_FLEX_MAJOR_VERSION) && YY_FLEX_MAJOR_VERSION >= 2 \ |
|
69 && defined (YY_FLEX_MINOR_VERSION) && YY_FLEX_MINOR_VERSION >= 5) |
|
70 #error lex.l requires flex version 2.5.4 or later |
|
71 #endif |
|
72 |
1826
|
73 // Flags that need to be shared between the lexer and parser. |
|
74 lexical_feedback lexer_flags; |
|
75 |
1351
|
76 // Stack to hold tokens so that we can delete them when the parser is |
|
77 // reset and avoid growing forever just because we are stashing some |
|
78 // information. This has to appear before lex.h is included, because |
|
79 // one of the macros defined there uses token_stack. |
2614
|
80 // |
|
81 // XXX FIXME XXX -- this should really be static, but that causes |
|
82 // problems on some systems. |
|
83 SLStack <token*> token_stack; |
1351
|
84 |
1826
|
85 // Did eat_whitespace() eat a space or tab, or a newline, or both? |
1
|
86 |
1826
|
87 typedef int yum_yum; |
1
|
88 |
1826
|
89 const yum_yum ATE_NOTHING = 0; |
|
90 const yum_yum ATE_SPACE_OR_TAB = 1; |
|
91 const yum_yum ATE_NEWLINE = 2; |
1088
|
92 |
1
|
93 // Is the closest nesting level a square brace or a paren? |
1826
|
94 |
|
95 class brace_paren_nesting_level : public SLStack <int> |
|
96 { |
|
97 public: |
|
98 |
|
99 brace_paren_nesting_level (void) : SLStack<int> () { } |
|
100 |
|
101 ~brace_paren_nesting_level (void) { } |
|
102 |
|
103 void brace (void) { push (BRACE); } |
|
104 bool is_brace (void) { return ! empty () && top () == BRACE; } |
|
105 |
|
106 void paren (void) { push (PAREN); } |
|
107 bool is_paren (void) { return ! empty () && top () == PAREN; } |
985
|
108 |
1826
|
109 bool none (void) { return empty (); } |
|
110 |
|
111 void remove (void) { if (! empty ()) SLStack<int>::pop (); } |
|
112 |
|
113 private: |
|
114 |
|
115 enum { BRACE = 1, PAREN = 2 }; |
|
116 |
|
117 brace_paren_nesting_level (const brace_paren_nesting_level&); |
|
118 |
|
119 brace_paren_nesting_level& operator = (const brace_paren_nesting_level&); |
|
120 }; |
|
121 |
|
122 static brace_paren_nesting_level nesting_level; |
1
|
123 |
2167
|
124 // Should whitespace in a literal matrix list be automatically |
|
125 // converted to commas and semicolons? |
|
126 // |
|
127 // user specifies value of var |
|
128 // -------------- ------------ |
|
129 // "ignore" 2 |
|
130 // "traditional" 1 |
|
131 // anything else 0 |
|
132 // |
|
133 // Octave will never insert a comma in a literal matrix list if the |
|
134 // user specifies "ignore". For example, the statement [1 2] will |
|
135 // result in an error instead of being treated the same as [1, 2], and |
|
136 // the statement |
|
137 // |
|
138 // [ 1, 2, |
|
139 // 3, 4 ] |
|
140 // |
|
141 // will result in the vector [1 2 3 4] instead of a matrix. |
|
142 // |
|
143 // Traditional behavior makes Octave convert spaces to a comma between |
|
144 // identifiers and `('. For example, the statement |
|
145 // |
|
146 // [eye (2)] |
|
147 // |
|
148 // will be parsed as |
|
149 // |
|
150 // [eye, (2)] |
|
151 // |
|
152 // and will result in an error since the `eye' function will be |
|
153 // called with no arguments. To get around this, you would have to |
|
154 // omit the space between `eye' and the `('. |
|
155 // |
|
156 // The default value is 0, which results in behavior that is the same |
|
157 // as traditional, except that Octave does not convert spaces to a |
|
158 // comma between identifiers and `('. For example, the statement |
|
159 // |
|
160 // [eye (2)] |
|
161 // |
|
162 // will result in a call to `eye' with the argument `2'. |
|
163 |
|
164 static int Vwhitespace_in_literal_matrix; |
|
165 |
|
166 |
146
|
167 // Forward declarations for functions defined at the bottom of this |
|
168 // file. |
|
169 |
1
|
170 static void do_string_escapes (char *s); |
|
171 static void fixup_column_count (char *s); |
146
|
172 static void do_comma_insert_check (void); |
1823
|
173 static int is_plot_keyword (const string& s); |
|
174 static int is_keyword (const string& s); |
|
175 static string plot_style_token (const string& s); |
|
176 static symbol_record *lookup_identifier (const string& s); |
1
|
177 static void grab_help_text (void); |
2857
|
178 static bool match_any (char c, const char *s); |
|
179 static bool next_token_is_bin_op (int spc_prev, char *yytext); |
|
180 static bool next_token_is_postfix_unary_op (int spc_prev, char *yytext); |
1823
|
181 static string strip_trailing_whitespace (char *s); |
972
|
182 static void handle_number (char *yytext); |
975
|
183 static int handle_string (char delim, int text_style = 0); |
1001
|
184 static int handle_close_brace (int spc_gobbled); |
1823
|
185 static int handle_identifier (const string& tok, int spc_gobbled); |
2857
|
186 static bool have_continuation (int trailing_comments_ok = 1); |
|
187 static bool have_ellipsis_continuation (int trailing_comments_ok = 1); |
1826
|
188 static yum_yum eat_whitespace (void); |
|
189 static yum_yum eat_continuation (void); |
1
|
190 |
|
191 %} |
|
192 |
|
193 D [0-9] |
|
194 S [ \t] |
2042
|
195 NL ((\n)|(\r\n)) |
|
196 SNL ({S}|{NL}) |
1
|
197 EL (\.\.\.) |
967
|
198 BS (\\) |
|
199 CONT ({EL}|{BS}) |
1
|
200 Im [iIjJ] |
967
|
201 CCHAR [#%] |
|
202 COMMENT ({CCHAR}.*{NL}) |
|
203 SNLCMT ({SNL}|{COMMENT}) |
|
204 NOTEQ ((~=)|(!=)|(<>)) |
|
205 POW ((\*\*)|(\^)) |
|
206 EPOW (\.{POW}) |
|
207 NOT ((\~)|(\!)) |
1
|
208 IDENT ([_a-zA-Z][_a-zA-Z0-9]*) |
|
209 EXPON ([DdEe][+-]?{D}+) |
968
|
210 NUMBER (({D}+\.?{D}*{EXPON}?)|(\.{D}+{EXPON}?)) |
1
|
211 %% |
|
212 |
968
|
213 %{ |
|
214 // Help and other text-style functions are a pain in the ass. This |
|
215 // stuff needs to be simplified. May require some changes in the |
|
216 // parser too. |
|
217 %} |
|
218 |
967
|
219 <TEXT_FCN>{NL} { |
|
220 BEGIN 0; |
|
221 current_input_column = 1; |
2857
|
222 lexer_flags.quote_is_transpose = false; |
|
223 lexer_flags.cant_be_identifier = false; |
|
224 lexer_flags.convert_spaces_to_comma = true; |
967
|
225 return '\n'; |
|
226 } |
1
|
227 |
967
|
228 <TEXT_FCN>[\;\,] { |
1826
|
229 if (lexer_flags.doing_set && strcmp (yytext, ",") == 0) |
967
|
230 { |
1060
|
231 TOK_PUSH_AND_RETURN (yytext, TEXT); |
967
|
232 } |
|
233 else |
|
234 { |
|
235 BEGIN 0; |
|
236 if (strcmp (yytext, ",") == 0) |
|
237 TOK_RETURN (','); |
|
238 else |
|
239 TOK_RETURN (';'); |
|
240 } |
|
241 } |
1
|
242 |
975
|
243 <TEXT_FCN>[\"\'] { |
|
244 current_input_column++; |
|
245 return handle_string (yytext[0], 1); |
|
246 } |
|
247 |
1
|
248 <TEXT_FCN>[^ \t\n\;\,]*{S}* { |
1823
|
249 string tok = strip_trailing_whitespace (yytext); |
1060
|
250 TOK_PUSH_AND_RETURN (tok, TEXT); |
967
|
251 } |
1
|
252 |
968
|
253 %{ |
1
|
254 // For this and the next two rules, we're looking at ']', and we |
971
|
255 // need to know if the next token is `=' or `=='. |
1
|
256 // |
|
257 // It would have been so much easier if the delimiters were simply |
|
258 // different for the expression on the left hand side of the equals |
|
259 // operator. |
971
|
260 // |
|
261 // It's also a pain in the ass to decide whether to insert a comma |
|
262 // after seeing a ']' character... |
968
|
263 %} |
|
264 |
2119
|
265 <MATRIX>{SNLCMT}*\]{S}* { |
1001
|
266 fixup_column_count (yytext); |
|
267 int c = yytext[yyleng-1]; |
|
268 int cont_is_spc = eat_continuation (); |
|
269 int spc_gobbled = (cont_is_spc || c == ' ' || c == '\t'); |
|
270 return handle_close_brace (spc_gobbled); |
967
|
271 } |
1
|
272 |
968
|
273 %{ |
1088
|
274 // Commas are element separators in matrix constants. If we don't |
|
275 // check for continuations here we can end up inserting too many |
|
276 // commas. |
968
|
277 %} |
|
278 |
967
|
279 <MATRIX>{S}*\,{S}* { |
1088
|
280 current_input_column += yyleng; |
|
281 int tmp = eat_continuation (); |
2857
|
282 lexer_flags.quote_is_transpose = false; |
|
283 lexer_flags.cant_be_identifier = false; |
|
284 lexer_flags.convert_spaces_to_comma = true; |
2167
|
285 if (Vwhitespace_in_literal_matrix != 2 |
1088
|
286 && (tmp & ATE_NEWLINE) == ATE_NEWLINE) |
|
287 unput (';'); |
|
288 return (','); |
967
|
289 } |
1
|
290 |
968
|
291 %{ |
|
292 // In some cases, spaces in matrix constants can turn into commas. |
|
293 // If commas are required, spaces are not important in matrix |
1088
|
294 // constants so we just eat them. If we don't check for continuations |
|
295 // here we can end up inserting too many commas. |
968
|
296 %} |
430
|
297 |
968
|
298 <MATRIX>{S}+ { |
1088
|
299 current_input_column += yyleng; |
2167
|
300 if (Vwhitespace_in_literal_matrix != 2) |
967
|
301 { |
1088
|
302 int tmp = eat_continuation (); |
967
|
303 int bin_op = next_token_is_bin_op (1, yytext); |
|
304 int postfix_un_op = next_token_is_postfix_unary_op (1, yytext); |
|
305 |
1826
|
306 if (! (postfix_un_op || bin_op) |
|
307 && nesting_level.is_brace () |
|
308 && lexer_flags.convert_spaces_to_comma) |
1088
|
309 { |
2857
|
310 lexer_flags.quote_is_transpose = false; |
|
311 lexer_flags.cant_be_identifier = false; |
|
312 lexer_flags.convert_spaces_to_comma = true; |
1088
|
313 if ((tmp & ATE_NEWLINE) == ATE_NEWLINE) |
|
314 unput (';'); |
|
315 return (','); |
|
316 } |
967
|
317 } |
|
318 } |
430
|
319 |
968
|
320 %{ |
1088
|
321 // Semicolons are handled as row seprators in matrix constants. If we |
|
322 // don't eat whitespace here we can end up inserting too many |
|
323 // semicolons. |
968
|
324 %} |
|
325 |
985
|
326 <MATRIX>{SNLCMT}*;{SNLCMT}* { |
967
|
327 fixup_column_count (yytext); |
1001
|
328 eat_whitespace (); |
2857
|
329 lexer_flags.quote_is_transpose = false; |
|
330 lexer_flags.cant_be_identifier = false; |
|
331 lexer_flags.convert_spaces_to_comma = true; |
967
|
332 return ';'; |
|
333 } |
|
334 |
968
|
335 %{ |
1088
|
336 // In some cases, new lines can also become row separators. If we |
|
337 // don't eat whitespace here we can end up inserting too many |
|
338 // semicolons. |
985
|
339 %} |
|
340 |
|
341 <MATRIX>{SNLCMT}*\n{SNLCMT}* { |
1082
|
342 fixup_column_count (yytext); |
1088
|
343 eat_whitespace (); |
2167
|
344 if (Vwhitespace_in_literal_matrix != 2) |
985
|
345 { |
2857
|
346 lexer_flags.quote_is_transpose = false; |
|
347 lexer_flags.cant_be_identifier = false; |
|
348 lexer_flags.convert_spaces_to_comma = true; |
985
|
349 |
1826
|
350 if (nesting_level.none ()) |
985
|
351 return LEXICAL_ERROR; |
|
352 |
1826
|
353 if (nesting_level.is_brace ()) |
985
|
354 return ';'; |
|
355 } |
|
356 } |
|
357 |
|
358 %{ |
968
|
359 // Open and close brace are handled differently if we are in the range |
|
360 // part of a plot command. |
975
|
361 // |
968
|
362 %} |
1
|
363 |
967
|
364 \[{S}* { |
1826
|
365 nesting_level.brace (); |
975
|
366 |
1082
|
367 current_input_column += yyleng; |
2857
|
368 lexer_flags.quote_is_transpose = false; |
|
369 lexer_flags.cant_be_identifier = false; |
|
370 lexer_flags.convert_spaces_to_comma = true; |
975
|
371 |
|
372 promptflag--; |
|
373 eat_whitespace (); |
|
374 |
1826
|
375 if (lexer_flags.plotting && ! lexer_flags.past_plot_range) |
967
|
376 { |
2857
|
377 lexer_flags.in_plot_range = true; |
1082
|
378 return OPEN_BRACE; |
967
|
379 } |
|
380 else |
|
381 { |
1826
|
382 lexer_flags.braceflag++; |
975
|
383 BEGIN MATRIX; |
1082
|
384 return '['; |
967
|
385 } |
|
386 } |
1
|
387 |
968
|
388 \] { |
1826
|
389 nesting_level.remove (); |
968
|
390 |
1826
|
391 if (lexer_flags.plotting && ! lexer_flags.past_plot_range) |
968
|
392 { |
2857
|
393 lexer_flags.in_plot_range = false; |
968
|
394 TOK_RETURN (CLOSE_BRACE); |
|
395 } |
|
396 else |
|
397 TOK_RETURN (']'); |
|
398 } |
|
399 |
|
400 %{ |
|
401 // Imaginary numbers. |
|
402 %} |
|
403 |
|
404 {NUMBER}{Im} { |
972
|
405 handle_number (yytext); |
968
|
406 return IMAG_NUM; |
|
407 } |
|
408 |
|
409 %{ |
|
410 // Real numbers. Don't grab the `.' part of a dot operator as part of |
|
411 // the constant. |
|
412 %} |
|
413 |
|
414 {D}+/\.[\*/\\^'] | |
|
415 {NUMBER} { |
972
|
416 handle_number (yytext); |
968
|
417 return NUM; |
|
418 } |
|
419 |
|
420 %{ |
|
421 // Eat whitespace. Whitespace inside matrix constants is handled by |
|
422 // the <MATRIX> start state code above. |
|
423 %} |
|
424 |
967
|
425 {S}* { |
|
426 current_input_column += yyleng; |
|
427 } |
|
428 |
968
|
429 %{ |
|
430 // Continuation lines. Allow comments after continuations. |
|
431 %} |
|
432 |
967
|
433 {CONT}{S}*{NL} | |
|
434 {CONT}{S}*{COMMENT} { |
|
435 promptflag--; |
|
436 current_input_column = 1; |
|
437 } |
1
|
438 |
968
|
439 %{ |
|
440 // An ellipsis not at the end of a line is not a continuation, but |
|
441 // does have another meaning. |
|
442 %} |
|
443 |
967
|
444 {EL} { |
|
445 return ELLIPSIS; |
|
446 } |
1
|
447 |
968
|
448 %{ |
|
449 // End of file. |
|
450 %} |
|
451 |
967
|
452 <<EOF>> { |
|
453 TOK_RETURN (END_OF_INPUT); |
|
454 } |
1
|
455 |
968
|
456 %{ |
970
|
457 // Identifiers. Truncate the token at the first space or tab but |
|
458 // don't write directly on yytext. |
968
|
459 %} |
|
460 |
967
|
461 {IDENT}{S}* { |
1823
|
462 string tok = strip_trailing_whitespace (yytext); |
1001
|
463 int c = yytext[yyleng-1]; |
|
464 int cont_is_spc = eat_continuation (); |
|
465 int spc_gobbled = (cont_is_spc || c == ' ' || c == '\t'); |
|
466 return handle_identifier (tok, spc_gobbled); |
967
|
467 } |
1
|
468 |
968
|
469 %{ |
|
470 // A new line character. New line characters inside matrix constants |
985
|
471 // are handled by the <MATRIX> start state code above. If closest |
|
472 // nesting is inside parentheses, don't return a row separator. |
968
|
473 %} |
|
474 |
967
|
475 {NL} { |
|
476 current_input_column = 1; |
2857
|
477 lexer_flags.quote_is_transpose = false; |
|
478 lexer_flags.cant_be_identifier = false; |
|
479 lexer_flags.convert_spaces_to_comma = true; |
985
|
480 |
1826
|
481 if (nesting_level.none ()) |
985
|
482 return '\n'; |
|
483 |
1826
|
484 if (nesting_level.is_brace ()) |
985
|
485 return LEXICAL_ERROR; |
967
|
486 } |
1
|
487 |
968
|
488 %{ |
|
489 // Single quote can either be the beginning of a string or a transpose |
|
490 // operator. |
|
491 %} |
|
492 |
967
|
493 "'" { |
|
494 current_input_column++; |
2857
|
495 lexer_flags.convert_spaces_to_comma = true; |
1
|
496 |
1826
|
497 if (lexer_flags.quote_is_transpose) |
967
|
498 { |
|
499 do_comma_insert_check (); |
|
500 return QUOTE; |
|
501 } |
|
502 else |
973
|
503 return handle_string ('\''); |
967
|
504 } |
1
|
505 |
968
|
506 %{ |
971
|
507 // Double quotes always begin strings. |
|
508 %} |
|
509 |
973
|
510 \" { |
|
511 current_input_column++; |
|
512 return handle_string ('"'); |
|
513 } |
971
|
514 |
|
515 %{ |
|
516 // The colon operator is handled differently if we are in the range |
|
517 // part of a plot command. |
968
|
518 %} |
|
519 |
967
|
520 ":" { |
1826
|
521 if (lexer_flags.plotting |
|
522 && (lexer_flags.in_plot_range || lexer_flags.in_plot_using)) |
2857
|
523 BIN_OP_RETURN (COLON, true); |
967
|
524 else |
2857
|
525 BIN_OP_RETURN (':', false); |
967
|
526 } |
1
|
527 |
968
|
528 %{ |
985
|
529 // Gobble comments. If closest nesting is inside parentheses, don't |
|
530 // return a new line. |
|
531 %} |
968
|
532 |
967
|
533 {CCHAR} { |
1826
|
534 if (help_buf.empty () |
|
535 && lexer_flags.beginning_of_function |
|
536 && nesting_level.none ()) |
967
|
537 { |
|
538 grab_help_text (); |
2857
|
539 lexer_flags.beginning_of_function = false; |
967
|
540 } |
|
541 else |
|
542 { |
|
543 int c; |
|
544 while ((c = yyinput ()) != EOF && c != '\n') |
|
545 ; // Eat comment. |
|
546 } |
440
|
547 |
967
|
548 current_input_column = 1; |
2857
|
549 lexer_flags.quote_is_transpose = false; |
|
550 lexer_flags.cant_be_identifier = false; |
|
551 lexer_flags.convert_spaces_to_comma = true; |
985
|
552 |
1826
|
553 if (nesting_level.none ()) |
985
|
554 return '\n'; |
1826
|
555 else if (nesting_level.is_brace ()) |
1566
|
556 return ';'; |
967
|
557 } |
440
|
558 |
968
|
559 %{ |
|
560 // Other operators. |
|
561 %} |
|
562 |
2857
|
563 ".+" { BIN_OP_RETURN (EPLUS, false); } |
|
564 ".-" { BIN_OP_RETURN (EMINUS, false); } |
|
565 ".*" { BIN_OP_RETURN (EMUL, false); } |
|
566 "./" { BIN_OP_RETURN (EDIV, false); } |
|
567 ".\\" { BIN_OP_RETURN (ELEFTDIV, false); } |
|
568 {EPOW} { BIN_OP_RETURN (EPOW, false); } |
|
569 ".'" { do_comma_insert_check (); BIN_OP_RETURN (TRANSPOSE, true); } |
|
570 "++" { do_comma_insert_check (); BIN_OP_RETURN (PLUS_PLUS, true); } |
|
571 "--" { do_comma_insert_check (); BIN_OP_RETURN (MINUS_MINUS, true); } |
|
572 "<=" { BIN_OP_RETURN (EXPR_LE, false); } |
|
573 "==" { BIN_OP_RETURN (EXPR_EQ, false); } |
|
574 {NOTEQ} { BIN_OP_RETURN (EXPR_NE, false); } |
|
575 ">=" { BIN_OP_RETURN (EXPR_GE, false); } |
2877
|
576 "&" { BIN_OP_RETURN (EXPR_AND, false); } |
2857
|
577 "|" { BIN_OP_RETURN (EXPR_OR, false); } |
|
578 "<" { BIN_OP_RETURN (EXPR_LT, false); } |
|
579 ">" { BIN_OP_RETURN (EXPR_GT, false); } |
|
580 "*" { BIN_OP_RETURN ('*', false); } |
|
581 "/" { BIN_OP_RETURN ('/', false); } |
|
582 "\\" { BIN_OP_RETURN (LEFTDIV, false); } |
|
583 ";" { BIN_OP_RETURN (';', true); } |
|
584 "," { BIN_OP_RETURN (',', true); } |
|
585 {POW} { BIN_OP_RETURN (POW, false); } |
|
586 "=" { BIN_OP_RETURN ('=', true); } |
2877
|
587 "&&" { BIN_OP_RETURN (EXPR_AND_AND, false); } |
2857
|
588 "||" { BIN_OP_RETURN (EXPR_OR_OR, false); } |
2900
|
589 "<<" { BIN_OP_RETURN (LSHIFT, false); } |
|
590 ">>" { BIN_OP_RETURN (RSHIFT, false); } |
967
|
591 |
|
592 {NOT} { |
1826
|
593 if (lexer_flags.plotting && ! lexer_flags.in_plot_range) |
2857
|
594 lexer_flags.past_plot_range = true; |
|
595 BIN_OP_RETURN (EXPR_NOT, false); |
967
|
596 } |
1
|
597 |
1276
|
598 "+" { |
1826
|
599 if (lexer_flags.plotting && ! lexer_flags.in_plot_range) |
2857
|
600 lexer_flags.past_plot_range = true; |
|
601 BIN_OP_RETURN ('+', false); |
967
|
602 } |
|
603 |
1276
|
604 "-" { |
1826
|
605 if (lexer_flags.plotting && ! lexer_flags.in_plot_range) |
2857
|
606 lexer_flags.past_plot_range = true; |
|
607 BIN_OP_RETURN ('-', false); |
967
|
608 } |
|
609 |
|
610 "(" { |
1826
|
611 if (lexer_flags.plotting && ! lexer_flags.in_plot_range) |
2857
|
612 lexer_flags.past_plot_range = true; |
1826
|
613 nesting_level.paren (); |
985
|
614 promptflag--; |
967
|
615 TOK_RETURN ('('); |
|
616 } |
|
617 |
|
618 ")" { |
1826
|
619 nesting_level.remove (); |
1001
|
620 |
967
|
621 current_input_column++; |
2857
|
622 lexer_flags.cant_be_identifier = true; |
|
623 lexer_flags.quote_is_transpose = true; |
1826
|
624 lexer_flags.convert_spaces_to_comma = nesting_level.is_brace (); |
1001
|
625 do_comma_insert_check (); |
967
|
626 return ')'; |
|
627 } |
|
628 |
2066
|
629 "." { |
|
630 TOK_RETURN ('.'); |
|
631 } |
|
632 |
2877
|
633 "+=" { BIN_OP_RETURN (ADD_EQ, false); } |
|
634 "-=" { BIN_OP_RETURN (SUB_EQ, false); } |
|
635 "*=" { BIN_OP_RETURN (MUL_EQ, false); } |
|
636 "/=" { BIN_OP_RETURN (DIV_EQ, false); } |
|
637 ".+=" { BIN_OP_RETURN (ADD_EQ, false); } |
|
638 ".-=" { BIN_OP_RETURN (SUB_EQ, false); } |
|
639 ".*=" { BIN_OP_RETURN (EMUL_EQ, false); } |
|
640 "./=" { BIN_OP_RETURN (EDIV_EQ, false); } |
|
641 "&=" { BIN_OP_RETURN (AND_EQ, false); } |
|
642 "|=" { BIN_OP_RETURN (OR_EQ, false); } |
2900
|
643 "<<=" { BIN_OP_RETURN (LSHIFT_EQ, false); } |
|
644 ">>=" { BIN_OP_RETURN (RSHIFT_EQ, false); } |
2877
|
645 |
968
|
646 %{ |
2066
|
647 // Unrecognized input is a lexical error. |
968
|
648 %} |
1
|
649 |
2042
|
650 . { |
2066
|
651 current_input_column++; |
|
652 |
|
653 error ("invalid character `%s' near line %d, column %d", |
|
654 undo_string_escape (yytext[0]), input_line_number, |
|
655 current_input_column); |
|
656 |
|
657 return LEXICAL_ERROR; |
|
658 } |
1
|
659 |
|
660 %% |
|
661 |
767
|
662 // GAG. |
|
663 // |
|
664 // If we're reading a matrix and the next character is '[', make sure |
|
665 // that we insert a comma ahead of it. |
|
666 |
146
|
667 void |
1
|
668 do_comma_insert_check (void) |
|
669 { |
1001
|
670 int spc_gobbled = eat_continuation (); |
1
|
671 int c = yyinput (); |
146
|
672 yyunput (c, yytext); |
1001
|
673 if (spc_gobbled) |
|
674 yyunput (' ', yytext); |
1826
|
675 lexer_flags.do_comma_insert = (lexer_flags.braceflag && c == '['); |
1
|
676 } |
|
677 |
767
|
678 // Fix things up for errors or interrupts. The parser is never called |
|
679 // recursively, so it is always safe to reinitialize its state before |
|
680 // doing any parsing. |
|
681 |
1
|
682 void |
|
683 reset_parser (void) |
|
684 { |
1826
|
685 // Start off on the right foot. |
1
|
686 BEGIN 0; |
166
|
687 error_state = 0; |
287
|
688 |
1826
|
689 // We do want a prompt by default. |
1
|
690 promptflag = 1; |
287
|
691 |
1826
|
692 // Error may have occurred inside some parentheses or braces. |
985
|
693 nesting_level.clear (); |
287
|
694 |
1826
|
695 // Clear out the stack of token info used to track line and column |
|
696 // numbers. |
143
|
697 while (! token_stack.empty ()) |
|
698 delete token_stack.pop (); |
287
|
699 |
1826
|
700 // Can be reset by defining a function. |
985
|
701 if (! (reading_script_file || reading_fcn_file)) |
|
702 { |
|
703 current_input_column = 1; |
|
704 input_line_number = current_command_number - 1; |
|
705 } |
287
|
706 |
1826
|
707 // Only ask for input from stdin if we are expecting interactive |
|
708 // input. |
338
|
709 if (interactive && ! (reading_fcn_file || get_input_from_eval_string)) |
287
|
710 yyrestart (stdin); |
991
|
711 |
1826
|
712 // Clear the buffer for help text. |
|
713 help_buf.resize (0); |
1755
|
714 |
1826
|
715 // Reset other flags. |
|
716 lexer_flags.init (); |
1
|
717 } |
|
718 |
767
|
719 // Replace backslash escapes in a string with the real values. |
|
720 |
1
|
721 static void |
|
722 do_string_escapes (char *s) |
|
723 { |
|
724 char *p1 = s; |
|
725 char *p2 = s; |
|
726 while (*p2 != '\0') |
|
727 { |
|
728 if (*p2 == '\\' && *(p2+1) != '\0') |
|
729 { |
|
730 switch (*++p2) |
|
731 { |
|
732 case 'a': |
|
733 *p1 = '\a'; |
|
734 break; |
777
|
735 |
1
|
736 case 'b': // backspace |
|
737 *p1 = '\b'; |
|
738 break; |
777
|
739 |
1
|
740 case 'f': // formfeed |
|
741 *p1 = '\f'; |
|
742 break; |
777
|
743 |
1
|
744 case 'n': // newline |
|
745 *p1 = '\n'; |
|
746 break; |
777
|
747 |
1
|
748 case 'r': // carriage return |
|
749 *p1 = '\r'; |
|
750 break; |
777
|
751 |
1
|
752 case 't': // horizontal tab |
|
753 *p1 = '\t'; |
|
754 break; |
777
|
755 |
1
|
756 case 'v': // vertical tab |
|
757 *p1 = '\v'; |
|
758 break; |
777
|
759 |
1
|
760 case '\\': // backslash |
|
761 *p1 = '\\'; |
|
762 break; |
777
|
763 |
1
|
764 case '\'': // quote |
|
765 *p1 = '\''; |
|
766 break; |
777
|
767 |
1
|
768 case '"': // double quote |
|
769 *p1 = '"'; |
|
770 break; |
777
|
771 |
1
|
772 default: |
777
|
773 warning ("unrecognized escape sequence `\\%c' --\ |
|
774 converting to `%c'", *p2, *p2); |
1
|
775 *p1 = *p2; |
|
776 break; |
|
777 } |
|
778 } |
|
779 else |
|
780 { |
|
781 *p1 = *p2; |
|
782 } |
|
783 |
|
784 p1++; |
|
785 p2++; |
|
786 } |
|
787 |
|
788 *p1 = '\0'; |
|
789 } |
|
790 |
767
|
791 // If we read some newlines, we need figure out what column we're |
|
792 // really looking at. |
|
793 |
1
|
794 static void |
|
795 fixup_column_count (char *s) |
|
796 { |
|
797 char c; |
|
798 while ((c = *s++) != '\0') |
|
799 { |
|
800 if (c == '\n') |
143
|
801 current_input_column = 1; |
1
|
802 else |
|
803 current_input_column++; |
|
804 } |
|
805 } |
|
806 |
767
|
807 // Include these so that we don't have to link to libfl.a. |
246
|
808 |
1
|
809 #ifdef yywrap |
|
810 #undef yywrap |
|
811 #endif |
246
|
812 static int |
1
|
813 yywrap (void) |
|
814 { |
287
|
815 return 1; |
1
|
816 } |
|
817 |
767
|
818 // Tell us all what the current buffer is. |
|
819 |
1
|
820 YY_BUFFER_STATE |
|
821 current_buffer (void) |
|
822 { |
|
823 return YY_CURRENT_BUFFER; |
|
824 } |
|
825 |
767
|
826 // Create a new buffer. |
|
827 |
1
|
828 YY_BUFFER_STATE |
|
829 create_buffer (FILE *f) |
|
830 { |
|
831 return yy_create_buffer (f, YY_BUF_SIZE); |
|
832 } |
|
833 |
767
|
834 // Start reading a new buffer. |
|
835 |
1
|
836 void |
|
837 switch_to_buffer (YY_BUFFER_STATE buf) |
|
838 { |
|
839 yy_switch_to_buffer (buf); |
|
840 } |
|
841 |
767
|
842 // Delete a buffer. |
|
843 |
1
|
844 void |
|
845 delete_buffer (YY_BUFFER_STATE buf) |
|
846 { |
|
847 yy_delete_buffer (buf); |
|
848 } |
|
849 |
767
|
850 // Restore a buffer (for unwind-prot). |
|
851 |
1
|
852 void |
|
853 restore_input_buffer (void *buf) |
|
854 { |
2861
|
855 switch_to_buffer (static_cast<YY_BUFFER_STATE> (buf)); |
1
|
856 } |
|
857 |
767
|
858 // Delete a buffer (for unwind-prot). |
|
859 |
1
|
860 void |
|
861 delete_input_buffer (void *buf) |
|
862 { |
2861
|
863 delete_buffer (static_cast<YY_BUFFER_STATE> (buf)); |
1
|
864 } |
|
865 |
767
|
866 // Check to see if a character string matches any of the possible line |
|
867 // styles for plots. |
|
868 |
1823
|
869 static string |
|
870 plot_style_token (const string& s) |
1
|
871 { |
1823
|
872 string retval; |
|
873 |
2804
|
874 static const char *plot_styles[] = |
146
|
875 { |
925
|
876 "boxes", |
924
|
877 "boxerrorbars", |
2542
|
878 "boxxyerrorbars", |
|
879 "candlesticks", |
146
|
880 "dots", |
|
881 "errorbars", |
2542
|
882 "financebars", |
|
883 "fsteps", |
|
884 "histeps", |
146
|
885 "impulses", |
|
886 "lines", |
|
887 "linespoints", |
|
888 "points", |
926
|
889 "steps", |
2542
|
890 "vector", |
|
891 "xerrorbars", |
|
892 "xyerrorbars", |
|
893 "yerrorbars", |
522
|
894 0, |
146
|
895 }; |
|
896 |
2804
|
897 const char * const *tmp = plot_styles; |
522
|
898 while (*tmp) |
1
|
899 { |
1823
|
900 if (almost_match (*tmp, s.c_str ())) |
|
901 { |
|
902 retval = *tmp; |
|
903 break; |
|
904 } |
1
|
905 |
|
906 tmp++; |
|
907 } |
|
908 |
1823
|
909 return retval; |
1
|
910 } |
|
911 |
767
|
912 // Check to see if a character string matches any one of the plot |
941
|
913 // option keywords. Don't match abbreviations for clear, since that's |
|
914 // not a gnuplot keyword (users will probably only expect to be able |
|
915 // to abbreviate actual gnuplot keywords). |
767
|
916 |
1
|
917 static int |
1823
|
918 is_plot_keyword (const string& s) |
1
|
919 { |
1823
|
920 const char *t = s.c_str (); |
|
921 if (almost_match ("title", t)) |
146
|
922 { |
|
923 return TITLE; |
|
924 } |
1823
|
925 else if (almost_match ("using", t)) |
146
|
926 { |
2857
|
927 lexer_flags.in_plot_using = true; |
146
|
928 return USING; |
|
929 } |
1823
|
930 else if (almost_match ("with", t)) |
146
|
931 { |
2857
|
932 lexer_flags.in_plot_style = true; |
146
|
933 return WITH; |
|
934 } |
1823
|
935 else if (strcmp ("clear", t) == 0) |
883
|
936 { |
|
937 return CLEAR; |
|
938 } |
1
|
939 else |
146
|
940 { |
|
941 return 0; |
|
942 } |
1
|
943 } |
|
944 |
2877
|
945 // Handle keywords. |
767
|
946 |
1
|
947 static int |
1823
|
948 is_keyword (const string& s) |
1
|
949 { |
1826
|
950 if (lexer_flags.plotting && lexer_flags.in_plot_style) |
1
|
951 { |
1823
|
952 string sty = plot_style_token (s); |
|
953 |
|
954 if (! sty.empty ()) |
1
|
955 { |
2857
|
956 lexer_flags.in_plot_style = false; |
143
|
957 yylval.tok_val = new token (sty); |
|
958 token_stack.push (yylval.tok_val); |
1
|
959 return STYLE; |
|
960 } |
|
961 } |
|
962 |
143
|
963 int l = input_line_number; |
|
964 int c = current_input_column; |
|
965 |
1823
|
966 int len = s.length (); |
922
|
967 |
1823
|
968 const octave_kw *kw = octave_kw_lookup (s.c_str (), len); |
191
|
969 |
1497
|
970 if (kw) |
143
|
971 { |
1497
|
972 yylval.tok_val = 0; |
|
973 |
|
974 switch (kw->kw_id) |
|
975 { |
|
976 case all_va_args_kw: |
|
977 case break_kw: |
2764
|
978 case case_kw: |
1497
|
979 case catch_kw: |
|
980 case continue_kw: |
|
981 case else_kw: |
|
982 case elseif_kw: |
|
983 case global_kw: |
2764
|
984 case otherwise_kw: |
1497
|
985 case return_kw: |
2846
|
986 case static_kw: |
1497
|
987 case unwind_protect_cleanup_kw: |
|
988 break; |
|
989 |
|
990 case end_kw: |
|
991 yylval.tok_val = new token (token::simple_end, l, c); |
|
992 break; |
|
993 |
|
994 case end_try_catch_kw: |
|
995 yylval.tok_val = new token (token::try_catch_end, l, c); |
|
996 break; |
|
997 |
|
998 case end_unwind_protect_kw: |
|
999 yylval.tok_val = new token (token::unwind_protect_end, l, c); |
|
1000 break; |
|
1001 |
|
1002 case endfor_kw: |
|
1003 yylval.tok_val = new token (token::for_end, l, c); |
|
1004 break; |
|
1005 |
|
1006 case endfunction_kw: |
|
1007 yylval.tok_val = new token (token::function_end, l, c); |
|
1008 break; |
|
1009 |
|
1010 case endif_kw: |
|
1011 yylval.tok_val = new token (token::if_end, l, c); |
|
1012 break; |
|
1013 |
2764
|
1014 case endswitch_kw: |
|
1015 yylval.tok_val = new token (token::switch_end, l, c); |
|
1016 break; |
|
1017 |
1497
|
1018 case endwhile_kw: |
|
1019 yylval.tok_val = new token (token::while_end, l, c); |
|
1020 break; |
|
1021 |
|
1022 case for_kw: |
|
1023 case while_kw: |
|
1024 promptflag--; |
1826
|
1025 lexer_flags.looping++; |
1497
|
1026 break; |
|
1027 |
|
1028 case if_kw: |
|
1029 case try_kw: |
2764
|
1030 case switch_kw: |
1497
|
1031 case unwind_protect_kw: |
|
1032 promptflag--; |
|
1033 break; |
|
1034 |
|
1035 case gplot_kw: |
2857
|
1036 lexer_flags.plotting = true; |
1497
|
1037 yylval.tok_val = new token (token::two_dee, l, c); |
|
1038 break; |
|
1039 |
|
1040 case gsplot_kw: |
2857
|
1041 lexer_flags.plotting = true; |
1497
|
1042 yylval.tok_val = new token (token::three_dee, l, c); |
|
1043 break; |
|
1044 |
|
1045 case replot_kw: |
2857
|
1046 lexer_flags.plotting = true; |
1497
|
1047 yylval.tok_val = new token (token::replot, l, c); |
|
1048 break; |
|
1049 |
|
1050 case function_kw: |
1826
|
1051 if (lexer_flags.defining_func) |
1497
|
1052 { |
|
1053 error ("function keyword invalid within a function body"); |
|
1054 |
|
1055 if ((reading_fcn_file || reading_script_file) |
1755
|
1056 && ! curr_fcn_file_name.empty ()) |
1497
|
1057 error ("defining new function near line %d of file `%s.m'", |
1755
|
1058 input_line_number, curr_fcn_file_name.c_str ()); |
1497
|
1059 else |
1755
|
1060 error ("defining new function near line %d", |
|
1061 input_line_number); |
1497
|
1062 |
|
1063 return LEXICAL_ERROR; |
|
1064 } |
|
1065 else |
|
1066 { |
2877
|
1067 // Prepare for local symbols. |
|
1068 |
1497
|
1069 tmp_local_sym_tab = new symbol_table (); |
2877
|
1070 |
|
1071 promptflag--; |
|
1072 |
2857
|
1073 lexer_flags.defining_func = true; |
2877
|
1074 lexer_flags.parsed_function_name = false; |
2857
|
1075 lexer_flags.beginning_of_function = true; |
2877
|
1076 |
1497
|
1077 if (! (reading_fcn_file || reading_script_file)) |
|
1078 input_line_number = 1; |
|
1079 } |
|
1080 break; |
|
1081 |
|
1082 default: |
|
1083 panic_impossible (); |
|
1084 } |
|
1085 |
|
1086 if (! yylval.tok_val) |
|
1087 yylval.tok_val = new token (l, c); |
|
1088 |
476
|
1089 token_stack.push (yylval.tok_val); |
1497
|
1090 |
|
1091 return kw->tok; |
143
|
1092 } |
1
|
1093 |
|
1094 return 0; |
|
1095 } |
|
1096 |
767
|
1097 // Try to find an identifier. All binding to global or builtin |
|
1098 // variables occurs when expressions are evaluated. |
|
1099 |
1
|
1100 static symbol_record * |
1823
|
1101 lookup_identifier (const string& name) |
1
|
1102 { |
2856
|
1103 return curr_sym_tab->lookup (name, true); |
1
|
1104 } |
|
1105 |
2702
|
1106 static bool |
|
1107 is_variable (const string& name) |
|
1108 { |
2856
|
1109 symbol_record *sr = curr_sym_tab->lookup (name); |
2702
|
1110 |
|
1111 return sr && sr->is_variable (); |
|
1112 } |
|
1113 |
|
1114 static void |
|
1115 force_local_variable (const string& name) |
|
1116 { |
2856
|
1117 symbol_record *sr = curr_sym_tab->lookup (name, true); |
2702
|
1118 |
|
1119 if (sr) |
|
1120 sr->define (octave_value ()); |
|
1121 } |
|
1122 |
1019
|
1123 // Grab the help text from an function file. Always overwrites the |
|
1124 // current contents of help_buf. |
767
|
1125 |
2300
|
1126 // XXX FIXME XXX -- gobble_leading_white_space() in variables.cc |
|
1127 // duplicates some of this code! |
|
1128 |
1
|
1129 static void |
|
1130 grab_help_text (void) |
|
1131 { |
1755
|
1132 help_buf.resize (0); |
1019
|
1133 |
2300
|
1134 bool begin_comment = true; |
|
1135 bool in_comment = true; |
1019
|
1136 int c = 0; |
1
|
1137 |
1019
|
1138 while ((c = yyinput ()) != EOF) |
|
1139 { |
2300
|
1140 if (begin_comment) |
|
1141 { |
|
1142 if (c == '%' || c == '#') |
|
1143 continue; |
|
1144 else |
|
1145 begin_comment = false; |
|
1146 } |
|
1147 |
1019
|
1148 if (in_comment) |
1
|
1149 { |
1755
|
1150 help_buf += (char) c; |
|
1151 |
1019
|
1152 if (c == '\n') |
2300
|
1153 in_comment = false; |
1019
|
1154 } |
|
1155 else |
|
1156 { |
|
1157 switch (c) |
991
|
1158 { |
1019
|
1159 case '%': |
|
1160 case '#': |
2300
|
1161 in_comment = true; |
|
1162 begin_comment = true; |
1019
|
1163 break; |
777
|
1164 |
1019
|
1165 case ' ': |
|
1166 case '\t': |
|
1167 break; |
777
|
1168 |
1019
|
1169 default: |
|
1170 goto done; |
1
|
1171 } |
|
1172 } |
1019
|
1173 } |
991
|
1174 |
1019
|
1175 done: |
991
|
1176 |
1019
|
1177 if (c) |
|
1178 yyunput (c, yytext); |
1
|
1179 } |
|
1180 |
767
|
1181 // Return 1 if the given character matches any character in the given |
|
1182 // string. |
|
1183 |
2857
|
1184 static bool |
2804
|
1185 match_any (char c, const char *s) |
1
|
1186 { |
|
1187 char tmp; |
|
1188 while ((tmp = *s++) != '\0') |
|
1189 { |
|
1190 if (c == tmp) |
2857
|
1191 return true; |
1
|
1192 } |
2857
|
1193 return false; |
1
|
1194 } |
|
1195 |
767
|
1196 // Given information about the spacing surrounding an operator, |
|
1197 // return 1 if it looks like it should be treated as a binary |
|
1198 // operator. For example, |
|
1199 // |
|
1200 // [ 1 + 2 ] or [ 1+ 2] or [ 1+2 ] ==> binary |
|
1201 |
2857
|
1202 static bool |
1
|
1203 looks_like_bin_op (int spc_prev, int spc_next) |
|
1204 { |
608
|
1205 return ((spc_prev && spc_next) || ! spc_prev); |
1
|
1206 } |
|
1207 |
767
|
1208 // Try to determine if the next token should be treated as a postfix |
|
1209 // unary operator. This is ugly, but it seems to do the right thing. |
|
1210 |
2857
|
1211 static bool |
1
|
1212 next_token_is_postfix_unary_op (int spc_prev, char *yytext) |
|
1213 { |
2857
|
1214 bool un_op = false; |
1
|
1215 |
|
1216 int c0 = yyinput (); |
|
1217 int c1 = yyinput (); |
|
1218 |
|
1219 yyunput (c1, yytext); |
|
1220 yyunput (c0, yytext); |
|
1221 |
|
1222 int transpose = (c0 == '.' && c1 == '\''); |
|
1223 int hermitian = (c0 == '\''); |
|
1224 |
|
1225 un_op = (transpose || (hermitian && ! spc_prev)); |
|
1226 |
|
1227 return un_op; |
|
1228 } |
|
1229 |
767
|
1230 // Try to determine if the next token should be treated as a binary |
|
1231 // operator. This is even uglier, but it also seems to do the right |
1276
|
1232 // thing. Note that it is only necessary to check the spacing for `+' |
|
1233 // and `-', since those are the only tokens that can appear as unary |
|
1234 // ops too. |
1521
|
1235 // |
|
1236 // Note that this never returns true for `.', even though it can be a |
|
1237 // binary operator (the structure reference thing). The only time |
|
1238 // this appears to matter is for things like |
|
1239 // |
|
1240 // [ a . b ] |
|
1241 // |
|
1242 // which probably doesn't occur that often, can be worked around by |
|
1243 // eliminating the whitespace, putting the expression in parentheses, |
|
1244 // or using `whitespace_in_literal_matrix = "ignored"', so I think it |
|
1245 // is an acceptable change. It would be quite a bit harder to `fix' |
|
1246 // this. (Well, maybe not. the best fix would be to do away with the |
|
1247 // specialness of whitespace inside of `[ ... ]'). |
1554
|
1248 // |
|
1249 // However, we still do check for `.+', `.*', etc. |
767
|
1250 |
2857
|
1251 static bool |
1
|
1252 next_token_is_bin_op (int spc_prev, char *yytext) |
|
1253 { |
2857
|
1254 bool bin_op = false; |
1
|
1255 |
|
1256 int c0 = yyinput (); |
|
1257 |
|
1258 switch (c0) |
|
1259 { |
777
|
1260 case '+': |
|
1261 case '-': |
1276
|
1262 { |
|
1263 int c1 = yyinput (); |
|
1264 yyunput (c1, yytext); |
|
1265 int spc_next = (c1 == ' ' || c1 == '\t'); |
|
1266 bin_op = looks_like_bin_op (spc_prev, spc_next); |
|
1267 } |
|
1268 break; |
|
1269 |
1554
|
1270 case '.': |
|
1271 { |
|
1272 int c1 = yyinput (); |
|
1273 yyunput (c1, yytext); |
|
1274 bin_op = match_any (c1, "+-*/\\^"); |
|
1275 } |
|
1276 break; |
|
1277 |
777
|
1278 case '/': |
|
1279 case ':': |
|
1280 case '\\': |
|
1281 case '^': |
1
|
1282 case '&': |
|
1283 case '*': |
|
1284 case '|': |
|
1285 case '<': |
|
1286 case '>': |
777
|
1287 case '~': |
|
1288 case '!': |
|
1289 case '=': |
2857
|
1290 bin_op = true; |
1
|
1291 break; |
|
1292 |
|
1293 default: |
1276
|
1294 break; |
1
|
1295 } |
|
1296 |
|
1297 yyunput (c0, yytext); |
|
1298 |
|
1299 return bin_op; |
|
1300 } |
|
1301 |
767
|
1302 // Used to delete trailing white space from tokens. |
|
1303 |
1823
|
1304 static string |
1
|
1305 strip_trailing_whitespace (char *s) |
|
1306 { |
1823
|
1307 string retval = s; |
1
|
1308 |
1823
|
1309 size_t pos = retval.find_first_of (" \t"); |
1
|
1310 |
1823
|
1311 if (pos != NPOS) |
|
1312 retval.resize (pos); |
1
|
1313 |
|
1314 return retval; |
|
1315 } |
|
1316 |
1001
|
1317 // Discard whitespace, including comments and continuations. |
1088
|
1318 // |
|
1319 // Return value is logical OR of the following values: |
|
1320 // |
1826
|
1321 // ATE_NOTHING : no spaces to eat |
1088
|
1322 // ATE_SPACE_OR_TAB : space or tab in input |
|
1323 // ATE_NEWLINE : bare new line in input |
1001
|
1324 |
1826
|
1325 static yum_yum |
975
|
1326 eat_whitespace (void) |
|
1327 { |
1826
|
1328 yum_yum retval = ATE_NOTHING; |
2857
|
1329 bool in_comment = false; |
975
|
1330 int c; |
|
1331 while ((c = yyinput ()) != EOF) |
|
1332 { |
|
1333 current_input_column++; |
|
1334 |
|
1335 switch (c) |
|
1336 { |
|
1337 case ' ': |
|
1338 case '\t': |
1088
|
1339 retval |= ATE_SPACE_OR_TAB; |
975
|
1340 break; |
|
1341 |
|
1342 case '\n': |
1088
|
1343 retval |= ATE_NEWLINE; |
2857
|
1344 in_comment = false; |
975
|
1345 current_input_column = 0; |
|
1346 break; |
|
1347 |
|
1348 case '#': |
|
1349 case '%': |
2857
|
1350 in_comment = true; |
975
|
1351 break; |
|
1352 |
1001
|
1353 case '.': |
|
1354 if (in_comment) |
|
1355 break; |
|
1356 else |
|
1357 { |
|
1358 if (have_ellipsis_continuation ()) |
|
1359 break; |
|
1360 else |
|
1361 goto done; |
|
1362 } |
|
1363 |
|
1364 case '\\': |
|
1365 if (in_comment) |
|
1366 break; |
|
1367 else |
|
1368 { |
|
1369 if (have_continuation ()) |
|
1370 break; |
|
1371 else |
|
1372 goto done; |
|
1373 } |
|
1374 |
975
|
1375 default: |
|
1376 if (in_comment) |
|
1377 break; |
|
1378 else |
|
1379 goto done; |
|
1380 } |
|
1381 } |
|
1382 |
|
1383 done: |
|
1384 yyunput (c, yytext); |
1082
|
1385 current_input_column--; |
1001
|
1386 return retval; |
975
|
1387 } |
|
1388 |
|
1389 static void |
972
|
1390 handle_number (char *yytext) |
|
1391 { |
2621
|
1392 char *tmp = strsave (yytext); |
|
1393 |
|
1394 char *idx = strpbrk (tmp, "Dd"); |
|
1395 |
|
1396 if (idx) |
|
1397 *idx = 'e'; |
|
1398 |
972
|
1399 double value; |
2621
|
1400 int nread = sscanf (tmp, "%lf", &value); |
|
1401 |
|
1402 delete [] tmp; |
972
|
1403 |
1826
|
1404 // If yytext doesn't contain a valid number, we are in deep doo doo. |
985
|
1405 |
972
|
1406 assert (nread == 1); |
|
1407 |
1826
|
1408 lexer_flags.quote_is_transpose = 1; |
|
1409 lexer_flags.cant_be_identifier = 1; |
|
1410 lexer_flags.convert_spaces_to_comma = 1; |
972
|
1411 |
1826
|
1412 if (lexer_flags.plotting && ! lexer_flags.in_plot_range) |
|
1413 lexer_flags.past_plot_range = 1; |
972
|
1414 |
|
1415 yylval.tok_val = new token (value, yytext, input_line_number, |
|
1416 current_input_column); |
|
1417 |
|
1418 token_stack.push (yylval.tok_val); |
|
1419 |
|
1420 current_input_column += yyleng; |
|
1421 |
|
1422 do_comma_insert_check (); |
|
1423 } |
|
1424 |
1001
|
1425 // We have seen a backslash and need to find out if it should be |
|
1426 // treated as a continuation character. If so, this eats it, up to |
|
1427 // and including the new line character. |
|
1428 // |
973
|
1429 // Match whitespace only, followed by a comment character or newline. |
|
1430 // Once a comment character is found, discard all input until newline. |
|
1431 // If non-whitespace characters are found before comment |
|
1432 // characters, return 0. Otherwise, return 1. |
|
1433 |
2857
|
1434 static bool |
1091
|
1435 have_continuation (int trailing_comments_ok) |
973
|
1436 { |
|
1437 ostrstream buf; |
|
1438 |
2857
|
1439 bool in_comment = false; |
973
|
1440 char c; |
|
1441 while ((c = yyinput ()) != EOF) |
|
1442 { |
|
1443 buf << (char) c; |
|
1444 |
|
1445 switch (c) |
|
1446 { |
|
1447 case ' ': |
|
1448 case '\t': |
|
1449 break; |
|
1450 |
|
1451 case '%': |
|
1452 case '#': |
1091
|
1453 if (trailing_comments_ok) |
2857
|
1454 in_comment = true; |
1091
|
1455 else |
|
1456 goto cleanup; |
973
|
1457 break; |
|
1458 |
|
1459 case '\n': |
975
|
1460 current_input_column = 0; |
1001
|
1461 promptflag--; |
2857
|
1462 return true; |
973
|
1463 |
|
1464 default: |
1091
|
1465 if (! in_comment) |
|
1466 goto cleanup; |
|
1467 break; |
973
|
1468 } |
|
1469 } |
|
1470 |
|
1471 yyunput (c, yytext); |
2857
|
1472 return false; |
973
|
1473 |
1091
|
1474 cleanup: |
|
1475 buf << ends; |
|
1476 char *s = buf.str (); |
|
1477 if (s) |
|
1478 { |
|
1479 int len = strlen (s); |
|
1480 while (len--) |
|
1481 yyunput (s[len], yytext); |
|
1482 } |
|
1483 delete [] s; |
2857
|
1484 return false; |
973
|
1485 } |
|
1486 |
1001
|
1487 // We have seen a `.' and need to see if it is the start of a |
|
1488 // continuation. If so, this eats it, up to and including the new |
|
1489 // line character. |
|
1490 |
2857
|
1491 static bool |
1091
|
1492 have_ellipsis_continuation (int trailing_comments_ok) |
973
|
1493 { |
|
1494 char c1 = yyinput (); |
|
1495 if (c1 == '.') |
|
1496 { |
|
1497 char c2 = yyinput (); |
1091
|
1498 if (c2 == '.' && have_continuation (trailing_comments_ok)) |
2857
|
1499 return true; |
973
|
1500 else |
|
1501 { |
|
1502 yyunput (c2, yytext); |
|
1503 yyunput (c1, yytext); |
|
1504 } |
|
1505 } |
|
1506 else |
|
1507 yyunput (c1, yytext); |
|
1508 |
2857
|
1509 return false; |
973
|
1510 } |
|
1511 |
1001
|
1512 // See if we have a continuation line. If so, eat it and the leading |
|
1513 // whitespace on the next line. |
1088
|
1514 // |
|
1515 // Return value is the same as described for eat_whitespace(). |
1001
|
1516 |
1826
|
1517 static yum_yum |
1001
|
1518 eat_continuation (void) |
|
1519 { |
1826
|
1520 int retval = ATE_NOTHING; |
1001
|
1521 int c = yyinput (); |
|
1522 if ((c == '.' && have_ellipsis_continuation ()) |
|
1523 || (c == '\\' && have_continuation ())) |
|
1524 retval = eat_whitespace (); |
|
1525 else |
|
1526 yyunput (c, yytext); |
|
1527 |
|
1528 return retval; |
|
1529 } |
|
1530 |
973
|
1531 static int |
975
|
1532 handle_string (char delim, int text_style) |
973
|
1533 { |
|
1534 ostrstream buf; |
|
1535 |
|
1536 int c; |
1031
|
1537 int escape_pending = 0; |
973
|
1538 |
|
1539 while ((c = yyinput ()) != EOF) |
|
1540 { |
|
1541 current_input_column++; |
|
1542 |
|
1543 if (c == '\\') |
|
1544 { |
1053
|
1545 if (escape_pending) |
|
1546 { |
|
1547 buf << (char) c; |
|
1548 escape_pending = 0; |
|
1549 } |
|
1550 else |
|
1551 { |
1091
|
1552 if (have_continuation (0)) |
1053
|
1553 escape_pending = 0; |
|
1554 else |
|
1555 { |
|
1556 buf << (char) c; |
|
1557 escape_pending = 1; |
|
1558 } |
|
1559 } |
1031
|
1560 continue; |
973
|
1561 } |
|
1562 else if (c == '.') |
|
1563 { |
1091
|
1564 if (! have_ellipsis_continuation (0)) |
973
|
1565 buf << (char) c; |
|
1566 } |
|
1567 else if (c == '\n') |
|
1568 { |
1053
|
1569 error ("unterminated string constant"); |
973
|
1570 break; |
|
1571 } |
|
1572 else if (c == delim) |
|
1573 { |
1031
|
1574 if (escape_pending) |
973
|
1575 buf << (char) c; |
|
1576 else |
|
1577 { |
|
1578 c = yyinput (); |
|
1579 if (c == delim) |
|
1580 buf << (char) c; |
|
1581 else |
|
1582 { |
|
1583 yyunput (c, yytext); |
|
1584 buf << ends; |
|
1585 char *tok = buf.str (); |
|
1586 do_string_escapes (tok); |
975
|
1587 |
1826
|
1588 if (text_style && lexer_flags.doing_set) |
975
|
1589 { |
|
1590 if (tok) |
|
1591 { |
|
1592 int len = strlen (tok) + 3; |
|
1593 char *tmp = tok; |
|
1594 tok = new char [len]; |
|
1595 tok[0] = delim; |
|
1596 strcpy (tok+1, tmp); |
|
1597 tok[len-2] = delim; |
|
1598 tok[len-1] = '\0'; |
|
1599 delete [] tmp; |
|
1600 } |
|
1601 } |
|
1602 else |
|
1603 { |
2857
|
1604 lexer_flags.quote_is_transpose = true; |
|
1605 lexer_flags.cant_be_identifier = true; |
|
1606 lexer_flags.convert_spaces_to_comma = true; |
975
|
1607 } |
|
1608 |
973
|
1609 yylval.tok_val = new token (tok); |
|
1610 delete [] tok; |
|
1611 token_stack.push (yylval.tok_val); |
|
1612 return TEXT; |
|
1613 } |
|
1614 } |
|
1615 } |
|
1616 else |
|
1617 { |
|
1618 buf << (char) c; |
|
1619 } |
|
1620 |
1031
|
1621 escape_pending = 0; |
973
|
1622 } |
|
1623 |
|
1624 return LEXICAL_ERROR; |
|
1625 } |
|
1626 |
971
|
1627 static int |
1001
|
1628 handle_close_brace (int spc_gobbled) |
971
|
1629 { |
1826
|
1630 if (! nesting_level.none ()) |
971
|
1631 { |
1826
|
1632 nesting_level.remove (); |
|
1633 lexer_flags.braceflag--; |
971
|
1634 } |
|
1635 |
1826
|
1636 if (lexer_flags.braceflag == 0) |
1001
|
1637 BEGIN 0; |
|
1638 |
971
|
1639 int c1 = yyinput (); |
|
1640 if (c1 == '=') |
|
1641 { |
2857
|
1642 lexer_flags.quote_is_transpose = false; |
|
1643 lexer_flags.cant_be_identifier = false; |
|
1644 lexer_flags.convert_spaces_to_comma = true; |
971
|
1645 |
|
1646 int c2 = yyinput (); |
|
1647 unput (c2); |
|
1648 unput (c1); |
|
1649 |
1826
|
1650 if (c2 != '=' && lexer_flags.maybe_screwed_again) |
971
|
1651 return SCREW_TWO; |
|
1652 else |
|
1653 return ']'; |
|
1654 } |
|
1655 else |
|
1656 { |
|
1657 unput (c1); |
|
1658 |
2167
|
1659 if (lexer_flags.braceflag && Vwhitespace_in_literal_matrix != 2) |
971
|
1660 { |
1001
|
1661 int bin_op = next_token_is_bin_op (spc_gobbled, yytext); |
971
|
1662 int postfix_un_op = next_token_is_postfix_unary_op |
1001
|
1663 (spc_gobbled, yytext); |
971
|
1664 |
|
1665 int other_op = match_any (c1, ",;\n]"); |
|
1666 |
1826
|
1667 if (! (postfix_un_op || bin_op || other_op) |
|
1668 && nesting_level.is_brace () |
|
1669 && lexer_flags.convert_spaces_to_comma) |
971
|
1670 { |
|
1671 unput (','); |
|
1672 return ']'; |
|
1673 } |
|
1674 } |
|
1675 } |
|
1676 |
2857
|
1677 lexer_flags.quote_is_transpose = true; |
|
1678 lexer_flags.cant_be_identifier = false; |
|
1679 lexer_flags.convert_spaces_to_comma = true; |
971
|
1680 return ']'; |
|
1681 } |
|
1682 |
1072
|
1683 static void |
|
1684 maybe_unput_comma (int spc_gobbled) |
|
1685 { |
2167
|
1686 if (Vwhitespace_in_literal_matrix != 2 |
1826
|
1687 && nesting_level.is_brace ()) |
1072
|
1688 { |
|
1689 int bin_op = next_token_is_bin_op (spc_gobbled, yytext); |
|
1690 |
|
1691 int postfix_un_op = next_token_is_postfix_unary_op (spc_gobbled, |
|
1692 yytext); |
|
1693 |
|
1694 int c1 = yyinput (); |
|
1695 int c2 = yyinput (); |
|
1696 unput (c2); |
|
1697 unput (c1); |
|
1698 int sep_op = match_any (c1, ",;\n]"); |
|
1699 int dot_op = (c1 == '.' |
|
1700 && (isalpha (c2) || isspace (c2) || c2 == '_')); |
|
1701 int index_op = (c1 == '(' |
2167
|
1702 && (Vwhitespace_in_literal_matrix == 0 |
1072
|
1703 || ! spc_gobbled)); |
|
1704 |
|
1705 if (! (postfix_un_op || bin_op || sep_op || dot_op || index_op)) |
|
1706 unput (','); |
|
1707 } |
|
1708 } |
|
1709 |
767
|
1710 // Figure out exactly what kind of token to return when we have seen |
|
1711 // an identifier. Handles keywords. |
|
1712 |
146
|
1713 static int |
1823
|
1714 handle_identifier (const string& tok, int spc_gobbled) |
146
|
1715 { |
1826
|
1716 // It is almost always an error for an identifier to be followed |
|
1717 // directly by another identifier. Special cases are handled |
|
1718 // below. |
883
|
1719 |
2857
|
1720 lexer_flags.cant_be_identifier = true; |
883
|
1721 |
1826
|
1722 // If we are expecting a structure element, we just want to return |
|
1723 // TEXT_ID, which is a string that is also a valid identifier. But |
|
1724 // first, we have to decide whether to insert a comma. |
747
|
1725 |
1826
|
1726 if (lexer_flags.looking_at_indirect_ref) |
1072
|
1727 { |
|
1728 maybe_unput_comma (spc_gobbled); |
2819
|
1729 |
|
1730 yylval.tok_val = new token (tok, input_line_number, |
|
1731 current_input_column); |
|
1732 |
|
1733 token_stack.push (yylval.tok_val); |
|
1734 |
2857
|
1735 lexer_flags.cant_be_identifier = false; |
|
1736 lexer_flags.quote_is_transpose = true; |
|
1737 lexer_flags.convert_spaces_to_comma = true; |
2819
|
1738 |
|
1739 current_input_column += yyleng; |
|
1740 |
|
1741 return TEXT_ID; |
1072
|
1742 } |
747
|
1743 |
1826
|
1744 // If we have a regular keyword, or a plot STYLE, return it. |
|
1745 // Keywords can be followed by identifiers (TOK_RETURN handles |
|
1746 // that). |
146
|
1747 |
|
1748 int kw_token = is_keyword (tok); |
|
1749 if (kw_token) |
|
1750 { |
|
1751 if (kw_token == STYLE) |
|
1752 { |
1060
|
1753 current_input_column += yyleng; |
2857
|
1754 lexer_flags.quote_is_transpose = false; |
|
1755 lexer_flags.convert_spaces_to_comma = true; |
146
|
1756 return kw_token; |
|
1757 } |
|
1758 else |
|
1759 TOK_RETURN (kw_token); |
|
1760 } |
|
1761 |
1826
|
1762 // See if we have a plot keyword (title, using, with, or clear). |
146
|
1763 |
1826
|
1764 if (lexer_flags.plotting) |
941
|
1765 { |
1826
|
1766 // Yes, we really do need both of these plot_range variables. |
|
1767 // One is used to mark when we are past all possiblity of a plot |
|
1768 // range, the other is used to mark when we are actually between |
|
1769 // the square brackets that surround the range. |
146
|
1770 |
1826
|
1771 if (! lexer_flags.in_plot_range) |
2857
|
1772 lexer_flags.past_plot_range = true; |
941
|
1773 |
1273
|
1774 // Option keywords can't appear in parentheses or braces. |
|
1775 |
|
1776 int plot_option_kw = 0; |
1826
|
1777 if (nesting_level.none ()) |
1273
|
1778 plot_option_kw = is_plot_keyword (tok); |
941
|
1779 |
1826
|
1780 if (lexer_flags.cant_be_identifier && plot_option_kw) |
941
|
1781 TOK_RETURN (plot_option_kw); |
|
1782 } |
146
|
1783 |
1001
|
1784 int c = yyinput (); |
|
1785 yyunput (c, yytext); |
2702
|
1786 bool next_tok_is_eq = (c == '='); |
|
1787 bool next_tok_is_paren = (c == '('); |
1001
|
1788 |
1826
|
1789 // Make sure we put the return values of a function in the symbol |
|
1790 // table that is local to the function. |
146
|
1791 |
2877
|
1792 // If we are defining a function and we have not seen the function |
|
1793 // name yet and the next token is `=', then this identifier must be |
|
1794 // the only return value for the function and it belongs in the |
|
1795 // local symbol table. |
|
1796 |
1826
|
1797 if (next_tok_is_eq |
2877
|
1798 && lexer_flags.defining_func |
|
1799 && ! lexer_flags.parsed_function_name) |
146
|
1800 curr_sym_tab = tmp_local_sym_tab; |
|
1801 |
2702
|
1802 // Kluge alert. |
|
1803 // |
|
1804 // If we are looking at a text style function, set up to gobble its |
2745
|
1805 // arguments. |
|
1806 // |
|
1807 // If the following token is `=', or if we are parsing a function |
|
1808 // return list or function parameter list, force the symbol to be |
2702
|
1809 // inserted as a variable in the current symbol table. |
|
1810 |
|
1811 if (is_text_function_name (tok) && ! is_variable (tok)) |
|
1812 { |
2745
|
1813 if (next_tok_is_eq |
|
1814 || lexer_flags.looking_at_return_list |
|
1815 || lexer_flags.looking_at_parameter_list) |
|
1816 { |
|
1817 force_local_variable (tok); |
|
1818 } |
2702
|
1819 else if (! next_tok_is_paren) |
|
1820 { |
|
1821 if (tok == "gset") |
2857
|
1822 lexer_flags.doing_set = true; |
2702
|
1823 |
|
1824 BEGIN TEXT_FCN; |
|
1825 } |
|
1826 } |
|
1827 |
1826
|
1828 // Find the token in the symbol table. |
146
|
1829 |
|
1830 yylval.tok_val = new token (lookup_identifier (tok), |
|
1831 input_line_number, |
|
1832 current_input_column); |
|
1833 |
|
1834 token_stack.push (yylval.tok_val); |
|
1835 |
1826
|
1836 // After seeing an identifer, it is ok to convert spaces to a comma |
|
1837 // (if needed). |
146
|
1838 |
2857
|
1839 lexer_flags.convert_spaces_to_comma = true; |
146
|
1840 |
2877
|
1841 if (! next_tok_is_eq) |
|
1842 { |
|
1843 lexer_flags.quote_is_transpose = true; |
146
|
1844 |
2877
|
1845 do_comma_insert_check (); |
|
1846 |
|
1847 maybe_unput_comma (spc_gobbled); |
146
|
1848 } |
|
1849 |
2877
|
1850 current_input_column += yyleng; |
146
|
1851 |
|
1852 return NAME; |
|
1853 } |
|
1854 |
767
|
1855 // Print a warning if a function file that defines a function has |
|
1856 // anything other than comments and whitespace following the END token |
|
1857 // that matches the FUNCTION statement. |
|
1858 |
1
|
1859 void |
|
1860 check_for_garbage_after_fcn_def (void) |
|
1861 { |
1826
|
1862 // By making a newline be the next character to be read, we will |
|
1863 // force the parser to return after reading the function. Calling |
|
1864 // yyunput with EOF seems not to work... |
1
|
1865 |
2857
|
1866 bool in_comment = false; |
1
|
1867 int lineno = input_line_number; |
|
1868 int c; |
|
1869 while ((c = yyinput ()) != EOF) |
|
1870 { |
|
1871 switch (c) |
|
1872 { |
|
1873 case ' ': |
|
1874 case '\t': |
|
1875 case ';': |
|
1876 case ',': |
|
1877 break; |
777
|
1878 |
1
|
1879 case '\n': |
|
1880 if (in_comment) |
2857
|
1881 in_comment = false; |
1
|
1882 break; |
777
|
1883 |
1
|
1884 case '%': |
|
1885 case '#': |
2857
|
1886 in_comment = true; |
1
|
1887 break; |
777
|
1888 |
1
|
1889 default: |
|
1890 if (in_comment) |
|
1891 break; |
|
1892 else |
|
1893 { |
|
1894 warning ("ignoring trailing garbage after end of function\n\ |
1755
|
1895 near line %d of file `%s.m'", lineno, curr_fcn_file_name.c_str ()); |
1
|
1896 |
|
1897 yyunput ('\n', yytext); |
|
1898 return; |
|
1899 } |
|
1900 } |
|
1901 } |
|
1902 yyunput ('\n', yytext); |
|
1903 } |
|
1904 |
1826
|
1905 void |
|
1906 lexical_feedback::init (void) |
|
1907 { |
|
1908 // Not initially defining a matrix list. |
|
1909 braceflag = 0; |
|
1910 |
|
1911 // Not initially inside a loop or if statement. |
|
1912 looping = 0; |
|
1913 |
2857
|
1914 // Not initially defining a function. |
|
1915 beginning_of_function = false; |
|
1916 defining_func = false; |
2877
|
1917 parsed_function_name = false; |
2857
|
1918 |
|
1919 // Not parsing a function return or parameter list. |
|
1920 looking_at_return_list = false; |
|
1921 looking_at_parameter_list = false; |
|
1922 |
|
1923 // Next token can be identifier. |
|
1924 cant_be_identifier = false; |
|
1925 |
|
1926 // No need to do comma insert or convert spaces to comma at |
|
1927 // beginning of input. |
|
1928 convert_spaces_to_comma = true; |
|
1929 do_comma_insert = false; |
|
1930 |
|
1931 // Not initially doing any plotting or setting of plot attributes. |
|
1932 doing_set = false; |
|
1933 in_plot_range = false; |
|
1934 in_plot_style = false; |
|
1935 in_plot_using = false; |
|
1936 past_plot_range = false; |
|
1937 plotting = false; |
|
1938 |
1826
|
1939 // Not initially looking at indirect references. |
2857
|
1940 looking_at_indirect_ref = false; |
1826
|
1941 |
|
1942 // Not initially screwed by `function [...] = f (...)' syntax. |
|
1943 maybe_screwed_again = 0; |
1
|
1944 |
1826
|
1945 // Quote marks strings intially. |
2857
|
1946 quote_is_transpose = false; |
1826
|
1947 } |
|
1948 |
2167
|
1949 int |
|
1950 whitespace_in_literal_matrix (void) |
|
1951 { |
|
1952 int pref = 0; |
|
1953 string val = builtin_string_variable ("whitespace_in_literal_matrix"); |
|
1954 if (! val.empty ()) |
|
1955 { |
|
1956 if (val.compare ("ignore", 0, 6) == 0) |
|
1957 pref = 2; |
|
1958 else if (val.compare ("traditional", 0, 11) == 0) |
|
1959 pref = 1; |
|
1960 } |
|
1961 Vwhitespace_in_literal_matrix = pref; |
|
1962 return 0; |
|
1963 } |
|
1964 |
|
1965 void |
|
1966 symbols_of_lex (void) |
|
1967 { |
|
1968 DEFVAR (whitespace_in_literal_matrix, "", 0, whitespace_in_literal_matrix, |
|
1969 "control auto-insertion of commas and semicolons in literal matrices"); |
|
1970 } |
|
1971 |
1994
|
1972 /* |
|
1973 ;;; Local Variables: *** |
|
1974 ;;; mode: C++ *** |
|
1975 ;;; End: *** |
|
1976 */ |