4 points · by DiabloD3 · 14y ago · 6 comments
Are there any language aware preprocessors out there that would allow me to define new syntax for C without descending into CPP hell (or, alternatively, not make the code gcc only)?
Edit: I'm trying to avoid sed and m4. Please don't make me use m4, I beg of you.
Thus the cynic in me wants to answer, "to prevent a C+++."
Also, IIRC, programming languages with mutable syntax were generally acknowledged to be a bad idea around the time C was being born. Something about every program being written in a different language :-)
That said, metaprogramming certainly has a place, particularly when creating state machines in code (e.g. yacc, lex, re2c, ragel). It makes you wish for a standard way, but C is a conservative language, and I think that's been a key to its success.
i don't know of a good preprocessor/template engine that does what you want (i had a similar need recently and came to the conclusion that there's a hole here - but i don't know m4 well enough to know what a replacement should look like). could you not use some language that compiles to c (gambit springs to mind) or switch to go (i haven't used go much, but from a little experience it strikes me as a very good "better c").
i guess another option is to look at the llvm toolchain. maybe you can hack their c front-end...?