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 the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.