From: | "Dmitry A. Kazakov" <mailbox@dmitry-kazakov.de> |
Newsgroups: | comp.compilers |
Date: | 12 Aug 2006 13:07:27 -0400 |
Organization: | cbb software GmbH |
References: | 06-08-042 |
Keywords: | C++, lex |
Posted-Date: | 12 Aug 2006 13:07:27 EDT |
On 9 Aug 2006 00:03:49 -0400, chtaylo3@gmail.com wrote:
> I'm trying to determine if a given line is a C/C++ style comment.
The answer depends on the context and the direction of scanning the
text. A SNOBOL-like pattern that matches C/C++ comments without nested
/* */ could be
'/*' *(END/|%): '*/' | '//'...END/
But you must be sure that the position where you start to scan is not
in another comment, string literal etc.
> My motivation for this is determing 4 metrics:
> how many lines of code have been added/changed
> how many lines of code have been removed
> how many lines of pure comments have been added/changed
> how many lines of pure comments have been removed.
Basically you should parse the program text and perhaps; as our
moderator has suggested, a lexer would be the best solution.
As for patterns you could use immediate assignment to get on
metrics. That is - when a comment pattern matches a comment in the
text, it assigns a variable, which in turn causes some action, like
metric change:
Comment_Var=('/*' *(END/|%): '*/' | '//'...END/)
which would be a subpattern of a larger patter that matches the whole
program and as a side effect produces metrics of.
--
Regards,
Dmitry A. Kazakov
http://www.dmitry-kazakov.de
Return to the
comp.compilers page.
Search the
comp.compilers archives again.