Symbol Tables
To understand the uses of names in program source code, your compiler must figure out what each use of a name refers to. If the program is reading from or writing to a variable, which variable is it? A local variable? A global variable? Or maybe a class member? You can look up symbols at each location they are used by using table data structures that are auxiliary to the syntax tree, called symbol tables. Performing operations to construct and then use symbol tables is the first step of semantic analysis. Semantic analysis is where the compiler studies the meaning of the input source code. Chapter 7 and Chapter 8 will build on this chapter and round out our discussion of semantic analysis.
Context-free grammars, explored in the preceding two chapters of this book, have terminal symbols and non-terminal symbols, and those are represented in tree nodes and token structures. When talking about a program’s source code and its semantics, the word symbol is used...