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 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.