[antlr-interest] Reusing Lexer/Parser instances

Ric Klaren klaren at cs.utwente.nl
Fri Jul 11 08:20:49 PDT 2003


Hi,

On Fri, Jul 11, 2003 at 03:04:47PM -0000, defordusa wrote:
> I have been able to reuse the lexer and parser instances calling 
> setInputState and setTokenBuffer on the lexer and parser 
> respectively. However, I still have the overhead of millions of 
> instances being created, dramatically reducing performance.
> 
> Is there a better way of doing this?
> 
> Here is a snippet of my code:
> ...
> while( in.ready() )
> {
>   lexer.setInputState(new LexerSharedInputState(new StringReader
> (in.readLine())));
>   parser.setTokenBuffer( new TokenBuffer(lexer) );
>   parser.startRule();
> }

Have a look at:

- CharScanner.getInputState() (get an existing SharedLexerInputState from 
  the lexer)
- LexerSharedInputState.reset() (have to do that between invocations,
  resets line info and some other bookkeeping)
- InputBuffer.reset() (called by the above reset)
- CharBuffer.java

Hmmm looks like in java you might have to write a subclass of CharBuffer to
include a method to hook a new Reader to the buffer or something.

Cheers,

Ric
-- 
-----+++++*****************************************************+++++++++-------
    ---- Ric Klaren ----- j.klaren at utwente.nl ----- +31 53 4893722  ----
-----+++++*****************************************************+++++++++-------
  "Of all the things i've lost i miss my mind the most -Ozzy Osbourne


 

Your use of Yahoo! Groups is subject to http://docs.yahoo.com/info/terms/ 




More information about the antlr-interest mailing list