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 |
4753
|
23 %option prefix = "octave_" |
|
24 |
4208
|
25 %s COMMAND_START |
|
26 %s MATRIX_START |
4240
|
27 |
|
28 %x NESTED_FUNCTION_END |
|
29 %x NESTED_FUNCTION_BEGIN |
1
|
30 |
|
31 %{ |
240
|
32 #ifdef HAVE_CONFIG_H |
1220
|
33 #include <config.h> |
240
|
34 #endif |
|
35 |
1341
|
36 #include <cctype> |
|
37 #include <cstring> |
|
38 |
1823
|
39 #include <string> |
4214
|
40 #include <stack> |
1823
|
41 |
4093
|
42 #ifdef HAVE_UNISTD_H |
|
43 #ifdef HAVE_SYS_TYPES_H |
|
44 #include <sys/types.h> |
|
45 #endif |
|
46 #include <unistd.h> |
|
47 #endif |
|
48 |
2926
|
49 #include "cmd-edit.h" |
4153
|
50 #include "quit.h" |
4910
|
51 #include "lo-mappers.h" |
4051
|
52 #include "lo-sstream.h" |
2926
|
53 |
1497
|
54 // These would be alphabetical, but y.tab.h must be included before |
|
55 // oct-gperf.h and y.tab.h must be included after token.h and the tree |
|
56 // class declarations. We can't include y.tab.h in oct-gperf.h |
|
57 // because it may not be protected to allow it to be included multiple |
|
58 // times. |
|
59 |
4264
|
60 #include "Cell.h" |
3665
|
61 #include "comment-list.h" |
2181
|
62 #include "defun.h" |
1355
|
63 #include "error.h" |
4910
|
64 #include "gripes.h" |
1351
|
65 #include "input.h" |
1355
|
66 #include "lex.h" |
2891
|
67 #include "ov.h" |
1355
|
68 #include "parse.h" |
2987
|
69 #include "pt-all.h" |
2891
|
70 #include "symtab.h" |
|
71 #include "token.h" |
|
72 #include "toplev.h" |
1355
|
73 #include "utils.h" |
|
74 #include "variables.h" |
2492
|
75 #include <y.tab.h> |
|
76 #include <oct-gperf.h> |
1
|
77 |
2716
|
78 #if ! (defined (FLEX_SCANNER) \ |
|
79 && defined (YY_FLEX_MAJOR_VERSION) && YY_FLEX_MAJOR_VERSION >= 2 \ |
|
80 && defined (YY_FLEX_MINOR_VERSION) && YY_FLEX_MINOR_VERSION >= 5) |
|
81 #error lex.l requires flex version 2.5.4 or later |
|
82 #endif |
|
83 |
4753
|
84 #define yylval octave_lval |
|
85 |
|
86 // Arrange to get input via readline. |
|
87 |
|
88 #ifdef YY_INPUT |
|
89 #undef YY_INPUT |
|
90 #endif |
|
91 #define YY_INPUT(buf, result, max_size) \ |
|
92 if ((result = octave_read (buf, max_size)) < 0) \ |
|
93 YY_FATAL_ERROR ("octave_read () in flex scanner failed"); |
|
94 |
|
95 // Try to avoid crashing out completely on fatal scanner errors. |
|
96 // The call to yy_fatal_error should never happen, but it avoids a |
|
97 // `static function defined but not used' warning from gcc. |
|
98 |
|
99 #ifdef YY_FATAL_ERROR |
|
100 #undef YY_FATAL_ERROR |
|
101 #endif |
|
102 #define YY_FATAL_ERROR(msg) \ |
|
103 do \ |
|
104 { \ |
|
105 error (msg); \ |
|
106 OCTAVE_QUIT; \ |
|
107 yy_fatal_error (msg); \ |
|
108 } \ |
|
109 while (0) |
|
110 |
4910
|
111 #define COUNT_TOK_AND_RETURN(tok) \ |
|
112 do \ |
|
113 { \ |
|
114 Vtoken_count++; \ |
|
115 return tok; \ |
|
116 } \ |
|
117 while (0) |
|
118 |
4753
|
119 #define TOK_RETURN(tok) \ |
|
120 do \ |
|
121 { \ |
|
122 current_input_column += yyleng; \ |
|
123 lexer_flags.quote_is_transpose = false; \ |
|
124 lexer_flags.convert_spaces_to_comma = true; \ |
4910
|
125 COUNT_TOK_AND_RETURN (tok); \ |
4753
|
126 } \ |
|
127 while (0) |
|
128 |
|
129 #define TOK_PUSH_AND_RETURN(name, tok) \ |
|
130 do \ |
|
131 { \ |
|
132 yylval.tok_val = new token (name, input_line_number, \ |
|
133 current_input_column); \ |
|
134 token_stack.push (yylval.tok_val); \ |
|
135 TOK_RETURN (tok); \ |
|
136 } \ |
|
137 while (0) |
|
138 |
|
139 #define BIN_OP_RETURN(tok, convert) \ |
|
140 do \ |
|
141 { \ |
|
142 yylval.tok_val = new token (input_line_number, current_input_column); \ |
|
143 token_stack.push (yylval.tok_val); \ |
|
144 current_input_column += yyleng; \ |
|
145 lexer_flags.quote_is_transpose = false; \ |
|
146 lexer_flags.convert_spaces_to_comma = convert; \ |
4910
|
147 COUNT_TOK_AND_RETURN (tok); \ |
4753
|
148 } \ |
|
149 while (0) |
|
150 |
|
151 #define XBIN_OP_RETURN(tok, convert) \ |
|
152 do \ |
|
153 { \ |
|
154 gripe_matlab_incompatible_operator (yytext); \ |
|
155 BIN_OP_RETURN (tok, convert); \ |
|
156 } \ |
|
157 while (0) |
|
158 |
3883
|
159 // TRUE means that we have encountered EOF on the input stream. |
|
160 bool parser_end_of_input = false; |
|
161 |
1826
|
162 // Flags that need to be shared between the lexer and parser. |
|
163 lexical_feedback lexer_flags; |
|
164 |
1351
|
165 // Stack to hold tokens so that we can delete them when the parser is |
|
166 // reset and avoid growing forever just because we are stashing some |
|
167 // information. This has to appear before lex.h is included, because |
|
168 // one of the macros defined there uses token_stack. |
2614
|
169 // |
|
170 // XXX FIXME XXX -- this should really be static, but that causes |
|
171 // problems on some systems. |
4214
|
172 std::stack <token*> token_stack; |
1351
|
173 |
1826
|
174 // Did eat_whitespace() eat a space or tab, or a newline, or both? |
1
|
175 |
1826
|
176 typedef int yum_yum; |
1
|
177 |
1826
|
178 const yum_yum ATE_NOTHING = 0; |
|
179 const yum_yum ATE_SPACE_OR_TAB = 1; |
|
180 const yum_yum ATE_NEWLINE = 2; |
1088
|
181 |
3351
|
182 // Is the closest nesting level a square bracket, squiggly brace or a paren? |
1826
|
183 |
4214
|
184 class bracket_brace_paren_nesting_level |
1826
|
185 { |
|
186 public: |
|
187 |
4214
|
188 bracket_brace_paren_nesting_level (void) : context () { } |
1826
|
189 |
3351
|
190 ~bracket_brace_paren_nesting_level (void) { } |
|
191 |
4214
|
192 void bracket (void) { context.push (BRACKET); } |
|
193 bool is_bracket (void) |
|
194 { return ! context.empty () && context.top () == BRACKET; } |
|
195 |
|
196 void brace (void) { context.push (BRACE); } |
|
197 bool is_brace (void) |
|
198 { return ! context.empty () && context.top () == BRACE; } |
|
199 |
|
200 void paren (void) { context.push (PAREN); } |
|
201 bool is_paren (void) |
|
202 { return ! context.empty () && context.top () == PAREN; } |
|
203 |
4608
|
204 bool is_bracket_or_brace (void) |
|
205 { return (! context.empty () |
|
206 && (context.top () == BRACKET || context.top () == BRACE)); } |
|
207 |
4214
|
208 bool none (void) { return context.empty (); } |
|
209 |
|
210 void remove (void) { if (! context.empty ()) context.pop (); } |
|
211 |
|
212 void clear (void) { while (! context.empty ()) context.pop (); } |
1826
|
213 |
|
214 private: |
|
215 |
4214
|
216 std::stack<int> context; |
|
217 |
5225
|
218 static const int BRACKET; |
|
219 static const int BRACE; |
|
220 static const int PAREN; |
1826
|
221 |
3351
|
222 bracket_brace_paren_nesting_level (const bracket_brace_paren_nesting_level&); |
1826
|
223 |
3351
|
224 bracket_brace_paren_nesting_level& |
|
225 operator = (const bracket_brace_paren_nesting_level&); |
1826
|
226 }; |
|
227 |
5225
|
228 const int bracket_brace_paren_nesting_level::BRACKET = 1; |
|
229 const int bracket_brace_paren_nesting_level::BRACE = 2; |
|
230 const int bracket_brace_paren_nesting_level::PAREN = 3; |
|
231 |
3351
|
232 static bracket_brace_paren_nesting_level nesting_level; |
1
|
233 |
4037
|
234 static bool Vwarn_matlab_incompatible = false; |
|
235 |
3388
|
236 static bool Vwarn_separator_insert = false; |
|
237 |
3400
|
238 static bool Vwarn_single_quote_string = false; |
|
239 |
4910
|
240 static unsigned int Vtoken_count = 0; |
|
241 |
146
|
242 // Forward declarations for functions defined at the bottom of this |
|
243 // file. |
|
244 |
1
|
245 static void fixup_column_count (char *s); |
146
|
246 static void do_comma_insert_check (void); |
4867
|
247 static int is_keyword_token (const std::string& s); |
4238
|
248 static void prep_for_function (void); |
|
249 static void prep_for_nested_function (void); |
3523
|
250 static symbol_record *lookup_identifier (const std::string& s); |
4426
|
251 static std::string grab_help_text (void); |
2857
|
252 static bool match_any (char c, const char *s); |
3263
|
253 static bool next_token_is_sep_op (void); |
3246
|
254 static bool next_token_is_bin_op (bool spc_prev); |
|
255 static bool next_token_is_postfix_unary_op (bool spc_prev); |
3523
|
256 static std::string strip_trailing_whitespace (char *s); |
3246
|
257 static void handle_number (void); |
975
|
258 static int handle_string (char delim, int text_style = 0); |
4612
|
259 static int handle_close_bracket (bool spc_gobbled, int bracket_type); |
3974
|
260 static int handle_identifier (void); |
3096
|
261 static bool have_continuation (bool trailing_comments_ok = true); |
|
262 static bool have_ellipsis_continuation (bool trailing_comments_ok = true); |
3665
|
263 static void scan_for_comments (const char *); |
1826
|
264 static yum_yum eat_whitespace (void); |
|
265 static yum_yum eat_continuation (void); |
3388
|
266 static void maybe_warn_separator_insert (char sep); |
3400
|
267 static void gripe_single_quote_string (void); |
4037
|
268 static void gripe_matlab_incompatible (const std::string& msg); |
|
269 static void maybe_gripe_matlab_incompatible_comment (char c); |
|
270 static void gripe_matlab_incompatible_continuation (void); |
|
271 static void gripe_matlab_incompatible_operator (const std::string& op); |
1
|
272 |
|
273 %} |
|
274 |
|
275 D [0-9] |
|
276 S [ \t] |
2042
|
277 NL ((\n)|(\r\n)) |
|
278 SNL ({S}|{NL}) |
1
|
279 EL (\.\.\.) |
967
|
280 BS (\\) |
|
281 CONT ({EL}|{BS}) |
1
|
282 Im [iIjJ] |
967
|
283 CCHAR [#%] |
|
284 COMMENT ({CCHAR}.*{NL}) |
|
285 SNLCMT ({SNL}|{COMMENT}) |
|
286 NOT ((\~)|(\!)) |
4037
|
287 POW ((\*\*)|(\^)) |
|
288 EPOW (\.{POW}) |
5290
|
289 IDENT ([_$a-zA-Z][_$a-zA-Z0-9]*) |
1
|
290 EXPON ([DdEe][+-]?{D}+) |
3220
|
291 NUMBER (({D}+\.?{D}*{EXPON}?)|(\.{D}+{EXPON}?)|(0[xX][0-9a-fA-F]+)) |
1
|
292 %% |
|
293 |
4240
|
294 <NESTED_FUNCTION_END>. { |
4323
|
295 BEGIN (NESTED_FUNCTION_BEGIN); |
4410
|
296 yyunput (yytext[0], yytext); |
4910
|
297 COUNT_TOK_AND_RETURN (';'); |
4240
|
298 } |
|
299 |
|
300 <NESTED_FUNCTION_BEGIN>. { |
4323
|
301 BEGIN (INITIAL); |
4410
|
302 yyunput (yytext[0], yytext); |
4238
|
303 prep_for_nested_function (); |
4910
|
304 COUNT_TOK_AND_RETURN (FCN); |
4238
|
305 } |
|
306 |
968
|
307 %{ |
4208
|
308 // Help and other command-style functions are a pain in the ass. This |
968
|
309 // stuff needs to be simplified. May require some changes in the |
|
310 // parser too. |
|
311 %} |
|
312 |
4208
|
313 <COMMAND_START>{NL} { |
4323
|
314 BEGIN (INITIAL); |
967
|
315 current_input_column = 1; |
2857
|
316 lexer_flags.quote_is_transpose = false; |
|
317 lexer_flags.convert_spaces_to_comma = true; |
5212
|
318 lexer_flags.doing_rawcommand = false; |
4910
|
319 COUNT_TOK_AND_RETURN ('\n'); |
967
|
320 } |
1
|
321 |
4208
|
322 <COMMAND_START>[\;\,] { |
5102
|
323 if (lexer_flags.doing_rawcommand) |
5279
|
324 TOK_PUSH_AND_RETURN (yytext, SQ_STRING); |
5102
|
325 |
|
326 BEGIN (INITIAL); |
|
327 |
|
328 if (strcmp (yytext, ",") == 0) |
|
329 TOK_RETURN (','); |
967
|
330 else |
5102
|
331 TOK_RETURN (';'); |
967
|
332 } |
1
|
333 |
4208
|
334 <COMMAND_START>[\"\'] { |
975
|
335 current_input_column++; |
4910
|
336 COUNT_TOK_AND_RETURN (handle_string (yytext[0], true)); |
975
|
337 } |
|
338 |
4923
|
339 <COMMAND_START>[^#% \t\r\n\;\,\"\'][^ \t\r\n\;\,]*{S}* { |
3523
|
340 std::string tok = strip_trailing_whitespace (yytext); |
5279
|
341 TOK_PUSH_AND_RETURN (tok, SQ_STRING); |
967
|
342 } |
1
|
343 |
968
|
344 %{ |
1
|
345 // For this and the next two rules, we're looking at ']', and we |
971
|
346 // need to know if the next token is `=' or `=='. |
1
|
347 // |
|
348 // It would have been so much easier if the delimiters were simply |
|
349 // different for the expression on the left hand side of the equals |
|
350 // operator. |
971
|
351 // |
|
352 // It's also a pain in the ass to decide whether to insert a comma |
|
353 // after seeing a ']' character... |
968
|
354 %} |
|
355 |
4208
|
356 <MATRIX_START>{SNLCMT}*\]{S}* { |
3665
|
357 scan_for_comments (yytext); |
1001
|
358 fixup_column_count (yytext); |
|
359 int c = yytext[yyleng-1]; |
|
360 int cont_is_spc = eat_continuation (); |
4608
|
361 bool spc_gobbled = (cont_is_spc || c == ' ' || c == '\t'); |
4910
|
362 COUNT_TOK_AND_RETURN (handle_close_bracket (spc_gobbled, ']')); |
4608
|
363 } |
|
364 |
|
365 <MATRIX_START>{SNLCMT}*\}{S}* { |
|
366 scan_for_comments (yytext); |
|
367 fixup_column_count (yytext); |
|
368 int c = yytext[yyleng-1]; |
|
369 int cont_is_spc = eat_continuation (); |
|
370 bool spc_gobbled = (cont_is_spc || c == ' ' || c == '\t'); |
4910
|
371 COUNT_TOK_AND_RETURN (handle_close_bracket (spc_gobbled, '}')); |
967
|
372 } |
1
|
373 |
968
|
374 %{ |
1088
|
375 // Commas are element separators in matrix constants. If we don't |
|
376 // check for continuations here we can end up inserting too many |
|
377 // commas. |
968
|
378 %} |
|
379 |
4208
|
380 <MATRIX_START>{S}*\,{S}* { |
1088
|
381 current_input_column += yyleng; |
3388
|
382 |
1088
|
383 int tmp = eat_continuation (); |
3388
|
384 |
2857
|
385 lexer_flags.quote_is_transpose = false; |
|
386 lexer_flags.convert_spaces_to_comma = true; |
3388
|
387 |
|
388 if ((tmp & ATE_NEWLINE) == ATE_NEWLINE) |
|
389 { |
|
390 maybe_warn_separator_insert (';'); |
|
391 |
4476
|
392 yyunput (';', yytext); |
3388
|
393 } |
|
394 |
4910
|
395 COUNT_TOK_AND_RETURN (','); |
967
|
396 } |
1
|
397 |
968
|
398 %{ |
|
399 // In some cases, spaces in matrix constants can turn into commas. |
|
400 // If commas are required, spaces are not important in matrix |
1088
|
401 // constants so we just eat them. If we don't check for continuations |
|
402 // here we can end up inserting too many commas. |
968
|
403 %} |
430
|
404 |
4208
|
405 <MATRIX_START>{S}+ { |
1088
|
406 current_input_column += yyleng; |
3388
|
407 |
|
408 int tmp = eat_continuation (); |
|
409 int bin_op = next_token_is_bin_op (true); |
|
410 int postfix_un_op = next_token_is_postfix_unary_op (true); |
|
411 |
|
412 if (! (postfix_un_op || bin_op) |
4608
|
413 && nesting_level.is_bracket_or_brace () |
3388
|
414 && lexer_flags.convert_spaces_to_comma) |
967
|
415 { |
3388
|
416 if ((tmp & ATE_NEWLINE) == ATE_NEWLINE) |
|
417 { |
|
418 maybe_warn_separator_insert (';'); |
967
|
419 |
4476
|
420 yyunput (';', yytext); |
3388
|
421 } |
|
422 |
4476
|
423 lexer_flags.quote_is_transpose = false; |
|
424 lexer_flags.convert_spaces_to_comma = true; |
|
425 |
|
426 maybe_warn_separator_insert (','); |
|
427 |
4910
|
428 COUNT_TOK_AND_RETURN (','); |
967
|
429 } |
|
430 } |
430
|
431 |
968
|
432 %{ |
1088
|
433 // Semicolons are handled as row seprators in matrix constants. If we |
|
434 // don't eat whitespace here we can end up inserting too many |
|
435 // semicolons. |
968
|
436 %} |
|
437 |
4208
|
438 <MATRIX_START>{SNLCMT}*;{SNLCMT}* { |
3665
|
439 scan_for_comments (yytext); |
967
|
440 fixup_column_count (yytext); |
1001
|
441 eat_whitespace (); |
2857
|
442 lexer_flags.quote_is_transpose = false; |
|
443 lexer_flags.convert_spaces_to_comma = true; |
4910
|
444 COUNT_TOK_AND_RETURN (';'); |
967
|
445 } |
|
446 |
968
|
447 %{ |
1088
|
448 // In some cases, new lines can also become row separators. If we |
|
449 // don't eat whitespace here we can end up inserting too many |
|
450 // semicolons. |
985
|
451 %} |
|
452 |
4208
|
453 <MATRIX_START>{S}*{COMMENT}{SNLCMT}* | |
|
454 <MATRIX_START>{S}*{NL}{SNLCMT}* { |
3665
|
455 scan_for_comments (yytext); |
1082
|
456 fixup_column_count (yytext); |
1088
|
457 eat_whitespace (); |
3388
|
458 |
4476
|
459 lexer_flags.quote_is_transpose = false; |
|
460 lexer_flags.convert_spaces_to_comma = true; |
|
461 |
|
462 if (nesting_level.none ()) |
|
463 return LEXICAL_ERROR; |
985
|
464 |
4608
|
465 if (nesting_level.is_bracket_or_brace ()) |
3388
|
466 { |
|
467 maybe_warn_separator_insert (';'); |
|
468 |
4910
|
469 COUNT_TOK_AND_RETURN (';'); |
985
|
470 } |
|
471 } |
|
472 |
967
|
473 \[{S}* { |
3351
|
474 nesting_level.bracket (); |
975
|
475 |
1082
|
476 current_input_column += yyleng; |
2857
|
477 lexer_flags.quote_is_transpose = false; |
|
478 lexer_flags.convert_spaces_to_comma = true; |
975
|
479 |
|
480 promptflag--; |
|
481 eat_whitespace (); |
|
482 |
5102
|
483 lexer_flags.bracketflag++; |
|
484 BEGIN (MATRIX_START); |
|
485 COUNT_TOK_AND_RETURN ('['); |
967
|
486 } |
1
|
487 |
968
|
488 \] { |
1826
|
489 nesting_level.remove (); |
968
|
490 |
5102
|
491 TOK_RETURN (']'); |
968
|
492 } |
|
493 |
|
494 %{ |
|
495 // Imaginary numbers. |
|
496 %} |
|
497 |
|
498 {NUMBER}{Im} { |
3246
|
499 handle_number (); |
4910
|
500 COUNT_TOK_AND_RETURN (IMAG_NUM); |
968
|
501 } |
|
502 |
|
503 %{ |
|
504 // Real numbers. Don't grab the `.' part of a dot operator as part of |
|
505 // the constant. |
|
506 %} |
|
507 |
|
508 {D}+/\.[\*/\\^'] | |
|
509 {NUMBER} { |
3246
|
510 handle_number (); |
4910
|
511 COUNT_TOK_AND_RETURN (NUM); |
968
|
512 } |
|
513 |
|
514 %{ |
|
515 // Eat whitespace. Whitespace inside matrix constants is handled by |
4208
|
516 // the <MATRIX_START> start state code above. |
968
|
517 %} |
|
518 |
967
|
519 {S}* { |
|
520 current_input_column += yyleng; |
|
521 } |
|
522 |
968
|
523 %{ |
|
524 // Continuation lines. Allow comments after continuations. |
|
525 %} |
|
526 |
967
|
527 {CONT}{S}*{NL} | |
|
528 {CONT}{S}*{COMMENT} { |
4037
|
529 if (yytext[0] == '\\') |
|
530 gripe_matlab_incompatible_continuation (); |
3665
|
531 scan_for_comments (yytext); |
967
|
532 promptflag--; |
|
533 current_input_column = 1; |
|
534 } |
1
|
535 |
968
|
536 %{ |
|
537 // An ellipsis not at the end of a line is not a continuation, but |
|
538 // does have another meaning. |
|
539 %} |
|
540 |
967
|
541 {EL} { |
3973
|
542 if (lexer_flags.looking_at_parameter_list) |
3974
|
543 { |
|
544 warning ("`...' is deprecated; use varargin instead"); |
4910
|
545 COUNT_TOK_AND_RETURN (VARARGIN); |
3974
|
546 } |
3973
|
547 else if (lexer_flags.looking_at_return_list) |
3974
|
548 { |
|
549 warning ("`...' is deprecated; use varargout instead"); |
4910
|
550 COUNT_TOK_AND_RETURN (VARARGOUT); |
3974
|
551 } |
3973
|
552 else |
|
553 return LEXICAL_ERROR; |
967
|
554 } |
1
|
555 |
968
|
556 %{ |
|
557 // End of file. |
|
558 %} |
|
559 |
967
|
560 <<EOF>> { |
|
561 TOK_RETURN (END_OF_INPUT); |
|
562 } |
1
|
563 |
968
|
564 %{ |
970
|
565 // Identifiers. Truncate the token at the first space or tab but |
|
566 // don't write directly on yytext. |
968
|
567 %} |
|
568 |
967
|
569 {IDENT}{S}* { |
4238
|
570 int id_tok = handle_identifier (); |
|
571 |
|
572 if (id_tok >= 0) |
4910
|
573 COUNT_TOK_AND_RETURN (id_tok); |
967
|
574 } |
1
|
575 |
968
|
576 %{ |
4342
|
577 // Function handles. |
|
578 %} |
|
579 |
4930
|
580 "@" { |
|
581 current_input_column++; |
|
582 lexer_flags.quote_is_transpose = false; |
|
583 lexer_flags.convert_spaces_to_comma = false; |
|
584 lexer_flags.looking_at_function_handle++; |
|
585 COUNT_TOK_AND_RETURN ('@'); |
4342
|
586 } |
|
587 |
|
588 %{ |
968
|
589 // A new line character. New line characters inside matrix constants |
4208
|
590 // are handled by the <MATRIX_START> start state code above. If closest |
985
|
591 // nesting is inside parentheses, don't return a row separator. |
968
|
592 %} |
|
593 |
967
|
594 {NL} { |
|
595 current_input_column = 1; |
2857
|
596 lexer_flags.quote_is_transpose = false; |
|
597 lexer_flags.convert_spaces_to_comma = true; |
1826
|
598 if (nesting_level.none ()) |
4910
|
599 COUNT_TOK_AND_RETURN ('\n'); |
4037
|
600 else if (nesting_level.is_paren ()) |
|
601 gripe_matlab_incompatible ("bare newline inside parentheses"); |
4608
|
602 else if (nesting_level.is_bracket_or_brace ()) |
985
|
603 return LEXICAL_ERROR; |
967
|
604 } |
1
|
605 |
968
|
606 %{ |
|
607 // Single quote can either be the beginning of a string or a transpose |
|
608 // operator. |
|
609 %} |
|
610 |
967
|
611 "'" { |
|
612 current_input_column++; |
2857
|
613 lexer_flags.convert_spaces_to_comma = true; |
1
|
614 |
1826
|
615 if (lexer_flags.quote_is_transpose) |
967
|
616 { |
|
617 do_comma_insert_check (); |
4910
|
618 COUNT_TOK_AND_RETURN (QUOTE); |
967
|
619 } |
|
620 else |
4910
|
621 COUNT_TOK_AND_RETURN (handle_string ('\'')); |
967
|
622 } |
1
|
623 |
968
|
624 %{ |
971
|
625 // Double quotes always begin strings. |
|
626 %} |
|
627 |
973
|
628 \" { |
|
629 current_input_column++; |
4910
|
630 COUNT_TOK_AND_RETURN (handle_string ('"')); |
973
|
631 } |
971
|
632 |
|
633 %{ |
985
|
634 // Gobble comments. If closest nesting is inside parentheses, don't |
|
635 // return a new line. |
|
636 %} |
968
|
637 |
967
|
638 {CCHAR} { |
4426
|
639 std::string help_txt; |
|
640 |
|
641 if (! help_buf.empty ()) |
|
642 help_txt = help_buf.top (); |
|
643 |
|
644 if (help_txt.empty () |
1826
|
645 && lexer_flags.beginning_of_function |
|
646 && nesting_level.none ()) |
967
|
647 { |
3665
|
648 lexer_flags.beginning_of_function = false; |
|
649 |
4426
|
650 std::string txt = grab_help_text (); |
|
651 |
|
652 if (! help_buf.empty ()) |
|
653 help_buf.pop (); |
|
654 |
|
655 help_buf.push (txt); |
|
656 |
|
657 octave_comment_buffer::append (txt); |
967
|
658 } |
|
659 else |
|
660 { |
3665
|
661 std::string buf; |
|
662 |
|
663 bool begin_comment = true; |
|
664 |
967
|
665 int c; |
|
666 while ((c = yyinput ()) != EOF && c != '\n') |
3665
|
667 { |
|
668 if (begin_comment && (c == '#' || c == '%')) |
|
669 ; /* Skip leading comment characters. */ |
|
670 else |
3802
|
671 buf += static_cast<char> (c); |
3665
|
672 } |
|
673 |
|
674 octave_comment_buffer::append (buf); |
967
|
675 } |
440
|
676 |
967
|
677 current_input_column = 1; |
2857
|
678 lexer_flags.quote_is_transpose = false; |
|
679 lexer_flags.convert_spaces_to_comma = true; |
985
|
680 |
4037
|
681 maybe_gripe_matlab_incompatible_comment (yytext[0]); |
|
682 |
4323
|
683 if (YY_START == COMMAND_START) |
|
684 BEGIN (INITIAL); |
|
685 |
1826
|
686 if (nesting_level.none ()) |
4910
|
687 COUNT_TOK_AND_RETURN ('\n'); |
4608
|
688 else if (nesting_level.is_bracket_or_brace ()) |
4910
|
689 COUNT_TOK_AND_RETURN (';'); |
967
|
690 } |
440
|
691 |
968
|
692 %{ |
|
693 // Other operators. |
|
694 %} |
|
695 |
5102
|
696 ":" { BIN_OP_RETURN (':', false); } |
|
697 |
4037
|
698 ".+" { XBIN_OP_RETURN (EPLUS, false); } |
|
699 ".-" { XBIN_OP_RETURN (EMINUS, false); } |
2857
|
700 ".*" { BIN_OP_RETURN (EMUL, false); } |
|
701 "./" { BIN_OP_RETURN (EDIV, false); } |
|
702 ".\\" { BIN_OP_RETURN (ELEFTDIV, false); } |
4037
|
703 ".^" { BIN_OP_RETURN (EPOW, false); } |
|
704 ".**" { XBIN_OP_RETURN (EPOW, false); } |
2857
|
705 ".'" { do_comma_insert_check (); BIN_OP_RETURN (TRANSPOSE, true); } |
4037
|
706 "++" { do_comma_insert_check (); XBIN_OP_RETURN (PLUS_PLUS, true); } |
|
707 "--" { do_comma_insert_check (); XBIN_OP_RETURN (MINUS_MINUS, true); } |
2857
|
708 "<=" { BIN_OP_RETURN (EXPR_LE, false); } |
|
709 "==" { BIN_OP_RETURN (EXPR_EQ, false); } |
4037
|
710 "~=" { BIN_OP_RETURN (EXPR_NE, false); } |
|
711 "!=" { XBIN_OP_RETURN (EXPR_NE, false); } |
2857
|
712 ">=" { BIN_OP_RETURN (EXPR_GE, false); } |
2877
|
713 "&" { BIN_OP_RETURN (EXPR_AND, false); } |
2857
|
714 "|" { BIN_OP_RETURN (EXPR_OR, false); } |
|
715 "<" { BIN_OP_RETURN (EXPR_LT, false); } |
|
716 ">" { BIN_OP_RETURN (EXPR_GT, false); } |
5102
|
717 "+" { BIN_OP_RETURN ('+', false); } |
|
718 "-" { BIN_OP_RETURN ('-', false); } |
2857
|
719 "*" { BIN_OP_RETURN ('*', false); } |
|
720 "/" { BIN_OP_RETURN ('/', false); } |
|
721 "\\" { BIN_OP_RETURN (LEFTDIV, false); } |
|
722 ";" { BIN_OP_RETURN (';', true); } |
|
723 "," { BIN_OP_RETURN (',', true); } |
4037
|
724 "^" { BIN_OP_RETURN (POW, false); } |
|
725 "**" { XBIN_OP_RETURN (POW, false); } |
2857
|
726 "=" { BIN_OP_RETURN ('=', true); } |
2877
|
727 "&&" { BIN_OP_RETURN (EXPR_AND_AND, false); } |
2857
|
728 "||" { BIN_OP_RETURN (EXPR_OR_OR, false); } |
4037
|
729 "<<" { XBIN_OP_RETURN (LSHIFT, false); } |
|
730 ">>" { XBIN_OP_RETURN (RSHIFT, false); } |
967
|
731 |
|
732 {NOT} { |
4037
|
733 if (yytext[0] == '~') |
|
734 BIN_OP_RETURN (EXPR_NOT, false); |
|
735 else |
|
736 XBIN_OP_RETURN (EXPR_NOT, false); |
967
|
737 } |
1
|
738 |
967
|
739 "(" { |
4131
|
740 lexer_flags.looking_at_indirect_ref = false; |
1826
|
741 nesting_level.paren (); |
985
|
742 promptflag--; |
967
|
743 TOK_RETURN ('('); |
|
744 } |
|
745 |
|
746 ")" { |
1826
|
747 nesting_level.remove (); |
967
|
748 current_input_column++; |
2857
|
749 lexer_flags.quote_is_transpose = true; |
4608
|
750 lexer_flags.convert_spaces_to_comma = nesting_level.is_bracket_or_brace (); |
1001
|
751 do_comma_insert_check (); |
4910
|
752 COUNT_TOK_AND_RETURN (')'); |
967
|
753 } |
|
754 |
5102
|
755 "." { TOK_RETURN ('.'); } |
2066
|
756 |
4037
|
757 "+=" { XBIN_OP_RETURN (ADD_EQ, false); } |
|
758 "-=" { XBIN_OP_RETURN (SUB_EQ, false); } |
|
759 "*=" { XBIN_OP_RETURN (MUL_EQ, false); } |
|
760 "/=" { XBIN_OP_RETURN (DIV_EQ, false); } |
|
761 "\\=" { XBIN_OP_RETURN (LEFTDIV_EQ, false); } |
|
762 ".+=" { XBIN_OP_RETURN (ADD_EQ, false); } |
|
763 ".-=" { XBIN_OP_RETURN (SUB_EQ, false); } |
|
764 ".*=" { XBIN_OP_RETURN (EMUL_EQ, false); } |
|
765 "./=" { XBIN_OP_RETURN (EDIV_EQ, false); } |
|
766 ".\\=" { XBIN_OP_RETURN (ELEFTDIV_EQ, false); } |
|
767 {POW}= { XBIN_OP_RETURN (POW_EQ, false); } |
|
768 {EPOW}= { XBIN_OP_RETURN (EPOW_EQ, false); } |
|
769 "&=" { XBIN_OP_RETURN (AND_EQ, false); } |
|
770 "|=" { XBIN_OP_RETURN (OR_EQ, false); } |
|
771 "<<=" { XBIN_OP_RETURN (LSHIFT_EQ, false); } |
|
772 ">>=" { XBIN_OP_RETURN (RSHIFT_EQ, false); } |
2877
|
773 |
4608
|
774 \{{S}* { |
3351
|
775 nesting_level.brace (); |
4608
|
776 |
|
777 current_input_column += yyleng; |
|
778 lexer_flags.quote_is_transpose = false; |
|
779 lexer_flags.convert_spaces_to_comma = true; |
|
780 |
3351
|
781 promptflag--; |
4608
|
782 eat_whitespace (); |
|
783 |
4613
|
784 lexer_flags.braceflag++; |
4608
|
785 BEGIN (MATRIX_START); |
4910
|
786 COUNT_TOK_AND_RETURN ('{'); |
3351
|
787 } |
|
788 |
|
789 "}" { |
|
790 nesting_level.remove (); |
|
791 |
4608
|
792 TOK_RETURN ('}'); |
3351
|
793 } |
|
794 |
968
|
795 %{ |
2066
|
796 // Unrecognized input is a lexical error. |
968
|
797 %} |
1
|
798 |
2042
|
799 . { |
4240
|
800 // EOF happens here if we are parsing nested functions. |
|
801 |
4410
|
802 yyunput (yytext[0], yytext); |
4248
|
803 |
|
804 int c = yyinput (); |
|
805 |
|
806 if (c != EOF) |
4240
|
807 { |
|
808 current_input_column++; |
|
809 |
|
810 error ("invalid character `%s' (ASCII %d) near line %d, column %d", |
4248
|
811 undo_string_escape (static_cast<char> (c)), c, |
4240
|
812 input_line_number, current_input_column); |
|
813 |
|
814 return LEXICAL_ERROR; |
|
815 } |
|
816 else |
|
817 TOK_RETURN (END_OF_INPUT); |
2066
|
818 } |
1
|
819 |
|
820 %% |
|
821 |
767
|
822 // GAG. |
|
823 // |
|
824 // If we're reading a matrix and the next character is '[', make sure |
|
825 // that we insert a comma ahead of it. |
|
826 |
146
|
827 void |
1
|
828 do_comma_insert_check (void) |
|
829 { |
1001
|
830 int spc_gobbled = eat_continuation (); |
2970
|
831 |
1
|
832 int c = yyinput (); |
2970
|
833 |
4410
|
834 yyunput (c, yytext); |
2970
|
835 |
1001
|
836 if (spc_gobbled) |
4410
|
837 yyunput (' ', yytext); |
2970
|
838 |
3351
|
839 lexer_flags.do_comma_insert = (lexer_flags.bracketflag && c == '['); |
1
|
840 } |
|
841 |
767
|
842 // Fix things up for errors or interrupts. The parser is never called |
|
843 // recursively, so it is always safe to reinitialize its state before |
|
844 // doing any parsing. |
|
845 |
1
|
846 void |
|
847 reset_parser (void) |
|
848 { |
1826
|
849 // Start off on the right foot. |
4323
|
850 BEGIN (INITIAL); |
4318
|
851 |
3883
|
852 parser_end_of_input = false; |
4238
|
853 end_tokens_expected = 0; |
|
854 |
|
855 while (! symtab_context.empty ()) |
|
856 symtab_context.pop (); |
287
|
857 |
1826
|
858 // We do want a prompt by default. |
1
|
859 promptflag = 1; |
287
|
860 |
3351
|
861 // Error may have occurred inside some brackets, braces, or parentheses. |
985
|
862 nesting_level.clear (); |
287
|
863 |
1826
|
864 // Clear out the stack of token info used to track line and column |
|
865 // numbers. |
143
|
866 while (! token_stack.empty ()) |
4214
|
867 { |
|
868 delete token_stack.top (); |
|
869 token_stack.pop (); |
|
870 } |
287
|
871 |
1826
|
872 // Can be reset by defining a function. |
985
|
873 if (! (reading_script_file || reading_fcn_file)) |
|
874 { |
|
875 current_input_column = 1; |
2926
|
876 input_line_number = command_editor::current_command_number () - 1; |
985
|
877 } |
287
|
878 |
1826
|
879 // Only ask for input from stdin if we are expecting interactive |
|
880 // input. |
3174
|
881 if ((interactive || forced_interactive) |
3880
|
882 && ! (reading_fcn_file |
|
883 || reading_script_file |
|
884 || get_input_from_eval_string |
3174
|
885 || input_from_startup_file)) |
287
|
886 yyrestart (stdin); |
991
|
887 |
1826
|
888 // Clear the buffer for help text. |
4426
|
889 while (! help_buf.empty ()) |
|
890 help_buf.pop (); |
1755
|
891 |
1826
|
892 // Reset other flags. |
|
893 lexer_flags.init (); |
1
|
894 } |
|
895 |
767
|
896 // If we read some newlines, we need figure out what column we're |
|
897 // really looking at. |
|
898 |
1
|
899 static void |
|
900 fixup_column_count (char *s) |
|
901 { |
|
902 char c; |
|
903 while ((c = *s++) != '\0') |
|
904 { |
|
905 if (c == '\n') |
143
|
906 current_input_column = 1; |
1
|
907 else |
|
908 current_input_column++; |
|
909 } |
|
910 } |
|
911 |
767
|
912 // Include these so that we don't have to link to libfl.a. |
246
|
913 |
3332
|
914 int |
1
|
915 yywrap (void) |
|
916 { |
287
|
917 return 1; |
1
|
918 } |
|
919 |
767
|
920 // Tell us all what the current buffer is. |
|
921 |
1
|
922 YY_BUFFER_STATE |
|
923 current_buffer (void) |
|
924 { |
|
925 return YY_CURRENT_BUFFER; |
|
926 } |
|
927 |
767
|
928 // Create a new buffer. |
|
929 |
1
|
930 YY_BUFFER_STATE |
|
931 create_buffer (FILE *f) |
|
932 { |
|
933 return yy_create_buffer (f, YY_BUF_SIZE); |
|
934 } |
|
935 |
767
|
936 // Start reading a new buffer. |
|
937 |
1
|
938 void |
|
939 switch_to_buffer (YY_BUFFER_STATE buf) |
|
940 { |
|
941 yy_switch_to_buffer (buf); |
|
942 } |
|
943 |
767
|
944 // Delete a buffer. |
|
945 |
1
|
946 void |
|
947 delete_buffer (YY_BUFFER_STATE buf) |
|
948 { |
|
949 yy_delete_buffer (buf); |
|
950 } |
|
951 |
767
|
952 // Restore a buffer (for unwind-prot). |
|
953 |
1
|
954 void |
|
955 restore_input_buffer (void *buf) |
|
956 { |
2861
|
957 switch_to_buffer (static_cast<YY_BUFFER_STATE> (buf)); |
1
|
958 } |
|
959 |
767
|
960 // Delete a buffer (for unwind-prot). |
|
961 |
1
|
962 void |
|
963 delete_input_buffer (void *buf) |
|
964 { |
2861
|
965 delete_buffer (static_cast<YY_BUFFER_STATE> (buf)); |
1
|
966 } |
|
967 |
4238
|
968 static void |
|
969 prep_for_function (void) |
|
970 { |
|
971 end_tokens_expected++; |
|
972 |
|
973 // Prepare for local symbols. |
|
974 |
|
975 tmp_local_sym_tab = new symbol_table (); |
|
976 |
|
977 promptflag--; |
|
978 |
|
979 lexer_flags.defining_func = true; |
|
980 lexer_flags.parsed_function_name = false; |
|
981 lexer_flags.beginning_of_function = true; |
|
982 |
|
983 if (! (reading_fcn_file || reading_script_file)) |
|
984 input_line_number = 1; |
|
985 } |
|
986 |
|
987 static void |
|
988 prep_for_nested_function (void) |
|
989 { |
4240
|
990 lexer_flags.parsing_nested_function = 1; |
4426
|
991 help_buf.push (std::string ()); |
4238
|
992 prep_for_function (); |
4240
|
993 // We're still only expecting one end token for this set of functions. |
|
994 end_tokens_expected--; |
4238
|
995 yylval.tok_val = new token (input_line_number, current_input_column); |
|
996 token_stack.push (yylval.tok_val); |
|
997 } |
|
998 |
|
999 // Handle keywords. Return -1 if the keyword should be ignored. |
767
|
1000 |
1
|
1001 static int |
4867
|
1002 is_keyword_token (const std::string& s) |
1
|
1003 { |
3805
|
1004 int l = input_line_number; |
|
1005 int c = current_input_column; |
|
1006 |
1823
|
1007 int len = s.length (); |
922
|
1008 |
5088
|
1009 const octave_kw *kw = octave_kw_hash::in_word_set (s.c_str (), len); |
191
|
1010 |
1497
|
1011 if (kw) |
143
|
1012 { |
1497
|
1013 yylval.tok_val = 0; |
|
1014 |
|
1015 switch (kw->kw_id) |
|
1016 { |
|
1017 case all_va_args_kw: |
|
1018 case break_kw: |
2764
|
1019 case case_kw: |
1497
|
1020 case catch_kw: |
|
1021 case continue_kw: |
|
1022 case else_kw: |
|
1023 case elseif_kw: |
|
1024 case global_kw: |
2764
|
1025 case otherwise_kw: |
1497
|
1026 case return_kw: |
2846
|
1027 case static_kw: |
3484
|
1028 case until_kw: |
1497
|
1029 case unwind_protect_cleanup_kw: |
|
1030 break; |
|
1031 |
|
1032 case end_kw: |
4234
|
1033 if (lexer_flags.looking_at_object_index) |
|
1034 return 0; |
|
1035 else |
4238
|
1036 { |
|
1037 if (reading_fcn_file && end_tokens_expected == 1) |
|
1038 return -1; |
|
1039 else |
|
1040 { |
|
1041 yylval.tok_val = new token (token::simple_end, l, c); |
|
1042 end_tokens_expected--; |
|
1043 } |
|
1044 } |
1497
|
1045 break; |
|
1046 |
|
1047 case end_try_catch_kw: |
4238
|
1048 end_tokens_expected--; |
1497
|
1049 yylval.tok_val = new token (token::try_catch_end, l, c); |
|
1050 break; |
|
1051 |
|
1052 case end_unwind_protect_kw: |
4238
|
1053 end_tokens_expected--; |
1497
|
1054 yylval.tok_val = new token (token::unwind_protect_end, l, c); |
|
1055 break; |
|
1056 |
|
1057 case endfor_kw: |
4238
|
1058 end_tokens_expected--; |
1497
|
1059 yylval.tok_val = new token (token::for_end, l, c); |
|
1060 break; |
|
1061 |
|
1062 case endfunction_kw: |
4238
|
1063 { |
|
1064 if (reading_fcn_file && end_tokens_expected == 1) |
|
1065 return -1; |
|
1066 else |
|
1067 { |
|
1068 yylval.tok_val = new token (token::function_end, l, c); |
|
1069 end_tokens_expected--; |
|
1070 } |
|
1071 } |
1497
|
1072 break; |
|
1073 |
|
1074 case endif_kw: |
4238
|
1075 end_tokens_expected--; |
1497
|
1076 yylval.tok_val = new token (token::if_end, l, c); |
|
1077 break; |
|
1078 |
2764
|
1079 case endswitch_kw: |
4238
|
1080 end_tokens_expected--; |
2764
|
1081 yylval.tok_val = new token (token::switch_end, l, c); |
|
1082 break; |
|
1083 |
1497
|
1084 case endwhile_kw: |
4238
|
1085 end_tokens_expected--; |
1497
|
1086 yylval.tok_val = new token (token::while_end, l, c); |
|
1087 break; |
|
1088 |
|
1089 case for_kw: |
|
1090 case while_kw: |
4238
|
1091 end_tokens_expected++; |
|
1092 // Fall through... |
|
1093 |
|
1094 case do_kw: |
1497
|
1095 promptflag--; |
1826
|
1096 lexer_flags.looping++; |
1497
|
1097 break; |
|
1098 |
|
1099 case if_kw: |
|
1100 case try_kw: |
2764
|
1101 case switch_kw: |
1497
|
1102 case unwind_protect_kw: |
4238
|
1103 end_tokens_expected++; |
1497
|
1104 promptflag--; |
|
1105 break; |
|
1106 |
|
1107 case function_kw: |
4238
|
1108 { |
|
1109 if (lexer_flags.defining_func) |
|
1110 { |
|
1111 if (reading_fcn_file) |
|
1112 { |
|
1113 if (lexer_flags.parsing_nested_function) |
|
1114 { |
4323
|
1115 BEGIN (NESTED_FUNCTION_END); |
4240
|
1116 |
4238
|
1117 yylval.tok_val = new token (token::function_end, l, c); |
4240
|
1118 token_stack.push (yylval.tok_val); |
|
1119 |
|
1120 return END; |
4238
|
1121 } |
|
1122 else |
|
1123 { |
|
1124 prep_for_nested_function (); |
4240
|
1125 |
4238
|
1126 return FCN; |
|
1127 } |
|
1128 } |
|
1129 else |
|
1130 { |
|
1131 error ("nested functions not implemented in this context"); |
|
1132 |
|
1133 if ((reading_fcn_file || reading_script_file) |
|
1134 && ! curr_fcn_file_name.empty ()) |
|
1135 error ("near line %d of file `%s.m'", |
|
1136 input_line_number, curr_fcn_file_name.c_str ()); |
|
1137 else |
|
1138 error ("near line %d", input_line_number); |
|
1139 |
|
1140 return LEXICAL_ERROR; |
|
1141 } |
|
1142 } |
|
1143 else |
|
1144 prep_for_function (); |
|
1145 } |
1497
|
1146 break; |
|
1147 |
3174
|
1148 case magic_file_kw: |
|
1149 { |
|
1150 if ((reading_fcn_file || reading_script_file) |
|
1151 && ! curr_fcn_file_full_name.empty ()) |
|
1152 yylval.tok_val = new token (curr_fcn_file_full_name, l, c); |
|
1153 else |
|
1154 yylval.tok_val = new token ("stdin", l, c); |
|
1155 } |
|
1156 break; |
|
1157 |
|
1158 case magic_line_kw: |
|
1159 yylval.tok_val = new token (static_cast<double> (l), "", l, c); |
|
1160 break; |
|
1161 |
3974
|
1162 case varargin_kw: |
|
1163 if (! lexer_flags.looking_at_parameter_list) |
|
1164 return 0; |
|
1165 break; |
|
1166 |
|
1167 case varargout_kw: |
4678
|
1168 if (! (lexer_flags.looking_at_return_list |
|
1169 || (lexer_flags.defining_func |
|
1170 && ! lexer_flags.parsed_function_name))) |
3974
|
1171 return 0; |
|
1172 break; |
|
1173 |
1497
|
1174 default: |
|
1175 panic_impossible (); |
|
1176 } |
|
1177 |
|
1178 if (! yylval.tok_val) |
|
1179 yylval.tok_val = new token (l, c); |
|
1180 |
476
|
1181 token_stack.push (yylval.tok_val); |
1497
|
1182 |
|
1183 return kw->tok; |
143
|
1184 } |
1
|
1185 |
|
1186 return 0; |
|
1187 } |
|
1188 |
767
|
1189 // Try to find an identifier. All binding to global or builtin |
|
1190 // variables occurs when expressions are evaluated. |
|
1191 |
1
|
1192 static symbol_record * |
3523
|
1193 lookup_identifier (const std::string& name) |
1
|
1194 { |
4238
|
1195 std::string sym_name = name; |
|
1196 |
|
1197 if (curr_sym_tab == fbi_sym_tab |
|
1198 && lexer_flags.parsing_nested_function) |
|
1199 sym_name = parent_function_name + ":" + sym_name; |
|
1200 |
|
1201 return curr_sym_tab->lookup (sym_name, true); |
1
|
1202 } |
|
1203 |
2702
|
1204 static bool |
3523
|
1205 is_variable (const std::string& name) |
2702
|
1206 { |
2856
|
1207 symbol_record *sr = curr_sym_tab->lookup (name); |
2702
|
1208 |
|
1209 return sr && sr->is_variable (); |
|
1210 } |
|
1211 |
|
1212 static void |
3523
|
1213 force_local_variable (const std::string& name) |
2702
|
1214 { |
4101
|
1215 if (! is_variable (name)) |
|
1216 curr_sym_tab->clear (name); |
|
1217 |
2856
|
1218 symbol_record *sr = curr_sym_tab->lookup (name, true); |
2702
|
1219 |
|
1220 if (sr) |
|
1221 sr->define (octave_value ()); |
|
1222 } |
|
1223 |
4426
|
1224 // Grab the help text from an function file. |
767
|
1225 |
3427
|
1226 // XXX FIXME XXX -- gobble_leading_white_space() in parse.y |
2300
|
1227 // duplicates some of this code! |
|
1228 |
4426
|
1229 static std::string |
1
|
1230 grab_help_text (void) |
|
1231 { |
4426
|
1232 std::string buf; |
1019
|
1233 |
2300
|
1234 bool begin_comment = true; |
|
1235 bool in_comment = true; |
3427
|
1236 bool discard_space = true; |
3665
|
1237 |
1019
|
1238 int c = 0; |
1
|
1239 |
1019
|
1240 while ((c = yyinput ()) != EOF) |
|
1241 { |
2300
|
1242 if (begin_comment) |
|
1243 { |
|
1244 if (c == '%' || c == '#') |
|
1245 continue; |
3427
|
1246 else if (discard_space && c == ' ') |
|
1247 { |
|
1248 discard_space = false; |
|
1249 continue; |
|
1250 } |
2300
|
1251 else |
|
1252 begin_comment = false; |
|
1253 } |
|
1254 |
1019
|
1255 if (in_comment) |
1
|
1256 { |
4426
|
1257 buf += static_cast<char> (c); |
1755
|
1258 |
1019
|
1259 if (c == '\n') |
3427
|
1260 { |
|
1261 in_comment = false; |
|
1262 discard_space = true; |
|
1263 } |
1019
|
1264 } |
|
1265 else |
|
1266 { |
|
1267 switch (c) |
991
|
1268 { |
4037
|
1269 case '#': |
1019
|
1270 case '%': |
4037
|
1271 maybe_gripe_matlab_incompatible_comment (yytext[0]); |
2300
|
1272 in_comment = true; |
|
1273 begin_comment = true; |
1019
|
1274 break; |
777
|
1275 |
1019
|
1276 case ' ': |
|
1277 case '\t': |
|
1278 break; |
777
|
1279 |
1019
|
1280 default: |
|
1281 goto done; |
1
|
1282 } |
|
1283 } |
1019
|
1284 } |
991
|
1285 |
1019
|
1286 done: |
991
|
1287 |
1019
|
1288 if (c) |
4410
|
1289 yyunput (c, yytext); |
4426
|
1290 |
|
1291 return buf; |
1
|
1292 } |
|
1293 |
767
|
1294 // Return 1 if the given character matches any character in the given |
|
1295 // string. |
|
1296 |
2857
|
1297 static bool |
2804
|
1298 match_any (char c, const char *s) |
1
|
1299 { |
|
1300 char tmp; |
|
1301 while ((tmp = *s++) != '\0') |
|
1302 { |
|
1303 if (c == tmp) |
2857
|
1304 return true; |
1
|
1305 } |
2857
|
1306 return false; |
1
|
1307 } |
|
1308 |
767
|
1309 // Given information about the spacing surrounding an operator, |
|
1310 // return 1 if it looks like it should be treated as a binary |
|
1311 // operator. For example, |
|
1312 // |
3774
|
1313 // [ 1 + 2 ] or [ 1+ 2] or [ 1+2 ] ==> binary |
|
1314 // |
|
1315 // [ 1 +2 ] ==> unary |
767
|
1316 |
2857
|
1317 static bool |
3246
|
1318 looks_like_bin_op (bool spc_prev, int next_char) |
1
|
1319 { |
3246
|
1320 bool spc_next = (next_char == ' ' || next_char == '\t'); |
|
1321 |
608
|
1322 return ((spc_prev && spc_next) || ! spc_prev); |
1
|
1323 } |
|
1324 |
3263
|
1325 // Recognize separators. If the separator is a CRLF pair, it is |
|
1326 // replaced by a single LF. |
|
1327 |
|
1328 static bool |
|
1329 next_token_is_sep_op (void) |
|
1330 { |
|
1331 bool retval = false; |
|
1332 |
|
1333 int c1 = yyinput (); |
|
1334 |
|
1335 if (c1 == '\r') |
|
1336 { |
|
1337 int c2 = yyinput (); |
|
1338 |
|
1339 if (c2 == '\n') |
|
1340 { |
|
1341 c1 = '\n'; |
|
1342 |
|
1343 retval = true; |
|
1344 } |
|
1345 else |
4410
|
1346 yyunput (c2, yytext); |
3263
|
1347 } |
|
1348 else |
|
1349 retval = match_any (c1, ",;\n]"); |
|
1350 |
4410
|
1351 yyunput (c1, yytext); |
3263
|
1352 |
|
1353 return retval; |
|
1354 } |
|
1355 |
767
|
1356 // Try to determine if the next token should be treated as a postfix |
|
1357 // unary operator. This is ugly, but it seems to do the right thing. |
|
1358 |
2857
|
1359 static bool |
3246
|
1360 next_token_is_postfix_unary_op (bool spc_prev) |
1
|
1361 { |
2857
|
1362 bool un_op = false; |
1
|
1363 |
|
1364 int c0 = yyinput (); |
|
1365 |
3246
|
1366 if (c0 == '\'' && ! spc_prev) |
|
1367 { |
|
1368 un_op = true; |
|
1369 } |
|
1370 else if (c0 == '.') |
|
1371 { |
|
1372 int c1 = yyinput (); |
|
1373 un_op = (c1 == '\''); |
4410
|
1374 yyunput (c1, yytext); |
3246
|
1375 } |
4613
|
1376 else if (c0 == '+') |
|
1377 { |
|
1378 int c1 = yyinput (); |
|
1379 un_op = (c1 == '+'); |
|
1380 yyunput (c1, yytext); |
|
1381 } |
|
1382 else if (c0 == '-') |
|
1383 { |
|
1384 int c1 = yyinput (); |
|
1385 un_op = (c1 == '-'); |
|
1386 yyunput (c1, yytext); |
|
1387 } |
1
|
1388 |
4410
|
1389 yyunput (c0, yytext); |
1
|
1390 |
|
1391 return un_op; |
|
1392 } |
|
1393 |
767
|
1394 // Try to determine if the next token should be treated as a binary |
3246
|
1395 // operator. |
1521
|
1396 // |
3246
|
1397 // This kluge exists because whitespace is not always ignored inside |
3774
|
1398 // the square brackets that are used to create matrix objects (though |
|
1399 // spacing only really matters in the cases that can be interpreted |
|
1400 // either as binary ops or prefix unary ops: currently just +, -). |
|
1401 // |
3779
|
1402 // Note that a line continuation directly following a + or - operator |
|
1403 // (e.g., the characters '[' 'a' ' ' '+' '\' LFD 'b' ']') will be |
|
1404 // parsed as a binary operator. |
767
|
1405 |
2857
|
1406 static bool |
3246
|
1407 next_token_is_bin_op (bool spc_prev) |
1
|
1408 { |
2857
|
1409 bool bin_op = false; |
1
|
1410 |
|
1411 int c0 = yyinput (); |
|
1412 |
|
1413 switch (c0) |
|
1414 { |
777
|
1415 case '+': |
|
1416 case '-': |
3774
|
1417 { |
|
1418 int c1 = yyinput (); |
|
1419 |
|
1420 switch (c1) |
|
1421 { |
|
1422 case '+': |
|
1423 case '-': |
|
1424 // Unary ops, spacing doesn't matter. |
|
1425 break; |
|
1426 |
|
1427 case '=': |
|
1428 // Binary ops, spacing doesn't matter. |
|
1429 bin_op = true; |
|
1430 break; |
|
1431 |
|
1432 default: |
|
1433 // Could be either, spacing matters. |
|
1434 bin_op = looks_like_bin_op (spc_prev, c1); |
|
1435 break; |
|
1436 } |
|
1437 |
4410
|
1438 yyunput (c1, yytext); |
3774
|
1439 } |
|
1440 break; |
|
1441 |
|
1442 case ':': |
3246
|
1443 case '/': |
|
1444 case '\\': |
|
1445 case '^': |
3774
|
1446 // Always a binary op (may also include /=, \=, and ^=). |
|
1447 bin_op = true; |
1276
|
1448 break; |
|
1449 |
3246
|
1450 // .+ .- ./ .\ .^ .* .** |
1554
|
1451 case '.': |
|
1452 { |
|
1453 int c1 = yyinput (); |
3246
|
1454 |
3774
|
1455 if (match_any (c1, "+-/\\^*")) |
|
1456 // Always a binary op (may also include .+=, .-=, ./=, ...). |
|
1457 bin_op = true; |
3698
|
1458 else if (! isdigit (c1) && c1 != ' ' && c1 != '\t' && c1 != '.') |
3774
|
1459 // A structure element reference is a binary op. |
|
1460 bin_op = true; |
3246
|
1461 |
4410
|
1462 yyunput (c1, yytext); |
1554
|
1463 } |
|
1464 break; |
|
1465 |
3246
|
1466 // = == & && | || * ** |
|
1467 case '=': |
1
|
1468 case '&': |
3246
|
1469 case '|': |
1
|
1470 case '*': |
3774
|
1471 // Always a binary op (may also include ==, &&, ||, **). |
|
1472 bin_op = true; |
3246
|
1473 break; |
|
1474 |
3774
|
1475 // < <= <> > >= |
1
|
1476 case '<': |
|
1477 case '>': |
3774
|
1478 // Always a binary op (may also include <=, <>, >=). |
|
1479 bin_op = true; |
|
1480 break; |
|
1481 |
|
1482 // ~= != |
777
|
1483 case '~': |
|
1484 case '!': |
3246
|
1485 { |
|
1486 int c1 = yyinput (); |
|
1487 |
3774
|
1488 // ~ and ! can be unary ops, so require following =. |
|
1489 if (c1 == '=') |
|
1490 bin_op = true; |
3246
|
1491 |
4410
|
1492 yyunput (c1, yytext); |
3246
|
1493 } |
1
|
1494 break; |
|
1495 |
|
1496 default: |
1276
|
1497 break; |
1
|
1498 } |
|
1499 |
4410
|
1500 yyunput (c0, yytext); |
1
|
1501 |
|
1502 return bin_op; |
|
1503 } |
|
1504 |
767
|
1505 // Used to delete trailing white space from tokens. |
|
1506 |
3536
|
1507 static std::string |
1
|
1508 strip_trailing_whitespace (char *s) |
|
1509 { |
3523
|
1510 std::string retval = s; |
1
|
1511 |
1823
|
1512 size_t pos = retval.find_first_of (" \t"); |
1
|
1513 |
1823
|
1514 if (pos != NPOS) |
|
1515 retval.resize (pos); |
1
|
1516 |
|
1517 return retval; |
|
1518 } |
|
1519 |
3665
|
1520 static void |
|
1521 scan_for_comments (const char *text) |
|
1522 { |
|
1523 std::string comment_buf; |
|
1524 |
|
1525 bool in_comment = false; |
|
1526 bool beginning_of_comment = false; |
|
1527 |
|
1528 int len = strlen (text); |
|
1529 int i = 0; |
|
1530 |
|
1531 while (i < len) |
|
1532 { |
|
1533 char c = text[i++]; |
|
1534 |
|
1535 switch (c) |
|
1536 { |
|
1537 case '%': |
|
1538 case '#': |
|
1539 if (in_comment) |
|
1540 { |
|
1541 if (! beginning_of_comment) |
3802
|
1542 comment_buf += static_cast<char> (c); |
3665
|
1543 } |
|
1544 else |
|
1545 { |
4037
|
1546 maybe_gripe_matlab_incompatible_comment (c); |
3665
|
1547 in_comment = true; |
|
1548 beginning_of_comment = true; |
|
1549 } |
|
1550 break; |
|
1551 |
|
1552 case '\n': |
|
1553 if (in_comment) |
|
1554 { |
3802
|
1555 comment_buf += static_cast<char> (c); |
3665
|
1556 octave_comment_buffer::append (comment_buf); |
|
1557 comment_buf.resize (0); |
|
1558 in_comment = false; |
|
1559 beginning_of_comment = false; |
|
1560 } |
|
1561 break; |
|
1562 |
|
1563 case '\r': |
|
1564 if (in_comment) |
3802
|
1565 comment_buf += static_cast<char> (c); |
3665
|
1566 if (i < len) |
|
1567 { |
|
1568 c = text[i++]; |
|
1569 |
|
1570 if (c == '\n') |
|
1571 { |
|
1572 if (in_comment) |
|
1573 { |
3802
|
1574 comment_buf += static_cast<char> (c); |
3665
|
1575 octave_comment_buffer::append (comment_buf); |
|
1576 in_comment = false; |
|
1577 beginning_of_comment = false; |
|
1578 } |
|
1579 } |
|
1580 } |
|
1581 |
|
1582 default: |
|
1583 if (in_comment) |
|
1584 { |
3802
|
1585 comment_buf += static_cast<char> (c); |
3665
|
1586 beginning_of_comment = false; |
|
1587 } |
|
1588 break; |
|
1589 } |
|
1590 } |
|
1591 |
|
1592 if (! comment_buf.empty ()) |
|
1593 octave_comment_buffer::append (comment_buf); |
|
1594 } |
|
1595 |
1001
|
1596 // Discard whitespace, including comments and continuations. |
1088
|
1597 // |
|
1598 // Return value is logical OR of the following values: |
|
1599 // |
1826
|
1600 // ATE_NOTHING : no spaces to eat |
1088
|
1601 // ATE_SPACE_OR_TAB : space or tab in input |
|
1602 // ATE_NEWLINE : bare new line in input |
1001
|
1603 |
1826
|
1604 static yum_yum |
975
|
1605 eat_whitespace (void) |
|
1606 { |
1826
|
1607 yum_yum retval = ATE_NOTHING; |
3665
|
1608 |
|
1609 std::string comment_buf; |
|
1610 |
2857
|
1611 bool in_comment = false; |
3665
|
1612 bool beginning_of_comment = false; |
|
1613 |
|
1614 int c = 0; |
|
1615 |
975
|
1616 while ((c = yyinput ()) != EOF) |
|
1617 { |
|
1618 current_input_column++; |
|
1619 |
|
1620 switch (c) |
|
1621 { |
|
1622 case ' ': |
|
1623 case '\t': |
3665
|
1624 if (in_comment) |
|
1625 { |
3802
|
1626 comment_buf += static_cast<char> (c); |
3665
|
1627 beginning_of_comment = false; |
|
1628 } |
1088
|
1629 retval |= ATE_SPACE_OR_TAB; |
975
|
1630 break; |
|
1631 |
|
1632 case '\n': |
1088
|
1633 retval |= ATE_NEWLINE; |
3665
|
1634 if (in_comment) |
|
1635 { |
3802
|
1636 comment_buf += static_cast<char> (c); |
3665
|
1637 octave_comment_buffer::append (comment_buf); |
|
1638 comment_buf.resize (0); |
|
1639 in_comment = false; |
|
1640 beginning_of_comment = false; |
|
1641 } |
975
|
1642 current_input_column = 0; |
|
1643 break; |
|
1644 |
|
1645 case '#': |
|
1646 case '%': |
3665
|
1647 if (in_comment) |
|
1648 { |
|
1649 if (! beginning_of_comment) |
3802
|
1650 comment_buf += static_cast<char> (c); |
3665
|
1651 } |
|
1652 else |
|
1653 { |
4037
|
1654 maybe_gripe_matlab_incompatible_comment (c); |
3665
|
1655 in_comment = true; |
|
1656 beginning_of_comment = true; |
|
1657 } |
975
|
1658 break; |
|
1659 |
1001
|
1660 case '.': |
|
1661 if (in_comment) |
3665
|
1662 { |
3802
|
1663 comment_buf += static_cast<char> (c); |
3665
|
1664 beginning_of_comment = false; |
|
1665 break; |
|
1666 } |
1001
|
1667 else |
|
1668 { |
|
1669 if (have_ellipsis_continuation ()) |
|
1670 break; |
|
1671 else |
|
1672 goto done; |
|
1673 } |
|
1674 |
|
1675 case '\\': |
|
1676 if (in_comment) |
3665
|
1677 { |
3802
|
1678 comment_buf += static_cast<char> (c); |
3665
|
1679 beginning_of_comment = false; |
|
1680 break; |
|
1681 } |
1001
|
1682 else |
|
1683 { |
3105
|
1684 if (have_continuation ()) |
1001
|
1685 break; |
|
1686 else |
|
1687 goto done; |
|
1688 } |
|
1689 |
975
|
1690 default: |
|
1691 if (in_comment) |
3665
|
1692 { |
3802
|
1693 comment_buf += static_cast<char> (c); |
3665
|
1694 beginning_of_comment = false; |
|
1695 break; |
|
1696 } |
975
|
1697 else |
|
1698 goto done; |
|
1699 } |
|
1700 } |
|
1701 |
3665
|
1702 if (! comment_buf.empty ()) |
|
1703 octave_comment_buffer::append (comment_buf); |
|
1704 |
975
|
1705 done: |
4410
|
1706 yyunput (c, yytext); |
1082
|
1707 current_input_column--; |
1001
|
1708 return retval; |
975
|
1709 } |
|
1710 |
3220
|
1711 static inline bool |
|
1712 looks_like_hex (const char *s, int len) |
|
1713 { |
|
1714 return (len > 2 && s[0] == '0' && (s[1] == 'x' || s[1] == 'X')); |
|
1715 } |
|
1716 |
975
|
1717 static void |
3246
|
1718 handle_number (void) |
972
|
1719 { |
3220
|
1720 double value = 0.0; |
|
1721 int nread = 0; |
|
1722 |
3598
|
1723 if (looks_like_hex (yytext, strlen (yytext))) |
3220
|
1724 { |
|
1725 unsigned long ival; |
3598
|
1726 |
|
1727 nread = sscanf (yytext, "%lx", &ival); |
|
1728 |
3220
|
1729 value = static_cast<double> (ival); |
|
1730 } |
|
1731 else |
3598
|
1732 { |
|
1733 char *tmp = strsave (yytext); |
|
1734 |
|
1735 char *idx = strpbrk (tmp, "Dd"); |
2621
|
1736 |
3598
|
1737 if (idx) |
|
1738 *idx = 'e'; |
|
1739 |
|
1740 nread = sscanf (tmp, "%lf", &value); |
|
1741 |
|
1742 delete [] tmp; |
|
1743 } |
972
|
1744 |
1826
|
1745 // If yytext doesn't contain a valid number, we are in deep doo doo. |
985
|
1746 |
972
|
1747 assert (nread == 1); |
|
1748 |
3988
|
1749 lexer_flags.quote_is_transpose = true; |
|
1750 lexer_flags.convert_spaces_to_comma = true; |
972
|
1751 |
|
1752 yylval.tok_val = new token (value, yytext, input_line_number, |
|
1753 current_input_column); |
|
1754 |
|
1755 token_stack.push (yylval.tok_val); |
|
1756 |
|
1757 current_input_column += yyleng; |
|
1758 |
|
1759 do_comma_insert_check (); |
|
1760 } |
|
1761 |
1001
|
1762 // We have seen a backslash and need to find out if it should be |
|
1763 // treated as a continuation character. If so, this eats it, up to |
|
1764 // and including the new line character. |
|
1765 // |
973
|
1766 // Match whitespace only, followed by a comment character or newline. |
|
1767 // Once a comment character is found, discard all input until newline. |
|
1768 // If non-whitespace characters are found before comment |
|
1769 // characters, return 0. Otherwise, return 1. |
|
1770 |
2857
|
1771 static bool |
3096
|
1772 have_continuation (bool trailing_comments_ok) |
973
|
1773 { |
4051
|
1774 OSSTREAM buf; |
973
|
1775 |
3665
|
1776 std::string comment_buf; |
|
1777 |
2857
|
1778 bool in_comment = false; |
3665
|
1779 bool beginning_of_comment = false; |
|
1780 |
|
1781 int c = 0; |
|
1782 |
973
|
1783 while ((c = yyinput ()) != EOF) |
|
1784 { |
3802
|
1785 buf << static_cast<char> (c); |
973
|
1786 |
|
1787 switch (c) |
|
1788 { |
|
1789 case ' ': |
|
1790 case '\t': |
3665
|
1791 if (in_comment) |
|
1792 { |
3802
|
1793 comment_buf += static_cast<char> (c); |
3665
|
1794 beginning_of_comment = false; |
|
1795 } |
973
|
1796 break; |
|
1797 |
|
1798 case '%': |
|
1799 case '#': |
1091
|
1800 if (trailing_comments_ok) |
3665
|
1801 { |
|
1802 if (in_comment) |
|
1803 { |
|
1804 if (! beginning_of_comment) |
3802
|
1805 comment_buf += static_cast<char> (c); |
3665
|
1806 } |
|
1807 else |
|
1808 { |
4037
|
1809 maybe_gripe_matlab_incompatible_comment (c); |
3665
|
1810 in_comment = true; |
|
1811 beginning_of_comment = true; |
|
1812 } |
|
1813 } |
1091
|
1814 else |
|
1815 goto cleanup; |
973
|
1816 break; |
|
1817 |
|
1818 case '\n': |
3665
|
1819 if (in_comment) |
|
1820 { |
3802
|
1821 comment_buf += static_cast<char> (c); |
3665
|
1822 octave_comment_buffer::append (comment_buf); |
|
1823 } |
975
|
1824 current_input_column = 0; |
1001
|
1825 promptflag--; |
4037
|
1826 gripe_matlab_incompatible_continuation (); |
2857
|
1827 return true; |
973
|
1828 |
3263
|
1829 case '\r': |
3665
|
1830 if (in_comment) |
3802
|
1831 comment_buf += static_cast<char> (c); |
3263
|
1832 c = yyinput (); |
|
1833 if (c == EOF) |
|
1834 break; |
|
1835 else if (c == '\n') |
|
1836 { |
3665
|
1837 if (in_comment) |
|
1838 { |
3802
|
1839 comment_buf += static_cast<char> (c); |
3665
|
1840 octave_comment_buffer::append (comment_buf); |
|
1841 } |
3263
|
1842 current_input_column = 0; |
|
1843 promptflag--; |
4037
|
1844 gripe_matlab_incompatible_continuation (); |
3263
|
1845 return true; |
3665
|
1846 } |
3263
|
1847 |
3802
|
1848 // Fall through... |
|
1849 |
973
|
1850 default: |
3665
|
1851 if (in_comment) |
|
1852 { |
3802
|
1853 comment_buf += static_cast<char> (c); |
3665
|
1854 beginning_of_comment = false; |
|
1855 } |
|
1856 else |
1091
|
1857 goto cleanup; |
|
1858 break; |
973
|
1859 } |
|
1860 } |
|
1861 |
4410
|
1862 yyunput (c, yytext); |
2857
|
1863 return false; |
973
|
1864 |
3096
|
1865 cleanup: |
4051
|
1866 |
|
1867 buf << OSSTREAM_ENDS; |
|
1868 std::string s = OSSTREAM_STR (buf); |
|
1869 OSSTREAM_FREEZE (buf); |
|
1870 |
|
1871 int len = s.length (); |
|
1872 while (len--) |
4410
|
1873 yyunput (s[len], yytext); |
3096
|
1874 |
2857
|
1875 return false; |
973
|
1876 } |
|
1877 |
1001
|
1878 // We have seen a `.' and need to see if it is the start of a |
|
1879 // continuation. If so, this eats it, up to and including the new |
|
1880 // line character. |
|
1881 |
2857
|
1882 static bool |
3096
|
1883 have_ellipsis_continuation (bool trailing_comments_ok) |
973
|
1884 { |
|
1885 char c1 = yyinput (); |
|
1886 if (c1 == '.') |
|
1887 { |
|
1888 char c2 = yyinput (); |
1091
|
1889 if (c2 == '.' && have_continuation (trailing_comments_ok)) |
2857
|
1890 return true; |
973
|
1891 else |
|
1892 { |
4410
|
1893 yyunput (c2, yytext); |
|
1894 yyunput (c1, yytext); |
973
|
1895 } |
|
1896 } |
|
1897 else |
4410
|
1898 yyunput (c1, yytext); |
973
|
1899 |
2857
|
1900 return false; |
973
|
1901 } |
|
1902 |
1001
|
1903 // See if we have a continuation line. If so, eat it and the leading |
|
1904 // whitespace on the next line. |
1088
|
1905 // |
|
1906 // Return value is the same as described for eat_whitespace(). |
1001
|
1907 |
1826
|
1908 static yum_yum |
1001
|
1909 eat_continuation (void) |
|
1910 { |
1826
|
1911 int retval = ATE_NOTHING; |
3665
|
1912 |
1001
|
1913 int c = yyinput (); |
3665
|
1914 |
1001
|
1915 if ((c == '.' && have_ellipsis_continuation ()) |
3105
|
1916 || (c == '\\' && have_continuation ())) |
1001
|
1917 retval = eat_whitespace (); |
|
1918 else |
4410
|
1919 yyunput (c, yytext); |
1001
|
1920 |
|
1921 return retval; |
|
1922 } |
|
1923 |
973
|
1924 static int |
975
|
1925 handle_string (char delim, int text_style) |
973
|
1926 { |
4051
|
1927 OSSTREAM buf; |
973
|
1928 |
3805
|
1929 int bos_line = input_line_number; |
|
1930 int bos_col = current_input_column; |
|
1931 |
973
|
1932 int c; |
1031
|
1933 int escape_pending = 0; |
973
|
1934 |
|
1935 while ((c = yyinput ()) != EOF) |
|
1936 { |
|
1937 current_input_column++; |
|
1938 |
3105
|
1939 if (c == '\\') |
973
|
1940 { |
1053
|
1941 if (escape_pending) |
|
1942 { |
3802
|
1943 buf << static_cast<char> (c); |
1053
|
1944 escape_pending = 0; |
|
1945 } |
|
1946 else |
|
1947 { |
3096
|
1948 if (have_continuation (false)) |
1053
|
1949 escape_pending = 0; |
|
1950 else |
|
1951 { |
3802
|
1952 buf << static_cast<char> (c); |
1053
|
1953 escape_pending = 1; |
|
1954 } |
|
1955 } |
1031
|
1956 continue; |
973
|
1957 } |
|
1958 else if (c == '.') |
|
1959 { |
3096
|
1960 if (! have_ellipsis_continuation (false)) |
3802
|
1961 buf << static_cast<char> (c); |
973
|
1962 } |
|
1963 else if (c == '\n') |
|
1964 { |
1053
|
1965 error ("unterminated string constant"); |
973
|
1966 break; |
|
1967 } |
|
1968 else if (c == delim) |
|
1969 { |
1031
|
1970 if (escape_pending) |
3802
|
1971 buf << static_cast<char> (c); |
973
|
1972 else |
|
1973 { |
|
1974 c = yyinput (); |
|
1975 if (c == delim) |
5102
|
1976 { |
|
1977 buf << static_cast<char> (c); |
|
1978 if (lexer_flags.doing_rawcommand) |
|
1979 buf << static_cast<char> (c); |
|
1980 } |
973
|
1981 else |
|
1982 { |
5102
|
1983 std::string s; |
4410
|
1984 yyunput (c, yytext); |
4051
|
1985 buf << OSSTREAM_ENDS; |
5279
|
1986 if (lexer_flags.doing_rawcommand || delim == '\'') |
5102
|
1987 s = OSSTREAM_STR (buf); |
|
1988 else |
|
1989 s = do_string_escapes (OSSTREAM_STR(buf)); |
4051
|
1990 OSSTREAM_FREEZE (buf); |
975
|
1991 |
5102
|
1992 if (text_style && lexer_flags.doing_rawcommand) |
|
1993 s = std::string (1, delim) + s + std::string (1, delim); |
975
|
1994 else |
|
1995 { |
2857
|
1996 lexer_flags.quote_is_transpose = true; |
|
1997 lexer_flags.convert_spaces_to_comma = true; |
975
|
1998 } |
|
1999 |
3805
|
2000 yylval.tok_val = new token (s, bos_line, bos_col); |
973
|
2001 token_stack.push (yylval.tok_val); |
3400
|
2002 |
4037
|
2003 if (delim == '"') |
|
2004 gripe_matlab_incompatible ("\" used as string delimiter"); |
|
2005 else if (delim == '\'') |
3400
|
2006 gripe_single_quote_string (); |
|
2007 |
5279
|
2008 return delim == '"' ? DQ_STRING : SQ_STRING; |
973
|
2009 } |
|
2010 } |
|
2011 } |
|
2012 else |
|
2013 { |
3802
|
2014 buf << static_cast<char> (c); |
973
|
2015 } |
|
2016 |
1031
|
2017 escape_pending = 0; |
973
|
2018 } |
|
2019 |
|
2020 return LEXICAL_ERROR; |
|
2021 } |
|
2022 |
3208
|
2023 static bool |
|
2024 next_token_is_assign_op (void) |
|
2025 { |
|
2026 bool retval = false; |
|
2027 |
|
2028 int c0 = yyinput (); |
|
2029 |
|
2030 switch (c0) |
|
2031 { |
|
2032 case '=': |
|
2033 { |
|
2034 int c1 = yyinput (); |
4410
|
2035 yyunput (c1, yytext); |
3208
|
2036 if (c1 != '=') |
|
2037 retval = true; |
|
2038 } |
|
2039 break; |
|
2040 |
|
2041 case '+': |
|
2042 case '-': |
|
2043 case '*': |
|
2044 case '/': |
|
2045 case '\\': |
|
2046 case '&': |
|
2047 case '|': |
|
2048 { |
|
2049 int c1 = yyinput (); |
4410
|
2050 yyunput (c1, yytext); |
3208
|
2051 if (c1 == '=') |
|
2052 retval = true; |
|
2053 } |
|
2054 break; |
|
2055 |
|
2056 case '.': |
|
2057 { |
|
2058 int c1 = yyinput (); |
|
2059 if (match_any (c1, "+-*/\\")) |
|
2060 { |
|
2061 int c2 = yyinput (); |
4410
|
2062 yyunput (c2, yytext); |
3208
|
2063 if (c2 == '=') |
|
2064 retval = true; |
|
2065 } |
4410
|
2066 yyunput (c1, yytext); |
3208
|
2067 } |
|
2068 break; |
|
2069 |
|
2070 case '>': |
|
2071 { |
|
2072 int c1 = yyinput (); |
|
2073 if (c1 == '>') |
|
2074 { |
|
2075 int c2 = yyinput (); |
4410
|
2076 yyunput (c2, yytext); |
3208
|
2077 if (c2 == '=') |
|
2078 retval = true; |
|
2079 } |
4410
|
2080 yyunput (c1, yytext); |
3208
|
2081 } |
|
2082 break; |
|
2083 |
|
2084 case '<': |
|
2085 { |
|
2086 int c1 = yyinput (); |
|
2087 if (c1 == '<') |
|
2088 { |
|
2089 int c2 = yyinput (); |
4410
|
2090 yyunput (c2, yytext); |
3208
|
2091 if (c2 == '=') |
|
2092 retval = true; |
|
2093 } |
4410
|
2094 yyunput (c1, yytext); |
3208
|
2095 } |
|
2096 break; |
|
2097 |
|
2098 default: |
|
2099 break; |
|
2100 } |
|
2101 |
4410
|
2102 yyunput (c0, yytext); |
3208
|
2103 |
|
2104 return retval; |
|
2105 } |
|
2106 |
4633
|
2107 static bool |
|
2108 next_token_is_index_op (void) |
|
2109 { |
|
2110 int c = yyinput (); |
|
2111 yyunput (c, yytext); |
|
2112 return c == '(' || c == '{'; |
|
2113 } |
|
2114 |
4612
|
2115 static int |
|
2116 handle_close_bracket (bool spc_gobbled, int bracket_type) |
971
|
2117 { |
4612
|
2118 int retval = bracket_type; |
3208
|
2119 |
1826
|
2120 if (! nesting_level.none ()) |
971
|
2121 { |
1826
|
2122 nesting_level.remove (); |
4613
|
2123 |
|
2124 if (bracket_type == ']') |
|
2125 lexer_flags.bracketflag--; |
|
2126 else if (bracket_type == '}') |
|
2127 lexer_flags.braceflag--; |
|
2128 else |
|
2129 panic_impossible (); |
971
|
2130 } |
|
2131 |
4613
|
2132 if (lexer_flags.bracketflag == 0 && lexer_flags.braceflag == 0) |
4323
|
2133 BEGIN (INITIAL); |
1001
|
2134 |
4608
|
2135 if (bracket_type == ']' |
|
2136 && next_token_is_assign_op () |
|
2137 && ! lexer_flags.looking_at_return_list) |
971
|
2138 { |
3208
|
2139 retval = CLOSE_BRACE; |
971
|
2140 } |
4613
|
2141 else if ((lexer_flags.bracketflag || lexer_flags.braceflag) |
|
2142 && lexer_flags.convert_spaces_to_comma |
|
2143 && (nesting_level.is_bracket () |
|
2144 || (nesting_level.is_brace () |
|
2145 && ! lexer_flags.looking_at_object_index))) |
971
|
2146 { |
4633
|
2147 bool index_op = next_token_is_index_op (); |
|
2148 |
|
2149 // Don't insert comma if we are looking at something like |
|
2150 // |
|
2151 // [x{i}{j}] or [x{i}(j)] |
|
2152 // |
|
2153 // but do if we are looking at |
|
2154 // |
|
2155 // [x{i} {j}] or [x{i} (j)] |
|
2156 |
|
2157 if (spc_gobbled || ! (bracket_type == '}' && index_op)) |
971
|
2158 { |
4633
|
2159 bool bin_op = next_token_is_bin_op (spc_gobbled); |
|
2160 |
|
2161 bool postfix_un_op = next_token_is_postfix_unary_op (spc_gobbled); |
|
2162 |
|
2163 bool sep_op = next_token_is_sep_op (); |
|
2164 |
|
2165 if (! (postfix_un_op || bin_op || sep_op)) |
|
2166 { |
|
2167 maybe_warn_separator_insert (','); |
|
2168 |
|
2169 yyunput (',', yytext); |
|
2170 return retval; |
|
2171 } |
971
|
2172 } |
|
2173 } |
|
2174 |
2857
|
2175 lexer_flags.quote_is_transpose = true; |
|
2176 lexer_flags.convert_spaces_to_comma = true; |
3208
|
2177 |
|
2178 return retval; |
971
|
2179 } |
|
2180 |
1072
|
2181 static void |
|
2182 maybe_unput_comma (int spc_gobbled) |
|
2183 { |
4613
|
2184 if (nesting_level.is_bracket () |
|
2185 || (nesting_level.is_brace () |
|
2186 && ! lexer_flags.looking_at_object_index)) |
1072
|
2187 { |
3246
|
2188 int bin_op = next_token_is_bin_op (spc_gobbled); |
1072
|
2189 |
3246
|
2190 int postfix_un_op = next_token_is_postfix_unary_op (spc_gobbled); |
1072
|
2191 |
|
2192 int c1 = yyinput (); |
|
2193 int c2 = yyinput (); |
2970
|
2194 |
4410
|
2195 yyunput (c2, yytext); |
|
2196 yyunput (c1, yytext); |
2970
|
2197 |
3263
|
2198 int sep_op = next_token_is_sep_op (); |
2970
|
2199 |
1072
|
2200 int dot_op = (c1 == '.' |
|
2201 && (isalpha (c2) || isspace (c2) || c2 == '_')); |
2970
|
2202 |
3388
|
2203 if (postfix_un_op || bin_op || sep_op || dot_op) |
|
2204 return; |
|
2205 |
3985
|
2206 int index_op = (c1 == '(' || c1 == '{'); |
3388
|
2207 |
4476
|
2208 // If there is no space before the indexing op, we don't insert |
|
2209 // a comma. |
|
2210 |
|
2211 if (index_op && ! spc_gobbled) |
|
2212 return; |
|
2213 |
|
2214 maybe_warn_separator_insert (','); |
|
2215 |
|
2216 yyunput (',', yytext); |
1072
|
2217 } |
|
2218 } |
|
2219 |
767
|
2220 // Figure out exactly what kind of token to return when we have seen |
4238
|
2221 // an identifier. Handles keywords. Return -1 if the identifier |
|
2222 // should be ignored. |
767
|
2223 |
146
|
2224 static int |
3974
|
2225 handle_identifier (void) |
146
|
2226 { |
3974
|
2227 std::string tok = strip_trailing_whitespace (yytext); |
|
2228 |
|
2229 int c = yytext[yyleng-1]; |
|
2230 |
|
2231 int cont_is_spc = eat_continuation (); |
|
2232 |
|
2233 int spc_gobbled = (cont_is_spc || c == ' ' || c == '\t'); |
|
2234 |
2970
|
2235 // If we are expecting a structure element, avoid recognizing |
|
2236 // keywords and other special names and return STRUCT_ELT, which is |
|
2237 // a string that is also a valid identifier. But first, we have to |
|
2238 // decide whether to insert a comma. |
747
|
2239 |
1826
|
2240 if (lexer_flags.looking_at_indirect_ref) |
1072
|
2241 { |
2970
|
2242 do_comma_insert_check (); |
|
2243 |
1072
|
2244 maybe_unput_comma (spc_gobbled); |
2819
|
2245 |
|
2246 yylval.tok_val = new token (tok, input_line_number, |
|
2247 current_input_column); |
|
2248 |
|
2249 token_stack.push (yylval.tok_val); |
|
2250 |
2857
|
2251 lexer_flags.quote_is_transpose = true; |
|
2252 lexer_flags.convert_spaces_to_comma = true; |
2819
|
2253 |
|
2254 current_input_column += yyleng; |
|
2255 |
2970
|
2256 return STRUCT_ELT; |
1072
|
2257 } |
747
|
2258 |
4930
|
2259 int kw_token = is_keyword_token (tok); |
|
2260 |
|
2261 if (lexer_flags.looking_at_function_handle) |
|
2262 { |
|
2263 if (kw_token) |
|
2264 { |
|
2265 error ("function handles may not refer to keywords"); |
|
2266 |
|
2267 return LEXICAL_ERROR; |
|
2268 } |
|
2269 else |
|
2270 TOK_PUSH_AND_RETURN (tok, FCN_HANDLE); |
|
2271 } |
|
2272 |
5102
|
2273 // If we have a regular keyword, return it. |
1826
|
2274 // Keywords can be followed by identifiers (TOK_RETURN handles |
|
2275 // that). |
146
|
2276 |
|
2277 if (kw_token) |
|
2278 { |
4238
|
2279 if (kw_token < 0) |
|
2280 return kw_token; |
146
|
2281 else |
|
2282 TOK_RETURN (kw_token); |
|
2283 } |
|
2284 |
1826
|
2285 // See if we have a plot keyword (title, using, with, or clear). |
146
|
2286 |
3480
|
2287 int c1 = yyinput (); |
|
2288 |
|
2289 bool next_tok_is_paren = (c1 == '('); |
|
2290 |
|
2291 bool next_tok_is_eq = false; |
|
2292 if (c1 == '=') |
|
2293 { |
|
2294 int c2 = yyinput (); |
4410
|
2295 yyunput (c2, yytext); |
3480
|
2296 |
|
2297 if (c2 != '=') |
|
2298 next_tok_is_eq = true; |
|
2299 } |
|
2300 |
4410
|
2301 yyunput (c1, yytext); |
1001
|
2302 |
1826
|
2303 // Make sure we put the return values of a function in the symbol |
|
2304 // table that is local to the function. |
146
|
2305 |
2877
|
2306 // If we are defining a function and we have not seen the function |
|
2307 // name yet and the next token is `=', then this identifier must be |
|
2308 // the only return value for the function and it belongs in the |
|
2309 // local symbol table. |
|
2310 |
1826
|
2311 if (next_tok_is_eq |
2877
|
2312 && lexer_flags.defining_func |
|
2313 && ! lexer_flags.parsed_function_name) |
146
|
2314 curr_sym_tab = tmp_local_sym_tab; |
|
2315 |
2702
|
2316 // Kluge alert. |
|
2317 // |
|
2318 // If we are looking at a text style function, set up to gobble its |
2745
|
2319 // arguments. |
|
2320 // |
|
2321 // If the following token is `=', or if we are parsing a function |
3189
|
2322 // return list or function parameter list, or if we are looking at |
|
2323 // something like [ab,cd] = foo (), force the symbol to be inserted |
|
2324 // as a variable in the current symbol table. |
2702
|
2325 |
4208
|
2326 if (is_command_name (tok) && ! is_variable (tok)) |
2702
|
2327 { |
2745
|
2328 if (next_tok_is_eq |
|
2329 || lexer_flags.looking_at_return_list |
3189
|
2330 || lexer_flags.looking_at_parameter_list |
4101
|
2331 || lexer_flags.looking_at_matrix_or_assign_lhs) |
2745
|
2332 { |
|
2333 force_local_variable (tok); |
|
2334 } |
2702
|
2335 else if (! next_tok_is_paren) |
|
2336 { |
5102
|
2337 BEGIN (COMMAND_START); |
|
2338 } |
|
2339 |
|
2340 if (is_rawcommand_name (tok)) |
|
2341 { |
|
2342 lexer_flags.doing_rawcommand = true; |
4323
|
2343 BEGIN (COMMAND_START); |
2702
|
2344 } |
|
2345 } |
|
2346 |
4234
|
2347 // Find the token in the symbol table. Beware the magic |
|
2348 // transformation of the end keyword... |
|
2349 |
|
2350 if (tok == "end") |
|
2351 tok = "__end__"; |
146
|
2352 |
|
2353 yylval.tok_val = new token (lookup_identifier (tok), |
|
2354 input_line_number, |
|
2355 current_input_column); |
|
2356 |
|
2357 token_stack.push (yylval.tok_val); |
|
2358 |
1826
|
2359 // After seeing an identifer, it is ok to convert spaces to a comma |
|
2360 // (if needed). |
146
|
2361 |
2857
|
2362 lexer_flags.convert_spaces_to_comma = true; |
146
|
2363 |
2877
|
2364 if (! next_tok_is_eq) |
|
2365 { |
|
2366 lexer_flags.quote_is_transpose = true; |
146
|
2367 |
2877
|
2368 do_comma_insert_check (); |
|
2369 |
|
2370 maybe_unput_comma (spc_gobbled); |
146
|
2371 } |
|
2372 |
2877
|
2373 current_input_column += yyleng; |
146
|
2374 |
|
2375 return NAME; |
|
2376 } |
|
2377 |
1826
|
2378 void |
|
2379 lexical_feedback::init (void) |
|
2380 { |
|
2381 // Not initially defining a matrix list. |
3351
|
2382 bracketflag = 0; |
1826
|
2383 |
4613
|
2384 // Not initially defining a cell array list. |
|
2385 braceflag = 0; |
|
2386 |
1826
|
2387 // Not initially inside a loop or if statement. |
|
2388 looping = 0; |
|
2389 |
2857
|
2390 // Not initially defining a function. |
|
2391 beginning_of_function = false; |
|
2392 defining_func = false; |
2877
|
2393 parsed_function_name = false; |
4240
|
2394 parsing_nested_function = 0; |
2857
|
2395 |
4930
|
2396 // Not initiallly looking at a function handle. |
|
2397 looking_at_function_handle = 0; |
|
2398 |
2857
|
2399 // Not parsing a function return or parameter list. |
|
2400 looking_at_return_list = false; |
|
2401 looking_at_parameter_list = false; |
|
2402 |
3796
|
2403 // Not parsing a matrix or the left hand side of multi-value |
|
2404 // assignment statement. |
|
2405 looking_at_matrix_or_assign_lhs = false; |
|
2406 |
4234
|
2407 // Not parsing an object index. |
4237
|
2408 looking_at_object_index = 0; |
4234
|
2409 |
2857
|
2410 // No need to do comma insert or convert spaces to comma at |
|
2411 // beginning of input. |
|
2412 convert_spaces_to_comma = true; |
|
2413 do_comma_insert = false; |
|
2414 |
|
2415 // Not initially doing any plotting or setting of plot attributes. |
5102
|
2416 doing_rawcommand = false; |
2857
|
2417 |
1826
|
2418 // Not initially looking at indirect references. |
2857
|
2419 looking_at_indirect_ref = false; |
1826
|
2420 |
|
2421 // Quote marks strings intially. |
2857
|
2422 quote_is_transpose = false; |
1826
|
2423 } |
|
2424 |
4867
|
2425 bool |
|
2426 is_keyword (const std::string& s) |
|
2427 { |
5088
|
2428 return octave_kw_hash::in_word_set (s.c_str (), s.length ()) != 0; |
4867
|
2429 } |
|
2430 |
4264
|
2431 DEFCMD (iskeyword, args, , |
|
2432 "-*- texinfo -*-\n\ |
|
2433 @deftypefn {Built-in Function} {} iskeyword (@var{name})\n\ |
|
2434 Return true if @var{name} is an Octave keyword. If @var{name}\n\ |
|
2435 is omitted, return a list of keywords.\n\ |
|
2436 @end deftypefn") |
|
2437 { |
|
2438 octave_value retval; |
|
2439 |
|
2440 int argc = args.length () + 1; |
|
2441 |
4867
|
2442 string_vector argv = args.make_argv ("iskeyword"); |
4264
|
2443 |
|
2444 if (error_state) |
|
2445 return retval; |
|
2446 |
|
2447 if (argc == 1) |
|
2448 { |
|
2449 string_vector lst (TOTAL_KEYWORDS); |
|
2450 |
|
2451 for (int i = 0; i < TOTAL_KEYWORDS; i++) |
|
2452 lst[i] = wordlist[i].name; |
|
2453 |
|
2454 retval = Cell (lst.qsort ()); |
|
2455 } |
|
2456 else if (argc == 2) |
|
2457 { |
4867
|
2458 retval = is_keyword (argv[1]); |
4264
|
2459 } |
|
2460 else |
|
2461 print_usage ("iskeyword"); |
|
2462 |
|
2463 return retval; |
|
2464 } |
|
2465 |
|
2466 |
3388
|
2467 static void |
|
2468 maybe_warn_separator_insert (char sep) |
|
2469 { |
3523
|
2470 std::string nm = curr_fcn_file_full_name; |
3388
|
2471 |
|
2472 if (Vwarn_separator_insert) |
|
2473 { |
|
2474 if (nm.empty ()) |
|
2475 warning ("potential auto-insertion of `%c' near line %d", |
|
2476 sep, input_line_number); |
|
2477 else |
|
2478 warning ("potential auto-insertion of `%c' near line %d of file %s", |
|
2479 sep, input_line_number, nm.c_str ()); |
|
2480 } |
|
2481 } |
|
2482 |
3400
|
2483 static void |
|
2484 gripe_single_quote_string (void) |
|
2485 { |
3523
|
2486 std::string nm = curr_fcn_file_full_name; |
3400
|
2487 |
|
2488 if (Vwarn_single_quote_string) |
|
2489 { |
|
2490 if (nm.empty ()) |
|
2491 warning ("single quote delimited string near line %d", |
|
2492 input_line_number); |
|
2493 else |
|
2494 warning ("single quote delimited string near line %d of file %s", |
|
2495 input_line_number, nm.c_str ()); |
|
2496 } |
|
2497 } |
|
2498 |
4037
|
2499 static void |
|
2500 gripe_matlab_incompatible (const std::string& msg) |
|
2501 { |
|
2502 if (Vwarn_matlab_incompatible) |
|
2503 warning ("potential Matlab compatibility problem: %s", msg.c_str ()); |
|
2504 } |
|
2505 |
|
2506 static void |
|
2507 maybe_gripe_matlab_incompatible_comment (char c) |
|
2508 { |
|
2509 if (c == '#') |
|
2510 gripe_matlab_incompatible ("# used as comment character"); |
|
2511 } |
|
2512 |
|
2513 static void |
|
2514 gripe_matlab_incompatible_continuation (void) |
|
2515 { |
|
2516 gripe_matlab_incompatible ("\\ used as line continuation marker"); |
|
2517 } |
|
2518 |
|
2519 static void |
|
2520 gripe_matlab_incompatible_operator (const std::string& op) |
|
2521 { |
|
2522 std::string t = op; |
|
2523 int n = t.length (); |
|
2524 if (t[n-1] == '\n') |
|
2525 t.resize (n-1); |
|
2526 gripe_matlab_incompatible (t + " used as operator"); |
|
2527 } |
|
2528 |
4910
|
2529 DEFUN (__token_count__, , , |
|
2530 "-*- texinfo -*-\n\ |
|
2531 @deftypefn {Built-in Function} {} __token_count__\n\ |
|
2532 Number of language tokens processed since Octave startup.\n\ |
|
2533 @end deftypefn") |
|
2534 { |
|
2535 return octave_value (Vtoken_count); |
|
2536 } |
|
2537 |
4037
|
2538 static int |
|
2539 warn_matlab_incompatible (void) |
|
2540 { |
|
2541 Vwarn_matlab_incompatible = check_preference ("warn_matlab_incompatible"); |
|
2542 |
|
2543 return 0; |
|
2544 } |
|
2545 |
3388
|
2546 static int |
|
2547 warn_separator_insert (void) |
|
2548 { |
|
2549 Vwarn_separator_insert = check_preference ("warn_separator_insert"); |
|
2550 |
|
2551 return 0; |
|
2552 } |
|
2553 |
3246
|
2554 static int |
3400
|
2555 warn_single_quote_string (void) |
|
2556 { |
|
2557 Vwarn_single_quote_string = check_preference ("warn_single_quote_string"); |
|
2558 |
|
2559 return 0; |
|
2560 } |
|
2561 |
2167
|
2562 void |
|
2563 symbols_of_lex (void) |
|
2564 { |
4233
|
2565 DEFVAR (warn_matlab_incompatible, false, warn_matlab_incompatible, |
4037
|
2566 "-*- texinfo -*-\n\ |
|
2567 @defvr {Built-in Variable} warn_matlab_incompatible\n\ |
|
2568 Print warnings for Octave language features that may cause\n\ |
|
2569 compatibility problems with Matlab.\n\ |
|
2570 @end defvr"); |
|
2571 |
4233
|
2572 DEFVAR (warn_separator_insert, false, warn_separator_insert, |
3428
|
2573 "-*- texinfo -*-\n\ |
|
2574 @defvr {Built-in Variable} warn_separator_insert\n\ |
3567
|
2575 Print warning if commas or semicolons might be inserted\n\ |
3428
|
2576 automatically in literal matrices.\n\ |
|
2577 @end defvr"); |
3388
|
2578 |
4233
|
2579 DEFVAR (warn_single_quote_string, false, warn_single_quote_string, |
3428
|
2580 "-*- texinfo -*-\n\ |
|
2581 @defvr {Built-in Variable} warn_single_quote_string\n\ |
|
2582 Print warning if a signle quote character is used to introduce a\n\ |
|
2583 string constant.\n\ |
|
2584 @end defvr"); |
2167
|
2585 } |
|
2586 |
1994
|
2587 /* |
|
2588 ;;; Local Variables: *** |
|
2589 ;;; mode: C++ *** |
|
2590 ;;; End: *** |
|
2591 */ |