[antlr-interest] superClass

Paul Keir paul at paulkeir.com
Sun Oct 21 15:00:58 PDT 2007


Hello again,

I have a grammar embedded within the C example grammar, and now I'd like 
to separate the extension cleanly into a separate file. I was hoping the 
'superClass' option, described in the book, could help me here. I've 
tried a few ideas now, but not yet with any luck.

First, I tried compiling the original C grammar (C.g) as usual, then 
created a new grammar file containing only its name (newC), and a single 
superclass option of 'superClass=CParser;', but that results in a null 
pointer exception (in Grammar.setGrammarContent).

I then added a single rule,
myrule : struct_or_union;
and that failed too, with the statement that the 'struct_or_union' rule 
is undefined. I tried adding 'import CParser/Lexer' to the @header 
section, but that changed nothing.

Changing tack slightly I tried overriding an existing C method:
storage_class_specifier : 'extern' | 'static' | 'auto' | 'register' | 
'test' ;
and Antlr could compile that, but javac *.java now has a problem:
newCParser.java:26: storage_class_specifier() in newCParser cannot 
override storage_class_specifier() in CParser; overridden method is final

I'm clearly well off track, so any advice at all would be gratefully 
received.

Yours confused,
Paul



More information about the antlr-interest mailing list