Collecting Information About Program Entities
To build a symbol table, we need to formalize what we do implicitly when we read and write software. First, let’s figure out how to represent program entities. Take a look at the following C++ code:
| class T { … }; // define class T |
| T f() { … } // define function f returning type T |
| int x; // define variable x of type int |
We unconsciously define three symbols (program entities) in our head: class T, function f, and variable x. To build a language application, we need to mimic this in software. For those definitions, we need to do something like the following:
| Type c = new ClassSymbol("T"); // define class |
| MethodSymbol m = new MethodSymbol("f", c); // define method |
| Type |
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.