This is the mail archive of the
gcc-help@gcc.gnu.org
mailing list for the GCC project.
Re: Re: Can `cpp' strip off comments in C source code?
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.