[antlr-interest] Re: Translators Should Use Tree Grammars

atripp54321 atripp at comcast.net
Sun Nov 21 15:03:55 PST 2004



--- In antlr-interest at yahoogroups.com, Oliver Zeigermann
<oliver.zeigermann at g...> wrote:
> I understand most of your stuff and especially the one about Magic.
> What I do not quite understand that - as it seems - for the parser you
> accept grammars are a concise language to describe the language to
> parse and seem to prefer it over pure Java. Why not for certain tree
> transformations? I understand in tree transformations the emphasis is
> not on revealing structure (analysis), but rahter on what to do with
> certain patterns (synthesis).Do you thing this the important
> difference?

Yes, I think that's it exactly.
It seems to me that something like a C-to-Java translator
is more like an English-to-Spanish translator than it is like
a C-to-object code compiler. The work that needs to be done
is so large and complicated, that it lends itself to
a pattern-matching-and-replacement approach rather than
a traverse-the-AST approach.

I did investigate some of the natural language translation tools,
and there were lots of different approaches, but most were
loose pattern-matching approaches. That's because parsing
English into a tree-like structure (English grammar...noun,
verb, etc) doesn't do much for you. The rules for translation
are so complicated that you can't say "when we see a noun, do
the following". You might think that you could say
"when we find adjective-noun, change it to noun-adjective", but
there are so many thousands of exceptions to that rule that
it doesn't help much to think in that way.

I mean look at this huge list of just some of what's
 needed to convert
C to Java, omitting almost all detail:
http://jazillian.com/how.html
How can you specify
that kind of functionality in a tree grammar?  You'll end up
with tens of thousands of lines of code embedded within
a couple of hundred lines of grammar. Moving the code
out into another file doesn't change much.

I don't want to "walk the tree", I want to "search the tree
for patterns and make replacements". If the tree transformations
can all be nicely specified in a little language (like TXL),
then that's fine. But from what I've seen, TXL looks
pretty limited and cryptic too.

Andy
> 
> Oliver






 
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