Comments can be classified by:
- style (inline/block)
- parse rules (ignored/interpolated/stored in memory)
- recursivity (nestable/non-nestable)
- uses (docstrings/throwaway comments/other)
]
Inline comments are generally those that use a newline character to indicate the end of a comment, and an arbitrary delimiter or sequence of tokensto indicate the beginning of a comment.
Examples:
| Symbol | Languages |
|---|---|
C |
Fortran 77 and earlier; the 'C' must be in column 1 of a line to indicate a comment. |
REM, ::, :
|
BASIC, COMMAND.COM, cmd.exe, batch files |
NB. |
J; from the (historically) common abbreviation Nota bene, the Latin for "note well". |
⍝ |
APL; the mnemonic is the glyph (jot overstruck with shoe-down) resembles a desk lamp, and hence "illuminates" the foregoing. |
# |
Bourne shell and other UNIX shells, Cobra, Perl, Python, Ruby, Seed7, Windows PowerShell, PHP, R, Maple |
% |
TeX, Prolog, MATLAB,Visual Prolog |
// |
ActionScript, C (C99), C++, C#, D, Go, Java, JavaScript, Object Pascal (Delphi), Objective-C, PHP, Scala, SASS |
' |
Visual Basic, VBScript, RealBasic |
! |
Fortran, Basic Plus, Inform |
; |
AutoHotkey, AutoIt, Lisp, Common Lisp, Clojure, Rebol, Scheme, many assemblers |
-- |
Euphoria, Haskell, SQL, Ada, AppleScript, Eiffel, Lua, VHDL, SGML |
* |
COBOL (if fixed-form and * in column 7), PAW, many assemblers, Fortran (if fixed-form and * in column 1) |
|| |
Curl |
" |
Vimscript |
\ |
Forth |
]
Block comments are generally those that use a delimiter to indicate the beginning of a comment, and another delimiter to indicate the end of a comment. In this context, whitespace and newline characters are not counted as delimiters.
Examples:
| Symbol | Languages |
|---|---|
¢ ~ ¢, # ~ #, co ~ co, comment ~comment
|
ALGOL 68 |
/* */
|
ActionScript, AutoHotkey, C, C++, C#, D, Go, Java, JavaScript, Objective-C, PHP, PL/I, Scala (can be nested), SASS, SQL, Visual Prolog, CSS |
#cs #ce
|
AutoIt |
/+ +/
|
D (can be nested) |
/# #/
|
Cobra (can be nested) |
<# #>
|
Powershell |
=begin =cut
|
Perl |
=begin =end
|
Ruby |
#<tag></code> <code>#</tag> |
S-Lang |
{- -}
|
Haskell (can be nested) |
(* *)
|
Object Pascal (Delphi), ML, Mathematica, Pascal, Seed7, Applescript, OCaml (can be nested), Standard ML (can be nested), Maple, Newspeak |
{ }
|
Object Pascal (Delphi), Pascal |
|# #|
|
Curl |
%{ %}
|
MATLAB[9] (the symbols must be in a separate line) |
#| |#
|
Lisp, Scheme, Racket (can be nested in all three). |
--[[ ]] |
Lua |
" "
|
Smalltalk |
(comment ...)
|
Clojure |