[antlr-interest] Abstract tree parser

Jim Idle jimi at temporal-wave.com
Thu Feb 25 12:47:21 PST 2010


tree grammar IScriptTreeParser;
options {
   language = Java;
   tokenVocab = IScript;
   ASTLabelType = CommonTree;
   SuperClass = AbstractIScriptTreeParser;
}
 
@header {
     package com.something.test;
}
 
 
program
    :    g=globalStatement { blah($g); 

     ;


AbstractIScriptCompiler.java

public class AbstractIScriptCompiler extends TreeParser {

 ///// Implement constructors

 ////; Implement member methods

 protected void blah(CommonTree t) ...
}



Etc!

Jim

> -----Original Message-----
> From: antlr-interest-bounces at antlr.org [mailto:antlr-interest-
> bounces at antlr.org] On Behalf Of Christian Pontesegger
> Sent: Thursday, February 25, 2010 12:19 PM
> To: Terence Parr
> Cc: antlr-interest at antlr.org
> Subject: Re: [antlr-interest] Abstract tree parser
> 
> I still don't get it:
> 
> Here is my treegrammar:
> 
> tree grammar IScriptCompiler;
> 
> options {
>   language = Java;
>   tokenVocab = IScript;
>   ASTLabelType = CommonTree;
> }
> 
> @header {
>     package com.something.test;
> }
> 
> @members {
> 
>     protected abstract void foo();
> 
> }
> 
> program
>     :    globalStatement*
>     ;
> 
> ... to be continued
> 
> 
> 
> 
> Now what I get is a java class like this:
> 
> 
> public class IScriptCompiler extends TreeParser {
> 
>     <snip>
> 
>         protected abstract void foo();
> 
> ...
> 
> This is not valid java code!
> 
> I need something like this
> 
> abstract public class IScriptCompiler extends TreeParser {
> 
>     <snip>
> 
>         protected abstract void foo();
> 
> 
> How do I get this little "abstract" modifier in front of the class
> name?
> 
> 
> BTW:
> What should
> 
> 	protected abstract void foo() {}
> 
> do? A body for an abstract method???
> 
> 
> Christian
> 
> 
> On 24.02.2010 20:38,  Terence Parr wrote:
> > oh, i do:
> >
> > protected abstract void foo() {}
> >
> > Ter
> > On Feb 24, 2010, at 11:36 AM, Christian Pontesegger wrote:
> >
> >
> >> Terence Parr wrote:
> >>
> >>> You can either define abstract methods within @members and then
> subclass the parser or you can create a subclass of Parser with the
> abstract methods or concrete methods then use superClass.
> >>>
> >>>
> >> Thats what I intend to do, have
> >>
> >> @members {
> >>
> >>    protected abstract void foo();
> >>    ...
> >> }
> >>
> >> but then the generated class will have an error due to the missing
> >> "abstract" modifier in the class definition. Unfortunately the
> @headers
> >> section is pasted right before some other imports. If it were the
> last
> >> before the class definition I could put my "abstract" modifier
> there.
> >>
> >> I want to derive from my abstract parser and have several
> implementing
> >> parsers with different functionality. Right now I am declaring dummy
> >> methods within @members and overwrite them in my subclasses. But
> thats
> >> not the way java is meant to be, right?
> >>
> >> So if it is not possible to do that now, maybe this is some input
> for a
> >> future version of ANTLR.
> >>
> >> Christian
> >>
> >> List: http://www.antlr.org/mailman/listinfo/antlr-interest
> >> Unsubscribe: http://www.antlr.org/mailman/options/antlr-
> interest/your-email-address
> >>
> >
> 
> 
> List: http://www.antlr.org/mailman/listinfo/antlr-interest
> Unsubscribe: http://www.antlr.org/mailman/options/antlr-interest/your-
> email-address





More information about the antlr-interest mailing list