[antlr-interest] Re: AST enhancements (forgot one)
Eric Mahurin
eric_mahurin at yahoo.com
Wed Aug 11 21:18:43 PDT 2004
--- In antlr-interest at yahoogroups.com, "Eric Mahurin"
<eric_mahurin at y...> wrote:
> While I'm thinking about it, here is a list of things that would be
> nice to have regarding AST's:
>
> 1. Allow for sub-rules to have there own root rather than always
> rooting the super-rule. This is described in the documentation as
> labeled sub-rules, but apparently is not implemented. Right now to
> get the right AST struture you have to partition the rules to get the
> right roots.
>
> 2. Allow rule references in addtion to token references to be rooted.
> This feature was described in my previous message. Right now you may
> have to flatten the rules to get the right roots.
>
> 3. Have a standard interface for separating/storing/retrieving
> children to the left vs. right of the root so that token order can be
> easily preserved. Right now with the way ASTFactory does things, the
> current interface can be used to get the token order correct, but the
> "addChild" definition must be changed (insert child at beginning
> instead of end). Instead, I think the interface and ASTFactory should
> assume that the AST's keep order, but the implementation wouldn't have
> to. Maybe all that is needed is a redefinition of addChild (insert to
> the left of the left children), and a few methods which return
> separate left and right children lists (non-ordered ASTs would return
> the whole list or nothing for these).
>
> 4. Consider using a more generic "List" like interface storing sibling
> lists. This way you can have implementations other than linked lists
> and you can get easy random access.
>
> 5. Add some symbol table stuff. It would be nice to be able to easily
> store symbol table data in the AST. I haven't thought through the
> details yet, but I was thinking you'd have some suffix to say you
> wanted something to be a key in a symbol table and the "children" ASTs
> would be the value for this entry. This could work similar to the "^"
> AST operator, but instead of making a root with children, it would
> make a map entry.
6. Make it simple to add extra tokens to the AST structure. It seems
like the majority (all?) of the time you resort to the # actions for
making AST's, you just end up putting in extra tokens in. Those #
actions seem hacky (and limited) anyways (like the $ stuff) - why not
just directly support inserting extra tokens. So, instead of:
decl : ( TYPE ID )+ { #decl = #([DECL,"decl"], #decl); } ;
you could do:
decl : [DECL,"decl"]^ ( TYPE ID )+ ;
Maybe go ahead and just support an AST constructor call here to give
all the flexibility. Doing it this new way seems much more
understandable. That # stuff seems very ugly since it is merged in
with Java and has syntax nothing like java (at least the $ stuff is
closer).
Yahoo! Groups Links
<*> To visit your group on the web, go to:
http://groups.yahoo.com/group/antlr-interest/
<*> To unsubscribe from this group, send an email to:
antlr-interest-unsubscribe at yahoogroups.com
<*> Your use of Yahoo! Groups is subject to:
http://docs.yahoo.com/info/terms/
More information about the antlr-interest
mailing list