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