[antlr-interest] Why (or why not) reuse parsers and lexers?

"Paul Bouché (NSN)" paul.bouche at nsn.com
Thu Feb 5 04:36:46 PST 2009


Hi,

I also thought about doing this. I guess it really depends on the 
Parser, if it has state associated it needs to be resetted. Since a 
grammer can contain arbitrary member definitions of a parser it also 
really depends on the grammar at hand.

But I guess you are wondering about the internal state that a parser 
always has, i.e. in Java the BaseRecognizer class. I am not sure about 
that, but I am also interested in a definitive answer. Yet my 
performance tests have shown that creating these objects a new is not 
expensive not regarding the generated GC load though. If an application 
is already at a tight memory state one wants to avoid creating new 
objects as far as possible.

Best,
Paul

Chris Lambrou schrieb:
> Hi all,
>
> Is there any reason why I should consider recycling lexers and parsers 
> in preference to creating new instances on demand?
>
> For example, should I consider doing this:
>
>     existingLexer.Reser();
>     existingLexer.CharStream = charStream;
>
> instead of this:
>
>     new MyGrammarLexer(charStream);
>
>
> And should I do this:
>
>     existingParser.Reset();
>     existingParser.TokenStream = tokenStream
>
> instead of this:
>
>     new MyGrammarParser(tokenStream)
>
>
> Are parsers and lexers especially heavyweight at all?  If the answer 
> depends on the context, then I should point out that I'm using the C# 
> runtime, and parsing many different input strings.
>
>
> Thanks,
>
> Chris
>
>
> ------------------------------------------------------------------------
>
>
> List: http://www.antlr.org/mailman/listinfo/antlr-interest
> Unsubscribe: http://www.antlr.org/mailman/options/antlr-interest/your-email-address
>   


-- 
Paul Bouché
Voice: +49 30 590080-1284
 
Nokia Siemens Networks GmbH & Co. KG, An den Treptowers 1, 12435 Berlin, Germany
Sitz der Gesellschaft: München / Registered office: Munich
Registergericht: München / Commercial registry: Munich, HRA 88537
WEEE-Reg.-Nr.: DE 52984304

Persönlich haftende Gesellschafterin / General Partner: Nokia Siemens Networks Management GmbH
Geschäftsleitung / Board of Directors: Lydia Sommer, Olaf Horsthemke
Vorsitzender des Aufsichtsrats / Chairman of supervisory board: Lauri Kivinen
Sitz der Gesellschaft: München / Registered office: Munich
Registergericht: München / Commercial registry: Munich, HRB 163416

-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.antlr.org/pipermail/antlr-interest/attachments/20090205/f1d34592/attachment.html 


More information about the antlr-interest mailing list