Get line numbers with Antlr parser

Ulrich Hobelmann <u.hobelmann@web.de>
16 May 2006 15:43:47 -0400

          From comp.compilers

Related articles
Get line numbers with Antlr parser u.hobelmann@web.de (Ulrich Hobelmann) (2006-05-16)
Re: Get line numbers with Antlr parser reilles@loria.fr (Antoine Reilles) (2006-05-18)
Re: Get line numbers with Antlr parser java.3.kkoehne@spamgourmet.org (Kai Koehne) (2006-05-18)
Re: Get line numbers with Antlr parser u.hobelmann@web.de (Ulrich Hobelmann) (2006-05-18)
| List of all articles for this month |

From: Ulrich Hobelmann <u.hobelmann@web.de>
Newsgroups: comp.compilers.tools.pccts,comp.compilers
Date: 16 May 2006 15:43:47 -0400
Organization: Compilers Central
Keywords: PCCTS, question
Posted-Date: 16 May 2006 15:43:47 EDT

Hi, I'm using the Java1.5 parser + tree parser by Mike Studman.


My problem: I need to extract the line numbers from the parser.


Funny thing: in one part of the parser it works, but in the tree parser
it doesn't. In java15.g I added some printlns to print getLine() of
some nodes, and they printed the lines. The very same nodes are also
put into a tree structure to read by the java-tree parser (obviously).


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.


Why is this?


What can / do I have to do, to get the line numbers to the high level,
where I need it?


I also tried various ways of modifying the trees built, including
creating a custom tree (using #() instead of the ^ often used in
java15.g) with some nodes that only have line info. Every time the line
info seems to disappear.


Unfortunately Antlr documentation isn't really helpful. It only
mentions that there *is* the newline() method and that getLine() can be
used, but it doesn't explain why between files the line information
disappears.


(or is this a bug?)


Best regards,
      Ulrich



Post a followup to this message

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