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