I'm looking for Python code that removes C and C++ comments from a string. (Assume the string contains an entire C source file.)
I realize that I could .match() substrings with a Regex, but that doesn't solve nesting /*, or having a // inside a /* */.
Ideally, I would prefer a non-naive implementation that properly handles awkward cases.
The regular expression cases will fall down in some situations, like where a string literal contains a subsequence which matches the comment syntax.  You really need a parse tree to deal with this.
Remove C and C++ comments using Python?