Re: How is the concept of scope implemented?

"Tony" <tony@my.net>
Wed, 19 Nov 2008 23:10:25 -0600

          From comp.compilers

Related articles
[7 earlier articles]
Re: How is the concept of scope implemented? tony@my.net (Tony) (2008-11-18)
Re: How is the concept of scope implemented? tony@my.net (Tony) (2008-11-18)
Re: How is the concept of scope implemented? kamalpr@hp.com (kamal) (2008-11-18)
Re: How is the concept of scope implemented? DrDiettrich1@aol.com (Hans-Peter Diettrich) (2008-11-19)
Re: How is the concept of scope implemented? yangjunpro@gmail.com (yangjunpro: Target locked-->Ruby++) (2008-11-18)
Re: How is the concept of scope implemented? j.vimal@gmail.com (Vimal) (2008-11-19)
Re: How is the concept of scope implemented? tony@my.net (Tony) (2008-11-19)
Re: How is the concept of scope implemented? tony@my.net (Tony) (2008-11-19)
Re: How is the concept of scope implemented? tony@my.net (Tony) (2008-11-19)
Re: How is the concept of scope implemented? lkrupp@pssw.com (Louis Krupp) (2008-11-21)
| List of all articles for this month |

From: "Tony" <tony@my.net>
Newsgroups: comp.compilers
Date: Wed, 19 Nov 2008 23:10:25 -0600
Organization: at&t http://my.att.net/
References: 08-11-054 08-11-062 08-11-089 08-11-095
Keywords: storage, symbols
Posted-Date: 20 Nov 2008 17:46:53 EST

"Hans-Peter Diettrich" <DrDiettrich1@aol.com> wrote in message
> Tony schrieb:
>
>> I like the multiple table method, or some kind of
>> hierarchial/multi-data-structure thing. It seems to me though that
>> keeping track of the current scope can be a potential source of
>> inefficiency. For example:
> [...]
>> Compiler generates :
>>
>> void my_func()
>> {
>> EnterScope(my_func); // compiler generates
>>
>> // func code
>>
>> LeaveScope(my_func); // compiler generates
>> }
>
> I can't see anything inefficient here. When a scope requires allocation
> of memory, on the stack or somewhere else, it doesn't matter whether
> that memory is allocated and released by the coder or by the compiler.
> In C++, Delphi etc. the compiler inserts the construction and
> destruction of local objects, at the begin and end of every scope block.


I'm still not used to that concept: inserting stuff at the entry and exit of
every function, because to me (as a higher level developer), "a function
call is expensive" rings in my ear. I have a tracer class that I use during
development that maintains a call stack list, but I turn it off for
"release" code.


Obviously I'm missing the common knowlege on the subject, but I do
appreciate the responses because I am learning things. My texts on the
subject matter haven't arrived yet, but I have them on order to help me to
decide whether or not to pursue implementing (not designing, I know WHAT I
want) a new (not just "another"?) language.


>
> Perhaps you missed that the scopes (as symbol tables) are required only
> during compilation, not at runtime.


Definitely "missed" that. As a developer, of course I know what scope is,
but now I'm trying to get my mind around how that is implemented, and now
you just taught me WHEN it applies.


> Typical object files only contain
> one symbol table, for use by the linker. More detailed debug information
> may be created, too, but only for use by an interpreter or debugger.


To me, (take with a lot of salt), it seems that at some level, MULTIPLE
symbol tables would be appropriate: at the "module" level, for example.


I'm "way out of the league" as far as compiler implementation goes, so I
apologize to everyone in advance for asking "dumb" questions. All of this
info and my ponderings will surely help me in reading what has been
described, mildly, as "hard to approach" tomes (e.g., "The Dragon Book").


Tony



Post a followup to this message

Return to the comp.compilers page.
Search the comp.compilers archives again.