[antlr-interest] Re: output code generation in c++
jsamort at gmail.com
Tue Aug 1 07:33:45 PDT 2006
dotnet fr wrote:
> In the antlr steps :
> -create the grammar file (parse the file and generate AST)
> -generate code in c++.
> Now I want to use my AST to generate ouput code (for example .hpp, cpp)
> Is it available in Antlr 2.7.6 ? Is it possible ?
This is slightly different. If I understand you correctly, you are
attempting to convert some language construct to C++? Certainly it is
possible, but not in any automatic way. Your options would be to: (1)
create a TreeWalker and output your C++ code to stream or file from
within the various nodes; or (2) take the AST generated by your grammar
and manually walk it, outputting in a similar way to 1.
Of course, this option does not require that your actual
lexer/parser/treewalker be C++ code. You could set ANTLR to use a C#,
Java or Python target, and then make use of the StringTemplate code
Here are a couple of links to discussion for and against using a manual
approach versus StringTemplate:
More information about the antlr-interest