comparison libinterp/parse-tree/oct-parse.yy @ 31478:ef9c804676b9 stable

don't accept '!' to indicate ignored function parameters * lex.ll ("~", "!", lexical_feedback::previous_token_is_binop, base_lexer::display_token): Use separate '~' and '!' tokens instead of recognizing both as EXPR_NOT. * oct-parse.yy: Adjust list of tokens and precedence list in parser. (magic_tilde): Accept only '~', not EXPR_NOT. (oper_expr, power_expr, attr, base_parser::make_prefix_op): Handle '~' and '!' tokens separately.
author John W. Eaton <jwe@octave.org>
date Fri, 18 Nov 2022 23:49:32 -0500
parents 7781b1e77406
children e88a07dec498
comparison
equal deleted inserted replaced
31476:77072a5e99a5 31478:ef9c804676b9
200 octave::tree_classdef_enum_list* tree_classdef_enum_list_type; 200 octave::tree_classdef_enum_list* tree_classdef_enum_list_type;
201 octave::tree_classdef_enum_block* tree_classdef_enum_block_type; 201 octave::tree_classdef_enum_block* tree_classdef_enum_block_type;
202 } 202 }
203 203
204 // Tokens with line and column information. 204 // Tokens with line and column information.
205 %token <tok_val> '=' ':' '-' '+' '*' '/' 205 %token <tok_val> '=' ':' '-' '+' '*' '/' '~' '!'
206 %token <tok_val> '(' ')' '[' ']' '{' '}' '.' '@' 206 %token <tok_val> '(' ')' '[' ']' '{' '}' '.' '@'
207 %token <tok_val> ',' ';' '\n' 207 %token <tok_val> ',' ';' '\n'
208 %token <tok_val> ADD_EQ SUB_EQ MUL_EQ DIV_EQ LEFTDIV_EQ POW_EQ 208 %token <tok_val> ADD_EQ SUB_EQ MUL_EQ DIV_EQ LEFTDIV_EQ POW_EQ
209 %token <tok_val> EMUL_EQ EDIV_EQ ELEFTDIV_EQ EPOW_EQ AND_EQ OR_EQ 209 %token <tok_val> EMUL_EQ EDIV_EQ ELEFTDIV_EQ EPOW_EQ AND_EQ OR_EQ
210 %token <tok_val> EXPR_AND_AND EXPR_OR_OR 210 %token <tok_val> EXPR_AND_AND EXPR_OR_OR
211 %token <tok_val> EXPR_AND EXPR_OR EXPR_NOT 211 %token <tok_val> EXPR_AND EXPR_OR
212 %token <tok_val> EXPR_LT EXPR_LE EXPR_EQ EXPR_NE EXPR_GE EXPR_GT 212 %token <tok_val> EXPR_LT EXPR_LE EXPR_EQ EXPR_NE EXPR_GE EXPR_GT
213 %token <tok_val> LEFTDIV EMUL EDIV ELEFTDIV 213 %token <tok_val> LEFTDIV EMUL EDIV ELEFTDIV
214 %token <tok_val> HERMITIAN TRANSPOSE 214 %token <tok_val> HERMITIAN TRANSPOSE
215 %token <tok_val> PLUS_PLUS MINUS_MINUS POW EPOW 215 %token <tok_val> PLUS_PLUS MINUS_MINUS POW EPOW
216 %token <tok_val> NUMBER 216 %token <tok_val> NUMBER
323 %left EXPR_AND 323 %left EXPR_AND
324 %left EXPR_LT EXPR_LE EXPR_EQ EXPR_NE EXPR_GE EXPR_GT 324 %left EXPR_LT EXPR_LE EXPR_EQ EXPR_NE EXPR_GE EXPR_GT
325 %left ':' 325 %left ':'
326 %left '-' '+' 326 %left '-' '+'
327 %left '*' '/' LEFTDIV EMUL EDIV ELEFTDIV 327 %left '*' '/' LEFTDIV EMUL EDIV ELEFTDIV
328 %right UNARY EXPR_NOT 328 %right UNARY '~' '!'
329 %left POW EPOW HERMITIAN TRANSPOSE 329 %left POW EPOW HERMITIAN TRANSPOSE
330 %right PLUS_PLUS MINUS_MINUS 330 %right PLUS_PLUS MINUS_MINUS
331 %left '(' '.' '{' 331 %left '(' '.' '{'
332 332
333 // How to clean up if there is a parse error. We handle deleting tokens 333 // How to clean up if there is a parse error. We handle deleting tokens
687 687
688 magic_colon : ':' 688 magic_colon : ':'
689 { $$ = parser.make_constant ($1); } 689 { $$ = parser.make_constant ($1); }
690 ; 690 ;
691 691
692 magic_tilde : EXPR_NOT 692 magic_tilde : '~'
693 { 693 {
694 OCTAVE_YYUSE ($1); 694 OCTAVE_YYUSE ($1);
695 695
696 $$ = parser.make_black_hole (); 696 $$ = parser.make_black_hole ();
697 } 697 }
796 } 796 }
797 | PLUS_PLUS oper_expr %prec UNARY 797 | PLUS_PLUS oper_expr %prec UNARY
798 { $$ = parser.make_prefix_op (PLUS_PLUS, $2, $1); } 798 { $$ = parser.make_prefix_op (PLUS_PLUS, $2, $1); }
799 | MINUS_MINUS oper_expr %prec UNARY 799 | MINUS_MINUS oper_expr %prec UNARY
800 { $$ = parser.make_prefix_op (MINUS_MINUS, $2, $1); } 800 { $$ = parser.make_prefix_op (MINUS_MINUS, $2, $1); }
801 | EXPR_NOT oper_expr %prec UNARY 801 | '~' oper_expr %prec UNARY
802 { $$ = parser.make_prefix_op (EXPR_NOT, $2, $1); } 802 { $$ = parser.make_prefix_op ('~', $2, $1); }
803 | '!' oper_expr %prec UNARY
804 { $$ = parser.make_prefix_op ('!', $2, $1); }
803 | '+' oper_expr %prec UNARY 805 | '+' oper_expr %prec UNARY
804 { $$ = parser.make_prefix_op ('+', $2, $1); } 806 { $$ = parser.make_prefix_op ('+', $2, $1); }
805 | '-' oper_expr %prec UNARY 807 | '-' oper_expr %prec UNARY
806 { $$ = parser.make_prefix_op ('-', $2, $1); } 808 { $$ = parser.make_prefix_op ('-', $2, $1); }
807 | oper_expr POW power_expr 809 | oper_expr POW power_expr
886 } 888 }
887 | PLUS_PLUS power_expr %prec POW 889 | PLUS_PLUS power_expr %prec POW
888 { $$ = parser.make_prefix_op (PLUS_PLUS, $2, $1); } 890 { $$ = parser.make_prefix_op (PLUS_PLUS, $2, $1); }
889 | MINUS_MINUS power_expr %prec POW 891 | MINUS_MINUS power_expr %prec POW
890 { $$ = parser.make_prefix_op (MINUS_MINUS, $2, $1); } 892 { $$ = parser.make_prefix_op (MINUS_MINUS, $2, $1); }
891 | EXPR_NOT power_expr %prec POW 893 | '~' power_expr %prec POW
892 { $$ = parser.make_prefix_op (EXPR_NOT, $2, $1); } 894 { $$ = parser.make_prefix_op ('~', $2, $1); }
895 | '!' power_expr %prec POW
896 { $$ = parser.make_prefix_op ('!', $2, $1); }
893 | '+' power_expr %prec POW 897 | '+' power_expr %prec POW
894 { $$ = parser.make_prefix_op ('+', $2, $1); } 898 { $$ = parser.make_prefix_op ('+', $2, $1); }
895 | '-' power_expr %prec POW 899 | '-' power_expr %prec POW
896 { $$ = parser.make_prefix_op ('-', $2, $1); } 900 { $$ = parser.make_prefix_op ('-', $2, $1); }
897 ; 901 ;
1885 { 1889 {
1886 OCTAVE_YYUSE ($2); 1890 OCTAVE_YYUSE ($2);
1887 1891
1888 $$ = parser.make_classdef_attribute ($1, $3); 1892 $$ = parser.make_classdef_attribute ($1, $3);
1889 } 1893 }
1890 | EXPR_NOT identifier 1894 | '~' identifier
1895 {
1896 OCTAVE_YYUSE ($1);
1897
1898 $$ = parser.make_not_classdef_attribute ($2);
1899 }
1900 | '!' identifier
1891 { 1901 {
1892 OCTAVE_YYUSE ($1); 1902 OCTAVE_YYUSE ($1);
1893 1903
1894 $$ = parser.make_not_classdef_attribute ($2); 1904 $$ = parser.make_not_classdef_attribute ($2);
1895 } 1905 }
3207 { 3217 {
3208 octave_value::unary_op t = octave_value::unknown_unary_op; 3218 octave_value::unary_op t = octave_value::unknown_unary_op;
3209 3219
3210 switch (op) 3220 switch (op)
3211 { 3221 {
3212 case EXPR_NOT: 3222 case '~':
3223 case '!':
3213 t = octave_value::op_not; 3224 t = octave_value::op_not;
3214 break; 3225 break;
3215 3226
3216 case '+': 3227 case '+':
3217 t = octave_value::op_uplus; 3228 t = octave_value::op_uplus;