Software Design by Example 15: Code Generator
Chapter 14 turned source code into a data structure in order to check that the code obeyed style rules. This chapter reverses the process by turning the data structure that represents source code back into text. This may seem like a pointless exercise, but in between the parsing and the unparsing we can modify the data structure in order to produce a program that’s slightly different from the one we started with. If we do this carefully, we can insert extra statements to check which functions are called when the program runs or to record how long their execution takes. Once more, treating programs as data allows us to do some pretty powerful things.
Terms defined: byte code, code coverage (in testing), compiler, Decorator pattern, macro, nested function, two hard problems in computer science.