how to remove comment from c source code.
removing comment
Collapse
This topic is closed.
X
X
-
daskumardilip@gmail.comTags: None -
David Marsh
Re: removing comment
daskumardilip@g mail.com wrote:Select it and press "delete."how to remove comment from c source code.
>
David
-
vimComment
-
xianwei
Re: removing comment
On Sep 26, 8:55 pm, daskumardi...@g mail.com wrote:If you use VIM, I think the built-in regxp is a good idea.how to remove comment from c source code.
But I not good at it, so I can't help you~~~~
Comment
-
Walter Roberson
Re: removing comment
In article <1190814438.015 492.177410@n39g 2000hsh.googleg roups.com>,
vim <vgstech@gmail. comwrote:You cannot reliably detect comments using regular expressions.>Use text processing languages
>lex and yaac
>Use regular expressions in that
#define COMMENT /*
#define ENDCOMMENT */
COMMENT
this is a comment
#ifdef __GCC
ENDCOMMENT
#error The license of this example forbids use under GCC
#else
Ah, that's better
ENDCOMMENT
#endif
#include <stdio.h>
int main(void) { printf("Hello /*\"Zippity\"*/World"); return 0; }
The points:
- comments can be triggered by macros
- comment formation is affected by preprocessor conditions that a
textual parser cannot know the answer to
- inside string literals, comment-like sequences are just
regular characters
- determining whether you are inside a string literal requires
matching double-quotes, which is made non-trivial due to
backslashes
Summary:
You cannot remove comments from source without something approaching
the power of the preprocessor, with complete knowledge of the
defines in effect.
--
I was very young in those days, but I was also rather dim.
-- Christopher Priest
Comment
-
Richard Heathfield
Re: removing comment
Walter Roberson said:
<snip>
Comment removal occurs before macro expansion.- comments can be triggered by macros
<snip>
--
Richard Heathfield <http://www.cpax.org.uk >
Email: -http://www. +rjh@
Google users: <http://www.cpax.org.uk/prg/writings/googly.php>
"Usenet is a strange place" - dmr 29 July 1999
Comment
-
CBFalconer
Re: removing comment
daskumardilip@g mail.com wrote:Consider the DELETE key.>
how to remove comment from c source code.
--
Chuck F (cbfalconer at maineline dot net)
Available for consulting/temporary embedded and systems.
<http://cbfalconer.home .att.net>
--
Posted via a free Usenet account from http://www.teranews.com
Comment
-
Eric Sosman
Re: removing comment
Walter Roberson wrote On 09/26/07 10:07,:This much defines COMMENT as an object-likeIn article <1190814438.015 492.177410@n39g 2000hsh.googleg roups.com>,
vim <vgstech@gmail. comwrote:
>>>>Use text processing languages
>>lex and yaac
>>Use regular expressions in that
>
You cannot reliably detect comments using regular expressions.
>
>
#define COMMENT /*
#define ENDCOMMENT */
macro with an empty replacement list.
This expands COMMENT, producing nothing at all.COMMENT
This is syntax error, and there's no pointthis is a comment
in further analysis.
If "triggered by" means "generated by expansion of,"[...]
The points:
- comments can be triggered by macros
this is false.
False.- comment formation is affected by preprocessor conditions that a
textual parser cannot know the answer to
True. The same holds for character literals, too:- inside string literals, comment-like sequences are just
regular characters
char c = '/* no comment starts here';
char d = '// nor here';
True.- determining whether you are inside a string literal requires
matching double-quotes, which is made non-trivial due to
backslashes
False. The preprocessor has no knowledge of comments,Summary:
You cannot remove comments from source without something approaching
the power of the preprocessor, with complete knowledge of the
defines in effect.
no influence on comments, and nothing to do with comments.
You need only a lexical analyzer; no knowledge or processing
of macros is required or desired.
--
Eric.Sosman@sun .com
Comment
-
Tor Rustad
Re: removing comment
Walter Roberson wrote:Of course we can, I have even written such a lex spec myself. :)In article <1190814438.015 492.177410@n39g 2000hsh.googleg roups.com>,
vim <vgstech@gmail. comwrote:>>Use text processing languages
>lex and yaac
>Use regular expressions in that
You cannot reliably detect comments using regular expressions.
IIRC, the "lex & yacc" book, even provide an example for the /**/
comments, and handling the // comment case is easier.
#define COMMENT /*
#define ENDCOMMENT */
COMMENT
this is a comment
#ifdef __GCC
ENDCOMMENT
Wrong. After translation phase:
1. Trigraph replacement
2. Line-splicing
3. replace WS sequences & comments with a space
this reads:
#define COMMENT
COMMENT
this is a comment
Macro expansion comes in translation phase 4.
--
Tor <torust [at] online [dot] no>
Comment
-
Walter Roberson
Re: removing comment
In article <N7ydnZGjJuZAEm fb4p2dnAA@telen or.com>,
Tor Rustad <tor_rustad@hot mail.comwrote:>Walter Roberson wrote:>You cannot reliably detect comments using regular expressions.lex does not use strict regular expressions. lex and yacc together>Of course we can, I have even written such a lex spec myself. :)
are LALR, which requires a pushdown stack, a feature missing
in regular expressions.
--
Programming is what happens while you're busy making other plans.
Comment
-
Lew Pitcher
Re: removing comment
On Sep 26, 8:55 am, daskumardi...@g mail.com wrote:Search the web for Richard Heathfields page on solutions to problemshow to remove comment from c source code.
posed in K&R2
You are looking for the solutions to exercise 1-23. Many of the
regular clc participants contributed solutions, although (IIRC) not
many offered bulletproof implementations .
Look here -http://users.powernet.co.uk/eton/kandr2/krx123.html if
nowhere else <grin>
HTH
--
Lew
Comment
-
Keith Thompson
Re: removing comment
Eric Sosman <Eric.Sosman@su n.comwrites:[...]Walter Roberson wrote On 09/26/07 10:07,:I agree with your conclusion, but not necessarily with your statement>>Summary:
> You cannot remove comments from source without something approaching
> the power of the preprocessor, with complete knowledge of the
> defines in effect.
False. The preprocessor has no knowledge of comments,
no influence on comments, and nothing to do with comments.
You need only a lexical analyzer; no knowledge or processing
of macros is required or desired.
that the preprocessor has no knowledge of comments.
The standard defines 8 translation phases. Comments are replaced by
space characters in phase 3; preprocessing directives are executed and
macros are expanded in phase 4. But the standard doesn't define what
"the preprocessor" is. In an implementation which has a distinct
"preprocess or" component, perhaps a separate program, that program
could handle phases 1 through 4, or 1 through 5, or even 1 through 6.
(See C99 5.1.1.2 for the descriptions of the translation phases.)
--
Keith Thompson (The_Other_Keit h) kst-u@mib.org <http://www.ghoti.net/~kst>
San Diego Supercomputer Center <* <http://users.sdsc.edu/~kst>
"We must do something. This is something. Therefore, we must do this."
-- Antony Jay and Jonathan Lynn, "Yes Minister"
Comment
-
Keith Thompson
Re: removing comment
daskumardilip@g mail.com writes:As you've seen from the variety of responses, you need to be morehow to remove comment from c source code.
specific in your question. You can remove comments manually, or you
can write a program to do it automatically, or you can use some
existing program. Or you can print out the C source code and write
over the comments with a black marker.
What exactly are you trying to do, and *why* do you want to remove
comments? The only good reason I can think of for doing so is if
you're writing a compiler, but in that case you've got a lot of work
ahead of you.
--
Keith Thompson (The_Other_Keit h) kst-u@mib.org <http://www.ghoti.net/~kst>
San Diego Supercomputer Center <* <http://users.sdsc.edu/~kst>
"We must do something. This is something. Therefore, we must do this."
-- Antony Jay and Jonathan Lynn, "Yes Minister"
Comment
-
Richard Heathfield
Re: removing comment
Lew Pitcher said:
Please don't look there. Look here instead:On Sep 26, 8:55 am, daskumardi...@g mail.com wrote:>>how to remove comment from c source code.
Search the web for Richard Heathfields page on solutions to problems
posed in K&R2
You are looking for the solutions to exercise 1-23. Many of the
regular clc participants contributed solutions, although (IIRC) not
many offered bulletproof implementations .
>
Look here -http://users.powernet.co.uk/eton/kandr2/krx123.html if
nowhere else <grin>
--
Richard Heathfield <http://www.cpax.org.uk >
Email: -http://www. +rjh@
Google users: <http://www.cpax.org.uk/prg/writings/googly.php>
"Usenet is a strange place" - dmr 29 July 1999
Comment
-
Tor Rustad
Re: removing comment
Walter Roberson wrote:[snipped context and good advice by vim added]In article <N7ydnZGjJuZAEm fb4p2dnAA@telen or.com>,
Tor Rustad <tor_rustad@hot mail.comwrote:>Walter Roberson wrote:
>>vim said:
>>>"Use text processing languages
>>>lex and yaac
>>>Use regular expressions in that"Well, yacc is a LALR parser, but that's beside the point, since yacc>>>You cannot reliably detect comments using regular expressions.>>Of course we can, I have even written such a lex spec myself. :)
lex does not use strict regular expressions. lex and yacc together
are LALR, which requires a pushdown stack, a feature missing
in regular expressions.
isn't needed here. OP's request can be done with lex alone, see e.g.
"lex and yacc" example 2-9, or look at
for ideas. Another alternative, is writing a small C program, an
untested initial version, took me ca. 15 minutes to write.
--
Tor <torust [at] online [dot] no>
Comment
Comment