[antlr-interest] ParseTree::getLine problem

Thomas Brandon tbrandonau at gmail.com
Thu Aug 28 06:35:50 PDT 2008


On Thu, Aug 28, 2008 at 11:11 PM, Peter Bulychev
<peter.bulychev at gmail.com> wrote:
> Hello.
>
> I have a parse tree and I want to know, in which lines of parsed file do
> nodes of this tree reside.
>
> ParseTree class itself doesn't have getLine function, but its parent
> (BaseTree class) does have.
> Unfortunately its getLine function seems to be constantly zero:   "public
> int getLine() {\n return 0;\n}"
>
> Did I do something wrong and what workaround can be invented?
You can access the original token via the payload object (for the leaf
nodes that represent children). Note though that the parse tree
functionality is included as a debugging aid not as an alternate to
building ASTs in the usual way. So unless this is for testing or some
non-standard use you are probably best to switch to proper ASTs to
avoid other limitations.

Tom.
>
> Thank you.
>
> p.s.  I use ANTLR 3.1.
>
> --
> Best regards,
> Peter Bulychev.
>
>
> List: http://www.antlr.org/mailman/listinfo/antlr-interest
> Unsubscribe:
> http://www.antlr.org/mailman/options/antlr-interest/your-email-address
>
>
>


More information about the antlr-interest mailing list