chapter nine

9 Checking the AST

 

This chapter covers:

  • Determining the various ways the build system, and Runtime can produces faults
  • Dealing with such faults as if they had been encountered and reported by domain experts
  • Adding constraints to the DSL so that issues are reported to domain experts that warm them about faults
  • Strengthening the generator to be able to deal with certain faults

In the previous chapter 8, we implemented a code generator that generated code from an AST representing DSL content that was produced using the Domain IDE. That generator, and the generated code, worked for the AST of the example DSL content, and probably also for a lot of other DSL content. However, some ASTs could cause the generator to produce code that can’t be built, crashes, or runs incorrectly. The generator itself can even crash on a particular AST - for example, when the generator expects some property to have a setting, when it doesn’t.

Figure 9.1. Faulty situations that may occur in a DSL-based software development approach, and how to prevent them.
fault modes

In this chapter, we’re going to learn how to deal with such faulty situations. Phrased positively: we’re going to find out how we can avoid ending up in a situation where things are blowing up in the first place. Sometimes, we’ll do that by adapting, or “strengthening”, the generator so that any “explosion” that does happen, causes much less “damage”. Most of the time, we’ll impose constraints on the AST representing the DSL content.

9.1 Preventing faults by adding constraints

9.2 A template case: dealing with an attribute without a name

9.3.1 An attribute without a type

9.3.2 An attribute with an initial value “with holes”

9.3.3 Related attributes with unequal types

9.3.4 Sorting attributes according to dependency order

9.3.5 Detecting cycles of attributes

9.3.6 Attributes with similar names

9.4 Summary