comparison libinterp/parse-tree/oct-parse.in.yy @ 16360:11115c237231

recognize variables when parsing (bug #38576) * lex.h, lex.ll (lexical_feedback::mark_as_variable, lexical_feedback::maybe_mark_previous_token_as_variable, lexical_feedback::mark_as_variables, octave_lexer::is_variable): New fucntions. ("="): Call maybe_mark_previous_toke_as_variable. (handle_identifier): Don't tag variables as possible commands. (param_list): Mark names in list as variables. (octave_base_parser::validate_matrix_for_assignment): Likewise. * pt-arg-list.h, pt-arg-list.cc (tree_argument_list::variable_names): New function. * pt-misc.h, pt-misc.cc (tree_parameter_list::variable_names): New function. * token.h, token.cc (token::symbol_name, token::is_symbol): New functions. * test/bug-38576.tst: New file. * test/Makefile.am (FCN_FILES): Add bug-38576.tst to the list.
author John W. Eaton <jwe@octave.org>
date Sat, 23 Mar 2013 15:02:29 -0400
parents 09f0cb9cac7d
children 302157614308
comparison
equal deleted inserted replaced
16359:253e13e77d12 16360:11115c237231
1034 lexer.looking_for_object_index = false; 1034 lexer.looking_for_object_index = false;
1035 } 1035 }
1036 ; 1036 ;
1037 1037
1038 param_list : param_list_beg param_list1 param_list_end 1038 param_list : param_list_beg param_list1 param_list_end
1039 { $$ = $2; } 1039 {
1040 if ($2)
1041 lexer.mark_as_variables ($2->variable_names ());
1042
1043 $$ = $2;
1044 }
1040 | param_list_beg error 1045 | param_list_beg error
1041 { 1046 {
1042 parser.bison_error ("invalid parameter list"); 1047 parser.bison_error ("invalid parameter list");
1043 $$ = 0; 1048 $$ = 0;
1044 ABORT_PARSE; 1049 ABORT_PARSE;
1049 { $$ = 0; } 1054 { $$ = 0; }
1050 | param_list2 1055 | param_list2
1051 { 1056 {
1052 $1->mark_as_formal_parameters (); 1057 $1->mark_as_formal_parameters ();
1053 if ($1->validate (tree_parameter_list::in)) 1058 if ($1->validate (tree_parameter_list::in))
1054 $$ = $1; 1059 {
1060 lexer.mark_as_variables ($1->variable_names ());
1061 $$ = $1;
1062 }
1055 else 1063 else
1056 ABORT_PARSE; 1064 ABORT_PARSE;
1057 } 1065 }
1058 ; 1066 ;
1059 1067
2967 } 2975 }
2968 else 2976 else
2969 tmp = new tree_argument_list (e); 2977 tmp = new tree_argument_list (e);
2970 2978
2971 if (tmp && tmp->is_valid_lvalue_list ()) 2979 if (tmp && tmp->is_valid_lvalue_list ())
2972 retval = tmp; 2980 {
2981 lexer.mark_as_variables (tmp->variable_names ());
2982 retval = tmp;
2983 }
2973 else 2984 else
2974 { 2985 {
2975 bison_error ("invalid left hand side of assignment"); 2986 bison_error ("invalid left hand side of assignment");
2976 delete tmp; 2987 delete tmp;
2977 } 2988 }