views:

41

answers:

1

Hi, I was wondering if someone uses a generic preprocessor for manipulating text files.

The idea came up, as Java does not have a preprocessor, but I'd like to have conditional code compilation, etc.

Now, taking that idea further, I might as well use a generic preprocessor for any kind of files that need frequent editing, but all edits are in a similar manner.

Now, there's good ol' m4 which I'd like to use as I use the C-preprocessor and there is GPP, that one however, stopped being developed in 2007.

I'd like some suggestions which preprocessor is preferable, if possible, it should take directives the same way C-preprocessor takes them #define SOMETHING.

Since m4 doesn't use sigils or something, it might collide with other code, when m4 is the way to go, I'd need advice on how to prefix every directive with a sigil or a different prefix or something.

A: 

Most C/C++ compilers allow you to just run the preprocessor and save the output, and can be used on generic input. (for Visual C++, I blieve the option is /P)

But remember the preprocessors cause as many problems as they solve. The designers of both C++ and Java have tried hard to eliminate the need for using the preprocessor. For example, in Java, code like this:

if (true)
     CallThis();
else
     DoNotCallThis();

will just generate code for the CallThis() call and not generate code for the condition or the else branch. (This is not a qulaity of Implemetation issue --- it's a requirement of the Java language definition).

James Curran
I'm gonna do a field test with m4, since this is the most common used language and see if I'm happy with it.I'll test GPP here and there, though I'm not really confident this is gonna hold up.
polemon
You were right, the preprocessor directives made somewhat the code unreadable, but I guess there's not much what I can do about it. I'm using it with shell scripts and makefiles. Anyway, using m4 and cpp, is pretty much of a hassle...
polemon