Pattern 18Symbol Table for Data Aggregates

Purpose

This pattern tracks symbols and builds a scope tree for data aggregates such as C’s structs.

Discussion

To manage struct scopes, we’ll build a scope tree and define symbols just like we did in Pattern 17, Symbol Table for Nested Scopes. The only difference lies in symbol resolution. Member access expressions like a.b can see fields inside a struct.

In Building Scope Trees for Structs, we examined the scope tree for some sample Cymbol struct definitions. The goal of this pattern is to describe the rules and mechanism for building that scope tree and filling the nodes (scopes) with symbols. To get started, we need a new kind of scope tree node called StructSymbol to represent structs. Here’s ...

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.