[antlr-interest] Abstract tree parser
Christian Pontesegger
christian.pontesegger at web.de
Thu Feb 25 12:18:59 PST 2010
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
>>
>
More information about the antlr-interest
mailing list