[antlr-interest] Using Tree Interface not plain Object

Terence Parr parrt at cs.usfca.edu
Sun Sep 4 12:22:14 PDT 2011


Hi. Currently v3 requires nothing of your tree nodes; all you have to do is give me an adapter that says how to create them and navigate them and manipulate them. Users can set up ASTLabelType as an option so that $x in actions has the user's type instead of plain object.

Sam Harwell and I were talking today about restructuring all of the tree interfaces. We're breaking it up into a hierarchy with Tree interface at the top. Tree just says you can get a payload, some children, and parent. ParseTree and AST split off as sub interfaces. We were thinking that it's pretty silly to use simple object when we could require the minimal Tree interface so at least code could display or navigate them. The reason I went with plain object originally was so people could use any existing object they have, even if they only have binary for it. This seems like a fairly extreme example and, in the worst case, somebody could wrap those objects so they were suitable for use with ANTLR. More than likely, somebody in that situation would simply use actions to construct the trees they want. Most trees not built for antlr expect everything in the constructor, whereas antlr has to build up the trees piecemeal as it parses.

So, does anybody object to ANTLR assuming Tree in the parser if you are building trees and then AST in the tree parsers?

Ter


More information about the antlr-interest mailing list