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