Path: csiph.com!usenet.pasdenom.info!usenet.blueworldhosting.com!feeder01.blueworldhosting.com!border4.nntp.dca.giganews.com!border2.nntp.dca.giganews.com!border3.nntp.dca.giganews.com!border1.nntp.dca.giganews.com!nntp.giganews.com!news.iecc.com!.POSTED!nerds-end From: Louis Krupp Newsgroups: comp.compilers Subject: Re: Is multi-level function return possible? Date: Tue, 11 Mar 2014 15:16:46 -0600 Organization: Compilers Central Lines: 34 Sender: news@iecc.com Approved: comp.compilers@iecc.com Message-ID: <14-03-024@comp.compilers> References: <14-03-020@comp.compilers> NNTP-Posting-Host: news.iecc.com Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit X-Trace: miucha.iecc.com 1394679885 33244 64.57.183.58 (13 Mar 2014 03:04:45 GMT) X-Complaints-To: abuse@iecc.com NNTP-Posting-Date: Thu, 13 Mar 2014 03:04:45 +0000 (UTC) Keywords: code, C++ Posted-Date: 12 Mar 2014 23:04:45 EDT X-submission-address: compilers@iecc.com X-moderator-address: compilers-request@iecc.com X-FAQ-and-archives: http://compilers.iecc.com Xref: csiph.com comp.compilers:1146 On Mon, 10 Mar 2014 15:46:31 -0400, noitalmost wrote: >Is this a doable thing for a Pascal-like language that is meant to be >compiled? I have a multi-level break which works within a procedure, but the >return across procedure boundaries seems to add a lot of complications. > >I don't recall this being discussed in the dragon book, perhaps because it's >just a silly idea. But implementing the multi-level break got me curious >whether it's possible. >[Sure, you can do it. PL/I let you jump out of a routine and I think Algol60 >may have, too. You just need to keep your stack frames sufficiently linked >so that you can find the one you want and unwind everything below it. Look >at the way Algol and Pascal reference variables in blocks outside the current >routine and you'll get most of what you need. -John] What you're looking for sounds similar to the setjmp/longjmp feature in C and exception handling in C++. If you're going to attract C++ users to your language, the try/catch block would be a good thing to imitate. Unisys ALGOL has a TRY statement; see http://public.support.unisys.com/aseries/docs/clearpath-mcp-15.0/pdf/86000098-511.pdf for details. I believe that exception handling as it's usually implemented is driven by the calling routine, while it sounds like what you want is for a nested procedure to return from an outer procedure. Unisys ALGOL does at least some of this with a "bad" GO TO statement, which branches out of one or more blocks. If an outer procedure END statement has a label, and if you branch to it from within a contained procedure, you've accomplished your multi-level return. Louis