[antlr-interest] Re: Line numbers
Terence Parr
parrt at jguru.com
Mon Jan 20 12:13:34 PST 2003
On Monday, January 20, 2003, at 11:59 AM, micheal_jor
<open.zone at virgin.net> wrote:
>
>> Hi there. I believe there was a quick thread previously where I
>> decided to add getToken() method to the AST interface and then
> modify
>> the AST factory method create(Token t) to just store the token not
> pull
>> out the text/type and store it. This way the tree will have a ref
> to
>> the token and you can ask (and my tree parsers can ask) for the
> line
>> number.
>
> -1
>
> With large files, the AST consumes lots of memory. More memory than
> I'd like usually. With lots of Token objects hanging around
> indefinitely, the problem would be compounded.
This was the original reason I didn't just have the AST point at the
token ;)
>
> My humble alternatives:
>
> 1. Supply a new xxxAST class with ANTLR that overrides initialize
> (Token) to copy the line/column/file values from the Token object.
>
> 2. For those who have no memory issues or prefer having the Token
> objects around - Supply another new xxxAST class with ANTLR that has
> getToken() and overrides initialize(Token) to do what you described.
Problem here is that they all use the AST interface...i'll have to add
that method (can be dummy for old classes).
Yep, these kinds of things should work. I'd like to see how i can
integrate in by default though so that the tree parsers can provide
meaningful errors. Right now they don't ;)
>
>> I would do this yourself until all ANTLR does it. :)
>
> ANTLR already makes it easy to do ;-)
:)
Ter
--
Co-founder, http://www.jguru.com
Creator, ANTLR Parser Generator: http://www.antlr.org
Lecturer in Comp. Sci., University of San Francisco
Your use of Yahoo! Groups is subject to http://docs.yahoo.com/info/terms/
More information about the antlr-interest
mailing list