Rule-Based Translation
To build a translator, we have to define an input-to-output mapping (a set of “this goes to that” rules) no matter what translator architecture we use. Instead of coding them with a general-purpose programming language, we can use a translation DSL. There are a number of excellent rule-based systems available such as ASF+SDF,[40] Stratego/XT,[41] and TXL.[42] The ANTLR project also has a simple rule engine called ANTLRMorph.[43]
To use these engines, we feed them an input language grammar and a set of translation rules, as shown in the following image. From the grammar, the engine builds a parse tree from the input and then applies the rules to get the output. As we saw in Decoupling Tree Traversal from Pattern Matching ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access