Mercurial > hg > octave-nkf
comparison libinterp/parse-tree/lex.ll @ 16110:7302f8a4df83
use pointer for global lexical_feedback structure
* lex.h, lex.ll (curr_lexer): Rename from lexer_flags.
Declare as pointer. Change all uses.
* lex.h (lexical_feedback): Make copy constructor and operator=
private.
* toplev.cc (main_loop): Protect existing and initialize new
curr_lexer.
* input.cc (get_debug_input): Likewise.
author | John W. Eaton <jwe@octave.org> |
---|---|
date | Tue, 26 Feb 2013 01:10:08 -0500 |
parents | 031117f4db7c |
children | 3ec4f6488569 |
comparison
equal
deleted
inserted
replaced
16109:229eb14653fd | 16110:7302f8a4df83 |
---|---|
146 while (0) | 146 while (0) |
147 | 147 |
148 #define TOK_RETURN(tok) \ | 148 #define TOK_RETURN(tok) \ |
149 do \ | 149 do \ |
150 { \ | 150 { \ |
151 lexer_flags.current_input_column += yyleng; \ | 151 curr_lexer->current_input_column += yyleng; \ |
152 lexer_flags.quote_is_transpose = false; \ | 152 curr_lexer->quote_is_transpose = false; \ |
153 lexer_flags.convert_spaces_to_comma = true; \ | 153 curr_lexer->convert_spaces_to_comma = true; \ |
154 COUNT_TOK_AND_RETURN (tok); \ | 154 COUNT_TOK_AND_RETURN (tok); \ |
155 } \ | 155 } \ |
156 while (0) | 156 while (0) |
157 | 157 |
158 #define TOK_PUSH_AND_RETURN(name, tok) \ | 158 #define TOK_PUSH_AND_RETURN(name, tok) \ |
159 do \ | 159 do \ |
160 { \ | 160 { \ |
161 yylval.tok_val = new token (name, lexer_flags.input_line_number, \ | 161 yylval.tok_val = new token (name, curr_lexer->input_line_number, \ |
162 lexer_flags.current_input_column); \ | 162 curr_lexer->current_input_column); \ |
163 token_stack.push (yylval.tok_val); \ | 163 token_stack.push (yylval.tok_val); \ |
164 TOK_RETURN (tok); \ | 164 TOK_RETURN (tok); \ |
165 } \ | 165 } \ |
166 while (0) | 166 while (0) |
167 | 167 |
168 #define BIN_OP_RETURN_INTERNAL(tok, convert, bos, qit) \ | 168 #define BIN_OP_RETURN_INTERNAL(tok, convert, bos, qit) \ |
169 do \ | 169 do \ |
170 { \ | 170 { \ |
171 yylval.tok_val = new token (lexer_flags.input_line_number, \ | 171 yylval.tok_val = new token (curr_lexer->input_line_number, \ |
172 lexer_flags.current_input_column); \ | 172 curr_lexer->current_input_column); \ |
173 token_stack.push (yylval.tok_val); \ | 173 token_stack.push (yylval.tok_val); \ |
174 lexer_flags.current_input_column += yyleng; \ | 174 curr_lexer->current_input_column += yyleng; \ |
175 lexer_flags.quote_is_transpose = qit; \ | 175 curr_lexer->quote_is_transpose = qit; \ |
176 lexer_flags.convert_spaces_to_comma = convert; \ | 176 curr_lexer->convert_spaces_to_comma = convert; \ |
177 lexer_flags.looking_for_object_index = false; \ | 177 curr_lexer->looking_for_object_index = false; \ |
178 lexer_flags.at_beginning_of_statement = bos; \ | 178 curr_lexer->at_beginning_of_statement = bos; \ |
179 COUNT_TOK_AND_RETURN (tok); \ | 179 COUNT_TOK_AND_RETURN (tok); \ |
180 } \ | 180 } \ |
181 while (0) | 181 while (0) |
182 | 182 |
183 #define XBIN_OP_RETURN_INTERNAL(tok, convert, bos, qit) \ | 183 #define XBIN_OP_RETURN_INTERNAL(tok, convert, bos, qit) \ |
210 lexer_debug (pattern, yytext); \ | 210 lexer_debug (pattern, yytext); \ |
211 } \ | 211 } \ |
212 while (0) | 212 while (0) |
213 | 213 |
214 // The state of the lexer. | 214 // The state of the lexer. |
215 lexical_feedback lexer_flags; | 215 lexical_feedback *curr_lexer = 0; |
216 | 216 |
217 // Stack to hold tokens so that we can delete them when the parser is | 217 // Stack to hold tokens so that we can delete them when the parser is |
218 // reset and avoid growing forever just because we are stashing some | 218 // reset and avoid growing forever just because we are stashing some |
219 // information. This has to appear before lex.h is included, because | 219 // information. This has to appear before lex.h is included, because |
220 // one of the macros defined there uses token_stack. | 220 // one of the macros defined there uses token_stack. |
313 | 313 |
314 <COMMAND_START>{NL} { | 314 <COMMAND_START>{NL} { |
315 LEXER_DEBUG ("<COMMAND_START>{NL}"); | 315 LEXER_DEBUG ("<COMMAND_START>{NL}"); |
316 | 316 |
317 BEGIN (INITIAL); | 317 BEGIN (INITIAL); |
318 lexer_flags.input_line_number++; | 318 curr_lexer->input_line_number++; |
319 lexer_flags.current_input_column = 1; | 319 curr_lexer->current_input_column = 1; |
320 | 320 |
321 lexer_flags.quote_is_transpose = false; | 321 curr_lexer->quote_is_transpose = false; |
322 lexer_flags.convert_spaces_to_comma = true; | 322 curr_lexer->convert_spaces_to_comma = true; |
323 lexer_flags.looking_for_object_index = false; | 323 curr_lexer->looking_for_object_index = false; |
324 lexer_flags.at_beginning_of_statement = true; | 324 curr_lexer->at_beginning_of_statement = true; |
325 | 325 |
326 COUNT_TOK_AND_RETURN ('\n'); | 326 COUNT_TOK_AND_RETURN ('\n'); |
327 } | 327 } |
328 | 328 |
329 <COMMAND_START>[\;\,] { | 329 <COMMAND_START>[\;\,] { |
330 LEXER_DEBUG ("<COMMAND_START>[\\;\\,]"); | 330 LEXER_DEBUG ("<COMMAND_START>[\\;\\,]"); |
331 | 331 |
332 lexer_flags.looking_for_object_index = false; | 332 curr_lexer->looking_for_object_index = false; |
333 lexer_flags.at_beginning_of_statement = true; | 333 curr_lexer->at_beginning_of_statement = true; |
334 | 334 |
335 BEGIN (INITIAL); | 335 BEGIN (INITIAL); |
336 | 336 |
337 if (strcmp (yytext, ",") == 0) | 337 if (strcmp (yytext, ",") == 0) |
338 TOK_RETURN (','); | 338 TOK_RETURN (','); |
341 } | 341 } |
342 | 342 |
343 <COMMAND_START>[\"\'] { | 343 <COMMAND_START>[\"\'] { |
344 LEXER_DEBUG ("<COMMAND_START>[\\\"\\']"); | 344 LEXER_DEBUG ("<COMMAND_START>[\\\"\\']"); |
345 | 345 |
346 lexer_flags.at_beginning_of_statement = false; | 346 curr_lexer->at_beginning_of_statement = false; |
347 | 347 |
348 lexer_flags.current_input_column++; | 348 curr_lexer->current_input_column++; |
349 int tok = handle_string (yytext[0]); | 349 int tok = handle_string (yytext[0]); |
350 | 350 |
351 COUNT_TOK_AND_RETURN (tok); | 351 COUNT_TOK_AND_RETURN (tok); |
352 } | 352 } |
353 | 353 |
354 <COMMAND_START>[^#% \t\r\n\;\,\"\'][^ \t\r\n\;\,]*{S}* { | 354 <COMMAND_START>[^#% \t\r\n\;\,\"\'][^ \t\r\n\;\,]*{S}* { |
355 LEXER_DEBUG ("<COMMAND_START>[^#% \\t\\r\\n\\;\\,\\\"\\'][^ \\t\\r\\n\\;\\,]*{S}*"); | 355 LEXER_DEBUG ("<COMMAND_START>[^#% \\t\\r\\n\\;\\,\\\"\\'][^ \\t\\r\\n\\;\\,]*{S}*"); |
356 | 356 |
357 std::string tok = strip_trailing_whitespace (yytext); | 357 std::string tok = strip_trailing_whitespace (yytext); |
358 | 358 |
359 lexer_flags.looking_for_object_index = false; | 359 curr_lexer->looking_for_object_index = false; |
360 lexer_flags.at_beginning_of_statement = false; | 360 curr_lexer->at_beginning_of_statement = false; |
361 | 361 |
362 TOK_PUSH_AND_RETURN (tok, SQ_STRING); | 362 TOK_PUSH_AND_RETURN (tok, SQ_STRING); |
363 } | 363 } |
364 | 364 |
365 %{ | 365 %{ |
380 LEXER_DEBUG ("<MATRIX_START>{SNLCMT}*\\]{S}*"); | 380 LEXER_DEBUG ("<MATRIX_START>{SNLCMT}*\\]{S}*"); |
381 | 381 |
382 scan_for_comments (yytext); | 382 scan_for_comments (yytext); |
383 fixup_column_count (yytext); | 383 fixup_column_count (yytext); |
384 | 384 |
385 lexer_flags.looking_at_object_index.pop_front (); | 385 curr_lexer->looking_at_object_index.pop_front (); |
386 | 386 |
387 lexer_flags.looking_for_object_index = true; | 387 curr_lexer->looking_for_object_index = true; |
388 lexer_flags.at_beginning_of_statement = false; | 388 curr_lexer->at_beginning_of_statement = false; |
389 | 389 |
390 int c = yytext[yyleng-1]; | 390 int c = yytext[yyleng-1]; |
391 bool cont_is_spc = (eat_continuation () != lexical_feedback::NO_WHITESPACE); | 391 bool cont_is_spc = (eat_continuation () != lexical_feedback::NO_WHITESPACE); |
392 bool spc_gobbled = (cont_is_spc || c == ' ' || c == '\t'); | 392 bool spc_gobbled = (cont_is_spc || c == ' ' || c == '\t'); |
393 int tok_to_return = handle_close_bracket (spc_gobbled, ']'); | 393 int tok_to_return = handle_close_bracket (spc_gobbled, ']'); |
406 LEXER_DEBUG ("<MATRIX_START>{SNLCMT}*\\}{S}*"); | 406 LEXER_DEBUG ("<MATRIX_START>{SNLCMT}*\\}{S}*"); |
407 | 407 |
408 scan_for_comments (yytext); | 408 scan_for_comments (yytext); |
409 fixup_column_count (yytext); | 409 fixup_column_count (yytext); |
410 | 410 |
411 lexer_flags.looking_at_object_index.pop_front (); | 411 curr_lexer->looking_at_object_index.pop_front (); |
412 | 412 |
413 lexer_flags.looking_for_object_index = true; | 413 curr_lexer->looking_for_object_index = true; |
414 lexer_flags.at_beginning_of_statement = false; | 414 curr_lexer->at_beginning_of_statement = false; |
415 | 415 |
416 int c = yytext[yyleng-1]; | 416 int c = yytext[yyleng-1]; |
417 bool cont_is_spc = (eat_continuation () != lexical_feedback::NO_WHITESPACE); | 417 bool cont_is_spc = (eat_continuation () != lexical_feedback::NO_WHITESPACE); |
418 bool spc_gobbled = (cont_is_spc || c == ' ' || c == '\t'); | 418 bool spc_gobbled = (cont_is_spc || c == ' ' || c == '\t'); |
419 int tok_to_return = handle_close_bracket (spc_gobbled, '}'); | 419 int tok_to_return = handle_close_bracket (spc_gobbled, '}'); |
431 %} | 431 %} |
432 | 432 |
433 <MATRIX_START>{S}*\,{S}* { | 433 <MATRIX_START>{S}*\,{S}* { |
434 LEXER_DEBUG ("<MATRIX_START>{S}*\\,{S}*"); | 434 LEXER_DEBUG ("<MATRIX_START>{S}*\\,{S}*"); |
435 | 435 |
436 lexer_flags.current_input_column += yyleng; | 436 curr_lexer->current_input_column += yyleng; |
437 | 437 |
438 int tmp = eat_continuation (); | 438 int tmp = eat_continuation (); |
439 | 439 |
440 lexer_flags.quote_is_transpose = false; | 440 curr_lexer->quote_is_transpose = false; |
441 lexer_flags.convert_spaces_to_comma = true; | 441 curr_lexer->convert_spaces_to_comma = true; |
442 lexer_flags.looking_for_object_index = false; | 442 curr_lexer->looking_for_object_index = false; |
443 lexer_flags.at_beginning_of_statement = false; | 443 curr_lexer->at_beginning_of_statement = false; |
444 | 444 |
445 if (! lexer_flags.looking_at_object_index.front ()) | 445 if (! curr_lexer->looking_at_object_index.front ()) |
446 { | 446 { |
447 if ((tmp & lexical_feedback::NEWLINE) == lexical_feedback::NEWLINE) | 447 if ((tmp & lexical_feedback::NEWLINE) == lexical_feedback::NEWLINE) |
448 { | 448 { |
449 maybe_warn_separator_insert (';'); | 449 maybe_warn_separator_insert (';'); |
450 | 450 |
463 %} | 463 %} |
464 | 464 |
465 <MATRIX_START>{S}+ { | 465 <MATRIX_START>{S}+ { |
466 LEXER_DEBUG ("<MATRIX_START>{S}+"); | 466 LEXER_DEBUG ("<MATRIX_START>{S}+"); |
467 | 467 |
468 lexer_flags.current_input_column += yyleng; | 468 curr_lexer->current_input_column += yyleng; |
469 | 469 |
470 lexer_flags.at_beginning_of_statement = false; | 470 curr_lexer->at_beginning_of_statement = false; |
471 | 471 |
472 int tmp = eat_continuation (); | 472 int tmp = eat_continuation (); |
473 | 473 |
474 if (! lexer_flags.looking_at_object_index.front ()) | 474 if (! curr_lexer->looking_at_object_index.front ()) |
475 { | 475 { |
476 bool bin_op = next_token_is_bin_op (true); | 476 bool bin_op = next_token_is_bin_op (true); |
477 bool postfix_un_op = next_token_is_postfix_unary_op (true); | 477 bool postfix_un_op = next_token_is_postfix_unary_op (true); |
478 bool sep_op = next_token_is_sep_op (); | 478 bool sep_op = next_token_is_sep_op (); |
479 | 479 |
480 if (! (postfix_un_op || bin_op || sep_op) | 480 if (! (postfix_un_op || bin_op || sep_op) |
481 && lexer_flags.nesting_level.is_bracket_or_brace () | 481 && curr_lexer->nesting_level.is_bracket_or_brace () |
482 && lexer_flags.convert_spaces_to_comma) | 482 && curr_lexer->convert_spaces_to_comma) |
483 { | 483 { |
484 if ((tmp & lexical_feedback::NEWLINE) == lexical_feedback::NEWLINE) | 484 if ((tmp & lexical_feedback::NEWLINE) == lexical_feedback::NEWLINE) |
485 { | 485 { |
486 maybe_warn_separator_insert (';'); | 486 maybe_warn_separator_insert (';'); |
487 | 487 |
488 xunput (';', yytext); | 488 xunput (';', yytext); |
489 } | 489 } |
490 | 490 |
491 lexer_flags.quote_is_transpose = false; | 491 curr_lexer->quote_is_transpose = false; |
492 lexer_flags.convert_spaces_to_comma = true; | 492 curr_lexer->convert_spaces_to_comma = true; |
493 lexer_flags.looking_for_object_index = false; | 493 curr_lexer->looking_for_object_index = false; |
494 | 494 |
495 maybe_warn_separator_insert (','); | 495 maybe_warn_separator_insert (','); |
496 | 496 |
497 COUNT_TOK_AND_RETURN (','); | 497 COUNT_TOK_AND_RETURN (','); |
498 } | 498 } |
512 | 512 |
513 scan_for_comments (yytext); | 513 scan_for_comments (yytext); |
514 fixup_column_count (yytext); | 514 fixup_column_count (yytext); |
515 eat_whitespace (); | 515 eat_whitespace (); |
516 | 516 |
517 lexer_flags.quote_is_transpose = false; | 517 curr_lexer->quote_is_transpose = false; |
518 lexer_flags.convert_spaces_to_comma = true; | 518 curr_lexer->convert_spaces_to_comma = true; |
519 lexer_flags.looking_for_object_index = false; | 519 curr_lexer->looking_for_object_index = false; |
520 lexer_flags.at_beginning_of_statement = false; | 520 curr_lexer->at_beginning_of_statement = false; |
521 | 521 |
522 COUNT_TOK_AND_RETURN (';'); | 522 COUNT_TOK_AND_RETURN (';'); |
523 } | 523 } |
524 | 524 |
525 %{ | 525 %{ |
536 | 536 |
537 scan_for_comments (yytext); | 537 scan_for_comments (yytext); |
538 fixup_column_count (yytext); | 538 fixup_column_count (yytext); |
539 eat_whitespace (); | 539 eat_whitespace (); |
540 | 540 |
541 lexer_flags.quote_is_transpose = false; | 541 curr_lexer->quote_is_transpose = false; |
542 lexer_flags.convert_spaces_to_comma = true; | 542 curr_lexer->convert_spaces_to_comma = true; |
543 lexer_flags.at_beginning_of_statement = false; | 543 curr_lexer->at_beginning_of_statement = false; |
544 | 544 |
545 if (lexer_flags.nesting_level.none ()) | 545 if (curr_lexer->nesting_level.none ()) |
546 return LEXICAL_ERROR; | 546 return LEXICAL_ERROR; |
547 | 547 |
548 if (! lexer_flags.looking_at_object_index.front () | 548 if (! curr_lexer->looking_at_object_index.front () |
549 && lexer_flags.nesting_level.is_bracket_or_brace ()) | 549 && curr_lexer->nesting_level.is_bracket_or_brace ()) |
550 { | 550 { |
551 maybe_warn_separator_insert (';'); | 551 maybe_warn_separator_insert (';'); |
552 | 552 |
553 COUNT_TOK_AND_RETURN (';'); | 553 COUNT_TOK_AND_RETURN (';'); |
554 } | 554 } |
555 } | 555 } |
556 | 556 |
557 \[{S}* { | 557 \[{S}* { |
558 LEXER_DEBUG ("\\[{S}*"); | 558 LEXER_DEBUG ("\\[{S}*"); |
559 | 559 |
560 lexer_flags.nesting_level.bracket (); | 560 curr_lexer->nesting_level.bracket (); |
561 | 561 |
562 lexer_flags.looking_at_object_index.push_front (false); | 562 curr_lexer->looking_at_object_index.push_front (false); |
563 | 563 |
564 lexer_flags.current_input_column += yyleng; | 564 curr_lexer->current_input_column += yyleng; |
565 lexer_flags.quote_is_transpose = false; | 565 curr_lexer->quote_is_transpose = false; |
566 lexer_flags.convert_spaces_to_comma = true; | 566 curr_lexer->convert_spaces_to_comma = true; |
567 lexer_flags.looking_for_object_index = false; | 567 curr_lexer->looking_for_object_index = false; |
568 lexer_flags.at_beginning_of_statement = false; | 568 curr_lexer->at_beginning_of_statement = false; |
569 | 569 |
570 if (lexer_flags.defining_func | 570 if (curr_lexer->defining_func |
571 && ! lexer_flags.parsed_function_name.top ()) | 571 && ! curr_lexer->parsed_function_name.top ()) |
572 lexer_flags.looking_at_return_list = true; | 572 curr_lexer->looking_at_return_list = true; |
573 else | 573 else |
574 lexer_flags.looking_at_matrix_or_assign_lhs = true; | 574 curr_lexer->looking_at_matrix_or_assign_lhs = true; |
575 | 575 |
576 promptflag--; | 576 promptflag--; |
577 eat_whitespace (); | 577 eat_whitespace (); |
578 | 578 |
579 lexer_flags.bracketflag++; | 579 curr_lexer->bracketflag++; |
580 BEGIN (MATRIX_START); | 580 BEGIN (MATRIX_START); |
581 COUNT_TOK_AND_RETURN ('['); | 581 COUNT_TOK_AND_RETURN ('['); |
582 } | 582 } |
583 | 583 |
584 \] { | 584 \] { |
585 LEXER_DEBUG ("\\]"); | 585 LEXER_DEBUG ("\\]"); |
586 | 586 |
587 lexer_flags.nesting_level.remove (); | 587 curr_lexer->nesting_level.remove (); |
588 | 588 |
589 lexer_flags.looking_at_object_index.pop_front (); | 589 curr_lexer->looking_at_object_index.pop_front (); |
590 | 590 |
591 lexer_flags.looking_for_object_index = true; | 591 curr_lexer->looking_for_object_index = true; |
592 lexer_flags.at_beginning_of_statement = false; | 592 curr_lexer->at_beginning_of_statement = false; |
593 | 593 |
594 TOK_RETURN (']'); | 594 TOK_RETURN (']'); |
595 } | 595 } |
596 | 596 |
597 %{ | 597 %{ |
621 // Eat whitespace. Whitespace inside matrix constants is handled by | 621 // Eat whitespace. Whitespace inside matrix constants is handled by |
622 // the <MATRIX_START> start state code above. | 622 // the <MATRIX_START> start state code above. |
623 %} | 623 %} |
624 | 624 |
625 {S}* { | 625 {S}* { |
626 lexer_flags.current_input_column += yyleng; | 626 curr_lexer->current_input_column += yyleng; |
627 } | 627 } |
628 | 628 |
629 %{ | 629 %{ |
630 // Continuation lines. Allow comments after continuations. | 630 // Continuation lines. Allow comments after continuations. |
631 %} | 631 %} |
636 | 636 |
637 if (yytext[0] == '\\') | 637 if (yytext[0] == '\\') |
638 gripe_matlab_incompatible_continuation (); | 638 gripe_matlab_incompatible_continuation (); |
639 scan_for_comments (yytext); | 639 scan_for_comments (yytext); |
640 promptflag--; | 640 promptflag--; |
641 lexer_flags.input_line_number++; | 641 curr_lexer->input_line_number++; |
642 lexer_flags.current_input_column = 1; | 642 curr_lexer->current_input_column = 1; |
643 } | 643 } |
644 | 644 |
645 %{ | 645 %{ |
646 // End of file. | 646 // End of file. |
647 %} | 647 %} |
648 | 648 |
649 <<EOF>> { | 649 <<EOF>> { |
650 LEXER_DEBUG ("<<EOF>>"); | 650 LEXER_DEBUG ("<<EOF>>"); |
651 | 651 |
652 if (lexer_flags.block_comment_nesting_level != 0) | 652 if (curr_lexer->block_comment_nesting_level != 0) |
653 { | 653 { |
654 warning ("block comment open at end of input"); | 654 warning ("block comment open at end of input"); |
655 | 655 |
656 if ((reading_fcn_file || reading_script_file || reading_classdef_file) | 656 if ((reading_fcn_file || reading_script_file || reading_classdef_file) |
657 && ! curr_fcn_file_name.empty ()) | 657 && ! curr_fcn_file_name.empty ()) |
658 warning ("near line %d of file '%s.m'", | 658 warning ("near line %d of file '%s.m'", |
659 lexer_flags.input_line_number, curr_fcn_file_name.c_str ()); | 659 curr_lexer->input_line_number, curr_fcn_file_name.c_str ()); |
660 } | 660 } |
661 | 661 |
662 TOK_RETURN (END_OF_INPUT); | 662 TOK_RETURN (END_OF_INPUT); |
663 } | 663 } |
664 | 664 |
686 | 686 |
687 int id_tok = handle_superclass_identifier (); | 687 int id_tok = handle_superclass_identifier (); |
688 | 688 |
689 if (id_tok >= 0) | 689 if (id_tok >= 0) |
690 { | 690 { |
691 lexer_flags.looking_for_object_index = true; | 691 curr_lexer->looking_for_object_index = true; |
692 | 692 |
693 COUNT_TOK_AND_RETURN (SUPERCLASSREF); | 693 COUNT_TOK_AND_RETURN (SUPERCLASSREF); |
694 } | 694 } |
695 } | 695 } |
696 | 696 |
704 | 704 |
705 int id_tok = handle_meta_identifier (); | 705 int id_tok = handle_meta_identifier (); |
706 | 706 |
707 if (id_tok >= 0) | 707 if (id_tok >= 0) |
708 { | 708 { |
709 lexer_flags.looking_for_object_index = true; | 709 curr_lexer->looking_for_object_index = true; |
710 | 710 |
711 COUNT_TOK_AND_RETURN (METAQUERY); | 711 COUNT_TOK_AND_RETURN (METAQUERY); |
712 } | 712 } |
713 } | 713 } |
714 | 714 |
717 %} | 717 %} |
718 | 718 |
719 "@" { | 719 "@" { |
720 LEXER_DEBUG ("@"); | 720 LEXER_DEBUG ("@"); |
721 | 721 |
722 lexer_flags.current_input_column++; | 722 curr_lexer->current_input_column++; |
723 | 723 |
724 lexer_flags.quote_is_transpose = false; | 724 curr_lexer->quote_is_transpose = false; |
725 lexer_flags.convert_spaces_to_comma = false; | 725 curr_lexer->convert_spaces_to_comma = false; |
726 lexer_flags.looking_at_function_handle++; | 726 curr_lexer->looking_at_function_handle++; |
727 lexer_flags.looking_for_object_index = false; | 727 curr_lexer->looking_for_object_index = false; |
728 lexer_flags.at_beginning_of_statement = false; | 728 curr_lexer->at_beginning_of_statement = false; |
729 | 729 |
730 COUNT_TOK_AND_RETURN ('@'); | 730 COUNT_TOK_AND_RETURN ('@'); |
731 | 731 |
732 } | 732 } |
733 | 733 |
738 %} | 738 %} |
739 | 739 |
740 {NL} { | 740 {NL} { |
741 LEXER_DEBUG ("{NL}"); | 741 LEXER_DEBUG ("{NL}"); |
742 | 742 |
743 lexer_flags.input_line_number++; | 743 curr_lexer->input_line_number++; |
744 lexer_flags.current_input_column = 1; | 744 curr_lexer->current_input_column = 1; |
745 | 745 |
746 lexer_flags.quote_is_transpose = false; | 746 curr_lexer->quote_is_transpose = false; |
747 lexer_flags.convert_spaces_to_comma = true; | 747 curr_lexer->convert_spaces_to_comma = true; |
748 | 748 |
749 if (lexer_flags.nesting_level.none ()) | 749 if (curr_lexer->nesting_level.none ()) |
750 { | 750 { |
751 lexer_flags.at_beginning_of_statement = true; | 751 curr_lexer->at_beginning_of_statement = true; |
752 COUNT_TOK_AND_RETURN ('\n'); | 752 COUNT_TOK_AND_RETURN ('\n'); |
753 } | 753 } |
754 else if (lexer_flags.nesting_level.is_paren ()) | 754 else if (curr_lexer->nesting_level.is_paren ()) |
755 { | 755 { |
756 lexer_flags.at_beginning_of_statement = false; | 756 curr_lexer->at_beginning_of_statement = false; |
757 gripe_matlab_incompatible ("bare newline inside parentheses"); | 757 gripe_matlab_incompatible ("bare newline inside parentheses"); |
758 } | 758 } |
759 else if (lexer_flags.nesting_level.is_bracket_or_brace ()) | 759 else if (curr_lexer->nesting_level.is_bracket_or_brace ()) |
760 return LEXICAL_ERROR; | 760 return LEXICAL_ERROR; |
761 } | 761 } |
762 | 762 |
763 %{ | 763 %{ |
764 // Single quote can either be the beginning of a string or a transpose | 764 // Single quote can either be the beginning of a string or a transpose |
766 %} | 766 %} |
767 | 767 |
768 "'" { | 768 "'" { |
769 LEXER_DEBUG ("'"); | 769 LEXER_DEBUG ("'"); |
770 | 770 |
771 lexer_flags.current_input_column++; | 771 curr_lexer->current_input_column++; |
772 lexer_flags.convert_spaces_to_comma = true; | 772 curr_lexer->convert_spaces_to_comma = true; |
773 | 773 |
774 if (lexer_flags.quote_is_transpose) | 774 if (curr_lexer->quote_is_transpose) |
775 { | 775 { |
776 do_comma_insert_check (); | 776 do_comma_insert_check (); |
777 COUNT_TOK_AND_RETURN (QUOTE); | 777 COUNT_TOK_AND_RETURN (QUOTE); |
778 } | 778 } |
779 else | 779 else |
788 %} | 788 %} |
789 | 789 |
790 \" { | 790 \" { |
791 LEXER_DEBUG ("\""); | 791 LEXER_DEBUG ("\""); |
792 | 792 |
793 lexer_flags.current_input_column++; | 793 curr_lexer->current_input_column++; |
794 int tok = handle_string ('"'); | 794 int tok = handle_string ('"'); |
795 | 795 |
796 COUNT_TOK_AND_RETURN (tok); | 796 COUNT_TOK_AND_RETURN (tok); |
797 } | 797 } |
798 | 798 |
801 %} | 801 %} |
802 | 802 |
803 {CCHAR} { | 803 {CCHAR} { |
804 LEXER_DEBUG ("{CCHAR}"); | 804 LEXER_DEBUG ("{CCHAR}"); |
805 | 805 |
806 lexer_flags.looking_for_object_index = false; | 806 curr_lexer->looking_for_object_index = false; |
807 | 807 |
808 xunput (yytext[0], yytext); | 808 xunput (yytext[0], yytext); |
809 | 809 |
810 bool eof = false; | 810 bool eof = false; |
811 int tok = process_comment (false, eof); | 811 int tok = process_comment (false, eof); |
821 %} | 821 %} |
822 | 822 |
823 ^{S}*{CCHAR}\{{S}*{NL} { | 823 ^{S}*{CCHAR}\{{S}*{NL} { |
824 LEXER_DEBUG ("^{S}*{CCHAR}\\{{S}*{NL}"); | 824 LEXER_DEBUG ("^{S}*{CCHAR}\\{{S}*{NL}"); |
825 | 825 |
826 lexer_flags.looking_for_object_index = false; | 826 curr_lexer->looking_for_object_index = false; |
827 | 827 |
828 lexer_flags.input_line_number++; | 828 curr_lexer->input_line_number++; |
829 lexer_flags.current_input_column = 1; | 829 curr_lexer->current_input_column = 1; |
830 lexer_flags.block_comment_nesting_level++; | 830 curr_lexer->block_comment_nesting_level++; |
831 promptflag--; | 831 promptflag--; |
832 | 832 |
833 bool eof = false; | 833 bool eof = false; |
834 process_comment (true, eof); | 834 process_comment (true, eof); |
835 } | 835 } |
863 "-" { LEXER_DEBUG ("-"); BIN_OP_RETURN ('-', false, false); } | 863 "-" { LEXER_DEBUG ("-"); BIN_OP_RETURN ('-', false, false); } |
864 "*" { LEXER_DEBUG ("*"); BIN_OP_RETURN ('*', false, false); } | 864 "*" { LEXER_DEBUG ("*"); BIN_OP_RETURN ('*', false, false); } |
865 "/" { LEXER_DEBUG ("/"); BIN_OP_RETURN ('/', false, false); } | 865 "/" { LEXER_DEBUG ("/"); BIN_OP_RETURN ('/', false, false); } |
866 "\\" { LEXER_DEBUG ("\\"); BIN_OP_RETURN (LEFTDIV, false, false); } | 866 "\\" { LEXER_DEBUG ("\\"); BIN_OP_RETURN (LEFTDIV, false, false); } |
867 ";" { LEXER_DEBUG (";"); BIN_OP_RETURN (';', true, true); } | 867 ";" { LEXER_DEBUG (";"); BIN_OP_RETURN (';', true, true); } |
868 "," { LEXER_DEBUG (","); BIN_OP_RETURN (',', true, ! lexer_flags.looking_at_object_index.front ()); } | 868 "," { LEXER_DEBUG (","); BIN_OP_RETURN (',', true, ! curr_lexer->looking_at_object_index.front ()); } |
869 "^" { LEXER_DEBUG ("^"); BIN_OP_RETURN (POW, false, false); } | 869 "^" { LEXER_DEBUG ("^"); BIN_OP_RETURN (POW, false, false); } |
870 "**" { LEXER_DEBUG ("**"); XBIN_OP_RETURN (POW, false, false); } | 870 "**" { LEXER_DEBUG ("**"); XBIN_OP_RETURN (POW, false, false); } |
871 "=" { LEXER_DEBUG ("="); BIN_OP_RETURN ('=', true, false); } | 871 "=" { LEXER_DEBUG ("="); BIN_OP_RETURN ('=', true, false); } |
872 "&&" { LEXER_DEBUG ("&&"); BIN_OP_RETURN (EXPR_AND_AND, false, false); } | 872 "&&" { LEXER_DEBUG ("&&"); BIN_OP_RETURN (EXPR_AND_AND, false, false); } |
873 "||" { LEXER_DEBUG ("||"); BIN_OP_RETURN (EXPR_OR_OR, false, false); } | 873 "||" { LEXER_DEBUG ("||"); BIN_OP_RETURN (EXPR_OR_OR, false, false); } |
889 // If we are looking for an object index, then push TRUE for | 889 // If we are looking for an object index, then push TRUE for |
890 // looking_at_object_index. Otherwise, just push whatever state | 890 // looking_at_object_index. Otherwise, just push whatever state |
891 // is current (so that we can pop it off the stack when we find | 891 // is current (so that we can pop it off the stack when we find |
892 // the matching close paren). | 892 // the matching close paren). |
893 | 893 |
894 lexer_flags.looking_at_object_index.push_front | 894 curr_lexer->looking_at_object_index.push_front |
895 (lexer_flags.looking_for_object_index); | 895 (curr_lexer->looking_for_object_index); |
896 | 896 |
897 lexer_flags.looking_at_indirect_ref = false; | 897 curr_lexer->looking_at_indirect_ref = false; |
898 lexer_flags.looking_for_object_index = false; | 898 curr_lexer->looking_for_object_index = false; |
899 lexer_flags.at_beginning_of_statement = false; | 899 curr_lexer->at_beginning_of_statement = false; |
900 | 900 |
901 lexer_flags.nesting_level.paren (); | 901 curr_lexer->nesting_level.paren (); |
902 promptflag--; | 902 promptflag--; |
903 | 903 |
904 TOK_RETURN ('('); | 904 TOK_RETURN ('('); |
905 } | 905 } |
906 | 906 |
907 ")" { | 907 ")" { |
908 LEXER_DEBUG (")"); | 908 LEXER_DEBUG (")"); |
909 | 909 |
910 lexer_flags.nesting_level.remove (); | 910 curr_lexer->nesting_level.remove (); |
911 lexer_flags.current_input_column++; | 911 curr_lexer->current_input_column++; |
912 | 912 |
913 lexer_flags.looking_at_object_index.pop_front (); | 913 curr_lexer->looking_at_object_index.pop_front (); |
914 | 914 |
915 lexer_flags.quote_is_transpose = true; | 915 curr_lexer->quote_is_transpose = true; |
916 lexer_flags.convert_spaces_to_comma | 916 curr_lexer->convert_spaces_to_comma |
917 = (lexer_flags.nesting_level.is_bracket_or_brace () | 917 = (curr_lexer->nesting_level.is_bracket_or_brace () |
918 && ! lexer_flags.looking_at_anon_fcn_args); | 918 && ! curr_lexer->looking_at_anon_fcn_args); |
919 lexer_flags.looking_for_object_index = true; | 919 curr_lexer->looking_for_object_index = true; |
920 lexer_flags.at_beginning_of_statement = false; | 920 curr_lexer->at_beginning_of_statement = false; |
921 | 921 |
922 if (lexer_flags.looking_at_anon_fcn_args) | 922 if (curr_lexer->looking_at_anon_fcn_args) |
923 lexer_flags.looking_at_anon_fcn_args = false; | 923 curr_lexer->looking_at_anon_fcn_args = false; |
924 | 924 |
925 do_comma_insert_check (); | 925 do_comma_insert_check (); |
926 | 926 |
927 COUNT_TOK_AND_RETURN (')'); | 927 COUNT_TOK_AND_RETURN (')'); |
928 } | 928 } |
929 | 929 |
930 "." { | 930 "." { |
931 LEXER_DEBUG ("."); | 931 LEXER_DEBUG ("."); |
932 | 932 |
933 lexer_flags.looking_for_object_index = false; | 933 curr_lexer->looking_for_object_index = false; |
934 lexer_flags.at_beginning_of_statement = false; | 934 curr_lexer->at_beginning_of_statement = false; |
935 | 935 |
936 TOK_RETURN ('.'); | 936 TOK_RETURN ('.'); |
937 } | 937 } |
938 | 938 |
939 "+=" { LEXER_DEBUG ("+="); XBIN_OP_RETURN (ADD_EQ, false, false); } | 939 "+=" { LEXER_DEBUG ("+="); XBIN_OP_RETURN (ADD_EQ, false, false); } |
954 ">>=" { LEXER_DEBUG (">>="); XBIN_OP_RETURN (RSHIFT_EQ, false, false); } | 954 ">>=" { LEXER_DEBUG (">>="); XBIN_OP_RETURN (RSHIFT_EQ, false, false); } |
955 | 955 |
956 \{{S}* { | 956 \{{S}* { |
957 LEXER_DEBUG ("\\{{S}*"); | 957 LEXER_DEBUG ("\\{{S}*"); |
958 | 958 |
959 lexer_flags.nesting_level.brace (); | 959 curr_lexer->nesting_level.brace (); |
960 | 960 |
961 lexer_flags.looking_at_object_index.push_front | 961 curr_lexer->looking_at_object_index.push_front |
962 (lexer_flags.looking_for_object_index); | 962 (curr_lexer->looking_for_object_index); |
963 | 963 |
964 lexer_flags.current_input_column += yyleng; | 964 curr_lexer->current_input_column += yyleng; |
965 lexer_flags.quote_is_transpose = false; | 965 curr_lexer->quote_is_transpose = false; |
966 lexer_flags.convert_spaces_to_comma = true; | 966 curr_lexer->convert_spaces_to_comma = true; |
967 lexer_flags.looking_for_object_index = false; | 967 curr_lexer->looking_for_object_index = false; |
968 lexer_flags.at_beginning_of_statement = false; | 968 curr_lexer->at_beginning_of_statement = false; |
969 | 969 |
970 promptflag--; | 970 promptflag--; |
971 eat_whitespace (); | 971 eat_whitespace (); |
972 | 972 |
973 lexer_flags.braceflag++; | 973 curr_lexer->braceflag++; |
974 BEGIN (MATRIX_START); | 974 BEGIN (MATRIX_START); |
975 COUNT_TOK_AND_RETURN ('{'); | 975 COUNT_TOK_AND_RETURN ('{'); |
976 } | 976 } |
977 | 977 |
978 "}" { | 978 "}" { |
979 LEXER_DEBUG ("}"); | 979 LEXER_DEBUG ("}"); |
980 | 980 |
981 lexer_flags.looking_at_object_index.pop_front (); | 981 curr_lexer->looking_at_object_index.pop_front (); |
982 | 982 |
983 lexer_flags.looking_for_object_index = true; | 983 curr_lexer->looking_for_object_index = true; |
984 lexer_flags.at_beginning_of_statement = false; | 984 curr_lexer->at_beginning_of_statement = false; |
985 | 985 |
986 lexer_flags.nesting_level.remove (); | 986 curr_lexer->nesting_level.remove (); |
987 | 987 |
988 TOK_RETURN ('}'); | 988 TOK_RETURN ('}'); |
989 } | 989 } |
990 | 990 |
991 %{ | 991 %{ |
999 | 999 |
1000 int c = text_yyinput (); | 1000 int c = text_yyinput (); |
1001 | 1001 |
1002 if (c != EOF) | 1002 if (c != EOF) |
1003 { | 1003 { |
1004 lexer_flags.current_input_column++; | 1004 curr_lexer->current_input_column++; |
1005 | 1005 |
1006 error ("invalid character '%s' (ASCII %d) near line %d, column %d", | 1006 error ("invalid character '%s' (ASCII %d) near line %d, column %d", |
1007 undo_string_escape (static_cast<char> (c)), c, | 1007 undo_string_escape (static_cast<char> (c)), c, |
1008 lexer_flags.input_line_number, lexer_flags.current_input_column); | 1008 curr_lexer->input_line_number, curr_lexer->current_input_column); |
1009 | 1009 |
1010 return LEXICAL_ERROR; | 1010 return LEXICAL_ERROR; |
1011 } | 1011 } |
1012 else | 1012 else |
1013 TOK_RETURN (END_OF_INPUT); | 1013 TOK_RETURN (END_OF_INPUT); |
1030 xunput (c, yytext); | 1030 xunput (c, yytext); |
1031 | 1031 |
1032 if (spc_gobbled) | 1032 if (spc_gobbled) |
1033 xunput (' ', yytext); | 1033 xunput (' ', yytext); |
1034 | 1034 |
1035 lexer_flags.do_comma_insert = (! lexer_flags.looking_at_object_index.front () | 1035 curr_lexer->do_comma_insert = (! curr_lexer->looking_at_object_index.front () |
1036 && lexer_flags.bracketflag && c == '['); | 1036 && curr_lexer->bracketflag && c == '['); |
1037 } | 1037 } |
1038 | 1038 |
1039 // Fix things up for errors or interrupts. The parser is never called | 1039 // Fix things up for errors or interrupts. The parser is never called |
1040 // recursively, so it is always safe to reinitialize its state before | 1040 // recursively, so it is always safe to reinitialize its state before |
1041 // doing any parsing. | 1041 // doing any parsing. |
1072 yyrestart (stdin); | 1072 yyrestart (stdin); |
1073 | 1073 |
1074 // Clear the buffer for help text. | 1074 // Clear the buffer for help text. |
1075 while (! help_buf.empty ()) | 1075 while (! help_buf.empty ()) |
1076 help_buf.pop (); | 1076 help_buf.pop (); |
1077 | |
1078 // Reset other flags. | |
1079 lexer_flags = lexical_feedback (); | |
1080 } | 1077 } |
1081 | 1078 |
1082 static void | 1079 static void |
1083 display_character (char c) | 1080 display_character (char c) |
1084 { | 1081 { |
1256 c = '\n'; | 1253 c = '\n'; |
1257 } | 1254 } |
1258 } | 1255 } |
1259 | 1256 |
1260 if (c == '\n') | 1257 if (c == '\n') |
1261 lexer_flags.input_line_number++; | 1258 curr_lexer->input_line_number++; |
1262 | 1259 |
1263 return c; | 1260 return c; |
1264 } | 1261 } |
1265 | 1262 |
1266 static void | 1263 static void |
1272 display_character (c); | 1269 display_character (c); |
1273 std::cerr << std::endl; | 1270 std::cerr << std::endl; |
1274 } | 1271 } |
1275 | 1272 |
1276 if (c == '\n') | 1273 if (c == '\n') |
1277 lexer_flags.input_line_number--; | 1274 curr_lexer->input_line_number--; |
1278 | 1275 |
1279 yyunput (c, buf); | 1276 yyunput (c, buf); |
1280 } | 1277 } |
1281 | 1278 |
1282 // If we read some newlines, we need figure out what column we're | 1279 // If we read some newlines, we need figure out what column we're |
1288 char c; | 1285 char c; |
1289 while ((c = *s++) != '\0') | 1286 while ((c = *s++) != '\0') |
1290 { | 1287 { |
1291 if (c == '\n') | 1288 if (c == '\n') |
1292 { | 1289 { |
1293 lexer_flags.input_line_number++; | 1290 curr_lexer->input_line_number++; |
1294 lexer_flags.current_input_column = 1; | 1291 curr_lexer->current_input_column = 1; |
1295 } | 1292 } |
1296 else | 1293 else |
1297 lexer_flags.current_input_column++; | 1294 curr_lexer->current_input_column++; |
1298 } | 1295 } |
1299 } | 1296 } |
1300 | 1297 |
1301 // Include these so that we don't have to link to libfl.a. | 1298 // Include these so that we don't have to link to libfl.a. |
1302 | 1299 |
1377 static bool | 1374 static bool |
1378 inside_any_object_index (void) | 1375 inside_any_object_index (void) |
1379 { | 1376 { |
1380 bool retval = false; | 1377 bool retval = false; |
1381 | 1378 |
1382 for (std::list<bool>::const_iterator i = lexer_flags.looking_at_object_index.begin (); | 1379 for (std::list<bool>::const_iterator i = curr_lexer->looking_at_object_index.begin (); |
1383 i != lexer_flags.looking_at_object_index.end (); i++) | 1380 i != curr_lexer->looking_at_object_index.end (); i++) |
1384 { | 1381 { |
1385 if (*i) | 1382 if (*i) |
1386 { | 1383 { |
1387 retval = true; | 1384 retval = true; |
1388 break; | 1385 break; |
1395 // Handle keywords. Return -1 if the keyword should be ignored. | 1392 // Handle keywords. Return -1 if the keyword should be ignored. |
1396 | 1393 |
1397 static int | 1394 static int |
1398 is_keyword_token (const std::string& s) | 1395 is_keyword_token (const std::string& s) |
1399 { | 1396 { |
1400 int l = lexer_flags.input_line_number; | 1397 int l = curr_lexer->input_line_number; |
1401 int c = lexer_flags.current_input_column; | 1398 int c = curr_lexer->current_input_column; |
1402 | 1399 |
1403 int len = s.length (); | 1400 int len = s.length (); |
1404 | 1401 |
1405 const octave_kw *kw = octave_kw_hash::in_word_set (s.c_str (), len); | 1402 const octave_kw *kw = octave_kw_hash::in_word_set (s.c_str (), len); |
1406 | 1403 |
1415 case continue_kw: | 1412 case continue_kw: |
1416 case else_kw: | 1413 case else_kw: |
1417 case otherwise_kw: | 1414 case otherwise_kw: |
1418 case return_kw: | 1415 case return_kw: |
1419 case unwind_protect_cleanup_kw: | 1416 case unwind_protect_cleanup_kw: |
1420 lexer_flags.at_beginning_of_statement = true; | 1417 curr_lexer->at_beginning_of_statement = true; |
1421 break; | 1418 break; |
1422 | 1419 |
1423 case static_kw: | 1420 case static_kw: |
1424 if ((reading_fcn_file || reading_script_file | 1421 if ((reading_fcn_file || reading_script_file |
1425 || reading_classdef_file) | 1422 || reading_classdef_file) |
1426 && ! curr_fcn_file_full_name.empty ()) | 1423 && ! curr_fcn_file_full_name.empty ()) |
1427 warning_with_id ("Octave:deprecated-keyword", | 1424 warning_with_id ("Octave:deprecated-keyword", |
1428 "the 'static' keyword is obsolete and will be removed from a future version of Octave; please use 'persistent' instead; near line %d of file '%s'", | 1425 "the 'static' keyword is obsolete and will be removed from a future version of Octave; please use 'persistent' instead; near line %d of file '%s'", |
1429 lexer_flags.input_line_number, | 1426 curr_lexer->input_line_number, |
1430 curr_fcn_file_full_name.c_str ()); | 1427 curr_fcn_file_full_name.c_str ()); |
1431 else | 1428 else |
1432 warning_with_id ("Octave:deprecated-keyword", | 1429 warning_with_id ("Octave:deprecated-keyword", |
1433 "the 'static' keyword is obsolete and will be removed from a future version of Octave; please use 'persistent' instead; near line %d", | 1430 "the 'static' keyword is obsolete and will be removed from a future version of Octave; please use 'persistent' instead; near line %d", |
1434 lexer_flags.input_line_number); | 1431 curr_lexer->input_line_number); |
1435 // fall through ... | 1432 // fall through ... |
1436 | 1433 |
1437 case persistent_kw: | 1434 case persistent_kw: |
1438 break; | 1435 break; |
1439 | 1436 |
1444 break; | 1441 break; |
1445 | 1442 |
1446 case end_kw: | 1443 case end_kw: |
1447 if (inside_any_object_index () | 1444 if (inside_any_object_index () |
1448 || (! reading_classdef_file | 1445 || (! reading_classdef_file |
1449 && (lexer_flags.defining_func | 1446 && (curr_lexer->defining_func |
1450 && ! (lexer_flags.looking_at_return_list | 1447 && ! (curr_lexer->looking_at_return_list |
1451 || lexer_flags.parsed_function_name.top ())))) | 1448 || curr_lexer->parsed_function_name.top ())))) |
1452 return 0; | 1449 return 0; |
1453 | 1450 |
1454 yylval.tok_val = new token (token::simple_end, l, c); | 1451 yylval.tok_val = new token (token::simple_end, l, c); |
1455 lexer_flags.at_beginning_of_statement = true; | 1452 curr_lexer->at_beginning_of_statement = true; |
1456 break; | 1453 break; |
1457 | 1454 |
1458 case end_try_catch_kw: | 1455 case end_try_catch_kw: |
1459 yylval.tok_val = new token (token::try_catch_end, l, c); | 1456 yylval.tok_val = new token (token::try_catch_end, l, c); |
1460 lexer_flags.at_beginning_of_statement = true; | 1457 curr_lexer->at_beginning_of_statement = true; |
1461 break; | 1458 break; |
1462 | 1459 |
1463 case end_unwind_protect_kw: | 1460 case end_unwind_protect_kw: |
1464 yylval.tok_val = new token (token::unwind_protect_end, l, c); | 1461 yylval.tok_val = new token (token::unwind_protect_end, l, c); |
1465 lexer_flags.at_beginning_of_statement = true; | 1462 curr_lexer->at_beginning_of_statement = true; |
1466 break; | 1463 break; |
1467 | 1464 |
1468 case endfor_kw: | 1465 case endfor_kw: |
1469 yylval.tok_val = new token (token::for_end, l, c); | 1466 yylval.tok_val = new token (token::for_end, l, c); |
1470 lexer_flags.at_beginning_of_statement = true; | 1467 curr_lexer->at_beginning_of_statement = true; |
1471 break; | 1468 break; |
1472 | 1469 |
1473 case endfunction_kw: | 1470 case endfunction_kw: |
1474 yylval.tok_val = new token (token::function_end, l, c); | 1471 yylval.tok_val = new token (token::function_end, l, c); |
1475 lexer_flags.at_beginning_of_statement = true; | 1472 curr_lexer->at_beginning_of_statement = true; |
1476 break; | 1473 break; |
1477 | 1474 |
1478 case endif_kw: | 1475 case endif_kw: |
1479 yylval.tok_val = new token (token::if_end, l, c); | 1476 yylval.tok_val = new token (token::if_end, l, c); |
1480 lexer_flags.at_beginning_of_statement = true; | 1477 curr_lexer->at_beginning_of_statement = true; |
1481 break; | 1478 break; |
1482 | 1479 |
1483 case endparfor_kw: | 1480 case endparfor_kw: |
1484 yylval.tok_val = new token (token::parfor_end, l, c); | 1481 yylval.tok_val = new token (token::parfor_end, l, c); |
1485 lexer_flags.at_beginning_of_statement = true; | 1482 curr_lexer->at_beginning_of_statement = true; |
1486 break; | 1483 break; |
1487 | 1484 |
1488 case endswitch_kw: | 1485 case endswitch_kw: |
1489 yylval.tok_val = new token (token::switch_end, l, c); | 1486 yylval.tok_val = new token (token::switch_end, l, c); |
1490 lexer_flags.at_beginning_of_statement = true; | 1487 curr_lexer->at_beginning_of_statement = true; |
1491 break; | 1488 break; |
1492 | 1489 |
1493 case endwhile_kw: | 1490 case endwhile_kw: |
1494 yylval.tok_val = new token (token::while_end, l, c); | 1491 yylval.tok_val = new token (token::while_end, l, c); |
1495 lexer_flags.at_beginning_of_statement = true; | 1492 curr_lexer->at_beginning_of_statement = true; |
1496 break; | 1493 break; |
1497 | 1494 |
1498 case endclassdef_kw: | 1495 case endclassdef_kw: |
1499 yylval.tok_val = new token (token::classdef_end, l, c); | 1496 yylval.tok_val = new token (token::classdef_end, l, c); |
1500 lexer_flags.at_beginning_of_statement = true; | 1497 curr_lexer->at_beginning_of_statement = true; |
1501 break; | 1498 break; |
1502 | 1499 |
1503 case endenumeration_kw: | 1500 case endenumeration_kw: |
1504 yylval.tok_val = new token (token::enumeration_end, l, c); | 1501 yylval.tok_val = new token (token::enumeration_end, l, c); |
1505 lexer_flags.at_beginning_of_statement = true; | 1502 curr_lexer->at_beginning_of_statement = true; |
1506 break; | 1503 break; |
1507 | 1504 |
1508 case endevents_kw: | 1505 case endevents_kw: |
1509 yylval.tok_val = new token (token::events_end, l, c); | 1506 yylval.tok_val = new token (token::events_end, l, c); |
1510 lexer_flags.at_beginning_of_statement = true; | 1507 curr_lexer->at_beginning_of_statement = true; |
1511 break; | 1508 break; |
1512 | 1509 |
1513 case endmethods_kw: | 1510 case endmethods_kw: |
1514 yylval.tok_val = new token (token::methods_end, l, c); | 1511 yylval.tok_val = new token (token::methods_end, l, c); |
1515 lexer_flags.at_beginning_of_statement = true; | 1512 curr_lexer->at_beginning_of_statement = true; |
1516 break; | 1513 break; |
1517 | 1514 |
1518 case endproperties_kw: | 1515 case endproperties_kw: |
1519 yylval.tok_val = new token (token::properties_end, l, c); | 1516 yylval.tok_val = new token (token::properties_end, l, c); |
1520 lexer_flags.at_beginning_of_statement = true; | 1517 curr_lexer->at_beginning_of_statement = true; |
1521 break; | 1518 break; |
1522 | 1519 |
1523 | 1520 |
1524 case for_kw: | 1521 case for_kw: |
1525 case parfor_kw: | 1522 case parfor_kw: |
1526 case while_kw: | 1523 case while_kw: |
1527 promptflag--; | 1524 promptflag--; |
1528 lexer_flags.looping++; | 1525 curr_lexer->looping++; |
1529 break; | 1526 break; |
1530 | 1527 |
1531 case do_kw: | 1528 case do_kw: |
1532 lexer_flags.at_beginning_of_statement = true; | 1529 curr_lexer->at_beginning_of_statement = true; |
1533 promptflag--; | 1530 promptflag--; |
1534 lexer_flags.looping++; | 1531 curr_lexer->looping++; |
1535 break; | 1532 break; |
1536 | 1533 |
1537 case try_kw: | 1534 case try_kw: |
1538 case unwind_protect_kw: | 1535 case unwind_protect_kw: |
1539 lexer_flags.at_beginning_of_statement = true; | 1536 curr_lexer->at_beginning_of_statement = true; |
1540 promptflag--; | 1537 promptflag--; |
1541 break; | 1538 break; |
1542 | 1539 |
1543 case if_kw: | 1540 case if_kw: |
1544 case switch_kw: | 1541 case switch_kw: |
1547 | 1544 |
1548 case get_kw: | 1545 case get_kw: |
1549 case set_kw: | 1546 case set_kw: |
1550 // 'get' and 'set' are keywords in classdef method | 1547 // 'get' and 'set' are keywords in classdef method |
1551 // declarations. | 1548 // declarations. |
1552 if (! lexer_flags.maybe_classdef_get_set_method) | 1549 if (! curr_lexer->maybe_classdef_get_set_method) |
1553 return 0; | 1550 return 0; |
1554 break; | 1551 break; |
1555 | 1552 |
1556 case enumeration_kw: | 1553 case enumeration_kw: |
1557 case events_kw: | 1554 case events_kw: |
1558 case methods_kw: | 1555 case methods_kw: |
1559 case properties_kw: | 1556 case properties_kw: |
1560 // 'properties', 'methods' and 'events' are keywords for | 1557 // 'properties', 'methods' and 'events' are keywords for |
1561 // classdef blocks. | 1558 // classdef blocks. |
1562 if (! lexer_flags.parsing_classdef) | 1559 if (! curr_lexer->parsing_classdef) |
1563 return 0; | 1560 return 0; |
1564 // fall through ... | 1561 // fall through ... |
1565 | 1562 |
1566 case classdef_kw: | 1563 case classdef_kw: |
1567 // 'classdef' is always a keyword. | 1564 // 'classdef' is always a keyword. |
1569 break; | 1566 break; |
1570 | 1567 |
1571 case function_kw: | 1568 case function_kw: |
1572 promptflag--; | 1569 promptflag--; |
1573 | 1570 |
1574 lexer_flags.defining_func++; | 1571 curr_lexer->defining_func++; |
1575 lexer_flags.parsed_function_name.push (false); | 1572 curr_lexer->parsed_function_name.push (false); |
1576 | 1573 |
1577 if (! (reading_fcn_file || reading_script_file | 1574 if (! (reading_fcn_file || reading_script_file |
1578 || reading_classdef_file)) | 1575 || reading_classdef_file)) |
1579 lexer_flags.input_line_number = 1; | 1576 curr_lexer->input_line_number = 1; |
1580 break; | 1577 break; |
1581 | 1578 |
1582 case magic_file_kw: | 1579 case magic_file_kw: |
1583 { | 1580 { |
1584 if ((reading_fcn_file || reading_script_file | 1581 if ((reading_fcn_file || reading_script_file |
1611 | 1608 |
1612 static bool | 1609 static bool |
1613 is_variable (const std::string& name) | 1610 is_variable (const std::string& name) |
1614 { | 1611 { |
1615 return (symbol_table::is_variable (name) | 1612 return (symbol_table::is_variable (name) |
1616 || (lexer_flags.pending_local_variables.find (name) | 1613 || (curr_lexer->pending_local_variables.find (name) |
1617 != lexer_flags.pending_local_variables.end ())); | 1614 != curr_lexer->pending_local_variables.end ())); |
1618 } | 1615 } |
1619 | 1616 |
1620 static std::string | 1617 static std::string |
1621 grab_block_comment (stream_reader& reader, bool& eof) | 1618 grab_block_comment (stream_reader& reader, bool& eof) |
1622 { | 1619 { |
1629 | 1626 |
1630 int c = 0; | 1627 int c = 0; |
1631 | 1628 |
1632 while ((c = reader.getc ()) != EOF) | 1629 while ((c = reader.getc ()) != EOF) |
1633 { | 1630 { |
1634 lexer_flags.current_input_column++; | 1631 curr_lexer->current_input_column++; |
1635 | 1632 |
1636 if (look_for_marker) | 1633 if (look_for_marker) |
1637 { | 1634 { |
1638 at_bol = false; | 1635 at_bol = false; |
1639 look_for_marker = false; | 1636 look_for_marker = false; |
1646 | 1643 |
1647 bool done = false; | 1644 bool done = false; |
1648 | 1645 |
1649 while ((c = reader.getc ()) != EOF && ! done) | 1646 while ((c = reader.getc ()) != EOF && ! done) |
1650 { | 1647 { |
1651 lexer_flags.current_input_column++; | 1648 curr_lexer->current_input_column++; |
1652 | 1649 |
1653 switch (c) | 1650 switch (c) |
1654 { | 1651 { |
1655 case ' ': | 1652 case ' ': |
1656 case '\t': | 1653 case '\t': |
1657 tmp_buf += static_cast<char> (c); | 1654 tmp_buf += static_cast<char> (c); |
1658 break; | 1655 break; |
1659 | 1656 |
1660 case '\n': | 1657 case '\n': |
1661 { | 1658 { |
1662 lexer_flags.current_input_column = 0; | 1659 curr_lexer->current_input_column = 0; |
1663 at_bol = true; | 1660 at_bol = true; |
1664 done = true; | 1661 done = true; |
1665 | 1662 |
1666 if (type == '{') | 1663 if (type == '{') |
1667 { | 1664 { |
1668 lexer_flags.block_comment_nesting_level++; | 1665 curr_lexer->block_comment_nesting_level++; |
1669 promptflag--; | 1666 promptflag--; |
1670 } | 1667 } |
1671 else | 1668 else |
1672 { | 1669 { |
1673 lexer_flags.block_comment_nesting_level--; | 1670 curr_lexer->block_comment_nesting_level--; |
1674 promptflag++; | 1671 promptflag++; |
1675 | 1672 |
1676 if (lexer_flags.block_comment_nesting_level == 0) | 1673 if (curr_lexer->block_comment_nesting_level == 0) |
1677 { | 1674 { |
1678 buf += grab_comment_block (reader, true, eof); | 1675 buf += grab_comment_block (reader, true, eof); |
1679 | 1676 |
1680 return buf; | 1677 return buf; |
1681 } | 1678 } |
1709 { | 1706 { |
1710 buf += static_cast<char> (c); | 1707 buf += static_cast<char> (c); |
1711 | 1708 |
1712 if (c == '\n') | 1709 if (c == '\n') |
1713 { | 1710 { |
1714 lexer_flags.current_input_column = 0; | 1711 curr_lexer->current_input_column = 0; |
1715 at_bol = true; | 1712 at_bol = true; |
1716 } | 1713 } |
1717 } | 1714 } |
1718 } | 1715 } |
1719 | 1716 |
1739 | 1736 |
1740 int c = 0; | 1737 int c = 0; |
1741 | 1738 |
1742 while ((c = reader.getc ()) != EOF) | 1739 while ((c = reader.getc ()) != EOF) |
1743 { | 1740 { |
1744 lexer_flags.current_input_column++; | 1741 curr_lexer->current_input_column++; |
1745 | 1742 |
1746 if (begin_comment) | 1743 if (begin_comment) |
1747 { | 1744 { |
1748 if (c == '%' || c == '#') | 1745 if (c == '%' || c == '#') |
1749 { | 1746 { |
1756 | 1753 |
1757 bool done = false; | 1754 bool done = false; |
1758 | 1755 |
1759 while ((c = reader.getc ()) != EOF && ! done) | 1756 while ((c = reader.getc ()) != EOF && ! done) |
1760 { | 1757 { |
1761 lexer_flags.current_input_column++; | 1758 curr_lexer->current_input_column++; |
1762 | 1759 |
1763 switch (c) | 1760 switch (c) |
1764 { | 1761 { |
1765 case ' ': | 1762 case ' ': |
1766 case '\t': | 1763 case '\t': |
1767 tmp_buf += static_cast<char> (c); | 1764 tmp_buf += static_cast<char> (c); |
1768 break; | 1765 break; |
1769 | 1766 |
1770 case '\n': | 1767 case '\n': |
1771 { | 1768 { |
1772 lexer_flags.current_input_column = 0; | 1769 curr_lexer->current_input_column = 0; |
1773 at_bol = true; | 1770 at_bol = true; |
1774 done = true; | 1771 done = true; |
1775 | 1772 |
1776 lexer_flags.block_comment_nesting_level++; | 1773 curr_lexer->block_comment_nesting_level++; |
1777 promptflag--; | 1774 promptflag--; |
1778 | 1775 |
1779 buf += grab_block_comment (reader, eof); | 1776 buf += grab_block_comment (reader, eof); |
1780 | 1777 |
1781 in_comment = false; | 1778 in_comment = false; |
1806 buf += static_cast<char> (c); | 1803 buf += static_cast<char> (c); |
1807 | 1804 |
1808 if (c == '\n') | 1805 if (c == '\n') |
1809 { | 1806 { |
1810 at_bol = true; | 1807 at_bol = true; |
1811 lexer_flags.current_input_column = 0; | 1808 curr_lexer->current_input_column = 0; |
1812 in_comment = false; | 1809 in_comment = false; |
1813 | 1810 |
1814 // FIXME -- bailing out here prevents things like | 1811 // FIXME -- bailing out here prevents things like |
1815 // | 1812 // |
1816 // octave> # comment | 1813 // octave> # comment |
1846 in_comment = true; | 1843 in_comment = true; |
1847 begin_comment = true; | 1844 begin_comment = true; |
1848 break; | 1845 break; |
1849 | 1846 |
1850 default: | 1847 default: |
1851 lexer_flags.current_input_column--; | 1848 curr_lexer->current_input_column--; |
1852 reader.ungetc (c); | 1849 reader.ungetc (c); |
1853 goto done; | 1850 goto done; |
1854 } | 1851 } |
1855 } | 1852 } |
1856 } | 1853 } |
1903 : grab_comment_block (flex_reader, false, eof); | 1900 : grab_comment_block (flex_reader, false, eof); |
1904 | 1901 |
1905 if (lexer_debug_flag) | 1902 if (lexer_debug_flag) |
1906 std::cerr << "C: " << txt << std::endl; | 1903 std::cerr << "C: " << txt << std::endl; |
1907 | 1904 |
1908 if (help_txt.empty () && lexer_flags.nesting_level.none ()) | 1905 if (help_txt.empty () && curr_lexer->nesting_level.none ()) |
1909 { | 1906 { |
1910 if (! help_buf.empty ()) | 1907 if (! help_buf.empty ()) |
1911 help_buf.pop (); | 1908 help_buf.pop (); |
1912 | 1909 |
1913 help_buf.push (txt); | 1910 help_buf.push (txt); |
1914 } | 1911 } |
1915 | 1912 |
1916 octave_comment_buffer::append (txt); | 1913 octave_comment_buffer::append (txt); |
1917 | 1914 |
1918 lexer_flags.current_input_column = 1; | 1915 curr_lexer->current_input_column = 1; |
1919 lexer_flags.quote_is_transpose = false; | 1916 curr_lexer->quote_is_transpose = false; |
1920 lexer_flags.convert_spaces_to_comma = true; | 1917 curr_lexer->convert_spaces_to_comma = true; |
1921 lexer_flags.at_beginning_of_statement = true; | 1918 curr_lexer->at_beginning_of_statement = true; |
1922 | 1919 |
1923 if (YY_START == COMMAND_START) | 1920 if (YY_START == COMMAND_START) |
1924 BEGIN (INITIAL); | 1921 BEGIN (INITIAL); |
1925 | 1922 |
1926 if (lexer_flags.nesting_level.none ()) | 1923 if (curr_lexer->nesting_level.none ()) |
1927 return '\n'; | 1924 return '\n'; |
1928 else if (lexer_flags.nesting_level.is_bracket_or_brace ()) | 1925 else if (curr_lexer->nesting_level.is_bracket_or_brace ()) |
1929 return ';'; | 1926 return ';'; |
1930 else | 1927 else |
1931 return 0; | 1928 return 0; |
1932 } | 1929 } |
1933 | 1930 |
2218 | 2215 |
2219 int c = 0; | 2216 int c = 0; |
2220 | 2217 |
2221 while ((c = text_yyinput ()) != EOF) | 2218 while ((c = text_yyinput ()) != EOF) |
2222 { | 2219 { |
2223 lexer_flags.current_input_column++; | 2220 curr_lexer->current_input_column++; |
2224 | 2221 |
2225 switch (c) | 2222 switch (c) |
2226 { | 2223 { |
2227 case ' ': | 2224 case ' ': |
2228 case '\t': | 2225 case '\t': |
2242 octave_comment_buffer::append (comment_buf); | 2239 octave_comment_buffer::append (comment_buf); |
2243 comment_buf.resize (0); | 2240 comment_buf.resize (0); |
2244 in_comment = false; | 2241 in_comment = false; |
2245 beginning_of_comment = false; | 2242 beginning_of_comment = false; |
2246 } | 2243 } |
2247 lexer_flags.current_input_column = 0; | 2244 curr_lexer->current_input_column = 0; |
2248 break; | 2245 break; |
2249 | 2246 |
2250 case '#': | 2247 case '#': |
2251 case '%': | 2248 case '%': |
2252 if (in_comment) | 2249 if (in_comment) |
2307 if (! comment_buf.empty ()) | 2304 if (! comment_buf.empty ()) |
2308 octave_comment_buffer::append (comment_buf); | 2305 octave_comment_buffer::append (comment_buf); |
2309 | 2306 |
2310 done: | 2307 done: |
2311 xunput (c, yytext); | 2308 xunput (c, yytext); |
2312 lexer_flags.current_input_column--; | 2309 curr_lexer->current_input_column--; |
2313 return retval; | 2310 return retval; |
2314 } | 2311 } |
2315 | 2312 |
2316 static inline bool | 2313 static inline bool |
2317 looks_like_hex (const char *s, int len) | 2314 looks_like_hex (const char *s, int len) |
2349 | 2346 |
2350 // If yytext doesn't contain a valid number, we are in deep doo doo. | 2347 // If yytext doesn't contain a valid number, we are in deep doo doo. |
2351 | 2348 |
2352 assert (nread == 1); | 2349 assert (nread == 1); |
2353 | 2350 |
2354 lexer_flags.quote_is_transpose = true; | 2351 curr_lexer->quote_is_transpose = true; |
2355 lexer_flags.convert_spaces_to_comma = true; | 2352 curr_lexer->convert_spaces_to_comma = true; |
2356 lexer_flags.looking_for_object_index = false; | 2353 curr_lexer->looking_for_object_index = false; |
2357 lexer_flags.at_beginning_of_statement = false; | 2354 curr_lexer->at_beginning_of_statement = false; |
2358 | 2355 |
2359 yylval.tok_val = new token (value, yytext, lexer_flags.input_line_number, | 2356 yylval.tok_val = new token (value, yytext, curr_lexer->input_line_number, |
2360 lexer_flags.current_input_column); | 2357 curr_lexer->current_input_column); |
2361 | 2358 |
2362 token_stack.push (yylval.tok_val); | 2359 token_stack.push (yylval.tok_val); |
2363 | 2360 |
2364 lexer_flags.current_input_column += yyleng; | 2361 curr_lexer->current_input_column += yyleng; |
2365 | 2362 |
2366 do_comma_insert_check (); | 2363 do_comma_insert_check (); |
2367 } | 2364 } |
2368 | 2365 |
2369 // We have seen a backslash and need to find out if it should be | 2366 // We have seen a backslash and need to find out if it should be |
2428 if (in_comment) | 2425 if (in_comment) |
2429 { | 2426 { |
2430 comment_buf += static_cast<char> (c); | 2427 comment_buf += static_cast<char> (c); |
2431 octave_comment_buffer::append (comment_buf); | 2428 octave_comment_buffer::append (comment_buf); |
2432 } | 2429 } |
2433 lexer_flags.current_input_column = 0; | 2430 curr_lexer->current_input_column = 0; |
2434 promptflag--; | 2431 promptflag--; |
2435 gripe_matlab_incompatible_continuation (); | 2432 gripe_matlab_incompatible_continuation (); |
2436 return true; | 2433 return true; |
2437 | 2434 |
2438 default: | 2435 default: |
2508 static int | 2505 static int |
2509 handle_string (char delim) | 2506 handle_string (char delim) |
2510 { | 2507 { |
2511 std::ostringstream buf; | 2508 std::ostringstream buf; |
2512 | 2509 |
2513 int bos_line = lexer_flags.input_line_number; | 2510 int bos_line = curr_lexer->input_line_number; |
2514 int bos_col = lexer_flags.current_input_column; | 2511 int bos_col = curr_lexer->current_input_column; |
2515 | 2512 |
2516 int c; | 2513 int c; |
2517 int escape_pending = 0; | 2514 int escape_pending = 0; |
2518 | 2515 |
2519 while ((c = text_yyinput ()) != EOF) | 2516 while ((c = text_yyinput ()) != EOF) |
2520 { | 2517 { |
2521 lexer_flags.current_input_column++; | 2518 curr_lexer->current_input_column++; |
2522 | 2519 |
2523 if (c == '\\') | 2520 if (c == '\\') |
2524 { | 2521 { |
2525 if (delim == '\'' || escape_pending) | 2522 if (delim == '\'' || escape_pending) |
2526 { | 2523 { |
2568 if (delim == '\'') | 2565 if (delim == '\'') |
2569 s = buf.str (); | 2566 s = buf.str (); |
2570 else | 2567 else |
2571 s = do_string_escapes (buf.str ()); | 2568 s = do_string_escapes (buf.str ()); |
2572 | 2569 |
2573 lexer_flags.quote_is_transpose = true; | 2570 curr_lexer->quote_is_transpose = true; |
2574 lexer_flags.convert_spaces_to_comma = true; | 2571 curr_lexer->convert_spaces_to_comma = true; |
2575 | 2572 |
2576 yylval.tok_val = new token (s, bos_line, bos_col); | 2573 yylval.tok_val = new token (s, bos_line, bos_col); |
2577 token_stack.push (yylval.tok_val); | 2574 token_stack.push (yylval.tok_val); |
2578 | 2575 |
2579 if (delim == '"') | 2576 if (delim == '"') |
2580 gripe_matlab_incompatible ("\" used as string delimiter"); | 2577 gripe_matlab_incompatible ("\" used as string delimiter"); |
2581 else if (delim == '\'') | 2578 else if (delim == '\'') |
2582 gripe_single_quote_string (); | 2579 gripe_single_quote_string (); |
2583 | 2580 |
2584 lexer_flags.looking_for_object_index = true; | 2581 curr_lexer->looking_for_object_index = true; |
2585 lexer_flags.at_beginning_of_statement = false; | 2582 curr_lexer->at_beginning_of_statement = false; |
2586 | 2583 |
2587 return delim == '"' ? DQ_STRING : SQ_STRING; | 2584 return delim == '"' ? DQ_STRING : SQ_STRING; |
2588 } | 2585 } |
2589 } | 2586 } |
2590 } | 2587 } |
2694 static int | 2691 static int |
2695 handle_close_bracket (bool spc_gobbled, int bracket_type) | 2692 handle_close_bracket (bool spc_gobbled, int bracket_type) |
2696 { | 2693 { |
2697 int retval = bracket_type; | 2694 int retval = bracket_type; |
2698 | 2695 |
2699 if (! lexer_flags.nesting_level.none ()) | 2696 if (! curr_lexer->nesting_level.none ()) |
2700 { | 2697 { |
2701 lexer_flags.nesting_level.remove (); | 2698 curr_lexer->nesting_level.remove (); |
2702 | 2699 |
2703 if (bracket_type == ']') | 2700 if (bracket_type == ']') |
2704 lexer_flags.bracketflag--; | 2701 curr_lexer->bracketflag--; |
2705 else if (bracket_type == '}') | 2702 else if (bracket_type == '}') |
2706 lexer_flags.braceflag--; | 2703 curr_lexer->braceflag--; |
2707 else | 2704 else |
2708 panic_impossible (); | 2705 panic_impossible (); |
2709 } | 2706 } |
2710 | 2707 |
2711 if (lexer_flags.bracketflag == 0 && lexer_flags.braceflag == 0) | 2708 if (curr_lexer->bracketflag == 0 && curr_lexer->braceflag == 0) |
2712 BEGIN (INITIAL); | 2709 BEGIN (INITIAL); |
2713 | 2710 |
2714 if (bracket_type == ']' | 2711 if (bracket_type == ']' |
2715 && next_token_is_assign_op () | 2712 && next_token_is_assign_op () |
2716 && ! lexer_flags.looking_at_return_list) | 2713 && ! curr_lexer->looking_at_return_list) |
2717 { | 2714 { |
2718 retval = CLOSE_BRACE; | 2715 retval = CLOSE_BRACE; |
2719 } | 2716 } |
2720 else if ((lexer_flags.bracketflag || lexer_flags.braceflag) | 2717 else if ((curr_lexer->bracketflag || curr_lexer->braceflag) |
2721 && lexer_flags.convert_spaces_to_comma | 2718 && curr_lexer->convert_spaces_to_comma |
2722 && (lexer_flags.nesting_level.is_bracket () | 2719 && (curr_lexer->nesting_level.is_bracket () |
2723 || (lexer_flags.nesting_level.is_brace () | 2720 || (curr_lexer->nesting_level.is_brace () |
2724 && ! lexer_flags.looking_at_object_index.front ()))) | 2721 && ! curr_lexer->looking_at_object_index.front ()))) |
2725 { | 2722 { |
2726 bool index_op = next_token_is_index_op (); | 2723 bool index_op = next_token_is_index_op (); |
2727 | 2724 |
2728 // Don't insert comma if we are looking at something like | 2725 // Don't insert comma if we are looking at something like |
2729 // | 2726 // |
2749 return retval; | 2746 return retval; |
2750 } | 2747 } |
2751 } | 2748 } |
2752 } | 2749 } |
2753 | 2750 |
2754 lexer_flags.quote_is_transpose = true; | 2751 curr_lexer->quote_is_transpose = true; |
2755 lexer_flags.convert_spaces_to_comma = true; | 2752 curr_lexer->convert_spaces_to_comma = true; |
2756 | 2753 |
2757 return retval; | 2754 return retval; |
2758 } | 2755 } |
2759 | 2756 |
2760 static void | 2757 static void |
2761 maybe_unput_comma (int spc_gobbled) | 2758 maybe_unput_comma (int spc_gobbled) |
2762 { | 2759 { |
2763 if (lexer_flags.nesting_level.is_bracket () | 2760 if (curr_lexer->nesting_level.is_bracket () |
2764 || (lexer_flags.nesting_level.is_brace () | 2761 || (curr_lexer->nesting_level.is_brace () |
2765 && ! lexer_flags.looking_at_object_index.front ())) | 2762 && ! curr_lexer->looking_at_object_index.front ())) |
2766 { | 2763 { |
2767 int bin_op = next_token_is_bin_op (spc_gobbled); | 2764 int bin_op = next_token_is_bin_op (spc_gobbled); |
2768 | 2765 |
2769 int postfix_un_op = next_token_is_postfix_unary_op (spc_gobbled); | 2766 int postfix_un_op = next_token_is_postfix_unary_op (spc_gobbled); |
2770 | 2767 |
3088 | 3085 |
3089 yylval.tok_val | 3086 yylval.tok_val |
3090 = new token (meth.empty () ? 0 : &(symbol_table::insert (meth)), | 3087 = new token (meth.empty () ? 0 : &(symbol_table::insert (meth)), |
3091 cls.empty () ? 0 : &(symbol_table::insert (cls)), | 3088 cls.empty () ? 0 : &(symbol_table::insert (cls)), |
3092 pkg.empty () ? 0 : &(symbol_table::insert (pkg)), | 3089 pkg.empty () ? 0 : &(symbol_table::insert (pkg)), |
3093 lexer_flags.input_line_number, | 3090 curr_lexer->input_line_number, |
3094 lexer_flags.current_input_column); | 3091 curr_lexer->current_input_column); |
3095 token_stack.push (yylval.tok_val); | 3092 token_stack.push (yylval.tok_val); |
3096 | 3093 |
3097 lexer_flags.convert_spaces_to_comma = true; | 3094 curr_lexer->convert_spaces_to_comma = true; |
3098 lexer_flags.current_input_column += yyleng; | 3095 curr_lexer->current_input_column += yyleng; |
3099 | 3096 |
3100 return SUPERCLASSREF; | 3097 return SUPERCLASSREF; |
3101 } | 3098 } |
3102 | 3099 |
3103 static int | 3100 static int |
3123 } | 3120 } |
3124 | 3121 |
3125 yylval.tok_val | 3122 yylval.tok_val |
3126 = new token (cls.empty () ? 0 : &(symbol_table::insert (cls)), | 3123 = new token (cls.empty () ? 0 : &(symbol_table::insert (cls)), |
3127 pkg.empty () ? 0 : &(symbol_table::insert (pkg)), | 3124 pkg.empty () ? 0 : &(symbol_table::insert (pkg)), |
3128 lexer_flags.input_line_number, | 3125 curr_lexer->input_line_number, |
3129 lexer_flags.current_input_column); | 3126 curr_lexer->current_input_column); |
3130 | 3127 |
3131 token_stack.push (yylval.tok_val); | 3128 token_stack.push (yylval.tok_val); |
3132 | 3129 |
3133 lexer_flags.convert_spaces_to_comma = true; | 3130 curr_lexer->convert_spaces_to_comma = true; |
3134 lexer_flags.current_input_column += yyleng; | 3131 curr_lexer->current_input_column += yyleng; |
3135 | 3132 |
3136 return METAQUERY; | 3133 return METAQUERY; |
3137 } | 3134 } |
3138 | 3135 |
3139 // Figure out exactly what kind of token to return when we have seen | 3136 // Figure out exactly what kind of token to return when we have seen |
3141 // should be ignored. | 3138 // should be ignored. |
3142 | 3139 |
3143 static int | 3140 static int |
3144 handle_identifier (void) | 3141 handle_identifier (void) |
3145 { | 3142 { |
3146 bool at_bos = lexer_flags.at_beginning_of_statement; | 3143 bool at_bos = curr_lexer->at_beginning_of_statement; |
3147 | 3144 |
3148 std::string tok = strip_trailing_whitespace (yytext); | 3145 std::string tok = strip_trailing_whitespace (yytext); |
3149 | 3146 |
3150 int c = yytext[yyleng-1]; | 3147 int c = yytext[yyleng-1]; |
3151 | 3148 |
3156 // If we are expecting a structure element, avoid recognizing | 3153 // If we are expecting a structure element, avoid recognizing |
3157 // keywords and other special names and return STRUCT_ELT, which is | 3154 // keywords and other special names and return STRUCT_ELT, which is |
3158 // a string that is also a valid identifier. But first, we have to | 3155 // a string that is also a valid identifier. But first, we have to |
3159 // decide whether to insert a comma. | 3156 // decide whether to insert a comma. |
3160 | 3157 |
3161 if (lexer_flags.looking_at_indirect_ref) | 3158 if (curr_lexer->looking_at_indirect_ref) |
3162 { | 3159 { |
3163 do_comma_insert_check (); | 3160 do_comma_insert_check (); |
3164 | 3161 |
3165 maybe_unput_comma (spc_gobbled); | 3162 maybe_unput_comma (spc_gobbled); |
3166 | 3163 |
3167 yylval.tok_val = new token (tok, lexer_flags.input_line_number, | 3164 yylval.tok_val = new token (tok, curr_lexer->input_line_number, |
3168 lexer_flags.current_input_column); | 3165 curr_lexer->current_input_column); |
3169 | 3166 |
3170 token_stack.push (yylval.tok_val); | 3167 token_stack.push (yylval.tok_val); |
3171 | 3168 |
3172 lexer_flags.quote_is_transpose = true; | 3169 curr_lexer->quote_is_transpose = true; |
3173 lexer_flags.convert_spaces_to_comma = true; | 3170 curr_lexer->convert_spaces_to_comma = true; |
3174 lexer_flags.looking_for_object_index = true; | 3171 curr_lexer->looking_for_object_index = true; |
3175 | 3172 |
3176 lexer_flags.current_input_column += yyleng; | 3173 curr_lexer->current_input_column += yyleng; |
3177 | 3174 |
3178 return STRUCT_ELT; | 3175 return STRUCT_ELT; |
3179 } | 3176 } |
3180 | 3177 |
3181 lexer_flags.at_beginning_of_statement = false; | 3178 curr_lexer->at_beginning_of_statement = false; |
3182 | 3179 |
3183 // The is_keyword_token may reset | 3180 // The is_keyword_token may reset |
3184 // lexer_flags.at_beginning_of_statement. For example, if it sees | 3181 // curr_lexer->at_beginning_of_statement. For example, if it sees |
3185 // an else token, then the next token is at the beginning of a | 3182 // an else token, then the next token is at the beginning of a |
3186 // statement. | 3183 // statement. |
3187 | 3184 |
3188 int kw_token = is_keyword_token (tok); | 3185 int kw_token = is_keyword_token (tok); |
3189 | 3186 |
3190 // If we found a keyword token, then the beginning_of_statement flag | 3187 // If we found a keyword token, then the beginning_of_statement flag |
3191 // is already set. Otherwise, we won't be at the beginning of a | 3188 // is already set. Otherwise, we won't be at the beginning of a |
3192 // statement. | 3189 // statement. |
3193 | 3190 |
3194 if (lexer_flags.looking_at_function_handle) | 3191 if (curr_lexer->looking_at_function_handle) |
3195 { | 3192 { |
3196 if (kw_token) | 3193 if (kw_token) |
3197 { | 3194 { |
3198 error ("function handles may not refer to keywords"); | 3195 error ("function handles may not refer to keywords"); |
3199 | 3196 |
3200 return LEXICAL_ERROR; | 3197 return LEXICAL_ERROR; |
3201 } | 3198 } |
3202 else | 3199 else |
3203 { | 3200 { |
3204 yylval.tok_val = new token (tok, lexer_flags.input_line_number, | 3201 yylval.tok_val = new token (tok, curr_lexer->input_line_number, |
3205 lexer_flags.current_input_column); | 3202 curr_lexer->current_input_column); |
3206 | 3203 |
3207 token_stack.push (yylval.tok_val); | 3204 token_stack.push (yylval.tok_val); |
3208 | 3205 |
3209 lexer_flags.current_input_column += yyleng; | 3206 curr_lexer->current_input_column += yyleng; |
3210 lexer_flags.quote_is_transpose = false; | 3207 curr_lexer->quote_is_transpose = false; |
3211 lexer_flags.convert_spaces_to_comma = true; | 3208 curr_lexer->convert_spaces_to_comma = true; |
3212 lexer_flags.looking_for_object_index = true; | 3209 curr_lexer->looking_for_object_index = true; |
3213 | 3210 |
3214 return FCN_HANDLE; | 3211 return FCN_HANDLE; |
3215 } | 3212 } |
3216 } | 3213 } |
3217 | 3214 |
3220 | 3217 |
3221 if (kw_token) | 3218 if (kw_token) |
3222 { | 3219 { |
3223 if (kw_token >= 0) | 3220 if (kw_token >= 0) |
3224 { | 3221 { |
3225 lexer_flags.current_input_column += yyleng; | 3222 curr_lexer->current_input_column += yyleng; |
3226 lexer_flags.quote_is_transpose = false; | 3223 curr_lexer->quote_is_transpose = false; |
3227 lexer_flags.convert_spaces_to_comma = true; | 3224 curr_lexer->convert_spaces_to_comma = true; |
3228 lexer_flags.looking_for_object_index = false; | 3225 curr_lexer->looking_for_object_index = false; |
3229 } | 3226 } |
3230 | 3227 |
3231 return kw_token; | 3228 return kw_token; |
3232 } | 3229 } |
3233 | 3230 |
3263 && looks_like_command_arg ()) | 3260 && looks_like_command_arg ()) |
3264 { | 3261 { |
3265 BEGIN (COMMAND_START); | 3262 BEGIN (COMMAND_START); |
3266 } | 3263 } |
3267 else if (next_tok_is_eq | 3264 else if (next_tok_is_eq |
3268 || lexer_flags.looking_at_decl_list | 3265 || curr_lexer->looking_at_decl_list |
3269 || lexer_flags.looking_at_return_list | 3266 || curr_lexer->looking_at_return_list |
3270 || (lexer_flags.looking_at_parameter_list | 3267 || (curr_lexer->looking_at_parameter_list |
3271 && ! lexer_flags.looking_at_initializer_expression)) | 3268 && ! curr_lexer->looking_at_initializer_expression)) |
3272 { | 3269 { |
3273 symbol_table::force_variable (tok); | 3270 symbol_table::force_variable (tok); |
3274 } | 3271 } |
3275 else if (lexer_flags.looking_at_matrix_or_assign_lhs) | 3272 else if (curr_lexer->looking_at_matrix_or_assign_lhs) |
3276 { | 3273 { |
3277 lexer_flags.pending_local_variables.insert (tok); | 3274 curr_lexer->pending_local_variables.insert (tok); |
3278 } | 3275 } |
3279 } | 3276 } |
3280 | 3277 |
3281 // Find the token in the symbol table. Beware the magic | 3278 // Find the token in the symbol table. Beware the magic |
3282 // transformation of the end keyword... | 3279 // transformation of the end keyword... |
3283 | 3280 |
3284 if (tok == "end") | 3281 if (tok == "end") |
3285 tok = "__end__"; | 3282 tok = "__end__"; |
3286 | 3283 |
3287 yylval.tok_val = new token (&(symbol_table::insert (tok)), | 3284 yylval.tok_val = new token (&(symbol_table::insert (tok)), |
3288 lexer_flags.input_line_number, | 3285 curr_lexer->input_line_number, |
3289 lexer_flags.current_input_column); | 3286 curr_lexer->current_input_column); |
3290 | 3287 |
3291 token_stack.push (yylval.tok_val); | 3288 token_stack.push (yylval.tok_val); |
3292 | 3289 |
3293 // After seeing an identifer, it is ok to convert spaces to a comma | 3290 // After seeing an identifer, it is ok to convert spaces to a comma |
3294 // (if needed). | 3291 // (if needed). |
3295 | 3292 |
3296 lexer_flags.convert_spaces_to_comma = true; | 3293 curr_lexer->convert_spaces_to_comma = true; |
3297 | 3294 |
3298 if (! (next_tok_is_eq || YY_START == COMMAND_START)) | 3295 if (! (next_tok_is_eq || YY_START == COMMAND_START)) |
3299 { | 3296 { |
3300 lexer_flags.quote_is_transpose = true; | 3297 curr_lexer->quote_is_transpose = true; |
3301 | 3298 |
3302 do_comma_insert_check (); | 3299 do_comma_insert_check (); |
3303 | 3300 |
3304 maybe_unput_comma (spc_gobbled); | 3301 maybe_unput_comma (spc_gobbled); |
3305 } | 3302 } |
3306 | 3303 |
3307 lexer_flags.current_input_column += yyleng; | 3304 curr_lexer->current_input_column += yyleng; |
3308 | 3305 |
3309 if (tok != "__end__") | 3306 if (tok != "__end__") |
3310 lexer_flags.looking_for_object_index = true; | 3307 curr_lexer->looking_for_object_index = true; |
3311 | 3308 |
3312 return NAME; | 3309 return NAME; |
3313 } | 3310 } |
3314 | 3311 |
3315 bool | 3312 bool |
3464 std::string nm = curr_fcn_file_full_name; | 3461 std::string nm = curr_fcn_file_full_name; |
3465 | 3462 |
3466 if (nm.empty ()) | 3463 if (nm.empty ()) |
3467 warning_with_id ("Octave:separator-insert", | 3464 warning_with_id ("Octave:separator-insert", |
3468 "potential auto-insertion of '%c' near line %d", | 3465 "potential auto-insertion of '%c' near line %d", |
3469 sep, lexer_flags.input_line_number); | 3466 sep, curr_lexer->input_line_number); |
3470 else | 3467 else |
3471 warning_with_id ("Octave:separator-insert", | 3468 warning_with_id ("Octave:separator-insert", |
3472 "potential auto-insertion of '%c' near line %d of file %s", | 3469 "potential auto-insertion of '%c' near line %d of file %s", |
3473 sep, lexer_flags.input_line_number, nm.c_str ()); | 3470 sep, curr_lexer->input_line_number, nm.c_str ()); |
3474 } | 3471 } |
3475 | 3472 |
3476 static void | 3473 static void |
3477 gripe_single_quote_string (void) | 3474 gripe_single_quote_string (void) |
3478 { | 3475 { |
3479 std::string nm = curr_fcn_file_full_name; | 3476 std::string nm = curr_fcn_file_full_name; |
3480 | 3477 |
3481 if (nm.empty ()) | 3478 if (nm.empty ()) |
3482 warning_with_id ("Octave:single-quote-string", | 3479 warning_with_id ("Octave:single-quote-string", |
3483 "single quote delimited string near line %d", | 3480 "single quote delimited string near line %d", |
3484 lexer_flags.input_line_number); | 3481 curr_lexer->input_line_number); |
3485 else | 3482 else |
3486 warning_with_id ("Octave:single-quote-string", | 3483 warning_with_id ("Octave:single-quote-string", |
3487 "single quote delimited string near line %d of file %s", | 3484 "single quote delimited string near line %d of file %s", |
3488 lexer_flags.input_line_number, nm.c_str ()); | 3485 curr_lexer->input_line_number, nm.c_str ()); |
3489 } | 3486 } |
3490 | 3487 |
3491 static void | 3488 static void |
3492 gripe_matlab_incompatible (const std::string& msg) | 3489 gripe_matlab_incompatible (const std::string& msg) |
3493 { | 3490 { |
3498 "potential Matlab compatibility problem: %s", | 3495 "potential Matlab compatibility problem: %s", |
3499 msg.c_str ()); | 3496 msg.c_str ()); |
3500 else | 3497 else |
3501 warning_with_id ("Octave:matlab-incompatible", | 3498 warning_with_id ("Octave:matlab-incompatible", |
3502 "potential Matlab compatibility problem: %s near line %d offile %s", | 3499 "potential Matlab compatibility problem: %s near line %d offile %s", |
3503 msg.c_str (), lexer_flags.input_line_number, nm.c_str ()); | 3500 msg.c_str (), curr_lexer->input_line_number, nm.c_str ()); |
3504 } | 3501 } |
3505 | 3502 |
3506 static void | 3503 static void |
3507 maybe_gripe_matlab_incompatible_comment (char c) | 3504 maybe_gripe_matlab_incompatible_comment (char c) |
3508 { | 3505 { |