Article View: comp.std.c
Article #3475Re: Multi-level break and elimination of GOTO
From: Andrew Dunbar
Date: Mon, 13 Nov 1995 03:04
Date: Mon, 13 Nov 1995 03:04
82 lines
3252 bytes
3252 bytes
Greg Comeau (comeau@panix.com) wrote:
: In article <47s7l0$r18@news.mel.aone.net.au> andrewd@agnus.livewire.com.au (Andrew Dunbar) writes:
: >The only problem I can see is for do loops:
: >
: >do
: >{
: > while inner (exp1)
: > {
: > if (exp2)
: > break outer;
: > }
: >} while outer;
: >
:
: That's one issue. That wouldn't work anyway because you do not have
: an expression for the do/while. Which is part of the point of where
: things start collapsing with some proposals re things like this.
: Because now we can have:
:
: do .... while outer (expr);
:
Oops! That was a typo on my part. It should have been as you have suggested
above.
:
: while looks odder (IMO) that the for, but then so does:
: do outer.... while (expr);
This is syntactically ambiguous anyway as 'outer' is simply an identifier
it is a legal statement and the syntax of a do loop is:
do <statement> while (<expression>);
Although as there is no semicolon after the loop name it may be distinguishable
but I still doubt it. I might try it out with YACC soon.
:
: and any other permutations.
:
: Or to minimize impacts to the grammar, why not just leave as normal labels:
:
: outer: for(...) { ... }
:
Well that's the Java approach so I've heard, but I didn't really think of the
loop names as labels. This would cause confusion for humans and parsers/
optimizers with real goto labels.
: but that doesn't fly as well, so how about:
:
: for(...) { ... } outer:
:
: But that seems odd, and further, doesn't work in all cases w/o having
: to add a ; or something.
:
When I thought it up I had multi-level break specifically in mind so:
iteration-statement:
while <loop-name> ( <expression> ) <statement>
do <statement> while <loop-name> ( <expression> ) ;
for <loop-name> ( <expression>opt ; <expression>opt ;
<expression>opt ) <statement>
selection-statement:
switch <loop-name> ( <expression> ) <statement>
jump-statement:
break <loop-name> ;
would be the exact additions I would introduce into the grammar as
stated in 'The C Programming Language 2nd Edition'
(where 'loop-name' is simply a synonym for 'identifier')
: And while we are at it, why not add it to if statements, switches,
: (even return! <gasp>) and so on.
:
I can't see a use for named 'if' statements but there may be a case for it?
: The idea is probably nice, and there is prior art from other languages,
: however, the impact and tradeoffs get bigger and bigger the more you
: look at it within a C/C++ world.
:
Thanks for your views Greg
Andrew Dunbar
GPSoftware
Technical Details
Message-ID:
<486cj7$o4s@news.mel.aone.net.au>Path:
arc1-ca.pugleaf.net!news.mel.aone.net.au!not-for-mailReferences:
<43pdut$hoh@galaxy.csc.calpoly.edu> <DF8FE3.97H@news.cern.ch> <47s7l0$r18@news.mel.aone.net.au> <480ps3$nqj@panix.com>Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!news.mel.aone.net.au!not-for-mail From: andrewd@agnus.livewire.com.au (Andrew Dunbar) Newsgroups: comp.std.c,comp.lang.c Subject: Re: Multi-level break and elimination of GOTO Followup-To: comp.std.c,comp.lang.c Date: 13 Nov 1995 03:04:07 GMT Organization: Livewire Communications Message-ID: <486cj7$o4s@news.mel.aone.net.au> References: <43pdut$hoh@galaxy.csc.calpoly.edu> <DF8FE3.97H@news.cern.ch> <47s7l0$r18@news.mel.aone.net.au> <480ps3$nqj@panix.com> NNTP-Posting-Host: agnus.livewire.com.au X-Newsreader: TIN [UNIX 1.3 950515BETA PL0]