1
$\begingroup$

This question already has an answer here:

I am aware that a similar question was already asked here and that the recent question A DFA for recognizing comments is also related but I am not satisfied with the answers.

The point is that

printf("/* This is not a comment */")

is a perfectly legal instruction in C and, as suggested by its name, the pattern to be printed is not a comment.

Is there a regular expression describing C-style /**/ comments in a correct C program?

$\endgroup$

marked as duplicate by Raphael Apr 6 '16 at 11:27

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

  • $\begingroup$ 1) The way to draw attention to a question with unsatisfactory answers is to open a bounty, not by creating a duplicate. 2) I assume that you are well aware that regular expressions are not powerful enough to parse C, ergo they can not detect exactly comments (even if not nested). Your question seems to be almost a proof of that fact, and should be added as an answer here. $\endgroup$ – Raphael Apr 6 '16 at 11:26
  • $\begingroup$ I know that that regular expressions are not powerful enough to parse C, but I don't see why it implies that comments cannot be detected by a regular expression. $\endgroup$ – J.-E. Pin Apr 6 '16 at 21:11
  • $\begingroup$ Seems to me you have to do full parsing so you can detect all kinds of language features that my "hide" comments. Strings are one example; there may be others. Plus, nested comments can never work with regular expressions. $\endgroup$ – Raphael Apr 7 '16 at 7:24