Type representation in the compiler
Frequently, our compiler will need to do things such as compare the types of two variables to see whether they are compatible. Program source code represents types with string data, which is incorporated in our syntax tree. In some languages, it might be possible to use little syntax subtrees to represent the types that are used in type checking, but in general, type information does not exactly correspond to a subtree within our syntax tree. This is because part of the type information is pulled in from elsewhere, such as another type. For this reason, we need a new data type just to represent the type information associated with any given value that is declared or computed in the program.
It would be nice if we could just represent types with a single atomic value such as an integer code or a string type name. For example, we could use 1 for an integer, 2 for a real number, or 3 for a string. If a language had only a small, fixed set of built...