One of the key principles in programming languages is the ability to incorporate comments and other documentation directly to the source code. Whether it is FORTRAN, COBOL or C++, the ability exists, but in varying forms.
Essentially, there are three different types of comment terminals used in programming languages: those that tell the compiler to ignore the remaining text in the current line of code and those used to denote the start and end of a multi-line comment.
To accommodate the intricacies of comments, the GOLD Parser Builder provides for this special class of terminals.
| Comment Start | The Comment Start terminal defines the symbol used to begin a block comment. When the tokenizer engine reads this symbol from the source text, it will increment an internal counter and ignore all other tokens until the Comment End token is encountered. Comments will be nested. |
| Comment End | The Comment End terminal defines the symbol that will denote the end of a block comment. |
| Comment Line | Unlike the Comment Start and Comment End terminals, the tokenizer will simply discard the rest of the line. |
This documentation contains an example on how to use the comment terminals in a grammar.
Below is a comparison of comment terminals in several common programming languages. Blanks fields denote the programming language lacks a terminal of that type. For instance, Visual Basic does not provide block comments.
| Programming Language | Line Comment | Comment Start | Comment End |
|---|---|---|---|
| Ada | -- | ||
| BASIC | REM | ||
| C (Original) | /* | */ | |
| C (ANSI) | // | /* | */ |
| C++ | // | /* | */ |
| COBOL | * | ||
| Delphi | { | } | |
| LISP | ; | ||
| FORTRAN 90 | ! | ||
| Java | // | /* | */ |
| Perl | # | ||
| Prolog | % | /* | */ |
| SQL | -- | /* | */ |
| Visual Basic | ' | ||
| GOLD Meta-Language | ! | !* | *! |