[antlr-interest] saving, duplicating and substituting tree nodes in the C API

David Minor dahvid.minor at gmail.com
Mon Sep 7 10:14:06 PDT 2009


Hi Jim,
What is the right way to do it?  I can save the $rule.tree but when I
encounter the already bound variable, which will be in another expression,
how do I substitute $rule.tree for it? That's the question, it will
definitely be in a symbol table at any rate.

in semi-psuedo code:

bound_function :


On Sun, Sep 6, 2009 at 5:53 PM, Jim Idle <jimi at temporal-wave.com> wrote:

> 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
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.antlr.org/pipermail/antlr-interest/attachments/20090907/71139352/attachment.html 


More information about the antlr-interest mailing list