8 Generating code from the AST
This chapter covers
- How the build system relates to the Domain IDE and the Runtime
- Why make a reference implementation of the Runtime first
- Implementing a code generator using templates
- Deriving templates iteratively from the reference implementation’s code
- Composing templates conveniently, with declarative indentation
In the previous chapters, we started working on a Domain IDE that will allow domain experts to capture their business knowledge in the form of DSL content. I said in chapter 1 that this DSL content should not just be “pretty pictures” or mere documentation, but should be precise enough to build software from (see figure 8.1). In this chapter, we’re going to do exactly that: generate a Runtime from DSL content written using the Domain IDE.
Figure 8.1 Using a DSL-based approach to develop a Runtime using a Domain IDE

Our example DSL and its content captures how to compute a rental price based on the data input by business stakeholders. The Runtime for this DSL content could be as simple as a web app that displays a form in which business stakeholders input data about a rental.
Figure 8.2 focuses on the Runtime, and on how its codebase is organized in general.
Figure 8.2 The organization of the Runtime’s codebase

The Runtime’s codebase can be divided into the following parts: