[antlr-interest] LPG WAS Retaining comments
Andy Tripp
antlr at jazillian.com
Wed Mar 19 08:13:17 PDT 2008
Olivier Lefevre wrote:
> Olivier Lefevre wrote:
>> I still think it useful to think of the parse tree as something the
>> tool will build for you automatically (if you ask it to) whereas the
>> AST is something _you_ must build, making _all_ the decisions.
No, ANTLR will build you an AST when you specify "output=AST", even if
you don't give it any instructions for doing so (putting ^ chars in
your grammar). It's just that the "tree" will degenerate/flat.
That doesn't seem like a good thing to me, and that's what I was
arguing in that other thread.
>
> To elaborate just a tiny bit, you might say this is a superficial
> difference but if you ask a tree from the tool it will of necessity
> return a parse tree because that's the only thing it can return
That's what it *should* do, IMHO, but that's not what it does.
(it
> can't possibly know what kind of AST you want) whereas if you build the
> tree you will, well, not "of necessity" but almost certainly build an
> AST of sorts, reflecting your post-processing needs and thus the
> semantics of the language. Thus in practice the parse tree vs. AST
> divide tends to overlap neatly with the by-default vs. explicitly built
> divide.
I agree with you, but I think most here don't.
>
> -- O.L.
>
More information about the antlr-interest
mailing list