[antlr-interest] philosophy about translation
Kay Roepke
kroepke at classdump.org
Fri Oct 27 10:51:30 PDT 2006
On 27. Oct 2006, at 16:44 , Andy Tripp wrote:
> So what I'm doing is write a tree-matching class that allows you to
> say
> "v + x --> v.add(x)" to mean "look through an AST for a "+"
> node with a first child that's an IDENT that has a particular text,
> and any arbitrary
> second child. If found, replace that AST node with a different AST
> node
> that has a METHOD_CALL node as its root, a DOT node as first child,
> etc."
Like a parser rule with a rewrite action? Sounds tremendously like
it...;)
I think a filtering parser (or even tree parser with rewrite
ability) will be able to
do just that!
For some reason there's a voice in my head that says "you want to
write a translator from
a more human-readable text input to ANTLR grammars". Because this is
pretty much what you
can do with ANTLR already, although not completely in ANTLR syntax.
Once ANTLR can support tree rewrites I don't see why you'd have to
resort to custom Java
classes to reimplement that.
It seems to me that you are actually implementing a treeparser
generator, looking at
"v + x ..." and your explanation of it. Just with a different (non-
EBNF) syntax. Is that a
wise decision? I cannot really say, but I have the feeling that you
might open a can of worms
there. Of course, I might also be totally wrong :)
If I was to tackle this problem, I'd try to actually generate some
sort of ANTLR grammar to
do the actual tree walking for me, translated from my rule definitions.
This could mean that I'd have to enhance certain aspects of ANTLR
(like implementing filtering
parsers and treeparsers, tree rewrites), but in the long run that
would be worth it, I think.
cheers,
-k
More information about the antlr-interest
mailing list