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

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

[Octave-bug-tracker] [bug #41032] Command function parsing: does handle


From: anonymous
Subject: [Octave-bug-tracker] [bug #41032] Command function parsing: does handle certain patterns involving commas as parentheses
Date: Mon, 30 Dec 2013 07:16:55 +0000
User-agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_9_1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/31.0.1650.63 Safari/537.36

URL:
  <http://savannah.gnu.org/bugs/?41032>

                 Summary: Command function parsing: does handle certain
patterns involving commas as parentheses
                 Project: GNU Octave
            Submitted by: None
            Submitted on: Mon 30 Dec 2013 07:16:54 AM UTC
                Category: Interpreter
                Severity: 3 - Normal
                Priority: 5 - Normal
              Item Group: Matlab Compatibility
                  Status: None
             Assigned to: None
         Originator Name: Michael C. Grant
        Originator Email: address@hidden
             Open/Closed: Open
         Discussion Lock: Any
                 Release: 3.8.0
        Operating System: Mac OS

    _______________________________________________________

Details:

I'm trying to port my optimization modeling software CVX (http://cvxr.com/cvx)
to Octave. 3.8.0 is a huge leap forward and I believe I'm very close to being
able to do this. I can't tell you how often I am asked about this, and I'm
pleased that it seems that soon it will be possible to do so.

I use MATLAB's command syntax extensively to emulate an embedded modeling
language. Unfortunately, Octave 3.8 is unable to handle some of the
constructions constructions. For instance, to declare a 2-D matrix variable of
size M times N, I allow the user to enter the following command:


variable A(M,N)
-verbatim

MATLAB slurps in 'A(M,N)' as a single token, which I can then parse to extract
the name and dimension information. I can include whitespace within the
parentheses, and MATLAB will still preserve the result as a single token.
Unfortunately, Octave's behavior is different: not only does it ignore
parentheses grouping, but it cannot handle commas at all. Actually, this
second issue is understandable given the first, since the comma has an
important syntactic purpose in MATLAB.

To demonstrate, consider the following code:


function command_test1(varargin)
disp(sprintf('{%s}',varargin{:}))


Here is some sample output:

octave:63> command_test1 this is a test
{this}{is}{a}{test}
octave:64> command_test1 this(nx) is a test
{this(nx)}{is}{a}{test}


So far, so good; this matches MATLAB precisely. However, this differs between
Octave and MATLAB:

Octave:

octave:65> command_test1 this( nx ) is a test
{this(}{nx}{)}{is}{a}{test}


MATLAB:

>> command_test1 this( nx ) is a test
{this( nx )}{is}{a}{test}


Furthermore, if I try this, I get a parse error:

Octave:

octave:64> command_test1 this(nx,ny) is a test
parse error:

  syntax error

>>> command_test1 this(nx,ny) is a test
                            ^


MATLAB:

>> command_test1 this(nx,ny) is a test
{this(nx,ny)}{is}{a}{test}


I have found that employing quotes is a workaround, but this behavior differs
between MATLAB and Octave as well. And I'm afraid it would defeat a
fundamental purpose of my code to require it:

Octave:

octave:67> command_test1 "this(,)" is a test
{this(,)}{is}{a}{test}
octave:68> command_test1 'this(,)' is a test
{this(,)}{is}{a}{test}


MATLAB:

>> command_test1 "this( nx )" is a test
{"this( nx )"}{is}{a}{test}
>> command_test1 'this( nx )' is a test
{this( nx )}{is}{a}{test}


The quoting behavior causes no conflicts with my code (and I understand the
motivation for supporting double quotes for strings). But the lack of
parenthesis support does. I would much appreciate it if you would consider
adopting a modification that brings Octave closer to parity here. I'll see if
I can't dig into the parsing and do a patch.

Thanks
Michael







    _______________________________________________________

Reply to this item at:

  <http://savannah.gnu.org/bugs/?41032>

_______________________________________________
  Message sent via/by Savannah
  http://savannah.gnu.org/




reply via email to

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