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