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