[antlr-interest] How to keep the embedded Java code to minimum.

Randall R Schulz rschulz at sonic.net
Thu Mar 27 12:28:37 PDT 2008


On Thursday 27 March 2008 08:59, Grzegorz Cieslewski wrote:
> All,
>
> I have a general question for  ANTLR folks.  How do you keep the
> embedded java (or other) code in your grammar to a minimum to
> preserve readability of the grammar?

I create an interface that defines all the semantic actions. Then I 
require an instance of (an implementation of) that interface in the 
constructor for the parser (the second-pass AST parser). This makes it 
easy to implement a variety of processing for the language in question.

I've used this technique with JavaCC and ANTLR grammars. It's pretty 
generic.


> Greg


Randall Schulz


More information about the antlr-interest mailing list