Can `cpp' strip off comments in C source code?
NightStrike
nightstrike@gmail.com
Mon Dec 24 11:15:00 GMT 2007
On 12/24/07, PRC <panruochen@gmail.com> wrote:
> Things are a little complicated. I've googled a sed script on:
> http://sed.sourceforge.net/grabbag/scripts/remccoms2.sh.txt
>
> But the script can't handle this testcase:
> printf("/* Haha \n"); /* Haha */
> printf("// Haha \n"); // Haha
>
> I think a simple regular expression filter is not enough. A lexical parsing is required to ensure the results come out right in all cases.
> A prefessional utility is more suitable than a script written by me since I am not an expert in ANSI C standard.
>
> >AWK itself can do it, as can sed.
>
>
Here's an AWK solution for you:
http://newsgroups.derkeiler.com/Archive/Comp/comp.lang.awk/2006-03/msg00200.html
See if it suits your needs. For something like this, I think awk
might be more capable than sed... not sure, though.
More information about the Gcc-help
mailing list