[antlr-interest] postmortem

Andy Tripp antlr at jazillian.com
Thu Mar 13 11:38:05 PDT 2008


Darien Hager wrote:
>
>
> On 3/13/08, *Gavin Lambert* <antlr at mirality.co.nz 
> <mailto:antlr at mirality.co.nz>> wrote:
>
>     I had a fairly trivial DSL to parse and I wanted to throw it into
>     a codegen routine afterwards.  I noticed that there was this "AST"
>     option that said it would output a tree, which I thought would be
>     useful.  So I switched it on, and was puzzled that I didn't get a
>     tree out of it.  (I was basically expecting that by default every
>     time I called a subrule it would drop a level down in the tree.) 
>
>
> I had the same experience. However, the architectual impliciations behind action code creeped me out even more, so I kept looking :P
I started with ANTLR by using an existing (C) grammar, not my own from 
scratch.
In my case, it wasn't until I started wanting changes in the AST that I 
went to figure out
how the AST was being built. My first reaction was probably "wait, there 
are two things going on here, one is
to parse the input and the other is to build a tree...shouldn't those be 
two distinct steps? And then the realization that
building the AST involved little more than throwing in ^ and ! into the 
grammar. And finally, the realization that
there's no other reasonable way to do it.
>  
>
>
>     However I can see the other side of this too.  If ANTLR did
>     default to dropping a tree level for each subrule call, how would
>     you go ahout telling it to not do that?
>
>
> Could this be a tool-level solution? Parse the grammar 
> file, and automatically insert basic AST-rewrite rules to achieve the same effect? The benefit of this is that it involves no additional magic on ANTLR's part, and would be easier to customize if it turns  
> out that the grammar rules are best arranged in one way but the AST is 
> best arranged in another.
That would be an interesting project.
My guess is that you could use various heuristics to try to figure out 
what a reasonable AST might be.
But that approach of using heuristics and producing less-than-perfect 
output doesn't go over well with the compiler crowd.
>
>
> -- 
> Darien Hager
> Developer
> Etelos, Inc.
> darien at etelos.com <mailto:darien at etelos.com>
>
> http://www.etelos.com
> "Revolutionizing the way applications are developed, distributed and 
> consumed."
>
> This e-mail message, including attachments, may contain confidential 
> information for the sole use of the intended recipient(s). If you are 
> not the intended recipient, then this is notice that any use, 
> disclosure, dissemination, distribution or copying is strictly 
> prohibited. If you have received this message in error please contact 
> the sender by reply mail and destroy all copies of the original message.
> This e-mail message, including attachments, may contain confidential information 
> for the sole use of the intended recipient(s). If you are not the intended recipient,
> then this is notice that any use, disclosure, dissemination, distribution or copying is 
> strictly prohibited.  If you have received this message in error please contact the 
> sender by reply mail and destroy all copies of the original message.
>
>   

-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.antlr.org/pipermail/antlr-interest/attachments/20080313/8e801583/attachment-0001.html 


More information about the antlr-interest mailing list