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