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