Re: Get line numbers with Antlr parser

Ulrich Hobelmann <>
18 May 2006 23:52:38 -0400

          From comp.compilers

Related articles
Get line numbers with Antlr parser (Ulrich Hobelmann) (2006-05-16)
Re: Get line numbers with Antlr parser (Antoine Reilles) (2006-05-18)
Re: Get line numbers with Antlr parser (Kai Koehne) (2006-05-18)
Re: Get line numbers with Antlr parser (Ulrich Hobelmann) (2006-05-18)
| List of all articles for this month |

From: Ulrich Hobelmann <>
Date: 18 May 2006 23:52:38 -0400
Organization: Compilers Central
References: 06-05-058
Keywords: PCCTS
Posted-Date: 18 May 2006 23:52:38 EDT

Ulrich Hobelmann wrote:
> Now for some reason the line information disappears while the tree is
> being built. In java15.tree.g I can add printlns, but the line number
> of the *same* node as in java15.g is suddenly 0, while it was, say 15,
> only a second (and I assume a "return") before.
> (or is this a bug?)

I haven't found an answer to the above, but for the record let me post
my solution:
since Antlr seems to exterminate the line numbers when the nodes are
passed between parsers, the workaround was to "wrap" line numbers as
: lc:LCURLY!
                          >ompoundStatement =
In the tree parser, the IDENTs are then collected and disassembled (i.e.
getText() extracts the text and Integer.parseInt() unwraps them into the
line number they once were). Ugly, but it does the job.

Until last night, that is. This morning I did some more typing, but now
for some reason I get the message: "<AST>: expecting IDENT, found
'<empty tree>'", and I forgot what exactly I changed that suddenly
produces this behavior. Everything seems to work correctly as before,
except for the annoying message.

Of course, Antlr is being true to its tradition of transparency, and
doesn't bother to mention *where* this occurs, so I have - again - no
idea what exactly is going on.

If anybody has any idea, I'd be thankful for that. (Otherwise I just
hope I'll be done with this project as soon as possible (and don't have
to touch it again).)


Post a followup to this message

Return to the comp.compilers page.
Search the comp.compilers archives again.