Re: How to parse and call c++ constructors?

Chris F Clark <cfc@shell01.TheWorld.com>
23 Sep 2005 15:56:50 -0400

          From comp.compilers

Related articles
How to parse and call c++ constructors? groleo@gmail.com (Groleo) (2005-09-17)
Re: How to parse and call c++ constructors? Meyer-Eltz@t-online.de (Detlef Meyer-Eltz) (2005-09-18)
Re: How to parse and call c++ constructors? Juergen.Kahrs@vr-web.de (=?ISO-8859-1?Q?J=FCrgen_Kahrs?=) (2005-09-22)
Re: How to parse and call c++ constructors? pohjalai@cc.helsinki.fi (A Pietu Pohjalainen) (2005-09-22)
Re: How to parse and call c++ constructors? DrDiettrich@compuserve.de (Hans-Peter Diettrich) (2005-09-22)
Re: How to parse and call c++ constructors? groleo@gmail.com (Groleo) (2005-09-22)
Re: How to parse and call c++ constructors? cfc@shell01.TheWorld.com (Chris F Clark) (2005-09-23)
| List of all articles for this month |

From: Chris F Clark <cfc@shell01.TheWorld.com>
Newsgroups: comp.compilers
Date: 23 Sep 2005 15:56:50 -0400
Organization: The World Public Access UNIX, Brookline, MA
References: 05-09-072 05-09-092
Keywords: parse, C++
Posted-Date: 23 Sep 2005 15:56:50 EDT

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@world.std.com
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)


Post a followup to this message

Return to the comp.compilers page.
Search the comp.compilers archives again.