Model-Driven Translation

In a model-driven translator, everything centers around an input model created by the parser. In its simplest form, a model-driven translator creates an AST input model and then walks it to generate output with print statements.[46] The only difference between this and a syntax-directed translator is that we generate text while walking a tree instead of while parsing a token stream.

The advantage of creating an AST first is that we can do semantic analysis before generating output. Most of the time, we’ll need to annotate the AST with symbol and type information before generating output. In Figure 31, Model-driven translator, we can see the overall architecture. From a software engineering point of view, it’s also nice ...

Get Language Implementation Patterns now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.