[antlr-interest] LPG WAS Retaining comments

Jim Idle jimi at temporal-wave.com
Thu Mar 13 10:06:24 PDT 2008



> -----Original Message-----
> From: Andy Tripp [mailto:antlr at jazillian.com]
> Sent: Thursday, March 13, 2008 8:31 AM
> To: Jim Idle
> Cc: antlr-interest at antlr.org
> Subject: Re: [antlr-interest] LPG WAS Retaining comments
> 
> Jim Idle wrote:
> > [snip snide remarks about parse trees and ASTs]
> > ...Good Grief
> Yea, I probably need to take an anger management class.
> 
> I'm pretty sure it was the lack of an answer to "what good is a flat
> AST?" that set me off.
> So much so that I've lowered my estimate of its usefulness from 1% down
> to 0%.

Nobody said that there was any such use. I could make one up, but that would be pretty pointless. Oh well, suppose that your parser just works with the lexer to get some intermediate token form, but the language is such that you can't really infer any structure at that point as you need multiple passes to work anything out at all. Then your parser might build symbols (or just leave it to an AST walk), then pass the unshaped tree along for actual shaping now that it knows something about

But, as I said a bunch of times, whether a flat tree is any good or not is utterly and completely not the point. It is just that any auto generated structure probably isn't any better. The point is that spending a lot of effort to try and produce a tree automagically makes no sense, as it will undoubtedly be worth very little to anyone. The parse tree is only useful if you really want to do something with parser tree, which more than likely is just display it, so there is no real point making that the default tree. Basically as soon as you want to actually do something with the tree beyond look at it in ANTLRWorks, which gives you the parser tree anyway, you will realize that you need to formulate you own structure. Hence, a default structure isn't really of any use to anyone, not even people new to the idea. Most people will know what 'tree' means, but then need to work out what parser tree vs AST means and will soon be on their way to using it effectively.

> 
> The "Trust me, I translate from one non-trivial language to another
> without needing an AST,
> but I wont give any details at all" thread from someone else is really
> bugging me, too.

Well, all the poster was saying (I think) is that he was able to write a translator by just using actions in the parser. I have done the same thing in the past. However, what Loring was trying to say (and most would agree I think), is that as soon as you get to a non-trivial case, while you can probably find a way to do without, you will find it better on many levels to construct an AST. I don't think that that is in any way a contentious statement.

Anyway, I have spent enough time on this and probably bored the pants off everyone, so I think I will fix the reported 3.1 C runtime bugs instead ;-)

Jim






More information about the antlr-interest mailing list