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 (); |
1
|
673 int c = yyinput (); |
146
|
674 yyunput (c, yytext); |
1001
|
675 if (spc_gobbled) |
|
676 yyunput (' ', yytext); |
1826
|
677 lexer_flags.do_comma_insert = (lexer_flags.braceflag && c == '['); |
1
|
678 } |
|
679 |
767
|
680 // Fix things up for errors or interrupts. The parser is never called |
|
681 // recursively, so it is always safe to reinitialize its state before |
|
682 // doing any parsing. |
|
683 |
1
|
684 void |
|
685 reset_parser (void) |
|
686 { |
1826
|
687 // Start off on the right foot. |
1
|
688 BEGIN 0; |
166
|
689 error_state = 0; |
287
|
690 |
1826
|
691 // We do want a prompt by default. |
1
|
692 promptflag = 1; |
287
|
693 |
1826
|
694 // Error may have occurred inside some parentheses or braces. |
985
|
695 nesting_level.clear (); |
287
|
696 |
1826
|
697 // Clear out the stack of token info used to track line and column |
|
698 // numbers. |
143
|
699 while (! token_stack.empty ()) |
|
700 delete token_stack.pop (); |
287
|
701 |
1826
|
702 // Can be reset by defining a function. |
985
|
703 if (! (reading_script_file || reading_fcn_file)) |
|
704 { |
|
705 current_input_column = 1; |
2926
|
706 input_line_number = command_editor::current_command_number () - 1; |
985
|
707 } |
287
|
708 |
1826
|
709 // Only ask for input from stdin if we are expecting interactive |
|
710 // input. |
338
|
711 if (interactive && ! (reading_fcn_file || get_input_from_eval_string)) |
287
|
712 yyrestart (stdin); |
991
|
713 |
1826
|
714 // Clear the buffer for help text. |
|
715 help_buf.resize (0); |
1755
|
716 |
1826
|
717 // Reset other flags. |
|
718 lexer_flags.init (); |
1
|
719 } |
|
720 |
767
|
721 // Replace backslash escapes in a string with the real values. |
|
722 |
1
|
723 static void |
|
724 do_string_escapes (char *s) |
|
725 { |
|
726 char *p1 = s; |
|
727 char *p2 = s; |
|
728 while (*p2 != '\0') |
|
729 { |
|
730 if (*p2 == '\\' && *(p2+1) != '\0') |
|
731 { |
|
732 switch (*++p2) |
|
733 { |
|
734 case 'a': |
|
735 *p1 = '\a'; |
|
736 break; |
777
|
737 |
1
|
738 case 'b': // backspace |
|
739 *p1 = '\b'; |
|
740 break; |
777
|
741 |
1
|
742 case 'f': // formfeed |
|
743 *p1 = '\f'; |
|
744 break; |
777
|
745 |
1
|
746 case 'n': // newline |
|
747 *p1 = '\n'; |
|
748 break; |
777
|
749 |
1
|
750 case 'r': // carriage return |
|
751 *p1 = '\r'; |
|
752 break; |
777
|
753 |
1
|
754 case 't': // horizontal tab |
|
755 *p1 = '\t'; |
|
756 break; |
777
|
757 |
1
|
758 case 'v': // vertical tab |
|
759 *p1 = '\v'; |
|
760 break; |
777
|
761 |
1
|
762 case '\\': // backslash |
|
763 *p1 = '\\'; |
|
764 break; |
777
|
765 |
1
|
766 case '\'': // quote |
|
767 *p1 = '\''; |
|
768 break; |
777
|
769 |
1
|
770 case '"': // double quote |
|
771 *p1 = '"'; |
|
772 break; |
777
|
773 |
1
|
774 default: |
777
|
775 warning ("unrecognized escape sequence `\\%c' --\ |
|
776 converting to `%c'", *p2, *p2); |
1
|
777 *p1 = *p2; |
|
778 break; |
|
779 } |
|
780 } |
|
781 else |
|
782 { |
|
783 *p1 = *p2; |
|
784 } |
|
785 |
|
786 p1++; |
|
787 p2++; |
|
788 } |
|
789 |
|
790 *p1 = '\0'; |
|
791 } |
|
792 |
767
|
793 // If we read some newlines, we need figure out what column we're |
|
794 // really looking at. |
|
795 |
1
|
796 static void |
|
797 fixup_column_count (char *s) |
|
798 { |
|
799 char c; |
|
800 while ((c = *s++) != '\0') |
|
801 { |
|
802 if (c == '\n') |
143
|
803 current_input_column = 1; |
1
|
804 else |
|
805 current_input_column++; |
|
806 } |
|
807 } |
|
808 |
767
|
809 // Include these so that we don't have to link to libfl.a. |
246
|
810 |
1
|
811 #ifdef yywrap |
|
812 #undef yywrap |
|
813 #endif |
246
|
814 static int |
1
|
815 yywrap (void) |
|
816 { |
287
|
817 return 1; |
1
|
818 } |
|
819 |
767
|
820 // Tell us all what the current buffer is. |
|
821 |
1
|
822 YY_BUFFER_STATE |
|
823 current_buffer (void) |
|
824 { |
|
825 return YY_CURRENT_BUFFER; |
|
826 } |
|
827 |
767
|
828 // Create a new buffer. |
|
829 |
1
|
830 YY_BUFFER_STATE |
|
831 create_buffer (FILE *f) |
|
832 { |
|
833 return yy_create_buffer (f, YY_BUF_SIZE); |
|
834 } |
|
835 |
767
|
836 // Start reading a new buffer. |
|
837 |
1
|
838 void |
|
839 switch_to_buffer (YY_BUFFER_STATE buf) |
|
840 { |
|
841 yy_switch_to_buffer (buf); |
|
842 } |
|
843 |
767
|
844 // Delete a buffer. |
|
845 |
1
|
846 void |
|
847 delete_buffer (YY_BUFFER_STATE buf) |
|
848 { |
|
849 yy_delete_buffer (buf); |
|
850 } |
|
851 |
767
|
852 // Restore a buffer (for unwind-prot). |
|
853 |
1
|
854 void |
|
855 restore_input_buffer (void *buf) |
|
856 { |
2861
|
857 switch_to_buffer (static_cast<YY_BUFFER_STATE> (buf)); |
1
|
858 } |
|
859 |
767
|
860 // Delete a buffer (for unwind-prot). |
|
861 |
1
|
862 void |
|
863 delete_input_buffer (void *buf) |
|
864 { |
2861
|
865 delete_buffer (static_cast<YY_BUFFER_STATE> (buf)); |
1
|
866 } |
|
867 |
767
|
868 // Check to see if a character string matches any of the possible line |
|
869 // styles for plots. |
|
870 |
1823
|
871 static string |
|
872 plot_style_token (const string& s) |
1
|
873 { |
1823
|
874 string retval; |
|
875 |
2804
|
876 static const char *plot_styles[] = |
146
|
877 { |
925
|
878 "boxes", |
924
|
879 "boxerrorbars", |
2542
|
880 "boxxyerrorbars", |
|
881 "candlesticks", |
146
|
882 "dots", |
|
883 "errorbars", |
2542
|
884 "financebars", |
|
885 "fsteps", |
|
886 "histeps", |
146
|
887 "impulses", |
|
888 "lines", |
|
889 "linespoints", |
|
890 "points", |
926
|
891 "steps", |
2542
|
892 "vector", |
|
893 "xerrorbars", |
|
894 "xyerrorbars", |
|
895 "yerrorbars", |
522
|
896 0, |
146
|
897 }; |
|
898 |
2804
|
899 const char * const *tmp = plot_styles; |
522
|
900 while (*tmp) |
1
|
901 { |
1823
|
902 if (almost_match (*tmp, s.c_str ())) |
|
903 { |
|
904 retval = *tmp; |
|
905 break; |
|
906 } |
1
|
907 |
|
908 tmp++; |
|
909 } |
|
910 |
1823
|
911 return retval; |
1
|
912 } |
|
913 |
767
|
914 // Check to see if a character string matches any one of the plot |
941
|
915 // option keywords. Don't match abbreviations for clear, since that's |
|
916 // not a gnuplot keyword (users will probably only expect to be able |
|
917 // to abbreviate actual gnuplot keywords). |
767
|
918 |
1
|
919 static int |
1823
|
920 is_plot_keyword (const string& s) |
1
|
921 { |
1823
|
922 const char *t = s.c_str (); |
|
923 if (almost_match ("title", t)) |
146
|
924 { |
|
925 return TITLE; |
|
926 } |
1823
|
927 else if (almost_match ("using", t)) |
146
|
928 { |
2857
|
929 lexer_flags.in_plot_using = true; |
146
|
930 return USING; |
|
931 } |
1823
|
932 else if (almost_match ("with", t)) |
146
|
933 { |
2857
|
934 lexer_flags.in_plot_style = true; |
146
|
935 return WITH; |
|
936 } |
1823
|
937 else if (strcmp ("clear", t) == 0) |
883
|
938 { |
|
939 return CLEAR; |
|
940 } |
1
|
941 else |
146
|
942 { |
|
943 return 0; |
|
944 } |
1
|
945 } |
|
946 |
2877
|
947 // Handle keywords. |
767
|
948 |
1
|
949 static int |
1823
|
950 is_keyword (const string& s) |
1
|
951 { |
1826
|
952 if (lexer_flags.plotting && lexer_flags.in_plot_style) |
1
|
953 { |
1823
|
954 string sty = plot_style_token (s); |
|
955 |
|
956 if (! sty.empty ()) |
1
|
957 { |
2857
|
958 lexer_flags.in_plot_style = false; |
143
|
959 yylval.tok_val = new token (sty); |
|
960 token_stack.push (yylval.tok_val); |
1
|
961 return STYLE; |
|
962 } |
|
963 } |
|
964 |
143
|
965 int l = input_line_number; |
|
966 int c = current_input_column; |
|
967 |
1823
|
968 int len = s.length (); |
922
|
969 |
1823
|
970 const octave_kw *kw = octave_kw_lookup (s.c_str (), len); |
191
|
971 |
1497
|
972 if (kw) |
143
|
973 { |
1497
|
974 yylval.tok_val = 0; |
|
975 |
|
976 switch (kw->kw_id) |
|
977 { |
|
978 case all_va_args_kw: |
|
979 case break_kw: |
2764
|
980 case case_kw: |
1497
|
981 case catch_kw: |
|
982 case continue_kw: |
|
983 case else_kw: |
|
984 case elseif_kw: |
|
985 case global_kw: |
2764
|
986 case otherwise_kw: |
1497
|
987 case return_kw: |
2846
|
988 case static_kw: |
1497
|
989 case unwind_protect_cleanup_kw: |
|
990 break; |
|
991 |
|
992 case end_kw: |
|
993 yylval.tok_val = new token (token::simple_end, l, c); |
|
994 break; |
|
995 |
|
996 case end_try_catch_kw: |
|
997 yylval.tok_val = new token (token::try_catch_end, l, c); |
|
998 break; |
|
999 |
|
1000 case end_unwind_protect_kw: |
|
1001 yylval.tok_val = new token (token::unwind_protect_end, l, c); |
|
1002 break; |
|
1003 |
|
1004 case endfor_kw: |
|
1005 yylval.tok_val = new token (token::for_end, l, c); |
|
1006 break; |
|
1007 |
|
1008 case endfunction_kw: |
|
1009 yylval.tok_val = new token (token::function_end, l, c); |
|
1010 break; |
|
1011 |
|
1012 case endif_kw: |
|
1013 yylval.tok_val = new token (token::if_end, l, c); |
|
1014 break; |
|
1015 |
2764
|
1016 case endswitch_kw: |
|
1017 yylval.tok_val = new token (token::switch_end, l, c); |
|
1018 break; |
|
1019 |
1497
|
1020 case endwhile_kw: |
|
1021 yylval.tok_val = new token (token::while_end, l, c); |
|
1022 break; |
|
1023 |
|
1024 case for_kw: |
|
1025 case while_kw: |
|
1026 promptflag--; |
1826
|
1027 lexer_flags.looping++; |
1497
|
1028 break; |
|
1029 |
|
1030 case if_kw: |
|
1031 case try_kw: |
2764
|
1032 case switch_kw: |
1497
|
1033 case unwind_protect_kw: |
|
1034 promptflag--; |
|
1035 break; |
|
1036 |
|
1037 case gplot_kw: |
2857
|
1038 lexer_flags.plotting = true; |
1497
|
1039 yylval.tok_val = new token (token::two_dee, l, c); |
|
1040 break; |
|
1041 |
|
1042 case gsplot_kw: |
2857
|
1043 lexer_flags.plotting = true; |
1497
|
1044 yylval.tok_val = new token (token::three_dee, l, c); |
|
1045 break; |
|
1046 |
|
1047 case replot_kw: |
2857
|
1048 lexer_flags.plotting = true; |
1497
|
1049 yylval.tok_val = new token (token::replot, l, c); |
|
1050 break; |
|
1051 |
|
1052 case function_kw: |
1826
|
1053 if (lexer_flags.defining_func) |
1497
|
1054 { |
|
1055 error ("function keyword invalid within a function body"); |
|
1056 |
|
1057 if ((reading_fcn_file || reading_script_file) |
1755
|
1058 && ! curr_fcn_file_name.empty ()) |
1497
|
1059 error ("defining new function near line %d of file `%s.m'", |
1755
|
1060 input_line_number, curr_fcn_file_name.c_str ()); |
1497
|
1061 else |
1755
|
1062 error ("defining new function near line %d", |
|
1063 input_line_number); |
1497
|
1064 |
|
1065 return LEXICAL_ERROR; |
|
1066 } |
|
1067 else |
|
1068 { |
2877
|
1069 // Prepare for local symbols. |
|
1070 |
1497
|
1071 tmp_local_sym_tab = new symbol_table (); |
2877
|
1072 |
|
1073 promptflag--; |
|
1074 |
2857
|
1075 lexer_flags.defining_func = true; |
2877
|
1076 lexer_flags.parsed_function_name = false; |
2857
|
1077 lexer_flags.beginning_of_function = true; |
2877
|
1078 |
1497
|
1079 if (! (reading_fcn_file || reading_script_file)) |
|
1080 input_line_number = 1; |
|
1081 } |
|
1082 break; |
|
1083 |
|
1084 default: |
|
1085 panic_impossible (); |
|
1086 } |
|
1087 |
|
1088 if (! yylval.tok_val) |
|
1089 yylval.tok_val = new token (l, c); |
|
1090 |
476
|
1091 token_stack.push (yylval.tok_val); |
1497
|
1092 |
|
1093 return kw->tok; |
143
|
1094 } |
1
|
1095 |
|
1096 return 0; |
|
1097 } |
|
1098 |
767
|
1099 // Try to find an identifier. All binding to global or builtin |
|
1100 // variables occurs when expressions are evaluated. |
|
1101 |
1
|
1102 static symbol_record * |
1823
|
1103 lookup_identifier (const string& name) |
1
|
1104 { |
2856
|
1105 return curr_sym_tab->lookup (name, true); |
1
|
1106 } |
|
1107 |
2702
|
1108 static bool |
|
1109 is_variable (const string& name) |
|
1110 { |
2856
|
1111 symbol_record *sr = curr_sym_tab->lookup (name); |
2702
|
1112 |
|
1113 return sr && sr->is_variable (); |
|
1114 } |
|
1115 |
|
1116 static void |
|
1117 force_local_variable (const string& name) |
|
1118 { |
2856
|
1119 symbol_record *sr = curr_sym_tab->lookup (name, true); |
2702
|
1120 |
|
1121 if (sr) |
|
1122 sr->define (octave_value ()); |
|
1123 } |
|
1124 |
1019
|
1125 // Grab the help text from an function file. Always overwrites the |
|
1126 // current contents of help_buf. |
767
|
1127 |
2300
|
1128 // XXX FIXME XXX -- gobble_leading_white_space() in variables.cc |
|
1129 // duplicates some of this code! |
|
1130 |
1
|
1131 static void |
|
1132 grab_help_text (void) |
|
1133 { |
1755
|
1134 help_buf.resize (0); |
1019
|
1135 |
2300
|
1136 bool begin_comment = true; |
|
1137 bool in_comment = true; |
1019
|
1138 int c = 0; |
1
|
1139 |
1019
|
1140 while ((c = yyinput ()) != EOF) |
|
1141 { |
2300
|
1142 if (begin_comment) |
|
1143 { |
|
1144 if (c == '%' || c == '#') |
|
1145 continue; |
|
1146 else |
|
1147 begin_comment = false; |
|
1148 } |
|
1149 |
1019
|
1150 if (in_comment) |
1
|
1151 { |
1755
|
1152 help_buf += (char) c; |
|
1153 |
1019
|
1154 if (c == '\n') |
2300
|
1155 in_comment = false; |
1019
|
1156 } |
|
1157 else |
|
1158 { |
|
1159 switch (c) |
991
|
1160 { |
1019
|
1161 case '%': |
|
1162 case '#': |
2300
|
1163 in_comment = true; |
|
1164 begin_comment = true; |
1019
|
1165 break; |
777
|
1166 |
1019
|
1167 case ' ': |
|
1168 case '\t': |
|
1169 break; |
777
|
1170 |
1019
|
1171 default: |
|
1172 goto done; |
1
|
1173 } |
|
1174 } |
1019
|
1175 } |
991
|
1176 |
1019
|
1177 done: |
991
|
1178 |
1019
|
1179 if (c) |
|
1180 yyunput (c, yytext); |
1
|
1181 } |
|
1182 |
767
|
1183 // Return 1 if the given character matches any character in the given |
|
1184 // string. |
|
1185 |
2857
|
1186 static bool |
2804
|
1187 match_any (char c, const char *s) |
1
|
1188 { |
|
1189 char tmp; |
|
1190 while ((tmp = *s++) != '\0') |
|
1191 { |
|
1192 if (c == tmp) |
2857
|
1193 return true; |
1
|
1194 } |
2857
|
1195 return false; |
1
|
1196 } |
|
1197 |
767
|
1198 // Given information about the spacing surrounding an operator, |
|
1199 // return 1 if it looks like it should be treated as a binary |
|
1200 // operator. For example, |
|
1201 // |
|
1202 // [ 1 + 2 ] or [ 1+ 2] or [ 1+2 ] ==> binary |
|
1203 |
2857
|
1204 static bool |
1
|
1205 looks_like_bin_op (int spc_prev, int spc_next) |
|
1206 { |
608
|
1207 return ((spc_prev && spc_next) || ! spc_prev); |
1
|
1208 } |
|
1209 |
767
|
1210 // Try to determine if the next token should be treated as a postfix |
|
1211 // unary operator. This is ugly, but it seems to do the right thing. |
|
1212 |
2857
|
1213 static bool |
1
|
1214 next_token_is_postfix_unary_op (int spc_prev, char *yytext) |
|
1215 { |
2857
|
1216 bool un_op = false; |
1
|
1217 |
|
1218 int c0 = yyinput (); |
|
1219 int c1 = yyinput (); |
|
1220 |
|
1221 yyunput (c1, yytext); |
|
1222 yyunput (c0, yytext); |
|
1223 |
|
1224 int transpose = (c0 == '.' && c1 == '\''); |
|
1225 int hermitian = (c0 == '\''); |
|
1226 |
|
1227 un_op = (transpose || (hermitian && ! spc_prev)); |
|
1228 |
|
1229 return un_op; |
|
1230 } |
|
1231 |
767
|
1232 // Try to determine if the next token should be treated as a binary |
|
1233 // operator. This is even uglier, but it also seems to do the right |
1276
|
1234 // thing. Note that it is only necessary to check the spacing for `+' |
|
1235 // and `-', since those are the only tokens that can appear as unary |
|
1236 // ops too. |
1521
|
1237 // |
|
1238 // Note that this never returns true for `.', even though it can be a |
|
1239 // binary operator (the structure reference thing). The only time |
|
1240 // this appears to matter is for things like |
|
1241 // |
|
1242 // [ a . b ] |
|
1243 // |
|
1244 // which probably doesn't occur that often, can be worked around by |
|
1245 // eliminating the whitespace, putting the expression in parentheses, |
|
1246 // or using `whitespace_in_literal_matrix = "ignored"', so I think it |
|
1247 // is an acceptable change. It would be quite a bit harder to `fix' |
|
1248 // this. (Well, maybe not. the best fix would be to do away with the |
|
1249 // specialness of whitespace inside of `[ ... ]'). |
1554
|
1250 // |
|
1251 // However, we still do check for `.+', `.*', etc. |
767
|
1252 |
2857
|
1253 static bool |
1
|
1254 next_token_is_bin_op (int spc_prev, char *yytext) |
|
1255 { |
2857
|
1256 bool bin_op = false; |
1
|
1257 |
|
1258 int c0 = yyinput (); |
|
1259 |
|
1260 switch (c0) |
|
1261 { |
777
|
1262 case '+': |
|
1263 case '-': |
1276
|
1264 { |
|
1265 int c1 = yyinput (); |
|
1266 yyunput (c1, yytext); |
|
1267 int spc_next = (c1 == ' ' || c1 == '\t'); |
|
1268 bin_op = looks_like_bin_op (spc_prev, spc_next); |
|
1269 } |
|
1270 break; |
|
1271 |
1554
|
1272 case '.': |
|
1273 { |
|
1274 int c1 = yyinput (); |
|
1275 yyunput (c1, yytext); |
|
1276 bin_op = match_any (c1, "+-*/\\^"); |
|
1277 } |
|
1278 break; |
|
1279 |
777
|
1280 case '/': |
|
1281 case ':': |
|
1282 case '\\': |
|
1283 case '^': |
1
|
1284 case '&': |
|
1285 case '*': |
|
1286 case '|': |
|
1287 case '<': |
|
1288 case '>': |
777
|
1289 case '~': |
|
1290 case '!': |
|
1291 case '=': |
2857
|
1292 bin_op = true; |
1
|
1293 break; |
|
1294 |
|
1295 default: |
1276
|
1296 break; |
1
|
1297 } |
|
1298 |
|
1299 yyunput (c0, yytext); |
|
1300 |
|
1301 return bin_op; |
|
1302 } |
|
1303 |
767
|
1304 // Used to delete trailing white space from tokens. |
|
1305 |
1823
|
1306 static string |
1
|
1307 strip_trailing_whitespace (char *s) |
|
1308 { |
1823
|
1309 string retval = s; |
1
|
1310 |
1823
|
1311 size_t pos = retval.find_first_of (" \t"); |
1
|
1312 |
1823
|
1313 if (pos != NPOS) |
|
1314 retval.resize (pos); |
1
|
1315 |
|
1316 return retval; |
|
1317 } |
|
1318 |
1001
|
1319 // Discard whitespace, including comments and continuations. |
1088
|
1320 // |
|
1321 // Return value is logical OR of the following values: |
|
1322 // |
1826
|
1323 // ATE_NOTHING : no spaces to eat |
1088
|
1324 // ATE_SPACE_OR_TAB : space or tab in input |
|
1325 // ATE_NEWLINE : bare new line in input |
1001
|
1326 |
1826
|
1327 static yum_yum |
975
|
1328 eat_whitespace (void) |
|
1329 { |
1826
|
1330 yum_yum retval = ATE_NOTHING; |
2857
|
1331 bool in_comment = false; |
975
|
1332 int c; |
|
1333 while ((c = yyinput ()) != EOF) |
|
1334 { |
|
1335 current_input_column++; |
|
1336 |
|
1337 switch (c) |
|
1338 { |
|
1339 case ' ': |
|
1340 case '\t': |
1088
|
1341 retval |= ATE_SPACE_OR_TAB; |
975
|
1342 break; |
|
1343 |
|
1344 case '\n': |
1088
|
1345 retval |= ATE_NEWLINE; |
2857
|
1346 in_comment = false; |
975
|
1347 current_input_column = 0; |
|
1348 break; |
|
1349 |
|
1350 case '#': |
|
1351 case '%': |
2857
|
1352 in_comment = true; |
975
|
1353 break; |
|
1354 |
1001
|
1355 case '.': |
|
1356 if (in_comment) |
|
1357 break; |
|
1358 else |
|
1359 { |
|
1360 if (have_ellipsis_continuation ()) |
|
1361 break; |
|
1362 else |
|
1363 goto done; |
|
1364 } |
|
1365 |
|
1366 case '\\': |
|
1367 if (in_comment) |
|
1368 break; |
|
1369 else |
|
1370 { |
|
1371 if (have_continuation ()) |
|
1372 break; |
|
1373 else |
|
1374 goto done; |
|
1375 } |
|
1376 |
975
|
1377 default: |
|
1378 if (in_comment) |
|
1379 break; |
|
1380 else |
|
1381 goto done; |
|
1382 } |
|
1383 } |
|
1384 |
|
1385 done: |
|
1386 yyunput (c, yytext); |
1082
|
1387 current_input_column--; |
1001
|
1388 return retval; |
975
|
1389 } |
|
1390 |
|
1391 static void |
972
|
1392 handle_number (char *yytext) |
|
1393 { |
2621
|
1394 char *tmp = strsave (yytext); |
|
1395 |
|
1396 char *idx = strpbrk (tmp, "Dd"); |
|
1397 |
|
1398 if (idx) |
|
1399 *idx = 'e'; |
|
1400 |
972
|
1401 double value; |
2621
|
1402 int nread = sscanf (tmp, "%lf", &value); |
|
1403 |
|
1404 delete [] tmp; |
972
|
1405 |
1826
|
1406 // If yytext doesn't contain a valid number, we are in deep doo doo. |
985
|
1407 |
972
|
1408 assert (nread == 1); |
|
1409 |
1826
|
1410 lexer_flags.quote_is_transpose = 1; |
|
1411 lexer_flags.cant_be_identifier = 1; |
|
1412 lexer_flags.convert_spaces_to_comma = 1; |
972
|
1413 |
1826
|
1414 if (lexer_flags.plotting && ! lexer_flags.in_plot_range) |
|
1415 lexer_flags.past_plot_range = 1; |
972
|
1416 |
|
1417 yylval.tok_val = new token (value, yytext, input_line_number, |
|
1418 current_input_column); |
|
1419 |
|
1420 token_stack.push (yylval.tok_val); |
|
1421 |
|
1422 current_input_column += yyleng; |
|
1423 |
|
1424 do_comma_insert_check (); |
|
1425 } |
|
1426 |
1001
|
1427 // We have seen a backslash and need to find out if it should be |
|
1428 // treated as a continuation character. If so, this eats it, up to |
|
1429 // and including the new line character. |
|
1430 // |
973
|
1431 // Match whitespace only, followed by a comment character or newline. |
|
1432 // Once a comment character is found, discard all input until newline. |
|
1433 // If non-whitespace characters are found before comment |
|
1434 // characters, return 0. Otherwise, return 1. |
|
1435 |
2857
|
1436 static bool |
1091
|
1437 have_continuation (int trailing_comments_ok) |
973
|
1438 { |
|
1439 ostrstream buf; |
|
1440 |
2857
|
1441 bool in_comment = false; |
973
|
1442 char c; |
|
1443 while ((c = yyinput ()) != EOF) |
|
1444 { |
|
1445 buf << (char) c; |
|
1446 |
|
1447 switch (c) |
|
1448 { |
|
1449 case ' ': |
|
1450 case '\t': |
|
1451 break; |
|
1452 |
|
1453 case '%': |
|
1454 case '#': |
1091
|
1455 if (trailing_comments_ok) |
2857
|
1456 in_comment = true; |
1091
|
1457 else |
|
1458 goto cleanup; |
973
|
1459 break; |
|
1460 |
|
1461 case '\n': |
975
|
1462 current_input_column = 0; |
1001
|
1463 promptflag--; |
2857
|
1464 return true; |
973
|
1465 |
|
1466 default: |
1091
|
1467 if (! in_comment) |
|
1468 goto cleanup; |
|
1469 break; |
973
|
1470 } |
|
1471 } |
|
1472 |
|
1473 yyunput (c, yytext); |
2857
|
1474 return false; |
973
|
1475 |
1091
|
1476 cleanup: |
|
1477 buf << ends; |
|
1478 char *s = buf.str (); |
|
1479 if (s) |
|
1480 { |
|
1481 int len = strlen (s); |
|
1482 while (len--) |
|
1483 yyunput (s[len], yytext); |
|
1484 } |
|
1485 delete [] s; |
2857
|
1486 return false; |
973
|
1487 } |
|
1488 |
1001
|
1489 // We have seen a `.' and need to see if it is the start of a |
|
1490 // continuation. If so, this eats it, up to and including the new |
|
1491 // line character. |
|
1492 |
2857
|
1493 static bool |
1091
|
1494 have_ellipsis_continuation (int trailing_comments_ok) |
973
|
1495 { |
|
1496 char c1 = yyinput (); |
|
1497 if (c1 == '.') |
|
1498 { |
|
1499 char c2 = yyinput (); |
1091
|
1500 if (c2 == '.' && have_continuation (trailing_comments_ok)) |
2857
|
1501 return true; |
973
|
1502 else |
|
1503 { |
|
1504 yyunput (c2, yytext); |
|
1505 yyunput (c1, yytext); |
|
1506 } |
|
1507 } |
|
1508 else |
|
1509 yyunput (c1, yytext); |
|
1510 |
2857
|
1511 return false; |
973
|
1512 } |
|
1513 |
1001
|
1514 // See if we have a continuation line. If so, eat it and the leading |
|
1515 // whitespace on the next line. |
1088
|
1516 // |
|
1517 // Return value is the same as described for eat_whitespace(). |
1001
|
1518 |
1826
|
1519 static yum_yum |
1001
|
1520 eat_continuation (void) |
|
1521 { |
1826
|
1522 int retval = ATE_NOTHING; |
1001
|
1523 int c = yyinput (); |
|
1524 if ((c == '.' && have_ellipsis_continuation ()) |
|
1525 || (c == '\\' && have_continuation ())) |
|
1526 retval = eat_whitespace (); |
|
1527 else |
|
1528 yyunput (c, yytext); |
|
1529 |
|
1530 return retval; |
|
1531 } |
|
1532 |
973
|
1533 static int |
975
|
1534 handle_string (char delim, int text_style) |
973
|
1535 { |
|
1536 ostrstream buf; |
|
1537 |
|
1538 int c; |
1031
|
1539 int escape_pending = 0; |
973
|
1540 |
|
1541 while ((c = yyinput ()) != EOF) |
|
1542 { |
|
1543 current_input_column++; |
|
1544 |
|
1545 if (c == '\\') |
|
1546 { |
1053
|
1547 if (escape_pending) |
|
1548 { |
|
1549 buf << (char) c; |
|
1550 escape_pending = 0; |
|
1551 } |
|
1552 else |
|
1553 { |
1091
|
1554 if (have_continuation (0)) |
1053
|
1555 escape_pending = 0; |
|
1556 else |
|
1557 { |
|
1558 buf << (char) c; |
|
1559 escape_pending = 1; |
|
1560 } |
|
1561 } |
1031
|
1562 continue; |
973
|
1563 } |
|
1564 else if (c == '.') |
|
1565 { |
1091
|
1566 if (! have_ellipsis_continuation (0)) |
973
|
1567 buf << (char) c; |
|
1568 } |
|
1569 else if (c == '\n') |
|
1570 { |
1053
|
1571 error ("unterminated string constant"); |
973
|
1572 break; |
|
1573 } |
|
1574 else if (c == delim) |
|
1575 { |
1031
|
1576 if (escape_pending) |
973
|
1577 buf << (char) c; |
|
1578 else |
|
1579 { |
|
1580 c = yyinput (); |
|
1581 if (c == delim) |
|
1582 buf << (char) c; |
|
1583 else |
|
1584 { |
|
1585 yyunput (c, yytext); |
|
1586 buf << ends; |
|
1587 char *tok = buf.str (); |
|
1588 do_string_escapes (tok); |
975
|
1589 |
1826
|
1590 if (text_style && lexer_flags.doing_set) |
975
|
1591 { |
|
1592 if (tok) |
|
1593 { |
|
1594 int len = strlen (tok) + 3; |
|
1595 char *tmp = tok; |
|
1596 tok = new char [len]; |
|
1597 tok[0] = delim; |
|
1598 strcpy (tok+1, tmp); |
|
1599 tok[len-2] = delim; |
|
1600 tok[len-1] = '\0'; |
|
1601 delete [] tmp; |
|
1602 } |
|
1603 } |
|
1604 else |
|
1605 { |
2857
|
1606 lexer_flags.quote_is_transpose = true; |
|
1607 lexer_flags.cant_be_identifier = true; |
|
1608 lexer_flags.convert_spaces_to_comma = true; |
975
|
1609 } |
|
1610 |
973
|
1611 yylval.tok_val = new token (tok); |
|
1612 delete [] tok; |
|
1613 token_stack.push (yylval.tok_val); |
|
1614 return TEXT; |
|
1615 } |
|
1616 } |
|
1617 } |
|
1618 else |
|
1619 { |
|
1620 buf << (char) c; |
|
1621 } |
|
1622 |
1031
|
1623 escape_pending = 0; |
973
|
1624 } |
|
1625 |
|
1626 return LEXICAL_ERROR; |
|
1627 } |
|
1628 |
971
|
1629 static int |
1001
|
1630 handle_close_brace (int spc_gobbled) |
971
|
1631 { |
1826
|
1632 if (! nesting_level.none ()) |
971
|
1633 { |
1826
|
1634 nesting_level.remove (); |
|
1635 lexer_flags.braceflag--; |
971
|
1636 } |
|
1637 |
1826
|
1638 if (lexer_flags.braceflag == 0) |
1001
|
1639 BEGIN 0; |
|
1640 |
971
|
1641 int c1 = yyinput (); |
|
1642 if (c1 == '=') |
|
1643 { |
2857
|
1644 lexer_flags.quote_is_transpose = false; |
|
1645 lexer_flags.cant_be_identifier = false; |
|
1646 lexer_flags.convert_spaces_to_comma = true; |
971
|
1647 |
|
1648 int c2 = yyinput (); |
|
1649 unput (c2); |
|
1650 unput (c1); |
|
1651 |
1826
|
1652 if (c2 != '=' && lexer_flags.maybe_screwed_again) |
971
|
1653 return SCREW_TWO; |
|
1654 else |
|
1655 return ']'; |
|
1656 } |
|
1657 else |
|
1658 { |
|
1659 unput (c1); |
|
1660 |
2167
|
1661 if (lexer_flags.braceflag && Vwhitespace_in_literal_matrix != 2) |
971
|
1662 { |
1001
|
1663 int bin_op = next_token_is_bin_op (spc_gobbled, yytext); |
971
|
1664 int postfix_un_op = next_token_is_postfix_unary_op |
1001
|
1665 (spc_gobbled, yytext); |
971
|
1666 |
|
1667 int other_op = match_any (c1, ",;\n]"); |
|
1668 |
1826
|
1669 if (! (postfix_un_op || bin_op || other_op) |
|
1670 && nesting_level.is_brace () |
|
1671 && lexer_flags.convert_spaces_to_comma) |
971
|
1672 { |
|
1673 unput (','); |
|
1674 return ']'; |
|
1675 } |
|
1676 } |
|
1677 } |
|
1678 |
2857
|
1679 lexer_flags.quote_is_transpose = true; |
|
1680 lexer_flags.cant_be_identifier = false; |
|
1681 lexer_flags.convert_spaces_to_comma = true; |
971
|
1682 return ']'; |
|
1683 } |
|
1684 |
1072
|
1685 static void |
|
1686 maybe_unput_comma (int spc_gobbled) |
|
1687 { |
2167
|
1688 if (Vwhitespace_in_literal_matrix != 2 |
1826
|
1689 && nesting_level.is_brace ()) |
1072
|
1690 { |
|
1691 int bin_op = next_token_is_bin_op (spc_gobbled, yytext); |
|
1692 |
|
1693 int postfix_un_op = next_token_is_postfix_unary_op (spc_gobbled, |
|
1694 yytext); |
|
1695 |
|
1696 int c1 = yyinput (); |
|
1697 int c2 = yyinput (); |
|
1698 unput (c2); |
|
1699 unput (c1); |
|
1700 int sep_op = match_any (c1, ",;\n]"); |
|
1701 int dot_op = (c1 == '.' |
|
1702 && (isalpha (c2) || isspace (c2) || c2 == '_')); |
|
1703 int index_op = (c1 == '(' |
2167
|
1704 && (Vwhitespace_in_literal_matrix == 0 |
1072
|
1705 || ! spc_gobbled)); |
|
1706 |
|
1707 if (! (postfix_un_op || bin_op || sep_op || dot_op || index_op)) |
|
1708 unput (','); |
|
1709 } |
|
1710 } |
|
1711 |
767
|
1712 // Figure out exactly what kind of token to return when we have seen |
|
1713 // an identifier. Handles keywords. |
|
1714 |
146
|
1715 static int |
1823
|
1716 handle_identifier (const string& tok, int spc_gobbled) |
146
|
1717 { |
1826
|
1718 // It is almost always an error for an identifier to be followed |
|
1719 // directly by another identifier. Special cases are handled |
|
1720 // below. |
883
|
1721 |
2857
|
1722 lexer_flags.cant_be_identifier = true; |
883
|
1723 |
1826
|
1724 // If we are expecting a structure element, we just want to return |
|
1725 // TEXT_ID, which is a string that is also a valid identifier. But |
|
1726 // first, we have to decide whether to insert a comma. |
747
|
1727 |
1826
|
1728 if (lexer_flags.looking_at_indirect_ref) |
1072
|
1729 { |
|
1730 maybe_unput_comma (spc_gobbled); |
2819
|
1731 |
|
1732 yylval.tok_val = new token (tok, input_line_number, |
|
1733 current_input_column); |
|
1734 |
|
1735 token_stack.push (yylval.tok_val); |
|
1736 |
2857
|
1737 lexer_flags.cant_be_identifier = false; |
|
1738 lexer_flags.quote_is_transpose = true; |
|
1739 lexer_flags.convert_spaces_to_comma = true; |
2819
|
1740 |
|
1741 current_input_column += yyleng; |
|
1742 |
|
1743 return TEXT_ID; |
1072
|
1744 } |
747
|
1745 |
1826
|
1746 // If we have a regular keyword, or a plot STYLE, return it. |
|
1747 // Keywords can be followed by identifiers (TOK_RETURN handles |
|
1748 // that). |
146
|
1749 |
|
1750 int kw_token = is_keyword (tok); |
|
1751 if (kw_token) |
|
1752 { |
|
1753 if (kw_token == STYLE) |
|
1754 { |
1060
|
1755 current_input_column += yyleng; |
2857
|
1756 lexer_flags.quote_is_transpose = false; |
|
1757 lexer_flags.convert_spaces_to_comma = true; |
146
|
1758 return kw_token; |
|
1759 } |
|
1760 else |
|
1761 TOK_RETURN (kw_token); |
|
1762 } |
|
1763 |
1826
|
1764 // See if we have a plot keyword (title, using, with, or clear). |
146
|
1765 |
1826
|
1766 if (lexer_flags.plotting) |
941
|
1767 { |
1826
|
1768 // Yes, we really do need both of these plot_range variables. |
|
1769 // One is used to mark when we are past all possiblity of a plot |
|
1770 // range, the other is used to mark when we are actually between |
|
1771 // the square brackets that surround the range. |
146
|
1772 |
1826
|
1773 if (! lexer_flags.in_plot_range) |
2857
|
1774 lexer_flags.past_plot_range = true; |
941
|
1775 |
1273
|
1776 // Option keywords can't appear in parentheses or braces. |
|
1777 |
|
1778 int plot_option_kw = 0; |
1826
|
1779 if (nesting_level.none ()) |
1273
|
1780 plot_option_kw = is_plot_keyword (tok); |
941
|
1781 |
1826
|
1782 if (lexer_flags.cant_be_identifier && plot_option_kw) |
941
|
1783 TOK_RETURN (plot_option_kw); |
|
1784 } |
146
|
1785 |
1001
|
1786 int c = yyinput (); |
|
1787 yyunput (c, yytext); |
2702
|
1788 bool next_tok_is_eq = (c == '='); |
|
1789 bool next_tok_is_paren = (c == '('); |
1001
|
1790 |
1826
|
1791 // Make sure we put the return values of a function in the symbol |
|
1792 // table that is local to the function. |
146
|
1793 |
2877
|
1794 // If we are defining a function and we have not seen the function |
|
1795 // name yet and the next token is `=', then this identifier must be |
|
1796 // the only return value for the function and it belongs in the |
|
1797 // local symbol table. |
|
1798 |
1826
|
1799 if (next_tok_is_eq |
2877
|
1800 && lexer_flags.defining_func |
|
1801 && ! lexer_flags.parsed_function_name) |
146
|
1802 curr_sym_tab = tmp_local_sym_tab; |
|
1803 |
2702
|
1804 // Kluge alert. |
|
1805 // |
|
1806 // If we are looking at a text style function, set up to gobble its |
2745
|
1807 // arguments. |
|
1808 // |
|
1809 // If the following token is `=', or if we are parsing a function |
|
1810 // return list or function parameter list, force the symbol to be |
2702
|
1811 // inserted as a variable in the current symbol table. |
|
1812 |
|
1813 if (is_text_function_name (tok) && ! is_variable (tok)) |
|
1814 { |
2745
|
1815 if (next_tok_is_eq |
|
1816 || lexer_flags.looking_at_return_list |
|
1817 || lexer_flags.looking_at_parameter_list) |
|
1818 { |
|
1819 force_local_variable (tok); |
|
1820 } |
2702
|
1821 else if (! next_tok_is_paren) |
|
1822 { |
|
1823 if (tok == "gset") |
2857
|
1824 lexer_flags.doing_set = true; |
2702
|
1825 |
|
1826 BEGIN TEXT_FCN; |
|
1827 } |
|
1828 } |
|
1829 |
1826
|
1830 // Find the token in the symbol table. |
146
|
1831 |
|
1832 yylval.tok_val = new token (lookup_identifier (tok), |
|
1833 input_line_number, |
|
1834 current_input_column); |
|
1835 |
|
1836 token_stack.push (yylval.tok_val); |
|
1837 |
1826
|
1838 // After seeing an identifer, it is ok to convert spaces to a comma |
|
1839 // (if needed). |
146
|
1840 |
2857
|
1841 lexer_flags.convert_spaces_to_comma = true; |
146
|
1842 |
2877
|
1843 if (! next_tok_is_eq) |
|
1844 { |
|
1845 lexer_flags.quote_is_transpose = true; |
146
|
1846 |
2877
|
1847 do_comma_insert_check (); |
|
1848 |
|
1849 maybe_unput_comma (spc_gobbled); |
146
|
1850 } |
|
1851 |
2877
|
1852 current_input_column += yyleng; |
146
|
1853 |
|
1854 return NAME; |
|
1855 } |
|
1856 |
767
|
1857 // Print a warning if a function file that defines a function has |
|
1858 // anything other than comments and whitespace following the END token |
|
1859 // that matches the FUNCTION statement. |
|
1860 |
1
|
1861 void |
|
1862 check_for_garbage_after_fcn_def (void) |
|
1863 { |
1826
|
1864 // By making a newline be the next character to be read, we will |
|
1865 // force the parser to return after reading the function. Calling |
|
1866 // yyunput with EOF seems not to work... |
1
|
1867 |
2857
|
1868 bool in_comment = false; |
1
|
1869 int lineno = input_line_number; |
|
1870 int c; |
|
1871 while ((c = yyinput ()) != EOF) |
|
1872 { |
|
1873 switch (c) |
|
1874 { |
|
1875 case ' ': |
|
1876 case '\t': |
|
1877 case ';': |
|
1878 case ',': |
|
1879 break; |
777
|
1880 |
1
|
1881 case '\n': |
|
1882 if (in_comment) |
2857
|
1883 in_comment = false; |
1
|
1884 break; |
777
|
1885 |
1
|
1886 case '%': |
|
1887 case '#': |
2857
|
1888 in_comment = true; |
1
|
1889 break; |
777
|
1890 |
1
|
1891 default: |
|
1892 if (in_comment) |
|
1893 break; |
|
1894 else |
|
1895 { |
|
1896 warning ("ignoring trailing garbage after end of function\n\ |
1755
|
1897 near line %d of file `%s.m'", lineno, curr_fcn_file_name.c_str ()); |
1
|
1898 |
|
1899 yyunput ('\n', yytext); |
|
1900 return; |
|
1901 } |
|
1902 } |
|
1903 } |
|
1904 yyunput ('\n', yytext); |
|
1905 } |
|
1906 |
1826
|
1907 void |
|
1908 lexical_feedback::init (void) |
|
1909 { |
|
1910 // Not initially defining a matrix list. |
|
1911 braceflag = 0; |
|
1912 |
|
1913 // Not initially inside a loop or if statement. |
|
1914 looping = 0; |
|
1915 |
2857
|
1916 // Not initially defining a function. |
|
1917 beginning_of_function = false; |
|
1918 defining_func = false; |
2877
|
1919 parsed_function_name = false; |
2857
|
1920 |
|
1921 // Not parsing a function return or parameter list. |
|
1922 looking_at_return_list = false; |
|
1923 looking_at_parameter_list = false; |
|
1924 |
|
1925 // Next token can be identifier. |
|
1926 cant_be_identifier = false; |
|
1927 |
|
1928 // No need to do comma insert or convert spaces to comma at |
|
1929 // beginning of input. |
|
1930 convert_spaces_to_comma = true; |
|
1931 do_comma_insert = false; |
|
1932 |
|
1933 // Not initially doing any plotting or setting of plot attributes. |
|
1934 doing_set = false; |
|
1935 in_plot_range = false; |
|
1936 in_plot_style = false; |
|
1937 in_plot_using = false; |
|
1938 past_plot_range = false; |
|
1939 plotting = false; |
|
1940 |
1826
|
1941 // Not initially looking at indirect references. |
2857
|
1942 looking_at_indirect_ref = false; |
1826
|
1943 |
|
1944 // Not initially screwed by `function [...] = f (...)' syntax. |
|
1945 maybe_screwed_again = 0; |
1
|
1946 |
1826
|
1947 // Quote marks strings intially. |
2857
|
1948 quote_is_transpose = false; |
1826
|
1949 } |
|
1950 |
2167
|
1951 int |
|
1952 whitespace_in_literal_matrix (void) |
|
1953 { |
|
1954 int pref = 0; |
|
1955 string val = builtin_string_variable ("whitespace_in_literal_matrix"); |
|
1956 if (! val.empty ()) |
|
1957 { |
|
1958 if (val.compare ("ignore", 0, 6) == 0) |
|
1959 pref = 2; |
|
1960 else if (val.compare ("traditional", 0, 11) == 0) |
|
1961 pref = 1; |
|
1962 } |
|
1963 Vwhitespace_in_literal_matrix = pref; |
|
1964 return 0; |
|
1965 } |
|
1966 |
|
1967 void |
|
1968 symbols_of_lex (void) |
|
1969 { |
|
1970 DEFVAR (whitespace_in_literal_matrix, "", 0, whitespace_in_literal_matrix, |
|
1971 "control auto-insertion of commas and semicolons in literal matrices"); |
|
1972 } |
|
1973 |
1994
|
1974 /* |
|
1975 ;;; Local Variables: *** |
|
1976 ;;; mode: C++ *** |
|
1977 ;;; End: *** |
|
1978 */ |