[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [Grammatica-users] Reusing the Parser and Tokenizer classes
From: |
Per Cederberg |
Subject: |
Re: [Grammatica-users] Reusing the Parser and Tokenizer classes |
Date: |
Tue, 13 Jan 2004 22:51:00 +0100 |
On Tue, 2004-01-13 at 19:32, Luc Morin wrote:
> <snip>
> I'm making a lot of calls to this function, and each time the Parser has
> to be re-initialized, calling its CreatePatterns() function. The Tokenizer
> also calls its own CreatePatterns() function each time. I see this as a
> performance issue.
Indeed it is. I haven't measured the performance hit resulting from
this, but for a complex grammar it can be a serious problem. (For an
example, see the Mibble project at Savannah.)
> Would it be possible to reuse the Parser and Tokenizer classes such that
> they get instantiated only once, and then be able to parse() strings
> without having to re-init ?
Yes, it would be possible after breaking the Grammatica API. It is not
a trivial change, but neither is it overly complex. It is a design
mistake that things look like this, one that I made simply as it didn't
occur to me at the time that this could be an issue... :-(
Anyway, there is a future improvement request registered for this at
Savannah if you are interested (bug #4500):
http://savannah.nongnu.org/bugs/?func=detailitem&item_id=4500
I'm currently quite pressed for time, so I won't be able to do anything
about this issue (or others) in the near future. It is definitely on
the list for Grammatica 2.0 though... If you feel like giving it a stab
yourself I'd be more than happy to accept any contribution!
> This would imply modifying the code templates I guess. Would it involve a
> lot of work from the developers of Grammatica ?
Actually Grammatica does not generate the output source code from
templates. Instead, a source code object model (containing (methods,
classes, comments...) is created and then written to a stream. It's
quite dynamic actually, do take a peek at it if you are interested!
> Or maybe this feature is already in there and I just haven't seen it ?
If things were only so good... ;-)
Cheers,
/Per
--
Per Cederberg, Software Consultant
http://www.percederberg.net/software