bugGNU Octave - Bugs: bug #58945, Octave parser allows keyword 'end'...

 
 

bug #58945: Octave parser allows keyword 'end' as a function parameter

Submitter:  Rik <rik5>
Submitted:  Thu 13 Aug 2020 10:08:07 PM UTC
   
 
Category:  Interpreter Severity:  2 - Minor
Priority:  5 - Normal Item Group:  Incorrect Result
Status:  Fixed Assigned to:  None
Originator Name:  Open/Closed:  * Closed
Release:  * dev Operating System:  * Any
Fixed Release:  None Planned Release:  None
* Mandatory Fields

Add a New Comment Rich Markup
   

Jump to the original submission

Thu 03 Sep 2020 09:02:39 PM UTC, comment #7: 

Thanks, much nicer reporting now.

Rik <rik5>
Group administrator
Thu 03 Sep 2020 08:47:15 PM UTC, comment #6: 

I pushed a fix for the token position problem on stable and merged with default.

http://hg.savannah.gnu.org/hgweb/octave/rev/9117c746de0c

John W. Eaton <jwe>
Group administrator
Thu 03 Sep 2020 02:49:19 PM UTC, comment #5: 

I agree that the incorrect token position info is less critical, but I think it is still important to fix.  It seems to be incorrect on stable, so I'll try to look at this ASAP so it can be fixed before the release.

John W. Eaton <jwe>
Group administrator
Thu 03 Sep 2020 12:55:48 AM UTC, comment #4: 

This now correctly throws an error so I'm going to close this report.  I do notice that the carat that indicates where the error has occurred seems to be unrelated to where the actual error occurs, but that's pretty minor.


octave:1> fend (1:10)
error: parse error near line 1 of file /home/rik/wip/Projects_Mine/octave-dev/fend.m

  invalid use of keyword 'end' in parameter list

>>> function y = fend (end)
                                      ^



Rik <rik5>
Group administrator
Fri 21 Aug 2020 12:38:25 PM UTC, comment #3: 
John W. Eaton <jwe>
Group administrator
Fri 14 Aug 2020 06:31:45 PM UTC, comment #2: 

Yes, in m-code one could just call


iskeyword (PARAMETER_NAME)


to verify the PARAMETER_NAME before continuing parsing.

The C function octave::iskeyword in lex.ll is available so I don't think it should be hard to add the check.

Rik <rik5>
Group administrator
Fri 14 Aug 2020 03:28:33 PM UTC, comment #1: 

Se we just need a check that keywords are not allowed as variables, including when they are used as function inputs or outputs, correct?  That should not be too difficult.

John W. Eaton <jwe>
Group administrator
Thu 13 Aug 2020 10:08:07 PM UTC, original submission:  

Keywords are reserved, and shouldn't be available for use as variable names.  This is the case for the keyword 'end' when used on the command line.  For example,


end = 1
error: parse error:

  syntax error

>>> end = 1
         ^


It might be nicer to have a more specific message then just "syntax error" in this case, but it still does prevent user's from re-assigning a keyword.

On the other hand, this function allows assigning to a keyword via the parameter name of a function.


function y = fend (end)
  disp (end(1:end));
end


For certain values of the input parameter, such as 1, this works.  In Matlab, there is an error on line 1, column 20 which is the start of the keyword "end".

This is a small priority so I've made the severity minor.

Also, 'end' was just an example.  One can alias any keyword such as 'for', 'while', etc.



Rik <rik5>
Group administrator

 

(Note: upload size limit is set to 16384 kB, after insertion of the required escape characters.)

Attach Files:
   
   
Comment:
   

No files currently attached

 

Depends on the following items: None found

Items that depend on this one: None found

 

Carbon-Copy List
  • -email is unavailable- added by jwe (Posted a comment)
  • -email is unavailable- added by rik5 (Submitted the item)
  •  

    There are 0 votes so far. Votes easily highlight which items people would like to see resolved in priority, independently of the priority of the item set by tracker managers.

    Only group members can vote.

     

    Follow 3 latest changes.

    Date Changed by Updated Field Previous Value => Replaced by
    2020-09-03 rik5 StatusReady For Test Fixed
        Open/ClosedOpen Closed
    2020-08-21 jwe StatusConfirmed Ready For Test

    Back to the top

    Powered by Savane 3.13-d3ae.
    Corresponding source code