[antlr-interest] Re: Merging token vocabularies; Ter adds grammar composition

Monty Zukowski monty at codetransform.com
Thu Jun 24 16:29:14 PDT 2004


On Jun 24, 2004, at 3:59 PM, Terence Parr wrote:

> Back to trees with vocab not grammar imports...I'd like to hear from
> Monty to hear more about his use of combined vocabs in his tree walkers
> and his use of inheritance.  I think Monty made a tree supergrammar
> that had all the tokens in it and then each tree walker phase of the
> translator subclassed that grammar to get all the tokens.  That is
> basically the same as doing an importVocab on a combined vocab you
> built.
>

You got it right.  I started from one language, not two, but added all 
the second language's tokens to the "super" tree grammar.  This tree 
grammar had the rules for both AREV trees and VB trees.  The tree 
grammars for both languages were essentially orthogonal because the 
token types were distinct, or when shared they had identical meaning.  
But I couldn't even share ID because of naming rules.  I think INT was 
shared :)

So the cool thing was that after every pass (which subclassed the 
"super" tree grammar), even though the resulting tree was a mixture of 
AREV and VB trees my "super" tree grammar could walk that tree and 
validate the structure (handy during development to know my resulting 
trees were ok).  I joined the languages at places like "statement" and 
"expression", meaning roughly "statement: arevStatement | vbStatement;" 
  After the last pass my trees were completely VB, but still I 
subclassed the "super" tree grammar for the code emitter.  I suppose I 
could have overridden the AREV rules to throw an exception if I 
encountered them in that last phase if I wanted to be safe.

More details on the AREV->VB translator are at 
http://www.codetransform.com/fun_with_antlr.html

If you look at the "metamorphic syntax macro" stuff they show stuff 
like adding a new expression type or a new statement.  Most people 
don't want to muck with the syntax of, say, the case statement or array 
initializer.  I emphasize that because the metamorphic guys make it 
"safe" to add a new statement by not letting you do something that 
introduces ambiguities language wide.  I think that is quite handy for 
folks in the Domain Specific Language world.

Monty

ANTLR & Java Consultant -- http://www.codetransform.com
ANSI C/GCC transformation toolkit -- 
http://www.codetransform.com/gcc.html
Embrace the Decay -- http://www.codetransform.com/EmbraceDecay.html



 
Yahoo! Groups Links

<*> To visit your group on the web, go to:
     http://groups.yahoo.com/group/antlr-interest/

<*> To unsubscribe from this group, send an email to:
     antlr-interest-unsubscribe at yahoogroups.com

<*> Your use of Yahoo! Groups is subject to:
     http://docs.yahoo.com/info/terms/
 



More information about the antlr-interest mailing list