I have an assignment for my Programming language project to create a
compiler that takes a C++ file as input and translate it into the C
file. Here I have to take care of inheritance and operator overloading
and virtual functions. I mean it should not hamper the C++ meaning. In
frank and simple terms i need to implement a small C++ compiler in C++,
and i want the intermediate representation to be C. Please help me in
this.
I have now read a few dozen messages in what seems like a
dozen newgroups. Unfortunately, you have not IMO fully
told us all that you're seeking.
I am also surprised that nobody seems to have mentioned
Lippman's "Inside the C++ Object Model"
(see
http://www.comeaucomputing.com/booklist for ISBN info)
which discusses some of the issues involved in such a
translation, and some actual model suggestions of what
can be sought and implemented.
I am further surprised at how easy and trivial some of
the posters are making the assignment. This project is not
just about macro substituting the keyword class and replacing
it with struct. And the overloading part is not just about
text substituting void foo() into void foo(void).
You mention "i need to implement a small C++ compiler in
C++" however, to "take care of inheritance and operator
overloading and virtual functions" is quite a tall order
by itself. So it's unclear where "small" comes in.
To do it, means have to have written something of the scale
of a C compiler already (this does not mean you need to start
with a C compiler but that something will need to exist
underlying that accepts basic types, basic etc), with all
it's anomalies, subtleties, semantics, etc. And then
add on tons of stuff.
Implementing virtual functions implies a whole slew of
issues be established first. Function overloading is
hardly understandable no less implementable correctly,
and also implies a whole different slew of issues be
understood and implemented first.
Trying to do what it sounds like you're requesting before
end of June is not practical, unless you really are limiting
the features, like no templates, no exceptions, no namespaces,
no preprocessor (which implies no includes, etc), no comments,
no multiple inheritance, no RTTI, and no doubt hundreds of
other 1/2 or non-implementations of other features,
no bool/wchar_t/etc, no conditional declarations, most things
for classes missing (no initializers, member lists, mutable,
explicit, covariant return types, accessibility, class new/delete,
etc.), no typesafe linkage, no new style casts, no nested classes,
no friends, completely different lookup rules (which competes
with getting overloading working), and the list goes on and on.
Contrary to some posts in the numerous NGs you posted your
message in, a full blown compiler is a multi-man year effort.
Even w/o all the above exclusions, it's still a tall order to
start from scratch and still get simple inheritance and simple
operator overloading (sic) working by June.
So, what is the subset you're seeking? Did the teacher give
out an exact list of the subset? Or is this for say a Phd
where you get to define what the project is about?
Lastly, but not least, doing a project of this nature is not
something you just sit down and do, and is not something that
you just sit down and start anywhere. It has its own set of
implications as well: organization, grammars, design,
understanding the subset, etc etc etc.