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