David Minor wrote: > I'm working on a language that allows assignment of functions to > variables. > Something like this. > fun = execute(params); > > Later in the same scope if I want to do. > another_fun = fun > > The most natural way to do this > seems to me to save the tree from the first execute(params) in a > symbol table > and then, while generating the AST, when I see that "fun" is defined, > to substitute a duplicate of it's tree for the assignment to another_fun. That doesn't sound like the correct way to do things to be honest, the AST is just the parsed elements and you probably need to do a lot more with these than just store them? Linguistically, that looks very confusing, you shoudl probably use a different operator than = :-) > > The trouble is the symbol table is in C world not Antlr. It looks > like I could just duplicate the node save > the pointer and then re-use it, but I don't see any examples of how to > do this. > > Does anyone have an idea? Even a Java example would be helpful. > What are you trying to do/build? An interpreter? Basically, you should do as little as possible in the parser other than the basics such as build the symbol table if that is a a possibility (you know what all the types are while you are parsing etc). Generally, you would not want to duplicate the sub-tree for a symbol table but you can just reuse the pointer anyway as it is returned by the rule that parses your function. $rule.tree should do it I think.
Jim List: http://www.antlr.org/mailman/listinfo/antlr-interest Unsubscribe: http://www.antlr.org/mailman/options/antlr-interest/your-email-address --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "il-antlr-interest" group. To post to this group, send email to [email protected] To unsubscribe from this group, send email to [email protected] For more options, visit this group at http://groups.google.com/group/il-antlr-interest?hl=en -~----------~----~----~----~------~----~------~--~---
