[antlr-interest] De-emphasizing tree grammars?

Terence Parr parrt at cs.usfca.edu
Tue Dec 27 11:08:52 PST 2011

On Dec 26, 2011, at 2:54 PM, Gavin King wrote:

> This all looks reasonable to me. The only doubt I have is how close
> the structure of the parse tree is to the AST in a complex grammar. I

Well, an AST does not have rule nodes so they will always be very different.

> imagine that in most cases it's very close, so probably not a major
> issue. Still, it might be nice to be able to mark a rule as not
> producing a node in the typesafe parse tree.

I thought about that, but since the rule invocation stack/tree of context objects does double duty for holding context and representing the final parse tree, it's hard to remove some of the nodes. For example, if there's an error in a rule that we told to drop from the parse tree, there's no way for me to provide that information to an IDE or whatever.

> There might even be some
> other stuff you could provide to allow a bit of additional control
> over the resulting tree. However, I can understand if that's a
> non-goal - it's still going to be much, much easier to transform the
> parse tree to an AST.

Yep, We should also set it up so that you can create new subtrees using concrete syntax. The following would start parsing at rule stat and return a tree given the string input.

parse("stat", "while (i>3) {...}");


More information about the antlr-interest mailing list