changeset 16790: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 2cfd8cd9e1b6
children 2f63d2f3ff11
files libinterp/parse-tree/lex.ll
diffstat 1 files changed, 17 insertions(+), 3 deletions(-) [+]
line wrap: on
line diff
--- a/libinterp/parse-tree/lex.ll
+++ b/libinterp/parse-tree/lex.ll
@@ -173,8 +173,15 @@
  \
       if (curr_lexer->previous_token_may_be_command ()) \
         { \
-          yyless (0); \
-          curr_lexer->push_start_state (COMMAND_START); \
+          if (curr_lexer->looks_like_command_arg ()) \
+            { \
+              yyless (0); \
+              curr_lexer->push_start_state (COMMAND_START); \
+            } \
+          else \
+            { \
+              return curr_lexer->handle_op_internal (TOK, false, COMPAT); \
+            } \
         } \
       else \
         { \
@@ -2652,9 +2659,16 @@
   token *tok_val = new token (NAME, &(symbol_table::insert (tok, sid)),
                               input_line_number, current_input_column);
 
+  // The following symbols are handled specially so that things like
+  //
+  //   pi +1
+  //
+  // are parsed as an addition expression instead of as a command-style
+  // function call with the argument "+1".
+
   if (at_beginning_of_statement
       && (! (is_variable (tok)
-             || tok == "e"
+             || tok == "e" || tok == "pi"
              || tok == "I" || tok == "i"
              || tok == "J" || tok == "j"
              || tok == "Inf" || tok == "inf"