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 |
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" |
4051
|
53 #include "lo-sstream.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 // |
|
171 // XXX FIXME XXX -- this should really be static, but that causes |
|
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 |
4037
|
235 static bool Vwarn_matlab_incompatible = false; |
|
236 |
3388
|
237 static bool Vwarn_separator_insert = false; |
|
238 |
3400
|
239 static bool Vwarn_single_quote_string = false; |
|
240 |
4910
|
241 static unsigned int Vtoken_count = 0; |
|
242 |
146
|
243 // Forward declarations for functions defined at the bottom of this |
|
244 // file. |
|
245 |
1
|
246 static void fixup_column_count (char *s); |
146
|
247 static void do_comma_insert_check (void); |
4867
|
248 static int is_keyword_token (const std::string& s); |
4238
|
249 static void prep_for_function (void); |
|
250 static void prep_for_nested_function (void); |
3523
|
251 static symbol_record *lookup_identifier (const std::string& s); |
4426
|
252 static std::string grab_help_text (void); |
2857
|
253 static bool match_any (char c, const char *s); |
3263
|
254 static bool next_token_is_sep_op (void); |
3246
|
255 static bool next_token_is_bin_op (bool spc_prev); |
|
256 static bool next_token_is_postfix_unary_op (bool spc_prev); |
3523
|
257 static std::string strip_trailing_whitespace (char *s); |
3246
|
258 static void handle_number (void); |
975
|
259 static int handle_string (char delim, int text_style = 0); |
4612
|
260 static int handle_close_bracket (bool spc_gobbled, int bracket_type); |
3974
|
261 static int handle_identifier (void); |
3096
|
262 static bool have_continuation (bool trailing_comments_ok = true); |
|
263 static bool have_ellipsis_continuation (bool trailing_comments_ok = true); |
3665
|
264 static void scan_for_comments (const char *); |
1826
|
265 static yum_yum eat_whitespace (void); |
|
266 static yum_yum eat_continuation (void); |
3388
|
267 static void maybe_warn_separator_insert (char sep); |
3400
|
268 static void gripe_single_quote_string (void); |
4037
|
269 static void gripe_matlab_incompatible (const std::string& msg); |
|
270 static void maybe_gripe_matlab_incompatible_comment (char c); |
|
271 static void gripe_matlab_incompatible_continuation (void); |
|
272 static void gripe_matlab_incompatible_operator (const std::string& op); |
1
|
273 |
|
274 %} |
|
275 |
|
276 D [0-9] |
|
277 S [ \t] |
2042
|
278 NL ((\n)|(\r\n)) |
|
279 SNL ({S}|{NL}) |
1
|
280 EL (\.\.\.) |
967
|
281 BS (\\) |
|
282 CONT ({EL}|{BS}) |
1
|
283 Im [iIjJ] |
967
|
284 CCHAR [#%] |
|
285 COMMENT ({CCHAR}.*{NL}) |
|
286 SNLCMT ({SNL}|{COMMENT}) |
|
287 NOT ((\~)|(\!)) |
4037
|
288 POW ((\*\*)|(\^)) |
|
289 EPOW (\.{POW}) |
5290
|
290 IDENT ([_$a-zA-Z][_$a-zA-Z0-9]*) |
1
|
291 EXPON ([DdEe][+-]?{D}+) |
3220
|
292 NUMBER (({D}+\.?{D}*{EXPON}?)|(\.{D}+{EXPON}?)|(0[xX][0-9a-fA-F]+)) |
1
|
293 %% |
|
294 |
4240
|
295 <NESTED_FUNCTION_END>. { |
4323
|
296 BEGIN (NESTED_FUNCTION_BEGIN); |
4410
|
297 yyunput (yytext[0], yytext); |
4910
|
298 COUNT_TOK_AND_RETURN (';'); |
4240
|
299 } |
|
300 |
|
301 <NESTED_FUNCTION_BEGIN>. { |
4323
|
302 BEGIN (INITIAL); |
4410
|
303 yyunput (yytext[0], yytext); |
4238
|
304 prep_for_nested_function (); |
4910
|
305 COUNT_TOK_AND_RETURN (FCN); |
4238
|
306 } |
|
307 |
968
|
308 %{ |
4208
|
309 // Help and other command-style functions are a pain in the ass. This |
968
|
310 // stuff needs to be simplified. May require some changes in the |
|
311 // parser too. |
|
312 %} |
|
313 |
4208
|
314 <COMMAND_START>{NL} { |
4323
|
315 BEGIN (INITIAL); |
967
|
316 current_input_column = 1; |
2857
|
317 lexer_flags.quote_is_transpose = false; |
|
318 lexer_flags.convert_spaces_to_comma = true; |
5212
|
319 lexer_flags.doing_rawcommand = false; |
4910
|
320 COUNT_TOK_AND_RETURN ('\n'); |
967
|
321 } |
1
|
322 |
4208
|
323 <COMMAND_START>[\;\,] { |
5102
|
324 if (lexer_flags.doing_rawcommand) |
5279
|
325 TOK_PUSH_AND_RETURN (yytext, SQ_STRING); |
5102
|
326 |
|
327 BEGIN (INITIAL); |
|
328 |
|
329 if (strcmp (yytext, ",") == 0) |
|
330 TOK_RETURN (','); |
967
|
331 else |
5102
|
332 TOK_RETURN (';'); |
967
|
333 } |
1
|
334 |
4208
|
335 <COMMAND_START>[\"\'] { |
975
|
336 current_input_column++; |
4910
|
337 COUNT_TOK_AND_RETURN (handle_string (yytext[0], true)); |
975
|
338 } |
|
339 |
4923
|
340 <COMMAND_START>[^#% \t\r\n\;\,\"\'][^ \t\r\n\;\,]*{S}* { |
3523
|
341 std::string tok = strip_trailing_whitespace (yytext); |
5279
|
342 TOK_PUSH_AND_RETURN (tok, SQ_STRING); |
967
|
343 } |
1
|
344 |
968
|
345 %{ |
1
|
346 // For this and the next two rules, we're looking at ']', and we |
971
|
347 // need to know if the next token is `=' or `=='. |
1
|
348 // |
|
349 // It would have been so much easier if the delimiters were simply |
|
350 // different for the expression on the left hand side of the equals |
|
351 // operator. |
971
|
352 // |
|
353 // It's also a pain in the ass to decide whether to insert a comma |
|
354 // after seeing a ']' character... |
968
|
355 %} |
|
356 |
4208
|
357 <MATRIX_START>{SNLCMT}*\]{S}* { |
3665
|
358 scan_for_comments (yytext); |
1001
|
359 fixup_column_count (yytext); |
|
360 int c = yytext[yyleng-1]; |
|
361 int cont_is_spc = eat_continuation (); |
4608
|
362 bool spc_gobbled = (cont_is_spc || c == ' ' || c == '\t'); |
5345
|
363 int tok_to_return = handle_close_bracket (spc_gobbled, ']'); |
|
364 if (spc_gobbled) |
|
365 yyunput (' ', yytext); |
|
366 COUNT_TOK_AND_RETURN (tok_to_return); |
4608
|
367 } |
|
368 |
|
369 <MATRIX_START>{SNLCMT}*\}{S}* { |
|
370 scan_for_comments (yytext); |
|
371 fixup_column_count (yytext); |
|
372 int c = yytext[yyleng-1]; |
|
373 int cont_is_spc = eat_continuation (); |
|
374 bool spc_gobbled = (cont_is_spc || c == ' ' || c == '\t'); |
5345
|
375 int tok_to_return = handle_close_bracket (spc_gobbled, '}'); |
|
376 if (spc_gobbled) |
|
377 yyunput (' ', yytext); |
|
378 COUNT_TOK_AND_RETURN (tok_to_return); |
967
|
379 } |
1
|
380 |
968
|
381 %{ |
1088
|
382 // Commas are element separators in matrix constants. If we don't |
|
383 // check for continuations here we can end up inserting too many |
|
384 // commas. |
968
|
385 %} |
|
386 |
4208
|
387 <MATRIX_START>{S}*\,{S}* { |
1088
|
388 current_input_column += yyleng; |
3388
|
389 |
1088
|
390 int tmp = eat_continuation (); |
3388
|
391 |
2857
|
392 lexer_flags.quote_is_transpose = false; |
|
393 lexer_flags.convert_spaces_to_comma = true; |
3388
|
394 |
|
395 if ((tmp & ATE_NEWLINE) == ATE_NEWLINE) |
|
396 { |
|
397 maybe_warn_separator_insert (';'); |
|
398 |
4476
|
399 yyunput (';', yytext); |
3388
|
400 } |
|
401 |
4910
|
402 COUNT_TOK_AND_RETURN (','); |
967
|
403 } |
1
|
404 |
968
|
405 %{ |
|
406 // In some cases, spaces in matrix constants can turn into commas. |
|
407 // If commas are required, spaces are not important in matrix |
1088
|
408 // constants so we just eat them. If we don't check for continuations |
|
409 // here we can end up inserting too many commas. |
968
|
410 %} |
430
|
411 |
4208
|
412 <MATRIX_START>{S}+ { |
1088
|
413 current_input_column += yyleng; |
3388
|
414 |
|
415 int tmp = eat_continuation (); |
|
416 int bin_op = next_token_is_bin_op (true); |
|
417 int postfix_un_op = next_token_is_postfix_unary_op (true); |
|
418 |
|
419 if (! (postfix_un_op || bin_op) |
4608
|
420 && nesting_level.is_bracket_or_brace () |
3388
|
421 && lexer_flags.convert_spaces_to_comma) |
967
|
422 { |
3388
|
423 if ((tmp & ATE_NEWLINE) == ATE_NEWLINE) |
|
424 { |
|
425 maybe_warn_separator_insert (';'); |
967
|
426 |
4476
|
427 yyunput (';', yytext); |
3388
|
428 } |
|
429 |
4476
|
430 lexer_flags.quote_is_transpose = false; |
|
431 lexer_flags.convert_spaces_to_comma = true; |
|
432 |
|
433 maybe_warn_separator_insert (','); |
|
434 |
4910
|
435 COUNT_TOK_AND_RETURN (','); |
967
|
436 } |
|
437 } |
430
|
438 |
968
|
439 %{ |
1088
|
440 // Semicolons are handled as row seprators in matrix constants. If we |
|
441 // don't eat whitespace here we can end up inserting too many |
|
442 // semicolons. |
968
|
443 %} |
|
444 |
4208
|
445 <MATRIX_START>{SNLCMT}*;{SNLCMT}* { |
3665
|
446 scan_for_comments (yytext); |
967
|
447 fixup_column_count (yytext); |
1001
|
448 eat_whitespace (); |
2857
|
449 lexer_flags.quote_is_transpose = false; |
|
450 lexer_flags.convert_spaces_to_comma = true; |
4910
|
451 COUNT_TOK_AND_RETURN (';'); |
967
|
452 } |
|
453 |
968
|
454 %{ |
1088
|
455 // In some cases, new lines can also become row separators. If we |
|
456 // don't eat whitespace here we can end up inserting too many |
|
457 // semicolons. |
985
|
458 %} |
|
459 |
4208
|
460 <MATRIX_START>{S}*{COMMENT}{SNLCMT}* | |
|
461 <MATRIX_START>{S}*{NL}{SNLCMT}* { |
3665
|
462 scan_for_comments (yytext); |
1082
|
463 fixup_column_count (yytext); |
1088
|
464 eat_whitespace (); |
3388
|
465 |
4476
|
466 lexer_flags.quote_is_transpose = false; |
|
467 lexer_flags.convert_spaces_to_comma = true; |
|
468 |
|
469 if (nesting_level.none ()) |
|
470 return LEXICAL_ERROR; |
985
|
471 |
4608
|
472 if (nesting_level.is_bracket_or_brace ()) |
3388
|
473 { |
|
474 maybe_warn_separator_insert (';'); |
|
475 |
4910
|
476 COUNT_TOK_AND_RETURN (';'); |
985
|
477 } |
|
478 } |
|
479 |
967
|
480 \[{S}* { |
3351
|
481 nesting_level.bracket (); |
975
|
482 |
1082
|
483 current_input_column += yyleng; |
2857
|
484 lexer_flags.quote_is_transpose = false; |
|
485 lexer_flags.convert_spaces_to_comma = true; |
975
|
486 |
|
487 promptflag--; |
|
488 eat_whitespace (); |
|
489 |
5102
|
490 lexer_flags.bracketflag++; |
|
491 BEGIN (MATRIX_START); |
|
492 COUNT_TOK_AND_RETURN ('['); |
967
|
493 } |
1
|
494 |
968
|
495 \] { |
1826
|
496 nesting_level.remove (); |
968
|
497 |
5102
|
498 TOK_RETURN (']'); |
968
|
499 } |
|
500 |
|
501 %{ |
|
502 // Imaginary numbers. |
|
503 %} |
|
504 |
|
505 {NUMBER}{Im} { |
3246
|
506 handle_number (); |
4910
|
507 COUNT_TOK_AND_RETURN (IMAG_NUM); |
968
|
508 } |
|
509 |
|
510 %{ |
|
511 // Real numbers. Don't grab the `.' part of a dot operator as part of |
|
512 // the constant. |
|
513 %} |
|
514 |
|
515 {D}+/\.[\*/\\^'] | |
|
516 {NUMBER} { |
3246
|
517 handle_number (); |
4910
|
518 COUNT_TOK_AND_RETURN (NUM); |
968
|
519 } |
|
520 |
|
521 %{ |
|
522 // Eat whitespace. Whitespace inside matrix constants is handled by |
4208
|
523 // the <MATRIX_START> start state code above. |
968
|
524 %} |
|
525 |
967
|
526 {S}* { |
|
527 current_input_column += yyleng; |
|
528 } |
|
529 |
968
|
530 %{ |
|
531 // Continuation lines. Allow comments after continuations. |
|
532 %} |
|
533 |
967
|
534 {CONT}{S}*{NL} | |
|
535 {CONT}{S}*{COMMENT} { |
4037
|
536 if (yytext[0] == '\\') |
|
537 gripe_matlab_incompatible_continuation (); |
3665
|
538 scan_for_comments (yytext); |
967
|
539 promptflag--; |
|
540 current_input_column = 1; |
|
541 } |
1
|
542 |
968
|
543 %{ |
|
544 // An ellipsis not at the end of a line is not a continuation, but |
|
545 // does have another meaning. |
|
546 %} |
|
547 |
967
|
548 {EL} { |
3973
|
549 if (lexer_flags.looking_at_parameter_list) |
3974
|
550 { |
|
551 warning ("`...' is deprecated; use varargin instead"); |
4910
|
552 COUNT_TOK_AND_RETURN (VARARGIN); |
3974
|
553 } |
3973
|
554 else if (lexer_flags.looking_at_return_list) |
3974
|
555 { |
|
556 warning ("`...' is deprecated; use varargout instead"); |
4910
|
557 COUNT_TOK_AND_RETURN (VARARGOUT); |
3974
|
558 } |
3973
|
559 else |
|
560 return LEXICAL_ERROR; |
967
|
561 } |
1
|
562 |
968
|
563 %{ |
|
564 // End of file. |
|
565 %} |
|
566 |
967
|
567 <<EOF>> { |
|
568 TOK_RETURN (END_OF_INPUT); |
|
569 } |
1
|
570 |
968
|
571 %{ |
970
|
572 // Identifiers. Truncate the token at the first space or tab but |
|
573 // don't write directly on yytext. |
968
|
574 %} |
|
575 |
967
|
576 {IDENT}{S}* { |
4238
|
577 int id_tok = handle_identifier (); |
|
578 |
|
579 if (id_tok >= 0) |
4910
|
580 COUNT_TOK_AND_RETURN (id_tok); |
967
|
581 } |
1
|
582 |
968
|
583 %{ |
4342
|
584 // Function handles. |
|
585 %} |
|
586 |
4930
|
587 "@" { |
|
588 current_input_column++; |
|
589 lexer_flags.quote_is_transpose = false; |
|
590 lexer_flags.convert_spaces_to_comma = false; |
|
591 lexer_flags.looking_at_function_handle++; |
|
592 COUNT_TOK_AND_RETURN ('@'); |
4342
|
593 } |
|
594 |
|
595 %{ |
968
|
596 // A new line character. New line characters inside matrix constants |
4208
|
597 // are handled by the <MATRIX_START> start state code above. If closest |
985
|
598 // nesting is inside parentheses, don't return a row separator. |
968
|
599 %} |
|
600 |
967
|
601 {NL} { |
|
602 current_input_column = 1; |
2857
|
603 lexer_flags.quote_is_transpose = false; |
|
604 lexer_flags.convert_spaces_to_comma = true; |
1826
|
605 if (nesting_level.none ()) |
4910
|
606 COUNT_TOK_AND_RETURN ('\n'); |
4037
|
607 else if (nesting_level.is_paren ()) |
|
608 gripe_matlab_incompatible ("bare newline inside parentheses"); |
4608
|
609 else if (nesting_level.is_bracket_or_brace ()) |
985
|
610 return LEXICAL_ERROR; |
967
|
611 } |
1
|
612 |
968
|
613 %{ |
|
614 // Single quote can either be the beginning of a string or a transpose |
|
615 // operator. |
|
616 %} |
|
617 |
967
|
618 "'" { |
|
619 current_input_column++; |
2857
|
620 lexer_flags.convert_spaces_to_comma = true; |
1
|
621 |
1826
|
622 if (lexer_flags.quote_is_transpose) |
967
|
623 { |
|
624 do_comma_insert_check (); |
4910
|
625 COUNT_TOK_AND_RETURN (QUOTE); |
967
|
626 } |
|
627 else |
4910
|
628 COUNT_TOK_AND_RETURN (handle_string ('\'')); |
967
|
629 } |
1
|
630 |
968
|
631 %{ |
971
|
632 // Double quotes always begin strings. |
|
633 %} |
|
634 |
973
|
635 \" { |
|
636 current_input_column++; |
4910
|
637 COUNT_TOK_AND_RETURN (handle_string ('"')); |
973
|
638 } |
971
|
639 |
|
640 %{ |
985
|
641 // Gobble comments. If closest nesting is inside parentheses, don't |
|
642 // return a new line. |
|
643 %} |
968
|
644 |
967
|
645 {CCHAR} { |
4426
|
646 std::string help_txt; |
|
647 |
|
648 if (! help_buf.empty ()) |
|
649 help_txt = help_buf.top (); |
|
650 |
|
651 if (help_txt.empty () |
1826
|
652 && lexer_flags.beginning_of_function |
|
653 && nesting_level.none ()) |
967
|
654 { |
3665
|
655 lexer_flags.beginning_of_function = false; |
|
656 |
4426
|
657 std::string txt = grab_help_text (); |
|
658 |
|
659 if (! help_buf.empty ()) |
|
660 help_buf.pop (); |
|
661 |
|
662 help_buf.push (txt); |
|
663 |
|
664 octave_comment_buffer::append (txt); |
967
|
665 } |
|
666 else |
|
667 { |
3665
|
668 std::string buf; |
|
669 |
|
670 bool begin_comment = true; |
|
671 |
967
|
672 int c; |
|
673 while ((c = yyinput ()) != EOF && c != '\n') |
3665
|
674 { |
|
675 if (begin_comment && (c == '#' || c == '%')) |
|
676 ; /* Skip leading comment characters. */ |
|
677 else |
3802
|
678 buf += static_cast<char> (c); |
3665
|
679 } |
|
680 |
|
681 octave_comment_buffer::append (buf); |
967
|
682 } |
440
|
683 |
967
|
684 current_input_column = 1; |
2857
|
685 lexer_flags.quote_is_transpose = false; |
|
686 lexer_flags.convert_spaces_to_comma = true; |
985
|
687 |
4037
|
688 maybe_gripe_matlab_incompatible_comment (yytext[0]); |
|
689 |
4323
|
690 if (YY_START == COMMAND_START) |
|
691 BEGIN (INITIAL); |
|
692 |
1826
|
693 if (nesting_level.none ()) |
4910
|
694 COUNT_TOK_AND_RETURN ('\n'); |
4608
|
695 else if (nesting_level.is_bracket_or_brace ()) |
4910
|
696 COUNT_TOK_AND_RETURN (';'); |
967
|
697 } |
440
|
698 |
968
|
699 %{ |
|
700 // Other operators. |
|
701 %} |
|
702 |
5102
|
703 ":" { BIN_OP_RETURN (':', false); } |
|
704 |
4037
|
705 ".+" { XBIN_OP_RETURN (EPLUS, false); } |
|
706 ".-" { XBIN_OP_RETURN (EMINUS, false); } |
2857
|
707 ".*" { BIN_OP_RETURN (EMUL, false); } |
|
708 "./" { BIN_OP_RETURN (EDIV, false); } |
|
709 ".\\" { BIN_OP_RETURN (ELEFTDIV, false); } |
4037
|
710 ".^" { BIN_OP_RETURN (EPOW, false); } |
|
711 ".**" { XBIN_OP_RETURN (EPOW, false); } |
2857
|
712 ".'" { do_comma_insert_check (); BIN_OP_RETURN (TRANSPOSE, true); } |
4037
|
713 "++" { do_comma_insert_check (); XBIN_OP_RETURN (PLUS_PLUS, true); } |
|
714 "--" { do_comma_insert_check (); XBIN_OP_RETURN (MINUS_MINUS, true); } |
2857
|
715 "<=" { BIN_OP_RETURN (EXPR_LE, false); } |
|
716 "==" { BIN_OP_RETURN (EXPR_EQ, false); } |
4037
|
717 "~=" { BIN_OP_RETURN (EXPR_NE, false); } |
|
718 "!=" { XBIN_OP_RETURN (EXPR_NE, false); } |
2857
|
719 ">=" { BIN_OP_RETURN (EXPR_GE, false); } |
2877
|
720 "&" { BIN_OP_RETURN (EXPR_AND, false); } |
2857
|
721 "|" { BIN_OP_RETURN (EXPR_OR, false); } |
|
722 "<" { BIN_OP_RETURN (EXPR_LT, false); } |
|
723 ">" { BIN_OP_RETURN (EXPR_GT, false); } |
5102
|
724 "+" { BIN_OP_RETURN ('+', false); } |
|
725 "-" { BIN_OP_RETURN ('-', false); } |
2857
|
726 "*" { BIN_OP_RETURN ('*', false); } |
|
727 "/" { BIN_OP_RETURN ('/', false); } |
|
728 "\\" { BIN_OP_RETURN (LEFTDIV, false); } |
|
729 ";" { BIN_OP_RETURN (';', true); } |
|
730 "," { BIN_OP_RETURN (',', true); } |
4037
|
731 "^" { BIN_OP_RETURN (POW, false); } |
|
732 "**" { XBIN_OP_RETURN (POW, false); } |
2857
|
733 "=" { BIN_OP_RETURN ('=', true); } |
2877
|
734 "&&" { BIN_OP_RETURN (EXPR_AND_AND, false); } |
2857
|
735 "||" { BIN_OP_RETURN (EXPR_OR_OR, false); } |
4037
|
736 "<<" { XBIN_OP_RETURN (LSHIFT, false); } |
|
737 ">>" { XBIN_OP_RETURN (RSHIFT, false); } |
967
|
738 |
|
739 {NOT} { |
4037
|
740 if (yytext[0] == '~') |
|
741 BIN_OP_RETURN (EXPR_NOT, false); |
|
742 else |
|
743 XBIN_OP_RETURN (EXPR_NOT, false); |
967
|
744 } |
1
|
745 |
967
|
746 "(" { |
4131
|
747 lexer_flags.looking_at_indirect_ref = false; |
1826
|
748 nesting_level.paren (); |
985
|
749 promptflag--; |
967
|
750 TOK_RETURN ('('); |
|
751 } |
|
752 |
|
753 ")" { |
1826
|
754 nesting_level.remove (); |
967
|
755 current_input_column++; |
2857
|
756 lexer_flags.quote_is_transpose = true; |
4608
|
757 lexer_flags.convert_spaces_to_comma = nesting_level.is_bracket_or_brace (); |
1001
|
758 do_comma_insert_check (); |
4910
|
759 COUNT_TOK_AND_RETURN (')'); |
967
|
760 } |
|
761 |
5102
|
762 "." { TOK_RETURN ('.'); } |
2066
|
763 |
4037
|
764 "+=" { XBIN_OP_RETURN (ADD_EQ, false); } |
|
765 "-=" { XBIN_OP_RETURN (SUB_EQ, false); } |
|
766 "*=" { XBIN_OP_RETURN (MUL_EQ, false); } |
|
767 "/=" { XBIN_OP_RETURN (DIV_EQ, false); } |
|
768 "\\=" { XBIN_OP_RETURN (LEFTDIV_EQ, false); } |
|
769 ".+=" { XBIN_OP_RETURN (ADD_EQ, false); } |
|
770 ".-=" { XBIN_OP_RETURN (SUB_EQ, false); } |
|
771 ".*=" { XBIN_OP_RETURN (EMUL_EQ, false); } |
|
772 "./=" { XBIN_OP_RETURN (EDIV_EQ, false); } |
|
773 ".\\=" { XBIN_OP_RETURN (ELEFTDIV_EQ, false); } |
|
774 {POW}= { XBIN_OP_RETURN (POW_EQ, false); } |
|
775 {EPOW}= { XBIN_OP_RETURN (EPOW_EQ, false); } |
|
776 "&=" { XBIN_OP_RETURN (AND_EQ, false); } |
|
777 "|=" { XBIN_OP_RETURN (OR_EQ, false); } |
|
778 "<<=" { XBIN_OP_RETURN (LSHIFT_EQ, false); } |
|
779 ">>=" { XBIN_OP_RETURN (RSHIFT_EQ, false); } |
2877
|
780 |
4608
|
781 \{{S}* { |
3351
|
782 nesting_level.brace (); |
4608
|
783 |
|
784 current_input_column += yyleng; |
|
785 lexer_flags.quote_is_transpose = false; |
|
786 lexer_flags.convert_spaces_to_comma = true; |
|
787 |
3351
|
788 promptflag--; |
4608
|
789 eat_whitespace (); |
|
790 |
4613
|
791 lexer_flags.braceflag++; |
4608
|
792 BEGIN (MATRIX_START); |
4910
|
793 COUNT_TOK_AND_RETURN ('{'); |
3351
|
794 } |
|
795 |
|
796 "}" { |
|
797 nesting_level.remove (); |
|
798 |
4608
|
799 TOK_RETURN ('}'); |
3351
|
800 } |
|
801 |
968
|
802 %{ |
2066
|
803 // Unrecognized input is a lexical error. |
968
|
804 %} |
1
|
805 |
2042
|
806 . { |
4240
|
807 // EOF happens here if we are parsing nested functions. |
|
808 |
4410
|
809 yyunput (yytext[0], yytext); |
4248
|
810 |
|
811 int c = yyinput (); |
|
812 |
|
813 if (c != EOF) |
4240
|
814 { |
|
815 current_input_column++; |
|
816 |
|
817 error ("invalid character `%s' (ASCII %d) near line %d, column %d", |
4248
|
818 undo_string_escape (static_cast<char> (c)), c, |
4240
|
819 input_line_number, current_input_column); |
|
820 |
|
821 return LEXICAL_ERROR; |
|
822 } |
|
823 else |
|
824 TOK_RETURN (END_OF_INPUT); |
2066
|
825 } |
1
|
826 |
|
827 %% |
|
828 |
767
|
829 // GAG. |
|
830 // |
|
831 // If we're reading a matrix and the next character is '[', make sure |
|
832 // that we insert a comma ahead of it. |
|
833 |
146
|
834 void |
1
|
835 do_comma_insert_check (void) |
|
836 { |
1001
|
837 int spc_gobbled = eat_continuation (); |
2970
|
838 |
1
|
839 int c = yyinput (); |
2970
|
840 |
4410
|
841 yyunput (c, yytext); |
2970
|
842 |
1001
|
843 if (spc_gobbled) |
4410
|
844 yyunput (' ', yytext); |
2970
|
845 |
3351
|
846 lexer_flags.do_comma_insert = (lexer_flags.bracketflag && c == '['); |
1
|
847 } |
|
848 |
767
|
849 // Fix things up for errors or interrupts. The parser is never called |
|
850 // recursively, so it is always safe to reinitialize its state before |
|
851 // doing any parsing. |
|
852 |
1
|
853 void |
|
854 reset_parser (void) |
|
855 { |
1826
|
856 // Start off on the right foot. |
4323
|
857 BEGIN (INITIAL); |
4318
|
858 |
3883
|
859 parser_end_of_input = false; |
4238
|
860 end_tokens_expected = 0; |
|
861 |
|
862 while (! symtab_context.empty ()) |
|
863 symtab_context.pop (); |
287
|
864 |
1826
|
865 // We do want a prompt by default. |
1
|
866 promptflag = 1; |
287
|
867 |
3351
|
868 // Error may have occurred inside some brackets, braces, or parentheses. |
985
|
869 nesting_level.clear (); |
287
|
870 |
1826
|
871 // Clear out the stack of token info used to track line and column |
|
872 // numbers. |
143
|
873 while (! token_stack.empty ()) |
4214
|
874 { |
|
875 delete token_stack.top (); |
|
876 token_stack.pop (); |
|
877 } |
287
|
878 |
1826
|
879 // Can be reset by defining a function. |
985
|
880 if (! (reading_script_file || reading_fcn_file)) |
|
881 { |
|
882 current_input_column = 1; |
2926
|
883 input_line_number = command_editor::current_command_number () - 1; |
985
|
884 } |
287
|
885 |
1826
|
886 // Only ask for input from stdin if we are expecting interactive |
|
887 // input. |
3174
|
888 if ((interactive || forced_interactive) |
3880
|
889 && ! (reading_fcn_file |
|
890 || reading_script_file |
|
891 || get_input_from_eval_string |
3174
|
892 || input_from_startup_file)) |
287
|
893 yyrestart (stdin); |
991
|
894 |
1826
|
895 // Clear the buffer for help text. |
4426
|
896 while (! help_buf.empty ()) |
|
897 help_buf.pop (); |
1755
|
898 |
1826
|
899 // Reset other flags. |
|
900 lexer_flags.init (); |
1
|
901 } |
|
902 |
767
|
903 // If we read some newlines, we need figure out what column we're |
|
904 // really looking at. |
|
905 |
1
|
906 static void |
|
907 fixup_column_count (char *s) |
|
908 { |
|
909 char c; |
|
910 while ((c = *s++) != '\0') |
|
911 { |
|
912 if (c == '\n') |
143
|
913 current_input_column = 1; |
1
|
914 else |
|
915 current_input_column++; |
|
916 } |
|
917 } |
|
918 |
767
|
919 // Include these so that we don't have to link to libfl.a. |
246
|
920 |
3332
|
921 int |
1
|
922 yywrap (void) |
|
923 { |
287
|
924 return 1; |
1
|
925 } |
|
926 |
767
|
927 // Tell us all what the current buffer is. |
|
928 |
1
|
929 YY_BUFFER_STATE |
|
930 current_buffer (void) |
|
931 { |
|
932 return YY_CURRENT_BUFFER; |
|
933 } |
|
934 |
767
|
935 // Create a new buffer. |
|
936 |
1
|
937 YY_BUFFER_STATE |
|
938 create_buffer (FILE *f) |
|
939 { |
|
940 return yy_create_buffer (f, YY_BUF_SIZE); |
|
941 } |
|
942 |
767
|
943 // Start reading a new buffer. |
|
944 |
1
|
945 void |
|
946 switch_to_buffer (YY_BUFFER_STATE buf) |
|
947 { |
|
948 yy_switch_to_buffer (buf); |
|
949 } |
|
950 |
767
|
951 // Delete a buffer. |
|
952 |
1
|
953 void |
|
954 delete_buffer (YY_BUFFER_STATE buf) |
|
955 { |
|
956 yy_delete_buffer (buf); |
|
957 } |
|
958 |
767
|
959 // Restore a buffer (for unwind-prot). |
|
960 |
1
|
961 void |
|
962 restore_input_buffer (void *buf) |
|
963 { |
2861
|
964 switch_to_buffer (static_cast<YY_BUFFER_STATE> (buf)); |
1
|
965 } |
|
966 |
767
|
967 // Delete a buffer (for unwind-prot). |
|
968 |
1
|
969 void |
|
970 delete_input_buffer (void *buf) |
|
971 { |
2861
|
972 delete_buffer (static_cast<YY_BUFFER_STATE> (buf)); |
1
|
973 } |
|
974 |
4238
|
975 static void |
|
976 prep_for_function (void) |
|
977 { |
|
978 end_tokens_expected++; |
|
979 |
|
980 // Prepare for local symbols. |
|
981 |
|
982 tmp_local_sym_tab = new symbol_table (); |
|
983 |
|
984 promptflag--; |
|
985 |
|
986 lexer_flags.defining_func = true; |
|
987 lexer_flags.parsed_function_name = false; |
|
988 lexer_flags.beginning_of_function = true; |
|
989 |
|
990 if (! (reading_fcn_file || reading_script_file)) |
|
991 input_line_number = 1; |
|
992 } |
|
993 |
|
994 static void |
|
995 prep_for_nested_function (void) |
|
996 { |
4240
|
997 lexer_flags.parsing_nested_function = 1; |
4426
|
998 help_buf.push (std::string ()); |
4238
|
999 prep_for_function (); |
4240
|
1000 // We're still only expecting one end token for this set of functions. |
|
1001 end_tokens_expected--; |
4238
|
1002 yylval.tok_val = new token (input_line_number, current_input_column); |
|
1003 token_stack.push (yylval.tok_val); |
|
1004 } |
|
1005 |
|
1006 // Handle keywords. Return -1 if the keyword should be ignored. |
767
|
1007 |
1
|
1008 static int |
4867
|
1009 is_keyword_token (const std::string& s) |
1
|
1010 { |
3805
|
1011 int l = input_line_number; |
|
1012 int c = current_input_column; |
|
1013 |
1823
|
1014 int len = s.length (); |
922
|
1015 |
5088
|
1016 const octave_kw *kw = octave_kw_hash::in_word_set (s.c_str (), len); |
191
|
1017 |
1497
|
1018 if (kw) |
143
|
1019 { |
1497
|
1020 yylval.tok_val = 0; |
|
1021 |
|
1022 switch (kw->kw_id) |
|
1023 { |
|
1024 case all_va_args_kw: |
|
1025 case break_kw: |
2764
|
1026 case case_kw: |
1497
|
1027 case catch_kw: |
|
1028 case continue_kw: |
|
1029 case else_kw: |
|
1030 case elseif_kw: |
|
1031 case global_kw: |
2764
|
1032 case otherwise_kw: |
1497
|
1033 case return_kw: |
2846
|
1034 case static_kw: |
3484
|
1035 case until_kw: |
1497
|
1036 case unwind_protect_cleanup_kw: |
|
1037 break; |
|
1038 |
|
1039 case end_kw: |
4234
|
1040 if (lexer_flags.looking_at_object_index) |
|
1041 return 0; |
|
1042 else |
4238
|
1043 { |
|
1044 if (reading_fcn_file && end_tokens_expected == 1) |
|
1045 return -1; |
|
1046 else |
|
1047 { |
|
1048 yylval.tok_val = new token (token::simple_end, l, c); |
|
1049 end_tokens_expected--; |
|
1050 } |
|
1051 } |
1497
|
1052 break; |
|
1053 |
|
1054 case end_try_catch_kw: |
4238
|
1055 end_tokens_expected--; |
1497
|
1056 yylval.tok_val = new token (token::try_catch_end, l, c); |
|
1057 break; |
|
1058 |
|
1059 case end_unwind_protect_kw: |
4238
|
1060 end_tokens_expected--; |
1497
|
1061 yylval.tok_val = new token (token::unwind_protect_end, l, c); |
|
1062 break; |
|
1063 |
|
1064 case endfor_kw: |
4238
|
1065 end_tokens_expected--; |
1497
|
1066 yylval.tok_val = new token (token::for_end, l, c); |
|
1067 break; |
|
1068 |
|
1069 case endfunction_kw: |
4238
|
1070 { |
|
1071 if (reading_fcn_file && end_tokens_expected == 1) |
|
1072 return -1; |
|
1073 else |
|
1074 { |
|
1075 yylval.tok_val = new token (token::function_end, l, c); |
|
1076 end_tokens_expected--; |
|
1077 } |
|
1078 } |
1497
|
1079 break; |
|
1080 |
|
1081 case endif_kw: |
4238
|
1082 end_tokens_expected--; |
1497
|
1083 yylval.tok_val = new token (token::if_end, l, c); |
|
1084 break; |
|
1085 |
2764
|
1086 case endswitch_kw: |
4238
|
1087 end_tokens_expected--; |
2764
|
1088 yylval.tok_val = new token (token::switch_end, l, c); |
|
1089 break; |
|
1090 |
1497
|
1091 case endwhile_kw: |
4238
|
1092 end_tokens_expected--; |
1497
|
1093 yylval.tok_val = new token (token::while_end, l, c); |
|
1094 break; |
|
1095 |
|
1096 case for_kw: |
|
1097 case while_kw: |
4238
|
1098 end_tokens_expected++; |
|
1099 // Fall through... |
|
1100 |
|
1101 case do_kw: |
1497
|
1102 promptflag--; |
1826
|
1103 lexer_flags.looping++; |
1497
|
1104 break; |
|
1105 |
|
1106 case if_kw: |
|
1107 case try_kw: |
2764
|
1108 case switch_kw: |
1497
|
1109 case unwind_protect_kw: |
4238
|
1110 end_tokens_expected++; |
1497
|
1111 promptflag--; |
|
1112 break; |
|
1113 |
|
1114 case function_kw: |
4238
|
1115 { |
|
1116 if (lexer_flags.defining_func) |
|
1117 { |
|
1118 if (reading_fcn_file) |
|
1119 { |
|
1120 if (lexer_flags.parsing_nested_function) |
|
1121 { |
4323
|
1122 BEGIN (NESTED_FUNCTION_END); |
4240
|
1123 |
4238
|
1124 yylval.tok_val = new token (token::function_end, l, c); |
4240
|
1125 token_stack.push (yylval.tok_val); |
|
1126 |
|
1127 return END; |
4238
|
1128 } |
|
1129 else |
|
1130 { |
|
1131 prep_for_nested_function (); |
4240
|
1132 |
4238
|
1133 return FCN; |
|
1134 } |
|
1135 } |
|
1136 else |
|
1137 { |
|
1138 error ("nested functions not implemented in this context"); |
|
1139 |
|
1140 if ((reading_fcn_file || reading_script_file) |
|
1141 && ! curr_fcn_file_name.empty ()) |
|
1142 error ("near line %d of file `%s.m'", |
|
1143 input_line_number, curr_fcn_file_name.c_str ()); |
|
1144 else |
|
1145 error ("near line %d", input_line_number); |
|
1146 |
|
1147 return LEXICAL_ERROR; |
|
1148 } |
|
1149 } |
|
1150 else |
|
1151 prep_for_function (); |
|
1152 } |
1497
|
1153 break; |
|
1154 |
3174
|
1155 case magic_file_kw: |
|
1156 { |
|
1157 if ((reading_fcn_file || reading_script_file) |
|
1158 && ! curr_fcn_file_full_name.empty ()) |
|
1159 yylval.tok_val = new token (curr_fcn_file_full_name, l, c); |
|
1160 else |
|
1161 yylval.tok_val = new token ("stdin", l, c); |
|
1162 } |
|
1163 break; |
|
1164 |
|
1165 case magic_line_kw: |
|
1166 yylval.tok_val = new token (static_cast<double> (l), "", l, c); |
|
1167 break; |
|
1168 |
3974
|
1169 case varargin_kw: |
|
1170 if (! lexer_flags.looking_at_parameter_list) |
|
1171 return 0; |
|
1172 break; |
|
1173 |
|
1174 case varargout_kw: |
4678
|
1175 if (! (lexer_flags.looking_at_return_list |
|
1176 || (lexer_flags.defining_func |
|
1177 && ! lexer_flags.parsed_function_name))) |
3974
|
1178 return 0; |
|
1179 break; |
|
1180 |
1497
|
1181 default: |
|
1182 panic_impossible (); |
|
1183 } |
|
1184 |
|
1185 if (! yylval.tok_val) |
|
1186 yylval.tok_val = new token (l, c); |
|
1187 |
476
|
1188 token_stack.push (yylval.tok_val); |
1497
|
1189 |
|
1190 return kw->tok; |
143
|
1191 } |
1
|
1192 |
|
1193 return 0; |
|
1194 } |
|
1195 |
767
|
1196 // Try to find an identifier. All binding to global or builtin |
|
1197 // variables occurs when expressions are evaluated. |
|
1198 |
1
|
1199 static symbol_record * |
3523
|
1200 lookup_identifier (const std::string& name) |
1
|
1201 { |
4238
|
1202 std::string sym_name = name; |
|
1203 |
|
1204 if (curr_sym_tab == fbi_sym_tab |
|
1205 && lexer_flags.parsing_nested_function) |
|
1206 sym_name = parent_function_name + ":" + sym_name; |
|
1207 |
|
1208 return curr_sym_tab->lookup (sym_name, true); |
1
|
1209 } |
|
1210 |
2702
|
1211 static bool |
3523
|
1212 is_variable (const std::string& name) |
2702
|
1213 { |
2856
|
1214 symbol_record *sr = curr_sym_tab->lookup (name); |
2702
|
1215 |
|
1216 return sr && sr->is_variable (); |
|
1217 } |
|
1218 |
|
1219 static void |
3523
|
1220 force_local_variable (const std::string& name) |
2702
|
1221 { |
4101
|
1222 if (! is_variable (name)) |
|
1223 curr_sym_tab->clear (name); |
|
1224 |
2856
|
1225 symbol_record *sr = curr_sym_tab->lookup (name, true); |
2702
|
1226 |
|
1227 if (sr) |
|
1228 sr->define (octave_value ()); |
|
1229 } |
|
1230 |
4426
|
1231 // Grab the help text from an function file. |
767
|
1232 |
3427
|
1233 // XXX FIXME XXX -- gobble_leading_white_space() in parse.y |
2300
|
1234 // duplicates some of this code! |
|
1235 |
4426
|
1236 static std::string |
1
|
1237 grab_help_text (void) |
|
1238 { |
4426
|
1239 std::string buf; |
1019
|
1240 |
2300
|
1241 bool begin_comment = true; |
|
1242 bool in_comment = true; |
3427
|
1243 bool discard_space = true; |
3665
|
1244 |
1019
|
1245 int c = 0; |
1
|
1246 |
1019
|
1247 while ((c = yyinput ()) != EOF) |
|
1248 { |
2300
|
1249 if (begin_comment) |
|
1250 { |
|
1251 if (c == '%' || c == '#') |
|
1252 continue; |
3427
|
1253 else if (discard_space && c == ' ') |
|
1254 { |
|
1255 discard_space = false; |
|
1256 continue; |
|
1257 } |
2300
|
1258 else |
|
1259 begin_comment = false; |
|
1260 } |
|
1261 |
1019
|
1262 if (in_comment) |
1
|
1263 { |
4426
|
1264 buf += static_cast<char> (c); |
1755
|
1265 |
1019
|
1266 if (c == '\n') |
3427
|
1267 { |
|
1268 in_comment = false; |
|
1269 discard_space = true; |
|
1270 } |
1019
|
1271 } |
|
1272 else |
|
1273 { |
|
1274 switch (c) |
991
|
1275 { |
4037
|
1276 case '#': |
1019
|
1277 case '%': |
4037
|
1278 maybe_gripe_matlab_incompatible_comment (yytext[0]); |
2300
|
1279 in_comment = true; |
|
1280 begin_comment = true; |
1019
|
1281 break; |
777
|
1282 |
1019
|
1283 case ' ': |
|
1284 case '\t': |
|
1285 break; |
777
|
1286 |
1019
|
1287 default: |
|
1288 goto done; |
1
|
1289 } |
|
1290 } |
1019
|
1291 } |
991
|
1292 |
1019
|
1293 done: |
991
|
1294 |
1019
|
1295 if (c) |
4410
|
1296 yyunput (c, yytext); |
4426
|
1297 |
|
1298 return buf; |
1
|
1299 } |
|
1300 |
767
|
1301 // Return 1 if the given character matches any character in the given |
|
1302 // string. |
|
1303 |
2857
|
1304 static bool |
2804
|
1305 match_any (char c, const char *s) |
1
|
1306 { |
|
1307 char tmp; |
|
1308 while ((tmp = *s++) != '\0') |
|
1309 { |
|
1310 if (c == tmp) |
2857
|
1311 return true; |
1
|
1312 } |
2857
|
1313 return false; |
1
|
1314 } |
|
1315 |
767
|
1316 // Given information about the spacing surrounding an operator, |
|
1317 // return 1 if it looks like it should be treated as a binary |
|
1318 // operator. For example, |
|
1319 // |
3774
|
1320 // [ 1 + 2 ] or [ 1+ 2] or [ 1+2 ] ==> binary |
|
1321 // |
|
1322 // [ 1 +2 ] ==> unary |
767
|
1323 |
2857
|
1324 static bool |
3246
|
1325 looks_like_bin_op (bool spc_prev, int next_char) |
1
|
1326 { |
3246
|
1327 bool spc_next = (next_char == ' ' || next_char == '\t'); |
|
1328 |
608
|
1329 return ((spc_prev && spc_next) || ! spc_prev); |
1
|
1330 } |
|
1331 |
3263
|
1332 // Recognize separators. If the separator is a CRLF pair, it is |
|
1333 // replaced by a single LF. |
|
1334 |
|
1335 static bool |
|
1336 next_token_is_sep_op (void) |
|
1337 { |
|
1338 bool retval = false; |
|
1339 |
|
1340 int c1 = yyinput (); |
|
1341 |
|
1342 if (c1 == '\r') |
|
1343 { |
|
1344 int c2 = yyinput (); |
|
1345 |
|
1346 if (c2 == '\n') |
|
1347 { |
|
1348 c1 = '\n'; |
|
1349 |
|
1350 retval = true; |
|
1351 } |
|
1352 else |
4410
|
1353 yyunput (c2, yytext); |
3263
|
1354 } |
|
1355 else |
|
1356 retval = match_any (c1, ",;\n]"); |
|
1357 |
4410
|
1358 yyunput (c1, yytext); |
3263
|
1359 |
|
1360 return retval; |
|
1361 } |
|
1362 |
767
|
1363 // Try to determine if the next token should be treated as a postfix |
|
1364 // unary operator. This is ugly, but it seems to do the right thing. |
|
1365 |
2857
|
1366 static bool |
3246
|
1367 next_token_is_postfix_unary_op (bool spc_prev) |
1
|
1368 { |
2857
|
1369 bool un_op = false; |
1
|
1370 |
|
1371 int c0 = yyinput (); |
|
1372 |
3246
|
1373 if (c0 == '\'' && ! spc_prev) |
|
1374 { |
|
1375 un_op = true; |
|
1376 } |
|
1377 else if (c0 == '.') |
|
1378 { |
|
1379 int c1 = yyinput (); |
|
1380 un_op = (c1 == '\''); |
4410
|
1381 yyunput (c1, yytext); |
3246
|
1382 } |
4613
|
1383 else if (c0 == '+') |
|
1384 { |
|
1385 int c1 = yyinput (); |
|
1386 un_op = (c1 == '+'); |
|
1387 yyunput (c1, yytext); |
|
1388 } |
|
1389 else if (c0 == '-') |
|
1390 { |
|
1391 int c1 = yyinput (); |
|
1392 un_op = (c1 == '-'); |
|
1393 yyunput (c1, yytext); |
|
1394 } |
1
|
1395 |
4410
|
1396 yyunput (c0, yytext); |
1
|
1397 |
|
1398 return un_op; |
|
1399 } |
|
1400 |
767
|
1401 // Try to determine if the next token should be treated as a binary |
3246
|
1402 // operator. |
1521
|
1403 // |
3246
|
1404 // This kluge exists because whitespace is not always ignored inside |
3774
|
1405 // the square brackets that are used to create matrix objects (though |
|
1406 // spacing only really matters in the cases that can be interpreted |
|
1407 // either as binary ops or prefix unary ops: currently just +, -). |
|
1408 // |
3779
|
1409 // Note that a line continuation directly following a + or - operator |
|
1410 // (e.g., the characters '[' 'a' ' ' '+' '\' LFD 'b' ']') will be |
|
1411 // parsed as a binary operator. |
767
|
1412 |
2857
|
1413 static bool |
3246
|
1414 next_token_is_bin_op (bool spc_prev) |
1
|
1415 { |
2857
|
1416 bool bin_op = false; |
1
|
1417 |
|
1418 int c0 = yyinput (); |
|
1419 |
|
1420 switch (c0) |
|
1421 { |
777
|
1422 case '+': |
|
1423 case '-': |
3774
|
1424 { |
|
1425 int c1 = yyinput (); |
|
1426 |
|
1427 switch (c1) |
|
1428 { |
|
1429 case '+': |
|
1430 case '-': |
|
1431 // Unary ops, spacing doesn't matter. |
|
1432 break; |
|
1433 |
|
1434 case '=': |
|
1435 // Binary ops, spacing doesn't matter. |
|
1436 bin_op = true; |
|
1437 break; |
|
1438 |
|
1439 default: |
|
1440 // Could be either, spacing matters. |
|
1441 bin_op = looks_like_bin_op (spc_prev, c1); |
|
1442 break; |
|
1443 } |
|
1444 |
4410
|
1445 yyunput (c1, yytext); |
3774
|
1446 } |
|
1447 break; |
|
1448 |
|
1449 case ':': |
3246
|
1450 case '/': |
|
1451 case '\\': |
|
1452 case '^': |
3774
|
1453 // Always a binary op (may also include /=, \=, and ^=). |
|
1454 bin_op = true; |
1276
|
1455 break; |
|
1456 |
3246
|
1457 // .+ .- ./ .\ .^ .* .** |
1554
|
1458 case '.': |
|
1459 { |
|
1460 int c1 = yyinput (); |
3246
|
1461 |
3774
|
1462 if (match_any (c1, "+-/\\^*")) |
|
1463 // Always a binary op (may also include .+=, .-=, ./=, ...). |
|
1464 bin_op = true; |
3698
|
1465 else if (! isdigit (c1) && c1 != ' ' && c1 != '\t' && c1 != '.') |
3774
|
1466 // A structure element reference is a binary op. |
|
1467 bin_op = true; |
3246
|
1468 |
4410
|
1469 yyunput (c1, yytext); |
1554
|
1470 } |
|
1471 break; |
|
1472 |
3246
|
1473 // = == & && | || * ** |
|
1474 case '=': |
1
|
1475 case '&': |
3246
|
1476 case '|': |
1
|
1477 case '*': |
3774
|
1478 // Always a binary op (may also include ==, &&, ||, **). |
|
1479 bin_op = true; |
3246
|
1480 break; |
|
1481 |
3774
|
1482 // < <= <> > >= |
1
|
1483 case '<': |
|
1484 case '>': |
3774
|
1485 // Always a binary op (may also include <=, <>, >=). |
|
1486 bin_op = true; |
|
1487 break; |
|
1488 |
|
1489 // ~= != |
777
|
1490 case '~': |
|
1491 case '!': |
3246
|
1492 { |
|
1493 int c1 = yyinput (); |
|
1494 |
3774
|
1495 // ~ and ! can be unary ops, so require following =. |
|
1496 if (c1 == '=') |
|
1497 bin_op = true; |
3246
|
1498 |
4410
|
1499 yyunput (c1, yytext); |
3246
|
1500 } |
1
|
1501 break; |
|
1502 |
|
1503 default: |
1276
|
1504 break; |
1
|
1505 } |
|
1506 |
4410
|
1507 yyunput (c0, yytext); |
1
|
1508 |
|
1509 return bin_op; |
|
1510 } |
|
1511 |
767
|
1512 // Used to delete trailing white space from tokens. |
|
1513 |
3536
|
1514 static std::string |
1
|
1515 strip_trailing_whitespace (char *s) |
|
1516 { |
3523
|
1517 std::string retval = s; |
1
|
1518 |
1823
|
1519 size_t pos = retval.find_first_of (" \t"); |
1
|
1520 |
1823
|
1521 if (pos != NPOS) |
|
1522 retval.resize (pos); |
1
|
1523 |
|
1524 return retval; |
|
1525 } |
|
1526 |
3665
|
1527 static void |
|
1528 scan_for_comments (const char *text) |
|
1529 { |
|
1530 std::string comment_buf; |
|
1531 |
|
1532 bool in_comment = false; |
|
1533 bool beginning_of_comment = false; |
|
1534 |
|
1535 int len = strlen (text); |
|
1536 int i = 0; |
|
1537 |
|
1538 while (i < len) |
|
1539 { |
|
1540 char c = text[i++]; |
|
1541 |
|
1542 switch (c) |
|
1543 { |
|
1544 case '%': |
|
1545 case '#': |
|
1546 if (in_comment) |
|
1547 { |
|
1548 if (! beginning_of_comment) |
3802
|
1549 comment_buf += static_cast<char> (c); |
3665
|
1550 } |
|
1551 else |
|
1552 { |
4037
|
1553 maybe_gripe_matlab_incompatible_comment (c); |
3665
|
1554 in_comment = true; |
|
1555 beginning_of_comment = true; |
|
1556 } |
|
1557 break; |
|
1558 |
|
1559 case '\n': |
|
1560 if (in_comment) |
|
1561 { |
3802
|
1562 comment_buf += static_cast<char> (c); |
3665
|
1563 octave_comment_buffer::append (comment_buf); |
|
1564 comment_buf.resize (0); |
|
1565 in_comment = false; |
|
1566 beginning_of_comment = false; |
|
1567 } |
|
1568 break; |
|
1569 |
|
1570 case '\r': |
|
1571 if (in_comment) |
3802
|
1572 comment_buf += static_cast<char> (c); |
3665
|
1573 if (i < len) |
|
1574 { |
|
1575 c = text[i++]; |
|
1576 |
|
1577 if (c == '\n') |
|
1578 { |
|
1579 if (in_comment) |
|
1580 { |
3802
|
1581 comment_buf += static_cast<char> (c); |
3665
|
1582 octave_comment_buffer::append (comment_buf); |
|
1583 in_comment = false; |
|
1584 beginning_of_comment = false; |
|
1585 } |
|
1586 } |
|
1587 } |
|
1588 |
|
1589 default: |
|
1590 if (in_comment) |
|
1591 { |
3802
|
1592 comment_buf += static_cast<char> (c); |
3665
|
1593 beginning_of_comment = false; |
|
1594 } |
|
1595 break; |
|
1596 } |
|
1597 } |
|
1598 |
|
1599 if (! comment_buf.empty ()) |
|
1600 octave_comment_buffer::append (comment_buf); |
|
1601 } |
|
1602 |
1001
|
1603 // Discard whitespace, including comments and continuations. |
1088
|
1604 // |
|
1605 // Return value is logical OR of the following values: |
|
1606 // |
1826
|
1607 // ATE_NOTHING : no spaces to eat |
1088
|
1608 // ATE_SPACE_OR_TAB : space or tab in input |
|
1609 // ATE_NEWLINE : bare new line in input |
1001
|
1610 |
1826
|
1611 static yum_yum |
975
|
1612 eat_whitespace (void) |
|
1613 { |
1826
|
1614 yum_yum retval = ATE_NOTHING; |
3665
|
1615 |
|
1616 std::string comment_buf; |
|
1617 |
2857
|
1618 bool in_comment = false; |
3665
|
1619 bool beginning_of_comment = false; |
|
1620 |
|
1621 int c = 0; |
|
1622 |
975
|
1623 while ((c = yyinput ()) != EOF) |
|
1624 { |
|
1625 current_input_column++; |
|
1626 |
|
1627 switch (c) |
|
1628 { |
|
1629 case ' ': |
|
1630 case '\t': |
3665
|
1631 if (in_comment) |
|
1632 { |
3802
|
1633 comment_buf += static_cast<char> (c); |
3665
|
1634 beginning_of_comment = false; |
|
1635 } |
1088
|
1636 retval |= ATE_SPACE_OR_TAB; |
975
|
1637 break; |
|
1638 |
|
1639 case '\n': |
1088
|
1640 retval |= ATE_NEWLINE; |
3665
|
1641 if (in_comment) |
|
1642 { |
3802
|
1643 comment_buf += static_cast<char> (c); |
3665
|
1644 octave_comment_buffer::append (comment_buf); |
|
1645 comment_buf.resize (0); |
|
1646 in_comment = false; |
|
1647 beginning_of_comment = false; |
|
1648 } |
975
|
1649 current_input_column = 0; |
|
1650 break; |
|
1651 |
|
1652 case '#': |
|
1653 case '%': |
3665
|
1654 if (in_comment) |
|
1655 { |
|
1656 if (! beginning_of_comment) |
3802
|
1657 comment_buf += static_cast<char> (c); |
3665
|
1658 } |
|
1659 else |
|
1660 { |
4037
|
1661 maybe_gripe_matlab_incompatible_comment (c); |
3665
|
1662 in_comment = true; |
|
1663 beginning_of_comment = true; |
|
1664 } |
975
|
1665 break; |
|
1666 |
1001
|
1667 case '.': |
|
1668 if (in_comment) |
3665
|
1669 { |
3802
|
1670 comment_buf += static_cast<char> (c); |
3665
|
1671 beginning_of_comment = false; |
|
1672 break; |
|
1673 } |
1001
|
1674 else |
|
1675 { |
|
1676 if (have_ellipsis_continuation ()) |
|
1677 break; |
|
1678 else |
|
1679 goto done; |
|
1680 } |
|
1681 |
|
1682 case '\\': |
|
1683 if (in_comment) |
3665
|
1684 { |
3802
|
1685 comment_buf += static_cast<char> (c); |
3665
|
1686 beginning_of_comment = false; |
|
1687 break; |
|
1688 } |
1001
|
1689 else |
|
1690 { |
3105
|
1691 if (have_continuation ()) |
1001
|
1692 break; |
|
1693 else |
|
1694 goto done; |
|
1695 } |
|
1696 |
975
|
1697 default: |
|
1698 if (in_comment) |
3665
|
1699 { |
3802
|
1700 comment_buf += static_cast<char> (c); |
3665
|
1701 beginning_of_comment = false; |
|
1702 break; |
|
1703 } |
975
|
1704 else |
|
1705 goto done; |
|
1706 } |
|
1707 } |
|
1708 |
3665
|
1709 if (! comment_buf.empty ()) |
|
1710 octave_comment_buffer::append (comment_buf); |
|
1711 |
975
|
1712 done: |
4410
|
1713 yyunput (c, yytext); |
1082
|
1714 current_input_column--; |
1001
|
1715 return retval; |
975
|
1716 } |
|
1717 |
3220
|
1718 static inline bool |
|
1719 looks_like_hex (const char *s, int len) |
|
1720 { |
|
1721 return (len > 2 && s[0] == '0' && (s[1] == 'x' || s[1] == 'X')); |
|
1722 } |
|
1723 |
975
|
1724 static void |
3246
|
1725 handle_number (void) |
972
|
1726 { |
3220
|
1727 double value = 0.0; |
|
1728 int nread = 0; |
|
1729 |
3598
|
1730 if (looks_like_hex (yytext, strlen (yytext))) |
3220
|
1731 { |
|
1732 unsigned long ival; |
3598
|
1733 |
|
1734 nread = sscanf (yytext, "%lx", &ival); |
|
1735 |
3220
|
1736 value = static_cast<double> (ival); |
|
1737 } |
|
1738 else |
3598
|
1739 { |
|
1740 char *tmp = strsave (yytext); |
|
1741 |
|
1742 char *idx = strpbrk (tmp, "Dd"); |
2621
|
1743 |
3598
|
1744 if (idx) |
|
1745 *idx = 'e'; |
|
1746 |
|
1747 nread = sscanf (tmp, "%lf", &value); |
|
1748 |
|
1749 delete [] tmp; |
|
1750 } |
972
|
1751 |
1826
|
1752 // If yytext doesn't contain a valid number, we are in deep doo doo. |
985
|
1753 |
972
|
1754 assert (nread == 1); |
|
1755 |
3988
|
1756 lexer_flags.quote_is_transpose = true; |
|
1757 lexer_flags.convert_spaces_to_comma = true; |
972
|
1758 |
|
1759 yylval.tok_val = new token (value, yytext, input_line_number, |
|
1760 current_input_column); |
|
1761 |
|
1762 token_stack.push (yylval.tok_val); |
|
1763 |
|
1764 current_input_column += yyleng; |
|
1765 |
|
1766 do_comma_insert_check (); |
|
1767 } |
|
1768 |
1001
|
1769 // We have seen a backslash and need to find out if it should be |
|
1770 // treated as a continuation character. If so, this eats it, up to |
|
1771 // and including the new line character. |
|
1772 // |
973
|
1773 // Match whitespace only, followed by a comment character or newline. |
|
1774 // Once a comment character is found, discard all input until newline. |
|
1775 // If non-whitespace characters are found before comment |
|
1776 // characters, return 0. Otherwise, return 1. |
|
1777 |
2857
|
1778 static bool |
3096
|
1779 have_continuation (bool trailing_comments_ok) |
973
|
1780 { |
4051
|
1781 OSSTREAM buf; |
973
|
1782 |
3665
|
1783 std::string comment_buf; |
|
1784 |
2857
|
1785 bool in_comment = false; |
3665
|
1786 bool beginning_of_comment = false; |
|
1787 |
|
1788 int c = 0; |
|
1789 |
973
|
1790 while ((c = yyinput ()) != EOF) |
|
1791 { |
3802
|
1792 buf << static_cast<char> (c); |
973
|
1793 |
|
1794 switch (c) |
|
1795 { |
|
1796 case ' ': |
|
1797 case '\t': |
3665
|
1798 if (in_comment) |
|
1799 { |
3802
|
1800 comment_buf += static_cast<char> (c); |
3665
|
1801 beginning_of_comment = false; |
|
1802 } |
973
|
1803 break; |
|
1804 |
|
1805 case '%': |
|
1806 case '#': |
1091
|
1807 if (trailing_comments_ok) |
3665
|
1808 { |
|
1809 if (in_comment) |
|
1810 { |
|
1811 if (! beginning_of_comment) |
3802
|
1812 comment_buf += static_cast<char> (c); |
3665
|
1813 } |
|
1814 else |
|
1815 { |
4037
|
1816 maybe_gripe_matlab_incompatible_comment (c); |
3665
|
1817 in_comment = true; |
|
1818 beginning_of_comment = true; |
|
1819 } |
|
1820 } |
1091
|
1821 else |
|
1822 goto cleanup; |
973
|
1823 break; |
|
1824 |
|
1825 case '\n': |
3665
|
1826 if (in_comment) |
|
1827 { |
3802
|
1828 comment_buf += static_cast<char> (c); |
3665
|
1829 octave_comment_buffer::append (comment_buf); |
|
1830 } |
975
|
1831 current_input_column = 0; |
1001
|
1832 promptflag--; |
4037
|
1833 gripe_matlab_incompatible_continuation (); |
2857
|
1834 return true; |
973
|
1835 |
3263
|
1836 case '\r': |
3665
|
1837 if (in_comment) |
3802
|
1838 comment_buf += static_cast<char> (c); |
3263
|
1839 c = yyinput (); |
|
1840 if (c == EOF) |
|
1841 break; |
|
1842 else if (c == '\n') |
|
1843 { |
3665
|
1844 if (in_comment) |
|
1845 { |
3802
|
1846 comment_buf += static_cast<char> (c); |
3665
|
1847 octave_comment_buffer::append (comment_buf); |
|
1848 } |
3263
|
1849 current_input_column = 0; |
|
1850 promptflag--; |
4037
|
1851 gripe_matlab_incompatible_continuation (); |
3263
|
1852 return true; |
3665
|
1853 } |
3263
|
1854 |
3802
|
1855 // Fall through... |
|
1856 |
973
|
1857 default: |
3665
|
1858 if (in_comment) |
|
1859 { |
3802
|
1860 comment_buf += static_cast<char> (c); |
3665
|
1861 beginning_of_comment = false; |
|
1862 } |
|
1863 else |
1091
|
1864 goto cleanup; |
|
1865 break; |
973
|
1866 } |
|
1867 } |
|
1868 |
4410
|
1869 yyunput (c, yytext); |
2857
|
1870 return false; |
973
|
1871 |
3096
|
1872 cleanup: |
4051
|
1873 |
|
1874 buf << OSSTREAM_ENDS; |
|
1875 std::string s = OSSTREAM_STR (buf); |
|
1876 OSSTREAM_FREEZE (buf); |
|
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 { |
4051
|
1934 OSSTREAM 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 { |
1053
|
1948 if (escape_pending) |
|
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 { |
3096
|
1967 if (! 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); |
4051
|
1992 buf << OSSTREAM_ENDS; |
5279
|
1993 if (lexer_flags.doing_rawcommand || delim == '\'') |
5102
|
1994 s = OSSTREAM_STR (buf); |
|
1995 else |
|
1996 s = do_string_escapes (OSSTREAM_STR(buf)); |
4051
|
1997 OSSTREAM_FREEZE (buf); |
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 } |
2702
|
2342 else if (! next_tok_is_paren) |
|
2343 { |
5102
|
2344 BEGIN (COMMAND_START); |
|
2345 } |
|
2346 |
|
2347 if (is_rawcommand_name (tok)) |
|
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 |
|
2468 print_usage ("iskeyword"); |
|
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 |
|
2479 if (Vwarn_separator_insert) |
|
2480 { |
|
2481 if (nm.empty ()) |
|
2482 warning ("potential auto-insertion of `%c' near line %d", |
|
2483 sep, input_line_number); |
|
2484 else |
|
2485 warning ("potential auto-insertion of `%c' near line %d of file %s", |
|
2486 sep, input_line_number, nm.c_str ()); |
|
2487 } |
|
2488 } |
|
2489 |
3400
|
2490 static void |
|
2491 gripe_single_quote_string (void) |
|
2492 { |
3523
|
2493 std::string nm = curr_fcn_file_full_name; |
3400
|
2494 |
|
2495 if (Vwarn_single_quote_string) |
|
2496 { |
|
2497 if (nm.empty ()) |
|
2498 warning ("single quote delimited string near line %d", |
|
2499 input_line_number); |
|
2500 else |
|
2501 warning ("single quote delimited string near line %d of file %s", |
|
2502 input_line_number, nm.c_str ()); |
|
2503 } |
|
2504 } |
|
2505 |
4037
|
2506 static void |
|
2507 gripe_matlab_incompatible (const std::string& msg) |
|
2508 { |
|
2509 if (Vwarn_matlab_incompatible) |
|
2510 warning ("potential Matlab compatibility problem: %s", msg.c_str ()); |
|
2511 } |
|
2512 |
|
2513 static void |
|
2514 maybe_gripe_matlab_incompatible_comment (char c) |
|
2515 { |
|
2516 if (c == '#') |
|
2517 gripe_matlab_incompatible ("# used as comment character"); |
|
2518 } |
|
2519 |
|
2520 static void |
|
2521 gripe_matlab_incompatible_continuation (void) |
|
2522 { |
|
2523 gripe_matlab_incompatible ("\\ used as line continuation marker"); |
|
2524 } |
|
2525 |
|
2526 static void |
|
2527 gripe_matlab_incompatible_operator (const std::string& op) |
|
2528 { |
|
2529 std::string t = op; |
|
2530 int n = t.length (); |
|
2531 if (t[n-1] == '\n') |
|
2532 t.resize (n-1); |
|
2533 gripe_matlab_incompatible (t + " used as operator"); |
|
2534 } |
|
2535 |
4910
|
2536 DEFUN (__token_count__, , , |
|
2537 "-*- texinfo -*-\n\ |
|
2538 @deftypefn {Built-in Function} {} __token_count__\n\ |
|
2539 Number of language tokens processed since Octave startup.\n\ |
|
2540 @end deftypefn") |
|
2541 { |
|
2542 return octave_value (Vtoken_count); |
|
2543 } |
|
2544 |
4037
|
2545 static int |
|
2546 warn_matlab_incompatible (void) |
|
2547 { |
|
2548 Vwarn_matlab_incompatible = check_preference ("warn_matlab_incompatible"); |
|
2549 |
|
2550 return 0; |
|
2551 } |
|
2552 |
3388
|
2553 static int |
|
2554 warn_separator_insert (void) |
|
2555 { |
|
2556 Vwarn_separator_insert = check_preference ("warn_separator_insert"); |
|
2557 |
|
2558 return 0; |
|
2559 } |
|
2560 |
3246
|
2561 static int |
3400
|
2562 warn_single_quote_string (void) |
|
2563 { |
|
2564 Vwarn_single_quote_string = check_preference ("warn_single_quote_string"); |
|
2565 |
|
2566 return 0; |
|
2567 } |
|
2568 |
2167
|
2569 void |
|
2570 symbols_of_lex (void) |
|
2571 { |
4233
|
2572 DEFVAR (warn_matlab_incompatible, false, warn_matlab_incompatible, |
4037
|
2573 "-*- texinfo -*-\n\ |
|
2574 @defvr {Built-in Variable} warn_matlab_incompatible\n\ |
|
2575 Print warnings for Octave language features that may cause\n\ |
|
2576 compatibility problems with Matlab.\n\ |
|
2577 @end defvr"); |
|
2578 |
4233
|
2579 DEFVAR (warn_separator_insert, false, warn_separator_insert, |
3428
|
2580 "-*- texinfo -*-\n\ |
|
2581 @defvr {Built-in Variable} warn_separator_insert\n\ |
3567
|
2582 Print warning if commas or semicolons might be inserted\n\ |
3428
|
2583 automatically in literal matrices.\n\ |
|
2584 @end defvr"); |
3388
|
2585 |
4233
|
2586 DEFVAR (warn_single_quote_string, false, warn_single_quote_string, |
3428
|
2587 "-*- texinfo -*-\n\ |
|
2588 @defvr {Built-in Variable} warn_single_quote_string\n\ |
|
2589 Print warning if a signle quote character is used to introduce a\n\ |
|
2590 string constant.\n\ |
|
2591 @end defvr"); |
2167
|
2592 } |
|
2593 |
1994
|
2594 /* |
|
2595 ;;; Local Variables: *** |
|
2596 ;;; mode: C++ *** |
|
2597 ;;; End: *** |
|
2598 */ |