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) |
[1 later articles] |
From: | haberg@math.su.se (Hans Aberg) |
Newsgroups: | comp.compilers |
Date: | 10 Aug 2006 15:44:27 -0400 |
Organization: | Mathematics |
References: | 06-08-042 |
Keywords: | C, lex |
Posted-Date: | 10 Aug 2006 15:44:27 EDT |
chtaylo3@gmail.com wrote:
> obviously it is pretty straight forward to determine if a line uses the
> // style comment syntax, what's more difficult is determining if a
> given line is a pure comment inside a /* */ block.
> [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]
I think Bison <http://www.gnu.org/software/bison/bison.html> is doing it
to parse the actions in the .y files: C/C++ comments should not be altered
there, And it uses Flex/Bison .l/.y files to do the job.
For just recognizing C comments, there is an example in the Flex manual,
in its FAQ "How can I match C-style comments?.
--
Hans Aberg
Return to the
comp.compilers page.
Search the
comp.compilers archives again.