Mercurial > octave-dspies
comparison libinterp/parse-tree/lex.ll @ 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 | 6bfd8dbd7d3c |
children | e1dcd834751f |
comparison
equal
deleted
inserted
replaced
16359:253e13e77d12 | 16360:11115c237231 |
---|---|
1054 | 1054 |
1055 %{ | 1055 %{ |
1056 // = and op= operators. | 1056 // = and op= operators. |
1057 %} | 1057 %} |
1058 | 1058 |
1059 "=" { return curr_lexer->handle_op ("=", '='); } | 1059 "=" { |
1060 curr_lexer->maybe_mark_previous_token_as_variable (); | |
1061 | |
1062 return curr_lexer->handle_op ("=", '='); | |
1063 } | |
1064 | |
1060 "+=" { return curr_lexer->handle_incompatible_op ("+=", ADD_EQ); } | 1065 "+=" { return curr_lexer->handle_incompatible_op ("+=", ADD_EQ); } |
1061 "-=" { return curr_lexer->handle_incompatible_op ("-=", SUB_EQ); } | 1066 "-=" { return curr_lexer->handle_incompatible_op ("-=", SUB_EQ); } |
1062 "*=" { return curr_lexer->handle_incompatible_op ("*=", MUL_EQ); } | 1067 "*=" { return curr_lexer->handle_incompatible_op ("*=", MUL_EQ); } |
1063 "/=" { return curr_lexer->handle_incompatible_op ("/=", DIV_EQ); } | 1068 "/=" { return curr_lexer->handle_incompatible_op ("/=", DIV_EQ); } |
1064 "\\=" { return curr_lexer->handle_incompatible_op ("\\=", LEFTDIV_EQ); } | 1069 "\\=" { return curr_lexer->handle_incompatible_op ("\\=", LEFTDIV_EQ); } |
1549 { | 1554 { |
1550 const token *tok = tokens.front (); | 1555 const token *tok = tokens.front (); |
1551 return tok ? tok->may_be_command () : false; | 1556 return tok ? tok->may_be_command () : false; |
1552 } | 1557 } |
1553 | 1558 |
1559 void | |
1560 lexical_feedback::maybe_mark_previous_token_as_variable (void) | |
1561 { | |
1562 token *tok = tokens.front (); | |
1563 if (tok->is_symbol ()) | |
1564 pending_local_variables.insert (tok->symbol_name ()); | |
1565 } | |
1566 | |
1567 void | |
1568 lexical_feedback::mark_as_variables (const std::list<std::string>& lst) | |
1569 { | |
1570 for (std::list<std::string>::const_iterator p = lst.begin (); | |
1571 p != lst.end (); p++) | |
1572 { | |
1573 pending_local_variables.insert (*p); | |
1574 } | |
1575 } | |
1576 | |
1554 static bool | 1577 static bool |
1555 looks_like_copyright (const std::string& s) | 1578 looks_like_copyright (const std::string& s) |
1556 { | 1579 { |
1557 bool retval = false; | 1580 bool retval = false; |
1558 | 1581 |
1780 break; | 1803 break; |
1781 } | 1804 } |
1782 } | 1805 } |
1783 | 1806 |
1784 return retval; | 1807 return retval; |
1808 } | |
1809 | |
1810 bool | |
1811 octave_base_lexer::is_variable (const std::string& name) | |
1812 { | |
1813 return (symbol_table::is_variable (name) | |
1814 || (pending_local_variables.find (name) | |
1815 != pending_local_variables.end ())); | |
1785 } | 1816 } |
1786 | 1817 |
1787 // Handle keywords. Return -1 if the keyword should be ignored. | 1818 // Handle keywords. Return -1 if the keyword should be ignored. |
1788 | 1819 |
1789 int | 1820 int |
2549 | 2580 |
2550 token *tok_val = new token (NAME, &(symbol_table::insert (tok, sid)), | 2581 token *tok_val = new token (NAME, &(symbol_table::insert (tok, sid)), |
2551 input_line_number, current_input_column); | 2582 input_line_number, current_input_column); |
2552 | 2583 |
2553 if (at_beginning_of_statement | 2584 if (at_beginning_of_statement |
2554 && (! (tok == "e" | 2585 && (! (is_variable (tok) |
2586 || tok == "e" | |
2555 || tok == "I" || tok == "i" | 2587 || tok == "I" || tok == "i" |
2556 || tok == "J" || tok == "j" | 2588 || tok == "J" || tok == "j" |
2557 || tok == "Inf" || tok == "inf" | 2589 || tok == "Inf" || tok == "inf" |
2558 || tok == "NaN" || tok == "nan"))) | 2590 || tok == "NaN" || tok == "nan"))) |
2559 tok_val->mark_may_be_command (); | 2591 tok_val->mark_may_be_command (); |