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 // An ellipsis not at the end of a line is not a continuation, but |
|
544 // does have another meaning. |
|
545 %} |
|
546 |
967
|
547 {EL} { |
3973
|
548 if (lexer_flags.looking_at_parameter_list) |
3974
|
549 { |
|
550 warning ("`...' is deprecated; use varargin instead"); |
4910
|
551 COUNT_TOK_AND_RETURN (VARARGIN); |
3974
|
552 } |
3973
|
553 else if (lexer_flags.looking_at_return_list) |
3974
|
554 { |
|
555 warning ("`...' is deprecated; use varargout instead"); |
4910
|
556 COUNT_TOK_AND_RETURN (VARARGOUT); |
3974
|
557 } |
3973
|
558 else |
|
559 return LEXICAL_ERROR; |
967
|
560 } |
1
|
561 |
968
|
562 %{ |
|
563 // End of file. |
|
564 %} |
|
565 |
967
|
566 <<EOF>> { |
|
567 TOK_RETURN (END_OF_INPUT); |
|
568 } |
1
|
569 |
968
|
570 %{ |
970
|
571 // Identifiers. Truncate the token at the first space or tab but |
|
572 // don't write directly on yytext. |
968
|
573 %} |
|
574 |
967
|
575 {IDENT}{S}* { |
4238
|
576 int id_tok = handle_identifier (); |
|
577 |
|
578 if (id_tok >= 0) |
4910
|
579 COUNT_TOK_AND_RETURN (id_tok); |
967
|
580 } |
1
|
581 |
968
|
582 %{ |
4342
|
583 // Function handles. |
|
584 %} |
|
585 |
4930
|
586 "@" { |
|
587 current_input_column++; |
|
588 lexer_flags.quote_is_transpose = false; |
|
589 lexer_flags.convert_spaces_to_comma = false; |
|
590 lexer_flags.looking_at_function_handle++; |
|
591 COUNT_TOK_AND_RETURN ('@'); |
4342
|
592 } |
|
593 |
|
594 %{ |
968
|
595 // A new line character. New line characters inside matrix constants |
4208
|
596 // are handled by the <MATRIX_START> start state code above. If closest |
985
|
597 // nesting is inside parentheses, don't return a row separator. |
968
|
598 %} |
|
599 |
967
|
600 {NL} { |
|
601 current_input_column = 1; |
2857
|
602 lexer_flags.quote_is_transpose = false; |
|
603 lexer_flags.convert_spaces_to_comma = true; |
1826
|
604 if (nesting_level.none ()) |
4910
|
605 COUNT_TOK_AND_RETURN ('\n'); |
4037
|
606 else if (nesting_level.is_paren ()) |
|
607 gripe_matlab_incompatible ("bare newline inside parentheses"); |
4608
|
608 else if (nesting_level.is_bracket_or_brace ()) |
985
|
609 return LEXICAL_ERROR; |
967
|
610 } |
1
|
611 |
968
|
612 %{ |
|
613 // Single quote can either be the beginning of a string or a transpose |
|
614 // operator. |
|
615 %} |
|
616 |
967
|
617 "'" { |
|
618 current_input_column++; |
2857
|
619 lexer_flags.convert_spaces_to_comma = true; |
1
|
620 |
1826
|
621 if (lexer_flags.quote_is_transpose) |
967
|
622 { |
|
623 do_comma_insert_check (); |
4910
|
624 COUNT_TOK_AND_RETURN (QUOTE); |
967
|
625 } |
|
626 else |
4910
|
627 COUNT_TOK_AND_RETURN (handle_string ('\'')); |
967
|
628 } |
1
|
629 |
968
|
630 %{ |
971
|
631 // Double quotes always begin strings. |
|
632 %} |
|
633 |
973
|
634 \" { |
|
635 current_input_column++; |
4910
|
636 COUNT_TOK_AND_RETURN (handle_string ('"')); |
973
|
637 } |
971
|
638 |
|
639 %{ |
985
|
640 // Gobble comments. If closest nesting is inside parentheses, don't |
|
641 // return a new line. |
|
642 %} |
968
|
643 |
967
|
644 {CCHAR} { |
4426
|
645 std::string help_txt; |
|
646 |
|
647 if (! help_buf.empty ()) |
|
648 help_txt = help_buf.top (); |
|
649 |
|
650 if (help_txt.empty () |
1826
|
651 && lexer_flags.beginning_of_function |
|
652 && nesting_level.none ()) |
967
|
653 { |
3665
|
654 lexer_flags.beginning_of_function = false; |
|
655 |
4426
|
656 std::string txt = grab_help_text (); |
|
657 |
|
658 if (! help_buf.empty ()) |
|
659 help_buf.pop (); |
|
660 |
|
661 help_buf.push (txt); |
|
662 |
|
663 octave_comment_buffer::append (txt); |
967
|
664 } |
|
665 else |
|
666 { |
3665
|
667 std::string buf; |
|
668 |
|
669 bool begin_comment = true; |
|
670 |
967
|
671 int c; |
|
672 while ((c = yyinput ()) != EOF && c != '\n') |
3665
|
673 { |
|
674 if (begin_comment && (c == '#' || c == '%')) |
|
675 ; /* Skip leading comment characters. */ |
|
676 else |
3802
|
677 buf += static_cast<char> (c); |
3665
|
678 } |
|
679 |
|
680 octave_comment_buffer::append (buf); |
967
|
681 } |
440
|
682 |
967
|
683 current_input_column = 1; |
2857
|
684 lexer_flags.quote_is_transpose = false; |
|
685 lexer_flags.convert_spaces_to_comma = true; |
985
|
686 |
4037
|
687 maybe_gripe_matlab_incompatible_comment (yytext[0]); |
|
688 |
4323
|
689 if (YY_START == COMMAND_START) |
|
690 BEGIN (INITIAL); |
|
691 |
1826
|
692 if (nesting_level.none ()) |
5783
|
693 { |
|
694 lexer_flags.doing_rawcommand = false; |
|
695 COUNT_TOK_AND_RETURN ('\n'); |
|
696 } |
4608
|
697 else if (nesting_level.is_bracket_or_brace ()) |
4910
|
698 COUNT_TOK_AND_RETURN (';'); |
967
|
699 } |
440
|
700 |
968
|
701 %{ |
|
702 // Other operators. |
|
703 %} |
|
704 |
5102
|
705 ":" { BIN_OP_RETURN (':', false); } |
|
706 |
4037
|
707 ".+" { XBIN_OP_RETURN (EPLUS, false); } |
|
708 ".-" { XBIN_OP_RETURN (EMINUS, false); } |
2857
|
709 ".*" { BIN_OP_RETURN (EMUL, false); } |
|
710 "./" { BIN_OP_RETURN (EDIV, false); } |
|
711 ".\\" { BIN_OP_RETURN (ELEFTDIV, false); } |
4037
|
712 ".^" { BIN_OP_RETURN (EPOW, false); } |
|
713 ".**" { XBIN_OP_RETURN (EPOW, false); } |
2857
|
714 ".'" { do_comma_insert_check (); BIN_OP_RETURN (TRANSPOSE, true); } |
4037
|
715 "++" { do_comma_insert_check (); XBIN_OP_RETURN (PLUS_PLUS, true); } |
|
716 "--" { do_comma_insert_check (); XBIN_OP_RETURN (MINUS_MINUS, true); } |
2857
|
717 "<=" { BIN_OP_RETURN (EXPR_LE, false); } |
|
718 "==" { BIN_OP_RETURN (EXPR_EQ, false); } |
4037
|
719 "~=" { BIN_OP_RETURN (EXPR_NE, false); } |
|
720 "!=" { XBIN_OP_RETURN (EXPR_NE, false); } |
2857
|
721 ">=" { BIN_OP_RETURN (EXPR_GE, false); } |
2877
|
722 "&" { BIN_OP_RETURN (EXPR_AND, false); } |
2857
|
723 "|" { BIN_OP_RETURN (EXPR_OR, false); } |
|
724 "<" { BIN_OP_RETURN (EXPR_LT, false); } |
|
725 ">" { BIN_OP_RETURN (EXPR_GT, false); } |
5102
|
726 "+" { BIN_OP_RETURN ('+', false); } |
|
727 "-" { BIN_OP_RETURN ('-', false); } |
2857
|
728 "*" { BIN_OP_RETURN ('*', false); } |
|
729 "/" { BIN_OP_RETURN ('/', false); } |
|
730 "\\" { BIN_OP_RETURN (LEFTDIV, false); } |
|
731 ";" { BIN_OP_RETURN (';', true); } |
|
732 "," { BIN_OP_RETURN (',', true); } |
4037
|
733 "^" { BIN_OP_RETURN (POW, false); } |
|
734 "**" { XBIN_OP_RETURN (POW, false); } |
2857
|
735 "=" { BIN_OP_RETURN ('=', true); } |
2877
|
736 "&&" { BIN_OP_RETURN (EXPR_AND_AND, false); } |
2857
|
737 "||" { BIN_OP_RETURN (EXPR_OR_OR, false); } |
4037
|
738 "<<" { XBIN_OP_RETURN (LSHIFT, false); } |
|
739 ">>" { XBIN_OP_RETURN (RSHIFT, false); } |
967
|
740 |
|
741 {NOT} { |
4037
|
742 if (yytext[0] == '~') |
|
743 BIN_OP_RETURN (EXPR_NOT, false); |
|
744 else |
|
745 XBIN_OP_RETURN (EXPR_NOT, false); |
967
|
746 } |
1
|
747 |
967
|
748 "(" { |
4131
|
749 lexer_flags.looking_at_indirect_ref = false; |
1826
|
750 nesting_level.paren (); |
985
|
751 promptflag--; |
967
|
752 TOK_RETURN ('('); |
|
753 } |
|
754 |
|
755 ")" { |
1826
|
756 nesting_level.remove (); |
967
|
757 current_input_column++; |
2857
|
758 lexer_flags.quote_is_transpose = true; |
4608
|
759 lexer_flags.convert_spaces_to_comma = nesting_level.is_bracket_or_brace (); |
1001
|
760 do_comma_insert_check (); |
4910
|
761 COUNT_TOK_AND_RETURN (')'); |
967
|
762 } |
|
763 |
5102
|
764 "." { TOK_RETURN ('.'); } |
2066
|
765 |
4037
|
766 "+=" { XBIN_OP_RETURN (ADD_EQ, false); } |
|
767 "-=" { XBIN_OP_RETURN (SUB_EQ, false); } |
|
768 "*=" { XBIN_OP_RETURN (MUL_EQ, false); } |
|
769 "/=" { XBIN_OP_RETURN (DIV_EQ, false); } |
|
770 "\\=" { XBIN_OP_RETURN (LEFTDIV_EQ, false); } |
|
771 ".+=" { XBIN_OP_RETURN (ADD_EQ, false); } |
|
772 ".-=" { XBIN_OP_RETURN (SUB_EQ, false); } |
|
773 ".*=" { XBIN_OP_RETURN (EMUL_EQ, false); } |
|
774 "./=" { XBIN_OP_RETURN (EDIV_EQ, false); } |
|
775 ".\\=" { XBIN_OP_RETURN (ELEFTDIV_EQ, false); } |
|
776 {POW}= { XBIN_OP_RETURN (POW_EQ, false); } |
|
777 {EPOW}= { XBIN_OP_RETURN (EPOW_EQ, false); } |
|
778 "&=" { XBIN_OP_RETURN (AND_EQ, false); } |
|
779 "|=" { XBIN_OP_RETURN (OR_EQ, false); } |
|
780 "<<=" { XBIN_OP_RETURN (LSHIFT_EQ, false); } |
|
781 ">>=" { XBIN_OP_RETURN (RSHIFT_EQ, false); } |
2877
|
782 |
4608
|
783 \{{S}* { |
3351
|
784 nesting_level.brace (); |
4608
|
785 |
|
786 current_input_column += yyleng; |
|
787 lexer_flags.quote_is_transpose = false; |
|
788 lexer_flags.convert_spaces_to_comma = true; |
|
789 |
3351
|
790 promptflag--; |
4608
|
791 eat_whitespace (); |
|
792 |
4613
|
793 lexer_flags.braceflag++; |
4608
|
794 BEGIN (MATRIX_START); |
4910
|
795 COUNT_TOK_AND_RETURN ('{'); |
3351
|
796 } |
|
797 |
|
798 "}" { |
|
799 nesting_level.remove (); |
|
800 |
4608
|
801 TOK_RETURN ('}'); |
3351
|
802 } |
|
803 |
968
|
804 %{ |
2066
|
805 // Unrecognized input is a lexical error. |
968
|
806 %} |
1
|
807 |
2042
|
808 . { |
4240
|
809 // EOF happens here if we are parsing nested functions. |
|
810 |
4410
|
811 yyunput (yytext[0], yytext); |
4248
|
812 |
|
813 int c = yyinput (); |
|
814 |
|
815 if (c != EOF) |
4240
|
816 { |
|
817 current_input_column++; |
|
818 |
|
819 error ("invalid character `%s' (ASCII %d) near line %d, column %d", |
4248
|
820 undo_string_escape (static_cast<char> (c)), c, |
4240
|
821 input_line_number, current_input_column); |
|
822 |
|
823 return LEXICAL_ERROR; |
|
824 } |
|
825 else |
|
826 TOK_RETURN (END_OF_INPUT); |
2066
|
827 } |
1
|
828 |
|
829 %% |
|
830 |
767
|
831 // GAG. |
|
832 // |
|
833 // If we're reading a matrix and the next character is '[', make sure |
|
834 // that we insert a comma ahead of it. |
|
835 |
146
|
836 void |
1
|
837 do_comma_insert_check (void) |
|
838 { |
1001
|
839 int spc_gobbled = eat_continuation (); |
2970
|
840 |
1
|
841 int c = yyinput (); |
2970
|
842 |
4410
|
843 yyunput (c, yytext); |
2970
|
844 |
1001
|
845 if (spc_gobbled) |
4410
|
846 yyunput (' ', yytext); |
2970
|
847 |
3351
|
848 lexer_flags.do_comma_insert = (lexer_flags.bracketflag && c == '['); |
1
|
849 } |
|
850 |
767
|
851 // Fix things up for errors or interrupts. The parser is never called |
|
852 // recursively, so it is always safe to reinitialize its state before |
|
853 // doing any parsing. |
|
854 |
1
|
855 void |
|
856 reset_parser (void) |
|
857 { |
1826
|
858 // Start off on the right foot. |
4323
|
859 BEGIN (INITIAL); |
4318
|
860 |
3883
|
861 parser_end_of_input = false; |
4238
|
862 end_tokens_expected = 0; |
|
863 |
|
864 while (! symtab_context.empty ()) |
|
865 symtab_context.pop (); |
287
|
866 |
1826
|
867 // We do want a prompt by default. |
1
|
868 promptflag = 1; |
287
|
869 |
3351
|
870 // Error may have occurred inside some brackets, braces, or parentheses. |
985
|
871 nesting_level.clear (); |
287
|
872 |
1826
|
873 // Clear out the stack of token info used to track line and column |
|
874 // numbers. |
143
|
875 while (! token_stack.empty ()) |
4214
|
876 { |
|
877 delete token_stack.top (); |
|
878 token_stack.pop (); |
|
879 } |
287
|
880 |
1826
|
881 // Can be reset by defining a function. |
985
|
882 if (! (reading_script_file || reading_fcn_file)) |
|
883 { |
|
884 current_input_column = 1; |
2926
|
885 input_line_number = command_editor::current_command_number () - 1; |
985
|
886 } |
287
|
887 |
1826
|
888 // Only ask for input from stdin if we are expecting interactive |
|
889 // input. |
3174
|
890 if ((interactive || forced_interactive) |
3880
|
891 && ! (reading_fcn_file |
|
892 || reading_script_file |
|
893 || get_input_from_eval_string |
3174
|
894 || input_from_startup_file)) |
287
|
895 yyrestart (stdin); |
991
|
896 |
1826
|
897 // Clear the buffer for help text. |
4426
|
898 while (! help_buf.empty ()) |
|
899 help_buf.pop (); |
1755
|
900 |
1826
|
901 // Reset other flags. |
|
902 lexer_flags.init (); |
1
|
903 } |
|
904 |
767
|
905 // If we read some newlines, we need figure out what column we're |
|
906 // really looking at. |
|
907 |
1
|
908 static void |
|
909 fixup_column_count (char *s) |
|
910 { |
|
911 char c; |
|
912 while ((c = *s++) != '\0') |
|
913 { |
|
914 if (c == '\n') |
143
|
915 current_input_column = 1; |
1
|
916 else |
|
917 current_input_column++; |
|
918 } |
|
919 } |
|
920 |
767
|
921 // Include these so that we don't have to link to libfl.a. |
246
|
922 |
3332
|
923 int |
1
|
924 yywrap (void) |
|
925 { |
287
|
926 return 1; |
1
|
927 } |
|
928 |
767
|
929 // Tell us all what the current buffer is. |
|
930 |
1
|
931 YY_BUFFER_STATE |
|
932 current_buffer (void) |
|
933 { |
|
934 return YY_CURRENT_BUFFER; |
|
935 } |
|
936 |
767
|
937 // Create a new buffer. |
|
938 |
1
|
939 YY_BUFFER_STATE |
|
940 create_buffer (FILE *f) |
|
941 { |
|
942 return yy_create_buffer (f, YY_BUF_SIZE); |
|
943 } |
|
944 |
767
|
945 // Start reading a new buffer. |
|
946 |
1
|
947 void |
|
948 switch_to_buffer (YY_BUFFER_STATE buf) |
|
949 { |
|
950 yy_switch_to_buffer (buf); |
|
951 } |
|
952 |
767
|
953 // Delete a buffer. |
|
954 |
1
|
955 void |
|
956 delete_buffer (YY_BUFFER_STATE buf) |
|
957 { |
|
958 yy_delete_buffer (buf); |
|
959 } |
|
960 |
767
|
961 // Restore a buffer (for unwind-prot). |
|
962 |
1
|
963 void |
|
964 restore_input_buffer (void *buf) |
|
965 { |
2861
|
966 switch_to_buffer (static_cast<YY_BUFFER_STATE> (buf)); |
1
|
967 } |
|
968 |
767
|
969 // Delete a buffer (for unwind-prot). |
|
970 |
1
|
971 void |
|
972 delete_input_buffer (void *buf) |
|
973 { |
2861
|
974 delete_buffer (static_cast<YY_BUFFER_STATE> (buf)); |
1
|
975 } |
|
976 |
4238
|
977 static void |
|
978 prep_for_function (void) |
|
979 { |
|
980 end_tokens_expected++; |
|
981 |
|
982 // Prepare for local symbols. |
|
983 |
|
984 tmp_local_sym_tab = new symbol_table (); |
|
985 |
|
986 promptflag--; |
|
987 |
|
988 lexer_flags.defining_func = true; |
|
989 lexer_flags.parsed_function_name = false; |
|
990 lexer_flags.beginning_of_function = true; |
|
991 |
|
992 if (! (reading_fcn_file || reading_script_file)) |
|
993 input_line_number = 1; |
|
994 } |
|
995 |
|
996 static void |
|
997 prep_for_nested_function (void) |
|
998 { |
4240
|
999 lexer_flags.parsing_nested_function = 1; |
4426
|
1000 help_buf.push (std::string ()); |
4238
|
1001 prep_for_function (); |
4240
|
1002 // We're still only expecting one end token for this set of functions. |
|
1003 end_tokens_expected--; |
4238
|
1004 yylval.tok_val = new token (input_line_number, current_input_column); |
|
1005 token_stack.push (yylval.tok_val); |
|
1006 } |
|
1007 |
|
1008 // Handle keywords. Return -1 if the keyword should be ignored. |
767
|
1009 |
1
|
1010 static int |
4867
|
1011 is_keyword_token (const std::string& s) |
1
|
1012 { |
3805
|
1013 int l = input_line_number; |
|
1014 int c = current_input_column; |
|
1015 |
1823
|
1016 int len = s.length (); |
922
|
1017 |
5088
|
1018 const octave_kw *kw = octave_kw_hash::in_word_set (s.c_str (), len); |
191
|
1019 |
1497
|
1020 if (kw) |
143
|
1021 { |
1497
|
1022 yylval.tok_val = 0; |
|
1023 |
|
1024 switch (kw->kw_id) |
|
1025 { |
|
1026 case all_va_args_kw: |
|
1027 case break_kw: |
2764
|
1028 case case_kw: |
1497
|
1029 case catch_kw: |
|
1030 case continue_kw: |
|
1031 case else_kw: |
|
1032 case elseif_kw: |
|
1033 case global_kw: |
2764
|
1034 case otherwise_kw: |
1497
|
1035 case return_kw: |
2846
|
1036 case static_kw: |
3484
|
1037 case until_kw: |
1497
|
1038 case unwind_protect_cleanup_kw: |
|
1039 break; |
|
1040 |
|
1041 case end_kw: |
4234
|
1042 if (lexer_flags.looking_at_object_index) |
|
1043 return 0; |
|
1044 else |
4238
|
1045 { |
|
1046 if (reading_fcn_file && end_tokens_expected == 1) |
|
1047 return -1; |
|
1048 else |
|
1049 { |
|
1050 yylval.tok_val = new token (token::simple_end, l, c); |
|
1051 end_tokens_expected--; |
|
1052 } |
|
1053 } |
1497
|
1054 break; |
|
1055 |
|
1056 case end_try_catch_kw: |
4238
|
1057 end_tokens_expected--; |
1497
|
1058 yylval.tok_val = new token (token::try_catch_end, l, c); |
|
1059 break; |
|
1060 |
|
1061 case end_unwind_protect_kw: |
4238
|
1062 end_tokens_expected--; |
1497
|
1063 yylval.tok_val = new token (token::unwind_protect_end, l, c); |
|
1064 break; |
|
1065 |
|
1066 case endfor_kw: |
4238
|
1067 end_tokens_expected--; |
1497
|
1068 yylval.tok_val = new token (token::for_end, l, c); |
|
1069 break; |
|
1070 |
|
1071 case endfunction_kw: |
4238
|
1072 { |
|
1073 if (reading_fcn_file && end_tokens_expected == 1) |
|
1074 return -1; |
|
1075 else |
|
1076 { |
|
1077 yylval.tok_val = new token (token::function_end, l, c); |
|
1078 end_tokens_expected--; |
|
1079 } |
|
1080 } |
1497
|
1081 break; |
|
1082 |
|
1083 case endif_kw: |
4238
|
1084 end_tokens_expected--; |
1497
|
1085 yylval.tok_val = new token (token::if_end, l, c); |
|
1086 break; |
|
1087 |
2764
|
1088 case endswitch_kw: |
4238
|
1089 end_tokens_expected--; |
2764
|
1090 yylval.tok_val = new token (token::switch_end, l, c); |
|
1091 break; |
|
1092 |
1497
|
1093 case endwhile_kw: |
4238
|
1094 end_tokens_expected--; |
1497
|
1095 yylval.tok_val = new token (token::while_end, l, c); |
|
1096 break; |
|
1097 |
|
1098 case for_kw: |
|
1099 case while_kw: |
4238
|
1100 end_tokens_expected++; |
|
1101 // Fall through... |
|
1102 |
|
1103 case do_kw: |
1497
|
1104 promptflag--; |
1826
|
1105 lexer_flags.looping++; |
1497
|
1106 break; |
|
1107 |
|
1108 case if_kw: |
|
1109 case try_kw: |
2764
|
1110 case switch_kw: |
1497
|
1111 case unwind_protect_kw: |
4238
|
1112 end_tokens_expected++; |
1497
|
1113 promptflag--; |
|
1114 break; |
|
1115 |
|
1116 case function_kw: |
4238
|
1117 { |
|
1118 if (lexer_flags.defining_func) |
|
1119 { |
|
1120 if (reading_fcn_file) |
|
1121 { |
|
1122 if (lexer_flags.parsing_nested_function) |
|
1123 { |
4323
|
1124 BEGIN (NESTED_FUNCTION_END); |
4240
|
1125 |
4238
|
1126 yylval.tok_val = new token (token::function_end, l, c); |
4240
|
1127 token_stack.push (yylval.tok_val); |
|
1128 |
|
1129 return END; |
4238
|
1130 } |
|
1131 else |
|
1132 { |
|
1133 prep_for_nested_function (); |
4240
|
1134 |
4238
|
1135 return FCN; |
|
1136 } |
|
1137 } |
|
1138 else |
|
1139 { |
|
1140 error ("nested functions not implemented in this context"); |
|
1141 |
|
1142 if ((reading_fcn_file || reading_script_file) |
|
1143 && ! curr_fcn_file_name.empty ()) |
|
1144 error ("near line %d of file `%s.m'", |
|
1145 input_line_number, curr_fcn_file_name.c_str ()); |
|
1146 else |
|
1147 error ("near line %d", input_line_number); |
|
1148 |
|
1149 return LEXICAL_ERROR; |
|
1150 } |
|
1151 } |
|
1152 else |
|
1153 prep_for_function (); |
|
1154 } |
1497
|
1155 break; |
|
1156 |
3174
|
1157 case magic_file_kw: |
|
1158 { |
|
1159 if ((reading_fcn_file || reading_script_file) |
|
1160 && ! curr_fcn_file_full_name.empty ()) |
|
1161 yylval.tok_val = new token (curr_fcn_file_full_name, l, c); |
|
1162 else |
|
1163 yylval.tok_val = new token ("stdin", l, c); |
|
1164 } |
|
1165 break; |
|
1166 |
|
1167 case magic_line_kw: |
|
1168 yylval.tok_val = new token (static_cast<double> (l), "", l, c); |
|
1169 break; |
|
1170 |
3974
|
1171 case varargin_kw: |
|
1172 if (! lexer_flags.looking_at_parameter_list) |
|
1173 return 0; |
|
1174 break; |
|
1175 |
|
1176 case varargout_kw: |
4678
|
1177 if (! (lexer_flags.looking_at_return_list |
|
1178 || (lexer_flags.defining_func |
|
1179 && ! lexer_flags.parsed_function_name))) |
3974
|
1180 return 0; |
|
1181 break; |
|
1182 |
1497
|
1183 default: |
|
1184 panic_impossible (); |
|
1185 } |
|
1186 |
|
1187 if (! yylval.tok_val) |
|
1188 yylval.tok_val = new token (l, c); |
|
1189 |
476
|
1190 token_stack.push (yylval.tok_val); |
1497
|
1191 |
|
1192 return kw->tok; |
143
|
1193 } |
1
|
1194 |
|
1195 return 0; |
|
1196 } |
|
1197 |
767
|
1198 // Try to find an identifier. All binding to global or builtin |
|
1199 // variables occurs when expressions are evaluated. |
|
1200 |
1
|
1201 static symbol_record * |
3523
|
1202 lookup_identifier (const std::string& name) |
1
|
1203 { |
4238
|
1204 std::string sym_name = name; |
|
1205 |
|
1206 if (curr_sym_tab == fbi_sym_tab |
|
1207 && lexer_flags.parsing_nested_function) |
|
1208 sym_name = parent_function_name + ":" + sym_name; |
|
1209 |
|
1210 return curr_sym_tab->lookup (sym_name, true); |
1
|
1211 } |
|
1212 |
2702
|
1213 static bool |
3523
|
1214 is_variable (const std::string& name) |
2702
|
1215 { |
2856
|
1216 symbol_record *sr = curr_sym_tab->lookup (name); |
2702
|
1217 |
|
1218 return sr && sr->is_variable (); |
|
1219 } |
|
1220 |
|
1221 static void |
3523
|
1222 force_local_variable (const std::string& name) |
2702
|
1223 { |
4101
|
1224 if (! is_variable (name)) |
|
1225 curr_sym_tab->clear (name); |
|
1226 |
2856
|
1227 symbol_record *sr = curr_sym_tab->lookup (name, true); |
2702
|
1228 |
|
1229 if (sr) |
|
1230 sr->define (octave_value ()); |
|
1231 } |
|
1232 |
4426
|
1233 // Grab the help text from an function file. |
767
|
1234 |
5775
|
1235 // FIXME -- gobble_leading_white_space() in parse.y |
2300
|
1236 // duplicates some of this code! |
|
1237 |
4426
|
1238 static std::string |
1
|
1239 grab_help_text (void) |
|
1240 { |
4426
|
1241 std::string buf; |
1019
|
1242 |
2300
|
1243 bool begin_comment = true; |
|
1244 bool in_comment = true; |
3427
|
1245 bool discard_space = true; |
3665
|
1246 |
1019
|
1247 int c = 0; |
1
|
1248 |
1019
|
1249 while ((c = yyinput ()) != EOF) |
|
1250 { |
2300
|
1251 if (begin_comment) |
|
1252 { |
|
1253 if (c == '%' || c == '#') |
|
1254 continue; |
3427
|
1255 else if (discard_space && c == ' ') |
|
1256 { |
|
1257 discard_space = false; |
|
1258 continue; |
|
1259 } |
2300
|
1260 else |
|
1261 begin_comment = false; |
|
1262 } |
|
1263 |
1019
|
1264 if (in_comment) |
1
|
1265 { |
4426
|
1266 buf += static_cast<char> (c); |
1755
|
1267 |
1019
|
1268 if (c == '\n') |
3427
|
1269 { |
|
1270 in_comment = false; |
|
1271 discard_space = true; |
|
1272 } |
1019
|
1273 } |
|
1274 else |
|
1275 { |
|
1276 switch (c) |
991
|
1277 { |
4037
|
1278 case '#': |
1019
|
1279 case '%': |
4037
|
1280 maybe_gripe_matlab_incompatible_comment (yytext[0]); |
2300
|
1281 in_comment = true; |
|
1282 begin_comment = true; |
1019
|
1283 break; |
777
|
1284 |
1019
|
1285 case ' ': |
|
1286 case '\t': |
|
1287 break; |
777
|
1288 |
1019
|
1289 default: |
|
1290 goto done; |
1
|
1291 } |
|
1292 } |
1019
|
1293 } |
991
|
1294 |
1019
|
1295 done: |
991
|
1296 |
1019
|
1297 if (c) |
4410
|
1298 yyunput (c, yytext); |
4426
|
1299 |
|
1300 return buf; |
1
|
1301 } |
|
1302 |
767
|
1303 // Return 1 if the given character matches any character in the given |
|
1304 // string. |
|
1305 |
2857
|
1306 static bool |
2804
|
1307 match_any (char c, const char *s) |
1
|
1308 { |
|
1309 char tmp; |
|
1310 while ((tmp = *s++) != '\0') |
|
1311 { |
|
1312 if (c == tmp) |
2857
|
1313 return true; |
1
|
1314 } |
2857
|
1315 return false; |
1
|
1316 } |
|
1317 |
767
|
1318 // Given information about the spacing surrounding an operator, |
|
1319 // return 1 if it looks like it should be treated as a binary |
|
1320 // operator. For example, |
|
1321 // |
3774
|
1322 // [ 1 + 2 ] or [ 1+ 2] or [ 1+2 ] ==> binary |
|
1323 // |
|
1324 // [ 1 +2 ] ==> unary |
767
|
1325 |
2857
|
1326 static bool |
3246
|
1327 looks_like_bin_op (bool spc_prev, int next_char) |
1
|
1328 { |
3246
|
1329 bool spc_next = (next_char == ' ' || next_char == '\t'); |
|
1330 |
608
|
1331 return ((spc_prev && spc_next) || ! spc_prev); |
1
|
1332 } |
|
1333 |
3263
|
1334 // Recognize separators. If the separator is a CRLF pair, it is |
|
1335 // replaced by a single LF. |
|
1336 |
|
1337 static bool |
|
1338 next_token_is_sep_op (void) |
|
1339 { |
|
1340 bool retval = false; |
|
1341 |
|
1342 int c1 = yyinput (); |
|
1343 |
|
1344 if (c1 == '\r') |
|
1345 { |
|
1346 int c2 = yyinput (); |
|
1347 |
|
1348 if (c2 == '\n') |
|
1349 { |
|
1350 c1 = '\n'; |
|
1351 |
|
1352 retval = true; |
|
1353 } |
|
1354 else |
4410
|
1355 yyunput (c2, yytext); |
3263
|
1356 } |
|
1357 else |
|
1358 retval = match_any (c1, ",;\n]"); |
|
1359 |
4410
|
1360 yyunput (c1, yytext); |
3263
|
1361 |
|
1362 return retval; |
|
1363 } |
|
1364 |
767
|
1365 // Try to determine if the next token should be treated as a postfix |
|
1366 // unary operator. This is ugly, but it seems to do the right thing. |
|
1367 |
2857
|
1368 static bool |
3246
|
1369 next_token_is_postfix_unary_op (bool spc_prev) |
1
|
1370 { |
2857
|
1371 bool un_op = false; |
1
|
1372 |
|
1373 int c0 = yyinput (); |
|
1374 |
3246
|
1375 if (c0 == '\'' && ! spc_prev) |
|
1376 { |
|
1377 un_op = true; |
|
1378 } |
|
1379 else if (c0 == '.') |
|
1380 { |
|
1381 int c1 = yyinput (); |
|
1382 un_op = (c1 == '\''); |
4410
|
1383 yyunput (c1, yytext); |
3246
|
1384 } |
4613
|
1385 else if (c0 == '+') |
|
1386 { |
|
1387 int c1 = yyinput (); |
|
1388 un_op = (c1 == '+'); |
|
1389 yyunput (c1, yytext); |
|
1390 } |
|
1391 else if (c0 == '-') |
|
1392 { |
|
1393 int c1 = yyinput (); |
|
1394 un_op = (c1 == '-'); |
|
1395 yyunput (c1, yytext); |
|
1396 } |
1
|
1397 |
4410
|
1398 yyunput (c0, yytext); |
1
|
1399 |
|
1400 return un_op; |
|
1401 } |
|
1402 |
767
|
1403 // Try to determine if the next token should be treated as a binary |
3246
|
1404 // operator. |
1521
|
1405 // |
3246
|
1406 // This kluge exists because whitespace is not always ignored inside |
3774
|
1407 // the square brackets that are used to create matrix objects (though |
|
1408 // spacing only really matters in the cases that can be interpreted |
|
1409 // either as binary ops or prefix unary ops: currently just +, -). |
|
1410 // |
3779
|
1411 // Note that a line continuation directly following a + or - operator |
|
1412 // (e.g., the characters '[' 'a' ' ' '+' '\' LFD 'b' ']') will be |
|
1413 // parsed as a binary operator. |
767
|
1414 |
2857
|
1415 static bool |
3246
|
1416 next_token_is_bin_op (bool spc_prev) |
1
|
1417 { |
2857
|
1418 bool bin_op = false; |
1
|
1419 |
|
1420 int c0 = yyinput (); |
|
1421 |
|
1422 switch (c0) |
|
1423 { |
777
|
1424 case '+': |
|
1425 case '-': |
3774
|
1426 { |
|
1427 int c1 = yyinput (); |
|
1428 |
|
1429 switch (c1) |
|
1430 { |
|
1431 case '+': |
|
1432 case '-': |
|
1433 // Unary ops, spacing doesn't matter. |
|
1434 break; |
|
1435 |
|
1436 case '=': |
|
1437 // Binary ops, spacing doesn't matter. |
|
1438 bin_op = true; |
|
1439 break; |
|
1440 |
|
1441 default: |
|
1442 // Could be either, spacing matters. |
|
1443 bin_op = looks_like_bin_op (spc_prev, c1); |
|
1444 break; |
|
1445 } |
|
1446 |
4410
|
1447 yyunput (c1, yytext); |
3774
|
1448 } |
|
1449 break; |
|
1450 |
|
1451 case ':': |
3246
|
1452 case '/': |
|
1453 case '\\': |
|
1454 case '^': |
3774
|
1455 // Always a binary op (may also include /=, \=, and ^=). |
|
1456 bin_op = true; |
1276
|
1457 break; |
|
1458 |
3246
|
1459 // .+ .- ./ .\ .^ .* .** |
1554
|
1460 case '.': |
|
1461 { |
|
1462 int c1 = yyinput (); |
3246
|
1463 |
3774
|
1464 if (match_any (c1, "+-/\\^*")) |
|
1465 // Always a binary op (may also include .+=, .-=, ./=, ...). |
|
1466 bin_op = true; |
3698
|
1467 else if (! isdigit (c1) && c1 != ' ' && c1 != '\t' && c1 != '.') |
3774
|
1468 // A structure element reference is a binary op. |
|
1469 bin_op = true; |
3246
|
1470 |
4410
|
1471 yyunput (c1, yytext); |
1554
|
1472 } |
|
1473 break; |
|
1474 |
3246
|
1475 // = == & && | || * ** |
|
1476 case '=': |
1
|
1477 case '&': |
3246
|
1478 case '|': |
1
|
1479 case '*': |
3774
|
1480 // Always a binary op (may also include ==, &&, ||, **). |
|
1481 bin_op = true; |
3246
|
1482 break; |
|
1483 |
3774
|
1484 // < <= <> > >= |
1
|
1485 case '<': |
|
1486 case '>': |
3774
|
1487 // Always a binary op (may also include <=, <>, >=). |
|
1488 bin_op = true; |
|
1489 break; |
|
1490 |
|
1491 // ~= != |
777
|
1492 case '~': |
|
1493 case '!': |
3246
|
1494 { |
|
1495 int c1 = yyinput (); |
|
1496 |
3774
|
1497 // ~ and ! can be unary ops, so require following =. |
|
1498 if (c1 == '=') |
|
1499 bin_op = true; |
3246
|
1500 |
4410
|
1501 yyunput (c1, yytext); |
3246
|
1502 } |
1
|
1503 break; |
|
1504 |
|
1505 default: |
1276
|
1506 break; |
1
|
1507 } |
|
1508 |
4410
|
1509 yyunput (c0, yytext); |
1
|
1510 |
|
1511 return bin_op; |
|
1512 } |
|
1513 |
767
|
1514 // Used to delete trailing white space from tokens. |
|
1515 |
3536
|
1516 static std::string |
1
|
1517 strip_trailing_whitespace (char *s) |
|
1518 { |
3523
|
1519 std::string retval = s; |
1
|
1520 |
1823
|
1521 size_t pos = retval.find_first_of (" \t"); |
1
|
1522 |
1823
|
1523 if (pos != NPOS) |
|
1524 retval.resize (pos); |
1
|
1525 |
|
1526 return retval; |
|
1527 } |
|
1528 |
3665
|
1529 static void |
|
1530 scan_for_comments (const char *text) |
|
1531 { |
|
1532 std::string comment_buf; |
|
1533 |
|
1534 bool in_comment = false; |
|
1535 bool beginning_of_comment = false; |
|
1536 |
|
1537 int len = strlen (text); |
|
1538 int i = 0; |
|
1539 |
|
1540 while (i < len) |
|
1541 { |
|
1542 char c = text[i++]; |
|
1543 |
|
1544 switch (c) |
|
1545 { |
|
1546 case '%': |
|
1547 case '#': |
|
1548 if (in_comment) |
|
1549 { |
|
1550 if (! beginning_of_comment) |
3802
|
1551 comment_buf += static_cast<char> (c); |
3665
|
1552 } |
|
1553 else |
|
1554 { |
4037
|
1555 maybe_gripe_matlab_incompatible_comment (c); |
3665
|
1556 in_comment = true; |
|
1557 beginning_of_comment = true; |
|
1558 } |
|
1559 break; |
|
1560 |
|
1561 case '\n': |
|
1562 if (in_comment) |
|
1563 { |
3802
|
1564 comment_buf += static_cast<char> (c); |
3665
|
1565 octave_comment_buffer::append (comment_buf); |
|
1566 comment_buf.resize (0); |
|
1567 in_comment = false; |
|
1568 beginning_of_comment = false; |
|
1569 } |
|
1570 break; |
|
1571 |
|
1572 case '\r': |
|
1573 if (in_comment) |
3802
|
1574 comment_buf += static_cast<char> (c); |
3665
|
1575 if (i < len) |
|
1576 { |
|
1577 c = text[i++]; |
|
1578 |
|
1579 if (c == '\n') |
|
1580 { |
|
1581 if (in_comment) |
|
1582 { |
3802
|
1583 comment_buf += static_cast<char> (c); |
3665
|
1584 octave_comment_buffer::append (comment_buf); |
|
1585 in_comment = false; |
|
1586 beginning_of_comment = false; |
|
1587 } |
|
1588 } |
|
1589 } |
|
1590 |
|
1591 default: |
|
1592 if (in_comment) |
|
1593 { |
3802
|
1594 comment_buf += static_cast<char> (c); |
3665
|
1595 beginning_of_comment = false; |
|
1596 } |
|
1597 break; |
|
1598 } |
|
1599 } |
|
1600 |
|
1601 if (! comment_buf.empty ()) |
|
1602 octave_comment_buffer::append (comment_buf); |
|
1603 } |
|
1604 |
1001
|
1605 // Discard whitespace, including comments and continuations. |
1088
|
1606 // |
|
1607 // Return value is logical OR of the following values: |
|
1608 // |
1826
|
1609 // ATE_NOTHING : no spaces to eat |
1088
|
1610 // ATE_SPACE_OR_TAB : space or tab in input |
|
1611 // ATE_NEWLINE : bare new line in input |
1001
|
1612 |
1826
|
1613 static yum_yum |
975
|
1614 eat_whitespace (void) |
|
1615 { |
1826
|
1616 yum_yum retval = ATE_NOTHING; |
3665
|
1617 |
|
1618 std::string comment_buf; |
|
1619 |
2857
|
1620 bool in_comment = false; |
3665
|
1621 bool beginning_of_comment = false; |
|
1622 |
|
1623 int c = 0; |
|
1624 |
975
|
1625 while ((c = yyinput ()) != EOF) |
|
1626 { |
|
1627 current_input_column++; |
|
1628 |
|
1629 switch (c) |
|
1630 { |
|
1631 case ' ': |
|
1632 case '\t': |
3665
|
1633 if (in_comment) |
|
1634 { |
3802
|
1635 comment_buf += static_cast<char> (c); |
3665
|
1636 beginning_of_comment = false; |
|
1637 } |
1088
|
1638 retval |= ATE_SPACE_OR_TAB; |
975
|
1639 break; |
|
1640 |
|
1641 case '\n': |
1088
|
1642 retval |= ATE_NEWLINE; |
3665
|
1643 if (in_comment) |
|
1644 { |
3802
|
1645 comment_buf += static_cast<char> (c); |
3665
|
1646 octave_comment_buffer::append (comment_buf); |
|
1647 comment_buf.resize (0); |
|
1648 in_comment = false; |
|
1649 beginning_of_comment = false; |
|
1650 } |
975
|
1651 current_input_column = 0; |
|
1652 break; |
|
1653 |
|
1654 case '#': |
|
1655 case '%': |
3665
|
1656 if (in_comment) |
|
1657 { |
|
1658 if (! beginning_of_comment) |
3802
|
1659 comment_buf += static_cast<char> (c); |
3665
|
1660 } |
|
1661 else |
|
1662 { |
4037
|
1663 maybe_gripe_matlab_incompatible_comment (c); |
3665
|
1664 in_comment = true; |
|
1665 beginning_of_comment = true; |
|
1666 } |
975
|
1667 break; |
|
1668 |
1001
|
1669 case '.': |
|
1670 if (in_comment) |
3665
|
1671 { |
3802
|
1672 comment_buf += static_cast<char> (c); |
3665
|
1673 beginning_of_comment = false; |
|
1674 break; |
|
1675 } |
1001
|
1676 else |
|
1677 { |
|
1678 if (have_ellipsis_continuation ()) |
|
1679 break; |
|
1680 else |
|
1681 goto done; |
|
1682 } |
|
1683 |
|
1684 case '\\': |
|
1685 if (in_comment) |
3665
|
1686 { |
3802
|
1687 comment_buf += static_cast<char> (c); |
3665
|
1688 beginning_of_comment = false; |
|
1689 break; |
|
1690 } |
1001
|
1691 else |
|
1692 { |
3105
|
1693 if (have_continuation ()) |
1001
|
1694 break; |
|
1695 else |
|
1696 goto done; |
|
1697 } |
|
1698 |
975
|
1699 default: |
|
1700 if (in_comment) |
3665
|
1701 { |
3802
|
1702 comment_buf += static_cast<char> (c); |
3665
|
1703 beginning_of_comment = false; |
|
1704 break; |
|
1705 } |
975
|
1706 else |
|
1707 goto done; |
|
1708 } |
|
1709 } |
|
1710 |
3665
|
1711 if (! comment_buf.empty ()) |
|
1712 octave_comment_buffer::append (comment_buf); |
|
1713 |
975
|
1714 done: |
4410
|
1715 yyunput (c, yytext); |
1082
|
1716 current_input_column--; |
1001
|
1717 return retval; |
975
|
1718 } |
|
1719 |
3220
|
1720 static inline bool |
|
1721 looks_like_hex (const char *s, int len) |
|
1722 { |
|
1723 return (len > 2 && s[0] == '0' && (s[1] == 'x' || s[1] == 'X')); |
|
1724 } |
|
1725 |
975
|
1726 static void |
3246
|
1727 handle_number (void) |
972
|
1728 { |
3220
|
1729 double value = 0.0; |
|
1730 int nread = 0; |
|
1731 |
3598
|
1732 if (looks_like_hex (yytext, strlen (yytext))) |
3220
|
1733 { |
|
1734 unsigned long ival; |
3598
|
1735 |
|
1736 nread = sscanf (yytext, "%lx", &ival); |
|
1737 |
3220
|
1738 value = static_cast<double> (ival); |
|
1739 } |
|
1740 else |
3598
|
1741 { |
|
1742 char *tmp = strsave (yytext); |
|
1743 |
|
1744 char *idx = strpbrk (tmp, "Dd"); |
2621
|
1745 |
3598
|
1746 if (idx) |
|
1747 *idx = 'e'; |
|
1748 |
|
1749 nread = sscanf (tmp, "%lf", &value); |
|
1750 |
|
1751 delete [] tmp; |
|
1752 } |
972
|
1753 |
1826
|
1754 // If yytext doesn't contain a valid number, we are in deep doo doo. |
985
|
1755 |
972
|
1756 assert (nread == 1); |
|
1757 |
3988
|
1758 lexer_flags.quote_is_transpose = true; |
|
1759 lexer_flags.convert_spaces_to_comma = true; |
972
|
1760 |
|
1761 yylval.tok_val = new token (value, yytext, input_line_number, |
|
1762 current_input_column); |
|
1763 |
|
1764 token_stack.push (yylval.tok_val); |
|
1765 |
|
1766 current_input_column += yyleng; |
|
1767 |
|
1768 do_comma_insert_check (); |
|
1769 } |
|
1770 |
1001
|
1771 // We have seen a backslash and need to find out if it should be |
|
1772 // treated as a continuation character. If so, this eats it, up to |
|
1773 // and including the new line character. |
|
1774 // |
973
|
1775 // Match whitespace only, followed by a comment character or newline. |
|
1776 // Once a comment character is found, discard all input until newline. |
|
1777 // If non-whitespace characters are found before comment |
|
1778 // characters, return 0. Otherwise, return 1. |
|
1779 |
2857
|
1780 static bool |
3096
|
1781 have_continuation (bool trailing_comments_ok) |
973
|
1782 { |
5765
|
1783 std::ostringstream buf; |
973
|
1784 |
3665
|
1785 std::string comment_buf; |
|
1786 |
2857
|
1787 bool in_comment = false; |
3665
|
1788 bool beginning_of_comment = false; |
|
1789 |
|
1790 int c = 0; |
|
1791 |
973
|
1792 while ((c = yyinput ()) != EOF) |
|
1793 { |
3802
|
1794 buf << static_cast<char> (c); |
973
|
1795 |
|
1796 switch (c) |
|
1797 { |
|
1798 case ' ': |
|
1799 case '\t': |
3665
|
1800 if (in_comment) |
|
1801 { |
3802
|
1802 comment_buf += static_cast<char> (c); |
3665
|
1803 beginning_of_comment = false; |
|
1804 } |
973
|
1805 break; |
|
1806 |
|
1807 case '%': |
|
1808 case '#': |
1091
|
1809 if (trailing_comments_ok) |
3665
|
1810 { |
|
1811 if (in_comment) |
|
1812 { |
|
1813 if (! beginning_of_comment) |
3802
|
1814 comment_buf += static_cast<char> (c); |
3665
|
1815 } |
|
1816 else |
|
1817 { |
4037
|
1818 maybe_gripe_matlab_incompatible_comment (c); |
3665
|
1819 in_comment = true; |
|
1820 beginning_of_comment = true; |
|
1821 } |
|
1822 } |
1091
|
1823 else |
|
1824 goto cleanup; |
973
|
1825 break; |
|
1826 |
|
1827 case '\n': |
3665
|
1828 if (in_comment) |
|
1829 { |
3802
|
1830 comment_buf += static_cast<char> (c); |
3665
|
1831 octave_comment_buffer::append (comment_buf); |
|
1832 } |
975
|
1833 current_input_column = 0; |
1001
|
1834 promptflag--; |
4037
|
1835 gripe_matlab_incompatible_continuation (); |
2857
|
1836 return true; |
973
|
1837 |
3263
|
1838 case '\r': |
3665
|
1839 if (in_comment) |
3802
|
1840 comment_buf += static_cast<char> (c); |
3263
|
1841 c = yyinput (); |
|
1842 if (c == EOF) |
|
1843 break; |
|
1844 else if (c == '\n') |
|
1845 { |
3665
|
1846 if (in_comment) |
|
1847 { |
3802
|
1848 comment_buf += static_cast<char> (c); |
3665
|
1849 octave_comment_buffer::append (comment_buf); |
|
1850 } |
3263
|
1851 current_input_column = 0; |
|
1852 promptflag--; |
4037
|
1853 gripe_matlab_incompatible_continuation (); |
3263
|
1854 return true; |
3665
|
1855 } |
3263
|
1856 |
3802
|
1857 // Fall through... |
|
1858 |
973
|
1859 default: |
3665
|
1860 if (in_comment) |
|
1861 { |
3802
|
1862 comment_buf += static_cast<char> (c); |
3665
|
1863 beginning_of_comment = false; |
|
1864 } |
|
1865 else |
1091
|
1866 goto cleanup; |
|
1867 break; |
973
|
1868 } |
|
1869 } |
|
1870 |
4410
|
1871 yyunput (c, yytext); |
2857
|
1872 return false; |
973
|
1873 |
3096
|
1874 cleanup: |
4051
|
1875 |
5765
|
1876 std::string s = buf.str (); |
4051
|
1877 |
|
1878 int len = s.length (); |
|
1879 while (len--) |
4410
|
1880 yyunput (s[len], yytext); |
3096
|
1881 |
2857
|
1882 return false; |
973
|
1883 } |
|
1884 |
1001
|
1885 // We have seen a `.' and need to see if it is the start of a |
|
1886 // continuation. If so, this eats it, up to and including the new |
|
1887 // line character. |
|
1888 |
2857
|
1889 static bool |
3096
|
1890 have_ellipsis_continuation (bool trailing_comments_ok) |
973
|
1891 { |
|
1892 char c1 = yyinput (); |
|
1893 if (c1 == '.') |
|
1894 { |
|
1895 char c2 = yyinput (); |
1091
|
1896 if (c2 == '.' && have_continuation (trailing_comments_ok)) |
2857
|
1897 return true; |
973
|
1898 else |
|
1899 { |
4410
|
1900 yyunput (c2, yytext); |
|
1901 yyunput (c1, yytext); |
973
|
1902 } |
|
1903 } |
|
1904 else |
4410
|
1905 yyunput (c1, yytext); |
973
|
1906 |
2857
|
1907 return false; |
973
|
1908 } |
|
1909 |
1001
|
1910 // See if we have a continuation line. If so, eat it and the leading |
|
1911 // whitespace on the next line. |
1088
|
1912 // |
|
1913 // Return value is the same as described for eat_whitespace(). |
1001
|
1914 |
1826
|
1915 static yum_yum |
1001
|
1916 eat_continuation (void) |
|
1917 { |
1826
|
1918 int retval = ATE_NOTHING; |
3665
|
1919 |
1001
|
1920 int c = yyinput (); |
3665
|
1921 |
1001
|
1922 if ((c == '.' && have_ellipsis_continuation ()) |
3105
|
1923 || (c == '\\' && have_continuation ())) |
1001
|
1924 retval = eat_whitespace (); |
|
1925 else |
4410
|
1926 yyunput (c, yytext); |
1001
|
1927 |
|
1928 return retval; |
|
1929 } |
|
1930 |
973
|
1931 static int |
975
|
1932 handle_string (char delim, int text_style) |
973
|
1933 { |
5765
|
1934 std::ostringstream buf; |
973
|
1935 |
3805
|
1936 int bos_line = input_line_number; |
|
1937 int bos_col = current_input_column; |
|
1938 |
973
|
1939 int c; |
1031
|
1940 int escape_pending = 0; |
973
|
1941 |
|
1942 while ((c = yyinput ()) != EOF) |
|
1943 { |
|
1944 current_input_column++; |
|
1945 |
3105
|
1946 if (c == '\\') |
973
|
1947 { |
5359
|
1948 if (delim == '\'' || escape_pending) |
1053
|
1949 { |
3802
|
1950 buf << static_cast<char> (c); |
1053
|
1951 escape_pending = 0; |
|
1952 } |
|
1953 else |
|
1954 { |
3096
|
1955 if (have_continuation (false)) |
1053
|
1956 escape_pending = 0; |
|
1957 else |
|
1958 { |
3802
|
1959 buf << static_cast<char> (c); |
1053
|
1960 escape_pending = 1; |
|
1961 } |
|
1962 } |
1031
|
1963 continue; |
973
|
1964 } |
|
1965 else if (c == '.') |
|
1966 { |
5359
|
1967 if (delim == '\'' || ! have_ellipsis_continuation (false)) |
3802
|
1968 buf << static_cast<char> (c); |
973
|
1969 } |
|
1970 else if (c == '\n') |
|
1971 { |
1053
|
1972 error ("unterminated string constant"); |
973
|
1973 break; |
|
1974 } |
|
1975 else if (c == delim) |
|
1976 { |
1031
|
1977 if (escape_pending) |
3802
|
1978 buf << static_cast<char> (c); |
973
|
1979 else |
|
1980 { |
|
1981 c = yyinput (); |
|
1982 if (c == delim) |
5102
|
1983 { |
|
1984 buf << static_cast<char> (c); |
|
1985 if (lexer_flags.doing_rawcommand) |
|
1986 buf << static_cast<char> (c); |
|
1987 } |
973
|
1988 else |
|
1989 { |
5102
|
1990 std::string s; |
4410
|
1991 yyunput (c, yytext); |
5765
|
1992 |
5279
|
1993 if (lexer_flags.doing_rawcommand || delim == '\'') |
5765
|
1994 s = buf.str (); |
5102
|
1995 else |
5765
|
1996 s = do_string_escapes (buf.str ()); |
975
|
1997 |
5102
|
1998 if (text_style && lexer_flags.doing_rawcommand) |
|
1999 s = std::string (1, delim) + s + std::string (1, delim); |
975
|
2000 else |
|
2001 { |
2857
|
2002 lexer_flags.quote_is_transpose = true; |
|
2003 lexer_flags.convert_spaces_to_comma = true; |
975
|
2004 } |
|
2005 |
3805
|
2006 yylval.tok_val = new token (s, bos_line, bos_col); |
973
|
2007 token_stack.push (yylval.tok_val); |
3400
|
2008 |
4037
|
2009 if (delim == '"') |
|
2010 gripe_matlab_incompatible ("\" used as string delimiter"); |
|
2011 else if (delim == '\'') |
3400
|
2012 gripe_single_quote_string (); |
|
2013 |
5279
|
2014 return delim == '"' ? DQ_STRING : SQ_STRING; |
973
|
2015 } |
|
2016 } |
|
2017 } |
|
2018 else |
|
2019 { |
3802
|
2020 buf << static_cast<char> (c); |
973
|
2021 } |
|
2022 |
1031
|
2023 escape_pending = 0; |
973
|
2024 } |
|
2025 |
|
2026 return LEXICAL_ERROR; |
|
2027 } |
|
2028 |
3208
|
2029 static bool |
|
2030 next_token_is_assign_op (void) |
|
2031 { |
|
2032 bool retval = false; |
|
2033 |
|
2034 int c0 = yyinput (); |
|
2035 |
|
2036 switch (c0) |
|
2037 { |
|
2038 case '=': |
|
2039 { |
|
2040 int c1 = yyinput (); |
4410
|
2041 yyunput (c1, yytext); |
3208
|
2042 if (c1 != '=') |
|
2043 retval = true; |
|
2044 } |
|
2045 break; |
|
2046 |
|
2047 case '+': |
|
2048 case '-': |
|
2049 case '*': |
|
2050 case '/': |
|
2051 case '\\': |
|
2052 case '&': |
|
2053 case '|': |
|
2054 { |
|
2055 int c1 = yyinput (); |
4410
|
2056 yyunput (c1, yytext); |
3208
|
2057 if (c1 == '=') |
|
2058 retval = true; |
|
2059 } |
|
2060 break; |
|
2061 |
|
2062 case '.': |
|
2063 { |
|
2064 int c1 = yyinput (); |
|
2065 if (match_any (c1, "+-*/\\")) |
|
2066 { |
|
2067 int c2 = yyinput (); |
4410
|
2068 yyunput (c2, yytext); |
3208
|
2069 if (c2 == '=') |
|
2070 retval = true; |
|
2071 } |
4410
|
2072 yyunput (c1, yytext); |
3208
|
2073 } |
|
2074 break; |
|
2075 |
|
2076 case '>': |
|
2077 { |
|
2078 int c1 = yyinput (); |
|
2079 if (c1 == '>') |
|
2080 { |
|
2081 int c2 = yyinput (); |
4410
|
2082 yyunput (c2, yytext); |
3208
|
2083 if (c2 == '=') |
|
2084 retval = true; |
|
2085 } |
4410
|
2086 yyunput (c1, yytext); |
3208
|
2087 } |
|
2088 break; |
|
2089 |
|
2090 case '<': |
|
2091 { |
|
2092 int c1 = yyinput (); |
|
2093 if (c1 == '<') |
|
2094 { |
|
2095 int c2 = yyinput (); |
4410
|
2096 yyunput (c2, yytext); |
3208
|
2097 if (c2 == '=') |
|
2098 retval = true; |
|
2099 } |
4410
|
2100 yyunput (c1, yytext); |
3208
|
2101 } |
|
2102 break; |
|
2103 |
|
2104 default: |
|
2105 break; |
|
2106 } |
|
2107 |
4410
|
2108 yyunput (c0, yytext); |
3208
|
2109 |
|
2110 return retval; |
|
2111 } |
|
2112 |
4633
|
2113 static bool |
|
2114 next_token_is_index_op (void) |
|
2115 { |
|
2116 int c = yyinput (); |
|
2117 yyunput (c, yytext); |
|
2118 return c == '(' || c == '{'; |
|
2119 } |
|
2120 |
4612
|
2121 static int |
|
2122 handle_close_bracket (bool spc_gobbled, int bracket_type) |
971
|
2123 { |
4612
|
2124 int retval = bracket_type; |
3208
|
2125 |
1826
|
2126 if (! nesting_level.none ()) |
971
|
2127 { |
1826
|
2128 nesting_level.remove (); |
4613
|
2129 |
|
2130 if (bracket_type == ']') |
|
2131 lexer_flags.bracketflag--; |
|
2132 else if (bracket_type == '}') |
|
2133 lexer_flags.braceflag--; |
|
2134 else |
|
2135 panic_impossible (); |
971
|
2136 } |
|
2137 |
4613
|
2138 if (lexer_flags.bracketflag == 0 && lexer_flags.braceflag == 0) |
4323
|
2139 BEGIN (INITIAL); |
1001
|
2140 |
4608
|
2141 if (bracket_type == ']' |
|
2142 && next_token_is_assign_op () |
|
2143 && ! lexer_flags.looking_at_return_list) |
971
|
2144 { |
3208
|
2145 retval = CLOSE_BRACE; |
971
|
2146 } |
4613
|
2147 else if ((lexer_flags.bracketflag || lexer_flags.braceflag) |
|
2148 && lexer_flags.convert_spaces_to_comma |
|
2149 && (nesting_level.is_bracket () |
|
2150 || (nesting_level.is_brace () |
|
2151 && ! lexer_flags.looking_at_object_index))) |
971
|
2152 { |
4633
|
2153 bool index_op = next_token_is_index_op (); |
|
2154 |
|
2155 // Don't insert comma if we are looking at something like |
|
2156 // |
|
2157 // [x{i}{j}] or [x{i}(j)] |
|
2158 // |
|
2159 // but do if we are looking at |
|
2160 // |
|
2161 // [x{i} {j}] or [x{i} (j)] |
|
2162 |
|
2163 if (spc_gobbled || ! (bracket_type == '}' && index_op)) |
971
|
2164 { |
4633
|
2165 bool bin_op = next_token_is_bin_op (spc_gobbled); |
|
2166 |
|
2167 bool postfix_un_op = next_token_is_postfix_unary_op (spc_gobbled); |
|
2168 |
|
2169 bool sep_op = next_token_is_sep_op (); |
|
2170 |
|
2171 if (! (postfix_un_op || bin_op || sep_op)) |
|
2172 { |
|
2173 maybe_warn_separator_insert (','); |
|
2174 |
|
2175 yyunput (',', yytext); |
|
2176 return retval; |
|
2177 } |
971
|
2178 } |
|
2179 } |
|
2180 |
2857
|
2181 lexer_flags.quote_is_transpose = true; |
|
2182 lexer_flags.convert_spaces_to_comma = true; |
3208
|
2183 |
|
2184 return retval; |
971
|
2185 } |
|
2186 |
1072
|
2187 static void |
|
2188 maybe_unput_comma (int spc_gobbled) |
|
2189 { |
4613
|
2190 if (nesting_level.is_bracket () |
|
2191 || (nesting_level.is_brace () |
|
2192 && ! lexer_flags.looking_at_object_index)) |
1072
|
2193 { |
3246
|
2194 int bin_op = next_token_is_bin_op (spc_gobbled); |
1072
|
2195 |
3246
|
2196 int postfix_un_op = next_token_is_postfix_unary_op (spc_gobbled); |
1072
|
2197 |
|
2198 int c1 = yyinput (); |
|
2199 int c2 = yyinput (); |
2970
|
2200 |
4410
|
2201 yyunput (c2, yytext); |
|
2202 yyunput (c1, yytext); |
2970
|
2203 |
3263
|
2204 int sep_op = next_token_is_sep_op (); |
2970
|
2205 |
1072
|
2206 int dot_op = (c1 == '.' |
|
2207 && (isalpha (c2) || isspace (c2) || c2 == '_')); |
2970
|
2208 |
3388
|
2209 if (postfix_un_op || bin_op || sep_op || dot_op) |
|
2210 return; |
|
2211 |
3985
|
2212 int index_op = (c1 == '(' || c1 == '{'); |
3388
|
2213 |
4476
|
2214 // If there is no space before the indexing op, we don't insert |
|
2215 // a comma. |
|
2216 |
|
2217 if (index_op && ! spc_gobbled) |
|
2218 return; |
|
2219 |
|
2220 maybe_warn_separator_insert (','); |
|
2221 |
|
2222 yyunput (',', yytext); |
1072
|
2223 } |
|
2224 } |
|
2225 |
767
|
2226 // Figure out exactly what kind of token to return when we have seen |
4238
|
2227 // an identifier. Handles keywords. Return -1 if the identifier |
|
2228 // should be ignored. |
767
|
2229 |
146
|
2230 static int |
3974
|
2231 handle_identifier (void) |
146
|
2232 { |
3974
|
2233 std::string tok = strip_trailing_whitespace (yytext); |
|
2234 |
|
2235 int c = yytext[yyleng-1]; |
|
2236 |
|
2237 int cont_is_spc = eat_continuation (); |
|
2238 |
|
2239 int spc_gobbled = (cont_is_spc || c == ' ' || c == '\t'); |
|
2240 |
2970
|
2241 // If we are expecting a structure element, avoid recognizing |
|
2242 // keywords and other special names and return STRUCT_ELT, which is |
|
2243 // a string that is also a valid identifier. But first, we have to |
|
2244 // decide whether to insert a comma. |
747
|
2245 |
1826
|
2246 if (lexer_flags.looking_at_indirect_ref) |
1072
|
2247 { |
2970
|
2248 do_comma_insert_check (); |
|
2249 |
1072
|
2250 maybe_unput_comma (spc_gobbled); |
2819
|
2251 |
|
2252 yylval.tok_val = new token (tok, input_line_number, |
|
2253 current_input_column); |
|
2254 |
|
2255 token_stack.push (yylval.tok_val); |
|
2256 |
2857
|
2257 lexer_flags.quote_is_transpose = true; |
|
2258 lexer_flags.convert_spaces_to_comma = true; |
2819
|
2259 |
|
2260 current_input_column += yyleng; |
|
2261 |
2970
|
2262 return STRUCT_ELT; |
1072
|
2263 } |
747
|
2264 |
4930
|
2265 int kw_token = is_keyword_token (tok); |
|
2266 |
|
2267 if (lexer_flags.looking_at_function_handle) |
|
2268 { |
|
2269 if (kw_token) |
|
2270 { |
|
2271 error ("function handles may not refer to keywords"); |
|
2272 |
|
2273 return LEXICAL_ERROR; |
|
2274 } |
|
2275 else |
|
2276 TOK_PUSH_AND_RETURN (tok, FCN_HANDLE); |
|
2277 } |
|
2278 |
5102
|
2279 // If we have a regular keyword, return it. |
1826
|
2280 // Keywords can be followed by identifiers (TOK_RETURN handles |
|
2281 // that). |
146
|
2282 |
|
2283 if (kw_token) |
|
2284 { |
4238
|
2285 if (kw_token < 0) |
|
2286 return kw_token; |
146
|
2287 else |
|
2288 TOK_RETURN (kw_token); |
|
2289 } |
|
2290 |
1826
|
2291 // See if we have a plot keyword (title, using, with, or clear). |
146
|
2292 |
3480
|
2293 int c1 = yyinput (); |
|
2294 |
|
2295 bool next_tok_is_paren = (c1 == '('); |
|
2296 |
|
2297 bool next_tok_is_eq = false; |
|
2298 if (c1 == '=') |
|
2299 { |
|
2300 int c2 = yyinput (); |
4410
|
2301 yyunput (c2, yytext); |
3480
|
2302 |
|
2303 if (c2 != '=') |
|
2304 next_tok_is_eq = true; |
|
2305 } |
|
2306 |
4410
|
2307 yyunput (c1, yytext); |
1001
|
2308 |
1826
|
2309 // Make sure we put the return values of a function in the symbol |
|
2310 // table that is local to the function. |
146
|
2311 |
2877
|
2312 // If we are defining a function and we have not seen the function |
|
2313 // name yet and the next token is `=', then this identifier must be |
|
2314 // the only return value for the function and it belongs in the |
|
2315 // local symbol table. |
|
2316 |
1826
|
2317 if (next_tok_is_eq |
2877
|
2318 && lexer_flags.defining_func |
|
2319 && ! lexer_flags.parsed_function_name) |
146
|
2320 curr_sym_tab = tmp_local_sym_tab; |
|
2321 |
2702
|
2322 // Kluge alert. |
|
2323 // |
|
2324 // If we are looking at a text style function, set up to gobble its |
2745
|
2325 // arguments. |
|
2326 // |
|
2327 // If the following token is `=', or if we are parsing a function |
3189
|
2328 // return list or function parameter list, or if we are looking at |
|
2329 // something like [ab,cd] = foo (), force the symbol to be inserted |
|
2330 // as a variable in the current symbol table. |
2702
|
2331 |
4208
|
2332 if (is_command_name (tok) && ! is_variable (tok)) |
2702
|
2333 { |
2745
|
2334 if (next_tok_is_eq |
|
2335 || lexer_flags.looking_at_return_list |
3189
|
2336 || lexer_flags.looking_at_parameter_list |
4101
|
2337 || lexer_flags.looking_at_matrix_or_assign_lhs) |
2745
|
2338 { |
|
2339 force_local_variable (tok); |
|
2340 } |
2702
|
2341 else if (! next_tok_is_paren) |
|
2342 { |
5102
|
2343 BEGIN (COMMAND_START); |
|
2344 } |
|
2345 |
|
2346 if (is_rawcommand_name (tok)) |
|
2347 { |
|
2348 lexer_flags.doing_rawcommand = true; |
4323
|
2349 BEGIN (COMMAND_START); |
2702
|
2350 } |
|
2351 } |
|
2352 |
4234
|
2353 // Find the token in the symbol table. Beware the magic |
|
2354 // transformation of the end keyword... |
|
2355 |
|
2356 if (tok == "end") |
|
2357 tok = "__end__"; |
146
|
2358 |
|
2359 yylval.tok_val = new token (lookup_identifier (tok), |
|
2360 input_line_number, |
|
2361 current_input_column); |
|
2362 |
|
2363 token_stack.push (yylval.tok_val); |
|
2364 |
1826
|
2365 // After seeing an identifer, it is ok to convert spaces to a comma |
|
2366 // (if needed). |
146
|
2367 |
2857
|
2368 lexer_flags.convert_spaces_to_comma = true; |
146
|
2369 |
2877
|
2370 if (! next_tok_is_eq) |
|
2371 { |
|
2372 lexer_flags.quote_is_transpose = true; |
146
|
2373 |
2877
|
2374 do_comma_insert_check (); |
|
2375 |
|
2376 maybe_unput_comma (spc_gobbled); |
146
|
2377 } |
|
2378 |
2877
|
2379 current_input_column += yyleng; |
146
|
2380 |
|
2381 return NAME; |
|
2382 } |
|
2383 |
1826
|
2384 void |
|
2385 lexical_feedback::init (void) |
|
2386 { |
|
2387 // Not initially defining a matrix list. |
3351
|
2388 bracketflag = 0; |
1826
|
2389 |
4613
|
2390 // Not initially defining a cell array list. |
|
2391 braceflag = 0; |
|
2392 |
1826
|
2393 // Not initially inside a loop or if statement. |
|
2394 looping = 0; |
|
2395 |
2857
|
2396 // Not initially defining a function. |
|
2397 beginning_of_function = false; |
|
2398 defining_func = false; |
2877
|
2399 parsed_function_name = false; |
4240
|
2400 parsing_nested_function = 0; |
2857
|
2401 |
4930
|
2402 // Not initiallly looking at a function handle. |
|
2403 looking_at_function_handle = 0; |
|
2404 |
2857
|
2405 // Not parsing a function return or parameter list. |
|
2406 looking_at_return_list = false; |
|
2407 looking_at_parameter_list = false; |
|
2408 |
3796
|
2409 // Not parsing a matrix or the left hand side of multi-value |
|
2410 // assignment statement. |
|
2411 looking_at_matrix_or_assign_lhs = false; |
|
2412 |
4234
|
2413 // Not parsing an object index. |
4237
|
2414 looking_at_object_index = 0; |
4234
|
2415 |
2857
|
2416 // No need to do comma insert or convert spaces to comma at |
|
2417 // beginning of input. |
|
2418 convert_spaces_to_comma = true; |
|
2419 do_comma_insert = false; |
|
2420 |
|
2421 // Not initially doing any plotting or setting of plot attributes. |
5102
|
2422 doing_rawcommand = false; |
2857
|
2423 |
1826
|
2424 // Not initially looking at indirect references. |
2857
|
2425 looking_at_indirect_ref = false; |
1826
|
2426 |
|
2427 // Quote marks strings intially. |
2857
|
2428 quote_is_transpose = false; |
1826
|
2429 } |
|
2430 |
4867
|
2431 bool |
|
2432 is_keyword (const std::string& s) |
|
2433 { |
5088
|
2434 return octave_kw_hash::in_word_set (s.c_str (), s.length ()) != 0; |
4867
|
2435 } |
|
2436 |
4264
|
2437 DEFCMD (iskeyword, args, , |
|
2438 "-*- texinfo -*-\n\ |
|
2439 @deftypefn {Built-in Function} {} iskeyword (@var{name})\n\ |
|
2440 Return true if @var{name} is an Octave keyword. If @var{name}\n\ |
|
2441 is omitted, return a list of keywords.\n\ |
|
2442 @end deftypefn") |
|
2443 { |
|
2444 octave_value retval; |
|
2445 |
|
2446 int argc = args.length () + 1; |
|
2447 |
4867
|
2448 string_vector argv = args.make_argv ("iskeyword"); |
4264
|
2449 |
|
2450 if (error_state) |
|
2451 return retval; |
|
2452 |
|
2453 if (argc == 1) |
|
2454 { |
|
2455 string_vector lst (TOTAL_KEYWORDS); |
|
2456 |
|
2457 for (int i = 0; i < TOTAL_KEYWORDS; i++) |
|
2458 lst[i] = wordlist[i].name; |
|
2459 |
|
2460 retval = Cell (lst.qsort ()); |
|
2461 } |
|
2462 else if (argc == 2) |
|
2463 { |
4867
|
2464 retval = is_keyword (argv[1]); |
4264
|
2465 } |
|
2466 else |
5823
|
2467 print_usage (); |
4264
|
2468 |
|
2469 return retval; |
|
2470 } |
|
2471 |
|
2472 |
3388
|
2473 static void |
|
2474 maybe_warn_separator_insert (char sep) |
|
2475 { |
3523
|
2476 std::string nm = curr_fcn_file_full_name; |
3388
|
2477 |
5794
|
2478 if (nm.empty ()) |
|
2479 warning_with_id ("Octave:separator-insert", |
|
2480 "potential auto-insertion of `%c' near line %d", |
|
2481 sep, input_line_number); |
|
2482 else |
|
2483 warning_with_id ("Octave:separator-insert", |
|
2484 "potential auto-insertion of `%c' near line %d of file %s", |
|
2485 sep, input_line_number, nm.c_str ()); |
3388
|
2486 } |
|
2487 |
3400
|
2488 static void |
|
2489 gripe_single_quote_string (void) |
|
2490 { |
3523
|
2491 std::string nm = curr_fcn_file_full_name; |
3400
|
2492 |
5794
|
2493 if (nm.empty ()) |
|
2494 warning_with_id ("Octave:single-quote-string", |
|
2495 "single quote delimited string near line %d", |
|
2496 input_line_number); |
|
2497 else |
|
2498 warning_with_id ("Octave:single-quote-string", |
|
2499 "single quote delimited string near line %d of file %s", |
|
2500 input_line_number, nm.c_str ()); |
3400
|
2501 } |
|
2502 |
4037
|
2503 static void |
|
2504 gripe_matlab_incompatible (const std::string& msg) |
|
2505 { |
5794
|
2506 warning_with_id ("Octave:matlab-incompatible", |
|
2507 "potential Matlab compatibility problem: %s", |
|
2508 msg.c_str ()); |
4037
|
2509 } |
|
2510 |
|
2511 static void |
|
2512 maybe_gripe_matlab_incompatible_comment (char c) |
|
2513 { |
|
2514 if (c == '#') |
|
2515 gripe_matlab_incompatible ("# used as comment character"); |
|
2516 } |
|
2517 |
|
2518 static void |
|
2519 gripe_matlab_incompatible_continuation (void) |
|
2520 { |
|
2521 gripe_matlab_incompatible ("\\ used as line continuation marker"); |
|
2522 } |
|
2523 |
|
2524 static void |
|
2525 gripe_matlab_incompatible_operator (const std::string& op) |
|
2526 { |
|
2527 std::string t = op; |
|
2528 int n = t.length (); |
|
2529 if (t[n-1] == '\n') |
|
2530 t.resize (n-1); |
|
2531 gripe_matlab_incompatible (t + " used as operator"); |
|
2532 } |
|
2533 |
4910
|
2534 DEFUN (__token_count__, , , |
|
2535 "-*- texinfo -*-\n\ |
|
2536 @deftypefn {Built-in Function} {} __token_count__\n\ |
|
2537 Number of language tokens processed since Octave startup.\n\ |
|
2538 @end deftypefn") |
|
2539 { |
|
2540 return octave_value (Vtoken_count); |
|
2541 } |
|
2542 |
1994
|
2543 /* |
|
2544 ;;; Local Variables: *** |
|
2545 ;;; mode: C++ *** |
|
2546 ;;; End: *** |
|
2547 */ |