On Thursday 09 October 2008 00:30, Ronghui Yu wrote: > On Thu, Oct 9, 2008 at 3:12 PM, Gavin Lambert <[EMAIL PROTECTED]> wrote: > > At 19:59 9/10/2008, Ronghui Yu wrote: > >> As I mentioned before, I use the same lexer and parser object for > >> parsing different SQL statements. > > > > Is there some particular reason why you don't want to construct a > > new instance? > > Yes, this is the easiest way to make it work. > It is not I who designed the architecture. But I think the reason may > be the performance, the parser object contains over 1000 fields > needed to be set, it may be much faster to reuse it by resetting some > fields of it.
Why don't you refactor the design so that pile of state is a separate object? It doesn't sound like it belongs in the parser. I like to define an interface, an "acceptor" that is passed to the tree parser constructor. All the AST parser does is the minimum required to interpret the AST it's parsing. All the specifics of what happens with each individual target language construct resides in the acceptor. I usually create a "null acceptor" that implements all the acceptor interface's methods but does nothing. It's the default acceptor and can be used as a base class for implementing acceptors that don't need to handle every construct in the target language. This setup allows a given language to be processed in many different ways. It would also serve to separate the voluminous state you have from the AST parser proper. Randall Schulz List: http://www.antlr.org:8080/mailman/listinfo/antlr-interest Unsubscribe: http://www.antlr.org:8080/mailman/options/antlr-interest/your-email-address --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "il-antlr-interest" group. To post to this group, send email to [email protected] To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/il-antlr-interest?hl=en -~----------~----~----~----~------~----~------~--~---
