[antlr-interest] How do I preserve comments in a language to language translator
Howard Nasgaard
nasgaard at ca.ibm.com
Wed Aug 11 13:13:01 PDT 2010
I am writing a translator that will convert from one version of a language
to a newer version of that language. The versions are syntactically
similar so their underlying ASTs are similar. I am using parsers for the
grammar and tree grammars generated as C++. The old language is parsed
and an AST is built. Then numerous walks of the AST are done using
generated tree grammars. One of the walks creates a new AST, the
translation, which conforms to the tree hierarchy that describes the new
language elements. A final walk of the new AST "pretty prints" the
translation.
As part of the translation walk, or whatever works, I would like to copy
as many of the comment tokens across to the new AST as possible. Based on
my reading, the comments are there as they are being directed to the
HIDDEN channel. It is just not clear how, in my tree grammar, I would
access them. I have been unable to find any descriptions of how to do
this that apply to antlr3 and C++.
Howard W. Nasgaard
More information about the antlr-interest
mailing list