Scopes and Symbol Tables
摘要
An important concept in programming languages is the ability to name items such as variables, functions and types. Each such named item will have a declaration, where the name is defined as a synonym for the item. This is called binding. Each name will also have a number of uses, where the name is used as a reference to the item to which it is bound. Often, the declaration of a name has a limited scope: a portion of the program where the name will be visible. Such declarations are called local declarations, whereas a declaration that makes the declared name visible in the entire program is called global. It may happen that the same name is declared in several nested scopes. In this case, it is normal that the declaration closest to a use of the name will be the one that defines that particular use. A compiler will need to keep track of names and the items these are bound to, so that any use of a name will be attributed correctly to its declaration. This is typically done using a symbol table.