[antlr-interest] Creating an AST from a Parsers output
Eric Crahen
eric.crahen.lists at gmail.com
Fri Aug 10 11:09:25 PDT 2007
I'd like to create an AST representation of a Java source file, not the
grammar for the language, a source file. I can't seem to find any way to
actually convert the output of a Lexer or Parser into a Tree. One of the
classes in the tree package, DOTTreeGenerator seems like it might have been
a step in this direction, but the Lexer and Parser classes generated with
ANTRL 3.0 don't have the e() method.
/** A utility class to generate DOT diagrams (graphviz) from
* arbitrary trees. You can pass in your own templates and
* can pass in any kind of tree or use Tree interface method.
* I wanted this separator so that you don't have to include
* ST just to use the org.antlr.runtime.tree.* package.
* This is a set of non-static methods so you can subclass
* to override. For example, here is an invocation:
*
* CharStream input = new ANTLRInputStream(System.in);
* TLexer lex = new TLexer(input);
* CommonTokenStream tokens = new CommonTokenStream(lex);
* TParser parser = new TParser(tokens);
* TParser.e_return r = parser.e();
* Tree t = (Tree)r.tree;
* System.out.println(t.toStringTree());
* DOTTreeGenerator gen = new DOTTreeGenerator();
* StringTemplate st = gen.toDOT(t);
* System.out.println(st);
*/
Is there any way to accomplish this with ANTLR?
--
- Eric
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.antlr.org/pipermail/antlr-interest/attachments/20070810/0620015f/attachment.html
More information about the antlr-interest
mailing list