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 |
7016
|
9 Free Software Foundation; either version 3 of the License, or (at your |
|
10 option) any later version. |
1
|
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 |
7016
|
18 along with Octave; see the file COPYING. If not, see |
|
19 <http://www.gnu.org/licenses/>. |
1
|
20 |
|
21 */ |
|
22 |
4753
|
23 %option prefix = "octave_" |
|
24 |
4208
|
25 %s COMMAND_START |
|
26 %s MATRIX_START |
4240
|
27 |
|
28 %x NESTED_FUNCTION_END |
|
29 %x NESTED_FUNCTION_BEGIN |
1
|
30 |
|
31 %{ |
240
|
32 #ifdef HAVE_CONFIG_H |
1220
|
33 #include <config.h> |
240
|
34 #endif |
|
35 |
1341
|
36 #include <cctype> |
|
37 #include <cstring> |
|
38 |
5765
|
39 #include <sstream> |
1823
|
40 #include <string> |
4214
|
41 #include <stack> |
1823
|
42 |
4093
|
43 #ifdef HAVE_UNISTD_H |
|
44 #ifdef HAVE_SYS_TYPES_H |
|
45 #include <sys/types.h> |
|
46 #endif |
|
47 #include <unistd.h> |
|
48 #endif |
|
49 |
2926
|
50 #include "cmd-edit.h" |
4153
|
51 #include "quit.h" |
4910
|
52 #include "lo-mappers.h" |
2926
|
53 |
1497
|
54 // These would be alphabetical, but y.tab.h must be included before |
|
55 // oct-gperf.h and y.tab.h must be included after token.h and the tree |
|
56 // class declarations. We can't include y.tab.h in oct-gperf.h |
|
57 // because it may not be protected to allow it to be included multiple |
|
58 // times. |
|
59 |
4264
|
60 #include "Cell.h" |
3665
|
61 #include "comment-list.h" |
2181
|
62 #include "defun.h" |
1355
|
63 #include "error.h" |
4910
|
64 #include "gripes.h" |
1351
|
65 #include "input.h" |
1355
|
66 #include "lex.h" |
2891
|
67 #include "ov.h" |
1355
|
68 #include "parse.h" |
2987
|
69 #include "pt-all.h" |
2891
|
70 #include "symtab.h" |
|
71 #include "token.h" |
|
72 #include "toplev.h" |
1355
|
73 #include "utils.h" |
|
74 #include "variables.h" |
2492
|
75 #include <y.tab.h> |
|
76 #include <oct-gperf.h> |
1
|
77 |
2716
|
78 #if ! (defined (FLEX_SCANNER) \ |
|
79 && defined (YY_FLEX_MAJOR_VERSION) && YY_FLEX_MAJOR_VERSION >= 2 \ |
|
80 && defined (YY_FLEX_MINOR_VERSION) && YY_FLEX_MINOR_VERSION >= 5) |
|
81 #error lex.l requires flex version 2.5.4 or later |
|
82 #endif |
|
83 |
4753
|
84 #define yylval octave_lval |
|
85 |
|
86 // Arrange to get input via readline. |
|
87 |
|
88 #ifdef YY_INPUT |
|
89 #undef YY_INPUT |
|
90 #endif |
|
91 #define YY_INPUT(buf, result, max_size) \ |
|
92 if ((result = octave_read (buf, max_size)) < 0) \ |
|
93 YY_FATAL_ERROR ("octave_read () in flex scanner failed"); |
|
94 |
|
95 // Try to avoid crashing out completely on fatal scanner errors. |
|
96 // The call to yy_fatal_error should never happen, but it avoids a |
|
97 // `static function defined but not used' warning from gcc. |
|
98 |
|
99 #ifdef YY_FATAL_ERROR |
|
100 #undef YY_FATAL_ERROR |
|
101 #endif |
|
102 #define YY_FATAL_ERROR(msg) \ |
|
103 do \ |
|
104 { \ |
|
105 error (msg); \ |
|
106 OCTAVE_QUIT; \ |
|
107 yy_fatal_error (msg); \ |
|
108 } \ |
|
109 while (0) |
|
110 |
4910
|
111 #define COUNT_TOK_AND_RETURN(tok) \ |
|
112 do \ |
|
113 { \ |
|
114 Vtoken_count++; \ |
|
115 return tok; \ |
|
116 } \ |
|
117 while (0) |
|
118 |
4753
|
119 #define TOK_RETURN(tok) \ |
|
120 do \ |
|
121 { \ |
|
122 current_input_column += yyleng; \ |
|
123 lexer_flags.quote_is_transpose = false; \ |
|
124 lexer_flags.convert_spaces_to_comma = true; \ |
4910
|
125 COUNT_TOK_AND_RETURN (tok); \ |
4753
|
126 } \ |
|
127 while (0) |
|
128 |
|
129 #define TOK_PUSH_AND_RETURN(name, tok) \ |
|
130 do \ |
|
131 { \ |
|
132 yylval.tok_val = new token (name, input_line_number, \ |
|
133 current_input_column); \ |
|
134 token_stack.push (yylval.tok_val); \ |
|
135 TOK_RETURN (tok); \ |
|
136 } \ |
|
137 while (0) |
|
138 |
|
139 #define BIN_OP_RETURN(tok, convert) \ |
|
140 do \ |
|
141 { \ |
|
142 yylval.tok_val = new token (input_line_number, current_input_column); \ |
|
143 token_stack.push (yylval.tok_val); \ |
|
144 current_input_column += yyleng; \ |
|
145 lexer_flags.quote_is_transpose = false; \ |
|
146 lexer_flags.convert_spaces_to_comma = convert; \ |
4910
|
147 COUNT_TOK_AND_RETURN (tok); \ |
4753
|
148 } \ |
|
149 while (0) |
|
150 |
|
151 #define XBIN_OP_RETURN(tok, convert) \ |
|
152 do \ |
|
153 { \ |
|
154 gripe_matlab_incompatible_operator (yytext); \ |
|
155 BIN_OP_RETURN (tok, convert); \ |
|
156 } \ |
|
157 while (0) |
|
158 |
3883
|
159 // TRUE means that we have encountered EOF on the input stream. |
|
160 bool parser_end_of_input = false; |
|
161 |
1826
|
162 // Flags that need to be shared between the lexer and parser. |
|
163 lexical_feedback lexer_flags; |
|
164 |
1351
|
165 // Stack to hold tokens so that we can delete them when the parser is |
|
166 // reset and avoid growing forever just because we are stashing some |
|
167 // information. This has to appear before lex.h is included, because |
|
168 // one of the macros defined there uses token_stack. |
2614
|
169 // |
5775
|
170 // FIXME -- this should really be static, but that causes |
2614
|
171 // problems on some systems. |
4214
|
172 std::stack <token*> token_stack; |
1351
|
173 |
1826
|
174 // Did eat_whitespace() eat a space or tab, or a newline, or both? |
1
|
175 |
1826
|
176 typedef int yum_yum; |
1
|
177 |
1826
|
178 const yum_yum ATE_NOTHING = 0; |
|
179 const yum_yum ATE_SPACE_OR_TAB = 1; |
|
180 const yum_yum ATE_NEWLINE = 2; |
1088
|
181 |
3351
|
182 // Is the closest nesting level a square bracket, squiggly brace or a paren? |
1826
|
183 |
4214
|
184 class bracket_brace_paren_nesting_level |
1826
|
185 { |
|
186 public: |
|
187 |
4214
|
188 bracket_brace_paren_nesting_level (void) : context () { } |
1826
|
189 |
3351
|
190 ~bracket_brace_paren_nesting_level (void) { } |
|
191 |
4214
|
192 void bracket (void) { context.push (BRACKET); } |
|
193 bool is_bracket (void) |
|
194 { return ! context.empty () && context.top () == BRACKET; } |
|
195 |
|
196 void brace (void) { context.push (BRACE); } |
|
197 bool is_brace (void) |
|
198 { return ! context.empty () && context.top () == BRACE; } |
|
199 |
|
200 void paren (void) { context.push (PAREN); } |
|
201 bool is_paren (void) |
|
202 { return ! context.empty () && context.top () == PAREN; } |
|
203 |
4608
|
204 bool is_bracket_or_brace (void) |
|
205 { return (! context.empty () |
|
206 && (context.top () == BRACKET || context.top () == BRACE)); } |
|
207 |
4214
|
208 bool none (void) { return context.empty (); } |
|
209 |
|
210 void remove (void) { if (! context.empty ()) context.pop (); } |
|
211 |
|
212 void clear (void) { while (! context.empty ()) context.pop (); } |
1826
|
213 |
|
214 private: |
|
215 |
4214
|
216 std::stack<int> context; |
|
217 |
5225
|
218 static const int BRACKET; |
|
219 static const int BRACE; |
|
220 static const int PAREN; |
1826
|
221 |
3351
|
222 bracket_brace_paren_nesting_level (const bracket_brace_paren_nesting_level&); |
1826
|
223 |
3351
|
224 bracket_brace_paren_nesting_level& |
|
225 operator = (const bracket_brace_paren_nesting_level&); |
1826
|
226 }; |
|
227 |
5225
|
228 const int bracket_brace_paren_nesting_level::BRACKET = 1; |
|
229 const int bracket_brace_paren_nesting_level::BRACE = 2; |
|
230 const int bracket_brace_paren_nesting_level::PAREN = 3; |
|
231 |
3351
|
232 static bracket_brace_paren_nesting_level nesting_level; |
1
|
233 |
4910
|
234 static unsigned int Vtoken_count = 0; |
|
235 |
146
|
236 // Forward declarations for functions defined at the bottom of this |
|
237 // file. |
|
238 |
1
|
239 static void fixup_column_count (char *s); |
146
|
240 static void do_comma_insert_check (void); |
4867
|
241 static int is_keyword_token (const std::string& s); |
4238
|
242 static void prep_for_function (void); |
|
243 static void prep_for_nested_function (void); |
3523
|
244 static symbol_record *lookup_identifier (const std::string& s); |
4426
|
245 static std::string grab_help_text (void); |
2857
|
246 static bool match_any (char c, const char *s); |
3263
|
247 static bool next_token_is_sep_op (void); |
3246
|
248 static bool next_token_is_bin_op (bool spc_prev); |
|
249 static bool next_token_is_postfix_unary_op (bool spc_prev); |
3523
|
250 static std::string strip_trailing_whitespace (char *s); |
3246
|
251 static void handle_number (void); |
975
|
252 static int handle_string (char delim, int text_style = 0); |
4612
|
253 static int handle_close_bracket (bool spc_gobbled, int bracket_type); |
3974
|
254 static int handle_identifier (void); |
3096
|
255 static bool have_continuation (bool trailing_comments_ok = true); |
|
256 static bool have_ellipsis_continuation (bool trailing_comments_ok = true); |
3665
|
257 static void scan_for_comments (const char *); |
1826
|
258 static yum_yum eat_whitespace (void); |
|
259 static yum_yum eat_continuation (void); |
3388
|
260 static void maybe_warn_separator_insert (char sep); |
3400
|
261 static void gripe_single_quote_string (void); |
4037
|
262 static void gripe_matlab_incompatible (const std::string& msg); |
|
263 static void maybe_gripe_matlab_incompatible_comment (char c); |
|
264 static void gripe_matlab_incompatible_continuation (void); |
|
265 static void gripe_matlab_incompatible_operator (const std::string& op); |
1
|
266 |
|
267 %} |
|
268 |
|
269 D [0-9] |
|
270 S [ \t] |
5570
|
271 NL ((\n)|(\r)|(\r\n)) |
2042
|
272 SNL ({S}|{NL}) |
1
|
273 EL (\.\.\.) |
967
|
274 BS (\\) |
|
275 CONT ({EL}|{BS}) |
1
|
276 Im [iIjJ] |
967
|
277 CCHAR [#%] |
|
278 COMMENT ({CCHAR}.*{NL}) |
|
279 SNLCMT ({SNL}|{COMMENT}) |
|
280 NOT ((\~)|(\!)) |
4037
|
281 POW ((\*\*)|(\^)) |
|
282 EPOW (\.{POW}) |
5290
|
283 IDENT ([_$a-zA-Z][_$a-zA-Z0-9]*) |
1
|
284 EXPON ([DdEe][+-]?{D}+) |
3220
|
285 NUMBER (({D}+\.?{D}*{EXPON}?)|(\.{D}+{EXPON}?)|(0[xX][0-9a-fA-F]+)) |
1
|
286 %% |
|
287 |
4240
|
288 <NESTED_FUNCTION_END>. { |
4323
|
289 BEGIN (NESTED_FUNCTION_BEGIN); |
4410
|
290 yyunput (yytext[0], yytext); |
4910
|
291 COUNT_TOK_AND_RETURN (';'); |
4240
|
292 } |
|
293 |
|
294 <NESTED_FUNCTION_BEGIN>. { |
4323
|
295 BEGIN (INITIAL); |
4410
|
296 yyunput (yytext[0], yytext); |
4238
|
297 prep_for_nested_function (); |
4910
|
298 COUNT_TOK_AND_RETURN (FCN); |
4238
|
299 } |
|
300 |
968
|
301 %{ |
4208
|
302 // Help and other command-style functions are a pain in the ass. This |
968
|
303 // stuff needs to be simplified. May require some changes in the |
|
304 // parser too. |
|
305 %} |
|
306 |
4208
|
307 <COMMAND_START>{NL} { |
4323
|
308 BEGIN (INITIAL); |
967
|
309 current_input_column = 1; |
2857
|
310 lexer_flags.quote_is_transpose = false; |
|
311 lexer_flags.convert_spaces_to_comma = true; |
5212
|
312 lexer_flags.doing_rawcommand = false; |
4910
|
313 COUNT_TOK_AND_RETURN ('\n'); |
967
|
314 } |
1
|
315 |
4208
|
316 <COMMAND_START>[\;\,] { |
5102
|
317 if (lexer_flags.doing_rawcommand) |
5279
|
318 TOK_PUSH_AND_RETURN (yytext, SQ_STRING); |
5102
|
319 |
|
320 BEGIN (INITIAL); |
|
321 |
|
322 if (strcmp (yytext, ",") == 0) |
|
323 TOK_RETURN (','); |
967
|
324 else |
5102
|
325 TOK_RETURN (';'); |
967
|
326 } |
1
|
327 |
4208
|
328 <COMMAND_START>[\"\'] { |
975
|
329 current_input_column++; |
4910
|
330 COUNT_TOK_AND_RETURN (handle_string (yytext[0], true)); |
975
|
331 } |
|
332 |
4923
|
333 <COMMAND_START>[^#% \t\r\n\;\,\"\'][^ \t\r\n\;\,]*{S}* { |
3523
|
334 std::string tok = strip_trailing_whitespace (yytext); |
5279
|
335 TOK_PUSH_AND_RETURN (tok, SQ_STRING); |
967
|
336 } |
1
|
337 |
968
|
338 %{ |
1
|
339 // For this and the next two rules, we're looking at ']', and we |
971
|
340 // need to know if the next token is `=' or `=='. |
1
|
341 // |
|
342 // It would have been so much easier if the delimiters were simply |
|
343 // different for the expression on the left hand side of the equals |
|
344 // operator. |
971
|
345 // |
|
346 // It's also a pain in the ass to decide whether to insert a comma |
|
347 // after seeing a ']' character... |
968
|
348 %} |
|
349 |
4208
|
350 <MATRIX_START>{SNLCMT}*\]{S}* { |
3665
|
351 scan_for_comments (yytext); |
1001
|
352 fixup_column_count (yytext); |
|
353 int c = yytext[yyleng-1]; |
|
354 int cont_is_spc = eat_continuation (); |
4608
|
355 bool spc_gobbled = (cont_is_spc || c == ' ' || c == '\t'); |
5345
|
356 int tok_to_return = handle_close_bracket (spc_gobbled, ']'); |
|
357 if (spc_gobbled) |
|
358 yyunput (' ', yytext); |
|
359 COUNT_TOK_AND_RETURN (tok_to_return); |
4608
|
360 } |
|
361 |
|
362 <MATRIX_START>{SNLCMT}*\}{S}* { |
|
363 scan_for_comments (yytext); |
|
364 fixup_column_count (yytext); |
|
365 int c = yytext[yyleng-1]; |
|
366 int cont_is_spc = eat_continuation (); |
|
367 bool spc_gobbled = (cont_is_spc || c == ' ' || c == '\t'); |
5345
|
368 int tok_to_return = handle_close_bracket (spc_gobbled, '}'); |
|
369 if (spc_gobbled) |
|
370 yyunput (' ', yytext); |
|
371 COUNT_TOK_AND_RETURN (tok_to_return); |
967
|
372 } |
1
|
373 |
968
|
374 %{ |
1088
|
375 // Commas are element separators in matrix constants. If we don't |
|
376 // check for continuations here we can end up inserting too many |
|
377 // commas. |
968
|
378 %} |
|
379 |
4208
|
380 <MATRIX_START>{S}*\,{S}* { |
1088
|
381 current_input_column += yyleng; |
3388
|
382 |
1088
|
383 int tmp = eat_continuation (); |
3388
|
384 |
2857
|
385 lexer_flags.quote_is_transpose = false; |
|
386 lexer_flags.convert_spaces_to_comma = true; |
3388
|
387 |
|
388 if ((tmp & ATE_NEWLINE) == ATE_NEWLINE) |
|
389 { |
|
390 maybe_warn_separator_insert (';'); |
|
391 |
4476
|
392 yyunput (';', yytext); |
3388
|
393 } |
|
394 |
4910
|
395 COUNT_TOK_AND_RETURN (','); |
967
|
396 } |
1
|
397 |
968
|
398 %{ |
|
399 // In some cases, spaces in matrix constants can turn into commas. |
|
400 // If commas are required, spaces are not important in matrix |
1088
|
401 // constants so we just eat them. If we don't check for continuations |
|
402 // here we can end up inserting too many commas. |
968
|
403 %} |
430
|
404 |
4208
|
405 <MATRIX_START>{S}+ { |
1088
|
406 current_input_column += yyleng; |
3388
|
407 |
|
408 int tmp = eat_continuation (); |
|
409 int bin_op = next_token_is_bin_op (true); |
|
410 int postfix_un_op = next_token_is_postfix_unary_op (true); |
|
411 |
|
412 if (! (postfix_un_op || bin_op) |
4608
|
413 && nesting_level.is_bracket_or_brace () |
3388
|
414 && lexer_flags.convert_spaces_to_comma) |
967
|
415 { |
3388
|
416 if ((tmp & ATE_NEWLINE) == ATE_NEWLINE) |
|
417 { |
|
418 maybe_warn_separator_insert (';'); |
967
|
419 |
4476
|
420 yyunput (';', yytext); |
3388
|
421 } |
|
422 |
4476
|
423 lexer_flags.quote_is_transpose = false; |
|
424 lexer_flags.convert_spaces_to_comma = true; |
|
425 |
|
426 maybe_warn_separator_insert (','); |
|
427 |
4910
|
428 COUNT_TOK_AND_RETURN (','); |
967
|
429 } |
|
430 } |
430
|
431 |
968
|
432 %{ |
1088
|
433 // Semicolons are handled as row seprators in matrix constants. If we |
|
434 // don't eat whitespace here we can end up inserting too many |
|
435 // semicolons. |
968
|
436 %} |
|
437 |
4208
|
438 <MATRIX_START>{SNLCMT}*;{SNLCMT}* { |
3665
|
439 scan_for_comments (yytext); |
967
|
440 fixup_column_count (yytext); |
1001
|
441 eat_whitespace (); |
2857
|
442 lexer_flags.quote_is_transpose = false; |
|
443 lexer_flags.convert_spaces_to_comma = true; |
4910
|
444 COUNT_TOK_AND_RETURN (';'); |
967
|
445 } |
|
446 |
968
|
447 %{ |
1088
|
448 // In some cases, new lines can also become row separators. If we |
|
449 // don't eat whitespace here we can end up inserting too many |
|
450 // semicolons. |
985
|
451 %} |
|
452 |
4208
|
453 <MATRIX_START>{S}*{COMMENT}{SNLCMT}* | |
|
454 <MATRIX_START>{S}*{NL}{SNLCMT}* { |
3665
|
455 scan_for_comments (yytext); |
1082
|
456 fixup_column_count (yytext); |
1088
|
457 eat_whitespace (); |
3388
|
458 |
4476
|
459 lexer_flags.quote_is_transpose = false; |
|
460 lexer_flags.convert_spaces_to_comma = true; |
|
461 |
|
462 if (nesting_level.none ()) |
|
463 return LEXICAL_ERROR; |
985
|
464 |
4608
|
465 if (nesting_level.is_bracket_or_brace ()) |
3388
|
466 { |
|
467 maybe_warn_separator_insert (';'); |
|
468 |
4910
|
469 COUNT_TOK_AND_RETURN (';'); |
985
|
470 } |
|
471 } |
|
472 |
967
|
473 \[{S}* { |
3351
|
474 nesting_level.bracket (); |
975
|
475 |
1082
|
476 current_input_column += yyleng; |
2857
|
477 lexer_flags.quote_is_transpose = false; |
|
478 lexer_flags.convert_spaces_to_comma = true; |
975
|
479 |
5615
|
480 if (lexer_flags.defining_func && ! lexer_flags.parsed_function_name) |
|
481 lexer_flags.looking_at_return_list = true; |
|
482 else |
|
483 lexer_flags.looking_at_matrix_or_assign_lhs = true; |
|
484 |
975
|
485 promptflag--; |
|
486 eat_whitespace (); |
|
487 |
5102
|
488 lexer_flags.bracketflag++; |
|
489 BEGIN (MATRIX_START); |
|
490 COUNT_TOK_AND_RETURN ('['); |
967
|
491 } |
1
|
492 |
968
|
493 \] { |
1826
|
494 nesting_level.remove (); |
968
|
495 |
5102
|
496 TOK_RETURN (']'); |
968
|
497 } |
|
498 |
|
499 %{ |
|
500 // Imaginary numbers. |
|
501 %} |
|
502 |
|
503 {NUMBER}{Im} { |
3246
|
504 handle_number (); |
4910
|
505 COUNT_TOK_AND_RETURN (IMAG_NUM); |
968
|
506 } |
|
507 |
|
508 %{ |
|
509 // Real numbers. Don't grab the `.' part of a dot operator as part of |
|
510 // the constant. |
|
511 %} |
|
512 |
|
513 {D}+/\.[\*/\\^'] | |
|
514 {NUMBER} { |
3246
|
515 handle_number (); |
4910
|
516 COUNT_TOK_AND_RETURN (NUM); |
968
|
517 } |
|
518 |
|
519 %{ |
|
520 // Eat whitespace. Whitespace inside matrix constants is handled by |
4208
|
521 // the <MATRIX_START> start state code above. |
968
|
522 %} |
|
523 |
967
|
524 {S}* { |
|
525 current_input_column += yyleng; |
|
526 } |
|
527 |
968
|
528 %{ |
|
529 // Continuation lines. Allow comments after continuations. |
|
530 %} |
|
531 |
967
|
532 {CONT}{S}*{NL} | |
|
533 {CONT}{S}*{COMMENT} { |
4037
|
534 if (yytext[0] == '\\') |
|
535 gripe_matlab_incompatible_continuation (); |
3665
|
536 scan_for_comments (yytext); |
967
|
537 promptflag--; |
|
538 current_input_column = 1; |
|
539 } |
1
|
540 |
968
|
541 %{ |
|
542 // End of file. |
|
543 %} |
|
544 |
967
|
545 <<EOF>> { |
|
546 TOK_RETURN (END_OF_INPUT); |
|
547 } |
1
|
548 |
968
|
549 %{ |
970
|
550 // Identifiers. Truncate the token at the first space or tab but |
|
551 // don't write directly on yytext. |
968
|
552 %} |
|
553 |
967
|
554 {IDENT}{S}* { |
4238
|
555 int id_tok = handle_identifier (); |
|
556 |
|
557 if (id_tok >= 0) |
4910
|
558 COUNT_TOK_AND_RETURN (id_tok); |
967
|
559 } |
1
|
560 |
968
|
561 %{ |
4342
|
562 // Function handles. |
|
563 %} |
|
564 |
4930
|
565 "@" { |
|
566 current_input_column++; |
|
567 lexer_flags.quote_is_transpose = false; |
|
568 lexer_flags.convert_spaces_to_comma = false; |
|
569 lexer_flags.looking_at_function_handle++; |
|
570 COUNT_TOK_AND_RETURN ('@'); |
4342
|
571 } |
|
572 |
|
573 %{ |
968
|
574 // A new line character. New line characters inside matrix constants |
4208
|
575 // are handled by the <MATRIX_START> start state code above. If closest |
985
|
576 // nesting is inside parentheses, don't return a row separator. |
968
|
577 %} |
|
578 |
967
|
579 {NL} { |
|
580 current_input_column = 1; |
2857
|
581 lexer_flags.quote_is_transpose = false; |
|
582 lexer_flags.convert_spaces_to_comma = true; |
1826
|
583 if (nesting_level.none ()) |
4910
|
584 COUNT_TOK_AND_RETURN ('\n'); |
4037
|
585 else if (nesting_level.is_paren ()) |
|
586 gripe_matlab_incompatible ("bare newline inside parentheses"); |
4608
|
587 else if (nesting_level.is_bracket_or_brace ()) |
985
|
588 return LEXICAL_ERROR; |
967
|
589 } |
1
|
590 |
968
|
591 %{ |
|
592 // Single quote can either be the beginning of a string or a transpose |
|
593 // operator. |
|
594 %} |
|
595 |
967
|
596 "'" { |
|
597 current_input_column++; |
2857
|
598 lexer_flags.convert_spaces_to_comma = true; |
1
|
599 |
1826
|
600 if (lexer_flags.quote_is_transpose) |
967
|
601 { |
|
602 do_comma_insert_check (); |
4910
|
603 COUNT_TOK_AND_RETURN (QUOTE); |
967
|
604 } |
|
605 else |
4910
|
606 COUNT_TOK_AND_RETURN (handle_string ('\'')); |
967
|
607 } |
1
|
608 |
968
|
609 %{ |
971
|
610 // Double quotes always begin strings. |
|
611 %} |
|
612 |
973
|
613 \" { |
|
614 current_input_column++; |
4910
|
615 COUNT_TOK_AND_RETURN (handle_string ('"')); |
973
|
616 } |
971
|
617 |
|
618 %{ |
985
|
619 // Gobble comments. If closest nesting is inside parentheses, don't |
|
620 // return a new line. |
|
621 %} |
968
|
622 |
967
|
623 {CCHAR} { |
4426
|
624 std::string help_txt; |
|
625 |
|
626 if (! help_buf.empty ()) |
|
627 help_txt = help_buf.top (); |
|
628 |
|
629 if (help_txt.empty () |
1826
|
630 && lexer_flags.beginning_of_function |
|
631 && nesting_level.none ()) |
967
|
632 { |
3665
|
633 lexer_flags.beginning_of_function = false; |
|
634 |
4426
|
635 std::string txt = grab_help_text (); |
|
636 |
|
637 if (! help_buf.empty ()) |
|
638 help_buf.pop (); |
|
639 |
|
640 help_buf.push (txt); |
|
641 |
|
642 octave_comment_buffer::append (txt); |
967
|
643 } |
|
644 else |
|
645 { |
3665
|
646 std::string buf; |
|
647 |
|
648 bool begin_comment = true; |
|
649 |
967
|
650 int c; |
|
651 while ((c = yyinput ()) != EOF && c != '\n') |
3665
|
652 { |
|
653 if (begin_comment && (c == '#' || c == '%')) |
|
654 ; /* Skip leading comment characters. */ |
|
655 else |
3802
|
656 buf += static_cast<char> (c); |
3665
|
657 } |
|
658 |
|
659 octave_comment_buffer::append (buf); |
967
|
660 } |
440
|
661 |
967
|
662 current_input_column = 1; |
2857
|
663 lexer_flags.quote_is_transpose = false; |
|
664 lexer_flags.convert_spaces_to_comma = true; |
985
|
665 |
4037
|
666 maybe_gripe_matlab_incompatible_comment (yytext[0]); |
|
667 |
4323
|
668 if (YY_START == COMMAND_START) |
|
669 BEGIN (INITIAL); |
|
670 |
1826
|
671 if (nesting_level.none ()) |
5783
|
672 { |
|
673 lexer_flags.doing_rawcommand = false; |
|
674 COUNT_TOK_AND_RETURN ('\n'); |
|
675 } |
4608
|
676 else if (nesting_level.is_bracket_or_brace ()) |
4910
|
677 COUNT_TOK_AND_RETURN (';'); |
967
|
678 } |
440
|
679 |
968
|
680 %{ |
|
681 // Other operators. |
|
682 %} |
|
683 |
5102
|
684 ":" { BIN_OP_RETURN (':', false); } |
|
685 |
4037
|
686 ".+" { XBIN_OP_RETURN (EPLUS, false); } |
|
687 ".-" { XBIN_OP_RETURN (EMINUS, false); } |
2857
|
688 ".*" { BIN_OP_RETURN (EMUL, false); } |
|
689 "./" { BIN_OP_RETURN (EDIV, false); } |
|
690 ".\\" { BIN_OP_RETURN (ELEFTDIV, false); } |
4037
|
691 ".^" { BIN_OP_RETURN (EPOW, false); } |
|
692 ".**" { XBIN_OP_RETURN (EPOW, false); } |
2857
|
693 ".'" { do_comma_insert_check (); BIN_OP_RETURN (TRANSPOSE, true); } |
4037
|
694 "++" { do_comma_insert_check (); XBIN_OP_RETURN (PLUS_PLUS, true); } |
|
695 "--" { do_comma_insert_check (); XBIN_OP_RETURN (MINUS_MINUS, true); } |
2857
|
696 "<=" { BIN_OP_RETURN (EXPR_LE, false); } |
|
697 "==" { BIN_OP_RETURN (EXPR_EQ, false); } |
4037
|
698 "~=" { BIN_OP_RETURN (EXPR_NE, false); } |
|
699 "!=" { XBIN_OP_RETURN (EXPR_NE, false); } |
2857
|
700 ">=" { BIN_OP_RETURN (EXPR_GE, false); } |
2877
|
701 "&" { BIN_OP_RETURN (EXPR_AND, false); } |
2857
|
702 "|" { BIN_OP_RETURN (EXPR_OR, false); } |
|
703 "<" { BIN_OP_RETURN (EXPR_LT, false); } |
|
704 ">" { BIN_OP_RETURN (EXPR_GT, false); } |
5102
|
705 "+" { BIN_OP_RETURN ('+', false); } |
|
706 "-" { BIN_OP_RETURN ('-', false); } |
2857
|
707 "*" { BIN_OP_RETURN ('*', false); } |
|
708 "/" { BIN_OP_RETURN ('/', false); } |
|
709 "\\" { BIN_OP_RETURN (LEFTDIV, false); } |
|
710 ";" { BIN_OP_RETURN (';', true); } |
|
711 "," { BIN_OP_RETURN (',', true); } |
4037
|
712 "^" { BIN_OP_RETURN (POW, false); } |
|
713 "**" { XBIN_OP_RETURN (POW, false); } |
2857
|
714 "=" { BIN_OP_RETURN ('=', true); } |
2877
|
715 "&&" { BIN_OP_RETURN (EXPR_AND_AND, false); } |
2857
|
716 "||" { BIN_OP_RETURN (EXPR_OR_OR, false); } |
4037
|
717 "<<" { XBIN_OP_RETURN (LSHIFT, false); } |
|
718 ">>" { XBIN_OP_RETURN (RSHIFT, false); } |
967
|
719 |
|
720 {NOT} { |
4037
|
721 if (yytext[0] == '~') |
|
722 BIN_OP_RETURN (EXPR_NOT, false); |
|
723 else |
|
724 XBIN_OP_RETURN (EXPR_NOT, false); |
967
|
725 } |
1
|
726 |
967
|
727 "(" { |
4131
|
728 lexer_flags.looking_at_indirect_ref = false; |
1826
|
729 nesting_level.paren (); |
985
|
730 promptflag--; |
967
|
731 TOK_RETURN ('('); |
|
732 } |
|
733 |
|
734 ")" { |
1826
|
735 nesting_level.remove (); |
967
|
736 current_input_column++; |
2857
|
737 lexer_flags.quote_is_transpose = true; |
4608
|
738 lexer_flags.convert_spaces_to_comma = nesting_level.is_bracket_or_brace (); |
1001
|
739 do_comma_insert_check (); |
4910
|
740 COUNT_TOK_AND_RETURN (')'); |
967
|
741 } |
|
742 |
5102
|
743 "." { TOK_RETURN ('.'); } |
2066
|
744 |
4037
|
745 "+=" { XBIN_OP_RETURN (ADD_EQ, false); } |
|
746 "-=" { XBIN_OP_RETURN (SUB_EQ, false); } |
|
747 "*=" { XBIN_OP_RETURN (MUL_EQ, false); } |
|
748 "/=" { XBIN_OP_RETURN (DIV_EQ, false); } |
|
749 "\\=" { XBIN_OP_RETURN (LEFTDIV_EQ, false); } |
|
750 ".+=" { XBIN_OP_RETURN (ADD_EQ, false); } |
|
751 ".-=" { XBIN_OP_RETURN (SUB_EQ, false); } |
|
752 ".*=" { XBIN_OP_RETURN (EMUL_EQ, false); } |
|
753 "./=" { XBIN_OP_RETURN (EDIV_EQ, false); } |
|
754 ".\\=" { XBIN_OP_RETURN (ELEFTDIV_EQ, false); } |
|
755 {POW}= { XBIN_OP_RETURN (POW_EQ, false); } |
|
756 {EPOW}= { XBIN_OP_RETURN (EPOW_EQ, false); } |
|
757 "&=" { XBIN_OP_RETURN (AND_EQ, false); } |
|
758 "|=" { XBIN_OP_RETURN (OR_EQ, false); } |
|
759 "<<=" { XBIN_OP_RETURN (LSHIFT_EQ, false); } |
|
760 ">>=" { XBIN_OP_RETURN (RSHIFT_EQ, false); } |
2877
|
761 |
4608
|
762 \{{S}* { |
3351
|
763 nesting_level.brace (); |
4608
|
764 |
|
765 current_input_column += yyleng; |
|
766 lexer_flags.quote_is_transpose = false; |
|
767 lexer_flags.convert_spaces_to_comma = true; |
|
768 |
3351
|
769 promptflag--; |
4608
|
770 eat_whitespace (); |
|
771 |
4613
|
772 lexer_flags.braceflag++; |
4608
|
773 BEGIN (MATRIX_START); |
4910
|
774 COUNT_TOK_AND_RETURN ('{'); |
3351
|
775 } |
|
776 |
|
777 "}" { |
|
778 nesting_level.remove (); |
|
779 |
4608
|
780 TOK_RETURN ('}'); |
3351
|
781 } |
|
782 |
968
|
783 %{ |
2066
|
784 // Unrecognized input is a lexical error. |
968
|
785 %} |
1
|
786 |
2042
|
787 . { |
4240
|
788 // EOF happens here if we are parsing nested functions. |
|
789 |
4410
|
790 yyunput (yytext[0], yytext); |
4248
|
791 |
|
792 int c = yyinput (); |
|
793 |
|
794 if (c != EOF) |
4240
|
795 { |
|
796 current_input_column++; |
|
797 |
|
798 error ("invalid character `%s' (ASCII %d) near line %d, column %d", |
4248
|
799 undo_string_escape (static_cast<char> (c)), c, |
4240
|
800 input_line_number, current_input_column); |
|
801 |
|
802 return LEXICAL_ERROR; |
|
803 } |
|
804 else |
|
805 TOK_RETURN (END_OF_INPUT); |
2066
|
806 } |
1
|
807 |
|
808 %% |
|
809 |
767
|
810 // GAG. |
|
811 // |
|
812 // If we're reading a matrix and the next character is '[', make sure |
|
813 // that we insert a comma ahead of it. |
|
814 |
146
|
815 void |
1
|
816 do_comma_insert_check (void) |
|
817 { |
1001
|
818 int spc_gobbled = eat_continuation (); |
2970
|
819 |
1
|
820 int c = yyinput (); |
2970
|
821 |
4410
|
822 yyunput (c, yytext); |
2970
|
823 |
1001
|
824 if (spc_gobbled) |
4410
|
825 yyunput (' ', yytext); |
2970
|
826 |
3351
|
827 lexer_flags.do_comma_insert = (lexer_flags.bracketflag && c == '['); |
1
|
828 } |
|
829 |
767
|
830 // Fix things up for errors or interrupts. The parser is never called |
|
831 // recursively, so it is always safe to reinitialize its state before |
|
832 // doing any parsing. |
|
833 |
1
|
834 void |
|
835 reset_parser (void) |
|
836 { |
1826
|
837 // Start off on the right foot. |
4323
|
838 BEGIN (INITIAL); |
4318
|
839 |
3883
|
840 parser_end_of_input = false; |
4238
|
841 end_tokens_expected = 0; |
|
842 |
|
843 while (! symtab_context.empty ()) |
|
844 symtab_context.pop (); |
287
|
845 |
1826
|
846 // We do want a prompt by default. |
1
|
847 promptflag = 1; |
287
|
848 |
3351
|
849 // Error may have occurred inside some brackets, braces, or parentheses. |
985
|
850 nesting_level.clear (); |
287
|
851 |
1826
|
852 // Clear out the stack of token info used to track line and column |
|
853 // numbers. |
143
|
854 while (! token_stack.empty ()) |
4214
|
855 { |
|
856 delete token_stack.top (); |
|
857 token_stack.pop (); |
|
858 } |
287
|
859 |
1826
|
860 // Can be reset by defining a function. |
985
|
861 if (! (reading_script_file || reading_fcn_file)) |
|
862 { |
|
863 current_input_column = 1; |
2926
|
864 input_line_number = command_editor::current_command_number () - 1; |
985
|
865 } |
287
|
866 |
1826
|
867 // Only ask for input from stdin if we are expecting interactive |
|
868 // input. |
3174
|
869 if ((interactive || forced_interactive) |
3880
|
870 && ! (reading_fcn_file |
|
871 || reading_script_file |
|
872 || get_input_from_eval_string |
3174
|
873 || input_from_startup_file)) |
287
|
874 yyrestart (stdin); |
991
|
875 |
1826
|
876 // Clear the buffer for help text. |
4426
|
877 while (! help_buf.empty ()) |
|
878 help_buf.pop (); |
1755
|
879 |
1826
|
880 // Reset other flags. |
|
881 lexer_flags.init (); |
1
|
882 } |
|
883 |
767
|
884 // If we read some newlines, we need figure out what column we're |
|
885 // really looking at. |
|
886 |
1
|
887 static void |
|
888 fixup_column_count (char *s) |
|
889 { |
|
890 char c; |
|
891 while ((c = *s++) != '\0') |
|
892 { |
|
893 if (c == '\n') |
143
|
894 current_input_column = 1; |
1
|
895 else |
|
896 current_input_column++; |
|
897 } |
|
898 } |
|
899 |
767
|
900 // Include these so that we don't have to link to libfl.a. |
246
|
901 |
3332
|
902 int |
1
|
903 yywrap (void) |
|
904 { |
287
|
905 return 1; |
1
|
906 } |
|
907 |
767
|
908 // Tell us all what the current buffer is. |
|
909 |
1
|
910 YY_BUFFER_STATE |
|
911 current_buffer (void) |
|
912 { |
|
913 return YY_CURRENT_BUFFER; |
|
914 } |
|
915 |
767
|
916 // Create a new buffer. |
|
917 |
1
|
918 YY_BUFFER_STATE |
|
919 create_buffer (FILE *f) |
|
920 { |
|
921 return yy_create_buffer (f, YY_BUF_SIZE); |
|
922 } |
|
923 |
767
|
924 // Start reading a new buffer. |
|
925 |
1
|
926 void |
|
927 switch_to_buffer (YY_BUFFER_STATE buf) |
|
928 { |
|
929 yy_switch_to_buffer (buf); |
|
930 } |
|
931 |
767
|
932 // Delete a buffer. |
|
933 |
1
|
934 void |
|
935 delete_buffer (YY_BUFFER_STATE buf) |
|
936 { |
|
937 yy_delete_buffer (buf); |
|
938 } |
|
939 |
767
|
940 // Restore a buffer (for unwind-prot). |
|
941 |
1
|
942 void |
|
943 restore_input_buffer (void *buf) |
|
944 { |
2861
|
945 switch_to_buffer (static_cast<YY_BUFFER_STATE> (buf)); |
1
|
946 } |
|
947 |
767
|
948 // Delete a buffer (for unwind-prot). |
|
949 |
1
|
950 void |
|
951 delete_input_buffer (void *buf) |
|
952 { |
2861
|
953 delete_buffer (static_cast<YY_BUFFER_STATE> (buf)); |
1
|
954 } |
|
955 |
4238
|
956 static void |
|
957 prep_for_function (void) |
|
958 { |
|
959 end_tokens_expected++; |
|
960 |
|
961 // Prepare for local symbols. |
|
962 |
|
963 tmp_local_sym_tab = new symbol_table (); |
|
964 |
|
965 promptflag--; |
|
966 |
|
967 lexer_flags.defining_func = true; |
|
968 lexer_flags.parsed_function_name = false; |
|
969 lexer_flags.beginning_of_function = true; |
|
970 |
|
971 if (! (reading_fcn_file || reading_script_file)) |
|
972 input_line_number = 1; |
|
973 } |
|
974 |
|
975 static void |
|
976 prep_for_nested_function (void) |
|
977 { |
4240
|
978 lexer_flags.parsing_nested_function = 1; |
4426
|
979 help_buf.push (std::string ()); |
4238
|
980 prep_for_function (); |
4240
|
981 // We're still only expecting one end token for this set of functions. |
|
982 end_tokens_expected--; |
4238
|
983 yylval.tok_val = new token (input_line_number, current_input_column); |
|
984 token_stack.push (yylval.tok_val); |
|
985 } |
|
986 |
|
987 // Handle keywords. Return -1 if the keyword should be ignored. |
767
|
988 |
1
|
989 static int |
4867
|
990 is_keyword_token (const std::string& s) |
1
|
991 { |
3805
|
992 int l = input_line_number; |
|
993 int c = current_input_column; |
|
994 |
1823
|
995 int len = s.length (); |
922
|
996 |
5088
|
997 const octave_kw *kw = octave_kw_hash::in_word_set (s.c_str (), len); |
191
|
998 |
1497
|
999 if (kw) |
143
|
1000 { |
1497
|
1001 yylval.tok_val = 0; |
|
1002 |
|
1003 switch (kw->kw_id) |
|
1004 { |
|
1005 case break_kw: |
2764
|
1006 case case_kw: |
1497
|
1007 case catch_kw: |
|
1008 case continue_kw: |
|
1009 case else_kw: |
|
1010 case elseif_kw: |
|
1011 case global_kw: |
2764
|
1012 case otherwise_kw: |
1497
|
1013 case return_kw: |
2846
|
1014 case static_kw: |
3484
|
1015 case until_kw: |
1497
|
1016 case unwind_protect_cleanup_kw: |
|
1017 break; |
|
1018 |
|
1019 case end_kw: |
4234
|
1020 if (lexer_flags.looking_at_object_index) |
|
1021 return 0; |
|
1022 else |
4238
|
1023 { |
|
1024 if (reading_fcn_file && end_tokens_expected == 1) |
|
1025 return -1; |
|
1026 else |
|
1027 { |
|
1028 yylval.tok_val = new token (token::simple_end, l, c); |
|
1029 end_tokens_expected--; |
|
1030 } |
|
1031 } |
1497
|
1032 break; |
|
1033 |
|
1034 case end_try_catch_kw: |
4238
|
1035 end_tokens_expected--; |
1497
|
1036 yylval.tok_val = new token (token::try_catch_end, l, c); |
|
1037 break; |
|
1038 |
|
1039 case end_unwind_protect_kw: |
4238
|
1040 end_tokens_expected--; |
1497
|
1041 yylval.tok_val = new token (token::unwind_protect_end, l, c); |
|
1042 break; |
|
1043 |
|
1044 case endfor_kw: |
4238
|
1045 end_tokens_expected--; |
1497
|
1046 yylval.tok_val = new token (token::for_end, l, c); |
|
1047 break; |
|
1048 |
|
1049 case endfunction_kw: |
4238
|
1050 { |
|
1051 if (reading_fcn_file && end_tokens_expected == 1) |
|
1052 return -1; |
|
1053 else |
|
1054 { |
|
1055 yylval.tok_val = new token (token::function_end, l, c); |
|
1056 end_tokens_expected--; |
|
1057 } |
|
1058 } |
1497
|
1059 break; |
|
1060 |
|
1061 case endif_kw: |
4238
|
1062 end_tokens_expected--; |
1497
|
1063 yylval.tok_val = new token (token::if_end, l, c); |
|
1064 break; |
|
1065 |
2764
|
1066 case endswitch_kw: |
4238
|
1067 end_tokens_expected--; |
2764
|
1068 yylval.tok_val = new token (token::switch_end, l, c); |
|
1069 break; |
|
1070 |
1497
|
1071 case endwhile_kw: |
4238
|
1072 end_tokens_expected--; |
1497
|
1073 yylval.tok_val = new token (token::while_end, l, c); |
|
1074 break; |
|
1075 |
|
1076 case for_kw: |
|
1077 case while_kw: |
4238
|
1078 end_tokens_expected++; |
|
1079 // Fall through... |
|
1080 |
|
1081 case do_kw: |
1497
|
1082 promptflag--; |
1826
|
1083 lexer_flags.looping++; |
1497
|
1084 break; |
|
1085 |
|
1086 case if_kw: |
|
1087 case try_kw: |
2764
|
1088 case switch_kw: |
1497
|
1089 case unwind_protect_kw: |
4238
|
1090 end_tokens_expected++; |
1497
|
1091 promptflag--; |
|
1092 break; |
|
1093 |
|
1094 case function_kw: |
4238
|
1095 { |
|
1096 if (lexer_flags.defining_func) |
|
1097 { |
|
1098 if (reading_fcn_file) |
|
1099 { |
|
1100 if (lexer_flags.parsing_nested_function) |
|
1101 { |
4323
|
1102 BEGIN (NESTED_FUNCTION_END); |
4240
|
1103 |
4238
|
1104 yylval.tok_val = new token (token::function_end, l, c); |
4240
|
1105 token_stack.push (yylval.tok_val); |
|
1106 |
|
1107 return END; |
4238
|
1108 } |
|
1109 else |
|
1110 { |
|
1111 prep_for_nested_function (); |
4240
|
1112 |
4238
|
1113 return FCN; |
|
1114 } |
|
1115 } |
|
1116 else |
|
1117 { |
|
1118 error ("nested functions not implemented in this context"); |
|
1119 |
|
1120 if ((reading_fcn_file || reading_script_file) |
|
1121 && ! curr_fcn_file_name.empty ()) |
|
1122 error ("near line %d of file `%s.m'", |
|
1123 input_line_number, curr_fcn_file_name.c_str ()); |
|
1124 else |
|
1125 error ("near line %d", input_line_number); |
|
1126 |
|
1127 return LEXICAL_ERROR; |
|
1128 } |
|
1129 } |
|
1130 else |
|
1131 prep_for_function (); |
|
1132 } |
1497
|
1133 break; |
|
1134 |
3174
|
1135 case magic_file_kw: |
|
1136 { |
|
1137 if ((reading_fcn_file || reading_script_file) |
|
1138 && ! curr_fcn_file_full_name.empty ()) |
|
1139 yylval.tok_val = new token (curr_fcn_file_full_name, l, c); |
|
1140 else |
|
1141 yylval.tok_val = new token ("stdin", l, c); |
|
1142 } |
|
1143 break; |
|
1144 |
|
1145 case magic_line_kw: |
|
1146 yylval.tok_val = new token (static_cast<double> (l), "", l, c); |
|
1147 break; |
|
1148 |
3974
|
1149 case varargin_kw: |
|
1150 if (! lexer_flags.looking_at_parameter_list) |
|
1151 return 0; |
|
1152 break; |
|
1153 |
|
1154 case varargout_kw: |
4678
|
1155 if (! (lexer_flags.looking_at_return_list |
|
1156 || (lexer_flags.defining_func |
|
1157 && ! lexer_flags.parsed_function_name))) |
3974
|
1158 return 0; |
|
1159 break; |
|
1160 |
1497
|
1161 default: |
|
1162 panic_impossible (); |
|
1163 } |
|
1164 |
|
1165 if (! yylval.tok_val) |
|
1166 yylval.tok_val = new token (l, c); |
|
1167 |
476
|
1168 token_stack.push (yylval.tok_val); |
1497
|
1169 |
|
1170 return kw->tok; |
143
|
1171 } |
1
|
1172 |
|
1173 return 0; |
|
1174 } |
|
1175 |
767
|
1176 // Try to find an identifier. All binding to global or builtin |
|
1177 // variables occurs when expressions are evaluated. |
|
1178 |
1
|
1179 static symbol_record * |
3523
|
1180 lookup_identifier (const std::string& name) |
1
|
1181 { |
4238
|
1182 std::string sym_name = name; |
|
1183 |
|
1184 if (curr_sym_tab == fbi_sym_tab |
|
1185 && lexer_flags.parsing_nested_function) |
|
1186 sym_name = parent_function_name + ":" + sym_name; |
|
1187 |
|
1188 return curr_sym_tab->lookup (sym_name, true); |
1
|
1189 } |
|
1190 |
2702
|
1191 static bool |
3523
|
1192 is_variable (const std::string& name) |
2702
|
1193 { |
2856
|
1194 symbol_record *sr = curr_sym_tab->lookup (name); |
2702
|
1195 |
|
1196 return sr && sr->is_variable (); |
|
1197 } |
|
1198 |
|
1199 static void |
3523
|
1200 force_local_variable (const std::string& name) |
2702
|
1201 { |
4101
|
1202 if (! is_variable (name)) |
|
1203 curr_sym_tab->clear (name); |
|
1204 |
2856
|
1205 symbol_record *sr = curr_sym_tab->lookup (name, true); |
2702
|
1206 |
|
1207 if (sr) |
|
1208 sr->define (octave_value ()); |
|
1209 } |
|
1210 |
4426
|
1211 // Grab the help text from an function file. |
767
|
1212 |
5775
|
1213 // FIXME -- gobble_leading_white_space() in parse.y |
2300
|
1214 // duplicates some of this code! |
|
1215 |
4426
|
1216 static std::string |
1
|
1217 grab_help_text (void) |
|
1218 { |
4426
|
1219 std::string buf; |
1019
|
1220 |
2300
|
1221 bool begin_comment = true; |
|
1222 bool in_comment = true; |
3427
|
1223 bool discard_space = true; |
3665
|
1224 |
1019
|
1225 int c = 0; |
1
|
1226 |
1019
|
1227 while ((c = yyinput ()) != EOF) |
|
1228 { |
2300
|
1229 if (begin_comment) |
|
1230 { |
|
1231 if (c == '%' || c == '#') |
|
1232 continue; |
3427
|
1233 else if (discard_space && c == ' ') |
|
1234 { |
|
1235 discard_space = false; |
|
1236 continue; |
|
1237 } |
2300
|
1238 else |
|
1239 begin_comment = false; |
|
1240 } |
|
1241 |
1019
|
1242 if (in_comment) |
1
|
1243 { |
4426
|
1244 buf += static_cast<char> (c); |
1755
|
1245 |
1019
|
1246 if (c == '\n') |
3427
|
1247 { |
|
1248 in_comment = false; |
|
1249 discard_space = true; |
|
1250 } |
1019
|
1251 } |
|
1252 else |
|
1253 { |
|
1254 switch (c) |
991
|
1255 { |
4037
|
1256 case '#': |
1019
|
1257 case '%': |
4037
|
1258 maybe_gripe_matlab_incompatible_comment (yytext[0]); |
2300
|
1259 in_comment = true; |
|
1260 begin_comment = true; |
1019
|
1261 break; |
777
|
1262 |
1019
|
1263 case ' ': |
|
1264 case '\t': |
|
1265 break; |
777
|
1266 |
1019
|
1267 default: |
|
1268 goto done; |
1
|
1269 } |
|
1270 } |
1019
|
1271 } |
991
|
1272 |
1019
|
1273 done: |
991
|
1274 |
1019
|
1275 if (c) |
4410
|
1276 yyunput (c, yytext); |
4426
|
1277 |
|
1278 return buf; |
1
|
1279 } |
|
1280 |
767
|
1281 // Return 1 if the given character matches any character in the given |
|
1282 // string. |
|
1283 |
2857
|
1284 static bool |
2804
|
1285 match_any (char c, const char *s) |
1
|
1286 { |
|
1287 char tmp; |
|
1288 while ((tmp = *s++) != '\0') |
|
1289 { |
|
1290 if (c == tmp) |
2857
|
1291 return true; |
1
|
1292 } |
2857
|
1293 return false; |
1
|
1294 } |
|
1295 |
767
|
1296 // Given information about the spacing surrounding an operator, |
|
1297 // return 1 if it looks like it should be treated as a binary |
|
1298 // operator. For example, |
|
1299 // |
3774
|
1300 // [ 1 + 2 ] or [ 1+ 2] or [ 1+2 ] ==> binary |
|
1301 // |
|
1302 // [ 1 +2 ] ==> unary |
767
|
1303 |
2857
|
1304 static bool |
3246
|
1305 looks_like_bin_op (bool spc_prev, int next_char) |
1
|
1306 { |
3246
|
1307 bool spc_next = (next_char == ' ' || next_char == '\t'); |
|
1308 |
608
|
1309 return ((spc_prev && spc_next) || ! spc_prev); |
1
|
1310 } |
|
1311 |
3263
|
1312 // Recognize separators. If the separator is a CRLF pair, it is |
|
1313 // replaced by a single LF. |
|
1314 |
|
1315 static bool |
|
1316 next_token_is_sep_op (void) |
|
1317 { |
|
1318 bool retval = false; |
|
1319 |
|
1320 int c1 = yyinput (); |
|
1321 |
|
1322 if (c1 == '\r') |
|
1323 { |
|
1324 int c2 = yyinput (); |
|
1325 |
|
1326 if (c2 == '\n') |
|
1327 { |
|
1328 c1 = '\n'; |
|
1329 |
|
1330 retval = true; |
|
1331 } |
|
1332 else |
4410
|
1333 yyunput (c2, yytext); |
3263
|
1334 } |
|
1335 else |
|
1336 retval = match_any (c1, ",;\n]"); |
|
1337 |
4410
|
1338 yyunput (c1, yytext); |
3263
|
1339 |
|
1340 return retval; |
|
1341 } |
|
1342 |
767
|
1343 // Try to determine if the next token should be treated as a postfix |
|
1344 // unary operator. This is ugly, but it seems to do the right thing. |
|
1345 |
2857
|
1346 static bool |
3246
|
1347 next_token_is_postfix_unary_op (bool spc_prev) |
1
|
1348 { |
2857
|
1349 bool un_op = false; |
1
|
1350 |
|
1351 int c0 = yyinput (); |
|
1352 |
3246
|
1353 if (c0 == '\'' && ! spc_prev) |
|
1354 { |
|
1355 un_op = true; |
|
1356 } |
|
1357 else if (c0 == '.') |
|
1358 { |
|
1359 int c1 = yyinput (); |
|
1360 un_op = (c1 == '\''); |
4410
|
1361 yyunput (c1, yytext); |
3246
|
1362 } |
4613
|
1363 else if (c0 == '+') |
|
1364 { |
|
1365 int c1 = yyinput (); |
|
1366 un_op = (c1 == '+'); |
|
1367 yyunput (c1, yytext); |
|
1368 } |
|
1369 else if (c0 == '-') |
|
1370 { |
|
1371 int c1 = yyinput (); |
|
1372 un_op = (c1 == '-'); |
|
1373 yyunput (c1, yytext); |
|
1374 } |
1
|
1375 |
4410
|
1376 yyunput (c0, yytext); |
1
|
1377 |
|
1378 return un_op; |
|
1379 } |
|
1380 |
767
|
1381 // Try to determine if the next token should be treated as a binary |
3246
|
1382 // operator. |
1521
|
1383 // |
3246
|
1384 // This kluge exists because whitespace is not always ignored inside |
3774
|
1385 // the square brackets that are used to create matrix objects (though |
|
1386 // spacing only really matters in the cases that can be interpreted |
|
1387 // either as binary ops or prefix unary ops: currently just +, -). |
|
1388 // |
3779
|
1389 // Note that a line continuation directly following a + or - operator |
|
1390 // (e.g., the characters '[' 'a' ' ' '+' '\' LFD 'b' ']') will be |
|
1391 // parsed as a binary operator. |
767
|
1392 |
2857
|
1393 static bool |
3246
|
1394 next_token_is_bin_op (bool spc_prev) |
1
|
1395 { |
2857
|
1396 bool bin_op = false; |
1
|
1397 |
|
1398 int c0 = yyinput (); |
|
1399 |
|
1400 switch (c0) |
|
1401 { |
777
|
1402 case '+': |
|
1403 case '-': |
3774
|
1404 { |
|
1405 int c1 = yyinput (); |
|
1406 |
|
1407 switch (c1) |
|
1408 { |
|
1409 case '+': |
|
1410 case '-': |
|
1411 // Unary ops, spacing doesn't matter. |
|
1412 break; |
|
1413 |
|
1414 case '=': |
|
1415 // Binary ops, spacing doesn't matter. |
|
1416 bin_op = true; |
|
1417 break; |
|
1418 |
|
1419 default: |
|
1420 // Could be either, spacing matters. |
|
1421 bin_op = looks_like_bin_op (spc_prev, c1); |
|
1422 break; |
|
1423 } |
|
1424 |
4410
|
1425 yyunput (c1, yytext); |
3774
|
1426 } |
|
1427 break; |
|
1428 |
|
1429 case ':': |
3246
|
1430 case '/': |
|
1431 case '\\': |
|
1432 case '^': |
3774
|
1433 // Always a binary op (may also include /=, \=, and ^=). |
|
1434 bin_op = true; |
1276
|
1435 break; |
|
1436 |
3246
|
1437 // .+ .- ./ .\ .^ .* .** |
1554
|
1438 case '.': |
|
1439 { |
|
1440 int c1 = yyinput (); |
3246
|
1441 |
3774
|
1442 if (match_any (c1, "+-/\\^*")) |
|
1443 // Always a binary op (may also include .+=, .-=, ./=, ...). |
|
1444 bin_op = true; |
3698
|
1445 else if (! isdigit (c1) && c1 != ' ' && c1 != '\t' && c1 != '.') |
3774
|
1446 // A structure element reference is a binary op. |
|
1447 bin_op = true; |
3246
|
1448 |
4410
|
1449 yyunput (c1, yytext); |
1554
|
1450 } |
|
1451 break; |
|
1452 |
3246
|
1453 // = == & && | || * ** |
|
1454 case '=': |
1
|
1455 case '&': |
3246
|
1456 case '|': |
1
|
1457 case '*': |
3774
|
1458 // Always a binary op (may also include ==, &&, ||, **). |
|
1459 bin_op = true; |
3246
|
1460 break; |
|
1461 |
3774
|
1462 // < <= <> > >= |
1
|
1463 case '<': |
|
1464 case '>': |
3774
|
1465 // Always a binary op (may also include <=, <>, >=). |
|
1466 bin_op = true; |
|
1467 break; |
|
1468 |
|
1469 // ~= != |
777
|
1470 case '~': |
|
1471 case '!': |
3246
|
1472 { |
|
1473 int c1 = yyinput (); |
|
1474 |
3774
|
1475 // ~ and ! can be unary ops, so require following =. |
|
1476 if (c1 == '=') |
|
1477 bin_op = true; |
3246
|
1478 |
4410
|
1479 yyunput (c1, yytext); |
3246
|
1480 } |
1
|
1481 break; |
|
1482 |
|
1483 default: |
1276
|
1484 break; |
1
|
1485 } |
|
1486 |
4410
|
1487 yyunput (c0, yytext); |
1
|
1488 |
|
1489 return bin_op; |
|
1490 } |
|
1491 |
767
|
1492 // Used to delete trailing white space from tokens. |
|
1493 |
3536
|
1494 static std::string |
1
|
1495 strip_trailing_whitespace (char *s) |
|
1496 { |
3523
|
1497 std::string retval = s; |
1
|
1498 |
1823
|
1499 size_t pos = retval.find_first_of (" \t"); |
1
|
1500 |
1823
|
1501 if (pos != NPOS) |
|
1502 retval.resize (pos); |
1
|
1503 |
|
1504 return retval; |
|
1505 } |
|
1506 |
3665
|
1507 static void |
|
1508 scan_for_comments (const char *text) |
|
1509 { |
|
1510 std::string comment_buf; |
|
1511 |
|
1512 bool in_comment = false; |
|
1513 bool beginning_of_comment = false; |
|
1514 |
|
1515 int len = strlen (text); |
|
1516 int i = 0; |
|
1517 |
|
1518 while (i < len) |
|
1519 { |
|
1520 char c = text[i++]; |
|
1521 |
|
1522 switch (c) |
|
1523 { |
|
1524 case '%': |
|
1525 case '#': |
|
1526 if (in_comment) |
|
1527 { |
|
1528 if (! beginning_of_comment) |
3802
|
1529 comment_buf += static_cast<char> (c); |
3665
|
1530 } |
|
1531 else |
|
1532 { |
4037
|
1533 maybe_gripe_matlab_incompatible_comment (c); |
3665
|
1534 in_comment = true; |
|
1535 beginning_of_comment = true; |
|
1536 } |
|
1537 break; |
|
1538 |
|
1539 case '\n': |
|
1540 if (in_comment) |
|
1541 { |
3802
|
1542 comment_buf += static_cast<char> (c); |
3665
|
1543 octave_comment_buffer::append (comment_buf); |
|
1544 comment_buf.resize (0); |
|
1545 in_comment = false; |
|
1546 beginning_of_comment = false; |
|
1547 } |
|
1548 break; |
|
1549 |
|
1550 case '\r': |
|
1551 if (in_comment) |
3802
|
1552 comment_buf += static_cast<char> (c); |
3665
|
1553 if (i < len) |
|
1554 { |
|
1555 c = text[i++]; |
|
1556 |
|
1557 if (c == '\n') |
|
1558 { |
|
1559 if (in_comment) |
|
1560 { |
3802
|
1561 comment_buf += static_cast<char> (c); |
3665
|
1562 octave_comment_buffer::append (comment_buf); |
|
1563 in_comment = false; |
|
1564 beginning_of_comment = false; |
|
1565 } |
|
1566 } |
|
1567 } |
|
1568 |
|
1569 default: |
|
1570 if (in_comment) |
|
1571 { |
3802
|
1572 comment_buf += static_cast<char> (c); |
3665
|
1573 beginning_of_comment = false; |
|
1574 } |
|
1575 break; |
|
1576 } |
|
1577 } |
|
1578 |
|
1579 if (! comment_buf.empty ()) |
|
1580 octave_comment_buffer::append (comment_buf); |
|
1581 } |
|
1582 |
1001
|
1583 // Discard whitespace, including comments and continuations. |
1088
|
1584 // |
|
1585 // Return value is logical OR of the following values: |
|
1586 // |
1826
|
1587 // ATE_NOTHING : no spaces to eat |
1088
|
1588 // ATE_SPACE_OR_TAB : space or tab in input |
|
1589 // ATE_NEWLINE : bare new line in input |
1001
|
1590 |
1826
|
1591 static yum_yum |
975
|
1592 eat_whitespace (void) |
|
1593 { |
1826
|
1594 yum_yum retval = ATE_NOTHING; |
3665
|
1595 |
|
1596 std::string comment_buf; |
|
1597 |
2857
|
1598 bool in_comment = false; |
3665
|
1599 bool beginning_of_comment = false; |
|
1600 |
|
1601 int c = 0; |
|
1602 |
975
|
1603 while ((c = yyinput ()) != EOF) |
|
1604 { |
|
1605 current_input_column++; |
|
1606 |
|
1607 switch (c) |
|
1608 { |
|
1609 case ' ': |
|
1610 case '\t': |
3665
|
1611 if (in_comment) |
|
1612 { |
3802
|
1613 comment_buf += static_cast<char> (c); |
3665
|
1614 beginning_of_comment = false; |
|
1615 } |
1088
|
1616 retval |= ATE_SPACE_OR_TAB; |
975
|
1617 break; |
|
1618 |
|
1619 case '\n': |
1088
|
1620 retval |= ATE_NEWLINE; |
3665
|
1621 if (in_comment) |
|
1622 { |
3802
|
1623 comment_buf += static_cast<char> (c); |
3665
|
1624 octave_comment_buffer::append (comment_buf); |
|
1625 comment_buf.resize (0); |
|
1626 in_comment = false; |
|
1627 beginning_of_comment = false; |
|
1628 } |
975
|
1629 current_input_column = 0; |
|
1630 break; |
|
1631 |
|
1632 case '#': |
|
1633 case '%': |
3665
|
1634 if (in_comment) |
|
1635 { |
|
1636 if (! beginning_of_comment) |
3802
|
1637 comment_buf += static_cast<char> (c); |
3665
|
1638 } |
|
1639 else |
|
1640 { |
4037
|
1641 maybe_gripe_matlab_incompatible_comment (c); |
3665
|
1642 in_comment = true; |
|
1643 beginning_of_comment = true; |
|
1644 } |
975
|
1645 break; |
|
1646 |
1001
|
1647 case '.': |
|
1648 if (in_comment) |
3665
|
1649 { |
3802
|
1650 comment_buf += static_cast<char> (c); |
3665
|
1651 beginning_of_comment = false; |
|
1652 break; |
|
1653 } |
1001
|
1654 else |
|
1655 { |
|
1656 if (have_ellipsis_continuation ()) |
|
1657 break; |
|
1658 else |
|
1659 goto done; |
|
1660 } |
|
1661 |
|
1662 case '\\': |
|
1663 if (in_comment) |
3665
|
1664 { |
3802
|
1665 comment_buf += static_cast<char> (c); |
3665
|
1666 beginning_of_comment = false; |
|
1667 break; |
|
1668 } |
1001
|
1669 else |
|
1670 { |
3105
|
1671 if (have_continuation ()) |
1001
|
1672 break; |
|
1673 else |
|
1674 goto done; |
|
1675 } |
|
1676 |
6187
|
1677 case '\r': |
|
1678 if (in_comment) |
|
1679 comment_buf += static_cast<char> (c); |
|
1680 c = yyinput (); |
|
1681 if (c == EOF) |
|
1682 break; |
|
1683 else if (c == '\n') |
|
1684 { |
|
1685 retval |= ATE_NEWLINE; |
|
1686 if (in_comment) |
|
1687 { |
|
1688 comment_buf += static_cast<char> (c); |
|
1689 octave_comment_buffer::append (comment_buf); |
|
1690 in_comment = false; |
|
1691 beginning_of_comment = false; |
|
1692 } |
|
1693 current_input_column = 0; |
|
1694 break; |
|
1695 } |
|
1696 |
|
1697 // Fall through... |
|
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 } |
6067
|
2341 else if (! (next_tok_is_paren || lexer_flags.looking_at_object_index)) |
2702
|
2342 { |
5102
|
2343 BEGIN (COMMAND_START); |
|
2344 } |
|
2345 |
6067
|
2346 if (is_rawcommand_name (tok) && ! lexer_flags.looking_at_object_index) |
5102
|
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 */ |