Re: How to determine if a given line is a C/C++ comment

glen herrmannsfeldt <gah@ugcs.caltech.edu>
14 Aug 2006 15:06:41 -0400

          From comp.compilers

Related articles
How to determine if a given line is a C/C++ comment chtaylo3@gmail.com (2006-08-09)
Re: How to determine if a given line is a C/C++ comment tom@infoether.com (Tom Copeland) (2006-08-10)
Re: How to determine if a given line is a C/C++ comment haberg@math.su.se (2006-08-10)
Re: How to determine if a given line is a C/C++ comment nicola.musatti@gmail.com (Nicola Musatti) (2006-08-10)
Re: How to determine if a given line is a C/C++ comment johnmillaway@yahoo.com (John Millaway) (2006-08-10)
Re: How to determine if a given line is a C/C++ comment mailbox@dmitry-kazakov.de (Dmitry A. Kazakov) (2006-08-12)
Re: How to determine if a given line is a C/C++ comment listas@nicolasb.com.ar (Nico) (2006-08-12)
Re: How to determine if a given line is a C/C++ comment gah@ugcs.caltech.edu (glen herrmannsfeldt) (2006-08-14)
Re: How to determine if a given line is a C/C++ comment nicola.musatti@gmail.com (Nicola Musatti) (2006-08-18)
Re: How to determine if a given line is a C/C++ comment zebedee@zebedee.net (zebedee) (2006-09-12)
| List of all articles for this month |

From: glen herrmannsfeldt <gah@ugcs.caltech.edu>
Newsgroups: comp.compilers
Date: 14 Aug 2006 15:06:41 -0400
Organization: Compilers Central
References: 06-08-042
Keywords: C++, lex

chtaylo3@gmail.com wrote:
(snip)


> I'm trying to determine if a given line is a C/C++ style comment.


(snip)


> [You need about 2/3 of a C++ lexer. You more or less need to
> scan for /* and then the matching */, except that you also need
> to look for quoted strings since "/*" is a string, not a comment.
> It's not that hard, with a lexer generator like flex you should
> be able to do it in a few hours. But people must have done this
> a hundred times before so I would first poke around on the net and
> see if there is code you can just steal. -John]


There is also the preprocessor to consider.


As I understand it, the OP is trying to understand how statement
counts change with editing, such as through diff.


Consider:


#if 0
/*
#endif


I pretty often use #if 0 to get around the non-nesting of comments,
and would never put a partial comment in a #if 0/#endif block,
but someone else might do it.


-- glen


Post a followup to this message

Return to the comp.compilers page.
Search the comp.compilers archives again.