comparison libinterp/parse-tree/oct-parse.in.yy @ 16681:d3619d4d267c

recognize character string at beginning of statement (bug #38926, #38958) * lex.ll ("'"): Always begin a character string if at the beginning of a statement. * oct-parse.in.yy (stmt_begin): New non-terminal. (anon_fcn_handle, if_cmd_list1, elseif_clause, switch_case, loop_command): Use it. * pt-fcn-handle.cc, for.tst, if.tst, switch.tst, while.tst: New tests.
author John W. Eaton <jwe@octave.org>
date Sat, 18 May 2013 16:21:32 -0400
parents de91b1621260
children e1c6ad54259f 2f63d2f3ff11
comparison
equal deleted inserted replaced
16680:de79cdbbdf7c 16681:d3619d4d267c
486 $$ = parser.make_fcn_handle ($2); 486 $$ = parser.make_fcn_handle ($2);
487 lexer.looking_at_function_handle--; 487 lexer.looking_at_function_handle--;
488 } 488 }
489 ; 489 ;
490 490
491 anon_fcn_handle : '@' param_list statement 491 anon_fcn_handle : '@' param_list stmt_begin statement
492 { 492 {
493 $$ = parser.make_anon_fcn_handle ($2, $3); 493 $$ = parser.make_anon_fcn_handle ($2, $4);
494 lexer.nesting_level.remove (); 494 lexer.nesting_level.remove ();
495 } 495 }
496 ; 496 ;
497 497
498 primary_expr : identifier 498 primary_expr : identifier
829 $1->append ($2); 829 $1->append ($2);
830 $$ = $1; 830 $$ = $1;
831 } 831 }
832 ; 832 ;
833 833
834 if_cmd_list1 : expression opt_sep opt_list 834 if_cmd_list1 : expression stmt_begin opt_sep opt_list
835 { 835 {
836 $1->mark_braindead_shortcircuit (lexer.fcn_file_full_name); 836 $1->mark_braindead_shortcircuit (lexer.fcn_file_full_name);
837 837
838 $$ = parser.start_if_command ($1, $3); 838 $$ = parser.start_if_command ($1, $4);
839 } 839 }
840 | if_cmd_list1 elseif_clause 840 | if_cmd_list1 elseif_clause
841 { 841 {
842 $1->append ($2); 842 $1->append ($2);
843 $$ = $1; 843 $$ = $1;
844 } 844 }
845 ; 845 ;
846 846
847 elseif_clause : ELSEIF stash_comment opt_sep expression opt_sep opt_list 847 elseif_clause : ELSEIF stash_comment opt_sep expression stmt_begin opt_sep opt_list
848 { 848 {
849 $4->mark_braindead_shortcircuit (lexer.fcn_file_full_name); 849 $4->mark_braindead_shortcircuit (lexer.fcn_file_full_name);
850 850
851 $$ = parser.make_elseif_clause ($1, $4, $6, $2); 851 $$ = parser.make_elseif_clause ($1, $4, $7, $2);
852 } 852 }
853 ; 853 ;
854 854
855 else_clause : ELSE stash_comment opt_sep opt_list 855 else_clause : ELSE stash_comment opt_sep opt_list
856 { $$ = new tree_if_clause ($4, $2); } 856 { $$ = new tree_if_clause ($4, $2); }
887 $1->append ($2); 887 $1->append ($2);
888 $$ = $1; 888 $$ = $1;
889 } 889 }
890 ; 890 ;
891 891
892 switch_case : CASE stash_comment opt_sep expression opt_sep opt_list 892 switch_case : CASE stash_comment opt_sep expression stmt_begin opt_sep opt_list
893 { $$ = parser.make_switch_case ($1, $4, $6, $2); } 893 { $$ = parser.make_switch_case ($1, $4, $7, $2); }
894 ; 894 ;
895 895
896 default_case : OTHERWISE stash_comment opt_sep opt_list 896 default_case : OTHERWISE stash_comment opt_sep opt_list
897 { 897 {
898 $$ = new tree_switch_case ($4, $2); 898 $$ = new tree_switch_case ($4, $2);
901 901
902 // ======= 902 // =======
903 // Looping 903 // Looping
904 // ======= 904 // =======
905 905
906 loop_command : WHILE stash_comment expression opt_sep opt_list END 906 loop_command : WHILE stash_comment expression stmt_begin opt_sep opt_list END
907 { 907 {
908 $3->mark_braindead_shortcircuit (lexer.fcn_file_full_name); 908 $3->mark_braindead_shortcircuit (lexer.fcn_file_full_name);
909 909
910 if (! ($$ = parser.make_while_command ($1, $3, $5, $6, $2))) 910 if (! ($$ = parser.make_while_command ($1, $3, $6, $7, $2)))
911 ABORT_PARSE; 911 ABORT_PARSE;
912 } 912 }
913 | DO stash_comment opt_sep opt_list UNTIL expression 913 | DO stash_comment opt_sep opt_list UNTIL expression
914 { 914 {
915 if (! ($$ = parser.make_do_until_command ($5, $4, $6, $2))) 915 if (! ($$ = parser.make_do_until_command ($5, $4, $6, $2)))
916 ABORT_PARSE; 916 ABORT_PARSE;
917 } 917 }
918 | FOR stash_comment assign_lhs '=' expression opt_sep opt_list END 918 | FOR stash_comment assign_lhs '=' expression stmt_begin opt_sep opt_list END
919 { 919 {
920 if (! ($$ = parser.make_for_command (FOR, $1, $3, $5, 0, 920 if (! ($$ = parser.make_for_command (FOR, $1, $3, $5, 0,
921 $7, $8, $2))) 921 $8, $9, $2)))
922 ABORT_PARSE; 922 ABORT_PARSE;
923 } 923 }
924 | FOR stash_comment '(' assign_lhs '=' expression ')' opt_sep opt_list END 924 | FOR stash_comment '(' assign_lhs '=' expression ')' opt_sep opt_list END
925 { 925 {
926 if (! ($$ = parser.make_for_command (FOR, $1, $4, $6, 0, 926 if (! ($$ = parser.make_for_command (FOR, $1, $4, $6, 0,
927 $9, $10, $2))) 927 $9, $10, $2)))
928 ABORT_PARSE; 928 ABORT_PARSE;
929 } 929 }
930 | PARFOR stash_comment assign_lhs '=' expression opt_sep opt_list END 930 | PARFOR stash_comment assign_lhs '=' expression stmt_begin opt_sep opt_list END
931 { 931 {
932 if (! ($$ = parser.make_for_command (PARFOR, $1, $3, $5, 932 if (! ($$ = parser.make_for_command (PARFOR, $1, $3, $5,
933 0, $7, $8, $2))) 933 0, $8, $9, $2)))
934 ABORT_PARSE; 934 ABORT_PARSE;
935 } 935 }
936 | PARFOR stash_comment '(' assign_lhs '=' expression ',' expression ')' opt_sep opt_list END 936 | PARFOR stash_comment '(' assign_lhs '=' expression ',' expression ')' opt_sep opt_list END
937 { 937 {
938 if (! ($$ = parser.make_for_command (PARFOR, $1, $4, $6, 938 if (! ($$ = parser.make_for_command (PARFOR, $1, $4, $6,
1403 ; 1403 ;
1404 1404
1405 // ============= 1405 // =============
1406 // Miscellaneous 1406 // Miscellaneous
1407 // ============= 1407 // =============
1408
1409 stmt_begin : // empty
1410 { lexer.at_beginning_of_statement = true; }
1411 ;
1408 1412
1409 stash_comment : // empty 1413 stash_comment : // empty
1410 { $$ = octave_comment_buffer::get_comment (); } 1414 { $$ = octave_comment_buffer::get_comment (); }
1411 ; 1415 ;
1412 1416