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



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)
.



Relevant Pages

  • Re: Miltu-core CPUs, threads vs AST driven approaches
    ... The way to do that is to run the several 'worker' threads at normal (not AST) level, and use the AST routines only to process I/O completion and as part of that completion move the continuation context for the relevant activity onto a 'to do' queue, which each thread visits whenever it has no processing to do. ... This preserves VMS's guarantee that no more than one AST will be active at a time, and the extremely brief processing required at AST level (compared with the processing required in each thread between interruptions) ensures that this will not impede progress even if many processors are working in parallel in the single process. ... The main gotcha here is that *all* the context for each operation must be held in that queued context structure, rather than conveniently on a thread's stack - since the thread's stack gets unwound before each such interruption. ...
    (comp.os.vms)
  • Re: WORKING_SET.COM gives all COM states when run at high priority
    ... > When you're executing that AST I posted to you. ... You've taken this out of the context of the thread to which I posted it. ... Yes it will be become COMputable and, eventually, CURrent when an AST is ... "Well my son, life is like a beanstalk, isn't it?" ...
    (comp.os.vms)
  • Re: WORKING_SET.COM gives all COM states when run at high priority
    ... >> When you're executing that AST I posted to you. ... > You've taken this out of the context of the thread to which I posted it. ... denizens firing off SKASTs! ...
    (comp.os.vms)