[antlr-interest] superClass usage
Terence Parr
parrt at cs.usfca.edu
Wed Nov 14 08:46:29 PST 2007
see
http://www.antlr.org/wiki/display/~admin/2007/07/18/On+the+reuse+of
+grammars
for my initial thoughts; i still need to write doc.
Ter
On Nov 13, 2007, at 3:23 PM, Paul Keir wrote:
> Thanks Oti. Yeah, I finally realised I was hoping for too much from
> superClass. It seems like grammar inheritance is only something for
> the antlr wishlist.
> Paul
>
> Oti wrote:
>> 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
>>>
>>>
>>>
>>>
>>>
>>>
>>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.antlr.org/pipermail/antlr-interest/attachments/20071114/6e76cdb0/attachment-0001.html
More information about the antlr-interest
mailing list