Using the C Preprocessor for languages other than C

c-preprocessor

Solution

You can call CPP directly:

cpp <file>

Rather than calling it through gcc:

gcc -E filename

Do note however that, as mentioned in the same Wikipedia article, C preprocessor's language is not really equipped for general-purpose use:

However, since the C preprocessor does not have features of some other preprocessors, such as recursive macros, selective expansion according to quoting, string evaluation in conditionals, and Turing completeness, it is very limited in comparison to a more general macro processor such as m4.

Have you considered dabbling with a more flexible macro processing language, like the aforementioned m4 for instance?

Problem

The Wikipedia entry for the C Preprocessor states: The language of preprocessor directives is agnostic to the grammar of C, so the C preprocessor can also be used independently to process other types of files. How can this be done? Any examples or techniques? EDIT: Yes, I'm mostly interested in macro processing. Even though it's probably not advisable or maintainable it would still be useful to know what's possible.

Original source