[antlr-interest] Avoiding the generation of final methods

Gavin Lambert antlr at mirality.co.nz
Thu Apr 16 12:11:22 PDT 2009


At 04:12 17/04/2009, Paul Bouché (NSN) wrote:
>In the past I would have liked the same, but.... 
>As a workaround you could add for each parser 
>method an @init and @after which calls some 
>custom added methods (in the @members section) 
>which are non-final, have some default behavior 
>and can be overriden in a subclass of a parser. 
>I think this is the closest you can get to 
>"overriden parser methods" out-of-the-box. And 
>also some action methods.
>
>I.e. with Java-target
>
>@members {
>     public void fooInit() { }
>     public void fooAfter() { }
>     public void fooBAR() { }
>}
>foo
>@init {
>     fooInit();
>}
>@after {
>     fooAfter();
>}
>:
>BAR { fooBAR(); }
>;

Another option is to have your action code call 
an interface provided to the parser rather than 
taking any direct action.  You can get all the 
flexibility you want that way.

(Although even then, it might be better to 
generate an AST and have alternate tree walkers 
for each separate task you want to perform.)



More information about the antlr-interest mailing list