[SOLUTION] Re: [antlr-interest] Again: Source code position
Matthias Kempka
lists at mkempka.de
Tue Dec 6 02:07:26 PST 2005
Matthias Kempka wrote:
>Hello all,
>
>I'm aware that I'm not the first one to ask this question, but neither
>the FAQ nor the mailing list archive give me answers that I can work
>with, so here's my problem:
>
>I'm working with ANTLR 2.7.5 and the Java 1.5 Grammar by Michael Studmann.
>What I need is the source code position of an element in the AST.
>
>I see that the tokens that are created by the lexer have exactly the
>information I need. So I subclassed the CommonAST with a class named
>TokenPreservingAST. In the section Tokens{} in the Grammar I added the
>information which tokens should be represented by a TokenPreservingAST
>object.
>
>
When I don't care about the Tokens{} in the grammar, but call
myParser.setASTNodeClass(TokenPreservingAST.class.getName());
before calling myParser.compilationUnit(), the ASTs are initialized correct.
Maybe, this is a thing for the FAQ.
Regards,
Matthias Kempka
More information about the antlr-interest
mailing list