Establishing the groundwork for symbol tables
In software engineering, you must go through requirements analysis and design before you start coding. Similarly, to build symbol tables, you first need to understand what they are for and how to go about writing the syntax tree traversals that do the work. For starters, you should review what kinds of information your compiler must store and recall different kinds of variables. The information will be stored in symbol tables from declarations in the program code, so let’s look at those.
Declarations and scopes
The meaning of a computer program boils down to the meaning of the information being computed, and the actual computations to be performed. Symbol tables are all about the first part: defining what information the program is manipulating. We will begin by identifying what names are being used, what they are referring to, and how they are being used.
Consider a simple assignment statement such as the following...