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