[antlr-interest] superClass usage

Oti ohumbel at gmail.com
Tue Nov 13 14:35:07 PST 2007


Paul,

you are talking about grammar inheritance - sorry no experience with that.
What I meant was putting most of the @member stuff, exception handling
and the like into a simple java super class.
This keeps your grammar cleaner, and simplifies unit testing.

Best wishes,
Oti.

On Nov 5, 2007 10:30 PM, Paul Keir <paul at paulkeir.com> wrote:
>
>  Thanks. But how can I use a parser rule from a grammar's superClass?
> Taking, say, the SimpleC.g Java example Grammar, I create a new test file,
> Mine.g:
>
>  grammar Mine;
>
>  options {
>    superClass=simpleCParser;
>  }
>
>  catchme
>  : variable | declarator
>  ;
>
>  When I then run,
>  java org.antlr.Tool SimpleC.g Mine.g
>  it fails due to the 'variable' and 'declarator' rules being undefined.
>
>  Thanks again,
>  Paul
>
>
>
>  Oti wrote:
>  Paul,
>
> for the parser superclass, it is really that easy as described in section
> 5.7.
> Currently there is no way of specifiying the lexer superclass. But you
> can use a package trick in Foo.g:
>
> @lexer::header {
> package my.lexer;
> }
>
> If you create a class named "Lexer" (which extends
> org.antlr.runtime.Lexer) in package my.lexer, your own Lexer will be
> the superclass. That's because ANTLR generates:
>
> package my.lexer;
> import org.antlr.runtime.*;
> public class FooLexer extends Lexer {...
>
> Hope this helps a little,
> Oti.
>
>
> On 10/28/07, Paul Keir <paul at paulkeir.com> wrote:
>
>
>  Hi all,
>
> Does anyone have an example using the superClass option described in
> section 5.7 of the ANTLR ref. book? I'd like to extend an existing
> combined grammar.
>
> Thanks in advance,
> Paul
>
>
>
>
>


More information about the antlr-interest mailing list