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