Chapter 8Enforcing Static Typing Rules

We derive the meaning of a sentence from both its structure (syntax) and the particular vocabulary symbols it uses. The structure says what to do, and the symbols say what to do it to. For example, in phrase print x, the syntax says to print a value, and the symbol x says which value to print. Sometimes, though, we write code that make no sense even if the syntax is correct. Such programs violate a language’s semantic rules.

Languages typically have lots and lots of semantic rules. Some rules are run-time constraints (dynamic semantics), and some are compile-time constraints (static semantics). Dynamic semantic rules enforce things like “no division by zero” and “no array index out of bounds.” Depending ...

Get Language Implementation Patterns now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.