How to parse and call c++ constructors?



Hi.

I have the following problem:

Given a file,:

A {
B {
text="cucu"
}
}

it;s parsed like:
text=cucu
B
A.


But to make this usefull, I wanted to fill up a datastructure:
struct B {
char* text;
};

struct A {
struct B _b;
};

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



Relevant Pages


Loading