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