[antlr-interest] Superclasses = best practise ...?

Jim Idle jimi at temporal-wave.com
Tue May 24 09:41:37 PDT 2011


I uses super classes to separate the grammar from the code - you can also
use separate helper classes to do this too. I recommend keeping the logic
out of the grammar, but if you have a smaller grammar and will never
target other languages or want to reuse the grammar to do more than one
task on the language, then you are not required to follow the Maven
archetype. However, the lists of reasons not to put logic in with the
grammar soon piles up.

Jim

> -----Original Message-----
> From: antlr-interest-bounces at antlr.org [mailto:antlr-interest-
> bounces at antlr.org] On Behalf Of Hans-Juergen Rennau
> Sent: Tuesday, May 24, 2011 1:14 AM
> To: antlr-interest at antlr.org
> Subject: [antlr-interest] Superclasses = best practise ...?
>
> Hello People,
>
> this is a question about best practices when augmenting lexer and
> parser with Java code providing helper methods (or even inner classes
> for storare purposes).
>
> The Maven prototype "antlr3-maven-archetype" creates example grammars
> which use super classes (AbstractTParser and AbstractTLexer). The
> comments in those super classes suggest to honour this as a general
> pattern: put helper methods in a grammar base class in order to keep
> the grammar light and clean. I think this has pros and a con. The con
> is that this way the compactness of "all-in-one-unit" is sacrificed;
> and reading the grammar one has to consult a second source. Also I
> noted that the Definitive Guide never made any suggestions to employ
> superclasses.
>
> So this is my question: would you recommend the superclass approach
> indeed as the best practise, or rather regard it as a good practise one
> might follow or not, perhaps depending on complexity?
>
> Thank you,
>
> cheers,
>
> -- Hans-Juergen Rennau
>
> List: http://www.antlr.org/mailman/listinfo/antlr-interest
> Unsubscribe: http://www.antlr.org/mailman/options/antlr-interest/your-
> email-address


More information about the antlr-interest mailing list