Errata for Domain-Specific Languages

As with any book, I make mistakes. This page lists the currently known errors in the book. If you spot something that I don't have here, please let me know.

Errors in 2nd and later printings

Page 122 §8.1: In figure 8.1 I have the event labels the wrong way around. The event on the transition from on to off should read switchDown. (I blame growing up in the UK and now living in the US.)

Errors in the 1st printing

Page 9 §1.2: In the code for the state machine class, I don't show the declaration of the getter for the start state: public State getStart() {return start;} [Corrected in the 2nd printing]

Page 20 §1.5: In both diagrams I use "eligable" when I should use "eligible". [Corrected in the 2nd printing]

Page 27 §2.1: Second bullet point. "the way they can by composed" should read "the way they can be composed" [Corrected in the 2nd printing]

Page 32 §2.1.2: In the first reference the example I'm referring to is in section 1.3, page 12 [Corrected in the 2nd printing]

Page 61 §3.6.3: In the first paragraph of the section "using too different mechanisms" should read "using two different mechanisms" [Corrected in the 2nd printing]

Page 73 §4.3: In the third paragraph on the page "Consider the calls to diskSize" should read "Consider the calls to size" [Corrected in the 2nd printing]

Page 98 §5.3.4: In the last but one paragraph "It similarly recognizes the second line of input" should read "It similarly recognizes the third line of input" [Corrected in the 2nd printing]

Page 119 §7.1.3: In Figure 7.3 the arrowheads for both of the transitions between the collecting and paid states should be reversed. [Corrected in the 2nd printing]

Page 122 §8.1: In figure 8.1 I have the event labels the wrong way around. The event on the transition from on to off should read switchDown. (I blame growing up in the UK and now living in the US.)

Page 131 §9.2: 5th para. "from the active state to the waiting-for-light state" should read "from the active state to the waiting-for-drawer state". The diagram should say "drawer" instead of "draw" too. [Corrected in the 2nd printing]

Page 140 §9.5: Fourth para in section. "MetaEdit from from MetaCase" should read "MetaEdit from from MetaCase" [Corrected in the 2nd printing]

Page 143 §9.7: Last paragraph: "they are worth experimenting experimenting with" only needs one "experimenting". [Corrected in the 2nd printing]

Page 152 §10.4: In the last paragraph of the section, "constraints of a syntax tree usually help more than they hinder" should read "constraints of a syntax tree usually hinder more than they help" [Corrected in the 2nd printing]

Page 205 §17.3.1: In the UML diagram, the multiplicity from Location Specification to Hotel is *:1 but should be *:*. [Corrected in the 2nd printing]

Page 206 §17.3.1: The text mentions the Offer class, but the code was missed out. Here is the code.

class Offer...
    public int Score(Activity a) {
      return Location.IsSatisfiedBy(a) && Activity.isSatisfiedBy(a) 
          ? Reward.Score(a) : 0;
    }
    public Reward Reward { get; set; }
    public LocationSpecification Location { get; set; }
    public ActivitySpecification Activity { get; set; }
[Corrected in the 2nd printing]

Page 215 §17.4: Second to last para on page "the primeState method" should read "the primeMachine method". IntelliJ's rename refactoring is good, but not that good. [Corrected in the 2nd printing]

Page 221 §18.1.1: In the first block, the token definitions should be capitalized, so the block should read:

Event-keyword: 'events';
Command-keyword: 'commands';
End-keyword: 'end';
Identifier: [a-zA-Z0-9]*;
[Corrected in the 2nd printing]

Page 221 §18.1.1: First code fragment. The line identifier: [a-z A-Z 0-9]*; should read identifier: [a-zA-Z0-9]*; (removed spaces in character class). [Corrected in the 2nd printing]

Page 222 §18.1.1: Code line towards bottom of page. code: [A-Z 0-9]{4} should read code: [A-Z0-9]{4} (removed spaces in character class). [Corrected in the 2nd printing]

Page 226 §18.1.2: First paragraph on page. "tend to refer to the parser as the activity" should read "tend to refer to "parse" as the activity" [Corrected in the 2nd printing]

Page 228 §29.1.1: In the last paragraph "%prec UNMINUS" should read "%prec UMINUS" [Corrected in the 2nd printing]

Page 264 §22.3: 3rd line of first paragraph. "the resulting action value" should read "the resulting match value". [Corrected in the 2nd printing]

Page 267 §22.3: 3rd code segment. eventDecList: eventDec+ should read eventDecList: eventDec* [Corrected in the 2nd printing]

Page 268 §22.3: 2nd code segment. eventDec: identifier identifier should read eventDec: IDENTIFIER IDENTIFIER to be consistent with earlier statement of rule. [Corrected in the 2nd printing]

Page 276 §23.3.3: Last para on page, "add it into the grammar as a loader" should read "add it into the grammar as a helper" [Corrected in the 2nd printing]

Page 279 §23.3.4: Top of page 279 "I no longer need to override reportErrors" should read "I no longer need to override reportErrors" [Corrected in the 2nd printing]

Page 301 §25.3: Just after the first code block the line "The top level of the grammar defines the state machine file." should read "The top level of the grammar defines the state machine file." [Corrected in the 2nd printing]

Page 303 §25.3: The last code segment at the bottom of the page addResetEvent is unnecessarily repeated from just earlier. [Corrected in the 2nd printing]

Page 306 §26.3: Fourth paragraph in section: "that wraps the ANTLR grammar file" should read "that wraps the ANTLR generated parser" [Corrected in the 2nd printing]

Page 307 §26.3:

The code sample for the rest of the calculator is missing the clause for mult_exp:

  mult_exp returns [double result]	
  	: a=power_exp {$result = $a.result;}
   	  ( '*' b = power_exp {$result *= $b.result;}
   	  | '/' b = power_exp {$result /= $b.result;}
   	  )*
   	;
      
[Corrected in the 2nd printing]

Page 322 §28.1.2: Last paragraph on page "Flex, the GNU version of lex" should read "Flex, the open source version of lex". Since Flex usually comes with Bison, and Bison is a GNU project, I fell into the common trap of assuming Flex was GNU too. [Corrected in the 2nd printing]

Page 353 §33.3: Last paragraph of page. "create a value for collecting" should read "create a child builder for collecting" [Corrected in the 2nd printing]

Page 358 §34.1: 3rd paragraph. "A parent function can define exactly the arguments required in the child functions" should read "A parent function can define exactly the arguments required using child functions" [Corrected in the 2nd printing]

Page 374 §35.1: Third code fragment, private HardDrive speed (int arg) { should read public HardDrive speed (int arg) { so it can be used properly [Corrected in the 2nd printing]

Page 382 §35.4: Third code fragment private HardDriveBuilder SATA { should read public HardDriveBuilder SATA { [Corrected in the 2nd printing]

Page 387 §36.3.2: The last four lines of the DSL script are not described nor used in the example and thus should be removed. [Corrected in the 2nd printing]

Page 387 §36.3: The last four lines of the DSL script are not described nor used in the example and thus should be removed. [Corrected in the 2nd printing]

Page 392 §36.4: The last five lines of the DSL script are not described nor used in the example and thus should be removed. [Corrected in the 2nd printing]

Page 411 §38.6: Second paragraph of section. "doesn't necessarily fit will" should read "doesn't necessarily fit well" [Corrected in the 2nd printing]

Page 420 §40.1: Second line on page. The code processor("cores", 2, "type" "i386") is missing a comma between the last two arguments. [Corrected in the 2nd printing]

Page 431 §41.3.1: After the paragraph starting "promotions are a set of rules", the code class Itinerary should read class Promotion [Corrected in the 2nd printing]

Page 432 §41.3.1: After the top paragraph (starting "The approach here"), the code class Itinerary should read class Promotion [Corrected in the 2nd printing]

Page 434 §41.3.2: The paragraph that ends "creates the appropriate rules" should read "populates the appropriate rules". [Corrected in the 2nd printing]

Page 434 §41.3.2: The code example doesn't give the content of the add_condition method, which is defined on the PromotionBuilder class. The body of this method reads: @rules.last.add_condition arg. [Corrected in the 2nd printing]

Page 436 §41.4.2: In various places in this section the class ConditionAtributeNameBuilder is missing a 't' and should read ConditionAttributeNameBuilder [Corrected in the 2nd printing]

Page 436 §41.4.2: In the paragraph starting "To build the condition" the phrase "has three parts: name, operator, and condition" should read "has three parts: name, operator, and value" [Corrected in the 2nd printing]

Page 437 §41.4.2: The line of code attr_reader :condition_class is dead code and should be removed. [Corrected in the 2nd printing]

Page 448 §42.1.2: First sentance of last paragraph, "Processing can occur in multiple places with multiple definitions of the processing." should read Processing can occur in multiple places without multiple definitions of the processing. [Corrected in the 2nd printing]

Page 451 §42.4: In the first code fragment Domain Object should read DomainObject (no space). [Corrected in the 2nd printing]

Page 451 §42.3: In the code sample, class ValidRangeFieldValidator should read class ValidRangeFieldValidator implements FieldValidator to clarify the implementation relationship. [Corrected in the 2nd printing]

Page 468 §44.1: Fourth para in section. "put code in the constructor to populate the fields" should read "put code in an initializer method to populate the fields". The constructor is a valid initialization method for this approach, but you can use other ways too - as I do in the following example [Corrected in the 2nd printing]

Page 479 §45.3: In third text paragraph the code builder_has_rule? should read builder.has_rule? (dot replaces underscore). [Corrected in the 2nd printing]

Page 499 §48.3: First code sample on page (content field and constructor) is part of the class ConditionBlock [Corrected in the 2nd printing]

Page 500 §48.3: Second code sample on page (the Matches method) is part of the class ConditionBlock [Corrected in the 2nd printing]

Page 510 §49.3.1: Last but one line "particularly to the kittens" should read "particularly to the hamsters" (No kittens were harmed during the production of this book.) [Corrected in the 2nd printing]

Page 519 §50.3.1: Last line in paragraph. engine.Run(john) should read engine.Run(tim) [Corrected in the 2nd printing]

Page 519 §50.3.2: The code for the ValidationRuleBuilder is missing. It should read:

  class ValidationRuleBuilder : WithParser {
    readonly string description;
    readonly ValidationEngine engine;
    public ValidationRuleBuilder(string description, ValidationEngine engine) {
      this.description = description;
      this.engine = engine;
    }
    public void With(Predicate<Person> condition) {
      engine.AddRule(condition, description);
    }
  }

 
[Corrected in the 2nd printing]

Page 523 §50.4: On the first line "Productive Solider" should read "Productive Soldier" [Corrected in the 2nd printing]

Page 528 §51.1: In Figure 51.1 the arrowheads for both of the transitions between the collecting and paid states should be reversed. [Corrected in the 2nd printing]

Page 540 §53.1: Second paragraph on page: "The template is is the source text" should read "The template is is the source text" [Corrected in the 2nd printing]

Page 554:

This page is blank, but should contain the following text:

"(For) instance, suppose the HTML designer wants to add a style class to the link output; if the Embedment Helper generates that link, then the designer has to coordinate with a programmer to make that change. Of course, this is only a problem if you have different people working on the different files; when generating code for a DSL, this is usually not the case."

[Corrected in the 2nd printing]

Page 556 §55.1: Last para of section, second to last sentence: "with running the code-generation process" should read "without running the code-generation process" [Corrected in the 2nd printing]

Page 558 §55.3: 9 lines from bottom. "I declare the state machine and the controller as static variables" should read "I declare the state machine and the controller as static global variables" [Corrected in the 2nd printing]

Page 566 §55.4: Just after first code fragment. "calls the static declare functions" should read "calls the static declare functions" [Corrected in the 2nd printing]

Page 580: The paper entitled "On Designing Safe and Embedded DSLs with Java 5" should be entitled "On Designing Safe and Flexible Embedded DSLs with Java 5" [Corrected in the 2nd printing]


Many thanks to Ayumi Otomo, Naoki Sakamoto, Yasushi Ohtsuka, Akira Hirasawa, Ahmad Hindi, Yuzuru Takahashi, Nicholas Radcliffe and others I've forgotten for spotting and telling me about these errors