From bug-request at octave dot org Wed Feb 2 15:59:31 2005 Subject: Should be able to say 'for (k=1:N)' From: "John W. Eaton" To: Julius Smith Cc: bug at octave dot org Date: Wed, 2 Feb 2005 15:57:21 -0600 On 2-Feb-2005, Julius Smith wrote: | The octave session below illustrates a small parser inconsistency (see | fourth command line) that tends to bite C programmers. :-) | | > octave | GNU Octave, version 2.1.64 (i686-pc-linux-gnu). | ... | | octave:1> 1:4 | ans = | | 1 2 3 4 | | octave:2> (1:4) | ans = | | 1 2 3 4 | | octave:3> (k=1:4) | k = | | 1 2 3 4 | | octave:4> for (k=1:4), k, end | parse error: | | syntax error | | >>> for (k=1:4), k, end | ^ | | octave:4> for k=1:4, k, end | k = 1 | k = 2 | k = 3 | k = 4 | octave:5> Please try the following patch. Thanks, jwe src/ChangeLog: 2005-02-02 John W. Eaton * Makefile.in (parse.cc): Expect 12 shift/reduce conflicts. * parse.y (loop_command): Allow "for (k=1:10) ... endfor". Index: src/Makefile.in =================================================================== RCS file: /usr/local/cvsroot/octave/src/Makefile.in,v retrieving revision 1.356 diff -u -r1.356 Makefile.in --- src/Makefile.in 21 Jan 2005 03:32:09 -0000 1.356 +++ src/Makefile.in 2 Feb 2005 21:57:42 -0000 at @ -513,7 +513,7 @@ at $(top_srcdir)/move-if-change $@-t $@ parse.cc : parse.y - at echo "expect 11 shift/reduce conflicts" + at echo "expect 12 shift/reduce conflicts" $(YACC) $(YFLAGS) $< at $(top_srcdir)/move-if-change y.tab.c $(@F) Index: src/parse.y =================================================================== RCS file: /usr/local/cvsroot/octave/src/parse.y,v retrieving revision 1.225 diff -u -r1.225 parse.y --- src/parse.y 28 Dec 2004 01:59:05 -0000 1.225 +++ src/parse.y 2 Feb 2005 21:57:42 -0000 at @ -1068,6 +1068,11 @@ if (! ($$ = make_for_command ($1, $3, $5, $7, $8, $2))) ABORT_PARSE; } + | FOR stash_comment '(' assign_lhs '=' expression ')' opt_sep opt_list END + { + if (! ($$ = make_for_command ($1, $4, $6, $9, $10, $2))) + ABORT_PARSE; + } ; // ======= ------------------------------------------------------------- Octave is freely available under the terms of the GNU GPL. Octave's home on the web: http://www.octave.org How to fund new projects: http://www.octave.org/funding.html Subscription information: http://www.octave.org/archive.html -------------------------------------------------------------