Re: How to parse and call c++ constructors?
- From: Chris F Clark <cfc@xxxxxxxxxxxxxxxxxxxx>
- Date: 23 Sep 2005 15:56:50 -0400
Groleo wrote:
> So, to show the actions too:
> A { <-- a =new A();
> B { <-- a->_b =new B();
> text="cucu" <-- a->_b->text = $2;
> }
> }
>
> So again this is translated into:
>
> a->_b->text = $2; //error: a was not allocated, b was not allocated
> a->_b =new B(); //error: a was not allocated.
> a =new A();// too late :)
>
> How can this be done without errors?
With an LR parser, it is easiest if you put the actions at the end and
don't depend on your "calling" rule (the context).
> A {
> B {
> text="cucu"
> } <-- b =new B(); b->text = $2;
> } <-- a =new A(); a->b = $1;
Of course, since all you are doing is building an AST to capture the
input, you should probably use a tool that will automatically
construct the AST for you. It will make your life easier as you will
write less code (that is less code which you *might* get wrong, and
thus might have to debug).
Hope this helps,
-Chris
*****************************************************************************
Chris Clark Internet : compres@xxxxxxxxxxxxx
Compiler Resources, Inc. Web Site : http://world.std.com/~compres
23 Bailey Rd voice : (508) 435-5016
Berlin, MA 01503 USA fax : (978) 838-0263 (24 hours)
.
- References:
- How to parse and call c++ constructors?
- From: Groleo
- Re: How to parse and call c++ constructors?
- From: Hans-Peter Diettrich
- How to parse and call c++ constructors?
- Prev by Date: Re: Parsing Expression Grammar
- Next by Date: Re: generated code
- Previous by thread: Re: How to parse and call c++ constructors?
- Next by thread: Interpreter Memory Models?
- Index(es):
Relevant Pages
|
|