in reply to Re: Help Creating a Code Filter
in thread Help Creating a Code Filter

I agree that the Right Thing is to create a grammar and use a real parser, and that Parse::RecDescent is relatively easy to use. However, if this conversion is a one-off thing, or if you can't easily come up with a grammar for the source language (e.g. it's an ad-hoc language), the regexp approach can get the job done. Furthermore, it's easier to ignore parts of the language you don't understand using regexps.

If you do take the regexp approach, I would suggest doing the conversion in multiple passes, e.g. remove the comments, then convert the small/local constructs, then convert the larger ones. You probably also want to order your patterns from most-specific to most-general. You are lucky that you're running the result through a C++ compiler, since if you mistranslate something, odds are good that the compiler will catch it.