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