Re: How is the concept of scope implemented?

"Tony" <tony@my.net>
Tue, 18 Nov 2008 15:52:21 -0600

          From comp.compilers

Related articles
How is the concept of scope implemented? tony@my.net (Tony) (2008-11-14)
Re: How is the concept of scope implemented? bear@sonic.net (Ray Dillinger) (2008-11-14)
Re: How is the concept of scope implemented? m.helvensteijn@gmail.com (2008-11-14)
Re: How is the concept of scope implemented? tony@my.net (Tony) (2008-11-14)
Re: How is the concept of scope implemented? liangkun1983@gmail.com (Alex L.K) (2008-11-15)
Re: How is the concept of scope implemented? lkrupp@pssw.com (Louis Krupp) (2008-11-15)
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? 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)
[3 later articles]
| List of all articles for this month |

From: "Tony" <tony@my.net>
Newsgroups: comp.compilers
Date: Tue, 18 Nov 2008 15:52:21 -0600
Organization: at&t http://my.att.net/
References: 08-11-054 08-11-059
Keywords: symbols
Posted-Date: 18 Nov 2008 19:18:34 EST

> On Nov 14, 3:40 pm, "Tony" <t...@my.net> wrote:
>> In C++, there is many kinds of scope: global, translation unit, function,


"Alex L.K" <liangkun1983@gmail.com> wrote in message
> Basically, you can implement it with a tree. Each node in this tree
> corresponds to a scope and contains the declarations in this scope.
> When you search for a declaration, you begin with current node in the
> tree, if you do not find it, you continue in the parent and so on.
> In practice, nobody would like accturally maintain this tree, they use
> a stack to keep a path from the root to current node of this tree.


How does a compiler keep track of which scope it is currently under?
Naively, I could think that it maintains something like a trace call stack
noting the hierarchial scope level, but that seems too processor intensive
to do at each scope entry/exit.


Tony
[This topic is covered well in texts like the old Dragon Book. In the
object code you don't usually need to know what scope you're in, because
the compiler can figure out what names correspond to what variables.
If you have variable sized arrays and scope across routine boundaries,
i.e., code in a routine can see non-static data outside the routine, it
gets somewhat hairier. But this was all figured out in the early 1960s
for Algol60. -John]











Post a followup to this message

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