[antlr-interest] philosophy about translation

Monty Zukowski monty at codetransform.com
Tue Oct 10 13:38:20 PDT 2006


> * Ease of specification.  Rules are clearly easier than a tree walker
> when they are clean and there are few of them.  How can one beat the
> following?
>
> ADD v1 TO v2. --> v2 += v1;
>
> Though with trees, one could perhaps auto translate that text to
> trees.   Or, just use raw:
>
> ^(ADD v1 v2) -> ^(PLUS_EQUAL v2 v1)
>

Note that the E language guys came up with a nice shorthand described
tersely here:  http://www.erights.org/elang/grammar/quasi-terms.html
and http://www.erights.org/elang/grammar/quasi-xml.html.  Basically it
lets you parse something like ADD @v1:expr TO @v2:expr into a tree
that can be matched against your source tree.  Then you can write the
--> @v2 += @v1 on the other side, which is parsed into a tree and it
will substitute the AST nodes appropriately,   So basically you are
specifying in text yet working in trees.

Ter, I think we discussed this at the Cabal.  The trick is that the
parser and lexer needs to know how to just return a generic EXPR token
for @v1:expr -- and build a tree with that as a placeholder.

> Personally,  I think that a hybrid system that does most of the work
> in a tree walker but with rules, for all of the special cases that
> Andy has pointed out, would be great!
>

Yes, I agree.  This is quite an interesting discussion.

Monty


More information about the antlr-interest mailing list