From bug-octave-request at bevo dot che dot wisc dot edu Tue Nov 12 16:59:36 2002 Subject: Unidentified subject! From: "John W. Eaton" To: Pascal dot Dupuis at esat dot kuleuven dot ac dot be Cc: bug-octave at bevo dot che dot wisc dot edu Date: Tue, 12 Nov 2002 16:59:16 -0600 On 11-Sep-2002, Pascal dot Dupuis at esat dot kuleuven dot ac dot be wrote: | To: bug-octave at bevo dot che dot wisc dot edu | | Subject: parser error | | Bug report for Octave 2.1.36 configured for i686-pc-linux-gnu | | Description: | ----------- | | I have written a script to read data generated by an application. This | script mainly parse a header to get some scale constant, then read the | data. Now I rewrite it to detect abnormal conditions, mainly EOF while | reading file, so it goes essentially like this: | | [val, count] = fgets(file, 256); | if -1 == count, error('Empty file %s\n', name); end | | Once being a Perl hacker, I noticed this can be rewritten as | | [val, count] = fgets(file, 256); | -1 ~= count || error('Empty file %s\n', name); | | The first logical expression is evaluated, with the side effect of | determining is the second must be 'evaluated' (executed) or not. | | This doesn't work in the following case: | | if ~isempty(findstr(val, 'Waveforms')) | break; | end | | meaning we must exit the loop processing the header when we find a | line with the keyword "Waveforms". The following expression gives a | parser error: | | ~isempty(findstr(val, 'Waveforms')) && break; | | parse error near line xx of file yy | | >>> ~isempty(findstr(val, | | It can be objected that 'break', by itself, is not a logical | expression, but it can be evaluated. In the present case, is there | some reason while the parser hangs with this expression ? | | | Repeat-By: | --------- | | ~isempty(findstr(val, 'Waveforms')) && break; | | Fix: | --- | | The '~' should indicate that we associate a logical value to the whole | expression isempty(), so the part at the left of && is a valid logical | expression OK, I've made some changes (should be checked in to CVS soon) so that break, continue and return are now expressions instead of statements, so they can be used in some expression contexts. For example, you can do for i = 1:10, i, i == 3 && break; end or for i = 1:10, i, i == 3 && (x = break); end, x but not for i = 1:10, i, i == 3 && (x = break + 1); end, x In all cases, the value of break, continue, and return is logical TRUE. Should the use of these new "expressions" be available for use in any kind of expression (addition, subtraction, etc.) or be restricted even more (say, only in && and || expressions? jwe ------------------------------------------------------------- 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 -------------------------------------------------------------