Chapter 11Translating Computer Languages

So far, we’ve focused on reading in programs and other structured text in this book. Previously, we built input models (usually ASTs) of the input and then analyzed or even executed that input by scanning the model. In this next part of the book, we’re going to reverse the process and build text-to-text translators and generators that emit structured text. Translators let us implement new DSLs and programming languages quickly by translating them to existing languages. For example, the first C++ implementation (cfront) translated C++ to C. Translators are also heavily used for migrating legacy code and data formats.

A translator is a program that maps input constructs to output constructs. Sometimes ...

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.