Re: Hierarchical query
Date: Thu, 14 Jun 2007 01:58:15 -0000
Message-ID: <1181786295.814513.138980_at_o11g2000prd.googlegroups.com>
On Jun 13, 5:35 pm, Vadim Tropashko <vadimtro_inva..._at_yahoo.com>
wrote:
> On Jun 13, 4:47 pm, Marshall <marshall.spi..._at_gmail.com> wrote:
>
> > 3) is interesting. I admit that when I first heard about the
> > idea I was extremely skeptical. The idea that one would
> > write a grammar to abstract operating on a tree one had
> > generated by using a grammar to abstract over a language
> > seemed perverse and unnecessarily complex at first.
> > However in practice it's turned out to be the opposite:
> > it is extremely simple. Tree grammars are a fraction
> > of the size of the original grammar, possible similarly
> > to the size of an XPath expression to a DTD.
>
> Do you have a reference?http://antlr.org/article/1170602723163/treewalkers.html
> insists that the "tree grammar" concept is not appeared to be coherent
> to begin with...
Well, that paper's on Terrence's site, so probably he doesn't see it as *too* devastating. :-)
But really, I had all those arguments in my head, until I tried it. It turned out really easy to do.
In something I did recently, a simple expression grammar, all the precedence, etc, went in the "regular" grammar. So the AST captured all of that. Then I needed to translate the AST into custom Java objects. It was ridiculously easy; the tree grammar was just:
prog: expr*;
expr: <node1 a, b> {new Node1(a, b);}
| <node2> {new Node2();}
| ...
;
Perhaps my next step is getting rid of the Java AST objects and just using the Antlr AST object.
Anyway, I've been very impressed with ANTLR.
As an aside, another idea of Terrence's was an IDE for Antrlr, which I also thought was ridiculous when I first heard about it. But now v3.0 is out and I've used the IDE and it's as much a win for parsers as it is for source code. Being able to interactively tweak the grammar and parse programs with each revision, having a CST and AST view, being able to single step through the parse, etc.
Marshall Received on Thu Jun 14 2007 - 03:58:15 CEST