[antlr-interest] tree walking and semantic analysis
Carter Cheng
carter_cheng at yahoo.com
Wed Feb 4 23:44:57 PST 2009
Thanks Andy.
--- On Wed, 2/4/09, Andy Tripp <antlr at jazillian.com> wrote:
> From: Andy Tripp <antlr at jazillian.com>
> Subject: Re: [antlr-interest] tree walking and semantic analysis
> To: carter_cheng at yahoo.com
> Cc: antlr-interest at antlr.org
> Date: Wednesday, February 4, 2009, 7:04 AM
> Hi Carter,
>
> Sounds like you should just walk the AST "by
> hand".
> I think the ANTLR treewalkers are geared more toward simple
> cases where you have
> just a few actions at various points in the AST.
> See
> http://www.antlr2.org/article/1170602723163/treewalkers.html
> for more info.
>
> Andy
>
> Carter Cheng wrote:
> > Hi Andy and the others,
> >
> > Thanks for the reply. I am currently reworking my tree
> code and doing it somewhat manually because I was having
> some difficulties with working with the C runtime in C++
> mode. The difficulty I was having was something along these
> lines-
> > program[int pass] : (declarations[pass])*
> > ;
> > declarations[int pass]
> > : /* some CFG rule case */ { switch(pass) { /* do
> something depending on the pass */ } }
> > ;
> >
> > This obviously seems like quite a mess. Especially
> when in different passes you need to percolate different
> types of data up the tree and left to right depending on the
> pass.
> > A possible alternative is to using some sort of
> visitor or function object which behaves differently on each
> pass. However I am not quite sure how to get this to work
> properly. The issue primarily is with the return value types
> in my language I have certain expression constants which
> need to be checked and if possible reduced to their actual
> values in certain descents of the grammar and in other cases
> return the whole expression tree-
> > declaration[Functor f] returns [??? retval ]
> > : /* some CFG rule case */ { $retval = f(e); }
> > ;
> >
> > The return type can be quite different depending on
> the functor in question making it somewhat difficult to
> determine what the type of retval should be.
> > This is getting a bit long I suspect with the error
> situation with multiple errors the only thing that can be
> done is return something... pass in some sort of functor or
> I/O stream which can be used to dump data back to the user
> etc.
> >
> > I hope that sort of makes sense.
> >
> > Regards,
> >
> > Carter.
> >
> >
> >
> > List:
> http://www.antlr.org/mailman/listinfo/antlr-interest
> > Unsubscribe:
> http://www.antlr.org/mailman/options/antlr-interest/your-email-address
> >
More information about the antlr-interest
mailing list