[antlr-interest] Treeparser inheritance?

Terence Parr parrt at cs.usfca.edu
Fri Nov 18 08:12:10 PST 2005


On Nov 18, 2005, at 7:24 AM, Jos Fries wrote:
> 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?

You have overridden rule expr so it doesn't contain the original.  It  
mirrors how method overriding workings too.  You cannot bring in just  
a few alts from above.  Sorry.
Ter


More information about the antlr-interest mailing list