各种语言的注释总结--from wiki

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[edit]

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:

SymbolLanguages
C Fortran 77 and earlier; the 'C' must be in column 1 of a line to indicate a comment.
REM::: BASICCOMMAND.COMcmd.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 shellsCobraPerlPythonRubySeed7Windows PowerShellPHPRMaple
% TeXPrologMATLAB,[9] ErlangS-LangVisual Prolog
// ActionScriptC (C99)C++C#DGoJavaJavaScriptObject Pascal (Delphi), Objective-CPHPScalaSASS
' Visual BasicVBScriptRealBasic
! Fortran, Basic Plus, Inform
; AutoHotkeyAutoItLispCommon LispClojureRebolScheme, many assemblers
-- EuphoriaHaskellSQLAdaAppleScriptEiffelLuaVHDLSGML
* COBOL (if fixed-form and * in column 7), PAW, many assemblers, Fortran (if fixed-form and * in column 1)
|| Curl
" Vimscript
\ Forth

Block comments[edit]

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:

 

SymbolLanguages
¢ ~ ¢# ~ #co ~ cocomment ~comment ALGOL 68
/* */ ActionScript, AutoHotkey, C, C++, C#, D, Go, Java, JavaScript, Objective-C, PHP, PL/I, Scala (can be nested), SASS, SQL, Visual PrologCSS
#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, PascalSeed7ApplescriptOCaml (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)
#| |# LispSchemeRacket (can be nested in all three).
--[[ ]] Lua
" " Smalltalk
(comment ...) Clojure

posted @ 2014-03-17 20:35  二郎那个三郎  阅读(1033)  评论(0编辑  收藏  举报