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]
Return to the
comp.compilers page.
Search the
comp.compilers archives again.