C++ Meta Programming language

I

Ian

Jon said:
I thought about that. I could just keep the property info in xml and load it
up at runtime when I need too. While this is one way I feel its not the
optimal(because one still have to modify the xml for every change). (though
I think you are talking bout doing pre-compile time code generation and it
might be a viable alternative too)
Surely no matter what you do, you will have to change something when you
make a change? XML/XSLT (generation) and XML/DOM (parse at runtime) are
a powerful techniques of separating the structure from the content. We
currently use the latter, so we don't have to update our application
when the data changes.
I just feel that the compiler/pre-processor can handle the properties much
more efficiently than I can and basicaly it could automate much of the
process that I would end up having to do by hand(in any way that I had to do
it).

You still have to provide the content, don't you?

Ian
 
J

Jon Slaughter

Ian said:
Surely no matter what you do, you will have to change something when you
make a change?
heh, I can't argue with that ;)
XML/XSLT (generation) and XML/DOM (parse at runtime) are a powerful
techniques of separating the structure from the content. We currently use
the latter, so we don't have to update our application when the data
changes.

Well I don't have much experience with XML but I just brought 3 books on the
subjet. Basicaly I want to define a new type called a property. This is
sorta like making a defining a new type using a class so one can do some
very complex things using simple ideas(say for example using operator
overloading).

My idea is to create a new keyword in C++ called property

the syntax might be osmething like

property base_type type_name = default_value;

base_type is some complex data type such as the first 10 letters of hte
alphebet or the integer range 10 to 58.

then I could do stuff like

type_name.base_type and it will return a string representing the base type

or

type_name.range and it will return a list of the possible values(or a range
indicator such as 10..58 to represent numeric ranges).


or I'd rather define property as

property data_type type_name = range : default_value;

where data_type is one of the simple data type of C++(since thats all I need
for my application.

now, I can do all that using classes and make it pretty efficient on the
coding side... but its going to get pretty bloated. Theres no reason for me
to store the range of the base_type in its object(I could make it static
though) or its name.

The problem with that is I could have many many simple properties that all
have different ranges and I'd have to code a class for each range and type.

I could possibly do this using templates but I have to see if there are
going to be any pitfalls and see if it will work well for what I need(it may
or may not).

It would just be easier for if I could get the compiler/pre-processor to do
most of the work for me in a similar way that one uses templates and
polymorphism.


You still have to provide the content, don't you?

yes, but I don't want to provide it more than once and I don't want to have
to split it up over several parts of the program(because I believe that
leads to many problems).

While I'm not saying your method is wrong or not good enough, I am saying
that I am not sure it is the best... though it may or may not be. I think
actually the templates method would be better but I think that it is not
still not the best. The "best" method would be for "C++" to handle a
properties like keyword similar to what I have shown above. (ofcourse
theres more to it than that but I think it would be much more direct than
the other methods).


I'm going to mess around with templates and see what I get out of it. If its
not satisfactory then I'll go ahead and look at spirit and see what I can do
there(cause I think in the long run its probably better to go ahead and
implement some type of pre-processing so one can "patch" of C++'s
compile-time short-commings).



Jon
 
J

Jon Slaughter

Allan Wind said:
If you just want a pre-processor check out m4.


/Allan

Well, at first glance it seems its purely a macro driven pre-processor? I
need a little more power than that(else I'd just use C++'s). I'll look into
it some more later.

Thanks, Jon
 
M

Me

Basicaly I have some specific things I need to do and it
seems that the c++ language does not make them easy to do(and they are not
really worth while to do by "hand" in C++)... but if I could tell "program"
the pre-processor a little to do some simple things(like insert some code
somewhere(though at multiple places at once) then it would be a hell of a
lot easier.

Anything like that out there?

Among the other things mentioned in this thread, take a look at:
http://www.csg.is.titech.ac.jp/~chiba/openc++.html
 
J

Jon Slaughter

Me said:
Among the other things mentioned in this thread, take a look at:
http://www.csg.is.titech.ac.jp/~chiba/openc++.html

Looks very nice. I think it might be exactly what I need all wrapped up in
one package. Though it seems that it is a compiler and not just a
translator. What I really want is to parse a "C++" file and generate a new
C++ that is compatible with most C++ compilers. (cause I don't know how good
the openC++ compiler is and not sure if I would want it to compile my
programs). I'm looking at it now and downloading and going to see what its
all about.


Thanks!

Jon
 
M

Matthieu Villeneuve

Donovan Rebbechi said:
Much easier to do this with interpreted languages -- you can literally
create and execute classes on the fly. I have actually done this in
python (for example). In an interpreted language, you just need to
generate the strings, and eval them.

This does not require the language (or implementation, rather) to be
interpreted, for example, compiled Common Lisp programs can create and
modify classes at runtime...
 
I

Ira Baxter

Jon Slaughter said:
Looks very nice. I think it might be exactly what I need all wrapped up in
one package. Though it seems that it is a compiler and not just a
translator. What I really want is to parse a "C++" file and generate a new
C++ that is compatible with most C++ compilers. (cause I don't know how good
the openC++ compiler is and not sure if I would want it to compile my
programs). I'm looking at it now and downloading and going to see what its
all about.

[OpenC++ does not compile programs. It translates them from
C++, perhaps with idiom extensions, into vanilla C++.
It also has a number of limitations; IIRC, it doesn't do templates,
it doesn't preserve macros, ...]

The DMS Software Reengineering Toolkit is generalized compiler technology
that can parse/analyze/transform massively programs in many languages,
including C++. It handles the full C++ language in a number of dialects:
ANSI, GNU 3, MS 6, MS managed C++ and MS C++ CLI.
It has been used for massive C++ source code reengineering tasks.

See http://www.semdesigns.com/Products/FrontEnds/CppFrontEnd.html.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,743
Messages
2,569,478
Members
44,898
Latest member
BlairH7607

Latest Threads

Top