Building Retargetable Translators

If we can easily make a translator generate different output, we say that it’s retargetable. As we mentioned in Using a Tree Grammar to Create Templates, altering or swapping in new templates is one way to do this. The template hierarchy stays the same, just the contents of those templates change. This retargeting approach is really useful if you need to generate different SQL to suit different database vendors, for example. (Alas, we often do.)

In this section, we’re going to learn another retargeting strategy that changes the output language by changing the template hierarchy. The interesting thing is that we assemble different hierarchies using the templates themselves, not using Java code. As before, all ...

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.