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

The Researcher researcher0x00 at gmail.com
Tue May 24 05:36:44 PDT 2011


I am currently converting the C++ grammar from a  C back-end to a C#
back-end. The original C back-end code has support code, support
initialization code and utility code. Several versions of the grammar are
being developed at the same time; ISO, Microsoft, Test, etc. Each version of
the grammar has a different namespace.

The support initialization code was moved to the superclass constructor so
that it would be initialized during construction and not appear as a large
method in the grammar.

The parser was split into multiple files using partial classes with one of
the partial classes being the generated parser, and another being the
support methods that make calls to the parser code like LA(). This lets
generating of the the parser take place as often as needed without touching
the code in the other partial class.  This also keeps most of the code out
of the grammar file.

Lastly the utility code was put into a separate namespace with most of the
methods being static. This was done because I am working with multiple
versions and allows me to have only one copy of most of the support code.

Since most of the back-end code is moved out of the grammar, you can use
your favorite IDE to edit the code.

Eric


More information about the antlr-interest mailing list