7
Checking Base Types
This is the first of two chapters about type checking. In most mainstream programming languages, type checking is a key aspect of semantic analysis that must be performed before you can generate code. Type checking uses the syntax trees from Chapter 5 and the symbol tables from Chapter 6.
This chapter will show you how to do simple type checks for the base types included in the Jzero subset of Java. A by-product of checking the types is adding type information to the syntax tree. Knowing the types of operands in the syntax tree enables you to generate correct instructions for various operations. For example, if your compiler sees the code x + y, should it generate code for integer addition? Floating-point addition? Something ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access