octave-maintainers
[Top][All Lists]
Advanced

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

Re: parsing commands


From: John W. Eaton
Subject: Re: parsing commands
Date: Sat, 18 May 2013 14:41:02 -0400
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:10.0.11) Gecko/20121122 Icedove/10.0.11

On 05/18/2013 08:36 AM, Clemens Buchacher wrote:
On Fri, May 17, 2013 at 06:04:16PM -0400, John W. Eaton wrote:

For Octave, we have to decide what to do for the operators that are
unique to Octave.  That includes all op= assignment operators, ++, and
--.  Since Matlab does not have --,

   foo --

will be a command.  But for Octave, that could be a decrement
operation.

The -- argument is used by some command line tools as a separator of
options and arguments, e.g. from 'info rm':

     rm -- -f

I realized that this could only be a valid expression if "rm" is a variable. We already track that in the lexer+parser, so when looking at -- or ++, I think it is sufficient to simply check whether the previous token could be a command (at the beginning of a statement and not already defined as a variable).

For op= assignment operator this reasoning makes less sense. And having
inconsistent behavior between op=, --, and ++ seems like a bad idea.

I think most importantly we should keep consistency between those three
at least. I can see arguments both for and against interpreting these
examples as commands:

     rm -- -f
     git-checkout --
     x -= 5;
     x ++;

I'd tend towards interpreting all of these as operators (with a syntax
error in the first example), since Octave is foremost a tool for numeric
computation and not a shell.

I don't think the situation is as bad as I originally thought because things like

  x -= 5

can only be valid expressions if X is already defined as a variable.

I checked in the following patch.

  http://hg.savannah.gnu.org/hgweb/octave/rev/de79cdbbdf7c

jwe




reply via email to

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