comparison libinterp/parse-tree/lex.ll @ 16788:f89de736eecd

correctly parse expressions like pi+1 (bug #39301) * lex.ll (CMD_OR_UNARY_OP): Also check whether the current token looks like a command argument. (octave_base_lexer::handle_identifier): Special treatment for pi.
author John W. Eaton <jwe@octave.org>
date Thu, 20 Jun 2013 18:21:48 -0400
parents 0bf1d559b321
children 498b2dd1bd56 531473481084
comparison
equal deleted inserted replaced
16787:2cfd8cd9e1b6 16788:f89de736eecd
171 { \ 171 { \
172 curr_lexer->lexer_debug (PATTERN); \ 172 curr_lexer->lexer_debug (PATTERN); \
173 \ 173 \
174 if (curr_lexer->previous_token_may_be_command ()) \ 174 if (curr_lexer->previous_token_may_be_command ()) \
175 { \ 175 { \
176 yyless (0); \ 176 if (curr_lexer->looks_like_command_arg ()) \
177 curr_lexer->push_start_state (COMMAND_START); \ 177 { \
178 yyless (0); \
179 curr_lexer->push_start_state (COMMAND_START); \
180 } \
181 else \
182 { \
183 return curr_lexer->handle_op_internal (TOK, false, COMPAT); \
184 } \
178 } \ 185 } \
179 else \ 186 else \
180 { \ 187 { \
181 int tok \ 188 int tok \
182 = (COMPAT \ 189 = (COMPAT \
2650 symbol_table::scope_id sid = symtab_context.curr_scope (); 2657 symbol_table::scope_id sid = symtab_context.curr_scope ();
2651 2658
2652 token *tok_val = new token (NAME, &(symbol_table::insert (tok, sid)), 2659 token *tok_val = new token (NAME, &(symbol_table::insert (tok, sid)),
2653 input_line_number, current_input_column); 2660 input_line_number, current_input_column);
2654 2661
2662 // The following symbols are handled specially so that things like
2663 //
2664 // pi +1
2665 //
2666 // are parsed as an addition expression instead of as a command-style
2667 // function call with the argument "+1".
2668
2655 if (at_beginning_of_statement 2669 if (at_beginning_of_statement
2656 && (! (is_variable (tok) 2670 && (! (is_variable (tok)
2657 || tok == "e" 2671 || tok == "e" || tok == "pi"
2658 || tok == "I" || tok == "i" 2672 || tok == "I" || tok == "i"
2659 || tok == "J" || tok == "j" 2673 || tok == "J" || tok == "j"
2660 || tok == "Inf" || tok == "inf" 2674 || tok == "Inf" || tok == "inf"
2661 || tok == "NaN" || tok == "nan"))) 2675 || tok == "NaN" || tok == "nan")))
2662 tok_val->mark_may_be_command (); 2676 tok_val->mark_may_be_command ();