[antlr-interest] Treeparser inheritance?

Jos Fries ga-fries at veenendaalnet.nl
Fri Nov 18 07:24:22 PST 2005


Terence wrote:

> Oh, sorry.  Now I remember.  Inheritance is an "include".  The  
> implementation says it inherits from the tree parser, but you'll see  
> all your overridden rules inside. :)
> 
> Ter

I see what you mean but it doesn't function for me... I'll get more concrete. I have a simple AST for predicate expressions:

class PredicateTreeWalker extends TreeParser;

expr returns [ String s ]
{ String e1, e2 = new String (); s = new String (); }
: #(FORALL v1:VPSNAME c1:VPSNAME e1=expr) { s = "forAll (" + v1 + ", " + c1 + ", " + e1 + ")"; }
| #(EXISTS v2:VPSNAME c2:VPSNAME e2=expr) { s = "exists (" + v2 + ", " + c1 + ", " + e2 + ")"; } 
| #(OR e1=expr e2=expr) { s = e1 + " + " + e2; }
| #(AND e1=expr e2=expr) { s = e1 + " * " + e2; }
| #(LPAREN e1=expr) { s = "( " + e1 + " )"; }
| #(NOT e1=expr) { s = ".N. " + e1; }
| n:VPSNAME { s = n.getText (); };

Now I would like to extend this AST with an assignment statement:

class StateExprTreeWalker extends PredicateTreeWalker;
options { importVocab = PredicateLexer; }

expr returns [ String s ]
{ String e1 = new String(); s = new String (); }
: #(EQUALS v1:VPSNAME e1=expr) { s = v1 + " = " + e1; }
;

The generated class StateExprTreeWalker only contains its own actions. How can I get it to contain also the actions from PredicateTreeWalker?

Regards,

Jos

----- Original Message ----- 
From: "Terence Parr" <parrt at cs.usfca.edu>
To: "ANTLR Interest" <antlr-interest at antlr.org>
Sent: Monday, November 14, 2005 9:06 PM
Subject: Re: [antlr-interest] Treeparser inheritance?


> Oh, sorry.  Now I remember.  Inheritance is an "include".  The  
> implementation says it inherits from the tree parser, but you'll see  
> all your overridden rules inside. :)
> 
> Ter
> On Nov 14, 2005, at 11:49 AM, Jos Fries wrote:
> 
>> Hi Terrence,
>>
>> Could you point me to an example in which a tree parser in a  
>> subgrammar inherits from the tree parser in the supergrammer? I  
>> searched in vain for that use of inheritance in the reference  
>> manual...
>>
>> Regards,
>>
>> Jos
>>
>>
>>>
>>> On Nov 14, 2005, at 8:37 AM, Jos Fries wrote:
>>>
>>>> Hi,
>>>>
>>>> Last weekend I experimented with grammar inheritance. I   
>>>> successfully extended a lexer and a parser. Extending my tree   
>>>> parser however failed. My statement "class BTreeWalker extends   
>>>> ATreeWalker;" is accepted by ANTLR but compiled to the Java code   
>>>> "public class BTreeWalker extends antlr.TreeParser".
>>>>
>>>> Excuse the newbie character of the question, but does the  
>>>> concept  of grammar inheritance also apply to tree parsers? The   
>>>> documentation doesn't state anything about this. I'm using antlr   
>>>> 2.7.4.
>>>
>>> Hi Jos, it should work as you describe.  Are you sure you're doing  
>>> it just like in the examples?
>>>
>>> Terence
>>>
>>>
>>>
>>>
>>> -- 
>>> No virus found in this incoming message.
>>> Checked by AVG Free Edition.
>>> Version: 7.1.362 / Virus Database: 267.13.0/167 - Release Date:  
>>> 11-11-2005
>>>
>>
> 
> 
> 
> 
> -- 
> No virus found in this incoming message.
> Checked by AVG Free Edition.
> Version: 7.1.362 / Virus Database: 267.13.0/167 - Release Date: 11-11-2005
> 
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.antlr.org/pipermail/antlr-interest/attachments/20051118/5504d017/attachment.html


More information about the antlr-interest mailing list