Pattern 30Rule-Based Translator

Purpose

A rule-based translator expresses a translation with a set of “x becomes y” rules, written in the DSL of a pattern-matching engine.

Discussion

To use a rule-based system, we have to feed it two things: a grammar that describes input sentences and a set of translation rules. The reason we need the grammar is to get a Pattern 8, Parse Tree. The parse tree concretely defines what the various phrases and subphrases are. That’s how they can avoid applying transformations inside comments in the input stream, for example. Although it looks like we’re doing text-to-text transformations, the underlying engine is actually doing tree rewrites.

For complicated translators, we need to build a lot of ancillary data ...

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.