help-octave
[Top][All Lists]
Advanced

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

Re: space vs semicolon - why syntax error with the former ? (octave-3.4.


From: Ben Abbott
Subject: Re: space vs semicolon - why syntax error with the former ? (octave-3.4.2)
Date: Tue, 16 Aug 2011 08:24:15 -0400

On Aug 16, 2011, at 8:03 AM, Sergei Steshenko wrote:

> 
> 
> --- On Tue, 8/16/11, Ben Abbott <address@hidden> wrote:
> 
>> From: Ben Abbott <address@hidden>
>> Subject: Re: space vs semicolon - why syntax error with the former ? 
>> (octave-3.4.2)
>> To: "Sergei Steshenko" <address@hidden>
>> Cc: address@hidden
>> Date: Tuesday, August 16, 2011, 4:55 AM
>> On Aug 16, 2011, at 7:25 AM, Sergei
>> Steshenko wrote:
>> 
>>> Hello,
>>> 
>>> here is a screen session:
>>> "
>>> octave:1> for ii=1:1 ii endfor disp(ii)
>>> parse error:
>>> 
>>>   syntax error
>>> 
>>>>>> for ii=1:1 ii endfor disp(ii)
>>>                
>>             ^
>>> 
>>> octave:1> for ii=1:1 ii endfor;disp(ii)
>>> ii =  1
>>> 1
>>> octave:2>
>>> ".
>>> 
>>> Why is it so 'octave' doesn't accept the first variant
>> ?
>>> 
>>> With "traditional" 'endfor' on a new line semicolon
>> isn't needed ?
>>> Is there any reason for newline whitespace to be
>> treated differently than space whitespace ?
>>> 
>>> Thanks,
>>>   Sergei.
>> 
>> The parser treats keywords and functions differently.
>> 
>> I am not familiar with the parser implementation, so I
>> can't give a better explanation. To see what Octave's
>> keywords are, you can use the undocumented function
>> __keywords__.
>> 
>> To see what functions are in the path, use
>> __list_functions__.  There are builtin function as
>> well. To see those use __builtins__.
>> 
>> Ben
> 
> I do not grasp your reply. My point is that in "normal" languages all
> whitespaces are created equal. So, since the following works:
> 
> "
> octave:1> for ii = 1:1
>>  ii
>> endfor
> ii =  1
> octave:2> disp(ii);
> 1
> octave:3>           
> "
> 
> , and in this case 'endfor' is separated from 'disp' by newline, I  also
> expect
> 
> "
> octave:3> for ii = 1:1 ii endfor disp(ii);
> parse error:
> 
>  syntax error
> 
>>>> for ii = 1:1 ii endfor disp(ii);
>                              ^
> octave:3>    
> ",
> 
> to work (because newline and space both look like created equal whitespaces 
> to me), but it doesn't.
> 
> Thanks,
>  Sergei.

As I said, I am not familiar with the parser. What I did notice is that the 
parser is treating keywords differently than functions.

I am also aware of a  feature of both Matlab and Octave that means all space 
are not equal. Consider that each of the commands below are valid syntax.

        disp("Hello World")

... and ...

        disp ("Hello World")

... and ...

        disp "Hello World"

Also consider that each of the commands below are also valid syntax

        ("Hello World")

        "Hello World"

In Octave/Matlab spaces are not equal.

Back to your example, there is more than one interpretation of ...

        for ii = 1:1 ii endfor disp ii ;

Ben





reply via email to

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