Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>Be careful... the following is legal:</p> <pre><code>if (x &gt; /*let's think... I think comparing it to 3 will be a good idea! */ 3) { peanut(); } </code></pre> <p>So any script will have to make sure to put the single-line comment at the end of the line. This loses the precise location of the comment, plus you need to think what to do with things like this:</p> <pre><code>if (/*hmm... x?*/ x /* yes, x! */ &gt; 3) { butter(); } </code></pre> <p>So you probably want to restrict yourself to comment blocks not appearing on the same line with other code. In that case, be aware block comments can be captured by a single regular expression, so a small <a href="https://stackoverflow.com/questions/3056518/looking-for-a-script-to-convert-multiline-block-comments-in-c-c-to-single-lin/3056623#3056623">Perl script</a> could probably do the job.</p> <p><strong>EDIT:</strong> actually, "code not appearing in the same line" is not enough:</p> <pre><code>char* s = "hello \ /* this is not a comment"; /* this is */ </code></pre> <p><strong>EDIT2:</strong> If you want to cover all corner cases, I think a better solution is to <a href="http://en.wikipedia.org/wiki/Lexical_analysis" rel="nofollow noreferrer">tokenize</a> the entire file. Since you can ignore many things, it wouldn't be too difficult - I've done so myself, in the past, for a C-like language. Once you get a token stream you can go over it, holding a "status" mode to keep track of strings / single-line comments / multiline comments.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload