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

Michael Bedward michael.bedward at gmail.com
Tue May 24 01:24:36 PDT 2011

Nice question.

My own experience is that the superclass approach really helps me to
keep both my grammar and my supporting code much easier to read,
understand and maintain. Being lazy I always start with the "one big
lump" model but once the supporting code gets beyond a modest size it
really obscures the grammar - although perhaps this is also a comment
on the tidiness, or lack of it, in my code.

Nutshell summary: when my grammar file starts getting ugly I've found
extracting a super-class to be very helpful.


On 24 May 2011 18:14, Hans-Juergen Rennau <hrennau at yahoo.de> wrote:
> 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