473,386 Members | 1,674 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

removing comment

how to remove comment from c source code.

Sep 26 '07 #1
14 3843
da***********@gmail.com wrote:
how to remove comment from c source code.
Select it and press "delete."

David
Sep 26 '07 #2
vim
Use text processing languages
lex and yaac
Use regular expressions in that

Sep 26 '07 #3
On Sep 26, 8:55 pm, daskumardi...@gmail.com wrote:
how to remove comment from c source code.
If you use VIM, I think the built-in regxp is a good idea.
But I not good at it, so I can't help you~~~~

Sep 26 '07 #4
In article <11**********************@n39g2000hsh.googlegroups .com>,
vim <vg*****@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 */
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
Sep 26 '07 #5
Walter Roberson said:

<snip>
- comments can be triggered by macros
Comment removal occurs before macro expansion.

<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
Sep 26 '07 #6
da***********@gmail.com wrote:
>
how to remove comment from c source code.
Consider the DELETE key.

--
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

Sep 26 '07 #7
Walter Roberson wrote On 09/26/07 10:07,:
In article <11**********************@n39g2000hsh.googlegroups .com>,
vim <vg*****@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 */
This much defines COMMENT as an object-like
macro with an empty replacement list.
COMMENT
This expands COMMENT, producing nothing at all.
this is a comment
This is syntax error, and there's no point
in further analysis.
[...]
The points:
- comments can be triggered by macros
If "triggered by" means "generated by expansion of,"
this is false.
- comment formation is affected by preprocessor conditions that a
textual parser cannot know the answer to
False.
- inside string literals, comment-like sequences are just
regular characters
True. The same holds for character literals, too:

char c = '/* no comment starts here';
char d = '// nor here';
- determining whether you are inside a string literal requires
matching double-quotes, which is made non-trivial due to
backslashes
True.
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.

--
Er*********@sun.com
Sep 26 '07 #8
Walter Roberson wrote:
In article <11**********************@n39g2000hsh.googlegroups .com>,
vim <vg*****@gmail.comwrote:
>Use text processing languages
lex and yaac
Use regular expressions in that

You cannot reliably detect comments using regular expressions.
Of course we can, I have even written such a lex spec myself. :)

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>
Sep 26 '07 #9
In article <N7*********************@telenor.com>,
Tor Rustad <to********@hotmail.comwrote:
>Walter Roberson wrote:
>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.
--
Programming is what happens while you're busy making other plans.
Sep 26 '07 #10
On Sep 26, 8:55 am, daskumardi...@gmail.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>

HTH
--
Lew

Sep 26 '07 #11
Eric Sosman <Er*********@sun.comwrites:
Walter Roberson wrote On 09/26/07 10:07,:
[...]
>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.
I agree with your conclusion, but not necessarily with your statement
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
"preprocessor" 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_Keith) ks***@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"
Sep 26 '07 #12
da***********@gmail.com writes:
how to remove comment from c source code.
As you've seen from the variety of responses, you need to be more
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_Keith) ks***@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"
Sep 26 '07 #13
Lew Pitcher said:
On Sep 26, 8:55 am, daskumardi...@gmail.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>
Please don't look there. Look here instead:

http://clc-wiki.net/wiki/K%26R2_solu...%3AExercise_23

--
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
Sep 26 '07 #14
Walter Roberson wrote:
In article <N7*********************@telenor.com>,
Tor Rustad <to********@hotmail.comwrote:
>Walter Roberson wrote:
[snipped context and good advice by vim added]
>>vim said:
"Use text processing languages
lex and yaac
Use regular expressions in that"
>>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.
Well, yacc is a LALR parser, but that's beside the point, since yacc
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

http://www.lysator.liu.se/c/ANSI-C-grammar-l.html

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>
Sep 26 '07 #15

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Noud Aldenhoven | last post by:
Hello everyone, I was wondering how to remove comments away form a file. So that's why I made this script. =============================== #!/usr/bin/env python import sys import string
16
by: qwweeeit | last post by:
In analysing a very big application (pysol) made of almost 100 sources, I had the need to remove comments. Removing the comments which take all the line is straightforward... Instead for the...
2
by: user | last post by:
Hi How do i remove comments from a DOM object ? I tried searching the man pages XML::DOM, XML::DOM::Comment and XML::DOM::Document but could not find anything The code used to parse the...
16
by: graham.reeds | last post by:
I am updating a website that uses a countdown script embedded on the page. When the page is served the var's are set to how long the countdown has left in minutes and seconds, but the rest of the...
32
by: Stephen | last post by:
Is there a standard way to remove the warning that a C compiler might produce from the statement: if (a = b) {} I don't want to do: if ((a = b) != 0) {} Because my "a = b" is actually...
0
by: IGotNothin | last post by:
I'm running FxCop on one of my vb.net projects. One of the items is recommends is removing: Private designerPlaceholderDeclaration As System.Object ....as it is never used or is only ever...
6
by: HappyHippy | last post by:
More of a minor niggle than anything but how would I remove the aforementioned space? eg. strName = 'World' print 'Hello', strName, ', how are you today?' comes out as "Hello World , how are...
7
by: Simon Hart | last post by:
Hi, I have a requirement to remove the xmlns from the DOM in order to pass over to MS CRM 3.0 Fetch method.It seems the fetch method blows up if there is a xmlns present!?! The reason I have a...
17
by: Eric_Dexter | last post by:
def simplecsdtoorc(filename): file = open(filename,"r") alllines = file.read_until("</CsInstruments>") pattern1 = re.compile("</") orcfilename = filename + "orc" for line in alllines: if not...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.