[antlr-interest] LIP pg. 285 11.4 Rewriter. How do you do it with ANLTR 3?

The Researcher researcher0x00 at gmail.com
Wed Mar 16 11:20:32 PDT 2011


In "Language Implementation Patterns" on page 285, Figure 11.4 Model-Driven
Translator With Tree Rewriting,
the picture shows a Rewriter.

The rewriter takes in an IR, alters IR structure then outputs an IR.

The only mention in the book is "The role of tree rewriting in translator
design is a pretty big topic and too much to go into here."

I have no doubt that it is a pretty big topic if one tries to rewrite the
processing logic of a language, however I am only working on the data
structures which should be a lot simpler.

For those who have seen my earlier questions, I have set aside trying to get
ANTLR 3 to read a data structure directly and am now creating a DSL to read
data structure definitions. In other words I am not abusing predicates this
round and using ANTLR as intended.

What I am hoping can be done, but have little hope, is that one can define a
grammar that takes in an AST, alters the AST with ANTLR rewrite rules, and
outputs an AST.

So how is a rewrite implemented with ANTLR3? Can you provide a reference to
an example.

Thanks Eric


More information about the antlr-interest mailing list