In this March 2025 Microsoft Dynamics 365 Developer training mini guide we go over what are X++ comments, the syntax standards and even the relation between D365FO programming and BNF.

Your comments help to annotate your code so it is much more maintainable and even easier to read for others. The X++ compiler tends not to consider comments while code is actually being executed at runtime, many compilers like X++ even strip comments in the compiled version and X++ can support two kinds of comments:
Single-line comments are starting with double forward slashes (//). Then everything after the // on that very same line is then a comment when it’s considered by X++.
// This is example of a single-line comment.
int x = 10; // This example comment is after a statement.
Multi-line comments appear between /* and */ symbols. This means to you that comments may take up multiple lines and not just one line.
// This is a kind of multi-line comment
// but it is written using better practice single-line comment syntax.
int z = 30;
/* here are examples of
multiple lines with multi line comment */
Both are available, but it is usually considered better practice to use the forward slashes or // kind of style in order to delineate your comments, and that goes for even multi-line comments so that your code can end up being more readable to other people.
X++ does recognize TODO comments. When your comment starts with TODO, it can have designation in Task List window when you work with Microsoft Visual Studio so your developers can track pending tasks
public void processMyOrder()
{
// TODO: Implement here your order processing logic.
}
In theoretical Backus-Naur Form (BNF), though note the actual BNF definition of X++ may or may not be exactly like this as the real internal implementation of Microsoft X++ is proprietary, an idea is that you may want to define your own comments as optional syntax elements that do not really affect the actual execution of the language. In X++, comments could be represented in BNF in order to show their syntax role in the language.
If we were to theoretically define comments in BNF for X++, well they might look something along the lines of this:
Single-Line Comments
Since single-line comments in X++ start with // and then continue until the end of the line, then in BNF, it might be something like:
SINGLE_LINE_COMMENT ::= "//" COMMENT_TEXT
COMMENT_TEXT ::= ANY_CHARACTER_EXCEPT_NEWLINE COMMENT_TEXT
| EMPTY
So // means the beginning of a comment.
COMMENT_TEXT means any characters except a newline.
The comment then terminates when your newline is encountered.
Since multi-line comments in X++ tend to show up between /* and */ this might be definable in BNF like this for ecample theoretically:
MULTI_LINE_COMMENT ::= "/*" COMMENT_BODY "*/"
COMMENT_BODY ::= ANY_CHARACTER COMMENT_BODY
| EMPTY
Here /* means to start the multi-line comment.
COMMENT_BODY means here any characters can be inside the comment.
The comment finally ends when */ has been encountered somewhere.
Theoretical BNF exploration goes into X++ syntax validation which helps with parsing language and with ignoring comments correctly. Grammar completeness in X++ means your language’s definition has all the syntactical stuff included there in the proper way. When you go into compiler implementation that can help with making a parser that end up correctly discarding your comments during compilation such as how C++, X++, C# and many other programming language parsers may tend to work internally.
What are the basics or what might X++ even be? You may find more in our longer March 2025 X++ training guide for developers to get some more information or contact Dynamics Edge with your questions.
Have a Question ?
Fill out this short form, one of our Experts will contact you soon.
Call Us Today For Your Free Consultation
Call Now