Path: csiph.com!x330-a1.tempe.blueboxinc.net!newsfeed.hal-mli.net!feeder1.hal-mli.net!news.glorb.com!usenet.stanford.edu!news.iecc.com!nerds-end From: George Neuner Newsgroups: comp.compilers Subject: Re: How to handle qualified identifiers such as x.y in a Pascal-like language Date: Sat, 25 Jun 2011 17:11:48 -0400 Organization: A noiseless patient Spider Lines: 45 Sender: news@iecc.com Approved: comp.compilers@iecc.com Message-ID: <11-06-048@comp.compilers> References: <11-06-037@comp.compilers> <11-06-040@comp.compilers> <11-06-044@comp.compilers> NNTP-Posting-Host: news.iecc.com X-Trace: gal.iecc.com 1309370609 13632 64.57.183.58 (29 Jun 2011 18:03:29 GMT) X-Complaints-To: abuse@iecc.com NNTP-Posting-Date: Wed, 29 Jun 2011 18:03:29 +0000 (UTC) Keywords: symbols, storage Posted-Date: 29 Jun 2011 14:03:29 EDT X-submission-address: compilers@iecc.com X-moderator-address: compilers-request@iecc.com X-FAQ-and-archives: http://compilers.iecc.com Xref: x330-a1.tempe.blueboxinc.net comp.compilers:174 On Fri, 24 Jun 2011 13:58:23 +0200, "[Linux Magazine]" wrote: >In practice people do not write procedures in procedures that much, and >procedures in procedures in procedures are rare. Nested procedures and 1st class closures are very common in functional languages. C and its current popular variants don't permit them (though C++0x has added anonymous lambda) and so, IMO, too many programmers have no experience of their power. 1st class closures are more general and more powerful than most object systems - closures permit the construction of ad hoc objects that can bind arbitrary functions to arbitrary data without the need for class definitions or template objects. >This also means that you need efficient access to global variables and >variables local to the procedure currently being executed. Further the >access to variables declared in the directly surrounding scope should be >fairly efficient. This goes without saying. However, it's fairly easy to arrange fast access to nonlocals even in scopes several nest levels distant. As has been mentioned, display is the canon method. Displays, though, have a problem dealing with deep nesting ... which, admittedly is rare, but not unheard of. Typically, the compiler will allow only so many nesting levels and if you exceed that number, the compilation fails. Closure conversion - aka lambda lifting - is IMO a better method because it can handle any nesting depth. It takes a bit more analysis during compilation, but it is more flexible than a display. >The rest just needs to work. You will do fine with an implementation >where all procedures have direct access to its own variables and global >variables, and variables declared in surrounding procedures may be more >difficult to access. Yes ... asymmetric access is acceptable for an academic exercise, but not for a compiler that you would want others to use. I know the OP is a novice compiler developer, but let's advocate learning general solutions that will continue to work for more advanced projects in the future. George