[antlr-interest] Abstract tree parser
Ron Hunter-Duvar
ron.hunter-duvar at oracle.com
Fri Feb 26 07:16:17 PST 2010
If I understand what you're asking for, the simplest way is to give up
on trying to declare the foo method abstract in IScriptTreeParser, and
declare it as:
protected void foo() {}
Then you can override it in the subclasses you write. I know abstract is
good because it forces you to redefine the method, but is it worth the
extra pain?
If you really want to have the abstract, I think you'd either have to do
it with some post-generation scripting, or modify Antlr to make it do
this as an option (but that's probably overkill). On Linux, the
following command should do the trick for you:
sed -ie 's/(public) (class IScriptTreeParser)/\1 abstract \2/'
IScriptTreeParser.java
Ron
Christian Pontesegger wrote:
> On 25.02.2010 21:47, Jim Idle wrote:
>
>> tree grammar IScriptTreeParser;
>> options {
>> language = Java;
>> tokenVocab = IScript;
>> ASTLabelType = CommonTree;
>> SuperClass = AbstractIScriptTreeParser;
>> }
>>
>>
>
> Still not what I'd like to have. I think I'll give it one more try:
>
> When finished I want to have following inheritance
>
> TreeParser <-- IScriptTreeParser <-- ConcreteTreeParser
> TreeParser <-- IScriptTreeParser <-- AnotherConcreteTreeParser
>
> TreeParser
> * is the ANTLR base class
>
> IScriptTreeParser is:
> * automatically generated from my treegrammar file
> * abstract public class IScriptCompiler extends TreeParser {... }
> ----^^^
> * has some abstract methods defined in @members
>
> ConcreteTreeParser is:
> * some class I am doing on my own
> * implements abstract stuff from IScriptTreeParser
>
> AnotherConcreteTreeParser is:
> * some class I am doing on my own
> * different implementation of abstract methods
>
>
> so far I did not get a recommendation how to do that.
>
> any ideas?
> Christian
>
>
>
> List: http://www.antlr.org/mailman/listinfo/antlr-interest
> Unsubscribe: http://www.antlr.org/mailman/options/antlr-interest/your-email-address
>
>
--
Ron Hunter-Duvar | Software Developer V | 403-272-6580
Oracle Service Engineering
Gulf Canada Square 401 - 9th Avenue S.W., Calgary, AB, Canada T2P 3C5
All opinions expressed here are mine, and do not necessarily represent
those of my employer.
More information about the antlr-interest
mailing list