Building Scope Trees for Structs

struct scopes behave just like local scopes from a scope tree construction point of view. They are just another node in the scope tree. That means we’ll have StructSymbol nodes as well as LocalScope, MethodSymbol, and GlobalScope nodes. The scope tree for the following sample program appears in Figure 16, Scope tree for nested data aggregates:

symtab/aggr/t.cymbol
​ 
// start of global scope //
​ 
struct​ A {
 
int​ x;
​ 
struct​ B { ​int​ y; };
 
B b;
​ 
struct​ C { ​int​ z; };
 
C c;
 
};
 
A a;
 
​ 
void​ f()
​ 
{
​ 
struct​ D {
 
int​ i;
 
};
 
D d;
 
d.i = a.b.y;
 
}
images/symtab/aggr-symtab.png
Figure 15. Scope ...

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.