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