[antlr-interest] How to reuse lexer object and parser object

Jim Idle jimi at temporal-wave.com
Fri Oct 10 12:08:19 PDT 2008


On Thu, 2008-10-09 at 14:59 +0800, Ronghui Yu wrote:
> Hi, Jim,
>  
> Sorry to bother you again.
> As I mentioned before, I use the same lexer and parser object for
> parsing different SQL statements.
> When using ANTLR3.0.1, everything works fine, but when upgrade to
> ANTLR3.1, I found that it is necessary to save the
> ctx->pParser->rec->state->tokenNames before calling setTokenStream,
> and restore it to the previous value after.
>  
> But we found that it is not enough yet. Sometimes, it needs to set
> ctx->pParser->rec->state->tokFactory to NULL, otherwise, it will
> result in crash. What I do now is closing the tokFactory and setting
> it to NULL.
>  
> The problem is, I am not sure if there are other fields I need to
> reset, or what values I should set them to.
> Could you give me some advices?
> Or if possible, you may provide an API for doing this job.


I will have to look in to the code, but also please try the 3.1.1 code
as I think I corrected at least one issue for that. However, creating
the objects doesn't really take any time either - it isn't very costly
to allocate the memory and fill in  the method addresses.

Jim
>  
> Thanks a lot.
> 
> 
> -- 
> ===========================
> Regards
> Ronghui Yu
> 
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.antlr.org/pipermail/antlr-interest/attachments/20081010/ce26bf3b/attachment.html 


More information about the antlr-interest mailing list