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