[antlr-interest] philosophy about translation

Terence Parr parrt at cs.usfca.edu
Fri Oct 6 11:05:13 PDT 2006


On Oct 5, 2006, at 12:25 PM, Monty Zukowski wrote:
> In fact it is quite easy to have multiple languages in the same tree.
> I did this for the AREV->VB translator.  The key is to have AREV_PLUS
> and VB_PLUS for the '+' tree nodes.  Then you don't have to guess if
> you are processing arev addition or vb addition.

Hi Monty!  Nice to see you pop your head up!

Well, I'm not so much worried about how to differentiate the tree  
nodes per se.  I am concerned about making a union grammar that has  
to have both AREV_PLUS and VB_PLUS rules.  Or, if I'm doing this by  
hand, I have to have code that deals with both kinds of tree nodes.   
Propagating grammatical changes forward from phase n to n+i can be  
challenging even if using a grammar.

> I had one super-treegrammar with two complete tree grammars therin.  I
> found it convenient to bifurcate at the statement level.  For example:
>
> program: (statement)*;
> statement:arevStatement | vbStatement;

   Yes, but what happens when you decide that you need to do a  
transformation sooner than you had it before?  You need to modify all  
of the intermediate transformation phases to deal with new  
grammatical structure.  This cannot really be done automatically.

> I was raving about this like 7 years ago, it just totally rocks!

   I build my Fortran translators this way in the old days, but I  
just remember all of the pain when changing the phase in which I did  
a transformation because it ripples through the remaining phases.

> Check the archives for my posts about multiple tree grammars, or ask
> questions if something isn't clear.
>
> By the last pass, I had a completely vb tree, and then I finally
> dumped it to text.

   Yes, that is the really great feature of this approach.

TXL uses the union grammar approach by the way also.

Ter



More information about the antlr-interest mailing list