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