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 break_kw: |
2764
|
1007 case case_kw: |
1497
|
1008 case catch_kw: |
|
1009 case continue_kw: |
|
1010 case else_kw: |
|
1011 case elseif_kw: |
|
1012 case global_kw: |
2764
|
1013 case otherwise_kw: |
1497
|
1014 case return_kw: |
2846
|
1015 case static_kw: |
3484
|
1016 case until_kw: |
1497
|
1017 case unwind_protect_cleanup_kw: |
|
1018 break; |
|
1019 |
|
1020 case end_kw: |
4234
|
1021 if (lexer_flags.looking_at_object_index) |
|
1022 return 0; |
|
1023 else |
4238
|
1024 { |
|
1025 if (reading_fcn_file && end_tokens_expected == 1) |
|
1026 return -1; |
|
1027 else |
|
1028 { |
|
1029 yylval.tok_val = new token (token::simple_end, l, c); |
|
1030 end_tokens_expected--; |
|
1031 } |
|
1032 } |
1497
|
1033 break; |
|
1034 |
|
1035 case end_try_catch_kw: |
4238
|
1036 end_tokens_expected--; |
1497
|
1037 yylval.tok_val = new token (token::try_catch_end, l, c); |
|
1038 break; |
|
1039 |
|
1040 case end_unwind_protect_kw: |
4238
|
1041 end_tokens_expected--; |
1497
|
1042 yylval.tok_val = new token (token::unwind_protect_end, l, c); |
|
1043 break; |
|
1044 |
|
1045 case endfor_kw: |
4238
|
1046 end_tokens_expected--; |
1497
|
1047 yylval.tok_val = new token (token::for_end, l, c); |
|
1048 break; |
|
1049 |
|
1050 case endfunction_kw: |
4238
|
1051 { |
|
1052 if (reading_fcn_file && end_tokens_expected == 1) |
|
1053 return -1; |
|
1054 else |
|
1055 { |
|
1056 yylval.tok_val = new token (token::function_end, l, c); |
|
1057 end_tokens_expected--; |
|
1058 } |
|
1059 } |
1497
|
1060 break; |
|
1061 |
|
1062 case endif_kw: |
4238
|
1063 end_tokens_expected--; |
1497
|
1064 yylval.tok_val = new token (token::if_end, l, c); |
|
1065 break; |
|
1066 |
2764
|
1067 case endswitch_kw: |
4238
|
1068 end_tokens_expected--; |
2764
|
1069 yylval.tok_val = new token (token::switch_end, l, c); |
|
1070 break; |
|
1071 |
1497
|
1072 case endwhile_kw: |
4238
|
1073 end_tokens_expected--; |
1497
|
1074 yylval.tok_val = new token (token::while_end, l, c); |
|
1075 break; |
|
1076 |
|
1077 case for_kw: |
|
1078 case while_kw: |
4238
|
1079 end_tokens_expected++; |
|
1080 // Fall through... |
|
1081 |
|
1082 case do_kw: |
1497
|
1083 promptflag--; |
1826
|
1084 lexer_flags.looping++; |
1497
|
1085 break; |
|
1086 |
|
1087 case if_kw: |
|
1088 case try_kw: |
2764
|
1089 case switch_kw: |
1497
|
1090 case unwind_protect_kw: |
4238
|
1091 end_tokens_expected++; |
1497
|
1092 promptflag--; |
|
1093 break; |
|
1094 |
|
1095 case function_kw: |
4238
|
1096 { |
|
1097 if (lexer_flags.defining_func) |
|
1098 { |
|
1099 if (reading_fcn_file) |
|
1100 { |
|
1101 if (lexer_flags.parsing_nested_function) |
|
1102 { |
4323
|
1103 BEGIN (NESTED_FUNCTION_END); |
4240
|
1104 |
4238
|
1105 yylval.tok_val = new token (token::function_end, l, c); |
4240
|
1106 token_stack.push (yylval.tok_val); |
|
1107 |
|
1108 return END; |
4238
|
1109 } |
|
1110 else |
|
1111 { |
|
1112 prep_for_nested_function (); |
4240
|
1113 |
4238
|
1114 return FCN; |
|
1115 } |
|
1116 } |
|
1117 else |
|
1118 { |
|
1119 error ("nested functions not implemented in this context"); |
|
1120 |
|
1121 if ((reading_fcn_file || reading_script_file) |
|
1122 && ! curr_fcn_file_name.empty ()) |
|
1123 error ("near line %d of file `%s.m'", |
|
1124 input_line_number, curr_fcn_file_name.c_str ()); |
|
1125 else |
|
1126 error ("near line %d", input_line_number); |
|
1127 |
|
1128 return LEXICAL_ERROR; |
|
1129 } |
|
1130 } |
|
1131 else |
|
1132 prep_for_function (); |
|
1133 } |
1497
|
1134 break; |
|
1135 |
3174
|
1136 case magic_file_kw: |
|
1137 { |
|
1138 if ((reading_fcn_file || reading_script_file) |
|
1139 && ! curr_fcn_file_full_name.empty ()) |
|
1140 yylval.tok_val = new token (curr_fcn_file_full_name, l, c); |
|
1141 else |
|
1142 yylval.tok_val = new token ("stdin", l, c); |
|
1143 } |
|
1144 break; |
|
1145 |
|
1146 case magic_line_kw: |
|
1147 yylval.tok_val = new token (static_cast<double> (l), "", l, c); |
|
1148 break; |
|
1149 |
3974
|
1150 case varargin_kw: |
|
1151 if (! lexer_flags.looking_at_parameter_list) |
|
1152 return 0; |
|
1153 break; |
|
1154 |
|
1155 case varargout_kw: |
4678
|
1156 if (! (lexer_flags.looking_at_return_list |
|
1157 || (lexer_flags.defining_func |
|
1158 && ! lexer_flags.parsed_function_name))) |
3974
|
1159 return 0; |
|
1160 break; |
|
1161 |
1497
|
1162 default: |
|
1163 panic_impossible (); |
|
1164 } |
|
1165 |
|
1166 if (! yylval.tok_val) |
|
1167 yylval.tok_val = new token (l, c); |
|
1168 |
476
|
1169 token_stack.push (yylval.tok_val); |
1497
|
1170 |
|
1171 return kw->tok; |
143
|
1172 } |
1
|
1173 |
|
1174 return 0; |
|
1175 } |
|
1176 |
767
|
1177 // Try to find an identifier. All binding to global or builtin |
|
1178 // variables occurs when expressions are evaluated. |
|
1179 |
1
|
1180 static symbol_record * |
3523
|
1181 lookup_identifier (const std::string& name) |
1
|
1182 { |
4238
|
1183 std::string sym_name = name; |
|
1184 |
|
1185 if (curr_sym_tab == fbi_sym_tab |
|
1186 && lexer_flags.parsing_nested_function) |
|
1187 sym_name = parent_function_name + ":" + sym_name; |
|
1188 |
|
1189 return curr_sym_tab->lookup (sym_name, true); |
1
|
1190 } |
|
1191 |
2702
|
1192 static bool |
3523
|
1193 is_variable (const std::string& name) |
2702
|
1194 { |
2856
|
1195 symbol_record *sr = curr_sym_tab->lookup (name); |
2702
|
1196 |
|
1197 return sr && sr->is_variable (); |
|
1198 } |
|
1199 |
|
1200 static void |
3523
|
1201 force_local_variable (const std::string& name) |
2702
|
1202 { |
4101
|
1203 if (! is_variable (name)) |
|
1204 curr_sym_tab->clear (name); |
|
1205 |
2856
|
1206 symbol_record *sr = curr_sym_tab->lookup (name, true); |
2702
|
1207 |
|
1208 if (sr) |
|
1209 sr->define (octave_value ()); |
|
1210 } |
|
1211 |
4426
|
1212 // Grab the help text from an function file. |
767
|
1213 |
5775
|
1214 // FIXME -- gobble_leading_white_space() in parse.y |
2300
|
1215 // duplicates some of this code! |
|
1216 |
4426
|
1217 static std::string |
1
|
1218 grab_help_text (void) |
|
1219 { |
4426
|
1220 std::string buf; |
1019
|
1221 |
2300
|
1222 bool begin_comment = true; |
|
1223 bool in_comment = true; |
3427
|
1224 bool discard_space = true; |
3665
|
1225 |
1019
|
1226 int c = 0; |
1
|
1227 |
1019
|
1228 while ((c = yyinput ()) != EOF) |
|
1229 { |
2300
|
1230 if (begin_comment) |
|
1231 { |
|
1232 if (c == '%' || c == '#') |
|
1233 continue; |
3427
|
1234 else if (discard_space && c == ' ') |
|
1235 { |
|
1236 discard_space = false; |
|
1237 continue; |
|
1238 } |
2300
|
1239 else |
|
1240 begin_comment = false; |
|
1241 } |
|
1242 |
1019
|
1243 if (in_comment) |
1
|
1244 { |
4426
|
1245 buf += static_cast<char> (c); |
1755
|
1246 |
1019
|
1247 if (c == '\n') |
3427
|
1248 { |
|
1249 in_comment = false; |
|
1250 discard_space = true; |
|
1251 } |
1019
|
1252 } |
|
1253 else |
|
1254 { |
|
1255 switch (c) |
991
|
1256 { |
4037
|
1257 case '#': |
1019
|
1258 case '%': |
4037
|
1259 maybe_gripe_matlab_incompatible_comment (yytext[0]); |
2300
|
1260 in_comment = true; |
|
1261 begin_comment = true; |
1019
|
1262 break; |
777
|
1263 |
1019
|
1264 case ' ': |
|
1265 case '\t': |
|
1266 break; |
777
|
1267 |
1019
|
1268 default: |
|
1269 goto done; |
1
|
1270 } |
|
1271 } |
1019
|
1272 } |
991
|
1273 |
1019
|
1274 done: |
991
|
1275 |
1019
|
1276 if (c) |
4410
|
1277 yyunput (c, yytext); |
4426
|
1278 |
|
1279 return buf; |
1
|
1280 } |
|
1281 |
767
|
1282 // Return 1 if the given character matches any character in the given |
|
1283 // string. |
|
1284 |
2857
|
1285 static bool |
2804
|
1286 match_any (char c, const char *s) |
1
|
1287 { |
|
1288 char tmp; |
|
1289 while ((tmp = *s++) != '\0') |
|
1290 { |
|
1291 if (c == tmp) |
2857
|
1292 return true; |
1
|
1293 } |
2857
|
1294 return false; |
1
|
1295 } |
|
1296 |
767
|
1297 // Given information about the spacing surrounding an operator, |
|
1298 // return 1 if it looks like it should be treated as a binary |
|
1299 // operator. For example, |
|
1300 // |
3774
|
1301 // [ 1 + 2 ] or [ 1+ 2] or [ 1+2 ] ==> binary |
|
1302 // |
|
1303 // [ 1 +2 ] ==> unary |
767
|
1304 |
2857
|
1305 static bool |
3246
|
1306 looks_like_bin_op (bool spc_prev, int next_char) |
1
|
1307 { |
3246
|
1308 bool spc_next = (next_char == ' ' || next_char == '\t'); |
|
1309 |
608
|
1310 return ((spc_prev && spc_next) || ! spc_prev); |
1
|
1311 } |
|
1312 |
3263
|
1313 // Recognize separators. If the separator is a CRLF pair, it is |
|
1314 // replaced by a single LF. |
|
1315 |
|
1316 static bool |
|
1317 next_token_is_sep_op (void) |
|
1318 { |
|
1319 bool retval = false; |
|
1320 |
|
1321 int c1 = yyinput (); |
|
1322 |
|
1323 if (c1 == '\r') |
|
1324 { |
|
1325 int c2 = yyinput (); |
|
1326 |
|
1327 if (c2 == '\n') |
|
1328 { |
|
1329 c1 = '\n'; |
|
1330 |
|
1331 retval = true; |
|
1332 } |
|
1333 else |
4410
|
1334 yyunput (c2, yytext); |
3263
|
1335 } |
|
1336 else |
|
1337 retval = match_any (c1, ",;\n]"); |
|
1338 |
4410
|
1339 yyunput (c1, yytext); |
3263
|
1340 |
|
1341 return retval; |
|
1342 } |
|
1343 |
767
|
1344 // Try to determine if the next token should be treated as a postfix |
|
1345 // unary operator. This is ugly, but it seems to do the right thing. |
|
1346 |
2857
|
1347 static bool |
3246
|
1348 next_token_is_postfix_unary_op (bool spc_prev) |
1
|
1349 { |
2857
|
1350 bool un_op = false; |
1
|
1351 |
|
1352 int c0 = yyinput (); |
|
1353 |
3246
|
1354 if (c0 == '\'' && ! spc_prev) |
|
1355 { |
|
1356 un_op = true; |
|
1357 } |
|
1358 else if (c0 == '.') |
|
1359 { |
|
1360 int c1 = yyinput (); |
|
1361 un_op = (c1 == '\''); |
4410
|
1362 yyunput (c1, yytext); |
3246
|
1363 } |
4613
|
1364 else if (c0 == '+') |
|
1365 { |
|
1366 int c1 = yyinput (); |
|
1367 un_op = (c1 == '+'); |
|
1368 yyunput (c1, yytext); |
|
1369 } |
|
1370 else if (c0 == '-') |
|
1371 { |
|
1372 int c1 = yyinput (); |
|
1373 un_op = (c1 == '-'); |
|
1374 yyunput (c1, yytext); |
|
1375 } |
1
|
1376 |
4410
|
1377 yyunput (c0, yytext); |
1
|
1378 |
|
1379 return un_op; |
|
1380 } |
|
1381 |
767
|
1382 // Try to determine if the next token should be treated as a binary |
3246
|
1383 // operator. |
1521
|
1384 // |
3246
|
1385 // This kluge exists because whitespace is not always ignored inside |
3774
|
1386 // the square brackets that are used to create matrix objects (though |
|
1387 // spacing only really matters in the cases that can be interpreted |
|
1388 // either as binary ops or prefix unary ops: currently just +, -). |
|
1389 // |
3779
|
1390 // Note that a line continuation directly following a + or - operator |
|
1391 // (e.g., the characters '[' 'a' ' ' '+' '\' LFD 'b' ']') will be |
|
1392 // parsed as a binary operator. |
767
|
1393 |
2857
|
1394 static bool |
3246
|
1395 next_token_is_bin_op (bool spc_prev) |
1
|
1396 { |
2857
|
1397 bool bin_op = false; |
1
|
1398 |
|
1399 int c0 = yyinput (); |
|
1400 |
|
1401 switch (c0) |
|
1402 { |
777
|
1403 case '+': |
|
1404 case '-': |
3774
|
1405 { |
|
1406 int c1 = yyinput (); |
|
1407 |
|
1408 switch (c1) |
|
1409 { |
|
1410 case '+': |
|
1411 case '-': |
|
1412 // Unary ops, spacing doesn't matter. |
|
1413 break; |
|
1414 |
|
1415 case '=': |
|
1416 // Binary ops, spacing doesn't matter. |
|
1417 bin_op = true; |
|
1418 break; |
|
1419 |
|
1420 default: |
|
1421 // Could be either, spacing matters. |
|
1422 bin_op = looks_like_bin_op (spc_prev, c1); |
|
1423 break; |
|
1424 } |
|
1425 |
4410
|
1426 yyunput (c1, yytext); |
3774
|
1427 } |
|
1428 break; |
|
1429 |
|
1430 case ':': |
3246
|
1431 case '/': |
|
1432 case '\\': |
|
1433 case '^': |
3774
|
1434 // Always a binary op (may also include /=, \=, and ^=). |
|
1435 bin_op = true; |
1276
|
1436 break; |
|
1437 |
3246
|
1438 // .+ .- ./ .\ .^ .* .** |
1554
|
1439 case '.': |
|
1440 { |
|
1441 int c1 = yyinput (); |
3246
|
1442 |
3774
|
1443 if (match_any (c1, "+-/\\^*")) |
|
1444 // Always a binary op (may also include .+=, .-=, ./=, ...). |
|
1445 bin_op = true; |
3698
|
1446 else if (! isdigit (c1) && c1 != ' ' && c1 != '\t' && c1 != '.') |
3774
|
1447 // A structure element reference is a binary op. |
|
1448 bin_op = true; |
3246
|
1449 |
4410
|
1450 yyunput (c1, yytext); |
1554
|
1451 } |
|
1452 break; |
|
1453 |
3246
|
1454 // = == & && | || * ** |
|
1455 case '=': |
1
|
1456 case '&': |
3246
|
1457 case '|': |
1
|
1458 case '*': |
3774
|
1459 // Always a binary op (may also include ==, &&, ||, **). |
|
1460 bin_op = true; |
3246
|
1461 break; |
|
1462 |
3774
|
1463 // < <= <> > >= |
1
|
1464 case '<': |
|
1465 case '>': |
3774
|
1466 // Always a binary op (may also include <=, <>, >=). |
|
1467 bin_op = true; |
|
1468 break; |
|
1469 |
|
1470 // ~= != |
777
|
1471 case '~': |
|
1472 case '!': |
3246
|
1473 { |
|
1474 int c1 = yyinput (); |
|
1475 |
3774
|
1476 // ~ and ! can be unary ops, so require following =. |
|
1477 if (c1 == '=') |
|
1478 bin_op = true; |
3246
|
1479 |
4410
|
1480 yyunput (c1, yytext); |
3246
|
1481 } |
1
|
1482 break; |
|
1483 |
|
1484 default: |
1276
|
1485 break; |
1
|
1486 } |
|
1487 |
4410
|
1488 yyunput (c0, yytext); |
1
|
1489 |
|
1490 return bin_op; |
|
1491 } |
|
1492 |
767
|
1493 // Used to delete trailing white space from tokens. |
|
1494 |
3536
|
1495 static std::string |
1
|
1496 strip_trailing_whitespace (char *s) |
|
1497 { |
3523
|
1498 std::string retval = s; |
1
|
1499 |
1823
|
1500 size_t pos = retval.find_first_of (" \t"); |
1
|
1501 |
1823
|
1502 if (pos != NPOS) |
|
1503 retval.resize (pos); |
1
|
1504 |
|
1505 return retval; |
|
1506 } |
|
1507 |
3665
|
1508 static void |
|
1509 scan_for_comments (const char *text) |
|
1510 { |
|
1511 std::string comment_buf; |
|
1512 |
|
1513 bool in_comment = false; |
|
1514 bool beginning_of_comment = false; |
|
1515 |
|
1516 int len = strlen (text); |
|
1517 int i = 0; |
|
1518 |
|
1519 while (i < len) |
|
1520 { |
|
1521 char c = text[i++]; |
|
1522 |
|
1523 switch (c) |
|
1524 { |
|
1525 case '%': |
|
1526 case '#': |
|
1527 if (in_comment) |
|
1528 { |
|
1529 if (! beginning_of_comment) |
3802
|
1530 comment_buf += static_cast<char> (c); |
3665
|
1531 } |
|
1532 else |
|
1533 { |
4037
|
1534 maybe_gripe_matlab_incompatible_comment (c); |
3665
|
1535 in_comment = true; |
|
1536 beginning_of_comment = true; |
|
1537 } |
|
1538 break; |
|
1539 |
|
1540 case '\n': |
|
1541 if (in_comment) |
|
1542 { |
3802
|
1543 comment_buf += static_cast<char> (c); |
3665
|
1544 octave_comment_buffer::append (comment_buf); |
|
1545 comment_buf.resize (0); |
|
1546 in_comment = false; |
|
1547 beginning_of_comment = false; |
|
1548 } |
|
1549 break; |
|
1550 |
|
1551 case '\r': |
|
1552 if (in_comment) |
3802
|
1553 comment_buf += static_cast<char> (c); |
3665
|
1554 if (i < len) |
|
1555 { |
|
1556 c = text[i++]; |
|
1557 |
|
1558 if (c == '\n') |
|
1559 { |
|
1560 if (in_comment) |
|
1561 { |
3802
|
1562 comment_buf += static_cast<char> (c); |
3665
|
1563 octave_comment_buffer::append (comment_buf); |
|
1564 in_comment = false; |
|
1565 beginning_of_comment = false; |
|
1566 } |
|
1567 } |
|
1568 } |
|
1569 |
|
1570 default: |
|
1571 if (in_comment) |
|
1572 { |
3802
|
1573 comment_buf += static_cast<char> (c); |
3665
|
1574 beginning_of_comment = false; |
|
1575 } |
|
1576 break; |
|
1577 } |
|
1578 } |
|
1579 |
|
1580 if (! comment_buf.empty ()) |
|
1581 octave_comment_buffer::append (comment_buf); |
|
1582 } |
|
1583 |
1001
|
1584 // Discard whitespace, including comments and continuations. |
1088
|
1585 // |
|
1586 // Return value is logical OR of the following values: |
|
1587 // |
1826
|
1588 // ATE_NOTHING : no spaces to eat |
1088
|
1589 // ATE_SPACE_OR_TAB : space or tab in input |
|
1590 // ATE_NEWLINE : bare new line in input |
1001
|
1591 |
1826
|
1592 static yum_yum |
975
|
1593 eat_whitespace (void) |
|
1594 { |
1826
|
1595 yum_yum retval = ATE_NOTHING; |
3665
|
1596 |
|
1597 std::string comment_buf; |
|
1598 |
2857
|
1599 bool in_comment = false; |
3665
|
1600 bool beginning_of_comment = false; |
|
1601 |
|
1602 int c = 0; |
|
1603 |
975
|
1604 while ((c = yyinput ()) != EOF) |
|
1605 { |
|
1606 current_input_column++; |
|
1607 |
|
1608 switch (c) |
|
1609 { |
|
1610 case ' ': |
|
1611 case '\t': |
3665
|
1612 if (in_comment) |
|
1613 { |
3802
|
1614 comment_buf += static_cast<char> (c); |
3665
|
1615 beginning_of_comment = false; |
|
1616 } |
1088
|
1617 retval |= ATE_SPACE_OR_TAB; |
975
|
1618 break; |
|
1619 |
|
1620 case '\n': |
1088
|
1621 retval |= ATE_NEWLINE; |
3665
|
1622 if (in_comment) |
|
1623 { |
3802
|
1624 comment_buf += static_cast<char> (c); |
3665
|
1625 octave_comment_buffer::append (comment_buf); |
|
1626 comment_buf.resize (0); |
|
1627 in_comment = false; |
|
1628 beginning_of_comment = false; |
|
1629 } |
975
|
1630 current_input_column = 0; |
|
1631 break; |
|
1632 |
|
1633 case '#': |
|
1634 case '%': |
3665
|
1635 if (in_comment) |
|
1636 { |
|
1637 if (! beginning_of_comment) |
3802
|
1638 comment_buf += static_cast<char> (c); |
3665
|
1639 } |
|
1640 else |
|
1641 { |
4037
|
1642 maybe_gripe_matlab_incompatible_comment (c); |
3665
|
1643 in_comment = true; |
|
1644 beginning_of_comment = true; |
|
1645 } |
975
|
1646 break; |
|
1647 |
1001
|
1648 case '.': |
|
1649 if (in_comment) |
3665
|
1650 { |
3802
|
1651 comment_buf += static_cast<char> (c); |
3665
|
1652 beginning_of_comment = false; |
|
1653 break; |
|
1654 } |
1001
|
1655 else |
|
1656 { |
|
1657 if (have_ellipsis_continuation ()) |
|
1658 break; |
|
1659 else |
|
1660 goto done; |
|
1661 } |
|
1662 |
|
1663 case '\\': |
|
1664 if (in_comment) |
3665
|
1665 { |
3802
|
1666 comment_buf += static_cast<char> (c); |
3665
|
1667 beginning_of_comment = false; |
|
1668 break; |
|
1669 } |
1001
|
1670 else |
|
1671 { |
3105
|
1672 if (have_continuation ()) |
1001
|
1673 break; |
|
1674 else |
|
1675 goto done; |
|
1676 } |
|
1677 |
6187
|
1678 case '\r': |
|
1679 if (in_comment) |
|
1680 comment_buf += static_cast<char> (c); |
|
1681 c = yyinput (); |
|
1682 if (c == EOF) |
|
1683 break; |
|
1684 else if (c == '\n') |
|
1685 { |
|
1686 retval |= ATE_NEWLINE; |
|
1687 if (in_comment) |
|
1688 { |
|
1689 comment_buf += static_cast<char> (c); |
|
1690 octave_comment_buffer::append (comment_buf); |
|
1691 in_comment = false; |
|
1692 beginning_of_comment = false; |
|
1693 } |
|
1694 current_input_column = 0; |
|
1695 break; |
|
1696 } |
|
1697 |
|
1698 // Fall through... |
|
1699 |
975
|
1700 default: |
|
1701 if (in_comment) |
3665
|
1702 { |
3802
|
1703 comment_buf += static_cast<char> (c); |
3665
|
1704 beginning_of_comment = false; |
|
1705 break; |
|
1706 } |
975
|
1707 else |
|
1708 goto done; |
|
1709 } |
|
1710 } |
|
1711 |
3665
|
1712 if (! comment_buf.empty ()) |
|
1713 octave_comment_buffer::append (comment_buf); |
|
1714 |
975
|
1715 done: |
4410
|
1716 yyunput (c, yytext); |
1082
|
1717 current_input_column--; |
1001
|
1718 return retval; |
975
|
1719 } |
|
1720 |
3220
|
1721 static inline bool |
|
1722 looks_like_hex (const char *s, int len) |
|
1723 { |
|
1724 return (len > 2 && s[0] == '0' && (s[1] == 'x' || s[1] == 'X')); |
|
1725 } |
|
1726 |
975
|
1727 static void |
3246
|
1728 handle_number (void) |
972
|
1729 { |
3220
|
1730 double value = 0.0; |
|
1731 int nread = 0; |
|
1732 |
3598
|
1733 if (looks_like_hex (yytext, strlen (yytext))) |
3220
|
1734 { |
|
1735 unsigned long ival; |
3598
|
1736 |
|
1737 nread = sscanf (yytext, "%lx", &ival); |
|
1738 |
3220
|
1739 value = static_cast<double> (ival); |
|
1740 } |
|
1741 else |
3598
|
1742 { |
|
1743 char *tmp = strsave (yytext); |
|
1744 |
|
1745 char *idx = strpbrk (tmp, "Dd"); |
2621
|
1746 |
3598
|
1747 if (idx) |
|
1748 *idx = 'e'; |
|
1749 |
|
1750 nread = sscanf (tmp, "%lf", &value); |
|
1751 |
|
1752 delete [] tmp; |
|
1753 } |
972
|
1754 |
1826
|
1755 // If yytext doesn't contain a valid number, we are in deep doo doo. |
985
|
1756 |
972
|
1757 assert (nread == 1); |
|
1758 |
3988
|
1759 lexer_flags.quote_is_transpose = true; |
|
1760 lexer_flags.convert_spaces_to_comma = true; |
972
|
1761 |
|
1762 yylval.tok_val = new token (value, yytext, input_line_number, |
|
1763 current_input_column); |
|
1764 |
|
1765 token_stack.push (yylval.tok_val); |
|
1766 |
|
1767 current_input_column += yyleng; |
|
1768 |
|
1769 do_comma_insert_check (); |
|
1770 } |
|
1771 |
1001
|
1772 // We have seen a backslash and need to find out if it should be |
|
1773 // treated as a continuation character. If so, this eats it, up to |
|
1774 // and including the new line character. |
|
1775 // |
973
|
1776 // Match whitespace only, followed by a comment character or newline. |
|
1777 // Once a comment character is found, discard all input until newline. |
|
1778 // If non-whitespace characters are found before comment |
|
1779 // characters, return 0. Otherwise, return 1. |
|
1780 |
2857
|
1781 static bool |
3096
|
1782 have_continuation (bool trailing_comments_ok) |
973
|
1783 { |
5765
|
1784 std::ostringstream buf; |
973
|
1785 |
3665
|
1786 std::string comment_buf; |
|
1787 |
2857
|
1788 bool in_comment = false; |
3665
|
1789 bool beginning_of_comment = false; |
|
1790 |
|
1791 int c = 0; |
|
1792 |
973
|
1793 while ((c = yyinput ()) != EOF) |
|
1794 { |
3802
|
1795 buf << static_cast<char> (c); |
973
|
1796 |
|
1797 switch (c) |
|
1798 { |
|
1799 case ' ': |
|
1800 case '\t': |
3665
|
1801 if (in_comment) |
|
1802 { |
3802
|
1803 comment_buf += static_cast<char> (c); |
3665
|
1804 beginning_of_comment = false; |
|
1805 } |
973
|
1806 break; |
|
1807 |
|
1808 case '%': |
|
1809 case '#': |
1091
|
1810 if (trailing_comments_ok) |
3665
|
1811 { |
|
1812 if (in_comment) |
|
1813 { |
|
1814 if (! beginning_of_comment) |
3802
|
1815 comment_buf += static_cast<char> (c); |
3665
|
1816 } |
|
1817 else |
|
1818 { |
4037
|
1819 maybe_gripe_matlab_incompatible_comment (c); |
3665
|
1820 in_comment = true; |
|
1821 beginning_of_comment = true; |
|
1822 } |
|
1823 } |
1091
|
1824 else |
|
1825 goto cleanup; |
973
|
1826 break; |
|
1827 |
|
1828 case '\n': |
3665
|
1829 if (in_comment) |
|
1830 { |
3802
|
1831 comment_buf += static_cast<char> (c); |
3665
|
1832 octave_comment_buffer::append (comment_buf); |
|
1833 } |
975
|
1834 current_input_column = 0; |
1001
|
1835 promptflag--; |
4037
|
1836 gripe_matlab_incompatible_continuation (); |
2857
|
1837 return true; |
973
|
1838 |
3263
|
1839 case '\r': |
3665
|
1840 if (in_comment) |
3802
|
1841 comment_buf += static_cast<char> (c); |
3263
|
1842 c = yyinput (); |
|
1843 if (c == EOF) |
|
1844 break; |
|
1845 else if (c == '\n') |
|
1846 { |
3665
|
1847 if (in_comment) |
|
1848 { |
3802
|
1849 comment_buf += static_cast<char> (c); |
3665
|
1850 octave_comment_buffer::append (comment_buf); |
|
1851 } |
3263
|
1852 current_input_column = 0; |
|
1853 promptflag--; |
4037
|
1854 gripe_matlab_incompatible_continuation (); |
3263
|
1855 return true; |
3665
|
1856 } |
3263
|
1857 |
3802
|
1858 // Fall through... |
|
1859 |
973
|
1860 default: |
3665
|
1861 if (in_comment) |
|
1862 { |
3802
|
1863 comment_buf += static_cast<char> (c); |
3665
|
1864 beginning_of_comment = false; |
|
1865 } |
|
1866 else |
1091
|
1867 goto cleanup; |
|
1868 break; |
973
|
1869 } |
|
1870 } |
|
1871 |
4410
|
1872 yyunput (c, yytext); |
2857
|
1873 return false; |
973
|
1874 |
3096
|
1875 cleanup: |
4051
|
1876 |
5765
|
1877 std::string s = buf.str (); |
4051
|
1878 |
|
1879 int len = s.length (); |
|
1880 while (len--) |
4410
|
1881 yyunput (s[len], yytext); |
3096
|
1882 |
2857
|
1883 return false; |
973
|
1884 } |
|
1885 |
1001
|
1886 // We have seen a `.' and need to see if it is the start of a |
|
1887 // continuation. If so, this eats it, up to and including the new |
|
1888 // line character. |
|
1889 |
2857
|
1890 static bool |
3096
|
1891 have_ellipsis_continuation (bool trailing_comments_ok) |
973
|
1892 { |
|
1893 char c1 = yyinput (); |
|
1894 if (c1 == '.') |
|
1895 { |
|
1896 char c2 = yyinput (); |
1091
|
1897 if (c2 == '.' && have_continuation (trailing_comments_ok)) |
2857
|
1898 return true; |
973
|
1899 else |
|
1900 { |
4410
|
1901 yyunput (c2, yytext); |
|
1902 yyunput (c1, yytext); |
973
|
1903 } |
|
1904 } |
|
1905 else |
4410
|
1906 yyunput (c1, yytext); |
973
|
1907 |
2857
|
1908 return false; |
973
|
1909 } |
|
1910 |
1001
|
1911 // See if we have a continuation line. If so, eat it and the leading |
|
1912 // whitespace on the next line. |
1088
|
1913 // |
|
1914 // Return value is the same as described for eat_whitespace(). |
1001
|
1915 |
1826
|
1916 static yum_yum |
1001
|
1917 eat_continuation (void) |
|
1918 { |
1826
|
1919 int retval = ATE_NOTHING; |
3665
|
1920 |
1001
|
1921 int c = yyinput (); |
3665
|
1922 |
1001
|
1923 if ((c == '.' && have_ellipsis_continuation ()) |
3105
|
1924 || (c == '\\' && have_continuation ())) |
1001
|
1925 retval = eat_whitespace (); |
|
1926 else |
4410
|
1927 yyunput (c, yytext); |
1001
|
1928 |
|
1929 return retval; |
|
1930 } |
|
1931 |
973
|
1932 static int |
975
|
1933 handle_string (char delim, int text_style) |
973
|
1934 { |
5765
|
1935 std::ostringstream buf; |
973
|
1936 |
3805
|
1937 int bos_line = input_line_number; |
|
1938 int bos_col = current_input_column; |
|
1939 |
973
|
1940 int c; |
1031
|
1941 int escape_pending = 0; |
973
|
1942 |
|
1943 while ((c = yyinput ()) != EOF) |
|
1944 { |
|
1945 current_input_column++; |
|
1946 |
3105
|
1947 if (c == '\\') |
973
|
1948 { |
5359
|
1949 if (delim == '\'' || escape_pending) |
1053
|
1950 { |
3802
|
1951 buf << static_cast<char> (c); |
1053
|
1952 escape_pending = 0; |
|
1953 } |
|
1954 else |
|
1955 { |
3096
|
1956 if (have_continuation (false)) |
1053
|
1957 escape_pending = 0; |
|
1958 else |
|
1959 { |
3802
|
1960 buf << static_cast<char> (c); |
1053
|
1961 escape_pending = 1; |
|
1962 } |
|
1963 } |
1031
|
1964 continue; |
973
|
1965 } |
|
1966 else if (c == '.') |
|
1967 { |
5359
|
1968 if (delim == '\'' || ! have_ellipsis_continuation (false)) |
3802
|
1969 buf << static_cast<char> (c); |
973
|
1970 } |
|
1971 else if (c == '\n') |
|
1972 { |
1053
|
1973 error ("unterminated string constant"); |
973
|
1974 break; |
|
1975 } |
|
1976 else if (c == delim) |
|
1977 { |
1031
|
1978 if (escape_pending) |
3802
|
1979 buf << static_cast<char> (c); |
973
|
1980 else |
|
1981 { |
|
1982 c = yyinput (); |
|
1983 if (c == delim) |
5102
|
1984 { |
|
1985 buf << static_cast<char> (c); |
|
1986 if (lexer_flags.doing_rawcommand) |
|
1987 buf << static_cast<char> (c); |
|
1988 } |
973
|
1989 else |
|
1990 { |
5102
|
1991 std::string s; |
4410
|
1992 yyunput (c, yytext); |
5765
|
1993 |
5279
|
1994 if (lexer_flags.doing_rawcommand || delim == '\'') |
5765
|
1995 s = buf.str (); |
5102
|
1996 else |
5765
|
1997 s = do_string_escapes (buf.str ()); |
975
|
1998 |
5102
|
1999 if (text_style && lexer_flags.doing_rawcommand) |
|
2000 s = std::string (1, delim) + s + std::string (1, delim); |
975
|
2001 else |
|
2002 { |
2857
|
2003 lexer_flags.quote_is_transpose = true; |
|
2004 lexer_flags.convert_spaces_to_comma = true; |
975
|
2005 } |
|
2006 |
3805
|
2007 yylval.tok_val = new token (s, bos_line, bos_col); |
973
|
2008 token_stack.push (yylval.tok_val); |
3400
|
2009 |
4037
|
2010 if (delim == '"') |
|
2011 gripe_matlab_incompatible ("\" used as string delimiter"); |
|
2012 else if (delim == '\'') |
3400
|
2013 gripe_single_quote_string (); |
|
2014 |
5279
|
2015 return delim == '"' ? DQ_STRING : SQ_STRING; |
973
|
2016 } |
|
2017 } |
|
2018 } |
|
2019 else |
|
2020 { |
3802
|
2021 buf << static_cast<char> (c); |
973
|
2022 } |
|
2023 |
1031
|
2024 escape_pending = 0; |
973
|
2025 } |
|
2026 |
|
2027 return LEXICAL_ERROR; |
|
2028 } |
|
2029 |
3208
|
2030 static bool |
|
2031 next_token_is_assign_op (void) |
|
2032 { |
|
2033 bool retval = false; |
|
2034 |
|
2035 int c0 = yyinput (); |
|
2036 |
|
2037 switch (c0) |
|
2038 { |
|
2039 case '=': |
|
2040 { |
|
2041 int c1 = yyinput (); |
4410
|
2042 yyunput (c1, yytext); |
3208
|
2043 if (c1 != '=') |
|
2044 retval = true; |
|
2045 } |
|
2046 break; |
|
2047 |
|
2048 case '+': |
|
2049 case '-': |
|
2050 case '*': |
|
2051 case '/': |
|
2052 case '\\': |
|
2053 case '&': |
|
2054 case '|': |
|
2055 { |
|
2056 int c1 = yyinput (); |
4410
|
2057 yyunput (c1, yytext); |
3208
|
2058 if (c1 == '=') |
|
2059 retval = true; |
|
2060 } |
|
2061 break; |
|
2062 |
|
2063 case '.': |
|
2064 { |
|
2065 int c1 = yyinput (); |
|
2066 if (match_any (c1, "+-*/\\")) |
|
2067 { |
|
2068 int c2 = yyinput (); |
4410
|
2069 yyunput (c2, yytext); |
3208
|
2070 if (c2 == '=') |
|
2071 retval = true; |
|
2072 } |
4410
|
2073 yyunput (c1, yytext); |
3208
|
2074 } |
|
2075 break; |
|
2076 |
|
2077 case '>': |
|
2078 { |
|
2079 int c1 = yyinput (); |
|
2080 if (c1 == '>') |
|
2081 { |
|
2082 int c2 = yyinput (); |
4410
|
2083 yyunput (c2, yytext); |
3208
|
2084 if (c2 == '=') |
|
2085 retval = true; |
|
2086 } |
4410
|
2087 yyunput (c1, yytext); |
3208
|
2088 } |
|
2089 break; |
|
2090 |
|
2091 case '<': |
|
2092 { |
|
2093 int c1 = yyinput (); |
|
2094 if (c1 == '<') |
|
2095 { |
|
2096 int c2 = yyinput (); |
4410
|
2097 yyunput (c2, yytext); |
3208
|
2098 if (c2 == '=') |
|
2099 retval = true; |
|
2100 } |
4410
|
2101 yyunput (c1, yytext); |
3208
|
2102 } |
|
2103 break; |
|
2104 |
|
2105 default: |
|
2106 break; |
|
2107 } |
|
2108 |
4410
|
2109 yyunput (c0, yytext); |
3208
|
2110 |
|
2111 return retval; |
|
2112 } |
|
2113 |
4633
|
2114 static bool |
|
2115 next_token_is_index_op (void) |
|
2116 { |
|
2117 int c = yyinput (); |
|
2118 yyunput (c, yytext); |
|
2119 return c == '(' || c == '{'; |
|
2120 } |
|
2121 |
4612
|
2122 static int |
|
2123 handle_close_bracket (bool spc_gobbled, int bracket_type) |
971
|
2124 { |
4612
|
2125 int retval = bracket_type; |
3208
|
2126 |
1826
|
2127 if (! nesting_level.none ()) |
971
|
2128 { |
1826
|
2129 nesting_level.remove (); |
4613
|
2130 |
|
2131 if (bracket_type == ']') |
|
2132 lexer_flags.bracketflag--; |
|
2133 else if (bracket_type == '}') |
|
2134 lexer_flags.braceflag--; |
|
2135 else |
|
2136 panic_impossible (); |
971
|
2137 } |
|
2138 |
4613
|
2139 if (lexer_flags.bracketflag == 0 && lexer_flags.braceflag == 0) |
4323
|
2140 BEGIN (INITIAL); |
1001
|
2141 |
4608
|
2142 if (bracket_type == ']' |
|
2143 && next_token_is_assign_op () |
|
2144 && ! lexer_flags.looking_at_return_list) |
971
|
2145 { |
3208
|
2146 retval = CLOSE_BRACE; |
971
|
2147 } |
4613
|
2148 else if ((lexer_flags.bracketflag || lexer_flags.braceflag) |
|
2149 && lexer_flags.convert_spaces_to_comma |
|
2150 && (nesting_level.is_bracket () |
|
2151 || (nesting_level.is_brace () |
|
2152 && ! lexer_flags.looking_at_object_index))) |
971
|
2153 { |
4633
|
2154 bool index_op = next_token_is_index_op (); |
|
2155 |
|
2156 // Don't insert comma if we are looking at something like |
|
2157 // |
|
2158 // [x{i}{j}] or [x{i}(j)] |
|
2159 // |
|
2160 // but do if we are looking at |
|
2161 // |
|
2162 // [x{i} {j}] or [x{i} (j)] |
|
2163 |
|
2164 if (spc_gobbled || ! (bracket_type == '}' && index_op)) |
971
|
2165 { |
4633
|
2166 bool bin_op = next_token_is_bin_op (spc_gobbled); |
|
2167 |
|
2168 bool postfix_un_op = next_token_is_postfix_unary_op (spc_gobbled); |
|
2169 |
|
2170 bool sep_op = next_token_is_sep_op (); |
|
2171 |
|
2172 if (! (postfix_un_op || bin_op || sep_op)) |
|
2173 { |
|
2174 maybe_warn_separator_insert (','); |
|
2175 |
|
2176 yyunput (',', yytext); |
|
2177 return retval; |
|
2178 } |
971
|
2179 } |
|
2180 } |
|
2181 |
2857
|
2182 lexer_flags.quote_is_transpose = true; |
|
2183 lexer_flags.convert_spaces_to_comma = true; |
3208
|
2184 |
|
2185 return retval; |
971
|
2186 } |
|
2187 |
1072
|
2188 static void |
|
2189 maybe_unput_comma (int spc_gobbled) |
|
2190 { |
4613
|
2191 if (nesting_level.is_bracket () |
|
2192 || (nesting_level.is_brace () |
|
2193 && ! lexer_flags.looking_at_object_index)) |
1072
|
2194 { |
3246
|
2195 int bin_op = next_token_is_bin_op (spc_gobbled); |
1072
|
2196 |
3246
|
2197 int postfix_un_op = next_token_is_postfix_unary_op (spc_gobbled); |
1072
|
2198 |
|
2199 int c1 = yyinput (); |
|
2200 int c2 = yyinput (); |
2970
|
2201 |
4410
|
2202 yyunput (c2, yytext); |
|
2203 yyunput (c1, yytext); |
2970
|
2204 |
3263
|
2205 int sep_op = next_token_is_sep_op (); |
2970
|
2206 |
1072
|
2207 int dot_op = (c1 == '.' |
|
2208 && (isalpha (c2) || isspace (c2) || c2 == '_')); |
2970
|
2209 |
3388
|
2210 if (postfix_un_op || bin_op || sep_op || dot_op) |
|
2211 return; |
|
2212 |
3985
|
2213 int index_op = (c1 == '(' || c1 == '{'); |
3388
|
2214 |
4476
|
2215 // If there is no space before the indexing op, we don't insert |
|
2216 // a comma. |
|
2217 |
|
2218 if (index_op && ! spc_gobbled) |
|
2219 return; |
|
2220 |
|
2221 maybe_warn_separator_insert (','); |
|
2222 |
|
2223 yyunput (',', yytext); |
1072
|
2224 } |
|
2225 } |
|
2226 |
767
|
2227 // Figure out exactly what kind of token to return when we have seen |
4238
|
2228 // an identifier. Handles keywords. Return -1 if the identifier |
|
2229 // should be ignored. |
767
|
2230 |
146
|
2231 static int |
3974
|
2232 handle_identifier (void) |
146
|
2233 { |
3974
|
2234 std::string tok = strip_trailing_whitespace (yytext); |
|
2235 |
|
2236 int c = yytext[yyleng-1]; |
|
2237 |
|
2238 int cont_is_spc = eat_continuation (); |
|
2239 |
|
2240 int spc_gobbled = (cont_is_spc || c == ' ' || c == '\t'); |
|
2241 |
2970
|
2242 // If we are expecting a structure element, avoid recognizing |
|
2243 // keywords and other special names and return STRUCT_ELT, which is |
|
2244 // a string that is also a valid identifier. But first, we have to |
|
2245 // decide whether to insert a comma. |
747
|
2246 |
1826
|
2247 if (lexer_flags.looking_at_indirect_ref) |
1072
|
2248 { |
2970
|
2249 do_comma_insert_check (); |
|
2250 |
1072
|
2251 maybe_unput_comma (spc_gobbled); |
2819
|
2252 |
|
2253 yylval.tok_val = new token (tok, input_line_number, |
|
2254 current_input_column); |
|
2255 |
|
2256 token_stack.push (yylval.tok_val); |
|
2257 |
2857
|
2258 lexer_flags.quote_is_transpose = true; |
|
2259 lexer_flags.convert_spaces_to_comma = true; |
2819
|
2260 |
|
2261 current_input_column += yyleng; |
|
2262 |
2970
|
2263 return STRUCT_ELT; |
1072
|
2264 } |
747
|
2265 |
4930
|
2266 int kw_token = is_keyword_token (tok); |
|
2267 |
|
2268 if (lexer_flags.looking_at_function_handle) |
|
2269 { |
|
2270 if (kw_token) |
|
2271 { |
|
2272 error ("function handles may not refer to keywords"); |
|
2273 |
|
2274 return LEXICAL_ERROR; |
|
2275 } |
|
2276 else |
|
2277 TOK_PUSH_AND_RETURN (tok, FCN_HANDLE); |
|
2278 } |
|
2279 |
5102
|
2280 // If we have a regular keyword, return it. |
1826
|
2281 // Keywords can be followed by identifiers (TOK_RETURN handles |
|
2282 // that). |
146
|
2283 |
|
2284 if (kw_token) |
|
2285 { |
4238
|
2286 if (kw_token < 0) |
|
2287 return kw_token; |
146
|
2288 else |
|
2289 TOK_RETURN (kw_token); |
|
2290 } |
|
2291 |
1826
|
2292 // See if we have a plot keyword (title, using, with, or clear). |
146
|
2293 |
3480
|
2294 int c1 = yyinput (); |
|
2295 |
|
2296 bool next_tok_is_paren = (c1 == '('); |
|
2297 |
|
2298 bool next_tok_is_eq = false; |
|
2299 if (c1 == '=') |
|
2300 { |
|
2301 int c2 = yyinput (); |
4410
|
2302 yyunput (c2, yytext); |
3480
|
2303 |
|
2304 if (c2 != '=') |
|
2305 next_tok_is_eq = true; |
|
2306 } |
|
2307 |
4410
|
2308 yyunput (c1, yytext); |
1001
|
2309 |
1826
|
2310 // Make sure we put the return values of a function in the symbol |
|
2311 // table that is local to the function. |
146
|
2312 |
2877
|
2313 // If we are defining a function and we have not seen the function |
|
2314 // name yet and the next token is `=', then this identifier must be |
|
2315 // the only return value for the function and it belongs in the |
|
2316 // local symbol table. |
|
2317 |
1826
|
2318 if (next_tok_is_eq |
2877
|
2319 && lexer_flags.defining_func |
|
2320 && ! lexer_flags.parsed_function_name) |
146
|
2321 curr_sym_tab = tmp_local_sym_tab; |
|
2322 |
2702
|
2323 // Kluge alert. |
|
2324 // |
|
2325 // If we are looking at a text style function, set up to gobble its |
2745
|
2326 // arguments. |
|
2327 // |
|
2328 // If the following token is `=', or if we are parsing a function |
3189
|
2329 // return list or function parameter list, or if we are looking at |
|
2330 // something like [ab,cd] = foo (), force the symbol to be inserted |
|
2331 // as a variable in the current symbol table. |
2702
|
2332 |
4208
|
2333 if (is_command_name (tok) && ! is_variable (tok)) |
2702
|
2334 { |
2745
|
2335 if (next_tok_is_eq |
|
2336 || lexer_flags.looking_at_return_list |
3189
|
2337 || lexer_flags.looking_at_parameter_list |
4101
|
2338 || lexer_flags.looking_at_matrix_or_assign_lhs) |
2745
|
2339 { |
|
2340 force_local_variable (tok); |
|
2341 } |
6067
|
2342 else if (! (next_tok_is_paren || lexer_flags.looking_at_object_index)) |
2702
|
2343 { |
5102
|
2344 BEGIN (COMMAND_START); |
|
2345 } |
|
2346 |
6067
|
2347 if (is_rawcommand_name (tok) && ! lexer_flags.looking_at_object_index) |
5102
|
2348 { |
|
2349 lexer_flags.doing_rawcommand = true; |
4323
|
2350 BEGIN (COMMAND_START); |
2702
|
2351 } |
|
2352 } |
|
2353 |
4234
|
2354 // Find the token in the symbol table. Beware the magic |
|
2355 // transformation of the end keyword... |
|
2356 |
|
2357 if (tok == "end") |
|
2358 tok = "__end__"; |
146
|
2359 |
|
2360 yylval.tok_val = new token (lookup_identifier (tok), |
|
2361 input_line_number, |
|
2362 current_input_column); |
|
2363 |
|
2364 token_stack.push (yylval.tok_val); |
|
2365 |
1826
|
2366 // After seeing an identifer, it is ok to convert spaces to a comma |
|
2367 // (if needed). |
146
|
2368 |
2857
|
2369 lexer_flags.convert_spaces_to_comma = true; |
146
|
2370 |
2877
|
2371 if (! next_tok_is_eq) |
|
2372 { |
|
2373 lexer_flags.quote_is_transpose = true; |
146
|
2374 |
2877
|
2375 do_comma_insert_check (); |
|
2376 |
|
2377 maybe_unput_comma (spc_gobbled); |
146
|
2378 } |
|
2379 |
2877
|
2380 current_input_column += yyleng; |
146
|
2381 |
|
2382 return NAME; |
|
2383 } |
|
2384 |
1826
|
2385 void |
|
2386 lexical_feedback::init (void) |
|
2387 { |
|
2388 // Not initially defining a matrix list. |
3351
|
2389 bracketflag = 0; |
1826
|
2390 |
4613
|
2391 // Not initially defining a cell array list. |
|
2392 braceflag = 0; |
|
2393 |
1826
|
2394 // Not initially inside a loop or if statement. |
|
2395 looping = 0; |
|
2396 |
2857
|
2397 // Not initially defining a function. |
|
2398 beginning_of_function = false; |
|
2399 defining_func = false; |
2877
|
2400 parsed_function_name = false; |
4240
|
2401 parsing_nested_function = 0; |
2857
|
2402 |
4930
|
2403 // Not initiallly looking at a function handle. |
|
2404 looking_at_function_handle = 0; |
|
2405 |
2857
|
2406 // Not parsing a function return or parameter list. |
|
2407 looking_at_return_list = false; |
|
2408 looking_at_parameter_list = false; |
|
2409 |
3796
|
2410 // Not parsing a matrix or the left hand side of multi-value |
|
2411 // assignment statement. |
|
2412 looking_at_matrix_or_assign_lhs = false; |
|
2413 |
4234
|
2414 // Not parsing an object index. |
4237
|
2415 looking_at_object_index = 0; |
4234
|
2416 |
2857
|
2417 // No need to do comma insert or convert spaces to comma at |
|
2418 // beginning of input. |
|
2419 convert_spaces_to_comma = true; |
|
2420 do_comma_insert = false; |
|
2421 |
|
2422 // Not initially doing any plotting or setting of plot attributes. |
5102
|
2423 doing_rawcommand = false; |
2857
|
2424 |
1826
|
2425 // Not initially looking at indirect references. |
2857
|
2426 looking_at_indirect_ref = false; |
1826
|
2427 |
|
2428 // Quote marks strings intially. |
2857
|
2429 quote_is_transpose = false; |
1826
|
2430 } |
|
2431 |
4867
|
2432 bool |
|
2433 is_keyword (const std::string& s) |
|
2434 { |
5088
|
2435 return octave_kw_hash::in_word_set (s.c_str (), s.length ()) != 0; |
4867
|
2436 } |
|
2437 |
4264
|
2438 DEFCMD (iskeyword, args, , |
|
2439 "-*- texinfo -*-\n\ |
|
2440 @deftypefn {Built-in Function} {} iskeyword (@var{name})\n\ |
|
2441 Return true if @var{name} is an Octave keyword. If @var{name}\n\ |
|
2442 is omitted, return a list of keywords.\n\ |
|
2443 @end deftypefn") |
|
2444 { |
|
2445 octave_value retval; |
|
2446 |
|
2447 int argc = args.length () + 1; |
|
2448 |
4867
|
2449 string_vector argv = args.make_argv ("iskeyword"); |
4264
|
2450 |
|
2451 if (error_state) |
|
2452 return retval; |
|
2453 |
|
2454 if (argc == 1) |
|
2455 { |
|
2456 string_vector lst (TOTAL_KEYWORDS); |
|
2457 |
|
2458 for (int i = 0; i < TOTAL_KEYWORDS; i++) |
|
2459 lst[i] = wordlist[i].name; |
|
2460 |
|
2461 retval = Cell (lst.qsort ()); |
|
2462 } |
|
2463 else if (argc == 2) |
|
2464 { |
4867
|
2465 retval = is_keyword (argv[1]); |
4264
|
2466 } |
|
2467 else |
5823
|
2468 print_usage (); |
4264
|
2469 |
|
2470 return retval; |
|
2471 } |
|
2472 |
|
2473 |
3388
|
2474 static void |
|
2475 maybe_warn_separator_insert (char sep) |
|
2476 { |
3523
|
2477 std::string nm = curr_fcn_file_full_name; |
3388
|
2478 |
5794
|
2479 if (nm.empty ()) |
|
2480 warning_with_id ("Octave:separator-insert", |
|
2481 "potential auto-insertion of `%c' near line %d", |
|
2482 sep, input_line_number); |
|
2483 else |
|
2484 warning_with_id ("Octave:separator-insert", |
|
2485 "potential auto-insertion of `%c' near line %d of file %s", |
|
2486 sep, input_line_number, nm.c_str ()); |
3388
|
2487 } |
|
2488 |
3400
|
2489 static void |
|
2490 gripe_single_quote_string (void) |
|
2491 { |
3523
|
2492 std::string nm = curr_fcn_file_full_name; |
3400
|
2493 |
5794
|
2494 if (nm.empty ()) |
|
2495 warning_with_id ("Octave:single-quote-string", |
|
2496 "single quote delimited string near line %d", |
|
2497 input_line_number); |
|
2498 else |
|
2499 warning_with_id ("Octave:single-quote-string", |
|
2500 "single quote delimited string near line %d of file %s", |
|
2501 input_line_number, nm.c_str ()); |
3400
|
2502 } |
|
2503 |
4037
|
2504 static void |
|
2505 gripe_matlab_incompatible (const std::string& msg) |
|
2506 { |
5794
|
2507 warning_with_id ("Octave:matlab-incompatible", |
|
2508 "potential Matlab compatibility problem: %s", |
|
2509 msg.c_str ()); |
4037
|
2510 } |
|
2511 |
|
2512 static void |
|
2513 maybe_gripe_matlab_incompatible_comment (char c) |
|
2514 { |
|
2515 if (c == '#') |
|
2516 gripe_matlab_incompatible ("# used as comment character"); |
|
2517 } |
|
2518 |
|
2519 static void |
|
2520 gripe_matlab_incompatible_continuation (void) |
|
2521 { |
|
2522 gripe_matlab_incompatible ("\\ used as line continuation marker"); |
|
2523 } |
|
2524 |
|
2525 static void |
|
2526 gripe_matlab_incompatible_operator (const std::string& op) |
|
2527 { |
|
2528 std::string t = op; |
|
2529 int n = t.length (); |
|
2530 if (t[n-1] == '\n') |
|
2531 t.resize (n-1); |
|
2532 gripe_matlab_incompatible (t + " used as operator"); |
|
2533 } |
|
2534 |
4910
|
2535 DEFUN (__token_count__, , , |
|
2536 "-*- texinfo -*-\n\ |
|
2537 @deftypefn {Built-in Function} {} __token_count__\n\ |
|
2538 Number of language tokens processed since Octave startup.\n\ |
|
2539 @end deftypefn") |
|
2540 { |
|
2541 return octave_value (Vtoken_count); |
|
2542 } |
|
2543 |
1994
|
2544 /* |
|
2545 ;;; Local Variables: *** |
|
2546 ;;; mode: C++ *** |
|
2547 ;;; End: *** |
|
2548 */ |