Re: removing comment
- From: Eric Sosman <Eric.Sosman@xxxxxxx>
- Date: Wed, 26 Sep 2007 11:12:09 -0400
Walter Roberson wrote On 09/26/07 10:07,:
In article <1190814438.015492.177410@xxxxxxxxxxxxxxxxxxxxxxxxxxxx>,
vim <vgstech@xxxxxxxxx> wrote:
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.
--
Eric.Sosman@xxxxxxx
.
- Follow-Ups:
- Re: removing comment
- From: Keith Thompson
- Re: removing comment
- References:
- removing comment
- From: daskumardilip
- Re: removing comment
- From: David Marsh
- Re: removing comment
- From: vim
- Re: removing comment
- From: Walter Roberson
- removing comment
- Prev by Date: Re: C is too old? opinions?
- Next by Date: Re: C is too old? opinions?
- Previous by thread: Re: removing comment
- Next by thread: Re: removing comment
- Index(es):
Relevant Pages
|
|