Building Scope Trees for Classes

Classes are like structs in that they can inherit members from another class (the superclass). That means classes have two parent scopes: the usual enclosing scope (physical location) and a superclass scope. To resolve symbols, sometimes we’ll chase the enclosing scope pointer, and sometimes we’ll chase the superclass pointer. Let’s start by looking at the scope tree for the following Cymbol code (see Figure 17, Scope tree for classes A and B).

images/symtab/class-symtab.png
Figure 16. Scope tree for classes A and B
symtab/class/AB.cymbol
​ 
// start of global scope //
​ 
class A {
 
public:
 
int​ x;
​ 
void​ foo()
​ 
{ ; }
 
}; ...

Get Language Implementation Patterns now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.