Label: faq_trees

Content with label faq_trees in ANTLR 3 (See content from all spaces)
Related Labels: faq_lexing, faq_treeparsing

Page: Can you explain ANTLR's tree construction facilities?
Introduction ANTLR v3 has moved away from using the ANTLR v2 child-sibling trees for the common tree implementation. Instead, ANTLR v3 uses a simple list-of-children approach by default. To avoid lock…
Other labels: faq_treeparsing
Page: How can I build a different AST node type for each token type?
This is the same as asking "how do I build heterogeneous trees?" At the moment, the answer is simply to override create(Token) in a TreeAdaptor such as CommonTreeAdaptor and then create different node…
Page: How can I build parse trees not ASTs?
It's simple. Using the debug event interface, the predefined ParseTreeBuilder class listens for debug events and build a parse tree. Just turn on -debug commandline option and then pass in the ParseTr…
Page: How do I display ASTs graphically
Instead of using t.toStringTree(), you can ask ANTLR to generate DOT/graphviz format: DOTTreeGenerator gen = new DOTTreeGenerator(); StringTemplate st = gen.toDOT(t); System.out.println(st); To displa…
Page: How do I track whitespace, comments, and other hidden channels during AST construction?
David Holroyd wrote: ANTLR 2 provides CommonHiddenStreamToken et al, which I try to use for layout-preserving code rewriting. I've just been looking at v3 to see if manipulating ASTs containing hidden…
Other labels: faq_lexing
Page: Why do I get a ClassCastException when parsing a tree?
If you get: Exception in thread "main" java.lang.ClassCastException: org.antlr.runtime.tree.CommonTree cannot be cast to MyCustomASTNode It's probably because you forgot to set a custom tree adaptor i…
Other labels: faq_treeparsing