octave-bug-tracker
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Octave-bug-tracker] [bug #60882] error parsing command syntax


From: John W. Eaton
Subject: [Octave-bug-tracker] [bug #60882] error parsing command syntax
Date: Mon, 19 Jul 2021 14:00:56 -0400 (EDT)
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101 Firefox/78.0

Follow-up Comment #17, bug #60882 (project octave):

The Matlab docs also explain that at the command line, Matlab may check the
current workspace to determine whether the first symbol in an expression is a
variable.  But in a script or function, command syntax is recognized purely
from syntax.  They also explain that when looking at syntax alone, '=' is
always recognized as assignment regardless of whitespace but


v1 OPv2  %% command
v1 OP v2 %% expression
v1OPv2   %% expression


We attempt the same, but we have the following extra operators:


 !=
 ++  --
 **
.**  .+   .-
 +=   -=   *=   /=   \\=    ^=   **=   &=   |=
.+=  .-=  .*=  ./=  .\\=   .^=  .**=


I already made the OP= operators always behave as operators regardless of
spacing and added the following comment to lex.ll:


// Use the following to handle computed assignment operators
// (+=, -=, etc.) in word list commands in a way that is compatible
// with Matlab.  However, that will also make it impossible to use
// these operators with a space before them:
//
//   x = 1;
//   x+=2;   ## ok
//   x+= 2;  ## ok
//   x +=2;  ## error: invalid use of symbol as both variable and command
//   x += 2; ## error: invalid use of symbol as both variable and command


but maybe that's not the correct behavior anyway.  Instead, would it be OK if
we could make Octave behave as follows?


  x-=2   %% -= is an operator
  x-= 2  %% -= is an operator
  x -= 2 %% -= is an operator
  x -=2  %% -=2 is an argument to a command-style function call


The difference with Matlab would still be that "-=" by itself is recognized as
an argument to a command-style function call because Matlab doesn't have "-="
as an operator so it recognizes this as "-" followed by another character with
no space, so that looks like a command-style argument instead of an operator. 
This behavior may break some valid Matlab code that currently works in Octave
because users expect "-ANYTHING" to be recognized as a command option.


    _______________________________________________________

Reply to this item at:

  <https://savannah.gnu.org/bugs/?60882>

_______________________________________________
  Message sent via Savannah
  https://savannah.gnu.org/




reply via email to

[Prev in Thread] Current Thread [Next in Thread]