Chapter 9: Intermediate Code Generation
After the semantic analysis is complete, you can contemplate how to execute the program. For compilers, the next step is to produce a sequence of machine-independent instructions called intermediate code. This is usually followed by an optimization phase and final code generation for a target machine. This chapter will show you how to generate intermediate code by looking at examples for the Jzero language. After several chapters where you learned how to write tree traversals that analyze and add information to the syntax tree constructed from the input, the exciting thing about this chapter is that the tree traversals in it begin the process of constructing the compiler's output.
This chapter covers the following main topics:
- Preparing to generate code
- Defining an intermediate code instruction set
- Generating code for expressions
- Generating code for control flow
It is time to start by gaining some perspective...