<p>I am wondering if this piece of G-code is valid:</p>

<pre><code>G0 (Some comment (Its G0 command)) Y10 Z-5
</code></pre>

<p>I have tested this on my Chinese CNC machine and it strips out the comment and works flawlessly.</p>

<p>The machine processes this as <code>G0Y10Z-5</code> which seems like the correct approach to me.</p>

<p>I have however never seen such comment in real CNC practise.
It would be nice if anyone is able to test it out on their CNC/3D Printer.</p>

<p>Many G-code simulators on the internet fail to process such a line in their parser so it makes me confused. I haven't found anything about it on RepRap Wiki or even Google.</p>

[{'answer_id': 6411, 'author': 'Tom van der Zanden', 'author_id': 26, 'author_profile': 'https://3dprinting.stackexchange.com/users/26', 'pm_score': 4, 'selected': False, 'text': '<p>This is not universally valid G-code, and how it is handled depends on the implementation. You can use this style of comment on <em>some</em> machines, but not all.</p>\n\n<p>The way parsing used to be implemented in Marlin (a very common 3D printer firmware), it would work fine unless the comment string included a X, Y, Z, E or F character. The parser simply looks for the first occurrence of X/Y/Z/E/F and then tries to parse the bit of text appearing after that character into a number. If the string cannot be parsed as a number, it defaults to 0 instead. For example,</p>\n\n<pre><code> G0 (Some comment containing the character Y) Y10 Z-5\n</code></pre>\n\n<p>would be interpreted as <code>G0 Y0 Z-5</code> and not as <code>G0 Y10 Z-5</code>, because ") " (the string appearing after the first occurrence of "Y") does not parse to any valid number. Your example happens to work fine because the comment string doesn\'t contain any special characters.</p>\n\n<p>Marlin does support end-of-line comments, which should start with a semicolon and continue until the end of the line.</p>\n\n<p>This is how it used to work in older Marlin versions. Newer Marlin versions have a more advanced parser, but it still would not play well with these parentheses-style comments. It is best to avoid them, as compatibility is not guaranteed.</p>\n'}, {'answer_id': 6412, 'author': 'Jan Vorisek', 'author_id': 12353, 'author_profile': 'https://3dprinting.stackexchange.com/users/12353', 'pm_score': 3, 'selected': True, 'text': '<p>It looks like comments inside parentheses are not allowed in numerous parsers (ie. Marlin). This seems to be true for most of the 3D printers. Classical CNC milling machines use parentheses without problems.</p>\n<p>It should work on Prusa printers as stated in their <a href="https://reprap.org/wiki/G-code#Comments" rel="nofollow noreferrer">Wiki</a>. Unfortunately there are no words about nesting of the comments.</p>\n<p>I have however found a comment on cnczone.com forums regarding the nesting of comments within parentheses.</p>\n<blockquote>\n<p>Printable characters and white space inside parentheses is a comment. A left parenthesis always starts a comment. The comment ends at the first right parenthesis found thereafter.</p>\n<p>Once a left parenthesis is placed on a line, a matching right parenthesis must appear before the end of the line.</p>\n<p>Comments may not be nested; it is an error if a left parenthesis is found after the start of a comment and before the end of the comment.</p>\n<p>Here is an example of a line containing a comment: <code>G80 M5 (stop motion)</code></p>\n</blockquote>\n<p>Source: <a href="https://www.cnczone.com/forums/g-code-programing/103434-coments-g-code.html#post763510" rel="nofollow noreferrer">cnczone.com</a></p>\n'}]
['https://3dprinting.stackexchange.com/questions/6410', 'https://3dprinting.stackexchange.com', 'https://3dprinting.stackexchange.com/users/12353/']